public synchronized void render(InputHandler inputHandler)
throws FOPException {
XMLReader parser = inputHandler.getParser();
- inputHandler.setParserFeatures(parser);
render(parser, inputHandler.getInputSource());
}
if (reader == null) {
if (!(source instanceof DocumentInputSource)) {
- try {
- SAXParserFactory spf = javax.xml.parsers.SAXParserFactory.newInstance();
- spf.setNamespaceAware(true);
- reader = spf.newSAXParser().getXMLReader();
- } catch (SAXException e) {
- throw new FOPException(e);
- } catch (ParserConfigurationException e) {
- throw new FOPException(e);
- }
+ //TODO: (gm) rename to FOFileHandler or similar
+ reader = org.apache.fop.apps.FOInputHandler.createParser();
}
}
render(reader, source);
}
}
-
}
// Imported SAX classes
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotSupportedException;
// java
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.net.URL;
+
/**
* Manages input if it is an XSL-FO file.
*/
* @see org.apache.fop.apps.InputHandler#getParser()
*/
public XMLReader getParser() throws FOPException {
- return super.createParser();
+ return createParser();
}
/**
throw new FOPException("not implemented: FOInputHandler.run(Driver)");
}
+ /**
+ * Creates <code>XMLReader</code> object using default
+ * <code>SAXParserFactory</code>
+ * @return the created <code>XMLReader</code>
+ * @throws FOPException if the parser couldn't be created or configured for proper operation.
+ */
+ protected static XMLReader createParser() throws FOPException {
+ try {
+ SAXParserFactory factory = SAXParserFactory.newInstance();
+ factory.setNamespaceAware(true);
+ factory.setFeature(
+ "http://xml.org/sax/features/namespace-prefixes", true);
+ return factory.newSAXParser().getXMLReader();
+ } catch (SAXNotSupportedException se) {
+ throw new FOPException("Error: You need a parser which allows the"
+ + " http://xml.org/sax/features/namespace-prefixes"
+ + " feature to be set to true to support namespaces", se);
+ } catch (SAXException se) {
+ throw new FOPException("Couldn't create XMLReader", se);
+ } catch (ParserConfigurationException pce) {
+ throw new FOPException("Couldn't create XMLReader", pce);
+ }
+ }
}
throw new Error("unexpected MalformedURLException");
}
}
-
- /**
- * Creates <code>XMLReader</code> object using default
- * <code>SAXParserFactory</code>
- * @return the created <code>XMLReader</code>
- * @throws FOPException if the parser couldn't be created or configured for proper operation.
- */
- protected static XMLReader createParser() throws FOPException {
- try {
- 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);
- }
- }
/**
* Runs this InputHandler through the Driver.
* @throws FOPException if processing this InputHandler fails
*/
public abstract void run(Driver driver) throws FOPException;
-
- /**
- * Sets the parser features on an XMLReader
- * @param parser XMLReader to set features on
- * @throws FOPException if the XMLReader doesn't support the feature that
- * need to be set
- */
- public static void setParserFeatures(XMLReader parser) throws FOPException {
- try {
- parser.setFeature("http://xml.org/sax/features/namespace-prefixes",
- true);
- } catch (SAXException e) {
- throw new FOPException("Error: You need a parser which allows the"
- + " http://xml.org/sax/features/namespace-prefixes"
- + " feature to be set to true to support namespaces", e);
- }
- }
}
saxTFactory.newXMLFilter(xsltSource);
// Create an XMLReader.
- XMLReader parser = createParser();
+ XMLReader parser = FOInputHandler.createParser();
if (parser == null) {
throw new FOPException("Unable to create SAX parser");
}