You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by sa...@apache.org on 2002/04/08 18:18:39 UTC

cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/trax SAX2DOM.java

santiagopg    02/04/08 09:18:39

  Modified:    java/src/org/apache/xalan/xsltc/trax SAX2DOM.java
  Log:
  Add support for user-specified root node.
  
  Revision  Changes    Path
  1.9       +15 -15    xml-xalan/java/src/org/apache/xalan/xsltc/trax/SAX2DOM.java
  
  Index: SAX2DOM.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/SAX2DOM.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- SAX2DOM.java	2 Apr 2002 23:50:25 -0000	1.8
  +++ SAX2DOM.java	8 Apr 2002 16:18:39 -0000	1.9
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: SAX2DOM.java,v 1.8 2002/04/02 23:50:25 santiagopg Exp $
  + * @(#)$Id: SAX2DOM.java,v 1.9 2002/04/08 16:18:39 santiagopg Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -82,35 +82,35 @@
   
   class SAX2DOM implements ContentHandler, Constants {
   
  -    private Stack _nodeStk = null;
  -    private Document _document = null;
  -    private DocumentBuilder _builder = null;
  - 
  +    private Document _root = null;
  +    private Stack _nodeStk = new Stack();
       private Vector _namespaceDecls = null;
   
       public SAX2DOM() throws ParserConfigurationException {
  -	DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  -	_builder = factory.newDocumentBuilder();
  -	_nodeStk = new Stack();
  +	final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  +	_root = factory.newDocumentBuilder().newDocument();
  +    }
  +
  +    public SAX2DOM(Node root) throws ParserConfigurationException {
  +	_root = (Document) root;   // TODO: add support for frags and elems
       }
   
       public Node getDOM() {
  -	return _document;
  +	return _root;
       }
   
       public void characters(char[] ch, int start, int length) {
   	final Node last = (Node)_nodeStk.peek();
  -	final String text = new String(ch, start, length);
   
   	// No text nodes can be children of root (DOM006 exception)
  -	if (last != _document) {
  -	    last.appendChild(_document.createTextNode(text));
  +	if (last != _root) {
  +	    final String text = new String(ch, start, length);
  +	    last.appendChild(_root.createTextNode(text));
   	}
       }
   
       public void startDocument() {
  -	_document = _builder.newDocument();
  -	_nodeStk.push(_document);
  +	_nodeStk.push(_root);
       }
   
       public void endDocument() {
  @@ -119,7 +119,7 @@
       public void startElement(String namespace, String localName, String qName,
   	Attributes attrs) 
       {
  -	final Element tmp = (Element)_document.createElementNS(namespace, qName);
  +	final Element tmp = (Element)_root.createElementNS(namespace, qName);
   
   	// Add namespace declarations first
   	if (_namespaceDecls != null) {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org