+ This schema document describes the XML namespace, in a form + suitable for import by other schema documents. +
++ See + http://www.w3.org/XML/1998/namespace.html and + + http://www.w3.org/TR/REC-xml for information + about this namespace. +
++ Note that local names in this namespace are intended to be + defined only by the World Wide Web Consortium or its subgroups. + The names currently defined in this namespace are listed below. + They should not be used with conflicting semantics by any Working + Group, specification, or document instance. +
++ See further below in this document for more information about how to refer to this schema document from your own + XSD schema documents and about the + namespace-versioning policy governing this schema document. +
++ denotes an attribute whose value + is a language code for the natural language of the content of + any element; its value is inherited. This name is reserved + by virtue of its definition in the XML specification.
+ ++ Attempting to install the relevant ISO 2- and 3-letter + codes as the enumerated possible values is probably never + going to be a realistic possibility. +
++ See BCP 47 at + http://www.rfc-editor.org/rfc/bcp/bcp47.txt + and the IANA language subtag registry at + + http://www.iana.org/assignments/language-subtag-registry + for further information. +
++ The union allows for the 'un-declaration' of xml:lang with + the empty string. +
++ denotes an attribute whose + value is a keyword indicating what whitespace processing + discipline is intended for the content of the element; its + value is inherited. This name is reserved by virtue of its + definition in the XML specification.
+ ++ denotes an attribute whose value + provides a URI to be used as the base for interpreting any + relative URIs in the scope of the element on which it + appears; its value is inherited. This name is reserved + by virtue of its definition in the XML Base specification.
+ ++ See http://www.w3.org/TR/xmlbase/ + for information about this attribute. +
++ denotes an attribute whose value + should be interpreted as if declared to be of type ID. + This name is reserved by virtue of its definition in the + xml:id specification.
+ ++ See http://www.w3.org/TR/xml-id/ + for information about this attribute. +
++ denotes Jon Bosak, the chair of + the original XML Working Group. This name is reserved by + the following decision of the W3C XML Plenary and + XML Coordination groups: +
++++ In appreciation for his vision, leadership and + dedication the W3C XML Plenary on this 10th day of + February, 2000, reserves for Jon Bosak in perpetuity + the XML name "xml:Father". +
+
+ This schema defines attributes and an attribute group suitable
+ for use by schemas wishing to allow xml:base
,
+ xml:lang
, xml:space
or
+ xml:id
attributes on elements they define.
+
+ To enable this, such a schema must import this schema for + the XML namespace, e.g. as follows: +
++ <schema . . .> + . . . + <import namespace="http://www.w3.org/XML/1998/namespace" + schemaLocation="http://www.w3.org/2001/xml.xsd"/> ++
+ or +
++ <import namespace="http://www.w3.org/XML/1998/namespace" + schemaLocation="http://www.w3.org/2009/01/xml.xsd"/> ++
+ Subsequently, qualified reference to any of the attributes or the + group defined below will have the desired effect, e.g. +
++ <type . . .> + . . . + <attributeGroup ref="xml:specialAttrs"/> ++
+ will define a type which will schema-validate an instance element + with any of those attributes. +
++ In keeping with the XML Schema WG's standard versioning + policy, this schema document will persist at + + http://www.w3.org/2009/01/xml.xsd. +
++ At the date of issue it can also be found at + + http://www.w3.org/2001/xml.xsd. +
++ The schema document at that URI may however change in the future, + in order to remain compatible with the latest version of XML + Schema itself, or with the XML namespace itself. In other words, + if the XML Schema or XML namespaces change, the version of this + document at + http://www.w3.org/2001/xml.xsd + + will change accordingly; the version at + + http://www.w3.org/2009/01/xml.xsd + + will not change. +
++ Previous dated (and unchanging) versions of this schema + document are at: +
+ +ddJavaAll.xsl
XSLT extracted from the resource stream.
* @throws TransformerException
*/
- public void generateCode(final MetadataParserPath path, final boolean verbose) throws TransformerException
- {
+ public void generateCode(final MetadataParserPath path, final boolean verbose) throws TransformerException {
+
/** initialize the map which will overwrite global parameters as defined in metadata.xsl/ddJava.xsl */
final Map+ * The implementation is based on the xerces xni library. + *
+ * In order to make validations fast, the required schemas should be + * available on the classpath. The implementation searches the resources + * at the following locations: + *
getResourceAsStream()
*/
+ private ListXMLGrammarPreparser
and
+ * XMLGrammarPoolImpl
outside of the class.
+ * @param type defines the schema type.
+ * @param preparser the preparser created by the caller.
+ * @param grammarPool the grammar pool created by the caller.
+ */
+ public XmlValidator(
+ final SchemaType type,
+ final XMLGrammarPreparser preparser) {
+
+ if (type == null) {
+ throw new RuntimeException("The schema type must be initialized");
+ }
+
+ if (preparser == null) {
+ throw new RuntimeException("The preparser must be initialized");
+ }
+
+ if (preparser.getGrammarPool() == null) {
+ throw new RuntimeException("The grammar pool must be initialized");
+ }
+
+ this.schemaType = type;
+ this.preparser = preparser;
+ this.grammarPool = preparser.getGrammarPool();
+
+ initializeSearchLocations();
+ }
+
+ //-----------------------------------------------------------------------||
+ //-- Public Grammar Loader Methods --------------------------------------||
+ //-----------------------------------------------------------------------||
+
+ /**
+ * Installs the user XMLErrorHandler
instance.
+ * @param errorHandler the user specific error handler.
+ */
+ public void setErrorHandler(final XMLErrorHandler errorHandler) {
+ this.errorHandler = errorHandler;
+ }
+
+ /**
+ * Adds a new search location to the existing locations by inserting the
+ * new location at the first position.
+ *
+ * A location is an absolute path on the classpath, .e.g 'META-INF/xsd'
+ * without a leading slash ('/').
+ * @param location
+ */
+ public void addSearchLocation(final String location) {
+ if (!searchLocationList.isEmpty()) {
+ searchLocationList.add(0, location);
+ }
+ else {
+ searchLocationList.add(location);
+ }
+ }
+
+ /**
+ * Returns the current search locations.
+ * @return a unmodifiable list of the current search locations.
+ */
+ public List
+ This schema document describes the XML namespace, in a form
+ suitable for import by other schema documents.
+
+ See
+ http://www.w3.org/XML/1998/namespace.html and
+
+ http://www.w3.org/TR/REC-xml for information
+ about this namespace.
+
+ Note that local names in this namespace are intended to be
+ defined only by the World Wide Web Consortium or its subgroups.
+ The names currently defined in this namespace are listed below.
+ They should not be used with conflicting semantics by any Working
+ Group, specification, or document instance.
+
+ See further below in this document for more information about how to refer to this schema document from your own
+ XSD schema documents and about the
+ namespace-versioning policy governing this schema document.
+
+ denotes an attribute whose value
+ is a language code for the natural language of the content of
+ any element; its value is inherited. This name is reserved
+ by virtue of its definition in the XML specification.
+ Attempting to install the relevant ISO 2- and 3-letter
+ codes as the enumerated possible values is probably never
+ going to be a realistic possibility.
+
+ See BCP 47 at
+ http://www.rfc-editor.org/rfc/bcp/bcp47.txt
+ and the IANA language subtag registry at
+
+ http://www.iana.org/assignments/language-subtag-registry
+ for further information.
+
+ The union allows for the 'un-declaration' of xml:lang with
+ the empty string.
+
+ denotes an attribute whose
+ value is a keyword indicating what whitespace processing
+ discipline is intended for the content of the element; its
+ value is inherited. This name is reserved by virtue of its
+ definition in the XML specification.
+ denotes an attribute whose value
+ provides a URI to be used as the base for interpreting any
+ relative URIs in the scope of the element on which it
+ appears; its value is inherited. This name is reserved
+ by virtue of its definition in the XML Base specification.
+ See http://www.w3.org/TR/xmlbase/
+ for information about this attribute.
+
+ denotes an attribute whose value
+ should be interpreted as if declared to be of type ID.
+ This name is reserved by virtue of its definition in the
+ xml:id specification.
+ See http://www.w3.org/TR/xml-id/
+ for information about this attribute.
+
+ denotes Jon Bosak, the chair of
+ the original XML Working Group. This name is reserved by
+ the following decision of the W3C XML Plenary and
+ XML Coordination groups:
+
+ In appreciation for his vision, leadership and
+ dedication the W3C XML Plenary on this 10th day of
+ February, 2000, reserves for Jon Bosak in perpetuity
+ the XML name "xml:Father".
+
+ This schema defines attributes and an attribute group suitable
+ for use by schemas wishing to allow
+ To enable this, such a schema must import this schema for
+ the XML namespace, e.g. as follows:
+
+ or
+
+ Subsequently, qualified reference to any of the attributes or the
+ group defined below will have the desired effect, e.g.
+
+ will define a type which will schema-validate an instance element
+ with any of those attributes.
+
+ In keeping with the XML Schema WG's standard versioning
+ policy, this schema document will persist at
+
+ http://www.w3.org/2009/01/xml.xsd.
+
+ At the date of issue it can also be found at
+
+ http://www.w3.org/2001/xml.xsd.
+
+ The schema document at that URI may however change in the future,
+ in order to remain compatible with the latest version of XML
+ Schema itself, or with the XML namespace itself. In other words,
+ if the XML Schema or XML namespaces change, the version of this
+ document at
+ http://www.w3.org/2001/xml.xsd
+
+ will change accordingly; the version at
+
+ http://www.w3.org/2009/01/xml.xsd
+
+ will not change.
+
+ Previous dated (and unchanging) versions of this schema
+ document are at:
+
+ This schema document describes the XML namespace, in a form
+ suitable for import by other schema documents.
+
+ See
+ http://www.w3.org/XML/1998/namespace.html and
+
+ http://www.w3.org/TR/REC-xml for information
+ about this namespace.
+
+ Note that local names in this namespace are intended to be
+ defined only by the World Wide Web Consortium or its subgroups.
+ The names currently defined in this namespace are listed below.
+ They should not be used with conflicting semantics by any Working
+ Group, specification, or document instance.
+
+ See further below in this document for more information about how to refer to this schema document from your own
+ XSD schema documents and about the
+ namespace-versioning policy governing this schema document.
+
+ denotes an attribute whose value
+ is a language code for the natural language of the content of
+ any element; its value is inherited. This name is reserved
+ by virtue of its definition in the XML specification.
+ Attempting to install the relevant ISO 2- and 3-letter
+ codes as the enumerated possible values is probably never
+ going to be a realistic possibility.
+
+ See BCP 47 at
+ http://www.rfc-editor.org/rfc/bcp/bcp47.txt
+ and the IANA language subtag registry at
+
+ http://www.iana.org/assignments/language-subtag-registry
+ for further information.
+
+ The union allows for the 'un-declaration' of xml:lang with
+ the empty string.
+
+ denotes an attribute whose
+ value is a keyword indicating what whitespace processing
+ discipline is intended for the content of the element; its
+ value is inherited. This name is reserved by virtue of its
+ definition in the XML specification.
+ denotes an attribute whose value
+ provides a URI to be used as the base for interpreting any
+ relative URIs in the scope of the element on which it
+ appears; its value is inherited. This name is reserved
+ by virtue of its definition in the XML Base specification.
+ See http://www.w3.org/TR/xmlbase/
+ for information about this attribute.
+
+ denotes an attribute whose value
+ should be interpreted as if declared to be of type ID.
+ This name is reserved by virtue of its definition in the
+ xml:id specification.
+ See http://www.w3.org/TR/xml-id/
+ for information about this attribute.
+
+ denotes Jon Bosak, the chair of
+ the original XML Working Group. This name is reserved by
+ the following decision of the W3C XML Plenary and
+ XML Coordination groups:
+
+ In appreciation for his vision, leadership and
+ dedication the W3C XML Plenary on this 10th day of
+ February, 2000, reserves for Jon Bosak in perpetuity
+ the XML name "xml:Father".
+
+ This schema defines attributes and an attribute group suitable
+ for use by schemas wishing to allow
+ To enable this, such a schema must import this schema for
+ the XML namespace, e.g. as follows:
+
+ or
+
+ Subsequently, qualified reference to any of the attributes or the
+ group defined below will have the desired effect, e.g.
+
+ will define a type which will schema-validate an instance element
+ with any of those attributes.
+
+ In keeping with the XML Schema WG's standard versioning
+ policy, this schema document will persist at
+
+ http://www.w3.org/2009/01/xml.xsd.
+
+ At the date of issue it can also be found at
+
+ http://www.w3.org/2001/xml.xsd.
+
+ The schema document at that URI may however change in the future,
+ in order to remain compatible with the latest version of XML
+ Schema itself, or with the XML namespace itself. In other words,
+ if the XML Schema or XML namespaces change, the version of this
+ document at
+ http://www.w3.org/2001/xml.xsd
+
+ will change accordingly; the version at
+
+ http://www.w3.org/2009/01/xml.xsd
+
+ will not change.
+
+ Previous dated (and unchanging) versions of this schema
+ document are at:
+ XMLGrammarDescription
string based in the schema type.
+ * @return
+ */
+ private String getGrammarDescription() {
+ String grammarDescr = null;
+ if (schemaType == SchemaType.DTD) {
+ grammarDescr = XMLGrammarDescription.XML_DTD;
+ } else if (schemaType == SchemaType.XSD) {
+ grammarDescr = XMLGrammarDescription.XML_SCHEMA;
+ } else {
+ throw new RuntimeException("Not supported: " + schemaType);
+ }
+ return grammarDescr;
+ }
+
+ /**
+ * Returns a XMLParserConfiguration
based on the preparser configuration.
+ * @return a XMLParserConfiguration
.
+ */
+ private XMLParserConfiguration getParserConfiguration() {
+ final XMLParserConfiguration parserConfiguration = new XIncludeAwareParserConfiguration(sym, grammarPool);
+
+ // copy over the parser configuration
+ parserConfiguration.setFeature(XmlValidatorConstants.NAMESPACES_FEATURE_ID, nameSpacesID);
+ parserConfiguration.setFeature(XmlValidatorConstants.VALIDATION_FEATURE_ID, validationID);
+ parserConfiguration.setFeature(XmlValidatorConstants.SCHEMA_VALIDATION_FEATURE_ID, schemaValidationID);
+ parserConfiguration.setFeature(XmlValidatorConstants.SCHEMA_FULL_CHECKING_FEATURE_ID, schemaFullCheckingID);
+ parserConfiguration.setFeature(XmlValidatorConstants.HONOUR_ALL_SCHEMA_LOCATIONS_ID, honourAllSchemaID);
+
+ // install our own error handler in case no external error hander is defined.
+ if (errorHandler == null) {
+ parserConfiguration.setErrorHandler(new ErrorHandler());
+ }
+
+ return parserConfiguration;
+ }
+
+ /**
+ * Checks that at least one grammar is loaded.
+ */
+ private void checkGrammarPoolSize() {
+ if (grammarCount == 0) {
+ throw new RuntimeException("No grammar loaded. Please, load the grammars first");
+ }
+ }
+
+ private void initializePreparser() {
+ preparser.setProperty(XmlValidatorConstants.GRAMMAR_POOL, grammarPool);
+ preparser.setFeature(XmlValidatorConstants.NAMESPACES_FEATURE_ID, nameSpacesID);
+ preparser.setFeature(XmlValidatorConstants.VALIDATION_FEATURE_ID, validationID);
+ preparser.setFeature(XmlValidatorConstants.SCHEMA_VALIDATION_FEATURE_ID, schemaValidationID);
+ preparser.setFeature(XmlValidatorConstants.SCHEMA_FULL_CHECKING_FEATURE_ID, schemaFullCheckingID);
+ preparser.setFeature(XmlValidatorConstants.HONOUR_ALL_SCHEMA_LOCATIONS_ID, honourAllSchemaID);
+ preparser.setEntityResolver(new ResourceStreamResolver());
+ }
+
+ /**
+ * Returns a XMLInputSource
object.
+ * @param uri the URI from which the input source is created.
+ * @return
+ */
+ private static XMLInputSource stringToXIS(final String uri) {
+ return new XMLInputSource(null, uri, null);
+ }
+
+
+ //-----------------------------------------------------------------------||
+ //-- Private Classes ----------------------------------------------------||
+ //-----------------------------------------------------------------------||
+
+ /**
+ * This our default entity resolver. This class is able to resolve
+ * system id's as a resource stream preventing HTTP calls.
+ */
+ private class ResourceStreamResolver implements XMLEntityResolver {
+
+ @Override
+ public XMLInputSource resolveEntity(final XMLResourceIdentifier resourceIdentifier)
+ throws XNIException, IOException {
+
+ XMLInputSource xmlInputStream = null;
+ InputStream inputStream = null;
+ if (resourceIdentifier.getExpandedSystemId().equals("http://www.w3.org/2001/xml.xsd")) {
+ inputStream = getFirstValidInputStream("xml.xsd");
+
+ } else {
+ // try to get the resource from a resource
+ inputStream = getInputStream(resourceIdentifier);
+ }
+
+ if (inputStream != null) {
+ xmlInputStream = new XMLInputSource(null,
+ resourceIdentifier.getExpandedSystemId(), null, inputStream, null);
+ }
+
+ return xmlInputStream;
+ }
+
+ }
+
+ /**
+ * Checks if the given resource name starts with a path seperator. If yes,
+ * then the resource is a File
resource. If not, then
+ * we assume that the resource can be loaded via resource stream.
+ * @param resourceName
+ * @return true, if the resource can be loaded via resources stream, otherwise
+ * it is assumed that the resource is file on the file system.
+ */
+ private boolean isResourceCandidate(final String resourceName) {
+ if (resourceName.indexOf(File.pathSeparator) >= 0) {
+ return false;
+ }
+ return true;
+ }
+
+ private InputStream getInputStream(final XMLResourceIdentifier resourceIdentifier) throws MalformedURLException {
+ final File url = new File(resourceIdentifier.getExpandedSystemId());
+ return getFirstValidInputStream(url.getName());
+ }
+
+ /**
+ * Returns the first not nullable InputStream
.
+ * @param resources
+ * @return the first resolvable InputStream
, or null if non of the resources are found.
+ */
+ private InputStream getFirstValidInputStream(final String schema) {
+ InputStream inputStream = null;
+ for (String location: searchLocationList) {
+ inputStream = getClassLoaderForClass(this.getClass()).getResourceAsStream(location + schema);
+ if (inputStream != null) {
+ break;
+ }
+ }
+ return inputStream;
+ }
+
+ /**
+ * Initializes the location list.
+ */
+ private void initializeSearchLocations() {
+ searchLocationList.add("META-INF/xsd/");
+ searchLocationList.add("xsd/");
+ searchLocationList.add("");
+ searchLocationList.add("META-INF/2001/");
+ }
+
+ /**
+ * This is our default error handler.
+ */
+ private class ErrorHandler implements XMLErrorHandler {
+
+ @Override
+ public void warning(String domain, String key,
+ XMLParseException exception) throws XNIException {
+ // we ignore warnings
+ }
+
+ @Override
+ public void error(String domain, String key,
+ XMLParseException exception) throws XNIException {
+ throw new XNIException(exception);
+ }
+
+ @Override
+ public void fatalError(String domain, String key,
+ XMLParseException exception) throws XNIException {
+ throw new XNIException(exception);
+ }
+ }
+
+ /**
+ * Returns the right ClassLoader.
+ * @param clazz
+ * @return
+ */
+ private static ClassLoader getClassLoaderForClass(final Class> clazz){
+ assert clazz!=null:"Class must be specified";
+ if(System.getSecurityManager()==null){
+ return clazz.getClassLoader();
+ }
+ else{
+ return AccessController.doPrivileged(new PrivilegedActionAbout the XML namespace
+
+ lang (as an attribute name)
+ Notes
+ space (as an attribute name)
+ base (as an attribute name)
+ id (as an attribute name)
+ Father (in any context at all)
+
+
+
+ About this schema document
+
+ xml:base
,
+ xml:lang
, xml:space
or
+ xml:id
attributes on elements they define.
+
+ <schema . . .>
+ . . .
+ <import namespace="http://www.w3.org/XML/1998/namespace"
+ schemaLocation="http://www.w3.org/2001/xml.xsd"/>
+
+
+ <import namespace="http://www.w3.org/XML/1998/namespace"
+ schemaLocation="http://www.w3.org/2009/01/xml.xsd"/>
+
+
+ <type . . .>
+ . . .
+ <attributeGroup ref="xml:specialAttrs"/>
+
+ Versioning policy for this schema document
+ About the XML namespace
+
+ lang (as an attribute name)
+ Notes
+ space (as an attribute name)
+ base (as an attribute name)
+ id (as an attribute name)
+ Father (in any context at all)
+
+
+
+ About this schema document
+
+ xml:base
,
+ xml:lang
, xml:space
or
+ xml:id
attributes on elements they define.
+
+ <schema . . .>
+ . . .
+ <import namespace="http://www.w3.org/XML/1998/namespace"
+ schemaLocation="http://www.w3.org/2001/xml.xsd"/>
+
+
+ <import namespace="http://www.w3.org/XML/1998/namespace"
+ schemaLocation="http://www.w3.org/2009/01/xml.xsd"/>
+
+
+ <type . . .>
+ . . .
+ <attributeGroup ref="xml:specialAttrs"/>
+
+ Versioning policy for this schema document
+