Methods Summary |
---|
public static boolean | booleanF(java.lang.Object obj)XSLT Standard function boolean()
if (obj instanceof Double) {
final double temp = ((Double) obj).doubleValue();
return temp != 0.0 && !Double.isNaN(temp);
}
else if (obj instanceof Integer) {
return ((Integer) obj).doubleValue() != 0;
}
else if (obj instanceof Boolean) {
return ((Boolean) obj).booleanValue();
}
else if (obj instanceof String) {
return !((String) obj).equals(EMPTYSTRING);
}
else if (obj instanceof DTMAxisIterator) {
DTMAxisIterator iter = (DTMAxisIterator) obj;
return iter.reset().next() != DTMAxisIterator.END;
}
else if (obj instanceof Node) {
return true;
}
else if (obj instanceof DOM) {
String temp = ((DOM) obj).getStringValue();
return !temp.equals(EMPTYSTRING);
}
else {
final String className = obj.getClass().getName();
runTimeError(INVALID_ARGUMENT_ERR, className, "boolean()");
}
return false;
|
public static void | checkAttribQName(java.lang.String name)Utility function to check if xsl:attribute has a valid qname
This method should only be invoked if the name attribute is an AVT
final int firstOccur = name.indexOf(":");
final int lastOccur = name.lastIndexOf(":");
final String localName = name.substring(lastOccur + 1);
if (firstOccur > 0) {
final String newPrefix = name.substring(0, firstOccur);
if (firstOccur != lastOccur) {
final String oriPrefix = name.substring(firstOccur+1, lastOccur);
if (!XML11Char.isXML11ValidNCName(oriPrefix)) {
// even though the orignal prefix is ignored, it should still get checked for valid NCName
runTimeError(INVALID_QNAME_ERR,oriPrefix+":"+localName);
}
}
// prefix must be a valid NCName
if (!XML11Char.isXML11ValidNCName(newPrefix)) {
runTimeError(INVALID_QNAME_ERR,newPrefix+":"+localName);
}
}
// local name must be a valid NCName and must not be XMLNS
if ((!XML11Char.isXML11ValidNCName(localName))||(localName.equals(Constants.XMLNS_PREFIX))) {
runTimeError(INVALID_QNAME_ERR,localName);
}
|
public static void | checkNCName(java.lang.String name)Utility function to check if a name is a valid ncname
This method should only be invoked if the attribute value is an AVT
if (!XML11Char.isXML11ValidNCName(name)) {
runTimeError(INVALID_NCNAME_ERR,name);
}
|
public static void | checkQName(java.lang.String name)Utility function to check if a name is a valid qname
This method should only be invoked if the attribute value is an AVT
if (!XML11Char.isXML11ValidQName(name)) {
runTimeError(INVALID_QNAME_ERR,name);
}
|
public static boolean | compare(com.sun.org.apache.xml.internal.dtm.DTMAxisIterator left, com.sun.org.apache.xml.internal.dtm.DTMAxisIterator right, int op, com.sun.org.apache.xalan.internal.xsltc.DOM dom)Utility function: node-set/node-set compare.
int lnode;
left.reset();
while ((lnode = left.next()) != DTMAxisIterator.END) {
final String lvalue = dom.getStringValueX(lnode);
int rnode;
right.reset();
while ((rnode = right.next()) != DTMAxisIterator.END) {
// String value must be the same if both nodes are the same
if (lnode == rnode) {
if (op == Operators.EQ) {
return true;
} else if (op == Operators.NE) {
continue;
}
}
if (compareStrings(lvalue, dom.getStringValueX(rnode), op,
dom)) {
return true;
}
}
}
return false;
|
public static boolean | compare(int node, com.sun.org.apache.xml.internal.dtm.DTMAxisIterator iterator, int op, com.sun.org.apache.xalan.internal.xsltc.DOM dom)
//iterator.reset();
int rnode;
String value;
switch(op) {
case Operators.EQ:
rnode = iterator.next();
if (rnode != DTMAxisIterator.END) {
value = dom.getStringValueX(node);
do {
if (node == rnode
|| value.equals(dom.getStringValueX(rnode))) {
return true;
}
} while ((rnode = iterator.next()) != DTMAxisIterator.END);
}
break;
case Operators.NE:
rnode = iterator.next();
if (rnode != DTMAxisIterator.END) {
value = dom.getStringValueX(node);
do {
if (node != rnode
&& !value.equals(dom.getStringValueX(rnode))) {
return true;
}
} while ((rnode = iterator.next()) != DTMAxisIterator.END);
}
break;
case Operators.LT:
// Assume we're comparing document order here
while ((rnode = iterator.next()) != DTMAxisIterator.END) {
if (rnode > node) return true;
}
break;
case Operators.GT:
// Assume we're comparing document order here
while ((rnode = iterator.next()) != DTMAxisIterator.END) {
if (rnode < node) return true;
}
break;
}
return(false);
|
public static boolean | compare(com.sun.org.apache.xml.internal.dtm.DTMAxisIterator left, double rnumber, int op, com.sun.org.apache.xalan.internal.xsltc.DOM dom)Utility function: node-set/number compare.
int node;
//left.reset();
switch (op) {
case Operators.EQ:
while ((node = left.next()) != DTMAxisIterator.END) {
if (numberF(dom.getStringValueX(node), dom) == rnumber)
return true;
}
break;
case Operators.NE:
while ((node = left.next()) != DTMAxisIterator.END) {
if (numberF(dom.getStringValueX(node), dom) != rnumber)
return true;
}
break;
case Operators.GT:
while ((node = left.next()) != DTMAxisIterator.END) {
if (numberF(dom.getStringValueX(node), dom) > rnumber)
return true;
}
break;
case Operators.LT:
while ((node = left.next()) != DTMAxisIterator.END) {
if (numberF(dom.getStringValueX(node), dom) < rnumber)
return true;
}
break;
case Operators.GE:
while ((node = left.next()) != DTMAxisIterator.END) {
if (numberF(dom.getStringValueX(node), dom) >= rnumber)
return true;
}
break;
case Operators.LE:
while ((node = left.next()) != DTMAxisIterator.END) {
if (numberF(dom.getStringValueX(node), dom) <= rnumber)
return true;
}
break;
default:
runTimeError(RUN_TIME_INTERNAL_ERR, "compare()");
}
return false;
|
public static boolean | compare(com.sun.org.apache.xml.internal.dtm.DTMAxisIterator left, java.lang.String rstring, int op, com.sun.org.apache.xalan.internal.xsltc.DOM dom)Utility function: node-set/string comparison.
int node;
//left.reset();
while ((node = left.next()) != DTMAxisIterator.END) {
if (compareStrings(dom.getStringValueX(node), rstring, op, dom)) {
return true;
}
}
return false;
|
public static boolean | compare(java.lang.Object left, java.lang.Object right, int op, com.sun.org.apache.xalan.internal.xsltc.DOM dom)
boolean result = false;
boolean hasSimpleArgs = hasSimpleType(left) && hasSimpleType(right);
if (op != Operators.EQ && op != Operators.NE) {
// If node-boolean comparison -> convert node to boolean
if (left instanceof Node || right instanceof Node) {
if (left instanceof Boolean) {
right = new Boolean(booleanF(right));
hasSimpleArgs = true;
}
if (right instanceof Boolean) {
left = new Boolean(booleanF(left));
hasSimpleArgs = true;
}
}
if (hasSimpleArgs) {
switch (op) {
case Operators.GT:
return numberF(left, dom) > numberF(right, dom);
case Operators.LT:
return numberF(left, dom) < numberF(right, dom);
case Operators.GE:
return numberF(left, dom) >= numberF(right, dom);
case Operators.LE:
return numberF(left, dom) <= numberF(right, dom);
default:
runTimeError(RUN_TIME_INTERNAL_ERR, "compare()");
}
}
// falls through
}
if (hasSimpleArgs) {
if (left instanceof Boolean || right instanceof Boolean) {
result = booleanF(left) == booleanF(right);
}
else if (left instanceof Double || right instanceof Double ||
left instanceof Integer || right instanceof Integer) {
result = numberF(left, dom) == numberF(right, dom);
}
else { // compare them as strings
result = stringF(left, dom).equals(stringF(right, dom));
}
if (op == Operators.NE) {
result = !result;
}
}
else {
if (left instanceof Node) {
left = new SingletonIterator(((Node)left).node);
}
if (right instanceof Node) {
right = new SingletonIterator(((Node)right).node);
}
if (hasSimpleType(left) ||
left instanceof DOM && right instanceof DTMAxisIterator) {
// swap operands and operator
final Object temp = right; right = left; left = temp;
op = Operators.swapOp(op);
}
if (left instanceof DOM) {
if (right instanceof Boolean) {
result = ((Boolean)right).booleanValue();
return result == (op == Operators.EQ);
}
final String sleft = ((DOM)left).getStringValue();
if (right instanceof Number) {
result = ((Number)right).doubleValue() ==
stringToReal(sleft);
}
else if (right instanceof String) {
result = sleft.equals((String)right);
}
else if (right instanceof DOM) {
result = sleft.equals(((DOM)right).getStringValue());
}
if (op == Operators.NE) {
result = !result;
}
return result;
}
// Next, node-set/t for t in {real, string, node-set, result-tree}
DTMAxisIterator iter = ((DTMAxisIterator)left).reset();
if (right instanceof DTMAxisIterator) {
result = compare(iter, (DTMAxisIterator)right, op, dom);
}
else if (right instanceof String) {
result = compare(iter, (String)right, op, dom);
}
else if (right instanceof Number) {
final double temp = ((Number)right).doubleValue();
result = compare(iter, temp, op, dom);
}
else if (right instanceof Boolean) {
boolean temp = ((Boolean)right).booleanValue();
result = (iter.reset().next() != DTMAxisIterator.END) == temp;
}
else if (right instanceof DOM) {
result = compare(iter, ((DOM)right).getStringValue(),
op, dom);
}
else if (right == null) {
return(false);
}
else {
final String className = right.getClass().getName();
runTimeError(INVALID_ARGUMENT_ERR, className, "compare()");
}
}
return result;
|
private static boolean | compareStrings(java.lang.String lstring, java.lang.String rstring, int op, com.sun.org.apache.xalan.internal.xsltc.DOM dom)
switch (op) {
case Operators.EQ:
return lstring.equals(rstring);
case Operators.NE:
return !lstring.equals(rstring);
case Operators.GT:
return numberF(lstring, dom) > numberF(rstring, dom);
case Operators.LT:
return numberF(lstring, dom) < numberF(rstring, dom);
case Operators.GE:
return numberF(lstring, dom) >= numberF(rstring, dom);
case Operators.LE:
return numberF(lstring, dom) <= numberF(rstring, dom);
default:
runTimeError(RUN_TIME_INTERNAL_ERR, "compare()");
return false;
}
|
public static void | consoleOutput(java.lang.String msg)
System.out.println(msg);
|
public static void | copy(java.lang.Object obj, com.sun.org.apache.xml.internal.serializer.SerializationHandler handler, int node, com.sun.org.apache.xalan.internal.xsltc.DOM dom)
try {
if (obj instanceof DTMAxisIterator)
{
DTMAxisIterator iter = (DTMAxisIterator) obj;
dom.copy(iter.reset(), handler);
}
else if (obj instanceof Node) {
dom.copy(((Node) obj).node, handler);
}
else if (obj instanceof DOM) {
//((DOM)obj).copy(((com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBase)((DOMAdapter)obj).getDOMImpl()).getDocument(), handler);
DOM newDom = (DOM)obj;
newDom.copy(newDom.getDocument(), handler);
}
else {
String string = obj.toString(); // or call stringF()
final int length = string.length();
if (length > _characterArray.length)
_characterArray = new char[length];
string.getChars(0, length, _characterArray, 0);
handler.characters(_characterArray, 0, length);
}
}
catch (SAXException e) {
runTimeError(RUN_TIME_COPY_ERR);
}
|
private static void | copyNodes(org.w3c.dom.NodeList nodeList, org.w3c.dom.Document doc, org.w3c.dom.Node parent)Utility function used to copy a node list to be under a parent node.
final int size = nodeList.getLength();
// copy Nodes from NodeList into new w3c DOM
for (int i = 0; i < size; i++)
{
org.w3c.dom.Node curr = nodeList.item(i);
int nodeType = curr.getNodeType();
String value = null;
try {
value = curr.getNodeValue();
} catch (DOMException ex) {
runTimeError(RUN_TIME_INTERNAL_ERR, ex.getMessage());
return;
}
String nodeName = curr.getNodeName();
org.w3c.dom.Node newNode = null;
switch (nodeType){
case org.w3c.dom.Node.ATTRIBUTE_NODE:
newNode = doc.createAttributeNS(curr.getNamespaceURI(),
nodeName);
break;
case org.w3c.dom.Node.CDATA_SECTION_NODE:
newNode = doc.createCDATASection(value);
break;
case org.w3c.dom.Node.COMMENT_NODE:
newNode = doc.createComment(value);
break;
case org.w3c.dom.Node.DOCUMENT_FRAGMENT_NODE:
newNode = doc.createDocumentFragment();
break;
case org.w3c.dom.Node.DOCUMENT_NODE:
newNode = doc.createElementNS(null, "__document__");
copyNodes(curr.getChildNodes(), doc, newNode);
break;
case org.w3c.dom.Node.DOCUMENT_TYPE_NODE:
// nothing?
break;
case org.w3c.dom.Node.ELEMENT_NODE:
// For Element node, also copy the children and the
// attributes.
org.w3c.dom.Element element = doc.createElementNS(
curr.getNamespaceURI(), nodeName);
if (curr.hasAttributes())
{
org.w3c.dom.NamedNodeMap attributes = curr.getAttributes();
for (int k = 0; k < attributes.getLength(); k++) {
org.w3c.dom.Node attr = attributes.item(k);
element.setAttributeNS(attr.getNamespaceURI(),
attr.getNodeName(), attr.getNodeValue());
}
}
copyNodes(curr.getChildNodes(), doc, element);
newNode = element;
break;
case org.w3c.dom.Node.ENTITY_NODE:
// nothing ?
break;
case org.w3c.dom.Node.ENTITY_REFERENCE_NODE:
newNode = doc.createEntityReference(nodeName);
break;
case org.w3c.dom.Node.NOTATION_NODE:
// nothing ?
break;
case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE:
newNode = doc.createProcessingInstruction(nodeName,
value);
break;
case org.w3c.dom.Node.TEXT_NODE:
newNode = doc.createTextNode(value);
break;
}
try {
parent.appendChild(newNode);
} catch (DOMException e) {
runTimeError(RUN_TIME_INTERNAL_ERR, e.getMessage());
return;
}
}
|
public static int | countF(com.sun.org.apache.xml.internal.dtm.DTMAxisIterator iterator)Standard function count(node-set)
return(iterator.getLast());
|
public static java.lang.String | formatNumber(double number, java.lang.String pattern, java.text.DecimalFormat formatter)
// bugzilla fix 12813
if (formatter == null) {
formatter = defaultFormatter;
}
try {
StringBuffer result = new StringBuffer();
if (pattern != defaultPattern) {
formatter.applyLocalizedPattern(pattern);
}
formatter.format(number, result, _fieldPosition);
return result.toString();
}
catch (IllegalArgumentException e) {
runTimeError(FORMAT_NUMBER_ERR, Double.toString(number), pattern);
return(EMPTYSTRING);
}
|
public static java.lang.String | generatePrefix() // not thread safe!!
return ("ns" + prefixIndex++);
|
public static java.lang.String | generate_idF(int node)XSLT Standard function generate-id().
if (node > 0)
// Only generate ID if node exists
return "N" + node;
else
// Otherwise return an empty string
return EMPTYSTRING;
|
public static java.lang.String | getLocalName(java.lang.String value)utility function for calls to local-name().
int idx = value.lastIndexOf(':");
if (idx >= 0) value = value.substring(idx + 1);
idx = value.lastIndexOf('@");
if (idx >= 0) value = value.substring(idx + 1);
return(value);
|
public static java.lang.String | getPrefix(java.lang.String qname)This function is used in the execution of xsl:element
final int index = qname.indexOf(':");
return (index > 0) ? qname.substring(0, index) : null;
|
public static com.sun.org.apache.xml.internal.dtm.DTMAxisIterator | getSingleNode(com.sun.org.apache.xml.internal.dtm.DTMAxisIterator iterator)Utility function: used with nth position filters to convert a sequence
of nodes to just one single node (the one at position n).
int node = iterator.next();
return(new SingletonIterator(node));
|
private static boolean | hasSimpleType(java.lang.Object obj)
return obj instanceof Boolean || obj instanceof Double ||
obj instanceof Integer || obj instanceof String ||
obj instanceof Node || obj instanceof DOM;
|
private static boolean | isWhiteSpace(char ch)
return ch == ' " || ch == '\t" || ch == '\n" || ch == '\r";
|
public static java.lang.String | mapQNameToJavaName(java.lang.String base)Utility method to allow setting parameters of the form
{namespaceuri}localName
which get mapped to an instance variable in the class
Hence a parameter of the form "{http://foo.bar}xyz"
will be replaced with the corresponding values
by the BasisLibrary's utility method mapQNametoJavaName
and thus get mapped to legal java variable names
return replace(base, ".-:/{}?#%*",
new String[] { "$dot$", "$dash$" ,"$colon$", "$slash$",
"","$colon$","$ques$","$hash$","$per$",
"$aster$"});
|
public static java.lang.String | namespace_uriF(com.sun.org.apache.xml.internal.dtm.DTMAxisIterator iter, com.sun.org.apache.xalan.internal.xsltc.DOM dom)XSLT Standard function namespace-uri(node-set).
return namespace_uriF(iter.next(), dom);
|
public static java.lang.String | namespace_uriF(int node, com.sun.org.apache.xalan.internal.xsltc.DOM dom)XSLT Standard function namespace-uri().
final String value = dom.getNodeName(node);
final int colon = value.lastIndexOf(':");
if (colon >= 0)
return value.substring(0, colon);
else
return EMPTYSTRING;
|
public static com.sun.org.apache.xml.internal.dtm.DTMAxisIterator | node2Iterator(org.w3c.dom.Node node, com.sun.org.apache.xalan.internal.xsltc.Translet translet, com.sun.org.apache.xalan.internal.xsltc.DOM dom)Utility function used to convert a w3c Node into an internal DOM iterator.
final org.w3c.dom.Node inNode = node;
// Create a dummy NodeList which only contains the given node to make
// use of the nodeList2Iterator() interface.
org.w3c.dom.NodeList nodelist = new org.w3c.dom.NodeList() {
public int getLength() {
return 1;
}
public org.w3c.dom.Node item(int index) {
if (index == 0)
return inNode;
else
return null;
}
};
return nodeList2Iterator(nodelist, translet, dom);
|
public static com.sun.org.apache.xml.internal.dtm.DTMAxisIterator | nodeList2Iterator(org.w3c.dom.NodeList nodeList, com.sun.org.apache.xalan.internal.xsltc.Translet translet, com.sun.org.apache.xalan.internal.xsltc.DOM dom)Utility function used to convert a w3c NodeList into a internal
DOM iterator.
// w3c NodeList -> w3c DOM
Document doc = null;
try {
doc = ((AbstractTranslet) translet).newDocument("", "__top__");
}
catch (javax.xml.parsers.ParserConfigurationException e) {
runTimeError(RUN_TIME_INTERNAL_ERR, e.getMessage());
return null;
}
// Copy all the nodes in the nodelist to be under the top element
copyNodes(nodeList, doc, doc.getDocumentElement());
// w3cDOM -> DTM -> DOMImpl
if (dom instanceof MultiDOM) {
final MultiDOM multiDOM = (MultiDOM) dom;
DTMDefaultBase dtm = (DTMDefaultBase)((DOMAdapter)multiDOM.getMain()).getDOMImpl();
DTMManager dtmManager = dtm.getManager();
DOM idom = (DOM)dtmManager.getDTM(new DOMSource(doc), false,
null, true, false);
// Create DOMAdapter and register with MultiDOM
DOMAdapter domAdapter = new DOMAdapter(idom,
translet.getNamesArray(),
translet.getUrisArray(),
translet.getTypesArray(),
translet.getNamespaceArray());
multiDOM.addDOMAdapter(domAdapter);
DTMAxisIterator iter1 = idom.getAxisIterator(Axis.CHILD);
DTMAxisIterator iter2 = idom.getAxisIterator(Axis.CHILD);
DTMAxisIterator iter = new AbsoluteIterator(
new StepIterator(iter1, iter2));
iter.setStartNode(DTMDefaultBase.ROOTNODE);
return iter;
}
else {
runTimeError(RUN_TIME_INTERNAL_ERR, "nodeList2Iterator()");
return null;
}
|
public static com.sun.org.apache.xml.internal.dtm.DTMAxisIterator | nodesetF(java.lang.Object obj)Implements the nodeset() extension function.
if (obj instanceof DOM) {
//final DOMAdapter adapter = (DOMAdapter) obj;
final DOM dom = (DOM)obj;
return new SingletonIterator(dom.getDocument(), true);
}
else if (obj instanceof DTMAxisIterator) {
return (DTMAxisIterator) obj;
}
else {
final String className = obj.getClass().getName();
runTimeError(DATA_CONVERSION_ERR, "node-set", className);
return null;
}
|
public static java.lang.String | normalize_spaceF(int node, com.sun.org.apache.xalan.internal.xsltc.DOM dom)XSLT Standard function normalize-space().
return normalize_spaceF(dom.getStringValueX(node));
|
public static java.lang.String | normalize_spaceF(java.lang.String value)XSLT Standard function normalize-space(string).
int i = 0, n = value.length();
StringBuffer result = new StringBuffer();
while (i < n && isWhiteSpace(value.charAt(i)))
i++;
while (true) {
while (i < n && !isWhiteSpace(value.charAt(i))) {
result.append(value.charAt(i++));
}
if (i == n)
break;
while (i < n && isWhiteSpace(value.charAt(i))) {
i++;
}
if (i < n)
result.append(' ");
}
return result.toString();
|
public static double | numberF(int node, com.sun.org.apache.xalan.internal.xsltc.DOM dom)XSLT Standard function number()
return stringToReal(dom.getStringValueX(node));
|
public static double | numberF(java.lang.Object obj, com.sun.org.apache.xalan.internal.xsltc.DOM dom)XSLT Standard function number(value)
if (obj instanceof Double) {
return ((Double) obj).doubleValue();
}
else if (obj instanceof Integer) {
return ((Integer) obj).doubleValue();
}
else if (obj instanceof Boolean) {
return ((Boolean) obj).booleanValue() ? 1.0 : 0.0;
}
else if (obj instanceof String) {
return stringToReal((String) obj);
}
else if (obj instanceof DTMAxisIterator) {
DTMAxisIterator iter = (DTMAxisIterator) obj;
return stringToReal(dom.getStringValueX(iter.reset().next()));
}
else if (obj instanceof Node) {
return stringToReal(dom.getStringValueX(((Node) obj).node));
}
else if (obj instanceof DOM) {
return stringToReal(((DOM) obj).getStringValue());
}
else {
final String className = obj.getClass().getName();
runTimeError(INVALID_ARGUMENT_ERR, className, "number()");
return 0.0;
}
|
public static java.lang.String | objectTypeF(java.lang.Object obj)Implements the object-type() extension function.
if (obj instanceof String)
return "string";
else if (obj instanceof Boolean)
return "boolean";
else if (obj instanceof Number)
return "number";
else if (obj instanceof DOM)
return "RTF";
else if (obj instanceof DTMAxisIterator)
return "node-set";
else
return "unknown";
|
public static int | positionF(com.sun.org.apache.xml.internal.dtm.DTMAxisIterator iterator)Standard function position()
return iterator.isReverse()
? iterator.getLast() - iterator.getPosition() + 1
: iterator.getPosition();
|
public static int | realToInt(double d)Utility function: used in RealType to convert a real to an integer
return (int)d;
|
public static java.lang.String | realToString(double d)Utility function: used in RealType to convert a real to a string.
Removes the decimal if null. Uses a specialized formatter object
for very large and very small numbers that ignores locales, thus
using always using "." as a decimal separator.
NumberFormat f = NumberFormat.getInstance(Locale.getDefault());
defaultFormatter = (f instanceof DecimalFormat) ?
(DecimalFormat) f : new DecimalFormat();
// Set max fraction digits so that truncation does not occur. Setting
// the max to Integer.MAX_VALUE may cause problems with some JDK's.
defaultFormatter.setMaximumFractionDigits(DOUBLE_FRACTION_DIGITS);
defaultFormatter.setMinimumFractionDigits(0);
defaultFormatter.setMinimumIntegerDigits(1);
defaultFormatter.setGroupingUsed(false);
// This formatter is used to convert numbers according to the XPath
// 1.0 syntax which ignores locales (http://www.w3.org/TR/xpath#NT-Number)
xpathFormatter = new DecimalFormat("",
new DecimalFormatSymbols(Locale.US));
xpathFormatter.setMaximumFractionDigits(DOUBLE_FRACTION_DIGITS);
xpathFormatter.setMinimumFractionDigits(0);
xpathFormatter.setMinimumIntegerDigits(1);
xpathFormatter.setGroupingUsed(false);
final double m = Math.abs(d);
if ((m >= lowerBounds) && (m < upperBounds)) {
final String result = Double.toString(d);
final int length = result.length();
// Remove leading zeros.
if ((result.charAt(length-2) == '.") &&
(result.charAt(length-1) == '0"))
return result.substring(0, length-2);
else
return result;
}
else {
if (Double.isNaN(d) || Double.isInfinite(d))
return(Double.toString(d));
// Use the XPath formatter to ignore locales
StringBuffer result = new StringBuffer();
xpathFormatter.format(d, result, _fieldPosition);
return result.toString();
}
|
public static boolean | referenceToBoolean(java.lang.Object obj)Utility function: used to convert reference to boolean.
if (obj instanceof Boolean) {
return ((Boolean) obj).booleanValue();
}
else {
final String className = obj.getClass().getName();
runTimeError(DATA_CONVERSION_ERR, className, Boolean.TYPE);
return false;
}
|
public static double | referenceToDouble(java.lang.Object obj)Utility function: used to convert reference to double.
if (obj instanceof Number) {
return ((Number) obj).doubleValue(); // handles Integer and Double
}
else {
final String className = obj.getClass().getName();
runTimeError(DATA_CONVERSION_ERR, className, Double.TYPE);
return 0;
}
|
public static long | referenceToLong(java.lang.Object obj)Utility function: used to convert reference to long.
if (obj instanceof Number) {
return ((Number) obj).longValue(); // handles Integer and Double
}
else {
final String className = obj.getClass().getName();
runTimeError(DATA_CONVERSION_ERR, className, Long.TYPE);
return 0;
}
|
public static org.w3c.dom.Node | referenceToNode(java.lang.Object obj, com.sun.org.apache.xalan.internal.xsltc.DOM dom)Utility function: used to convert reference to org.w3c.dom.Node.
if (obj instanceof Node || obj instanceof DTMAxisIterator) {
DTMAxisIterator iter = referenceToNodeSet(obj);
return dom.makeNode(iter);
}
else if (obj instanceof DOM) {
dom = (DOM)obj;
DTMAxisIterator iter = dom.getChildren(DTMDefaultBase.ROOTNODE);
return dom.makeNode(iter);
}
else {
final String className = obj.getClass().getName();
runTimeError(DATA_CONVERSION_ERR, className, "org.w3c.dom.Node");
return null;
}
|
public static org.w3c.dom.NodeList | referenceToNodeList(java.lang.Object obj, com.sun.org.apache.xalan.internal.xsltc.DOM dom)Utility function: used to convert reference to org.w3c.dom.NodeList.
if (obj instanceof Node || obj instanceof DTMAxisIterator) {
DTMAxisIterator iter = referenceToNodeSet(obj);
return dom.makeNodeList(iter);
}
else if (obj instanceof DOM) {
dom = (DOM)obj;
return dom.makeNodeList(DTMDefaultBase.ROOTNODE);
}
else {
final String className = obj.getClass().getName();
runTimeError(DATA_CONVERSION_ERR, className,
"org.w3c.dom.NodeList");
return null;
}
|
public static com.sun.org.apache.xml.internal.dtm.DTMAxisIterator | referenceToNodeSet(java.lang.Object obj)Utility function: used to convert references to node-sets. If the
obj is an instanceof Node then create a singleton iterator.
// Convert var/param -> node
if (obj instanceof Node) {
return(new SingletonIterator(((Node)obj).node));
}
// Convert var/param -> node-set
else if (obj instanceof DTMAxisIterator) {
return(((DTMAxisIterator)obj).cloneIterator());
}
else {
final String className = obj.getClass().getName();
runTimeError(DATA_CONVERSION_ERR, className, "node-set");
return null;
}
|
public static com.sun.org.apache.xalan.internal.xsltc.DOM | referenceToResultTree(java.lang.Object obj)Utility function used to convert references to DOMs.
try {
return ((DOM) obj);
}
catch (IllegalArgumentException e) {
final String className = obj.getClass().getName();
runTimeError(DATA_CONVERSION_ERR, "reference", className);
return null;
}
|
public static java.lang.String | referenceToString(java.lang.Object obj, com.sun.org.apache.xalan.internal.xsltc.DOM dom)Utility function: used to convert reference to String.
if (obj instanceof String) {
return (String) obj;
}
else if (obj instanceof DTMAxisIterator) {
return dom.getStringValueX(((DTMAxisIterator)obj).reset().next());
}
else if (obj instanceof Node) {
return dom.getStringValueX(((Node)obj).node);
}
else if (obj instanceof DOM) {
return ((DOM) obj).getStringValue();
}
else {
final String className = obj.getClass().getName();
runTimeError(DATA_CONVERSION_ERR, className, String.class);
return null;
}
|
public static java.lang.String | replace(java.lang.String base, char ch, java.lang.String str)Replace a certain character in a string with a new substring.
return (base.indexOf(ch) < 0) ? base :
replace(base, String.valueOf(ch), new String[] { str });
|
public static java.lang.String | replace(java.lang.String base, java.lang.String delim, java.lang.String[] str)
final int len = base.length();
final StringBuffer result = new StringBuffer();
for (int i = 0; i < len; i++) {
final char ch = base.charAt(i);
final int k = delim.indexOf(ch);
if (k >= 0) {
result.append(str[k]);
}
else {
result.append(ch);
}
}
return result.toString();
|
public static double | roundF(double d)XSLT Standard function round()
return (d<-0.5 || d>0.0)?Math.floor(d+0.5):((d==0.0)?
d:(Double.isNaN(d)?Double.NaN:-0.0));
|
public static void | runTimeError(java.lang.String code)Print a run-time error message.
String resource = "com.sun.org.apache.xalan.internal.xsltc.runtime.ErrorMessages";
m_bundle = ResourceBundle.getBundle(resource);
throw new RuntimeException(m_bundle.getString(code));
|
public static void | runTimeError(java.lang.String code, java.lang.Object[] args)
final String message = MessageFormat.format(m_bundle.getString(code),
args);
throw new RuntimeException(message);
|
public static void | runTimeError(java.lang.String code, java.lang.Object arg0)
runTimeError(code, new Object[]{ arg0 } );
|
public static void | runTimeError(java.lang.String code, java.lang.Object arg0, java.lang.Object arg1)
runTimeError(code, new Object[]{ arg0, arg1 } );
|
public static java.lang.String | startXslElement(java.lang.String qname, java.lang.String namespace, com.sun.org.apache.xml.internal.serializer.SerializationHandler handler, com.sun.org.apache.xalan.internal.xsltc.DOM dom, int node)Utility function for the implementation of xsl:element.
try {
// Get prefix from qname
String prefix;
final int index = qname.indexOf(':");
if (index > 0) {
prefix = qname.substring(0, index);
// Handle case when prefix is not known at compile time
if (namespace == null || namespace.length() == 0) {
try {
// not sure if this line of code ever works
namespace = dom.lookupNamespace(node, prefix);
}
catch(RuntimeException e) {
handler.flushPending(); // need to flush or else can't get namespacemappings
NamespaceMappings nm = handler.getNamespaceMappings();
namespace = nm.lookupNamespace(prefix);
if (namespace == null) {
runTimeError(NAMESPACE_PREFIX_ERR,prefix);
}
}
}
handler.startElement(namespace, qname.substring(index+1),
qname);
handler.namespaceAfterStartElement(prefix, namespace);
}
else {
// Need to generate a prefix?
if (namespace != null && namespace.length() > 0) {
prefix = generatePrefix();
qname = prefix + ':" + qname;
handler.startElement(namespace, qname, qname);
handler.namespaceAfterStartElement(prefix, namespace);
}
else {
handler.startElement(null, null, qname);
}
}
}
catch (SAXException e) {
throw new RuntimeException(e.getMessage());
}
return qname;
|
public static java.lang.String | stringF(int node, com.sun.org.apache.xalan.internal.xsltc.DOM dom)XSLT Standard function string()
return dom.getStringValueX(node);
|
public static java.lang.String | stringF(java.lang.Object obj, com.sun.org.apache.xalan.internal.xsltc.DOM dom)XSLT Standard function string(value)
if (obj instanceof DTMAxisIterator) {
return dom.getStringValueX(((DTMAxisIterator)obj).reset().next());
}
else if (obj instanceof Node) {
return dom.getStringValueX(((Node)obj).node);
}
else if (obj instanceof DOM) {
return ((DOM)obj).getStringValue();
}
else {
return obj.toString();
}
|
public static java.lang.String | stringF(java.lang.Object obj, int node, com.sun.org.apache.xalan.internal.xsltc.DOM dom)XSLT Standard function string(value)
if (obj instanceof DTMAxisIterator) {
return dom.getStringValueX(((DTMAxisIterator)obj).reset().next());
}
else if (obj instanceof Node) {
return dom.getStringValueX(((Node)obj).node);
}
else if (obj instanceof DOM) {
// When the first argument is a DOM we want the whole fecking
// DOM and not just a single node - that would not make sense.
//return ((DOM)obj).getStringValueX(node);
return ((DOM)obj).getStringValue();
}
else if (obj instanceof Double) {
Double d = (Double)obj;
final String result = d.toString();
final int length = result.length();
if ((result.charAt(length-2)=='.") &&
(result.charAt(length-1) == '0"))
return result.substring(0, length-2);
else
return result;
}
else {
return obj != null ? obj.toString() : "";
}
|
public static int | stringToInt(java.lang.String s)Utility function: used in StringType to convert a string to an int.
try {
return Integer.parseInt(s);
}
catch (NumberFormatException e) {
return(-1); // ???
}
|
public static double | stringToReal(java.lang.String s)Utility function: used in StringType to convert a string to a real.
try {
return Double.valueOf(s).doubleValue();
}
catch (NumberFormatException e) {
return Double.NaN;
}
|
public static java.lang.String | substringF(java.lang.String value, double start)XSLT Standard function substring(). Must take a double because of
conversions resulting into NaNs and rounding.
try {
final int strlen = value.length();
int istart = (int)Math.round(start) - 1;
if (Double.isNaN(start)) return(EMPTYSTRING);
if (istart > strlen) return(EMPTYSTRING);
if (istart < 1) istart = 0;
return value.substring(istart);
}
catch (IndexOutOfBoundsException e) {
runTimeError(RUN_TIME_INTERNAL_ERR, "substring()");
return null;
}
|
public static java.lang.String | substringF(java.lang.String value, double start, double length)XSLT Standard function substring(). Must take a double because of
conversions resulting into NaNs and rounding.
try {
final int strlen = value.length();
int istart = (int)Math.round(start) - 1;
int isum = istart + (int)Math.round(length);
if (Double.isInfinite(length)) isum = Integer.MAX_VALUE;
if (Double.isNaN(start) || Double.isNaN(length))
return(EMPTYSTRING);
if (Double.isInfinite(start)) return(EMPTYSTRING);
if (istart > strlen) return(EMPTYSTRING);
if (isum < 0) return(EMPTYSTRING);
if (istart < 0) istart = 0;
if (isum > strlen)
return value.substring(istart);
else
return value.substring(istart, isum);
}
catch (IndexOutOfBoundsException e) {
runTimeError(RUN_TIME_INTERNAL_ERR, "substring()");
return null;
}
|
public static java.lang.String | substring_afterF(java.lang.String value, java.lang.String substring)XSLT Standard function substring-after().
final int index = value.indexOf(substring);
if (index >= 0)
return value.substring(index + substring.length());
else
return EMPTYSTRING;
|
public static java.lang.String | substring_beforeF(java.lang.String value, java.lang.String substring)XSLT Standard function substring-before().
final int index = value.indexOf(substring);
if (index >= 0)
return value.substring(0, index);
else
return EMPTYSTRING;
|
public static double | sumF(com.sun.org.apache.xml.internal.dtm.DTMAxisIterator iterator, com.sun.org.apache.xalan.internal.xsltc.DOM dom)XSLT Standard function sum(node-set).
stringToDouble is inlined
try {
double result = 0.0;
int node;
while ((node = iterator.next()) != DTMAxisIterator.END) {
result += Double.parseDouble(dom.getStringValueX(node));
}
return result;
}
catch (NumberFormatException e) {
return Double.NaN;
}
|
public static java.lang.String | system_propertyF(java.lang.String name)XSLT Standard function system-property(name)
if (name.equals("xsl:version"))
return("1.0");
if (name.equals("xsl:vendor"))
return("Apache Software Foundation (Xalan XSLTC)");
if (name.equals("xsl:vendor-url"))
return("http://xml.apache.org/xalan-j");
runTimeError(INVALID_ARGUMENT_ERR, name, "system-property()");
return(EMPTYSTRING);
|
public static boolean | testLanguage(java.lang.String testLang, com.sun.org.apache.xalan.internal.xsltc.DOM dom, int node)Utility function: used to test context node's language
// language for context node (if any)
String nodeLang = dom.getLanguage(node);
if (nodeLang == null)
return(false);
else
nodeLang = nodeLang.toLowerCase();
// compare context node's language agains test language
testLang = testLang.toLowerCase();
if (testLang.length() == 2) {
return(nodeLang.startsWith(testLang));
}
else {
return(nodeLang.equals(testLang));
}
|
public static java.lang.String | translateF(java.lang.String value, java.lang.String from, java.lang.String to)XSLT Standard function translate().
final int tol = to.length();
final int froml = from.length();
final int valuel = value.length();
final StringBuffer result = new StringBuffer();
for (int j, i = 0; i < valuel; i++) {
final char ch = value.charAt(i);
for (j = 0; j < froml; j++) {
if (ch == from.charAt(j)) {
if (j < tol)
result.append(to.charAt(j));
break;
}
}
if (j == froml)
result.append(ch);
}
return result.toString();
|
public static void | unallowed_extension_elementF(java.lang.String name)Utility function to throw a runtime error on the use of an extension
element when the secure processing feature is set to true.
runTimeError(UNALLOWED_EXTENSION_ELEMENT_ERR, name);
|
public static void | unallowed_extension_functionF(java.lang.String name)Utility function to throw a runtime error on the use of an extension
function when the secure processing feature is set to true.
runTimeError(UNALLOWED_EXTENSION_FUNCTION_ERR, name);
|
public static void | unresolved_externalF(java.lang.String name)External functions that cannot be resolved are replaced with a call
to this method. This method will generate a runtime errors. A good
stylesheet checks whether the function exists using conditional
constructs, and never really tries to call it if it doesn't exist.
But simple stylesheets may result in a call to this method.
The compiler should generate a warning if it encounters a call to
an unresolved external function.
runTimeError(EXTERNAL_FUNC_ERR, name);
|
public static void | unsupported_ElementF(java.lang.String qname, boolean isExtension)Utility function to throw a runtime error for an unsupported element.
This is only used in forward-compatibility mode, when the control flow
cannot be determined. In 1.0 mode, the error message is emitted at
compile time.
if (isExtension)
runTimeError(UNSUPPORTED_EXT_ERR, qname);
else
runTimeError(UNSUPPORTED_XSL_ERR, qname);
|