annotate NGSrich_0.5.5/src/org/jdom/xpath/JaxenXPath.java @ 0:89ad0a9cca52 default tip

Uploaded
author pfrommolt
date Mon, 21 Nov 2011 08:12:19 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1 ///*--
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
2 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
3 // $Id: JaxenXPath.java,v 1.20 2007/11/10 05:29:02 jhunter Exp $
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
4 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
5 // Copyright (C) 2000-2007 Jason Hunter & Brett McLaughlin.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
6 // All rights reserved.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
7 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
8 // Redistribution and use in source and binary forms, with or without
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
9 // modification, are permitted provided that the following conditions
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
10 // are met:
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
11 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
12 // 1. Redistributions of source code must retain the above copyright
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
13 // notice, this list of conditions, and the following disclaimer.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
14 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
15 // 2. Redistributions in binary form must reproduce the above copyright
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
16 // notice, this list of conditions, and the disclaimer that follows
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
17 // these conditions in the documentation and/or other materials
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
18 // provided with the distribution.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
19 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
20 // 3. The name "JDOM" must not be used to endorse or promote products
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
21 // derived from this software without prior written permission. For
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
22 // written permission, please contact <request_AT_jdom_DOT_org>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
23 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
24 // 4. Products derived from this software may not be called "JDOM", nor
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
25 // may "JDOM" appear in their name, without prior written permission
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
26 // from the JDOM Project Management <request_AT_jdom_DOT_org>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
27 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
28 // In addition, we request (but do not require) that you include in the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
29 // end-user documentation provided with the redistribution and/or in the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
30 // software itself an acknowledgement equivalent to the following:
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
31 // "This product includes software developed by the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
32 // JDOM Project (http://www.jdom.org/)."
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
33 // Alternatively, the acknowledgment may be graphical using the logos
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
34 // available at http://www.jdom.org/images/logos.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
35 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
36 // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
37 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
38 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
39 // DISCLAIMED. IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
40 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
41 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
42 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
43 // USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
44 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
45 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
46 // OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
47 // SUCH DAMAGE.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
48 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
49 // This software consists of voluntary contributions made by many
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
50 // individuals on behalf of the JDOM Project and was originally
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
51 // created by Jason Hunter <jhunter_AT_jdom_DOT_org> and
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
52 // Brett McLaughlin <brett_AT_jdom_DOT_org>. For more information
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
53 // on the JDOM Project, please see <http://www.jdom.org/>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
54 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
55 // */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
56 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
57 //package org.jdom.xpath;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
58 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
59 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
60 //import java.util.*;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
61 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
62 //import org.jaxen.*;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
63 //import org.jaxen.jdom.*;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
64 //import org.jdom.*;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
65 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
66 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
67 ///**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
68 // * A non-public concrete XPath implementation for Jaxen.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
69 // *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
70 // * @version $Revision: 1.20 $, $Date: 2007/11/10 05:29:02 $
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
71 // * @author Laurent Bihanic
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
72 // */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
73 //class JaxenXPath extends XPath { // package protected
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
74 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
75 // private static final String CVS_ID =
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
76 // "@(#) $RCSfile: JaxenXPath.java,v $ $Revision: 1.20 $ $Date: 2007/11/10 05:29:02 $ $Name: jdom_1_1_1 $";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
77 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
78 // /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
79 // * The compiled XPath object to select nodes. This attribute can
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
80 // * not be made final as it needs to be set upon object
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
81 // * deserialization.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
82 // */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
83 // private transient JDOMXPath xPath;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
84 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
85 // /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
86 // * The current context for XPath expression evaluation.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
87 // */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
88 // private Object currentContext;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
89 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
90 // /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
91 // * Creates a new XPath wrapper object, compiling the specified
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
92 // * XPath expression.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
93 // *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
94 // * @param expr the XPath expression to wrap.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
95 // *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
96 // * @throws JDOMException if the XPath expression is invalid.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
97 // */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
98 // public JaxenXPath(String expr) throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
99 // setXPath(expr);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
100 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
101 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
102 // /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
103 // * Evaluates the wrapped XPath expression and returns the list
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
104 // * of selected items.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
105 // *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
106 // * @param context the node to use as context for evaluating
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
107 // * the XPath expression.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
108 // *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
109 // * @return the list of selected items, which may be of types: {@link Element},
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
110 // * {@link Attribute}, {@link Text}, {@link CDATA},
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
111 // * {@link Comment}, {@link ProcessingInstruction}, Boolean,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
112 // * Double, or String.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
113 // *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
114 // * @throws JDOMException if the evaluation of the XPath
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
115 // * expression on the specified context
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
116 // * failed.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
117 // */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
118 // public List selectNodes(Object context) throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
119 // try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
120 // currentContext = context;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
121 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
122 // return xPath.selectNodes(context);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
123 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
124 // catch (JaxenException ex1) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
125 // throw new JDOMException("XPath error while evaluating \"" +
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
126 // xPath.toString() + "\": " + ex1.getMessage(), ex1);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
127 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
128 // finally {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
129 // currentContext = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
130 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
131 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
132 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
133 // /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
134 // * Evaluates the wrapped XPath expression and returns the first
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
135 // * entry in the list of selected nodes (or atomics).
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
136 // *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
137 // * @param context the node to use as context for evaluating
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
138 // * the XPath expression.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
139 // *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
140 // * @return the first selected item, which may be of types: {@link Element},
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
141 // * {@link Attribute}, {@link Text}, {@link CDATA},
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
142 // * {@link Comment}, {@link ProcessingInstruction}, Boolean,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
143 // * Double, String, or <code>null</code> if no item was selected.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
144 // *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
145 // * @throws JDOMException if the evaluation of the XPath
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
146 // * expression on the specified context
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
147 // * failed.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
148 // */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
149 // public Object selectSingleNode(Object context) throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
150 // try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
151 // currentContext = context;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
152 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
153 // return xPath.selectSingleNode(context);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
154 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
155 // catch (JaxenException ex1) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
156 // throw new JDOMException("XPath error while evaluating \"" +
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
157 // xPath.toString() + "\": " + ex1.getMessage(), ex1);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
158 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
159 // finally {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
160 // currentContext = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
161 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
162 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
163 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
164 // /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
165 // * Returns the string value of the first node selected by applying
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
166 // * the wrapped XPath expression to the given context.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
167 // *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
168 // * @param context the element to use as context for evaluating
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
169 // * the XPath expression.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
170 // *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
171 // * @return the string value of the first node selected by applying
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
172 // * the wrapped XPath expression to the given context.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
173 // *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
174 // * @throws JDOMException if the XPath expression is invalid or
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
175 // * its evaluation on the specified context
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
176 // * failed.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
177 // */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
178 // public String valueOf(Object context) throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
179 // try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
180 // currentContext = context;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
181 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
182 // return xPath.stringValueOf(context);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
183 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
184 // catch (JaxenException ex1) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
185 // throw new JDOMException("XPath error while evaluating \"" +
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
186 // xPath.toString() + "\": " + ex1.getMessage(), ex1);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
187 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
188 // finally {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
189 // currentContext = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
190 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
191 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
192 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
193 // /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
194 // * Returns the number value of the first item selected by applying
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
195 // * the wrapped XPath expression to the given context.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
196 // *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
197 // * @param context the element to use as context for evaluating
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
198 // * the XPath expression.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
199 // *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
200 // * @return the number value of the first item selected by applying
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
201 // * the wrapped XPath expression to the given context,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
202 // * <code>null</code> if no node was selected or the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
203 // * special value {@link java.lang.Double#NaN}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
204 // * (Not-a-Number) if the selected value can not be
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
205 // * converted into a number value.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
206 // *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
207 // * @throws JDOMException if the XPath expression is invalid or
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
208 // * its evaluation on the specified context
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
209 // * failed.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
210 // */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
211 // public Number numberValueOf(Object context) throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
212 // try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
213 // currentContext = context;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
214 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
215 // return xPath.numberValueOf(context);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
216 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
217 // catch (JaxenException ex1) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
218 // throw new JDOMException("XPath error while evaluating \"" +
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
219 // xPath.toString() + "\": " + ex1.getMessage(), ex1);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
220 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
221 // finally {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
222 // currentContext = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
223 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
224 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
225 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
226 // /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
227 // * Defines an XPath variable and sets its value.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
228 // *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
229 // * @param name the variable name.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
230 // * @param value the variable value.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
231 // *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
232 // * @throws IllegalArgumentException if <code>name</code> is not
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
233 // * a valid XPath variable name
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
234 // * or if the value type is not
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
235 // * supported by the underlying
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
236 // * implementation
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
237 // */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
238 // public void setVariable(String name, Object value)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
239 // throws IllegalArgumentException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
240 // Object o = xPath.getVariableContext();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
241 // if (o instanceof SimpleVariableContext) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
242 // ((SimpleVariableContext)o).setVariableValue(null, name, value);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
243 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
244 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
245 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
246 // /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
247 // * Adds a namespace definition to the list of namespaces known of
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
248 // * this XPath expression.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
249 // * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
250 // * <strong>Note</strong>: In XPath, there is no such thing as a
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
251 // * 'default namespace'. The empty prefix <b>always</b> resolves
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
252 // * to the empty namespace URI.</p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
253 // *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
254 // * @param namespace the namespace.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
255 // */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
256 // public void addNamespace(Namespace namespace) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
257 // try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
258 // xPath.addNamespace(namespace.getPrefix(), namespace.getURI());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
259 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
260 // catch (JaxenException ex1) { /* Can't happen here. */ }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
261 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
262 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
263 // /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
264 // * Returns the wrapped XPath expression as a string.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
265 // *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
266 // * @return the wrapped XPath expression as a string.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
267 // */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
268 // public String getXPath() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
269 // return (xPath.toString());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
270 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
271 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
272 // /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
273 // * Compiles and sets the XPath expression wrapped by this object.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
274 // *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
275 // * @param expr the XPath expression to wrap.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
276 // *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
277 // * @throws JDOMException if the XPath expression is invalid.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
278 // */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
279 // private void setXPath(String expr) throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
280 // try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
281 // xPath = new JDOMXPath(expr);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
282 // xPath.setNamespaceContext(new NSContext());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
283 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
284 // catch (Exception ex1) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
285 // throw new JDOMException(
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
286 // "Invalid XPath expression: \"" + expr + "\"", ex1);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
287 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
288 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
289 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
290 // public String toString() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
291 // return (xPath.toString());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
292 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
293 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
294 // public boolean equals(Object o) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
295 // if (o instanceof JaxenXPath) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
296 // JaxenXPath x = (JaxenXPath)o;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
297 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
298 // return (super.equals(o) &&
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
299 // xPath.toString().equals(x.xPath.toString()));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
300 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
301 // return false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
302 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
303 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
304 // public int hashCode() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
305 // return xPath.hashCode();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
306 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
307 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
308 // private class NSContext extends SimpleNamespaceContext {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
309 // public NSContext() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
310 // super();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
311 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
312 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
313 // /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
314 // * <i>[Jaxen NamespaceContext interface support]</i> Translates
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
315 // * the provided namespace prefix into the matching bound
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
316 // * namespace URI.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
317 // *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
318 // * @param prefix the namespace prefix to resolve.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
319 // *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
320 // * @return the namespace URI matching the prefix.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
321 // */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
322 // public String translateNamespacePrefixToUri(String prefix) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
323 // if ((prefix == null) || (prefix.length() == 0)) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
324 // return null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
325 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
326 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
327 // String uri = super.translateNamespacePrefixToUri(prefix);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
328 // if (uri == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
329 // Object ctx = currentContext;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
330 // if (ctx != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
331 // Element elt = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
332 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
333 // // Get closer element node
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
334 // if (ctx instanceof Element) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
335 // elt = (Element)ctx;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
336 // } else if (ctx instanceof Attribute) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
337 // elt = ((Attribute)ctx).getParent();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
338 // } else if (ctx instanceof Content) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
339 // elt = ((Content) ctx).getParentElement();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
340 // } else if (ctx instanceof Document) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
341 // elt = ((Document)ctx).getRootElement();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
342 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
343 //
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
344 // if (elt != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
345 // Namespace ns = elt.getNamespace(prefix);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
346 // if (ns != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
347 // uri = ns.getURI();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
348 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
349 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
350 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
351 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
352 // return uri;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
353 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
354 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
355 //}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
356