outputproperties.java

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

JAVA
1,123
字号
  public void setQNameProperties(QName key, Vector v)  {    setQNameProperties(key.toNamespacedString(), v);  }  /**   * Set an output property with a QName list value.  The QNames will be turned   * into strings with the namespace in curly brackets.   *   * @param key the key to be placed into the property list.   * @param v non-null list of QNames corresponding to <tt>key</tt>.   * @see javax.xml.transform.OutputKeys   */  public void setQNameProperties(String key, Vector v)  {    int s = v.size();    // Just an initial guess at reasonable tuning parameters    FastStringBuffer fsb = new FastStringBuffer(9,9);    for (int i = 0; i < s; i++)    {      QName qname = (QName) v.elementAt(i);      fsb.append(qname.toNamespacedString());      // Don't append space after last value      if (i < s-1)         fsb.append(' ');    }    m_properties.put(key, fsb.toString());  }  /**   * Searches for the list of qname properties with the specified key in   * the property list.   * If the key is not found in this property list, the default property list,   * and its defaults, recursively, are then checked. The method returns   * <code>null</code> if the property is not found.   *   * @param   key   the property key.   * @return  the value in this property list as a vector of QNames, or false   * if null or not "yes".   */  public Vector getQNameProperties(QName key)  {    return getQNameProperties(key.toNamespacedString());  }  /**   * Searches for the list of qname properties with the specified key in   * the property list.   * If the key is not found in this property list, the default property list,   * and its defaults, recursively, are then checked. The method returns   * <code>null</code> if the property is not found.   *   * @param   key   the property key.   * @return  the value in this property list as a vector of QNames, or false   * if null or not "yes".   */  public Vector getQNameProperties(String key)  {    return getQNameProperties(key, m_properties);  }  /**   * Searches for the list of qname properties with the specified key in   * the property list.   * If the key is not found in this property list, the default property list,   * and its defaults, recursively, are then checked. The method returns   * <code>null</code> if the property is not found.   *   * @param   key   the property key.   * @param props the list of properties to search in.   * @return  the value in this property list as a vector of QNames, or false   * if null or not "yes".   */  public static Vector getQNameProperties(String key, Properties props)  {    String s = props.getProperty(key);    if (null != s)    {      Vector v = new Vector();      int l = s.length();      boolean inCurly = false;      FastStringBuffer buf = new FastStringBuffer();      // parse through string, breaking on whitespaces.  I do this instead       // of a tokenizer so I can track whitespace inside of curly brackets,       // which theoretically shouldn't happen if they contain legal URLs.      for (int i = 0; i < l; i++)      {        char c = s.charAt(i);        if (Character.isWhitespace(c))        {          if (!inCurly)          {            if (buf.length() > 0)            {              QName qname = QName.getQNameFromString(buf.toString());              v.addElement(qname);              buf.reset();            }            continue;          }        }        else if ('{' == c)          inCurly = true;        else if ('}' == c)          inCurly = false;        buf.append(c);      }      if (buf.length() > 0)      {        QName qname = QName.getQNameFromString(buf.toString());        v.addElement(qname);        buf.reset();      }      return v;    }    else      return null;  }  /**   * This function is called to recompose all of the output format extended elements.   *   * @param root non-null reference to the stylesheet root object.   */  public void recompose(StylesheetRoot root)    throws TransformerException  {    root.recomposeOutput(this);  }  /**   * This function is called after everything else has been   * recomposed, and allows the template to set remaining   * values that may be based on some other property that   * depends on recomposition.   */  public void compose(StylesheetRoot sroot) throws TransformerException  {    super.compose(sroot);    m_propertiesLevels = null;  }  /**   * Get the Properties object that this class wraps.   *   * @return non-null reference to Properties object.   */  public Properties getProperties()  {    return m_properties;  }    /**   * Copy the keys and values from the source to this object.  This will   * not copy the default values.  This is meant to be used by going from   * a higher precedence object to a lower precedence object, so that if a   * key already exists, this method will not reset it.   *   * @param src non-null reference to the source properties.   */  public void copyFrom(Properties src)  {    copyFrom(src, true);  }  /**   * Copy the keys and values from the source to this object.  This will   * not copy the default values.  This is meant to be used by going from   * a higher precedence object to a lower precedence object, so that if a   * key already exists, this method will not reset it.   *   * @param src non-null reference to the source properties.   * @param shouldResetDefaults true if the defaults should be reset based on    *                            the method property.   */  public void copyFrom(Properties src, boolean shouldResetDefaults)  {    Enumeration enum = src.keys();    while (enum.hasMoreElements())    {      String key = (String) enum.nextElement();          if (!isLegalPropertyKey(key))        throw new IllegalArgumentException(XSLMessages.createMessage(XSLTErrorResources.ER_OUTPUT_PROPERTY_NOT_RECOGNIZED, new Object[]{key})); //"output property not recognized: "            Object oldValue = m_properties.get(key);      if (null == oldValue)      {        String val = (String) src.get(key);                if(shouldResetDefaults && key.equals(OutputKeys.METHOD))        {          setMethodDefaults(val);        }        m_properties.put(key, val);      }      else if (key.equals(OutputKeys.CDATA_SECTION_ELEMENTS))      {        m_properties.put(key, (String) oldValue + " " + (String) src.get(key));      }    }  }  /**   * Copy the keys and values from the source to this object.  This will   * not copy the default values.  This is meant to be used by going from   * a higher precedence object to a lower precedence object, so that if a   * key already exists, this method will not reset it.   *   * @param opsrc non-null reference to an OutputProperties.   */  public void copyFrom(OutputProperties opsrc)    throws TransformerException  {    checkDuplicates(opsrc);    copyFrom(opsrc.getProperties());  }  /**   * Check to see if a set of properties is at the same import level as the   * last set of properties set that was passed as an argument to this method.   * This operation assumes that the OutputProperties are being called   * from most important to least important, in document order.   *   * @param newProps non-null reference to OutputProperties that is about to   *                 be added to this set.   */  private void checkDuplicates(OutputProperties newProps)    throws TransformerException  {    if (null == m_propertiesLevels)      m_propertiesLevels = new Hashtable();    // This operation assumes that the OutputProperties are being called     // from most important to least important, in reverse document order.    int newPrecedence = newProps.getStylesheetComposed().getImportCountComposed();    Properties p = newProps.getProperties();    Enumeration enum = p.keys();    while (enum.hasMoreElements())    {      String key = (String) enum.nextElement();      if (key.equals(OutputKeys.CDATA_SECTION_ELEMENTS))        continue;      // Do we already have this property? Call hashtable operation,       // since we don't want to look at default properties.      Integer oldPrecedence = (Integer) m_propertiesLevels.get(key);      if (null == oldPrecedence)      {        m_propertiesLevels.put(key, new Integer(newPrecedence));      }      else if (newPrecedence >= oldPrecedence.intValue())      {        String oldValue = (String) this.m_properties.get(key);        String newValue = (String) newProps.m_properties.get(key);        if ( ((oldValue == null) && (newValue != null)) || !oldValue.equals(newValue) )        {          String msg = key + " can not be multiply defined at the same "                       + "import level! Old value = "                        + oldValue + "; New value = " + newValue;          throw new TransformerException(msg, newProps);        }      }    }}  /**   * Report if the key given as an argument is a legal xsl:output key.   *   * @param key non-null reference to key name.   *   * @return true if key is legal.   */  public boolean isLegalPropertyKey(String key)  {    return (key.equals(OutputKeys.CDATA_SECTION_ELEMENTS)            || key.equals(OutputKeys.DOCTYPE_PUBLIC)            || key.equals(OutputKeys.DOCTYPE_SYSTEM)            || key.equals(OutputKeys.ENCODING)            || key.equals(OutputKeys.INDENT)            || key.equals(OutputKeys.MEDIA_TYPE)            || key.equals(OutputKeys.METHOD)            || key.equals(OutputKeys.OMIT_XML_DECLARATION)            || key.equals(OutputKeys.STANDALONE)            || key.equals(OutputKeys.VERSION)            || (key.length() > 0) && (key.charAt(0) == '{'));  }  /**   *  This ugly field is used during recomposition to track the import precedence   *  at which each attribute was first specified, so we can flag errors about values being   *  set multiple time at the same precedence level. Note that this field is only used   *  during recomposition, with the OutputProperties object owned by the   *  {@link org.apache.xalan.templates.StylesheetRoot} object.   */  private transient Hashtable m_propertiesLevels;  /** The output properties.   *  @serial */  private Properties m_properties = null;  // Some special Xalan keys.  /** The number of whitespaces to indent by, if indent="yes". */  public static String S_KEY_INDENT_AMOUNT =    S_BUILTIN_EXTENSIONS_UNIVERSAL+"indent-amount";  /**   * Fully qualified name of class with a default constructor that   *  implements the ContentHandler interface, where the result tree events   *  will be sent to.         */  public static String S_KEY_CONTENT_HANDLER =    S_BUILTIN_EXTENSIONS_UNIVERSAL+"content-handler";  /** File name of file that specifies character to entity reference mappings. */  public static String S_KEY_ENTITIES =    S_BUILTIN_EXTENSIONS_UNIVERSAL+"entities";  /** Use a value of "yes" if the href values for HTML serialization should    *  use %xx escaping. */  public static String S_USE_URL_ESCAPING =    S_BUILTIN_EXTENSIONS_UNIVERSAL+"use-url-escaping";  /** Use a value of "yes" if the META tag should be omitted where it would   *  otherwise be supplied.   */  public static String S_OMIT_META_TAG =    S_BUILTIN_EXTENSIONS_UNIVERSAL+"omit-meta-tag";  /** The default properties of all output files. */  private static Properties m_xml_properties = null;  /** The default properties when method="html". */  private static Properties m_html_properties = null;  /** The default properties when method="text". */  private static Properties m_text_properties = null;  /** Synchronization object for lazy initialization of the above tables. */  private static Integer m_synch_object = new Integer(1);  /** a zero length Class array used in loadPropertiesFile() */  private static final Class[] NO_CLASSES = new Class[0];  /** a zero length Object array used in loadPropertiesFile() */  private static final Object[] NO_OBJS = new Object[0];}

⌨️ 快捷键说明

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