src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java

Print this page

        

*** 21,30 **** --- 21,41 ---- * $Id: TransformerFactoryImpl.java,v 1.8 2007/04/09 21:30:41 joehw Exp $ */ package com.sun.org.apache.xalan.internal.xsltc.trax; + import com.sun.org.apache.xalan.internal.XalanConstants; + import com.sun.org.apache.xalan.internal.utils.FactoryImpl; + import com.sun.org.apache.xalan.internal.utils.ObjectFactory; + import com.sun.org.apache.xalan.internal.utils.SecuritySupport; + import com.sun.org.apache.xalan.internal.xsltc.compiler.Constants; + import com.sun.org.apache.xalan.internal.xsltc.compiler.SourceLoader; + import com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC; + import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg; + import com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager; + import com.sun.org.apache.xml.internal.utils.StopParseException; + import com.sun.org.apache.xml.internal.utils.StylesheetPIHandler; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FilenameFilter; import java.io.IOException;
*** 35,49 **** import java.util.Hashtable; import java.util.Properties; import java.util.Vector; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; - import javax.xml.XMLConstants; - import javax.xml.parsers.SAXParserFactory; import javax.xml.parsers.SAXParser; ! import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.ErrorListener; import javax.xml.transform.Source; import javax.xml.transform.Templates; import javax.xml.transform.Transformer; --- 46,58 ---- import java.util.Hashtable; import java.util.Properties; import java.util.Vector; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import javax.xml.XMLConstants; import javax.xml.parsers.SAXParser; ! import javax.xml.parsers.SAXParserFactory; import javax.xml.transform.ErrorListener; import javax.xml.transform.Source; import javax.xml.transform.Templates; import javax.xml.transform.Transformer;
*** 56,82 **** import javax.xml.transform.sax.SAXResult; import javax.xml.transform.sax.SAXSource; import javax.xml.transform.sax.SAXTransformerFactory; import javax.xml.transform.sax.TemplatesHandler; import javax.xml.transform.sax.TransformerHandler; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; - import javax.xml.transform.stax.*; - - import com.sun.org.apache.xml.internal.utils.StylesheetPIHandler; - import com.sun.org.apache.xml.internal.utils.StopParseException; - - import com.sun.org.apache.xalan.internal.XalanConstants; - import com.sun.org.apache.xalan.internal.xsltc.compiler.Constants; - import com.sun.org.apache.xalan.internal.xsltc.compiler.SourceLoader; - import com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC; - import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg; - import com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager; - import com.sun.org.apache.xalan.internal.utils.ObjectFactory; - import com.sun.org.apache.xalan.internal.utils.FactoryImpl; - import com.sun.org.apache.xalan.internal.utils.SecuritySupport; - import org.xml.sax.InputSource; import org.xml.sax.XMLFilter; import org.xml.sax.XMLReader; import org.xml.sax.helpers.XMLReaderFactory; --- 65,77 ---- import javax.xml.transform.sax.SAXResult; import javax.xml.transform.sax.SAXSource; import javax.xml.transform.sax.SAXTransformerFactory; import javax.xml.transform.sax.TemplatesHandler; import javax.xml.transform.sax.TransformerHandler; + import javax.xml.transform.stax.*; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; import org.xml.sax.InputSource; import org.xml.sax.XMLFilter; import org.xml.sax.XMLReader; import org.xml.sax.helpers.XMLReaderFactory;
*** 199,216 **** * Number of indent spaces when indentation is turned on. */ private int _indentNumber = -1; /** - * The provider of the XSLTC DTM Manager service. This is fixed for any - * instance of this class. In order to change service providers, a new - * XSLTC <code>TransformerFactory</code> must be instantiated. - * @see XSLTCDTMManager#getDTMManagerClass() - */ - private Class m_DTMManagerClass; - - /** * <p>State of secure processing feature.</p> */ private boolean _isNotSecureProcessing = true; /** * <p>State of secure mode.</p> --- 194,203 ----
*** 244,254 **** public static TransformerFactory newTransformerFactoryNoServiceLoader() { return new TransformerFactoryImpl(false); } private TransformerFactoryImpl(boolean useServicesMechanism) { - this.m_DTMManagerClass = XSLTCDTMManager.getDTMManagerClass(useServicesMechanism); this._useServicesMechanism = useServicesMechanism; String defaultAccess = XalanConstants.EXTERNAL_ACCESS_DEFAULT; if (System.getSecurityManager() != null) { _isSecureMode = true; --- 231,240 ----
*** 268,277 **** --- 254,264 ---- * transformation itself. * * @param listener The error listener to use with the TransformerFactory * @throws IllegalArgumentException */ + @Override public void setErrorListener(ErrorListener listener) throws IllegalArgumentException { if (listener == null) { ErrorMsg err = new ErrorMsg(ErrorMsg.ERROR_LISTENER_NULL_ERR,
*** 285,294 **** --- 272,282 ---- * javax.xml.transform.sax.TransformerFactory implementation. * Get the error event handler for the TransformerFactory. * * @return The error listener used with the TransformerFactory */ + @Override public ErrorListener getErrorListener() { return _errorListener; } /**
*** 297,306 **** --- 285,295 ---- * * @param name The attribute name * @return An object representing the attribute value * @throws IllegalArgumentException */ + @Override public Object getAttribute(String name) throws IllegalArgumentException { // Return value for attribute 'translet-name' if (name.equals(TRANSLET_NAME)) {
*** 336,345 **** --- 325,335 ---- * * @param name The attribute name * @param value An object representing the attribute value * @throws IllegalArgumentException */ + @Override public void setAttribute(String name, Object value) throws IllegalArgumentException { // Set the default translet name (ie. class name), which will be used // for translets that cannot be given a name from their system-id.
*** 458,467 **** --- 448,458 ---- * * @throws TransformerConfigurationException if this <code>TransformerFactory</code> * or the <code>Transformer</code>s or <code>Template</code>s it creates cannot support this feature. * @throws NullPointerException If the <code>name</code> parameter is null. */ + @Override public void setFeature(String name, boolean value) throws TransformerConfigurationException { // feature name cannot be null if (name == null) {
*** 502,511 **** --- 493,503 ---- * class are implemented. * * @param name The feature name * @return 'true' if feature is supported, 'false' if not */ + @Override public boolean getFeature(String name) { // All supported features should be listed here String[] features = { DOMSource.FEATURE, DOMResult.FEATURE,
*** 553,562 **** --- 545,555 ---- * resolve URIs used in document(), xsl:import, or xsl:include. * * @return The URLResolver used for this TransformerFactory and all * Templates and Transformer objects created using this factory */ + @Override public URIResolver getURIResolver() { return _uriResolver; } /**
*** 567,576 **** --- 560,570 ---- * created with this factory. * * @param resolver The URLResolver used for this TransformerFactory and all * Templates and Transformer objects created using this factory */ + @Override public void setURIResolver(URIResolver resolver) { _uriResolver = resolver; } /**
*** 586,602 **** * @param title The value of the title attribute to match. May be null. * @param charset The value of the charset attribute to match. May be null. * @return A Source object suitable for passing to the TransformerFactory. * @throws TransformerConfigurationException */ public Source getAssociatedStylesheet(Source source, String media, String title, String charset) throws TransformerConfigurationException { String baseId; ! XMLReader reader = null; ! InputSource isource = null; /** * Fix for bugzilla bug 24187 */ --- 580,597 ---- * @param title The value of the title attribute to match. May be null. * @param charset The value of the charset attribute to match. May be null. * @return A Source object suitable for passing to the TransformerFactory. * @throws TransformerConfigurationException */ + @Override public Source getAssociatedStylesheet(Source source, String media, String title, String charset) throws TransformerConfigurationException { String baseId; ! XMLReader reader; ! InputSource isource; /** * Fix for bugzilla bug 24187 */
*** 674,683 **** --- 669,679 ---- * Create a Transformer object that copies the input document to the result. * * @return A Transformer object that simply copies the source to the result. * @throws TransformerConfigurationException */ + @Override public Transformer newTransformer() throws TransformerConfigurationException { TransformerImpl result = new TransformerImpl(new Properties(), _indentNumber, this);
*** 699,708 **** --- 695,705 ---- * and every transformation. * * @return A Templates object that can be used to create Transformers. * @throws TransformerConfigurationException */ + @Override public Transformer newTransformer(Source source) throws TransformerConfigurationException { final Templates templates = newTemplates(source); final Transformer transformer = templates.newTransformer();
*** 762,771 **** --- 759,769 ---- * * @param source The input stylesheet - DOMSource not supported!!! * @return A Templates object that can be used to create Transformers. * @throws TransformerConfigurationException */ + @Override public Templates newTemplates(Source source) throws TransformerConfigurationException { // If the _useClasspath attribute is true, try to load the translet from // the CLASSPATH and create a template object using the loaded
*** 795,805 **** } // If _autoTranslet is true, we will try to load the bytecodes // from the translet classes without compiling the stylesheet. if (_autoTranslet) { ! byte[][] bytecodes = null; String transletClassName = getTransletBaseName(source); if (_packageName != null) transletClassName = _packageName + "." + transletClassName; --- 793,803 ---- } // If _autoTranslet is true, we will try to load the bytecodes // from the translet classes without compiling the stylesheet. if (_autoTranslet) { ! byte[][] bytecodes; String transletClassName = getTransletBaseName(source); if (_packageName != null) transletClassName = _packageName + "." + transletClassName;
*** 917,927 **** } // Check that the transformation went well before returning if (bytecodes == null) { Vector errs = xsltc.getErrors(); ! ErrorMsg err = null; if (errs != null) { err = (ErrorMsg)errs.elementAt(errs.size()-1); } else { err = new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR); } --- 915,925 ---- } // Check that the transformation went well before returning if (bytecodes == null) { Vector errs = xsltc.getErrors(); ! ErrorMsg err; if (errs != null) { err = (ErrorMsg)errs.elementAt(errs.size()-1); } else { err = new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR); }
*** 962,971 **** --- 960,970 ---- * events into a Templates object. * * @return A TemplatesHandler object that can handle SAX events * @throws TransformerConfigurationException */ + @Override public TemplatesHandler newTemplatesHandler() throws TransformerConfigurationException { final TemplatesHandlerImpl handler = new TemplatesHandlerImpl(_indentNumber, this);
*** 981,990 **** --- 980,990 ---- * events into a Result. This method will return a pure copy transformer. * * @return A TransformerHandler object that can handle SAX events * @throws TransformerConfigurationException */ + @Override public TransformerHandler newTransformerHandler() throws TransformerConfigurationException { final Transformer transformer = newTransformer(); if (_uriResolver != null) {
*** 1001,1010 **** --- 1001,1011 ---- * * @param src The source of the transformation instructions. * @return A TransformerHandler object that can handle SAX events * @throws TransformerConfigurationException */ + @Override public TransformerHandler newTransformerHandler(Source src) throws TransformerConfigurationException { final Transformer transformer = newTransformer(src); if (_uriResolver != null) {
*** 1021,1030 **** --- 1022,1032 ---- * * @param templates Represents a pre-processed stylesheet * @return A TransformerHandler object that can handle SAX events * @throws TransformerConfigurationException */ + @Override public TransformerHandler newTransformerHandler(Templates templates) throws TransformerConfigurationException { final Transformer transformer = templates.newTransformer(); final TransformerImpl internal = (TransformerImpl)transformer;
*** 1038,1047 **** --- 1040,1050 ---- * * @param src The source of the transformation instructions. * @return An XMLFilter object, or null if this feature is not supported. * @throws TransformerConfigurationException */ + @Override public XMLFilter newXMLFilter(Source src) throws TransformerConfigurationException { Templates templates = newTemplates(src); if (templates == null) return null;
*** 1055,1064 **** --- 1058,1068 ---- * * @param templates The source of the transformation instructions. * @return An XMLFilter object, or null if this feature is not supported. * @throws TransformerConfigurationException */ + @Override public XMLFilter newXMLFilter(Templates templates) throws TransformerConfigurationException { try { return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);
*** 1086,1095 **** --- 1090,1100 ---- * @param e The warning information encapsulated in a transformer * exception. * @throws TransformerException if the application chooses to discontinue * the transformation (always does in our case). */ + @Override public void error(TransformerException e) throws TransformerException { Throwable wrapped = e.getException(); if (wrapped != null) {
*** 1114,1123 **** --- 1119,1129 ---- * @param e warning information encapsulated in a transformer * exception. * @throws TransformerException if the application chooses to discontinue * the transformation (always does in our case). */ + @Override public void fatalError(TransformerException e) throws TransformerException { Throwable wrapped = e.getException(); if (wrapped != null) {
*** 1142,1151 **** --- 1148,1158 ---- * @param e The warning information encapsulated in a transformer * exception. * @throws TransformerException if the application chooses to discontinue * the transformation (never does in our case). */ + @Override public void warning(TransformerException e) throws TransformerException { Throwable wrapped = e.getException(); if (wrapped != null) {
*** 1165,1174 **** --- 1172,1182 ---- * @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 */ + @Override public InputSource loadSource(String href, String context, XSLTC xsltc) { try { if (_uriResolver != null) { final Source source = _uriResolver.resolve(href, context); if (source != null) {
*** 1251,1261 **** // Load the translet into a bytecode array. Vector bytecodes = new Vector(); int fileLength = (int)transletFile.length(); if (fileLength > 0) { ! FileInputStream input = null; try { input = new FileInputStream(transletFile); } catch (FileNotFoundException e) { return null; --- 1259,1269 ---- // Load the translet into a bytecode array. Vector bytecodes = new Vector(); int fileLength = (int)transletFile.length(); if (fileLength > 0) { ! FileInputStream input; try { input = new FileInputStream(transletFile); } catch (FileNotFoundException e) { return null;
*** 1283,1292 **** --- 1291,1301 ---- File transletParentFile = new File(transletParentDir); // Find all the auxiliary files which have a name pattern of "transletClass$nnn.class". final String transletAuxPrefix = transletName + "$"; File[] auxfiles = transletParentFile.listFiles(new FilenameFilter() { + @Override public boolean accept(File dir, String name) { return (name.endsWith(".class") && name.startsWith(transletAuxPrefix)); } });
*** 1346,1356 **** File xslFile = null; if (xslFileName != null) xslFile = new File(xslFileName); // Construct the path for the jar file ! String jarPath = null; if (_destinationDirectory != null) jarPath = _destinationDirectory + "/" + _jarFileName; else { if (xslFile != null && xslFile.getParent() != null) jarPath = xslFile.getParent() + "/" + _jarFileName; --- 1355,1365 ---- File xslFile = null; if (xslFileName != null) xslFile = new File(xslFileName); // Construct the path for the jar file ! String jarPath; if (_destinationDirectory != null) jarPath = _destinationDirectory + "/" + _jarFileName; else { if (xslFile != null && xslFile.getParent() != null) jarPath = xslFile.getParent() + "/" + _jarFileName;
*** 1371,1381 **** if (transletTimestamp < xslTimestamp) return null; } // Create a ZipFile object for the jar file ! ZipFile jarFile = null; try { jarFile = new ZipFile(file); } catch (IOException e) { return null; --- 1380,1390 ---- if (transletTimestamp < xslTimestamp) return null; } // Create a ZipFile object for the jar file ! ZipFile jarFile; try { jarFile = new ZipFile(file); } catch (IOException e) { return null;
*** 1489,1499 **** if (systemId != null) { File file = new File(systemId); if (file.exists()) return systemId; else { ! URL url = null; try { url = new URL(systemId); } catch (MalformedURLException e) { return null; --- 1498,1508 ---- if (systemId != null) { File file = new File(systemId); if (file.exists()) return systemId; else { ! URL url; try { url = new URL(systemId); } catch (MalformedURLException e) { return null;
*** 1508,1518 **** else return null; } /** ! * Returns the Class object the provides the XSLTC DTM Manager service. */ ! protected Class getDTMManagerClass() { ! return m_DTMManagerClass; } } --- 1517,1527 ---- else return null; } /** ! * Returns a new instance of the XSLTC DTM Manager service. */ ! protected final XSLTCDTMManager createNewDTMManagerInstance() { ! return XSLTCDTMManager.createNewDTMManagerInstance(); } }