KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejen > ext > XSLUtil


1 //
2
// Ejen (code generation system)
3
// Copyright (C) 2001, 2002 François Wolff (ejen@noos.fr).
4
//
5
// This file is part of Ejen.
6
//
7
// Ejen is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License as published by
9
// the Free Software Foundation; either version 2 of the License, or
10
// (at your option) any later version.
11
//
12
// Ejen is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License for more details.
16
//
17
// You should have received a copy of the GNU General Public License
18
// along with Ejen; if not, write to the Free Software
19
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
//
21
package org.ejen.ext;
22
23 import org.w3c.dom.Node JavaDoc;
24 import org.w3c.dom.traversal.NodeIterator;
25 import org.apache.xalan.extensions.XSLProcessorContext;
26 import org.apache.xalan.extensions.ExpressionContext;
27 import org.apache.xalan.templates.ElemExtensionCall;
28
29 /**
30  * XSL operations utility (static methods).
31  * <p>
32  * This class only wrappes some methods implemented in the
33  * {@link org.ejen.util.XSLUtil} class.
34  * <p>
35  * <table class="usage">
36  * <tr><th class="usage">Usage (XSL stylesheet)</th></tr>
37  * <tr><td class="usage"><pre>
38  *
39  * &lt;?xml version="1.0" encoding="iso-8859-1"?&gt;
40  *
41  * &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
42  * ...
43  * <b>xmlns:xsu="org.ejen.ext.XSLUtil"
44  * extension-element-prefixes="xsu ..."
45  * exclude-result-prefixes="xsu ..."</b>
46  * version="1.0"&gt;
47  *
48  * &lt;xsl:output method="xml" encoding="iso-8859-1"/&gt;
49  *
50  * &lt;xsl:template match="ejen"&gt;
51  *
52  * &lt;xsu:{@link #evaluate(XSLProcessorContext,ElemExtensionCall) evaluate} avt="{./file}.xml"/&gt;
53  * &lt;xsl:variable name="avt" select="xsu:{@link #evaluate(ExpressionContext,String) evaluate}('{./file}.xml')"/&gt;
54  * &lt;xsl:if test="xsu:{@link #equals(ExpressionContext,NodeIterator,NodeIterator) equals}($nodes1,$nodes2)"&gt;
55  * ...
56  * &lt;/xsl:if&gt;
57  * &lt;xsl:if test="xsu:{@link #equals(ExpressionContext,Node,Node) equals}($node1,$node2)"&gt;
58  * ...
59  * &lt;/xsl:if&gt;
60  *
61  * &lt;/xsl:template&gt;
62  *
63  * &lt;/xsl:stylesheet&gt;
64  * </pre></td></tr></table>
65  * @author F. Wolff
66  * @version 1.0
67  */

68 public class XSLUtil {
69
70     /**
71      * Prevents instanciation.
72      */

73     protected XSLUtil() {}
74
75     /**
76      * Returns an interpreted value (AVT) of a Node attribute whose name is "avt".
77      * <p>
78      * <table class="usage"><tr><td class="usage"><pre>
79      *
80      * &lt;xsu:evaluate avt="{./file}.xml"/&gt;
81      * </pre></td></tr></table>
82      * <p>
83      * <dd><dl><dt><b>XSLT Attributes:</b>
84      * <dd>avt <b>[Mandatory/AVT]</b> AVT to be evaluated.
85      * </dl></dd>
86      * <p>
87      * @param context the XSLProcessorContext to be used.
88      * @param elem the ElemExtensionCall to be used.
89      * @return the evaluated result.
90      * @throws java.lang.IllegalArgumentException bad context.
91      * @throws org.apache.xml.utils.WrappedRuntimeException ...
92      */

93     public static String JavaDoc evaluate(XSLProcessorContext context, ElemExtensionCall elem) {
94         return org.ejen.util.XSLUtil.evaluate(context, elem);
95     }
96
97     /**
98      * Returns an interpreted value (AVT) of a Node attribute whose name is equals
99      * to the avt parameter.
100      * <p>
101      * <table class="usage"><tr><td class="usage"><pre>
102      *
103      * &lt;xsl:variable name="avt" select="xsu:evaluate('{./file}.xml')"&gt;
104      * </pre></td></tr></table>
105      * <p>
106      * <dd><dl><dt><b>XSLT parameters:</b>
107      * <dd><b>[Mandatory/AVT]</b> AVT expression to be evaluated.
108      * </dl></dd>
109      * <p>
110      * @param context automatically passed by the xalan extension mechanism.
111      * @param avt the name of the attribute.
112      * @return the evaluated result.
113      * @throws java.lang.IllegalArgumentException bad context.
114      * @throws org.apache.xml.utils.WrappedRuntimeException ...
115      */

116     public static String JavaDoc evaluate(ExpressionContext context, String JavaDoc avt) {
117         return org.ejen.util.XSLUtil.evaluate(context, avt);
118     }
119
120     /**
121      * Checks ni1 and ni2 for strict equality (same names, same attributes,
122      * same child nodes...).
123      * <p>
124      * <table class="usage"><tr><td class="usage"><pre>
125      *
126      * &lt;xsl:if test="xsu:equals($nodes1,$nodes2)"&gt;
127      * ...
128      * &lt;/xsl:if&gt;
129      * </pre></td></tr></table>
130      * <p>
131      * <dd><dl><dt><b>XSLT parameters:</b>
132      * <dd><b>[Mandatory]</b> the first NodeIterator.
133      * <dd><b>[Mandatory]</b> the second NodeIterator.
134      * </dl></dd>
135      * <p>
136      * @param context automatically passed by the xalan extension mechanism.
137      * @param ni1 the first NodeIterator.
138      * @param ni2 the second NodeIterator.
139      * @return true if ni1 equals ni2, false otherwise.
140      */

141     public static boolean equals(ExpressionContext context, NodeIterator ni1, NodeIterator ni2) {
142         return org.ejen.util.XSLUtil.equals(ni1, ni2);
143     }
144
145     /**
146      * Checks n1 and n2 for strict equality (same names, same attributes,
147      * same child nodes...).
148      * <p>
149      * <table class="usage"><tr><td class="usage"><pre>
150      *
151      * &lt;xsl:if test="xsu:equals($node1,$node2)"&gt;
152      * ...
153      * &lt;/xsl:if&gt;
154      * </pre></td></tr></table>
155      * <p>
156      * <dd><dl><dt><b>XSLT parameters:</b>
157      * <dd><b>[Mandatory]</b> the first Node.
158      * <dd><b>[Mandatory]</b> the second Node.
159      * </dl></dd>
160      * <p>
161      * @param context automatically passed by the xalan extension mechanism.
162      * @param n1 the first Node.
163      * @param n2 the second Node.
164      * @return true if n1 equals n2, false otherwise.
165      */

166     public static boolean equals(ExpressionContext context, Node JavaDoc n1, Node JavaDoc n2) {
167         return org.ejen.util.XSLUtil.equals(n1, n2);
168     }
169 }
170
Popular Tags