6
|
1 |
/*
|
|
2 |
* reserved comment block
|
|
3 |
* DO NOT REMOVE OR ALTER!
|
|
4 |
*/
|
|
5 |
/*
|
|
6 |
* Copyright 1999-2004 The Apache Software Foundation.
|
|
7 |
*
|
|
8 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9 |
* you may not use this file except in compliance with the License.
|
|
10 |
* You may obtain a copy of the License at
|
|
11 |
*
|
|
12 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13 |
*
|
|
14 |
* Unless required by applicable law or agreed to in writing, software
|
|
15 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17 |
* See the License for the specific language governing permissions and
|
|
18 |
* limitations under the License.
|
|
19 |
*/
|
|
20 |
/*
|
|
21 |
* $Id: ExsltCommon.java,v 1.2.4.1 2005/09/15 02:45:24 jeffsuttor Exp $
|
|
22 |
*/
|
|
23 |
package com.sun.org.apache.xalan.internal.lib;
|
|
24 |
|
|
25 |
import com.sun.org.apache.xalan.internal.extensions.ExpressionContext;
|
|
26 |
import com.sun.org.apache.xml.internal.dtm.DTMIterator;
|
|
27 |
import com.sun.org.apache.xml.internal.dtm.ref.DTMNodeIterator;
|
|
28 |
import com.sun.org.apache.xpath.internal.NodeSet;
|
|
29 |
|
|
30 |
/**
|
|
31 |
* This class contains EXSLT common extension functions.
|
|
32 |
* It is accessed by specifying a namespace URI as follows:
|
|
33 |
* <pre>
|
|
34 |
* xmlns:exslt="http://exslt.org/common"
|
|
35 |
* </pre>
|
|
36 |
*
|
|
37 |
* The documentation for each function has been copied from the relevant
|
|
38 |
* EXSLT Implementer page.
|
|
39 |
*
|
|
40 |
* @see <a href="http://www.exslt.org/">EXSLT</a>
|
|
41 |
* @xsl.usage general
|
|
42 |
*/
|
|
43 |
public class ExsltCommon
|
|
44 |
{
|
|
45 |
/**
|
|
46 |
* The exsl:object-type function returns a string giving the type of the object passed
|
|
47 |
* as the argument. The possible object types are: 'string', 'number', 'boolean',
|
|
48 |
* 'node-set', 'RTF', or 'external'.
|
|
49 |
*
|
|
50 |
* Most XSLT object types can be coerced to each other without error. However, there are
|
|
51 |
* certain coercions that raise errors, most importantly treating anything other than a
|
|
52 |
* node set as a node set. Authors of utilities such as named templates or user-defined
|
|
53 |
* extension functions may wish to give some flexibility in the parameter and argument values
|
|
54 |
* that are accepted by the utility; the exsl:object-type function enables them to do so.
|
|
55 |
*
|
|
56 |
* The Xalan extensions MethodResolver converts 'object-type' to 'objectType'.
|
|
57 |
*
|
|
58 |
* @param obj The object to be typed.
|
|
59 |
* @return objectType 'string', 'number', 'boolean', 'node-set', 'RTF', or 'external'.
|
|
60 |
*
|
|
61 |
* @see <a href="http://www.exslt.org/">EXSLT</a>
|
|
62 |
*/
|
|
63 |
public static String objectType (Object obj)
|
|
64 |
{
|
|
65 |
if (obj instanceof String)
|
|
66 |
return "string";
|
|
67 |
else if (obj instanceof Boolean)
|
|
68 |
return "boolean";
|
|
69 |
else if (obj instanceof Number)
|
|
70 |
return "number";
|
|
71 |
else if (obj instanceof DTMNodeIterator)
|
|
72 |
{
|
|
73 |
DTMIterator dtmI = ((DTMNodeIterator)obj).getDTMIterator();
|
|
74 |
if (dtmI instanceof com.sun.org.apache.xpath.internal.axes.RTFIterator)
|
|
75 |
return "RTF";
|
|
76 |
else
|
|
77 |
return "node-set";
|
|
78 |
}
|
|
79 |
else
|
|
80 |
return "unknown";
|
|
81 |
}
|
|
82 |
|
|
83 |
/**
|
|
84 |
* The exsl:node-set function converts a result tree fragment (which is what you get
|
|
85 |
* when you use the content of xsl:variable rather than its select attribute to give
|
|
86 |
* a variable value) into a node set. This enables you to process the XML that you create
|
|
87 |
* within a variable, and therefore do multi-step processing.
|
|
88 |
*
|
|
89 |
* You can also use this function to turn a string into a text node, which is helpful
|
|
90 |
* if you want to pass a string to a function that only accepts a node set.
|
|
91 |
*
|
|
92 |
* The Xalan extensions MethodResolver converts 'node-set' to 'nodeSet'.
|
|
93 |
*
|
|
94 |
* @param myProcessor is passed in by the Xalan extension processor
|
|
95 |
* @param rtf The result tree fragment to be converted to a node-set.
|
|
96 |
*
|
|
97 |
* @return node-set with the contents of the result tree fragment.
|
|
98 |
*
|
|
99 |
* Note: Already implemented in the xalan namespace as nodeset.
|
|
100 |
*
|
|
101 |
* @see <a href="http://www.exslt.org/">EXSLT</a>
|
|
102 |
*/
|
|
103 |
public static NodeSet nodeSet(ExpressionContext myProcessor, Object rtf)
|
|
104 |
{
|
|
105 |
return Extensions.nodeset(myProcessor, rtf);
|
|
106 |
}
|
|
107 |
|
|
108 |
}
|