stylesheet.java

来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,413 行 · 第 1/4 页

JAVA
1,413
字号
/* * 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.1.2.2 2006/10/05 17:10:34 spericas 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;    }    /**

⌨️ 快捷键说明

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