stylesheet.java

来自「java jdk 1.4的源码」· Java 代码 · 共 1,548 行 · 第 1/3 页

JAVA
1,548
字号
/* * The Apache Software License, Version 1.1 * * * Copyright (c) 1999 The Apache Software Foundation.  All rights  * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer.  * * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in *    the documentation and/or other materials provided with the *    distribution. * * 3. The end-user documentation included with the redistribution, *    if any, must include the following acknowledgment:   *       "This product includes software developed by the *        Apache Software Foundation (http://www.apache.org/)." *    Alternately, this acknowledgment may appear in the software itself, *    if and wherever such third-party acknowledgments normally appear. * * 4. The names "Xalan" and "Apache Software Foundation" must *    not be used to endorse or promote products derived from this *    software without prior written permission. For written  *    permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", *    nor may "Apache" appear in their name, without prior written *    permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation and was * originally based on software copyright (c) 1999, Lotus * Development Corporation., http://www.lotus.com.  For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */package org.apache.xalan.templates;// Java importsimport java.io.ObjectInputStream;import java.io.IOException;import java.io.ObjectOutputStream;import java.text.DecimalFormatSymbols;import java.util.Hashtable;import java.util.Stack;import java.util.Vector;// Xalan importsimport org.apache.xml.utils.SystemIDResolver;import org.apache.xml.utils.QName;import org.apache.xml.utils.StringVector;import org.apache.xpath.XPath;// DOM Imports//import org.w3c.dom.Node;//import org.w3c.dom.Document;import org.apache.xml.dtm.DTM;// SAX2 Importsimport javax.xml.transform.TransformerException;import org.xml.sax.Locator;import javax.xml.transform.SourceLocator;/** * Represents a stylesheet element. * <p>All properties in this class have a fixed form of bean-style property * accessors for all properties that represent XSL attributes or elements. * These properties have setter method names accessed generically by the * processor, and so these names must be fixed according to the system * defined in the <a href="XSLTAttributeDef#getSetterMethodName">getSetterMethodName</a> * function.</p> * <p><pre> * <!ENTITY % top-level " *  (xsl:import*, *   (xsl:include *   | xsl:strip-space *   | xsl:preserve-space *   | xsl:output *   | xsl:key *   | xsl:decimal-format *   | xsl:attribute-set *   | xsl:variable *   | xsl:param *   | xsl:template *   | xsl:namespace-alias *   %non-xsl-top-level;)*) * "> * * <!ENTITY % top-level-atts ' *   extension-element-prefixes CDATA #IMPLIED *   exclude-result-prefixes CDATA #IMPLIED *   id ID #IMPLIED *   version NMTOKEN #REQUIRED *   xmlns:xsl CDATA #FIXED "http://www.w3.org/1999/XSL/Transform" *   %space-att; * '> * * <!ELEMENT xsl:stylesheet %top-level;> * <!ATTLIST xsl:stylesheet %top-level-atts;> * * <!ELEMENT xsl:transform %top-level;> * <!ATTLIST xsl:transform %top-level-atts;> * * </p></pre> * @see <a href="http://www.w3.org/TR/xslt#section-Stylesheet-Structure">section-Stylesheet-Structure in XSLT Specification</a> */public class Stylesheet extends ElemTemplateElement        implements java.io.Serializable /* , Document */{  /**   * Constructor for a Stylesheet.   * @param parent  The including or importing stylesheet.   */  public Stylesheet(Stylesheet parent)  {    if (null != parent)    {      m_stylesheetParent = parent;      m_stylesheetRoot = parent.getStylesheetRoot();    }  }  /**   * Get the owning stylesheet.  This looks up the   * inheritance chain until it calls getStylesheet   * on a Stylesheet object, which will return itself.   *   * @return The owning stylesheet, itself.   */  public Stylesheet getStylesheet()  {    return this;  }  /**   * Tell if this can be cast to a StylesheetComposed, meaning, you   * can ask questions from getXXXComposed functions.   *   * @return False if this is not a StylesheetComposed   */  public boolean isAggregatedType()  {    return false;  }  /**   * Tell if this is the root of the stylesheet tree.   *   * @return False is this is not the root of the stylesheet tree.   */  public boolean isRoot()  {    return false;  }  /**   * Extension to be used when serializing to disk.   */  public static final String STYLESHEET_EXT = ".lxc";  /**   * Read the stylesheet from a serialization stream.   *   * @param stream Input stream to read from   *   * @throws IOException   * @throws TransformerException   */  private void readObject(ObjectInputStream stream)          throws IOException, TransformerException  {    // System.out.println("Reading Stylesheet");    try    {      stream.defaultReadObject();    }    catch (ClassNotFoundException cnfe)    {      throw new TransformerException(cnfe);    }    // System.out.println("Done reading Stylesheet");  }  /**   * Write out the given output stream    *   *   * @param stream The output stream to write out   *   * @throws IOException   */  private void writeObject(ObjectOutputStream stream) throws IOException  {    // System.out.println("Writing Stylesheet");    stream.defaultWriteObject();    // System.out.println("Done writing Stylesheet");  }  //============== XSLT Properties =================  /**   * The "xmlns:xsl" property.   * @serial   */  private String m_XmlnsXsl;  /**   * Set the "xmlns:xsl" property.   * @see <a href="http://www.w3.org/TR/xslt#xslt-namespace">xslt-namespace in XSLT Specification</a>   *   * @param v The value to be set for the "xmlns:xsl" property.   */  public void setXmlnsXsl(String v)  {    m_XmlnsXsl = v;  }  /**   * Get the "xmlns:xsl" property.   * @see <a href="http://www.w3.org/TR/xslt#xslt-namespace">xslt-namespace in XSLT Specification</a>   *   * @return The value of the "xmlns:xsl" property.   */  public String getXmlnsXsl()  {    return m_XmlnsXsl;  }  /**   * The "extension-element-prefixes" property, actually contains URIs.   * @serial   */  private StringVector m_ExtensionElementURIs;  /**   * Set the "extension-element-prefixes" property.   * @see <a href="http://www.w3.org/TR/xslt#extension-element">extension-element in XSLT Specification</a>   *   * @param v The value to be set for the "extension-element-prefixes"    * property: a vector of extension element URIs.   */  public void setExtensionElementPrefixes(StringVector v)  {    m_ExtensionElementURIs = v;  }  /**   * Get and "extension-element-prefix" property.   * @see <a href="http://www.w3.org/TR/xslt#extension-element">extension-element in XSLT Specification</a>   *   * @param i Index of extension element URI in list    *   * @return The extension element URI at the given index   *   * @throws ArrayIndexOutOfBoundsException   */  public String getExtensionElementPrefix(int i)          throws ArrayIndexOutOfBoundsException  {    if (null == m_ExtensionElementURIs)      throw new ArrayIndexOutOfBoundsException();    return m_ExtensionElementURIs.elementAt(i);  }  /**   * Get the number of "extension-element-prefixes" Strings.   * @see <a href="http://www.w3.org/TR/xslt#extension-element">extension-element in XSLT Specification</a>   *   * @return Number of URIs in the list   */  public int getExtensionElementPrefixCount()  {    return (null != m_ExtensionElementURIs)           ? m_ExtensionElementURIs.size() : 0;  }  /**   * Find out if this contains a given "extension-element-prefix" property.   * @see <a href="http://www.w3.org/TR/xslt#extension-element">extension-element in XSLT Specification</a>   *   * @param uri URI of extension element to look for   *   * @return True if the given URI was found in the list    */  public boolean containsExtensionElementURI(String uri)  {    if (null == m_ExtensionElementURIs)      return false;    return m_ExtensionElementURIs.contains(uri);  }  /**   * The "exclude-result-prefixes" property.   * @serial   */  private StringVector m_ExcludeResultPrefixs;  /**   * Set the "exclude-result-prefixes" property.   * The designation of a namespace as an excluded namespace is   * effective within the subtree of the stylesheet rooted at   * the element bearing the exclude-result-prefixes or   * xsl:exclude-result-prefixes attribute; a subtree rooted   * at an xsl:stylesheet element does not include any stylesheets   * imported or included by children of that xsl:stylesheet element.   * @see <a href="http://www.w3.org/TR/xslt#literal-result-element">literal-result-element in XSLT Specification</a>   *   * @param v A StringVector of prefixes to exclude    */  public void setExcludeResultPrefixes(StringVector v)  {    m_ExcludeResultPrefixs = v;  }  /**   * Get an "exclude-result-prefix" property.   * The designation of a namespace as an excluded namespace is   * effective within the subtree of the stylesheet rooted at   * the element bearing the exclude-result-prefixes or   * xsl:exclude-result-prefixes attribute; a subtree rooted   * at an xsl:stylesheet element does not include any stylesheets   * imported or included by children of that xsl:stylesheet element.   * @see <a href="http://www.w3.org/TR/xslt#literal-result-element">literal-result-element in XSLT Specification</a>   *   * @param i Index of prefix to get in list    *   * @return Prefix to be excluded at the given index   *   * @throws ArrayIndexOutOfBoundsException   */  public String getExcludeResultPrefix(int i)          throws ArrayIndexOutOfBoundsException  {    if (null == m_ExcludeResultPrefixs)      throw new ArrayIndexOutOfBoundsException();    return m_ExcludeResultPrefixs.elementAt(i);  }  /**   * Get the number of "exclude-result-prefixes" Strings.   * @see <a href="http://www.w3.org/TR/xslt#literal-result-element">literal-result-element in XSLT Specification</a>   *   * @return The number of prefix strings to be excluded.    */  public int getExcludeResultPrefixCount()  {    return (null != m_ExcludeResultPrefixs)           ? m_ExcludeResultPrefixs.size() : 0;  }  /**   * Get whether or not the passed prefix is contained flagged by   * the "exclude-result-prefixes" property.   * @see <a href="http://www.w3.org/TR/xslt#literal-result-element">literal-result-element in XSLT Specification</a>   *   * @param prefix non-null reference to prefix that might be excluded.   * @param uri reference to namespace that prefix maps to   *   * @return true if the prefix should normally be excluded.>   */  public boolean containsExcludeResultPrefix(String prefix, String uri)   {    if (null == m_ExcludeResultPrefixs || uri == null )      return false;        // This loop is ok here because this code only runs during    // stylesheet compile time.    for (int i =0; i< m_ExcludeResultPrefixs.size(); i++)    {      if (uri.equals(getNamespaceForPrefix(m_ExcludeResultPrefixs.elementAt(i))))        return true;    }        return false;  /*  if (prefix.length() == 0)      prefix = Constants.ATTRVAL_DEFAULT_PREFIX;    return m_ExcludeResultPrefixs.contains(prefix); */  }  /**   * The "id" property.   * @serial   */  private String m_Id;  /**   * Set the "id" property.   * @see <a href="http://www.w3.org/TR/xslt#section-Embedding-Stylesheets">section-Embedding-Stylesheets in XSLT Specification</a>   *   * @param v Value for the "id" property.   */  public void setId(String v)  {    m_Id = v;  }  /**   * Get the "id" property.   * @see <a href="http://www.w3.org/TR/xslt#section-Embedding-Stylesheets">section-Embedding-Stylesheets in XSLT Specification</a>   *   * @return The value of the "id" property.   */  public String getId()  {    return m_Id;  }  /**   * The "version" property.   * @serial   */  private String m_Version;  /**   * Set the "version" property.   * @see <a href="http://www.w3.org/TR/xslt#forwards">forwards in XSLT Specification</a>   *   * @param v Value for the "version" property.   */  public void setVersion(String v)  {    m_Version = v;  }  /**   * Get the "version" property.   * @see <a href="http://www.w3.org/TR/xslt#forwards">forwards in XSLT Specification</a>   *   * @return The value of the "version" property.   */  public String getVersion()  {    return m_Version;  }  /**   * The "xsl:import" list.   * @serial   */  private Vector m_imports;  /**   * Add a stylesheet to the "import" list.   * @see <a href="http://www.w3.org/TR/xslt#import">import in XSLT Specification</a>   *   * @param v Stylesheet to add to the import list   */  public void setImport(StylesheetComposed v)  {    if (null == m_imports)      m_imports = new Vector();    // I'm going to insert the elements in backwards order,    // so I can walk them 0 to n.    m_imports.addElement(v);  }  /**   * Get a stylesheet from the "import" list.   * @see <a href="http://www.w3.org/TR/xslt#import">import in XSLT Specification</a>   *   * @param i Index of the stylesheet to get   *   * @return The stylesheet at the given index   *   * @throws ArrayIndexOutOfBoundsException   */  public StylesheetComposed getImport(int i)          throws ArrayIndexOutOfBoundsException  {    if (null == m_imports)      throw new ArrayIndexOutOfBoundsException();    return (StylesheetComposed) m_imports.elementAt(i);  }

⌨️ 快捷键说明

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