On 11/25/01 7:50 PM, "Sam Ruby" <[EMAIL PROTECTED]> wrote:

> Now that Xerces 2 is in it's third beta, perhaps it is time for Turbine to
> consider pluggable parsers?  I took a stab at converting torque over to
> JAXP... diffs below.  Should work with both Xerces 1 and 2, and perhaps
> even Crimson.
> 
> It looks like virtual clones of these source files are also present in
> turbine-2, so similar techniques should work there too.

I've made a little XML->Object mapper  using dom4j which can use whatever
parser you like so that we're not hooked directly into xerces. A
jakarta-turbine-stratum repository will be appearing shortly. It contains
the mapper that I've been talking about on the commons list.
 
> Note: gump's nightly nags are still based on Xerces 1 at the moment.  If
> you want a sneak peek at what builds under Xerces 2 will look like, check
> out http://nagoya.apache.org/~rubys/gump/xerces2/index.html
> 
> - Sam Ruby
> 
> Index: XmlToAppData.java
> ===================================================================
> RCS file: 
> /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/engine/database/tr
> ansform/XmlToAppData.java,v
> retrieving revision 1.8
> diff -u -r1.8 XmlToAppData.java
> --- XmlToAppData.java    2001/09/29 01:46:30  1.8
> +++ XmlToAppData.java    2001/11/26 00:25:24
> @@ -73,8 +73,9 @@
> import org.apache.torque.engine.database.model.Table;
> import org.apache.torque.engine.database.model.Unique;
> 
> -import org.apache.xerces.framework.XMLParser;
> -import org.apache.xerces.parsers.SAXParser;
> +import javax.xml.parsers.ParserConfigurationException;
> +import javax.xml.parsers.SAXParser;
> +import javax.xml.parsers.SAXParserFactory;
> 
> import org.xml.sax.Attributes;
> import org.xml.sax.ContentHandler;
> @@ -114,6 +115,13 @@
>    private Table foreignTable;
>    private String errorMessage;
> 
> +    private static SAXParserFactory saxFactory;
> +
> +    static {
> +        saxFactory = SAXParserFactory.newInstance();
> +        saxFactory.setValidating(true);
> +    }
> +
>    /**
>     * Creates a new instance.
>     */
> @@ -163,7 +171,7 @@
>            try
>            {
>                InputSource is = new InputSource (br);
> -                parser.parse(is);
> +                parser.parse(is, this);
>            }
>            finally
>            {
> @@ -189,23 +197,17 @@
>     * @return A validating XML parser.
>     */
>    protected SAXParser createParser()
> -        throws SAXNotRecognizedException, SAXNotSupportedException
> +        throws SAXException, ParserConfigurationException
>    {
> -        SAXParser parser = new SAXParser();
> +        SAXParser parser = saxFactory.newSAXParser();
> 
>        // We don't use an external handlers, instead implementing
>        // handler interfaces ourself.
> -        parser.setContentHandler(this);
> -        parser.setErrorHandler(this);
> +        parser.getParser().setErrorHandler(this);
> 
>        // Set the Resolver for the Torque's DTD.
>        DTDResolver dtdResolver = new DTDResolver();
> -        parser.setEntityResolver(dtdResolver);
> -
> -        // Validate the input file
> -        parser.setFeature
> -            ("http://apache.org/xml/features/validation/dynamic";, true);
> -        parser.setFeature("http://xml.org/sax/features/validation";, true);
> +        parser.getParser().setEntityResolver(dtdResolver);
> 
>        return parser;
>    }
> Index: XmlToData.java
> ===================================================================
> RCS file: 
> /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/engine/database/tr
> ansform/XmlToData.java,v
> retrieving revision 1.1.1.1
> diff -u -r1.1.1.1 XmlToData.java
> --- XmlToData.java  2001/08/02 05:08:33  1.1.1.1
> +++ XmlToData.java  2001/11/26 00:25:24
> @@ -65,11 +65,14 @@
> import java.net.URL;
> import java.util.List;
> import java.util.Vector;
> +
> +import javax.xml.parsers.ParserConfigurationException;
> +import javax.xml.parsers.SAXParser;
> +import javax.xml.parsers.SAXParserFactory;
> +
> import org.apache.torque.engine.database.model.Column;
> import org.apache.torque.engine.database.model.Database;
> import org.apache.torque.engine.database.model.Table;
> -import org.apache.xerces.framework.XMLParser;
> -import org.apache.xerces.parsers.SAXParser;
> import org.xml.sax.Attributes;
> import org.xml.sax.ContentHandler;
> import org.xml.sax.EntityResolver;
> @@ -99,6 +102,13 @@
>    private File dtdFile;
>    private InputSource dataDTD;
> 
> +    private static SAXParserFactory saxFactory;
> +
> +    static {
> +        saxFactory = SAXParserFactory.newInstance();
> +        saxFactory.setValidating(true);
> +    }
> +
>    /**
>     * Default custructor
>     */
> @@ -122,27 +132,20 @@
>        {
>            data = new Vector();
> 
> -            SAXParser parser = new SAXParser();
> +            SAXParser parser = saxFactory.newSAXParser();
> 
>            // set the Resolver for the DTD
> -            parser.setEntityResolver(this);
> +            parser.getParser().setEntityResolver(this);
> 
>            // We don't use an external content handler - we use this object
> -            parser.setContentHandler(this);
> -
> -            // Validate the input file
> -            parser.setFeature
> -                ("http://apache.org/xml/features/validation/dynamic";, true);
> -            parser.setFeature("http://xml.org/sax/features/validation";,
> true);
> -
> -            parser.setErrorHandler(this);
> +            parser.getParser().setErrorHandler(this);
> 
>            FileReader fr = new FileReader (xmlFile);
>            BufferedReader br = new BufferedReader (fr);
>            try
>            {
>                InputSource is = new InputSource (br);
> -                parser.parse(is);
> +                parser.parse(is, this);
>            }
>            finally
>            {
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

-- 

jvz.

Jason van Zyl

http://tambora.zenplex.org
http://jakarta.apache.org/turbine
http://jakarta.apache.org/velocity
http://jakarta.apache.org/alexandria
http://jakarta.apache.org/commons



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to