From: Oleg Tkachenko Date: Mon, 16 Dec 2002 22:01:43 +0000 (+0000) Subject: Modified to use SAXParserFactory instead of loading class by name. X-Git-Tag: Alt-Design-integration-base~243 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=aa9910dbbf6244ffaa1e3b82d20483f7d696ea30;p=xmlgraphics-fop.git Modified to use SAXParserFactory instead of loading class by name. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195772 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/org/apache/fop/apps/InputHandler.java b/src/org/apache/fop/apps/InputHandler.java index 6ce9ffd79..8c0bed8b2 100644 --- a/src/org/apache/fop/apps/InputHandler.java +++ b/src/org/apache/fop/apps/InputHandler.java @@ -10,27 +10,27 @@ package org.apache.fop.apps; // SAX import org.xml.sax.InputSource; import org.xml.sax.XMLReader; +import org.xml.sax.SAXException; // Java +import javax.xml.parsers.SAXParserFactory; +import javax.xml.parsers.ParserConfigurationException; import java.net.URL; import java.io.File; public abstract class InputHandler { - public abstract InputSource getInputSource(); public abstract XMLReader getParser() throws FOPException; - public static InputSource urlInputSource(URL url) { return new InputSource(url.toString()); } /** - * create an InputSource from a File - * - * @param file the File - * @return the InputSource created + * Creates an InputSource from a File + * @param file the File + * @return the InputSource created */ public static InputSource fileInputSource(File file) { /* this code adapted from James Clark's in XT */ @@ -50,29 +50,20 @@ public abstract class InputHandler { } /** - * creates a SAX parser, using the value of org.xml.sax.parser - * defaulting to org.apache.xerces.parsers.SAXParser - * - * @return the created SAX parser + * Creates XMLReader object using default + * SAXParserFactory + * @return the created XMLReader */ protected static XMLReader createParser() throws FOPException { - String parserClassName = Driver.getParserClassName(); - //log.debug("using SAX parser " + parserClassName); - try { - return (XMLReader)Class.forName(parserClassName).newInstance(); - } catch (ClassNotFoundException e) { - throw new FOPException(e); - } catch (InstantiationException e) { - throw new FOPException("Could not instantiate " - + parserClassName, e); - } catch (IllegalAccessException e) { - throw new FOPException("Could not access " + parserClassName, e); - } catch (ClassCastException e) { - throw new FOPException(parserClassName + " is not a SAX driver", - e); + SAXParserFactory factory = SAXParserFactory.newInstance(); + factory.setNamespaceAware(true); + return factory.newSAXParser().getXMLReader(); + } catch (SAXException se) { + throw new FOPException("Coudn't create XMLReader", se); + } catch (ParserConfigurationException pce) { + throw new FOPException("Coudn't create XMLReader", pce); } } - }