Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DtdValidator.cs
Go to the documentation of this file.
3using System.Text;
4
5namespace System.Xml.Schema;
6
7internal sealed class DtdValidator : BaseValidator
8{
9 private sealed class NamespaceManager : XmlNamespaceManager
10 {
11 public override string LookupNamespace(string prefix)
12 {
13 return prefix;
14 }
15 }
16
17 private static readonly NamespaceManager s_namespaceManager = new NamespaceManager();
18
20
22
24
25 private Hashtable _IDs;
26
28
29 private readonly bool _processIdentityConstraints;
30
31 public override bool PreserveWhitespace
32 {
33 get
34 {
35 if (context.ElementDecl == null)
36 {
37 return false;
38 }
40 }
41 }
42
49
50 [MemberNotNull("_validationStack")]
51 [MemberNotNull("_name")]
52 [MemberNotNull("_attPresence")]
53 private void Init()
54 {
55 _validationStack = new HWStack(10);
58 _attPresence = new Hashtable();
59 schemaInfo = new SchemaInfo();
60 checkDatatype = false;
61 Push(_name);
62 }
63
64 public override void Validate()
65 {
67 {
68 switch (reader.NodeType)
69 {
70 case XmlNodeType.Element:
73 {
74 goto case XmlNodeType.EndElement;
75 }
76 break;
77 case XmlNodeType.Whitespace:
78 case XmlNodeType.SignificantWhitespace:
80 {
82 }
83 break;
84 case XmlNodeType.ProcessingInstruction:
85 case XmlNodeType.Comment:
87 break;
88 case XmlNodeType.Text:
89 case XmlNodeType.CDATA:
91 break;
92 case XmlNodeType.EntityReference:
94 {
96 }
97 break;
98 case XmlNodeType.EndElement:
100 break;
101 case XmlNodeType.Attribute:
102 case XmlNodeType.Entity:
103 case XmlNodeType.Document:
104 case XmlNodeType.DocumentType:
105 case XmlNodeType.DocumentFragment:
106 case XmlNodeType.Notation:
107 break;
108 }
109 }
110 else if (reader.Depth == 0 && reader.NodeType == XmlNodeType.Element)
111 {
113 }
114 }
115
117 {
119 {
121 return false;
122 }
123 return true;
124 }
125
133
147
148 private void ValidateChildElement()
149 {
151 {
152 int errorCode = 0;
154 if (errorCode < 0)
155 {
156 XmlSchemaValidator.ElementValidationError(elementName, context, base.EventHandler, reader, reader.BaseURI, base.PositionInfo.LineNumber, base.PositionInfo.LinePosition, null);
157 }
158 }
159 }
160
161 private void ValidateStartElement()
162 {
163 if (context.ElementDecl != null)
164 {
166 if (base.Reader.IsEmptyElement && context.ElementDecl.DefaultValueTyped != null)
167 {
169 context.IsNill = true;
170 }
172 {
174 }
175 }
176 if (!base.Reader.MoveToFirstAttribute())
177 {
178 return;
179 }
180 do
181 {
182 try
183 {
186 if (attDef != null)
187 {
189 {
191 }
193 if (attDef.Datatype != null && !reader.IsDefault)
194 {
195 CheckValue(base.Reader.Value, attDef);
196 }
197 }
198 else
199 {
201 }
202 }
203 catch (XmlSchemaException ex)
204 {
205 ex.SetSource(base.Reader.BaseURI, base.PositionInfo.LineNumber, base.PositionInfo.LinePosition);
207 }
208 }
209 while (base.Reader.MoveToNextAttribute());
210 base.Reader.MoveToElement();
211 }
212
214 {
216 {
217 try
218 {
220 }
221 catch (XmlSchemaException ex)
222 {
223 ex.SetSource(base.Reader.BaseURI, base.PositionInfo.LineNumber, base.PositionInfo.LinePosition);
225 }
226 }
227 if (context.ElementDecl.Datatype != null)
228 {
229 checkDatatype = true;
230 hasSibling = false;
231 textString = string.Empty;
233 }
234 }
235
254
255 public override void CompleteValidation()
256 {
258 {
259 do
260 {
262 }
263 while (Pop());
265 }
266 }
267
268 private void ValidateEndElement()
269 {
270 if (context.ElementDecl != null)
271 {
273 {
274 XmlSchemaValidator.CompleteValidationError(context, base.EventHandler, reader, reader.BaseURI, base.PositionInfo.LineNumber, base.PositionInfo.LinePosition, null);
275 }
276 if (checkDatatype)
277 {
278 string value = ((!hasSibling) ? textString : textValue.ToString());
279 CheckValue(value, null);
280 checkDatatype = false;
282 textString = string.Empty;
283 }
284 }
285 Pop();
286 }
287
288 private void ProcessTokenizedType(XmlTokenizedType ttype, string name)
289 {
290 switch (ttype)
291 {
292 case XmlTokenizedType.ID:
294 {
295 if (FindId(name) != null)
296 {
298 }
299 else
300 {
301 AddID(name, context.LocalName);
302 }
303 }
304 break;
305 case XmlTokenizedType.IDREF:
307 {
308 object obj = FindId(name);
309 if (obj == null)
310 {
311 _idRefListHead = new IdRefNode(_idRefListHead, name, base.PositionInfo.LineNumber, base.PositionInfo.LinePosition);
312 }
313 }
314 break;
315 case XmlTokenizedType.ENTITY:
316 BaseValidator.ProcessEntity(schemaInfo, name, this, base.EventHandler, base.Reader.BaseURI, base.PositionInfo.LineNumber, base.PositionInfo.LinePosition);
317 break;
318 case XmlTokenizedType.IDREFS:
319 break;
320 }
321 }
322
323 private void CheckValue(string value, SchemaAttDef attdef)
324 {
325 try
326 {
328 bool flag = attdef != null;
330 if (xmlSchemaDatatype == null)
331 {
332 return;
333 }
334 if (xmlSchemaDatatype.TokenizedType != 0)
335 {
336 value = value.Trim();
337 }
342 {
344 {
345 string[] array = (string[])obj;
346 for (int i = 0; i < array.Length; i++)
347 {
349 }
350 }
351 else
352 {
353 ProcessTokenizedType(xmlSchemaDatatype.TokenizedType, (string)obj);
354 }
355 }
357 if (schemaDeclBase.Values != null && !schemaDeclBase.CheckEnumeration(obj))
358 {
359 if (xmlSchemaDatatype.TokenizedType == XmlTokenizedType.NOTATION)
360 {
362 }
363 else
364 {
366 }
367 }
368 if (!schemaDeclBase.CheckValue(obj))
369 {
370 if (flag)
371 {
373 }
374 else
375 {
377 }
378 }
379 }
380 catch (XmlSchemaException)
381 {
382 if (attdef != null)
383 {
385 }
386 else
387 {
389 }
390 }
391 }
392
393 internal void AddID(string name, object node)
394 {
395 if (_IDs == null)
396 {
397 _IDs = new Hashtable();
398 }
399 _IDs.Add(name, node);
400 }
401
402 public override object FindId(string name)
403 {
404 if (_IDs != null)
405 {
406 return _IDs[name];
407 }
408 return null;
409 }
410
411 private bool GenEntity(XmlQualifiedName qname)
412 {
413 string name = qname.Name;
414 if (name[0] == '#')
415 {
416 return false;
417 }
419 {
420 return false;
421 }
422 SchemaEntity entity = GetEntity(qname, fParameterEntity: false);
423 if (entity == null)
424 {
426 }
427 if (!entity.NData.IsEmpty)
428 {
430 }
432 {
434 }
435 return true;
436 }
437
439 {
442 {
443 if (schemaInfo.ParameterEntities.TryGetValue(qname, out value))
444 {
445 return value;
446 }
447 }
448 else if (schemaInfo.GeneralEntities.TryGetValue(qname, out value))
449 {
450 return value;
451 }
452 return null;
453 }
454
455 private void CheckForwardRefs()
456 {
458 while (idRefNode != null)
459 {
460 if (FindId(idRefNode.Id) == null)
461 {
463 }
464 IdRefNode next = idRefNode.Next;
465 idRefNode.Next = null;
466 idRefNode = next;
467 }
468 _idRefListHead = null;
469 }
470
485
486 private bool Pop()
487 {
488 if (_validationStack.Length > 1)
489 {
492 return true;
493 }
494 return false;
495 }
496
498 {
499 try
500 {
501 string text = attdef.DefaultValueExpanded;
502 XmlSchemaDatatype datatype = attdef.Datatype;
503 if (datatype != null)
504 {
505 if (datatype.TokenizedType != 0)
506 {
507 text = text.Trim();
508 }
509 attdef.DefaultValueTyped = datatype.ParseValue(text, readerAdapter.NameTable, readerAdapter.NamespaceResolver);
510 }
511 }
512 catch (Exception)
513 {
515 if (validationEventHandling != null)
516 {
519 }
520 }
521 }
522
524 {
525 try
526 {
527 if (baseUriStr == null)
528 {
529 baseUriStr = string.Empty;
530 }
531 XmlSchemaDatatype datatype = attdef.Datatype;
532 if (datatype == null)
533 {
534 return;
535 }
536 object defaultValueTyped = attdef.DefaultValueTyped;
537 switch (datatype.TokenizedType)
538 {
539 case XmlTokenizedType.ENTITY:
540 if (datatype.Variety == XmlSchemaDatatypeVariety.List)
541 {
542 string[] array = (string[])defaultValueTyped;
543 for (int i = 0; i < array.Length; i++)
544 {
545 BaseValidator.ProcessEntity(sinfo, array[i], eventHandling, baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
546 }
547 }
548 else
549 {
550 BaseValidator.ProcessEntity(sinfo, (string)defaultValueTyped, eventHandling, baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
551 }
552 break;
553 case XmlTokenizedType.ENUMERATION:
554 if (!attdef.CheckEnumeration(defaultValueTyped) && eventHandling != null)
555 {
556 XmlSchemaException exception = new XmlSchemaException(System.SR.Sch_EnumerationValue, defaultValueTyped.ToString(), baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
557 eventHandling.SendEvent(exception, XmlSeverityType.Error);
558 }
559 break;
560 }
561 }
562 catch (Exception)
563 {
564 if (eventHandling != null)
565 {
567 eventHandling.SendEvent(exception2, XmlSeverityType.Error);
568 }
569 }
570 }
571}
virtual void Add(object key, object? value)
Definition Hashtable.cs:676
static string Sch_AttributeValueDataType
Definition SR.cs:1808
static string Sch_ElementValueDataType
Definition SR.cs:1810
static string Sch_FixedElementValue
Definition SR.cs:494
static string Sch_UndeclaredId
Definition SR.cs:418
static string Sch_RootMatchDocType
Definition SR.cs:408
static string Sch_StandAlone
Definition SR.cs:590
static string Xml_UndeclaredEntity
Definition SR.cs:120
static string Sch_FixedAttributeValue
Definition SR.cs:492
static string Xml_UnparsedEntityRef
Definition SR.cs:128
static string Sch_AttributeDefaultDataType
Definition SR.cs:498
static string Sch_InvalidPIComment
Definition SR.cs:920
static string Sch_UndeclaredElement
Definition SR.cs:412
static string Xml_NoDTDPresent
Definition SR.cs:218
static string Sch_EnumerationValue
Definition SR.cs:568
static string Sch_DupId
Definition SR.cs:410
static string Sch_UndeclaredAttribute
Definition SR.cs:414
static string Sch_NotationValue
Definition SR.cs:566
Definition SR.cs:7
override string ToString()
void AddToTop(object o)
Definition HWStack.cs:90
object Push()
Definition HWStack.cs:52
object Peek()
Definition HWStack.cs:81
void SendValidationEvent(string code)
XmlValidatingReaderImpl reader
static void ProcessEntity(SchemaInfo sinfo, string name, object sender, ValidationEventHandler eventhandler, string baseUri, int lineNumber, int linePosition)
virtual bool CompleteValidation(ValidationState context)
static readonly ContentValidator Empty
virtual object ValidateElement(XmlQualifiedName name, ValidationState context, out int errorCode)
override string LookupNamespace(string prefix)
readonly bool _processIdentityConstraints
void Push(XmlQualifiedName elementName)
SchemaEntity GetEntity(XmlQualifiedName qname, bool fParameterEntity)
void ProcessTokenizedType(XmlTokenizedType ttype, string name)
void CheckValue(string value, SchemaAttDef attdef)
void AddID(string name, object node)
static void CheckDefaultValue(SchemaAttDef attdef, SchemaInfo sinfo, IValidationEventHandling eventHandling, string baseUriStr)
bool GenEntity(XmlQualifiedName qname)
override object FindId(string name)
DtdValidator(XmlValidatingReaderImpl reader, IValidationEventHandling eventHandling, bool processIdentityConstraints)
static void SetDefaultTypedValue(SchemaAttDef attdef, IDtdParserAdapter readerAdapter)
static readonly NamespaceManager s_namespaceManager
SchemaAttDef GetAttDef(XmlQualifiedName qname)
void CheckAttributes(Hashtable presence, bool standalone)
static bool IsPredefinedEntity(string n)
SchemaElementDecl GetElementDecl(XmlQualifiedName qname)
Dictionary< XmlQualifiedName, SchemaEntity > GeneralEntities
Definition SchemaInfo.cs:60
Dictionary< XmlQualifiedName, SchemaEntity > ParameterEntities
Definition SchemaInfo.cs:72
XmlQualifiedName DocTypeName
Definition SchemaInfo.cs:36
object ParseValue(string s, XmlNameTable? nameTable, IXmlNamespaceResolver? nsmgr)
virtual XmlSchemaDatatypeVariety Variety
static void ElementValidationError(XmlQualifiedName name, ValidationState context, ValidationEventHandler eventHandler, object sender, string sourceUri, int lineNo, int linePos, XmlSchemaSet schemaSet)
static void CompleteValidationError(ValidationState context, ValidationEventHandler eventHandler, object sender, string sourceUri, int lineNo, int linePos, XmlSchemaSet schemaSet)
static string QNameString(string localName, string ns)
override bool Equals([NotNullWhen(true)] object? other)
static readonly XmlQualifiedName Empty
void Init(string name, string ns)