Author: mrglavas
Date: Thu Aug 31 12:18:44 2006
New Revision: 439017
URL: http://svn.apache.org/viewvc?rev=439017&view=rev
Log:
It was possible for an application to set features on the SAXParserFactory
which have values that are inconsistent with the factory built-in settings.
This might mean the value they set gets ignored because the other instance
of the setting overwrites the first when the SAXParser is initially
configured. The features and built-in settings are now kept in synch. This
may also improve performance for some applications since we're not always
creating a new parser to test whether a feature is recognized by the factory.
Modified:
xerces/java/trunk/src/org/apache/xerces/jaxp/SAXParserFactoryImpl.java
Modified: xerces/java/trunk/src/org/apache/xerces/jaxp/SAXParserFactoryImpl.java
URL:
http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/jaxp/SAXParserFactoryImpl.java?rev=439017&r1=439016&r2=439017&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/jaxp/SAXParserFactoryImpl.java
(original)
+++ xerces/java/trunk/src/org/apache/xerces/jaxp/SAXParserFactoryImpl.java Thu
Aug 31 12:18:44 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2002,2004,2005 The Apache Software Foundation.
+ * Copyright 2000-2002,2004-2006 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.
@@ -24,6 +24,7 @@
import javax.xml.parsers.SAXParserFactory;
import javax.xml.validation.Schema;
+import org.apache.xerces.impl.Constants;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
@@ -39,6 +40,19 @@
* @version $Id$
*/
public class SAXParserFactoryImpl extends SAXParserFactory {
+
+ /** Feature identifier: namespaces. */
+ private static final String NAMESPACES_FEATURE =
+ Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE;
+
+ /** Feature identifier: validation. */
+ private static final String VALIDATION_FEATURE =
+ Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE;
+
+ /** Feature identifier: XInclude processing */
+ private static final String XINCLUDE_FEATURE =
+ Constants.XERCES_FEATURE_PREFIX + Constants.XINCLUDE_FEATURE;
+
private Hashtable features;
private Schema grammar;
private boolean isXIncludeAware;
@@ -54,16 +68,17 @@
* @return javax.xml.parsers.SAXParser
*/
public SAXParser newSAXParser()
- throws ParserConfigurationException
- {
+ throws ParserConfigurationException {
+
SAXParser saxParserImpl;
try {
saxParserImpl = new SAXParserImpl(this, features, fSecureProcess);
- } catch (SAXException se) {
+ }
+ catch (SAXException se) {
// Translate to ParserConfigurationException
throw new ParserConfigurationException(se.getMessage());
}
- return saxParserImpl;
+ return saxParserImpl;
}
/**
@@ -71,8 +86,8 @@
*/
private SAXParserImpl newSAXParserImpl()
throws ParserConfigurationException, SAXNotRecognizedException,
- SAXNotSupportedException
- {
+ SAXNotSupportedException {
+
SAXParserImpl saxParserImpl;
try {
saxParserImpl = new SAXParserImpl(this, features);
@@ -101,6 +116,19 @@
fSecureProcess = value;
return;
}
+ // Keep built-in settings in synch with the feature values.
+ else if (name.equals(NAMESPACES_FEATURE)) {
+ setNamespaceAware(value);
+ return;
+ }
+ else if (name.equals(VALIDATION_FEATURE)) {
+ setValidating(value);
+ return;
+ }
+ else if (name.equals(XINCLUDE_FEATURE)) {
+ setXIncludeAware(value);
+ return;
+ }
// XXX This is ugly. We have to collect the features and then
// later create an XMLReader to verify the features.
@@ -112,10 +140,12 @@
// Test the feature by possibly throwing SAX exceptions
try {
newSAXParserImpl();
- } catch (SAXNotSupportedException e) {
+ }
+ catch (SAXNotSupportedException e) {
features.remove(name);
throw e;
- } catch (SAXNotRecognizedException e) {
+ }
+ catch (SAXNotRecognizedException e) {
features.remove(name);
throw e;
}
@@ -133,6 +163,15 @@
}
if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
return fSecureProcess;
+ }
+ else if (name.equals(NAMESPACES_FEATURE)) {
+ return isNamespaceAware();
+ }
+ else if (name.equals(VALIDATION_FEATURE)) {
+ return isValidating();
+ }
+ else if (name.equals(XINCLUDE_FEATURE)) {
+ return isXIncludeAware();
}
// Check for valid name by creating a dummy XMLReader to get
// feature value
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]