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 2005/05/20 17:30:23 UTC

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

mkwan       2005/05/20 08:30:23

  Modified:    java/src/org/apache/xalan/xsltc/runtime/output
                        TransletOutputHandlerFactory.java
               java/src/org/apache/xalan/xsltc/trax SAX2DOM.java
                        TransformerImpl.java
  Log:
  Support DOMResult.nextSibling in XSLTC.
  The nextSibling information is passed from TransformerImpl to TransletOutputHandlerFactory,
  then to SAX2DOM. If nextSibling is not null, SAX2DOM inserts the result nodes before it.
  Otherwise the result nodes are appended as the last children of the parent.
  
  Revision  Changes    Path
  1.17      +7 -2      xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/TransletOutputHandlerFactory.java
  
  Index: TransletOutputHandlerFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/TransletOutputHandlerFactory.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- TransletOutputHandlerFactory.java	16 Feb 2004 22:56:25 -0000	1.16
  +++ TransletOutputHandlerFactory.java	20 May 2005 15:30:23 -0000	1.17
  @@ -54,6 +54,7 @@
       private OutputStream _ostream  = System.out;
       private Writer _writer         = null;
       private Node           _node   = null;
  +    private Node   _nextSibling    = null;
       private int _indentNumber      = -1;
       private ContentHandler _handler    = null;
       private LexicalHandler _lexHandler = null;
  @@ -100,6 +101,10 @@
   	return (_handler instanceof SAX2DOM) ? ((SAX2DOM)_handler).getDOM() 
   	   : null;
       }
  +    
  +    public void setNextSibling(Node nextSibling) {
  +        _nextSibling = nextSibling;
  +    }
   
       public void setIndentNumber(int value) {
   	_indentNumber = value;
  @@ -154,7 +159,7 @@
                   return result;
   
               case DOM :
  -                _handler = (_node != null) ? new SAX2DOM(_node) : new SAX2DOM();
  +                _handler = (_node != null) ? new SAX2DOM(_node, _nextSibling) : new SAX2DOM();
                   _lexHandler = (LexicalHandler) _handler;
                   // falls through
               case SAX :
  
  
  
  1.20      +31 -6     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.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- SAX2DOM.java	15 Jul 2004 07:25:15 -0000	1.19
  +++ SAX2DOM.java	20 May 2005 15:30:23 -0000	1.20
  @@ -48,6 +48,7 @@
   
       private Node _root = null;
       private Document _document = null;
  +    private Node _nextSibling = null;
       private Stack _nodeStk = new Stack();
       private Vector _namespaceDecls = null;
       private Node _lastSibling = null;
  @@ -59,7 +60,7 @@
   	_root = _document;
       }
   
  -    public SAX2DOM(Node root) throws ParserConfigurationException {
  +    public SAX2DOM(Node root, Node nextSibling) throws ParserConfigurationException {
   	_root = root;
   	if (root instanceof Document) {
   	  _document = (Document)root;
  @@ -73,6 +74,12 @@
   	  _document = factory.newDocumentBuilder().newDocument();
   	  _root = _document;
   	}
  +	
  +	_nextSibling = nextSibling;
  +    }
  +    
  +    public SAX2DOM(Node root) throws ParserConfigurationException {
  +        this(root, null);
       }
   
       public Node getDOM() {
  @@ -88,9 +95,13 @@
               if( _lastSibling != null && _lastSibling.getNodeType() == Node.TEXT_NODE ){
                     ((Text)_lastSibling).appendData(text);
               }
  -            else{
  +            else if (last == _root && _nextSibling != null) {
  +                _lastSibling = last.insertBefore(_document.createTextNode(text), _nextSibling);
  +            }
  +            else {
                   _lastSibling = last.appendChild(_document.createTextNode(text));
               }
  +            
           }
       }
   
  @@ -139,7 +150,13 @@
   
   	// Append this new node onto current stack node
   	Node last = (Node)_nodeStk.peek();
  -	last.appendChild(tmp);
  +	
  +	// If the SAX2DOM is created with a non-null next sibling node,
  +	// insert the result nodes before the next sibling under the root.
  +	if (last == _root && _nextSibling != null)
  +	    last.insertBefore(tmp, _nextSibling);
  +	else
  +	    last.appendChild(tmp);
   
   	// Push this node onto stack
   	_nodeStk.push(tmp);
  @@ -178,7 +195,11 @@
   	ProcessingInstruction pi = _document.createProcessingInstruction(
   		target, data);
   	if (pi != null){
  -          last.appendChild(pi);
  +          if (last == _root && _nextSibling != null)
  +              last.insertBefore(pi, _nextSibling);
  +          else
  +              last.appendChild(pi);
  +          
             _lastSibling = pi;
           }
       }
  @@ -205,7 +226,11 @@
   	final Node last = (Node)_nodeStk.peek();
   	Comment comment = _document.createComment(new String(ch,start,length));
   	if (comment != null){
  -          last.appendChild(comment);
  +          if (last == _root && _nextSibling != null)
  +              last.insertBefore(comment, _nextSibling);
  +          else
  +              last.appendChild(comment);
  +          
             _lastSibling = comment;
           }
       }
  
  
  
  1.85      +2 -1      xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerImpl.java
  
  Index: TransformerImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerImpl.java,v
  retrieving revision 1.84
  retrieving revision 1.85
  diff -u -r1.84 -r1.85
  --- TransformerImpl.java	19 May 2005 14:20:03 -0000	1.84
  +++ TransformerImpl.java	20 May 2005 15:30:23 -0000	1.85
  @@ -336,6 +336,7 @@
               }
   	    else if (result instanceof DOMResult) {
   		_tohFactory.setNode(((DOMResult) result).getNode());
  +		_tohFactory.setNextSibling(((DOMResult) result).getNextSibling());
   		_tohFactory.setOutputType(TransletOutputHandlerFactory.DOM);
   		return _tohFactory.getSerializationHandler();
               }
  
  
  

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