⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transformerfactoryimpl.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* * Copyright 2001-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *//* * $Id: TransformerFactoryImpl.java,v 1.8 2007/04/09 21:30:41 joehw Exp $ */package com.sun.org.apache.xalan.internal.xsltc.trax;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FilenameFilter;import java.io.IOException;import java.io.InputStream;import java.net.MalformedURLException;import java.net.URL;import java.util.Enumeration;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;import javax.xml.transform.TransformerConfigurationException;import javax.xml.transform.TransformerException;import javax.xml.transform.URIResolver;import javax.xml.transform.dom.DOMResult;import javax.xml.transform.dom.DOMSource;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 com.sun.org.apache.xml.internal.utils.StylesheetPIHandler;import com.sun.org.apache.xml.internal.utils.StopParseException;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 org.xml.sax.InputSource;import org.xml.sax.XMLFilter;import org.xml.sax.XMLReader;import org.xml.sax.helpers.XMLReaderFactory;/** * Implementation of a JAXP1.1 TransformerFactory for Translets. * @author G. Todd Miller  * @author Morten Jorgensen * @author Santiago Pericas-Geertsen */public class TransformerFactoryImpl    extends SAXTransformerFactory implements SourceLoader, ErrorListener {    // Public constants for attributes supported by the XSLTC TransformerFactory.    public final static String TRANSLET_NAME = "translet-name";    public final static String DESTINATION_DIRECTORY = "destination-directory";    public final static String PACKAGE_NAME = "package-name";    public final static String JAR_NAME = "jar-name";    public final static String GENERATE_TRANSLET = "generate-translet";    public final static String AUTO_TRANSLET = "auto-translet";    public final static String USE_CLASSPATH = "use-classpath";    public final static String DEBUG = "debug";    public final static String ENABLE_INLINING = "enable-inlining";    public final static String INDENT_NUMBER = "indent-number";            /**     * 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     */    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....     */    protected final static String DEFAULT_TRANSLET_NAME = "GregorSamsa";        /**     * The class name of the translet     */    private String _transletName = DEFAULT_TRANSLET_NAME;        /**     * The destination directory for the translet     */    private String _destinationDirectory = null;        /**     * The package name prefix for all generated translet classes     */    private String _packageName = null;        /**     * The jar file name which the translet classes are packaged into     */    private String _jarFileName = null;    /**     * 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.     */    private static class PIParamWrapper {	public String _media = null;	public String _title = null;	public String _charset = null;		public PIParamWrapper(String media, String title, String charset) {	    _media = media;	    _title = title;	    _charset = charset;	}    }    /**     * Set to <code>true</code> when debugging is enabled.     */    private boolean _debug = false;    /**     * Set to <code>true</code> when templates are inlined.     */    private boolean _enableInlining = false;        /**     * Set to <code>true</code> when we want to generate      * translet classes from the stylesheet.     */    private boolean _generateTranslet = false;        /**     * If this is set to <code>true</code>, we attempt to use translet classes     * for transformation if possible without compiling the stylesheet. The     * translet class is only used if its timestamp is newer than the timestamp     * of the stylesheet.     */    private boolean _autoTranslet = false;        /**     * If this is set to <code>true</code>, we attempt to load the translet     * from the CLASSPATH.     */    private boolean _useClasspath = false;    /**     * 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 _isSecureProcessing = false;    /**     * javax.xml.transform.sax.TransformerFactory implementation.     */    public TransformerFactoryImpl() {        m_DTMManagerClass = XSLTCDTMManager.getDTMManagerClass();    }    /**     * javax.xml.transform.sax.TransformerFactory implementation.     * Set the error event listener for the TransformerFactory, which is used     * for the processing of transformation instructions, and not for the     * transformation itself.     *     * @param listener The error listener to use with the TransformerFactory     * @throws IllegalArgumentException     */    public void setErrorListener(ErrorListener listener) 	throws IllegalArgumentException     {	if (listener == null) {	    ErrorMsg err = new ErrorMsg(ErrorMsg.ERROR_LISTENER_NULL_ERR,					"TransformerFactory");            throw new IllegalArgumentException(err.toString());	}	_errorListener = listener;    }    /**     * javax.xml.transform.sax.TransformerFactory implementation.     * Get the error event handler for the TransformerFactory.     *     * @return The error listener used with the TransformerFactory     */    public ErrorListener getErrorListener() { 	return _errorListener;    }    /**     * javax.xml.transform.sax.TransformerFactory implementation.     * Returns the value set for a TransformerFactory attribute     *     * @param name The attribute name     * @return An object representing the attribute value     * @throws IllegalArgumentException     */    public Object getAttribute(String name) 	throws IllegalArgumentException     { 	// Return value for attribute 'translet-name'	if (name.equals(TRANSLET_NAME)) {	    return _transletName;	}	else if (name.equals(GENERATE_TRANSLET)) {	    return new Boolean(_generateTranslet);	}	else if (name.equals(AUTO_TRANSLET)) {	    return new Boolean(_autoTranslet);	}	// Throw an exception for all other attributes	ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_INVALID_ATTR_ERR, name);	throw new IllegalArgumentException(err.toString());    }    /**     * javax.xml.transform.sax.TransformerFactory implementation.     * Sets the value for a TransformerFactory attribute.     *     * @param name The attribute name     * @param value An object representing the attribute value     * @throws IllegalArgumentException     */    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.	if (name.equals(TRANSLET_NAME) && value instanceof String) {	    _transletName = (String) value;	      	    return;	}	else if (name.equals(DESTINATION_DIRECTORY) && value instanceof String) {	    _destinationDirectory = (String) value;	    return;	}	else if (name.equals(PACKAGE_NAME) && value instanceof String) {	    _packageName = (String) value;	    return;	}	else if (name.equals(JAR_NAME) && value instanceof String) {	    _jarFileName = (String) value;	    return;	}	else if (name.equals(GENERATE_TRANSLET)) {	    if (value instanceof Boolean) {		_generateTranslet = ((Boolean) value).booleanValue();		return;	    }	    else if (value instanceof String) {		_generateTranslet = ((String) value).equalsIgnoreCase("true");		return;	    }	}	else if (name.equals(AUTO_TRANSLET)) {	    if (value instanceof Boolean) {		_autoTranslet = ((Boolean) value).booleanValue();		return;	    }	    else if (value instanceof String) {		_autoTranslet = ((String) value).equalsIgnoreCase("true");		return;	    }	}	else if (name.equals(USE_CLASSPATH)) {	    if (value instanceof Boolean) {		_useClasspath = ((Boolean) value).booleanValue();		return;	    }	    else if (value instanceof String) {		_useClasspath = ((String) value).equalsIgnoreCase("true");		return;	    }	    	}	else if (name.equals(DEBUG)) {	    if (value instanceof Boolean) {		_debug = ((Boolean) value).booleanValue();		return;	    }	    else if (value instanceof String) {		_debug = ((String) value).equalsIgnoreCase("true");		return;	    }	}	else if (name.equals(ENABLE_INLINING)) {	    if (value instanceof Boolean) {		_enableInlining = ((Boolean) value).booleanValue();		return;	    }	    else if (value instanceof String) {		_enableInlining = ((String) value).equalsIgnoreCase("true");		return;	    }	}	else if (name.equals(INDENT_NUMBER)) {	    if (value instanceof String) {		try {		    _indentNumber = Integer.parseInt((String) value);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -