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 2003/04/01 23:28:39 UTC

cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/runtime AbstractTranslet.java AttributeList.java BasisLibrary.java Constants.java StringValueHandler.java DefaultSAXOutputHandler.java SAXAdapter.java TextOutput.java TransletOutputBase.java

mkwan       2003/04/01 13:28:39

  Modified:    java/src/org/apache/xalan/xsltc/runtime
                        AbstractTranslet.java AttributeList.java
                        BasisLibrary.java Constants.java
                        StringValueHandler.java
  Removed:     java/src/org/apache/xalan/xsltc/runtime
                        DefaultSAXOutputHandler.java SAXAdapter.java
                        TextOutput.java TransletOutputBase.java
  Log:
  Merging XSLTC_DTM and common serializer to the head
  
  Changes in org.apache.xalan.xsltc.runtime.
  
  Revision  Changes    Path
  1.47      +131 -76   xml-xalan/java/src/org/apache/xalan/xsltc/runtime/AbstractTranslet.java
  
  Index: AbstractTranslet.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/AbstractTranslet.java,v
  retrieving revision 1.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- AbstractTranslet.java	30 Jan 2003 18:46:12 -0000	1.46
  +++ AbstractTranslet.java	1 Apr 2003 21:28:38 -0000	1.47
  @@ -70,18 +70,18 @@
   import java.text.DecimalFormatSymbols;
   import java.util.ArrayList;
   import java.util.Enumeration;
  +import java.util.Vector;
   
   import org.apache.xalan.xsltc.DOM;
   import org.apache.xalan.xsltc.DOMCache;
  -import org.apache.xalan.xsltc.NodeIterator;
   import org.apache.xalan.xsltc.Translet;
   import org.apache.xalan.xsltc.TransletException;
  -import org.apache.xalan.xsltc.TransletOutputHandler;
   import org.apache.xalan.xsltc.dom.DOMAdapter;
  -import org.apache.xalan.xsltc.dom.DOMImpl;
  -import org.apache.xalan.xsltc.dom.DTDMonitor;
   import org.apache.xalan.xsltc.dom.KeyIndex;
  +import org.apache.xalan.xsltc.dom.SAXImpl;
   import org.apache.xalan.xsltc.runtime.output.TransletOutputHandlerFactory;
  +import org.apache.xml.dtm.DTMAxisIterator;
  +import org.apache.xml.serializer.SerializationHandler;
   
   public abstract class AbstractTranslet implements Translet {
   
  @@ -96,11 +96,14 @@
       public String  _doctypeSystem = null;
       public boolean _indent = false;
       public String  _mediaType = null;
  -    public Hashtable _cdata = null;
  +    public Vector _cdata = null;
   
       // DOM/translet handshaking - the arrays are set by the compiled translet
       protected String[] namesArray;
       protected String[] namespaceArray;
  +    
  +    // Boolean flag to indicate whether this translet has id functions.
  +    protected boolean _hasIdCall = false;
   
       // TODO - these should only be instanciated when needed
       protected StringValueHandler stringValueHandler = new StringValueHandler();
  @@ -108,6 +111,9 @@
       // Use one empty string instead of constantly instanciating String("");
       private final static String EMPTYSTRING = "";
   
  +    // This is the name of the index used for ID attributes
  +    private final static String ID_INDEX_NAME = "##id";
  +
       
       /************************************************************************
        * Debugging
  @@ -131,10 +137,7 @@
        */
       public final DOMAdapter makeDOMAdapter(DOM dom)
   	throws TransletException {
  -	if (dom instanceof DOMImpl)
  -	    return new DOMAdapter((DOMImpl)dom, namesArray, namespaceArray);
  -	BasisLibrary.runTimeError(BasisLibrary.DOM_ADAPTER_INIT_ERR);
  -	return null;
  +	return new DOMAdapter(dom, namesArray, namespaceArray);
       }
   
       /************************************************************************
  @@ -296,56 +299,60 @@
   	return(null);
       }
   
  -    /************************************************************************
  -     * Unparsed entity URI handling - implements unparsed-entity-uri()
  -     ************************************************************************/
  -
  -    // Keeps all unparsed entity URIs specified in the XML input
  -    public Hashtable _unparsedEntities = null;
  -
  -    /**
  -     * Get the value of an unparsed entity URI.
  -     * This method is used by the compiler/UnparsedEntityUriCall class.
  -     */
  -    public final String getUnparsedEntity(String name) {
  -	final String uri = (String)_unparsedEntities.get(name);
  -	return uri == null ? EMPTYSTRING : uri;
  -    }
  -
  -    /**
  -     * Add an unparsed entity URI. The URI/value pairs are passed from the
  -     * DOM builder to the translet.
  -     */
  -    public final void addUnparsedEntity(String name, String uri) {
  -	if (_unparsedEntities == null)
  -	    _unparsedEntities = new Hashtable();
  -	if (_unparsedEntities.containsKey(name) == false)
  -	    _unparsedEntities.put(name, uri);
  -    }
  -    
       /**
  -     * Add an unparsed entity URI. The URI/value pairs are passed from the
  -     * DOM builder to the translet.
  -     */
  -    public final void setUnparsedEntityURIs(Hashtable table) {
  -	if (_unparsedEntities == null)
  -	    _unparsedEntities = table;
  -	else {
  -	    Enumeration keys = table.keys();
  -	    while (keys.hasMoreElements()) {
  -		String name = (String)keys.nextElement();
  -		_unparsedEntities.put(name,table.get(name));
  -	    }
  -	}
  +     * Give the translet an opportunity to perform a prepass on the document
  +     * to extract any information that it can store in an optimized form.
  +     *
  +     * Currently, it only extracts information about attributes of type ID.
  +     */
  +    public final void prepassDocument(DOM document) {
  +        setIndexSize(document.getSize());
  +        buildIDIndex(document);
       }
   
       /**
  -     * The DTD monitor used by the DOM builder scans the input document DTD
  -     * for unparsed entity URIs. These are passed to the translet using
  -     * this method.
  -     */
  -    public final void setDTDMonitor(DTDMonitor monitor) {
  -	setUnparsedEntityURIs(monitor.getUnparsedEntityURIs());
  +     * Leverages the Key Class to implement the XSLT id() function.
  +     * buildIdIndex creates the index (##id) that Key Class uses.
  +     * The index contains the element node index (int) and Id value (String).
  +     */
  +    private final void buildIDIndex(DOM document) {
  +        
  +        if (document instanceof SAXImpl) {
  +            SAXImpl saxImpl = (SAXImpl)document;
  +            
  +            // If the input source is DOMSource, the KeyIndex table is not
  +            // built at this time. It will be built later by the lookupId()
  +            // and containsId() methods of the KeyIndex class.
  +            if (saxImpl.hasDOMSource()) {
  +                buildKeyIndex(ID_INDEX_NAME, document);
  +                return;
  +            }
  +            else {
  +                final Hashtable elementsByID = saxImpl.getElementsWithIDs();
  +
  +                if (elementsByID == null) {
  +            	    return;
  +                }
  +
  +                // Given a Hashtable of DTM nodes indexed by ID attribute values,
  +                // loop through the table copying information to a KeyIndex
  +                // for the mapping from ID attribute value to DTM node
  +                final Enumeration idValues = elementsByID.keys();
  +                boolean hasIDValues = false;
  +
  +                while (idValues.hasMoreElements()) {
  +            	    final Object idValue = idValues.nextElement();
  +            	    final int element = ((Integer)elementsByID.get(idValue)).intValue();
  +
  +            	    buildKeyIndex(ID_INDEX_NAME, element, idValue);
  +            	    hasIDValues = true;
  +                }
  +
  +                if (hasIDValues) {
  +            	    setKeyIndexDom(ID_INDEX_NAME, document);
  +                }
  +            }
  +        }
       }
   
       /************************************************************************
  @@ -389,6 +396,21 @@
       }
   
       /**
  +     * Create an empty KeyIndex in the DOM case
  +     *   @name is the name of the index (the key or ##id)
  +     *   @node is the DOM
  +     */
  +    public void buildKeyIndex(String name, DOM dom) {
  +	if (_keyIndexes == null) _keyIndexes = new Hashtable();
  +	
  +	KeyIndex index = (KeyIndex)_keyIndexes.get(name);
  +	if (index == null) {
  +	    _keyIndexes.put(name, index = new KeyIndex(_indexSize));
  +	}
  +	index.setDom(dom);
  +    }
  +
  +    /**
        * Returns the index for a given key (or id).
        * The index implements our internal iterator interface
        */
  @@ -409,9 +431,19 @@
        * This method builds key indexes - it is overridden in the compiled
        * translet in cases where the <xsl:key> element is used
        */
  -    public void buildKeys(DOM document, NodeIterator iterator,
  -			  TransletOutputHandler handler,
  +    public void buildKeys(DOM document, DTMAxisIterator iterator,
  +			  SerializationHandler handler,
   			  int root) throws TransletException {
  +			  	
  +    }
  +    
  +    /**
  +     * This method builds key indexes - it is overridden in the compiled
  +     * translet in cases where the <xsl:key> element is used
  +     */
  +    public void setKeyIndexDom(String name, DOM document) {
  +    	getKeyIndex(name).setDom(document);
  +			  	
       }
   
       /************************************************************************
  @@ -442,7 +474,7 @@
        * See compiler/TransletOutput for actual implementation.
        ************************************************************************/
   
  -    public TransletOutputHandler openOutputHandler(String filename, boolean append) 
  +    public SerializationHandler openOutputHandler(String filename, boolean append) 
   	throws TransletException 
       {
   	try {
  @@ -454,8 +486,8 @@
   	    factory.setWriter(new FileWriter(filename, append));
   	    factory.setOutputType(TransletOutputHandlerFactory.STREAM);
   
  -	    final TransletOutputHandler handler 
  -		= factory.getTransletOutputHandler();
  +	    final SerializationHandler handler 
  +		= factory.getSerializationHandler();
   
   	    transferOutputSettings(handler);
   	    handler.startDocument();
  @@ -466,13 +498,13 @@
   	}
       }
   
  -    public TransletOutputHandler openOutputHandler(String filename) 
  +    public SerializationHandler openOutputHandler(String filename) 
          throws TransletException 
       {
          return openOutputHandler(filename, false);
       }
   
  -    public void closeOutputHandler(TransletOutputHandler handler) {
  +    public void closeOutputHandler(SerializationHandler handler) {
   	try {
   	    handler.endDocument();
   	    handler.close();
  @@ -489,14 +521,14 @@
       /**
        * Main transform() method - this is overridden by the compiled translet
        */
  -    public abstract void transform(DOM document, NodeIterator iterator,
  -				   TransletOutputHandler handler)
  +    public abstract void transform(DOM document, DTMAxisIterator iterator,
  +				   SerializationHandler handler)
   	throws TransletException;
   
       /**
        * Calls transform() with a given output handler
        */
  -    public final void transform(DOM document, TransletOutputHandler handler) 
  +    public final void transform(DOM document, SerializationHandler handler) 
   	throws TransletException {
   	transform(document, document.getIterator(), handler);
       }
  @@ -506,33 +538,52 @@
        * output handler
        */
       public final void characters(final String string,
  -				 TransletOutputHandler handler) 
  +				 SerializationHandler handler) 
   	throws TransletException {
  -	final int length = string.length();
  -	handler.characters(string.toCharArray(), 0, length);
  +        if (string != null) {
  +           //final int length = string.length();
  +           try {
  +               handler.characters(string);
  +           } catch (Exception e) {
  +               throw new TransletException(e);
  +           }
  +        }   
       }
   
       /**
        * Add's a name of an element whose text contents should be output as CDATA
        */
       public void addCdataElement(String name) {
  -	if (_cdata == null) _cdata = new Hashtable();
  -	_cdata.put(name, name);
  +	if (_cdata == null) {
  +            _cdata = new Vector();
  +        }
  +
  +        int lastColon = name.lastIndexOf(':');
  +
  +        if (lastColon > 0) {
  +            String uri = name.substring(0, lastColon);
  +            String localName = name.substring(lastColon+1);
  +	    _cdata.addElement(uri);
  +	    _cdata.addElement(localName);
  +        } else {
  +	    _cdata.addElement(null);
  +	    _cdata.addElement(name);
  +        }
       }
   
       /**
        * Transfer the output settings to the output post-processor
        */
  -    protected void transferOutputSettings(TransletOutputHandler handler) {
  +    protected void transferOutputSettings(SerializationHandler handler) {
   	if (_method != null) {
   	    if (_method.equals("xml")) {
   	        if (_standalone != null) {
   		    handler.setStandalone(_standalone);
   		}
   		if (_omitHeader) {
  -		    handler.omitHeader(true);
  +		    handler.setOmitXMLDeclaration(true);
   		}
  -		handler.setCdataElements(_cdata);
  +		handler.setCdataSectionElements(_cdata);
   		if (_version != null) {
   		    handler.setVersion(_version);
   		}
  @@ -550,7 +601,7 @@
   	    }
   	}
   	else {
  -	    handler.setCdataElements(_cdata);
  +	    handler.setCdataSectionElements(_cdata);
   	    if (_version != null) {
   		handler.setVersion(_version);
   	    }
  @@ -558,7 +609,7 @@
   		handler.setStandalone(_standalone);
   	    }
   	    if (_omitHeader) {
  -		handler.omitHeader(true);
  +		handler.setOmitXMLDeclaration(true);
   	    }
   	    handler.setIndent(_indent);
   	    handler.setDoctype(_doctypeSystem, _doctypePublic);
  @@ -583,5 +634,9 @@
       }
       public String[] getNamespaceArray() {
   	return namespaceArray;
  +    }
  +    
  +    public boolean hasIdCall() {
  +    	return _hasIdCall;
       }
   }
  
  
  
  1.7       +37 -11    xml-xalan/java/src/org/apache/xalan/xsltc/runtime/AttributeList.java
  
  Index: AttributeList.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/AttributeList.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- AttributeList.java	30 Jan 2003 18:46:12 -0000	1.6
  +++ AttributeList.java	1 Apr 2003 21:28:38 -0000	1.7
  @@ -80,11 +80,13 @@
        * AttributeList constructor
        */
       public AttributeList() {
  +	/*
   	_attributes = new Hashtable();
   	_names  = new Vector();
   	_values = new Vector();
   	_qnames = new Vector();
   	_uris   = new Vector();
  +	*/
   	_length = 0;
       }
   
  @@ -100,6 +102,20 @@
   	    }
   	}
       }
  +    
  +    /**
  +     * Allocate memory for the AttributeList
  +     * %OPT% Use on-demand allocation for the internal vectors. The memory
  +     * is only allocated when there is an attribute. This reduces the cost 
  +     * of creating many small RTFs.
  +     */
  +    private void alloc() {
  +	_attributes = new Hashtable();
  +	_names  = new Vector();
  +	_values = new Vector();
  +	_qnames = new Vector();
  +	_uris   = new Vector();        
  +    }
   
       /**
        * SAX2: Return the number of attributes in the list. 
  @@ -149,14 +165,14 @@
        * SAX2: Look up the index of an attribute by Namespace name.
        */
       public int getIndex(String namespaceURI, String localPart) {
  -	return(0);
  +	return(-1);
       }
   
       /**
        * SAX2: Look up the index of an attribute by XML 1.0 qualified name.
        */
       public int getIndex(String qname) {
  -	return(0);
  +	return(-1);
       }
   
       /**
  @@ -187,9 +203,13 @@
        * SAX2: Look up an attribute's value by qname.
        */
       public String getValue(String qname) {
  -	final Integer obj = (Integer)_attributes.get(qname);
  -	if (obj == null) return null;
  -	return(getValue(obj.intValue()));
  +	if (_attributes != null) {
  +	    final Integer obj = (Integer)_attributes.get(qname);
  +	    if (obj == null) return null;
  +	    return(getValue(obj.intValue()));
  +	}
  +	else
  +	    return null;
       }
   
       /**
  @@ -203,6 +223,10 @@
        * Adds an attribute to the list
        */
       public void add(String qname, String value) {
  +	// Initialize the internal vectors at the first usage.
  +	if (_attributes == null)
  +	    alloc();
  +	
   	// Stuff the QName into the names vector & hashtable
   	Integer obj = (Integer)_attributes.get(qname);
   	if (obj == null) {
  @@ -230,11 +254,13 @@
        */
       public void clear() {
   	_length = 0;
  -	_attributes.clear();
  -	_names.removeAllElements();
  -	_values.removeAllElements();
  -	_qnames.removeAllElements();
  -	_uris.removeAllElements();
  +	if (_attributes != null) {
  +	    _attributes.clear();
  +	    _names.removeAllElements();
  +	    _values.removeAllElements();
  +	    _qnames.removeAllElements();
  +	    _uris.removeAllElements();
  +	}
       }
       
   }
  
  
  
  1.61      +145 -136  xml-xalan/java/src/org/apache/xalan/xsltc/runtime/BasisLibrary.java
  
  Index: BasisLibrary.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/BasisLibrary.java,v
  retrieving revision 1.60
  retrieving revision 1.61
  diff -u -r1.60 -r1.61
  --- BasisLibrary.java	19 Mar 2003 22:14:10 -0000	1.60
  +++ BasisLibrary.java	1 Apr 2003 21:28:38 -0000	1.61
  @@ -75,25 +75,26 @@
   
   import javax.xml.parsers.DocumentBuilder;
   import javax.xml.parsers.DocumentBuilderFactory;
  +import javax.xml.transform.dom.DOMSource;
   
   import org.apache.xalan.xsltc.DOM;
  -import org.apache.xalan.xsltc.NodeIterator;
   import org.apache.xalan.xsltc.Translet;
  -import org.apache.xalan.xsltc.TransletException;
  -import org.apache.xalan.xsltc.TransletOutputHandler;
   import org.apache.xalan.xsltc.dom.AbsoluteIterator;
   import org.apache.xalan.xsltc.dom.Axis;
   import org.apache.xalan.xsltc.dom.DOMAdapter;
  -import org.apache.xalan.xsltc.dom.DOMBuilder;
  -import org.apache.xalan.xsltc.dom.DOMImpl;
  +import org.apache.xalan.xsltc.dom.SAXImpl;
   import org.apache.xalan.xsltc.dom.MultiDOM;
   import org.apache.xalan.xsltc.dom.SingletonIterator;
   import org.apache.xalan.xsltc.dom.StepIterator;
  -import org.apache.xalan.xsltc.trax.DOM2SAX;
  +import org.apache.xml.dtm.DTMAxisIterator;
  +import org.apache.xml.dtm.DTMManager;
  +import org.apache.xml.dtm.ref.DTMDefaultBase;
   
   import org.w3c.dom.DOMException;
   import org.w3c.dom.Document;
   import org.w3c.dom.NodeList;
  +import org.xml.sax.SAXException;
  +import org.apache.xml.serializer.SerializationHandler;
   
   /**
    * Standard XSLT functions. All standard functions expect the current node 
  @@ -106,15 +107,15 @@
       /**
        * Standard function count(node-set)
        */
  -    public static int countF(NodeIterator iterator) {
  +    public static int countF(DTMAxisIterator iterator) {
   	return(iterator.getLast());
       }
   
       /**
        * Standard function position()
        */
  -    public static int positionF(NodeIterator iterator) {
  -       return iterator.isReverse()
  +    public static int positionF(DTMAxisIterator iterator) {
  +	return iterator.isReverse()
                        ? iterator.getLast() - iterator.getPosition() + 1
                        : iterator.getPosition();
       }
  @@ -123,12 +124,12 @@
        * XSLT Standard function sum(node-set). 
        * stringToDouble is inlined
        */
  -    public static double sumF(NodeIterator iterator, DOM dom) {
  +    public static double sumF(DTMAxisIterator iterator, DOM dom) {
   	try {
   	    double result = 0.0;
   	    int node;
  -	    while ((node = iterator.next()) != NodeIterator.END) {
  -		result += Double.parseDouble(dom.getNodeValue(node));
  +	    while ((node = iterator.next()) != DTMAxisIterator.END) {
  +		result += Double.parseDouble(dom.getStringValueX(node));
   	    }
   	    return result;
   	}
  @@ -141,18 +142,18 @@
        * XSLT Standard function string()
        */
       public static String stringF(int node, DOM dom) {
  -	return dom.getNodeValue(node);
  +	return dom.getStringValueX(node);
       }
   
       /**
        * XSLT Standard function string(value)
        */
       public static String stringF(Object obj, DOM dom) {
  -	if (obj instanceof NodeIterator) {
  -	    return dom.getNodeValue(((NodeIterator)obj).reset().next());
  +	if (obj instanceof DTMAxisIterator) {
  +	    return dom.getStringValueX(((DTMAxisIterator)obj).reset().next());
   	}
   	else if (obj instanceof Node) {
  -	    return dom.getNodeValue(((Node)obj).node);
  +	    return dom.getStringValueX(((Node)obj).node);
   	}
   	else if (obj instanceof DOM) {
   	    return ((DOM)obj).getStringValue();
  @@ -166,16 +167,16 @@
        * XSLT Standard function string(value)
        */
       public static String stringF(Object obj, int node, DOM dom) {
  -	if (obj instanceof NodeIterator) {
  -	    return dom.getNodeValue(((NodeIterator)obj).reset().next());
  +	if (obj instanceof DTMAxisIterator) {
  +	    return dom.getStringValueX(((DTMAxisIterator)obj).reset().next());
   	}
   	else if (obj instanceof Node) {
  -	    return dom.getNodeValue(((Node)obj).node);
  +	    return dom.getStringValueX(((Node)obj).node);
   	}
   	else if (obj instanceof DOM) {
   	    // When the first argument is a DOM we want the whole fecking
   	    // DOM and not just a single node - that would not make sense.
  -	    //return ((DOM)obj).getNodeValue(node);
  +	    //return ((DOM)obj).getStringValueX(node);
   	    return ((DOM)obj).getStringValue();
   	}
   	else if (obj instanceof Double) {
  @@ -200,7 +201,7 @@
        * XSLT Standard function number()
        */
       public static double numberF(int node, DOM dom) {
  -	return stringToReal(dom.getNodeValue(node));
  +	return stringToReal(dom.getStringValueX(node));
       }
   
       /**
  @@ -219,12 +220,12 @@
   	else if (obj instanceof String) {
   	    return stringToReal((String) obj);
   	}
  -	else if (obj instanceof NodeIterator) {
  -	    NodeIterator iter = (NodeIterator) obj;
  -	    return stringToReal(dom.getNodeValue(iter.reset().next()));
  +	else if (obj instanceof DTMAxisIterator) {
  +	    DTMAxisIterator iter = (DTMAxisIterator) obj;
  +	    return stringToReal(dom.getStringValueX(iter.reset().next()));
   	}
   	else if (obj instanceof Node) {
  -	    return stringToReal(dom.getNodeValue(((Node) obj).node));
  +	    return stringToReal(dom.getStringValueX(((Node) obj).node));
   	}
   	else if (obj instanceof DOM) {
   	    return stringToReal(((DOM) obj).getStringValue());
  @@ -253,9 +254,9 @@
   	else if (obj instanceof String) {
   	    return !((String) obj).equals(EMPTYSTRING);
   	}
  -	else if (obj instanceof NodeIterator) {
  -	    NodeIterator iter = (NodeIterator) obj;
  -	    return iter.reset().next() != NodeIterator.END;
  +	else if (obj instanceof DTMAxisIterator) {
  +	    DTMAxisIterator iter = (DTMAxisIterator) obj;
  +	    return iter.reset().next() != DTMAxisIterator.END;
   	}
   	else if (obj instanceof Node) {
   	    return true;
  @@ -372,7 +373,7 @@
        * XSLT Standard function normalize-space(). 
        */
       public static String normalize_spaceF(int node, DOM dom) {
  -	return normalize_spaceF(dom.getNodeValue(node));
  +	return normalize_spaceF(dom.getStringValueX(node));
       }
   
       /**
  @@ -439,7 +440,7 @@
       /**
        * XSLT Standard function namespace-uri(node-set).
        */
  -    public static String namespace_uriF(NodeIterator iter, DOM dom) {
  +    public static String namespace_uriF(DTMAxisIterator iter, DOM dom) {
   	return namespace_uriF(iter.next(), dom);
       }
   
  @@ -483,9 +484,9 @@
           return "boolean";
         else if (obj instanceof Number)
           return "number";
  -      else if (obj instanceof DOMAdapter)
  +      else if (obj instanceof DOM)
           return "RTF";
  -      else if (obj instanceof NodeIterator)
  +      else if (obj instanceof DTMAxisIterator)
           return "node-set";
         else
           return "unknown";
  @@ -494,14 +495,14 @@
       /**
        * Implements the nodeset() extension function. 
        */
  -    public static NodeIterator nodesetF(Object obj) {
  +    public static DTMAxisIterator nodesetF(Object obj) {
   	if (obj instanceof DOM) {
  -	   final DOMAdapter adapter = (DOMAdapter) obj;
  -	   return new SingletonIterator(
  -		  DOM.ROOTNODE | adapter.getMultiDOMMask(), true);
  +	   //final DOMAdapter adapter = (DOMAdapter) obj;
  +	   final DOM dom = (DOM)obj;
  +	   return new SingletonIterator(dom.getDocument(), true);
   	}
  -        else if (obj instanceof NodeIterator) {
  -	   return (NodeIterator) obj;
  +        else if (obj instanceof DTMAxisIterator) {
  +	   return (DTMAxisIterator) obj;
           }
           else {
   	    final String className = obj.getClass().getName();
  @@ -546,19 +547,27 @@
       /**
        * Utility function: node-set/node-set compare. 
        */
  -    public static boolean compare(NodeIterator left, NodeIterator right,
  -				  int op, DOM dom) 
  -    {
  +    public static boolean compare(DTMAxisIterator left, DTMAxisIterator right,
  +				  int op, DOM dom) {
   	int lnode;
   	left.reset();
   	
  -	while ((lnode = left.next()) != NodeIterator.END) {
  -	    final String lvalue = dom.getNodeValue(lnode);
  +	while ((lnode = left.next()) != DTMAxisIterator.END) {
  +	    final String lvalue = dom.getStringValueX(lnode);
   	    
   	    int rnode;
   	    right.reset();
  -	    while ((rnode = right.next()) != NodeIterator.END) {
  -		if (compareStrings(lvalue, dom.getNodeValue(rnode), op, dom)) {
  +	    while ((rnode = right.next()) != DTMAxisIterator.END) {
  +                // String value must be the same if both nodes are the same
  +                if (lnode == rnode) {
  +                    if (op == EQ) {
  +                        return true;
  +                    } else if (op == NE) {
  +                        continue;
  +                    }
  +                }
  +		if (compareStrings(lvalue, dom.getStringValueX(rnode), op,
  +                                   dom)) {
   		    return true;
   		}
   	    }
  @@ -566,10 +575,8 @@
   	return false;
       }
   
  -
  -    public static boolean compare(int node, NodeIterator iterator,
  -				  int op, DOM dom) 
  -    {
  +    public static boolean compare(int node, DTMAxisIterator iterator,
  +				  int op, DOM dom) {
   	//iterator.reset();
   
   	int rnode;
  @@ -577,26 +584,38 @@
   
   	switch(op) {
   	case EQ:
  -	    value = dom.getNodeValue(node);
  -	    while ((rnode = iterator.next()) != NodeIterator.END) {
  -		if (value.equals(dom.getNodeValue(rnode))) return true;
  -	    }
  +            rnode = iterator.next();
  +            if (rnode != DTMAxisIterator.END) {
  +	        value = dom.getStringValueX(node);
  +                do {
  +		    if (node == rnode
  +                          || value.equals(dom.getStringValueX(rnode))) {
  +                       return true;
  +                    }
  +	        } while ((rnode = iterator.next()) != DTMAxisIterator.END);
  +            }
   	    break;
   	case NE:
  -	    value = dom.getNodeValue(node);
  -	    while ((rnode = iterator.next()) != NodeIterator.END) {
  -		if (!value.equals(dom.getNodeValue(rnode))) return true;
  -	    }
  +            rnode = iterator.next();
  +            if (rnode != DTMAxisIterator.END) {
  +	        value = dom.getStringValueX(node);
  +                do {
  +		    if (node != rnode
  +                          && !value.equals(dom.getStringValueX(rnode))) {
  +                        return true;
  +                    }
  +	        } while ((rnode = iterator.next()) != DTMAxisIterator.END);
  +            }
   	    break;
   	case LT:
   	    // Assume we're comparing document order here
  -	    while ((rnode = iterator.next()) != NodeIterator.END) {
  +	    while ((rnode = iterator.next()) != DTMAxisIterator.END) {
   		if (rnode > node) return true;
   	    }
   	    break;
   	case GT:
   	    // Assume we're comparing document order here
  -	    while ((rnode = iterator.next()) != NodeIterator.END) {
  +	    while ((rnode = iterator.next()) != DTMAxisIterator.END) {
   		if (rnode < node) return true;
   	    }
   	    break;
  @@ -604,55 +623,53 @@
   	return(false);
       }
   
  -
       /**
        * Utility function: node-set/number compare.
        */
  -    public static boolean compare(NodeIterator left, final double rnumber,
  -				  final int op, DOM dom) 
  -    {
  +    public static boolean compare(DTMAxisIterator left, final double rnumber,
  +				  final int op, DOM dom) {
   	int node;
   	//left.reset();
   
   	switch (op) {
   	case EQ:
  -	    while ((node = left.next()) != NodeIterator.END) {
  -		if (numberF(dom.getNodeValue(node), dom) == rnumber)
  +	    while ((node = left.next()) != DTMAxisIterator.END) {
  +		if (numberF(dom.getStringValueX(node), dom) == rnumber)
   		    return true;
   	    }
   	    break;
   
   	case NE:
  -	    while ((node = left.next()) != NodeIterator.END) {
  -		if (numberF(dom.getNodeValue(node), dom) != rnumber)
  +	    while ((node = left.next()) != DTMAxisIterator.END) {
  +		if (numberF(dom.getStringValueX(node), dom) != rnumber)
   		    return true;
   	    }
   	    break;
   
   	case GT:
  -	    while ((node = left.next()) != NodeIterator.END) {
  -		if (numberF(dom.getNodeValue(node), dom) > rnumber)
  +	    while ((node = left.next()) != DTMAxisIterator.END) {
  +		if (numberF(dom.getStringValueX(node), dom) > rnumber)
   		    return true;
   	    }
   	    break;
   
   	case LT:
  -	    while ((node = left.next()) != NodeIterator.END) {
  -		if (numberF(dom.getNodeValue(node), dom) < rnumber)
  +	    while ((node = left.next()) != DTMAxisIterator.END) {
  +		if (numberF(dom.getStringValueX(node), dom) < rnumber)
   		    return true;
   	    }
   	    break;
   
   	case GE:
  -	    while ((node = left.next()) != NodeIterator.END) {
  -		if (numberF(dom.getNodeValue(node), dom) >= rnumber)
  +	    while ((node = left.next()) != DTMAxisIterator.END) {
  +		if (numberF(dom.getStringValueX(node), dom) >= rnumber)
   		    return true;
   	    }
   	    break;
   
   	case LE:
  -	    while ((node = left.next()) != NodeIterator.END) {
  -		if (numberF(dom.getNodeValue(node), dom) <= rnumber)
  +	    while ((node = left.next()) != DTMAxisIterator.END) {
  +		if (numberF(dom.getStringValueX(node), dom) <= rnumber)
   		    return true;
   	    }
   	    break;
  @@ -667,13 +684,12 @@
       /**
        * Utility function: node-set/string comparison. 
        */
  -    public static boolean compare(NodeIterator left, final String rstring,
  -				  int op, DOM dom) 
  -    {
  +    public static boolean compare(DTMAxisIterator left, final String rstring,
  +				  int op, DOM dom) {
   	int node;
   	//left.reset();
  -	while ((node = left.next()) != NodeIterator.END) {
  -	    if (compareStrings(dom.getNodeValue(node), rstring, op, dom)) {
  +	while ((node = left.next()) != DTMAxisIterator.END) {
  +	    if (compareStrings(dom.getStringValueX(node), rstring, op, dom)) {
   		return true;
   	    }
   	}
  @@ -746,7 +762,7 @@
   	    }
   
   	    if (hasSimpleType(left) ||
  -		left instanceof DOM && right instanceof NodeIterator) {
  +		left instanceof DOM && right instanceof DTMAxisIterator) {
   		// swap operands
   		final Object temp = right; right = left; left = temp;
   	    }
  @@ -778,10 +794,10 @@
   
   	    // Next, node-set/t for t in {real, string, node-set, result-tree}
   
  -	    NodeIterator iter = ((NodeIterator)left).reset();
  +	    DTMAxisIterator iter = ((DTMAxisIterator)left).reset();
   
  -	    if (right instanceof NodeIterator) {
  -		result = compare(iter, (NodeIterator)right, op, dom);
  +	    if (right instanceof DTMAxisIterator) {
  +		result = compare(iter, (DTMAxisIterator)right, op, dom);
   	    }
   	    else if (right instanceof String) {
   		result = compare(iter, (String)right, op, dom);
  @@ -792,7 +808,7 @@
   	    }
   	    else if (right instanceof Boolean) {
   		boolean temp = ((Boolean)right).booleanValue();
  -		result = (iter.reset().next() != NodeIterator.END) == temp;
  +		result = (iter.reset().next() != DTMAxisIterator.END) == temp;
   	    }
   	    else if (right instanceof DOM) {
   		result = compare(iter, ((DOM)right).getStringValue(),
  @@ -961,14 +977,14 @@
        * Utility function: used to convert references to node-sets. If the
        * obj is an instanceof Node then create a singleton iterator.
        */
  -    public static NodeIterator referenceToNodeSet(Object obj) {
  +    public static DTMAxisIterator referenceToNodeSet(Object obj) {
   	// Convert var/param -> node
   	if (obj instanceof Node) {
   	    return(new SingletonIterator(((Node)obj).node));
   	}
   	// Convert var/param -> node-set
  -	else if (obj instanceof NodeIterator) {
  -	    return(((NodeIterator)obj).cloneIterator());
  +	else if (obj instanceof DTMAxisIterator) {
  +	    return(((DTMAxisIterator)obj).cloneIterator());
   	}
   	else {
   	    final String className = obj.getClass().getName();
  @@ -981,13 +997,13 @@
        * Utility function: used to convert reference to org.w3c.dom.NodeList.
        */
       public static NodeList referenceToNodeList(Object obj, DOM dom) {
  -        if (obj instanceof Node || obj instanceof NodeIterator) {
  -            NodeIterator iter = referenceToNodeSet(obj);
  +        if (obj instanceof Node || obj instanceof DTMAxisIterator) {
  +            DTMAxisIterator iter = referenceToNodeSet(obj);
               return dom.makeNodeList(iter);
           }
           else if (obj instanceof DOM) {
             dom = (DOM)obj;
  -          return dom.makeNodeList(DOM.ROOTNODE);
  +          return dom.makeNodeList(DTMDefaultBase.ROOTNODE);
           }
   	else {
   	    final String className = obj.getClass().getName();
  @@ -1000,13 +1016,13 @@
        * Utility function: used to convert reference to org.w3c.dom.Node.
        */
       public static org.w3c.dom.Node referenceToNode(Object obj, DOM dom) {
  -        if (obj instanceof Node || obj instanceof NodeIterator) {
  -            NodeIterator iter = referenceToNodeSet(obj);
  +        if (obj instanceof Node || obj instanceof DTMAxisIterator) {
  +            DTMAxisIterator iter = referenceToNodeSet(obj);
               return dom.makeNode(iter);
           }
           else if (obj instanceof DOM) {
             dom = (DOM)obj;
  -          NodeIterator iter = dom.getChildren(DOM.ROOTNODE);
  +          DTMAxisIterator iter = dom.getChildren(DTMDefaultBase.ROOTNODE);
             return dom.makeNode(iter);
           }
   	else {
  @@ -1019,7 +1035,7 @@
       /**
        * Utility function used to convert a w3c Node into an internal DOM iterator. 
        */
  -    public static NodeIterator node2Iterator(org.w3c.dom.Node node,
  +    public static DTMAxisIterator node2Iterator(org.w3c.dom.Node node,
   	Translet translet, DOM dom) 
       {
           final org.w3c.dom.Node inNode = node;
  @@ -1047,8 +1063,10 @@
       private static void copyNodes(org.w3c.dom.NodeList nodeList, 
   	org.w3c.dom.Document doc, org.w3c.dom.Node parent)
       {
  +        final int size = nodeList.getLength();
  +
             // copy Nodes from NodeList into new w3c DOM
  -        for (int i = 0; i < nodeList.getLength(); i++) 
  +        for (int i = 0; i < size; i++) 
           {
               org.w3c.dom.Node curr = nodeList.item(i);
               int nodeType = curr.getNodeType();
  @@ -1130,11 +1148,10 @@
        * Utility function used to convert a w3c NodeList into a internal
        * DOM iterator. 
        */
  -    public static NodeIterator nodeList2Iterator(org.w3c.dom.NodeList nodeList,
  -	Translet translet, DOM dom) 
  +    public static DTMAxisIterator nodeList2Iterator(
  +                                        org.w3c.dom.NodeList nodeList,
  +                                    	Translet translet, DOM dom) 
       {
  -	int size = nodeList.getLength();
  -
   	// w3c NodeList -> w3c DOM
   	DocumentBuilderFactory dfac = DocumentBuilderFactory.newInstance();
   	DocumentBuilder docbldr = null;
  @@ -1152,40 +1169,28 @@
   
           // Copy all the nodes in the nodelist to be under the top element
           copyNodes(nodeList, doc, topElementNode);
  -        
  -	// w3c DOM -> DOM2SAX -> DOMBuilder -> DOMImpl
  -	DOMImpl idom = new DOMImpl();
  -	final DOM2SAX dom2sax = new DOM2SAX(doc);
  -	final DOMBuilder domBuilder = idom.getBuilder();
  -	dom2sax.setContentHandler(domBuilder);
  -	try {
  -	    dom2sax.parse(); 
  -	} 
  -        catch (java.io.IOException e){
  -	    runTimeError(RUN_TIME_INTERNAL_ERR, e.getMessage());
  -            return null;
  -	}
  -        catch (org.xml.sax.SAXException e){
  -	    runTimeError(RUN_TIME_INTERNAL_ERR, e.getMessage());
  -            return null;
  -	}
  -	
   
  +        // w3cDOM -> DTM -> DOMImpl
   	if (dom instanceof MultiDOM) {
               final MultiDOM multiDOM = (MultiDOM) dom;
   
  +	    DTMDefaultBase dtm = (DTMDefaultBase)((DOMAdapter)multiDOM.getMain()).getDOMImpl();
  +	    DTMManager dtmManager = dtm.getManager();
  +	    
  +	    SAXImpl idom = (SAXImpl)dtmManager.getDTM(new DOMSource(doc), false,
  +						      null, true, false);
   	    // Create DOMAdapter and register with MultiDOM
   	    DOMAdapter domAdapter = new DOMAdapter(idom, 
                   translet.getNamesArray(),
   		translet.getNamespaceArray());
               multiDOM.addDOMAdapter(domAdapter);
   
  -	    NodeIterator iter1 = multiDOM.getAxisIterator(Axis.CHILD);
  -	    NodeIterator iter2 = multiDOM.getAxisIterator(Axis.CHILD);
  -            NodeIterator iter = new AbsoluteIterator(
  +	    DTMAxisIterator iter1 = idom.getAxisIterator(Axis.CHILD);
  +	    DTMAxisIterator iter2 = idom.getAxisIterator(Axis.CHILD);
  +            DTMAxisIterator iter = new AbsoluteIterator(
                   new StepIterator(iter1, iter2));
   
  - 	    iter.setStartNode(DOM.ROOTNODE | domAdapter.getMultiDOMMask());
  + 	    iter.setStartNode(DTMDefaultBase.ROOTNODE);
   	    return iter;
   	}
           else {
  @@ -1212,7 +1217,7 @@
        * Utility function: used with nth position filters to convert a sequence
        * of nodes to just one single node (the one at position n).
        */
  -    public static NodeIterator getSingleNode(NodeIterator iterator) {
  +    public static DTMAxisIterator getSingleNode(DTMAxisIterator iterator) {
   	int node = iterator.next();
   	return(new SingletonIterator(node));
       }
  @@ -1223,19 +1228,22 @@
       private static char[] _characterArray = new char[32];
   
       public static void copy(Object obj,
  -			    TransletOutputHandler handler,
  + 			    SerializationHandler handler,
   			    int node,
   			    DOM dom) {
   	try {
  -	    if (obj instanceof NodeIterator) {
  -		NodeIterator iter = (NodeIterator) obj;
  +	    if (obj instanceof DTMAxisIterator) 
  +      {
  +		DTMAxisIterator iter = (DTMAxisIterator) obj;
   		dom.copy(iter.reset(), handler);
   	    }
   	    else if (obj instanceof Node) {
   		dom.copy(((Node) obj).node, handler);
   	    }
   	    else if (obj instanceof DOM) {
  -		((DOM)obj).copy(1, handler);
  +		//((DOM)obj).copy(((org.apache.xml.dtm.ref.DTMDefaultBase)((DOMAdapter)obj).getDOMImpl()).getDocument(), handler);
  +		DOM newDom = (DOM)obj;
  +		newDom.copy(newDom.getDocument(), handler);
   	    }
   	    else {
   		String string = obj.toString();		// or call stringF()
  @@ -1246,7 +1254,7 @@
   		handler.characters(_characterArray, 0, length);
   	    }
   	}
  -	catch (TransletException e) {
  +	catch (SAXException e) {
   	    runTimeError(RUN_TIME_COPY_ERR);
   	}
       }
  @@ -1255,7 +1263,7 @@
        * Utility function for the implementation of xsl:element.
        */
       public static String startXslElement(String qname, String namespace,
  -	TransletOutputHandler handler, DOM dom, int node)
  +	SerializationHandler handler, DOM dom, int node)
       {
   	try {
   	    // Get prefix from qname
  @@ -1270,23 +1278,24 @@
   		    namespace = dom.lookupNamespace(node, prefix);
   		}
   
  -		handler.startElement(qname);
  -		handler.namespace(prefix, namespace); 
  +		handler.startElement(namespace, qname.substring(index+1),
  +                                     qname);
  +		handler.namespaceAfterStartElement(prefix, namespace); 
   	    }
   	    else {
   		// Need to generate a prefix?
   		if (namespace != null && namespace.length() > 0) {
   		    prefix = generatePrefix();
   		    qname = prefix + ':' + qname;   
  -		    handler.startElement(qname);   
  -		    handler.namespace(prefix, namespace);
  +		    handler.startElement(namespace, qname, qname);   
  +		    handler.namespaceAfterStartElement(prefix, namespace);
   		}
   		else {
  -		    handler.startElement(qname);   
  +		    handler.startElement(null, null, qname);   
   		}
   	    }
   	}
  -	catch (TransletException e) {
  +	catch (SAXException e) {
   	    throw new RuntimeException(e.getMessage());
   	}
   
  
  
  
  1.6       +7 -7      xml-xalan/java/src/org/apache/xalan/xsltc/runtime/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/Constants.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Constants.java	27 Jan 2003 18:44:50 -0000	1.5
  +++ Constants.java	1 Apr 2003 21:28:38 -0000	1.6
  @@ -63,7 +63,7 @@
   
   package org.apache.xalan.xsltc.runtime;
   
  -import org.apache.xalan.xsltc.DOM;
  +import org.apache.xml.dtm.DTM;
   
   /**
    * This class defines constants used by both the compiler and the 
  @@ -73,11 +73,11 @@
   
       final static int ANY       = -1;
       final static int ATTRIBUTE = -2;
  -    final static int ROOT      = DOM.ROOT;
  -    final static int TEXT      = DOM.TEXT;
  -    final static int ELEMENT   = DOM.ELEMENT;
  -    final static int COMMENT   = DOM.COMMENT;
  -    final static int PROCESSING_INSTRUCTION = DOM.PROCESSING_INSTRUCTION;
  +    final static int ROOT      = DTM.ROOT_NODE;
  +    final static int TEXT      = DTM.TEXT_NODE;
  +    final static int ELEMENT   = DTM.ELEMENT_NODE;
  +    final static int COMMENT   = DTM.COMMENT_NODE;
  +    final static int PROCESSING_INSTRUCTION = DTM.PROCESSING_INSTRUCTION_NODE;
   
       public static String XSLT_URI = "http://www.w3.org/1999/XSL/Transform";
       public static final String NAMESPACE_FEATURE =
  
  
  
  1.8       +49 -17    xml-xalan/java/src/org/apache/xalan/xsltc/runtime/StringValueHandler.java
  
  Index: StringValueHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/StringValueHandler.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- StringValueHandler.java	30 Jan 2003 18:46:12 -0000	1.7
  +++ StringValueHandler.java	1 Apr 2003 21:28:38 -0000	1.8
  @@ -64,33 +64,65 @@
   
   package org.apache.xalan.xsltc.runtime;
   
  -import org.apache.xalan.xsltc.TransletException;
  +import org.xml.sax.SAXException;
   
  -public final class StringValueHandler extends TransletOutputBase {
  +import org.apache.xml.serializer.EmptySerializer;
   
  -    private char[] _buffer = new char[32];
  -    private int _free = 0;
  +public final class StringValueHandler extends EmptySerializer {
  +
  +    private StringBuffer _buffer = new StringBuffer();
  +    private String _str = null;
  +    private static final String EMPTY_STR = "";
  +    private boolean m_escaping = false;
   	
       public void characters(char[] ch, int off, int len) 
  -	throws TransletException 
  +	throws SAXException 
       {
  -	if (_free + len >= _buffer.length) {
  -	    char[] newBuffer = new char[_free + len + 32];
  -	    System.arraycopy(_buffer, 0, newBuffer, 0, _free);
  -	    _buffer = newBuffer;
  +	if (_str != null) {
  +	    _buffer.append(_str);
  +	    _str = null;
   	}
  -	System.arraycopy(ch, off, _buffer, _free, len);
  -	_free += len;
  +	_buffer.append(ch, off, len);
       }
   
       public String getValue() {
  -	final int length = _free;
  -	_free = 0;		// getValue resets
  -	return new String(_buffer, 0, length);
  +	if (_buffer.length() != 0) {
  +	    String result = _buffer.toString();
  +	    _buffer.setLength(0);
  +	    return result;
  +	}
  +	else {
  +	    String result = _str;
  +	    _str = null;
  +	    return (result != null) ? result : EMPTY_STR;
  +	}
       }
   
  -    public void characters(String characters) throws TransletException {
  -	characters(characters.toCharArray(), 0, characters.length());
  +    public void characters(String characters) throws SAXException {
  +	if (_str == null && _buffer.length() == 0) {
  +	    _str = characters;
  +	}
  +	else {
  +	    if (_str != null) {
  +	        _buffer.append(_str);
  +	        _str = null;
  +	    }
  +	    
  +	    _buffer.append(characters);
  +	}
  +    }
  +    
  +    public void startElement(String qname) throws SAXException {
  +        throw new SAXException(EmptySerializer.ERR);
  +    }
  +
  +    // Override the setEscaping method just to indicate that this class is
  +    // aware that that method might be called.
  +    public boolean setEscaping(boolean bool) {
  +        boolean oldEscaping = m_escaping;
  +        m_escaping = bool;
  +
  +        return bool;
       }
   
       /**
  
  
  

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