xsltattributedef.java

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

JAVA
1,654
字号
/* * 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.processor;import org.apache.xml.utils.StringToIntTable;import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;import java.util.StringTokenizer;import java.util.Vector;import org.apache.xalan.templates.AVT;import org.apache.xalan.templates.ElemTemplateElement;import org.apache.xalan.templates.Constants;import org.apache.xalan.res.XSLMessages;import org.apache.xalan.res.XSLTErrorResources;import org.apache.xml.utils.QName;import org.apache.xml.utils.SystemIDResolver;import org.apache.xml.utils.StringVector;import org.apache.xml.utils.XMLChar;import org.apache.xpath.XPath;import javax.xml.transform.TransformerException; /** * This class defines an attribute for an element in a XSLT stylesheet, * is meant to reflect the structure defined in http://www.w3.org/TR/xslt#dtd, and the * mapping between Xalan classes and the markup attributes in the element. */public class XSLTAttributeDef{   // How to handle invalid values for this attribute    static final int FATAL = 0;   static final int ERROR = 1;   static final int WARNING = 2;        /**   * Construct an instance of XSLTAttributeDef.   *   * @param namespace The Namespace URI, or an empty string.   * @param name The local name (without prefix), or empty string if not namespace processing.   * @param type One of T_CDATA, T_URL, T_AVT, T_PATTERN, T_EXPR, T_CHAR,   * T_NUMBER, T_YESNO, T_QNAME, T_QNAMES, T_ENUM, T_SIMPLEPATTERNLIST,   * T_NMTOKEN, T_STRINGLIST, T_PREFIX_URLLIST, T_ENUM_OR_PQNAME, T_NCNAME.   * @param required true if this is attribute is required by the XSLT specification.   * @param supportsAVT true if this attribute supports AVT's.   * @param errorType the type of error to issue if validation fails.  One of FATAL, ERROR, WARNING.    */  XSLTAttributeDef(String namespace, String name, int type, boolean required, boolean supportsAVT, int errorType)  {    this.m_namespace = namespace;    this.m_name = name;    this.m_type = type;    this.m_required = required;    this.m_supportsAVT = supportsAVT;    this.m_errorType = errorType;  }  /**   * Construct an instance of XSLTAttributeDef.   *   * @param namespace The Namespace URI, or an empty string.   * @param name The local name (without prefix), or empty string if not namespace processing.   * @param type One of T_CDATA, T_URL, T_AVT, T_PATTERN, T_EXPR,   * T_CHAR, T_NUMBER, T_YESNO, T_QNAME, T_QNAMES, T_ENUM,   * T_SIMPLEPATTERNLIST, T_NMTOKEN, T_STRINGLIST, T_PREFIX_URLLIST,    * T_ENUM_OR_PQNAME, T_NCNAME.   * @param supportsAVT true if this attribute supports AVT's.    * @param errorType the type of error to issue if validation fails.  One of FATAL, ERROR, WARNING.    * @param defaultVal The default value for this attribute.   */  XSLTAttributeDef(String namespace, String name, int type, boolean supportsAVT, int errorType, String defaultVal)  {    this.m_namespace = namespace;    this.m_name = name;    this.m_type = type;    this.m_required = false;    this.m_supportsAVT = supportsAVT;      this.m_errorType = errorType;          this.m_default = defaultVal;   }  /**   * Construct an instance of XSLTAttributeDef that uses two   * enumerated values.   *   * @param namespace The Namespace URI, or an empty string.   * @param name The local name (without prefix), or empty string if not namespace processing.   * @param required true if this attribute is required by the XSLT specification.   * @param supportsAVT true if this attribute supports AVT's.     * @param prefixedQNameValAllowed If true, the type is T_ENUM_OR_PQNAME          * @param errorType the type of error to issue if validation fails.  One of FATAL, ERROR, WARNING.    * @param k1 The XSLT name of the enumerated value.   * @param v1 An integer representation of k1.   * @param k2 The XSLT name of the enumerated value.   * @param v2 An integer representation of k2.    */  XSLTAttributeDef(String namespace, String name, boolean required, boolean supportsAVT,                     boolean prefixedQNameValAllowed, int errorType, String k1, int v1, String k2, int v2)  {    this.m_namespace = namespace;    this.m_name = name;	this.m_type = prefixedQNameValAllowed ? this.T_ENUM_OR_PQNAME : this.T_ENUM;        this.m_required = required;    this.m_supportsAVT = supportsAVT;        this.m_errorType = errorType;        m_enums = new StringToIntTable(2);    m_enums.put(k1, v1);    m_enums.put(k2, v2);  }  /**   * Construct an instance of XSLTAttributeDef that uses three   * enumerated values.   *   * @param namespace The Namespace URI, or an empty string.   * @param name The local name (without prefix), or empty string if not namespace processing.   * @param required true if this attribute is required by the XSLT specification.   * @param supportsAVT true if this attribute supports AVT's.   * @param prefixedQNameValAllowed If true, the type is T_ENUM_OR_PQNAME   * @param errorType the type of error to issue if validation fails.  One of FATAL, ERROR, WARNING.    *    * @param k1 The XSLT name of the enumerated value.   * @param v1 An integer representation of k1.   * @param k2 The XSLT name of the enumerated value.   * @param v2 An integer representation of k2.   * @param k3 The XSLT name of the enumerated value.   * @param v3 An integer representation of k3.   */  XSLTAttributeDef(String namespace, String name, boolean required, boolean supportsAVT,                    boolean prefixedQNameValAllowed, int errorType, String k1, int v1, String k2, int v2, String k3, int v3)  {    this.m_namespace = namespace;    this.m_name = name;	this.m_type = prefixedQNameValAllowed ? this.T_ENUM_OR_PQNAME : this.T_ENUM;        this.m_required = required;    this.m_supportsAVT = supportsAVT;     this.m_errorType = errorType;          m_enums = new StringToIntTable(3);    m_enums.put(k1, v1);    m_enums.put(k2, v2);    m_enums.put(k3, v3);  }  /**   * Construct an instance of XSLTAttributeDef that uses three   * enumerated values.   *   * @param namespace The Namespace URI, or an empty string.   * @param name The local name (without prefix), or empty string if not namespace processing.   * @param required true if this attribute is required by the XSLT specification.   * @param supportsAVT true if this attribute supports AVT's.   * @param prefixedQNameValAllowed If true, the type is T_ENUM_OR_PQNAME   * @param errorType the type of error to issue if validation fails.  One of FATAL, ERROR, WARNING.    * @param k1 The XSLT name of the enumerated value.   * @param v1 An integer representation of k1.   * @param k2 The XSLT name of the enumerated value.   * @param v2 An integer representation of k2.   * @param k3 The XSLT name of the enumerated value.   * @param v3 An integer representation of k3.   * @param k4 The XSLT name of the enumerated value.   * @param v4 An integer representation of k4.   */  XSLTAttributeDef(String namespace, String name, boolean required, boolean supportsAVT,                   boolean prefixedQNameValAllowed, int errorType, String k1, int v1, String k2, int v2,                    String k3, int v3, String k4, int v4)  {    this.m_namespace = namespace;    this.m_name = name;	this.m_type = prefixedQNameValAllowed ? this.T_ENUM_OR_PQNAME : this.T_ENUM;        this.m_required = required;    this.m_supportsAVT = supportsAVT;          this.m_errorType = errorType;     m_enums = new StringToIntTable(4);    m_enums.put(k1, v1);    m_enums.put(k2, v2);    m_enums.put(k3, v3);    m_enums.put(k4, v4);  }  /** Type values that represent XSLT attribute types. */  static final int T_CDATA = 1,  // <!-- Used for the type of an attribute value that is a URI reference.-->  T_URL = 2,  // <!-- Used for the type of an attribute value that is an  // attribute value template.-->  T_AVT = 3,  // Attribute Value Template  // <!-- Used for the type of an attribute value that is a pattern.-->  T_PATTERN = 4,  // <!-- Used for the type of an attribute value that is an expression.-->  T_EXPR = 5,  // <!-- Used for the type of an attribute value that consists  // of a single character.-->  T_CHAR = 6,  // <!-- Used for the type of an attribute value that is a number. -->  T_NUMBER = 7,  // Used for boolean values  T_YESNO = 8,  // <!-- Used for the type of an attribute value that is a QName; the prefix  // gets expanded by the XSLT processor. -->  T_QNAME = 9,  // <!--Used for a whitespace-separated list of QNames where the non-prefixed  // entries are not to be placed in the default namespace. -->  T_QNAMES = 10,  // <!-- Used for enumerated values -->  T_ENUM = 11,  // Used for simple match patterns, i.e. xsl:strip-space spec.  T_SIMPLEPATTERNLIST = 12,  // Used for a known token.  T_NMTOKEN = 13,  // Used for a list of white-space delimited strings.  T_STRINGLIST = 14,  // Used for a list of white-space delimited strings.  T_PREFIX_URLLIST = 15,    // Used for enumerated values, one of which could be a qname-but-not-ncname  T_ENUM_OR_PQNAME = 16,  // Used for the type of an attribute value that is a NCName  T_NCNAME = 17,    // Used for QName attributes that are always AVT.  Prefix isn't resolved.  T_AVT_QNAME = 18,    // Used for a list of QNames where non-prefixed items are to be resolved  // using the default namespace (This is only true for cdata-section-elements)  T_QNAMES_RESOLVE_NULL = 19;    /** Representation for an attribute in a foreign namespace. */  static XSLTAttributeDef m_foreignAttr = new XSLTAttributeDef("*", "*",                                            XSLTAttributeDef.T_CDATA,false, false, WARNING);  /** Method name that objects may implement if they wish to have forein attributes set. */  static String S_FOREIGNATTR_SETTER = "setForeignAttr";  /**   * The allowed namespace for this element.   */  private String m_namespace;  /**   * Get the allowed namespace for this attribute.   *   * @return The allowed namespace for this attribute, which may be null, or may be "*".   */  String getNamespace()  {    return m_namespace;  }  /**   * The name of this element.   */  private String m_name;  /**   * Get the name of this attribute.   *   * @return non-null reference to the name of this attribute, which may be "*".   */  String getName()  {    return m_name;  }  /**   * The type of this attribute value.   */  private int m_type;  /**   * Get the type of this attribute value.   *   * @return One of T_CDATA, T_URL, T_AVT, T_PATTERN, T_EXPR, T_CHAR,   * T_NUMBER, T_YESNO, T_QNAME, T_QNAMES, T_ENUM, T_SIMPLEPATTERNLIST,   * T_NMTOKEN, T_STRINGLIST, T_PREFIX_URLLIST, T_ENUM_OR_PQNAME.   */  int getType()  {    return m_type;  }  /**   * If this element is of type T_ENUM, this will contain   * a map from the attribute string to the Xalan integer   * value.   */  private StringToIntTable m_enums;  /**   * If this element is of type T_ENUM, this will return   * a map from the attribute string to the Xalan integer   * value.   * @param key The XSLT attribute value.   *   * @return The integer representation of the enumerated value for this attribute.   * @throws Throws NullPointerException if m_enums is null.   */  private int getEnum(String key)  {    return m_enums.get(key);  } /**   * If this element is of type T_ENUM, this will return   * an array of strings - the values in the enumeration   *   * @return An array of the enumerated values permitted for this attribute.   *   * @throws Throws NullPointerException if m_enums is null.   */  private String[] getEnumNames()  {    return m_enums.keys();  }  /**   * The default value for this attribute.   */  private String m_default;  /**   * Get the default value for this attribute.   *   * @return The default value for this attribute, or null.   */  String getDefault()  {    return m_default;  }  /**   * Set the default value for this attribute.   *   * @param def String representation of the default value for this attribute.   */  void setDefault(String def)

⌨️ 快捷键说明

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