santiagopg    2002/08/12 12:33:56

  Modified:    java/src/org/apache/xalan/xsltc TransletOutputHandler.java
               java/src/org/apache/xalan/xsltc/runtime SAXAdapter.java
                        TextOutput.java TransletOutputBase.java
               java/src/org/apache/xalan/xsltc/runtime/output
                        OutputBase.java SAXXMLOutput.java
                        StreamHTMLOutput.java StreamOutput.java
                        StreamXMLOutput.java
               java/src/org/apache/xalan/xsltc/trax DOM2SAX.java
                        TemplatesHandlerImpl.java TemplatesImpl.java
                        TransformerFactoryImpl.java
                        TransformerHandlerImpl.java TransformerImpl.java
  Added:       java/src/org/apache/xalan/xsltc/trax DOM2TO.java SAX2TO.java
  Log:
  New implementation of identity transform. Fix for Bugzilla 11345.
  
  Revision  Changes    Path
  1.10      +3 -1      
xml-xalan/java/src/org/apache/xalan/xsltc/TransletOutputHandler.java
  
  Index: TransletOutputHandler.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/TransletOutputHandler.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TransletOutputHandler.java        21 May 2002 15:13:25 -0000      1.9
  +++ TransletOutputHandler.java        12 Aug 2002 19:33:55 -0000      1.10
  @@ -82,6 +82,8 @@
       public void comment(String comment) throws TransletException;
       public void processingInstruction(String target, String data)
        throws TransletException;
  +    public void startCDATA() throws TransletException;
  +    public void endCDATA() throws TransletException;
       public void setType(int type);
       public void setIndent(boolean indent);
       public void omitHeader(boolean value);
  
  
  
  1.14      +3 -1      
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/SAXAdapter.java
  
  Index: SAXAdapter.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/SAXAdapter.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- SAXAdapter.java   21 May 2002 15:13:25 -0000      1.13
  +++ SAXAdapter.java   12 Aug 2002 19:33:55 -0000      1.14
  @@ -186,6 +186,8 @@
       }
   
       // The SAX handler does not handle these:
  +    public void startCDATA() throws TransletException {}
  +    public void endCDATA() throws TransletException {}
       public void setType(int type) {}
       public void setHeader(String header) {}
       public void setIndent(boolean indent) {}
  
  
  
  1.58      +9 -1      
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/TextOutput.java
  
  Index: TextOutput.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/TextOutput.java,v
  retrieving revision 1.57
  retrieving revision 1.58
  diff -u -r1.57 -r1.58
  --- TextOutput.java   11 Jun 2002 20:11:18 -0000      1.57
  +++ TextOutput.java   12 Aug 2002 19:33:55 -0000      1.58
  @@ -384,6 +384,14 @@
        _cdataTagOpen = false;
       }
   
  +    public void startCDATA() throws TransletException {
  +     // This class is deprecated - use runtime.output package
  +    }
  +
  +    public void endCDATA() throws TransletException {
  +     // This class is deprecated - use runtime.output package
  +    }
  +
       /**
        * Send characters to the output document
        */
  
  
  
  1.10      +3 -1      
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/TransletOutputBase.java
  
  Index: TransletOutputBase.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/TransletOutputBase.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TransletOutputBase.java   21 May 2002 15:13:25 -0000      1.9
  +++ TransletOutputBase.java   12 Aug 2002 19:33:55 -0000      1.10
  @@ -85,6 +85,8 @@
        throws TransletException {}
       public boolean setEscaping(boolean escape) 
        throws TransletException { return true; }
  +    public void startCDATA() throws TransletException {}
  +    public void endCDATA() throws TransletException {}
       public String expandQName(String withPrefix) { return(withPrefix); }
       public void setType(int type) {}
       public void setIndent(boolean indent) {}
  
  
  
  1.8       +3 -2      
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/OutputBase.java
  
  Index: OutputBase.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/OutputBase.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- OutputBase.java   18 Jun 2002 22:29:27 -0000      1.7
  +++ OutputBase.java   12 Aug 2002 19:33:55 -0000      1.8
  @@ -288,7 +288,8 @@
           return uri;
       }
   
  -    // -- Temporary
  +    public void startCDATA() throws TransletException { }
  +    public void endCDATA() throws TransletException { }
       public void namespace(String prefix, String uri) throws 
TransletException { }
       public void setType(int type) { }
       public void setIndent(boolean indent) { }
  
  
  
  1.12      +38 -25    
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/SAXXMLOutput.java
  
  Index: SAXXMLOutput.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/SAXXMLOutput.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- SAXXMLOutput.java 18 Jun 2002 22:29:27 -0000      1.11
  +++ SAXXMLOutput.java 12 Aug 2002 19:33:55 -0000      1.12
  @@ -153,27 +153,24 @@
       public void attribute(String name, final String value)
           throws TransletException 
       {
  -     final String patchedName = patchName(name);
  -        final String localName = getLocalName(patchedName);
  -        final String uri = getNamespaceURI(patchedName, false);
  -
  -        final int index = (localName == null) ?
  -                _attributes.getIndex(name) :    /* don't use patchedName */
  -                _attributes.getIndex(uri, localName);
  -
  -        if (!_startTagOpen) {
  -            BasisLibrary.runTimeError(BasisLibrary.STRAY_ATTRIBUTE_ERR,
  -                patchedName);
  -        }
  -
  -     if (index >= 0) {       // Duplicate attribute?
  -         _attributes.setAttribute(index, uri, localName,
  -             patchedName, "CDATA", value);
  +     if (_startTagOpen) {
  +         final String patchedName = patchName(name);
  +         final String localName = getLocalName(patchedName);
  +         final String uri = getNamespaceURI(patchedName, false);
  +
  +         final int index = (localName == null) ?
  +                 _attributes.getIndex(name) :    /* don't use patchedName */
  +                 _attributes.getIndex(uri, localName);
  +
  +         if (index >= 0) {       // Duplicate attribute?
  +             _attributes.setAttribute(index, uri, localName,
  +                 patchedName, "CDATA", value);
  +         }
  +         else {
  +             _attributes.addAttribute(uri, localName, patchedName,
  +                 "CDATA", value);
  +         }
        }
  -     else {
  -         _attributes.addAttribute(uri, localName, patchedName,
  -             "CDATA", value);
  -        }
       }
   
       public void characters(char[] ch, int off, int len)
  @@ -330,10 +327,26 @@
           }
       }
   
  -    protected void closeCDATA() throws SAXException {
  -        // Output closing bracket - "]]>"
  -        _saxHandler.characters(ENDCDATA, 0, ENDCDATA.length);
  -        _cdataTagOpen = false;
  +    public void startCDATA() throws TransletException {
  +     try {
  +         // Output start bracket - "<![CDATA["
  +         _saxHandler.characters(BEGCDATA, 0, BEGCDATA.length);
  +         _cdataTagOpen = true;
  +     }
  +     catch (SAXException e) {
  +            throw new TransletException(e);
  +     }
  +    }
  +
  +    public void closeCDATA() throws TransletException {
  +     try {
  +         // Output closing bracket - "]]>"
  +         _saxHandler.characters(ENDCDATA, 0, ENDCDATA.length);
  +         _cdataTagOpen = false;
  +     }
  +     catch (SAXException e) {
  +            throw new TransletException(e);
  +     }
       }
   
       /**
  
  
  
  1.17      +6 -4      
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamHTMLOutput.java
  
  Index: StreamHTMLOutput.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamHTMLOutput.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- StreamHTMLOutput.java     23 Jul 2002 14:04:51 -0000      1.16
  +++ StreamHTMLOutput.java     12 Aug 2002 19:33:55 -0000      1.17
  @@ -98,19 +98,21 @@
       public StreamHTMLOutput(StreamOutput output) {
        super(output);
        setIndent(true);  // default for HTML
  -// System.out.println("StreamHTMLOutput.<init>");
  +// System.out.println("StreamHTMLOutput.<init> this = " + this);
       }
   
       public StreamHTMLOutput(Writer writer, String encoding) {
        super(writer, encoding);
  -// System.out.println("StreamHTMLOutput.<init>");
  +     setIndent(true);  // default for HTML
  +//System.out.println("StreamHTMLOutput.<init> this = " + this);
       }
   
       public StreamHTMLOutput(OutputStream out, String encoding) 
        throws IOException
       {
        super(out, encoding);
  -// System.out.println("StreamHTMLOutput.<init>");
  +     setIndent(true);  // default for HTML
  +//System.out.println("StreamHTMLOutput.<init> this = " + this);
       }
   
       public void startDocument() throws TransletException { 
  
  
  
  1.19      +2 -3      
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamOutput.java
  
  Index: StreamOutput.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamOutput.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- StreamOutput.java 22 Jul 2002 20:11:32 -0000      1.18
  +++ StreamOutput.java 12 Aug 2002 19:33:55 -0000      1.19
  @@ -89,7 +89,7 @@
       protected static final int MAX_INDENT_LEVEL = (INDENT.length >> 1);
       protected static final int MAX_INDENT       = INDENT.length;
   
  -    protected static final int BUFFER_SIZE = 64 * 1024;
  +    protected static final int BUFFER_SIZE = 32 * 1024;
       protected static final int OUTPUT_BUFFER_SIZE = 4 * 1024;
   
       protected Writer  _writer;
  @@ -111,7 +111,6 @@
   
       protected int     _indentNumber = 2;
   
  -    // protected HashSet _attributes = new HashSet();
       protected Vector _attributes = new Vector();
   
       static class Attribute {
  
  
  
  1.19      +11 -6     
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamXMLOutput.java
  
  Index: StreamXMLOutput.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamXMLOutput.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- StreamXMLOutput.java      23 Jul 2002 14:04:51 -0000      1.18
  +++ StreamXMLOutput.java      12 Aug 2002 19:33:55 -0000      1.19
  @@ -131,7 +131,7 @@
            closeStartTag();
        }
        else if (_cdataTagOpen) {
  -         closeCDATA();
  +         endCDATA();
        }
   
        // Handle document type declaration (for first element only)
  @@ -159,7 +159,7 @@
       public void endElement(String elementName) throws TransletException { 
   // System.out.println("endElement = " + elementName);
        if (_cdataTagOpen) {
  -         closeCDATA();
  +         endCDATA();
        }
   
        if (_startTagOpen) {
  @@ -248,7 +248,7 @@
            closeStartTag();
        }
        else if (_cdataTagOpen) {
  -         closeCDATA();
  +         endCDATA();
        }
        appendComment(comment);
       }
  @@ -261,7 +261,7 @@
            closeStartTag();
        }
        else if (_cdataTagOpen) {
  -         closeCDATA();
  +         endCDATA();
        }
   
        _buffer.append("<?").append(target).append(' ')
  @@ -339,7 +339,12 @@
        _cdataTagOpen = true;
       }
   
  -    private void closeCDATA() {
  +    public void startCDATA() throws TransletException {
  +     _buffer.append(BEGCDATA);
  +     _cdataTagOpen = true;
  +    }
  +
  +    public void endCDATA() throws TransletException {
        _buffer.append(ENDCDATA);
        _cdataTagOpen = false;
       }
  
  
  
  1.17      +12 -2     
xml-xalan/java/src/org/apache/xalan/xsltc/trax/DOM2SAX.java
  
  Index: DOM2SAX.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/DOM2SAX.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- DOM2SAX.java      25 Jul 2002 11:45:57 -0000      1.16
  +++ DOM2SAX.java      12 Aug 2002 19:33:55 -0000      1.17
  @@ -188,7 +188,17 @@
   
       public void parse() throws IOException, SAXException {
        if (_dom != null) {
  -         parse(_dom);
  +         boolean isIncomplete = 
  +             (_dom.getNodeType() != org.w3c.dom.Node.DOCUMENT_NODE);
  +
  +         if (isIncomplete) {
  +             _sax.startDocument();
  +             parse(_dom);
  +             _sax.endDocument();
  +         }
  +         else {
  +             parse(_dom);
  +         }
        }
       }
   
  
  
  
  1.14      +16 -7     
xml-xalan/java/src/org/apache/xalan/xsltc/trax/TemplatesHandlerImpl.java
  
  Index: TemplatesHandlerImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TemplatesHandlerImpl.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- TemplatesHandlerImpl.java 23 Jul 2002 16:33:41 -0000      1.13
  +++ TemplatesHandlerImpl.java 12 Aug 2002 19:33:55 -0000      1.14
  @@ -94,16 +94,21 @@
        */
       private URIResolver _uriResolver = null;
   
  -    // Temporary
  -    private boolean _oldOutputSystem;
  +    /**
  +     * A reference to the transformer factory that this templates
  +     * object belongs to.
  +     */
  +    private TransformerFactoryImpl _tfactory = null;
   
       /**
        * Default constructor
        */
  -    protected TemplatesHandlerImpl(int indentNumber, boolean 
oldOutputSystem) {
  +    protected TemplatesHandlerImpl(int indentNumber, 
  +     TransformerFactoryImpl tfactory) 
  +    {
        super(null);
        _indentNumber = indentNumber;
  -     _oldOutputSystem = oldOutputSystem;
  +     _tfactory = tfactory;
       }
   
       /**
  @@ -184,6 +189,10 @@
                stylesheet.setSystemId(_systemId);
                stylesheet.setParentStylesheet(null);
                setCurrentStylesheet(stylesheet);
  +
  +             // Set it as top-level in the XSLTC object
  +             xsltc.setStylesheet(stylesheet);
  +
                // Create AST under the Stylesheet element 
                createAST(stylesheet);
            }
  @@ -200,8 +209,7 @@
                if (bytecodes != null) {
                    final TemplatesImpl templates = 
                        new TemplatesImpl(xsltc.getBytecodes(), transletName, 
  -                         getOutputProperties(), _indentNumber, 
  -                         _oldOutputSystem);
  +                         getOutputProperties(), _indentNumber, _tfactory);
   
                    // Set URIResolver on templates object
                    if (_uriResolver != null) {
  @@ -223,6 +231,7 @@
        * of the location of the parsed document. 
        */
       public void setDocumentLocator(Locator locator) {
  +     super.setDocumentLocator(locator);
        setSystemId(locator.getSystemId());
       }
   
  
  
  
  1.21      +9 -6      
xml-xalan/java/src/org/apache/xalan/xsltc/trax/TemplatesImpl.java
  
  Index: TemplatesImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TemplatesImpl.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- TemplatesImpl.java        23 Jul 2002 21:09:19 -0000      1.20
  +++ TemplatesImpl.java        12 Aug 2002 19:33:55 -0000      1.21
  @@ -128,8 +128,11 @@
        */
       private URIResolver _uriResolver = null;
   
  -    // Temporary
  -    private boolean _oldOutputSystem;
  +    /**
  +     * A reference to the transformer factory that this templates
  +     * object belongs to.
  +     */
  +    private TransformerFactoryImpl _tfactory = null;
   
       private class TransletClassLoader extends ClassLoader {
   
  @@ -148,13 +151,13 @@
        */
       protected TemplatesImpl(byte[][] bytecodes, String transletName,
        Properties outputProperties, int indentNumber,
  -     boolean oldOutputSystem) 
  +     TransformerFactoryImpl tfactory) 
       {
        _bytecodes = bytecodes;
        _name      = transletName;
        _outputProperties = outputProperties;
        _indentNumber = indentNumber;
  -     _oldOutputSystem = oldOutputSystem;
  +     _tfactory = tfactory;
       }
   
       public synchronized void writeExternal(ObjectOutput out) 
  @@ -334,7 +337,7 @@
       {
        final TransformerImpl transformer =
            new TransformerImpl(getTransletInstance(), _outputProperties,
  -                             _indentNumber, _oldOutputSystem);
  +                             _indentNumber, _tfactory);
        if (_uriResolver != null) {
            transformer.setURIResolver(_uriResolver);
        }
  
  
  
  1.45      +24 -64    
xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerFactoryImpl.java
  
  Index: TransformerFactoryImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerFactoryImpl.java,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- TransformerFactoryImpl.java       23 Jul 2002 16:33:41 -0000      1.44
  +++ TransformerFactoryImpl.java       12 Aug 2002 19:33:55 -0000      1.45
  @@ -72,15 +72,16 @@
   import java.net.MalformedURLException;
   import java.util.Vector;
   import java.util.Hashtable;
  +import java.util.Properties;
   
   import javax.xml.transform.*;
   import javax.xml.transform.sax.*;
   import javax.xml.transform.dom.*;
   import javax.xml.transform.stream.*;
  +import javax.xml.parsers.SAXParserFactory;
   
  +import org.xml.sax.*;
   import org.w3c.dom.Document;
  -import org.xml.sax.XMLFilter;
  -import org.xml.sax.InputSource;
   
   import org.apache.xalan.xsltc.Translet;
   import org.apache.xalan.xsltc.runtime.AbstractTranslet;
  @@ -120,21 +121,6 @@
       protected static String _defaultTransletName = "GregorSamsa";
   
       /**
  -     * Cache for the newTransformer() method - see method for details
  -     */
  -    private Transformer _copyTransformer = null;
  -
  -    /**
  -     * XSL document for the default transformer
  -     */
  -    private static final String COPY_TRANSLET_CODE =
  -     "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\";>"+
  -     "<xsl:template match=\"/\">"+
  -     "  <xsl:copy-of select=\".\"/>"+
  -     "</xsl:template>"+
  -     "</xsl:stylesheet>";
  -
  -    /**
        * This Hashtable is used to store parameters for locating
        * <?xml-stylesheet ...?> processing instructions in XML docs.
        */
  @@ -170,8 +156,10 @@
        */
       private int _indentNumber = -1;
   
  -    // Temporary
  -    private boolean _oldOutputSystem = false;
  +    /**
  +     * A reference to an XML reader for parsing.
  +     */
  +    private XMLReader _xmlReader = null;
   
       /**
        * javax.xml.transform.sax.TransformerFactory implementation.
  @@ -268,16 +256,6 @@
                return;
            }
        }
  -     else if (name.equals("old-output")) {
  -         if (value instanceof Boolean) {
  -             _oldOutputSystem = ((Boolean) value).booleanValue();
  -             return;
  -         }
  -         else if (value instanceof String) {
  -             _oldOutputSystem = ((String) value).equalsIgnoreCase("true");
  -             return;
  -         }
  -     }
        else if (name.equals("indent-number")) {
            if (value instanceof String) {
                try {
  @@ -395,40 +373,12 @@
       public Transformer newTransformer()
        throws TransformerConfigurationException 
       { 
  -     if (_copyTransformer != null) {
  -         if (_uriResolver != null) {
  -             _copyTransformer.setURIResolver(_uriResolver);
  -         }
  -         return _copyTransformer;
  -     }
  -
  -     XSLTC xsltc = new XSLTC();
  -     if (_debug) xsltc.setDebug(true);
  -     if (_disableInlining) xsltc.setTemplateInlining(false);
  -     xsltc.init();
  -
  -     // Compile the default copy-stylesheet
  -     byte[] bytes = COPY_TRANSLET_CODE.getBytes();
  -     ByteArrayInputStream bytestream = new ByteArrayInputStream(bytes);
  -     InputSource input = new InputSource(bytestream);
  -     input.setSystemId(_defaultTransletName);
  -     byte[][] bytecodes = xsltc.compile(_defaultTransletName, input);
  -
  -     // Check that the transformation went well before returning
  -     if (bytecodes == null) {
  -         ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR);
  -         throw new TransformerConfigurationException(err.toString());
  -     }
  -
  -     // Create a Transformer object and store for other calls
  -     Templates templates = new TemplatesImpl(bytecodes, _defaultTransletName,
  -         xsltc.getOutputProperties(), _indentNumber, _oldOutputSystem);
  -
  -     _copyTransformer = templates.newTransformer();
  +     TransformerImpl result = new TransformerImpl(new Properties(), 
  +         _indentNumber, this);
        if (_uriResolver != null) {
  -         _copyTransformer.setURIResolver(_uriResolver);
  +         result.setURIResolver(_uriResolver);
        }
  -     return _copyTransformer;
  +     return result;
       }
   
       /**
  @@ -556,7 +506,7 @@
        }
   
        return new TemplatesImpl(bytecodes, transletName, 
  -         xsltc.getOutputProperties(), _indentNumber, _oldOutputSystem);
  +         xsltc.getOutputProperties(), _indentNumber, this);
       }
   
       /**
  @@ -571,7 +521,7 @@
        throws TransformerConfigurationException 
       { 
        final TemplatesHandlerImpl handler = 
  -         new TemplatesHandlerImpl(_indentNumber, _oldOutputSystem);
  +         new TemplatesHandlerImpl(_indentNumber, this);
        handler.init();
        if (_uriResolver != null) {
            handler.setURIResolver(_uriResolver);
  @@ -772,5 +722,15 @@
            // Falls through
        }
        return null;
  +    }
  +
  +    public XMLReader getXMLReader() throws Exception {
  +     if (_xmlReader == null) {
  +         final SAXParserFactory pfactory 
  +             = SAXParserFactory.newInstance();
  +         pfactory.setNamespaceAware(true);
  +         _xmlReader = pfactory.newSAXParser().getXMLReader();
  +     }
  +     return _xmlReader;
       }
   }
  
  
  
  1.11      +91 -38    
xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerHandlerImpl.java
  
  Index: TransformerHandlerImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerHandlerImpl.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TransformerHandlerImpl.java       4 Jun 2002 20:55:13 -0000       1.10
  +++ TransformerHandlerImpl.java       12 Aug 2002 19:33:55 -0000      1.11
  @@ -63,12 +63,15 @@
   package org.apache.xalan.xsltc.trax;
   
   import org.xml.sax.*;
  +import org.xml.sax.ext.LexicalHandler;
   import org.xml.sax.ext.DeclHandler;
  +import org.xml.sax.helpers.DefaultHandler;
   
   import javax.xml.transform.*;
   import javax.xml.transform.sax.*;
   
   import org.apache.xalan.xsltc.Translet;
  +import org.apache.xalan.xsltc.TransletOutputHandler;
   import org.apache.xalan.xsltc.dom.DOMImpl;
   import org.apache.xalan.xsltc.dom.DOMBuilder;
   import org.apache.xalan.xsltc.dom.DTDMonitor;
  @@ -84,28 +87,43 @@
       private AbstractTranslet _translet = null;
       private String           _systemId;
       private DOMImpl          _dom = null;
  -    private DOMBuilder       _handler = null;
  +    private ContentHandler   _handler = null;
  +    private LexicalHandler   _lexHandler = null;
       private DTDMonitor       _dtd = null;
       private Result           _result = null;
   
       private boolean          _done = false; // Set in endDocument()
   
       /**
  +     * A flag indicating whether this transformer handler implements the 
  +     * identity transform.
  +     */
  +    private boolean _isIdentity = false;
  +
  +    /**
        * Cosntructor - pass in reference to a TransformerImpl object
        */
       protected TransformerHandlerImpl(TransformerImpl transformer) {
        // Save the reference to the transformer
        _transformer = transformer;
   
  -     // Get a reference to the translet wrapped inside the transformer
  -     _translet = _transformer.getTranslet();
  -
  -     // Create a DOMBuilder object and get the handler
  -     _dom = new DOMImpl();
  -     _handler = _dom.getBuilder();
  +     if (transformer.isIdentity()) {
  +         // Set initial handler to the empty handler
  +         _handler = new DefaultHandler();
  +         _isIdentity = true;
  +     }
  +     else {
  +         // Get a reference to the translet wrapped inside the transformer
  +         _translet = _transformer.getTranslet();
  +
  +         // Create a DOMBuilder object and get the handler
  +         _dom = new DOMImpl();
  +         _handler = _dom.getBuilder();
  +         _lexHandler = (LexicalHandler) _handler;
   
  -     // Create a new DTD monitor
  -     _dtd = new DTDMonitor();
  +         // Create a new DTD monitor
  +         _dtd = new DTDMonitor();
  +     }
       }
   
       /**
  @@ -148,8 +166,22 @@
       public void setResult(Result result) throws IllegalArgumentException {
        _result = result;
   
  -     // Run the transformation now, if not already done
  -     if (_done) {
  +     if (_isIdentity) {
  +         try {
  +             // Connect this object with output system directly
  +             TransletOutputHandler outputHandler =
  +                 _transformer.getOutputHandler(result);
  +             _transformer.transferOutputProperties(outputHandler);
  +
  +             _handler = new SAX2TO(outputHandler);
  +             _lexHandler = (LexicalHandler) _handler;
  +         }
  +         catch (TransformerException e) {
  +             _result = null;
  +         }
  +     }
  +     else if (_done) {
  +         // Run the transformation now, if not already done
            try {
                _transformer.setDOM(_dom);
                _transformer.transform(null, _result);
  @@ -182,8 +214,10 @@
            throw new SAXException(err.toString());
        }
   
  -     // Set document URI
  -     _dom.setDocumentURI(_systemId);
  +     if (!_isIdentity) {
  +         // Set document URI
  +         _dom.setDocumentURI(_systemId);
  +     }
   
        // Proxy call
        _handler.startDocument();
  @@ -197,22 +231,24 @@
        // Signal to the DOMBuilder that the document is complete
        _handler.endDocument();
   
  -     // Run the transformation now if we have a reference to a Result object
  -     if (_result != null) {
  -         try {
  -             _transformer.setDOM(_dom);
  -             _transformer.setDTDMonitor(_dtd);       // for id/key
  -             _transformer.transform(null, _result);
  -         }
  -         catch (TransformerException e) {
  -             throw new SAXException(e);
  +     if (!_isIdentity) {
  +         // Run the transformation now if we have a reference to a Result 
object
  +         if (_result != null) {
  +             try {
  +                 _transformer.setDOM(_dom);
  +                 _transformer.setDTDMonitor(_dtd);   // for id/key
  +                 _transformer.transform(null, _result);
  +             }
  +             catch (TransformerException e) {
  +                 throw new SAXException(e);
  +             }
            }
  -     }
  -     // Signal that the internal DOM is build (see 'setResult()').
  -     _done = true;
  +         // Signal that the internal DOM is build (see 'setResult()').
  +         _done = true;
   
  -     // Set this DOM as the transformer's DOM
  -     _transformer.setDOM(_dom);
  +         // Set this DOM as the transformer's DOM
  +         _transformer.setDOM(_dom);
  +     }
       }
        
       /**
  @@ -221,7 +257,8 @@
        */
       public void startElement(String uri, String localName,
                             String qname, Attributes attributes)
  -     throws SAXException {
  +     throws SAXException 
  +    {
        _handler.startElement(uri, localName, qname, attributes);
       }
        
  @@ -230,7 +267,8 @@
        * Receive notification of the end of an element.
        */
       public void endElement(String namespaceURI, String localName, String 
qname)
  -     throws SAXException {
  +     throws SAXException 
  +    {
        _handler.endElement(namespaceURI, localName, qname);
       }
   
  @@ -239,7 +277,8 @@
        * Receive notification of a processing instruction.
        */
       public void processingInstruction(String target, String data)
  -     throws SAXException {
  +     throws SAXException 
  +    {
        _handler.processingInstruction(target, data);
       }
   
  @@ -247,14 +286,18 @@
        * Implements org.xml.sax.ext.LexicalHandler.startCDATA()
        */
       public void startCDATA() throws SAXException { 
  -     _handler.startCDATA();
  +     if (_lexHandler != null) {
  +         _lexHandler.startCDATA();
  +     }
       }
   
       /**
        * Implements org.xml.sax.ext.LexicalHandler.endCDATA()
        */
       public void endCDATA() throws SAXException { 
  -     _handler.endCDATA();
  +     if (_lexHandler != null) {
  +         _lexHandler.endCDATA();
  +     }
       }
   
       /**
  @@ -264,7 +307,9 @@
       public void comment(char[] ch, int start, int length) 
        throws SAXException 
       { 
  -     _handler.comment(ch, start, length);
  +     if (_lexHandler != null) {
  +         _lexHandler.comment(ch, start, length);
  +     }
       }
   
       /**
  @@ -317,28 +362,36 @@
       public void startDTD(String name, String publicId, String systemId) 
        throws SAXException
       { 
  -     _handler.startDTD(name, publicId, systemId);
  +     if (_lexHandler != null) {
  +         _lexHandler.startDTD(name, publicId, systemId);
  +     }
       }
   
       /**
        * Implements org.xml.sax.ext.LexicalHandler.endDTD()
        */
       public void endDTD() throws SAXException {
  -     _handler.endDTD();
  +     if (_lexHandler != null) {
  +         _lexHandler.endDTD();
  +     }
       }
   
       /**
        * Implements org.xml.sax.ext.LexicalHandler.startEntity()
        */
       public void startEntity(String name) throws SAXException { 
  -     _handler.startEntity(name);
  +     if (_lexHandler != null) {
  +         _lexHandler.startEntity(name);
  +     }
       }
   
       /**
        * Implements org.xml.sax.ext.LexicalHandler.endEntity()
        */
       public void endEntity(String name) throws SAXException { 
  -     _handler.endEntity(name);
  +     if (_lexHandler != null) {
  +         _lexHandler.endEntity(name);
  +     }
       }
   
       /**
  
  
  
  1.55      +273 -260  
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.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- TransformerImpl.java      24 Jul 2002 11:27:20 -0000      1.54
  +++ TransformerImpl.java      12 Aug 2002 19:33:55 -0000      1.55
  @@ -58,21 +58,13 @@
    *
    * @author Morten Jorgensen
    * @author G. Todd Miller
  + * @author Santiago Pericas-Geertsen
    *
    */
   
   package org.apache.xalan.xsltc.trax;
   
  -import java.io.File;
  -import java.io.FileOutputStream;
  -import java.io.Writer;
  -import java.io.Reader;
  -import java.io.InputStream;
  -import java.io.OutputStream;
  -import java.io.FileOutputStream;
  -import java.io.FileNotFoundException;
  -import java.io.IOException;
  -
  +import java.io.*;
   import java.net.URL;
   import java.net.URLConnection;
   import java.net.MalformedURLException;
  @@ -83,22 +75,20 @@
   import java.util.Enumeration;
   import java.util.StringTokenizer;
   
  -import org.xml.sax.SAXException;
  -import org.xml.sax.XMLReader;
  -import org.xml.sax.ContentHandler;
  -import org.xml.sax.InputSource;
  +import org.xml.sax.*;
   import org.xml.sax.ext.LexicalHandler;
   
   import org.w3c.dom.Document;
   
  -import javax.xml.parsers.SAXParser;
  -import javax.xml.parsers.SAXParserFactory;
  -import javax.xml.parsers.ParserConfigurationException;
   import javax.xml.transform.*;
   import javax.xml.transform.sax.*;
   import javax.xml.transform.dom.*;
   import javax.xml.transform.stream.*;
   
  +import javax.xml.parsers.SAXParser;
  +import javax.xml.parsers.SAXParserFactory;
  +import javax.xml.parsers.ParserConfigurationException;
  +
   import org.apache.xalan.xsltc.Translet;
   import org.apache.xalan.xsltc.TransletException;
   import org.apache.xalan.xsltc.TransletOutputHandler;
  @@ -113,66 +103,115 @@
   import java.util.Properties;
   
   public final class TransformerImpl extends Transformer
  -    implements DOMCache, ErrorListener {
  +    implements DOMCache, ErrorListener 
  +{
  +    private final static String EMPTY_STRING = "";
  +    private final static String NO_STRING    = "no";
  +    private final static String YES_STRING   = "yes";
  +    private final static String XML_STRING   = "xml";
   
  +    private final static String LEXICAL_HANDLER_PROPERTY =
  +     "http://xml.org/sax/properties/lexical-handler";;
  +    private static final String NAMESPACE_FEATURE =
  +     "http://xml.org/sax/features/namespaces";;
  +    
  +    /**
  +     * A reference to the translet or null if the identity transform.
  +     */
       private AbstractTranslet _translet = null;
  -    private String           _method   = null;
  -    private String           _encoding = null;
  -    private ContentHandler   _handler  = null;
   
       /**
  -     * SystemId set in input source.
  +     * The output method of this transformation.
  +     */
  +    private String _method = null;
  +
  +    /**
  +     * The output encoding of this transformation.
  +     */
  +    private String _encoding = null;
  +
  +    /**
  +     * The systemId set in input source.
        */
       private String _sourceSystemId = null;
   
  +    /**
  +     * An error listener for runtime errors.
  +     */
       private ErrorListener _errorListener = this;
  -    private URIResolver   _uriResolver = null;
  -    private Properties    _properties, _propertiesClone;
   
  -    // Used for default output property settings
  -    private final static String EMPTY_STRING = "";
  -    private final static String NO_STRING    = "no";
  -    private final static String YES_STRING   = "yes";
  -    private final static String XML_STRING   = "xml";
  +    /**
  +     * A reference to a URI resolver for calls to document().
  +     */
  +    private URIResolver _uriResolver = null;
   
  -    // Pre-set DOMImpl to use as input (used only with 
TransformerHandlerImpl)
  +    /**
  +     * Output properties of this transformer instance.
  +     */
  +    private Properties _properties, _propertiesClone;
  +
  +    /**
  +     * A reference to an output handler factory.
  +     */
  +    private TransletOutputHandlerFactory _tohFactory = null;
  +
  +    /**
  +     * A reference to a internal DOM represenation of the input.
  +     */
       private DOMImpl _dom = null;
   
  +    /**
  +     * DTD monitor needed for id()/key().
  +     */
       private DTDMonitor _dtdMonitor = null;
   
  -    private final static String LEXICAL_HANDLER_PROPERTY =
  -     "http://xml.org/sax/properties/lexical-handler";;
  -    private static final String NAMESPACE_FEATURE =
  -     "http://xml.org/sax/features/namespaces";;
  -    
  -    private TransletOutputHandlerFactory _tohFactory = null;
  -
  +    /**
  +     * Number of indent spaces to add when indentation is on.
  +     */
       private int _indentNumber;
   
  -    // Temporary
  -    private boolean _oldOutputSystem;
  +    /**
  +     * A reference to the transformer factory that this templates
  +     * object belongs to.
  +     */
  +    private TransformerFactoryImpl _tfactory = null;
   
       /**
  -     * Implements JAXP's Transformer constructor
  -     * Our Transformer objects always need a translet to do the actual work
  +     * A flag indicating whether this transformer implements the identity 
  +     * transform.
        */
  +    private boolean _isIdentity = false;
  +
  +    protected TransformerImpl(Properties outputProperties, int indentNumber, 
  +     TransformerFactoryImpl tfactory) 
  +    {
  +     this(null, outputProperties, indentNumber, tfactory);
  +     _isIdentity = true;
  +     // _properties.put(OutputKeys.METHOD, "xml");
  +    }
  +
       protected TransformerImpl(Translet translet, Properties outputProperties,
  -     int indentNumber, boolean oldOutputSystem) 
  +     int indentNumber, TransformerFactoryImpl tfactory) 
       {
        _translet = (AbstractTranslet) translet;
        _properties = createOutputProperties(outputProperties);
  -     _oldOutputSystem = oldOutputSystem;
        _propertiesClone = (Properties) _properties.clone();
        _indentNumber = indentNumber;
  +     _tfactory = tfactory;
       }
   
       /**
  -     * Returns the translet wrapped inside this Transformer
  +     * Returns the translet wrapped inside this Transformer or
  +     * null if this is the identity transform.
        */
       protected AbstractTranslet getTranslet() {
        return _translet;
       }
   
  +    public boolean isIdentity() {
  +     return _isIdentity;
  +    }
  +
       /**
        * Implements JAXP's Transformer.transform()
        *
  @@ -183,51 +222,34 @@
       public void transform(Source source, Result result)
        throws TransformerException 
       {
  -     if (_translet == null) {
  -         ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_NO_TRANSLET_ERR);
  -         throw new TransformerException(err.toString());
  -     }
  -
  -     // Pass output properties to the translet
  -     setOutputProperties(_translet, _properties);
  -         
  -     if (!_oldOutputSystem) {
  -         final TransletOutputHandler toHandler = getOutputHandler(result);
  -
  -         if (toHandler == null) {
  -             ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_NO_HANDLER_ERR);
  +     if (!_isIdentity) {
  +         if (_translet == null) {
  +             ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_NO_TRANSLET_ERR);
                throw new TransformerException(err.toString());
            }
  +         // Pass output properties to the translet
  +         transferOutputProperties(_translet);
  +     }
  +         
  +     final TransletOutputHandler toHandler = getOutputHandler(result);
  +     if (toHandler == null) {
  +         ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_NO_HANDLER_ERR);
  +         throw new TransformerException(err.toString());
  +     }
   
  -         if (_uriResolver != null) {
  -             _translet.setDOMCache(this);
  -         }
  -
  -         transform(source, toHandler, _encoding);
  -
  -         if (result instanceof DOMResult) {
  -             ((DOMResult)result).setNode(_tohFactory.getNode());
  -         }
  +     if (_uriResolver != null && !_isIdentity) {
  +         _translet.setDOMCache(this);
        }
  -     else {
  -         _handler = getOldOutputHandler(result);
  -         if (_handler == null) {
  -             ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_NO_HANDLER_ERR);
  -             throw new TransformerException(err.toString());
  -         }
   
  -         if (_uriResolver != null) {
  -             _translet.setDOMCache(this);
  -         }
  +     // Pass output properties to handler if identity
  +     if (_isIdentity) {
  +         transferOutputProperties(toHandler);
  +     }
   
  -         // Run the transformation
  -         transform(source, (ContentHandler)_handler, _encoding);
  +     transform(source, toHandler, _encoding);
   
  -         // If a DOMResult, then we must set the DOM Tree so it can
  -         // be retrieved later 
  -         if (result instanceof DOMResult) {
  -             ((DOMResult)result).setNode(((SAX2DOM)_handler).getDOM());
  -         }
  +     if (result instanceof DOMResult) {
  +         ((DOMResult)result).setNode(_tohFactory.getNode());
        }
       }
   
  @@ -236,7 +258,7 @@
        * the type and contents of the TrAX Result object passed to the 
        * transform() method. 
        */
  -    private TransletOutputHandler getOutputHandler(Result result) 
  +    public TransletOutputHandler getOutputHandler(Result result) 
        throws TransformerException 
       {
        // Get output method using get() to ignore defaults 
  @@ -346,102 +368,6 @@
       }
   
       /**
  -     * Create an output handler (SAX2 handler) for the transformation output
  -     * based on the type and contents of the TrAX Result object passed to
  -     * the transform() method. 
  -     */
  -    private ContentHandler getOldOutputHandler(Result result) throws 
  -     TransformerException 
  -    {
  -     // Try to get the encoding from the translet (may not be set)
  -     if (_translet._encoding != null) {
  -            _encoding = _translet._encoding;
  -        }
  -        else {
  -            _encoding = "UTF-8"; // default output encoding
  -        }
  -
  -     // Return the content handler for this Result object
  -     try {
  -         // Result object could be SAXResult, DOMResult, or StreamResult 
  -         if (result instanceof SAXResult) {
  -                final SAXResult target = (SAXResult)result;
  -                final ContentHandler handler = target.getHandler();
  -                // Simple as feck, just pass the SAX handler back...
  -                if (handler != null) return handler;
  -            }
  -         else if (result instanceof DOMResult) {
  -                return new SAX2DOM(((DOMResult) result).getNode());
  -            }
  -         else if (result instanceof StreamResult) {
  -             // Get StreamResult
  -             final StreamResult target = (StreamResult)result;       
  -
  -             // StreamResult may have been created with a java.io.File,
  -             // java.io.Writer, java.io.OutputStream or just a String
  -             // systemId. 
  -
  -             // try to get a Writer from Result object
  -             final Writer writer = target.getWriter();
  -             if (writer != null) {
  -                 return (new DefaultSAXOutputHandler(writer, _encoding));
  -             }
  -
  -             // or try to get an OutputStream from Result object
  -             final OutputStream ostream = target.getOutputStream();
  -             if (ostream != null) {
  -                 return (new DefaultSAXOutputHandler(ostream, _encoding));
  -             }
  -
  -             // or try to get just a systemId string from Result object
  -             String systemId = result.getSystemId();
  -             if (systemId == null) {
  -                 ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_NO_RESULT_ERR);
  -                    throw new TransformerException(err.toString());
  -             }
  -
  -             // System Id may be in one of several forms, (1) a uri
  -             // that starts with 'file:', (2) uri that starts with 'http:'
  -             // or (3) just a filename on the local system.
  -             OutputStream os = null;
  -             URL url = null;
  -             if (systemId.startsWith("file:")) {
  -                    url = new URL(systemId);
  -                    os = new FileOutputStream(url.getFile());
  -                 return (new DefaultSAXOutputHandler(os, _encoding));
  -                }
  -                else if (systemId.startsWith("http:")) {
  -                    url = new URL(systemId);
  -                    URLConnection connection = url.openConnection();
  -                    os = connection.getOutputStream();
  -                 return (new DefaultSAXOutputHandler(os, _encoding));
  -                }
  -                else {
  -                    // system id is just a filename
  -                    File tmp = new File(systemId);
  -                    url = tmp.toURL();
  -                    os = new FileOutputStream(url.getFile());
  -                 return (new DefaultSAXOutputHandler(os, _encoding));
  -                }
  -         }
  -     }
  -        // If we cannot write to the location specified by the SystemId
  -        catch (UnknownServiceException e) {
  -            throw new TransformerException(e);
  -        }
  -        // If we cannot create a SAX2DOM adapter
  -        catch (ParserConfigurationException e) {
  -            ErrorMsg err = new ErrorMsg(ErrorMsg.SAX2DOM_ADAPTER_ERR);
  -            throw new TransformerException(err.toString());
  -        }
  -        // If we cannot create the file specified by the SystemId
  -        catch (IOException e) {
  -            throw new TransformerException(e);
  -        }
  -     return null;
  -    }
  -
  -    /**
        * Set the internal DOMImpl that will be used for the next transformation
        */
       protected void setDOM(DOMImpl dom) {
  @@ -470,27 +396,22 @@
                _sourceSystemId = source.getSystemId();
            }
   
  -         // Handle SAXSource input
            if (source instanceof SAXSource) {
                // Get all info from the input SAXSource object
  -             final SAXSource   sax    = (SAXSource)source;
  -             XMLReader   reader = sax.getXMLReader();
  -             final InputSource input  = sax.getInputSource();
  +             final SAXSource sax = (SAXSource)source;
  +             XMLReader reader = sax.getXMLReader();
  +             final InputSource input = sax.getInputSource();
   
  -             // if reader was not set with setXMLReader by user,
  -             // then we must create one ourselves.
  +             // Create a reader if not set by user
                if (reader == null) {
  -                 SAXParserFactory pfactory= SAXParserFactory.newInstance();
  -                 pfactory.setNamespaceAware(true);
  -                 reader = pfactory.newSAXParser().getXMLReader();
  +                 reader = _tfactory.getXMLReader();
                }
   
                // Create a DTD monitor to trap all DTD/declarative events
                dtd = new DTDMonitor();
                dtd.handleDTD(reader);
   
  -             // Create a new internal DOM and set up its builder to trap
  -             // all content/lexical events
  +             // Create a new internal DOM and set up its builder 
                dom = new DOMImpl();
                final DOMBuilder builder = dom.getBuilder();
                try {
  @@ -505,18 +426,10 @@
                reader.parse(input);
                dom.setDocumentURI(_sourceSystemId);
            }
  -         // Handle DOMSource input
            else if (source instanceof DOMSource) {
                final DOMSource domsrc = (DOMSource) source;
                final org.w3c.dom.Node node = domsrc.getNode();
  -
  -             boolean isComplete = true;
  -             if (node.getNodeType() != org.w3c.dom.Node.DOCUMENT_NODE) {
  -                 isComplete = false;
  -             }
  -
                final DOM2SAX dom2sax = new DOM2SAX(node);
  -             final InputSource input = null; 
   
                // Create a DTD monitor to trap all DTD/declarative events
                dtd = new DTDMonitor();
  @@ -529,33 +442,15 @@
                dom2sax.setContentHandler(builder);
   
                // Parse the input and build the internal DOM
  -             if (!isComplete) {
  -                 builder.startDocument();
  -             }
  -             dom2sax.parse(input); // need this parameter?
  -             if (!isComplete) {
  -                 builder.endDocument();
  -             }
  +             dom2sax.parse();
                dom.setDocumentURI(_sourceSystemId);
            }
  -         // Handle StreamSource input
            else if (source instanceof StreamSource) {
                // Get all info from the input StreamSource object
                final StreamSource stream = (StreamSource)source;
  -             final InputStream  streamInput = stream.getInputStream();
  +             final InputStream streamInput = stream.getInputStream();
                final Reader streamReader = stream.getReader();
  -
  -             // With a StreamSource we need to create our own parser
  -             final SAXParserFactory factory = SAXParserFactory.newInstance();
  -             try {
  -                 factory.setFeature(NAMESPACE_FEATURE,true);
  -             }
  -             catch (Exception e) {
  -                 factory.setNamespaceAware(true);
  -             }
  -
  -             final SAXParser parser = factory.newSAXParser();
  -             final XMLReader reader = parser.getXMLReader();
  +             final XMLReader reader = _tfactory.getXMLReader();
   
                // Create a DTD monitor to trap all DTD/declarative events
                dtd = new DTDMonitor();
  @@ -594,7 +489,6 @@
                reader.parse(input);
                dom.setDocumentURI(_sourceSystemId);
            }
  -         // Handle XSLTC-internal Source input
            else if (source instanceof XSLTCSource) {
                final XSLTCSource xsltcsrc = (XSLTCSource)source;
                dtd = xsltcsrc.getDTD();
  @@ -610,12 +504,17 @@
            }
   
            // Set size of key/id indices
  -         _translet.setIndexSize(dom.getSize());
  -         // If there are any elements with ID attributes, build an index
  -         dtd.buildIdIndex(dom, mask, _translet);
  -         // Pass unparsed entity URIs to the translet
  -         _translet.setDTDMonitor(dtd);
  +         if (!_isIdentity) {
  +             _translet.setIndexSize(dom.getSize());
  +
  +             // If there are any elements with ID attributes, build an index
  +             dtd.buildIdIndex(dom, mask, _translet);
  +
  +             // Pass unparsed entity URIs to the translet
  +             _translet.setDTDMonitor(dtd);
  +         }
            return dom;
  +
        }
        catch (FileNotFoundException e) {
            if (_errorListener != null) postErrorToListener(e.getMessage());
  @@ -635,49 +534,99 @@
        }
       }
    
  -    /**
  -     * Internal transformation method - uses the internal APIs of XSLTC
  -     */
  -    private void transform(Source src, TransletOutputHandler handler, 
  -     String encoding) throws TransformerException 
  +    private void transformIdentity(Source source, TransletOutputHandler 
handler)
  +     throws Exception 
       {
  -     try {
  -         _translet.transform(getDOM(src, 0), handler);
  +     // Get systemId from source
  +     if (source != null) {
  +         _sourceSystemId = source.getSystemId();
  +     }
  +
  +     if (source instanceof StreamSource) {
  +         final StreamSource stream = (StreamSource) source;
  +         final InputStream streamInput = stream.getInputStream();
  +         final Reader streamReader = stream.getReader();
  +         final XMLReader reader = _tfactory.getXMLReader();
  +
  +         // Hook up reader and output handler 
  +         try {
  +             reader.setProperty(LEXICAL_HANDLER_PROPERTY, handler);
  +         }
  +         catch (SAXException e) {
  +             // Falls through
  +         }
  +         reader.setContentHandler(new SAX2TO(handler));
  +
  +         // Create input source from source
  +         InputSource input;
  +         if (streamInput != null) {
  +             input = new InputSource(streamInput);
  +             input.setSystemId(_sourceSystemId); 
  +         } 
  +         else if (streamReader != null) {
  +             input = new InputSource(streamReader);
  +             input.setSystemId(_sourceSystemId); 
  +         } 
  +         else if (_sourceSystemId != null) {
  +             input = new InputSource(_sourceSystemId);
  +         } 
  +         else {
  +             ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_NO_SOURCE_ERR);
  +             throw new TransformerException(err.toString());
  +         }
  +
  +         // Start pushing SAX events
  +         reader.parse(input);
        }
  -     catch (TransletException e) {
  -         if (_errorListener != null) postErrorToListener(e.getMessage());
  -         throw new TransformerException(e);
  +     else if (source instanceof SAXSource) {
  +         final SAXSource sax = (SAXSource) source;
  +         XMLReader reader = sax.getXMLReader();
  +         final InputSource input = sax.getInputSource();
  +
  +         // Create a reader if not set by user
  +         if (reader == null) {
  +             reader = _tfactory.getXMLReader();
  +         }
  +
  +         // Hook up reader and output handler 
  +         try {
  +             reader.setProperty(LEXICAL_HANDLER_PROPERTY, handler);
  +         }
  +         catch (SAXException e) {
  +             // Falls through
  +         }
  +         reader.setContentHandler(new SAX2TO(handler));
  +
  +         // Start pushing SAX events
  +         reader.parse(input);
        }
  -     catch (RuntimeException e) {
  -         if (_errorListener != null) postErrorToListener(e.getMessage());
  -         throw new TransformerException(e);
  +     else if (source instanceof DOMSource) {
  +         final DOMSource domsrc = (DOMSource) source;
  +         new DOM2TO(domsrc.getNode(), handler).parse();
        }
  -     catch (Exception e) {
  -         if (_errorListener != null) postErrorToListener(e.getMessage());
  -         throw new TransformerException(e);
  +     else if (source instanceof XSLTCSource) {
  +         final DOMImpl dom = ((XSLTCSource) source).getDOM();
  +         dom.copy(handler);
  +     }
  +     else {
  +         ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_NO_SOURCE_ERR);
  +         throw new TransformerException(err.toString());
        }
       }
   
       /**
        * Internal transformation method - uses the internal APIs of XSLTC
        */
  -    private void transform(Source src, ContentHandler sax, String encoding)
  -     throws TransformerException {
  +    private void transform(Source source, TransletOutputHandler handler, 
  +     String encoding) throws TransformerException 
  +    {
        try {
  -         // Build an iternal DOMImpl from the TrAX Source
  -         DOMImpl dom = getDOM(src, 0);
  -
  -         // This handler will post-process the translet output
  -         TextOutput handler;
  -
  -         // Check if the ContentHandler also implements LexicalHandler
  -         if (sax instanceof LexicalHandler) {
  -             handler = new TextOutput(sax, (LexicalHandler)sax, encoding);
  +         if (_isIdentity) {
  +             transformIdentity(source, handler);
            }
            else {
  -             handler = new TextOutput(sax, encoding);
  +             _translet.transform(getDOM(source, 0), handler);
            }
  -         _translet.transform(dom, handler);
        }
        catch (TransletException e) {
            if (_errorListener != null) postErrorToListener(e.getMessage());
  @@ -862,18 +811,17 @@
        * Internal method to pass any properties to the translet prior to
        * initiating the transformation
        */
  -    private void setOutputProperties(AbstractTranslet translet,
  -                                  Properties properties) 
  +    private void transferOutputProperties(AbstractTranslet translet)
       {
        // Return right now if no properties are set
  -     if (properties == null) return;
  +     if (_properties == null) return;
   
        // Get a list of all the defined properties
  -     Enumeration names = properties.propertyNames();
  +     Enumeration names = _properties.propertyNames();
        while (names.hasMoreElements()) {
            // Note the use of get() instead of getProperty()
            String name  = (String) names.nextElement();
  -         String value = (String) properties.get(name);
  +         String value = (String) _properties.get(name);
   
            // Ignore default properties
            if (value == null) continue;
  @@ -917,6 +865,71 @@
                    }
                }
            }
  +     }
  +    }
  +
  +    /**
  +     * This method is used to pass any properties to the output handler
  +     * when running the identity transform.
  +     */
  +    public void transferOutputProperties(TransletOutputHandler handler)
  +    {
  +     // Return right now if no properties are set
  +     if (_properties == null) return;
  +
  +     String doctypePublic = null;
  +     String doctypeSystem = null;
  +
  +     // Get a list of all the defined properties
  +     Enumeration names = _properties.propertyNames();
  +     while (names.hasMoreElements()) {
  +         // Note the use of get() instead of getProperty()
  +         String name  = (String) names.nextElement();
  +         String value = (String) _properties.get(name);
  +
  +         // Ignore default properties
  +         if (value == null) continue;
  +
  +         // Pass property value to translet - override previous setting
  +         if (name.equals(OutputKeys.DOCTYPE_PUBLIC)) {
  +             doctypePublic = value;
  +         }
  +         else if (name.equals(OutputKeys.DOCTYPE_SYSTEM)) {
  +             doctypeSystem = value;
  +         }
  +         else if (name.equals(OutputKeys.MEDIA_TYPE)) {
  +             handler.setMediaType(value);
  +         }
  +         else if (name.equals(OutputKeys.STANDALONE)) {
  +             handler.setStandalone(value);
  +         }
  +         else if (name.equals(OutputKeys.VERSION)) {
  +             handler.setVersion(value);
  +         }
  +         else if (name.equals(OutputKeys.OMIT_XML_DECLARATION)) {
  +             handler.omitHeader(
  +                 value != null && value.toLowerCase().equals("yes"));
  +         }
  +         else if (name.equals(OutputKeys.INDENT)) {
  +             handler.setIndent( 
  +                 value != null && value.toLowerCase().equals("yes"));
  +         }
  +         else if (name.equals(OutputKeys.CDATA_SECTION_ELEMENTS)) {
  +             if (value != null) {
  +                 Hashtable table = new Hashtable();
  +                 StringTokenizer e = new StringTokenizer(value);
  +                 while (e.hasMoreTokens()) {
  +                     final String token = e.nextToken();
  +                     table.put(token, token);
  +                 }
  +                 handler.setCdataElements(table);
  +             }
  +         }
  +     }
  +
  +     // Call setDoctype() if needed
  +     if (doctypePublic != null || doctypeSystem != null) {
  +         handler.setDoctype(doctypePublic, doctypeSystem);
        }
       }
   
  
  
  
  1.1                  
xml-xalan/java/src/org/apache/xalan/xsltc/trax/DOM2TO.java
  
  Index: DOM2TO.java
  ===================================================================
  /*
   * @(#)$Id: DOM2TO.java,v 1.1 2002/08/12 19:33:55 santiagopg Exp $
   *
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 2001, Sun
   * Microsystems., http://www.sun.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * @author Santiago Pericas-Geertsen
   *
   */
  
  package org.apache.xalan.xsltc.trax;
  
  import org.w3c.dom.Node;
  import org.w3c.dom.Document;
  import org.w3c.dom.NamedNodeMap;
  import java.io.IOException;
  import org.w3c.dom.Entity;
  import org.w3c.dom.Notation;
  
  import org.xml.sax.*;
  
  import org.apache.xalan.xsltc.TransletOutputHandler;
  
  public class DOM2TO implements XMLReader, Locator {
  
      private final static String EMPTYSTRING = "";
      private static final String XMLNS_PREFIX = "xmlns";
  
      /**
       * A reference to the DOM to be traversed.
       */
      private Node _dom;
  
      /**
       * A reference to the output handler receiving the events.
       */
      private TransletOutputHandler _handler;
  
      public DOM2TO(Node root, TransletOutputHandler handler) {
        _dom = root;
        _handler = handler;
      }
  
      public ContentHandler getContentHandler() { 
        return null;
      }
  
      public void setContentHandler(ContentHandler handler) {
        // Empty
      }
  
      public void parse(InputSource unused) throws IOException, SAXException {
          parse(_dom);
      }
  
      public void parse() throws IOException, SAXException {
        if (_dom != null) {
            boolean isIncomplete = 
                (_dom.getNodeType() != org.w3c.dom.Node.DOCUMENT_NODE);
  
            if (isIncomplete) {
                _handler.startDocument();
                parse(_dom);
                _handler.endDocument();
            }
            else {
                parse(_dom);
            }
        }
      }
  
      /**
       * Traverse the DOM and generate TO events for a handler. Notice that 
       * we need to handle implicit namespace declarations too.
       */
      private void parse(Node node) 
        throws IOException, SAXException 
      {
        if (node == null) return;
  
          switch (node.getNodeType()) {
        case Node.ATTRIBUTE_NODE:         // handled by ELEMENT_NODE
        case Node.DOCUMENT_FRAGMENT_NODE:
        case Node.DOCUMENT_TYPE_NODE :
        case Node.ENTITY_NODE :
        case Node.ENTITY_REFERENCE_NODE:
        case Node.NOTATION_NODE :
            // These node types are ignored!!!
            break;
        case Node.CDATA_SECTION_NODE:
            _handler.startCDATA();
            _handler.characters(node.getNodeValue());
            _handler.endCDATA();
            break;
  
        case Node.COMMENT_NODE:           // should be handled!!!
            _handler.comment(node.getNodeValue());
            break;
  
        case Node.DOCUMENT_NODE:
            _handler.startDocument();
            Node next = node.getFirstChild();
            while (next != null) {
                parse(next);
                next = next.getNextSibling();
            }
            _handler.endDocument();
            break;
  
        case Node.ELEMENT_NODE:
            // Generate SAX event to start element
            final String qname = node.getNodeName();
            _handler.startElement(qname);
  
            String prefix;
            final NamedNodeMap map = node.getAttributes();
            final int length = map.getLength();
  
            // Process all other attributes
            for (int i = 0; i < length; i++) {
                int colon;
                final Node attr = map.item(i);
                final String qnameAttr = attr.getNodeName();
  
                if (qnameAttr.startsWith(XMLNS_PREFIX)) {
                    final String uriAttr = attr.getNodeValue();
                    colon = qnameAttr.lastIndexOf(':');
                    prefix = (colon > 0) ? qnameAttr.substring(colon + 1) 
                        : EMPTYSTRING;
                    _handler.namespace(prefix, uriAttr);
                }
                else {
                    final String uriAttr = attr.getNamespaceURI();
                    // Uri may be implicitly declared
                    if (uriAttr != null) {      
                        colon = qnameAttr.lastIndexOf(':');
                        prefix = (colon > 0) ? qnameAttr.substring(0, colon) 
                            : EMPTYSTRING;
                        _handler.namespace(prefix, uriAttr);
                    }
                    _handler.attribute(qnameAttr, attr.getNodeValue());
                }
            }
  
            // Now element namespace and children
            final String uri = node.getNamespaceURI();
  
            // Uri may be implicitly declared
            if (uri != null) {  
                final int colon = qname.lastIndexOf(':');
                prefix = (colon > 0) ? qname.substring(0, colon) : EMPTYSTRING;
                _handler.namespace(prefix, uri);
            }
  
            // Traverse all child nodes of the element (if any)
            next = node.getFirstChild();
            while (next != null) {
                parse(next);
                next = next.getNextSibling();
            }
  
            // Generate SAX event to close element
            _handler.endElement(qname);
            break;
  
        case Node.PROCESSING_INSTRUCTION_NODE:
            _handler.processingInstruction(node.getNodeName(),
                                           node.getNodeValue());
            break;
  
        case Node.TEXT_NODE:
            _handler.characters(node.getNodeValue());
            break;
        }
      }
  
      /**
       * This class is only used internally so this method should never 
       * be called.
       */
      public DTDHandler getDTDHandler() { 
        return null;
      }
  
      /**
       * This class is only used internally so this method should never 
       * be called.
       */
      public ErrorHandler getErrorHandler() {
        return null;
      }
  
      /**
       * This class is only used internally so this method should never 
       * be called.
       */
      public boolean getFeature(String name) throws SAXNotRecognizedException,
        SAXNotSupportedException
      {
        return false;
      }
  
      /**
       * This class is only used internally so this method should never 
       * be called.
       */
      public void setFeature(String name, boolean value) throws 
        SAXNotRecognizedException, SAXNotSupportedException 
      {
      }
  
      /**
       * This class is only used internally so this method should never 
       * be called.
       */
      public void parse(String sysId) throws IOException, SAXException {
        throw new IOException("This method is not yet implemented.");
      }
  
      /**
       * This class is only used internally so this method should never 
       * be called.
       */
      public void setDTDHandler(DTDHandler handler) throws NullPointerException 
{
      }
  
      /**
       * This class is only used internally so this method should never 
       * be called.
       */
      public void setEntityResolver(EntityResolver resolver) throws 
        NullPointerException 
      {
      }
  
      /**
       * This class is only used internally so this method should never 
       * be called.
       */
      public EntityResolver getEntityResolver() {
        return null;
      }
  
      /**
       * This class is only used internally so this method should never 
       * be called.
       */
      public void setErrorHandler(ErrorHandler handler) throws 
        NullPointerException
      {
      }
  
      /**
       * This class is only used internally so this method should never 
       * be called.
       */
      public void setProperty(String name, Object value) throws
        SAXNotRecognizedException, SAXNotSupportedException {
      }
  
      /**
       * This class is only used internally so this method should never 
       * be called.
       */
      public Object getProperty(String name) throws SAXNotRecognizedException,
        SAXNotSupportedException
      {
        return null;
      }
  
      /**
       * This class is only used internally so this method should never 
       * be called.
       */
      public int getColumnNumber() { 
        return 0; 
      }
      
      /**
       * This class is only used internally so this method should never 
       * be called.
       */
      public int getLineNumber() { 
        return 0; 
      }
  
      /**
       * This class is only used internally so this method should never 
       * be called.
       */
      public String getPublicId() { 
        return null; 
      }
  
      /**
       * This class is only used internally so this method should never 
       * be called.
       */
      public String getSystemId() { 
        return null; 
      }
  
      // Debugging 
      private String getNodeTypeFromCode(short code) {
        String retval = null;
        switch (code) {
        case Node.ATTRIBUTE_NODE : 
            retval = "ATTRIBUTE_NODE"; break; 
        case Node.CDATA_SECTION_NODE :
            retval = "CDATA_SECTION_NODE"; break; 
        case Node.COMMENT_NODE :
            retval = "COMMENT_NODE"; break; 
        case Node.DOCUMENT_FRAGMENT_NODE :
            retval = "DOCUMENT_FRAGMENT_NODE"; break; 
        case Node.DOCUMENT_NODE :
            retval = "DOCUMENT_NODE"; break; 
        case Node.DOCUMENT_TYPE_NODE :
            retval = "DOCUMENT_TYPE_NODE"; break; 
        case Node.ELEMENT_NODE :
            retval = "ELEMENT_NODE"; break; 
        case Node.ENTITY_NODE :
            retval = "ENTITY_NODE"; break; 
        case Node.ENTITY_REFERENCE_NODE :
            retval = "ENTITY_REFERENCE_NODE"; break; 
        case Node.NOTATION_NODE :
            retval = "NOTATION_NODE"; break; 
        case Node.PROCESSING_INSTRUCTION_NODE :
            retval = "PROCESSING_INSTRUCTION_NODE"; break; 
        case Node.TEXT_NODE:
            retval = "TEXT_NODE"; break; 
          }
        return retval;
      }
  }
  
  
  
  1.1                  
xml-xalan/java/src/org/apache/xalan/xsltc/trax/SAX2TO.java
  
  Index: SAX2TO.java
  ===================================================================
  /*
   * @(#)$Id: SAX2TO.java,v 1.1 2002/08/12 19:33:55 santiagopg Exp $
   *
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 2001, Sun
   * Microsystems., http://www.sun.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * @author Santiago Pericas-Geertsen
   */
  
  
  package org.apache.xalan.xsltc.trax;
  
  import java.util.ArrayList;
  
  import org.xml.sax.ContentHandler;
  import org.xml.sax.Locator;
  import org.xml.sax.Attributes;
  import org.xml.sax.ext.LexicalHandler;
  import org.xml.sax.SAXException;
  
  import org.apache.xalan.xsltc.runtime.Constants;
  import org.apache.xalan.xsltc.TransletException;
  import org.apache.xalan.xsltc.TransletOutputHandler;
  
  public class SAX2TO implements ContentHandler, LexicalHandler, Constants {
  
      static private class Pair {
        String left;
        String right;
  
        public Pair(String ll, String rr) {
            left = ll; right = rr;
        }
      }
  
      TransletOutputHandler _handler;
      ArrayList _nsDeclarations = new ArrayList();
  
      public SAX2TO(TransletOutputHandler handler) {
        _handler = handler;
      }
  
      public void startDocument() throws TransletException {
        _handler.startDocument();
      }
  
      public void endDocument() throws TransletException {
        _handler.endDocument();
        _handler.close();
      }
  
      public void startElement(String namespace, String localName, String qName,
        Attributes attrs) throws TransletException
      {
        _handler.startElement(qName);
  
        int n = _nsDeclarations.size();
        for (int i = 0; i < n; i++) {
            final Pair pair = (Pair) _nsDeclarations.get(i);
            _handler.namespace(pair.left, pair.right);
        }
        _nsDeclarations.clear();
  
        n = attrs.getLength();
        for (int i = 0; i < n; i++) {
            _handler.attribute(attrs.getQName(i), attrs.getValue(i));
        }
      }
  
      public void endElement(String namespace, String localName, String qName) 
        throws TransletException
      {
        _handler.endElement(qName);
      }
  
      public void startPrefixMapping(String prefix, String uri)
        throws TransletException
      {
        _nsDeclarations.add(new Pair(prefix, uri));
      }
  
      public void endPrefixMapping(String prefix) {
        // Empty
      }
  
      public void characters(char[] ch, int start, int length)
        throws TransletException
      {
        _handler.characters(ch, start, length);
      }
  
      public void processingInstruction(String target, String data)
        throws TransletException
      {
        _handler.processingInstruction(target, data);
      }
  
      public void comment(char[] ch, int start, int length) 
        throws TransletException
      {
        _handler.comment(new String(ch, start, length));
      }
  
      public void ignorableWhitespace(char[] ch, int start, int length)
        throws TransletException
      {
        _handler.characters(ch, start, length);
      }
  
      public void startCDATA() throws TransletException { 
        _handler.startCDATA();
      }
  
      public void endCDATA() throws TransletException { 
        _handler.endCDATA();
      }
  
      public void setDocumentLocator(Locator locator) {
      }
  
      public void skippedEntity(String name) {
      }
  
      public void startEntity(java.lang.String name) { 
      }
  
      public void endDTD() { 
      }
  
      public void endEntity(String name) { 
      }
  
      public void startDTD(String name, String publicId, String systemId)
          throws SAXException 
      { 
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to