286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * Copyright 1999-2004 The Apache Software Foundation.
286N/A *
286N/A * Licensed under the Apache License, Version 2.0 (the "License");
286N/A * you may not use this file except in compliance with the License.
286N/A * You may obtain a copy of the License at
286N/A *
286N/A * http://www.apache.org/licenses/LICENSE-2.0
286N/A *
286N/A * Unless required by applicable law or agreed to in writing, software
286N/A * distributed under the License is distributed on an "AS IS" BASIS,
286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286N/A * See the License for the specific language governing permissions and
286N/A * limitations under the License.
286N/A */
286N/A/*
286N/A * $Id: ExsltCommon.java,v 1.2.4.1 2005/09/15 02:45:24 jeffsuttor Exp $
286N/A */
286N/Apackage com.sun.org.apache.xalan.internal.lib;
286N/A
286N/Aimport com.sun.org.apache.xalan.internal.extensions.ExpressionContext;
286N/Aimport com.sun.org.apache.xml.internal.dtm.DTMIterator;
286N/Aimport com.sun.org.apache.xml.internal.dtm.ref.DTMNodeIterator;
286N/Aimport com.sun.org.apache.xpath.internal.NodeSet;
286N/A
286N/A/**
286N/A * This class contains EXSLT common extension functions.
286N/A * It is accessed by specifying a namespace URI as follows:
286N/A * <pre>
286N/A * xmlns:exslt="http://exslt.org/common"
286N/A * </pre>
286N/A *
286N/A * The documentation for each function has been copied from the relevant
286N/A * EXSLT Implementer page.
286N/A *
286N/A * @see <a href="http://www.exslt.org/">EXSLT</a>
286N/A * @xsl.usage general
286N/A */
286N/Apublic class ExsltCommon
286N/A{
286N/A /**
286N/A * The exsl:object-type function returns a string giving the type of the object passed
286N/A * as the argument. The possible object types are: 'string', 'number', 'boolean',
286N/A * 'node-set', 'RTF', or 'external'.
286N/A *
286N/A * Most XSLT object types can be coerced to each other without error. However, there are
286N/A * certain coercions that raise errors, most importantly treating anything other than a
286N/A * node set as a node set. Authors of utilities such as named templates or user-defined
286N/A * extension functions may wish to give some flexibility in the parameter and argument values
286N/A * that are accepted by the utility; the exsl:object-type function enables them to do so.
286N/A *
286N/A * The Xalan extensions MethodResolver converts 'object-type' to 'objectType'.
286N/A *
286N/A * @param obj The object to be typed.
286N/A * @return objectType 'string', 'number', 'boolean', 'node-set', 'RTF', or 'external'.
286N/A *
286N/A * @see <a href="http://www.exslt.org/">EXSLT</a>
286N/A */
286N/A public static String objectType (Object obj)
286N/A {
286N/A if (obj instanceof String)
286N/A return "string";
286N/A else if (obj instanceof Boolean)
286N/A return "boolean";
286N/A else if (obj instanceof Number)
286N/A return "number";
286N/A else if (obj instanceof DTMNodeIterator)
286N/A {
286N/A DTMIterator dtmI = ((DTMNodeIterator)obj).getDTMIterator();
286N/A if (dtmI instanceof com.sun.org.apache.xpath.internal.axes.RTFIterator)
286N/A return "RTF";
286N/A else
286N/A return "node-set";
286N/A }
286N/A else
286N/A return "unknown";
286N/A }
286N/A
286N/A /**
286N/A * The exsl:node-set function converts a result tree fragment (which is what you get
286N/A * when you use the content of xsl:variable rather than its select attribute to give
286N/A * a variable value) into a node set. This enables you to process the XML that you create
286N/A * within a variable, and therefore do multi-step processing.
286N/A *
286N/A * You can also use this function to turn a string into a text node, which is helpful
286N/A * if you want to pass a string to a function that only accepts a node set.
286N/A *
286N/A * The Xalan extensions MethodResolver converts 'node-set' to 'nodeSet'.
286N/A *
286N/A * @param myProcessor is passed in by the Xalan extension processor
286N/A * @param rtf The result tree fragment to be converted to a node-set.
286N/A *
286N/A * @return node-set with the contents of the result tree fragment.
286N/A *
286N/A * Note: Already implemented in the xalan namespace as nodeset.
286N/A *
286N/A * @see <a href="http://www.exslt.org/">EXSLT</a>
286N/A */
286N/A public static NodeSet nodeSet(ExpressionContext myProcessor, Object rtf)
286N/A {
286N/A return Extensions.nodeset(myProcessor, rtf);
286N/A }
286N/A
286N/A}