Author: skitching
Date: Mon Mar 13 17:35:05 2006
New Revision: 385705
URL: http://svn.apache.org/viewcvs?rev=385705&view=rev
Log:
Fix for problem where SAXNotRecognisedException was being thrown when validation is enabled
(Digester.setValidating(true)) and Xerces is in the classpath BUT IS NOT the actual XML
parser being used. See bugzilla#38894.
This fix avoids using ParserFeatureSetterFactory just to enable validating; that can be
done in a more portable way.
There is still a bug in ParserFeatureSetterFactory to fix - the incorrect detection of
the underlying parser.
Modified:
jakarta/commons/proper/digester/trunk/src/java/org/apache/commons/digester/Digester.java
Modified: jakarta/commons/proper/digester/trunk/src/java/org/apache/commons/digester/Digester.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/digester/trunk/src/java/org/apache/commons/digester/Digester.java?rev=385705&r1=385704&r2=385705&view=diff
==============================================================================
--- jakarta/commons/proper/digester/trunk/src/java/org/apache/commons/digester/Digester.java
(original)
+++ jakarta/commons/proper/digester/trunk/src/java/org/apache/commons/digester/Digester.java
Mon Mar 13 17:35:05 2006
@@ -685,14 +685,25 @@
// Create a new parser
try {
- if (validating) {
+ if (validating && (schemaLocation != null)) {
+ // There is no portable way to specify the location of
+ // an xml schema to be applied to the input document, so
+ // we have to use parser-specific code for this. That code
+ // is hidden behind the ParserFeatureSetterFactory class.
+
Properties properties = new Properties();
properties.put("SAXParserFactory", getFactory());
if (schemaLocation != null) {
properties.put("schemaLocation", schemaLocation);
properties.put("schemaLanguage", schemaLanguage);
}
- parser = ParserFeatureSetterFactory.newSAXParser(properties);
} else {
+ parser = ParserFeatureSetterFactory.newSAXParser(properties);
+ } else {
+ // The user doesn't want to use any non-portable parsing features,
+ // so we can just use the portable API here. Note that method
+ // getFactory returns a factory already configured with the
+ // appropriate namespaceAware and validating properties.
+
parser = getFactory().newSAXParser();
}
} catch (Exception e) {
@@ -808,7 +819,24 @@
/**
- * Set the XML Schema URI used for validating a XML Instance.
+ * Set the XML Schema URI used for validating the input XML.
+ * <p>
+ * It is often desirable to <i>force</i> the input document to be
+ * validated against a particular schema regardless of what type
+ * the input document declares itself to be. This method allows that
+ * to be done.
+ * <p>
+ * Note, however, that there is no standard API for enabling this
+ * feature on the underlying SAX parser; this method therefore only works
+ * for those parsers explicitly supported by Digester's
+ * ParserFeatureSetterFactory class. If the underlying parser does not
+ * support the feature, or is not one of the supported parsers, then
+ * an exception will be thrown when getParser is called (explicitly,
+ * or implicitly via the parse method).
+ * <p>
+ * See also method setSchemaLanguage which allows the type of the schema
+ * specified here to be defined. By default, the schema is expected to
+ * be a W3C xml schema definition.
*
* @param schemaLocation a URI to the schema.
*/
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
|