morten 01/07/20 08:24:33
Modified: java/src/org/apache/xalan/xsltc/compiler Import.java
Include.java Stylesheet.java XSLTC.java
java/src/org/apache/xalan/xsltc/trax
TransformerFactoryImpl.java TransformerImpl.java
Added: java/src/org/apache/xalan/xsltc/compiler SourceLoader.java
Log:
Added a SourceLoader interface to the compiler package. This interface can
be used to plug in an external document loader for imported and/or
included stylesheets. The trax.TransformerImpl class is updated to
implement this interface and act as an adapter between the internal XSLTC
SourceLoader interface and TrAX's URIResolver interface.
PR: n/a
Obtained from: n/a
Submitted by: [EMAIL PROTECTED]
Reviewed by: [EMAIL PROTECTED]
Revision Changes Path
1.6 +15 -3 xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Import.java
Index: Import.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Import.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Import.java 2001/07/19 18:48:31 1.5
+++ Import.java 2001/07/20 15:24:32 1.6
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Import.java,v 1.5 2001/07/19 18:48:31 morten Exp $
+ * @(#)$Id: Import.java,v 1.6 2001/07/20 15:24:32 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -90,17 +90,29 @@
try {
final String systemId = getAttribute("href");
if (context.checkForLoop(systemId)) {
- ErrorMsg msg = new ErrorMsg(ErrorMsg.CIRCULAR_INC,systemId,this);
+ final int errno = ErrorMsg.CIRCULAR_INC;
+ final ErrorMsg msg = new ErrorMsg(errno, systemId, this);
parser.reportError(Constants.FATAL, msg);
return;
}
- InputSource input = new InputSource(systemId);
+ SourceLoader loader = context.getSourceLoader();
+ InputSource input = null;
+ if (loader != null) {
+ final XSLTC xsltc = parser.getXSLTC();
+ final String base = context.getSystemId();
+ input = loader.loadSource(base, systemId, xsltc);
+ }
+ else {
+ input = new InputSource(systemId);
+ }
+
final SyntaxTreeNode root = parser.parse(input);
if (root == null) return;
final Stylesheet _imported = parser.makeStylesheet(root);
if (_imported == null) return;
+ _imported.setSourceLoader(loader);
_imported.setSystemId(systemId);
_imported.setParentStylesheet(context);
1.6 +16 -3 xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Include.java
Index: Include.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Include.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Include.java 2001/07/19 18:48:31 1.5
+++ Include.java 2001/07/20 15:24:32 1.6
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Include.java,v 1.5 2001/07/19 18:48:31 morten Exp $
+ * @(#)$Id: Include.java,v 1.6 2001/07/20 15:24:32 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -90,16 +90,29 @@
try {
final String systemId = getAttribute("href");
if (context.checkForLoop(systemId)) {
- ErrorMsg msg = new ErrorMsg(ErrorMsg.CIRCULAR_INC,systemId,this);
+ final int errno = ErrorMsg.CIRCULAR_INC;
+ final ErrorMsg msg = new ErrorMsg(errno, systemId, this);
parser.reportError(Constants.FATAL, msg);
return;
}
- InputSource input = new InputSource(systemId);
+
+ SourceLoader loader = context.getSourceLoader();
+ InputSource input = null;
+ if (loader != null) {
+ final XSLTC xsltc = parser.getXSLTC();
+ final String base = context.getSystemId();
+ input = loader.loadSource(base, systemId, xsltc);
+ }
+ else {
+ input = new InputSource(systemId);
+ }
+
final SyntaxTreeNode root = parser.parse(input);
if (root == null) return;
final Stylesheet _included = parser.makeStylesheet(root);
if (_included == null) return;
+ _included.setSourceLoader(loader);
_included.setSystemId(systemId);
_included.setParentStylesheet(context);
1.13 +12 -1
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Stylesheet.java
Index: Stylesheet.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Stylesheet.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Stylesheet.java 2001/07/19 18:48:31 1.12
+++ Stylesheet.java 2001/07/20 15:24:32 1.13
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Stylesheet.java,v 1.12 2001/07/19 18:48:31 morten Exp $
+ * @(#)$Id: Stylesheet.java,v 1.13 2001/07/20 15:24:32 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -121,6 +121,9 @@
private boolean _simplified = false;
+ private SourceLoader _loader = null;
+
+
public boolean isSimplified() {
return(_simplified);
}
@@ -202,6 +205,14 @@
public String getSystemId() {
return _systemId;
+ }
+
+ public void setSourceLoader(SourceLoader loader) {
+ _loader = loader;
+ }
+
+ public SourceLoader getSourceLoader() {
+ return _loader;
}
private QName makeStylesheetName(String prefix) {
1.18 +14 -1 xml-xalan/java/src/org/apache/xalan/xsltc/compiler/XSLTC.java
Index: XSLTC.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/XSLTC.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- XSLTC.java 2001/07/20 12:52:18 1.17
+++ XSLTC.java 2001/07/20 15:24:33 1.18
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: XSLTC.java,v 1.17 2001/07/20 12:52:18 morten Exp $
+ * @(#)$Id: XSLTC.java,v 1.18 2001/07/20 15:24:33 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -95,6 +95,9 @@
// A reference to an external XMLReader (SAX parser) passed to us
private XMLReader _reader = null;
+
+ // A reference to an external SourceLoader (for use with include/import)
+ private SourceLoader _loader = null;
// A reference to the stylesheet being compiled.
private Stylesheet _stylesheet = null;
@@ -178,6 +181,15 @@
-1 // LEVEL_ANY
};
}
+
+ /**
+ * Defines an external SourceLoader to provide the compiler with documents
+ * referenced in xsl:include/import
+ * @param loader The SourceLoader to use for include/import
+ */
+ public void setSourceLoader(SourceLoader loader) {
+ _loader = loader;
+ }
/**
* Compiles an XSL stylesheet pointed to by a URL
@@ -264,6 +276,7 @@
if ((!_parser.errorsFound()) && (element != null)) {
// Create a Stylesheet element from the root node
_stylesheet = _parser.makeStylesheet(element);
+ _stylesheet.setSourceLoader(_loader);
_stylesheet.setSystemId(systemId);
_stylesheet.setParentStylesheet(null);
_parser.setCurrentStylesheet(_stylesheet);
1.1
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/SourceLoader.java
Index: SourceLoader.java
===================================================================
/*
* @(#)$Id: SourceLoader.java,v 1.1 2001/07/20 15:24:32 morten 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 makterials 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 Morten Jorgensen
*
*/
package org.apache.xalan.xsltc.compiler;
import org.xml.sax.InputSource;
public interface SourceLoader {
/**
* This interface is used to plug external document loaders into XSLTC
* (used with the <xsl:include> and <xsl:import> elements.
*
* @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);
}
1.12 +116 -49
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.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- TransformerFactoryImpl.java 2001/07/20 14:41:06 1.11
+++ TransformerFactoryImpl.java 2001/07/20 15:24:33 1.12
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: TransformerFactoryImpl.java,v 1.11 2001/07/20 14:41:06 tmiller Exp $
+ * @(#)$Id: TransformerFactoryImpl.java,v 1.12 2001/07/20 15:24:33 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -64,6 +64,7 @@
package org.apache.xalan.xsltc.trax;
+import java.io.File;
import java.io.Reader;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
@@ -80,6 +81,7 @@
import org.apache.xalan.xsltc.Translet;
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.runtime.AbstractTranslet;
@@ -87,9 +89,10 @@
import org.w3c.dom.Document;
import javax.xml.transform.dom.DOMSource;
/**
- * Implementation of a JAXP1.1 SAXTransformerFactory for Translets.
+ * Implementation of a JAXP1.1 TransformerFactory for Translets.
*/
-public class TransformerFactoryImpl extends TransformerFactory {
+public class TransformerFactoryImpl
+ extends TransformerFactory implements SourceLoader {
// This constant should be removed once all abstract methods are impl'ed.
private static final String NYI = "Not yet implemented";
@@ -113,7 +116,11 @@
private static final String ERROR_LISTENER_NULL =
"Attempting to set ErrorListener for TransformerFactory to null";
private static final String UNKNOWN_SOURCE_ERR =
- "Only StreamSource and SAXSource is supported by XSLTC";
+ "Only StreamSource and SAXSource are supported by XSLTC";
+ private static final String NO_SOURCE_ERR =
+ "Source object passed to newTemplates() has no contents";
+ private static final String NO_ACCESS_ERR =
+ "Cannot access file or URL ";
private static final String COMPILE_ERR =
"Could not compile stylesheet";
@@ -264,7 +271,11 @@
public Transformer newTransformer()
throws TransformerConfigurationException {
- if (_copyTransformer != null) return _copyTransformer;
+ if (_copyTransformer != null) {
+ if (_uriResolver != null)
+ _copyTransformer.setURIResolver(_uriResolver);
+ return _copyTransformer;
+ }
byte[][] bytecodes = null; // The translet classes go in here
@@ -286,6 +297,7 @@
// Create a Transformer object and store for other calls
Templates templates = new TemplatesImpl(bytecodes, COPY_TRANSLET_NAME);
_copyTransformer = templates.newTransformer();
+ if (_uriResolver != null) _copyTransformer.setURIResolver(_uriResolver);
return(_copyTransformer);
}
@@ -301,8 +313,10 @@
*/
public Transformer newTransformer(Source source) throws
TransformerConfigurationException {
- Templates templates = newTemplates(source);
- return(templates.newTransformer());
+ final Templates templates = newTemplates(source);
+ final Transformer transformer = templates.newTransformer();
+ if (_uriResolver != null) transformer.setURIResolver(_uriResolver);
+ return(transformer);
}
/**
@@ -348,6 +362,73 @@
}
/**
+ * Creates a SAX2 InputSource object from a TrAX Source object
+ */
+ private InputSource getInputSource(XSLTC xsltc, Source source)
+ throws TransformerConfigurationException {
+
+ InputSource input = null;
+ final String systemId = source.getSystemId();
+
+ 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) {
+ throw new TransformerConfigurationException(
+ "DOMSource not supported
yet.");
+ /****
+ final DOMSource domsrc = (DOMSource)source;
+ final Document dom = (Document)domsrc.getNode();
+ final DOM2SAX dom2sax = new DOM2SAX(dom);
+ xsltc.setXMLReader(dom2sax);
+ input = null;
+ ****/
+ }
+ // 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 {
+ throw new TransformerConfigurationException(UNKNOWN_SOURCE_ERR);
+ }
+
+ // Try to create an InputStream from the SystemId if no input so far
+ if (input == null) {
+ if ((new File(systemId)).exists())
+ input = new InputSource("file:/"+systemId);
+ else
+ input = new InputSource(systemId);
+ }
+
+ // Pass system id to InputSource just to be on the safe side
+ input.setSystemId(systemId);
+ }
+ catch (NullPointerException e) {
+ throw new TransformerConfigurationException(NO_SOURCE_ERR);
+ }
+ catch (SecurityException e) {
+ throw new TransformerConfigurationException(NO_ACCESS_ERR+systemId);
+ }
+ 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.
@@ -363,52 +444,15 @@
byte[][] bytecodes = null;
// Create and initialize a stylesheet compiler
- XSLTC xsltc = new XSLTC();
+ final XSLTC xsltc = new XSLTC();
xsltc.init();
-
- InputSource input = null;
- final String systemId = source.getSystemId();
- // 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) {
- throw new TransformerConfigurationException(
- "DOMSource not supported yet.");
- /****
- final DOMSource domsrc = (DOMSource)source;
- final Document dom = (Document)domsrc.getNode();
- final DOM2SAX dom2sax = new DOM2SAX(dom);
- xsltc.setXMLReader(dom2sax);
- input = null;
- ****/
- }
- // 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 {
- throw new TransformerConfigurationException(UNKNOWN_SOURCE_ERR);
- }
-
- // Try to create an InputStream from the SystemId if no input so far
- if (input == null) input = new InputSource(systemId);
+ // Set a document loader (for xsl:include/import) if defined
+ if (_uriResolver != null)
+ xsltc.setSourceLoader(this);
- // Pass system id to InputSource just to be on the safe side
- input.setSystemId(systemId);
// Compile the stylesheet
+ final InputSource input = getInputSource(xsltc, source);
bytecodes = xsltc.compile(null, input);
final String transletName = xsltc.getClassName();
@@ -530,6 +574,29 @@
}
throw e1;
}
+ }
+
+ /**
+ * 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);
+ final InputSource input = getInputSource(xsltc, source);
+ return(input);
+ }
+ catch (TransformerConfigurationException e) {
+ return null;
+ }
+ catch (TransformerException e) {
+ return null;
+ }
}
}
1.8 +77 -31
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.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- TransformerImpl.java 2001/07/20 11:56:48 1.7
+++ TransformerImpl.java 2001/07/20 15:24:33 1.8
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: TransformerImpl.java,v 1.7 2001/07/20 11:56:48 morten Exp $
+ * @(#)$Id: TransformerImpl.java,v 1.8 2001/07/20 15:24:33 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -63,6 +63,7 @@
package org.apache.xalan.xsltc.trax;
+import java.io.File;
import java.io.Writer;
import java.io.Reader;
import java.io.InputStream;
@@ -91,13 +92,14 @@
import org.apache.xalan.xsltc.Translet;
import org.apache.xalan.xsltc.TransletException;
+import org.apache.xalan.xsltc.DOMCache;
import org.apache.xalan.xsltc.dom.*;
import org.apache.xalan.xsltc.runtime.*;
import org.apache.xalan.xsltc.compiler.*;
import java.util.Properties;
-public final class TransformerImpl extends Transformer {
+public final class TransformerImpl extends Transformer implements DOMCache {
private AbstractTranslet _translet = null;
private String _encoding = null;
@@ -139,10 +141,15 @@
public void transform(Source source, Result result)
throws TransformerException {
- // Verify the input
- if (_translet == null) throw new TransformerException(TRANSLET_ERR_MSG);
+ if (_translet == null)
+ throw new TransformerException(TRANSLET_ERR_MSG);
+
_handler = getOutputHandler(result);
- if (_handler == null) throw new TransformerException(HANDLER_ERR_MSG);
+ if (_handler == null)
+ throw new TransformerException(HANDLER_ERR_MSG);
+
+ if (_uriResolver != null)
+ _translet.setDOMCache(this);
// Run the transformation
transform(source, _handler, _encoding);
@@ -163,7 +170,7 @@
_encoding = "utf-8"; // default output encoding
try {
- final String systemId = result.getSystemId();
+ String systemId = result.getSystemId();
// Handle SAXResult output handler
if (result instanceof SAXResult) {
@@ -187,6 +194,8 @@
// Common, final handling of all input sources, only used if the
// other contents of the Result object could not be used
if (systemId != null) {
+ if ((new File(systemId)).exists())
+ systemId = "file:/"+systemId;
final URL url = new URL(systemId);
final URLConnection connection = url.openConnection();
final OutputStream ostream = connection.getOutputStream();
@@ -206,13 +215,12 @@
throw new TransformerException(e);
}
}
-
+
/**
- * Internal transformation method - uses the internal APIs of XSLTC
+ * Builds an internal DOM from a TrAX Source object
*/
- private void transform(Source source,
- ContentHandler outputHandler,
- String encoding) throws TransformerException {
+ private DOMImpl getDOM(Source source, int mask)
+ throws TransformerException {
try {
// Create an internal DOM (not W3C) and get SAX2 input handler
final DOMImpl dom = new DOMImpl();
@@ -263,32 +271,16 @@
dom.setDocumentURI(systemId);
}
else {
- throw new TransformerException("Unsupported input.");
+ return null;
}
-
+
// Set size of key/id indices
_translet.setIndexSize(dom.getSize());
// If there are any elements with ID attributes, build an index
- dtdMonitor.buildIdIndex(dom, 0, _translet);
+ dtdMonitor.buildIdIndex(dom, mask, _translet);
// Pass unparsed entity URIs to the translet
_translet.setDTDMonitor(dtdMonitor);
-
- // Pass output properties to the translet
- setOutputProperties(_translet, _properties);
-
- // Transform the document
- TextOutput textOutput = new TextOutput(outputHandler, _encoding);
- _translet.transform(dom, textOutput);
- }
- catch (TransletException e) {
- if (_errorListener != null)
- postErrorToListener(e.getMessage());
- throw new TransformerException(e);
- }
- catch (RuntimeException e) {
- if (_errorListener != null)
- postErrorToListener("Runtime Error: " + e.getMessage());
- throw new TransformerException(e);
+ return dom;
}
catch (FileNotFoundException e) {
if (_errorListener != null)
@@ -311,6 +303,36 @@
throw new TransformerException(e);
}
}
+
+ /**
+ * Internal transformation method - uses the internal APIs of XSLTC
+ */
+ private void transform(Source src, ContentHandler handler, String encoding)
+ throws TransformerException {
+ try {
+ // Build an iternal DOMImpl from the TrAX Source
+ DOMImpl dom = getDOM(src, 0);
+ // Pass output properties to the translet
+ setOutputProperties(_translet, _properties);
+ // Transform the document
+ _translet.transform(dom, new TextOutput(handler, _encoding));
+ }
+ catch (TransletException e) {
+ if (_errorListener != null)
+ postErrorToListener(e.getMessage());
+ throw new TransformerException(e);
+ }
+ catch (RuntimeException e) {
+ if (_errorListener != null)
+ postErrorToListener("Runtime Error: " + e.getMessage());
+ throw new TransformerException(e);
+ }
+ catch (Exception e) {
+ if (_errorListener != null)
+ postErrorToListener("Internal error: " + e.getMessage());
+ throw new TransformerException(e);
+ }
+ }
/**
* Implements JAXP's Transformer.getErrorListener()
@@ -603,4 +625,28 @@
_uriResolver = resolver;
}
+ /**
+ * This class should only be used as a DOMCache for the translet if the
+ * URIResolver has been set.
+ *
+ * The method implements XSLTC's DOMCache interface, which is used to
+ * plug in an external document loader into a translet. This method acts
+ * as an adapter between TrAX's URIResolver interface and XSLTC's
+ * DOMCache interface. This approach is simple, but removes the
+ * possibility of using external document caches with XSLTC.
+ *
+ * @param uri An URI pointing to the document location
+ * @param mask Contains a document ID (passed from the translet)
+ * @param translet A reference to the translet requesting the document
+ */
+ public DOMImpl retrieveDocument(String uri, int mask, Translet translet) {
+ try {
+ return(getDOM(_uriResolver.resolve(uri, ""), mask));
+ }
+ catch (TransformerException e) {
+ if (_errorListener != null)
+ postErrorToListener("File not found: " + e.getMessage());
+ return(null);
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]