cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dles...@apache.org
Subject cvs commit: xml-stylebook/src/org/apache/stylebook/parsers XercesParser.java
Date Tue, 22 Jan 2002 18:24:53 GMT
dleslie     02/01/22 10:24:53

  Modified:    src/org/apache/stylebook/parsers XercesParser.java
  Log:
  Use JAXP DocumentBuilder to parse XML documents and return a
  Document.
  
  Revision  Changes    Path
  1.8       +31 -36    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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XercesParser.java	16 Jan 2002 15:59:05 -0000	1.7
  +++ XercesParser.java	22 Jan 2002 18:24:53 -0000	1.8
  @@ -12,20 +12,17 @@
   import org.apache.stylebook.Parser;
   import org.apache.stylebook.CreationException;
   import org.apache.xerces.dom.DocumentImpl;
  -import org.apache.xerces.parsers.DOMParser;
  +
   import org.xml.sax.ErrorHandler;
   import org.xml.sax.InputSource;
  +import org.xml.sax.SAXNotRecognizedException;
   import org.xml.sax.SAXException;
   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;
  +import javax.xml.parsers.DocumentBuilderFactory;
  +import javax.xml.parsers.DocumentBuilder;
  +import javax.xml.parsers.ParserConfigurationException;
   
   /**
    *
  @@ -33,18 +30,20 @@
    * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
    * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
    *         Software Foundation</a>. All rights reserved.
  - * @version CVS $Revision: 1.7 $ $Date: 2002/01/16 15:59:05 $
  + * @version CVS $Revision: 1.8 $ $Date: 2002/01/22 18:24:53 $
    */
   public class XercesParser extends AbstractParser implements Parser,ErrorHandler {
  -  TransformerFactory tFactory;
  -
  +  DocumentBuilderFactory docFactory;
  +  
     /**
  -   * 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).
  +   * Instantiate a DocumentBuilderFactory.
      */
  -  public XercesParser(){
  -   	tFactory = TransformerFactory.newInstance();
  -  }
  +  public XercesParser()
  +  {
  +    docFactory = DocumentBuilderFactory.newInstance();
  +    docFactory.setNamespaceAware(true);
  +    docFactory.setExpandEntityReferences(true);
  +  }  
   
   
       /**
  @@ -60,28 +59,24 @@
       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 (TransformerConfigurationException e) {
  +          DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
  +          Document document = docBuilder.parse(in);
  +
  +          if (document==null) {
  +              throw new CreationException("Cannot retrieve parsed document");
  +          } else return(document);
  +        } catch (IOException e) {
  +          this.log(e.getMessage());
  +          throw new CreationException("IOException caught while using DocumentBuilder to
parse an XML document.",e);
  +        } catch (ParserConfigurationException e) {
  +          this.log(e.getMessage());
  +          throw new CreationException("ParserConfigurationException caught while using
DocumentBuilder to parse an XML document.",e);
  +        } catch (SAXNotRecognizedException e) {
               this.log(e.getMessage());
  -            throw new CreationException("TransformerConfigurationException caught while
performing identity transform.",e);            
  -        } catch (TransformerException e) {
  +            throw new CreationException("SAXNotRecognizedException caught while using DocumentBuilder
to parse an XML document.",e);
  +        } catch (SAXException e) {
               this.log(e.getMessage());
  -            throw new CreationException("TransformerException caught while performing identity
transform.",e);
  +            throw new CreationException("SAXException caught using DocumentBuilder to parse
an XML document.",e);
           }
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Mime
View raw message