elemnumber.java

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

JAVA
1,968
字号
  /**   * Get the "lang" attribute.   * When numbering with an alphabetic sequence, the lang attribute   * specifies which language's alphabet is to be used; it has the same   * range of values as xml:lang [XML]; if no lang value is specified,   * the language should be determined from the system environment.   * Implementers should document for which languages they support numbering.   * @see <a href="http://www.w3.org/TR/xslt#convert">convert in XSLT Specification</a>   *   * @return Value ofr "lang" attribute.   */  public AVT getLang()  {    return m_lang_avt;  }  /**   * The letter-value attribute disambiguates between numbering   * sequences that use letters.   * @serial   */  private AVT m_lettervalue_avt = null;  /**   * Set the "letter-value" attribute.   * The letter-value attribute disambiguates between numbering sequences   * that use letters.   * @see <a href="http://www.w3.org/TR/xslt#convert">convert in XSLT Specification</a>   *   * @param v Value to set for "letter-value" attribute.   */  public void setLetterValue(AVT v)  {    m_lettervalue_avt = v;  }  /**   * Get the "letter-value" attribute.   * The letter-value attribute disambiguates between numbering sequences   * that use letters.   * @see <a href="http://www.w3.org/TR/xslt#convert">convert in XSLT Specification</a>   *   * @return Value to set for "letter-value" attribute.   */  public AVT getLetterValue()  {    return m_lettervalue_avt;  }  /**   * The grouping-separator attribute gives the separator   * used as a grouping (e.g. thousands) separator in decimal   * numbering sequences.   * @serial   */  private AVT m_groupingSeparator_avt = null;  /**   * Set the "grouping-separator" attribute.   * The grouping-separator attribute gives the separator   * used as a grouping (e.g. thousands) separator in decimal   * numbering sequences.   * @see <a href="http://www.w3.org/TR/xslt#convert">convert in XSLT Specification</a>   *   * @param v Value to set for "grouping-separator" attribute.   */  public void setGroupingSeparator(AVT v)  {    m_groupingSeparator_avt = v;  }  /**   * Get the "grouping-separator" attribute.   * The grouping-separator attribute gives the separator   * used as a grouping (e.g. thousands) separator in decimal   * numbering sequences.   * @see <a href="http://www.w3.org/TR/xslt#convert">convert in XSLT Specification</a>   *   * @return Value of "grouping-separator" attribute.   */  public AVT getGroupingSeparator()  {    return m_groupingSeparator_avt;  }  /**   * The optional grouping-size specifies the size (normally 3) of the grouping.   * @serial   */  private AVT m_groupingSize_avt = null;  /**   * Set the "grouping-size" attribute.   * The optional grouping-size specifies the size (normally 3) of the grouping.   * @see <a href="http://www.w3.org/TR/xslt#convert">convert in XSLT Specification</a>   *   * @param v Value to set for "grouping-size" attribute.   */  public void setGroupingSize(AVT v)  {    m_groupingSize_avt = v;  }  /**   * Get the "grouping-size" attribute.   * The optional grouping-size specifies the size (normally 3) of the grouping.   * @see <a href="http://www.w3.org/TR/xslt#convert">convert in XSLT Specification</a>   *   * @return Value of "grouping-size" attribute.   */  public AVT getGroupingSize()  {    return m_groupingSize_avt;  }  /**   * Shouldn't this be in the transformer?  Big worries about threads...   */  // private XResourceBundle thisBundle;  /**   * Table to help in converting decimals to roman numerals.   * @see org.apache.xalan.transformer.DecimalToRoman   */  private final static DecimalToRoman m_romanConvertTable[] = {    new DecimalToRoman(1000, "M", 900, "CM"),    new DecimalToRoman(500, "D", 400, "CD"),    new DecimalToRoman(100L, "C", 90L, "XC"),    new DecimalToRoman(50L, "L", 40L, "XL"),    new DecimalToRoman(10L, "X", 9L, "IX"),    new DecimalToRoman(5L, "V", 4L, "IV"),    new DecimalToRoman(1L, "I", 1L, "I") };  /**   * Chars for converting integers into alpha counts.   * @see TransformerImpl#int2alphaCount   */  private static char[] m_alphaCountTable = null;    /**   * 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);    StylesheetRoot.ComposeState cstate = sroot.getComposeState();    java.util.Vector vnames = cstate.getVariableNames();    if(null != m_countMatchPattern)      m_countMatchPattern.fixupVariables(vnames, cstate.getGlobalsSize());    if(null != m_format_avt)      m_format_avt.fixupVariables(vnames, cstate.getGlobalsSize());    if(null != m_fromMatchPattern)      m_fromMatchPattern.fixupVariables(vnames, cstate.getGlobalsSize());    if(null != m_groupingSeparator_avt)      m_groupingSeparator_avt.fixupVariables(vnames, cstate.getGlobalsSize());    if(null != m_groupingSize_avt)      m_groupingSize_avt.fixupVariables(vnames, cstate.getGlobalsSize());    if(null != m_lang_avt)      m_lang_avt.fixupVariables(vnames, cstate.getGlobalsSize());    if(null != m_lettervalue_avt)      m_lettervalue_avt.fixupVariables(vnames, cstate.getGlobalsSize());    if(null != m_valueExpr)      m_valueExpr.fixupVariables(vnames, cstate.getGlobalsSize());  }  /**   * Get an int constant identifying the type of element.   * @see org.apache.xalan.templates.Constants   *   * @return The token ID for this element   */  public int getXSLToken()  {    return Constants.ELEMNAME_NUMBER;  }  /**   * Return the node name.   *   * @return The element's name   */  public String getNodeName()  {    return Constants.ELEMNAME_NUMBER_STRING;  }  /**   * Execute an xsl:number instruction. The xsl:number element is   * used to insert a formatted number into the result tree.   *   * @param transformer non-null reference to the the current transform-time state.   * @param sourceNode non-null reference to the <a href="http://www.w3.org/TR/xslt#dt-current-node">current source node</a>.   * @param mode reference, which may be null, to the <a href="http://www.w3.org/TR/xslt#modes">current mode</a>.   *   * @throws TransformerException   */  public void execute(          TransformerImpl transformer)            throws TransformerException  {     if (TransformerImpl.S_DEBUG)      transformer.getTraceManager().fireTraceEvent(this);    int sourceNode = transformer.getXPathContext().getCurrentNode();    String countString = getCountString(transformer, sourceNode);    try    {      transformer.getResultTreeHandler().characters(countString.toCharArray(),                                                    0, countString.length());    }    catch(SAXException se)    {      throw new TransformerException(se);    }    finally    {      if (TransformerImpl.S_DEBUG)	    transformer.getTraceManager().fireTraceEndEvent(this);     }  }  /**   * Add a child to the child list.   *   * @param newChild Child to add to child list   *   * @return Child just added to child list   *   * @throws DOMException   */  public ElemTemplateElement appendChild(ElemTemplateElement newChild)  {    error(XSLTErrorResources.ER_CANNOT_ADD,          new Object[]{ newChild.getNodeName(),                        this.getNodeName() });  //"Can not add " +((ElemTemplateElement)newChild).m_elemName +    //" to " + this.m_elemName);    return null;  }  /**   * Given a 'from' pattern (ala xsl:number), a match pattern   * and a context, find the first ancestor that matches the   * pattern (including the context handed in).   *   * @param xctxt The XPath runtime state for this.   * @param fromMatchPattern The ancestor must match this pattern.   * @param countMatchPattern The ancestor must also match this pattern.   * @param context The node that "." expresses.   * @param namespaceContext The context in which namespaces in the   * queries are supposed to be expanded.   *   * @return the first ancestor that matches the given pattern   *   * @throws javax.xml.transform.TransformerException   */  int findAncestor(          XPathContext xctxt, XPath fromMatchPattern, XPath countMatchPattern,           int context, ElemNumber namespaceContext)            throws javax.xml.transform.TransformerException  {    DTM dtm = xctxt.getDTM(context);    while (DTM.NULL != context)    {      if (null != fromMatchPattern)      {        if (fromMatchPattern.getMatchScore(xctxt, context)                != XPath.MATCH_SCORE_NONE)        {          //context = null;          break;        }      }      if (null != countMatchPattern)      {        if (countMatchPattern.getMatchScore(xctxt, context)                != XPath.MATCH_SCORE_NONE)        {          break;        }      }      context = dtm.getParent(context);    }    return context;  }  /**   * Given a 'from' pattern (ala xsl:number), a match pattern   * and a context, find the first ancestor that matches the   * pattern (including the context handed in).   * @param xctxt The XPath runtime state for this.   * @param fromMatchPattern The ancestor must match this pattern.   * @param countMatchPattern The ancestor must also match this pattern.   * @param context The node that "." expresses.   * @param namespaceContext The context in which namespaces in the   * queries are supposed to be expanded.   *   * @return the first preceding, ancestor or self node that    * matches the given pattern   *   * @throws javax.xml.transform.TransformerException   */  private int findPrecedingOrAncestorOrSelf(          XPathContext xctxt, XPath fromMatchPattern, XPath countMatchPattern,           int context, ElemNumber namespaceContext)            throws javax.xml.transform.TransformerException  {    DTM dtm = xctxt.getDTM(context);    while (DTM.NULL != context)    {      if (null != fromMatchPattern)      {        if (fromMatchPattern.getMatchScore(xctxt, context)                != XPath.MATCH_SCORE_NONE)        {          context = DTM.NULL;          break;        }      }      if (null != countMatchPattern)      {        if (countMatchPattern.getMatchScore(xctxt, context)                != XPath.MATCH_SCORE_NONE)        {          break;        }      }      int prevSibling = dtm.getPreviousSibling(context);      if (DTM.NULL == prevSibling)      {        context = dtm.getParent(context);      }      else      {        // Now go down the chain of children of this sibling         context = dtm.getLastChild(prevSibling);        if (context == DTM.NULL)          context = prevSibling;      }    }    return context;  }  /**   * Get the count match pattern, or a default value.   *   * @param support The XPath runtime state for this.   * @param contextNode The node that "." expresses.   *   * @return the count match pattern, or a default value.    *   * @throws javax.xml.transform.TransformerException   */  XPath getCountMatchPattern(XPathContext support, int contextNode)          throws javax.xml.transform.TransformerException  {    XPath countMatchPattern = m_countMatchPattern;    DTM dtm = support.getDTM(contextNode);    if (null == countMatchPattern)    {      switch (dtm.getNodeType(contextNode))      {      case DTM.ELEMENT_NODE :        MyPrefixResolver resolver;        if (dtm.getNamespaceURI(contextNode) == null) {             resolver =  new MyPrefixResolver(dtm.getNode(contextNode), dtm,contextNode, false);        } else {            resolver = new MyPrefixResolver(dtm.getNode(contextNode), dtm,contextNode, true);        }        countMatchPattern = new XPath(dtm.getNodeName(contextNode), this, resolver,                                      XPath.MATCH, support.getErrorListener());        break;

⌨️ 快捷键说明

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