import java.io.InputStream;
import java.net.URL;
+import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;
import org.aspectj.util.LangUtil;
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
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);
}
}
+ 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;