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

📄 stylesheet.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * 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: Stylesheet.java,v 1.5 2005/09/28 13:48:16 pvedula Exp $ */package com.sun.org.apache.xalan.internal.xsltc.compiler;import java.net.URL;import java.net.MalformedURLException;import java.util.Vector;import java.util.Enumeration;import java.util.Hashtable;import java.util.Iterator;import java.util.Properties;import java.util.StringTokenizer;import com.sun.org.apache.xml.internal.utils.SystemIDResolver;import com.sun.org.apache.bcel.internal.generic.ANEWARRAY;import com.sun.org.apache.bcel.internal.generic.BasicType;import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;import com.sun.org.apache.bcel.internal.generic.FieldGen;import com.sun.org.apache.bcel.internal.generic.GETFIELD;import com.sun.org.apache.bcel.internal.generic.GETSTATIC;import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;import com.sun.org.apache.bcel.internal.generic.ISTORE;import com.sun.org.apache.bcel.internal.generic.InstructionHandle;import com.sun.org.apache.bcel.internal.generic.InstructionList;import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;import com.sun.org.apache.bcel.internal.generic.NEW;import com.sun.org.apache.bcel.internal.generic.NEWARRAY;import com.sun.org.apache.bcel.internal.generic.PUSH;import com.sun.org.apache.bcel.internal.generic.PUTFIELD;import com.sun.org.apache.bcel.internal.generic.PUTSTATIC;import com.sun.org.apache.bcel.internal.generic.TargetLostException;import com.sun.org.apache.bcel.internal.util.InstructionFinder;import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;import com.sun.org.apache.xml.internal.dtm.DTM;/** * @author Jacek Ambroziak * @author Santiago Pericas-Geertsen * @author Morten Jorgensen */public final class Stylesheet extends SyntaxTreeNode {    /**     * XSLT version defined in the stylesheet.     */    private String _version;        /**     * Internal name of this stylesheet used as a key into the symbol table.     */    private QName _name;        /**     * A URI that represents the system ID for this stylesheet.     */    private String _systemId;        /**     * A reference to the parent stylesheet or null if topmost.     */    private Stylesheet _parentStylesheet;	    /**     * Contains global variables and parameters defined in the stylesheet.     */    private Vector _globals = new Vector();    /**     * Used to cache the result returned by <code>hasLocalParams()</code>.     */    private Boolean _hasLocalParams = null;    /**     * The name of the class being generated.     */    private String _className;        /**      * Contains all templates defined in this stylesheet      */    private final Vector _templates = new Vector();        /**     * Used to cache result of <code>getAllValidTemplates()</code>. Only     * set in top-level stylesheets that include/import other stylesheets.     */    private Vector _allValidTemplates = null;    /**     * Counter to generate unique mode suffixes.     */    private int _nextModeSerial = 1;        /**     * Mapping between mode names and Mode instances.     */    private final Hashtable _modes = new Hashtable();        /**     * A reference to the default Mode object.     */    private Mode _defaultMode;    /**     * Mapping between extension URIs and their prefixes.     */    private final Hashtable _extensions = new Hashtable();    /**     * Reference to the stylesheet from which this stylesheet was     * imported (if any).     */    public Stylesheet _importedFrom = null;        /**     * Reference to the stylesheet from which this stylesheet was     * included (if any).     */    public Stylesheet _includedFrom = null;        /**      * Array of all the stylesheets imported or included from this one.     */    private Vector _includedStylesheets = null;        /**     * Import precendence for this stylesheet.     */    private int _importPrecedence = 1;    /**     * Minimum precendence of any descendant stylesheet by inclusion or     * importation.     */    private int _minimumDescendantPrecedence = -1;    /**     * Mapping between key names and Key objects (needed by Key/IdPattern).     */    private Hashtable _keys = new Hashtable();    /**      * A reference to the SourceLoader set by the user (a URIResolver     * if the JAXP API is being used).     */    private SourceLoader _loader = null;    /**     * Flag indicating if format-number() is called.     */    private boolean _numberFormattingUsed = false;    /**     * Flag indicating if this is a simplified stylesheets. A template     * matching on "/" must be added in this case.     */    private boolean _simplified = false;    /**     * Flag indicating if multi-document support is needed.     */    private boolean _multiDocument = false;        /**     * Flag indicating if nodset() is called.     */    private boolean _callsNodeset = false;    /**     * Flag indicating if id() is called.     */    private boolean _hasIdCall = false;        /**     * Set to true to enable template inlining optimization.     */    private boolean _templateInlining = true;    /**     * A reference to the last xsl:output object found in the styleshet.     */    private Output  _lastOutputElement = null;        /**     * Output properties for this stylesheet.     */    private Properties _outputProperties = null;        /**     * Output method for this stylesheet (must be set to one of     * the constants defined below).     */     private int _outputMethod = UNKNOWN_OUTPUT;    // Output method constants    public static final int UNKNOWN_OUTPUT = 0;    public static final int XML_OUTPUT     = 1;    public static final int HTML_OUTPUT    = 2;    public static final int TEXT_OUTPUT    = 3;        /**     * Return the output method     */    public int getOutputMethod() {    	return _outputMethod;    }        /**     * Check and set the output method     */    private void checkOutputMethod() {	if (_lastOutputElement != null) {	    String method = _lastOutputElement.getOutputMethod();	    if (method != null) {	        if (method.equals("xml"))	            _outputMethod = XML_OUTPUT;	        else if (method.equals("html"))	            _outputMethod = HTML_OUTPUT;	        else if (method.equals("text"))	            _outputMethod = TEXT_OUTPUT;	    }	}    }    public boolean getTemplateInlining() {	return _templateInlining;    }    public void setTemplateInlining(boolean flag) {	_templateInlining = flag;    }    public boolean isSimplified() {	return(_simplified);    }    public void setSimplified() {	_simplified = true;    }        public void setHasIdCall(boolean flag) {        _hasIdCall = flag;    }        public void setOutputProperty(String key, String value) {	if (_outputProperties == null) {	    _outputProperties = new Properties();	}	_outputProperties.setProperty(key, value);    }    public void setOutputProperties(Properties props) {	_outputProperties = props;    }    public Properties getOutputProperties() {	return _outputProperties;    }    public Output getLastOutputElement() {    	return _lastOutputElement;    }        public void setMultiDocument(boolean flag) {		_multiDocument = flag;    }    public boolean isMultiDocument() {	return _multiDocument;    }    public void setCallsNodeset(boolean flag) {	if (flag) setMultiDocument(flag);	_callsNodeset = flag;    }    public boolean callsNodeset() {	return _callsNodeset;    }    public void numberFormattingUsed() {	_numberFormattingUsed = true;        /*         * Fix for bug 23046, if the stylesheet is included, set the          * numberFormattingUsed flag to the parent stylesheet too.         * AbstractTranslet.addDecimalFormat() will be inlined once for the         * outer most stylesheet.          */         Stylesheet parent = getParentStylesheet();        if (null != parent) parent.numberFormattingUsed();            }    public void setImportPrecedence(final int precedence) {	// Set import precedence for this stylesheet	_importPrecedence = precedence;	// Set import precedence for all included stylesheets	final Enumeration elements = elements();	while (elements.hasMoreElements()) {	    SyntaxTreeNode child = (SyntaxTreeNode)elements.nextElement();	    if (child instanceof Include) {		Stylesheet included = ((Include)child).getIncludedStylesheet();		if (included != null && included._includedFrom == this) {		    included.setImportPrecedence(precedence);		}	    }	}	// Set import precedence for the stylesheet that imported this one	if (_importedFrom != null) {	    if (_importedFrom.getImportPrecedence() < precedence) {		final Parser parser = getParser();		final int nextPrecedence = parser.getNextImportPrecedence();		_importedFrom.setImportPrecedence(nextPrecedence);	    }	}	// Set import precedence for the stylesheet that included this one	else if (_includedFrom != null) {	    if (_includedFrom.getImportPrecedence() != precedence)		_includedFrom.setImportPrecedence(precedence);	}    }        public int getImportPrecedence() {	return _importPrecedence;    }    /**     * Get the minimum of the precedence of this stylesheet, any stylesheet     * imported by this stylesheet and any include/import descendant of this     * stylesheet.     */    public int getMinimumDescendantPrecedence() {        if (_minimumDescendantPrecedence == -1) {            // Start with precedence of current stylesheet as a basis.            int min = getImportPrecedence();            // Recursively examine all imported/included stylesheets.            final int inclImpCount = (_includedStylesheets != null)                                          ? _includedStylesheets.size()                                          : 0;            for (int i = 0; i < inclImpCount; i++) {                int prec = ((Stylesheet)_includedStylesheets.elementAt(i))                                              .getMinimumDescendantPrecedence();                if (prec < min) {                    min = prec;                }            }            _minimumDescendantPrecedence = min;        }        return _minimumDescendantPrecedence;    }    public boolean checkForLoop(String systemId) {	// Return true if this stylesheet includes/imports itself	if (_systemId != null && _systemId.equals(systemId)) {	    return true;	}	// Then check with any stylesheets that included/imported this one	if (_parentStylesheet != null) 	    return _parentStylesheet.checkForLoop(systemId);	// Otherwise OK	return false;    }        public void setParser(Parser parser) {	super.setParser(parser);	_name = makeStylesheetName("__stylesheet_");    }        public void setParentStylesheet(Stylesheet parent) {	_parentStylesheet = parent;    }        public Stylesheet getParentStylesheet() {	return _parentStylesheet;    }    public void setImportingStylesheet(Stylesheet parent) {	_importedFrom = parent;	parent.addIncludedStylesheet(this);    }    public void setIncludingStylesheet(Stylesheet parent) {	_includedFrom = parent;	parent.addIncludedStylesheet(this);    }    public void addIncludedStylesheet(Stylesheet child) {    	if (_includedStylesheets == null) {    	    _includedStylesheets = new Vector();    	}    	_includedStylesheets.addElement(child);    }    public void setSystemId(String systemId) {        if (systemId != null) {            _systemId = SystemIDResolver.getAbsoluteURI(systemId);        }    }        public String getSystemId() {	return _systemId;    }    public void setSourceLoader(SourceLoader loader) {	_loader = loader;    }        public SourceLoader getSourceLoader() {	return _loader;    }    private QName makeStylesheetName(String prefix) {	return getParser().getQName(prefix+getXSLTC().nextStylesheetSerial());    }    /**     * Returns true if this stylesheet has global vars or params.     */    public boolean hasGlobals() {	return _globals.size() > 0;    }    /**     * Returns true if at least one template in the stylesheet has params     * defined. Uses the variable <code>_hasLocalParams</code> to cache the     * result.     */    public boolean hasLocalParams() {	if (_hasLocalParams == null) {	    Vector templates = getAllValidTemplates();	    final int n = templates.size();	    for (int i = 0; i < n; i++) {		final Template template = (Template)templates.elementAt(i);		if (template.hasParams()) {		    _hasLocalParams = new Boolean(true);		    return true;		}	    }	    _hasLocalParams = new Boolean(false);

⌨️ 快捷键说明

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