KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > lib > ExsltCommon


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: ExsltCommon.java,v 1.10 2004/02/11 17:56:36 minchau Exp $
18  */

19 package org.apache.xalan.lib;
20
21 import org.apache.xalan.extensions.ExpressionContext;
22 import org.apache.xml.dtm.DTMIterator;
23 import org.apache.xml.dtm.ref.DTMNodeIterator;
24 import org.apache.xpath.NodeSet;
25
26 /**
27  * This class contains EXSLT common extension functions.
28  * It is accessed by specifying a namespace URI as follows:
29  * <pre>
30  * xmlns:exslt="http://exslt.org/common"
31  * </pre>
32  *
33  * The documentation for each function has been copied from the relevant
34  * EXSLT Implementer page.
35  *
36  * @see <a HREF="http://www.exslt.org/">EXSLT</a>
37  * @xsl.usage general
38  */

39 public class ExsltCommon
40 {
41   /**
42    * The exsl:object-type function returns a string giving the type of the object passed
43    * as the argument. The possible object types are: 'string', 'number', 'boolean',
44    * 'node-set', 'RTF', or 'external'.
45    *
46    * Most XSLT object types can be coerced to each other without error. However, there are
47    * certain coercions that raise errors, most importantly treating anything other than a
48    * node set as a node set. Authors of utilities such as named templates or user-defined
49    * extension functions may wish to give some flexibility in the parameter and argument values
50    * that are accepted by the utility; the exsl:object-type function enables them to do so.
51    *
52    * The Xalan extensions MethodResolver converts 'object-type' to 'objectType'.
53    *
54    * @param obj The object to be typed.
55    * @return objectType 'string', 'number', 'boolean', 'node-set', 'RTF', or 'external'.
56    *
57    * @see <a HREF="http://www.exslt.org/">EXSLT</a>
58    */

59   public static String JavaDoc objectType (Object JavaDoc obj)
60   {
61     if (obj instanceof String JavaDoc)
62       return "string";
63     else if (obj instanceof Boolean JavaDoc)
64       return "boolean";
65     else if (obj instanceof Number JavaDoc)
66       return "number";
67     else if (obj instanceof DTMNodeIterator)
68     {
69       DTMIterator dtmI = ((DTMNodeIterator)obj).getDTMIterator();
70       if (dtmI instanceof org.apache.xpath.axes.RTFIterator)
71         return "RTF";
72       else
73         return "node-set";
74     }
75     else
76       return "unknown";
77   }
78     
79   /**
80    * The exsl:node-set function converts a result tree fragment (which is what you get
81    * when you use the content of xsl:variable rather than its select attribute to give
82    * a variable value) into a node set. This enables you to process the XML that you create
83    * within a variable, and therefore do multi-step processing.
84    *
85    * You can also use this function to turn a string into a text node, which is helpful
86    * if you want to pass a string to a function that only accepts a node set.
87    *
88    * The Xalan extensions MethodResolver converts 'node-set' to 'nodeSet'.
89    *
90    * @param myProcesser is passed in by the Xalan extension processor
91    * @param rtf The result tree fragment to be converted to a node-set.
92    *
93    * @return node-set with the contents of the result tree fragment.
94    *
95    * Note: Already implemented in the xalan namespace as nodeset.
96    *
97    * @see <a HREF="http://www.exslt.org/">EXSLT</a>
98    */

99   public static NodeSet nodeSet(ExpressionContext myProcessor, Object JavaDoc rtf)
100   {
101     return Extensions.nodeset(myProcessor, rtf);
102   }
103  
104 }
105
Popular Tags