morten 01/07/12 08:55:12
Modified: java/src/org/apache/xalan/xsltc/compiler XSLTC.java
java/src/org/apache/xalan/xsltc/runtime
AbstractTranslet.java
java/src/org/apache/xalan/xsltc/trax TemplatesImpl.java
TransformerFactoryImpl.java TransformerImpl.java
Removed: java/src/org/apache/xalan/xsltc/trax TransletTemplates.java
Log:
A first stab at our new TrAX design.`
Submitted by: [EMAIL PROTECTED]
Reviewed by: [EMAIL PROTECTED]
Revision Changes Path
1.14 +18 -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.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- XSLTC.java 2001/07/12 12:54:40 1.13
+++ XSLTC.java 2001/07/12 15:54:44 1.14
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: XSLTC.java,v 1.13 2001/07/12 12:54:40 morten Exp $
+ * @(#)$Id: XSLTC.java,v 1.14 2001/07/12 15:54:44 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -314,6 +314,23 @@
_outputType = BYTEARRAY_OUTPUT;
setClassName(className);
if (compile(stylesheetURL)) {
+ final int count = _classes.size();
+ final byte[][] result = new byte[1][count];
+ for (int i = 0; i < count; i++)
+ result[i] = (byte[])_classes.elementAt(i);
+ return result;
+ }
+ return null;
+ }
+
+ /**
+ * Compiles a stylesheet pointed to by a URL. The result is put in a
+ * set of byte arrays. One byte array for each generated class.
+ */
+ public byte[][] compile(InputStream source, String className, int dummy)
{
+ _outputType = BYTEARRAY_OUTPUT;
+ setClassName(className);
+ if (compile(source, className)) {
final int count = _classes.size();
final byte[][] result = new byte[1][count];
for (int i = 0; i < count; i++)
1.11 +9 -286
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/AbstractTranslet.java
Index: AbstractTranslet.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/AbstractTranslet.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- AbstractTranslet.java 2001/07/09 10:17:52 1.10
+++ AbstractTranslet.java 2001/07/12 15:54:50 1.11
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: AbstractTranslet.java,v 1.10 2001/07/09 10:17:52 morten Exp $
+ * @(#)$Id: AbstractTranslet.java,v 1.11 2001/07/12 15:54:50 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -77,35 +77,8 @@
import org.apache.xalan.xsltc.dom.KeyIndex;
import org.apache.xalan.xsltc.dom.DTDMonitor;
-// GTM added all these
-import org.apache.xalan.xsltc.runtime.DefaultSAXOutputHandler;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.Source;
-import javax.xml.transform.Result;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.URIResolver;
-import javax.xml.transform.ErrorListener;
-import javax.xml.transform.OutputKeys;
-import java.lang.IllegalArgumentException;
-import java.util.Properties;
-import java.lang.IllegalArgumentException;
-import javax.xml.parsers.SAXParserFactory;
-import javax.xml.parsers.SAXParser;
-import org.xml.sax.XMLReader;
-import org.xml.sax.ContentHandler;
-import java.io.File;
-import java.io.Writer;
-import java.io.OutputStream;
-import java.io.FileOutputStream;
-import java.io.FileNotFoundException;
-import java.net.MalformedURLException;
-import java.net.UnknownHostException;
-// END.
+public abstract class AbstractTranslet implements Translet {
-public abstract class AbstractTranslet extends Transformer implements
Translet {
-
// DOM/translet handshaking - the arrays are set by the compiled translet
protected String[] namesArray;
protected String[] namespaceArray;
@@ -200,6 +173,13 @@
}
/**
+ * Clears the parameter stack.
+ */
+ public void clearParameters() {
+ paramsStack.clear();
+ }
+
+ /**
* Get the value of a parameter from the current frame or
* <tt>null</tt> if undefined.
*/
@@ -543,263 +523,6 @@
*/
public String getTransletName() {
return _transletName;
- }
-
- /************************************************************************
- * JAXP/TrAX Transformer interface implementation + etc. TrAX/JAXP stuff
- * This will be moved to org/apache/xalan/xsltc/trax/Transformer
-
************************************************************************/
-
- public void transform(Source xmlsrc, Result outputTarget)
- throws TransformerException {
-
- // try to get the encoding from Translet
- final Translet translet = (Translet)this;
- String encoding = translet.getOutputEncoding();
- if (encoding == null) encoding = "UTF-8";
-
- // create a DefaultSAXOutputHandler
- DefaultSAXOutputHandler saxHandler = null;
- StreamResult target = (StreamResult)outputTarget;
- java.io.Writer writer = target.getWriter();
- java.io.OutputStream os = target.getOutputStream();
- String systemid = target.getSystemId();
- if (writer != null) {
- // no constructor that takes encoding yet...
- try {
- saxHandler = new DefaultSAXOutputHandler(writer);
- } catch (java.io.IOException e) {
- throw new TransformerException(
- "IOException creating DefaultSAXOutputHandler");
- }
- } else if (os != null) {
- try {
- saxHandler = new DefaultSAXOutputHandler(os, encoding);
- } catch (java.io.IOException e) {
- throw new TransformerException(
- "IOException creating DefaultSAXOutputHandler");
- }
- } else if (systemid != null) {
- String filePrefix = new String("file:///");
- if (systemid.startsWith(filePrefix)) {
- systemid = systemid.substring(filePrefix.length());
- }
- try {
- saxHandler = new DefaultSAXOutputHandler(
- ((OutputStream)new FileOutputStream(systemid)),
- encoding);
- } catch (java.io.FileNotFoundException e) {
- throw new TransformerException(
- "Transform output target could not be opened.");
- } catch (java.io.IOException e) {
- throw new TransformerException(
- "Transform output target could not be opened.");
- }
- }
-
- // finally do the transformation...
- doTransform(xmlsrc.getSystemId(), saxHandler, encoding);
- }
-
- private void doTransform(String xmlDocName,
- ContentHandler saxHandler,
- String encoding) {
- try {
- // Create a SAX parser and get the XMLReader object it uses
- final SAXParserFactory factory = SAXParserFactory.newInstance();
- final SAXParser parser = factory.newSAXParser();
- final XMLReader reader = parser.getXMLReader();
-
- // Set the DOM's DOM builder as the XMLReader's SAX2 content handler
- final DOMImpl dom = new DOMImpl();
- reader.setContentHandler(dom.getBuilder());
- // Create a DTD monitor and pass it to the XMLReader object
- final DTDMonitor dtdMonitor = new DTDMonitor();
- dtdMonitor.handleDTD(reader);
-
- dom.setDocumentURI(xmlDocName);
- if (xmlDocName.startsWith("file:/")) {
- reader.parse(xmlDocName);
- } else {
- reader.parse("file:"+(new File(xmlDocName).getAbsolutePath()));
- }
-
- // Set size of key/id indices
- setIndexSize(dom.getSize());
- // If there are any elements with ID attributes, build an index
- dtdMonitor.buildIdIndex(dom, 0, this);
- // Pass unparsed entity URIs to the translet (this)
- setDTDMonitor(dtdMonitor);
-
- // Transform the document
- TextOutput textOutput = new TextOutput(saxHandler, encoding);
- transform(dom, textOutput);
- }
- catch (TransletException e) {
- if (_errorListener != null) {
- postErrorToListener(e.getMessage());
- } else {
- System.err.println("\nTranslet Error: " + e.getMessage());
- }
- System.exit(1);
- }
- catch (RuntimeException e) {
- if (_errorListener != null) {
- postErrorToListener("Runtime Error: " + e.getMessage());
- } else {
- System.err.println("\nRuntime Error: " + e.getMessage());
- }
- System.exit(1);
- }
- catch (FileNotFoundException e) {
- if (_errorListener != null) {
- postErrorToListener("File not found: " + e.getMessage());
- } else {
- System.err.println("Error: File not found:"+e.getMessage());
- }
- System.exit(1);
- }
- catch (MalformedURLException e) {
- if (_errorListener != null) {
- postErrorToListener("Malformed URL: " + e.getMessage());
- } else {
- System.err.println("Error: Malformed URL: "+e.getMessage());
- }
- System.exit(1);
- }
- catch (UnknownHostException e) {
- if (_errorListener != null) {
- postErrorToListener("Cannot resolve URI: " + e.getMessage());
- } else {
- System.err.println("Error: Cannot resolve URI: "+
- e.getMessage());
- }
- System.exit(1);
- }
- catch (Exception e) {
- if (_errorListener != null) {
- postErrorToListener("Internal error: " + e.getMessage());
- } else {
- System.err.println("Internal error: "+e.getMessage());
- e.printStackTrace();
- }
- System.exit(1);
- }
- }
-
- // TrAX support methods, get/setErrorListener
- private ErrorListener _errorListener = null;
-
- /**
- * Get the TrAX error listener
- */
- public ErrorListener getErrorListener() {
- return _errorListener;
- }
-
- /**
- * Set the TrAX error listener
- */
- public void setErrorListener(ErrorListener listener)
- throws IllegalArgumentException {
- if (listener == null) {
- throw new IllegalArgumentException(
- "Error: setErrorListener() call where ErrorListener is null");
- }
- _errorListener = listener;
- }
-
- /**
- * Inform TrAX error listener of an error
- */
- private void postErrorToListener(String msg) {
- try {
- _errorListener.error(new TransformerException(
- "Translet Error: " + msg));
- } catch (TransformerException e) {
- // TBD
- }
- }
-
- /**
- * Inform TrAX error listener of a warning
- */
- private void postWarningToListener(String msg) {
- try {
- _errorListener.warning(new TransformerException(
- "Translet Warning: " + msg));
- } catch (TransformerException e) {
- // TBD
- }
- }
-
- /**
- * Implements JAXP's Transformer.getOutputProperties().
- * Returns a copy of the output properties for the transformation.
- */
- public Properties getOutputProperties() throws IllegalArgumentException
{
- // TODO
- return(null);
- }
-
- /**
- * Implements JAXP's Transformer.getOutputProperty().
- * Set an output property that will be in effect for the transformation.
- */
- public String getOutputProperty(String name)
- throws IllegalArgumentException {
- // TODO
- return(null);
- }
-
- /**
- * Implements JAXP's Transformer.setOutputProperties().
- * Set the output properties for the transformation. These properties
- * will override properties set in the Templates with xsl:output.
- */
- public void setOutputProperties(Properties props)
- throws IllegalArgumentException {
- // TODO
- }
-
- /**
- * Implements JAXP's Transformer.setOutputProperty().
- * Get an output property that is in effect for the transformation. The
- * property specified may be a property that was set with
- * setOutputProperty(), or it may be a property specified in the
stylesheet.
- */
- public void setOutputProperty(String name, String value)
- throws IllegalArgumentException {
- // TODO
- }
-
- /**
- * Implements JAXP's Transformer.setParameter()
- * Add a parameter for the transformation.
- */
- public void setParameter(String name, Object value) {
- addParameter(name, value, false);
- }
-
- /**
- * Implements JAXP's Transformer.clearParameters()
- * Clears the parameter stack.
- */
- public void clearParameters() {
- paramsStack.clear();
- }
-
- /**
- * These two methods need to pass the URI resolver to the
dom/LoadDocument
- * class, which again must use the URI resolver if present.
- */
- public URIResolver getURIResolver() {
- // TBD
- return null;
- }
-
- public void setURIResolver(URIResolver resolver) {
- // TBD
}
}
1.2 +31 -2
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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TemplatesImpl.java 2001/07/12 12:54:46 1.1
+++ TemplatesImpl.java 2001/07/12 15:54:56 1.2
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: TemplatesImpl.java,v 1.1 2001/07/12 12:54:46 morten Exp $
+ * @(#)$Id: TemplatesImpl.java,v 1.2 2001/07/12 15:54:56 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -57,6 +57,7 @@
* <http://www.apache.org/>.
*
* @author Morten Jorgensen
+ * @author G. Todd Miller
*
*/
@@ -68,7 +69,9 @@
import org.apache.xalan.xsltc.compiler.*;
import org.apache.xalan.xsltc.runtime.*;
-public abstract class TemplatesImpl implements Templates {
+import java.util.Properties;
+
+public final class TemplatesImpl implements Templates {
private String _transletName = null;
private byte[][] _bytecodes = null;
@@ -81,6 +84,14 @@
}
/**
+ *
+ */
+ public TemplatesImpl(byte[][] bytecodes, String transletName) {
+ _bytecodes = bytecodes;
+ _transletName = transletName;
+ }
+
+ /**
* The TransformerFactory must pass us the translet bytecodes using this
* method before we can create any translet instances
*/
@@ -154,6 +165,24 @@
catch (LinkageError e) { return(null); }
catch (InstantiationException e) { return(null); }
catch (IllegalAccessException e) { return(null); }
+ }
+
+ /**
+ * JAXP interface implementation
+ */
+ public Transformer newTransformer() throws
+ TransformerConfigurationException {
+ Translet translet = getTransletInstance();
+ TransformerImpl transformer = new TransformerImpl(translet);
+ return(transformer);
+ }
+
+ /**
+ * JAXP interface implementation - UNFINISHED!!!
+ */
+ public Properties getOutputProperties() {
+ // TODO
+ return new Properties();
}
}
1.5 +42 -58
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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TransformerFactoryImpl.java 2001/07/12 14:26:03 1.4
+++ TransformerFactoryImpl.java 2001/07/12 15:54:59 1.5
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: TransformerFactoryImpl.java,v 1.4 2001/07/12 14:26:03 tmiller
Exp $
+ * @(#)$Id: TransformerFactoryImpl.java,v 1.5 2001/07/12 15:54:59 morten Exp
$
*
* The Apache Software License, Version 1.1
*
@@ -249,80 +249,64 @@
// End TransformerFactory methods
//////////////////////////////////////////////////////
+ /**
+ *
+ */
+ public Transformer newTransformer(Source source) throws
+ TransformerConfigurationException {
+ Templates templates = newTemplates(source);
+ return(templates.newTransformer());
+ }
- public Transformer newTransformer(Source stylesheet) throws
- TransformerConfigurationException
- {
+ /**
+ *
+ */
+ public Templates newTemplates(Source stylesheet) throws
+ TransformerConfigurationException {
+
XSLTC xsltc = new XSLTC();
xsltc.init();
- // check if destination has been set with system property
+ // Check if destination has been set with system property
+ // TODO: We probably have to change this.
+ // Xalan might already have a property defined for this
String transletDestDir = System.getProperty("transletPool");
if (transletDestDir != null) {
xsltc.setDestDirectory(transletDestDir);
}
- // compile stylesheet
- boolean isSuccessful = true;
- StreamSource strmsrc = (StreamSource)stylesheet;
- InputStream inputStream = strmsrc.getInputStream();
+ // Get down to business: Compile the stylesheet
+ InputStream inputStream =
((StreamSource)stylesheet).getInputStream();
String stylesheetName = stylesheet.getSystemId();
- String transletName = "no_name";
- if (inputStream != null) {
- isSuccessful = xsltc.compile(inputStream, transletName);
- } else if (stylesheetName != null ){
- transletName = Util.toJavaName(Util.noExtName(
- Util.baseName(stylesheetName)));
- try {
+ URL url = null;
+
+ // Attempt to get a decent name for the translet...
+ String transletName = "undefined";
+ if (stylesheetName != null) {
+ final String base = Util.baseName(stylesheetName);
+ final String noext = Util.noExtName(base);
+ transletName = Util.toJavaName(noext);
+ try {
if (stylesheetName.startsWith("file:/")) {
- isSuccessful = xsltc.compile(new URL(stylesheetName));
+ url = new URL(stylesheetName);
} else {
- File file = new File(stylesheetName);
- URL url = file.toURL();
- isSuccessful = xsltc.compile(url);
+ url = (new File(stylesheetName)).toURL();
}
- } catch (MalformedURLException e) {
- throw new TransformerConfigurationException(
- "URL for stylesheet '" + stylesheetName +
- "' can not be formed.");
- }
- } else {
- throw new TransformerConfigurationException(
- "Stylesheet must have a system id or be an InputStream.");
- }
-
- if (!isSuccessful) {
- throw new TransformerConfigurationException(
- "Compilation of stylesheet '" + stylesheetName + "' failed.");
+ }
+ catch (MalformedURLException e) { url = null; }
}
- Translet translet = null;
- try {
- Class clazz = Class.forName(transletName);
- translet = (Translet)clazz.newInstance();
- ((AbstractTranslet)translet).setTransletName(transletName);
- // GTM
- if (_errorListener != null) {
- ((AbstractTranslet)translet).setErrorListener(_errorListener);
- }
- } catch (ClassNotFoundException e) {
- throw new TransformerConfigurationException(
- "Translet class '" + transletName + "' not found.");
- } catch (InstantiationException e) {
- throw new TransformerConfigurationException(
- "Translet class '" + transletName +
- "' could not be instantiated");
- } catch (IllegalAccessException e) {
+ byte[][] bytecodes = null;
+
+ if (url != null)
+ bytecodes = xsltc.compile(url, transletName);
+ else if (inputStream != null)
+ bytecodes = xsltc.compile(inputStream, transletName, 77);
+ else
throw new TransformerConfigurationException(
- "Translet class '" + transletName + "' could not be accessed.");
- }
- return (AbstractTranslet)translet;
- }
+ "Stylesheet must have a system id or be an InputStream.");
- public Templates newTemplates(Source stylesheet) throws
- TransformerConfigurationException
- {
- return new TransletTemplates(stylesheet);
+ return(new TemplatesImpl(bytecodes, transletName));
}
private ErrorListener _errorListener = null;
1.2 +284 -6
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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TransformerImpl.java 2001/07/12 12:54:46 1.1
+++ TransformerImpl.java 2001/07/12 15:55:00 1.2
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: TransformerImpl.java,v 1.1 2001/07/12 12:54:46 morten Exp $
+ * @(#)$Id: TransformerImpl.java,v 1.2 2001/07/12 15:55:00 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -57,24 +57,302 @@
* <http://www.apache.org/>.
*
* @author Morten Jorgensen
+ * @author G. Todd Miller
*
*/
package org.apache.xalan.xsltc.trax;
+import java.io.File;
+import java.io.Writer;
+import java.io.OutputStream;
+import java.io.FileOutputStream;
+import java.io.FileNotFoundException;
+import java.net.MalformedURLException;
+import java.net.UnknownHostException;
+import java.lang.IllegalArgumentException;
+
+import org.xml.sax.XMLReader;
+import org.xml.sax.ContentHandler;
+
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.*;
+import javax.xml.transform.stream.StreamResult;
import org.apache.xalan.xsltc.Translet;
+import org.apache.xalan.xsltc.TransletException;
+import org.apache.xalan.xsltc.dom.*;
+import org.apache.xalan.xsltc.runtime.*;
+import org.apache.xalan.xsltc.compiler.*;
+
+import java.util.Properties;
-public abstract class TransformerImpl extends Transformer {
+public final class TransformerImpl extends Transformer {
- Translet _translet = null;
+ private AbstractTranslet _translet = null;
+ private String _encoding = null;
+ private ContentHandler _handler = null;
public TransformerImpl(Translet translet) {
- _translet = translet;
+ _translet = (AbstractTranslet)translet;
+ }
+
+ public void transform(Source source, Result result)
+ throws TransformerException {
+
+ if (_translet == null) return;
+ _handler = getOutputHandler(result);
+ if (_handler == null) return;
+
+ // finally do the transformation...
+ doTransform(source.getSystemId(), _handler, _encoding);
+ }
+
+ private ContentHandler getOutputHandler(Result result) {
+ // Try to get the encoding from Translet (may not be set)
+ _encoding = _translet.getOutputEncoding();
+ if (_encoding == null) _encoding = "UTF-8";
+
+ StreamResult target = (StreamResult)result;
+ Writer writer = target.getWriter();
+ OutputStream ostream = target.getOutputStream();
+ String systemid = target.getSystemId();
+
+ try {
+ if (writer != null) {
+ // no constructor that takes encoding yet...
+ return (new DefaultSAXOutputHandler(writer));
+ }
+ else if (ostream != null) {
+ return (new DefaultSAXOutputHandler(ostream, _encoding));
+ }
+ else if (systemid != null) {
+ String filePrefix = new String("file:///");
+ if (systemid.startsWith(filePrefix)) {
+ systemid = systemid.substring(filePrefix.length());
+ }
+ ostream = (OutputStream)(new FileOutputStream(systemid));
+ return(new DefaultSAXOutputHandler(ostream, _encoding));
+ }
+ }
+ catch (java.io.FileNotFoundException e) {
+ throw new TransformerException(e);
+ }
+ catch (java.io.IOException e) {
+ throw new TransformerException(e);
+ }
+ finally {
+ return null;
+ }
+ }
+
+ private void doTransform(String source, ContentHandler handler,
+ String encoding) {
+ try {
+ // Create a SAX parser and get the XMLReader object it uses
+ final SAXParserFactory factory = SAXParserFactory.newInstance();
+ final SAXParser parser = factory.newSAXParser();
+ final XMLReader reader = parser.getXMLReader();
+
+ // Set the DOM's DOM builder as the XMLReader's SAX2 content handler
+ final DOMImpl dom = new DOMImpl();
+ reader.setContentHandler(dom.getBuilder());
+ // Create a DTD monitor and pass it to the XMLReader object
+ final DTDMonitor dtdMonitor = new DTDMonitor();
+ dtdMonitor.handleDTD(reader);
+
+ dom.setDocumentURI(source);
+ if (source.startsWith("file:/")) {
+ reader.parse(source);
+ } else {
+ reader.parse("file:"+(new File(source).getAbsolutePath()));
+ }
+
+ // 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);
+ // Pass unparsed entity URIs to the translet
+ _translet.setDTDMonitor(dtdMonitor);
+
+ // Transform the document
+ TextOutput textOutput = new TextOutput(handler, _encoding);
+ _translet.transform(dom, textOutput);
+ }
+ catch (TransletException e) {
+ if (_errorListener != null) {
+ postErrorToListener(e.getMessage());
+ } else {
+ System.err.println("\nTranslet Error: " + e.getMessage());
+ }
+ System.exit(1);
+ }
+ catch (RuntimeException e) {
+ if (_errorListener != null) {
+ postErrorToListener("Runtime Error: " + e.getMessage());
+ } else {
+ System.err.println("\nRuntime Error: " + e.getMessage());
+ }
+ System.exit(1);
+ }
+ catch (FileNotFoundException e) {
+ if (_errorListener != null) {
+ postErrorToListener("File not found: " + e.getMessage());
+ } else {
+ System.err.println("Error: File not found:"+e.getMessage());
+ }
+ System.exit(1);
+ }
+ catch (MalformedURLException e) {
+ if (_errorListener != null) {
+ postErrorToListener("Malformed URL: " + e.getMessage());
+ } else {
+ System.err.println("Error: Malformed URL: "+e.getMessage());
+ }
+ System.exit(1);
+ }
+ catch (UnknownHostException e) {
+ if (_errorListener != null) {
+ postErrorToListener("Cannot resolve URI: " + e.getMessage());
+ } else {
+ System.err.println("Error: Cannot resolve URI: "+
+ e.getMessage());
+ }
+ System.exit(1);
+ }
+ catch (Exception e) {
+ if (_errorListener != null) {
+ postErrorToListener("Internal error: " + e.getMessage());
+ } else {
+ System.err.println("Internal error: "+e.getMessage());
+ e.printStackTrace();
+ }
+ System.exit(1);
+ }
+ }
+
+ // TrAX support methods, get/setErrorListener
+ private ErrorListener _errorListener = null;
+
+ /**
+ * Get the TrAX error listener
+ */
+ public ErrorListener getErrorListener() {
+ return _errorListener;
+ }
+
+ /**
+ * Set the TrAX error listener
+ */
+ public void setErrorListener(ErrorListener listener)
+ throws IllegalArgumentException {
+ if (listener == null) {
+ throw new IllegalArgumentException(
+ "Error: setErrorListener() call where ErrorListener is null");
+ }
+ _errorListener = listener;
+ }
+
+ /**
+ * Inform TrAX error listener of an error
+ */
+ private void postErrorToListener(String msg) {
+ try {
+ _errorListener.error(new TransformerException(
+ "Translet Error: " + msg));
+ } catch (TransformerException e) {
+ // TBD
+ }
}
- public void transform(Source source, Result result) {
- // copy in the transform() method from AbstractTranslet
+ /**
+ * Inform TrAX error listener of a warning
+ */
+ private void postWarningToListener(String msg) {
+ try {
+ _errorListener.warning(new TransformerException(
+ "Translet Warning: " + msg));
+ } catch (TransformerException e) {
+ // TBD
+ }
}
+
+ /**
+ * Implements JAXP's Transformer.getOutputProperties().
+ * Returns a copy of the output properties for the transformation.
+ */
+ public Properties getOutputProperties() throws IllegalArgumentException
{
+ // TODO
+ return(null);
+ }
+
+ /**
+ * Implements JAXP's Transformer.getOutputProperty().
+ * Set an output property that will be in effect for the transformation.
+ */
+ public String getOutputProperty(String name)
+ throws IllegalArgumentException {
+ // TODO
+ return(null);
+ }
+
+ /**
+ * Implements JAXP's Transformer.setOutputProperties().
+ * Set the output properties for the transformation. These properties
+ * will override properties set in the Templates with xsl:output.
+ */
+ public void setOutputProperties(Properties props)
+ throws IllegalArgumentException {
+ // TODO
+ }
+
+ /**
+ * Implements JAXP's Transformer.setOutputProperty().
+ * Get an output property that is in effect for the transformation. The
+ * property specified may be a property that was set with
+ * setOutputProperty(), or it may be a property specified in the
stylesheet.
+ */
+ public void setOutputProperty(String name, String value)
+ throws IllegalArgumentException {
+ // TODO
+ }
+
+ /**
+ * Implements JAXP's Transformer.setParameter()
+ * Add a parameter for the transformation.
+ */
+ public void setParameter(String name, Object value) {
+ _translet.addParameter(name, value, false);
+ }
+
+ /**
+ * Implements JAXP's Transformer.clearParameters()
+ * Clears the parameter stack.
+ */
+ public void clearParameters() {
+ _translet.clearParameters();
+ }
+
+ /**
+ * Implements JAXP's Transformer.getParameter()
+ * Returns the value of a given parameter
+ */
+ public final Object getParameter(String name) {
+ return(_translet.getParameter(name));
+ }
+
+ /**
+ * These two methods need to pass the URI resolver to the
dom/LoadDocument
+ * class, which again must use the URI resolver if present.
+ */
+ public URIResolver getURIResolver() {
+ // TODO
+ return null;
+ }
+
+ public void setURIResolver(URIResolver resolver) {
+ // TODO
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]