ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maart...@apache.org
Subject svn commit: r1055217 - /ant/ivy/core/trunk/src/java/org/apache/ivy/util/XMLHelper.java
Date Tue, 04 Jan 2011 22:36:11 GMT
Author: maartenc
Date: Tue Jan  4 22:36:10 2011
New Revision: 1055217

URL: http://svn.apache.org/viewvc?rev=1055217&view=rev
Log:
The created SAXParser is now always namespace aware.

Modified:
    ant/ivy/core/trunk/src/java/org/apache/ivy/util/XMLHelper.java

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/util/XMLHelper.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/util/XMLHelper.java?rev=1055217&r1=1055216&r2=1055217&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/util/XMLHelper.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/util/XMLHelper.java Tue Jan  4 22:36:10 2011
@@ -54,25 +54,27 @@ public abstract class XMLHelper {
     
     private static SAXParser newSAXParser(URL schema, InputStream schemaStream)
             throws ParserConfigurationException, SAXException {
-        if (!canUseSchemaValidation || schema == null) {
-            return SAXParserFactory.newInstance().newSAXParser();
-        }
-        try {
-            SAXParserFactory parserFactory = SAXParserFactory.newInstance();
-            parserFactory.setNamespaceAware(true);
-            parserFactory.setValidating(true);
-            SAXParser parser = parserFactory.newSAXParser();
-            parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
-            parser.setProperty(JAXP_SCHEMA_SOURCE, schemaStream);
-            parser.getXMLReader().setFeature(XML_NAMESPACE_PREFIXES, true);
-            return parser;
-        } catch (SAXNotRecognizedException ex) {
-            System.err.println(
-                "WARNING: problem while setting JAXP validating property on SAXParser...
"
-                + "XML validation will not be done: " + ex.getMessage());
-            canUseSchemaValidation = false;
-            return SAXParserFactory.newInstance().newSAXParser();
+        SAXParserFactory parserFactory = SAXParserFactory.newInstance();
+        parserFactory.setNamespaceAware(true);
+        parserFactory.setValidating(canUseSchemaValidation && (schema != null));
+        SAXParser parser = parserFactory.newSAXParser();
+        
+        if (canUseSchemaValidation && (schema != null)) {
+            try {
+                parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
+                parser.setProperty(JAXP_SCHEMA_SOURCE, schemaStream);
+            } catch (SAXNotRecognizedException ex) {
+                System.err.println(
+                    "WARNING: problem while setting JAXP validating property on SAXParser...
"
+                    + "XML validation will not be done: " + ex.getMessage());
+                canUseSchemaValidation = false;
+                parserFactory.setValidating(false);
+                parser = parserFactory.newSAXParser();
+            }
         }
+        
+        parser.getXMLReader().setFeature(XML_NAMESPACE_PREFIXES, true);
+        return parser;
     }
 
     // IMPORTANT: validation errors are only notified to the given handler, and



Mime
View raw message