You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mk...@apache.org on 2002/09/23 20:41:55 UTC

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

mkwan       2002/09/23 11:41:55

  Modified:    java/src/org/apache/xalan/xsltc/trax SAX2DOM.java
  Log:
  For Bugzilla 12924. In constructor SAX2DOM(Node), the Node might not always
  be a Document. Add additional handling code so that SAX2DOM can work with a
  non-Document root.
  
  Revision  Changes    Path
  1.15      +20 -12    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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- SAX2DOM.java	11 Jun 2002 17:03:49 -0000	1.14
  +++ SAX2DOM.java	23 Sep 2002 18:41:54 -0000	1.15
  @@ -86,24 +86,31 @@
   
   public class SAX2DOM implements ContentHandler, LexicalHandler, Constants {
   
  -    private Document _root = null;
  +    private Node _root = null;
  +    private Document _document = null;
       private Stack _nodeStk = new Stack();
       private Vector _namespaceDecls = null;
   
       public SAX2DOM() throws ParserConfigurationException {
   	final DocumentBuilderFactory factory = 
   		DocumentBuilderFactory.newInstance();
  -	_root = factory.newDocumentBuilder().newDocument();
  +	_document = factory.newDocumentBuilder().newDocument();
  +	_root = _document;
       }
   
       public SAX2DOM(Node root) throws ParserConfigurationException {
  -	if (root != null) {
  -	    _root = (Document) root;   // TODO: add support for frags and elems
  +	_root = root;
  +	if (root instanceof Document) {
  +	  _document = (Document)root;
  +	}
  +	else if (root != null) {
  +	  _document = root.getOwnerDocument();
   	}
   	else {
  -	    final DocumentBuilderFactory factory = 
  +	  final DocumentBuilderFactory factory = 
   		DocumentBuilderFactory.newInstance();
  -	    _root = factory.newDocumentBuilder().newDocument();
  +	  _document = factory.newDocumentBuilder().newDocument();
  +	  _root = _document;
   	}
       }
   
  @@ -115,9 +122,9 @@
   	final Node last = (Node)_nodeStk.peek();
   
   	// No text nodes can be children of root (DOM006 exception)
  -	if (last != _root) {
  +	if (last != _document) {
   	    final String text = new String(ch, start, length);
  -	    last.appendChild(_root.createTextNode(text));
  +	    last.appendChild(_document.createTextNode(text));
   	}
       }
   
  @@ -126,12 +133,13 @@
       }
   
       public void endDocument() {
  +        _nodeStk.pop();
       }
   
       public void startElement(String namespace, String localName, String qName,
   	Attributes attrs) 
       {
  -	final Element tmp = (Element)_root.createElementNS(namespace, qName);
  +	final Element tmp = (Element)_document.createElementNS(namespace, qName);
   
   	// Add namespace declarations first
   	if (_namespaceDecls != null) {
  @@ -199,7 +207,7 @@
        */
       public void processingInstruction(String target, String data) {
   	final Node last = (Node)_nodeStk.peek();
  -	ProcessingInstruction pi = _root.createProcessingInstruction(
  +	ProcessingInstruction pi = _document.createProcessingInstruction(
   		target, data);
   	if (pi != null)  last.appendChild(pi);
       }
  @@ -224,7 +232,7 @@
        */
       public void comment(char[] ch, int start, int length) {
   	final Node last = (Node)_nodeStk.peek();
  -	Comment comment = _root.createComment(new String(ch,start,length));
  +	Comment comment = _document.createComment(new String(ch,start,length));
   	if (comment != null) last.appendChild(comment);
       }
   
  
  
  

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