You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mr...@apache.org on 2005/06/10 04:38:18 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/jaxp SAXParserImpl.java DocumentBuilderImpl.java
mrglavas 2005/06/09 19:38:18
Modified: java/src/org/apache/xerces/jaxp SAXParserImpl.java
DocumentBuilderImpl.java
Log:
Integrating support for XInclude and getSchema(), plus some code reorganization.
Revision Changes Path
1.25 +64 -22 xml-xerces/java/src/org/apache/xerces/jaxp/SAXParserImpl.java
Index: SAXParserImpl.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/jaxp/SAXParserImpl.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- SAXParserImpl.java 17 May 2005 17:25:45 -0000 1.24
+++ SAXParserImpl.java 10 Jun 2005 02:38:18 -0000 1.25
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation.
+ * Copyright 2000-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
import java.util.Hashtable;
import javax.xml.parsers.SAXParserFactory;
+import javax.xml.validation.Schema;
import org.apache.xerces.impl.Constants;
import org.xml.sax.Parser;
@@ -44,9 +45,30 @@
*/
public class SAXParserImpl extends javax.xml.parsers.SAXParser
implements JAXPConstants, PSVIProvider {
+
+ /** Feature identifier: namespaces. */
+ private static final String NAMESPACES_FEATURE =
+ Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE;
+
+ /** Feature identifier: namespace prefixes. */
+ private static final String NAMESPACE_PREFIXES_FEATURE =
+ Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACE_PREFIXES_FEATURE;
+
+ /** Feature identifier: validation. */
+ private static final String VALIDATION_FEATURE =
+ Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE;
+
+ /** Feature identifier: XML Schema validation */
+ private static final String XMLSCHEMA_VALIDATION_FEATURE =
+ Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE;
+
+ /** Feature identifier: XInclude processing */
+ private static final String XINCLUDE_FEATURE =
+ Constants.XERCES_FEATURE_PREFIX + Constants.XINCLUDE_FEATURE;
private XMLReader xmlReader;
private String schemaLanguage = null; // null means DTD
+ private final Schema grammar;
/**
* Create a SAX parser with the associated features
@@ -66,22 +88,26 @@
xmlReader.setErrorHandler(new DefaultValidationErrorHandler());
}
- xmlReader.setFeature(Constants.SAX_FEATURE_PREFIX +
- Constants.VALIDATION_FEATURE, spf.isValidating());
+ xmlReader.setFeature(VALIDATION_FEATURE, spf.isValidating());
// JAXP "namespaceAware" == SAX Namespaces feature
// Note: there is a compatibility problem here with default values:
// JAXP default is false while SAX 2 default is true!
- xmlReader.setFeature(Constants.SAX_FEATURE_PREFIX +
- Constants.NAMESPACES_FEATURE,
- spf.isNamespaceAware());
+ xmlReader.setFeature(NAMESPACES_FEATURE, spf.isNamespaceAware());
// SAX "namespaces" and "namespace-prefixes" features should not
// both be false. We make them opposite for backward compatibility
// since JAXP 1.0 apps may want to receive xmlns* attributes.
- xmlReader.setFeature(Constants.SAX_FEATURE_PREFIX +
- Constants.NAMESPACE_PREFIXES_FEATURE,
- !spf.isNamespaceAware());
+ xmlReader.setFeature(NAMESPACE_PREFIXES_FEATURE, !spf.isNamespaceAware());
+
+ // Avoid setting the XInclude processing feature if the value is false.
+ // This will keep the configuration from throwing an exception if it
+ // does not support XInclude.
+ if (spf.isXIncludeAware()) {
+ xmlReader.setFeature(XINCLUDE_FEATURE, true);
+ }
+
+ this.grammar = spf.getSchema();
setFeatures(features);
}
@@ -121,21 +147,34 @@
public boolean isNamespaceAware() {
try {
- return xmlReader.getFeature(Constants.SAX_FEATURE_PREFIX +
- Constants.NAMESPACES_FEATURE);
- } catch (SAXException x) {
+ return xmlReader.getFeature(NAMESPACES_FEATURE);
+ }
+ catch (SAXException x) {
throw new IllegalStateException(x.getMessage());
}
}
public boolean isValidating() {
try {
- return xmlReader.getFeature(Constants.SAX_FEATURE_PREFIX +
- Constants.VALIDATION_FEATURE);
- } catch (SAXException x) {
+ return xmlReader.getFeature(VALIDATION_FEATURE);
+ }
+ catch (SAXException x) {
throw new IllegalStateException(x.getMessage());
}
}
+
+ /**
+ * Gets the XInclude processing mode for this parser
+ * @return the state of XInclude processing mode
+ */
+ public boolean isXIncludeAware() {
+ try {
+ return xmlReader.getFeature(XINCLUDE_FEATURE);
+ }
+ catch (SAXException exc) {
+ return false;
+ }
+ }
/**
* Sets the particular property in the underlying implementation of
@@ -150,9 +189,7 @@
//None of the properties will take effect till the setValidating(true) has been called
if( isValidating() ) {
schemaLanguage = W3C_XML_SCHEMA;
- xmlReader.setFeature(Constants.XERCES_FEATURE_PREFIX +
- Constants.SCHEMA_VALIDATION_FEATURE,
- true);
+ xmlReader.setFeature(XMLSCHEMA_VALIDATION_FEATURE, true);
// this will allow the parser not to emit DTD-related
// errors, as the spec demands
xmlReader.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
@@ -160,9 +197,7 @@
} else if (value == null) {
schemaLanguage = null;
- xmlReader.setFeature(Constants.XERCES_FEATURE_PREFIX +
- Constants.SCHEMA_VALIDATION_FEATURE,
- false);
+ xmlReader.setFeature(XMLSCHEMA_VALIDATION_FEATURE, false);
} else {
// REVISIT: It would be nice if we could format this message
// using a user specified locale as we do in the underlying
@@ -203,6 +238,13 @@
}
}
+ public Schema getSchema() {
+ return grammar;
+ }
+
+ // TODO: Add in implementation.
+ public void reset() {}
+
/*
* PSVIProvider methods
*/
1.26 +82 -28 xml-xerces/java/src/org/apache/xerces/jaxp/DocumentBuilderImpl.java
Index: DocumentBuilderImpl.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/jaxp/DocumentBuilderImpl.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- DocumentBuilderImpl.java 8 Aug 2004 21:24:10 -0000 1.25
+++ DocumentBuilderImpl.java 10 Jun 2005 02:38:18 -0000 1.26
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation.
+ * Copyright 2000-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.validation.Schema;
import org.apache.xerces.dom.DOMImplementationImpl;
import org.apache.xerces.dom.DOMMessageFormatter;
@@ -44,7 +45,40 @@
public class DocumentBuilderImpl extends DocumentBuilder
implements JAXPConstants
{
+ /** Feature identifier: namespaces. */
+ private static final String NAMESPACES_FEATURE =
+ Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE;
+
+ /** Feature identifier: include ignorable white space. */
+ private static final String INCLUDE_IGNORABLE_WHITESPACE =
+ Constants.XERCES_FEATURE_PREFIX + Constants.INCLUDE_IGNORABLE_WHITESPACE;
+
+ /** Feature identifier: create entiry ref nodes feature. */
+ private static final String CREATE_ENTITY_REF_NODES_FEATURE =
+ Constants.XERCES_FEATURE_PREFIX + Constants.CREATE_ENTITY_REF_NODES_FEATURE;
+
+ /** Feature identifier: include comments feature. */
+ private static final String INCLUDE_COMMENTS_FEATURE =
+ Constants.XERCES_FEATURE_PREFIX + Constants.INCLUDE_COMMENTS_FEATURE;
+
+ /** Feature identifier: create cdata nodes feature. */
+ private static final String CREATE_CDATA_NODES_FEATURE =
+ Constants.XERCES_FEATURE_PREFIX + Constants.CREATE_CDATA_NODES_FEATURE;
+
+ /** Feature identifier: XInclude processing */
+ private static final String XINCLUDE_FEATURE =
+ Constants.XERCES_FEATURE_PREFIX + Constants.XINCLUDE_FEATURE;
+
+ /** feature identifier: XML Schema validation */
+ private static final String XMLSCHEMA_VALIDATION_FEATURE =
+ Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE;
+
+ /** Feature identifier: validation */
+ private static final String VALIDATION_FEATURE =
+ Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE;
+
private DOMParser domParser = null;
+ private final Schema grammar;
DocumentBuilderImpl(DocumentBuilderFactory dbf, Hashtable dbfAttrs)
throws SAXNotRecognizedException, SAXNotSupportedException
@@ -58,27 +92,29 @@
setErrorHandler(new DefaultValidationErrorHandler());
}
- domParser.setFeature(Constants.SAX_FEATURE_PREFIX +
- Constants.VALIDATION_FEATURE, dbf.isValidating());
+ domParser.setFeature(VALIDATION_FEATURE, dbf.isValidating());
// "namespaceAware" == SAX Namespaces feature
- domParser.setFeature(Constants.SAX_FEATURE_PREFIX +
- Constants.NAMESPACES_FEATURE,
- dbf.isNamespaceAware());
+ domParser.setFeature(NAMESPACES_FEATURE, dbf.isNamespaceAware());
// Set various parameters obtained from DocumentBuilderFactory
- domParser.setFeature(Constants.XERCES_FEATURE_PREFIX +
- Constants.INCLUDE_IGNORABLE_WHITESPACE,
- !dbf.isIgnoringElementContentWhitespace());
- domParser.setFeature(Constants.XERCES_FEATURE_PREFIX +
- Constants.CREATE_ENTITY_REF_NODES_FEATURE,
- !dbf.isExpandEntityReferences());
- domParser.setFeature(Constants.XERCES_FEATURE_PREFIX +
- Constants.INCLUDE_COMMENTS_FEATURE,
- !dbf.isIgnoringComments());
- domParser.setFeature(Constants.XERCES_FEATURE_PREFIX +
- Constants.CREATE_CDATA_NODES_FEATURE,
- !dbf.isCoalescing());
+ domParser.setFeature(INCLUDE_IGNORABLE_WHITESPACE,
+ !dbf.isIgnoringElementContentWhitespace());
+ domParser.setFeature(CREATE_ENTITY_REF_NODES_FEATURE,
+ !dbf.isExpandEntityReferences());
+ domParser.setFeature(INCLUDE_COMMENTS_FEATURE,
+ !dbf.isIgnoringComments());
+ domParser.setFeature(CREATE_CDATA_NODES_FEATURE,
+ !dbf.isCoalescing());
+
+ // Avoid setting the XInclude processing feature if the value is false.
+ // This will keep the configuration from throwing an exception if it
+ // does not support XInclude.
+ if (dbf.isXIncludeAware()) {
+ domParser.setFeature(XINCLUDE_FEATURE, true);
+ }
+
+ this.grammar = dbf.getSchema();
setDocumentBuilderFactoryAttributes(dbfAttrs);
}
@@ -111,9 +147,7 @@
//None of the properties will take effect till the setValidating(true) has been called
if ( W3C_XML_SCHEMA.equals(val) ) {
if( isValidating() ) {
- domParser.setFeature(
- Constants.XERCES_FEATURE_PREFIX +
- Constants.SCHEMA_VALIDATION_FEATURE, true);
+ domParser.setFeature(XMLSCHEMA_VALIDATION_FEATURE, true);
// this should allow us not to emit DTD errors, as expected by the
// spec when schema validation is enabled
domParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
@@ -164,21 +198,34 @@
public boolean isNamespaceAware() {
try {
- return domParser.getFeature(Constants.SAX_FEATURE_PREFIX +
- Constants.NAMESPACES_FEATURE);
- } catch (SAXException x) {
+ return domParser.getFeature(NAMESPACES_FEATURE);
+ }
+ catch (SAXException x) {
throw new IllegalStateException(x.getMessage());
}
}
public boolean isValidating() {
try {
- return domParser.getFeature(Constants.SAX_FEATURE_PREFIX +
- Constants.VALIDATION_FEATURE);
- } catch (SAXException x) {
+ return domParser.getFeature(VALIDATION_FEATURE);
+ }
+ catch (SAXException x) {
throw new IllegalStateException(x.getMessage());
}
}
+
+ /**
+ * Gets the XInclude processing mode for this parser
+ * @return the state of XInclude processing mode
+ */
+ public boolean isXIncludeAware() {
+ try {
+ return domParser.getFeature(XINCLUDE_FEATURE);
+ }
+ catch (SAXException exc) {
+ return false;
+ }
+ }
public void setEntityResolver(EntityResolver er) {
domParser.setEntityResolver(er);
@@ -187,6 +234,13 @@
public void setErrorHandler(ErrorHandler eh) {
domParser.setErrorHandler(eh);
}
+
+ public Schema getSchema() {
+ return grammar;
+ }
+
+ // TODO: Add in implementation.
+ public void reset() {}
// package private
DOMParser getDOMParser() {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org