]> source.dussan.org Git - aspectj.git/commitdiff
fix for pr116255
authoraclement <aclement>
Tue, 15 Nov 2005 17:04:00 +0000 (17:04 +0000)
committeraclement <aclement>
Tue, 15 Nov 2005 17:04:00 +0000 (17:04 +0000)
loadtime/src/org/aspectj/weaver/loadtime/definition/DocumentParser.java

index 3036367b2aac7830904efa8063579461bd36f4a4..931e26d176a16d5acfac048a93c26ac45e45faca 100644 (file)
@@ -14,6 +14,7 @@ package org.aspectj.weaver.loadtime.definition;
 import java.io.InputStream;
 import java.net.URL;
 
+import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParserFactory;
 
 import org.aspectj.util.LangUtil;
@@ -23,6 +24,7 @@ import org.xml.sax.SAXException;
 import org.xml.sax.SAXParseException;
 import org.xml.sax.XMLReader;
 import org.xml.sax.helpers.DefaultHandler;
+import org.xml.sax.helpers.XMLReaderFactory;
 
 /**
  * FIXME AV - doc, concrete aspect
@@ -73,13 +75,13 @@ public class DocumentParser extends DefaultHandler {
     private DocumentParser() {
         m_definition = new Definition();
     }
-
+    
     public static Definition parse(final URL url) throws Exception {
         InputStream in = null;
         try {
             DocumentParser parser = new DocumentParser();
 
-            XMLReader xmlReader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
+            XMLReader xmlReader = getXMLReader();
             xmlReader.setContentHandler(parser);
             xmlReader.setErrorHandler(parser);
 
@@ -113,6 +115,21 @@ public class DocumentParser extends DefaultHandler {
         }
     }
 
+       private static XMLReader getXMLReader() throws SAXException, ParserConfigurationException {
+               XMLReader xmlReader = null;
+
+               /* Try this first for Java 5 */
+               try {
+                       xmlReader = XMLReaderFactory.createXMLReader();
+               }
+               
+               /* .. and ignore "System property ... not set" and then try this instead */
+               catch (SAXException ex) {
+                       xmlReader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
+               }
+               return xmlReader;
+       }
+
     public InputSource resolveEntity(String publicId, String systemId) throws SAXException {
         if (publicId.equals(DTD_PUBLIC_ID) || publicId.equals(DTD_PUBLIC_ID_ALIAS)) {
             InputStream in = DTD_STREAM;