elemnumber.java
来自「java jdk 1.4的源码」· Java 代码 · 共 1,968 行 · 第 1/5 页
JAVA
1,968 行
/* * 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;import org.apache.xml.utils.res.XResourceBundle;//import org.w3c.dom.*;//import org.w3c.dom.traversal.NodeIterator;import org.apache.xml.dtm.DTM;import org.apache.xml.dtm.DTMIterator;import org.w3c.dom.NamedNodeMap;import org.w3c.dom.Node;//import org.w3c.dom.xpath.XPathResult;import org.xml.sax.*;import java.util.*;import java.text.DecimalFormatSymbols;import java.text.NumberFormat;import java.text.DecimalFormat;import org.apache.xpath.*;import org.apache.xpath.objects.XObject;import org.apache.xpath.compiler.XPathParser;import org.apache.xml.utils.PrefixResolver;import org.apache.xml.utils.PrefixResolverDefault;import org.apache.xml.utils.QName;import org.apache.xml.utils.StringBufferPool;import org.apache.xml.utils.FastStringBuffer;import org.apache.xalan.res.*;import org.apache.xalan.transformer.DecimalToRoman;import org.apache.xalan.transformer.CountersTable;import org.apache.xalan.transformer.ResultTreeHandler;import org.apache.xalan.transformer.TransformerImpl;import org.apache.xml.utils.NodeVector;import javax.xml.transform.TransformerException;// import org.apache.xalan.dtm.*;/** * <meta name="usage" content="advanced"/> * Implement xsl:number. * <pre> * <!ELEMENT xsl:number EMPTY> * <!ATTLIST xsl:number * level (single|multiple|any) "single" * count %pattern; #IMPLIED * from %pattern; #IMPLIED * value %expr; #IMPLIED * format %avt; '1' * lang %avt; #IMPLIED * letter-value %avt; #IMPLIED * grouping-separator %avt; #IMPLIED * grouping-size %avt; #IMPLIED * > * </pre> * @see <a href="http://www.w3.org/TR/xslt#number">number in XSLT Specification</a> */public class ElemNumber extends ElemTemplateElement { private class MyPrefixResolver implements PrefixResolver { DTM dtm; int handle; boolean handleNullPrefix; /** * Constructor for MyPrefixResolver. * @param xpathExpressionContext */ public MyPrefixResolver(Node xpathExpressionContext, DTM dtm, int handle, boolean handleNullPrefix) { this.dtm = dtm; this.handle = handle; this.handleNullPrefix = handleNullPrefix; } /** * @see PrefixResolver#getNamespaceForPrefix(String, Node) */ public String getNamespaceForPrefix(String prefix) { return dtm.getNamespaceURI(handle); } /** * @see PrefixResolver#getNamespaceForPrefix(String, Node) * this shouldn't get called. */ public String getNamespaceForPrefix(String prefix, Node context) { return getNamespaceForPrefix(prefix); } /** * @see PrefixResolver#getBaseIdentifier() */ public String getBaseIdentifier() { return ElemNumber.this.getBaseIdentifier(); } /** * @see PrefixResolver#handlesNullPrefixes() */ public boolean handlesNullPrefixes() { return handleNullPrefix; }} /** * Only nodes are counted that match this pattern. * @serial */ private XPath m_countMatchPattern = null; /** * Set the "count" attribute. * The count attribute is a pattern that specifies what nodes * should be counted at those levels. If count attribute is not * specified, then it defaults to the pattern that matches any * node with the same node type as the current node and, if the * current node has an expanded-name, with the same expanded-name * as the current node. * * @param v Value to set for "count" attribute. */ public void setCount(XPath v) { m_countMatchPattern = v; } /** * Get the "count" attribute. * The count attribute is a pattern that specifies what nodes * should be counted at those levels. If count attribute is not * specified, then it defaults to the pattern that matches any * node with the same node type as the current node and, if the * current node has an expanded-name, with the same expanded-name * as the current node. * * @return Value of "count" attribute. */ public XPath getCount() { return m_countMatchPattern; } /** * Specifies where to count from. * For level="single" or level="multiple": * Only ancestors that are searched are * those that are descendants of the nearest ancestor that matches * the from pattern. * For level="any: * Only nodes after the first node before the * current node that match the from pattern are considered. * @serial */ private XPath m_fromMatchPattern = null; /** * Set the "from" attribute. Specifies where to count from. * For level="single" or level="multiple": * Only ancestors that are searched are * those that are descendants of the nearest ancestor that matches * the from pattern. * For level="any: * Only nodes after the first node before the * current node that match the from pattern are considered. * * @param v Value to set for "from" attribute. */ public void setFrom(XPath v) { m_fromMatchPattern = v; } /** * Get the "from" attribute. * For level="single" or level="multiple": * Only ancestors that are searched are * those that are descendants of the nearest ancestor that matches * the from pattern. * For level="any: * Only nodes after the first node before the * current node that match the from pattern are considered. * * @return Value of "from" attribute. */ public XPath getFrom() { return m_fromMatchPattern; } /** * When level="single", it goes up to the first node in the ancestor-or-self axis * that matches the count pattern, and constructs a list of length one containing * one plus the number of preceding siblings of that ancestor that match the count * pattern. If there is no such ancestor, it constructs an empty list. If the from * attribute is specified, then the only ancestors that are searched are those * that are descendants of the nearest ancestor that matches the from pattern. * Preceding siblings has the same meaning here as with the preceding-sibling axis. * * When level="multiple", it constructs a list of all ancestors of the current node * in document order followed by the element itself; it then selects from the list * those nodes that match the count pattern; it then maps each node in the list to * one plus the number of preceding siblings of that node that match the count pattern. * If the from attribute is specified, then the only ancestors that are searched are * those that are descendants of the nearest ancestor that matches the from pattern. * Preceding siblings has the same meaning here as with the preceding-sibling axis. * * When level="any", it constructs a list of length one containing the number of * nodes that match the count pattern and belong to the set containing the current * node and all nodes at any level of the document that are before the current node * in document order, excluding any namespace and attribute nodes (in other words * the union of the members of the preceding and ancestor-or-self axes). If the * from attribute is specified, then only nodes after the first node before the * current node that match the from pattern are considered. * @serial */ private int m_level = Constants.NUMBERLEVEL_SINGLE; /** * Set the "level" attribute. * The level attribute specifies what levels of the source tree should * be considered; it has the values single, multiple or any. The default * is single. * * @param v Value to set for "level" attribute. */ public void setLevel(int v) { m_level = v; } /** * Get the "level" attribute. * The level attribute specifies what levels of the source tree should * be considered; it has the values single, multiple or any. The default * is single. * * @return Value of "level" attribute. */ public int getLevel() { return m_level; } /** * The value attribute contains an expression. The expression is evaluated * and the resulting object is converted to a number as if by a call to the * number function. * @serial */ private XPath m_valueExpr = null; /** * Set the "value" attribute. * The value attribute contains an expression. The expression is evaluated * and the resulting object is converted to a number as if by a call to the * number function. * * @param v Value to set for "value" attribute. */ public void setValue(XPath v) { m_valueExpr = v; } /** * Get the "value" attribute. * The value attribute contains an expression. The expression is evaluated * and the resulting object is converted to a number as if by a call to the * number function. * * @return Value of "value" attribute. */ public XPath getValue() { return m_valueExpr; } /** * The "format" attribute is used to control conversion of a list of * numbers into a string. * @see <a href="http://www.w3.org/TR/xslt#convert">convert in XSLT Specification</a> * @serial */ private AVT m_format_avt = null; /** * Set the "format" attribute. * The "format" attribute is used to control conversion of a list of * numbers into a string. * @see <a href="http://www.w3.org/TR/xslt#convert">convert in XSLT Specification</a> * * @param v Value to set for "format" attribute. */ public void setFormat(AVT v) { m_format_avt = v; } /** * Get the "format" attribute. * The "format" attribute is used to control conversion of a list of * numbers into a string. * @see <a href="http://www.w3.org/TR/xslt#convert">convert in XSLT Specification</a> * * @return Value of "format" attribute. */ public AVT getFormat() { return m_format_avt; } /** * When numbering with an alphabetic sequence, the lang attribute * specifies which language's alphabet is to be used. * @serial */ private AVT m_lang_avt = null; /** * Set 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> * * @param v Value to set for "lang" attribute. */ public void setLang(AVT v) { m_lang_avt = v; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?