You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by sa...@apache.org on 2002/07/23 18:33:42 UTC

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

santiagopg    2002/07/23 09:33:42

  Modified:    java/src/org/apache/xalan/xsltc/trax
                        TemplatesHandlerImpl.java TemplatesImpl.java
                        TransformerFactoryImpl.java TransformerImpl.java
  Log:
  Fixed for Bugzilla 10625. URIResolvers were being dropped in several places.
  
  Revision  Changes    Path
  1.13      +67 -9     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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- TemplatesHandlerImpl.java	26 Jun 2002 22:55:07 -0000	1.12
  +++ TemplatesHandlerImpl.java	23 Jul 2002 16:33:41 -0000	1.13
  @@ -57,6 +57,7 @@
    * <http://www.apache.org/>.
    *
    * @author Morten Jorgensen
  + * @author Santiago Pericas-Geertsen
    *
    */
   
  @@ -66,18 +67,32 @@
   import javax.xml.transform.sax.*;
   
   import org.xml.sax.Locator;
  +import org.xml.sax.InputSource;
  +
  +import org.apache.xalan.xsltc.compiler.*;
   import org.apache.xalan.xsltc.Translet;
   import org.apache.xalan.xsltc.runtime.AbstractTranslet;
  -import org.apache.xalan.xsltc.compiler.*;
  -import org.apache.xalan.xsltc.compiler.util.Util;
   
   /**
    * Implementation of a JAXP1.1 TemplatesHandler
    */
  -public class TemplatesHandlerImpl extends Parser implements TemplatesHandler {
  -
  +public class TemplatesHandlerImpl extends Parser 
  +    implements TemplatesHandler, SourceLoader 
  +{
  +    /**
  +     * System ID for this stylesheet.
  +     */
       private String _systemId;
  -    private int    _indentNumber;
  +
  +    /**
  +     * Number of spaces to add for output indentation.
  +     */
  +    private int _indentNumber;
  +
  +    /**
  +     * This URIResolver is passed to all Transformers.
  +     */
  +    private URIResolver _uriResolver = null;
   
       // Temporary
       private boolean _oldOutputSystem;
  @@ -125,6 +140,13 @@
       }
   
       /**
  +     * Store URIResolver needed for Transformers.
  +     */
  +    public void setURIResolver(URIResolver resolver) {
  +	_uriResolver = resolver;
  +    }
  +
  +    /**
        * Implements javax.xml.transform.sax.TemplatesHandler.getTemplates()
        * When a TemplatesHandler object is used as a ContentHandler or
        * DocumentHandler for the parsing of transformation instructions, it
  @@ -137,6 +159,11 @@
   	try {
   	    final XSLTC xsltc = getXSLTC();
   
  +	    // Set a document loader (for xsl:include/import) if defined
  +	    if (_uriResolver != null) {
  +		xsltc.setSourceLoader(this);
  +	    }
  +
   	    // Set the translet class name if not already set
   	    String transletName = TransformerFactoryImpl._defaultTransletName;
   	    if (_systemId != null) {
  @@ -171,8 +198,16 @@
   		// Check that the transformation went well before returning
   		final byte[][] bytecodes = xsltc.getBytecodes();
   		if (bytecodes != null) {
  -		    return new TemplatesImpl(xsltc.getBytecodes(), transletName, 
  -			 getOutputProperties(), _indentNumber, _oldOutputSystem);
  +		    final TemplatesImpl templates = 
  +			new TemplatesImpl(xsltc.getBytecodes(), transletName, 
  +			    getOutputProperties(), _indentNumber, 
  +			    _oldOutputSystem);
  +
  +		    // Set URIResolver on templates object
  +		    if (_uriResolver != null) {
  +			templates.setURIResolver(_uriResolver);
  +		    }
  +		    return templates;
   		}
   	    }
   	}
  @@ -183,12 +218,35 @@
       }
   
       /**
  -     * recieve an object for locating the origin of SAX document events.
  +     * Recieve an object for locating the origin of SAX document events.
        * Most SAX parsers will use this method to inform content handler
        * of the location of the parsed document. 
        */
       public void setDocumentLocator(Locator locator) {
     	setSystemId(locator.getSystemId());
  +    }
  +
  +    /**
  +     * This method implements XSLTC's SourceLoader interface. It is used to
  +     * glue a TrAX URIResolver to the XSLTC compiler's Input and Import classes.
  +     *
  +     * @param href The URI of the document to load
  +     * @param context The URI of the currently loaded document
  +     * @param xsltc The compiler that resuests the document
  +     * @return An InputSource with the loaded document
  +     */
  +    public InputSource loadSource(String href, String context, XSLTC xsltc) {
  +	try {
  +	    // A _uriResolver must be set if this method is called
  +	    final Source source = _uriResolver.resolve(href, context);
  +	    if (source != null) {
  +		return Util.getInputSource(xsltc, source);
  +	    }
  +	}
  +	catch (TransformerException e) {
  +	    // Falls through
  +	}
  +	return null;
       }
   }
   
  
  
  
  1.19      +23 -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.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- TemplatesImpl.java	22 Jul 2002 15:45:06 -0000	1.18
  +++ TemplatesImpl.java	23 Jul 2002 16:33:41 -0000	1.19
  @@ -123,6 +123,11 @@
        */
       private int _indentNumber;
   
  +    /**
  +     * This URIResolver is passed to all Transformers.
  +     */
  +    private URIResolver _uriResolver = null;
  +
       // Temporary
       private boolean _oldOutputSystem;
   
  @@ -168,6 +173,13 @@
       }
   
       /**
  +     * Store URIResolver needed for Transformers.
  +     */
  +    public void setURIResolver(URIResolver resolver) {
  +	_uriResolver = resolver;
  +    }
  +
  +    /**
        * The TransformerFactory must pass us the translet bytecodes using this
        * method before we can create any translet instances
        */
  @@ -317,9 +329,15 @@
        * @throws TransformerConfigurationException
        */
       public Transformer newTransformer()
  -	throws TransformerConfigurationException {
  -        return new TransformerImpl(getTransletInstance(), _outputProperties,
  -	    _indentNumber, _oldOutputSystem);
  +	throws TransformerConfigurationException 
  +    {
  +	final TransformerImpl transformer =
  +	    new TransformerImpl(getTransletInstance(), _outputProperties,
  +			        _indentNumber, _oldOutputSystem);
  +	if (_uriResolver != null) {
  +	    transformer.setURIResolver(_uriResolver);
  +	}
  +	return transformer;
       }
   
       /**
  @@ -330,8 +348,7 @@
        */
       public Properties getOutputProperties() { 
   	try {
  -	    Transformer transformer = newTransformer();
  -	    return transformer.getOutputProperties();
  +	    return newTransformer().getOutputProperties();
   	}
   	catch (TransformerConfigurationException e) {
   	    return null;
  
  
  
  1.44      +162 -161  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.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- TransformerFactoryImpl.java	20 Jul 2002 23:46:13 -0000	1.43
  +++ TransformerFactoryImpl.java	23 Jul 2002 16:33:41 -0000	1.44
  @@ -58,6 +58,7 @@
    *
    * @author G. Todd Miller 
    * @author Morten Jorgensen
  + * @author Santiago Pericas-Geertsen
    *
    */
   
  @@ -87,35 +88,45 @@
   import org.apache.xalan.xsltc.compiler.XSLTC;
   import org.apache.xalan.xsltc.compiler.SourceLoader;
   import org.apache.xalan.xsltc.compiler.CompilerException;
  -import org.apache.xalan.xsltc.compiler.util.Util;
   import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
   
   /**
    * Implementation of a JAXP1.1 TransformerFactory for Translets.
    */
   public class TransformerFactoryImpl
  -    extends SAXTransformerFactory implements SourceLoader, ErrorListener {
  -
  -    // This error listener is used only for this factory and is not passed to
  -    // the Templates or Transformer objects that we create!!!
  +    extends SAXTransformerFactory implements SourceLoader, ErrorListener 
  +{
  +    /**
  +     * This error listener is used only for this factory and is not passed to
  +     * the Templates or Transformer objects that we create.
  +     */
       private ErrorListener _errorListener = this; 
   
  -    // This URIResolver is passed to all created Templates and Transformers
  +    /**
  +     * This URIResolver is passed to all created Templates and Transformers
  +     */
       private URIResolver _uriResolver = null;
   
  -    // As Gregor Samsa awoke one morning from uneasy dreams he found himself
  -    // transformed in his bed into a gigantic insect. He was lying on his hard,
  -    // as it were armour plated, back, and if he lifted his head a little he
  -    // could see his big, brown belly divided into stiff, arched segments, on
  -    // top of which the bed quilt could hardly keep in position and was about
  -    // to slide off completely. His numerous legs, which were pitifully thin
  -    // compared to the rest of his bulk, waved helplessly before his eyes.
  -    // "What has happened to me?", he thought. It was no dream....
  +    /** 
  +     * As Gregor Samsa awoke one morning from uneasy dreams he found himself
  +     * transformed in his bed into a gigantic insect. He was lying on his hard,
  +     * as it were armour plated, back, and if he lifted his head a little he
  +     * could see his big, brown belly divided into stiff, arched segments, on
  +     * top of which the bed quilt could hardly keep in position and was about
  +     * to slide off completely. His numerous legs, which were pitifully thin
  +     * compared to the rest of his bulk, waved helplessly before his eyes.
  +     * "What has happened to me?", he thought. It was no dream....
  +     */
       protected static String _defaultTransletName = "GregorSamsa";
   
  -    // Cache for the newTransformer() method - see method for details
  +    /**
  +     * Cache for the newTransformer() method - see method for details
  +     */
       private Transformer _copyTransformer = null;
  -    // XSL document for the default transformer
  +
  +    /**
  +     * 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=\"/\">"+
  @@ -123,11 +134,15 @@
   	"</xsl:template>"+
   	"</xsl:stylesheet>";
   
  -    // This Hashtable is used to store parameters for locating
  -    // <?xml-stylesheet ...?> processing instructions in XML documents.
  +    /**
  +     * This Hashtable is used to store parameters for locating
  +     * <?xml-stylesheet ...?> processing instructions in XML docs.
  +     */
       private Hashtable _piParams = null;
   
  -    // The above hashtable stores objects of this class only:
  +    /**
  +     * The above hashtable stores objects of this class.
  +     */
       private class PIParamWrapper {
   	public String _media = null;
   	public String _title = null;
  @@ -140,18 +155,29 @@
   	}
       }
   
  -    // This flags are passed to the compiler
  +    /**
  +     * Set to <code>true</code> when debugging is enabled.
  +     */
       private boolean _debug = false;
  +
  +    /**
  +     * Set to <code>true</code> when templates are not inlined.
  +     */
       private boolean _disableInlining = false;
  +
  +    /**
  +     * Number of indent spaces when indentation is turned on.
  +     */
  +    private int _indentNumber = -1;
  +
  +    // Temporary
       private boolean _oldOutputSystem = false;
  -    private int     _indentNumber    = -1;
   
       /**
        * javax.xml.transform.sax.TransformerFactory implementation.
        * Contains nothing yet
        */
       public TransformerFactoryImpl() {
  -	// Don't need anything here so far...
       }
   
       /**
  @@ -164,7 +190,8 @@
        * @throws IllegalArgumentException
        */
       public void setErrorListener(ErrorListener listener) 
  -	throws IllegalArgumentException {
  +	throws IllegalArgumentException 
  +    {
   	if (listener == null) {
   	    ErrorMsg err = new ErrorMsg(ErrorMsg.ERROR_LISTENER_NULL_ERR,
   					"TransformerFactory");
  @@ -192,9 +219,13 @@
        * @throws IllegalArgumentException
        */
       public Object getAttribute(String name) 
  -	throws IllegalArgumentException { 
  +	throws IllegalArgumentException 
  +    { 
   	// Return value for attribute 'translet-name'
  -	if (name.equals("translet-name")) return(_defaultTransletName);
  +	if (name.equals("translet-name")) {
  +	    return _defaultTransletName;
  +	}
  +
   	// Throw an exception for all other attributes
   	ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_INVALID_ATTR_ERR, name);
   	throw new IllegalArgumentException(err.toString());
  @@ -289,10 +320,12 @@
   	    StreamResult.FEATURE
   	};
   
  -	// Inefficient, but it really does not matter in a function like this
  -	for (int i=0; i<features.length; i++)
  -	    if (name.equals(features[i])) return true;
  -
  +	// Inefficient, but array is small
  +	for (int i =0; i < features.length; i++) {
  +	    if (name.equals(features[i])) {
  +		return true;
  +	    }
  +	}
   	// Feature not supported
   	return false;
       }
  @@ -306,7 +339,7 @@
        * Templates and Transformer objects created using this factory
        */    
       public URIResolver getURIResolver() {
  -	return(_uriResolver);
  +	return _uriResolver;
       } 
   
       /**
  @@ -340,13 +373,16 @@
        */
       public Source getAssociatedStylesheet(Source source, String media,
   					  String title, String charset)
  -	throws TransformerConfigurationException {
  +	throws TransformerConfigurationException 
  +    {
   	// First create a hashtable that maps Source refs. to parameters
  -	if (_piParams == null) _piParams = new Hashtable();
  +	if (_piParams == null) {
  +	    _piParams = new Hashtable();
  +	}
   	// Store the parameters for this Source in the Hashtable
   	_piParams.put(source, new PIParamWrapper(media, title, charset));
   	// Return the same Source - we'll locate the stylesheet later
  -	return(source);
  +	return source;
       }
   
       /**
  @@ -357,11 +393,12 @@
        * @throws TransformerConfigurationException
        */    
       public Transformer newTransformer()
  -	throws TransformerConfigurationException { 
  -
  +	throws TransformerConfigurationException 
  +    { 
   	if (_copyTransformer != null) {
  -	    if (_uriResolver != null)
  +	    if (_uriResolver != null) {
   		_copyTransformer.setURIResolver(_uriResolver);
  +	    }
   	    return _copyTransformer;
   	}
   
  @@ -405,10 +442,13 @@
        * @throws TransformerConfigurationException
        */
       public Transformer newTransformer(Source source) throws
  -	TransformerConfigurationException {
  +	TransformerConfigurationException 
  +    {
   	final Templates templates = newTemplates(source);
   	final Transformer transformer = templates.newTransformer();
  -	if (_uriResolver != null) transformer.setURIResolver(_uriResolver);
  +	if (_uriResolver != null) {
  +	    transformer.setURIResolver(_uriResolver);
  +	}
   	return(transformer);
       }
   
  @@ -418,7 +458,7 @@
       private void passWarningsToListener(Vector messages) 
   	throws TransformerException 
       {
  -	if (_errorListener == null || messages == null ) {
  +	if (_errorListener == null || messages == null) {
   	    return;
   	}
   	// Pass messages to listener, one by one
  @@ -435,13 +475,12 @@
        */
       private void passErrorsToListener(Vector messages) {
   	try {
  -	    // Nothing to do if there is no registered error listener
  -	    if (_errorListener == null) return;
  -	    // Nothing to do if there are not warning messages
  -	    if (messages == null) return;
  +	    if (_errorListener == null || messages == null) {
  +		return;
  +	    }
   	    // Pass messages to listener, one by one
   	    final int count = messages.size();
  -	    for (int pos=0; pos<count; pos++) {
  +	    for (int pos = 0; pos < count; pos++) {
   		String message = messages.elementAt(pos).toString();
   		_errorListener.error(new TransformerException(message));
   	    }
  @@ -452,70 +491,6 @@
       }
   
       /**
  -     * Creates a SAX2 InputSource object from a TrAX Source object
  -     */
  -    private InputSource getInputSource(XSLTC xsltc, Source source)
  -	throws TransformerConfigurationException {
  -
  -	InputSource input = null;
  -	String systemId = source.getSystemId();
  -	if (systemId == null) systemId = "";
  -
  -	try {
  -
  -	    // Try to get InputSource from SAXSource input
  -	    if (source instanceof SAXSource) {
  -		final SAXSource sax = (SAXSource)source;
  -		input = sax.getInputSource();
  -		// Pass the SAX parser to the compiler
  -		xsltc.setXMLReader(sax.getXMLReader());
  -	    }
  -	    // handle  DOMSource  
  -	    else if (source instanceof DOMSource) {
  -		final DOMSource domsrc = (DOMSource)source;
  -		final Document dom = (Document)domsrc.getNode();
  -		final DOM2SAX dom2sax = new DOM2SAX(dom);
  -		xsltc.setXMLReader(dom2sax);  
  -	        // try to get SAX InputSource from DOM Source.
  -		input = SAXSource.sourceToInputSource(source);
  -		if (input == null){
  -			input = new InputSource(domsrc.getSystemId());
  -		}
  -	    }
  -	    // Try to get InputStream or Reader from StreamSource
  -	    else if (source instanceof StreamSource) {
  -		final StreamSource stream = (StreamSource)source;
  -		final InputStream istream = stream.getInputStream();
  -		final Reader reader = stream.getReader();
  -		// Create InputSource from Reader or InputStream in Source
  -		if (istream != null)
  -		    input = new InputSource(istream);
  -		else if (reader != null)
  -		    input = new InputSource(reader);
  -		else
  -		    input = new InputSource(systemId);
  -	    }
  -	    else {
  -		ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_UNKNOWN_SOURCE_ERR);
  -		throw new TransformerConfigurationException(err.toString());
  -	    }
  -	    input.setSystemId(systemId);
  -	}
  -	catch (NullPointerException e) {
  - 	    ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_NO_SOURCE_ERR,
  -					"TransformerFactory.newTemplates()");
  -	    throw new TransformerConfigurationException(err.toString());
  -	}
  -	catch (SecurityException e) {
  - 	    ErrorMsg err = new ErrorMsg(ErrorMsg.FILE_ACCESS_ERR, systemId);
  -	    throw new TransformerConfigurationException(err.toString());
  -	}
  -	finally {
  -	    return(input);
  -	}
  -    }
  -
  -    /**
        * javax.xml.transform.sax.TransformerFactory implementation.
        * Process the Source into a Templates object, which is a a compiled
        * representation of the source.
  @@ -525,7 +500,8 @@
        * @throws TransformerConfigurationException
        */
       public Templates newTemplates(Source source)
  -	throws TransformerConfigurationException {
  +	throws TransformerConfigurationException 
  +    {
   	// Create and initialize a stylesheet compiler
   	final XSLTC xsltc = new XSLTC();
   	if (_debug) xsltc.setDebug(true);
  @@ -533,7 +509,9 @@
   	xsltc.init();
   
   	// Set a document loader (for xsl:include/import) if defined
  -	if (_uriResolver != null) xsltc.setSourceLoader(this);
  +	if (_uriResolver != null) {
  +	    xsltc.setSourceLoader(this);
  +	}
   
   	// Pass parameters to the Parser to make sure it locates the correct
   	// <?xml-stylesheet ...?> PI in an XML input document
  @@ -541,12 +519,13 @@
   	    // Get the parameters for this Source object
   	    PIParamWrapper p = (PIParamWrapper)_piParams.get(source);
   	    // Pass them on to the compiler (which will pass then to the parser)
  -	    if (p != null) 
  +	    if (p != null) {
   		xsltc.setPIParameters(p._media, p._title, p._charset);
  +	    }
   	}
   
   	// Compile the stylesheet
  -	final InputSource input = getInputSource(xsltc, source);
  +	final InputSource input = Util.getInputSource(xsltc, source);
   	byte[][] bytecodes = xsltc.compile(null, input);
   	final String transletName = xsltc.getClassName();
   
  @@ -566,13 +545,16 @@
   	// Check that the transformation went well before returning
   	if (bytecodes == null) {
   	    // Pass compiler errors to the error listener
  -	    if (_errorListener != null)
  +	    if (_errorListener != null) {
   		passErrorsToListener(xsltc.getErrors());
  -	    else
  +	    }
  +	    else {
   		xsltc.printErrors();
  +	    }
   	    ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR);
   	    throw new TransformerConfigurationException(err.toString());
   	}
  +
   	return new TemplatesImpl(bytecodes, transletName, 
   	    xsltc.getOutputProperties(), _indentNumber, _oldOutputSystem);
       }
  @@ -586,10 +568,14 @@
        * @throws TransformerConfigurationException
        */
       public TemplatesHandler newTemplatesHandler() 
  -	throws TransformerConfigurationException { 
  +	throws TransformerConfigurationException 
  +    { 
   	final TemplatesHandlerImpl handler = 
   	    new TemplatesHandlerImpl(_indentNumber, _oldOutputSystem);
   	handler.init();
  +	if (_uriResolver != null) {
  +	    handler.setURIResolver(_uriResolver);
  +	}
   	return handler;
       }
   
  @@ -602,10 +588,13 @@
        * @throws TransformerConfigurationException
        */
       public TransformerHandler newTransformerHandler() 
  -	throws TransformerConfigurationException {
  +	throws TransformerConfigurationException 
  +    {
   	final Transformer transformer = newTransformer();
  -	final TransformerImpl internal = (TransformerImpl)transformer;
  -	return(new TransformerHandlerImpl(internal));
  +	if (_uriResolver != null) {
  +	    transformer.setURIResolver(_uriResolver);
  +	}
  +	return new TransformerHandlerImpl((TransformerImpl) transformer);
       }
   
       /**
  @@ -619,10 +608,13 @@
        * @throws TransformerConfigurationException
        */
       public TransformerHandler newTransformerHandler(Source src) 
  -	throws TransformerConfigurationException { 
  +	throws TransformerConfigurationException 
  +    { 
   	final Transformer transformer = newTransformer(src);
  -	final TransformerImpl internal = (TransformerImpl)transformer;
  -	return(new TransformerHandlerImpl(internal));
  +	if (_uriResolver != null) {
  +	    transformer.setURIResolver(_uriResolver);
  +	}
  +	return new TransformerHandlerImpl((TransformerImpl) transformer);
       }
   
       /**
  @@ -636,13 +628,13 @@
        * @throws TransformerConfigurationException
        */    
       public TransformerHandler newTransformerHandler(Templates templates) 
  -	throws TransformerConfigurationException  {
  +	throws TransformerConfigurationException  
  +    {
   	final Transformer transformer = templates.newTransformer();
   	final TransformerImpl internal = (TransformerImpl)transformer;
  -	return(new TransformerHandlerImpl(internal));
  +	return new TransformerHandlerImpl(internal);
       }
   
  -
       /**
        * javax.xml.transform.sax.SAXTransformerFactory implementation.
        * Create an XMLFilter that uses the given source as the
  @@ -653,9 +645,10 @@
        * @throws TransformerConfigurationException
        */
       public XMLFilter newXMLFilter(Source src) 
  -	throws TransformerConfigurationException {
  +	throws TransformerConfigurationException 
  +    {
   	Templates templates = newTemplates(src);
  -	if (templates == null ) return null; 
  +	if (templates == null) return null; 
   	return newXMLFilter(templates);
       }
   
  @@ -669,17 +662,18 @@
        * @throws TransformerConfigurationException
        */
       public XMLFilter newXMLFilter(Templates templates) 
  -	throws TransformerConfigurationException {
  +	throws TransformerConfigurationException 
  +    {
   	try {
         	    return new org.apache.xalan.xsltc.trax.TrAXFilter(templates);
       	}
  -	catch(TransformerConfigurationException e1) {
  -      	    if(_errorListener != null) {
  +	catch (TransformerConfigurationException e1) {
  +      	    if (_errorListener != null) {
                   try {
             	    _errorListener.fatalError(e1);
             	    return null;
           	}
  -		catch( TransformerException e2) {
  +		catch (TransformerException e2) {
             	    new TransformerConfigurationException(e2);
           	}
         	    }
  @@ -688,28 +682,6 @@
       }
   
       /**
  -     * This method implements XSLTC's SourceLoader interface. It is used to
  -     * glue a TrAX URIResolver to the XSLTC compiler's Input and Import classes.
  -     *
  -     * @param href The URI of the document to load
  -     * @param context The URI of the currently loaded document
  -     * @param xsltc The compiler that resuests the document
  -     * @return An InputSource with the loaded document
  -     */
  -    public InputSource loadSource(String href, String context, XSLTC xsltc) {
  -	try {
  -	    final Source source = _uriResolver.resolve(href, context);
  -	    if (source != null) {
  -		return getInputSource(xsltc, source);
  -	    }
  -	}
  -	catch (TransformerException e) {
  -	    // Falls through
  -	}
  -	return null;
  -    }
  -
  -    /**
        * Receive notification of a recoverable error. 
        * The transformer must continue to provide normal parsing events after
        * invoking this method. It should still be possible for the application
  @@ -721,12 +693,14 @@
        * the transformation (always does in our case).
        */
       public void error(TransformerException e)
  -	throws TransformerException {
  +	throws TransformerException 
  +    {
   	System.err.println("ERROR: "+e.getMessageAndLocation());
   	Throwable wrapped = e.getException();
  -	if (wrapped != null)
  +	if (wrapped != null) {
   	    System.err.println("     : "+wrapped.getMessage());
  -	throw(e); 	
  +	}
  +	throw e; 	
       }
   
       /**
  @@ -743,12 +717,14 @@
        * the transformation (always does in our case).
        */
       public void fatalError(TransformerException e)
  -	throws TransformerException {
  +	throws TransformerException 
  +    {
   	System.err.println("FATAL: "+e.getMessageAndLocation());
   	Throwable wrapped = e.getException();
  -	if (wrapped != null)
  +	if (wrapped != null) {
   	    System.err.println("     : "+wrapped.getMessage());
  -	throw(e);
  +	}
  +	throw e;
       }
   
       /**
  @@ -765,11 +741,36 @@
        * the transformation (never does in our case).
        */
       public void warning(TransformerException e)
  -	throws TransformerException {
  +	throws TransformerException 
  +    {
   	System.err.println("WARNING: "+e.getMessageAndLocation());
   	Throwable wrapped = e.getException();
  -	if (wrapped != null)
  +	if (wrapped != null) {
   	    System.err.println("       : "+wrapped.getMessage());
  +	}
       }
   
  +    /**
  +     * This method implements XSLTC's SourceLoader interface. It is used to
  +     * glue a TrAX URIResolver to the XSLTC compiler's Input and Import classes.
  +     *
  +     * @param href The URI of the document to load
  +     * @param context The URI of the currently loaded document
  +     * @param xsltc The compiler that resuests the document
  +     * @return An InputSource with the loaded document
  +     */
  +    public InputSource loadSource(String href, String context, XSLTC xsltc) {
  +	try {
  +	    if (_uriResolver != null) {
  +		final Source source = _uriResolver.resolve(href, context);
  +		if (source != null) {
  +		    return Util.getInputSource(xsltc, source);
  +		}
  +	    }
  +	}
  +	catch (TransformerException e) {
  +	    // Falls through
  +	}
  +	return null;
  +    }
   }
  
  
  
  1.53      +24 -16    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.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- TransformerImpl.java	8 Jul 2002 18:33:08 -0000	1.52
  +++ TransformerImpl.java	23 Jul 2002 16:33:41 -0000	1.53
  @@ -120,6 +120,11 @@
       private String           _encoding = null;
       private ContentHandler   _handler  = null;
   
  +    /**
  +     * SystemId set in input source.
  +     */
  +    private String _sourceSystemId = null;
  +
       private ErrorListener _errorListener = this;
       private URIResolver   _uriResolver = null;
       private Properties    _properties, _propertiesClone;
  @@ -460,13 +465,15 @@
   	    DOMImpl dom = null;
   	    DTDMonitor dtd = null;
   
  +	    // Get systemId from source
  +	    _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 String      systemId = sax.getSystemId();
   
   		// if reader was not set with setXMLReader by user,
   		// then we must create one ourselves.
  @@ -494,11 +501,11 @@
   
   		// Parse the input and build the internal DOM
   		reader.parse(input);
  -		dom.setDocumentURI(systemId);
  +		dom.setDocumentURI(_sourceSystemId);
   	    }
   	    // Handle DOMSource input
   	    else if (source instanceof DOMSource) {
  -		final DOMSource   domsrc = (DOMSource)source;
  +		final DOMSource domsrc = (DOMSource) source;
   		final org.w3c.dom.Node node = domsrc.getNode();
   
   		boolean isComplete = true;
  @@ -506,9 +513,8 @@
   		    isComplete = false;
   		}
   
  -		final DOM2SAX     dom2sax = new DOM2SAX(node);
  +		final DOM2SAX dom2sax = new DOM2SAX(node);
   		final InputSource input = null; 
  -		final String      systemId = domsrc.getSystemId(); 
   
   		// Create a DTD monitor to trap all DTD/declarative events
   		dtd = new DTDMonitor();
  @@ -528,7 +534,7 @@
   		if (!isComplete) {
   		    builder.endDocument();
   		}
  -		dom.setDocumentURI(systemId);
  +		dom.setDocumentURI(_sourceSystemId);
   	    }
   	    // Handle StreamSource input
   	    else if (source instanceof StreamSource) {
  @@ -536,7 +542,6 @@
   		final StreamSource stream = (StreamSource)source;
   		final InputStream  streamInput = stream.getInputStream();
   		final Reader streamReader = stream.getReader();
  -		final String systemId = stream.getSystemId();
   
   		// With a StreamSource we need to create our own parser
   		final SAXParserFactory factory = SAXParserFactory.newInstance();
  @@ -569,20 +574,23 @@
   		InputSource input;
   		if (streamInput != null) {
   		    input = new InputSource(streamInput);
  -		    input.setSystemId(systemId); 
  -		} else if (streamReader != null) {
  +		    input.setSystemId(_sourceSystemId); 
  +		} 
  +		else if (streamReader != null) {
   		    input = new InputSource(streamReader);
  -		    input.setSystemId(systemId); 
  -		} else if (systemId != null) {
  -		    input = new InputSource(systemId);
  -		} else {
  +		    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());
   		}
   
   		// Parse the input and build the internal DOM
   		reader.parse(input);
  -		dom.setDocumentURI(systemId);
  +		dom.setDocumentURI(_sourceSystemId);
   	    }
   	    // Handle XSLTC-internal Source input
   	    else if (source instanceof XSLTCSource) {
  @@ -1047,7 +1055,7 @@
        */
       public DOMImpl retrieveDocument(String uri, int mask, Translet translet) {
   	try {
  -	    return(getDOM(_uriResolver.resolve(uri, ""), mask));
  +	    return getDOM(_uriResolver.resolve(uri, _sourceSystemId), mask);
   	}
   	catch (TransformerException e) {
   	    if (_errorListener != null)
  
  
  

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