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

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

zongaro     2002/08/13 14:19:08

  Modified:    java/src/org/apache/xalan/xsltc/trax Tag: XSLTC_DTM
                        TransformerImpl.java
  Log:
  Picked up latest changes from MAIN branch, as well as a fix for id/key from
  revision 1.42 that I merged incorrectly.  Also, in getDOM method, temporarily
  switched use of DOMImpl in DOMSource case to use DOM2SAX and SAXImpl, just to
  get things going for the trax.dom flavor.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.37.2.3  +301 -277  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.37.2.2
  retrieving revision 1.37.2.3
  diff -u -r1.37.2.2 -r1.37.2.3
  --- TransformerImpl.java	29 Jul 2002 00:01:29 -0000	1.37.2.2
  +++ TransformerImpl.java	13 Aug 2002 21:19:08 -0000	1.37.2.3
  @@ -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;
  @@ -116,66 +106,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;
  +
  +    /**
  +     * Output properties of this transformer instance.
  +     */
  +    private Properties _properties, _propertiesClone;
   
  -    // Pre-set DOM to use as input (used only with TransformerHandlerImpl)
  +    /**
  +     * A reference to an output handler factory.
  +     */
  +    private TransletOutputHandlerFactory _tohFactory = null;
  +
  +    /**
  +     * A reference to a internal DOM represenation of the input.
  +     */
       private DOM _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()
        *
  @@ -186,51 +225,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());
   	}
       }
   
  @@ -239,7 +261,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 
  @@ -349,102 +371,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 DOM that will be used for the next transformation
        */
       protected void setDOM(DOM dom) {
  @@ -464,13 +390,6 @@
       private DOM getDOM(Source source, int mask)
   	throws TransformerException {
   	try {
  -	    // Use the pre-defined DOM if present
  -	    if (_dom != null) {
  -		DOM dom = _dom;
  -		_dom = null; // use only once, so reset to 'null'
  -		return(dom);
  -	    }
  -
   	    DOM dom = null;
   	    DTDMonitor dtd = null;
   
  @@ -479,19 +398,15 @@
   		_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
  @@ -500,24 +415,28 @@
   
   		// Create a new internal DOM and set up its builder to trap
   		// all content/lexical events
  -    DTMManager dtmManager = XSLTCDTMManager.newInstance(
  -                 org.apache.xpath.objects.XMLStringFactoryImpl.getFactory());
  +		DTMManager dtmManager = XSLTCDTMManager.newInstance(
  +                   org.apache.xpath.objects.XMLStringFactoryImpl.getFactory());
   
  -    dom = (SAXImpl)dtmManager.getDTM(sax, false, null, true, true);
  +		dom = (SAXImpl)dtmManager.getDTM(sax, false, null, true, true);
  +		final DOMBuilder builder = ((SAXImpl)dom).getBuilder();
  +		try {
  +		    reader.setProperty(LEXICAL_HANDLER_PROPERTY, builder);
  +		}
  +		catch (SAXException e) {
  +		    // quitely ignored
  +		}
  +		reader.setContentHandler(builder);
   		((SAXImpl)dom).setDocumentURI(_sourceSystemId);
   	    }
  -	    // Handle DOMSource input
   	    else if (source instanceof DOMSource) {
  +                // %HZ% - Need to change following - it's wrapping DOM with
  +                // SAX to get to DTM.  Should wrap DOM with DTM directly!
   		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; 
  +                final boolean isComplete =
  +                    (node.getNodeType() == org.w3c.dom.Node.DOCUMENT_NODE);
   
   		// Create a DTD monitor to trap all DTD/declarative events
   		dtd = new DTDMonitor();
  @@ -525,39 +444,25 @@
   
   		// Create a new internal DOM and set up its builder to trap
   		// all content/lexical events
  -    DTMManager dtmManager = XSLTCDTMManager.newInstance(
  -                 org.apache.xpath.objects.XMLStringFactoryImpl.getFactory());
  +		DTMManager dtmManager = XSLTCDTMManager.newInstance(
  +                   org.apache.xpath.objects.XMLStringFactoryImpl.getFactory());
       
  -    dom = (DOMImpl)dtmManager.getDTM(domsrc, false, null, true, true);
  -		//dom = new DOMImpl();
  -		final DOMBuilder builder = ((DOMImpl)dom).getBuilder();
  -		if (!isComplete) {
  -		    builder.startDocument();
  -		}
  -		if (!isComplete) {
  -		    builder.endDocument();
  -		}
  -		((DOMImpl)dom).setDocumentURI(_sourceSystemId);
  +		dom = (SAXImpl)dtmManager.getDTM(null, false, null, true,
  +                                                 true);
  +		final DOMBuilder builder = ((SAXImpl)dom).getBuilder();
  +		dom2sax.setContentHandler(builder);
  +
  +		dom2sax.parse();
  +
  +		((SAXImpl)dom).setDocumentURI(_sourceSystemId);
   	    }
   	    // Handle StreamSource input
  -	    else if (source instanceof StreamSource) 
  -      {
  +	    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();
  @@ -565,10 +470,10 @@
   
   		// Create a new internal DOM and set up its builder to trap
   		// all content/lexical events
  -    DTMManager dtmManager = XSLTCDTMManager.newInstance(
  +		DTMManager dtmManager = XSLTCDTMManager.newInstance(
                    org.apache.xpath.objects.XMLStringFactoryImpl.getFactory());
   
  -    InputSource input;
  +		InputSource input;
   		if (streamInput != null)
   		    input = new InputSource(streamInput);
   		else if (streamReader != null)
  @@ -579,10 +484,10 @@
   		    ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_NO_SOURCE_ERR);
   		    throw new TransformerException(err.toString());
   		}
  -    dom = (SAXImpl)dtmManager.getDTM(new SAXSource(reader, input), false, null, true, true);
  +		dom = (SAXImpl)dtmManager.getDTM(new SAXSource(reader, input),
  +                                                 false, null, true, true);
   		((SAXImpl)dom).setDocumentURI(_sourceSystemId);
   	    }
  -	    // Handle XSLTC-internal Source input
   	    else if (source instanceof XSLTCSource) {
   		final XSLTCSource xsltcsrc = (XSLTCSource)source;
   		dtd = xsltcsrc.getDTD();
  @@ -598,12 +503,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());
  @@ -623,49 +533,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 DOM dom = ((XSLTCSource) source).getDOM();
  +	    ((SAXImpl)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
  -	    DOM 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());
  @@ -850,18 +810,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;
  @@ -905,6 +864,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);
   	}
       }
   
  
  
  

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