CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
xml_schema_validator.h
1
2
3#pragma once
4
5#include <xml/xml_char_type.h>
6#include <xml/schema/xml_schema_validation_flags.h>
7#include <xml/schema/validation_event_handler.h>
8#include <system/multicast_delegate.h>
9#include <system/exceptions.h>
10#include <system/enum_helpers.h>
11#include <system/array.h>
12#include <cstdint>
13
14
16namespace System
17{
18namespace Collections
19{
20namespace Generic
21{
22template <typename, typename> class Dictionary;
23template <typename> class List;
24} // namespace Generic
25} // namespace Collections
26namespace Text
27{
28class StringBuilder;
29} // namespace Text
30class Uri;
31namespace Xml
32{
33class DocumentSchemaValidator;
34class HWStack;
35class IDtdInfo;
36class IXmlLineInfo;
37class IXmlNamespaceResolver;
38namespace Schema
39{
40class BaseValidator;
41class DtdValidator;
42class IdRefNode;
43class SchemaAttDef;
44class SchemaDeclBase;
45class SchemaElementDecl;
46class SchemaInfo;
47class ValidationState;
48enum class ValidatorState;
49class XdrValidator;
50class XmlSchema;
51class XmlSchemaAttribute;
53enum class XmlSchemaContentType;
54class XmlSchemaDatatype;
55class XmlSchemaElement;
56class Details_XmlSchemaException; using XmlSchemaException = System::ExceptionWrapper<Details_XmlSchemaException>;
57class XmlSchemaInfo;
58class XmlSchemaObject;
59class XmlSchemaParticle;
60class XmlSchemaSet;
61class XmlSchemaSimpleType;
63enum class XmlSeverityType;
64class XsdValidator;
65} // namespace Schema
66class XmlNameTable;
67class XmlQualifiedName;
68class XmlResolver;
69enum class XmlTokenizedType;
70class XsdValidatingReader;
71} // namespace Xml
72} // namespace System
74
75namespace System {
76
77namespace Xml {
78
79namespace Schema {
80
85using XmlValueGetter = System::MulticastDelegate<SharedPtr<Object>()>;
86
92class ASPOSECPP_SHARED_CLASS XmlSchemaValidator final : public System::Object
93{
96
97 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
98 ASPOSECPP_SHARED_RTTI_INFO_DECL();
99
100public:
101
104
105private:
107 friend class System::Xml::XsdValidatingReader;
108 friend class System::Xml::DocumentSchemaValidator;
109 friend class BaseValidator;
110 friend class DtdValidator;
111 friend class XdrValidator;
112 friend class XsdValidator;
114
115public:
116
119
123 ASPOSECPP_SHARED_API void set_XmlResolver(const SharedPtr<System::Xml::XmlResolver>& value);
129 ASPOSECPP_SHARED_API void set_LineInfoProvider(const SharedPtr<IXmlLineInfo>& value);
132 ASPOSECPP_SHARED_API SharedPtr<Uri> get_SourceUri();
135 ASPOSECPP_SHARED_API void set_SourceUri(const SharedPtr<Uri>& value);
141 ASPOSECPP_SHARED_API void set_ValidationEventSender(const SharedPtr<Object>& value);
142
150 ASPOSECPP_SHARED_API XmlSchemaValidator(const SharedPtr<XmlNameTable>& nameTable, const SharedPtr<XmlSchemaSet>& schemas, const SharedPtr<IXmlNamespaceResolver>& namespaceResolver, XmlSchemaValidationFlags validationFlags);
151
158 ASPOSECPP_SHARED_API void AddSchema(const SharedPtr<XmlSchema>& schema);
162 ASPOSECPP_SHARED_API void Initialize();
171 ASPOSECPP_SHARED_API void Initialize(const SharedPtr<XmlSchemaObject>& partialValidationType);
180 ASPOSECPP_SHARED_API void ValidateElement(const String& localName, const String& namespaceUri, const SharedPtr<XmlSchemaInfo>& schemaInfo);
195 ASPOSECPP_SHARED_API void ValidateElement(const String& localName, const String& namespaceUri, const SharedPtr<XmlSchemaInfo>& schemaInfo, const String& xsiType, const String& xsiNil, const String& xsiSchemaLocation, const String& xsiNoNamespaceSchemaLocation);
207 ASPOSECPP_SHARED_API SharedPtr<Object> ValidateAttribute(const String& localName, const String& namespaceUri, const String& attributeValue, const SharedPtr<XmlSchemaInfo>& schemaInfo);
220 ASPOSECPP_SHARED_API SharedPtr<Object> ValidateAttribute(const String& localName, const String& namespaceUri, XmlValueGetter attributeValue, const SharedPtr<XmlSchemaInfo>& schemaInfo);
226 ASPOSECPP_SHARED_API void GetUnspecifiedDefaultAttributes(const SharedPtr<Collections::Generic::List<SharedPtr<Object>>>& defaultAttributes);
236 ASPOSECPP_SHARED_API void ValidateEndOfAttributes(const SharedPtr<XmlSchemaInfo>& schemaInfo);
244 ASPOSECPP_SHARED_API void ValidateText(const String& elementValue);
253 ASPOSECPP_SHARED_API void ValidateText(XmlValueGetter elementValue);
260 ASPOSECPP_SHARED_API void ValidateWhitespace(const String& elementValue);
268 ASPOSECPP_SHARED_API void ValidateWhitespace(XmlValueGetter elementValue);
277 ASPOSECPP_SHARED_API SharedPtr<Object> ValidateEndElement(const SharedPtr<XmlSchemaInfo>& schemaInfo);
288 ASPOSECPP_SHARED_API SharedPtr<Object> ValidateEndElement(const SharedPtr<XmlSchemaInfo>& schemaInfo, const SharedPtr<Object>& typedValue);
296 ASPOSECPP_SHARED_API void SkipToEndElement(const SharedPtr<XmlSchemaInfo>& schemaInfo);
299 ASPOSECPP_SHARED_API void EndValidation();
306
307protected:
308
310 static ArrayPtr<std::vector<bool>> ValidStates;
311
312 SharedPtr<XmlSchemaSet> get_SchemaSet();
313 XmlSchemaValidationFlags get_ValidationFlags();
314 XmlSchemaContentType get_CurrentContentType();
315 XmlSchemaContentProcessing get_CurrentProcessContents();
316 bool get_ProcessIdentityConstraints();
317 bool get_ReportValidationWarnings();
318 bool get_ProcessSchemaHints();
319
320 void GetUnspecifiedDefaultAttributes(const SharedPtr<Collections::Generic::List<SharedPtr<Object>>>& defaultAttributes, bool createNodeData);
321 void SetDtdSchemaInfo(const SharedPtr<IDtdInfo>& dtdSchemaInfo);
322 String GetConcatenatedValue();
323 SharedPtr<Object> CheckMixedValueConstraint(const String& elementValue);
324 void RecompileSchemaSet();
325 String GetDefaultAttributePrefix(const String& attributeNS);
326 static void ElementValidationError(const SharedPtr<XmlQualifiedName>& name, const SharedPtr<ValidationState>& context, System::Xml::Schema::ValidationEventHandler eventHandler, const SharedPtr<Object>& sender, const String& sourceUri, int32_t lineNo, int32_t linePos, const SharedPtr<XmlSchemaSet>& schemaSet);
327 static void CompleteValidationError(const SharedPtr<ValidationState>& context, System::Xml::Schema::ValidationEventHandler eventHandler, const SharedPtr<Object>& sender, const String& sourceUri, int32_t lineNo, int32_t linePos, const SharedPtr<XmlSchemaSet>& schemaSet);
328 static String PrintExpectedElements(const SharedPtr<Collections::Generic::List<SharedPtr<XmlSchemaParticle>>>& expected);
329 static String PrintExpectedElements(const SharedPtr<Collections::Generic::List<String>>& expected);
330 static String QNameString(const String& localName, const String& ns);
331 static String BuildElementName(const SharedPtr<XmlQualifiedName>& qname);
332 static String BuildElementName(const String& localName, const String& ns);
333 static void SendValidationEvent(System::Xml::Schema::ValidationEventHandler eventHandler, const SharedPtr<Object>& sender, XmlSchemaValidationException e, XmlSeverityType severity);
335
336 virtual ASPOSECPP_SHARED_API ~XmlSchemaValidator();
337
339 #ifdef ASPOSE_GET_SHARED_MEMBERS
340 ASPOSECPP_SHARED_API void GetSharedMembers(System::Object::shared_members_type& result) const override;
341 #endif
342
343 #ifdef __DBG_FOR_EACH_MEMBER
344public:
347 ASPOSECPP_SHARED_API void DBG_for_each_member(DBG::for_each_member_visitor& visitor) const override;
350 const char* DBG_class_name() const override { return "XmlSchemaValidator"; }
351#endif
353
354private:
355
356 SharedPtr<XmlSchemaSet> _schemaSet;
357 XmlSchemaValidationFlags _validationFlags;
358 int32_t _startIDConstraint;
359 static const int32_t STACK_INCREMENT;
360 bool _isRoot;
361 bool _rootHasSchema;
362 bool _attrValid;
363 bool _checkEntity;
364 SharedPtr<SchemaInfo> _compiledSchemaInfo;
365 SharedPtr<IDtdInfo> _dtdSchemaInfo;
367 SharedPtr<HWStack> _validationStack;
369 ValidatorState _currentState;
373 SharedPtr<IdRefNode> _idRefListHead;
374 SharedPtr<XmlQualifiedName> _contextQName;
375 String _nsXs;
376 String _nsXsi;
377 String _nsXmlNs;
378 String _nsXml;
379 SharedPtr<XmlSchemaObject> _partialValidationType;
381 WeakPtr<Object> _validationEventSender;
382 SharedPtr<XmlNameTable> _nameTable;
383 SharedPtr<IXmlLineInfo> _positionInfo;
384 SharedPtr<IXmlLineInfo> _dummyPositionInfo;
386 SharedPtr<Uri> _sourceUri;
387 String _sourceUriString;
389 XmlSchemaContentProcessing _processContents;
390 static SharedPtr<XmlSchemaAttribute> s_xsiTypeSO;
391 static SharedPtr<XmlSchemaAttribute> s_xsiNilSO;
392 static SharedPtr<XmlSchemaAttribute> s_xsiSLSO;
393 static SharedPtr<XmlSchemaAttribute> s_xsiNoNsSLSO;
394 String _xsiTypeString;
395 String _xsiNilString;
396 String _xsiSchemaLocationString;
397 String _xsiNoNamespaceSchemaLocationString;
398 static SharedPtr<XmlSchemaDatatype> s_dtQName;
399 static SharedPtr<XmlSchemaDatatype> s_dtCDATA;
400 static SharedPtr<XmlSchemaDatatype> s_dtStringArray;
401 static const String Quote;
402 static ArrayPtr<SharedPtr<XmlSchemaParticle>> s_emptyParticleArray;
403 static ArrayPtr<SharedPtr<XmlSchemaAttribute>> s_emptyAttributeArray;
404 XmlCharType _xmlCharType;
405 static ArrayPtr<String> s_methodNames;
406
407 bool get_StrictlyAssessed();
408 bool get_HasSchema();
409 bool get_HasIdentityConstraints();
411
412 void Init();
413 void Reset();
414 SharedPtr<Object> ValidateAttribute(String localName, String namespaceUri, XmlValueGetter attributeValueGetter, const String& attributeStringValue, const SharedPtr<XmlSchemaInfo>& schemaInfo);
415 void ValidateText(const String& elementStringValue, XmlValueGetter elementValueGetter);
416 void ValidateWhitespace(const String& elementStringValue, XmlValueGetter elementValueGetter);
417 SharedPtr<Object> InternalValidateEndElement(const SharedPtr<XmlSchemaInfo>& schemaInfo, SharedPtr<Object> typedValue);
418 void ProcessSchemaLocations(const String& xsiSchemaLocation, const String& xsiNoNamespaceSchemaLocation);
419 SharedPtr<Object> ValidateElementContext(const SharedPtr<XmlQualifiedName>& elementName, bool& invalidElementInContext);
420 SharedPtr<XmlSchemaElement> GetSubstitutionGroupHead(const SharedPtr<XmlQualifiedName>& member);
421 SharedPtr<Object> ValidateAtomicValue(const String& stringValue, SharedPtr<XmlSchemaSimpleType>& memberType);
422 SharedPtr<Object> ValidateAtomicValue(const SharedPtr<Object>& parsedValue, SharedPtr<XmlSchemaSimpleType>& memberType);
423 String GetTypeName(const SharedPtr<SchemaDeclBase>& decl);
424 void SaveTextValue(const SharedPtr<Object>& value);
425 void Push(const SharedPtr<XmlQualifiedName>& elementName);
426 void Pop();
427 void AddXsiAttributes(const SharedPtr<Collections::Generic::List<SharedPtr<XmlSchemaAttribute>>>& attList);
428 SharedPtr<SchemaElementDecl> FastGetElementDecl(const SharedPtr<XmlQualifiedName>& elementName, const SharedPtr<Object>& particle);
429 SharedPtr<SchemaElementDecl> CheckXsiTypeAndNil(SharedPtr<SchemaElementDecl> elementDecl, const String& xsiType, const String& xsiNil, bool& declFound);
430 void ThrowDeclNotFoundWarningOrError(bool declFound);
431 void CheckElementProperties();
432 void ValidateStartElementIdentityConstraints();
433 SharedPtr<SchemaAttDef> CheckIsXmlAttribute(const SharedPtr<XmlQualifiedName>& attQName);
434 void AddXmlNamespaceSchema();
435 void LoadSchema(const String& uri, const String& url);
436 void ProcessTokenizedType(XmlTokenizedType ttype, const String& name, bool attrValue);
437 SharedPtr<Object> CheckAttributeValue(const SharedPtr<Object>& value, const SharedPtr<SchemaAttDef>& attdef);
438 SharedPtr<Object> CheckElementValue(const String& stringValue);
439 void CheckTokenizedTypes(const SharedPtr<XmlSchemaDatatype>& dtype, const SharedPtr<Object>& typedValue, bool attrValue);
440 SharedPtr<Object> FindId(const String& name);
441 void CheckForwardRefs();
442 void CheckStateTransition(ValidatorState toState, const String& methodName);
443 void ClearPSVI();
444 void CheckRequiredAttributes(const SharedPtr<SchemaElementDecl>& currentElementDecl);
445 SharedPtr<XmlSchemaElement> GetSchemaElement();
446 void AddIdentityConstraints();
447 void ElementIdentityConstraints();
448 void AttributeIdentityConstraints(const String& name, const String& ns, const SharedPtr<Object>& obj, const String& sobj, const SharedPtr<XmlSchemaDatatype>& datatype);
449 void EndElementIdentityConstraints(const SharedPtr<Object>& typedValue, const String& stringValue, const SharedPtr<XmlSchemaDatatype>& datatype);
450 static void BuildXsiAttributes();
451 static void PrintNamesWithNS(const SharedPtr<Collections::Generic::List<SharedPtr<XmlQualifiedName>>>& expected, const SharedPtr<Text::StringBuilder>& builder);
452 static void EnumerateAny(const SharedPtr<Text::StringBuilder>& builder, const String& namespaces);
453 void ProcessEntity(const String& name);
454 void SendValidationEvent(const String& code);
455 void SendValidationEvent(const String& code, const ArrayPtr<String>& args);
456 void SendValidationEvent(const String& code, const String& arg);
457 void SendValidationEvent(const String& code, const String& arg1, const String& arg2);
458 void SendValidationEvent(const String& code, const ArrayPtr<String>& args, Exception innerException, XmlSeverityType severity);
459 void SendValidationEvent(const String& code, const ArrayPtr<String>& args, Exception innerException);
460 void SendValidationEvent(XmlSchemaValidationException e);
461 void SendValidationEvent(XmlSchemaException e);
462 void SendValidationEvent(const String& code, const String& msg, XmlSeverityType severity);
463 void SendValidationEvent(XmlSchemaValidationException e, XmlSeverityType severity);
464
465 static struct __StaticConstructor__ { __StaticConstructor__(); } s_constructor__;
466
467};
468
469} // namespace Schema
470} // namespace Xml
471} // namespace System
472
473
List forward declaration.
Definition: list.h:127
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:62
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
String class used across the library. Is a substitute for C# System.String when translating code....
Definition: string.h:122
Subclass of System::SmartPtr which sets itself to weak mode at construction. Please note that this cl...
Definition: weak_ptr.h:18
Represents an XML Schema Definition Language (XSD) Schema validation engine. The XmlSchemaValidator c...
Definition: xml_schema_validator.h:93
void ValidateText(const String &elementValue)
Validates whether the text string specified is allowed in the current element context,...
SharedPtr< IXmlLineInfo > get_LineInfoProvider()
Returns the line number information for the XML node being validated.
SharedPtr< Object > ValidateAttribute(const String &localName, const String &namespaceUri, const String &attributeValue, const SharedPtr< XmlSchemaInfo > &schemaInfo)
Validates the attribute name, namespace URI, and value in the current element context.
SharedPtr< Object > get_ValidationEventSender()
Returns the object sent as the sender object of a validation event.
XmlSchemaValidator(const SharedPtr< XmlNameTable > &nameTable, const SharedPtr< XmlSchemaSet > &schemas, const SharedPtr< IXmlNamespaceResolver > &namespaceResolver, XmlSchemaValidationFlags validationFlags)
Initializes a new instance of the XmlSchemaValidator class.
void set_SourceUri(const SharedPtr< Uri > &value)
Sets the source URI for the XML node being validated.
SharedPtr< Object > ValidateEndElement(const SharedPtr< XmlSchemaInfo > &schemaInfo)
Verifies if the text content of the element is valid according to its data type for elements with sim...
void ValidateWhitespace(const String &elementValue)
Validates whether the white space in the string specified is allowed in the current element context,...
void ValidateElement(const String &localName, const String &namespaceUri, const SharedPtr< XmlSchemaInfo > &schemaInfo, const String &xsiType, const String &xsiNil, const String &xsiSchemaLocation, const String &xsiNoNamespaceSchemaLocation)
Validates the element in the current context with the xsi:Type, xsi:Nil, xsi:SchemaLocation,...
void AddSchema(const SharedPtr< XmlSchema > &schema)
Adds an XML Schema Definition Language (XSD) schema to the set of schemas used for validation.
void ValidateText(XmlValueGetter elementValue)
Validates whether the text returned by the XmlValueGetter object specified is allowed in the current ...
void EndValidation()
Ends validation and checks identity constraints for the entire XML document.
void ValidateElement(const String &localName, const String &namespaceUri, const SharedPtr< XmlSchemaInfo > &schemaInfo)
Validates the element in the current context.
void set_LineInfoProvider(const SharedPtr< IXmlLineInfo > &value)
Sets the line number information for the XML node being validated.
SharedPtr< Uri > get_SourceUri()
Returns the source URI for the XML node being validated.
void set_XmlResolver(const SharedPtr< System::Xml::XmlResolver > &value)
Sets the XmlResolver object used to resolve xs:import and xs:include elements as well as xsi:schemaLo...
void ValidateEndOfAttributes(const SharedPtr< XmlSchemaInfo > &schemaInfo)
Verifies whether all the required attributes in the element context are present and prepares the XmlS...
void GetUnspecifiedDefaultAttributes(const SharedPtr< Collections::Generic::List< SharedPtr< Object > > > &defaultAttributes)
Validates identity constraints on the default attributes and populates the List specified with XmlSch...
void Initialize()
Initializes the state of the XmlSchemaValidator object.
void set_ValidationEventSender(const SharedPtr< Object > &value)
Sets the object sent as the sender object of a validation event.
System::Xml::Schema::ValidationEventHandler ValidationEventHandler
The ValidationEventHandler that receives schema validation warnings and errors encountered during sch...
Definition: xml_schema_validator.h:118
ArrayPtr< SharedPtr< XmlSchemaAttribute > > GetExpectedAttributes()
Returns the expected attributes for the current element context.
void SkipToEndElement(const SharedPtr< XmlSchemaInfo > &schemaInfo)
Skips validation of the current element content and prepares the XmlSchemaValidator object to validat...
SharedPtr< Object > ValidateAttribute(const String &localName, const String &namespaceUri, XmlValueGetter attributeValue, const SharedPtr< XmlSchemaInfo > &schemaInfo)
Validates the attribute name, namespace URI, and value in the current element context.
void Initialize(const SharedPtr< XmlSchemaObject > &partialValidationType)
Initializes the state of the XmlSchemaValidator object using the XmlSchemaObject specified for partia...
void ValidateWhitespace(XmlValueGetter elementValue)
Validates whether the white space returned by the XmlValueGetter object specified is allowed in the c...
ArrayPtr< SharedPtr< XmlSchemaParticle > > GetExpectedParticles()
Returns the expected particles in the current element context.
SharedPtr< Object > ValidateEndElement(const SharedPtr< XmlSchemaInfo > &schemaInfo, const SharedPtr< Object > &typedValue)
Verifies if the text content of the element specified is valid according to its data type.
For internal purposes. Do not use this class directly.
Definition: xml_char_type.h:61
class ASPOSECPP_SHARED_CLASS List
Definition: ienumerable.h:18
@ Text
Defines color adjustment information for text.
System::ExceptionWrapper< Details_XmlSchemaValidationException > XmlSchemaValidationException
Definition: xml_schema_validation_exception.h:36
System::ExceptionWrapper< Details_XmlSchemaException > XmlSchemaException
Definition: xml_schema_exception.h:76
XmlSchemaContentType
Enumerations for the content model of the complex type. This represents the content in the post-schem...
Definition: xml_schema_content_type.h:18
System::MulticastDelegate< void(SharedPtr< Object >, SharedPtr< ValidationEventArgs >)> ValidationEventHandler
Represents the callback method that will handle XML schema validation events and the ValidationEventA...
Definition: validation_event_handler.h:33
System::MulticastDelegate< SharedPtr< Object >()> XmlValueGetter
A callback used by the XmlSchemaValidator class to pass attribute, text,and white space values as a r...
Definition: xml_schema_validator.h:85
XmlSeverityType
Represents the severity of the validation event.
Definition: xml_severity_type.h:17
XmlSchemaContentProcessing
Provides information about the validation mode of any and anyAttribute element replacements.
Definition: xml_schema_content_processing.h:17
XmlSchemaValidationFlags
Specifies schema validation options used by the XmlSchemaValidator and XmlReader classes.
Definition: xml_schema_validation_flags.h:18
@ Schema
Validate according to XML Schema definition language (XSD) schemas, including inline XML Schemas....
@ Xml
Serialize according to the XML 1.0 rules.
XmlTokenizedType
Represents the XML type for the string. This allows the string to be read as a particular XML type,...
Definition: xml_tokenized_type.h:16
Definition: db_command.h:9