You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by dl...@apache.org on 2002/01/16 16:59:05 UTC
cvs commit: xml-stylebook/src/org/apache/stylebook/parsers XercesParser.java
dleslie 02/01/16 07:59:05
Modified: src/org/apache/stylebook/parsers XercesParser.java
Log:
Replaced DOMParser with an identity transormation to produce
input DOM objects.
This change required to sidestep a problem that appears with
Xerces-J2beta4 and the JAVAX 1.1 DocumentBuilder. Works
with Xerces-J1.44, Xerces-J2beta4, and presumably Crimson.
Revision Changes Path
1.7 +32 -3 xml-stylebook/src/org/apache/stylebook/parsers/XercesParser.java
Index: XercesParser.java
===================================================================
RCS file: /home/cvs/xml-stylebook/src/org/apache/stylebook/parsers/XercesParser.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XercesParser.java 1 Dec 1999 02:04:52 -0000 1.6
+++ XercesParser.java 16 Jan 2002 15:59:05 -0000 1.7
@@ -19,15 +19,34 @@
import org.xml.sax.SAXParseException;
import org.w3c.dom.Document;
+// Imported TraX classes
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.dom.DOMResult;
+
/**
*
*
* @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
* @author Copyright 1999 © <a href="http://www.apache.org">The Apache
* Software Foundation</a>. All rights reserved.
- * @version CVS $Revision: 1.6 $ $Date: 1999/12/01 02:04:52 $
+ * @version CVS $Revision: 1.7 $ $Date: 2002/01/16 15:59:05 $
*/
public class XercesParser extends AbstractParser implements Parser,ErrorHandler {
+ TransformerFactory tFactory;
+
+ /**
+ * Instantiate a TrasformerFactory to produce Transformers for identity transformations
+ * (to get around a Xerces-J2 problem parsing the input from a URL with the sbk: protocol).
+ */
+ public XercesParser(){
+ tFactory = TransformerFactory.newInstance();
+ }
+
+
/**
* Parse the specified InputSource.
*
@@ -41,18 +60,28 @@
throws IOException, CreationException {
this.debug("Parsing \""+in.getSystemId()+"\"");
try {
+/* replaced with the identity transform that follows -- Don Leslie 1/16/2002
DOMParser p=new DOMParser();
p.setFeature("http://apache.org/xml/features/dom/create-entity-ref-nodes",false);
p.setFeature("http://apache.org/xml/features/validation/dynamic",true);
p.setErrorHandler(this);
p.parse(in);
Document document=p.getDocument();
+*/
+ Transformer transformer = tFactory.newTransformer();
+ DOMResult domres = new DOMResult();
+ transformer.transform(new SAXSource(in), domres);
+ Document document = (Document)domres.getNode();
+
if (document==null) {
throw new CreationException("Cannot retrieve parsed document");
} else return(document);
- } catch (SAXException e) {
+ } catch (TransformerConfigurationException e) {
this.log(e.getMessage());
- throw new CreationException("SAXException caught while parsing",e);
+ throw new CreationException("TransformerConfigurationException caught while performing identity transform.",e);
+ } catch (TransformerException e) {
+ this.log(e.getMessage());
+ throw new CreationException("TransformerException caught while performing identity transform.",e);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org