FileDocCategorySizeDatePackage
BasisLibrary.javaAPI DocJava SE 5 API47889Fri Aug 26 14:55:40 BST 2005com.sun.org.apache.xalan.internal.xsltc.runtime

BasisLibrary

public final class BasisLibrary extends Object implements Operators
Standard XSLT functions. All standard functions expect the current node and the DOM as their last two arguments.

Fields Summary
private static final String
EMPTYSTRING
private static final int
DOUBLE_FRACTION_DIGITS
private static final double
lowerBounds
private static final double
upperBounds
private static DecimalFormat
defaultFormatter
private static String
defaultPattern
private static FieldPosition
_fieldPosition
Utility function: used to format/adjust a double to a string. The DecimalFormat object comes from the 'formatSymbols' hashtable in AbstractTranslet.
private static char[]
_characterArray
Utility function: used in xsl:copy.
private static int
prefixIndex
This function is used in the execution of xsl:element
public static final String
RUN_TIME_INTERNAL_ERR
public static final String
RUN_TIME_COPY_ERR
public static final String
DATA_CONVERSION_ERR
public static final String
EXTERNAL_FUNC_ERR
public static final String
EQUALITY_EXPR_ERR
public static final String
INVALID_ARGUMENT_ERR
public static final String
FORMAT_NUMBER_ERR
public static final String
ITERATOR_CLONE_ERR
public static final String
AXIS_SUPPORT_ERR
public static final String
TYPED_AXIS_SUPPORT_ERR
public static final String
STRAY_ATTRIBUTE_ERR
public static final String
STRAY_NAMESPACE_ERR
public static final String
NAMESPACE_PREFIX_ERR
public static final String
DOM_ADAPTER_INIT_ERR
public static final String
PARSER_DTD_SUPPORT_ERR
public static final String
NAMESPACES_SUPPORT_ERR
public static final String
CANT_RESOLVE_RELATIVE_URI_ERR
public static final String
UNSUPPORTED_XSL_ERR
public static final String
UNSUPPORTED_EXT_ERR
public static final String
UNKNOWN_TRANSLET_VERSION_ERR
public static final String
INVALID_QNAME_ERR
public static final String
INVALID_NCNAME_ERR
protected static ResourceBundle
m_bundle
public static final String
ERROR_MESSAGES_KEY
Constructors Summary
Methods Summary
public static booleanbooleanF(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, "number()");
	}
	return false;
    
public static voidcheckAttribQName(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 (!XMLChar.isValidNCName(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 (!XMLChar.isValidNCName(newPrefix)) {
                runTimeError(INVALID_QNAME_ERR,newPrefix+":"+localName); 
            }  
        }
                
        // local name must be a valid NCName and must not be XMLNS
        if ((!XMLChar.isValidNCName(localName))||(localName.equals(Constants.XMLNS_PREFIX))) {
            runTimeError(INVALID_QNAME_ERR,localName); 
        }
    
public static voidcheckNCName(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 (!XMLChar.isValidNCName(name)) {
            runTimeError(INVALID_NCNAME_ERR,name); 
        }  
    
public static voidcheckQName(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 (!XMLChar.isValidQName(name)) {
            runTimeError(INVALID_QNAME_ERR,name); 
        }  
    
public static booleancompare(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 == EQ) {
                        return true;
                    } else if (op == NE) {
                        continue;
                    }
                }
		if (compareStrings(lvalue, dom.getStringValueX(rnode), op,
                                   dom)) {
		    return true;
		}
	    }
	} 
	return false;
    
public static booleancompare(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 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 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 LT:
	    // Assume we're comparing document order here
	    while ((rnode = iterator.next()) != DTMAxisIterator.END) {
		if (rnode > node) return true;
	    }
	    break;
	case GT:
	    // Assume we're comparing document order here
	    while ((rnode = iterator.next()) != DTMAxisIterator.END) {
		if (rnode < node) return true;
	    }
	    break;
	} 
	return(false);
    
public static booleancompare(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 EQ:
	    while ((node = left.next()) != DTMAxisIterator.END) {
		if (numberF(dom.getStringValueX(node), dom) == rnumber)
		    return true;
	    }
	    break;

	case NE:
	    while ((node = left.next()) != DTMAxisIterator.END) {
		if (numberF(dom.getStringValueX(node), dom) != rnumber)
		    return true;
	    }
	    break;

	case GT:
	    while ((node = left.next()) != DTMAxisIterator.END) {
		if (numberF(dom.getStringValueX(node), dom) > rnumber)
		    return true;
	    }
	    break;

	case LT:
	    while ((node = left.next()) != DTMAxisIterator.END) {
		if (numberF(dom.getStringValueX(node), dom) < rnumber)
		    return true;
	    }
	    break;

	case GE:
	    while ((node = left.next()) != DTMAxisIterator.END) {
		if (numberF(dom.getStringValueX(node), dom) >= rnumber)
		    return true;
	    }
	    break;

	case 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 booleancompare(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 booleancompare(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 != EQ && op != 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 GT:
		    return numberF(left, dom) > numberF(right, dom);
		    
		case LT:
		    return numberF(left, dom) < numberF(right, dom);
		    
		case GE:
		    return numberF(left, dom) >= numberF(right, dom);
		    
		case 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
		final Object temp = right; right = left; left = temp;
	    }

	    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 booleancompareStrings(java.lang.String lstring, java.lang.String rstring, int op, com.sun.org.apache.xalan.internal.xsltc.DOM dom)

	switch (op) {
	case EQ:
	    return lstring.equals(rstring);

	case NE:
	    return !lstring.equals(rstring);

	case GT:
	    return numberF(lstring, dom) > numberF(rstring, dom);

	case LT:
	    return numberF(lstring, dom) < numberF(rstring, dom);

	case GE:
	    return numberF(lstring, dom) >= numberF(rstring, dom);

	case LE:
	    return numberF(lstring, dom) <= numberF(rstring, dom);

	default:
	    runTimeError(RUN_TIME_INTERNAL_ERR, "compare()");
	    return false;
	}
    
public static voidconsoleOutput(java.lang.String msg)

	System.out.println(msg);
    
public static voidcopy(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 voidcopyNodes(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 intcountF(com.sun.org.apache.xml.internal.dtm.DTMAxisIterator iterator)
Standard function count(node-set)


            
         
	return(iterator.getLast());
    
public static java.lang.StringformatNumber(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.StringgeneratePrefix()

		// not thread safe!!
        
	return ("ns" + prefixIndex++);
    
public static java.lang.Stringgenerate_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.StringgetLocalName(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.StringgetPrefix(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.DTMAxisIteratorgetSingleNode(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 booleanhasSimpleType(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 booleanisWhiteSpace(char ch)

	return ch == ' " || ch == '\t" || ch == '\n" || ch == '\r";
    
public static java.lang.StringmapQNameToJavaName(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.Stringnamespace_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.Stringnamespace_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.DTMAxisIteratornode2Iterator(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.DTMAxisIteratornodeList2Iterator(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;
	}
	
        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.DTMAxisIteratornodesetF(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.Stringnormalize_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.Stringnormalize_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 doublenumberF(int node, com.sun.org.apache.xalan.internal.xsltc.DOM dom)
XSLT Standard function number()

	return stringToReal(dom.getStringValueX(node));
    
public static doublenumberF(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.StringobjectTypeF(java.lang.Object obj)
Implements the object-type() extension function.

see
EXSLT

      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 intpositionF(com.sun.org.apache.xml.internal.dtm.DTMAxisIterator iterator)
Standard function position()

deprecated
This method exists only for backwards compatibility with old translets. New code should not reference it.

        return iterator.isReverse()
                     ? iterator.getLast() - iterator.getPosition() + 1
                     : iterator.getPosition();
    
public static intrealToInt(double d)
Utility function: used in RealType to convert a real to an integer

	return (int)d;
    
public static java.lang.StringrealToString(double d)
Utility function: used in RealType to convert a real to a string. Removes the decimal if null.


     
	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);
    
	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));
	    return formatNumber(d, defaultPattern, defaultFormatter);
	}
    
public static booleanreferenceToBoolean(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 doublereferenceToDouble(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 longreferenceToLong(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.NodereferenceToNode(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.NodeListreferenceToNodeList(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.DTMAxisIteratorreferenceToNodeSet(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.DOMreferenceToResultTree(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.StringreferenceToString(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.Stringreplace(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.Stringreplace(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 doubleroundF(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 voidrunTimeError(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 voidrunTimeError(java.lang.String code, java.lang.Object[] args)

	final String message = MessageFormat.format(m_bundle.getString(code),
                                                    args);
	throw new RuntimeException(message);
    
public static voidrunTimeError(java.lang.String code, java.lang.Object arg0)

	runTimeError(code, new Object[]{ arg0 } );
    
public static voidrunTimeError(java.lang.String code, java.lang.Object arg0, java.lang.Object arg1)

	runTimeError(code, new Object[]{ arg0, arg1 } );
    
public static java.lang.StringstartXslElement(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.StringstringF(int node, com.sun.org.apache.xalan.internal.xsltc.DOM dom)
XSLT Standard function string()

	return dom.getStringValueX(node);
    
public static java.lang.StringstringF(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.StringstringF(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 {
	    if (obj != null)
		return obj.toString();
	    else
		return stringF(node, dom);
	}
    
public static intstringToInt(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 doublestringToReal(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.StringsubstringF(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.StringsubstringF(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.Stringsubstring_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.Stringsubstring_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 doublesumF(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.Stringsystem_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 booleantestLanguage(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.StringtranslateF(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 voidunresolved_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 voidunsupported_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);