Skip to content

Commit f9c8caa

Browse files
committed
better site
Migrate User's Guide to the Javadoc overview
1 parent d45af9d commit f9c8caa

File tree

5 files changed

+337
-269
lines changed

5 files changed

+337
-269
lines changed

src/main/java/org/apache/commons/jxpath/JXPathContext.java

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@
9191
* Address addr = (Address) context.getValue("homeAddress");
9292
* </pre>
9393
*
94-
* <h3>Example 3: Collection Subscripts</h3> JXPath can extract elements from arrays and collections.
94+
* <h3>Example 3: Collection Subscripts</h3>
95+
* <p>
96+
* JXPath can extract elements from arrays and collections.
97+
* </p>
9598
*
9699
* <pre>
97100
* public class Integers {
@@ -109,7 +112,8 @@
109112
*
110113
* A collection can be an arbitrary array or an instance of java.util. Collection.
111114
* <p>
112-
* Note: in XPath the first element of a collection has index 1, not 0.<br>
115+
* Note: in XPath the first element of a collection has index 1, not 0.
116+
* </p>
113117
*
114118
* <h3>Example 4: Map Element Access</h3>
115119
*
@@ -136,7 +140,9 @@
136140
* String homeZipCode = (String)context.getValue("addresses/home/zipCode");
137141
* </pre>
138142
*
143+
* <p>
139144
* Often you will need to use the alternative syntax for accessing Map elements:
145+
* </p>
140146
*
141147
* <pre>
142148
*
@@ -192,9 +198,12 @@
192198
*
193199
* </pre>
194200
*
195-
* <h3>Example 7: Creating objects</h3> JXPath can be used to create new objects. First, create a subclass of {@link AbstractFactory AbstractFactory} and
201+
* <h3>Example 7: Creating objects</h3>
202+
* <p>
203+
* JXPath can be used to create new objects. First, create a subclass of {@link AbstractFactory AbstractFactory} and
196204
* install it on the JXPathContext. Then call {@link JXPathContext#createPath createPathAndSetValue()} instead of "setValue". JXPathContext will invoke your
197205
* AbstractFactory when it discovers that an intermediate node of the path is <strong>null</strong>. It will not override existing nodes.
206+
* </p>
198207
*
199208
* <pre>
200209
* public class AddressFactory extends AbstractFactory {
@@ -213,7 +222,10 @@
213222
* context.createPathAndSetValue("address/zipCode", "90190");
214223
* </pre>
215224
*
216-
* <h3>Example 8: Using Variables</h3> JXPath supports the notion of variables. The XPath syntax for accessing variables is <em>"$varName"</em>.
225+
* <h3>Example 8: Using Variables</h3>
226+
* <p>
227+
* JXPath supports the notion of variables. The XPath syntax for accessing variables is <em>"$varName"</em>.
228+
* </p>
217229
*
218230
* <pre>
219231
* public class Author {
@@ -231,16 +243,21 @@
231243
* Book secondBook = (Book)context.getValue("books[$index]");
232244
* </pre>
233245
*
246+
* <p>
234247
* You can also set variables using JXPath:
248+
* </p>
235249
*
236250
* <pre>
237251
* context.setValue("$index", Integer.valueOf(3));
238252
* </pre>
239253
*
254+
* <p>
240255
* Note: you can only <em>change</em> the value of an existing variable this way, you cannot <em>define</em> a new variable.
256+
* </p>
241257
*
242258
* <p>
243259
* When a variable contains a JavaBean or a collection, you can traverse the bean or collection as well:
260+
* </p>
244261
*
245262
* <pre>
246263
* ...
@@ -254,8 +271,11 @@
254271
* String title = (String)context.getValue("$books[2]/title);
255272
* </pre>
256273
*
257-
* <h3>Example 9: Using Nested Contexts</h3> If you need to use the same set of variable while interpreting XPaths with different beans, it makes sense to put
274+
* <h3>Example 9: Using Nested Contexts</h3>
275+
* <p>
276+
* If you need to use the same set of variable while interpreting XPaths with different beans, it makes sense to put
258277
* the variables in a separate context and specify that context as a parent context every time you allocate a new JXPathContext for a JavaBean.
278+
* </p>
259279
*
260280
* <pre>
261281
* JXPathContext varContext = JXPathContext.newContext(null);
@@ -264,40 +284,54 @@
264284
* Iterator javaBooks = context.iterate("books[title = $title]");
265285
* </pre>
266286
*
267-
* <h3>Using Custom Variable Pools</h3> By default, JXPathContext creates a HashMap of variables. However, you can substitute a custom implementation of the
287+
* <h3>Using Custom Variable Pools</h3>
288+
* <p>
289+
* By default, JXPathContext creates a HashMap of variables. However, you can substitute a custom implementation of the
268290
* Variables interface to make JXPath work with an alternative source of variables. For example, you can define implementations of Variables that cover a
269291
* servlet context, HTTP request or any similar structure.
292+
* </p>
270293
*
271294
* <h3>Example 10: Using Standard Extension Functions</h3> Using the standard extension functions, you can call methods on objects, static methods on classes
272295
* and create objects using any constructor. The class names should be fully qualified.
273296
* <p>
274297
* Here's how you can create new objects:
298+
* </p>
275299
*
276300
* <pre>
277301
*
278302
* Book book = (Book) context.getValue("org.apache.commons.jxpath.example.Book.new ('John Updike')");
279303
* </pre>
280304
*
305+
* <p>
281306
* Here's how you can call static methods:
307+
* </p>
282308
*
283309
* <pre>
284310
*
285311
* Book book = (Book) context.getValue("org. apache.commons.jxpath.example.Book.getBestBook('John Updike')");
286312
* </pre>
287313
*
314+
* <p>
288315
* Here's how you can call regular methods:
316+
* </p>
289317
*
290318
* <pre>
291319
*
292320
* String firstName = (String) context.getValue("getAuthorsFirstName($book)");
293321
* </pre>
294322
*
323+
* <p>
295324
* As you can see, the target of the method is specified as the first parameter of the function.
325+
* </p>
296326
*
297-
* <h3>Example 11: Using Custom Extension Functions</h3> Collections of custom extension functions can be implemented as {@link Functions Functions} objects or
327+
* <h3>Example 11: Using Custom Extension Functions</h3>
328+
* <p>
329+
* Collections of custom extension functions can be implemented as {@link Functions Functions} objects or
298330
* as Java classes, whose methods become extenstion functions.
331+
* </p>
299332
* <p>
300333
* Let's say the following class implements various formatting operations:
334+
* </p>
301335
*
302336
* <pre>
303337
* public class Formats {
@@ -308,7 +342,9 @@
308342
* }
309343
* </pre>
310344
*
345+
* <p>
311346
* We can register this class with a JXPathContext:
347+
* </p>
312348
*
313349
* <pre>
314350
* context.setFunctions(new ClassFunctions(Formats.class, "format"));
@@ -319,20 +355,25 @@
319355
*
320356
* </pre>
321357
*
358+
* <p>
322359
* You can also register whole packages of Java classes using PackageFunctions.
360+
* </p>
323361
* <p>
324362
* Also, see {@link FunctionLibrary FunctionLibrary}, which is a class that allows you to register multiple sets of extension functions with the same
325363
* JXPathContext.
364+
* </p>
326365
*
327366
* <h2>Configuring JXPath</h2>
328367
*
368+
* <p>
329369
* JXPath uses JavaBeans introspection to discover properties of JavaBeans. You can provide alternative property lists by supplying custom JXPathBeanInfo
330370
* classes (see {@link JXPathBeanInfo JXPathBeanInfo}).
371+
* </p>
331372
*
332373
* <h2>Notes</h2>
333374
* <ul>
334375
* <li>JXPath does not support DOM attributes for non-DOM objects. Even though XPaths like "para[@type='warning']" are legitimate, they will always produce
335-
* empty results. The only attribute supported for JavaBeans is "name". The XPath "foo/bar" is equivalent to "foo[@name='bar']".
376+
* empty results. The only attribute supported for JavaBeans is "name". The XPath "foo/bar" is equivalent to "foo[@name='bar']".</li>
336377
*
337378
* <li id='matches_no_property_in_the_graph'>The term <b>matches no property in the graph</b> is used throughout the documentation. It describes a property or
338379
* path that can be determined as not belonging to the graph. Determining whether a property or path belongs to the graph depends on the type of object being
@@ -351,11 +392,17 @@
351392
* </li>
352393
* </ul>
353394
*
354-
* See <a href="http://www.w3schools.com/xpath">XPath Tutorial by W3Schools</a><br>
355-
* . Also see <a href="http://www.w3.org/TR/xpath">XML Path Language (XPath) Version 1.0</a><br>
356-
* <br>
395+
* <p>
396+
* See also:
397+
* </p>
398+
* <ul>
399+
* <li>See <a href="http://www.w3schools.com/xpath">XPath Tutorial by W3Schools</a></li>
400+
* <li>See also <a href="http://www.w3.org/TR/xpath">XML Path Language (XPath) Version 1.0</a></li>
401+
* </ul>
357402
*
358-
* You will also find more information and examples in <a href="https://commons.apache.org/jxpath/users-guide.html"> JXPath User's Guide</a>
403+
* <p>
404+
* You will also find more information and examples in the <a href="https://commons.apache.org/proper/jxpath/apidocs/index.html">JXPath User's Guide</a>
405+
* </p>
359406
*/
360407
public abstract class JXPathContext {
361408

0 commit comments

Comments
 (0)