[FOray-commit] SF.net SVN: foray: [7802] trunk/foray/foray-core/src/java/org/foray/core
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2006-07-19 01:54:04
|
Revision: 7802 Author: victormote Date: 2006-07-18 18:53:59 -0700 (Tue, 18 Jul 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7802&view=rev Log Message: ----------- Put the default parser creation inside FOrayDocument. Modified Paths: -------------- trunk/foray/foray-core/src/java/org/foray/core/FOInputHandler.java trunk/foray/foray-core/src/java/org/foray/core/FOrayDocument.java trunk/foray/foray-core/src/java/org/foray/core/InputHandler.java Modified: trunk/foray/foray-core/src/java/org/foray/core/FOInputHandler.java =================================================================== --- trunk/foray/foray-core/src/java/org/foray/core/FOInputHandler.java 2006-07-19 01:53:48 UTC (rev 7801) +++ trunk/foray/foray-core/src/java/org/foray/core/FOInputHandler.java 2006-07-19 01:53:59 UTC (rev 7802) @@ -29,7 +29,6 @@ import org.apache.commons.logging.Log; import org.xml.sax.InputSource; -import org.xml.sax.XMLReader; import java.io.IOException; import java.net.URL; @@ -51,8 +50,4 @@ return inputSource; } - public XMLReader getParser() throws FOrayException { - return super.createParser(); - } - } Modified: trunk/foray/foray-core/src/java/org/foray/core/FOrayDocument.java =================================================================== --- trunk/foray/foray-core/src/java/org/foray/core/FOrayDocument.java 2006-07-19 01:53:48 UTC (rev 7801) +++ trunk/foray/foray-core/src/java/org/foray/core/FOrayDocument.java 2006-07-19 01:53:59 UTC (rev 7802) @@ -48,6 +48,7 @@ import java.net.URL; import java.util.ArrayList; +import javax.xml.parsers.SAXParserFactory; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; @@ -121,12 +122,18 @@ * Standard constructor. Accepts a SAX InputSource as input. * @param session The parent FOraySession. * @param inputSource A SAX InputSource. - * @param parser A SAX parser. + * @param parser A SAX parser. If null is passed, a default parser will be + * provided. + * @throws FOrayException If "null" parser is passed and there is an error + * creating one. */ public FOrayDocument(FOraySession session, InputSource inputSource, - XMLReader parser) { + XMLReader parser) throws FOrayException { this(session); this.inputSource = inputSource; + if (parser == null) { + parser = this.createParser(); + } this.parser = parser; this.parser.setContentHandler(treeBuilder); } @@ -359,4 +366,34 @@ return this.session.getLayoutFactory(); } + /** + * Creates a SAX parser. + * @return The newly-created SAX parser. + */ + XMLReader createParser() throws FOrayException { + SAXParserFactory spf = javax.xml.parsers.SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + XMLReader xmlReader = null; + try { + xmlReader = spf.newSAXParser().getXMLReader(); + } catch (javax.xml.parsers.ParserConfigurationException e) { + throw new FOrayException(e); + } catch (SAXException e) { + throw new FOrayException(e); + } + try { + xmlReader.setFeature( + "http://xml.org/sax/features/namespace-prefixes", true); + } catch (SAXException e) { + throw new FOrayException("Error in setting up parser feature " + + "namespace-prefixes\n" + + "You need a parser which supports SAX version 2", e); + } + if (this.getLogger().isDebugEnabled()) { + this.getLogger().debug("FO Parsing: Using " + + xmlReader.getClass().getName() + " as SAX2 Parser."); + } + return xmlReader; + } + } Modified: trunk/foray/foray-core/src/java/org/foray/core/InputHandler.java =================================================================== --- trunk/foray/foray-core/src/java/org/foray/core/InputHandler.java 2006-07-19 01:53:48 UTC (rev 7801) +++ trunk/foray/foray-core/src/java/org/foray/core/InputHandler.java 2006-07-19 01:53:59 UTC (rev 7802) @@ -29,13 +29,9 @@ import org.apache.commons.logging.Log; import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.XMLReader; import java.io.IOException; -import javax.xml.parsers.SAXParserFactory; - public abstract class InputHandler { Log logger; @@ -45,38 +41,10 @@ } /** - * Creates a SAX parser. - * @return The newly-created SAX parser. - */ - protected XMLReader createParser() throws FOrayException { - SAXParserFactory spf = javax.xml.parsers.SAXParserFactory.newInstance(); - spf.setNamespaceAware(true); - XMLReader xmlReader = null; - try { - xmlReader = spf.newSAXParser().getXMLReader(); - } catch (javax.xml.parsers.ParserConfigurationException e) { - throw new FOrayException(e); - } catch (SAXException e) { - throw new FOrayException(e); - } - if (this.logger.isDebugEnabled()) { - this.logger.debug("FO Parsing: Using " - + xmlReader.getClass().getName() + " as SAX2 Parser."); - } - return xmlReader; - } - - /** * Provides the SAX InputSource. * @return The SAX InputSource for this handler. * @throws IOException */ public abstract InputSource getInputSource() throws IOException ; - /** - * Provides the SAX parser for the SAX InputSource. - * @return The SAX parser for the SAX InputSource. - */ - public abstract XMLReader getParser() throws FOrayException; - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |