jaxen-1.1.6/0000775000175000017500000000000012174247550012165 5ustar ebourgebourgjaxen-1.1.6/LICENSE.txt0000664000175000017500000000305110371471320013776 0ustar ebourgebourg/* $Id: LICENSE.txt 1128 2006-02-05 21:49:04Z elharo $ Copyright 2003-2006 The Werken Company. All Rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Jaxen Project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ jaxen-1.1.6/INSTALL0000664000175000017500000000043612005262277013215 0ustar ebourgebourg To install Jaxen, you need to place: jaxen-1.1.5.jar In your CLASSPATH or your jre/lib/ext directory. This includes support for all object-models. Of course, you'll also need the supporting jars for your object-model, such as jdom.jar, xom.jar, or similar. bob@werken.com jaxen-1.1.6/xdocs/0000775000175000017500000000000012174247546013312 5ustar ebourgebourgjaxen-1.1.6/xdocs/jaxen.gif0000664000175000017500000000133710440364260015075 0ustar ebourgebourgGIF89a["UUUݪҎ99rrUU999!Created with The GIMP,[" B)blp,aì|׷oH,6qԑLtJZldC]n8h VtjY km_ tc+Hi) }Ymz) y"xm *}"nt GhJ+mf+ j *x" mY) u,,"*ӻ-)uںËJؔr-l+})-AʸC0.^D e=l/< 7_}dDDe"^HЇ Txf͖#KvB dn tR\Fgȥ)|(41}GW(c5+Zm̩ʃӓ=i¬ ]9maS:.Z ߁\Q2T2S=QC\ۘmł|;9]QgR9Ͱhm@r 8H 0% ˘,x)ܛZ[P-"wJ?CfSS)ɩʼ@YV`urIM@2yE7jY 5{a"8 $h0b,1 بc\68#@@;jaxen-1.1.6/xdocs/extensions.xml0000664000175000017500000001261010416452640016221 0ustar ebourgebourg Elliotte Rusty Harold Writing Jaxen Extension Functions Writing Jaxen Extension Functions

An extension function is any function used in an XPath expression that is not included in the standard XPath 1.0 library.

Whereas standard functions have unqualified names (string(), count(), boolean(), etc.), extension functions generally belong to a namespace and have prefixed names like saxon:evaluate or exslt:tokenize. (the bundled Jaxen extension functions in org.jaxen.function.ext do not yet have a namespace. This is a bug. Please don't emulate it with your own extension functions.)

Let's suppose you want to write an extension function that finds the minimum of a set of numeric values. We'll call this extension function min() and put it in the http://exslt.org/math namespace. (This is actually an extension function defined by the EXSLT library at http://www.exslt.org/math/functions/min/math.min.html) We'll use the prefix math in this document but the prefix can change as long as the URI is correct.

This function has the following signature:

number math:min(node-set)

In Jaxen terms a number is a java.lang.Double and a node-set is a java.util.List.

Each extension function is implemented by a single class. This class can belong to any package. It must have a no-args constructor and implement the org.jaxen.Function interface. This interface declares a single method, call:

package org.jaxen; public interface Function { Object call(Context context, List args) throws FunctionCallException; }

For the math:min function we'll need to iterate through the list, convert each one to a numeric value, and then finds the minimum. Some casting is required; but mostly we just iterate through the list while comparing each member of the list to the current minimum value. If the next value is smaller, then we replace the old minimum value with the new minimum value. Finally we return a new Double object containing the minimum value. Here's the code:

public class MinFunction implements Function { public Object call(Context context, List args) throws FunctionCallException { if (args.isEmpty()) return Double.valueOf(Double.NaN); Navigator navigator = context.getNavigator(); double min = Double.MAX_VALUE; Iterator iterator = args.iterator(); while (iterator.hasNext()) { double next = NumberFunction.evaluate(iterator.next(), navigator).doubleValue(); min = Math.min(min, next); } return new Double(min); } }

Notice the use of Jaxen's implementation of the XPath number() function to convert each value in the node-set to a double.

Extension functions should be side effect free. They should not write files, change fields, or modify the state of anything. Extension functions may be called at any time, and not necessarily in the order you expect them to be. Furthermore, extension functions may be called more or less often than you expect. Each invocation of an extension function should be completely self-contained.

You may have noticed the name and namespace of the extension function showed up nowhere in the extension function class. To bind it to a name it must be registered with the function context. You can either register it with the default global function context (XPathFunctionContext.INSTANCE) or register it with a custom function context for the XPath expression

Let's assume you want to register it with a custom function context. Simply pass the namespace URI, local name, and a MinFunction object to the XPathFunctionContext constructor:

SimpleFunctionContext fc = new XPathFunctionContext(); fc.registerFunction("http://exslt.org/math", "min", new MinFunction());

You'll also need a namespace context that can map the prefix math to the URI http://exslt.org/math:

SimpleNamespaceContext nc = new SimpleNamespaceContext(); nc.addNamespace("math", "http://exslt.org/math");

Finally when evaluating the function you'll need to set your custom XPath function and namespace contexts for the expression:

BaseXPath xpath = new DOMXPath("math:min(//x)"); xpath.setFunctionContext(fc); xpath.setNamespaceContext(nc);

Otherwise, evaluating the expression will throw a JaxenException.

You can add the function to the default function context by registering it with the constant XPathFunctionContext.INSTANCE instead:

XPathFunctionContext.INSTANCE.registerFunction("http://exslt.org/math", "min", new MinFunction());
jaxen-1.1.6/xdocs/building.xml0000664000175000017500000000675212074524256015636 0ustar ebourgebourg Elliotte Rusty Harold Building Jaxen Building Jaxen

Jaxen's build system is officially Maven 3. To compile Jaxen, install Maven. Then at the shell prompt inside the top-level jaxen directory, type "mvn compile":

$ mvn compile

You'll likely see some deprecation warnings. Don't worry about these. They're internal to jaxen, and do not indicate bugs.

To run the unit tests, type "mvn test":

$ mvn test

To build a jar file at the shell prompt type "mvn package":

$ mvn package

This runs the unit tests as well. The jar file will appear in the target directory.

To generate javadoc, type "mvn javadoc:javadoc":

$ mvn javadoc:javadoc

To generate the complete documentation for the site, including code coverage measurements, static code analysis, and more, type "mvn site":

$ mvn site

Again the output appears in the target folder.

To remove build artifacts, type "mvn clean":

$ mvn clean

To prepare jaxen for release:

  1. Update xdocs/releases.xml, xdocs/status.xml, and xdocs/index.xml with the new version number and information.
  2. Update project.xml and INSTALL with the new version number.
  3. Make sure all changes are committed.
  4. Check that all tests pass by running mvn test.
  5. Tag the release in Subversion.
  6. Generate the release files by running mvn package, mvn javadoc:javadoc, mvn assembly:single, and mvn site.
  7. Using a WebDAV client, open https://dav.codehaus.org/dist/jaxen/. (In the Mac OS X Finder, this is Go/Connect to Server...)
  8. Copy the .zip, .bz2 and .tar.gz files from target to https://dav.codehaus.org/dist/jaxen/distributions.
  9. Copy the .jar file from target to https://dav.codehaus.org/dist/jaxen/jars/.
  10. Copy the .pom file from target to https://dav.codehaus.org/dist/jaxen/poms/.
  11. Using the Mac Finder, or another WebDAV client, open https://dav.codehaus.org/jaxen/.
  12. Copy all files from target/site into this directory, overwriting the existing files.
jaxen-1.1.6/xdocs/releases.xml0000664000175000017500000000451412074524256015636 0ustar ebourgebourg bob mcwhirter Releases

The current version is 1.1.6. 1.1.6 fixes several bugs in IEEE 754 arithmetic.

1.1 is a major upgrade that significantly improved jaxen's conformance to the underlying XPath 1.0 specification. This release is a vast improvement over 1.0, and all users are strongly encouraged to upgrade. With a few small exceptions (e.g. the document() function has moved to the org.jaxen.function.xslt package, the IdentityHashMap class has been deleted, and the ElectricXML navigator has been deleted) 1.1.6 is backwards compatible with code written to the 1.0 APIs.

The recommended build is 1.1.6:

You can grab a tarball of the current CVS head from FishEye if you like. To build Jaxen, you'll need to have maven installed. Assuming you do, you should be able to just type "maven jar" at the command line in the jaxen directory to create a JAR archive.

jaxen-1.1.6/xdocs/faq.xml0000664000175000017500000002254511406373146014604 0ustar ebourgebourg bob mcwhirter FAQ Frequently Asked Questions

The jaxen project is a Java XPath Engine. jaxen is a universal object model walker, capable of evaluating XPath expressions across multiple models. Currently supported are dom4j, JDOM, and DOM.

We use an Apache-style open source license which is one of the least restrictive licenses around, you can use jaxen to create new products without them having to be open source.

After implementing an XPath engine for both dom4j and JDOM, and attempting to keep them both in sync, it was decided that factoring out the commonality would be a Good Thing. Thus, jaxen provides a single point for XPath expression evaluation, regardless of the target object model, whether its dom4j, JDOM, DOM, XOM, JavaBeans, or what not.

jaxen is better than werken.xpath specifically because it better handles XPath expressions, and syntax error reporting. Additionally, since jaxen is a unified code-base, developer effort isn't split between maintaining the dom4j version and the JDOM version. More hands working on the same project reduces bug count.

jaxen may be perceived to be better than other XPath technologies since it provides a single cohesive API for evaluating XPaths against multiple object models. Learn the jaxen API, and apply it to dom4j, JDOM, XOM or DOM trees in exactly the same way.

Also, since jaxen works against an adaptor which provides InfoSet access to arbitrary object models, it should be possible to build even larger tools in terms of jaxen, to work with multiple models. For example, an XQL engine could be developed, which would automagically work with all models already supported by jaxen.

jaxen itself is based upon SAXPath, which is an event-based model for parsing XPath expressions.

jaxen currently has navigators defined for dom4j and JDOM, two popular and convenient object models for representing XML documents. Of course, W3C DOM is also supported.

jaxen supports XPath 1.0. It does not support XPath 2.0. XPath 2.0 is a very different spec with many things to recommend it and a few things not to like as well. However XPath 2.0 is not compatible with XPath 1.0. It is far from a simple upgrade from XPath 1.0. It has a very different data model, that might well require significant revisions to jaxen's internal data structures, and possibly a very different API as well.

The current release plan focuses exclusively on XPath 1.0 compatibility. Perhaps one day someone will make a branch or fork of jaxen that supports XPath 2. However, this would be a significant undertaking, and so far little interest in this has been shown.

The only thing required is an implementation of the interface org.jaxen.Navigator. Not all of the interface is required, and a default implementation, in the form of org.jaxen.DefaultNavigator is also provided.

Since many of the XPath axes can be defined in terms of each other (for example, the ancestor axis is merely a the parent recursively applied), only a few low-level axis iterators are required to initially get started. Of course, you may implement them directly, instead of relying upon jaxen's composition ability.

No.

The DocumentNavigators provided with jaxen would be used by themselves, without the XPath evaluation engine, to provide univeral access to many object models for other technologies.

jaxen has been embedded directly into dom4j and XOM 1.1 to provide easy XPath evaluation directly from your documents. Additionally, it's being integrated into David Megginson's NewsML Framework. Tom Copeland's PMD static code analyzer uses jaxen to query Java code structures using XPath.

The XPath expression that selects elements or attributes in a namespace looks exactly the same as it does in any other XPath context; that is, use prefixed names where the prefixes are bound to the namespace URIs. For example,

/pre:bar/@xlink:href

However, because a Java program is not an XML document, it is also necessary to bind the prefixes to the appropriate namespace URIs through a NamespaceContext object. For example, this code sets up and then executes the above query:

  XPath xpath = new DOMXPath("/foo:bar/@xlink:href", nav);
  SimpleNamespaceContext nsContext = new SimpleNamespaceContext();
  nsContext.addNamespace("pre", "http://www.foo.org/");
  nsContext.addNamespace("xlink", "http://www.w3.org/1999/xlink");
  xpath.setNamespaceContext(nsContext);
  List result = contextpath.selectNodes(document);

As a shortcut, you can simply add a namespace binding to the XPath expression's current context using the addNamespace method:

  XPath xpath = new DOMXPath("/pre:root");
  xpath.addNamespace("pre", "http://www.example.org/");
  List result = xpath.selectNodes(root);

If the namespace context does not contain a binding for a prefix that is used in the XPath expression, an UnresolvableException (a subclass of JaxenException is thrown when you attempt to evaluate it.

The same way you do for elements and attributes that are in prefixed namespaces. That is, you use a prefix in the XPath expression and bind the prefix to the namespace URI. You do this even if the document you're querying uses unprefixed namespaced qualified names. In XPath 1.0, all unprefixed names are unqualified. There is no requirement that the prefixes used in the XPath expression are the same as the prefixes used in the document being queried. Only the namespace URIs need to match, not the prefixes.

For example, this code fragment queries the document ]]> using the XPath expression /pre:root:

        Element root = doc.createElementNS("http://www.example.org/", "root");
        doc.appendChild(root);
        XPath xpath = new DOMXPath("/pre:root");
        SimpleNamespaceContext context = new SimpleNamespaceContext();
        context.addNamespace("pre", "http://www.example.org/");
        xpath.setNamespaceContext(context);
        List result = xpath.selectNodes(root);

Alternately, using the shortcut:

        Element root = doc.createElementNS("http://www.example.org/", "root");
        doc.appendChild(root);
        XPath xpath = new DOMXPath("/pre:root");
        xpath.addNamespace("pre", "http://www.example.org/");
        List result = xpath.selectNodes(root);
jaxen-1.1.6/xdocs/navigation.xml0000664000175000017500000000132211004721050016143 0ustar ebourgebourg jaxen: universal Java XPath engine jaxen-1.1.6/xdocs/index.xml0000664000175000017500000000570012074524256015140 0ustar ebourgebourg bob mcwhirter jaxen

Jaxen is an open source XPath library written in Java. It is adaptable to many different object models, including DOM, XOM, dom4j, and JDOM. Is it also possible to write adapters that treat non-XML trees such as compiled Java byte code or Java beans as XML, thus enabling you to query these trees with XPath too.

The current version is 1.1.6:

You can download Jaxen from the releases page.

You browse the FAQ or the online JavaDoc.

XOM 1.2.8 bundles Jaxen 1.1.4.

Bob McWhirter talked about Jaxen at Software Development 2003 West.

Check out these Performance Benchmarks comparing dom4j and Jaxen against Xerces and Xalan.

Sun chose Jaxen for the XPath engine for the JSP Standard Tag Library (JSTL) and the Java Web Services Developer Pack 1.0 and 1.1.

Since the reference implementation of Java API for XML Messaging is based on dom4j and Jaxen, that means you can use Jaxen to query SOAP messages on the Java platform too!

Check out Elliotte Rusty Harold's book chapter on XPath and Jaxen

Alex Chaffee wrote XPath Explorer to help visualize results of XPath expressions.

jaxen-1.1.6/xdocs/stylesheets/0000775000175000017500000000000012174247546015666 5ustar ebourgebourgjaxen-1.1.6/xdocs/stylesheets/javadoc-style.css0000664000175000017500000000516107574432315021146 0ustar ebourgebourg/* Javadoc style sheet */ /* Define colors, fonts and other style attributes here to override the defaults */ /* Page background color */ body { background-color: #FFFFFF } a:link.selfref, a:visited.selfref { color: #555 !important; } a:link, a:visited { font-family: sans-serif; color:#000099; text-decoration: none; } a:active, a:hover { color:#990000; text-decoration: underline; } font.FrameItemFont { font-size:10pt; } a:link.selfref, a:visited.selfref { font-family: sans-serif; color: #555 !important; } .a td { background: #ddd; color: #000; font-family: sans-serif; } h2 { font-family: sans-serif; font-size:12pt; border:solid 1px #999999; padding:10px; background-color:#EEEEEE; } table { border: none; border-spacing: 2px; } .TableHeadingColor td { font-family: sans-serif; border: 1px solid #555555; font-size: 6pt; } tr.TableRowColor td { font-family: sans-serif; font-size: 12pt; border: 1px solid #999999; cell-padding: 2px; } td.NavBarCell1 table { border: none; } td.NavBarCell1 { border: none; } td.NavBarCell2 { border: 4px green; } dt { font-family: sans-serif; font-size: 10pt; } dt b { color:#990000; } dd { font-size:10pt; margin-top:4px; margin-bottom:4px; } dd code { color:#333333; font-size:10pt; } /* Table colors */ .TableHeadingColor { background: #cccccc; color:#990000} .TableSubHeadingColor { background: #dddddd; color:black;} .TableRowColor { background: #efefef; } /* Font used in left-hand frame lists */ .FrameTitleFont { font-weight: 900; font-size: 10pt; font-family: sans-serif; color:#FFFFFF } .FrameHeadingFont { font-weight: bold; font-size: 10pt; font-family: sans-serif; color:#990000; line-height: 2em; border: 1px solid #aaaaaa; padding-left:4px; padding-right:4px; padding-top:2px; padding-bottom:2px; } .FrameItemFont { font-size: normal; font-family: sans-serif; color:#FFFFFF } /* Example of smaller, sans-serif font in frames */ /* .FrameItemFont { font-size: 10pt; font-family: Helvetica, Arial, sans-serif } */ /* Navigation bar fonts and colors */ .NavBarCell1 { background-color:#ddd; border:none; padding: 2px; } .NavBarCell1Rev { background-color:#990000; border:none; padding: 2px; } .NavBarFont1 { font-family: Arial, Helvetica, sans-serif; font-size: 10pt; color:#000000; } .NavBarFont1Rev { font-family: Arial, Helvetica, sans-serif; font-size: 10pt; color:#FFFFFF; } .NavBarCell2 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF; border:none;} .NavBarCell3 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF; border:none;} jaxen-1.1.6/xdocs/stylesheets/print.css0000664000175000017500000000025007574432315017527 0ustar ebourgebourg#banner, #footer, #leftcol, #breadcrumbs, .docs #toc, .docs .courtesylinks { display: none; } body.docs div.docs { margin: 0 !important; border: none !important } jaxen-1.1.6/xdocs/stylesheets/ns4_only.css0000664000175000017500000000466607574432315020157 0ustar ebourgebourg/* simple rules suitable for Netscape 4.x only; richer rules are in tigris.css. see */ /* colors, backgrounds, borders, link indication */ body { background: #fff; color: #000; } #leftcol a:link, #leftcol a:visited { color: blue; } a:active, a:hover, #leftcol a:active, #leftcol a:hover { color: #f30; } #login a:link, #login a:visited { color: white; text-decoration: underline; } #banner a:active, #banner a:hover { color: #f90; } #leftcol a, #breadcrumbs a { text-decoration: none; } h2 .lastchild { color: #777 } .a td { background: #ddd; } .b td { background: #efefef; } .tabs td, .tabs th { background-color: #ddd; } body .app th { background-color: #bbb; } body .tabs th { background-color: #888; color: #fff; } body .app .axial th { background-color: #ddd; color: black } .tabs td { background-color: #ddd; } .alert { color: #c00; } .confirm { color: green; } .info { color: blue; } .selection { background: #ffc; } #login { color: #fff; } #helptext th { background: #cc9; } #helptext td { background: #ffc; } .tabs a { text-decoration: none; } #navcolumn div strong { color: #555; } #banner, #banner td { background: #036; color: #fff; } body #banner #login a { color: white; } /* font and text properties, exclusive of link indication, alignment, text-indent */ body, div, p, th, td, li, dl, dd { font-family: Lucida, Arial, Helvetica, sans-serif; } code, pre { font-family: 'Andale Mono', Courier, monospace; } h2, h3, h4 { font-family: Tahoma, Verdana, Helvetica, Arial, sans-serif; } .selection { font-weight: bold } #login .username { font-weight: bold; } /* box properties (exclusive of borders), positioning, alignments, list types, text-indent */ th, td { text-align: left; vertical-align: top } .right { text-align: right; } .center { text-align: center; } body .app .axial th { text-align: right; } .app .axial td th { text-align: left; } body td .stb { margin-top: 1em; text-indent: 0; } body td .mtb { margin-top: 2em; text-indent: 0; } dd { margin-bottom: .67em; } #footer { margin: 4px } #helptext { margin-top: 1em } #helptext td div { margin: .5em } .courtesylinks { margin-top: 1em; padding-top: 1em } #navcolumn div { margin-bottom: .5em; } #navcolumn div div { margin-top: .3em } #navcolumn div div { padding-left: 1em; } #banner, #banner td { vertical-align: middle; } body.docs, body.nonav { margin: 1em } jaxen-1.1.6/xdocs/stylesheets/maven.css0000664000175000017500000000672207670776560017525 0ustar ebourgebourgbody { background: #fff; color: #000; letter-spacing:1px; } a { font-weight: normal; } table { border: none; margin: 0px; padding: 0px; } .app h3 { font-family: sans-serif; border: solid 1px #999999; padding:6px; background-color:#dddddd; color:#990000; font-size:14pt; margin: 1pt; margin-top: 6pt; margin-left: -10px; } .app h3 a { font-size:14pt; font-stretch:expanded; } .app h3 a:before { content: "[ "; } .app h3 a:after { content: " ]"; } .app h4 { font-family: sans-serif; border:#bbbbbb solid 1px; padding:2px; background-color:#eeeeee; color:#990000; margin-left: -5px; padding-left: 10px; } .app h4 a { font-size:8pt; } .app h4 a:before { content: "..."; } .app h4 a:after { content: "..."; } .app th { background-color: #cccccc; color: #990000; font-family: sans-serif; font-size: 8pt; border: solid #777777 1px; padding: 4px; letter-spacing: normal; font-weight:normal; } .app td { font-family: sans-serif; font-size: 8pt; border: solid #777777 1px; padding: 4px; } div#banner { border: none; } code { color: #990000; } .b td { background: #dddddd; color: #000; border: solid #555555 1px; font-family: sans-serif; } .a td { background: #eeeeee; color: #000; font-family: sans-serif; } div#banner { /* border-top: 1px solid #369; border-bottom: 1px solid #003; */ } #bodycol div.h3 p { max-width: 5in; margin-left: 20px; line-height: 1.6em; font-size: 8pt; color:#777777; letter-spacing:normal; } #banner, #banner td { background: white; color: #fff; } #leftcol { background: #eeeeee; color: #000; border-right: 1px solid #777777; border-bottom: 1px solid #777777; /* border-bottom: 1px solid #aaa; border-top: 1px solid #fff; */ } #navcolumn { background: #eeeeee; color: #000; border-right: none; border-bottom: none; border-top: none; min-width:1.5in; margin-left:10px; } #navcolumn div strong { color:#990000; padding: 4px; line-height:20pt; border-bottom: 1px solid #bbbbbb; font-weight: normal; letter-spacing: normal; } #navcolumn div { margin-top:10px; } #navcolumn div div { margin-bottom:10px; } #breadcrumbs { border: 1px solid #777777; } #breadcrumbs { background-color: #dddddd; } #breadcrumbs td { border: none; color: #777777; padding-left: 1em; } #source { background-color: #fff; color: #000; border-right: 1px solid #888; border-left: 1px solid #888; border-top: 1px solid #888; border-bottom: 1px solid #888; margin-right: 7px; margin-left: 7px; margin-top: 1em; } pre { margin-right: 7px; margin-left: 7px; } #footer { background: #eeeeee; border: 1px solid #777777; margin-left: 0px; margin-right: 0px; padding-top: 3px; padding-bottom: 3px; padding-left: 1em; color:#777777; } #footer table { } #footer table tr td { border: none; padding: 0px; margin: 4px; } a:link, #breadcrumbs a:visited, #navcolumn a:visited, .tasknav a:visited { font-family: sans-serif; color:#000099; text-decoration: none; } a:active, a:hover, #leftcol a:active, #leftcol a:hover { font-family: sans-serif; color:#990000; text-decoration: none; } a:link.selfref, a:visited.selfref { color: #555 !important; } .app a:link, .app a:visited { font-family: sans-serif; color:#000099; text-decoration: none; } .app a:active, .app a:hover { color:#990000; text-decoration: underline; } h3, h4 { margin-top: 1em; margin-bottom: 0; } jaxen-1.1.6/xdocs/stylesheets/tigris.css0000664000175000017500000002011107574432315017672 0ustar ebourgebourg/* contains rules unsuitable for Netscape 4.x; simpler rules are in ns4_only.css. see */ /* colors, backgrounds, borders, link indication */ body { background: #fff; color: #000; } .app h3, .app h4, .app th, .tabs td, .tabs th, .functnbar { /* background-image: url(../images/nw_min.gif); background-repeat: no-repeat; */ } #navcolumn div div, body.docs #toc li li { background-image: url(../images/strich.gif); background-repeat: no-repeat; background-position: .5em .5em; } #navcolumn div div.heading { background-image: none; } .app h3, .app h4 { color: #fff; } .app h3 { background-color: #036; } .app h4 { background-color: #888; } .a td { background: #ddd; } .b td { background: #efefef; } table, th, td { border: none } .mtb { border-top: solid 1px #ddd; } div.colbar { background: #bbb; } div#banner { border-top: 1px solid #369; border-bottom: 1px solid #003; } div#helptext th { border-bottom: 1px solid #996; border-right: 1px solid #996; } div#helptext td { border-bottom: 1px solid #cc9; border-right: 1px solid #cc9; } .tabs { border-bottom: .75em #888 solid; } .tabs th, .tabs td { border-right: 1px solid #333; } .tabs td { border-bottom: 1px solid #ddd; } #navcolumn { background: #eee; border-right: 1px solid #aaa; border-bottom: 1px solid #aaa; } /* #breadcrumbs { border-bottom: 1px solid #aaa; background-color: #ddd; } */ /* #navcolumn, #breadcrumbs { border-top: 1px solid #fff; } */ #rightcol div.www, #rightcol div.help { border: 1px solid #ddd; } div#navcolumn div.focus { border-top: 1px solid #aaa; border-left: 1px solid #aaa; background-color: #fff; } body.docs div.docs { background: #fff; border-left: 1px solid #ddd; border-top: 1px solid #ddd; } body.docs { background: #eee url(../images/help_logo.gif) top right no-repeat !important; } .docs h3, .docs h4 { border-top: solid 1px #000; } #alerterrormessage { background: url(../images/icon_alert.gif) top left no-repeat !important; } .functnbar { background-color: #aaa; } .functnbar2, .functnbar3 { background: #aaa url(../images/sw_min.gif) no-repeat bottom left; } .functnbar3 { background-color: #ddd; } .functnbar, .functnbar2, .functnbar3 { color: #000; } .functnbar a, .functnbar2 a, .functnbar3 a { color: #000; text-decoration: underline; } #topmodule { background: #ddd; border-top: 1px solid #fff; border-bottom: 1px solid #aaa; border-right: 1px solid #aaa; } #topmodule #issueid { border-right: 1px solid #aaa; } /* a:link, #navcolumn a:visited, .app a:visited, .tasknav a:visited { color: blue; } a:active, a:hover, #leftcol a:active, #leftcol a:hover { color: #f30 !important; } */ /* #login a:link, #login a:visited { color: white; text-decoration: underline; } */ /* #banner a:active, #banner a:hover { color: #f90 !important; } */ /* #leftcol a, #breadcrumbs a { text-decoration: none; } */ /* a:link.selfref, a:visited.selfref { color: #555 !important; text-decoration: none; } */ h2 .lastchild { color: #777 } .tabs td, .tabs th { background-color: #ddd; } .app th { background-color: #bbb; } .tabs th { background-color: #888; color: #fff; } .axial th { background-color: #ddd; color: black } .tabs td { background-color: #ddd; } .alert { color: #c00; } .confirm { color: green; } .info { color: blue; } .selection { background: #ffc; } #login { color: #fff; } #helptext th { background: #cc9; } #helptext td { background: #ffc; } .tabs a { text-decoration: none; } #navcolumn div strong { color: #000; } #banner, #banner td { background: #036; color: #fff; } body #banner #login a { color: #fff; } /* font and text properties, exclusive of link indication, alignment, text-indent */ body, th, td, input, select, textarea, h2 small { font-family: Verdana, Helvetica, Arial, sans-serif; } code, pre { font-family: 'Andale Mono', Courier, monospace; } html body, body th, body td, textarea, h2 small, .app h3, .app h4, #rightcol h3, #bodycol pre, #bodycol code { font-size: x-small; voice-family: "\"}\""; voice-family: inherit; font-size: small } html>body, html>body th, html>body td, html>body input, html>body select, html>body textarea, html>body h2 small, html>body .app h3, html>body .app h4, html>body #rightcol h3, html>body #bodycol pre, html>body #bodycol code { font-size: small } small, div#footer td, div#login, div#helptext th, div#helptext td, div.tabs th, div.tabs td, input, select, .paginate, .functnbar, .functnbar2, .functnbar3, #breadcrumbs td, .courtesylinks, #rightcol div.help, .colbar, .tasknav, body.docs div#toc { font-size: xx-small; voice-family: "\"}\""; voice-family: inherit; font-size: x-small } html>body small, html>body div#footer td, html>body div#login, html>body div#helptext td, html>body div#helptext th, html>body div.tabs th, html>body div.tabs td, html>body input, html>body select, html>body .paginate, html>body .functnbar, html>body .functnbar2, html>body .functnbar3, html>body #breadcrumbs td, html>body .courtesylinks, html>body #rightcol div.help, html>body .colbar, html>body .tasknav, html>body.docs #toc { font-size: x-small } #bodycol h2 { font-family: Tahoma, Verdana, Helvetica, Arial, sans-serif; font-size: 1.5em; font-weight: normal; } h2 small { font-weight: bold; letter-spacing: .06em; } dt { font-weight: bold } #login .username { font-weight: bold; } h4 { font-size: 1em; } #breadcrumbs td { font-weight: bold; } .selection { font-weight: bold } /* box properties (exclusive of borders), positioning, alignments, list types, text-indent */ #bodycol h2 { margin-top: .3em; margin-bottom: .5em; } p, ul, ol, dl { margin-top: .67em; margin-bottom: .67em; } h3, h4 { margin-bottom: 0; } form { margin-top: 0; margin-bottom: 0; } #bodycol { padding-left: 12px; padding-right: 12px; width: 100%; voice-family: "\"}\""; voice-family: inherit; width: auto; } html>body #bodycol { width: auto; } .docs { line-height: 1.4; } .app h3, .app h4 { padding: 5px; margin-right: 2px; margin-left: 2px; } .h3 p, .h4 p, .h3 dt, .h4 dt { margin-right: 7px; margin-left: 7px; } .tasknav { margin-bottom: 1.33em } div.colbar { padding: 4px; margin: 2px 2px 0; } .tabs { margin-top: .67em; margin-right: 2px; margin-left: 2px; } #leftcol { padding-bottom: .5em; } #breadcrumbs td { vertical-align: middle; padding: 2px 8px; } #rightcol div.www, #rightcol div.help { padding: 0 .5em } #navcolumn { margin: -8px -8px 0 -8px; padding: 4px; } #navcolumn div { padding-left: 5px } div#navcolumn div div { margin-top: .3em; margin-bottom: .3em; } div#navcolumn div.focus { margin-top: -.1em; padding: .2em 4px; } body.docs #toc { position: absolute; top: 15px; left: 0px; width: 120px; padding: 0 20px 0 0 } body.docs #toc ul, #toc ol { margin-left: 0; padding-left: 0; } body.docs #toc li { margin-top: 7px; padding-left: 10px; list-style-type: none; } body.docs div.docs { margin: 61px 0 0 150px; padding: 1em 2em 1em 1em !important; } .docs p+p { text-indent: 5%; margin-top: -.67em } .docs h3, .docs h4 { margin-bottom: .1em; padding-top: .3em; } #alerterrormessage { padding-left: 100px; } .functnbar, .functnbar2, .functnbar3 { padding: 5px; margin: .67em 2px; } #topmodule td { vertical-align: middle; padding: 2px 8px } body { padding: 1em; } body.composite, body.docs { margin: 0; padding: 0; } th, td { text-align: left; vertical-align: top } .right { text-align: right !important; } .center { text-align: center !important; } .tabs td, .tabs th { padding-left: 7px; padding-right: 7px; } .axial th { text-align: right; } .app .axial td th { text-align: left; } body td .stb { margin-top: 1em; text-indent: 0; } body td .mtb { margin-top: 2em; text-indent: 0; } dd { margin-bottom: .67em; } #footer { margin: 4px } #helptext { margin-top: 1em } #helptext td div { margin: .5em } .courtesylinks { margin-top: 1em; padding-top: 1em } #navcolumn div { margin-bottom: .5em; } #navcolumn div div { margin-top: .3em } #navcolumn div div { padding-left: 1em; } #banner, #banner td { vertical-align: middle; } body.docs, body.nonav { margin: 1em } jaxen-1.1.6/xdocs/stylesheets/maven_ns4_only.css0000664000175000017500000000070207574432315021330 0ustar ebourgebourgbody { background: #fff; color: #000; } a:active, a:hover, #leftcol a:active, #leftcol a:hover { color: #f30; } #leftcol a:link, #leftcol a:visited { color: blue; } .a td { background: #ddd; color: #000; } .b td { background: #efefef; color: #000; } body .app th { background-color: #bbb; color: #fff; } #navcolumn div strong { background: #fff; color: #555; } #banner, #banner td { background: white; color: #fff; } jaxen-1.1.6/xdocs/status.xml0000664000175000017500000002751612074524256015365 0ustar ebourgebourg bob mcwhirter Status

Jaxen 1.1.6 fixes several bugs in the handling of IEEE-754 -0.

Jaxen 1.1.5 is now compatible with Maven 3, and has a significantly reduced dependency tree when built with Maven 3. It also fixes one very remote bug in boolean-to-number conversion that has probably never showed up in practice.

Jaxen 1.1.4 is now compatible with Java 7. It also fixes several bugs involving namespace nodes, and variable and function bindings in the presence of the default namespace.

Jaxen 1.1.3 fixes one bug involving non-element nodes and relational operators.

Jaxen 1.1.2 fixes a few assorted minor bugs.

Jaxen 1.1.1 fixes a number of minor bugs.

Jaxen 1.1.1 fixes a number of minor bugs.

Aside from the version number, 1.1 is identical to beta 12.

Beta 12 contains a few small bug fixes including the removal of an unintentional Java 5 dependence, some more API documentation, a few small API changes (getIterableAxis now throws an exception rather than returning null on a bad axis constant; getOperator has been pulled up into BinaryExpr rather than its subclasses) and two major API changes:

  • The Visitor interface, VisitorSupport class, XPath2XMLVisitor class, and associated methods have been deleted because they were undocumented, untested, and were tightly coupled to the underlying implementation. They may return in the future if there's demand and if someone volunteers to do or pay for the necessary work to bring them up to the standards of the rest of the code base.
  • The matrix-concat extension function has been removed because its license status was unclear, the originator could not be contacted, and it was undocumented and untested. If someone cares to reimplement it, it could be restored in the future.

The primary impetus for beta 11 was fixing the build process so it once again generates source bundles. A couple of small, almost cosmetic, bugs were also fixed. If you haven't noticed any problems with beta 10, you can safely skip this iteration.

Beta 10 fixes an assortment of small issues.

Beta 9 contains some small optimizations, improvements to the documentation, and minor bug fixes. The license should now be the same across all the files.

Beta 8 fixes a couple of bugs in XPath evaluation and optimizes the code in several places. The test suite has been expanded.

Beta 7 fixes a number of important bugs, especially involving operator associativity, the string and substring functions, and the dom4j navigator. The various root exception classes (JaxenException, JaxenRuntimeException, and SAXPathException) and all their subclasses now support Java 1.4 exception chaining even in 1.3 and earlier VMs. The DOM navigator should compile and run in both Java 1.4 and 1.5 (i.e. DOM level 2 and DOM Level 3). Namespace handling in DOM is more accurate. Paths can be begin with parenthesized steps like (//foo)/x. Beta 7 also features a reorganized, more modular test suite and expanded and improved API documentation.

Beta 6 makes a few small bug fixes and code clean ups, including removing an unintended dependence on Java 1.4. Most importantly it removes a file (IdentityHashMap) that we do not have the right to redistribute. All prior betas of Jaxen 1.1 should be considered tainted, and not redistributed in any way. If your project uses an earlier version, please remove it and replace it with beta 6. Jaxen 1.0 is not affected by any of this.

Beta 5 makes a few small bug fixes and code clean ups, especially in the DOM navigator. It also restores some test files that were inadvertently left out of the Beta 4 distribution.

1.1 is a major upgrade that significantly improves Jaxen's conformance to the underlying XPath specs. Even though it's officially a beta, it is a vast improvement over 1.0, and all users are strongly encouraged to upgrade. With a few small exceptions (e.g. the the document() function has moved to the org.jaxen.function.xslt package and the ElectricXML navigator has been deleted) it is backwards compatible with code written to the 1.0 APIs.

The lang() function is now supported.

All queries return nodes in the correct document order, without exception.

ancestor::* and ancestor-or-self::* axes no longer include the document node

NaN is handled properly.

The mod operator works on floating point numbers.

Navigators are now included for XOM, HTML DOM, and JavaBeans. These are experimental and may not be included in the final release.

Applied patch submitted by Shawn Bayern to fix the booleanValueOf() method.

Added licenses to each source file and a proper manifest to the build at last ;-).

There is now an XPath interface in the org.jaxen package to represent any XPath implementation. So this means that the XPath API of Jaxen is now polymorphic, the same interface can work with any model.

This now means that the org.jaxen.* package represents a purely interface based API to any XPath engine. So it should be possible to implement XPath, FunctionContext, NamespaceContext, VariableContext on any XPath engine if so desired.

The XPath implementation for each model has now got a fully qualified class name. The following code describes how to instantiate an XPath object for each model.

// for DOM
XPath xpath = new DOMXPath( "//foo" );

// for dom4j
XPath xpath = new Dom4jXPath( "//foo" );

// for JDOM
XPath xpath = new JDOMXPath( "//foo" );

The XPath.valueOf() method is now deprecated, XPath.stringValueOf() should be used instead.

Added new extension functions kindly provided by Mark Wilson. They are as follows...

  • upper-case() - converts the first argument to an upper case string using either the default Locale or the Locale specified by the second parameter
  • lower-case() - converts the first argument to a lower case string using either the default Locale or the Locale specified by the second parameter
  • ends-with() - evaluates true if the first string ends with the postfix

Locales can be specified either using a variable which is a Locale object or using an xml:lang style string which specifies the Locale via a language together with an optional country and variant such as 'fr', 'fr-CA' or 'es-ES-Traditional_WIN'. e.g.

upper-case( @foo, $myLocale )
upper-case( /foo/bar, 'fr' )
lower-case( foo, 'fr-CA' )
upper-case( @foo, 'es-ES-Traditional_WIN' )

The translate() function is now implemented - thanks to Jan for that!

Some auxiliary implementation detail changes, which shouldn't affect the public API in any way are as follows

  • The org.jaxen.JaXPath class has been removed. Now that we have an org.jaxen.XPath interface it's no longer required.
  • The org.jaxen.expr.XPath class has been renamed to org.jaxen.expr.XPathExpr to avoid confusion and to use a more consistent name. Similarly the DefaultXPath class has been renamed to DefaultXPathExpr as well.
  • The very confusing jaSelect*() methods have gone from JaXPath and BaseXPath. All evaluation methods can take a Context object, null, a node or a node set.

Initial beta development cycle. Please see CVS changelogs for up-to-date list of changes.

  • Implement a GenericXPath which could use reflection on the nodes passed into it to choose the Navigator to use. So the same GenericXPath instance could be used to evaluate XPaths on any object. This feature would be particularly useful in JSTL since it would allow web developers to mix and match any all XML models.
  • Jaxen is already pretty fast, but we are sure it could use some more tuning.
  • selectSingleNode() and possibly the *ValueOf() methods should be return-fast as a performance improvement. For example selectSingleNode( "//foo" ) on a document with lots of <foo/> elements would actually create a full node-set of results then extract the first element - rather than just returning as soon as the first one is found.
  • Better user guides and examples!
  • Any Locale specific functions, such as upper-case() and lowercase-case() could well follow the example of XSLT 2.0 by using the Unicode case mappings
  • id() function is not implemented for most models, though it works fine for W3C DOM.
jaxen-1.1.6/pom.xml0000664000175000017500000003254512074524256013513 0ustar ebourgebourg 4.0.0 oss-parent org.sonatype.oss 7 jaxen jaxen bundle jaxen 1.1.6 Jaxen is a universal Java XPath engine. http://jaxen.codehaus.org/ http://jaxen.codehaus.org/license.html JIRA http://jira.codehaus.org/BrowseProject.jspa?id=10022
dev@jaxen.codehaus.org
2001 UTF-8 UTF-8 Jaxen Users List user-subscribe@jaxen.codehaus.org user-unsubscribe@jaxen.codehaus.org http://archive.jaxen.codehaus.org/user/ Jaxen Developers List dev-subscribe@jaxen.codehaus.org dev-unsubscribe@jaxen.codehaus.org http://archive.jaxen.codehaus.org/dev/ Jaxen Commits List scm-subscribe@jaxen.codehaus.org scm-unsubscribe@jaxen.codehaus.org http://archive.jaxen.codehaus.org/scm/ bob Bob McWhirter bob@eng.werken.com The Werken Company jstrachan James Strachan james_strachan@yahoo.co.uk Spiritsoft dmegginson David Megginson contact@megginson.com Megginson Technologies eboldwidt Erwin Bolwidt erwin@klomp.org mbelonga Mark A. Belonga mbelonga@users.sourceforge.net cnentwich Christian Nentwich xcut@users.sourceforge.net purpletech Alexander Day Chaffee purpletech@users.sourceforge.net Purple Technologies jdvorak Jan Dvorak jdvorak@users.sourceforge.net szegedia Attila Szegedi szegedia@users.sourceforge.net proyal Peter Royal peter.royal@pobox.com http://fotap.org/~osi ssanders Scott Sanders scott@dotnot.org http://dotnot.org/blog dotnot bewins Brian Ewins brian.ewins@gmail.com elharo Elliotte Rusty Harold elharo@ibiblio.org http://www.elharo.com/ Cafe au Lait Ryan Gustafson rgustav@users.sourceforge.net David Peterson david@randombits.org Mark Wilson mark.wilson@wilsoncom.de Jacob Kjome hoju@visi.com Michael Brennan mpbrennan@earthlink.net Jason Hunter jhunter@xquery.com Brett Mclaughlin brett.mclaughlin@lutris.com Bradley S. Huffman hip@cs.okstate.edu K. Ari Krupnikov ari@lib.aero Paul R. Brown prb@fivesight.com Guoliang Cao cao@ispsoft.com Jérôme Nègre jerome.negre@e-xmlmedia.fr Eddie McGreal emcgreal@BlackPearl.com Steen Lehmann slehmann@users.sourceforge.net Ben McCann benjamin.j.mccann@gmail.com Don Corley don@donandann.com scm:svn:https://svn.codehaus.org/jaxen/trunk/jaxen/ http://fisheye.codehaus.org/browse/jaxen/ Codehaus http://codehaus.org src/java/main src/java/test maven-compiler-plugin 2.5.1 true true true 1.3 1.2 org.apache.felix maven-bundle-plugin 2.3.7 true 2 ${project.artifactId} ${project.version} org.jaxen.*;version=${project.version} org/w3c/dom/UserDataHandler.class=target/classes/org/w3c/dom/UserDataHandler.class, META-INF/LICENSE.txt=LICENSE.txt org.w3c.dom;resolution:=optional, *;resolution:=optional !org.w3c.dom org.apache.maven.plugins maven-assembly-plugin 2.3 package single javadoc site project src bin maven-repository-plugin 2.3.1 maven-javadoc-plugin 2.8.1 org.jaxen.saxpath.base,org.jaxen.saxpath.helpers http://java.sun.com/j2se/1.4.2/docs/api/ ${basedir}/src/site/resources/css/javadoc-style.css UTF-8 ./xdocs/stylesheets/javadoc-style.css To Do: todo Xa UTF-8 maven-surefire-plugin 2.12 **/*Test.java org.codehaus.mojo cobertura-maven-plugin 2.5.1 org.codehaus.mojo findbugs-maven-plugin 2.4.0 dom4j dom4j 1.6.1 true jdom jdom 1.0 true xml-apis xml-apis 1.3.02 provided xerces xercesImpl 2.6.2 provided xom xom 1.0 true junit junit 3.8.2 test maven-changelog-plugin 2.2 date 2007-05-06 UTF-8 maven-checkstyle-plugin 2.9.1 maven-javadoc-plugin 2.6.1 org.apache.maven.plugins maven-jxr-plugin 2.1 org.apache.maven.plugins maven-pmd-plugin 2.4 org.apache.maven.plugins maven-surefire-report-plugin 2.4.3 org.codehaus.mojo cobertura-maven-plugin 2.5.1 org.codehaus.mojo findbugs-maven-plugin 2.4.0 org.codehaus.mojo jdepend-maven-plugin 2.0-beta-2 org.apache.maven.plugins maven-project-info-reports-plugin 2.4 false false dependencies scm default Default Site scp://jaxen.codehaus.org/home/projects/jaxen/public_html
jaxen-1.1.6/src/0000775000175000017500000000000012174247550012754 5ustar ebourgebourgjaxen-1.1.6/src/latex/0000775000175000017500000000000012174247550014071 5ustar ebourgebourgjaxen-1.1.6/src/latex/intro-slides.tex0000664000175000017500000024115410260255514017227 0ustar ebourgebourg\documentclass[20pt,landscape,headrule,footrule]{foils} \usepackage{alltt} \usepackage{color} \usepackage{pstricks} \usepackage{graphicx} \usepackage{verbatim} \setlength{\fboxsep}{0pt} \setlength{\foilheadskip}{-30pt} \begin{document} \definecolor{highlight}{rgb}{0.6,0.0,0.0} \definecolor{grey}{rgb}{0.3,0.3,0.3} \definecolor{higreen}{rgb}{0.0,0.6,0.0} \definecolor{hipurple}{rgb}{0.6,0.0,0.6} \renewcommand{\emph}[1]{\textcolor{highlight}{#1}} \newcommand{\bemph}[1]{\textbf{\emph{#1}}} \newcommand{\hired}[1]{\textcolor{red}{#1}} \newcommand{\hipurple}[1]{\textcolor{hipurple}{#1}} \newcommand{\hiblue}[1]{\textcolor{blue}{#1}} \newcommand{\higreen}[1]{\textcolor{higreen}{#1}} \newcommand{\hifade}[1]{\textcolor{grey}{#1}} \newcommand{\slide}[1]{\foilhead{\bemph{#1}}} \newcommand{\subslide}[1]{\foilhead{\bemph{\small{(#1)}}}} \newcommand{\breakslide}[1]{\foilhead{}\vspace{1in}\begin{center}\Huge{\textcolor{highlight}{ #1}}\end{center}} \newcommand{\egxpath}[1]{\begin{center}\texttt{#1}\end{center}} \newcommand{\egcode}[1]{\begin{center}\texttt{#1}\end{center}} \newcommand{\at}[0]{\texttt{\@@}} \newcommand{\tag}[1]{\texttt{<#1>}} \newenvironment{codelisting}% {\begin{minipage}{\textwidth}\tiny\begin{alltt}}% {\end{alltt}\end{minipage}} \newcommand{\diagram}[1]{ \begin{minipage}{\textwidth} \begin{center} \includegraphics[scale=0.5]{#1} \end{center} \end{minipage} } \title{\emph{Introduction to XPath\\ in Java using Jaxen}\\ \small{SD West 2003}} \author{Bob McWhirter\\ \tiny{\emph{The Werken Company}}\\ \tiny{\texttt{bob@werken.com}}} \MyLogo{\emph{http://jaxen.org/}} \leftheader{\emph{Jaxen}} \maketitle %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \slide{Quickest Intro} \begin{itemize} \item Open-Source. \item Business-friendly license (ASF/BSD). \item Works with most XML object-models. \end{itemize} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \slide{Open-Source} Being open-source, \emph{jaxen} has numerous developers working on various aspects of the project, from supporting additional object-models to seeking out optimization opportunities. Jaxen has existed for about two years, and has over a dozen committers, with 2-to-3 active at any point in time. Some committers are simply users of \emph{jaxen}, others have created custom model adapters, while still others are implementors of other open-source XML object-models. %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \slide{Business-friendly License} Since \emph{jaxen} uses a license similar to the one used by the Apache Software Foundation, there are few restrictions on its usage. It may be used in other open-source projects or in closed-source commercial products. The only requirement is that the code maintains its copyrights. \begin{center} \bemph{That's it!} \end{center} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \slide{Works with Most XML Object-Models} \begin{itemize} \item \bemph{dom4j} James Strachan's dom4j includes direct support\\ for XPath by using the Jaxen library. \item \bemph{JDOM} Jason Hunter's JDOM includes optional support\\ for XPath by using the Jaxen library. \item \bemph{W3C DOM} Jaxen supports DOM documents. \item \bemph{EXML} The Mind Electric's EXML 6.0 includes direct \\ support for XPath by using the Jaxen library. \end{itemize} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \slide{History} The first XPath engine Bob created was \emph{werken.xpath}, and it worked only with JDOM. It was based upon an \emph{ANTLR} parser-generator grammar and contained numerous bugs. \emph{James Strachan} started the \emph{dom4j} project. Initially, we worked with porting werken.xpath to dom4j, but maintaining separate codebases proved difficult. And thus, the concept for jaxen was born\dots %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{History - The Beginnings} Due to issues with the ANTLR-based grammar, \emph{SAXPath}, a hand-rolled expression lexer and parser was written. SAXPath parses and reports XPath expressions in a manner similar to how SAX works for XML content. Bob McWhirter and James Strachan designed the \emph{Navigator} object-model adapter and implemented the core engine. James wrote the binding to dom4j while Bob wrote the bindings for JDOM and EXML. James Strachan and David Megginson created the W3C DOM binding. %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{History - Contributors} Many others contributed patches, optimizations and improvements: \begin{tabular}{ll} \begin{minipage}{4in} \small \begin{itemize} \item \emph{Erwin Boldwidt} \item \emph{Eddie McGreal} \item \emph{Jan Dvorak} \item \emph{Mark A. Belonga} \item \emph{Michael Brennan} \item \emph{Stephen Colebourne} %% \end{itemize} %% \end{minipage} %% & %% \begin{minipage}{4in} %% \small %% \begin{itemize} \item \emph{Paul R. Brown} \item \emph{Alex Chaffee} \item \emph{Steen Lehmann} \item \emph{Attila Szegedi} \item \emph{Christian Nentwich} \item \emph{Pete Kazmier} \item \emph{Jeffrey Brekke} \end{itemize} \end{minipage} \end{tabular} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \slide{Jaxen and the XML-InfoSet} \emph{jaxen}'s flexibility comes from the fact that it works purely in terms of the \emph{XML InfoSet} instead of any concrete XML representation. This flexibility actually allows jaxen to work with non-XML models. The only requirement is that a \emph{Navigator} adapter be written to satisfy the subset of the InfoSet required by jaxen. %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \slide{XML-InfoSet} The \emph{XML-InfoSet} defines the semantics of XML instead of the textual serialization as the original \emph{XML 1.0} spec does. The InfoSet recognizes that the true structure is a tree with various types of nodes which the spec refers to as ``information items''. \begin{minipage}{\textwidth} \small \begin{itemize} \item \emph{Document Information Item} \item \emph{Element Information Items} \item \emph{Attribute Information Items} \item \emph{Processing Instruction Information Items} \item \emph{Character Information Items} \item \emph{Comment Information Items} \item \emph{Namespace Information Items} \end{itemize} \end{minipage} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{InfoSet - Document Info Item} The \emph{Document} information item is typically modeled in XML object-model frameworks by an explicit class such as \emph{org.dom4j.Document} or \emph{org.jdom.Document}. The document information item most importantly contains children, including the root element and any comments or processing-instructions outside of the root element. \diagram{infoset-doc} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{InfoSet - Element Info Items} Each tag in an XML document is an element and is represented by the Info-Set as an \emph{Element} information item. Once again, most XML object-model frameworks represent each element with an instance of an element class, such as \emph{org.dom4j.Element} or \emph{org.jdom.Element}. An element information item contains several types of children, including attributes, comments, namespace declarations, text context and other elements. It also contains information regarding its own name and namespace. \begin{codelisting} \hifade{<\hiblue{article} id="mcw03" \hiblue{xmlns="http://jaxen.org/example-ns/"}>} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{InfoSet - Element Info Items - Diagram} \diagram{infoset-elem} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{InfoSet - Attribute Info Items} Each attribute that does not begin with \emph{xmlns} is represented by an \emph{Attribute} information item. Most object-models represent them with an explicit attribute class such as \emph{org.dom4j.Attribute} or \emph{org.jdom.Attribute}. It contains information regarding its own name and namespace. \begin{codelisting} \hifade{
} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{InfoSet - Processing-Instruction Info Items} Processing-instructions, while not widely used, embody their target and the text associated with them. Different object-models represent PIs differently, so no generalized statement may be made. \begin{codelisting} \hifade{} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{InfoSet - Character Info Items} The InfoSet defines a \emph{Character} information item for each individual text character. The \emph{Navigator} of jaxen works with consecutive spans of uninterrupted characters. \begin{codelisting} \hifade{ \hiblue{jaxen is a fun and exciting way to drive your coworkers insane..} } \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{InfoSet - Comment Info Items} \emph{Comment} information items appear as children of either \emph{Document} or \emph{Element} items and contain the textual content of the comments themselves. \begin{codelisting} \hifade{ \hiblue{} \hiblue{} } \end{codelisting} \emph{NOTE:} Due to how the specifications are written, there is no guarantee that XML parsed from a file will ever contain comment items. Parsers are allowed to discard the comments and so they may not be included in your model of choice. %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{InfoSet - Namespace Info Items} The \emph{Namespace} information items contained by \emph{Element} items represent all XML namespace bindings in effect at the scope of the element. \begin{codelisting} \hifade{ } \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \slide{What is XPath?} XPath is a node-addressing expression language for the XML InfoSet. XPath expressions are used to traverse the graph provided by the InfoSet in order to locate any node contained therein. \begin{itemize} \item \emph{Full expression language.} \item \emph{Multiple `directions' of traversal.} \item \emph{Predicate evaluation for filtering.} \item \emph{Extremely extensible.} \end{itemize} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \slide{Compared to XQuery} XPath and XQuery vaguely overlap in functionality. XPath 2.0 overlaps even more so with XQuery. In general, XQuery is more rigorously defined, more type-safe, much larger, and not finished. XPath is strictly an addressing language, not a full query language, but most people find that it satisfies the 80/20 rule where it provides 80\% of the solution for 20\% of the effort. %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \breakslide{Simple Expressions} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \slide{Math!} Since XPath is a full expression language, arbitrary arithmetic constitutes valid expressions. \egxpath{42 + 84.2} \egxpath{10 div 3} \egxpath{(1 + 3) * 42} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \slide{Location Paths} \emph{Location paths} are the core of the XPath expression language with regards to XML documents. A location path is comprised of a series of \emph{steps}. Each step is evaluated, in order, against the results of the previous step. The result of each step is a possibly empty set of some nodes from the document. \egxpath{/journal/article/author} What that means\dots %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Location Paths - Processing Logic} An XPath is evaluated in relation to some initial context which typically is a \emph{Document} node from an object-model. Examples of common initial context classes: \begin{minipage}{\textwidth} \small \begin{itemize} \item \emph{org.dom4j.Document} \item \emph{org.jdom.Document} \item \emph{org.w3c.dom.Document} \end{itemize} \end{minipage} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Location Paths - Processing Logic - Example Document} Given a document with the structure: \begin{codelisting}
... Bob McWhirter
... James Strachan
\end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Location Paths - Processing Logic - Example XPath} Given an XPath expression: \egxpath{/journal/article/author/last} Let's walk through how it is evaluated to select all \tag{last} elements which are children of \tag{author} elements which in turn are children of \tag{article} elements that have a parent \tag{journal} element that is the root element of a document. \dots{}whew\dots The initial slash character (``\texttt{/}'') indicates that regardless of the initial context, the path is an \emph{absolute location path} and thus starts at the very top of the document. %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Location Paths - Processing Logic - Journal } \egxpath{/\hiblue{journal}/article/author/last} \begin{codelisting} \hifade{\hiblue{}
... Bob McWhirter
... James Strachan
\hiblue{
}} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Location Paths - Processing Logic - Article } \egxpath{/journal/\hiblue{article}/author/last} \begin{codelisting} \hifade{ \hiblue{
} ... Bob McWhirter \hiblue{
} \hiblue{
} ... James Strachan \hiblue{
}
} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Location Paths - Processing Logic - Author } \egxpath{/journal/article/\hiblue{author}/last} \begin{codelisting} \hifade{
... \hiblue{} Bob McWhirter \hiblue{}
... \hiblue{} James Strachan \hiblue{}
} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Location Paths - Processing Logic - Last } \egxpath{/journal/article/author/\hiblue{last}} \begin{codelisting} \hifade{
... Bob \hiblue{McWhirter}
... James \hiblue{Strachan} /author>
} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Location Paths - Processing Logic - Results } The result of evaluating the XPath against the document is a \emph{node-set} that contains nodes directly from the original object-model. The results are \emph{not copies}. In this case, the results are two \emph{element} nodes, being instances of classes such as: \begin{minipage}{\textwidth} \small \begin{itemize} \item \emph{org.dom4j.Element} \item \emph{org.jdom.Element} \item \emph{org.w3c.dom.Element} \end{itemize} \end{minipage} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Location Paths - Attributes} The previous example demonstrated some of the simplest location path expressions possible. Not only can a location path select elements, they can also select attributes amongst other items. A step that begins with the ``\at'' character selects an attribute with the given name instead of an element. %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Location Paths - Attributes} \egxpath{/journal/article/\hiblue{@id}} This path would select the \texttt{id} attribute node from each of the \tag{article} tags. Once again, it selects instances of the actual corresponding classes for attributes in the target object-model, such as: \begin{itemize} \item \bemph{org.dom4j.Attribute} \item \bemph{org.jdom.Attribute} \item \bemph{org.w3c.dom.Attr} \end{itemize} The path does \emph{not} select the values of the attributes. %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Location Paths - Attributes - Example} \egxpath{/journal/article/\hiblue{@id}} \begin{codelisting}
... Bob McWhirter
... James Strachan
\end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Location Paths - Predicates} Sometimes it is desirable to narrow the results of a particular step of a location path. This narrowing is the job of a \emph{predicate}. Multiple predicates can be chained together to further and further constrain the result node set. \egxpath{/journal/article\hiblue{[@id='article.2']}} After a step has been evaluated, if a predicate follows, then the predicate is evaluated in relation to each member of the node set. %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Location Paths - Predicates - Base} \egxpath{\hiblue{/journal/article}[@id='article.2']} \begin{codelisting} \hiblue{
} ... Bob McWhirter \hiblue{
} \hiblue{
} ... James Strachan \hiblue{
}
\end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Location Paths - Predicates - 1st article} \egxpath{/journal/article[\hiblue{@id='article.2'}]} \begin{codelisting} \hiblue{
} ... Bob McWhirter \hiblue{
}
... James Strachan
\end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Location Paths - Predicates - 2nd article} \egxpath{/journal/article[\hiblue{@id='article.2'}]} \begin{codelisting}
... Bob McWhirter
\hiblue{
} ... James Strachan \hiblue{
}
\end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Location Paths - Predicates - Proximity} The previous predicate was based upon some \emph{content} as opposed to \emph{position} within the document. XPath defines the concept of a \emph{proximity predicate} that allows selection of specific elements by their location using roughly array notation. \egxpath{/journal/article[2]} Selects the second \tag{article} under the \tag{journal} tag. Since proximity predicates rely only on the positions of nodes, they are \emph{fragile} and do not survive large-scale editing of the document. \emph{NOTE:} Unlike Java, XPath indices begin at \texttt{1} instead of \texttt{0}. %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Location Paths - Predicates - Proximity} \egxpath{/journal/article[2]} \begin{codelisting}
... Bob McWhirter
\hiblue{
} ... James Strachan \hiblue{
}
\end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Location Paths - Predicates - Multiple} Predicates can be chained together to recursively refine the selection. \egxpath{/journal/article\hiblue{[author/last='Strachan'][1]}} This path would only select the first \tag{article} that was written by an author with the last name \texttt{Strachan}. %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Location Paths - Predicates - Nested} Predicates contain any arbitrary XPath expression which can include other location paths and predicates. \egxpath{/journal/article\hiblue{[author[1]/last='Strachan']}} This path would select all \tag{article} elements whose first \tag{author} has the \tag{last} name of \texttt{Strachan}. %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Location Paths - Predicates - Nested - Example} \egxpath{/journal/article\hiblue{[author[1]/last='Strachan']}} \begin{codelisting} \tiny \hiblue{
} ... James Strachan Bob McWhirter \hiblue{
}
\end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \breakslide{Jaxen API} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \slide{Model Bindings} Several object-models, such as \emph{dom4j} and \emph{EXML} include bindings to the jaxen xpath engine through their own APIs, typically in the form of \emph{selectNodes(String xpathExpr)} or \emph{selectSingleNode(String xpathExpr)} methods on their \emph{Document} and \emph{Element} classes. Here, we'll address using jaxen directly in conjunction with an object-model. Please consult your chosen model's API documentation for any native bindings it may have. %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \slide{The XPath Classes} The main interface for working with jaxen XPaths is \emph{org.jaxen.XPath}. \begin{codelisting} package org.jaxen; public interface XPath \{ Object evaluate(Object context) throws JaxenException; \dots \} \end{codelisting} Each supported object-model has a matching concrete implementation: \begin{minipage}{\textwidth} \small \begin{itemize} \item \bemph{org.jaxen.dom4j.Dom4jXPath} \item \bemph{org.jaxen.jdom.JDOMXPath} \item \bemph{org.jaxen.dom.DOMXPath} \end{itemize} \end{minipage} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{The XPath Classes - Constructing} Once the appropriate class has been selected and imported into your code, a new instance of the \emph{XPath} class may be created using the constructor that takes a string XPath expression. \begin{codelisting} try \{ \hiblue{XPath xpath = new Dom4jXPath( "/journal/article/[author/last='Strachan']" );} \} catch (JaxenException e) \{ e.printStackTrace(); \} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{The XPath Classes - Evaluation} Once an \emph{XPath} has been instantiated successfully, it may be evaluated against multiple different contexts. The \emph{XPath} implementations are thread-safe and so may be cached and shared by multiple threads. \begin{codelisting} try \{ \hiblue{XPath xpath = new Dom4jXPath( "/journal/article/[author/last='Strachan']" );} Document doc = retrieveDocument(); \hiblue{List results = (List) xpath.evaluate( doc );} \} catch (JaxenException e) \{ e.printStackTrace(); \} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{The XPath Classes - Evaluation - Results} As noted before, while the XPath is primarily intended for manipulating XML, it is a full expression language capable of evaluating non-XML-based expressions. The return value of \emph{evaluate(...)} is a \emph{java.lang.Object}. Calling code must cast the result to the appropriate class. When working with location paths, the result will always be a \emph{java.util.List} which represents the possibly empty node set of selected nodes. The members of the List will be instances of classes from the underlying object-model. In other cases, it may return \emph{java.lang.Number}, \emph{java.lang.Boolean}, or \emph{java.lang.String}. %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{The XPath Classes - Evaluation - Helpers} The \emph{XPath} interface allows for additional helper methods that handle much of the desired conversion and casting. \begin{codelisting} package org.jaxen; public interface XPath \{ String \hiblue{stringValueOf}(Object context) throws JaxenException; boolean \hiblue{booleanValueOf}(Object context) throws JaxenException; boolean \hiblue{numberValueOf}(Object context) throws JaxenException; List \hiblue{selectNodes}(Object context) throws JaxenException; Object \hiblue{selectSingleNode}(Object context) throws JaxenException; \} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{The XPath Classes - Evaluation - stringValueOf} The \emph{stringValueOf(...)} method performs a normal \emph{evaluate(...)} and then follows XPath's rules for coercion of the result to a string. In terms of XPath, this means that the first node is converted to its string value and all others are discarded. \egxpath{/journal/article/author/last} While this path would select both of the \tag{author} tags, only the first would be converted to its string value, which for elements, is the complete text content. This would result in the string \texttt{McWhirter}. %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{The XPath Classes - Evaluation - booleanValueOf} The \emph{booleanValueOf(...)} method performs a normal \emph{evaluate(...)} and then follows XPath's rules for coercion of the result to a boolean. An empty result set is interpreted as \texttt{false} while a non-empty result set is interpreted as \texttt{true}. This XPath would return \texttt{true}: \egxpath{/journal/article/author[last='McWhirter']} This XPath would return \texttt{false}: \egxpath{/journal/article/author[last='MacWithier']} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{The XPath Classes - Evaluation - numberValueOf} The \emph{numberValueOf(...)} method performs a normal \emph{evaluate(...)} and then follows XPath's rules for coercion of the result to a number. In terms of XPath, this means that the first node is converted to its number value and all others are discarded. %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{The XPath Classes - Evaluation - selectNodes} The \emph{selectNodes(...)} method makes sense only for XPaths that perform node selection and not arithmetic. It simplifies calling code by performing the cast to a \emph{List} on the results of \emph{evaluate(...)}. This XPath would return all \tag{author} elements in a list. \egxpath{/journal/article/author} \begin{codelisting} try \{ \hiblue{List authors = xpath.selectNodes( "/journal/article/author" );} \} catch (JaxenException e) \{ e.printStackTrace(); \} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{The XPath Classes - Evaluation - selectSingleNode} The \emph{selectSingleNode(...)} method operates similar to \emph{selectNodes(...)} but only returns the first member of the selected list as an \emph{Object}. Depending on the expression, calling code must cast to a class appropriate to the object-model being used. This XPath would return only the first \tag{author} element. \egxpath{/journal/article/author} \begin{codelisting} try \{ \hiblue{Element firstAuthor = (Element) xpath.selectSingleNode( "/journal/article/author" );} \} catch (JaxenException e) \{ e.printStackTrace(); \} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \breakslide{Advanced XPath\\ \& \\ Jaxen} \begin{center} Namespaces - Variables - Functions \end{center} \slide{Namespaces} In many modern XML documents, XML Namespaces are used to help differentiate tags. Multiple tags may have the same name but exist in different namespaces. These are considered unique. \begin{codelisting} <\hiblue{soap:Envelope} \hiblue{xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"} soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <\hiblue{mail:Envelope} \hiblue{xmlns:mail="http://jaxen.org/example-ns/mail/"}> bob@werken.com <\hiblue{/mail:Envelope}> <\hiblue{/soap:Envelope}> \end{codelisting} Here, two different \tag{Envelope} tags exist. One exists in the \bemph{http://schemas.xmlsoap.org/soap/envelope} namespace while the other is in the \bemph{http://jaxen.org/example-ns/mail/} namespace. %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Namespaces - URIs} The namespace of an element is a \emph{URI} that does not necessarily have to be resolvable or point to any particular type of resource. It acts purely as a distinguishing identifier. It would be unwieldy to affix the namespace URI to each element, so XML defines a way to declare a \emph{prefix mapping} for each namespace. This is accomplished by adding a pseudo-attribute to an element. \begin{codelisting} ... \end{codelisting} Any pseudo-attribute that begins with \emph{xmlns} is considered to be a namespace prefix mapping within the scope of the element upon which it is defined. %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Namespaces - Prefix Mapping} The normal form of a namespace prefix mapping declaration is: \egcode{\hiblue{xmlns:\$\{PREFIX\}="\$\{URI\}"}} \egcode{\hifade{}} The declaration is available for the tag upon which it is declared and any nested child tag. A prefix mapping is not required to be used by the tag upon which it is defined, and multiple mappings may be declared upon a single tag. \egcode{\hifade{<\hiblue{a:}tagname \hiblue{xmlns:a="uri-a" xmlns:b="uri-b"}>}} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Namespaces - Default Mapping} A \emph{default namespace mapping} can be used to define which namespace tags are a part of, unless otherwise specified. The format of the default mapping is identical to the prefix mapping, with the exception that a prefix is not used. \egcode{\hiblue{xmlns="\$\{URI\}"}} \egcode{\hifade{}} In this case, \tag{tagname} has no prefix but a default namespace mapping is defined, so \tag{tagname} is a member of \texttt{\hiblue{my-namespace}}. %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Namespaces - Prefixes Do Not Matter} The actual prefixes used within a document \bemph{do not matter}. Only the mapped namespace URI is important. These three documents are semantically identical: Using the default namespace mapping functionality: \begin{codelisting} \end{codelisting} Using the prefix namespace mapping functionality: \begin{codelisting} \end{codelisting} Using the prefix namespace mapping functionality with a different prefix: \begin{codelisting} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Namespaces - Prefixes - XPath} Since prefixes do not matter, how do you construct an XPath that works with namespaces? \begin{center} \bemph{Using prefixes!} \end{center} Just as each element in a document has a set of prefix-to-namespace mappings, an XPath expression may also contain a set of prefix-to-namespace mappings. The only caveat is that XPath has absolutely no concept of a default namespace mapping. \egxpath{\hiblue{j:}journal/\hiblue{j:}article/\hiblue{j:}author/\hiblue{j:}last} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Namespaces - Prefixes - XPath - Mappings} The XPath specification does not address how prefix namespace mappings are created. It only specifies that an XPath is evaluated within the scope of a \emph{namespace context} which defines the mappings. In \emph{XSLT}, the namespace context is composed of all namespace mappings in effect within the template \emph{(not the target document)} at the point the xpath is used. \begin{codelisting} \hifade{ \dots } \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Namespaces - Prefixes - XPath - Mappings} The template will match \tag{author} tags in the \emph{http://werken.com/werken-journal/} namespace, regardless of the actual prefix (or default mapping) used within the target document. \begin{codelisting} \hifade{ <\hiblue{author}> \dots <\hiblue{/author}> } \end{codelisting} \begin{codelisting} \hifade{ <\hiblue{yak:author}> \dots <\hiblue{/yak:author}> } \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Namespaces - Jaxen} Since jaxen is purely an XPath engine, and not an XSLT engine, it follows the specification in mandating nothing about how namespace prefix mappings are generated, but simply a \emph{namespace context} is available. This is accomplished through the \bemph{org.jaxen.NamespaceContext} interface. It contains but a single method declaration for translating a prefix to a namespace URI. \begin{codelisting} package org.jaxen; public interface NamespaceContext \{ \hiblue{String translateNamespacePrefixToUri(String prefix);} \} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Namespaces - Jaxen - SimpleNamespaceContext} Since mapping a prefix to a namespace URI is a perfect job for a look-up table, jaxen provides the \bemph{org.jaxen.SimpleNamespaceContext}, which is an implementation simply backed by a hash-map. \begin{codelisting} package org.jaxen; public class SimpleNamespaceContext implements NamespaceContext \{ public SimpleNamespaceContext() \{ \dots \} public SimpleNamespaceContext(Map namespaces) \{ \dots \} public void addNamespace(String prefix, String namespaceUri) \{ \dots \} public String translateNamespacePrefixToUri(String prefix) \{ \dots \} \} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Namespaces - Jaxen - Using NamespaceContext} Each \emph{XPath} has a \emph{NamespaceContext} associated with it. The association is made using the \emph{setNamespaceContext(...)} method. \begin{codelisting} package org.jaxen; public interface XPath \{ \dots \hiblue{void setNamespaceContext(NamespaceContext namespaceContext);} \dots \} \end{codelisting} Any prefix that is resolvable through the \emph{NamespaceContext} may be used within the XPath expression itself. If code using the \emph{XPath} does not explicitly set a \emph{NamespaceContext} then a default context that contains no mappings is used. %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Namespaces - Jaxen - Example} \begin{codelisting} try \{ XPath xpath = new Dom4jXPath( \hiblue{"/j:journal/j:article/j:author"} ); SimpleNamespaceContext nsContext = new SimpleNamespaceContext(); \hiblue{nsContext.addNamespace( "j" "http://werken.com/werken-journal/" ); xpath.setNamespaceContext( nsContext );} Document journalDoc = getJournalEdition( 42 ); List authors = xpath.selectNodes( journalDoc ); \} catch (JaxenException e) \{ e.printStackTrace(); \} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \slide{Variables} The XPath specification allows for \emph{variables} in expressions to allow parameterization at evaluation time. Similar to the namespace-context, each XPath expression also has a variable-context that maps variable names to values. \egxpath{/journal/article/author[last=\hiblue{\$lastName}]} Or with namespace support: \egxpath{/journal/article/author[last=\hiblue{\$myNsPrefix:lastName}]} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Variables - Jaxen - VariableContext} Parallel to the \emph{NamespaceContext}, jaxen provides an interface \emph{VariableContext} and a useful simple implementation. \begin{codelisting} package org.jaxen; public interface VariableContext \{ Object getVariableValue(String namespaceUri, String prefix, String localName) throws UnresolvableException; \} \end{codelisting} The three parameters to the \emph{getVariableValue(...)} method are: \begin{minipage}{\textwidth} \small \begin{enumerate} \item \bemph{namespaceUri} The namespace URI associated with the\\ prefix as determined by the current \emph{NamespaceContext}. \item \bemph{prefix} The actual prefix used in the XPath expression. \item \bemph{localName} The portion of the variable name that is\\ not the namespace prefix. \end{enumerate} \end{minipage} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Variables - Jaxen - SimpleVariableContext} A simple implementation of \emph{VariableContext} is provided by the sensibly-named \emph{SimpleVariableContext}, which is backed by a hash-map. \begin{codelisting} package org.jaxen; public class SimpleVariableContext implements VariableContext \{ public SimpleVariableContext() \{ \dots \} public void setVariableValue(String namespaceUri, String localName, Object value) \{ \dots \} public void setVariableValue(String localName, Object value) \{ \dots \} public Object getVariableValue(String namespaceUri, String prefix, String localName) throws UnresolvableException \{ \dots \} \} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Variables - Jaxen - Using VariableContext} Each \emph{XPath} has a \emph{VariableContext} associated with it. The association is made using the \emph{setVariableContext(...)} method. \begin{codelisting} package org.jaxen; public interface XPath \{ \dots \hiblue{void setVariableContext(VariableContext variableContext);} \dots \} \end{codelisting} If code using the \emph{XPath} does not explicitly set a \emph{VariableContex} then a default context that contains no variables is used. %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Variables - Jaxen - Example} \begin{codelisting} try \{ XPath xpath = new Dom4jXPath( "/journal/article[author/last=\hiblue{\$lastName}]" ); \hiblue{SimpleVariableContext varContext = new SimpleVariableContext(); varContext.setVariable( "lastName" "Strachan" ); xpath.setVariableContext( varContext );} Document journalDoc = getJournalEdition( 42 ); List strachanArticles = xpath.selectNodes( journalDoc ); \} catch (JaxenException e) \{ e.printStackTrace(); \} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \slide{Functions} The XPath language supports functions in expressions and provides for a core library of functions dealing with strings, numbers, booleans and node sets. Determine the number of articles written by Mr. Strachan: \egxpath{\hiblue{count(}/journal/article[author/last="Strachan"]\hiblue{)}} Find the Irish: \egxpath{/journal/article[\hiblue{starts-with(}author/last,"Mc"\hiblue{)}]} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Functions - Core Library} The core XPath function library is divided into four groups: \begin{enumerate} \item \bemph{Node set functions}\\ Functions for working with node-sets. Either the implicit current node set or one passed as a parameter. \item \bemph{String functions}\\ Functions for working with strings. Includes type coercions. \item \bemph{Boolean functions}\\ Functions for working with booleans. Includes type coercions. \item \bemph{Number functions}\\ Functions for working with numbers. Includes type coercions. \end{enumerate} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Functions - Core Library - Node Set Functions} \begin{minipage}{\textwidth} \small \begin{itemize} \item \bemph{last()} Returns the index of the last item of the current result set. \egxpath{/journal/article[\hiblue{last()}]} \item \bemph{position()} Returns the index of the current item in the current result set. \egxpath{/journal/article[\hiblue{position()}<3]} \item \bemph{count(\textsl{node-set})} Returns the number of items in the parameter result set. \egxpath{\hiblue{count(/journal/article)}} \item \bemph{id(\textsl{object})} Returns the elements with the ID specified. \egxpath{\hiblue{id("article.1")}/author/last} \end{itemize} \end{minipage} \subslide{Functions - Core Library - Node Set Functions} \begin{minipage}{\textwidth} \small \begin{itemize} \item \bemph{local-name(\textsl{node-set?})} Returns the non-namespace portion of the node name of either a node set passed as a parameter or the current node in the current node set. \egxpath{\hiblue{local-name(/wj:journal)}} \egxpath{/journal/*[\hiblue{local-name()}="article"]} \item \bemph{namespace-uri(\textsl{node-set?})} Returns the namespace URI of the node name of either a node set passed as a parameter or the current node in the current node set. \egxpath{\hiblue{namespace-uri(/wj:journal)}} \egxpath{/journal/*:*[\hiblue{namespace-uri()}="http://werken.com/werken-journal/"]} \item \bemph{name(\textsl{node-set?})} Returns the complete textual node name of either a node set passed as a parameter or the current node in the current node set. \egxpath{\hiblue{name(/journal)}} \egxpath{/*[\hiblue{name()}="soap:Envelope"]} \end{itemize} \end{minipage} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Functions - Core Library - String Functions} \begin{minipage}{\textwidth} \small \begin{itemize} \item \bemph{string(\textsl{object?})} Converts an object (possibly the current context node) to its string value. \egxpath{/journal/article/author[string()='Strachan']} \item \bemph{concat(\textsl{string, string, string*})} Concatenate two or more strings together. \egxpath{concat(author/salutation, ' ', author/last)} \item \bemph{starts-with(\textsl{string, string})} Determine if the first argument starts with the second argument string. \egxpath{/journal/article[starts-with(title, 'Advanced')]} \item \bemph{contains(\textsl{string, string})} Determine if the first argument contains the second argument string. \egxpath{/journal/article[contains(title, 'XPath')]} \end{itemize} \end{minipage} \subslide{Functions - Core Library - String Functions} \begin{minipage}{\textwidth} \small \begin{itemize} \item \bemph{substring-before(\textsl{string, string})} Retrieve the substring of the first argument that occurs before the first occurrence of the second argument string. \egxpath{substring-before(/journal/article[1]/date, '/')} \item \bemph{substring-after(\textsl{string, string})} Retrieve the substring of the first argument that occurs after the first occurrence of the second argument string. \egxpath{substring-after(/journal/article[1]/date, '/')} \item \bemph{substring(\textsl{string, number, number?})} Retrieve the substring of the first argument starting at the index of the second number argument, for the length of the optional third argument. \egxpath{substring('McStrachan', 3)} \item \bemph{string-length(\textsl{string?})} Determine the length of a string, or the current context node coerced to a string. \egxpath{/journal/article[string-length(author/last) > 9]} \end{itemize} \end{minipage} \subslide{Functions - Core Library - String Functions} \begin{minipage}{\textwidth} \small \begin{itemize} \item \bemph{normalize-space(\textsl{string?})} Retrieve the string argument or context node with all space normalized, trimming whitespace from the ends and compressing consecutive whitespace elements to a single space. \egxpath{normalize-space(/journal/article[1]/content)} \item \bemph{translate(\textsl{string, string, string})} Retrieve the first string argument augmented so that characters that occur in the second string argument are replaced by the character from the third argument in the same position. \egxpath{translate( 'bob', 'abc', 'ZXY' ) XoX} \end{itemize} \end{minipage} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Functions - Core Library - Boolean Functions} \begin{minipage}{\textwidth} \small \begin{itemize} \item \bemph{boolean(\textsl{object})} Convert the argument to a boolean value. \egxpath{boolean(/journal/article/author/last[.='Strachan']} \item \bemph{not(\textsl{boolean})} Negate a boolean value. \egxpath{not(/journal/article/author/last[.='Strachan']} \item \bemph{true()} Boolean true. \item \bemph{false()} Boolean false. \item \bemph{lang(\textsl{string})} Test if the lang, as set by \verb|xml:lang| attributes is the language specified. \egxpath{/journal/article[1]/content[lang('en')]} \end{itemize} \end{minipage} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Functions - Core Library - Number Functions} \begin{minipage}{\textwidth} \small \begin{itemize} \item \bemph{number(\textsl{object?})} Convert the argument or context node to a number value. \egxpath{/journal[number(year)=2003]} \item \bemph{sum(\textsl{node-set})} Sum the values of the node-set. \egxpath{sum(/journal/article/author/age)} \item \bemph{floor(\textsl{number})} Return the largest integer that is not greater than the number argument. \item \bemph{ceiling(\textsl{number})} Return the smallest integer that is not less than the number argument. \item \bemph{round(\textsl{number})} Round the number argument. \end{itemize} \end{minipage} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Functions - Function Context} Like most other things in XPath, there is a \emph{function context} that contains the core library of functions. The set of functions available within an expression is extensible. XSLT has added the \emph{document(\textsl{url})} function. Other technologies, such as \emph{XPointer} and \emph{BPEL4WS} add even more functions to the XPath function context. %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Functions - Jaxen - Function Context} An extensible function context is supported in jaxen through the \emph{FunctionContext} interface. \begin{codelisting} package org.jaxen; public interface FunctionContext \{ Function getFunction(String namepsaceUri, String prefix, String localName) throws UnresolvableException; \} \end{codelisting} The three parameters to the \emph{getFunction(...)} method are: \begin{minipage}{\textwidth} \small \begin{enumerate} \item \bemph{namespaceUri} The namespace URI associated with the\\ prefix as determined by the current \emph{NamespaceContext}. \item \bemph{prefix} The actual prefix used in the XPath expression. \item \bemph{localName} The portion of the variable name that is\\ not the namespace prefix. \end{enumerate} \end{minipage} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \breakslide{Quick Romp Through Advanced XPath} \slide{Advanced Axes} XPath provides many different semantic methods for navigating a document. Each direction is an \emph{axis} that defines which nodes each \emph{step} will be applied to. Some we have already visited. Each axis allows the effects of a particular step to be constrained to a certain set of nodes for matching. The general syntax for a step with an explicit axis is: \egxpath{\hiblue{\$\{AXIS\}::}\$\{NAME\}} \egxpath{/\hiblue{child::}journal/\hiblue{child::}article/\hiblue{attribute::}id} \egxpath{\small{/journal/article/@id}} \subslide{Advanced Axes - Descriptions} \begin{minipage}{\textwidth} \small \begin{itemize} \item \bemph{child} Children of the context node. This is the default implicit axis. \item \bemph{descendant} Descendent of the context node. \item \bemph{parent} Parent of the context node. \item \bemph{ancestor} Ancestors of the context node. \item \bemph{following-sibling} Following siblings of the context node. \item \bemph{preceding-sibling} Preceding siblings of the context node. \item \bemph{following} Nodes following the context node. \item \bemph{preceding} Nodes preceding the context node. \item \bemph{attribute} Attributes of the context node. Steps begining with `@' operate along the attribute axis. \item \bemph{namespace} Namespaces of the context node. \item \bemph{self} The context node. \item \bemph{descendant-or-self} The context node or its descendants. \item \bemph{ancestor-or-self} The context node or its ancestors \end{itemize} \end{minipage} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Advanced Axes - Examples} In the following slides, the context node will be highlighed in \hiblue{blue} and the axis will be demonstrated in \hired{red}. When the context node is a part of the axis, it will be highlighted in \hipurple{purple}. %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Advanced Axes - Examples - child} \begin{codelisting} \hifade{ ...
\hiblue{
} \hired{} \hired{} \hiblue{
}
...
} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Advanced Axes - Examples - descendant} \begin{codelisting} \hifade{ ...
\hiblue{
\hired{ }
}
...
} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Advanced Axes - Examples - parent} \begin{codelisting} \hifade{ ... \hired{}
\hiblue{
} \hiblue{
}
\hired{
} ...
} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Advanced Axes - Examples - ancestor} \begin{codelisting} \hifade{\hired{} ... \hired{}
\hiblue{
} \hiblue{
}
\hired{
} ... \hired{
}} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Advanced Axes - Examples - following-sibling} \begin{codelisting} \hifade{ ...
\hiblue{
} \hiblue{
} \hired{
} \hired{
}
...
} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Advanced Axes - Examples - preceding-sibling} \begin{codelisting} \hifade{ ... \hired{
} \hired{
} \hiblue{
} \hiblue{
}
...
} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Advanced Axes - Examples - following} \begin{codelisting} \hifade{ ...
\hiblue{
} \hiblue{
} \hired{
} \hired{
}
\hired{ ... }
} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Advanced Axes - Examples - preceding} \begin{codelisting} \hifade{ \hired{ ... } \hired{
} \hired{
} \hiblue{
} \hiblue{
}
...
} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Advanced Axes - Examples - attribute} \begin{codelisting} \hifade{ ...
\hiblue{
} \hiblue{
}
...
} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Advanced Axes - Examples - self} \begin{codelisting} \hifade{ ...
\hipurple{
} \hipurple{
}
...
} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Advanced Axes - Examples - descendant-or-self} \begin{codelisting} \hifade{ ...
\hipurple{
} \hired{ } \hipurple{
}
...
} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Advanced Axes - Examples - ancestor-or-self} \begin{codelisting} \hifade{\hired{} ... \hired{}
\hipurple{
} \hipurple{
}
\hired{
} ... \hired{
}} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \slide{Node Types} Most of the previous examples have dealt with elements and attributes, but XPath defines several types of nodes that can be matched by expressions. \begin{minipage}{\textwidth} \small \begin{itemize} \item \bemph{comment} Matches any comment node. \egxpath{//\hiblue{comment()}} \item \bemph{text} Matches text nodes. \egxpath{/journal/article/title/\hiblue{text()}} \item \bemph{processing-instruction} Matches processing-instructions. \egxpath{//\hiblue{processing-instruction( 'template' )}} \item \bemph{node} Matches any node. \egxpath{/journal/article/author/\hiblue{node()}} \end{itemize} \end{minipage} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Node Types - Implicit} Implicit node types addressable by names include: \begin{minipage}{\textwidth} \small \begin{itemize} \item \bemph{element} The default node-type when performing name-based matches: \egxpath{/journal/article/author} \item \bemph{attribute} The nodes matched by steps along the \emph{attribute} axis. \egxpath{/journal/article/attribute::id} \egxpath{/journal/article/@id} \item \bemph{namespace} The nodes matched by steps along the \emph{namespace} axis. \egxpath{/journal/namespace::*} \end{itemize} \end{minipage} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \slide{Abbreviations} The XPath syntax includes a few abbreviations to make authoring expressions easier. Implicitly, the \emph{child} axis is used for any name-based matches. \egxpath{/journal/article} \egxpath{/\hiblue{child::}journal/\hiblue{child::}article} The `@' symbol is used as an abbreviation for the \emph{attribute} axis. \egxpath{/journal/article/\hiblue{@}id} \egxpath{/journal/article/\hiblue{attribute::}id} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Abbreviations} The `.' character is an abbreviation for \emph{self::node()}. \egxpath{/journal/article[\hiblue{.}/@id='article.1']} The `//' sequence is an abbreviation for \emph{descendant-or-self::node()} which allows for matching nodes with arbitrary nodes in-between. \egxpath{\hiblue{//}author/last[.='Strachan']} \egxpath{\hiblue{/descendant-or-self::node()}/author/last[.='Strachan']} The `*' character matches any element or attribute name. \egxpath{/journal/\hiblue{*}[author/last='Strachan']} \egxpath{/journal/\hiblue{@*}} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \breakslide{Navigator} \begin{center} Adapting models for XPath \end{center} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \slide{Navigation} Since XPath expression steps are evaluated in relation to a context node across a particular axis of `travel', the main aspects of navigating an object-model involves iterating over members of an axis. The \emph{Navigator} interface has a method for each axis in the form of: \begin{center} \begin{minipage}{0.8\textwidth} \small \begin{alltt} Iterator get\hiblue{\$\{AXIS\}}AxisIterator(Object contextNode) throws UnsupportedAxisException; \end{alltt} \end{minipage} \end{center} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Navigation - Axis Iterators} \begin{codelisting} package org.jaxen; public interface Navigator \{ Iterator getChildAxisIterator(Object contextNode) throws UnsupportedAxisException; Iterator getDescendantAxisIterator(Object contextNode) throws UnsupportedAxisException; Iterator getParentAxisIterator(Object contextNode) throws UnsupportedAxisException; Iterator getAncestorAxisIterator(Object contextNode) throws UnsupportedAxisException; Iterator getFollowingSiblingAxisIterator(Object contextNode) throws UnsupportedAxisException; Iterator getPrecedingSiblingAxisIterator(Object contextNode) throws UnsupportedAxisException; \end{codelisting} continues\dots \subslide{Navigator - Axis Iterator - continued} \dots\ continued \begin{codelisting} Iterator getFollowingAxisIterator(Object contextNode) throws UnsupportedAxisException; Iterator getPrecedingAxisIterator(Object contextNode) throws UnsupportedAxisException; Iterator getAttributeAxisIterator(Object contextNode) throws UnsupportedAxisException; Iterator getNamespaceAxisIterator(Object contextNode) throws UnsupportedAxisException; Iterator getSelfAxisIterator(Object contextNode) throws UnsupportedAxisException; Iterator getDescendantOrSelfAxisIterator(Object contextNode) throws UnsupportedAxisException; Iterator getAncestorOrSelfAxisIterator(Object contextNode) throws UnsupportedAxisException; \} \end{codelisting} \subslide{Navigation - DefaultNavigator} Since many of the axes are composite axes that can be synthesized from a sub-set, jaxen provides the \emph{DefaultNavigator} which is a useful base class for model-specific navigators. If a model-specific navigator implements \emph{getParentAxisIterator(...)} then the \emph{DefaultNavigator} can synthesize a useful default \emph{getAncestorAxisIterator(...)}. \subslide{Navigation - DefaultNavigator - Axis Synthesis} The following axes can be synthesized: \begin{minipage}{\textwidth} \small \begin{itemize} \item \bemph{descendant} Built from \emph{child} recursively. \item \bemph{ancestor} Built from \emph{parent} recursively. \item \bemph{self} Completely synthetic. \item \bemph{descendant-or-self} Built from \emph{child} recursively. \item \bemph{ancestor-or-self} Built from \emph{parent} recursively. \item \bemph{following} Built from \emph{parent} and \emph{child}. \item \bemph{preceding} Built from \emph{parent} and \emph{child}. \item \bemph{following-sibling} Built from \emph{parent} and \emph{child}. \item \bemph{preceding-sibling} Built from \emph{parent} and \emph{child}. \end{itemize} Much of the axes are defined by purely providing implementation for accessing parent and child relationships. \end{minipage} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \subslide{Navigation - Node types} Each method is responsible for inspecting the \emph{contextNode} parameter object and returning an \emph{Iterator} over the axis in relation to the context-node object. If the object-model as a whole does not support a particular axis of travel, \emph{UnsupportedAxisException} may be thrown. The core jaxen engine will ensure that the methods are not called with a non-sensical context. For example, \emph{getAttributeAxisIterator(...)} will never be called with a \emph{comment} node as the parameter. The \emph{Navigator} provides methods to allow the core engine to determine the node's type. \subslide{Navigation - Node types - Tests} \begin{codelisting} package org.jaxen; public interface Navigator \{ boolean isDocument(Object object); boolean isElement(Object object); boolean isAttribute(Object object); boolean isNamespace(Object object); boolean isComment(Object object); boolean isText(Object object); boolean isProcessingInstruction(Object object); \} \end{codelisting} \subslide{Navigation - Inspection} The core jaxen engine requires a way to inspect nodes for various properties, such as names, namespace URIs, and string values. \begin{codelisting} package org.jaxen; public interface Navigator \{ String getElementName(Object element); String getElementNamespaceUri(Object element); String getAttributeName(Object attr); String getAttributeNameNamespaceUri(Object attr); String getProcessingInstructionTarget(Object pi); String getProcessingInstructionData(Object pi); String getCommentStringValue(Object comment); String getElementStringValue(Object element); String getAttributeStringValue(Object attr); String getNamespaceStringValue(Object ns); String getTextStringValue(Object text); String getTextStringValue(Object text); \} \end{codelisting} \subslide{Navigation - Example Navigator} Here are some examples of implementations from the \emph{DocumentNavigator} for dom4j. \subslide{Navigation - Example Navigator - Axis Iterators} \begin{codelisting} public Iterator getChildAxisIterator(Object contextNode) \{ if ( contextNode instanceof Branch ) \{ Branch node = (Branch) contextNode; return node.nodeIterator(); \} return null; \} public Iterator getAttributeAxisIterator(Object contextNode) \{ if ( ! ( contextNode instanceof Element ) ) { return null; } Element elem = (Element) contextNode; return elem.attributeIterator(); \} \end{codelisting} \subslide{Navigation - Example Navigator - Node Types} \begin{codelisting} public boolean isText(Object obj) \{ return ( obj instanceof Text || obj instanceof CDATA ); \} public boolean isAttribute(Object obj) \{ return obj instanceof Attribute; \} public boolean isProcessingInstruction(Object obj) \{ return obj instanceof ProcessingInstruction; \} \end{codelisting} \subslide{Navigation - Example Navigator - Inspection} \begin{codelisting} public String getAttributeName(Object obj) \{ Attribute attr = (Attribute) obj; return attr.getName(); \} public String getAttributeNamespaceUri(Object obj) \{ Attribute attr = (Attribute) obj; String uri = attr.getNamespaceURI(); if ( uri != null && uri.length() == 0 ) return null; else return uri; \} public String getNamespaceStringValue(Object obj) \{ Namespace ns = (Namespace) obj; return ns.getURI(); \} \end{codelisting} %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- %% ---------------------------------------------------------------------- \breakslide{Thanks} I'd particularly wish to thank Pete Kazmier and Jeffrey Brekke for their diligent review of this presentation. Any errors that remain herein are purely my own responsibility. \breakslide{Colophon} \FoilTeX\ \& \LaTeXe\ were used in the production of these slides. Images were produced via \texttt{dia}, exported to \texttt{EPS} and converted to \texttt{PDF} for inclusion using the \texttt{epstopdf} utility. This slide deck is 100\% Microsoft-free and produced using only open-source software. \end{document} jaxen-1.1.6/src/java/0000775000175000017500000000000012174247550013675 5ustar ebourgebourgjaxen-1.1.6/src/java/test/0000775000175000017500000000000012174247547014662 5ustar ebourgebourgjaxen-1.1.6/src/java/test/org/0000775000175000017500000000000012174247547015451 5ustar ebourgebourgjaxen-1.1.6/src/java/test/org/jaxen/0000775000175000017500000000000012174247547016556 5ustar ebourgebourgjaxen-1.1.6/src/java/test/org/jaxen/test/0000775000175000017500000000000012174247547017535 5ustar ebourgebourgjaxen-1.1.6/src/java/test/org/jaxen/test/DefaultNamestepTest.java0000664000175000017500000001012710610716306024305 0ustar ebourgebourg/* * $Header$ * $Revision: 1287 $ * $Date: 2007-04-16 17:56:54 +0200 (Mon, 16 Apr 2007) $ * * ==================================================================== * * Copyright 2007 Elliotte Rusty Harold * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultNamestepTest.java 1287 2007-04-16 15:56:54Z elharo $ */ package org.jaxen.test; import java.util.List; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.JaxenException; import org.jaxen.XPath; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; /** * @author Elliotte Rusty Harold * */ public class DefaultNamestepTest extends TestCase { private Document doc; public void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.newDocument(); } public DefaultNamestepTest(String name) { super(name); } public void testIdentitySetUsageInDefaultNameStep() throws JaxenException { XPath xpath = new DOMXPath("/a/x/preceding-sibling::x[last()]"); org.w3c.dom.Element a = doc.createElementNS("", "a"); doc.appendChild(a); org.w3c.dom.Element x1 = doc.createElementNS("", "x"); org.w3c.dom.Element x2 = doc.createElementNS("", "x"); org.w3c.dom.Element x3 = doc.createElementNS("", "x"); org.w3c.dom.Element x4 = doc.createElementNS("", "x"); org.w3c.dom.Element x5 = doc.createElementNS("", "x"); a.appendChild(x1); a.appendChild(x2); a.appendChild(x3); a.appendChild(x4); a.appendChild(x5); x1.appendChild(doc.createTextNode("1")); x2.appendChild(doc.createTextNode("2")); x3.appendChild(doc.createTextNode("3")); x4.appendChild(doc.createTextNode("4")); x5.appendChild(doc.createTextNode("5")); List result = xpath.selectNodes(doc); assertEquals(1, result.size()); assertEquals(x1, result.get(0)); } } jaxen-1.1.6/src/java/test/org/jaxen/test/BinaryExprTest.java0000664000175000017500000000651610547514047023325 0ustar ebourgebourg/* * $Header$ * $Revision: 1277 $ * $Date: 2007-01-05 19:25:43 +0100 (Fri, 05 Jan 2007) $ * * ==================================================================== * * Copyright 2007 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: BinaryExprTest.java 1277 2007-01-05 18:25:43Z elharo $ */ package org.jaxen.test; import javax.xml.parsers.ParserConfigurationException; import org.jaxen.JaxenException; import org.jaxen.dom.DOMXPath; import junit.framework.TestCase; /** *

* Test for various kinds of binary expressions. *

* * @author Elliotte Rusty Harold * @version 1.1.1 * */ public class BinaryExprTest extends TestCase { public void testBooleanPrecedence() throws JaxenException, ParserConfigurationException { // Note how the parentheses change the precedence and the result DOMXPath xpath1 = new DOMXPath("false() and (false() or true())"); Boolean result1 = (Boolean) xpath1.evaluate(null); assertFalse(result1.booleanValue()); DOMXPath xpath2 = new DOMXPath("false() and false() or true()"); Boolean result2 = (Boolean) xpath2.evaluate(null); assertTrue(result2.booleanValue()); String expr = xpath1.getRootExpr().getText(); DOMXPath xpath3 = new DOMXPath(expr); Boolean result3 = (Boolean) xpath3.evaluate(null); assertEquals(expr, result1, result3); assertFalse(expr, result3.booleanValue()); } }jaxen-1.1.6/src/java/test/org/jaxen/test/BaseXPathTest.java0000664000175000017500000012602111270037767023056 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.ObjectOutputStream; import java.util.Iterator; import java.util.List; import java.util.ArrayList; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.jaxen.BaseXPath; import org.jaxen.JaxenException; import org.jaxen.NamespaceContext; import org.jaxen.SimpleNamespaceContext; import org.jaxen.XPath; import org.jaxen.dom.DOMXPath; import org.jaxen.dom.DocumentNavigator; import org.jaxen.dom.NamespaceNode; import org.jaxen.pattern.Pattern; import org.jaxen.saxpath.helpers.XPathReaderFactory; import org.w3c.dom.Attr; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.Text; import org.xml.sax.SAXException; import junit.framework.TestCase; /** *

* Tests for org.jaxen.BaseXPath. *

* * @author Elliotte Rusty Harold * @version 1.1b10 * */ public class BaseXPathTest extends TestCase { private org.w3c.dom.Document doc; private DocumentBuilder builder; public BaseXPathTest(String name) { super(name); } protected void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); doc = factory.newDocumentBuilder().newDocument(); builder = factory.newDocumentBuilder(); } public void testSelectSingleNodeForContext() throws JaxenException { BaseXPath xpath = new DOMXPath("1 + 2"); String stringValue = xpath.stringValueOf(xpath); assertEquals("3", stringValue); Number numberValue = xpath.numberValueOf(xpath); assertEquals(3, numberValue.doubleValue(), 0.00001); } public void testParentOfSelection() throws JaxenException { /* html a img a <- return that node img <- select this node */ XPath xpath = new DOMXPath("(/html/a/img[contains(@src,'gif')])[2]/.."); org.w3c.dom.Element html = doc.createElementNS("", "html"); org.w3c.dom.Element a1 = doc.createElementNS("", "a"); org.w3c.dom.Element a2 = doc.createElementNS("", "a"); org.w3c.dom.Element img1 = doc.createElementNS("", "img"); org.w3c.dom.Attr img1_src = doc.createAttributeNS("", "src"); img1_src.setValue("1.gif"); org.w3c.dom.Element img2 = doc.createElementNS("", "img"); org.w3c.dom.Attr img2_src = doc.createAttributeNS("", "src"); img2_src.setValue("2.gif"); img1.setAttributeNode(img1_src); img2.setAttributeNode(img2_src); a1.appendChild(img1); a2.appendChild(img2); html.appendChild(a1); html.appendChild(a2); doc.appendChild(html); List result = xpath.selectNodes(doc); assertEquals(1, result.size()); assertEquals(a2, result.get(0)); } public void testEvaluateString() throws JaxenException { BaseXPath xpath = new DOMXPath("string(/*)"); doc.appendChild(doc.createElement("root")); String stringValue = (String) xpath.evaluate(doc); assertEquals("", stringValue); } public void testNumberValueOfEmptyNodeSetIsNaN() throws JaxenException { BaseXPath xpath = new DOMXPath("/x"); doc.appendChild(doc.createElement("root")); Double numberValue = (Double) xpath.numberValueOf(doc); assertTrue(numberValue.isNaN()); } public void testPathWithParentheses() throws JaxenException { BaseXPath xpath = new DOMXPath("(/root)/child"); Element root = doc.createElement("root"); doc.appendChild(root); Element child = doc.createElement("child"); root.appendChild(child); assertEquals(child, xpath.selectSingleNode(doc)); } public void testEvaluateWithMultiNodeAnswer() throws JaxenException { BaseXPath xpath = new DOMXPath("(/descendant-or-self::node())"); doc.appendChild(doc.createElement("root")); List result = (List) xpath.evaluate(doc); assertEquals(2, result.size()); } public void testValueOfEmptyListIsEmptyString() throws JaxenException { BaseXPath xpath = new DOMXPath("/element"); doc.appendChild(doc.createElement("root")); String stringValue = xpath.stringValueOf(doc); assertEquals("", stringValue); } public void testAllNodesQuery() throws JaxenException { BaseXPath xpath = new DOMXPath("//. | /"); org.w3c.dom.Element root = doc.createElementNS("http://www.example.org/", "root"); doc.appendChild(root); String stringValue = xpath.stringValueOf(doc); assertEquals("", stringValue); } public void testAncestorAxis() throws JaxenException { BaseXPath xpath = new DOMXPath("ancestor::*"); org.w3c.dom.Element root = doc.createElementNS("", "root"); org.w3c.dom.Element parent = doc.createElementNS("", "parent"); doc.appendChild(root); org.w3c.dom.Element child = doc.createElementNS("", "child"); root.appendChild(parent); parent.appendChild(child); List result = xpath.selectNodes(child); assertEquals(2, result.size()); assertEquals(root, result.get(0)); assertEquals(parent, result.get(1)); } public void testPrecedingSiblingAxisIsInDocumentOrder() throws JaxenException { BaseXPath xpath = new DOMXPath("preceding-sibling::*"); org.w3c.dom.Element root = doc.createElementNS("", "root"); doc.appendChild(root); org.w3c.dom.Element child1 = doc.createElementNS("", "child1"); root.appendChild(child1); org.w3c.dom.Element child2 = doc.createElementNS("", "child2"); root.appendChild(child2); org.w3c.dom.Element child3 = doc.createElementNS("", "child3"); root.appendChild(child3); List result = xpath.selectNodes(child3); assertEquals(2, result.size()); assertEquals(child1, result.get(0)); assertEquals(child2, result.get(1)); } public void testPrecedingAxisIsInDocumentOrder() throws JaxenException { BaseXPath xpath = new DOMXPath("preceding::*"); org.w3c.dom.Element root = doc.createElementNS("", "root"); doc.appendChild(root); org.w3c.dom.Element parent1 = doc.createElementNS("", "parent1"); root.appendChild(parent1); org.w3c.dom.Element parent2 = doc.createElementNS("", "parent2"); root.appendChild(parent2); org.w3c.dom.Element child1 = doc.createElementNS("", "child1"); parent2.appendChild(child1); org.w3c.dom.Element child2 = doc.createElementNS("", "child2"); parent2.appendChild(child2); org.w3c.dom.Element child3 = doc.createElementNS("", "child3"); parent2.appendChild(child3); List result = xpath.selectNodes(child3); assertEquals(3, result.size()); assertEquals(parent1, result.get(0)); assertEquals(child1, result.get(1)); assertEquals(child2, result.get(2)); } public void testPrecedingAxisWithPositionalPredicate() throws JaxenException { BaseXPath xpath = new DOMXPath("preceding::*[1]"); org.w3c.dom.Element root = doc.createElementNS("", "root"); doc.appendChild(root); org.w3c.dom.Element child1 = doc.createElementNS("", "child1"); root.appendChild(child1); org.w3c.dom.Element child2 = doc.createElementNS("", "child2"); root.appendChild(child2); org.w3c.dom.Element child3 = doc.createElementNS("", "child3"); root.appendChild(child3); List result = xpath.selectNodes(child3); assertEquals(1, result.size()); assertEquals(child2, result.get(0)); } public void testAncestorAxisWithPositionalPredicate() throws JaxenException { BaseXPath xpath = new DOMXPath("ancestor::*[1]"); org.w3c.dom.Element root = doc.createElementNS("", "root"); doc.appendChild(root); org.w3c.dom.Element child1 = doc.createElementNS("", "child1"); root.appendChild(child1); org.w3c.dom.Element child2 = doc.createElementNS("", "child2"); child1.appendChild(child2); org.w3c.dom.Element child3 = doc.createElementNS("", "child3"); child2.appendChild(child3); List result = xpath.selectNodes(child3); assertEquals(1, result.size()); assertEquals(child2, result.get(0)); } public void testAncestorOrSelfAxis() throws JaxenException { BaseXPath xpath = new DOMXPath("ancestor-or-self::*"); org.w3c.dom.Element root = doc.createElementNS("", "root"); org.w3c.dom.Element parent = doc.createElementNS("", "parent"); doc.appendChild(root); org.w3c.dom.Element child = doc.createElementNS("", "child"); root.appendChild(parent); parent.appendChild(child); List result = xpath.selectNodes(child); assertEquals(3, result.size()); assertEquals(root, result.get(0)); assertEquals(parent, result.get(1)); assertEquals(child, result.get(2)); } // test case for JAXEN-55 public void testAbbreviatedDoubleSlashAxis() throws JaxenException { BaseXPath xpath = new DOMXPath("//x"); org.w3c.dom.Element a = doc.createElementNS("", "a"); org.w3c.dom.Element b = doc.createElementNS("", "b"); doc.appendChild(a); org.w3c.dom.Element x1 = doc.createElementNS("", "x"); x1.appendChild(doc.createTextNode("1")); a.appendChild(x1); a.appendChild(b); org.w3c.dom.Element x2 = doc.createElementNS("", "x"); org.w3c.dom.Element x3 = doc.createElementNS("", "x"); org.w3c.dom.Element x4 = doc.createElementNS("", "x"); a.appendChild(x4); b.appendChild(x2); b.appendChild(x3); x2.appendChild(doc.createTextNode("2")); x3.appendChild(doc.createTextNode("3")); x4.appendChild(doc.createTextNode("4")); List result = xpath.selectNodes(doc); assertEquals(4, result.size()); assertEquals(x1, result.get(0)); assertEquals(x2, result.get(1)); assertEquals(x3, result.get(2)); assertEquals(x4, result.get(3)); } // test case for JAXEN-55 public void testAncestorFollowedByChildren() throws JaxenException { BaseXPath xpath = new DOMXPath("/a/b/x/ancestor::*/child::x"); org.w3c.dom.Element a = doc.createElementNS("", "a"); org.w3c.dom.Element b = doc.createElementNS("", "b"); doc.appendChild(a); org.w3c.dom.Element x1 = doc.createElementNS("", "x"); x1.appendChild(doc.createTextNode("1")); a.appendChild(x1); a.appendChild(b); org.w3c.dom.Element x2 = doc.createElementNS("", "x"); org.w3c.dom.Element x3 = doc.createElementNS("", "x"); org.w3c.dom.Element x4 = doc.createElementNS("", "x"); a.appendChild(x4); b.appendChild(x2); b.appendChild(x3); x2.appendChild(doc.createTextNode("2")); x3.appendChild(doc.createTextNode("3")); x4.appendChild(doc.createTextNode("4")); List result = xpath.selectNodes(doc); assertEquals(4, result.size()); assertEquals(x1, result.get(0)); assertEquals(x2, result.get(1)); assertEquals(x3, result.get(2)); assertEquals(x4, result.get(3)); } // test case for JAXEN-55 public void testDescendantAxis() throws JaxenException { BaseXPath xpath = new DOMXPath("/descendant::x"); org.w3c.dom.Element a = doc.createElementNS("", "a"); org.w3c.dom.Element b = doc.createElementNS("", "b"); doc.appendChild(a); org.w3c.dom.Element x1 = doc.createElementNS("", "x"); x1.appendChild(doc.createTextNode("1")); a.appendChild(x1); a.appendChild(b); org.w3c.dom.Element x2 = doc.createElementNS("", "x"); org.w3c.dom.Element x3 = doc.createElementNS("", "x"); org.w3c.dom.Element x4 = doc.createElementNS("", "x"); a.appendChild(x4); b.appendChild(x2); b.appendChild(x3); x2.appendChild(doc.createTextNode("2")); x3.appendChild(doc.createTextNode("3")); x4.appendChild(doc.createTextNode("4")); List result = xpath.selectNodes(doc); assertEquals(4, result.size()); assertEquals(x1, result.get(0)); assertEquals(x2, result.get(1)); assertEquals(x3, result.get(2)); assertEquals(x4, result.get(3)); } public void testDescendantAxisWithAttributes() throws JaxenException { BaseXPath xpath = new DOMXPath("/descendant::x/@*"); org.w3c.dom.Element a = doc.createElementNS("", "a"); org.w3c.dom.Element b = doc.createElementNS("", "b"); doc.appendChild(a); org.w3c.dom.Element x1 = doc.createElementNS("", "x"); a.appendChild(x1); a.appendChild(b); org.w3c.dom.Element x2 = doc.createElementNS("", "x"); org.w3c.dom.Element x3 = doc.createElementNS("", "x"); org.w3c.dom.Element x4 = doc.createElementNS("", "x"); a.appendChild(x4); b.appendChild(x2); b.appendChild(x3); Attr a1 = doc.createAttribute("name"); a1.setNodeValue("1"); x1.setAttributeNode(a1); Attr a2 = doc.createAttribute("name"); a2.setNodeValue("2"); x2.setAttributeNode(a2); Attr a3 = doc.createAttribute("name"); a3.setNodeValue("3"); x3.setAttributeNode(a3); Attr a4 = doc.createAttribute("name"); a4.setNodeValue("4"); x4.setAttributeNode(a4); List result = xpath.selectNodes(doc); assertEquals(4, result.size()); assertEquals(a1, result.get(0)); assertEquals(a2, result.get(1)); assertEquals(a3, result.get(2)); assertEquals(a4, result.get(3)); } public void testDescendantAxisWithNamespaceNodes() throws JaxenException { BaseXPath xpath = new DOMXPath("/descendant::x/namespace::node()"); org.w3c.dom.Element a = doc.createElementNS("", "a"); org.w3c.dom.Element b = doc.createElementNS("", "b"); doc.appendChild(a); org.w3c.dom.Element x1 = doc.createElementNS("", "x"); a.appendChild(x1); a.appendChild(b); org.w3c.dom.Element x2 = doc.createElementNS("", "x"); org.w3c.dom.Element x3 = doc.createElementNS("", "x"); org.w3c.dom.Element x4 = doc.createElementNS("", "x"); a.appendChild(x4); b.appendChild(x2); b.appendChild(x3); Attr a1 = doc.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:a"); a1.setNodeValue("http://www.example.org/"); x1.setAttributeNode(a1); Attr a2 = doc.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:b"); a2.setNodeValue("http://www.example.org/"); x2.setAttributeNode(a2); Attr a3 = doc.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:c"); a3.setNodeValue("http://www.example.org/"); x3.setAttributeNode(a3); Attr a4 = doc.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:d"); a4.setNodeValue("http://www.example.org/"); x4.setAttributeNode(a4); List result = xpath.selectNodes(doc); assertEquals(8, result.size()); Iterator iterator = result.iterator(); StringBuffer sb = new StringBuffer(4); while (iterator.hasNext()) { NamespaceNode ns = (NamespaceNode) iterator.next(); if (ns.getNodeValue().equals("http://www.example.org/")) { String name = ns.getNodeName(); sb.append(name); } } assertEquals("abcd", sb.toString()); } public void testMultipleAttributesOnElement() throws JaxenException { BaseXPath xpath = new DOMXPath("/descendant::x/@*"); org.w3c.dom.Element a = doc.createElementNS("", "a"); org.w3c.dom.Element b = doc.createElementNS("", "b"); doc.appendChild(a); org.w3c.dom.Element x1 = doc.createElementNS("", "x"); a.appendChild(x1); a.appendChild(b); Attr a1 = doc.createAttribute("name1"); a1.setNodeValue("1"); x1.setAttributeNode(a1); Attr a2 = doc.createAttribute("name2"); a2.setNodeValue("2"); x1.setAttributeNode(a2); Attr a3 = doc.createAttribute("name3"); a3.setNodeValue("3"); x1.setAttributeNode(a3); Attr a4 = doc.createAttribute("name4"); a4.setNodeValue("4"); x1.setAttributeNode(a4); List result = xpath.selectNodes(doc); assertEquals(4, result.size()); assertTrue(result.contains(a1)); assertTrue(result.contains(a2)); assertTrue(result.contains(a3)); assertTrue(result.contains(a4)); } public void testXMLNamespaceAttributeOrderOnAncestorAxis() throws JaxenException { org.w3c.dom.Element superroot = doc.createElement("superroot"); doc.appendChild(superroot); org.w3c.dom.Element root = doc.createElement("root"); superroot.appendChild(root); org.w3c.dom.Attr p0 = doc.createAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:id"); p0.setValue("p0"); superroot.setAttributeNodeNS(p0); org.w3c.dom.Attr p1 = doc.createAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:id"); p1.setValue("p1"); root.setAttributeNodeNS(p1); org.w3c.dom.Element child = doc.createElement("child312"); root.appendChild(child); BaseXPath xpath = new DOMXPath("ancestor::*/@xml:*"); List result = xpath.selectNodes(child); assertEquals(2, result.size()); assertEquals(p0, result.get(0)); assertEquals(p1, result.get(1)); } public void testDescendantAxisWithAttributesAndChildren() throws JaxenException { BaseXPath xpath = new DOMXPath("/descendant::x/@* | /descendant::x"); org.w3c.dom.Element a = doc.createElementNS("", "a"); org.w3c.dom.Element b = doc.createElementNS("", "b"); doc.appendChild(a); org.w3c.dom.Element x1 = doc.createElementNS("", "x"); a.appendChild(x1); a.appendChild(b); org.w3c.dom.Element x2 = doc.createElementNS("", "x"); org.w3c.dom.Element x3 = doc.createElementNS("", "x"); org.w3c.dom.Element x4 = doc.createElementNS("", "x"); a.appendChild(x4); b.appendChild(x2); b.appendChild(x3); Attr a1 = doc.createAttribute("name"); a1.setNodeValue("1"); x1.setAttributeNode(a1); Attr a2 = doc.createAttribute("name"); a2.setNodeValue("2"); x2.setAttributeNode(a2); Attr a3 = doc.createAttribute("name"); a3.setNodeValue("3"); x3.setAttributeNode(a3); Attr a4 = doc.createAttribute("name"); a4.setNodeValue("4"); x4.setAttributeNode(a4); List result = xpath.selectNodes(doc); assertEquals(8, result.size()); assertEquals(x1, result.get(0)); assertEquals(a1, result.get(1)); assertEquals(x2, result.get(2)); assertEquals(a2, result.get(3)); assertEquals(x3, result.get(4)); assertEquals(a3, result.get(5)); assertEquals(x4, result.get(6)); assertEquals(a4, result.get(7)); } public void testAncestorAxisWithAttributes() throws JaxenException { BaseXPath xpath = new DOMXPath("ancestor::*/@*"); org.w3c.dom.Element a = doc.createElementNS("", "a"); org.w3c.dom.Element b = doc.createElementNS("", "b"); doc.appendChild(a); a.appendChild(b); org.w3c.dom.Element x3 = doc.createElementNS("", "x"); b.appendChild(x3); Attr a1 = doc.createAttribute("name"); a1.setNodeValue("1"); a.setAttributeNode(a1); Attr a2 = doc.createAttribute("name"); a2.setNodeValue("2"); b.setAttributeNode(a2); Attr a3 = doc.createAttribute("name"); x3.setNodeValue("3"); x3.setAttributeNode(a3); List result = xpath.selectNodes(x3); assertEquals(2, result.size()); assertEquals(a1, result.get(0)); assertEquals(a2, result.get(1)); } // test for Jaxen-83 public void testPrincipalNodeTypeOfSelfAxisIsElement() throws JaxenException { BaseXPath xpath = new DOMXPath("child/@*[self::test]"); org.w3c.dom.Element a = doc.createElementNS("", "child"); org.w3c.dom.Attr test = doc.createAttributeNS("", "test"); test.setValue("value"); a.setAttributeNode(test); doc.appendChild(a); List result = xpath.selectNodes(doc); assertEquals(0, result.size()); } // test to make sure Jaxen-83 fix doesn't go too far public void testSelfAxisWithNodeTestCanReturnNonPrincipalNodeType() throws JaxenException { BaseXPath xpath = new DOMXPath("child/@*[self::node()]"); org.w3c.dom.Element a = doc.createElementNS("", "child"); org.w3c.dom.Attr test = doc.createAttributeNS("", "test"); test.setValue("value"); a.setAttributeNode(test); doc.appendChild(a); List result = xpath.selectNodes(doc); assertEquals(1, result.size()); } // another Jaxen-55 test to try to pin down exactly what does // and doesn't work public void testDescendantOrSelfAxis() throws JaxenException { BaseXPath xpath = new DOMXPath("/descendant-or-self::x"); org.w3c.dom.Element a = doc.createElementNS("", "a"); org.w3c.dom.Element b = doc.createElementNS("", "b"); doc.appendChild(a); org.w3c.dom.Element x1 = doc.createElementNS("", "x"); x1.appendChild(doc.createTextNode("1")); a.appendChild(x1); a.appendChild(b); org.w3c.dom.Element x2 = doc.createElementNS("", "x"); org.w3c.dom.Element x3 = doc.createElementNS("", "x"); org.w3c.dom.Element x4 = doc.createElementNS("", "x"); a.appendChild(x4); b.appendChild(x2); b.appendChild(x3); x2.appendChild(doc.createTextNode("2")); x3.appendChild(doc.createTextNode("3")); x4.appendChild(doc.createTextNode("4")); List result = xpath.selectNodes(doc); assertEquals(4, result.size()); assertEquals(x1, result.get(0)); assertEquals(x2, result.get(1)); assertEquals(x3, result.get(2)); assertEquals(x4, result.get(3)); } public void testDuplicateNodes() throws JaxenException { BaseXPath xpath = new DOMXPath("//x | //*"); org.w3c.dom.Element a = doc.createElementNS("", "a"); org.w3c.dom.Element b = doc.createElementNS("", "b"); doc.appendChild(a); org.w3c.dom.Element x1 = doc.createElementNS("", "x"); x1.appendChild(doc.createTextNode("1")); a.appendChild(x1); a.appendChild(b); org.w3c.dom.Element x2 = doc.createElementNS("", "x"); org.w3c.dom.Element x3 = doc.createElementNS("", "x"); org.w3c.dom.Element x4 = doc.createElementNS("", "x"); a.appendChild(x4); b.appendChild(x2); b.appendChild(x3); x2.appendChild(doc.createTextNode("2")); x3.appendChild(doc.createTextNode("3")); x4.appendChild(doc.createTextNode("4")); List result = xpath.selectNodes(doc); assertEquals(6, result.size()); } public void testUnionOfNodesWithNonNodes() throws JaxenException { BaseXPath xpath = new DOMXPath("count(//*) | //x "); org.w3c.dom.Element a = doc.createElementNS("", "a"); org.w3c.dom.Element b = doc.createElementNS("", "b"); doc.appendChild(a); org.w3c.dom.Element x1 = doc.createElementNS("", "x"); x1.appendChild(doc.createTextNode("1")); a.appendChild(x1); a.appendChild(b); org.w3c.dom.Element x2 = doc.createElementNS("", "x"); org.w3c.dom.Element x3 = doc.createElementNS("", "x"); org.w3c.dom.Element x4 = doc.createElementNS("", "x"); a.appendChild(x4); b.appendChild(x2); b.appendChild(x3); x2.appendChild(doc.createTextNode("2")); x3.appendChild(doc.createTextNode("3")); x4.appendChild(doc.createTextNode("4")); try { xpath.selectNodes(doc); fail("Allowed union with non-node-set"); } catch (JaxenException ex) { assertNotNull(ex.getMessage()); } } public void testUnionOfEmptyNodeSetWithNonNodes() throws JaxenException { BaseXPath xpath = new DOMXPath("//y | count(//*)"); org.w3c.dom.Element a = doc.createElementNS("", "a"); org.w3c.dom.Element b = doc.createElementNS("", "b"); doc.appendChild(a); org.w3c.dom.Element x1 = doc.createElementNS("", "x"); x1.appendChild(doc.createTextNode("1")); a.appendChild(x1); a.appendChild(b); org.w3c.dom.Element x2 = doc.createElementNS("", "x"); b.appendChild(x2); x2.appendChild(doc.createTextNode("2")); try { xpath.selectNodes(doc); fail("Allowed union with non-node-set"); } catch (JaxenException ex) { assertNotNull(ex.getMessage()); } } public void testSelectSingleNodeSelectsNothing() throws JaxenException { BaseXPath xpath = new DOMXPath("id('p1')"); org.w3c.dom.Element a = doc.createElementNS("", "a"); doc.appendChild(a); Object result = xpath.selectSingleNode(doc); assertNull(result); } public void testSAXPathExceptionThrownFromConstructor() { System.setProperty( XPathReaderFactory.DRIVER_PROPERTY, "java.lang.String" ); try { new DOMXPath("id('p1')"); } catch (JaxenException e) { assertNotNull(e.getMessage()); } finally { System.setProperty( XPathReaderFactory.DRIVER_PROPERTY, "" ); } } public void testBooleanValueOfEmptyNodeSetIsFalse() throws JaxenException { BaseXPath xpath = new DOMXPath("/b/c"); org.w3c.dom.Element a = doc.createElementNS("", "a"); doc.appendChild(a); List result = xpath.selectNodes(doc); assertTrue(! xpath.booleanValueOf(result)); } public void testAddNamespaceWithNonSimpleNamespaceContext() throws JaxenException { BaseXPath xpath = new DOMXPath("/b/c"); xpath.setNamespaceContext(new NamespaceContext() { public String translateNamespacePrefixToUri(String prefix) { return prefix; } }); try { xpath.addNamespace("pre", "foo"); fail("Added namespace"); } catch (JaxenException ex) { assertNotNull(ex.getMessage()); } } public void testDebug() throws JaxenException { BaseXPath xpath = new DOMXPath("/b/c"); assertEquals( "[(DefaultXPath): [(DefaultAbsoluteLocationPath): [(DefaultNameStep): b]/[(DefaultNameStep): c]]]", xpath.debug() ); } public void testGetRootExpr() throws JaxenException { BaseXPath xpath = new DOMXPath("/b/c"); assertTrue(xpath.getRootExpr() instanceof org.jaxen.expr.LocationPath); } public void testUnionUsesDocumentOrder() throws JaxenException { BaseXPath xpath = new DOMXPath("/descendant::x | /a | /a/b"); org.w3c.dom.Element a = doc.createElementNS("", "a"); org.w3c.dom.Element b = doc.createElementNS("", "b"); doc.appendChild(a); org.w3c.dom.Element x1 = doc.createElementNS("", "x"); x1.appendChild(doc.createTextNode("1")); a.appendChild(x1); a.appendChild(b); org.w3c.dom.Element x2 = doc.createElementNS("", "x"); org.w3c.dom.Element x3 = doc.createElementNS("", "x"); org.w3c.dom.Element x4 = doc.createElementNS("", "x"); a.appendChild(x4); b.appendChild(x2); b.appendChild(x3); x2.appendChild(doc.createTextNode("2")); x3.appendChild(doc.createTextNode("3")); x4.appendChild(doc.createTextNode("4")); List result = xpath.selectNodes(doc); assertEquals(6, result.size()); assertEquals(a, result.get(0)); assertEquals(x1, result.get(1)); assertEquals(b, result.get(2)); assertEquals(x2, result.get(3)); assertEquals(x3, result.get(4)); assertEquals(x4, result.get(5)); } public void testArithmeticAssociativity() throws JaxenException { XPath xpath = new DOMXPath("2+1-1+1"); Double result = (Double) xpath.evaluate(doc); assertEquals(3, result.intValue()); } public void testLogicalAssociativity() throws JaxenException { XPath xpath = new DOMXPath("false() or true() and true() and false()"); Boolean result = (Boolean) xpath.evaluate(doc); assertFalse(result.booleanValue()); } public void testRelationalAssociativity3() throws JaxenException { XPath xpath = new DOMXPath("3 > 2 > 1"); Boolean result = (Boolean) xpath.evaluate(doc); assertFalse(result.booleanValue()); } public void testRelationalAssociativity4() throws JaxenException { XPath xpath = new DOMXPath("4 > 3 > 2 > 1"); Boolean result = (Boolean) xpath.evaluate(doc); assertFalse(result.booleanValue()); } public void testRelationalGTAssociativity5() throws JaxenException { XPath xpath = new DOMXPath("5 > 4 > 3 > 2 > 1"); Boolean result = (Boolean) xpath.evaluate(doc); assertFalse(result.booleanValue()); } public void testRelationalLTAssociativity5() throws JaxenException { XPath xpath = new DOMXPath("1 < 2 < 3 < 4 < 5"); Boolean result = (Boolean) xpath.evaluate(doc); assertTrue(result.booleanValue()); } public void testRelationalLEAssociativity5() throws JaxenException { XPath xpath = new DOMXPath("1 <= 2 <= 3 <= 4 <= 5"); Boolean result = (Boolean) xpath.evaluate(doc); assertTrue(result.booleanValue()); } public void testRelationalGEAssociativity5() throws JaxenException { XPath xpath = new DOMXPath("5 >= 4 >= 3 >= 2 >= 1"); Boolean result = (Boolean) xpath.evaluate(doc); assertFalse(result.booleanValue()); } public void testRelationalGEAssociativity3() throws JaxenException { XPath xpath = new DOMXPath("3 >= 2 >= 1"); Boolean result = (Boolean) xpath.evaluate(doc); assertTrue(result.booleanValue()); } public void testRelationalGEAssociativity2() throws JaxenException { XPath xpath = new DOMXPath("2 >= 1"); Boolean result = (Boolean) xpath.evaluate(doc); assertTrue(result.booleanValue()); } public void testRelationalGEAssociativity4() throws JaxenException { XPath xpath = new DOMXPath("4 >= 3 >= 2 >= 1"); Boolean result = (Boolean) xpath.evaluate(doc); assertFalse(result.booleanValue()); } // This is the same test but with parentheses to make explicit // how the previous test should be evaluated. public void testRelationalAssociativity5P() throws JaxenException { XPath xpath = new DOMXPath("((((5 > 4) > 3) > 2) > 1)"); Boolean result = (Boolean) xpath.evaluate(doc); assertFalse(result.booleanValue()); } public void testInequalityAssociativity5() throws JaxenException { XPath xpath = new DOMXPath("2 != 3 != 1 != 4 != 0"); Boolean result = (Boolean) xpath.evaluate(doc); assertTrue(result.booleanValue()); } // This is the same test but with parentheses to make explicit // how the previous test should be evaluated. public void testInequalityAssociativity5P() throws JaxenException { XPath xpath = new DOMXPath("(((2 != 3) != 1) != 4) != 0"); Boolean result = (Boolean) xpath.evaluate(doc); assertTrue(result.booleanValue()); } public void testInequalityAssociativity5B() throws JaxenException { XPath xpath = new DOMXPath("2 != 3 != 1 != 4 != 1"); Boolean result = (Boolean) xpath.evaluate(doc); assertFalse(result.booleanValue()); } // This is the same test but with parentheses to make explicit // how the previous test should be evaluated. public void testInequalityAssociativity5BP() throws JaxenException { XPath xpath = new DOMXPath("(((2 != 3) != 1) != 4) != 1"); Boolean result = (Boolean) xpath.evaluate(doc); assertFalse(result.booleanValue()); } public void testEqualityAssociativity5() throws JaxenException { XPath xpath = new DOMXPath("2 = 3 = 1 = 4 = 0"); Boolean result = (Boolean) xpath.evaluate(doc); assertTrue(result.booleanValue()); } // This is the same test but with parentheses to make explicit // how the previous test should be evaluated. public void testEqualityAssociativity5P() throws JaxenException { XPath xpath = new DOMXPath("(((2 = 3) = 1) = 4) = 0"); Boolean result = (Boolean) xpath.evaluate(doc); assertTrue(result.booleanValue()); } public void testEqualityAssociativity5B() throws JaxenException { XPath xpath = new DOMXPath("2 = 3 = 1 = 4 = 1"); Boolean result = (Boolean) xpath.evaluate(doc); assertFalse(result.booleanValue()); } // This is the same test but with parentheses to make explicit // how the previous test should be evaluated. public void testEqualityAssociativity5BP() throws JaxenException { XPath xpath = new DOMXPath("(((2 = 3) = 1) = 4) = 1"); Boolean result = (Boolean) xpath.evaluate(doc); assertFalse(result.booleanValue()); } public void testMoreComplexArithmeticAssociativity() throws JaxenException { XPath xpath = new DOMXPath("1+2+1-1+1"); Double result = (Double) xpath.evaluate(doc); assertEquals(4, result.intValue()); } public void testMostComplexArithmeticAssociativity() throws JaxenException { XPath xpath = new DOMXPath("1+1+2+1-1+1"); Double result = (Double) xpath.evaluate(doc); assertEquals(5, result.intValue()); } public void testSimplerArithmeticAssociativity() throws JaxenException { XPath xpath = new DOMXPath("1-1+1"); Double result = (Double) xpath.evaluate(doc); assertEquals(1, result.intValue()); } public void testNamespaceNodesComeBeforeAttributeNodesInDocumentOrder() throws JaxenException { org.w3c.dom.Element root = doc.createElementNS("http://www.example.org", "pre:b"); doc.appendChild(root); root.setAttribute("name", "value"); XPath xpath = new DOMXPath("/*/attribute::* | /*/namespace::node()"); List result = xpath.selectNodes(doc); assertTrue(((org.w3c.dom.Node) result.get(0)).getNodeType() == Pattern.NAMESPACE_NODE); assertTrue(((org.w3c.dom.Node) result.get(1)).getNodeType() == Pattern.NAMESPACE_NODE); assertTrue(((org.w3c.dom.Node) result.get(2)).getNodeType() == Node.ATTRIBUTE_NODE); // now flip the order of the statement and retest xpath = new DOMXPath("/*/namespace::node() | /*/attribute::* "); result = xpath.selectNodes(doc); assertTrue(((org.w3c.dom.Node) result.get(0)).getNodeType() == Pattern.NAMESPACE_NODE); assertTrue(((org.w3c.dom.Node) result.get(1)).getNodeType() == Pattern.NAMESPACE_NODE); assertTrue(((org.w3c.dom.Node) result.get(2)).getNodeType() == Node.ATTRIBUTE_NODE); } public void testJaxen97() throws JaxenException { // jaxen 97 claims this expression throws an exception. new DOMXPath("/aaa:element/text()"); } public void testAttributeNodesOnParentComeBeforeNamespaceNodesInChildInDocumentOrder() throws JaxenException { org.w3c.dom.Element root = doc.createElement("root"); doc.appendChild(root); root.setAttribute("name", "value"); Element child = doc.createElementNS("http://www.example.org", "pre:child"); root.appendChild(child); XPath xpath = new DOMXPath("/*/*/namespace::node() | //attribute::* "); List result = xpath.selectNodes(doc); assertEquals(3, result.size()); assertTrue(((org.w3c.dom.Node) result.get(0)).getNodeType() == Node.ATTRIBUTE_NODE); assertTrue(((org.w3c.dom.Node) result.get(1)).getNodeType() == Pattern.NAMESPACE_NODE); } public void testJaxen107() throws JaxenException { org.w3c.dom.Element a = doc.createElementNS("http://www.a.com/", "a:foo"); doc.appendChild(a); Element b = doc.createElementNS("http://www.b.com/", "b:bar"); a.appendChild(b); XPath xpath = new DOMXPath("/a:foo/b:bar/namespace::*/parent::*"); SimpleNamespaceContext context1 = new SimpleNamespaceContext(); context1.addNamespace("a", "http://www.a.com/"); context1.addNamespace("b", "http://www.b.com/"); xpath.setNamespaceContext(context1); List result = xpath.selectNodes(doc); assertEquals(1, result.size()); assertEquals(b, result.get(0)); } public void testJaxen107FromFile() throws JaxenException, SAXException, IOException { doc = builder.parse(new File("xml/testNamespaces.xml")); XPath xpath = new DOMXPath("/Template/Application2/namespace::*/parent::*"); List result = xpath.selectNodes(doc); assertEquals(1, result.size()); } public void testSelectNodesReturnsANonNodeSet() throws JaxenException { XPath xpath = new DOMXPath("1 + 2 + 3"); List result = xpath.selectNodes(doc); assertEquals(1, result.size()); } public void testNonElementContextNode() throws JaxenException { org.w3c.dom.Element a = doc.createElementNS("http://www.a.com/", "a:foo"); doc.appendChild(a); Text b = doc.createTextNode("ready"); a.appendChild(b); XPath xpath = new DOMXPath(".."); List result = (List) xpath.evaluate(b); assertEquals(1, result.size()); assertEquals(a, result.get(0)); } public void testNonNodeContext() throws JaxenException { org.w3c.dom.Element a = doc.createElementNS("http://www.a.com/", "a:foo"); doc.appendChild(a); Text b = doc.createTextNode("ready"); a.appendChild(b); XPath xpath = new DOMXPath(".."); try { xpath.evaluate("String"); fail("Allowed String as context"); } catch (ClassCastException ex) { // success } } public void testIsSerializable() throws JaxenException, IOException { BaseXPath path = new BaseXPath("//foo", new DocumentNavigator()); ByteArrayOutputStream out = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(out); oos.writeObject(path); oos.close(); assertTrue(out.toByteArray().length > 0); } // JAXEN-206 public void testMismatchedDepthsInContext() throws JaxenException { XPath xpath = new DOMXPath("parent::*"); org.w3c.dom.Element z = doc.createElementNS("", "z"); doc.appendChild(z); org.w3c.dom.Element a = doc.createElementNS("", "a"); z.appendChild(a); org.w3c.dom.Element b = doc.createElementNS("", "b"); a.appendChild(b); org.w3c.dom.Element c = doc.createElementNS("", "c"); z.appendChild(c); List context = new ArrayList(); context.add(b); context.add(c); List result = xpath.selectNodes(context); assertEquals(z, result.get(0)); } } jaxen-1.1.6/src/java/test/org/jaxen/test/FollowingAxisIteratorTest.java0000664000175000017500000000714310371471320025525 0ustar ebourgebourg/* $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.util.Iterator; import java.util.NoSuchElementException; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.jaxen.UnsupportedAxisException; import org.jaxen.util.FollowingAxisIterator; import org.w3c.dom.Document; import junit.framework.TestCase; public class FollowingAxisIteratorTest extends TestCase { private Iterator iterator; public FollowingAxisIteratorTest(String name) { super(name); } protected void setUp() throws ParserConfigurationException, UnsupportedAxisException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); Document doc = factory.newDocumentBuilder().newDocument(); doc.appendChild(doc.createElement("root")); iterator = new FollowingAxisIterator(doc, new org.jaxen.dom.DocumentNavigator()); } public void testNoInfiniteLoops() { try { iterator.next(); fail("Iterated too far"); } catch (NoSuchElementException ex) { pass(); } } private void pass() { // Just to make checkstyle and the like happy } public void testRemove() { try { iterator.remove(); fail("Removed from descendant axis iterator"); } catch (UnsupportedOperationException ex) { pass(); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/ArithmeticTest.java0000664000175000017500000001371512074523431023324 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.JaxenException; import org.jaxen.XPath; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; /** * @author Elliotte Rusty Harold * */ public class ArithmeticTest extends TestCase { private Document doc; public void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.newDocument(); org.w3c.dom.Element a = doc.createElementNS("", "a"); doc.appendChild(a); } public ArithmeticTest(String name) { super(name); } public void testNumbersThatBeginWithADecimalPoint() throws JaxenException { XPath xpath = new DOMXPath(".5 > .4"); Boolean result = (Boolean) xpath.evaluate(doc); assertTrue(result.booleanValue()); } public void testNumbersThatBeginWithADecimalPoint2() throws JaxenException { XPath xpath = new DOMXPath(".3 <= .4 <= 1.1"); Boolean result = (Boolean) xpath.evaluate(doc); assertTrue(result.booleanValue()); } public void testLeftAssociativityOfLessThanOrEqual() throws JaxenException { XPath xpath = new DOMXPath(".3 <= .4 <= 0.9"); Boolean result = (Boolean) xpath.evaluate(doc); assertFalse(result.booleanValue()); } public void testNegativeZeroNotEqualsZero() throws JaxenException { XPath xpath = new DOMXPath("0 != -0"); Boolean result = (Boolean) xpath.evaluate(doc); assertFalse(result.booleanValue()); } public void testNegativeZeroEqualsZero() throws JaxenException { XPath xpath = new DOMXPath("0 = -0"); Boolean result = (Boolean) xpath.evaluate(doc); assertTrue(result.booleanValue()); } public void testZeroNotGreaterThanNegativeZero() throws JaxenException { XPath xpath = new DOMXPath("0 > -0"); Boolean result = (Boolean) xpath.evaluate(doc); assertFalse(result.booleanValue()); } public void testZeroGreaterThanOrEqualsToNegativeZero() throws JaxenException { XPath xpath = new DOMXPath("0 >= -0"); Boolean result = (Boolean) xpath.evaluate(doc); assertTrue(result.booleanValue()); } public void testZeroLessThanOrEqualToNegativeZero() throws JaxenException { XPath xpath = new DOMXPath("0 <= -0"); Boolean result = (Boolean) xpath.evaluate(doc); assertTrue(result.booleanValue()); } public void testNegativeZeroNotLessThanZero() throws JaxenException { XPath xpath = new DOMXPath("-0 < 0"); Boolean result = (Boolean) xpath.evaluate(doc); assertFalse(result.booleanValue()); } public void testNaNNotEqualsString() throws JaxenException { XPath xpath = new DOMXPath("(0.0 div 0.0) != 'foo'"); Boolean result = (Boolean) xpath.evaluate(doc); assertTrue(result.booleanValue()); } public void testNaNEqualsString() throws JaxenException { XPath xpath = new DOMXPath("(0.0 div 0.0) = 'foo'"); Boolean result = (Boolean) xpath.evaluate(doc); assertFalse(result.booleanValue()); } public void testEqualityPrecedence() throws JaxenException { XPath xpath = new DOMXPath("1.5 = 2.3 = 2.3"); Boolean result = (Boolean) xpath.evaluate(doc); assertFalse(result.booleanValue()); } } jaxen-1.1.6/src/java/test/org/jaxen/test/DescendantAxisIteratorTest.java0000664000175000017500000000700110371471320025626 0ustar ebourgebourg/* $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.util.Iterator; import java.util.NoSuchElementException; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.jaxen.UnsupportedAxisException; import org.jaxen.util.DescendantAxisIterator; import org.w3c.dom.Document; import junit.framework.TestCase; public class DescendantAxisIteratorTest extends TestCase { private Iterator iterator; public DescendantAxisIteratorTest(String name) { super(name); } protected void setUp() throws ParserConfigurationException, UnsupportedAxisException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); Document doc = factory.newDocumentBuilder().newDocument(); doc.appendChild(doc.createElement("root")); iterator = new DescendantAxisIterator(doc, new org.jaxen.dom.DocumentNavigator()); } public void testNoInfiniteLoops() { iterator.next(); try { iterator.next(); fail("Iterated too far"); } catch (NoSuchElementException ex) { } } public void testRemove() { try { iterator.remove(); fail("Removed from descendant axis iterator"); } catch (UnsupportedOperationException ex) { } } } jaxen-1.1.6/src/java/test/org/jaxen/test/StringTest.java0000664000175000017500000001532410371471320022474 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.util.List; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.FunctionCallException; import org.jaxen.JaxenException; import org.jaxen.XPath; import org.jaxen.dom.DOMXPath; import org.jaxen.dom.DocumentNavigator; import org.jaxen.function.StringFunction; import org.w3c.dom.Document; /** * @author Elliotte Rusty Harold * */ public class StringTest extends TestCase { private Document doc; public void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.newDocument(); } public StringTest(String name) { super(name); } // test case for JAXEN-55 public void testStringFunctionOperatesOnFirstNodeInDocumentOrder() throws JaxenException { XPath xpath = new DOMXPath("string(//x)"); org.w3c.dom.Element a = doc.createElementNS("", "a"); org.w3c.dom.Element b = doc.createElementNS("", "b"); doc.appendChild(a); a.appendChild(b); org.w3c.dom.Element x2 = doc.createElementNS("", "x"); org.w3c.dom.Element x3 = doc.createElementNS("", "x"); org.w3c.dom.Element x4 = doc.createElementNS("", "x"); a.appendChild(x4); b.appendChild(x2); b.appendChild(x3); x2.appendChild(doc.createTextNode("2")); x3.appendChild(doc.createTextNode("3")); x4.appendChild(doc.createTextNode("4")); List result = xpath.selectNodes(doc); assertEquals(1, result.size()); assertEquals("2", result.get(0)); } public void testStringValueOfComment() throws JaxenException { XPath xpath = new DOMXPath("string(/a/comment())"); org.w3c.dom.Element a = doc.createElementNS("", "a"); doc.appendChild(a); a.appendChild(doc.createComment("data")); String result = (String) xpath.evaluate(doc); assertEquals("data", result); } public void testStringValueOfNull() { assertEquals("", StringFunction.evaluate(null, null)); } public void testStringValueOfNullWithNonNullNavigator() { assertEquals("", StringFunction.evaluate(null, new DocumentNavigator())); } public void testStringValueOfNamespaceNode() throws JaxenException { XPath xpath = new DOMXPath("string(/a/namespace::node())"); org.w3c.dom.Element a = doc.createElementNS("", "a"); doc.appendChild(a); String result = (String) xpath.evaluate(doc); assertEquals("http://www.w3.org/XML/1998/namespace", result); } public void testSmallNumbersDontUseExponentialNotation() throws JaxenException { XPath xpath = new DOMXPath("string(0.0000003)"); String result = (String) xpath.evaluate(null); assertEquals("0.0000003", result); } public void testBigNumbersDontUseExponentialNotation() throws JaxenException { XPath xpath = new DOMXPath("string(100000000.5)"); String result = (String) xpath.evaluate(null); assertEquals("100000000.5", result); } public void testStringOfInfinity() throws JaxenException { XPath xpath = new DOMXPath("string(1 div 0)"); String result = (String) xpath.evaluate(null); assertEquals("Infinity", result); } public void testStringOfNegativeInfinity() throws JaxenException { XPath xpath = new DOMXPath("string(-1 div 0)"); String result = (String) xpath.evaluate(null); assertEquals("-Infinity", result); } public void testStringOfNegativeZero() throws JaxenException { XPath xpath = new DOMXPath("string(-0)"); String result = (String) xpath.evaluate(null); assertEquals("0", result); } public void testIntegersAreFormattedAsInts() throws JaxenException { XPath xpath = new DOMXPath("string(12)"); String result = (String) xpath.evaluate(null); assertEquals("12", result); } public void testStringFunctionRequiresAtMostOneArgument() throws JaxenException { XPath xpath = new DOMXPath("string('a', 1)"); try { xpath.selectNodes(doc); fail("Allowed string function with two arguments"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/SubstringTest.java0000664000175000017500000002044310371471320023204 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.FunctionCallException; import org.jaxen.JaxenException; import org.jaxen.XPath; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; /** * @author Elliotte Rusty Harold * */ public class SubstringTest extends TestCase { private Document doc; public void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.newDocument(); doc.appendChild(doc.createElement("root")); } public SubstringTest(String name) { super(name); } public void testSubstringOfNumber() throws JaxenException { XPath xpath = new DOMXPath( "substring(1234, 3)" ); String result = (String) xpath.evaluate( doc ); assertEquals("34", result); } public void testSubstringOfNumber2() throws JaxenException { XPath xpath = new DOMXPath( "substring(1234, 2, 3)" ); String result = (String) xpath.evaluate( doc ); assertEquals("234", result); } // Unusual tests from XPath spec public void testUnusualSubstring1() throws JaxenException { XPath xpath = new DOMXPath( "substring('12345', 1.5, 2.6)" ); String result = (String) xpath.evaluate( doc ); assertEquals("234", result); } public void testUnusualSubstring2() throws JaxenException { XPath xpath = new DOMXPath( "substring('12345', 0, 3)" ); String result = (String) xpath.evaluate( doc ); assertEquals("12", result); } public void testUnusualSubstring3() throws JaxenException { XPath xpath = new DOMXPath( "substring('12345', 0 div 0, 3)" ); String result = (String) xpath.evaluate( doc ); assertEquals("", result); } public void testUnusualSubstring4() throws JaxenException { XPath xpath = new DOMXPath( "substring('12345', 1, 0 div 0)" ); String result = (String) xpath.evaluate( doc ); assertEquals("", result); } public void testUnusualSubstring5() throws JaxenException { XPath xpath = new DOMXPath( "substring('12345', -42, 1 div 0)" ); String result = (String) xpath.evaluate( doc ); assertEquals("12345", result); } public void testUnusualSubstring6() throws JaxenException { XPath xpath = new DOMXPath( "substring('12345', -1 div 0, 1 div 0)" ); String result = (String) xpath.evaluate( doc ); assertEquals("", result); } public void testSubstringOfNaN() throws JaxenException { XPath xpath = new DOMXPath( "substring(0 div 0, 2)" ); String result = (String) xpath.evaluate( doc ); assertEquals("aN", result); } public void testSubstringOfEmptyString() throws JaxenException { XPath xpath = new DOMXPath( "substring('', 2)" ); String result = (String) xpath.evaluate( doc ); assertEquals("", result); } public void testSubstringWithNegativeLength() throws JaxenException { XPath xpath = new DOMXPath( "substring('12345', 2, -3)" ); String result = (String) xpath.evaluate( doc ); assertEquals("", result); } public void testSubstringWithExcessiveLength() throws JaxenException { XPath xpath = new DOMXPath( "substring('12345', 2, 32)" ); String result = (String) xpath.evaluate( doc ); assertEquals("2345", result); } public void testSubstringWithNegativeLength2() throws JaxenException { XPath xpath = new DOMXPath( "substring('12345', 2, -1)" ); String result = (String) xpath.evaluate( doc ); assertEquals("", result); } public void testSubstringFunctionRequiresAtLeastTwoArguments() throws JaxenException { XPath xpath = new DOMXPath("substring('a')"); try { xpath.selectNodes(doc); fail("Allowed substring function with one argument"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } public void testNegativeStartNoLength() throws JaxenException { XPath xpath = new DOMXPath("substring('Hello', -50)"); String result = (String) xpath.evaluate( doc ); assertEquals("Hello", result); } public void testNegativeStartWithLength() throws JaxenException { XPath xpath = new DOMXPath("substring('Hello', -50, 20)"); String result = (String) xpath.evaluate( doc ); assertEquals("", result); } public void testSubstringFunctionRequiresAtMostThreeArguments() throws JaxenException { XPath xpath = new DOMXPath("substring('a', 1, 1, 4)"); try { xpath.selectNodes(doc); fail("Allowed substring function with four arguments"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } public void testStringLengthCountsUnicodeCharactersNotJavaChars() throws JaxenException { XPath xpath = new DOMXPath("substring('A\uD834\uDD00', 1, 2)"); String result = (String) xpath.evaluate( doc ); assertEquals("A\uD834\uDD00", result); } public void testStringLengthIndexesUnicodeCharactersNotJavaChars() throws JaxenException { XPath xpath = new DOMXPath("substring('A\uD834\uDD00', 3, 1)"); String result = (String) xpath.evaluate( doc ); assertEquals("", result); } public void testStringLengthIndexesAndCountsUnicodeCharactersNotJavaChars() throws JaxenException { XPath xpath = new DOMXPath("substring('A\uD834\uDD00123', 3, 2)"); String result = (String) xpath.evaluate( doc ); assertEquals("12", result); } } jaxen-1.1.6/src/java/test/org/jaxen/test/ExtensionFunctionTest.java0000664000175000017500000001167710416453131024717 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005, 2006 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.util.Iterator; import java.util.List; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.*; import org.jaxen.dom.DOMXPath; import org.jaxen.function.NumberFunction; import org.jaxen.saxpath.SAXPathException; import org.w3c.dom.Document; /** * @author Elliotte Rusty Harold * */ public class ExtensionFunctionTest extends TestCase { private Document doc; public void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.newDocument(); } public ExtensionFunctionTest(String name) { super(name); } class MinFunction implements Function { public Object call(Context context, List args) { if (args.isEmpty()) return new Double(Double.NaN); Navigator navigator = context.getNavigator(); double min = Double.MAX_VALUE; Iterator iterator = args.iterator(); while (iterator.hasNext()) { double next = NumberFunction.evaluate(iterator.next(), navigator).doubleValue(); min = Math.min(min, next); } return new Double(min); } } public void testRegisterExtensionFunction() throws JaxenException { SimpleFunctionContext fc = new XPathFunctionContext(false); fc.registerFunction("http://exslt.org/math", "min", new MinFunction()); SimpleNamespaceContext nc = new SimpleNamespaceContext(); nc.addNamespace("math", "http://exslt.org/math"); BaseXPath xpath = new DOMXPath("math:min(//x)"); xpath.setFunctionContext(fc); xpath.setNamespaceContext(nc); org.w3c.dom.Element a = doc.createElementNS("", "a"); org.w3c.dom.Element b = doc.createElementNS("", "b"); doc.appendChild(a); a.appendChild(b); org.w3c.dom.Element x2 = doc.createElementNS("", "x"); org.w3c.dom.Element x3 = doc.createElementNS("", "x"); org.w3c.dom.Element x4 = doc.createElementNS("", "x"); a.appendChild(x4); b.appendChild(x2); b.appendChild(x3); x2.appendChild(doc.createTextNode("2")); x3.appendChild(doc.createTextNode("3")); x4.appendChild(doc.createTextNode("4")); Double result = (Double) xpath.evaluate(doc); assertEquals(new Double(2), result); } public void testJaxen47() throws SAXPathException { org.jaxen.dom.DocumentNavigator.getInstance().parseXPath("a:b()"); } } jaxen-1.1.6/src/java/test/org/jaxen/test/PatternTests.java0000664000175000017500000000477610371471320023037 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import junit.framework.Test; import junit.framework.TestSuite; /** *

* Collect the org.jaxen.pattern tests. *

* * @author Elliotte Rusty Harold * @version 1.1b9 * */ public class PatternTests { public static Test suite() { TestSuite result = new TestSuite(); result.addTest(new TestSuite(PatternHandlerTest.class)); return result; } }jaxen-1.1.6/src/java/test/org/jaxen/test/AddNamespaceTest.java0000664000175000017500000000575310371471320023540 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2000-2003 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import junit.framework.TestCase; import org.jaxen.NamespaceContext; import org.jaxen.XPath; import org.jaxen.dom.DOMXPath; import org.jaxen.saxpath.SAXPathException; public class AddNamespaceTest extends TestCase { public AddNamespaceTest(String name) { super( name ); } public void testDefaultContext() throws SAXPathException { XPath xpath = new DOMXPath("foo"); xpath.addNamespace("cheese", "http://cheese.org"); xpath.addNamespace("squeeze", "http://squeeze.org"); NamespaceContext nsContext = xpath.getNamespaceContext(); assertEquals( "http://cheese.org", nsContext.translateNamespacePrefixToUri( "cheese" ) ); assertEquals( "http://squeeze.org", nsContext.translateNamespacePrefixToUri( "squeeze" ) ); } }jaxen-1.1.6/src/java/test/org/jaxen/test/XOMXPathTest.java0000664000175000017500000000662310371471320022640 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2000-2003 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.io.IOException; import java.util.Iterator; import java.util.List; import junit.framework.TestCase; import nu.xom.Builder; import nu.xom.Document; import nu.xom.Element; import nu.xom.ParsingException; import org.jaxen.JaxenException; import org.jaxen.XPath; import org.jaxen.xom.XOMXPath; public class XOMXPathTest extends TestCase { private static final String BASIC_XML = "xml/basic.xml"; public XOMXPathTest(String name) { super( name ); } public void testConstruction() throws JaxenException { new XOMXPath( "/foo/bar/baz" ); } public void testSelection() throws ParsingException, IOException, JaxenException { XPath xpath = new XOMXPath( "/foo/bar/baz" ); Builder builder = new Builder(); Document doc = builder.build( BASIC_XML ); List results = xpath.selectNodes( doc ); assertEquals( 3, results.size() ); Iterator iter = results.iterator(); assertEquals( "baz", ((Element)iter.next()).getLocalName() ); assertEquals( "baz", ((Element)iter.next()).getLocalName() ); assertEquals( "baz", ((Element)iter.next()).getLocalName() ); assertTrue( ! iter.hasNext() ); } } jaxen-1.1.6/src/java/test/org/jaxen/test/JaxenRuntimeExceptionTest.java0000664000175000017500000000626510371471320025522 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.io.PrintWriter; import java.io.StringWriter; import org.jaxen.JaxenException; import org.jaxen.JaxenRuntimeException; import junit.framework.TestCase; /** * @author Elliotte Rusty Harold * */ public class JaxenRuntimeExceptionTest extends TestCase { public JaxenRuntimeExceptionTest(String name) { super(name); } public void testMessageIsNonNull() { JaxenException ex = new JaxenException("Hello"); JaxenRuntimeException rex = new JaxenRuntimeException(ex); assertEquals(ex.getMessage(), rex.getMessage()); assertEquals(ex, rex.getCause()); } public void testPrintStackTrace() { JaxenException cause = new JaxenException("1234"); JaxenRuntimeException ex = new JaxenRuntimeException(cause); StringWriter out = new StringWriter(); PrintWriter pw = new PrintWriter(out); ex.printStackTrace(pw); pw.close(); assertTrue(out.toString().indexOf("Caused by: org.jaxen.JaxenException") > 0); assertTrue(out.toString().indexOf("1234") > 0); } } jaxen-1.1.6/src/java/test/org/jaxen/test/UnsupportedAxisExceptionTest.java0000664000175000017500000000505610371471320026263 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import org.jaxen.UnsupportedAxisException; import junit.framework.TestCase; /** * @author Elliotte Rusty Harold * */ public class UnsupportedAxisExceptionTest extends TestCase { public UnsupportedAxisExceptionTest(String name) { super(name); } public void testMessageIsNonNull() { UnsupportedAxisException ex = new UnsupportedAxisException("Hello"); assertEquals("Hello", ex.getMessage()); } } jaxen-1.1.6/src/java/test/org/jaxen/test/NodesetEqualityTest.java0000664000175000017500000001502011102333372024333 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2008 Andrew Sales * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.JaxenException; import org.jaxen.XPath; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; import org.w3c.dom.Element; /** *

Tests comparison of nodesets using the = and != operators.

* *
If both objects to be compared are node-sets, then the comparison * will be true if and only if there is a node in the first node-set and a node * in the second node-set such that the result of performing the comparison * on the string-values of the two nodes is true
* * @author Andrew Sales * * $Id$ */ public class NodesetEqualityTest extends TestCase { private Document doc; public void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware( true ); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.newDocument(); /* foobarblort12.0blort */ Element a = doc.createElementNS( "", "a" ); doc.appendChild( a ); Element b1 = doc.createElementNS( "", "b" ); b1.appendChild( doc.createTextNode( "foo" ) ); Element b2 = doc.createElementNS( "", "b" ); b2.appendChild( doc.createTextNode( "bar" ) ); Element b3 = doc.createElementNS( "", "b" ); b3.appendChild( doc.createTextNode( "blort" ) ); a.appendChild( b1 ); a.appendChild( b2 ); a.appendChild( b3 ); Element c1 = doc.createElementNS( "", "c" ); Element c2 = doc.createElementNS( "", "c" ); Element c3 = doc.createElementNS( "", "c" ); c2.appendChild( doc.createTextNode( " 12.0 " ) ); c3.appendChild( doc.createTextNode( "bar" ) ); a.appendChild( c1 ); a.appendChild( c2 ); a.appendChild( c3 ); } public void testEqualsTwoNodesets() throws JaxenException { XPath xpath = new DOMXPath( "//b = //c" ); Boolean result = (Boolean) xpath.evaluate( doc ); assertTrue( result.booleanValue() ); } public void testNotEqualsTwoNodesets() throws JaxenException { XPath xpath = new DOMXPath( "//a != //b" ); Boolean result = (Boolean) xpath.evaluate( doc ); assertTrue( result.booleanValue() ); } public void testEqualsStringNodeset() throws JaxenException { XPath xpath = new DOMXPath( "//b = 'blort'" ); Boolean result = (Boolean) xpath.evaluate( doc ); assertTrue(result.booleanValue()); } public void testNotEqualsStringNodeset() throws JaxenException { XPath xpath = new DOMXPath( "//b != 'phooey'" ); Boolean result = (Boolean) xpath.evaluate( doc ); assertTrue(result.booleanValue()); } public void testEqualsNumberNodeset() throws JaxenException { XPath xpath = new DOMXPath( "//c = 12" ); Boolean result = (Boolean) xpath.evaluate( doc ); assertTrue(result.booleanValue()); } public void testNotEqualsNumberNodeset() throws JaxenException { XPath xpath = new DOMXPath( "//c != 256" ); Boolean result = (Boolean) xpath.evaluate( doc ); assertTrue(result.booleanValue()); } public void testEqualsBooleanNodeset1() throws JaxenException { XPath xpath = new DOMXPath( "//c = true()" ); Boolean result = (Boolean) xpath.evaluate( doc ); assertTrue(result.booleanValue()); } public void testEqualsBooleanNodeset2() throws JaxenException { //an empty nodeset should be equal to false() XPath xpath = new DOMXPath( "//d = false()" ); Boolean result = (Boolean) xpath.evaluate( doc ); assertTrue(result.booleanValue()); } public void testNotEqualsBooleanNodeset1() throws JaxenException { XPath xpath = new DOMXPath( "//c != false()" ); Boolean result = (Boolean) xpath.evaluate( doc ); assertTrue(result.booleanValue()); } public void testNotEqualsBooleanNodeset2() throws JaxenException { //an empty nodeset should be not equal to true() XPath xpath = new DOMXPath( "//d != true()" ); Boolean result = (Boolean) xpath.evaluate( doc ); assertTrue(result.booleanValue()); } } jaxen-1.1.6/src/java/test/org/jaxen/test/NamespaceTest.java0000664000175000017500000001534310371471320023123 0ustar ebourgebourg/* $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.util.List; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.jaxen.JaxenException; import org.jaxen.SimpleNamespaceContext; import org.jaxen.UnresolvableException; import org.jaxen.XPath; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Attr; import org.w3c.dom.Element; import junit.framework.TestCase; public class NamespaceTest extends TestCase { private org.w3c.dom.Document doc; public NamespaceTest(String name) { super(name); } protected void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); doc = factory.newDocumentBuilder().newDocument(); } public void testMultipleNamespaceAxis() throws JaxenException { Element root = doc.createElement("root"); doc.appendChild(root); Element child = doc.createElementNS("http://www.example.org", "child"); child.setAttributeNS("http://www.w3.org/2000/xmlns/" , "xmlns:pre", "value"); root.appendChild(child); XPath xpath = new DOMXPath("namespace::node()"); List result = xpath.selectNodes(child); assertEquals(3, result.size()); } public void testNumberOfNamespaceNodes() throws JaxenException { Element root = doc.createElement("root"); doc.appendChild(root); Element child = doc.createElementNS("http://www.example.org", "foo:child"); root.appendChild(child); XPath xpath = new DOMXPath("//namespace::node()"); List result = xpath.selectNodes(doc); assertEquals(3, result.size()); // 1 for xml prefix on root; 1 for foo prefix on child; 1 for xml prefix on child } public void testNamespaceAxis() throws JaxenException { Element root = doc.createElement("root"); doc.appendChild(root); Element child = doc.createElementNS("http://www.example.org", "foo:child"); root.appendChild(child); XPath xpath = new DOMXPath("namespace::node()"); List result = xpath.selectNodes(child); assertEquals(2, result.size()); } public void testUnprefixedNamespaceAxis() throws JaxenException { Element root = doc.createElement("root"); doc.appendChild(root); Element child = doc.createElementNS("http://www.example.org", "child"); root.appendChild(child); XPath xpath = new DOMXPath("namespace::node()"); List result = xpath.selectNodes(child); assertEquals(2, result.size()); } public void testNamespaceNodesReadFromAttributes() throws JaxenException { Element root = doc.createElement("root"); doc.appendChild(root); Attr a = doc.createAttributeNS("http://www.example.org/", "a"); a.setNodeValue("value"); root.setAttributeNode(a); XPath xpath = new DOMXPath("namespace::node()"); List result = xpath.selectNodes(root); // one for the xml prefix; one from the attribute node assertEquals(2, result.size()); } public void testUnboundNamespaceUsedInXPathExpression() throws JaxenException { Element root = doc.createElementNS("http://www.example.org/", "root"); doc.appendChild(root); XPath xpath = new DOMXPath("/pre:root"); try { xpath.selectNodes(root); fail("Used unresolvable prefix"); } catch (UnresolvableException ex) { assertNotNull(ex.getMessage()); } } public void testQueryDefaultNamespace() throws JaxenException { Element root = doc.createElementNS("http://www.example.org/", "root"); doc.appendChild(root); XPath xpath = new DOMXPath("/pre:root"); xpath.addNamespace("pre", "http://www.example.org/"); List result = xpath.selectNodes(root); assertEquals(1, result.size()); } public void testQueryDefaultNamespaceWithContext() throws JaxenException { Element root = doc.createElementNS("http://www.example.org/", "root"); doc.appendChild(root); XPath xpath = new DOMXPath("/pre:root"); SimpleNamespaceContext context = new SimpleNamespaceContext(); context.addNamespace("pre", "http://www.example.org/"); xpath.setNamespaceContext(context); List result = xpath.selectNodes(root); assertEquals(1, result.size()); } } jaxen-1.1.6/src/java/test/org/jaxen/test/LastTest.java0000664000175000017500000001164710371471320022135 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.util.List; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.BaseXPath; import org.jaxen.FunctionCallException; import org.jaxen.JaxenException; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; /** * @author Elliotte Rusty Harold * */ public class LastTest extends TestCase { private Document doc; public void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.newDocument(); } public LastTest(String name) { super(name); } // test case for JAXEN-55 public void testLastFunction() throws JaxenException { BaseXPath xpath = new DOMXPath("//x[position()=last()]"); org.w3c.dom.Element a = doc.createElementNS("", "a"); org.w3c.dom.Element b = doc.createElementNS("", "b"); doc.appendChild(a); a.appendChild(b); org.w3c.dom.Element x2 = doc.createElementNS("", "x"); org.w3c.dom.Element x3 = doc.createElementNS("", "x"); org.w3c.dom.Element x4 = doc.createElementNS("", "x"); a.appendChild(x4); b.appendChild(x2); b.appendChild(x3); x2.appendChild(doc.createTextNode("2")); x3.appendChild(doc.createTextNode("3")); x4.appendChild(doc.createTextNode("4")); List result = xpath.selectNodes(doc); assertEquals(2, result.size()); assertEquals(x3, result.get(0)); assertEquals(x4, result.get(1)); } public void testLastFunctionAllowsNoArguments() throws JaxenException { try { BaseXPath xpath = new DOMXPath("//x[position()=last(.)]"); org.w3c.dom.Element a = doc.createElementNS("", "a"); org.w3c.dom.Element b = doc.createElementNS("", "b"); doc.appendChild(a); a.appendChild(b); org.w3c.dom.Element x2 = doc.createElementNS("", "x"); org.w3c.dom.Element x3 = doc.createElementNS("", "x"); org.w3c.dom.Element x4 = doc.createElementNS("", "x"); a.appendChild(x4); b.appendChild(x2); b.appendChild(x3); x2.appendChild(doc.createTextNode("2")); x3.appendChild(doc.createTextNode("3")); x4.appendChild(doc.createTextNode("4")); xpath.selectNodes(doc); fail("last() function took arguments"); } catch (FunctionCallException e) { assertEquals("last() requires no arguments.", e.getMessage()); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/StartsWithTest.java0000664000175000017500000001345710371471320023347 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.BaseXPath; import org.jaxen.FunctionCallException; import org.jaxen.JaxenException; import org.jaxen.XPath; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; /** * @author Elliotte Rusty Harold * */ public class StartsWithTest extends TestCase { private Document doc; public void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.newDocument(); doc.appendChild(doc.createElement("root")); } public StartsWithTest(String name) { super(name); } public void testStartsWithNumber() throws JaxenException { XPath xpath = new DOMXPath( "starts-with(33, '3')" ); Boolean result = (Boolean) xpath.evaluate( doc ); assertEquals(Boolean.TRUE, result); } public void testStartsWithString() throws JaxenException { XPath xpath = new DOMXPath( "starts-with('test', 't')" ); Boolean result = (Boolean) xpath.evaluate( doc ); assertEquals(Boolean.TRUE, result); } public void testStartsWithString3() throws JaxenException { XPath xpath = new DOMXPath( "starts-with('superlative', 'superlative')" ); Boolean result = (Boolean) xpath.evaluate( doc ); assertEquals(Boolean.TRUE, result); } public void testStartsWithNumber2() throws JaxenException { XPath xpath = new DOMXPath( "starts-with(43, '3')" ); Boolean result = (Boolean) xpath.evaluate( doc ); assertEquals(Boolean.FALSE, result); } public void testStartsWithString2() throws JaxenException { XPath xpath = new DOMXPath( "starts-with('1234567890', '1234567a')" ); Boolean result = (Boolean) xpath.evaluate( doc ); assertEquals(Boolean.FALSE, result); } public void testEmptyStringStartsWithNonEmptyString() throws JaxenException { XPath xpath = new DOMXPath( "starts-with('', 'a')" ); Boolean result = (Boolean) xpath.evaluate( doc ); assertEquals(Boolean.FALSE, result); } public void testEmptyStringStartsWithEmptyString() throws JaxenException { XPath xpath = new DOMXPath( "starts-with('', '')" ); Boolean result = (Boolean) xpath.evaluate( doc ); assertEquals(Boolean.TRUE, result); } public void testStartsWithEmptyString() throws JaxenException { XPath xpath = new DOMXPath( "starts-with('a', '')" ); Boolean result = (Boolean) xpath.evaluate( doc ); assertEquals(Boolean.TRUE, result); } public void testStartsWithFunctionRequiresAtLeastTwoArguments() throws JaxenException { BaseXPath xpath = new DOMXPath("starts-with('a')"); try { xpath.selectNodes(doc); fail("Allowed starts-with function with one argument"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } public void testStartsWithFunctionRequiresAtMostTwoArguments() throws JaxenException { BaseXPath xpath = new DOMXPath("starts-with('a', 'a', 'a')"); try { xpath.selectNodes(doc); fail("Allowed starts-with function with three arguments"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/BaseTests.java0000664000175000017500000000500210371471320022253 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import junit.framework.Test; import junit.framework.TestSuite; /** *

* Collect the org.jaxen.saxpath.base tests. *

* * @author Elliotte Rusty Harold * @version 1.1b9 * */ public class BaseTests { public static Test suite() { TestSuite result = new TestSuite(); result.addTest(new TestSuite(XPathReaderTest.class)); return result; } }jaxen-1.1.6/src/java/test/org/jaxen/test/PrecedingAxisIteratorTest.java0000664000175000017500000000714310371471320025465 0ustar ebourgebourg/* $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.util.Iterator; import java.util.NoSuchElementException; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.jaxen.UnsupportedAxisException; import org.jaxen.util.PrecedingAxisIterator; import org.w3c.dom.Document; import junit.framework.TestCase; public class PrecedingAxisIteratorTest extends TestCase { private Iterator iterator; public PrecedingAxisIteratorTest(String name) { super(name); } protected void setUp() throws ParserConfigurationException, UnsupportedAxisException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); Document doc = factory.newDocumentBuilder().newDocument(); doc.appendChild(doc.createElement("root")); iterator = new PrecedingAxisIterator(doc, new org.jaxen.dom.DocumentNavigator()); } public void testNoInfiniteLoops() { try { iterator.next(); fail("Iterated too far"); } catch (NoSuchElementException ex) { pass(); } } private void pass() { // Just to make checkstyle and the like happy } public void testRemove() { try { iterator.remove(); fail("Removed from descendant axis iterator"); } catch (UnsupportedOperationException ex) { pass(); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/HelpersTests.java0000664000175000017500000000501610371471320023010 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import junit.framework.Test; import junit.framework.TestSuite; /** *

* Collect the org.jaxen.saxpath.helpers tests. *

* * @author Elliotte Rusty Harold * @version 1.1b9 * */ public class HelpersTests { public static Test suite() { TestSuite result = new TestSuite(); result.addTest(new TestSuite(XPathReaderFactoryTest.class)); return result; } }jaxen-1.1.6/src/java/test/org/jaxen/test/JDOMXPathTest.java0000664000175000017500000001472710443564523022742 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2000-2003 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import junit.framework.TestCase; import java.io.IOException; import java.io.StringReader; import java.util.Iterator; import java.util.List; import org.jaxen.JaxenException; import org.jaxen.XPath; import org.jaxen.jdom.JDOMXPath; import org.jdom.Attribute; import org.jdom.Document; import org.jdom.Element; import org.jdom.JDOMException; import org.jdom.Namespace; import org.jdom.Text; import org.jdom.input.SAXBuilder; import org.xml.sax.InputSource; public class JDOMXPathTest extends TestCase { private static final String BASIC_XML = "xml/basic.xml"; public JDOMXPathTest(String name) { super( name ); } public void testConstruction() throws JaxenException { new JDOMXPath( "/foo/bar/baz" ); } public void testSelection() throws JaxenException, JDOMException, IOException { XPath xpath = new JDOMXPath( "/foo/bar/baz" ); SAXBuilder builder = new SAXBuilder(); Document doc = builder.build( BASIC_XML ); List results = xpath.selectNodes( doc ); assertEquals( 3, results.size() ); Iterator iter = results.iterator(); assertEquals( "baz", ((Element)iter.next()).getName() ); assertEquals( "baz", ((Element)iter.next()).getName() ); assertEquals( "baz", ((Element)iter.next()).getName() ); assertTrue( ! iter.hasNext() ); } public void testGetDocumentNode() throws JaxenException, JDOMException, IOException { XPath xpath = new JDOMXPath( "/" ); SAXBuilder builder = new SAXBuilder(); Document doc = builder.build( BASIC_XML ); Element root = doc.getRootElement(); List results = xpath.selectNodes( root ); assertEquals( 1, results.size() ); Iterator iter = results.iterator(); assertEquals( doc, iter.next()); } public void testJaxen148() throws JaxenException, JDOMException, IOException { String xml = "" + "\ntest\n" + ""; SAXBuilder builder = new SAXBuilder(); Document document = builder.build( new InputSource( new StringReader(xml) ) ); JDOMXPath x = new JDOMXPath("/xml-document/nodes/node/text()"); Text t = (Text) x.selectSingleNode(document); assertEquals( "\ntest\n" , t.getText() ); } public void testJaxen53Text() throws JaxenException, JDOMException, IOException { XPath xpath = new JDOMXPath( "//data/text() " ); SAXBuilder builder = new SAXBuilder(); Document doc = builder.build( new StringReader("\n1\n") ); List results = xpath.selectNodes( doc ); assertEquals( 1, results.size() ); Iterator iter = results.iterator(); Text result = (Text) iter.next(); assertEquals( "1", result.getValue()); } public void testJaxen20AttributeNamespaceNodes() throws JaxenException { Namespace ns1 = Namespace.getNamespace("p1", "www.acme1.org"); Namespace ns2 = Namespace.getNamespace("p2", "www.acme2.org"); Element element = new Element("test", ns1); Attribute attribute = new Attribute("foo", "bar", ns2); element.setAttribute(attribute); Document doc = new Document(element); XPath xpath = new JDOMXPath( "//namespace::node()" ); List results = xpath.selectNodes( doc ); assertEquals( 3, results.size() ); } public void testNamespaceNodesAreInherited() throws JaxenException { Namespace ns0 = Namespace.getNamespace("p0", "www.acme0.org"); Namespace ns1 = Namespace.getNamespace("p1", "www.acme1.org"); Namespace ns2 = Namespace.getNamespace("p2", "www.acme2.org"); Element element = new Element("test", ns1); Attribute attribute = new Attribute("foo", "bar", ns2); element.setAttribute(attribute); Element root = new Element("root", ns0); root.addContent(element); Document doc = new Document(root); XPath xpath = new JDOMXPath( "/*/*/namespace::node()" ); List results = xpath.selectNodes( doc ); assertEquals( 4, results.size() ); } } jaxen-1.1.6/src/java/test/org/jaxen/test/SAXPathTests.java0000664000175000017500000000504210371471320022655 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import junit.framework.Test; import junit.framework.TestSuite; /** *

* Collect the org.jaxen.saxpath.base tests. *

* * @author Elliotte Rusty Harold * @version 1.1b9 * */ public class SAXPathTests { public static Test suite() { TestSuite result = new TestSuite(); result.addTestSuite(SAXPathExceptionTest.class); result.addTestSuite(AxisTest.class); return result; } }jaxen-1.1.6/src/java/test/org/jaxen/test/LiteralExprTest.java0000664000175000017500000000700610547514047023470 0ustar ebourgebourg/* * $Header$ * $Revision: 1277 $ * $Date: 2007-01-05 19:25:43 +0100 (Fri, 05 Jan 2007) $ * * ==================================================================== * * Copyright 2006 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: LiteralExprTest.java 1277 2007-01-05 18:25:43Z elharo $ */ package org.jaxen.test; import javax.xml.parsers.ParserConfigurationException; import org.jaxen.BaseXPath; import org.jaxen.JaxenException; import org.jaxen.dom.DOMXPath; import junit.framework.TestCase; /** *

* Test for various kinds of literals. *

* * @author Elliotte Rusty Harold * @version 1.1.1 * */ public class LiteralExprTest extends TestCase { public void testStringLiteralContainsDoubleQuote() throws JaxenException, ParserConfigurationException { DOMXPath xpath = new DOMXPath("'\"'"); String expr = xpath.getRootExpr().getText(); assertEquals("'\"'", expr); } public void testStringLiteralContainsSingleQuote() throws JaxenException, ParserConfigurationException { DOMXPath xpath = new DOMXPath("\"'\""); String expr = xpath.getRootExpr().getText(); assertEquals("\"'\"", expr); } public void testJaxen177() throws JaxenException, ParserConfigurationException { BaseXPath baseXPath = new BaseXPath("//Name[@Attribute = '\"']", null); BaseXPath baseXPath2 = new BaseXPath(baseXPath.getRootExpr().getText(), null); assertEquals( "/descendant-or-self::node()/child::Name[(attribute::Attribute = '\"')]", baseXPath2.getRootExpr().getText()); } }jaxen-1.1.6/src/java/test/org/jaxen/test/SumTest.java0000664000175000017500000000730210371471320021767 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.FunctionCallException; import org.jaxen.JaxenException; import org.jaxen.XPath; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; /** * @author Elliotte Rusty Harold * */ public class SumTest extends TestCase { private Document doc; public void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.newDocument(); doc.appendChild(doc.createElement("root")); } public SumTest(String name) { super(name); } public void testSumOfNumber() throws JaxenException { try { XPath xpath = new DOMXPath( "sum(3)" ); xpath.selectNodes( doc ); fail("sum of non-node-set"); } catch (FunctionCallException e) { assertEquals("The argument to the sum function must be a node-set", e.getMessage()); } } public void testSumNoArguments() throws JaxenException { try { XPath xpath = new DOMXPath( "sum()" ); xpath.selectNodes( doc ); fail("sum of nothing"); } catch (FunctionCallException e) { assertEquals("sum() requires one argument.", e.getMessage()); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/JavaBeanNavigatorTest.java0000664000175000017500000000232510317472755024562 0ustar ebourgebourgpackage org.jaxen.test; import java.util.List; import junit.framework.TestCase; import org.jaxen.JaxenException; import org.jaxen.javabean.JavaBeanXPath; import org.jaxen.saxpath.helpers.XPathReaderFactory; public class JavaBeanNavigatorTest extends TestCase { protected void setUp() throws Exception { System.setProperty( XPathReaderFactory.DRIVER_PROPERTY, "" ); } public void testSomething() throws JaxenException { // The position() function does not really have any meaning // for JavaBeans, but we know three of them will come before the fourth, // even if we don't know which ones. JavaBeanXPath xpath = new JavaBeanXPath( "brother[position()<4]/name" ); Person bob = new Person( "bob", 30 ); bob.addBrother( new Person( "billy", 34 ) ); bob.addBrother( new Person( "seth", 29 ) ); bob.addBrother( new Person( "dave", 32 ) ); bob.addBrother( new Person( "jim", 29 ) ); bob.addBrother( new Person( "larry", 42 ) ); bob.addBrother( new Person( "ted", 22 ) ); List result = (List) xpath.evaluate( bob ); assertEquals(3, result.size()); } } jaxen-1.1.6/src/java/test/org/jaxen/test/TrueTest.java0000664000175000017500000000647610371471320022155 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.FunctionCallException; import org.jaxen.JaxenException; import org.jaxen.XPath; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; /** * @author Elliotte Rusty Harold * */ public class TrueTest extends TestCase { private Document doc; public void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.newDocument(); doc.appendChild(doc.createElement("root")); } public TrueTest(String name) { super(name); } public void testTrueOfNumber() throws JaxenException { try { XPath xpath = new DOMXPath( "true(3)" ); xpath.selectNodes( doc ); fail("true() function took arguments"); } catch (FunctionCallException e) { assertEquals("true() requires no arguments.", e.getMessage()); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/PatternHandlerTest.java0000664000175000017500000000756410371471320024150 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import junit.framework.TestCase; import org.jaxen.JaxenException; import org.jaxen.pattern.Pattern; import org.jaxen.pattern.PatternParser; import org.jaxen.saxpath.SAXPathException; import org.jaxen.saxpath.XPathSyntaxException; public class PatternHandlerTest extends TestCase { String[] paths = { "foo", "*", "/", "foo/bar", "foo//bar", "/*/foo", "*[@name]", "foo/bar[1]", "foo[bar=\"contents\"]", "foo[bar='contents']", "foo|bar", "foo/title | bar/title | xyz/title", "/foo//*", "foo/text()", "foo/@*", }; String[] bogusPaths = { }; String[] ignore_bogusPaths = { // this path is bogus because of a trailing / "/foo/bar/", // This path is bogus because '/' is not division, but // rather just the step separator. "12 + sum(count(//author),count(//author/attribute::*)) / 2", "id()/2", "+" }; public PatternHandlerTest(String name) { super( name ); } public void testValidPaths() throws JaxenException, SAXPathException { for ( int i = 0; i < paths.length; i++ ) { String path = paths[i]; PatternParser.parse( path ); } } public void testBogusPaths() throws JaxenException, SAXPathException { for ( int i = 0; i < bogusPaths.length; i++ ) { String path = bogusPaths[i]; try { Pattern pattern = PatternParser.parse( path ); fail( "Parsed bogus path as: " + pattern ); } catch (XPathSyntaxException e) { } } } } jaxen-1.1.6/src/java/test/org/jaxen/test/DefaultXPathExprTest.java0000664000175000017500000001056210513271423024415 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.util.List; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.jaxen.JaxenException; import org.jaxen.dom.DOMXPath; import org.jaxen.expr.Expr; import org.w3c.dom.Document; import org.w3c.dom.Element; import junit.framework.TestCase; /** *

* Test for function context. *

* * @author Elliotte Rusty Harold * @version 1.1b12 * */ public class DefaultXPathExprTest extends TestCase { // http://jira.codehaus.org/browse/JAXEN-40 public void testJAXEN40() throws JaxenException, ParserConfigurationException { DOMXPath xpath = new DOMXPath("root/child1/grandchild1 | root/child2/grandchild2"); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); Document doc = factory.newDocumentBuilder().newDocument(); Element root = doc.createElement("root"); Element child1 = doc.createElement("child1"); Element child2 = doc.createElement("child2"); Element grandchild1 = doc.createElement("grandchild1"); Element grandchild2 = doc.createElement("grandchild2"); root.appendChild(child1); root.appendChild(child2); child1.appendChild(grandchild1); child2.appendChild(grandchild2); doc.appendChild(root); List results = xpath.selectNodes(doc); assertEquals(2, results.size()); assertTrue(results.indexOf(grandchild1) >= 0); assertTrue(results.indexOf(grandchild2) >= 0); } // http://jira.codehaus.org/browse/JAXEN-160 public void testJAXEN160GetText() throws JaxenException, ParserConfigurationException { DOMXPath xpath = new DOMXPath("$var1/foo"); Expr expr = xpath.getRootExpr(); assertEquals("$var1/child::foo", expr.getText()); } public void testJAXEN160ToString() throws JaxenException, ParserConfigurationException { DOMXPath xpath = new DOMXPath("$var1/foo"); Expr expr = xpath.getRootExpr(); assertEquals( "[(DefaultPathExpr): [(DefaultVariableReferenceExpr): var1], [(DefaultRelativeLocationPath): [(DefaultNameStep): foo]]]", expr.toString() ); } } jaxen-1.1.6/src/java/test/org/jaxen/test/DOM4JXPathTest.java0000664000175000017500000001466610452201460023014 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2000-2003 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import junit.framework.TestCase; import java.io.StringReader; import java.util.Iterator; import java.util.List; import org.dom4j.Attribute; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.Element; import org.dom4j.Namespace; import org.dom4j.io.SAXReader; import org.dom4j.tree.DefaultAttribute; import org.dom4j.tree.DefaultDocument; import org.dom4j.tree.DefaultElement; import org.jaxen.JaxenException; import org.jaxen.XPath; import org.jaxen.XPathSyntaxException; import org.jaxen.dom4j.Dom4jXPath; import org.jaxen.saxpath.helpers.XPathReaderFactory; public class DOM4JXPathTest extends TestCase { private static final String BASIC_XML = "xml/basic.xml"; public DOM4JXPathTest(String name) { super( name ); } public void setUp() { System.setProperty( XPathReaderFactory.DRIVER_PROPERTY, "" ); } public void testConstruction() throws JaxenException { new Dom4jXPath( "/foo/bar/baz" ); } public void testSelection() throws JaxenException, DocumentException { XPath xpath = new Dom4jXPath( "/foo/bar/baz" ); SAXReader reader = new SAXReader(); Document doc = reader.read( BASIC_XML ); List results = xpath.selectNodes( doc ); assertEquals( 3, results.size() ); Iterator iter = results.iterator(); assertEquals( "baz", ((Element)iter.next()).getName() ); assertEquals( "baz", ((Element)iter.next()).getName() ); assertEquals( "baz", ((Element)iter.next()).getName() ); assertTrue( ! iter.hasNext() ); } public void testAsBoolean() throws JaxenException, DocumentException { XPath xpath = new Dom4jXPath( "/root/a = 'a'" ); SAXReader reader = new SAXReader(); Document doc = reader.read( "xml/simple.xml" ); boolean answer = xpath.booleanValueOf( doc ); assertTrue( "Xpath worked: " + xpath, answer ); xpath = new Dom4jXPath( "'a' = 'b'" ); answer = xpath.booleanValueOf( doc ); assertTrue( "XPath should return false: " + xpath, ! answer ); } public void testJaxen20AttributeNamespaceNodes() throws JaxenException { Namespace ns1 = Namespace.get("p1", "www.acme1.org"); Namespace ns2 = Namespace.get("p2", "www.acme2.org"); Element element = new DefaultElement("test", ns1); Attribute attribute = new DefaultAttribute("pre:foo", "bar", ns2); element.add(attribute); Document doc = new DefaultDocument(element); XPath xpath = new Dom4jXPath( "//namespace::node()" ); List results = xpath.selectNodes( doc ); assertEquals( 3, results.size() ); } public void testJaxen16() throws JaxenException, DocumentException { String document = ""; SAXReader reader = new SAXReader(); Document doc = reader.read( new StringReader(document) ); XPath xpath = new Dom4jXPath( "/a/b" ); List results = xpath.selectNodes( doc ); assertEquals( 0, results.size() ); } public void testNamespaceNodesAreInherited() throws JaxenException { Namespace ns0 = Namespace.get("p0", "www.acme0.org"); Namespace ns1 = Namespace.get("p1", "www.acme1.org"); Namespace ns2 = Namespace.get("p2", "www.acme2.org"); Element element = new DefaultElement("test", ns1); Attribute attribute = new DefaultAttribute("pre:foo", "bar", ns2); element.add(attribute); Element root = new DefaultElement("root", ns0); root.add(element); Document doc = new DefaultDocument(root); XPath xpath = new Dom4jXPath( "/*/*/namespace::node()" ); List results = xpath.selectNodes( doc ); assertEquals( 4, results.size() ); } public void testSyntaxException() throws JaxenException { String path = "/row/[some_node='val1']|[some_node='val2']"; try { new Dom4jXPath(path); fail("Allowed union of non-node-sets"); } catch (XPathSyntaxException success) { assertNotNull(success.getMessage()); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/DOMTests.java0000664000175000017500000000525310371471320022030 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import junit.framework.Test; import junit.framework.TestSuite; /** *

* Collect Jaxen's DOM tests. *

* * @author Elliotte Rusty Harold * @version 1.1b9 * */ public class DOMTests { public static Test suite() { TestSuite result = new TestSuite(); result.addTest(new TestSuite(DOMNavigatorTest.class)); result.addTest(new TestSuite(DOMXPathTest.class)); result.addTest(new TestSuite(NamespaceTest.class)); result.addTest(new TestSuite(DOM3NamespaceTest.class)); return result; } }jaxen-1.1.6/src/java/test/org/jaxen/test/SubstringAfterTest.java0000664000175000017500000001405410371471320024167 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.BaseXPath; import org.jaxen.FunctionCallException; import org.jaxen.JaxenException; import org.jaxen.XPath; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; /** * @author Elliotte Rusty Harold * */ public class SubstringAfterTest extends TestCase { private Document doc; public void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.newDocument(); doc.appendChild(doc.createElement("root")); } public SubstringAfterTest(String name) { super(name); } public void testSubstringAfterNumber() throws JaxenException { XPath xpath = new DOMXPath( "substring-after(33, '3')" ); String result = (String) xpath.evaluate( doc ); assertEquals("3", result); } public void testSubstringAfterString() throws JaxenException { XPath xpath = new DOMXPath( "substring-after('test', 'es')" ); String result = (String) xpath.evaluate( doc ); assertEquals("t", result); } public void testSubstringAfterString4() throws JaxenException { XPath xpath = new DOMXPath( "substring-after('superlative', 'superlative')" ); String result = (String) xpath.evaluate( doc ); assertEquals("", result); } public void testSubstringAfterNumber2() throws JaxenException { XPath xpath = new DOMXPath( "substring-after(43, '0')" ); String result = (String) xpath.evaluate( doc ); assertEquals("", result); } public void testSubstringAfterString2() throws JaxenException { XPath xpath = new DOMXPath( "substring-after('1234567890', '1234567a')" ); String result = (String) xpath.evaluate( doc ); assertEquals("", result); } public void testSubstringAfterString3() throws JaxenException { XPath xpath = new DOMXPath( "substring-after('1234567890', '456')" ); String result = (String) xpath.evaluate( doc ); assertEquals("7890", result); } public void testEmptyStringSubstringAfterNonEmptyString() throws JaxenException { XPath xpath = new DOMXPath( "substring-after('', 'a')" ); String result = (String) xpath.evaluate( doc ); assertEquals("", result); } public void testEmptyStringBeforeEmptyString() throws JaxenException { XPath xpath = new DOMXPath( "substring-after('', '')" ); String result = (String) xpath.evaluate( doc ); assertEquals("", result); } public void testSubstringAfterEmptyString() throws JaxenException { XPath xpath = new DOMXPath( "substring-after('a', '')" ); String result = (String) xpath.evaluate( doc ); assertEquals("a", result); } public void testSubstringAfterFunctionRequiresAtLeastTwoArguments() throws JaxenException { BaseXPath xpath = new DOMXPath("substring-after('a')"); try { xpath.selectNodes(doc); fail("Allowed substring-after function with one argument"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } public void testSubstringAfterFunctionRequiresAtMostTwoArguments() throws JaxenException { BaseXPath xpath = new DOMXPath("substring-after('a', 'a', 'a')"); try { xpath.selectNodes(doc); fail("Allowed substring-after function with three arguments"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/IterableAxisTest.java0000664000175000017500000000571410513264270023606 0ustar ebourgebourg/* * $Header$ * $Revision: 1213 $ * $Date: 2006-10-11 23:57:12 +0200 (Wed, 11 Oct 2006) $ * * ==================================================================== * * Copyright 2006 Elliotte Rusty Harold * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: IterableAxisTest.java 1213 2006-10-11 21:57:12Z elharo $ */ package org.jaxen.test; import junit.framework.TestCase; import org.jaxen.JaxenException; import org.jaxen.expr.iter.IterableAxis; import org.jaxen.expr.iter.IterableSelfAxis; import org.xml.sax.SAXException; /** * @author Elliotte Rusty Harold * @version 1.1b12 * */ public class IterableAxisTest extends TestCase { public void testIterableSelfNamedAxis() throws JaxenException, SAXException { IterableAxis axis = new IterableSelfAxis(0); try { axis.namedAccessIterator(null, null, "name", "pre", "http://www.example.org/"); fail("should not support operation"); } catch (UnsupportedOperationException ex) { assertEquals("Named access unsupported", ex.getMessage()); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/DOMNavigatorTest.java0000664000175000017500000001301110371471320023507 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.jaxen.Navigator; import org.jaxen.dom.DocumentNavigator; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; public class DOMNavigatorTest extends XPathTestBase { private DocumentBuilder builder; public DOMNavigatorTest(String name) { super( name ); } public Navigator getNavigator() { return new DocumentNavigator(); } protected void setUp() throws Exception { super.setUp(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); builder = factory.newDocumentBuilder(); } public Object getDocument(String url) throws Exception { return builder.parse( url ); } public void testGetAttributeQNameOnElement() { Navigator nav = getNavigator(); Document doc = builder.newDocument(); Element a = doc.createElement("a"); String qname = nav.getAttributeQName(a); assertNull(qname); } public void testGetElementQNameOnAttr() { Navigator nav = getNavigator(); Document doc = builder.newDocument(); Attr a = doc.createAttribute("a"); String qname = nav.getElementQName(a); assertNull(qname); } public void testGetAttributeLocalNameOnElement() { Navigator nav = getNavigator(); Document doc = builder.newDocument(); Element a = doc.createElementNS("http://www.ex.com", "pre:a"); String name = nav.getAttributeName(a); assertNull(name); } public void testGetElementLocalNameOnAttr() { Navigator nav = getNavigator(); Document doc = builder.newDocument(); Attr a = doc.createAttributeNS("http://www.ex.com", "a"); String name = nav.getElementName(a); assertNull(name); } public void testGetAttributeNamespaceURIOnElement() { Navigator nav = getNavigator(); Document doc = builder.newDocument(); Element a = doc.createElementNS("http://www.example.org/", "a"); String qname = nav.getAttributeNamespaceUri(a); assertNull(qname); } public void testGetElementNamespaceURIOnAttr() { Navigator nav = getNavigator(); Document doc = builder.newDocument(); Attr a = doc.createAttributeNS("http://www.element.org/", "a"); String qname = nav.getElementNamespaceUri(a); assertNull(qname); } public void testGetTargetOfNonPI() { Navigator nav = getNavigator(); Document doc = builder.newDocument(); Attr a = doc.createAttributeNS("http://www.element.org/", "a"); try { nav.getProcessingInstructionTarget(a); fail("got target of non processing instruction"); } catch (ClassCastException ex) { assertNotNull(ex.getMessage()); } } public void testGetDataOfNonPI() { Navigator nav = getNavigator(); Document doc = builder.newDocument(); Attr a = doc.createAttributeNS("http://www.element.org/", "a"); try { nav.getProcessingInstructionData(a); fail("got data of non processing instruction"); } catch (ClassCastException ex) { assertNotNull(ex.getMessage()); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/FollowingSiblingAxisIteratorTest.java0000664000175000017500000000717710371471320027044 0ustar ebourgebourg/* $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.util.Iterator; import java.util.NoSuchElementException; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.jaxen.UnsupportedAxisException; import org.jaxen.util.FollowingSiblingAxisIterator; import org.w3c.dom.Document; import junit.framework.TestCase; public class FollowingSiblingAxisIteratorTest extends TestCase { private Iterator iterator; public FollowingSiblingAxisIteratorTest(String name) { super(name); } protected void setUp() throws ParserConfigurationException, UnsupportedAxisException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); Document doc = factory.newDocumentBuilder().newDocument(); doc.appendChild(doc.createElement("root")); iterator = new FollowingSiblingAxisIterator(doc, new org.jaxen.dom.DocumentNavigator()); } public void testNoInfiniteLoops() { try { iterator.next(); fail("Iterated too far"); } catch (NoSuchElementException ex) { pass(); } } private void pass() { // Just to make checkstyle and the like happy } public void testRemove() { try { iterator.remove(); fail("Removed from descendant axis iterator"); } catch (UnsupportedOperationException ex) { pass(); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/JDOMPerformance.java0000664000175000017500000000476010371471320023303 0ustar ebourgebourg/* $Id$ Copyright 2003 The Werken Company. All Rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Jaxen Project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.jaxen.test; import java.net.URL; import org.jaxen.jdom.JDOMXPath; import org.jdom.Document; import org.jdom.Element; import org.jdom.input.SAXBuilder; class JDOMPerformance { public static void main(String[] args) { try { URL u = new URL("http://www.ibiblio.org/xml/examples/shakespeare/much_ado.xml"); Document doc = new SAXBuilder().build(u); JDOMXPath xpath = new JDOMXPath("PLAY/ACT/SCENE/SPEECH/SPEAKER"); long start = System.currentTimeMillis(); int count = 0; for (int i = 0; i < 1000; i++) { Element speaker = (Element) xpath.selectSingleNode(doc); count += (speaker == null ? 0 : 1); } long end = System.currentTimeMillis(); System.out.println((end - start)); System.out.println(count); } catch (Exception ex) { ex.printStackTrace(); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/SingletonListTest.java0000664000175000017500000000504410371471320024022 0ustar ebourgebourg/* $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.util.List; import org.jaxen.util.SingletonList; import junit.framework.TestCase; public class SingletonListTest extends TestCase { public void testIndexOutOfBoundsException() { List list = new SingletonList(new Object()); try { list.get(1); fail("Got element 1"); } catch (IndexOutOfBoundsException ex) { assertNotNull(ex.getMessage()); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/XOMPerformance.java0000664000175000017500000000465510371471320023220 0ustar ebourgebourg/* $Id$ Copyright 2003 The Werken Company. All Rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Jaxen Project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.jaxen.test; import org.jaxen.xom.XOMXPath; import nu.xom.Document; import nu.xom.Element; import nu.xom.Builder; class XOMPerformance { public static void main(String[] args) { try { Document doc = new Builder().build("http://www.ibiblio.org/xml/examples/shakespeare/much_ado.xml"); XOMXPath xpath = new XOMXPath("PLAY/ACT/SCENE/SPEECH/SPEAKER"); long start = System.currentTimeMillis(); int count = 0; for (int i = 0; i < 1000; i++) { Element speaker = (Element) xpath.selectSingleNode(doc); count += (speaker == null ? 0 : 1); } long end = System.currentTimeMillis(); System.out.println((end - start)); System.out.println(count); } catch (Exception ex) { ex.printStackTrace(); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/ModTest.java0000664000175000017500000000612210546775031021753 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.jaxen.JaxenException; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; import org.w3c.dom.Element; import junit.framework.TestCase; /** *

* Test for the remainder function. *

* * @author Elliotte Rusty Harold * @version 1.1.1 * */ public class ModTest extends TestCase { public void testModofNonIntegers() throws JaxenException, ParserConfigurationException { DOMXPath xpath = new DOMXPath("5.5 mod 2.5"); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); Document doc = factory.newDocumentBuilder().newDocument(); Element root = doc.createElement("root"); doc.appendChild(root); Double result = (Double) xpath.evaluate(doc); assertEquals(0.5, result.doubleValue(), 0.000001); } } jaxen-1.1.6/src/java/test/org/jaxen/test/JDOMTests.java0000664000175000017500000000506110371471320022137 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import junit.framework.Test; import junit.framework.TestSuite; /** *

* Collect Jaxen's JDOM tests. *

* * @author Elliotte Rusty Harold * @version 1.1b9 * */ public class JDOMTests { public static Test suite() { TestSuite result = new TestSuite(); result.addTest(new TestSuite(JDOMNavigatorTest.class)); result.addTest(new TestSuite(JDOMXPathTest.class)); return result; } }jaxen-1.1.6/src/java/test/org/jaxen/test/Person.java0000664000175000017500000000125310317451242021631 0ustar ebourgebourgpackage org.jaxen.test; import java.util.Set; import java.util.HashSet; public class Person { private String name; private int age; private Set brothers; Person(String name, int age) { this.name = name; this.age = age; this.brothers = new HashSet(); } public String getName() { return this.name; } public int getAge() { return this.age; } void addBrother(Person brother) { this.brothers.add( brother ); } public Set getBrothers() { return this.brothers; } public String toString() { return "[Person: " + this.name + "]"; } } jaxen-1.1.6/src/java/test/org/jaxen/test/SubstringBeforeTest.java0000664000175000017500000001407310371471320024331 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.BaseXPath; import org.jaxen.FunctionCallException; import org.jaxen.JaxenException; import org.jaxen.XPath; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; /** * @author Elliotte Rusty Harold * */ public class SubstringBeforeTest extends TestCase { private Document doc; public void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.newDocument(); doc.appendChild(doc.createElement("root")); } public SubstringBeforeTest(String name) { super(name); } public void testSubstringBeforeNumber() throws JaxenException { XPath xpath = new DOMXPath( "substring-before(33, '3')" ); String result = (String) xpath.evaluate( doc ); assertEquals("", result); } public void testSubstringBeforeString() throws JaxenException { XPath xpath = new DOMXPath( "substring-before('test', 'es')" ); String result = (String) xpath.evaluate( doc ); assertEquals("t", result); } public void testContainsString3() throws JaxenException { XPath xpath = new DOMXPath( "substring-before('superlative', 'superlative')" ); String result = (String) xpath.evaluate( doc ); assertEquals("", result); } public void testSubstringBeforeNumber2() throws JaxenException { XPath xpath = new DOMXPath( "substring-before(43, '0')" ); String result = (String) xpath.evaluate( doc ); assertEquals("", result); } public void testSubstringBeforeString2() throws JaxenException { XPath xpath = new DOMXPath( "substring-before('1234567890', '1234567a')" ); String result = (String) xpath.evaluate( doc ); assertEquals("", result); } public void testSubstringBeforeString3() throws JaxenException { XPath xpath = new DOMXPath( "substring-before('1234567890', '456')" ); String result = (String) xpath.evaluate( doc ); assertEquals("123", result); } public void testEmptyStringSubstringBeforeNonEmptyString() throws JaxenException { XPath xpath = new DOMXPath( "substring-before('', 'a')" ); String result = (String) xpath.evaluate( doc ); assertEquals("", result); } public void testEmptyStringBeforeEmptyString() throws JaxenException { XPath xpath = new DOMXPath( "substring-before('', '')" ); String result = (String) xpath.evaluate( doc ); assertEquals("", result); } public void testSubstringBeforeEmptyString() throws JaxenException { XPath xpath = new DOMXPath( "substring-before('a', '')" ); String result = (String) xpath.evaluate( doc ); assertEquals("", result); } public void testSubstringBeforeFunctionRequiresAtLeastTwoArguments() throws JaxenException { BaseXPath xpath = new DOMXPath("substring-before('a')"); try { xpath.selectNodes(doc); fail("Allowed substring-before function with one argument"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } public void testSubstringBeforeFunctionRequiresAtMostTwoArguments() throws JaxenException { BaseXPath xpath = new DOMXPath("substring-before('a', 'a', 'a')"); try { xpath.selectNodes(doc); fail("Allowed substring-before function with three arguments"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/EqualsTest.java0000664000175000017500000001221510371471320022454 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.io.IOException; import java.io.StringReader; import java.util.List; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.jaxen.JaxenException; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import junit.framework.TestCase; /** *

* Test for function context. *

* * @author Elliotte Rusty Harold * @version 1.1b9 * */ public class EqualsTest extends TestCase { public void testEqualityAgainstNonExistentNodes() throws JaxenException, ParserConfigurationException { DOMXPath xpath = new DOMXPath("/a/b[c = ../d]"); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); Document doc = factory.newDocumentBuilder().newDocument(); Element root = doc.createElement("a"); doc.appendChild(root); Element b = doc.createElement("b"); root.appendChild(b); Element c = doc.createElement("c"); b.appendChild(c); List result = (List) xpath.evaluate(doc); assertEquals(0, result.size()); } public void testOlander() throws JaxenException, SAXException, IOException, ParserConfigurationException { DOMXPath xpath = new DOMXPath("//BlockStatement//IfStatement[./Statement = ./ancestor::BlockStatement/following-sibling::BlockStatement//IfStatement/Statement]"); String data = "booleanamethodBbmethodB"; StringReader reader = new StringReader(data); InputSource in = new InputSource(reader); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); Document doc = factory.newDocumentBuilder().parse(in); List result = (List) xpath.evaluate(doc); assertEquals(1, result.size()); } } jaxen-1.1.6/src/java/test/org/jaxen/test/PositionTest.java0000664000175000017500000000653410371471320023035 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.FunctionCallException; import org.jaxen.JaxenException; import org.jaxen.XPath; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; /** * @author Elliotte Rusty Harold * */ public class PositionTest extends TestCase { private Document doc; public void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.newDocument(); doc.appendChild(doc.createElement("root")); } public PositionTest(String name) { super(name); } public void testPositionOfNumber() throws JaxenException { try { XPath xpath = new DOMXPath( "position(3)" ); xpath.selectNodes( doc ); fail("position() function took arguments"); } catch (FunctionCallException e) { assertEquals("position() does not take any arguments.", e.getMessage()); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/SAXPathExceptionTest.java0000664000175000017500000000606210371471320024354 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.io.PrintWriter; import java.io.StringWriter; import org.jaxen.saxpath.SAXPathException; import junit.framework.TestCase; /** * @author Elliotte Rusty Harold * */ public class SAXPathExceptionTest extends TestCase { public SAXPathExceptionTest(String name) { super(name); } public void testMessageIsNonNull() { SAXPathException ex = new SAXPathException("Hello"); assertEquals("Hello", ex.getMessage()); } public void testPrintStackTrace() { StringIndexOutOfBoundsException cause = new StringIndexOutOfBoundsException("1234"); SAXPathException ex = new SAXPathException(cause); StringWriter out = new StringWriter(); PrintWriter pw = new PrintWriter(out); ex.printStackTrace(pw); pw.close(); assertTrue(out.toString().indexOf("Caused by: java.lang.StringIndexOutOfBoundsException") > 0); assertTrue(out.toString().indexOf("1234") > 0); } } jaxen-1.1.6/src/java/test/org/jaxen/test/XPathTestBase.java0000664000175000017500000021277611270037506023062 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import junit.framework.TestCase; import org.jaxen.*; import org.jaxen.dom.DOMXPath; import org.jaxen.function.StringFunction; import org.jaxen.saxpath.helpers.XPathReaderFactory; import org.jaxen.pattern.Pattern; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public abstract class XPathTestBase extends TestCase { protected static String VAR_URI = "http://jaxen.org/test-harness/var"; protected static String TESTS_XML = "xml/test/tests.xml"; protected static boolean verbose = false; protected static boolean debug = false; private ContextSupport contextSupport; protected XPathTestBase(String name) { super(name); } protected void setUp() throws Exception { this.contextSupport = null; System.setProperty(XPathReaderFactory.DRIVER_PROPERTY, ""); log("-----------------------------"); } public void log(String text) { log(verbose, text); } private void log(boolean actualVerbose, String text) { if (actualVerbose) System.out.println(text); } private void assertCountXPath(int expectedSize, Object context, String xpathStr) throws JaxenException { assertCountXPath2(expectedSize, context, xpathStr); } private Object assertCountXPath2(int expectedSize, Object context, String xpathStr) throws JaxenException { log(debug, " Select :: " + xpathStr); DOMXPath xpath = new DOMXPath(xpathStr); List results = xpath.selectNodes(getContext(context)); log(debug, " Expected Size :: " + expectedSize); log(debug, " Result Size :: " + results.size()); if (expectedSize != results.size()) { log(debug, " ## FAILED"); log(debug, " ## xpath: " + xpath + " = " + xpath.debug()); Iterator resultIter = results.iterator(); while (resultIter.hasNext()) { log(debug, " --> " + resultIter.next()); } } assertEquals(xpathStr, expectedSize, results.size()); assertExprGetTextIdempotent(xpath); if (expectedSize > 0) { return results.get(0); } return null; } private void assertInvalidXPath(Object context, String xpathStr) { try { log(debug, " Select :: " + xpathStr); DOMXPath xpath = new DOMXPath(xpathStr); List results = xpath.selectNodes(getContext(context)); log(debug, " Result Size :: " + results.size()); fail("An exception was expected."); } catch (JaxenException e) { log(debug, " Caught expected exception " + e.getMessage()); } } private void assertValueOfXPath(String expected, Object context, String xpathStr) throws JaxenException { DOMXPath xpath = new DOMXPath(xpathStr); Object node = xpath.evaluate(getContext(context)); String result = StringFunction.evaluate(node, getNavigator()); log(debug, " Select :: " + xpathStr); log(debug, " Expected :: " + expected); log(debug, " Result :: " + result); if (!expected.equals(result)) { log(debug, " ## FAILED"); log(debug, " ## xpath: " + xpath + " = " + xpath.debug()); } assertEquals(xpathStr, expected, result); assertExprGetTextIdempotent(xpath); } private void assertExprGetTextIdempotent(BaseXPath xpath) throws JaxenException { assertEquals(0, ExprComparator.EXPR_COMPARATOR.compare(xpath.getRootExpr(), new BaseXPath(xpath.getRootExpr().getText(), null).getRootExpr())); } private Context getContext(Object contextNode) { Context context = new Context(getContextSupport()); List list = new ArrayList(1); list.add(contextNode); context.setNodeSet(list); return context; } private ContextSupport getContextSupport() { if (this.contextSupport == null) { this.contextSupport = new ContextSupport(new SimpleNamespaceContext(), XPathFunctionContext.getInstance(), new SimpleVariableContext(), getNavigator()); } return this.contextSupport; } protected abstract Navigator getNavigator(); protected abstract Object getDocument(String url) throws Exception; public void testGetNodeType() throws FunctionCallException, UnsupportedAxisException { Navigator nav = getNavigator(); Object document = nav.getDocument("xml/testNamespaces.xml"); int count = 0; Iterator descendantOrSelfAxisIterator = nav.getDescendantOrSelfAxisIterator(document); while (descendantOrSelfAxisIterator.hasNext()) { Object node = descendantOrSelfAxisIterator.next(); Iterator namespaceAxisIterator = nav.getNamespaceAxisIterator(node); while (namespaceAxisIterator.hasNext()) { count++; assertEquals("Node type mismatch", Pattern.NAMESPACE_NODE, nav.getNodeType(namespaceAxisIterator.next())); } } assertEquals(25, count); } /** * test for jaxen-24 */ public void testJaxen24() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/jaxen24.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/body/div", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(1, context, "preceding::*[1]"); assertValueOfXPath("span", context, "local-name(preceding::*[1])"); } } /** * jaxen-58 */ public void testJaxen58() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/jaxen24.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(0, context, "//preceding::x"); assertCountXPath(0, context, "//following::x"); assertCountXPath(0, context, "/descendant::*/preceding::x"); assertCountXPath(0, context, "/descendant::node()/preceding::x"); } } /** * test for jaxen-3 */ public void testJaxen3() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/simple.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertValueOfXPath("abd", context, "string()"); } } public void testStringFunction1() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/simple.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/root", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertValueOfXPath("abd", context, "string()"); } } public void testStringFunction2() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/simple.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/root/a", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertValueOfXPath("a", context, "string()"); } } public void testStringFunction3() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/simple.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/root/c", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertValueOfXPath("d", context, "string()"); } } /** * test for jaxen-3 */ public void testJaxen3dupe() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/jaxen3.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(1, context, "/Configuration/hostname/attrlist/hostname[. = 'CE-A'] "); } } /** * parser test cases all of which should fail */ public void testForParserErrors() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/numbers.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); // repeated xpaths, jaxen-35 assertInvalidXPath(context, "/numbers numbers"); // invalid xpath, jaxen-34 assertInvalidXPath(context, "/a/b[c > d]efg"); // invalid xpath, jaxen-27 assertInvalidXPath(context, "/inv/child::"); // invalid xpath, jaxen-26 assertInvalidXPath(context, "/invoice/@test[abcd"); assertInvalidXPath(context, "/invoice/@test[abcd > x"); // unterminated string assertInvalidXPath(context, "string-length('a"); // various edge cases where code threw no exception assertInvalidXPath(context, "/descendant::()"); assertInvalidXPath(context, "(1 + 1"); // no ! operator assertInvalidXPath(context, "!false()"); } } /** * test cases for the use of underscores in names */ public void testUnderscoresInNames() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/underscore.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(1, context, "/root/@a"); assertCountXPath(1, context, "/root/@_a"); assertCountXPath(1, context, "/root/b"); assertCountXPath(1, context, "/root/_b"); assertValueOfXPath("1", context, "/root/@a"); assertValueOfXPath("2", context, "/root/@_a"); assertValueOfXPath("1", context, "/root/b"); assertValueOfXPath("2", context, "/root/_b"); } } /** * test cases for the use of = with node-sets */ public void testNodesetEqualsString() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/web.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertValueOfXPath("true", context, "/web-app/servlet/servlet-name = 'file'"); assertValueOfXPath("true", context, "/web-app/servlet/servlet-name = 'snoop'"); } } public void testNodesetEqualsNumber() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/numbers.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertValueOfXPath("true", context, "/numbers/set/nr = '-3'"); assertValueOfXPath("true", context, "/numbers/set/nr = -3"); assertValueOfXPath("true", context, "/numbers/set/nr = 24"); assertValueOfXPath("true", context, "/numbers/set/nr/@value = '9999'"); assertValueOfXPath("true", context, "/numbers/set/nr/@value = 9999.0"); assertValueOfXPath("true", context, "/numbers/set/nr/@value = 66"); } } /** * test basic math... */ public void testIntegerArithmetic() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/numbers.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertValueOfXPath("true", context, "(8 * 2 + 1) = 17"); assertValueOfXPath("true", context, "(1 + 8 * 2) = 17"); assertValueOfXPath("true", context, "(7 - 3 + 1) = 5"); assertValueOfXPath("true", context, "(8 - 4 + 5 - 6) = 3"); /** left-assoc tests, comments show WRONG evaluation */ /** 3 - 2 - 1 != 2 */ assertValueOfXPath("0", context, "3 - 2 - 1"); /** 8 div 4 div 2 != 4 */ assertValueOfXPath("1", context, "8 div 4 div 2"); /** 3 mod 5 mod 7 != 1 */ assertValueOfXPath("3", context, "3 mod 7 mod 5"); /** 1=(2=2) is true */ assertValueOfXPath("false", context, "1 = 2 = 2"); /** 2!=(3!=1) => 2!=1 => true, (2!=3)!=1 => 1!=1 => false */ assertValueOfXPath("false", context, "2 != 3 != 1"); /** 3 > (2 > 1) is true */ assertValueOfXPath("false", context, "3 > 2 > 1"); /** 3 >= (2 >= 2) is true */ assertValueOfXPath("false", context, "3 >= 2 >= 2"); /** 1 < (2 < 3) is false */ assertValueOfXPath("true", context, "1 < 2 < 3"); /** 0 <= (2 <= 3) is true */ assertValueOfXPath("true", context, "2 <= 2 <= 3"); } } public void testFloatingPointArithmetic() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/numbers.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertValueOfXPath("true", context, "(8.5 * 2.0 + 1) = 18"); assertValueOfXPath("true", context, "(1.00 + 8.5 * 2) = 18.0"); assertValueOfXPath("true", context, "(7.1 - 7.1 + 1.5) = 1.5"); assertValueOfXPath("true", context, "(8.000 - 4.0 + 5 - 6.00) = 3"); assertValueOfXPath("0", context, "3.5 - 2.5 - 1.0"); assertValueOfXPath("1", context, "8.0 div 4.0 div 2.0"); assertValueOfXPath("3", context, "3.0 mod 7.0 mod 5.0"); assertValueOfXPath("false", context, "1.5 = 2.3 = 2.3"); assertValueOfXPath("false", context, "2.1 != 3.2 != 1.9"); assertValueOfXPath("false", context, "3.8 > 2.7 > 1.6"); assertValueOfXPath("false", context, "3.4 >= 2.5 >= 2.5"); assertValueOfXPath("true", context, "1.4 < 2.3 < 3.2"); assertValueOfXPath("true", context, "2.5 <= 2.5 <= 3.5"); } } /** * test cases for preceding axis with different node types */ public void testPrecedingSiblingAxis() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/pi2.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/a/c", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(1, context, "//processing-instruction()"); assertCountXPath(1, context, "preceding-sibling::*"); assertCountXPath(5, context, "preceding-sibling::node()"); assertCountXPath(1, context, "preceding-sibling::*[1]"); assertCountXPath(1, context, "preceding-sibling::processing-instruction()"); assertValueOfXPath("order-by=\"x\"", context, "preceding-sibling::processing-instruction()"); assertValueOfXPath("foo", context, "preceding-sibling::*[1]"); assertValueOfXPath("order-by=\"x\"", context, "preceding-sibling::node()[2]"); } } public void testVariableLookup() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/id.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); SimpleVariableContext varContext = new SimpleVariableContext(); varContext.setVariableValue(null, "foobar", "foobar"); varContext.setVariableValue(null, "foo", "foo"); getContextSupport().setVariableContext(varContext); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertValueOfXPath("foobar", context, "$foobar"); assertCountXPath(1, context, "/foo[@id=$foobar]"); assertCountXPath(0, context, "/foo[@id='$foobar']"); assertCountXPath(1, context, "/foo[concat($foo, 'bar')=@id]"); assertCountXPath(0, context, "CD_Library/artist[@name=$artist]"); } } public void testAttributeParent() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/id.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); /** attributes have a parent: their element */ assertCountXPath(1, context, "/foo/@id/parent::foo"); } } /** * attributes can also be used as context nodes */ public void testAttributeAsContext() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/id.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/foo/@id", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(1, context, "parent::foo"); } } public void testid53992() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/pi.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(3, context, "//processing-instruction()"); assertCountXPath(2, context, "//processing-instruction('cheese')"); Object result = assertCountXPath2(1, context, "//processing-instruction('toast')"); assertValueOfXPath("is tasty", result, "string()"); } } /** * test evaluate() extension function */ public void testid54032() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/evaluate.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(3, context, "evaluate('//jumps/*')"); assertCountXPath(1, context, "evaluate('//jumps/object/dog')"); assertCountXPath(0, context, "evaluate('//jumps/object')/evaluate"); assertCountXPath(1, context, "evaluate('//jumps/object')/dog"); assertCountXPath(1, context, "evaluate('//jumps/*')/dog"); assertCountXPath(1, context, "//metatest[ evaluate(@select) = . ]"); } } public void testid54082() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/numbers.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/numbers/set[1]", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(1, context, "*[-3 = .]"); assertValueOfXPath("true", context, "54 < *"); assertValueOfXPath("true", context, "55 <= *"); assertValueOfXPath("false", context, "69 < *"); assertValueOfXPath("true", context, "-2 > *"); assertValueOfXPath("true", context, "-3 >= *"); assertValueOfXPath("false", context, "-4 >= *"); } } /* TODO This context should work, but needs a fixed version of saxpath to parse the right-hand side of the greater-than expression. false false true true */ /** * test sibling axes */ public void testid54145() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/axis.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/root", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(0, context, "preceding-sibling::*"); } } public void testid54156() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/axis.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/root/a/a.3", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(2, context, "preceding::*"); } } public void testid54168() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/axis.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/root/a/a.3", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(2, context, "preceding-sibling::*"); } } public void testid54180() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/axis.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertValueOfXPath("a.2", context, "name(/root/a/a.3/preceding-sibling::*[1])"); assertValueOfXPath("a.1", context, "name(/root/a/a.3/preceding-sibling::*[2])"); } } public void testid54197() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/axis.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertValueOfXPath("a.4", context, "name(/root/a/a.3/following-sibling::*[1])"); assertValueOfXPath("a.5", context, "name(/root/a/a.3/following-sibling::*[2])"); } } public void testid54219() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/web.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertValueOfXPath("snoop", context, "/web-app/servlet[1]/servlet-name"); assertValueOfXPath("snoop", context, "/web-app/servlet[1]/servlet-name/text()"); assertValueOfXPath("file", context, "/web-app/servlet[2]/servlet-name"); assertValueOfXPath("file", context, "/web-app/servlet[2]/servlet-name/text()"); } } public void testid54249() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/web.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/web-app/servlet[1]", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertValueOfXPath("snoop", context, "servlet-name"); assertValueOfXPath("snoop", context, "servlet-name/text()"); } } public void testid54266() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/web.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/web-app/servlet[2]/servlet-name", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(3, context, "preceding::*"); } } public void testid54278() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/web.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/web-app/servlet[2]/servlet-name", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(13, context, "following::*"); } } /** * test name */ public void testid54298() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/web.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); Object result = assertCountXPath2(1, context, "*"); assertValueOfXPath("web-app", result, "name()"); /* NOTE that the child::node() tests only work if the XML document does not contain comments or processing instructions */ result = assertCountXPath2(1, context, "./*"); assertValueOfXPath("web-app", result, "name()"); result = assertCountXPath2(1, context, "child::*"); assertValueOfXPath("web-app", result, "name()"); result = assertCountXPath2(1, context, "/*"); assertValueOfXPath("web-app", result, "name()"); result = assertCountXPath2(1, context, "/child::node()"); assertValueOfXPath("web-app", result, "name(.)"); result = assertCountXPath2(1, context, "child::node()"); assertValueOfXPath("web-app", result, "name(.)"); // empty names assertValueOfXPath("", context, "name()"); assertValueOfXPath("", context, "name(.)"); assertValueOfXPath("", context, "name(parent::*)"); assertValueOfXPath("", context, "name(/)"); assertValueOfXPath("", context, "name(/.)"); assertValueOfXPath("", context, "name(/self::node())"); /** name of root elemet */ assertValueOfXPath("web-app", context, "name(node())"); assertValueOfXPath("web-app", context, "name(/node())"); assertValueOfXPath("web-app", context, "name(/*)"); assertValueOfXPath("web-app", context, "name(/child::*)"); assertValueOfXPath("web-app", context, "name(/child::node())"); assertValueOfXPath("web-app", context, "name(/child::node())"); assertValueOfXPath("web-app", context, "name(child::node())"); assertValueOfXPath("web-app", context, "name(./*)"); assertValueOfXPath("web-app", context, "name(*)"); } } public void testid54467() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/web.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/*", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); /** empty names */ assertValueOfXPath("", context, "name(..)"); assertValueOfXPath("", context, "name(parent::node())"); assertValueOfXPath("", context, "name(parent::*)"); /** name of root elemet */ assertValueOfXPath("web-app", context, "name()"); assertValueOfXPath("web-app", context, "name(.)"); assertValueOfXPath("web-app", context, "name(../*)"); assertValueOfXPath("web-app", context, "name(../child::node())"); } } /** * test predicates */ public void testid54522() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/nitf.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/nitf/head/docdata", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(1, context, "doc-id[@regsrc='FAKE' and @id-string='YYY']"); } } public void testid54534() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/nitf.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/nitf/head", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(1, context, "meta[@name='fake-cycle']"); assertCountXPath(1, context, "meta[@content='FAKE']"); assertCountXPath(8, context, "meta[@name and @content]"); assertCountXPath(1, context, "meta[@name='fake-cycle' and @content='FAKE']"); assertCountXPath(7, context, "meta[@name != 'fake-cycle']"); } } public void testid54570() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/nitf.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(1, context, "/nitf/head/meta[@name='fake-cycle']"); assertCountXPath(1, context, "/nitf/head/meta[@content='FAKE']"); assertCountXPath(8, context, "/nitf/head/meta[@name and @content]"); assertCountXPath(1, context, "/nitf/head/meta[@name='fake-cycle' and @content='FAKE']"); assertCountXPath(7, context, "/nitf/head/meta[@name != 'fake-cycle']"); } } public void testid54614() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/moreover.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(1, context, "/child::node()"); assertCountXPath(1, context, "/*"); assertCountXPath(20, context, "/*/article"); assertCountXPath(221, context, "//*"); assertCountXPath(20, context, "//*[local-name()='article']"); assertCountXPath(20, context, "//article"); assertCountXPath(20, context, "/*/*[@code]"); assertCountXPath(1, context, "/moreovernews/article[@code='13563275']"); DOMXPath xpath = new DOMXPath("/moreovernews/article[@code='13563275']"); List results = xpath.selectNodes(getContext(context)); Object result = results.get(0); assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url"); xpath = new DOMXPath("/*/article[@code='13563275']"); results = xpath.selectNodes(getContext(context)); result = results.get(0); assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url"); xpath = new DOMXPath("//article[@code='13563275']"); results = xpath.selectNodes(getContext(context)); result = results.get(0); assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url"); xpath = new DOMXPath("//*[@code='13563275']"); results = xpath.selectNodes(getContext(context)); result = results.get(0); assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url"); xpath = new DOMXPath("/child::node()/child::node()[@code='13563275']"); results = xpath.selectNodes(getContext(context)); result = results.get(0); assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url"); xpath = new DOMXPath("/*/*[@code='13563275']"); results = xpath.selectNodes(getContext(context)); result = results.get(0); assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url"); } } /** * test other node types */ public void testNodeTypes() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/contents.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(3, context, "processing-instruction()"); assertCountXPath(3, context, "/processing-instruction()"); assertCountXPath(1, context, "/comment()"); assertCountXPath(1, context, "comment()"); assertCountXPath(2, context, "/child::node()/comment()"); assertCountXPath(2, context, "/*/comment()"); assertCountXPath(3, context, "//comment()"); } } /** * test positioning */ public void testPositioning() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/fibo.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(9, context, "/*/fibonacci[position() < 10]"); assertValueOfXPath("196417", context, "sum(//fibonacci)"); assertValueOfXPath("325", context, "sum(//fibonacci/@index)"); assertValueOfXPath("1", context, "/*/fibonacci[2]"); assertValueOfXPath("75025", context, "/*/fibonacci[ count(/*/fibonacci) ]"); assertValueOfXPath("46368", context, "/*/fibonacci[ count(/*/fibonacci) - 1 ]"); } } public void testid54853() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/web.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(19, context, "descendant-or-self::*"); assertCountXPath(19, context, "descendant::*"); assertCountXPath(19, context, "/descendant::*"); assertCountXPath(19, context, "/descendant-or-self::*"); assertCountXPath(2, context, "/descendant::servlet"); assertCountXPath(2, context, "/descendant-or-self::servlet"); assertCountXPath(2, context, "descendant-or-self::servlet"); assertCountXPath(2, context, "descendant::servlet"); assertCountXPath(2, context, "/*/servlet"); assertValueOfXPath("2", context, "count(/*/servlet)"); assertCountXPath(2, context, "//servlet"); assertValueOfXPath("2", context, "count(//servlet)"); } } public void testid54932() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/web.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/web-app", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(2, context, "/descendant::servlet"); assertCountXPath(2, context, "/descendant-or-self::servlet"); assertCountXPath(2, context, "descendant-or-self::servlet"); assertCountXPath(2, context, "descendant::servlet"); } } public void testCountFunction() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/much_ado.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(5, context, "/descendant::ACT"); assertCountXPath(5, context, "descendant::ACT"); assertValueOfXPath("Much Ado about Nothing", context, "/PLAY/TITLE"); assertValueOfXPath("4", context, "2+2"); assertValueOfXPath("21", context, "5 * 4 + 1"); assertValueOfXPath("5", context, "count(descendant::ACT)"); assertValueOfXPath("35", context, "10 + count(descendant::ACT) * 5"); assertValueOfXPath("75", context, "(10 + count(descendant::ACT)) * 5"); } } public void testCountFunctionMore() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/much_ado.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/PLAY/ACT[2]/SCENE[1]", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(5, context, "/descendant::ACT"); assertCountXPath(5, context, "../../descendant::ACT"); assertCountXPath(141, context, "/PLAY/ACT[2]/SCENE[1]/descendant::SPEAKER"); assertCountXPath(141, context, "descendant::SPEAKER"); assertValueOfXPath("646", context, "count(descendant::*)+1"); assertValueOfXPath("142", context, "count(descendant::SPEAKER)+1"); assertValueOfXPath("2", context, "count(ancestor::*)"); assertValueOfXPath("1", context, "count(ancestor::PLAY)"); assertValueOfXPath("3", context, "count(ancestor-or-self::*)"); assertValueOfXPath("1", context, "count(ancestor-or-self::PLAY)"); assertValueOfXPath("6", context, "5+count(ancestor::*)-1"); } } public void testCorrectPredicateApplication() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/much_ado.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); // Test correct predicate application assertValueOfXPath("5", context, "count(/PLAY/ACT/SCENE[1])"); } } /** test axis node ordering */ public void testAxisNodeOrdering() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/web.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); // Reported as Jira issue JAXEN-24 assertCountXPath(1, context, "//servlet-mapping/preceding::*[1][name()='description']"); assertCountXPath(1, context, "/web-app/servlet//description/following::*[1][name()='servlet-mapping']"); assertCountXPath(1, context, "/web-app/servlet//description/following::*[2][name()='servlet-name']"); } } /** * test document function */ public void testDocumentFunction1() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/text.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); Object result = assertCountXPath2(1, context, "document('xml/web.xml')"); assertValueOfXPath("snoop", result, "/web-app/servlet[1]/servlet-name"); assertValueOfXPath("snoop", result, "/web-app/servlet[1]/servlet-name/text()"); assertValueOfXPath("snoop", context, "document('xml/web.xml')/web-app/servlet[1]/servlet-name"); } } /** * Test to check if the context changes when an extension function is used. * First test is an example, second is the actual test. */ public void testDocumentFunctionContextExample() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/text.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/foo/bar/cheese[1]", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertValueOfXPath("3foo3", context, "concat(./@id,'foo',@id)"); assertValueOfXPath("3snoop3", context, "concat(./@id,document('xml/web.xml')/web-app/servlet[1]/servlet-name,./@id)"); } } public void testDocumentFunctionActual() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/message.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertValueOfXPath("Pruefgebiete", context, "/message/body/data/items/item[name/text()='parentinfo']/value"); assertValueOfXPath("Pruefgebiete", context, "document('xml/message.xml')/message/body/data/items/item[name/text()='parentinfo']/value"); } } /** * test behavior of AbsoluteLocationPath */ public void testAbsoluteLocationPaths() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/simple.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/root/a", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertValueOfXPath("ab", context, "concat( ., /root/b )"); assertValueOfXPath("ba", context, "concat( ../b, . )"); assertValueOfXPath("ba", context, "concat( /root/b, . )"); assertValueOfXPath("db", context, "concat( /root/c/d, ../b )"); } } /** * test the translate() function */ public void testTranslateFunction() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/simple.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertValueOfXPath("", context, "translate( '', '', '' )"); assertValueOfXPath("abcd", context, "translate( 'abcd', '', '' )"); assertValueOfXPath("abcd", context, "translate( 'abcd', 'abcd', 'abcd' )"); assertValueOfXPath("abcd", context, "translate( 'abcd', 'dcba', 'dcba' )"); assertValueOfXPath("dcba", context, "translate( 'abcd', 'abcd', 'dcba' )"); assertValueOfXPath("ab", context, "translate( 'abcd', 'abcd', 'ab' )"); assertValueOfXPath("cd", context, "translate( 'abcd', 'cdab', 'cd' )"); assertValueOfXPath("xy", context, "translate( 'abcd', 'acbd', 'xy' )"); assertValueOfXPath("abcd", context, "translate( 'abcd', 'abcdb', 'abcdb' )"); assertValueOfXPath("abcd", context, "translate( 'abcd', 'abcd', 'abcdb' )"); } } public void testSubstringFunction() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/simple.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertValueOfXPath("234", context, "substring('12345', 1.5, 2.6)"); assertValueOfXPath("12", context, "substring('12345', 0, 3)"); assertValueOfXPath("", context, "substring('12345', 0 div 0, 3)"); assertValueOfXPath("", context, "substring('12345', 1, 0 div 0)"); assertValueOfXPath("12345", context, "substring('12345', -42, 1 div 0)"); assertValueOfXPath("", context, "substring('12345', -1 div 0, 1 div 0)"); assertValueOfXPath("345", context, "substring('12345', 3)"); assertValueOfXPath("12345", context, "substring('12345',1,15)"); } } /** * Some tests for the normalize-space() function */ public void testNormalizeSpaceFunction() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/simple.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertValueOfXPath("abc", context, "normalize-space(' abc ')"); assertValueOfXPath("a b c", context, "normalize-space(' a b c ')"); assertValueOfXPath("a b c", context, "normalize-space(' a \n b \n c')"); // Next test case addresses issue JAXEN-22 assertValueOfXPath("", context, "normalize-space(' ')"); // Next test case addresses issue JAXEN-29 assertValueOfXPath("", context, "normalize-space('')"); } } /** * test cases for String extension functions */ public void testStringExtensionFunctions() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/web.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/web-app/servlet[1]", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertValueOfXPath("SNOOPSERVLET", context, "upper-case( servlet-class )"); assertValueOfXPath("snoopservlet", context, "lower-case( servlet-class )"); assertValueOfXPath("SNOOPSERVLET", context, "upper-case( servlet-class, 'fr' )"); assertValueOfXPath("SNOOPSERVLET", context, "upper-case( servlet-class, 'fr-CA' )"); assertValueOfXPath("SNOOPSERVLET", context, "upper-case( servlet-class, 'es-ES-Traditional_WIN' )"); assertValueOfXPath("true", context, "ends-with( servlet-class, 'Servlet' )"); assertValueOfXPath("false", context, "ends-with( servlet-class, 'S' )"); } } /** * test cases for the lang() function */ public void testLangFunction() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/lang.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(0, context, "/e1/e2[lang('hr')]"); assertCountXPath(1, context, "/e1/e2/e3[lang('en')]"); assertCountXPath(1, context, "/e1/e2/e3[lang('en-US')]"); assertCountXPath(0, context, "/e1/e2/e3[lang('en-GB')]"); assertCountXPath(2, context, "/e1/e2/e3[lang('hu')]"); assertCountXPath(0, context, "/e1/e2/e3[lang('hu-HU')]"); assertCountXPath(1, context, "/e1/e2/e3[lang('es')]"); assertCountXPath(0, context, "/e1/e2/e3[lang('es-BR')]"); } } /** * test namespace */ public void testNamespacesAgain() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/namespaces.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); SimpleNamespaceContext nsContext = new SimpleNamespaceContext(); nsContext.addNamespace("alias", "http://fooNamespace/"); nsContext.addNamespace("bar", "http://barNamespace/"); nsContext.addNamespace("voo", "http://fooNamespace/"); nsContext.addNamespace("foo", "http://fooNamespace/"); getContextSupport().setNamespaceContext(nsContext); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(1, context, "/*"); assertCountXPath(1, context, "/foo:a"); assertCountXPath(1, context, "/foo:a/b"); assertCountXPath(1, context, "/voo:a/b/c"); assertCountXPath(1, context, "/voo:a/bar:f"); assertCountXPath(1, context, "/*[namespace-uri()='http://fooNamespace/' and local-name()='a']"); assertCountXPath(1, context, "/*[local-name()='a' and namespace-uri()='http://fooNamespace/']/*[local-name()='x' and namespace-uri()='http://fooNamespace/']"); assertCountXPath(1, context, "/*[local-name()='a' and namespace-uri()='http://fooNamespace/']/*[local-name()='x' and namespace-uri()='http://fooNamespace/']/*[local-name()='y' and namespace-uri()='http://fooNamespace/']"); } } /** * the prefix here and in the document have no relation; it's their * namespace-uri binding that counts */ public void testPrefixDoesntMatter() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/namespaces.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); SimpleNamespaceContext nsContext = new SimpleNamespaceContext(); nsContext.addNamespace("foo", "http://somethingElse/"); getContextSupport().setNamespaceContext(nsContext); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(0, context, "/foo:a/b/c"); } } /** Jaxen-67, affects Jelly and Maven */ public void testCDATASectionsAreIncludedInTextNodes() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/cdata.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextPath = new BaseXPath("/p/text()", nav); log("Initial Context :: " + contextPath); List list = contextPath.selectNodes(document); // Depending on the object model, there can be anywhere from // 1 to 3 nodes returned here. StringBuffer buffer = new StringBuffer(10); Iterator iterator = list.iterator(); while (iterator.hasNext()) { buffer.append(StringFunction.evaluate(iterator.next(), nav)); } assertEquals("awhateverb", buffer.toString()); } public void testNamespaces() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/namespaces.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); SimpleNamespaceContext nsContext = new SimpleNamespaceContext(); nsContext.addNamespace("alias", "http://fooNamespace/"); nsContext.addNamespace("bar", "http://barNamespace/"); nsContext.addNamespace("foo", "http://fooNamespace/"); getContextSupport().setNamespaceContext(nsContext); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertValueOfXPath("Hello", context, "/foo:a/b/c"); assertValueOfXPath("Hey", context, "/foo:a/foo:d/foo:e"); assertValueOfXPath("Hey3", context, "/foo:a/alias:x/alias:y"); assertValueOfXPath("Hey3", context, "/foo:a/foo:x/foo:y"); assertValueOfXPath("Hey3", context, "/*[local-name()='a' and namespace-uri()='http://fooNamespace/']/*[local-name()='x' and namespace-uri()='http://fooNamespace/']/*[local-name()='y' and namespace-uri()='http://fooNamespace/']"); } } public void testNoNamespace() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/defaultNamespace.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); // NOTE: /a/b/c selects elements in no namespace only! assertCountXPath(0, context, "/a/b/c"); /* The following test uses an unbound prefix 'x' and should throw an exception. Addresses issue JAXEN-18. Turns out this isn't really tested as the test didn't fail when the exception wasn't thrown. */ } } public void testNamespaceResolution() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/defaultNamespace.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); SimpleNamespaceContext nsContext = new SimpleNamespaceContext(); nsContext.addNamespace("dummy", "http://dummyNamespace/"); getContextSupport().setNamespaceContext(nsContext); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(1, context, "/dummy:a/dummy:b/dummy:c"); } } public void testTextNodes() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/text.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(3, context, "/foo/bar/text()"); assertValueOfXPath("baz", context, "normalize-space(/foo/bar/text())"); } } public void testNamespaceNodeCounts1() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/testNamespaces.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); // the root is not an element, so no namespaces assertCountXPath(0, context, "namespace::*"); assertCountXPath(0, context, "/namespace::*"); // must count the default xml: prefix as well assertCountXPath(3, context, "/Template/Application1/namespace::*"); assertCountXPath(3, context, "/Template/Application2/namespace::*"); // every element has separate copies assertCountXPath(25, context, "//namespace::*"); } } public void testNamespaceNodeCounts() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/testNamespaces.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/Template/Application1", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); // must count the default xml: prefix as well assertCountXPath(3, context, "namespace::*"); assertCountXPath(0, context, "/namespace::*"); assertCountXPath(3, context, "/Template/Application1/namespace::*"); assertCountXPath(3, context, "/Template/Application2/namespace::*"); assertCountXPath(25, context, "//namespace::*"); assertCountXPath(8, context, "//namespace::xplt"); /* the name test literally matches the prefix as given in the document, and does not use the URI */ assertCountXPath(0, context, "//namespace::somethingelse"); } } public void testNamespaceNodesHaveParent() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/testNamespaces.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); // namespace nodes have their element as their parent assertCountXPath(1, context, "/Template/namespace::xml/parent::Template"); } } /** * namespace nodes can also be used as context nodes */ public void testNamespaceNodeAsContext() throws JaxenException { Navigator nav = getNavigator(); String url = "xml/testNamespaces.xml"; log("Document [" + url + "]"); Object document = nav.getDocument(url); XPath contextpath = new BaseXPath("/Template/namespace::xml", nav); log("Initial Context :: " + contextpath); List list = contextpath.selectNodes(document); Iterator iter = list.iterator(); while (iter.hasNext()) { Object context = iter.next(); assertCountXPath(1, context, "parent::Template"); } } }jaxen-1.1.6/src/java/test/org/jaxen/test/BooleanTest.java0000664000175000017500000001570710371471320022612 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.util.List; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.BaseXPath; import org.jaxen.FunctionCallException; import org.jaxen.JaxenException; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; /** * @author Elliotte Rusty Harold * */ public class BooleanTest extends TestCase { private Document doc; public void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.newDocument(); } public BooleanTest(String name) { super(name); } // test case for JAXEN-55 public void testNonEmptyNodeSetsAreTrue() throws JaxenException { BaseXPath xpath = new DOMXPath("boolean(//x)"); org.w3c.dom.Element a = doc.createElementNS("", "a"); org.w3c.dom.Element b = doc.createElementNS("", "b"); doc.appendChild(a); a.appendChild(b); org.w3c.dom.Element x2 = doc.createElementNS("", "x"); org.w3c.dom.Element x3 = doc.createElementNS("", "x"); org.w3c.dom.Element x4 = doc.createElementNS("", "x"); a.appendChild(x4); b.appendChild(x2); b.appendChild(x3); x2.appendChild(doc.createTextNode("false")); x3.appendChild(doc.createTextNode("false")); x4.appendChild(doc.createTextNode("false")); List result = xpath.selectNodes(doc); assertEquals(1, result.size()); assertEquals(Boolean.TRUE, result.get(0)); } public void testEmptyNodeSetsAreFalse() throws JaxenException { BaseXPath xpath = new DOMXPath("boolean(//y)"); org.w3c.dom.Element a = doc.createElementNS("", "a"); org.w3c.dom.Element b = doc.createElementNS("", "b"); doc.appendChild(a); a.appendChild(b); org.w3c.dom.Element x2 = doc.createElementNS("", "x"); org.w3c.dom.Element x3 = doc.createElementNS("", "x"); org.w3c.dom.Element x4 = doc.createElementNS("", "x"); a.appendChild(x4); b.appendChild(x2); b.appendChild(x3); x2.appendChild(doc.createTextNode("false")); x3.appendChild(doc.createTextNode("false")); x4.appendChild(doc.createTextNode("false")); List result = xpath.selectNodes(doc); assertEquals(1, result.size()); assertEquals(Boolean.FALSE, result.get(0)); } public void testZeroIsFalse() throws JaxenException { BaseXPath xpath = new DOMXPath("boolean(0)"); org.w3c.dom.Element a = doc.createElementNS("", "a"); List result = xpath.selectNodes(a); assertEquals(1, result.size()); assertEquals(Boolean.FALSE, result.get(0)); } public void testEmptyStringIsFalse() throws JaxenException { BaseXPath xpath = new DOMXPath("boolean('')"); org.w3c.dom.Element a = doc.createElementNS("", "a"); List result = xpath.selectNodes(a); assertEquals(1, result.size()); assertEquals(Boolean.FALSE, result.get(0)); } public void testNaNIsFalse() throws JaxenException { BaseXPath xpath = new DOMXPath("boolean(0 div 0)"); Object result = xpath.evaluate(null); assertEquals(Boolean.FALSE, result); } public void testNonEmptyStringIsTrue() throws JaxenException { BaseXPath xpath = new DOMXPath("boolean('false')"); org.w3c.dom.Element a = doc.createElementNS("", "a"); List result = xpath.selectNodes(a); assertEquals(1, result.size()); assertEquals(Boolean.TRUE, result.get(0)); } public void testBooleanFunctionRequiresOneArgument() throws JaxenException { BaseXPath xpath = new DOMXPath("boolean()"); org.w3c.dom.Element a = doc.createElementNS("", "a"); try { xpath.selectNodes(a); fail("Allowed boolean function with no arguments"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } public void testBooleanFunctionRequiresExactlyOneArgument() throws JaxenException { BaseXPath xpath = new DOMXPath("boolean('', '')"); org.w3c.dom.Element a = doc.createElementNS("", "a"); try { xpath.selectNodes(a); fail("Allowed boolean function with two arguments"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/ContainsTest.java0000664000175000017500000001336410371471320023006 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.BaseXPath; import org.jaxen.FunctionCallException; import org.jaxen.JaxenException; import org.jaxen.XPath; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; /** * @author Elliotte Rusty Harold * */ public class ContainsTest extends TestCase { private Document doc; public void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.newDocument(); doc.appendChild(doc.createElement("root")); } public ContainsTest(String name) { super(name); } public void testContainsNumber() throws JaxenException { XPath xpath = new DOMXPath( "contains(33, '3')" ); Boolean result = (Boolean) xpath.evaluate( doc ); assertEquals(Boolean.TRUE, result); } public void testContainsString() throws JaxenException { XPath xpath = new DOMXPath( "contains('test', 'es')" ); Boolean result = (Boolean) xpath.evaluate( doc ); assertEquals(Boolean.TRUE, result); } public void testContainsString3() throws JaxenException { XPath xpath = new DOMXPath( "contains('superlative', 'superlative')" ); Boolean result = (Boolean) xpath.evaluate( doc ); assertEquals(Boolean.TRUE, result); } public void testContainsNumber2() throws JaxenException { XPath xpath = new DOMXPath( "contains(43, '0')" ); Boolean result = (Boolean) xpath.evaluate( doc ); assertEquals(Boolean.FALSE, result); } public void testContainsString2() throws JaxenException { XPath xpath = new DOMXPath( "contains('1234567890', '1234567a')" ); Boolean result = (Boolean) xpath.evaluate( doc ); assertEquals(Boolean.FALSE, result); } public void testEmptyStringContainsNonEmptyString() throws JaxenException { XPath xpath = new DOMXPath( "contains('', 'a')" ); Boolean result = (Boolean) xpath.evaluate( doc ); assertEquals(Boolean.FALSE, result); } public void testEmptyStringContainsEmptyString() throws JaxenException { XPath xpath = new DOMXPath( "contains('', '')" ); Boolean result = (Boolean) xpath.evaluate( doc ); assertEquals(Boolean.TRUE, result); } public void testContainsEmptyString() throws JaxenException { XPath xpath = new DOMXPath( "contains('a', '')" ); Boolean result = (Boolean) xpath.evaluate( doc ); assertEquals(Boolean.TRUE, result); } public void testContainsFunctionRequiresAtLeastTwoArguments() throws JaxenException { BaseXPath xpath = new DOMXPath("contains('a')"); try { xpath.selectNodes(doc); fail("Allowed contains function with one argument"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } public void testContainsFunctionRequiresAtMostTwoArguments() throws JaxenException { BaseXPath xpath = new DOMXPath("contains('a', 'a', 'a')"); try { xpath.selectNodes(doc); fail("Allowed contains function with three arguments"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/JDOMNavigatorTest.java0000664000175000017500000000634410504043735023637 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.util.List; import org.jaxen.JaxenException; import org.jaxen.Navigator; import org.jaxen.XPath; import org.jaxen.jdom.DocumentNavigator; import org.jaxen.jdom.JDOMXPath; import org.jdom.Document; import org.jdom.Element; import org.jdom.Namespace; import org.jdom.input.SAXBuilder; public class JDOMNavigatorTest extends XPathTestBase { private SAXBuilder builder = new SAXBuilder(); public JDOMNavigatorTest(String name) { super( name ); } public Navigator getNavigator() { return new DocumentNavigator(); } public Object getDocument(String url) throws Exception { return this.builder.build( url ); } public void testNullNamespace() throws JaxenException { Namespace my = Namespace.getNamespace("foo", "http://mynamespace.org/"); Document doc = new Document(); Element root = new Element("root", my); doc.setRootElement(root); XPath nullNamespacePath = new JDOMXPath("/root"); List selectedNodes = nullNamespacePath.selectNodes(doc); assertEquals(0, selectedNodes.size()); } } jaxen-1.1.6/src/java/test/org/jaxen/test/CountTest.java0000664000175000017500000001107010371471320022310 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.io.IOException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.BaseXPath; import org.jaxen.FunctionCallException; import org.jaxen.JaxenException; import org.jaxen.XPath; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; import org.xml.sax.SAXException; /** * @author Elliotte Rusty Harold * */ public class CountTest extends TestCase { private Document doc; public void setUp() throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.parse( "xml/basic.xml" ); } public CountTest(String name) { super(name); } public void testCount3() { try { XPath xpath = new DOMXPath( "count(3)" ); xpath.selectNodes( doc ); fail("Allowed count of number"); } catch (FunctionCallException e) { assertEquals("count() function can only be used for node-sets", e.getMessage()); } catch (Exception e) { e.printStackTrace(); fail( e.getMessage() ); } } public void testCountFunctionRequiresAtLeastOneArgument() throws JaxenException { BaseXPath xpath = new DOMXPath("count()"); try { xpath.selectNodes(doc); fail("Allowed count function with no arguments"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } public void testCountFunctionRequiresAtMostOneArgument() throws JaxenException { BaseXPath xpath = new DOMXPath("count(/*, /@*)"); try { xpath.selectNodes(doc); fail("Allowed count function with two arguments"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } public void testCountRootElement() throws JaxenException { BaseXPath xpath = new DOMXPath("count(/*)"); Double result = (Double) xpath.evaluate(doc); assertEquals(1.0, result.doubleValue(), 0.00001); } } jaxen-1.1.6/src/java/test/org/jaxen/test/NamespaceURITest.java0000664000175000017500000001477710456426755023535 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.io.IOException; import java.util.List; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.FunctionCallException; import org.jaxen.JaxenException; import org.jaxen.XPath; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.ProcessingInstruction; import org.w3c.dom.Text; import org.xml.sax.SAXException; /** * @author Elliotte Rusty Harold * */ public class NamespaceURITest extends TestCase { private Document doc; private DocumentBuilder builder; public void setUp() throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); builder = factory.newDocumentBuilder(); doc = builder.parse( "xml/basic.xml" ); } public NamespaceURITest(String name) { super(name); } public void testNamespaceURIOfNumber() throws JaxenException { try { XPath xpath = new DOMXPath( "namespace-uri(3)" ); xpath.selectNodes( doc ); fail("namespace-uri of non-node-set"); } catch (FunctionCallException e) { assertEquals("The argument to the namespace-uri function must be a node-set", e.getMessage()); } } public void testNamespaceURINoArguments() throws JaxenException { XPath xpath = new DOMXPath( "namespace-uri()" ); List results = xpath.selectNodes( doc ); assertEquals("", results.get(0)); } public void testNamespaceURIOfEmptyNodeSetIsEmptyString() throws JaxenException { XPath xpath = new DOMXPath( "namespace-uri(/aaa)" ); String result = (String) xpath.evaluate(doc); assertEquals("", result); } public void testNamespaceURIOfProcessingInstructionIsEmptyString() throws JaxenException { XPath xpath = new DOMXPath( "namespace-uri(/processing-instruction())" ); ProcessingInstruction pi = doc.createProcessingInstruction("target", "value"); doc.appendChild(pi); String result = (String) xpath.evaluate(doc); assertEquals("", result); } public void testNamespaceURIOfAttribute() throws JaxenException { XPath xpath = new DOMXPath( "namespace-uri(/*/@*)" ); Attr a = doc.createAttribute("name"); doc.getDocumentElement().setAttributeNode(a); Object result = xpath.evaluate(doc); assertEquals("", result); } public void testNamespaceURIOfAttributeInNamespace() throws JaxenException { XPath xpath = new DOMXPath( "namespace-uri(/*/@*)" ); Attr a = doc.createAttributeNS("http://www.w3.org/", "pre:name"); doc.getDocumentElement().setAttributeNode(a); Object result = xpath.evaluate(doc); assertEquals("http://www.w3.org/", result); } public void testNamespaceURIOfTextIsEmptyString() throws JaxenException { XPath xpath = new DOMXPath( "namespace-uri(/*/text())" ); Text c = doc.createTextNode("test"); doc.getDocumentElement().appendChild(c); String result = (String) xpath.evaluate(doc); assertEquals("", result); } public void testNamespaceURIRequiresAtMostOneArgument() throws JaxenException { XPath xpath = new DOMXPath( "namespace-uri(/*, /*)" ); try { xpath.evaluate(doc); fail("Allowed namespace-uri function with no arguments"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } public void testNamespaceURIOfNamespaceIsNull() throws JaxenException { XPath xpath = new DOMXPath( "namespace-uri(/*/namespace::node())" ); String result = (String) xpath.evaluate(doc); assertEquals("", result); } public void testNamespaceURIOfComment() throws JaxenException { XPath xpath = new DOMXPath("namespace-uri(/a/comment())"); Document document = builder.getDOMImplementation().createDocument(null, "a", null); document.getDocumentElement().appendChild(document.createComment("data")); String result = (String) xpath.evaluate(document); assertEquals("", result); } } jaxen-1.1.6/src/java/test/org/jaxen/test/XOMNavigatorTest.java0000664000175000017500000000510110371471320023534 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2000-2003 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import org.jaxen.Navigator; import org.jaxen.xom.DocumentNavigator; import nu.xom.Builder; public class XOMNavigatorTest extends XPathTestBase { private Builder builder = new Builder(); public XOMNavigatorTest(String name) { super( name ); } public Navigator getNavigator() { return new DocumentNavigator(); } public Object getDocument(String url) throws Exception { return this.builder.build( url ); } } jaxen-1.1.6/src/java/test/org/jaxen/test/ExprTests.java0000664000175000017500000000557010610716306022333 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import junit.framework.Test; import junit.framework.TestSuite; /** *

* Collect Jaxen's expression tests. *

* * @author Elliotte Rusty Harold * @version 1.1.1 * */ public class ExprTests { public static Test suite() { TestSuite result = new TestSuite(); result.addTest(new TestSuite(DefaultXPathExprTest.class)); result.addTest(new TestSuite(DefaultNamestepTest.class)); result.addTest(new TestSuite(ModTest.class)); result.addTest(new TestSuite(EqualsTest.class)); result.addTest(new TestSuite(LiteralExprTest.class)); result.addTest(new TestSuite(BinaryExprTest.class)); result.addTest(new TestSuite(ProcessingInstructionNodeTest.class)); return result; } }jaxen-1.1.6/src/java/test/org/jaxen/test/DefaultXPathFactoryTest.java0000664000175000017500000000543610524651472025122 0ustar ebourgebourg/* * $Header$ * $Revision: 1251 $ * $Date: 2006-11-09 17:11:38 +0100 (Thu, 09 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultXPathFactoryTest.java 1251 2006-11-09 16:11:38Z elharo $ */ package org.jaxen.test; import org.jaxen.JaxenException; import org.jaxen.expr.*; import junit.framework.TestCase; /** *

* Test for function context. *

* * @author Elliotte Rusty Harold * @version 1.1b12 * */ public class DefaultXPathFactoryTest extends TestCase { public void testBadAxis() throws JaxenException { DefaultXPathFactory factory = new DefaultXPathFactory(); try { factory.createAllNodeStep(123434); fail("Allowed bad axis"); } catch (JaxenException ex) { assertNotNull(ex.getMessage()); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/FunctionTests.java0000664000175000017500000001005410371471320023171 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import junit.framework.Test; import junit.framework.TestSuite; /** *

* Suite for Jaxen's function tests. *

* * @author Elliotte Rusty Harold * @version 1.1b9 * */ public class FunctionTests { public static Test suite() { TestSuite result = new TestSuite(); result.addTest(new TestSuite(TranslateFunctionTest.class)); result.addTest(new TestSuite(SubstringTest.class)); result.addTest(new TestSuite(SubstringBeforeTest.class)); result.addTest(new TestSuite(SubstringAfterTest.class)); result.addTest(new TestSuite(LangTest.class)); result.addTest(new TestSuite(LastTest.class)); result.addTest(new TestSuite(ConcatTest.class)); result.addTest(new TestSuite(ContainsTest.class)); result.addTest(new TestSuite(StringLengthTest.class)); result.addTest(new TestSuite(StartsWithTest.class)); result.addTest(new TestSuite(CountTest.class)); result.addTest(new TestSuite(LocalNameTest.class)); result.addTest(new TestSuite(NameTest.class)); result.addTest(new TestSuite(NamespaceURITest.class)); result.addTest(new TestSuite(SumTest.class)); result.addTest(new TestSuite(NumberTest.class)); result.addTest(new TestSuite(RoundTest.class)); result.addTest(new TestSuite(StringTest.class)); result.addTest(new TestSuite(BooleanTest.class)); result.addTest(new TestSuite(CeilingTest.class)); result.addTest(new TestSuite(FloorTest.class)); result.addTest(new TestSuite(IdTest.class)); result.addTest(new TestSuite(TrueTest.class)); result.addTest(new TestSuite(FalseTest.class)); result.addTest(new TestSuite(NotTest.class)); result.addTest(new TestSuite(NormalizeSpaceTest.class)); result.addTest(new TestSuite(PositionTest.class)); result.addTest(new TestSuite(ExtensionFunctionTest.class)); return result; } }jaxen-1.1.6/src/java/test/org/jaxen/test/NameTest.java0000664000175000017500000001403010371471320022077 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.io.IOException; import java.util.List; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.FunctionCallException; import org.jaxen.JaxenException; import org.jaxen.XPath; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Attr; import org.w3c.dom.Comment; import org.w3c.dom.Document; import org.w3c.dom.ProcessingInstruction; import org.w3c.dom.Text; import org.xml.sax.SAXException; /** * @author Elliotte Rusty Harold * */ public class NameTest extends TestCase { private Document doc; public void setUp() throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.parse( "xml/basic.xml" ); } public NameTest(String name) { super(name); } public void testNameOfNumber() throws JaxenException { try { XPath xpath = new DOMXPath( "name(3)" ); xpath.selectNodes( doc ); fail("name of non-node-set"); } catch (FunctionCallException e) { assertEquals("The argument to the name function must be a node-set", e.getMessage()); } } public void testNameWithTwoArguments() throws JaxenException { try { XPath xpath = new DOMXPath( "name(/*, //*)" ); xpath.selectNodes( doc ); fail("name with two arguments"); } catch (FunctionCallException e) { assertEquals("name() requires zero or one argument.", e.getMessage()); } } public void testNameAllowsNoArguments() throws JaxenException { XPath xpath = new DOMXPath( "name()" ); String result = (String) xpath.evaluate( doc.getDocumentElement() ); assertEquals("foo", result); } public void testNameOfCommentIsEmptyString() throws JaxenException { XPath xpath = new DOMXPath( "name(/comment())" ); Comment c = doc.createComment("test"); doc.appendChild(c); String result = (String) xpath.evaluate(doc); assertEquals("", result); } public void testNameOfProcessingInstructionIsTarget() throws JaxenException { XPath xpath = new DOMXPath( "name(/processing-instruction())" ); ProcessingInstruction pi = doc.createProcessingInstruction("target", "value"); doc.appendChild(pi); String result = (String) xpath.evaluate(doc); assertEquals("target", result); } public void testNameOfAttribute() throws JaxenException { XPath xpath = new DOMXPath( "name(/*/@*)" ); Attr a = doc.createAttribute("name"); doc.getDocumentElement().setAttributeNode(a); String result = (String) xpath.evaluate(doc); assertEquals("name", result); } public void testNameOfTextIsEmptyString() throws JaxenException { XPath xpath = new DOMXPath( "name(/*/text())" ); Text c = doc.createTextNode("test"); doc.getDocumentElement().appendChild(c); String result = (String) xpath.evaluate(doc); assertEquals("", result); } public void testNameOfNamespaceIsPrefix() throws JaxenException { XPath xpath = new DOMXPath( "name(/*/namespace::node())" ); String result = (String) xpath.evaluate(doc); assertEquals("xml", result); } public void testNameNoArguments() { try { XPath xpath = new DOMXPath( "name()" ); List results = xpath.selectNodes( doc ); assertEquals("", results.get(0)); } catch (Exception e) { e.printStackTrace(); fail( e.getMessage() ); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/XPathSyntaxExceptionTest.java0000664000175000017500000000673110371471320025342 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import junit.framework.TestCase; import org.jaxen.JaxenException; import org.jaxen.XPathSyntaxException; import org.jaxen.dom.*; /** * @author Elliotte Rusty Harold * */ public class XPathSyntaxExceptionTest extends TestCase { public XPathSyntaxExceptionTest(String name) { super(name); } public void testGetXPath() throws JaxenException { try { new DOMXPath("///triple slash"); fail("Bad parsing"); } catch (XPathSyntaxException ex) { assertEquals("///triple slash", ex.getXPath()); } } public void testGetPositionMarker() throws JaxenException { try { new DOMXPath("///triple slash"); fail("Bad parsing"); } catch (XPathSyntaxException ex) { assertTrue(ex.getPositionMarker().startsWith(" ")); assertTrue(ex.getPositionMarker().endsWith("^")); } } public void testGetMultilineMessage() throws JaxenException { try { new DOMXPath("///triple slash"); fail("Bad parsing"); } catch (XPathSyntaxException ex) { String message = ex.getMultilineMessage(); assertTrue(message.indexOf("\n///triple slash\n") > 1); assertTrue(message.endsWith("^")); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/TranslateFunctionTest.java0000664000175000017500000001555711004755147024707 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.FunctionCallException; import org.jaxen.JaxenException; import org.jaxen.XPath; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; /** * @author Elliotte Rusty Harold * */ public class TranslateFunctionTest extends TestCase { private Document doc; protected void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.newDocument(); doc.appendChild(doc.createElement("root")); } public void testTranslate() throws JaxenException { XPath xpath = new DOMXPath( "translate('abc', 'b', 'd')" ); String result = (String) xpath.evaluate( doc ); assertEquals("adc", result); } public void testTranslateIgnoresExtraArguments() throws JaxenException { XPath xpath = new DOMXPath( "translate('abc', 'b', 'dghf')" ); String result = (String) xpath.evaluate( doc ); assertEquals("adc", result); } public void testTranslateFunctionRequiresAtLeastThreeArguments() throws JaxenException { XPath xpath = new DOMXPath("translate('a', 'b')"); try { xpath.selectNodes(doc); fail("Allowed translate function with two arguments"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } public void testTranslateRequiresAtMostThreeArguments() throws JaxenException { XPath xpath = new DOMXPath("substring-after('a', 'a', 'a', 'a')"); try { xpath.selectNodes(doc); fail("Allowed translate function with four arguments"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } public void testTranslateStringThatContainsNonBMPChars() throws JaxenException { XPath xpath = new DOMXPath( "translate('ab\uD834\uDD00b', 'b', 'd')" ); String result = (String) xpath.evaluate( doc ); assertEquals("ad\uD834\uDD00d", result); } public void testTranslateStringThatContainsPrivateUseChars() throws JaxenException { XPath xpath = new DOMXPath( "translate('ab\uE000\uE001', '\uE000', '\uE001')" ); String result = (String) xpath.evaluate( doc ); assertEquals("ab\uE001\uE001", result); } public void testTranslateNonBMPChars() throws JaxenException { XPath xpath = new DOMXPath( "translate('ab\uD834\uDD00b', '\uD834\uDD00', 'd')" ); String result = (String) xpath.evaluate( doc ); assertEquals("abdb", result); } public void testTranslateNonBMPChars2() throws JaxenException { XPath xpath = new DOMXPath( "translate('ab\uD834\uDD00b', '\uD834\uDD00', 'da')" ); String result = (String) xpath.evaluate( doc ); assertEquals("abdb", result); } public void testTranslateWithNonBMPChars() throws JaxenException { XPath xpath = new DOMXPath( "translate('abc', 'c', '\uD834\uDD00')" ); String result = (String) xpath.evaluate( doc ); assertEquals("ab\uD834\uDD00", result); } public void testTranslateWithNonBMPChars2() throws JaxenException { XPath xpath = new DOMXPath( "translate('abc', 'c', '\uD834\uDD00b')" ); String result = (String) xpath.evaluate( doc ); assertEquals("ab\uD834\uDD00", result); } public void testTranslateWithMalformedSurrogatePair() throws JaxenException { XPath xpath = new DOMXPath( "translate('abc', 'c', '\uD834X\uDD00b')" ); try { xpath.evaluate( doc ); fail("Allowed malformed surrogate pair"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } public void testTranslateWithMissingLowSurrogate() throws JaxenException { XPath xpath = new DOMXPath( "translate('abc', 'c', 'AB\uD834X')" ); try { xpath.evaluate( doc ); fail("Allowed malformed surrogate pair"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } public void testTranslateWithExtraCharsInReplacementString() throws JaxenException { XPath xpath = new DOMXPath( "translate('abc', 'c', 'def')" ); String result = (String) xpath.evaluate( doc ); assertEquals("abd", result); } } jaxen-1.1.6/src/java/test/org/jaxen/test/LangTest.java0000664000175000017500000003034610371471320022110 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.util.List; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.BaseXPath; import org.jaxen.FunctionCallException; import org.jaxen.JaxenException; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; import org.w3c.dom.Element; /** * @author Elliotte Rusty Harold * */ public class LangTest extends TestCase { private Document doc; private DocumentBuilder builder; public void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); builder = factory.newDocumentBuilder(); doc = builder.newDocument(); } public LangTest(String name) { super(name); } public void testLangFunction() throws JaxenException { BaseXPath xpath = new DOMXPath("//*[lang('en')]"); Element a = doc.createElementNS("", "a"); Element b = doc.createElementNS("", "b"); b.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:lang", "en"); doc.appendChild(a); a.appendChild(b); Element x2 = doc.createElementNS("", "x"); Element x3 = doc.createElementNS("", "x"); Element x4 = doc.createElementNS("", "x"); a.appendChild(x4); b.appendChild(x2); b.appendChild(x3); x2.appendChild(doc.createTextNode("2")); x3.appendChild(doc.createTextNode("3")); x4.appendChild(doc.createTextNode("4")); List result = xpath.selectNodes(doc); assertEquals(3, result.size()); assertEquals(b, result.get(0)); assertEquals(x2, result.get(1)); assertEquals(x3, result.get(2)); } public void testLangFunctionSelectsNothing() throws JaxenException { BaseXPath xpath = new DOMXPath("//*[lang('fr')]"); Element a = doc.createElementNS("", "a"); Element b = doc.createElementNS("", "b"); b.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:lang", "en"); doc.appendChild(a); a.appendChild(b); Element x2 = doc.createElementNS("", "x"); Element x3 = doc.createElementNS("", "x"); Element x4 = doc.createElementNS("", "x"); a.appendChild(x4); b.appendChild(x2); b.appendChild(x3); x2.appendChild(doc.createTextNode("2")); x3.appendChild(doc.createTextNode("3")); x4.appendChild(doc.createTextNode("4")); List result = xpath.selectNodes(doc); assertEquals(0, result.size()); } public void testLangFunctionSelectsSubcode() throws JaxenException { BaseXPath xpath = new DOMXPath("//*[lang('fr')]"); Element a = doc.createElementNS("", "a"); Element b = doc.createElementNS("", "b"); b.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:lang", "fr-CA"); doc.appendChild(a); a.appendChild(b); Element x2 = doc.createElementNS("", "x"); Element x3 = doc.createElementNS("", "x"); Element x4 = doc.createElementNS("", "x"); a.appendChild(x4); b.appendChild(x2); b.appendChild(x3); x2.appendChild(doc.createTextNode("2")); x3.appendChild(doc.createTextNode("3")); x4.appendChild(doc.createTextNode("4")); List result = xpath.selectNodes(doc); assertEquals(3, result.size()); assertEquals(b, result.get(0)); assertEquals(x2, result.get(1)); assertEquals(x3, result.get(2)); } public void testHyphenRequiredAtEnd() throws JaxenException { BaseXPath xpath = new DOMXPath("//*[lang('f')]"); Element a = doc.createElementNS("", "a"); Element b = doc.createElementNS("", "b"); b.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:lang", "fr-CA"); doc.appendChild(a); a.appendChild(b); Element x2 = doc.createElementNS("", "x"); Element x3 = doc.createElementNS("", "x"); Element x4 = doc.createElementNS("", "x"); a.appendChild(x4); b.appendChild(x2); b.appendChild(x3); x2.appendChild(doc.createTextNode("2")); x3.appendChild(doc.createTextNode("3")); x4.appendChild(doc.createTextNode("4")); List result = xpath.selectNodes(doc); assertEquals(0, result.size()); } public void testLangFunctionSelectsEmptyNodeSet() throws JaxenException { BaseXPath xpath = new DOMXPath("//*[lang(d)]"); // This node-set will be empty. Therefore it's the same as the // empty string. Therefore it matches all languages. Element a = doc.createElementNS("", "a"); Element b = doc.createElementNS("", "b"); b.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:lang", "fr-CA"); doc.appendChild(a); a.appendChild(b); Element x2 = doc.createElementNS("", "x"); Element x3 = doc.createElementNS("", "x"); Element x4 = doc.createElementNS("", "x"); a.appendChild(x4); b.appendChild(x2); b.appendChild(x3); x2.appendChild(doc.createTextNode("2")); x3.appendChild(doc.createTextNode("3")); x4.appendChild(doc.createTextNode("4")); List result = xpath.selectNodes(doc); assertEquals(0, result.size()); } public void testLangFunctionSelectsNonEmptyNodeSet() throws JaxenException { BaseXPath xpath = new DOMXPath("//*[lang(x)]"); Element a = doc.createElementNS("", "a"); Element b = doc.createElementNS("", "b"); b.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:lang", "fr-CA"); doc.appendChild(a); a.appendChild(b); Element x2 = doc.createElementNS("", "x"); Element x3 = doc.createElementNS("", "x"); Element x4 = doc.createElementNS("", "x"); a.appendChild(x4); b.appendChild(x2); b.appendChild(x3); x2.appendChild(doc.createTextNode("fr")); x3.appendChild(doc.createTextNode("3")); x4.appendChild(doc.createTextNode("4")); List result = xpath.selectNodes(doc); assertEquals(1, result.size()); assertEquals(b, result.get(0)); } public void testLangFunctionAppliedToNonElement() throws JaxenException { BaseXPath xpath = new DOMXPath("//text()[lang('fr')]"); Element a = doc.createElementNS("", "a"); Element b = doc.createElementNS("", "b"); b.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:lang", "fr-CA"); doc.appendChild(a); a.appendChild(b); Element x2 = doc.createElementNS("", "x"); Element x3 = doc.createElementNS("", "x"); Element x4 = doc.createElementNS("", "x"); a.appendChild(x4); b.appendChild(x2); b.appendChild(x3); x2.appendChild(doc.createTextNode("fr")); x3.appendChild(doc.createTextNode("3")); x4.appendChild(doc.createTextNode("4")); List result = xpath.selectNodes(doc); assertEquals(2, result.size()); assertEquals(x2.getFirstChild(), result.get(0)); assertEquals(x3.getFirstChild(), result.get(1)); } public void testLangFunctionAppliedToDocument() throws JaxenException { BaseXPath xpath = new DOMXPath("lang('fr')"); Element a = doc.createElementNS("", "a"); Element b = doc.createElementNS("", "b"); b.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:lang", "fr-CA"); doc.appendChild(a); a.appendChild(b); Element x2 = doc.createElementNS("", "x"); Element x3 = doc.createElementNS("", "x"); Element x4 = doc.createElementNS("", "x"); a.appendChild(x4); b.appendChild(x2); b.appendChild(x3); x2.appendChild(doc.createTextNode("fr")); x3.appendChild(doc.createTextNode("3")); x4.appendChild(doc.createTextNode("4")); Boolean result = (Boolean) xpath.evaluate(doc); assertEquals(Boolean.FALSE, result); } public void testLangFunctionSelectsNumber() throws JaxenException { BaseXPath xpath = new DOMXPath("//*[lang(3)]"); Element a = doc.createElementNS("", "a"); Element b = doc.createElementNS("", "b"); b.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:lang", "fr-CA"); doc.appendChild(a); a.appendChild(b); Element x2 = doc.createElementNS("", "x"); Element x3 = doc.createElementNS("", "x"); Element x4 = doc.createElementNS("", "x"); a.appendChild(x4); b.appendChild(x2); b.appendChild(x3); x2.appendChild(doc.createTextNode("2")); x3.appendChild(doc.createTextNode("3")); x4.appendChild(doc.createTextNode("4")); List result = xpath.selectNodes(doc); assertEquals(0, result.size()); } public void testLangFunctionRequiresOneArgument() throws JaxenException { try { BaseXPath xpath = new DOMXPath("lang()"); org.w3c.dom.Element a = doc.createElementNS("", "a"); doc.appendChild(a); xpath.selectNodes(doc); fail("Allowed empty lang() function"); } catch (FunctionCallException success) { assertNotNull(success.getMessage()); } } public void testLangFunctionRequiresAtMostOneArgument() throws JaxenException { try { BaseXPath xpath = new DOMXPath("lang('en', 'fr')"); org.w3c.dom.Element a = doc.createElementNS("", "a"); doc.appendChild(a); xpath.selectNodes(doc); fail("Allowed empty lang() function"); } catch (FunctionCallException success) { assertNotNull(success.getMessage()); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/FalseTest.java0000664000175000017500000000702410371471320022256 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.FunctionCallException; import org.jaxen.JaxenException; import org.jaxen.XPath; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; /** * @author Elliotte Rusty Harold * */ public class FalseTest extends TestCase { private Document doc; public void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.newDocument(); doc.appendChild(doc.createElement("root")); } public FalseTest(String name) { super(name); } public void testFalseOfNumber() throws JaxenException { try { XPath xpath = new DOMXPath( "false(3)" ); xpath.selectNodes( doc ); fail("false() function took arguments"); } catch (FunctionCallException e) { assertEquals("false() requires no arguments.", e.getMessage()); } } public void testFalse() throws JaxenException { XPath xpath = new DOMXPath( "false()" ); Object result = xpath.evaluate( doc ); assertEquals(Boolean.FALSE, result); } } jaxen-1.1.6/src/java/test/org/jaxen/test/JaxenExceptionTest.java0000664000175000017500000000615110371471320024150 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.io.PrintWriter; import java.io.StringWriter; import org.jaxen.JaxenException; import junit.framework.TestCase; /** * @author Elliotte Rusty Harold * */ public class JaxenExceptionTest extends TestCase { public JaxenExceptionTest(String name) { super(name); } public void testMessageIsNonNull() { JaxenException ex = new JaxenException("Hello"); assertEquals("Hello", ex.getMessage()); } public void testPrintStackTrace() { StringIndexOutOfBoundsException cause = new StringIndexOutOfBoundsException("1234"); JaxenException ex = new JaxenException(cause); StringWriter out = new StringWriter(); PrintWriter pw = new PrintWriter(out); ex.printStackTrace(pw); pw.close(); String trace = out.toString(); assertEquals(-1, trace.indexOf("Root cause:")); assertTrue(trace.indexOf("Caused by: java.lang.StringIndexOutOfBoundsException") > 0); assertTrue(trace.indexOf("1234") > 0); } } jaxen-1.1.6/src/java/test/org/jaxen/test/VariableContextTest.java0000664000175000017500000000762010371471320024320 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.jaxen.JaxenException; import org.jaxen.SimpleVariableContext; import org.jaxen.UnresolvableException; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; import org.w3c.dom.Element; import junit.framework.TestCase; /** *

* Test for function context. *

* * @author Elliotte Rusty Harold * @version 1.1b9 * */ public class VariableContextTest extends TestCase { private Document doc; public void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); doc = factory.newDocumentBuilder().newDocument(); Element root = doc.createElementNS("http://www.example.org/", "root"); doc.appendChild(root); root.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", "http://www.example.org/"); } public void testUnresolvableVariable() throws JaxenException { DOMXPath xpath = new DOMXPath("$a/root"); try { xpath.evaluate(doc); fail("Evaluated nonexistent variable"); } catch (UnresolvableException ex) { assertEquals("Variable a", ex.getMessage()); } } public void testGetVariableContext() throws JaxenException { DOMXPath xpath = new DOMXPath("/root/child"); assertNotNull(xpath.getVariableContext()); } public void testSetNamespacelessVariable() throws JaxenException { SimpleVariableContext context = new SimpleVariableContext(); context.setVariableValue("foo", "bar"); assertEquals("bar", context.getVariableValue("", "", "foo")); } } jaxen-1.1.6/src/java/test/org/jaxen/test/NotTest.java0000664000175000017500000001217710371471320021771 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.util.List; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.BaseXPath; import org.jaxen.FunctionCallException; import org.jaxen.JaxenException; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; /** * @author Elliotte Rusty Harold * */ public class NotTest extends TestCase { private Document doc; public void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.newDocument(); doc.appendChild(doc.createElement("root")); } public NotTest(String name) { super(name); } public void testZeroIsFalse() throws JaxenException { BaseXPath xpath = new DOMXPath("not(0)"); List result = xpath.selectNodes(doc); assertEquals(1, result.size()); assertEquals(Boolean.TRUE, result.get(0)); } public void testOneIsTrue() throws JaxenException { BaseXPath xpath = new DOMXPath("not(1)"); List result = xpath.selectNodes(doc); assertEquals(1, result.size()); assertEquals(Boolean.FALSE, result.get(0)); } public void testEmptyStringIsFalse() throws JaxenException { BaseXPath xpath = new DOMXPath("not('')"); List result = xpath.selectNodes(doc); assertEquals(1, result.size()); assertEquals(Boolean.TRUE, result.get(0)); } public void testNaNIsFalse() throws JaxenException { BaseXPath xpath = new DOMXPath("not(0 div 0)"); Object result = xpath.evaluate(null); assertEquals(Boolean.TRUE, result); } public void testNonEmptyStringIsTrue() throws JaxenException { BaseXPath xpath = new DOMXPath("not('false')"); List result = xpath.selectNodes(doc); assertEquals(1, result.size()); assertEquals(Boolean.FALSE, result.get(0)); } public void testNotFunctionRequiresOneArgument() throws JaxenException { BaseXPath xpath = new DOMXPath("not()"); try { xpath.selectNodes(doc); fail("Allowed not() function with no arguments"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } public void testNotFunctionRequiresExactlyOneArgument() throws JaxenException { BaseXPath xpath = new DOMXPath("not('', '')"); try { xpath.selectNodes(doc); fail("Allowed not() function with two arguments"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/JaxenTests.java0000664000175000017500000000576511102333372022463 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import junit.framework.Test; import junit.framework.TestSuite; /** *

* Collect all the Jaxen tests into one suite. *

* * @author Elliotte Rusty Harold * @version 1.1b9 * */ public class JaxenTests { public static Test suite() { TestSuite result = new TestSuite(); result.addTest(SAXPathTests.suite()); result.addTest(FunctionTests.suite()); result.addTest(CoreTests.suite()); result.addTest(DOMTests.suite()); result.addTest(JDOMTests.suite()); result.addTest(DOM4JTests.suite()); result.addTest(XOMTests.suite()); result.addTest(JavaBeanTests.suite()); result.addTest(PatternTests.suite()); result.addTest(BaseTests.suite()); result.addTest(HelpersTests.suite()); result.addTest(ExprTests.suite()); result.addTest(UtilTests.suite()); return result; } }jaxen-1.1.6/src/java/test/org/jaxen/test/NumberTest.java0000664000175000017500000001334112005235251022450 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.util.List; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.FunctionCallException; import org.jaxen.JaxenException; import org.jaxen.Navigator; import org.jaxen.XPath; import org.jaxen.dom.DOMXPath; import org.jaxen.dom.DocumentNavigator; import org.jaxen.function.NumberFunction; import org.w3c.dom.Document; /** * @author Elliotte Rusty Harold * */ public class NumberTest extends TestCase { private Document doc; public void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.newDocument(); } public NumberTest(String name) { super(name); } // test case for JAXEN-55 public void testNumberFunctionOperatesOnFirstNodeInDocumentOrder() throws JaxenException { XPath xpath = new DOMXPath("number(//x)"); org.w3c.dom.Element a = doc.createElementNS("", "a"); org.w3c.dom.Element b = doc.createElementNS("", "b"); doc.appendChild(a); a.appendChild(b); org.w3c.dom.Element x2 = doc.createElementNS("", "x"); org.w3c.dom.Element x3 = doc.createElementNS("", "x"); org.w3c.dom.Element x4 = doc.createElementNS("", "x"); a.appendChild(x4); b.appendChild(x2); b.appendChild(x3); x2.appendChild(doc.createTextNode("2")); x3.appendChild(doc.createTextNode("3")); x4.appendChild(doc.createTextNode("4")); List result = xpath.selectNodes(doc); assertEquals(1, result.size()); assertEquals(Double.valueOf("2.0"), result.get(0)); } public void testNumberFunctionOperatesOnContextNode() throws JaxenException { XPath xpath = new DOMXPath("number()"); org.w3c.dom.Element a = doc.createElementNS("", "a"); doc.appendChild(a); a.appendChild(doc.createTextNode("2")); Double result = (Double) xpath.evaluate(doc); assertEquals(2, result.intValue()); } public void testBooleanConvertedToNumber() { double tolerance = 0.0000001; Navigator navigator = new DocumentNavigator(); assertEquals(0.0, NumberFunction.evaluate(Boolean.FALSE, navigator ).doubleValue(), tolerance); assertEquals(1.0, NumberFunction.evaluate(Boolean.TRUE, navigator).doubleValue(), tolerance); assertEquals(0.0, NumberFunction.evaluate(new Boolean(false), navigator).doubleValue(), tolerance); assertEquals(1.0, NumberFunction.evaluate(new Boolean(true), navigator).doubleValue(), tolerance); } public void testNumberFunctionRequiresAtMostOneArgument() throws JaxenException { XPath xpath = new DOMXPath("number('2.2', '1.2')"); try { xpath.selectNodes(doc); fail("Allowed number function with two arguments"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } public void testNumberFunctionAppliedToNonNumericString() throws JaxenException { XPath xpath = new DOMXPath("number('Marx')"); Double result = (Double) xpath.evaluate(doc); assertEquals(new Double(Double.NaN), result); } public void testIsNan() { assertTrue(NumberFunction.isNaN(0.0 / 0.0)); } } jaxen-1.1.6/src/java/test/org/jaxen/test/XPathReaderTest.java0000664000175000017500000003433110456434562023407 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.io.IOException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.JaxenException; import org.jaxen.XPath; import org.jaxen.dom.DOMXPath; import org.jaxen.saxpath.SAXPathException; import org.jaxen.saxpath.base.XPathReader; import org.jaxen.saxpath.XPathSyntaxException; import org.w3c.dom.Document; import org.xml.sax.SAXException; public class XPathReaderTest extends TestCase { private ConformanceXPathHandler actual; private Document doc; private XPathReader reader; private String[] paths = { "/foo/bar[@a='1' and @b='2']", "/foo/bar[@a='1' and @b!='2']", "$varname[@a='1']", "//attribute::*[.!='crunchy']", "'//*[contains(string(text()),\"yada yada\")]'", }; private String[][] bogusPaths = { new String[]{"chyld::foo", "Expected valid axis name instead of [chyld]"}, new String[]{"foo/tacos()", "Expected node-type"}, new String[]{"foo/tacos()", "Expected node-type"}, new String[]{"*:foo", "Unexpected ':'"}, new String[]{"/foo/bar[baz", "Expected: ]"}, new String[]{"/cracker/cheese[(mold > 1) and (sense/taste", "Expected: )"}, new String[]{"//", "Location path cannot end with //"}, new String[]{"foo/$variable/foo", "Expected one of '.', '..', '@', '*', "} }; public XPathReaderTest( String name ) { super( name ); } public void setUp() throws ParserConfigurationException, SAXException, IOException { this.reader = new XPathReader(); this.actual = new ConformanceXPathHandler(); this.reader.setXPathHandler( this.actual ); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.parse( "xml/basic.xml" ); } public void tearDown() { this.reader = null; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- public void testPaths() throws SAXPathException { for( int i = 0; i < paths.length; ++i ) { reader.parse( paths[i] ); } } public void testBogusPaths() throws SAXPathException { for( int i = 0; i < bogusPaths.length; ++i ) { final String[] bogusPath = bogusPaths[i]; try { reader.parse( bogusPath[0] ); fail( "Should have thrown XPathSyntaxException for " + bogusPath[0]); } catch( XPathSyntaxException e ) { assertEquals( bogusPath[1], e.getMessage() ); } } } public void testChildrenOfNumber() throws SAXPathException { try { reader.parse( "1/child::test" ); fail( "Should have thrown XPathSyntaxException for 1/child::test"); } catch( XPathSyntaxException e ) { assertEquals( "Node-set expected", e.getMessage() ); } } public void testChildIsNumber() throws SAXPathException { try { reader.parse( "jane/3" ); fail( "Should have thrown XPathSyntaxException for jane/3"); } catch( XPathSyntaxException e ) { assertEquals( "Expected one of '.', '..', '@', '*', ", e.getMessage() ); } } public void testNumberOrNumber() { try { XPath xpath = new DOMXPath( "4 | 5" ); xpath.selectNodes( doc ); fail( "Should have thrown XPathSyntaxException for 4 | 5"); } catch( JaxenException e ) { assertEquals( "Unions are only allowed over node-sets", e.getMessage() ); } } public void testStringOrNumber() { try { XPath xpath = new DOMXPath( "\"test\" | 5" ); xpath.selectNodes( doc ); fail( "Should have thrown XPathSyntaxException for \"test\" | 5"); } catch( JaxenException e ) { assertEquals( "Unions are only allowed over node-sets", e.getMessage() ); } } public void testStringOrString() { try { XPath xpath = new DOMXPath( "\"test\" | \"festival\"" ); xpath.selectNodes( doc ); fail( "Should have thrown XPathSyntaxException for \"test\" | 5"); } catch( JaxenException e ) { assertEquals( "Unions are only allowed over node-sets", e.getMessage() ); } } public void testUnionofNodesAndNonNodes() { try { XPath xpath = new DOMXPath( "count(//*) | //* " ); xpath.selectNodes( doc ); fail( "Should have thrown XPathSyntaxException for \"count(//*) | //* "); } catch( JaxenException e ) { assertEquals( "Unions are only allowed over node-sets", e.getMessage() ); } } public void testValidAxis() throws SAXPathException { reader.parse( "child::foo" ); } public void testInvalidAxis() throws SAXPathException { try { reader.parse( "chyld::foo" ); fail( "Should have thrown XPathSyntaxException" ); } catch( XPathSyntaxException ex ) { assertNotNull(ex.getMessage()); } } /* public void testSimpleNameStep() throws SAXPathException { this.text = "foo"; this.reader.setUpParse( this.text ); this.reader.step( ); this.expected.startNameStep( Axis.CHILD, "", "foo" ); this.expected.endNameStep(); assertEquals( this.expected, this.actual ); } public void testNameStepWithAxisAndPrefix() throws SAXPathException { this.text = "parent::foo:bar"; this.reader.setUpParse( this.text ); this.reader.step( ); this.expected.startNameStep( Axis.PARENT, "foo", "bar" ); this.expected.endNameStep(); assertEquals( this.expected, this.actual ); } public void testNodeStepWithAxis() throws SAXPathException { this.text = "parent::node()"; this.reader.setUpParse( this.text ); this.reader.step(); this.expected.startAllNodeStep( Axis.PARENT ); this.expected.endAllNodeStep(); assertEquals( this.expected, this.actual ); } public void testProcessingInstructionStepWithName() throws SAXPathException { this.text = "parent::processing-instruction('cheese')"; this.reader.setUpParse( this.text ); this.reader.step( ); this.expected.startProcessingInstructionNodeStep( Axis.PARENT, "cheese" ); this.expected.endProcessingInstructionNodeStep(); assertEquals( this.expected, this.actual ); } public void testProcessingInstructionStepNoName() throws SAXPathException { this.text = "parent::processing-instruction()"; this.reader.setUpParse( this.text ); this.reader.step( ); this.expected.startProcessingInstructionNodeStep( Axis.PARENT, "" ); this.expected.endProcessingInstructionNodeStep(); assertEquals( this.expected, this.actual ); } public void testAllNodeStep() throws SAXPathException { this.text = "parent::node()"; this.reader.setUpParse( this.text ); this.reader.step( ); this.expected.startAllNodeStep( Axis.PARENT ); this.expected.endAllNodeStep(); assertEquals( this.expected, this.actual ); } public void testTextNodeStep() throws SAXPathException { this.text = "parent::text()"; this.reader.setUpParse( this.text ); this.reader.step( ); this.expected.startTextNodeStep( Axis.PARENT ); this.expected.endTextNodeStep(); assertEquals( this.expected, this.actual ); } public void testCommentNodeStep() throws SAXPathException { this.text = "parent::comment()"; this.reader.setUpParse( this.text ); this.reader.step( ); this.expected.startCommentNodeStep( Axis.PARENT ); this.expected.endCommentNodeStep(); assertEquals( this.expected, this.actual ); }*/ public void testLocationPathStartsWithVariable() throws SAXPathException { reader.parse( "$variable/foo" ); } public void testLocationPathStartsWithParentheses() throws SAXPathException { reader.parse( "(//x)/foo" ); } /*public void testRelativeLocationPath() throws SAXPathException { this.text = "foo/bar/baz"; this.reader.setUpParse( this.text ); this.reader.locationPath( false ); this.expected.startRelativeLocationPath(); this.expected.startNameStep( Axis.CHILD, "", "foo" ); this.expected.endNameStep(); this.expected.startNameStep( Axis.CHILD, "", "bar" ); this.expected.endNameStep(); this.expected.startNameStep( Axis.CHILD, "", "baz" ); this.expected.endNameStep(); this.expected.endRelativeLocationPath(); assertEquals( this.expected, this.actual ); } public void testAbsoluteLocationPath() throws SAXPathException { this.text = "/foo/bar/baz"; this.reader.setUpParse( this.text ); this.reader.locationPath( true ); this.expected.startAbsoluteLocationPath(); this.expected.startNameStep( Axis.CHILD, "", "foo" ); this.expected.endNameStep(); this.expected.startNameStep( Axis.CHILD, "", "bar" ); this.expected.endNameStep(); this.expected.startNameStep( Axis.CHILD, "", "baz" ); this.expected.endNameStep(); this.expected.endAbsoluteLocationPath(); assertEquals( this.expected, this.actual ); }*/ public void testNoSpaceAfterDiv() throws JaxenException { XPath xpath = new DOMXPath( "105 div10" ); Double result = (Double) xpath.evaluate(doc); assertEquals(10.5, result.doubleValue(), 0.000001); } public void testNoSpaceAfterMod() throws JaxenException { XPath xpath = new DOMXPath( "105 mod10" ); Double result = (Double) xpath.evaluate(doc); assertEquals(5, result.intValue()); } public void testNoSpaceAfterPlus() throws JaxenException { XPath xpath = new DOMXPath( "105 +10" ); Double result = (Double) xpath.evaluate(doc); assertEquals(115, result.intValue()); } public void testNoSpaceAfterAnd() throws JaxenException { XPath xpath = new DOMXPath("true() andfalse()"); Boolean result = (Boolean) xpath.evaluate(doc); assertFalse(result.booleanValue()); } public void testNoSpaceAfterOr() throws JaxenException { XPath xpath = new DOMXPath("true() orfalse()"); Boolean result = (Boolean) xpath.evaluate(doc); assertTrue(result.booleanValue()); } public void testAndImmediatelyFollowedByRelativeLocationPath() throws JaxenException { XPath xpath = new DOMXPath("true() andfoo"); Boolean result = (Boolean) xpath.evaluate(doc); assertTrue(result.booleanValue()); } } jaxen-1.1.6/src/java/test/org/jaxen/test/ExprComparator.java0000664000175000017500000003345710547742352023356 0ustar ebourgebourg/* * $Header$ * $Revision: 1283 $ * $Date: 2007-01-06 16:48:58 +0100 (Sat, 06 Jan 2007) $ * * ==================================================================== * * Copyright 2007 Ryan Gustafson * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: ExprComparator.java 1283 2007-01-06 15:48:58Z elharo $ */ package org.jaxen.test; import java.util.Comparator; import java.util.List; import org.jaxen.expr.AdditiveExpr; import org.jaxen.expr.AllNodeStep; import org.jaxen.expr.CommentNodeStep; import org.jaxen.expr.EqualityExpr; import org.jaxen.expr.FilterExpr; import org.jaxen.expr.FunctionCallExpr; import org.jaxen.expr.LiteralExpr; import org.jaxen.expr.LocationPath; import org.jaxen.expr.LogicalExpr; import org.jaxen.expr.MultiplicativeExpr; import org.jaxen.expr.NameStep; import org.jaxen.expr.NumberExpr; import org.jaxen.expr.PathExpr; import org.jaxen.expr.Predicate; import org.jaxen.expr.ProcessingInstructionNodeStep; import org.jaxen.expr.RelationalExpr; import org.jaxen.expr.TextNodeStep; import org.jaxen.expr.UnaryExpr; import org.jaxen.expr.UnionExpr; import org.jaxen.expr.VariableReferenceExpr; class ExprComparator implements Comparator { public static final Comparator EXPR_COMPARATOR = new ExprComparator(); private static final int TYPE_ADDITIVE_EXPR = 1; private static final int TYPE_ALL_NODE_STEP = 2; private static final int TYPE_COMMENT_NODE_STEP = 3; private static final int TYPE_EQUALITY_EXPR = 4; private static final int TYPE_FILTER_EXPR = 5; private static final int TYPE_FUNCTION_CALL_EXPR = 6; private static final int TYPE_LITERAL_EXPR = 7; private static final int TYPE_LOCATION_PATH = 8; private static final int TYPE_LOGICAL_EXP = 9; private static final int TYPE_MULTIPLICATIVE_EXPR = 10; private static final int TYPE_NAME_STEP = 11; private static final int TYPE_NUMBER_EXPR = 12; private static final int TYPE_PATH_EXPR = 13; private static final int TYPE_PREDICATE = 14; private static final int TYPE_PROCESSING_INSTRUCTION_NODE_STEP = 15; private static final int TYPE_RELATIONAL_EXPR = 16; private static final int TYPE_TEXT_NODE_STEP = 17; private static final int TYPE_UNARY_EXPR = 18; private static final int TYPE_UNION_EXPR = 19; private static final int TYPE_VARIABLE_REFERENCE_EXPR = 20; private ExprComparator() { } public int compare(Object o1, Object o2) { int type1 = getType(o1); int type2 = getType(o2); int cmp; if (type1 == type2) { switch (type1) { case TYPE_ADDITIVE_EXPR: AdditiveExpr additiveExpr1 = (AdditiveExpr)o1; AdditiveExpr additiveExpr2 = (AdditiveExpr)o2; cmp = additiveExpr1.getOperator().compareTo(additiveExpr2.getOperator()); if (cmp == 0) { cmp = compare(additiveExpr1.getLHS(), additiveExpr2.getLHS()); if (cmp == 0) { cmp = compare(additiveExpr1.getRHS(), additiveExpr2.getRHS()); } } break; case TYPE_ALL_NODE_STEP: AllNodeStep allNodeStep1 = (AllNodeStep)o1; AllNodeStep allNodeStep2 = (AllNodeStep)o2; cmp = allNodeStep1.getAxis() - allNodeStep2.getAxis(); if (cmp == 0) { cmp = compareLists(allNodeStep1.getPredicates(), allNodeStep2.getPredicates()); } break; case TYPE_COMMENT_NODE_STEP: CommentNodeStep commentNodeStep1 = (CommentNodeStep)o1; CommentNodeStep commentNodeStep2 = (CommentNodeStep)o2; cmp = commentNodeStep1.getAxis() - commentNodeStep2.getAxis(); if (cmp == 0) { cmp = compareLists(commentNodeStep1.getPredicates(), commentNodeStep2.getPredicates()); } break; case TYPE_EQUALITY_EXPR: EqualityExpr equalityExpr1 = (EqualityExpr)o1; EqualityExpr equalityExpr2 = (EqualityExpr)o2; cmp = equalityExpr1.getOperator().compareTo(equalityExpr2.getOperator()); if (cmp == 0) { cmp = compare(equalityExpr1.getLHS(), equalityExpr1.getLHS()); if (cmp == 0) { cmp = compare(equalityExpr1.getRHS(), equalityExpr1.getRHS()); } } break; case TYPE_FILTER_EXPR: if (true) throw new RuntimeException("Not yet implemented!"); break; case TYPE_FUNCTION_CALL_EXPR: FunctionCallExpr functionCallExpr1 = (FunctionCallExpr)o1; FunctionCallExpr functionCallExpr2 = (FunctionCallExpr)o2; cmp = compareStrings(functionCallExpr1.getPrefix(), functionCallExpr2.getPrefix()); if (cmp == 0) { cmp = functionCallExpr1.getFunctionName().compareTo(functionCallExpr2.getFunctionName()); if (cmp == 0) { cmp = compareLists(functionCallExpr1.getParameters(), functionCallExpr2.getParameters()); } } break; case TYPE_LITERAL_EXPR: LiteralExpr literalExpr1 = (LiteralExpr)o1; LiteralExpr literalExpr2 = (LiteralExpr)o2; cmp = literalExpr1.getLiteral().compareTo(literalExpr2.getLiteral()); break; case TYPE_LOCATION_PATH: LocationPath locationPath1 = (LocationPath)o1; LocationPath locationPath2 = (LocationPath)o2; if (locationPath1.isAbsolute() == locationPath2.isAbsolute()) { cmp = compareLists(locationPath1.getSteps(), locationPath2.getSteps()); } else if (locationPath1.isAbsolute()) { cmp = 1; } else { cmp = -1; } break; case TYPE_LOGICAL_EXP: LogicalExpr logicalExpr1 = (LogicalExpr)o1; LogicalExpr logicalExpr2 = (LogicalExpr)o2; cmp = logicalExpr1.getOperator().compareTo(logicalExpr2.getOperator()); if (cmp == 0) { cmp = compare(logicalExpr1.getLHS(), logicalExpr2.getLHS()); if (cmp == 0) { cmp = compare(logicalExpr1.getRHS(), logicalExpr2.getRHS()); } } break; case TYPE_MULTIPLICATIVE_EXPR: MultiplicativeExpr multiplicativeExpr1 = (MultiplicativeExpr)o1; MultiplicativeExpr multiplicativeExpr2 = (MultiplicativeExpr)o2; cmp = multiplicativeExpr1.getOperator().compareTo(multiplicativeExpr2.getOperator()); if (cmp == 0) { cmp = compare(multiplicativeExpr1.getLHS(), multiplicativeExpr2.getLHS()); if (cmp == 0) { cmp = compare(multiplicativeExpr1.getRHS(), multiplicativeExpr2.getRHS()); } } break; case TYPE_NAME_STEP: NameStep nameStep1 = (NameStep)o1; NameStep nameStep2 = (NameStep)o2; cmp = nameStep1.getAxis() - nameStep2.getAxis(); if (cmp == 0) { cmp = compareStrings(nameStep1.getPrefix(), nameStep2.getPrefix()); if (cmp == 0) { cmp = nameStep1.getLocalName().compareTo(nameStep2.getLocalName()); if (cmp == 0) { cmp = compareLists(nameStep1.getPredicates(), nameStep2.getPredicates()); } } } break; case TYPE_NUMBER_EXPR: NumberExpr numberExpr1 = (NumberExpr)o1; NumberExpr numberExpr2 = (NumberExpr)o2; cmp = new Double(numberExpr1.getNumber().doubleValue()).compareTo(new Double(numberExpr2.getNumber().doubleValue())); break; case TYPE_PATH_EXPR: PathExpr pathExpr1 = (PathExpr)o1; PathExpr pathExpr2 = (PathExpr)o2; cmp = compare(pathExpr1.getLocationPath(), pathExpr2.getLocationPath()); if (cmp == 0) { cmp = compare(pathExpr1.getFilterExpr(), pathExpr2.getFilterExpr()); } break; case TYPE_PREDICATE: Predicate predicate1 = (Predicate)o1; Predicate predicate2 = (Predicate)o2; cmp = compare(predicate1.getExpr(), predicate2.getExpr()); break; case TYPE_PROCESSING_INSTRUCTION_NODE_STEP: ProcessingInstructionNodeStep processingInstructionNodeStep1 = (ProcessingInstructionNodeStep)o1; ProcessingInstructionNodeStep processingInstructionNodeStep2 = (ProcessingInstructionNodeStep)o2; cmp = processingInstructionNodeStep1.getAxis() - processingInstructionNodeStep2.getAxis(); if (cmp == 0) { cmp = compareStrings(processingInstructionNodeStep1.getName(), processingInstructionNodeStep2.getName()); if (cmp == 0) { cmp = compareLists(processingInstructionNodeStep1.getPredicates(), processingInstructionNodeStep2.getPredicates()); } } break; case TYPE_RELATIONAL_EXPR: RelationalExpr relationalExpr1 = (RelationalExpr)o1; RelationalExpr relationalExpr2 = (RelationalExpr)o2; cmp = relationalExpr1.getOperator().compareTo(relationalExpr2.getOperator()); if (cmp == 0) { cmp = compare(relationalExpr1.getLHS(), relationalExpr2.getLHS()); if (cmp == 0) { cmp = compare(relationalExpr1.getRHS(), relationalExpr2.getRHS()); } } break; case TYPE_TEXT_NODE_STEP: TextNodeStep textNodeStep1 = (TextNodeStep)o1; TextNodeStep textNodeStep2 = (TextNodeStep)o2; cmp = textNodeStep1.getAxis() - textNodeStep2.getAxis(); if (cmp == 0) { cmp = compareLists(textNodeStep1.getPredicates(), textNodeStep2.getPredicates()); } break; case TYPE_UNARY_EXPR: UnaryExpr unaryExpr1 = (UnaryExpr)o1; UnaryExpr unaryExpr2 = (UnaryExpr)o2; cmp = compare(unaryExpr1.getExpr(), unaryExpr2.getExpr()); break; case TYPE_UNION_EXPR: if (true) throw new RuntimeException("Not yet implemented!"); break; case TYPE_VARIABLE_REFERENCE_EXPR: VariableReferenceExpr variableReferenceExpr1 = (VariableReferenceExpr)o1; VariableReferenceExpr variableReferenceExpr2 = (VariableReferenceExpr)o2; cmp = compareStrings(variableReferenceExpr1.getPrefix(), variableReferenceExpr2.getPrefix()); if (cmp == 0) { cmp = variableReferenceExpr1.getVariableName().compareTo(variableReferenceExpr2.getVariableName()); } break; default: throw new IllegalArgumentException("Unhandled type: " + type1); } } else { cmp = type1 - type2; } return cmp; } private int compareStrings(String s1, String s2) { int cmp; if (s1 == s2) { cmp = 0; } else if (s1 == null) { cmp = -1; } else if (s2 == null) { cmp = 1; } else { cmp = s1.compareTo(s2); } return cmp; } private int compareLists(List list1, List list2) { int cmp; if (list1 == list2) { cmp = 0; } else if (list1 == null) { cmp = -1; } else if (list2 == null) { cmp = 1; } else { cmp = list1.size() - list2.size(); if (cmp == 0) { for (int i = 0; i < list1.size() && cmp == 0; i++) { cmp = compare(list1.get(i), list2.get(i)); } } } return cmp; } private int getType(Object node) { if (node instanceof AdditiveExpr) { return TYPE_ADDITIVE_EXPR; } else if (node instanceof AllNodeStep) { return TYPE_ALL_NODE_STEP; } else if (node instanceof CommentNodeStep) { return TYPE_COMMENT_NODE_STEP; } else if (node instanceof EqualityExpr) { return TYPE_EQUALITY_EXPR; } else if (node instanceof FilterExpr) { return TYPE_FILTER_EXPR; } else if (node instanceof FunctionCallExpr) { return TYPE_FUNCTION_CALL_EXPR; } else if (node instanceof LiteralExpr) { return TYPE_LITERAL_EXPR; } else if (node instanceof LocationPath) { return TYPE_LOCATION_PATH; } else if (node instanceof LogicalExpr) { return TYPE_LOGICAL_EXP; } else if (node instanceof MultiplicativeExpr) { return TYPE_MULTIPLICATIVE_EXPR; } else if (node instanceof NameStep) { return TYPE_NAME_STEP; } else if (node instanceof NumberExpr) { return TYPE_NUMBER_EXPR; } else if (node instanceof PathExpr) { return TYPE_PATH_EXPR; } else if (node instanceof Predicate) { return TYPE_PREDICATE; } else if (node instanceof ProcessingInstructionNodeStep) { return TYPE_PROCESSING_INSTRUCTION_NODE_STEP; } else if (node instanceof RelationalExpr) { return TYPE_RELATIONAL_EXPR; } else if (node instanceof TextNodeStep) { return TYPE_TEXT_NODE_STEP; } else if (node instanceof UnaryExpr) { return TYPE_UNARY_EXPR; } else if (node instanceof UnionExpr) { return TYPE_UNION_EXPR; } else if (node instanceof VariableReferenceExpr) { return TYPE_VARIABLE_REFERENCE_EXPR; } else { throw new IllegalArgumentException("Unknown Jaxen AST node type: " + node); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/AxisTest.java0000664000175000017500000000516310371471320022132 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import org.jaxen.JaxenRuntimeException; import org.jaxen.saxpath.Axis; import junit.framework.TestCase; /** * @author Elliotte Rusty Harold * */ public class AxisTest extends TestCase { public AxisTest(String name) { super(name); } public void testIllegalAxisNumber() { try { Axis.lookup(-10009); fail("Looked up negative number"); } catch (JaxenRuntimeException ex) { assertEquals("Illegal Axis Number", ex.getMessage()); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/DOM4JNavigatorTest.java0000664000175000017500000000761710456426433023735 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.util.Iterator; import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.io.SAXReader; import org.jaxen.FunctionCallException; import org.jaxen.JaxenException; import org.jaxen.Navigator; import org.jaxen.UnsupportedAxisException; import org.jaxen.XPath; import org.jaxen.dom4j.DocumentNavigator; import org.jaxen.dom4j.Dom4jXPath; public class DOM4JNavigatorTest extends XPathTestBase { private SAXReader reader; public DOM4JNavigatorTest(String name) { super( name ); this.reader = new SAXReader(); this.reader.setMergeAdjacentText( true ); } public Navigator getNavigator() { return new DocumentNavigator(); } public Object getDocument(String url) throws Exception { return reader.read( url ); } /** * reported as JAXEN-104. * @throws FunctionCallException * @throws UnsupportedAxisException */ public void testConcurrentModification() throws FunctionCallException, UnsupportedAxisException { Navigator nav = new DocumentNavigator(); Object document = nav.getDocument("xml/testNamespaces.xml"); Iterator descendantOrSelfAxisIterator = nav.getDescendantOrSelfAxisIterator(document); while (descendantOrSelfAxisIterator.hasNext()) { Object node = descendantOrSelfAxisIterator.next(); Iterator namespaceAxisIterator = nav.getNamespaceAxisIterator(node); while (namespaceAxisIterator.hasNext()) { namespaceAxisIterator.next(); } } } public void testNullPointerException() throws JaxenException { Document doc = DocumentHelper.createDocument(); XPath xpath = new Dom4jXPath("/foo"); xpath.selectSingleNode(doc); } } jaxen-1.1.6/src/java/test/org/jaxen/test/NormalizeSpaceTest.java0000664000175000017500000001056710371471320024146 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.BaseXPath; import org.jaxen.FunctionCallException; import org.jaxen.JaxenException; import org.jaxen.XPath; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; /** * @author Elliotte Rusty Harold * */ public class NormalizeSpaceTest extends TestCase { private Document doc; public void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.newDocument(); doc.appendChild(doc.createElement("root")); } public NormalizeSpaceTest(String name) { super(name); } public void testNormalizeSpaceUsesXMLSpaceRulesNotJavaRules() throws JaxenException { // em space counts as whitespace in Java but not XML String data = "\u2003X\u2003"; XPath xpath = new DOMXPath( "normalize-space('" + data + "')" ); String result = (String) xpath.evaluate( doc ); assertEquals(data, result); } public void testNormalizeSpaceUsesXMLSpaceRulesNotJavaRules2() throws JaxenException { // em space counts as whitespace in Java but not XML String data = "\u2003X\u2003"; XPath xpath = new DOMXPath( "normalize-space(' " + data + " ')" ); String result = (String) xpath.evaluate( doc ); assertEquals(data, result); } public void testNormalizeSpaceInContextNode() throws JaxenException { XPath xpath = new DOMXPath( "normalize-space()" ); String result = (String) xpath.evaluate( doc ); assertEquals("", result); } public void testNormalizeSpaceRequiresAtMostOneArguments() throws JaxenException { BaseXPath xpath = new DOMXPath("normalize-space('a', 'a')"); try { xpath.selectNodes(doc); fail("Allowed normalize-space function with two arguments"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/RoundTest.java0000664000175000017500000001101310371471320022304 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.FunctionCallException; import org.jaxen.JaxenException; import org.jaxen.XPath; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; /** * @author Elliotte Rusty Harold * */ public class RoundTest extends TestCase { private Document doc; public void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.newDocument(); org.w3c.dom.Element a = doc.createElementNS("", "a"); doc.appendChild(a); } public RoundTest(String name) { super(name); } public void testRound() throws JaxenException { XPath xpath = new DOMXPath("round(1.5)"); Object result = xpath.evaluate(doc); assertEquals(2, ((Double) result).doubleValue(), 0.0001); } public void testNegativeRound() throws JaxenException { XPath xpath = new DOMXPath("round(-1.5)"); Object result = xpath.evaluate(doc); assertEquals(-1, ((Double) result).doubleValue(), 0.0001); } public void testNaNRoundIsNaN() throws JaxenException { XPath xpath = new DOMXPath("round(1.0 div 0.0 - 2.0 div 0.0)"); double result = ((Double) xpath.evaluate(doc)).doubleValue(); assertTrue(Double.isNaN(result)); } public void testRoundFunctionRequiresAtLeastOneArgument() throws JaxenException { XPath xpath = new DOMXPath("round()"); try { xpath.selectNodes(doc); fail("Allowed round function with no arguments"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } public void testRoundFunctionRequiresAtMostOneArgument() throws JaxenException { XPath xpath = new DOMXPath("round(2.2, 1.2)"); try { xpath.selectNodes(doc); fail("Allowed round function with two arguments"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/PrecedingSiblingAxisIteratorTest.java0000664000175000017500000000717710371471320027004 0ustar ebourgebourg/* $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.util.Iterator; import java.util.NoSuchElementException; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.jaxen.UnsupportedAxisException; import org.jaxen.util.PrecedingSiblingAxisIterator; import org.w3c.dom.Document; import junit.framework.TestCase; public class PrecedingSiblingAxisIteratorTest extends TestCase { private Iterator iterator; public PrecedingSiblingAxisIteratorTest(String name) { super(name); } protected void setUp() throws ParserConfigurationException, UnsupportedAxisException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); Document doc = factory.newDocumentBuilder().newDocument(); doc.appendChild(doc.createElement("root")); iterator = new PrecedingSiblingAxisIterator(doc, new org.jaxen.dom.DocumentNavigator()); } public void testNoInfiniteLoops() { try { iterator.next(); fail("Iterated too far"); } catch (NoSuchElementException ex) { pass(); } } private void pass() { // Just to make checkstyle and the like happy } public void testRemove() { try { iterator.remove(); fail("Removed from descendant axis iterator"); } catch (UnsupportedOperationException ex) { pass(); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/FunctionCallExceptionTest.java0000664000175000017500000000572210371471320025467 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import org.jaxen.FunctionCallException; import org.jaxen.JaxenException; import junit.framework.TestCase; /** * @author Elliotte Rusty Harold * */ public class FunctionCallExceptionTest extends TestCase { public FunctionCallExceptionTest(String name) { super(name); } public void testMessageIsNonNull() { JaxenException ex = new JaxenException("Hello"); FunctionCallException rex = new FunctionCallException(ex); assertEquals(ex.getMessage(), rex.getMessage()); assertEquals(ex, rex.getCause()); } public void testMessageIsSaved() { JaxenException ex = new JaxenException("Hello"); FunctionCallException rex = new FunctionCallException("Goodbye", ex); assertEquals("Goodbye", rex.getMessage()); assertEquals(ex, rex.getCause()); } } jaxen-1.1.6/src/java/test/org/jaxen/test/FunctionContextTest.java0000664000175000017500000001231710371471320024357 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.NotSerializableException; import java.io.ObjectOutputStream; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.jaxen.FunctionContext; import org.jaxen.JaxenException; import org.jaxen.SimpleNamespaceContext; import org.jaxen.UnresolvableException; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; import org.w3c.dom.Element; import junit.framework.TestCase; /** *

* Test for function context. *

* * @author Elliotte Rusty Harold * @version 1.1b9 * */ public class FunctionContextTest extends TestCase { private Document doc; public void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); doc = factory.newDocumentBuilder().newDocument(); Element root = doc.createElementNS("http://www.example.org/", "root"); doc.appendChild(root); root.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", "http://www.example.org/"); } public void testJAXEN50() throws JaxenException { DOMXPath xpath = new DOMXPath("true()"); SimpleNamespaceContext nsContext = new SimpleNamespaceContext(); // Add all namespace declarations from the node nsContext.addElementNamespaces(xpath.getNavigator(), doc); xpath.setNamespaceContext(nsContext); boolean result = xpath.booleanValueOf(doc); assertTrue(result); } public void testUnresolvableFunction() throws JaxenException { DOMXPath xpath = new DOMXPath("nonesuch()"); try { xpath.evaluate(doc); fail("Evaluated nonexistent function"); } catch (UnresolvableException ex) { assertNotNull(ex.getMessage()); } } public void testUnresolvableFunctionExceptionMessage() throws JaxenException { DOMXPath xpath = new DOMXPath("nonesuch()"); try { xpath.evaluate(doc); fail("Evaluated nonexistent function"); } catch (UnresolvableException ex) { assertEquals(-1, ex.getMessage().indexOf(':')); } } public void testGetFunctionContext() throws JaxenException { DOMXPath xpath = new DOMXPath("/root/child"); assertNotNull(xpath.getFunctionContext()); } public void testSerializeFunctionContext() throws JaxenException, IOException { DOMXPath xpath = new DOMXPath("/root/child"); FunctionContext context = xpath.getFunctionContext(); ByteArrayOutputStream out = new ByteArrayOutputStream(); ObjectOutputStream oout = new ObjectOutputStream(out); try { oout.writeObject(context); fail("serialized function context"); } catch (NotSerializableException ex) { assertNotNull(ex.getMessage()); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/ContextTest.java0000664000175000017500000001360610514521271022653 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import junit.framework.TestCase; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.List; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.jaxen.Context; import org.jaxen.ContextSupport; import org.jaxen.JaxenException; import org.jaxen.XPath; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.SAXException; public class ContextTest extends TestCase { private List nodeSet; private ContextSupport support; public ContextTest(String name) { super( name ); } public void setUp() { this.nodeSet = new ArrayList(); this.nodeSet.add( "one" ); this.nodeSet.add( "two" ); this.nodeSet.add( "three" ); this.nodeSet.add( "four" ); this.support = new ContextSupport(); } public void tearDown() { this.nodeSet = null; } public void testSetNodeSet() { Context original = new Context( this.support ); assertEquals(0, original.getNodeSet().size() ); original.setNodeSet( this.nodeSet ); assertEquals(4, original.getNodeSet().size() ); } public void testShrinkNodeSet() { Context original = new Context( this.support ); original.setNodeSet( this.nodeSet ); original.setPosition(3); ArrayList list = new ArrayList(); list.add("1"); list.add("2"); list.add("3"); original.setNodeSet(list); assertEquals(0, original.getPosition()); } public void testDuplicate() { Context original = new Context( this.support ); original.setNodeSet( this.nodeSet ); original.setSize( 4 ); original.setPosition( 2 ); Context dupe = original.duplicate(); assertEquals(2, dupe.getPosition()); assertEquals(4, dupe.getSize()); assertTrue( original != dupe ); List dupeNodeSet = dupe.getNodeSet(); assertTrue( original.getNodeSet() != dupe.getNodeSet() ); dupeNodeSet.clear(); assertSame( dupeNodeSet, dupe.getNodeSet() ); assertEquals( 0, dupe.getNodeSet().size() ); assertEquals( 4, original.getNodeSet().size() ); dupe.setSize( 0 ); dupe.setPosition( 0 ); assertEquals( 0, dupe.getSize() ); assertEquals( 0, dupe.getPosition() ); assertEquals( 4, original.getSize() ); assertEquals( 2, original.getPosition() ); } public void testXMLPrefixIsAlwaysBound() throws ParserConfigurationException, SAXException, IOException, JaxenException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse( "xml/basic.xml" ); Element root = doc.getDocumentElement(); root.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:lang", "en"); XPath xpath = new DOMXPath( "/*/@xml:lang" ); List result = xpath.selectNodes( doc ); assertEquals(1, result.size()); } public void testIsSerializable() throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(out); oos.writeObject(support); oos.close(); assertTrue(out.toByteArray().length > 0); } } jaxen-1.1.6/src/java/test/org/jaxen/test/UnresolvableExceptionTest.java0000664000175000017500000000713110371471320025543 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.jaxen.JaxenException; import org.jaxen.UnresolvableException; import org.jaxen.XPath; import org.jaxen.dom.DOMXPath; import junit.framework.TestCase; /** * @author Elliotte Rusty Harold * */ public class UnresolvableExceptionTest extends TestCase { public UnresolvableExceptionTest(String name) { super(name); } private org.w3c.dom.Document doc; protected void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); doc = factory.newDocumentBuilder().newDocument(); doc.appendChild(doc.createElement("foo")); } public void testUnresolvableVariable() throws JaxenException { try { XPath xpath = new DOMXPath("//foo[bar = $var]"); xpath.evaluate(doc); fail("Didn't throw Unresolvable Exception"); } catch (UnresolvableException ex) { assertNotNull(ex.getMessage()); } } public void testUnresolvableFunction() throws JaxenException { try { XPath xpath = new DOMXPath("nonesuch()"); xpath.evaluate(doc); fail("Didn't throw Unresolvable Exception"); } catch (UnresolvableException ex) { assertNotNull(ex.getMessage()); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/LocalNameTest.java0000664000175000017500000001462110371471320023060 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.io.IOException; import java.util.List; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.FunctionCallException; import org.jaxen.JaxenException; import org.jaxen.XPath; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Attr; import org.w3c.dom.Comment; import org.w3c.dom.Document; import org.w3c.dom.ProcessingInstruction; import org.w3c.dom.Text; import org.xml.sax.SAXException; /** * @author Elliotte Rusty Harold * */ public class LocalNameTest extends TestCase { private Document doc; public void setUp() throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.parse( "xml/basic.xml" ); } public LocalNameTest(String name) { super(name); } public void testLocalNameOfNumber() throws JaxenException { try { XPath xpath = new DOMXPath( "local-name(3)" ); xpath.selectNodes( doc ); fail("local-name of non-node-set"); } catch (FunctionCallException e) { assertEquals("The argument to the local-name function must be a node-set", e.getMessage()); } } public void testLocalNameWithTwoArguments() throws JaxenException { try { XPath xpath = new DOMXPath( "local-name(/*, //*)" ); xpath.selectNodes( doc ); fail("local-name with two arguments"); } catch (FunctionCallException e) { assertEquals("local-name() requires zero or one argument.", e.getMessage()); } } public void testLocalNameAllowsNoArguments() throws JaxenException { XPath xpath = new DOMXPath( "local-name()" ); String result = (String) xpath.evaluate( doc.getDocumentElement() ); assertEquals("foo", result); } public void testLocalNameOfCommentIsEmptyString() throws JaxenException { XPath xpath = new DOMXPath( "local-name(/comment())" ); Comment c = doc.createComment("test"); doc.appendChild(c); String result = (String) xpath.evaluate(doc); assertEquals("", result); } public void testLocalNameOfEmptyNodeSetIsEmptyString() throws JaxenException { XPath xpath = new DOMXPath( "local-name(/aaa)" ); String result = (String) xpath.evaluate(doc); assertEquals("", result); } public void testLocalNameOfProcessingInstructionIsTarget() throws JaxenException { XPath xpath = new DOMXPath( "local-name(/processing-instruction())" ); ProcessingInstruction pi = doc.createProcessingInstruction("target", "value"); doc.appendChild(pi); String result = (String) xpath.evaluate(doc); assertEquals("target", result); } public void testLocalNameOfAttribute() throws JaxenException { XPath xpath = new DOMXPath( "local-name(/*/@*)" ); Attr a = doc.createAttribute("name"); doc.getDocumentElement().setAttributeNode(a); String result = (String) xpath.evaluate(doc); assertEquals("name", result); } public void testLocalNameOfTextIsEmptyString() throws JaxenException { XPath xpath = new DOMXPath( "local-name(/*/text())" ); Text c = doc.createTextNode("test"); doc.getDocumentElement().appendChild(c); String result = (String) xpath.evaluate(doc); assertEquals("", result); } public void testLocalNameOfNamespaceIsPrefix() throws JaxenException { XPath xpath = new DOMXPath( "local-name(/*/namespace::node())" ); String result = (String) xpath.evaluate(doc); assertEquals("xml", result); } public void testLocalNameNoArguments() { try { XPath xpath = new DOMXPath( "local-name()" ); List results = xpath.selectNodes( doc ); assertEquals("", results.get(0)); } catch (Exception e) { e.printStackTrace(); fail( e.getMessage() ); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/ProcessingInstructionNodeTest.java0000664000175000017500000000673610547741306026432 0ustar ebourgebourg/* * $Header$ * $Revision: 1282 $ * $Date: 2007-01-06 16:39:50 +0100 (Sat, 06 Jan 2007) $ * * ==================================================================== * * Copyright 2007 Elliotte Rusty Harold * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: ProcessingInstructionNodeTest.java 1282 2007-01-06 15:39:50Z elharo $ */ package org.jaxen.test; import javax.xml.parsers.ParserConfigurationException; import org.jaxen.JaxenException; import org.jaxen.dom.DOMXPath; import junit.framework.TestCase; /** *

* Test for processing instruction node-steps. *

* * @author Elliotte Rusty Harold * @version 1.1.1 * */ public class ProcessingInstructionNodeTest extends TestCase { public void testGetText() throws JaxenException, ParserConfigurationException { DOMXPath xpath = new DOMXPath("processing-instruction()"); String expr = xpath.getRootExpr().getText(); assertEquals("child::processing-instruction()", expr); } public void testGetTextWithName() throws JaxenException, ParserConfigurationException { DOMXPath xpath = new DOMXPath("processing-instruction('foo')"); String expr = xpath.getRootExpr().getText(); assertEquals("child::processing-instruction('foo')", expr); } public void testGetTextWithPredicate() throws JaxenException, ParserConfigurationException { DOMXPath xpath = new DOMXPath("processing-instruction('foo')[1 = 1]"); String expr = xpath.getRootExpr().getText(); assertEquals("child::processing-instruction('foo')[(1.0 = 1.0)]", expr); } }jaxen-1.1.6/src/java/test/org/jaxen/test/SimpleNamespaceContextTest.java0000664000175000017500000001331010437564455025651 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005, 2006 Elliotte Rusty Harold * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.HashMap; import java.util.Map; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.jaxen.SimpleNamespaceContext; import org.jaxen.UnsupportedAxisException; import org.w3c.dom.Document; import org.w3c.dom.Element; import junit.framework.TestCase; /** *

* Test for namespace context. *

* * @author Elliotte Rusty Harold * @version 1.1b10 * */ public class SimpleNamespaceContextTest extends TestCase { /** * Need to make sure that changing the map after it's used to create the * namespace context does not affect the context. i.e. * data encapsulation is not violated. */ public void testMapCopy() { Map map = new HashMap(); SimpleNamespaceContext context = new SimpleNamespaceContext(map); map.put("pre", "http://www.example.org/"); assertNull(context.translateNamespacePrefixToUri("pre")); } public void testCantUseNonStringsAsValues() { Map map = new HashMap(); map.put("key", new Object()); try { new SimpleNamespaceContext(map); fail("added non String value to namespace context"); } catch (Exception ex) { assertNotNull(ex.getMessage()); } } public void testCantUseNonStringsAsKeys() { Map map = new HashMap(); map.put(new Object(), "value"); try { new SimpleNamespaceContext(map); fail("added non String key to namespace context"); } catch (Exception ex) { assertNotNull(ex.getMessage()); } } public void testContextFromElement() throws ParserConfigurationException, UnsupportedAxisException { SimpleNamespaceContext context = new SimpleNamespaceContext(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.newDocument(); Element root = doc.createElementNS("http://www.example.org/", "pre:root"); doc.appendChild(root); context.addElementNamespaces(new org.jaxen.dom.DocumentNavigator(), root); assertEquals("http://www.example.org/", context.translateNamespacePrefixToUri("pre")); } public void testSerialization() throws IOException, ClassNotFoundException { // construct test object SimpleNamespaceContext original = new SimpleNamespaceContext(); original.addNamespace("a", "http://www.a.com"); original.addNamespace("b", "http://www.b.com"); // serialize ByteArrayOutputStream out = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(out); oos.writeObject(original); oos.close(); //deserialize byte[] pickled = out.toByteArray(); InputStream in = new ByteArrayInputStream(pickled); ObjectInputStream ois = new ObjectInputStream(in); Object o = ois.readObject(); SimpleNamespaceContext copy = (SimpleNamespaceContext) o; // test the result assertEquals("http://www.a.com", copy.translateNamespacePrefixToUri("a")); assertEquals("http://www.b.com", copy.translateNamespacePrefixToUri("b")); assertEquals("", ""); } } jaxen-1.1.6/src/java/test/org/jaxen/test/CeilingTest.java0000664000175000017500000001107410371471320022576 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.BaseXPath; import org.jaxen.FunctionCallException; import org.jaxen.JaxenException; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; /** * @author Elliotte Rusty Harold * */ public class CeilingTest extends TestCase { private Document doc; public void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.newDocument(); org.w3c.dom.Element a = doc.createElementNS("", "a"); doc.appendChild(a); } public CeilingTest(String name) { super(name); } public void testCeiling() throws JaxenException { BaseXPath xpath = new DOMXPath("ceiling(1.5)"); Object result = xpath.evaluate(doc); assertEquals(2, ((Double) result).doubleValue(), 0.0001); } public void testNegativeCeiling() throws JaxenException { BaseXPath xpath = new DOMXPath("ceiling(-1.5)"); Object result = xpath.evaluate(doc); assertEquals(-1, ((Double) result).doubleValue(), 0.0001); } public void testNaNCeilingIsNaN() throws JaxenException { BaseXPath xpath = new DOMXPath("ceiling(1.0 div 0.0 - 2.0 div 0.0)"); double result = ((Double) xpath.evaluate(doc)).doubleValue(); assertTrue(Double.isNaN(result)); } public void testCeilingFunctionRequiresAtLeastOneArgument() throws JaxenException { BaseXPath xpath = new DOMXPath("ceiling()"); try { xpath.selectNodes(doc); fail("Allowed ceiling function with no arguments"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } public void testCeilingFunctionRequiresAtMostOneArgument() throws JaxenException { BaseXPath xpath = new DOMXPath("ceiling(2.2, 1.2)"); try { xpath.selectNodes(doc); fail("Allowed ceiling function with two arguments"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/ConformanceXPathHandler.java0000664000175000017500000001753210371471320025066 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import org.jaxen.saxpath.XPathHandler; class ConformanceXPathHandler implements XPathHandler { private List events; ConformanceXPathHandler() { this.events = new LinkedList(); } public void startXPath() { addEvent( "startXPath()" ); } public void endXPath() { addEvent( "endXPath()" ); } public void startPathExpr() { addEvent( "startPathExpr()" ); } public void endPathExpr() { addEvent( "endPathExpr()" ); } public void startAbsoluteLocationPath() { addEvent( "startAbsoluteLocationPath()" ); } public void endAbsoluteLocationPath() { addEvent( "endAbsoluteLocationPath()" ); } public void startRelativeLocationPath() { addEvent( "startRelativeLocationPath()" ); } public void endRelativeLocationPath() { addEvent( "endRelativeLocationPath()" ); } public void startNameStep(int axis, String prefix, String localName) { addEvent( "startNameStep(" + axis + ", \"" + prefix + "\", \"" + localName + "\")" ); } public void endNameStep() { addEvent( "endNameStep()" ); } public void startTextNodeStep(int axis) { addEvent( "startTextNodeStep(" + axis + ")" ); } public void endTextNodeStep() { addEvent( "endTextNodeStep()" ); } public void startCommentNodeStep(int axis) { addEvent( "startCommentNodeStep(" + axis + ")" ); } public void endCommentNodeStep() { addEvent( "endCommentNodeStep()" ); } public void startAllNodeStep(int axis) { addEvent( "startAllNodeStep(" + axis + ")" ); } public void endAllNodeStep() { addEvent( "endAllNodeStep()" ); } public void startProcessingInstructionNodeStep(int axis, String name) { addEvent( "startProcessingInstructionNodeStep(" + axis + ", \"" + name + "\")" ); } public void endProcessingInstructionNodeStep() { addEvent( "endProcessingInstructionNodeStep()" ); } public void startPredicate() { addEvent( "startPredicate()" ); } public void endPredicate() { addEvent( "endPredicate()" ); } public void startFilterExpr() { addEvent( "startFilterExpr()" ); } public void endFilterExpr() { addEvent( "endFilterExpr()" ); } public void startOrExpr() { addEvent( "startOrExpr()" ); } public void endOrExpr(boolean create) { addEvent( "endOrExpr(" + create + ")" ); } public void startAndExpr() { addEvent( "startAndExpr()" ); } public void endAndExpr(boolean create) { addEvent( "endAndExpr(" + create + ")" ); } public void startEqualityExpr() { addEvent( "startEqualityExpr()" ); } public void endEqualityExpr(int operator) { addEvent( "endEqualityExpr(" + operator + ")" ); } public void startRelationalExpr() { addEvent( "startRelationalExpr()" ); } public void endRelationalExpr(int operator) { addEvent( "endRelationalExpr(" + operator + ")" ); } public void startAdditiveExpr() { addEvent( "startAdditiveExpr()" ); } public void endAdditiveExpr(int operator) { addEvent( "endAdditiveExpr(" + operator + ")" ); } public void startMultiplicativeExpr() { addEvent( "startMultiplicativeExpr()" ); } public void endMultiplicativeExpr(int operator) { addEvent( "endMultiplicativeExpr(" + operator + ")" ); } public void startUnaryExpr() { addEvent( "startUnaryExpr()" ); } public void endUnaryExpr(int operator) { addEvent( "endUnaryExpr(" + operator + ")" ); } public void startUnionExpr() { addEvent( "startUnionExpr()" ); } public void endUnionExpr(boolean create) { addEvent( "endUnionExpr(" + create + ")" ); } public void number(int number) { addEvent( "number(" + number + ")" ); } public void number(double number) { addEvent( "number(" + number + ")" ); } public void literal(String literal) { addEvent( "literal(\"" + literal + "\")" ); } public void variableReference(String prefix, String variableName) { addEvent( "variableReference(\"" + prefix + ":" + variableName + "\")" ); } public void startFunction(String prefix, String functionName) { addEvent( "startFunction(\"" + prefix + ":" + functionName + "\")" ); } public void endFunction() { addEvent( "endFunction()" ); } private void addEvent(String eventStr) { this.events.add( eventStr ); } public boolean equals(Object thatObj) { if ( thatObj instanceof ConformanceXPathHandler ) { ConformanceXPathHandler that = (ConformanceXPathHandler) thatObj; return ( this.events.equals( that.events ) ); } return false; } public int hashCode() { return this.events.hashCode(); } public String toString() { Iterator eventIter = this.events.iterator(); int i = 0; StringBuffer buf = new StringBuffer(); while( eventIter.hasNext() ) { buf.append("(").append(i).append(") ").append( eventIter.next().toString() ).append("\n"); ++i; } return buf.toString(); } } jaxen-1.1.6/src/java/test/org/jaxen/test/StringLengthTest.java0000664000175000017500000001254011004755326023640 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.BaseXPath; import org.jaxen.FunctionCallException; import org.jaxen.JaxenException; import org.jaxen.XPath; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; /** * @author Elliotte Rusty Harold * */ public class StringLengthTest extends TestCase { private Document doc; public void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.newDocument(); doc.appendChild(doc.createElement("root")); } public StringLengthTest(String name) { super(name); } public void testStringLengthOfNumber() throws JaxenException { XPath xpath = new DOMXPath( "string-length(3)" ); Double result = (Double) xpath.evaluate( doc ); assertEquals(1, result.intValue()); } public void testStringLengthOfEmptyString() throws JaxenException { XPath xpath = new DOMXPath( "string-length('')" ); Double result = (Double) xpath.evaluate( doc ); assertEquals(0, result.intValue()); } public void testStringLengthOfString() throws JaxenException { XPath xpath = new DOMXPath( "string-length('0123456789')" ); Double result = (Double) xpath.evaluate( doc ); assertEquals(10, result.intValue()); } public void testStringLengthFunctionOperatesOnContextNode() throws JaxenException { BaseXPath xpath = new DOMXPath("string-length()"); Double result = (Double) xpath.evaluate( doc ); assertEquals(0, result.intValue()); } public void testStringLengthWithPrivateUseChars() throws JaxenException { XPath xpath = new DOMXPath( "string-length('ab\uE000\uE001')" ); Double result = (Double) xpath.evaluate( doc ); assertEquals(4, result.intValue()); } public void testStringLengthFunctionCountsUnicodeCharactersNotJavaChars() throws JaxenException { BaseXPath xpath = new DOMXPath("string-length('\uD834\uDD00')"); Double result = (Double) xpath.evaluate( doc ); assertEquals(1, result.intValue()); } public void testStringLengthFunctionWithMalformedString() throws JaxenException { BaseXPath xpath = new DOMXPath("string-length('\uD834A\uDD00')"); try { xpath.evaluate( doc ); fail("Allowed Malformed string"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } public void testStringLengthFunctionRequiresExactlyOneArgument() throws JaxenException { BaseXPath xpath = new DOMXPath("string-length('', '')"); try { xpath.selectNodes(doc); fail("Allowed string-length function with two arguments"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/XOMTests.java0000664000175000017500000000505510371471320022054 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import junit.framework.Test; import junit.framework.TestSuite; /** *

* Collect Jaxen's XOM tests. *

* * @author Elliotte Rusty Harold * @version 1.1b9 * */ public class XOMTests { public static Test suite() { TestSuite result = new TestSuite(); result.addTest(new TestSuite(XOMNavigatorTest.class)); result.addTest(new TestSuite(XOMXPathTest.class)); return result; } }jaxen-1.1.6/src/java/test/org/jaxen/test/DOMXPathTest.java0000664000175000017500000005022011751607254022616 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2000-2003 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import junit.framework.TestCase; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.Iterator; import java.util.List; import org.jaxen.JaxenException; import org.jaxen.SimpleVariableContext; import org.jaxen.XPath; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.xml.sax.SAXException; public class DOMXPathTest extends TestCase { private static final String BASIC_XML = "xml/basic.xml"; private Document doc; private DocumentBuilderFactory factory; public DOMXPathTest(String name) { super( name ); } public void setUp() throws ParserConfigurationException { factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); doc = factory.newDocumentBuilder().newDocument(); } // Jaxen-221 public void testTimSort() throws ParserConfigurationException, JaxenException { Element root = doc.createElement("root"); doc.appendChild(root); // need at least 32 of each to trigger the bug for (int i = 0; i < 32; i++) { root.setAttribute("att" + i, "one"); } for (int i = 0; i < 32; i++) { root.appendChild(doc.createElement("child")); } XPath xp = new DOMXPath("//@*[string() = 'one'] | //* "); xp.evaluate(doc); } public void testNamespaceNodesPrecedeAttributeNodes() throws ParserConfigurationException, JaxenException { Element root = doc.createElementNS("http://www.example.org/", "root"); doc.appendChild(root); root.setAttribute("att", "one"); XPath xp = new DOMXPath("//@* | //namespace::* "); List result = (List) xp.evaluate(doc); assertEquals(3, result.size()); Node third = (Node) result.get(2); assertEquals(Node.ATTRIBUTE_NODE, third.getNodeType()); } public void testNamespaceNodesPrecedeAttributeNodes2() throws ParserConfigurationException, JaxenException { Element root = doc.createElementNS("http://www.example.org/", "root"); doc.appendChild(root); root.setAttribute("att", "one"); XPath xp = new DOMXPath("//namespace::* | //@* "); List result = (List) xp.evaluate(doc); assertEquals(3, result.size()); Node third = (Node) result.get(2); assertEquals(Node.ATTRIBUTE_NODE, third.getNodeType()); } public void testConstruction() throws JaxenException { DOMXPath xpath = new DOMXPath( "/foo/bar/baz" ); assertEquals("/foo/bar/baz", xpath.toString()); } public void testJaxen193() throws JaxenException { DOMXPath xpath = new DOMXPath( "/*[ * or processing-instruction() ]" ); assertEquals("/*[ * or processing-instruction() ]", xpath.toString()); } public void testJaxen193InReverse() throws JaxenException { DOMXPath xpath = new DOMXPath( "/*[ processing-instruction() or *]" ); assertEquals("/*[ processing-instruction() or *]", xpath.toString()); } public void testConstructionWithNamespacePrefix() throws JaxenException { DOMXPath xpath = new DOMXPath( "/p:foo/p:bar/a:baz" ); assertEquals("/p:foo/p:bar/a:baz", xpath.toString()); } public void testNamespaceDeclarationsAreNotAttributes() throws JaxenException { Element root = doc.createElementNS("http://www.example.org/", "root"); doc.appendChild(root); root.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", "http://www.example.org/"); DOMXPath xpath = new DOMXPath( "count(/*/@*)" ); Number value = xpath.numberValueOf(doc); assertEquals(0, value.intValue()); } public void testFunctionWithNamespace() throws IOException, JaxenException { Element root = doc.createElementNS("http://www.example.org/", "root"); doc.appendChild(root); XPath xpath = new DOMXPath("//*[not(self::pre:test)]"); xpath.addNamespace("pre", "http://www.example.org/"); xpath.addNamespace("", "http://www.example.org/"); List result = xpath.selectNodes(doc); assertEquals(1, result.size()); } public void testVariableWithNamespace() throws IOException, JaxenException { Element root = doc.createElementNS("http://www.example.org/", "root"); doc.appendChild(root); XPath xpath = new DOMXPath("//*[not($foo)]"); SimpleVariableContext variables = new SimpleVariableContext(); variables.setVariableValue("foo", "bar"); xpath.setVariableContext(variables); xpath.addNamespace("", "http://www.example.org/"); List result = xpath.selectNodes(doc); assertEquals(0, result.size()); } public void testElementWithoutNamespace() throws IOException, JaxenException { Element root = doc.createElement("root"); doc.appendChild(root); XPath xpath = new DOMXPath("//root"); xpath.addNamespace("", "http://www.example.org/"); List result = xpath.selectNodes(doc); assertEquals(1, result.size()); } // see JAXEN-214 public void testAttributeNodesDontHaveChildren() throws JaxenException { Element root = doc.createElement("root"); doc.appendChild(root); root.setAttribute("name", "value"); XPath xpath = new DOMXPath("//@*/text()"); List result = xpath.selectNodes(doc); assertEquals(0, result.size()); } // see JAXEN-105 public void testConsistentNamespaceDeclarations() throws JaxenException { Element root = doc.createElement("root"); doc.appendChild(root); Element child = doc.createElementNS("http://www.example.org", "foo:child"); root.appendChild(child); // different prefix child.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:foo2", "http://www.contradictory.org"); XPath xpath = new DOMXPath("//namespace::node()"); List result = xpath.selectNodes(doc); assertEquals(4, result.size()); } // see JAXEN-105 public void testInconsistentNamespaceDeclarations() throws JaxenException { Element root = doc.createElement("root"); doc.appendChild(root); Element child = doc.createElementNS("http://www.example.org", "foo:child"); root.appendChild(child); // same prefix child.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:foo", "http://www.contradictory.org"); XPath xpath = new DOMXPath("//namespace::node()"); List result = xpath.selectNodes(doc); assertEquals(3, result.size()); } // see JAXEN-105 public void testIntrinsicNamespaceDeclarationOfElementBeatsContradictoryXmlnsPreAttr() throws JaxenException { Element root = doc.createElement("root"); doc.appendChild(root); Element child = doc.createElementNS("http://www.example.org", "foo:child"); root.appendChild(child); // same prefix child.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:foo", "http://www.contradictory.org"); XPath xpath = new DOMXPath("//namespace::node()[name(.)='foo']"); List result = xpath.selectNodes(doc); assertEquals(1, result.size()); Node node = (Node) result.get(0); assertEquals("http://www.example.org", node.getNodeValue()); } // see JAXEN-105 public void testIntrinsicNamespaceDeclarationOfAttrBeatsContradictoryXmlnsPreAttr() throws JaxenException { Element root = doc.createElement("root"); doc.appendChild(root); root.setAttributeNS("http://www.example.org/", "foo:a", "value"); // same prefix, different namespace root.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:foo", "http://www.contradictory.org"); XPath xpath = new DOMXPath("//namespace::node()[name(.)='foo']"); List result = xpath.selectNodes(doc); assertEquals(1, result.size()); Node node = (Node) result.get(0); assertEquals("http://www.example.org/", node.getNodeValue()); } // see JAXEN-105 public void testIntrinsicNamespaceDeclarationOfElementBeatsContradictoryIntrinsicNamespaceOfAttr() throws JaxenException { Element root = doc.createElementNS("http://www.example.org", "pre:root"); doc.appendChild(root); // same prefix root.setAttributeNS("http://www.contradictory.org", "pre:foo", "value"); XPath xpath = new DOMXPath("//namespace::node()[name(.)='pre']"); List result = xpath.selectNodes(doc); assertEquals(1, result.size()); Node node = (Node) result.get(0); assertEquals("http://www.example.org", node.getNodeValue()); } // Jaxen-54 public void testUpdateDOMNodesReturnedBySelectNodes() throws JaxenException { Element root = doc.createElementNS("http://www.example.org/", "root"); doc.appendChild(root); root.appendChild(doc.createComment("data")); DOMXPath xpath = new DOMXPath( "//comment()" ); List results = xpath.selectNodes(doc); Node backroot = (Node) results.get(0); backroot.setNodeValue("test"); assertEquals("test", backroot.getNodeValue()); } public void testSelection() throws JaxenException, ParserConfigurationException, SAXException, IOException { XPath xpath = new DOMXPath( "/foo/bar/baz" ); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse( BASIC_XML ); List results = xpath.selectNodes( document ); assertEquals( 3, results.size() ); Iterator iter = results.iterator(); assertEquals( "baz", ((Element)iter.next()).getLocalName() ); assertEquals( "baz", ((Element)iter.next()).getLocalName() ); assertEquals( "baz", ((Element)iter.next()).getLocalName() ); assertTrue( ! iter.hasNext() ); } // Jaxen-22 public void testPrecedingAxisWithPositionalPredicate() throws JaxenException, ParserConfigurationException, SAXException, IOException { XPath xpath = new DOMXPath( "//c/preceding::*[1][name()='d']" ); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse( "xml/web2.xml" ); List result = xpath.selectNodes(document); assertEquals(1, result.size()); } // Jaxen-22 public void testJaxen22() throws JaxenException, ParserConfigurationException, SAXException, IOException { XPath xpath = new DOMXPath( "name(//c/preceding::*[1])" ); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.parse("xml/web2.xml"); Object result = xpath.evaluate(doc); assertEquals("d", result); } public void testJaxen207() throws JaxenException { XPath xpath = new DOMXPath( "contains($FinResp, \"NS_Payables_Associate\") or" + "contains($FinResp, \"NS_Payables_Manager\") or" + "contains($FinResp, \"NS_Payment_Processing\") or" + "contains($FinResp, \"NS_Vendor_Maintenance\") or" + "contains($FinResp, \"NS_IB_Receivables_Manager\") or" + "contains($FinResp, \"NS_IB_Receivables_User\") or" + "contains($FinResp, \"NS_Receivables_Manager\") or" + "contains($FinResp, \"NS_Receivables_User\") or" + "contains($FinResp, \"NS_Cash_Management_User\") or" + "contains($FinResp, \"NS_Cost_Management\") or" + "contains($FinResp, \"NS_Fixed_Assets_Manager\") or" + "contains($FinResp, \"NS_Fixed_Asset_User\") or" + "contains($FinResp, \"NS_General_Ledger_Inquiry\") or" + "contains($FinResp, \"NS_General_Ledger_User\") or" + "contains($FinResp, \"NS_General_Ledger_Supervisor\") or" + "contains($FinResp, \"NS_IB_General_Ledger_User\") or" + "contains($FinResp, \"NS_IB_Oracle_Web_ADI\") or" + "contains($FinResp, \"NS_Oracle_Web_ADI\") or" + "contains($FinResp, \"NS_CRM_Resource_Manager\") or" + "contains($FinResp, \"NS_Distributor_Manager\") or" + "contains($FinResp, \"NS_OIC_User\") or" + "contains($FinResp, \" NS_Operations_Buyer\") or" + "contains($FinResp, \"NS_Purchasing_Buyer\") or" + "contains($FinResp, \"NS_Vendor_Maintenance\") or " + "contains($FinResp, \"SL_Payables_Manager\") or" + "contains($FinResp, \"SL_Payables_Super_User\") or" + "contains($FinResp, \"SL_Payment_Processing\") or" + "contains($FinResp, \"SL_Vendor_Maintenance\") or" + "contains($InvResp, \"SL_Inventory_Super_User\") or" + "contains($FinResp, \"\") or" + "contains($FinResp, \"SL_Receivables_Supervisor\") or" + "contains($FinResp, \"SL_Receivables_User\") or" + "contains($FinResp, \"NS_Cost_Management_Inquiry\") or" + "contains($FinResp, \"SL_Fixed_Asset_User\") or" + "contains($FinResp, \"SL_Fixed_Assets_Manager\") or" + "contains($FinResp, \"SL_General_Ledger_Inquiry\") or" + "contains($FinResp, \"SL_General_Ledger_Supervisor\") or" + "contains($FinResp, \"SL_General_Ledger_User\") or" + "contains($FinResp, \"SL_Oracle_Web_ADI\") or" + "contains($FinResp, \"SL_Buyer\") or" + "contains($FinResp, \"SL_Purchasing_Inquiry\") or" + "contains($FinResp, \"SL_Payables_Manager\") or" + "contains($FinResp, \"SL_Payables_Super_User\") or" + "contains($FinResp, \"SL_Payment_Processing\") or" + "contains($FinResp, \"SL_Vendor_Maintenance\") or" + "contains($InvResp, \"SL_Inventory_Super_User\") or" + "contains($FinResp, \"\") or" + "contains($FinResp, \"SL_Receivables_Supervisor\") or" + "contains($FinResp, \"SL_Receivables_User\") or" + "contains($FinResp, \"NS_Cost_Management_Inquiry\") or" + "contains($FinResp, \"SL_Fixed_Asset_User\") or" + "contains($FinResp, \"SL_Fixed_Assets_Manager\") or" + "contains($FinResp, \"SL_General_Ledger_Inquiry\") or" + "contains($FinResp, \"SL_General_Ledger_Supervisor\") or" + "contains($FinResp, \"SL_General_Ledger_User\") or" + "contains($FinResp, \"SL_Oracle_Web_ADI\") or" + "contains($FinResp, \"SL_Buyer\") or" + "contains($FinResp, \"SL_Purchasing_Inquiry\")"); } public void testImplictCastFromTextInARelationalExpression() throws JaxenException, ParserConfigurationException, SAXException, IOException { XPath implicitCast = new DOMXPath("//lat[(text() >= 37)]"); XPath explicitCast = new DOMXPath("//lat[(number(text()) >= 37)]"); DocumentBuilder builder = factory.newDocumentBuilder(); ByteArrayInputStream in = new ByteArrayInputStream("39".getBytes("UTF-8")); Document document = builder.parse(in); List result = explicitCast.selectNodes(document); assertEquals(1, result.size()); result = implicitCast.selectNodes(document); assertEquals(1, result.size()); } public void testImplictCastFromCommentInARelationalExpression() throws JaxenException, ParserConfigurationException, SAXException, IOException { XPath implicitCast = new DOMXPath("//lat[(comment() >= 37)]"); XPath explicitCast = new DOMXPath("//lat[(number(comment()) >= 37)]"); DocumentBuilder builder = factory.newDocumentBuilder(); ByteArrayInputStream in = new ByteArrayInputStream("".getBytes("UTF-8")); Document document = builder.parse(in); List result = explicitCast.selectNodes(document); assertEquals(1, result.size()); result = implicitCast.selectNodes(document); assertEquals(1, result.size()); } public void testImplictCastFromProcessingInstructionInARelationalExpression() throws JaxenException, ParserConfigurationException, SAXException, IOException { XPath implicitCast = new DOMXPath("//lat[(processing-instruction() >= 37)]"); XPath explicitCast = new DOMXPath("//lat[(number(processing-instruction()) >= 37)]"); DocumentBuilder builder = factory.newDocumentBuilder(); ByteArrayInputStream in = new ByteArrayInputStream("".getBytes("UTF-8")); Document document = builder.parse(in); List result = explicitCast.selectNodes(document); assertEquals(1, result.size()); result = implicitCast.selectNodes(document); assertEquals(1, result.size()); } public void testPrecedingAxisInDocumentOrder() throws JaxenException { XPath xpath = new DOMXPath( "preceding::*" ); Element root = doc.createElement("root"); doc.appendChild(root); Element a = doc.createElement("a"); root.appendChild(a); Element b = doc.createElement("b"); root.appendChild(b); Element c = doc.createElement("c"); a.appendChild(c); List result = xpath.selectNodes(b); assertEquals(2, result.size()); assertEquals(a, result.get(0)); assertEquals(c, result.get(1)); } } jaxen-1.1.6/src/java/test/org/jaxen/test/FloorTest.java0000664000175000017500000001214510371471320022305 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.BaseXPath; import org.jaxen.FunctionCallException; import org.jaxen.JaxenException; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; /** * @author Elliotte Rusty Harold * */ public class FloorTest extends TestCase { private Document doc; public void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.newDocument(); org.w3c.dom.Element a = doc.createElementNS("", "a"); doc.appendChild(a); } public FloorTest(String name) { super(name); } public void testFloor() throws JaxenException { BaseXPath xpath = new DOMXPath("floor(1.5)"); Object result = xpath.evaluate(doc); assertEquals(1, ((Double) result).doubleValue(), 0.0001); } public void testNegativeFloor() throws JaxenException { BaseXPath xpath = new DOMXPath("floor(-1.5)"); Object result = xpath.evaluate(doc); assertEquals(-2, ((Double) result).doubleValue(), 0.0001); } public void testNaNFloorIsNaN() throws JaxenException { BaseXPath xpath = new DOMXPath("floor(1.0 div 0.0 - 2.0 div 0.0)"); double result = ((Double) xpath.evaluate(doc)).doubleValue(); assertTrue(Double.isNaN(result)); } public void testInfFloorIsInf() throws JaxenException { BaseXPath xpath = new DOMXPath("floor(1.0 div 0.0)"); double result = ((Double) xpath.evaluate(doc)).doubleValue(); assertTrue(Double.isInfinite(result)); assertTrue(result > 0); } public void testNegativeInfFloorIsNegativeInf() throws JaxenException { BaseXPath xpath = new DOMXPath("floor(-1.0 div 0.0)"); double result = ((Double) xpath.evaluate(doc)).doubleValue(); assertTrue(Double.isInfinite(result)); assertTrue(result < 0); } public void testFloorFunctionRequiresAtLeastArgument() throws JaxenException { BaseXPath xpath = new DOMXPath("floor()"); try { xpath.selectNodes(doc); fail("Allowed floor function with no arguments"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } public void testBooleanFunctionRequiresExactlyOneArgument() throws JaxenException { BaseXPath xpath = new DOMXPath("floor(2.2, 1.2)"); try { xpath.selectNodes(doc); fail("Allowed floor function with two arguments"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/XPathReaderFactoryTest.java0000664000175000017500000001160010371471320024716 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import junit.framework.TestCase; import org.jaxen.saxpath.SAXPathException; import org.jaxen.saxpath.XPathReader; import org.jaxen.saxpath.helpers.XPathReaderFactory; public class XPathReaderFactoryTest extends TestCase { public XPathReaderFactoryTest(String name) { super( name ); } protected void tearDown() { System.setProperty( XPathReaderFactory.DRIVER_PROPERTY, "" ); } public void testDefault() throws SAXPathException { System.setProperty( XPathReaderFactory.DRIVER_PROPERTY, "" ); XPathReader reader = XPathReaderFactory.createReader(); assertNotNull( reader ); } public void testValidByProperty() throws SAXPathException { System.setProperty( XPathReaderFactory.DRIVER_PROPERTY, "org.jaxen.test.MockXPathReader" ); XPathReader reader = XPathReaderFactory.createReader(); assertNotNull( reader ); assertSame( MockXPathReader.class, reader.getClass() ); } public void testInvalidByProperty() { System.setProperty( XPathReaderFactory.DRIVER_PROPERTY, "java.lang.String" ); try { XPathReaderFactory.createReader(); fail( "Should have thrown SAXPathException" ); } catch (SAXPathException e) { // expected and correct assertNotNull(e.getMessage()); } } public void testNonExistantByProperty() { System.setProperty( XPathReaderFactory.DRIVER_PROPERTY, "i.am.a.class.that.does.not.Exist" ); try { XPathReaderFactory.createReader(); fail( "Should have thrown SAXPathException" ); } catch (org.jaxen.saxpath.SAXPathException e) { // expected and correct } } public void testValidExplicit() throws SAXPathException { XPathReader reader = XPathReaderFactory.createReader( "org.jaxen.test.MockXPathReader" ); assertNotNull( reader ); assertSame( MockXPathReader.class, reader.getClass() ); } public void testInvalidExplicit() { try { XPathReaderFactory.createReader( "java.lang.String" ); fail( "Should have thrown SAXPathException" ); } catch (org.jaxen.saxpath.SAXPathException e) { // expected and correct } } public void testNonExistantExplicit() { try { XPathReaderFactory.createReader( "i.am.a.class.that.does.not.Exist" ); fail( "Should have thrown SAXPathException" ); } catch (org.jaxen.saxpath.SAXPathException e) { // expected and correct } } } jaxen-1.1.6/src/java/test/org/jaxen/test/CoreTests.java0000664000175000017500000000735411102333372022302 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; /** *

* Collect the org.jaxen. tests. *

* * @author Elliotte Rusty Harold * @version 1.1.2 * */ public class CoreTests extends TestCase { public CoreTests(String name) { super(name); } public static Test suite() { TestSuite result = new TestSuite(); result.addTest(new TestSuite(AddNamespaceTest.class)); result.addTest(new TestSuite(BaseXPathTest.class)); result.addTest(new TestSuite(FunctionContextTest.class)); result.addTest(new TestSuite(SimpleNamespaceContextTest.class)); result.addTest(new TestSuite(ContextTest.class)); result.addTest(new TestSuite(JaxenHandlerTest.class)); result.addTest(new TestSuite(JaxenRuntimeExceptionTest.class)); result.addTest(new TestSuite(FunctionCallExceptionTest.class)); result.addTest(new TestSuite(UnresolvableExceptionTest.class)); result.addTest(new TestSuite(VariableContextTest.class)); result.addTest(new TestSuite(SimpleNamespaceContextTest.class)); result.addTest(new TestSuite(XPathSyntaxExceptionTest.class)); result.addTest(new TestSuite(UnsupportedAxisExceptionTest.class)); result.addTest(new TestSuite(JaxenExceptionTest.class)); result.addTest(new TestSuite(ArithmeticTest.class)); result.addTest(new TestSuite(IterableAxisTest.class)); result.addTest(new TestSuite(DefaultXPathFactoryTest.class)); result.addTest(new TestSuite(NodesetEqualityTest.class)); return result; } }jaxen-1.1.6/src/java/test/org/jaxen/test/MockXPathReader.java0000664000175000017500000000465610371471320023355 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import org.jaxen.saxpath.XPathHandler; import org.jaxen.saxpath.XPathReader; public class MockXPathReader implements XPathReader { public void parse(String xpath) { } public void setXPathHandler(XPathHandler handler) { } public XPathHandler getXPathHandler() { return null; } } jaxen-1.1.6/src/java/test/org/jaxen/test/ConcatTest.java0000664000175000017500000000653210371471320022436 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.BaseXPath; import org.jaxen.FunctionCallException; import org.jaxen.JaxenException; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Document; /** * @author Elliotte Rusty Harold * */ public class ConcatTest extends TestCase { private Document doc; public void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.newDocument(); doc.appendChild(doc.createElement("root")); } public ConcatTest(String name) { super(name); } public void testConcatFunctionRequiresAtLeastTwoArguments() throws JaxenException { BaseXPath xpath = new DOMXPath("concat('a')"); try { xpath.selectNodes(doc); fail("Allowed concat function with one argument"); } catch (FunctionCallException ex) { assertNotNull(ex.getMessage()); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/DOM4JTests.java0000664000175000017500000000506210371471320022224 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import junit.framework.Test; import junit.framework.TestSuite; /** *

* Collect Jaxen's dom4j tests. *

* * @author Elliotte Rusty Harold * @version 1.1b9 * */ public class DOM4JTests { public static Test suite() { TestSuite result = new TestSuite(); result.addTest(new TestSuite(DOM4JNavigatorTest.class)); result.addTest(new TestSuite(DOM4JXPathTest.class)); return result; } }jaxen-1.1.6/src/java/test/org/jaxen/test/PriorityTest.java0000664000175000017500000001102010371471320023034 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import junit.textui.TestRunner; import org.jaxen.JaxenException; import org.jaxen.pattern.Pattern; import org.jaxen.pattern.PatternParser; import org.jaxen.saxpath.SAXPathException; import org.jaxen.saxpath.helpers.XPathReaderFactory; /** Tests the use of priority in the Pattern implementations. * * @author
James Strachan * @version $Revision$ */ public class PriorityTest extends TestCase { public PriorityTest(String name) { super( name ); } public static void main(String[] args) { TestRunner.run( suite() ); } public static Test suite() { return new TestSuite( PriorityTest.class ); } public void setUp() { System.setProperty( XPathReaderFactory.DRIVER_PROPERTY, "" ); } public void testDocumentNode() throws Exception { testPriority( "/", -0.5, Pattern.DOCUMENT_NODE ); } public void testNameNode() throws Exception { testPriority( "foo", 0, Pattern.ELEMENT_NODE ); } public void testQNameNode() throws Exception { testPriority( "foo:bar", 0, Pattern.ELEMENT_NODE ); } public void testFilter() throws Exception { testPriority( "foo[@id='123']", 0.5, Pattern.ELEMENT_NODE ); } public void testURI() throws Exception { testPriority( "foo:*", -0.25, Pattern.ELEMENT_NODE ); } public void testNodeType() throws Exception { testPriority( "text()", -0.5, Pattern.TEXT_NODE ); } public void testAttribute() throws Exception { testPriority( "@*", -0.5, Pattern.ATTRIBUTE_NODE ); } public void testAnyNode() throws Exception { testPriority( "*", -0.5, Pattern.ELEMENT_NODE ); } protected void testPriority(String expr, double priority, short nodeType) throws JaxenException, SAXPathException { Pattern pattern = PatternParser.parse( expr ); double d = pattern.getPriority(); short nt = pattern.getMatchType(); assertEquals( "expr: " + expr, new Double( priority ), new Double( d ) ); assertEquals( "nodeType: " + expr, nodeType, nt ); } } jaxen-1.1.6/src/java/test/org/jaxen/test/IdTest.java0000664000175000017500000001704310371471320021562 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.io.IOException; import java.io.StringReader; import java.util.List; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.TestCase; import org.jaxen.BaseXPath; import org.jaxen.FunctionCallException; import org.jaxen.JaxenException; import org.jaxen.dom.DOMXPath; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.InputSource; import org.xml.sax.SAXException; /** * @author Elliotte Rusty Harold * */ public class IdTest extends TestCase { private Document doc; private DocumentBuilder builder; public void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); builder = factory.newDocumentBuilder(); doc = builder.newDocument(); } public IdTest(String name) { super(name); } public void testIDFunctionSelectsNothingInDocumentWithNoIds() throws JaxenException { BaseXPath xpath = new DOMXPath("id('p1')"); org.w3c.dom.Element a = doc.createElementNS("", "a"); org.w3c.dom.Element b = doc.createElementNS("", "b"); doc.appendChild(a); a.appendChild(b); org.w3c.dom.Element x2 = doc.createElementNS("", "x"); org.w3c.dom.Element x3 = doc.createElementNS("", "x"); org.w3c.dom.Element x4 = doc.createElementNS("", "x"); a.appendChild(x4); b.appendChild(x2); b.appendChild(x3); x2.appendChild(doc.createTextNode("2")); x3.appendChild(doc.createTextNode("3")); x4.appendChild(doc.createTextNode("4")); Attr id = doc.createAttribute("id"); id.setNodeValue("p1"); x2.setAttributeNode(id); List result = xpath.selectNodes(doc); assertEquals(0, result.size()); } public void testIDFunctionRequiresAtLeastOneArgument() throws JaxenException { try { BaseXPath xpath = new DOMXPath("id()"); org.w3c.dom.Element a = doc.createElementNS("", "a"); doc.appendChild(a); xpath.selectNodes(doc); fail("Allowed empty id() function"); } catch (FunctionCallException success) { assertNotNull(success.getMessage()); } } public void testIDFunctionRequiresAtMostOneArgument() throws JaxenException { try { BaseXPath xpath = new DOMXPath("id('p', 'q')"); org.w3c.dom.Element a = doc.createElementNS("", "a"); doc.appendChild(a); xpath.selectNodes(doc); fail("Allowed two-argument id() function"); } catch (FunctionCallException success) { assertNotNull(success.getMessage()); } } public void testFindElementById() throws JaxenException, SAXException, IOException { BaseXPath xpath = new DOMXPath("id('p1')"); String text = "]>"; StringReader reader = new StringReader(text); InputSource in = new InputSource(reader); Document doc = builder.parse(in); List result = xpath.selectNodes(doc); assertEquals(1, result.size()); Element a = (Element) result.get(0); assertEquals("a", a.getNodeName()); } /* public void testFindElementByXMLId() throws JaxenException, SAXException, IOException { BaseXPath xpath = new DOMXPath("id('p1')"); String text = ""; StringReader reader = new StringReader(text); InputSource in = new InputSource(reader); Document doc = builder.parse(in); List result = xpath.selectNodes(doc); assertEquals(1, result.size()); Element a = (Element) result.get(0); assertEquals("a", a.getNodeName()); } */ public void testFindMultipleElementsByMultipleIDs() throws JaxenException, SAXException, IOException { BaseXPath xpath = new DOMXPath("id(//id)"); String text = "]>p1p2p3"; StringReader reader = new StringReader(text); InputSource in = new InputSource(reader); Document doc = builder.parse(in); List result = xpath.selectNodes(doc); assertEquals(2, result.size()); Element a1 = (Element) result.get(0); Element a2 = (Element) result.get(1); assertEquals("a", a1.getNodeName()); assertEquals("a", a2.getNodeName()); } public void testIdReturnsFirstElementWithMatchingId() throws JaxenException, SAXException, IOException { BaseXPath xpath = new DOMXPath("id('p1')"); String text = "" + "]>"; StringReader reader = new StringReader(text); InputSource in = new InputSource(reader); Document doc = builder.parse(in); List result = xpath.selectNodes(doc); assertEquals(1, result.size()); Element a = (Element) result.get(0); assertEquals("a", a.getNodeName()); } } jaxen-1.1.6/src/java/test/org/jaxen/test/AncestorOrSelfAxisIteratorTest.java0000664000175000017500000000667210371471320026464 0ustar ebourgebourg/* $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.util.Iterator; import java.util.NoSuchElementException; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.jaxen.util.AncestorOrSelfAxisIterator; import org.w3c.dom.Document; import junit.framework.TestCase; public class AncestorOrSelfAxisIteratorTest extends TestCase { private Iterator iterator; public AncestorOrSelfAxisIteratorTest(String name) { super(name); } protected void setUp() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); Document doc = factory.newDocumentBuilder().newDocument(); doc.appendChild(doc.createElement("root")); iterator = new AncestorOrSelfAxisIterator(doc, new org.jaxen.dom.DocumentNavigator()); } public void testNoInfiniteLoops() { iterator.next(); try { iterator.next(); fail("Iterated twice"); } catch (NoSuchElementException ex) { } } public void testRemove() { try { iterator.remove(); fail("Removed from iterator"); } catch (UnsupportedOperationException ex) { } } } jaxen-1.1.6/src/java/test/org/jaxen/test/DOM4JPerformance.java0000664000175000017500000000476210371471320023371 0ustar ebourgebourg/* $Id$ Copyright 2003 The Werken Company. All Rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Jaxen Project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.jaxen.test; import java.net.URL; import org.dom4j.Document; import org.dom4j.Element; import org.dom4j.io.SAXReader; import org.jaxen.dom4j.Dom4jXPath; class DOM4JPerformance { public static void main(String[] args) { try { URL u = new URL("http://www.ibiblio.org/xml/examples/shakespeare/much_ado.xml"); Document doc = new SAXReader().read(u); Dom4jXPath xpath = new Dom4jXPath("PLAY/ACT/SCENE/SPEECH/SPEAKER"); long start = System.currentTimeMillis(); int count = 0; for (int i = 0; i < 1000; i++) { Element speaker = (Element) xpath.selectSingleNode(doc); count += (speaker == null ? 0 : 1); } long end = System.currentTimeMillis(); System.out.println((end - start)); System.out.println(count); } catch (Exception ex) { ex.printStackTrace(); } } } jaxen-1.1.6/src/java/test/org/jaxen/test/SingleObjectIteratorTest.java0000664000175000017500000000550210371471320025305 0ustar ebourgebourg/* $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.util.Iterator; import java.util.NoSuchElementException; import org.jaxen.util.SingleObjectIterator; import junit.framework.TestCase; public class SingleObjectIteratorTest extends TestCase { private Iterator iterator = new SingleObjectIterator(new Object()); public void testNoInfiniteLoops() { iterator.next(); try { iterator.next(); fail("Iterated twice"); } catch (NoSuchElementException ex) { } } public void testRemove() { try { iterator.remove(); fail("Removed from iterator"); } catch (UnsupportedOperationException ex) { } } } jaxen-1.1.6/src/java/test/org/jaxen/test/JaxenHandlerTest.java0000664000175000017500000001272110371471320023567 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import junit.framework.TestCase; import org.jaxen.JaxenHandler; import org.jaxen.expr.DefaultXPathFactory; import org.jaxen.expr.XPathExpr; import org.jaxen.saxpath.SAXPathException; import org.jaxen.saxpath.XPathReader; import org.jaxen.saxpath.XPathSyntaxException; import org.jaxen.saxpath.helpers.XPathReaderFactory; public class JaxenHandlerTest extends TestCase { private String[] paths = { "foo[.='bar']", "foo[.!='bar']", "/", "*", "//foo", "/*", "/.", "/foo[/bar[/baz]]", "/foo/bar/baz[(1 or 2) + 3 * 4 + 8 and 9]", "/foo/bar/baz", ".[1]", "self::node()", ".", "count(/)", "foo[1]", "/baz[(1 or 2) + 3 * 4 + 8 and 9]", "foo/bar[/baz[(1 or 2) - 3 mod 4 + 8 and 9 div 8]]", "foo/bar/yeah:baz[a/b/c and toast]", "/foo/bar[../x='123']", "/foo[@bar='1234']", "foo|bar", "/foo|/bar[@id='1234']", "count(//author/attribute::*)", "$author", "10 + $foo", "10 + (count(descendant::author) * 5)", "10 + count(descendant::author) * 5", "2 + (2 * 5)", "sum(count(//author), 5)", "sum(count(//author),count(//author/attribute::*))", "12 + sum(count(//author),count(//author/attribute::*)) div 2", "text()[.='foo']", "/*/*[@id='123']", "/child::node()/child::node()[@id='_13563275']", "$foo:bar", "//foo:bar", "/foo/bar[@a='1' and @c!='2']", }; private String[] bogusPaths = { "//:p" , // this path is bogus because of a trailing / "/foo/bar/", // This path is bogus because '/' is not division, but // rather just the step separator. "12 + sum(count(//author),count(//author/attribute::*)) / 2", "id()/2", "+" }; public JaxenHandlerTest(String name) { super( name ); } public void testValidPaths() { String path = null; try { // XXX Jiffie solution? XPathReader reader = XPathReaderFactory.createReader(); JaxenHandler handler = new JaxenHandler(); handler.setXPathFactory( new DefaultXPathFactory() ); reader.setXPathHandler( handler ); for ( int i = 0; i < paths.length; i++ ) { path = paths[i]; reader.parse(path); handler.getXPathExpr(false); handler.getXPathExpr(); } } catch (Exception e) { e.printStackTrace(); fail( path + " -> " + e.getMessage() ); } } public void testBogusPaths() throws SAXPathException { XPathReader reader = XPathReaderFactory.createReader(); JaxenHandler handler = new JaxenHandler(); handler.setXPathFactory( new DefaultXPathFactory() ); reader.setXPathHandler( handler ); for ( int i = 0; i < bogusPaths.length; i++ ) { String path = bogusPaths[i]; try { reader.parse(path); XPathExpr xpath = handler.getXPathExpr(false); fail( "Parsed bogus path as: " + xpath ); } catch (XPathSyntaxException e) { } } } } jaxen-1.1.6/src/java/test/org/jaxen/test/UtilTests.java0000664000175000017500000000577410371471320022336 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import junit.framework.Test; import junit.framework.TestSuite; /** *

* Collect the org.jaxen.util tests. *

* * @author Elliotte Rusty Harold * @version 1.1b9 * */ public class UtilTests { public static Test suite() { TestSuite result = new TestSuite(); result.addTest(new TestSuite(SingletonListTest.class)); result.addTest(new TestSuite(SingleObjectIteratorTest.class)); result.addTest(new TestSuite(AncestorOrSelfAxisIteratorTest.class)); result.addTest(new TestSuite(DescendantAxisIteratorTest.class)); result.addTest(new TestSuite(FollowingAxisIteratorTest.class)); result.addTest(new TestSuite(FollowingSiblingAxisIteratorTest.class)); result.addTest(new TestSuite(PrecedingAxisIteratorTest.class)); result.addTest(new TestSuite(PrecedingSiblingAxisIteratorTest.class)); return result; } }jaxen-1.1.6/src/java/test/org/jaxen/test/SimpleVariableContextTest.java0000664000175000017500000001100510520367563025473 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2006 Elliotte Rusty Harold * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import org.jaxen.SimpleVariableContext; import org.jaxen.UnresolvableException; import junit.framework.TestCase; /** *

* Test for namespace context. *

* * @author Elliotte Rusty Harold * @version 1.1b12 * */ public class SimpleVariableContextTest extends TestCase { public void testRoundTripSerialization() throws IOException, ClassNotFoundException, UnresolvableException { // construct test object SimpleVariableContext original = new SimpleVariableContext(); original.setVariableValue("s", "String Value"); original.setVariableValue("x", new Double(3.1415292)); original.setVariableValue("b", Boolean.TRUE); // serialize ByteArrayOutputStream out = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(out); oos.writeObject(original); oos.close(); //deserialize byte[] pickled = out.toByteArray(); InputStream in = new ByteArrayInputStream(pickled); ObjectInputStream ois = new ObjectInputStream(in); Object o = ois.readObject(); SimpleVariableContext copy = (SimpleVariableContext) o; // test the result assertEquals("String Value", copy.getVariableValue("", "", "s")); assertEquals(new Double(3.1415292), copy.getVariableValue("", "", "x")); assertEquals(Boolean.TRUE, copy.getVariableValue("", "", "b")); assertEquals("", ""); } public void testSerializationFormatHasNotChanged() throws IOException, ClassNotFoundException, UnresolvableException { //deserialize InputStream in = new FileInputStream("xml/simplevariablecontext.ser"); ObjectInputStream ois = new ObjectInputStream(in); Object o = ois.readObject(); SimpleVariableContext context = (SimpleVariableContext) o; // test the result assertEquals("String Value", context.getVariableValue("", "", "s")); assertEquals(new Double(3.1415292), context.getVariableValue("", "", "x")); assertEquals(Boolean.TRUE, context.getVariableValue("", "", "b")); assertEquals("", ""); } } jaxen-1.1.6/src/java/test/org/jaxen/test/DOM3NamespaceTest.java0000664000175000017500000001105611753411260023545 0ustar ebourgebourg/* $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import java.util.Iterator; import java.util.List; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.jaxen.*; import org.jaxen.dom.DOMXPath; import org.jaxen.dom.NamespaceNode; import org.w3c.dom.*; import junit.framework.TestCase; public class DOM3NamespaceTest extends TestCase { private NamespaceNode xmlNS; private NamespaceNode rootNS; private NamespaceNode attributeNS; public DOM3NamespaceTest(String name) { super(name); } protected void setUp() throws ParserConfigurationException, JaxenException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); Document doc = factory.newDocumentBuilder().newDocument(); org.w3c.dom.Element root = doc.createElementNS("http://www.root.com/", "root"); doc.appendChild(root); Attr a = doc.createAttributeNS("http://www.example.org/", "pre:a"); a.setNodeValue("value"); root.setAttributeNode(a); XPath xpath = new DOMXPath("namespace::node()"); List result = xpath.selectNodes(root); Iterator iterator = result.iterator(); while (iterator.hasNext()) { NamespaceNode node = (NamespaceNode) iterator.next(); if (node.getLocalName() == null || "".equals(node.getLocalName())) rootNS = node; else if (node.getLocalName().equals("xml")) xmlNS = node; else if (node.getLocalName().equals("pre")) attributeNS = node; } } public void testGetTextContent() { assertEquals("http://www.w3.org/XML/1998/namespace", xmlNS.getTextContent()); } public void testSetTextContent() { try { rootNS.setTextContent("http://www.a.com"); fail("set text content"); } catch (DOMException ex) { assertEquals(DOMException.NO_MODIFICATION_ALLOWED_ERR, ex.code); } } public void testGetFeature() { assertNull(attributeNS.getFeature("name", "value")); } // XXX need to distinguish these two cases public void testIsEqualNode() { assertFalse(rootNS.isEqualNode(xmlNS)); assertTrue(rootNS.isEqualNode(rootNS)); } public void testIsSameNode() { assertFalse(rootNS.isSameNode(xmlNS)); assertTrue(rootNS.isSameNode(rootNS)); } } jaxen-1.1.6/src/java/test/org/jaxen/test/JavaBeanTests.java0000664000175000017500000000500110371471320023047 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.test; import junit.framework.Test; import junit.framework.TestSuite; /** *

* Collect Jaxen's JavaBean tests. *

* * @author Elliotte Rusty Harold * @version 1.1b9 * */ public class JavaBeanTests { public static Test suite() { TestSuite result = new TestSuite(); result.addTest(new TestSuite(JavaBeanNavigatorTest.class)); return result; } }jaxen-1.1.6/src/java/samples/0000775000175000017500000000000012174247550015341 5ustar ebourgebourgjaxen-1.1.6/src/java/samples/Dom4jDemo.java0000664000175000017500000000774510371471320017772 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: Dom4jDemo.java 1128 2006-02-05 21:49:04Z elharo $ */ import org.dom4j.Document; import org.dom4j.Node; import org.dom4j.io.SAXReader; import org.jaxen.XPath; import org.jaxen.XPathSyntaxException; import org.jaxen.JaxenException; import org.jaxen.dom4j.Dom4jXPath; import java.util.List; import java.util.Iterator; public class Dom4jDemo { public static void main(String[] args) { if ( args.length != 2 ) { System.err.println("usage: Dom4jDemo "); System.exit( 1 ); } try { SAXReader reader = new SAXReader(); Document doc = reader.read( args[0] ); XPath xpath = new Dom4jXPath( args[1] ); List results = xpath.selectNodes( doc ); Iterator resultIter = results.iterator(); System.out.println("Document :: " + args[0] ); System.out.println(" XPath :: " + args[1] ); System.out.println(""); System.out.println("Results" ); System.out.println("----------------------------------"); while ( resultIter.hasNext() ) { Object object = resultIter.next(); if ( object instanceof Node ) { Node node = (Node) object; System.out.println( node.asXML() ); } else { System.out.println( object ); } } } catch (XPathSyntaxException e) { System.err.println( e.getMultilineMessage() ); } catch (JaxenException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } } jaxen-1.1.6/src/java/samples/DOMDemo.java0000664000175000017500000000765110371471320017430 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DOMDemo.java 1128 2006-02-05 21:49:04Z elharo $ */ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.jaxen.dom.DOMXPath; import org.jaxen.XPath; import org.jaxen.XPathSyntaxException; import org.jaxen.JaxenException; import java.util.List; import java.util.Iterator; public class DOMDemo { public static void main(String[] args) { if ( args.length != 2 ) { System.err.println("usage: DOMDemo "); System.exit( 1 ); } try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse( args[0] ); XPath xpath = new DOMXPath( args[1] ); System.out.println( "XPah:h " + xpath ); List results = xpath.selectNodes( doc ); Iterator resultIter = results.iterator(); System.out.println("Document :: " + args[0] ); System.out.println(" XPath :: " + args[1] ); System.out.println(""); System.out.println("Results" ); System.out.println("----------------------------------"); while ( resultIter.hasNext() ) { System.out.println( resultIter.next() ); } } catch (XPathSyntaxException e) { System.err.println( e.getMultilineMessage() ); } catch (JaxenException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } } jaxen-1.1.6/src/java/samples/JDOMDemo.java0000664000175000017500000000742710371471320017543 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: JDOMDemo.java 1128 2006-02-05 21:49:04Z elharo $ */ import org.jdom.Document; import org.jdom.JDOMException; import org.jdom.input.SAXBuilder; import org.jaxen.XPath; import org.jaxen.XPathSyntaxException; import org.jaxen.JaxenException; import org.jaxen.jdom.JDOMXPath; import java.util.List; import java.util.Iterator; public class JDOMDemo { public static void main(String[] args) { if ( args.length != 2 ) { System.err.println("usage: JDOMDemo "); System.exit( 1 ); } try { SAXBuilder builder = new SAXBuilder(); Document doc = builder.build( args[0] ); XPath xpath = new JDOMXPath( args[1] ); List results = xpath.selectNodes( doc ); Iterator resultIter = results.iterator(); System.out.println("Document :: " + args[0] ); System.out.println(" XPath :: " + args[1] ); System.out.println(""); System.out.println("Results" ); System.out.println("----------------------------------"); while ( resultIter.hasNext() ) { System.out.println( resultIter.next() ); } } catch (JDOMException e) { e.printStackTrace(); } catch (XPathSyntaxException e) { System.err.println( e.getMultilineMessage() ); } catch (JaxenException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } } jaxen-1.1.6/src/java/main/0000775000175000017500000000000012174247547014627 5ustar ebourgebourgjaxen-1.1.6/src/java/main/org/0000775000175000017500000000000012174247550015410 5ustar ebourgebourgjaxen-1.1.6/src/java/main/org/jaxen/0000775000175000017500000000000012174247550016515 5ustar ebourgebourgjaxen-1.1.6/src/java/main/org/jaxen/VariableContext.java0000664000175000017500000001147610452203147022452 0ustar ebourgebourg/* * $Header$ * $Revision: 1168 $ * $Date: 2006-07-03 13:58:31 +0200 (Mon, 03 Jul 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: VariableContext.java 1168 2006-07-03 11:58:31Z elharo $ */ package org.jaxen; /** Resolves variable bindings within an XPath expression. * *

* Variables within an XPath expression are denoted using * notation such as $varName or * $nsPrefix:varName, and may * refer to a Boolean, Double, String, * node-set (List) or individual XML node. *

* *

* When a variable is bound to a node-set, the * actual Java object returned should be a java.util.List * containing XML nodes from the object-model (e.g. dom4j, JDOM, DOM, etc.) * being used with the XPath. *

* *

* A variable may validly be assigned the null value, * but an unbound variable (one that this context does not know about) * should cause an {@link UnresolvableException} to be thrown. *

* *

* Implementations of this interface should implement Serializable. *

* * @see SimpleVariableContext * @see NamespaceContext * * @author
bob mcwhirter * @author James Strachan */ public interface VariableContext { /** An implementation should return the value of an XPath variable * based on the namespace URI and local name of the variable-reference * expression. * *

* It must not use the prefix parameter to select a variable, * because a prefix could be bound to any namespace; the prefix parameter * could be used in debugging output or other generated information. * The prefix may otherwise be ignored. *

* * @param namespaceURI the namespace URI to which the prefix parameter * is bound in the XPath expression. If the variable * reference expression had no prefix, the namespace * URI is null. * @param prefix the prefix that was used in the variable reference * expression; this value is ignored and has no effect * @param localName the local name of the variable-reference * expression. If there is no prefix, then this is * the whole name of the variable. * * @return the variable's value (which can be null) * @throws UnresolvableException when the variable cannot be resolved */ public Object getVariableValue( String namespaceURI, String prefix, String localName ) throws UnresolvableException; } jaxen-1.1.6/src/java/main/org/jaxen/pattern/0000775000175000017500000000000012174247550020172 5ustar ebourgebourgjaxen-1.1.6/src/java/main/org/jaxen/pattern/LocationPathPattern.java0000664000175000017500000002203310371471320024747 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: LocationPathPattern.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.pattern; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.jaxen.Context; import org.jaxen.JaxenException; import org.jaxen.Navigator; import org.jaxen.expr.FilterExpr; import org.jaxen.util.SingletonList; /**

LocationPathPattern matches any node using a * location path such as A/B/C. * The parentPattern and ancestorPattern properties are used to * chain location path patterns together

* * @author James Strachan * @version $Revision: 1128 $ */ public class LocationPathPattern extends Pattern { /** The node test to perform on this step of the path */ private NodeTest nodeTest = AnyNodeTest.getInstance(); /** Patterns matching my parent node */ private Pattern parentPattern; /** Patterns matching one of my ancestors */ private Pattern ancestorPattern; /** The filters to match against */ private List filters; /** Whether this lcoation path is absolute or not */ private boolean absolute; public LocationPathPattern() { } public LocationPathPattern(NodeTest nodeTest) { this.nodeTest = nodeTest; } public Pattern simplify() { if ( parentPattern != null ) { parentPattern = parentPattern.simplify(); } if ( ancestorPattern != null ) { ancestorPattern = ancestorPattern.simplify(); } if ( filters == null ) { if ( parentPattern == null && ancestorPattern == null ) { return nodeTest; } if ( parentPattern != null && ancestorPattern == null ) { if ( nodeTest instanceof AnyNodeTest ) { return parentPattern; } } } return this; } /** Adds a filter to this pattern */ public void addFilter(FilterExpr filter) { if ( filters == null ) { filters = new ArrayList(); } filters.add( filter ); } /** Adds a pattern for the parent of the current * context node used in this pattern. */ public void setParentPattern(Pattern parentPattern) { this.parentPattern = parentPattern; } /** Adds a pattern for an ancestor of the current * context node used in this pattern. */ public void setAncestorPattern(Pattern ancestorPattern) { this.ancestorPattern = ancestorPattern; } /** Allows the NodeTest to be set */ public void setNodeTest(NodeTest nodeTest) throws JaxenException { if ( this.nodeTest instanceof AnyNodeTest ) { this.nodeTest = nodeTest; } else { throw new JaxenException( "Attempt to overwrite nodeTest: " + this.nodeTest + " with: " + nodeTest ); } } /** @return true if the pattern matches the given node */ public boolean matches( Object node, Context context ) throws JaxenException { Navigator navigator = context.getNavigator(); /* if ( isAbsolute() ) { node = navigator.getDocumentNode( node ); } */ if (! nodeTest.matches(node, context) ) { return false; } if (parentPattern != null) { Object parent = navigator.getParentNode( node ); if ( parent == null ) { return false; } if ( ! parentPattern.matches( parent, context ) ) { return false; } } if (ancestorPattern != null) { Object ancestor = navigator.getParentNode( node ); while (true) { if ( ancestorPattern.matches( ancestor, context ) ) { break; } if ( ancestor == null ) { return false; } if ( navigator.isDocument( ancestor ) ) { return false; } ancestor = navigator.getParentNode( ancestor ); } } if (filters != null) { List list = new SingletonList(node); context.setNodeSet( list ); // XXXX: filters aren't positional, so should we clone context? boolean answer = true; for (Iterator iter = filters.iterator(); iter.hasNext(); ) { FilterExpr filter = (FilterExpr) iter.next(); if ( ! filter.asBoolean( context ) ) { answer = false; break; } } // restore context context.setNodeSet( list ); return answer; } return true; } public double getPriority() { if ( filters != null ) { return 0.5; } return nodeTest.getPriority(); } public short getMatchType() { return nodeTest.getMatchType(); } public String getText() { StringBuffer buffer = new StringBuffer(); if ( absolute ) { buffer.append( "/" ); } if (ancestorPattern != null) { String text = ancestorPattern.getText(); if ( text.length() > 0 ) { buffer.append( text ); buffer.append( "//" ); } } if (parentPattern != null) { String text = parentPattern.getText(); if ( text.length() > 0 ) { buffer.append( text ); buffer.append( "/" ); } } buffer.append( nodeTest.getText() ); if ( filters != null ) { buffer.append( "[" ); for (Iterator iter = filters.iterator(); iter.hasNext(); ) { FilterExpr filter = (FilterExpr) iter.next(); buffer.append( filter.getText() ); } buffer.append( "]" ); } return buffer.toString(); } public String toString() { return super.toString() + "[ absolute: " + absolute + " parent: " + parentPattern + " ancestor: " + ancestorPattern + " filters: " + filters + " nodeTest: " + nodeTest + " ]"; } public boolean isAbsolute() { return absolute; } public void setAbsolute(boolean absolute) { this.absolute = absolute; } public boolean hasAnyNodeTest() { return nodeTest instanceof AnyNodeTest; } } jaxen-1.1.6/src/java/main/org/jaxen/pattern/NamespaceTest.java0000664000175000017500000001051710371471320023564 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: NamespaceTest.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.pattern; import org.jaxen.Context; import org.jaxen.Navigator; /**

NamespaceTest tests for a given namespace URI.

* * @author James Strachan * @version $Revision: 1128 $ */ public class NamespaceTest extends NodeTest { /** The prefix to match against */ private String prefix; /** The type of node to match - either attribute or element */ private short nodeType; public NamespaceTest(String prefix, short nodeType) { if ( prefix == null ) { prefix = ""; } this.prefix = prefix; this.nodeType = nodeType; } /** @return true if the pattern matches the given node */ public boolean matches( Object node, Context context ) { Navigator navigator = context.getNavigator(); String uri = getURI( node, context ); if ( nodeType == Pattern.ELEMENT_NODE ) { return navigator.isElement( node ) && uri.equals( navigator.getElementNamespaceUri( node ) ); } else if ( nodeType == Pattern.ATTRIBUTE_NODE ) { return navigator.isAttribute( node ) && uri.equals( navigator.getAttributeNamespaceUri( node ) ); } return false; } public double getPriority() { return -0.25; } public short getMatchType() { return nodeType; } public String getText() { return prefix + ":"; } public String toString() { return super.toString() + "[ prefix: " + prefix + " type: " + nodeType + " ]"; } /** Returns the URI of the current prefix or "" if no URI can be found */ protected String getURI(Object node, Context context) { String uri = context.getNavigator().translateNamespacePrefixToUri( prefix, node ); if ( uri == null ) { uri = context.getContextSupport().translateNamespacePrefixToUri( prefix ); } if ( uri == null ) { uri = ""; } return uri; } } jaxen-1.1.6/src/java/main/org/jaxen/pattern/TextNodeTest.java0000664000175000017500000000574410371471320023430 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: TextNodeTest.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.pattern; import org.jaxen.Context; /**

TextNodeTest matches any text node.

* * @author James Strachan * @version $Revision: 1128 $ */ public class TextNodeTest extends NodeTest { public static final TextNodeTest SINGLETON = new TextNodeTest(); public TextNodeTest() { } /** @return true if the pattern matches the given node */ public boolean matches( Object node, Context context ) { return context.getNavigator().isText( node ); } public double getPriority() { return -0.5; } public short getMatchType() { return Pattern.TEXT_NODE; } public String getText() { return "text()"; } } jaxen-1.1.6/src/java/main/org/jaxen/pattern/PatternParser.java0000664000175000017500000002462310371471320023625 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: PatternParser.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.pattern; import java.util.Iterator; import java.util.List; import java.util.ListIterator; import org.jaxen.JaxenException; import org.jaxen.JaxenHandler; import org.jaxen.expr.DefaultAllNodeStep; import org.jaxen.expr.DefaultCommentNodeStep; import org.jaxen.expr.DefaultFilterExpr; import org.jaxen.expr.DefaultNameStep; import org.jaxen.expr.DefaultProcessingInstructionNodeStep; import org.jaxen.expr.DefaultStep; import org.jaxen.expr.DefaultTextNodeStep; import org.jaxen.expr.DefaultXPathFactory; import org.jaxen.expr.Expr; import org.jaxen.expr.FilterExpr; import org.jaxen.expr.LocationPath; import org.jaxen.expr.Predicate; import org.jaxen.expr.PredicateSet; import org.jaxen.expr.Step; import org.jaxen.expr.UnionExpr; import org.jaxen.saxpath.Axis; import org.jaxen.saxpath.XPathReader; import org.jaxen.saxpath.helpers.XPathReaderFactory; /** PatternParser is a helper class for parsing * XSLT patterns * * @author James Strachan */ public class PatternParser { private static final boolean TRACE = false; private static final boolean USE_HANDLER = false; public static Pattern parse(String text) throws JaxenException, org.jaxen.saxpath.SAXPathException { if ( USE_HANDLER ) { XPathReader reader = XPathReaderFactory.createReader(); PatternHandler handler = new PatternHandler(); handler.setXPathFactory( new DefaultXPathFactory() ); reader.setXPathHandler( handler ); reader.parse( text ); return handler.getPattern(); } else { XPathReader reader = XPathReaderFactory.createReader(); JaxenHandler handler = new JaxenHandler(); handler.setXPathFactory( new DefaultXPathFactory() ); reader.setXPathHandler( handler ); reader.parse( text ); Pattern pattern = convertExpr( handler.getXPathExpr().getRootExpr() ); return pattern.simplify(); } } protected static Pattern convertExpr(Expr expr) throws JaxenException { if ( TRACE ) { System.out.println( "Converting: " + expr + " into a pattern." ); } if ( expr instanceof LocationPath ) { return convertExpr( (LocationPath) expr ); } else if ( expr instanceof FilterExpr ) { LocationPathPattern answer = new LocationPathPattern(); answer.addFilter( (FilterExpr) expr ); return answer; } else if ( expr instanceof UnionExpr ) { UnionExpr unionExpr = (UnionExpr) expr; Pattern lhs = convertExpr( unionExpr.getLHS() ); Pattern rhs = convertExpr( unionExpr.getRHS() ); return new UnionPattern( lhs, rhs ); } else { LocationPathPattern answer = new LocationPathPattern(); answer.addFilter( new DefaultFilterExpr( expr, new PredicateSet()) ); return answer; } } protected static LocationPathPattern convertExpr(LocationPath locationPath) throws JaxenException { LocationPathPattern answer = new LocationPathPattern(); //answer.setAbsolute( locationPath.isAbsolute() ); List steps = locationPath.getSteps(); // go through steps backwards LocationPathPattern path = answer; boolean first = true; for ( ListIterator iter = steps.listIterator( steps.size() ); iter.hasPrevious(); ) { Step step = (Step) iter.previous(); if ( first ) { first = false; path = convertStep( path, step ); } else { if ( navigationStep( step ) ) { LocationPathPattern parent = new LocationPathPattern(); int axis = step.getAxis(); if ( axis == Axis.DESCENDANT || axis == Axis.DESCENDANT_OR_SELF ) { path.setAncestorPattern( parent ); } else { path.setParentPattern( parent ); } path = parent; } path = convertStep( path, step ); } } if ( locationPath.isAbsolute() ) { LocationPathPattern parent = new LocationPathPattern( NodeTypeTest.DOCUMENT_TEST ); path.setParentPattern( parent ); } return answer; } protected static LocationPathPattern convertStep(LocationPathPattern path, Step step) throws JaxenException { if ( step instanceof DefaultAllNodeStep ) { int axis = step.getAxis(); if ( axis == Axis.ATTRIBUTE ) { path.setNodeTest( NodeTypeTest.ATTRIBUTE_TEST ); } else { path.setNodeTest( NodeTypeTest.ELEMENT_TEST ); } } else if ( step instanceof DefaultCommentNodeStep ) { path.setNodeTest( NodeTypeTest.COMMENT_TEST ); } else if ( step instanceof DefaultProcessingInstructionNodeStep ) { path.setNodeTest( NodeTypeTest.PROCESSING_INSTRUCTION_TEST ); } else if ( step instanceof DefaultTextNodeStep ) { path.setNodeTest( TextNodeTest.SINGLETON ); } else if ( step instanceof DefaultCommentNodeStep ) { path.setNodeTest( NodeTypeTest.COMMENT_TEST ); } else if ( step instanceof DefaultNameStep ) { DefaultNameStep nameStep = (DefaultNameStep) step; String localName = nameStep.getLocalName(); String prefix = nameStep.getPrefix(); int axis = nameStep.getAxis(); short nodeType = Pattern.ELEMENT_NODE; if ( axis == Axis.ATTRIBUTE ) { nodeType = Pattern.ATTRIBUTE_NODE; } if ( nameStep.isMatchesAnyName() ) { if ( prefix.length() == 0 || prefix.equals( "*" ) ) { if ( axis == Axis.ATTRIBUTE ) { path.setNodeTest( NodeTypeTest.ATTRIBUTE_TEST ); } else { path.setNodeTest( NodeTypeTest.ELEMENT_TEST ); } } else { path.setNodeTest( new NamespaceTest( prefix, nodeType ) ); } } else { path.setNodeTest( new NameTest( localName, nodeType ) ); // XXXX: should support namespace in the test too } return convertDefaultStep(path, nameStep); } else if ( step instanceof DefaultStep ) { return convertDefaultStep(path, (DefaultStep) step); } else { throw new JaxenException( "Cannot convert: " + step + " to a Pattern" ); } return path; } protected static LocationPathPattern convertDefaultStep(LocationPathPattern path, DefaultStep step) throws JaxenException { List predicates = step.getPredicates(); if ( ! predicates.isEmpty() ) { FilterExpr filter = new DefaultFilterExpr(new PredicateSet()); for ( Iterator iter = predicates.iterator(); iter.hasNext(); ) { filter.addPredicate( (Predicate) iter.next() ); } path.addFilter( filter ); } return path; } protected static boolean navigationStep( Step step ) { if ( step instanceof DefaultNameStep ) { return true; } else if ( step.getClass().equals( DefaultStep.class ) ) { return ! step.getPredicates().isEmpty(); } else { return true; } } } jaxen-1.1.6/src/java/main/org/jaxen/pattern/AnyChildNodeTest.java0000664000175000017500000000632510371471320024173 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: AnyChildNodeTest.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.pattern; import org.jaxen.Context; /**

AnyChildNodeTest matches any child node.

* * @author James Strachan * @version $Revision: 1128 $ */ public class AnyChildNodeTest extends NodeTest { private static AnyChildNodeTest instance = new AnyChildNodeTest(); public static AnyChildNodeTest getInstance() { return instance; } public AnyChildNodeTest() { } /** @return true if the pattern matches the given node */ public boolean matches( Object node, Context context ) { short type = context.getNavigator().getNodeType( node ); return type == ELEMENT_NODE || type == TEXT_NODE || type == COMMENT_NODE || type == PROCESSING_INSTRUCTION_NODE; } public double getPriority() { return -0.5; } public short getMatchType() { return ANY_NODE; } public String getText() { return "*"; } } jaxen-1.1.6/src/java/main/org/jaxen/pattern/NodeTest.java0000664000175000017500000000466110371471320022560 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: NodeTest.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.pattern; /**

NodeTest is a simple test on a node.

* * @author James Strachan * @version $Revision: 1128 $ */ public abstract class NodeTest extends Pattern { } jaxen-1.1.6/src/java/main/org/jaxen/pattern/PatternHandler.java0000664000175000017500000002502110371471320023737 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: PatternHandler.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.pattern; import java.util.LinkedList; import org.jaxen.JaxenException; import org.jaxen.JaxenHandler; import org.jaxen.expr.Expr; import org.jaxen.expr.FilterExpr; import org.jaxen.saxpath.Axis; /** SAXPath XPathHandler implementation capable * of building Jaxen expression trees which can walk various * different object models. * * @author bob mcwhirter (bob@werken.com) */ public class PatternHandler extends JaxenHandler { private Pattern pattern; public PatternHandler() { } /** Retrieve the simplified Jaxen Pattern expression tree. * *

* This method is only valid once XPathReader.parse(...) * successfully returned. *

* * @return The Pattern expression tree. */ public Pattern getPattern() { return getPattern( true ); } /** Retrieve the Jaxen Pattern expression tree, optionally * simplified. * *

* This method is only valid once XPathReader.parse(...) * successfully returned. *

* * @param shouldSimplify ???? * * @return The Pattern expression tree. */ public Pattern getPattern(boolean shouldSimplify) { if ( shouldSimplify && ! this.simplified ) { //System.err.println("simplifying...."); this.pattern.simplify(); this.simplified = true; } return this.pattern; } public void endXPath() { this.pattern = (Pattern) pop(); System.out.println( "stack is: " + stack ); popFrame(); } public void endPathExpr() { //System.err.println("endPathExpr()"); // PathExpr ::= LocationPath // | FilterExpr // | FilterExpr / RelativeLocationPath // | FilterExpr // RelativeLocationPath // // If the current stack-frame has two items, it's a // FilterExpr and a LocationPath (of some flavor). // // If the current stack-frame has one item, it's simply // a FilterExpr, and more than like boils down to a // primary expr of some flavor. But that's for another // method... LinkedList frame = popFrame(); System.out.println( "endPathExpr(): " + frame ); push( frame.removeFirst() ); /* LocationPathPattern locationPath = new LocationPathPattern(); push( locationPath ); while (! frame.isEmpty() ) { Object filter = frame.removeLast(); if ( filter instanceof NodeTest ) { locationPath.setNodeTest( (NodeTest) filter ); } else if ( filter instanceof FilterExpr ) { locationPath.addFilter( (FilterExpr) filter ); } else if ( filter instanceof LocationPathPattern ) { LocationPathPattern parent = (LocationPathPattern) filter; locationPath.setParentPattern( parent ); locationPath = parent; } else if ( filter != null ) { throw new JaxenException( "Unknown filter: " + filter ); } } */ } public void startAbsoluteLocationPath() { //System.err.println("startAbsoluteLocationPath()"); pushFrame(); push( createAbsoluteLocationPath() ); } public void endAbsoluteLocationPath() throws JaxenException { //System.err.println("endAbsoluteLocationPath()"); endLocationPath(); } public void startRelativeLocationPath() { //System.err.println("startRelativeLocationPath()"); pushFrame(); push( createRelativeLocationPath() ); } public void endRelativeLocationPath() throws JaxenException { //System.err.println("endRelativeLocationPath()"); endLocationPath(); } protected void endLocationPath() throws JaxenException { // start at the back, its the main pattern then add everything else as LinkedList list = popFrame(); System.out.println( "endLocationPath: " + list ); LocationPathPattern locationPath = (LocationPathPattern) list.removeFirst(); push( locationPath ); boolean doneNodeTest = false; while ( ! list.isEmpty() ) { Object filter = list.removeFirst(); if ( filter instanceof NodeTest ) { if ( doneNodeTest ) { LocationPathPattern parent = new LocationPathPattern( (NodeTest) filter ); locationPath.setParentPattern( parent ); locationPath = parent; doneNodeTest = false; } else { locationPath.setNodeTest( (NodeTest) filter ); } } else if ( filter instanceof FilterExpr ) { locationPath.addFilter( (FilterExpr) filter ); } else if ( filter instanceof LocationPathPattern ) { LocationPathPattern parent = (LocationPathPattern) filter; locationPath.setParentPattern( parent ); locationPath = parent; doneNodeTest = false; } } } public void startNameStep(int axis, String prefix, String localName) { //System.err.println("startNameStep(" + axis + ", " + prefix + ", " + localName + ")"); pushFrame(); short nodeType = Pattern.ELEMENT_NODE; switch ( axis ) { case Axis.ATTRIBUTE: nodeType = Pattern.ATTRIBUTE_NODE; break; case Axis.NAMESPACE: nodeType = Pattern.NAMESPACE_NODE; break; } if ( prefix != null && prefix.length() > 0 && ! prefix.equals( "*" ) ) { push( new NamespaceTest( prefix, nodeType ) ); } if ( localName != null && localName.length() > 0 && ! localName.equals( "*" ) ) { push( new NameTest( localName, nodeType ) ); } } public void startTextNodeStep(int axis) { //System.err.println("startTextNodeStep()"); pushFrame(); push( new NodeTypeTest( Pattern.TEXT_NODE ) ); } public void startCommentNodeStep(int axis) { //System.err.println("startCommentNodeStep()"); pushFrame(); push( new NodeTypeTest( Pattern.COMMENT_NODE ) ); } public void startAllNodeStep(int axis) { //System.err.println("startAllNodeStep()"); pushFrame(); push( AnyNodeTest.getInstance() ); } public void startProcessingInstructionNodeStep(int axis, String name) { //System.err.println("startProcessingInstructionStep()"); pushFrame(); // XXXX: should we throw an exception if name is present? push( new NodeTypeTest( Pattern.PROCESSING_INSTRUCTION_NODE ) ); } protected void endStep() { LinkedList list = popFrame(); if ( ! list.isEmpty() ) { push( list.removeFirst() ); if ( ! list.isEmpty() ) { System.out.println( "List should now be empty!" + list ); } } } public void startUnionExpr() { //System.err.println("startUnionExpr()"); } public void endUnionExpr(boolean create) throws JaxenException { //System.err.println("endUnionExpr()"); if ( create ) { //System.err.println("makeUnionExpr"); Expr rhs = (Expr) pop(); Expr lhs = (Expr) pop(); push( getXPathFactory().createUnionExpr( lhs, rhs ) ); } } protected Pattern createAbsoluteLocationPath() { return new LocationPathPattern( NodeTypeTest.DOCUMENT_TEST ); } protected Pattern createRelativeLocationPath() { return new LocationPathPattern(); } } jaxen-1.1.6/src/java/main/org/jaxen/pattern/NameTest.java0000664000175000017500000001022710371471320022546 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: NameTest.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.pattern; import org.jaxen.Context; import org.jaxen.Navigator; /**

NameTest tests for a node name.

* * @author James Strachan * @version $Revision: 1128 $ */ public class NameTest extends NodeTest { /** The name to match against */ private String name; /** The type of node to match - either attribute or element */ private short nodeType; public NameTest(String name, short nodeType) { this.name = name; this.nodeType = nodeType; } /** @return true if the pattern matches the given node */ public boolean matches( Object node, Context context ) { Navigator navigator = context.getNavigator(); if ( nodeType == Pattern.ELEMENT_NODE ) { return navigator.isElement( node ) && name.equals( navigator.getElementName( node ) ); } else if ( nodeType == Pattern.ATTRIBUTE_NODE ) { return navigator.isAttribute( node ) && name.equals( navigator.getAttributeName( node ) ); } else { if ( navigator.isElement( node ) ) { return name.equals( navigator.getElementName( node ) ); } else if ( navigator.isAttribute( node ) ) { return name.equals( navigator.getAttributeName( node ) ); } } return false; } public double getPriority() { return 0.0; } public short getMatchType() { return nodeType; } public String getText() { if ( nodeType == Pattern.ATTRIBUTE_NODE ) { return "@" + name; } else { return name; } } public String toString() { return super.toString() + "[ name: " + name + " type: " + nodeType + " ]"; } } jaxen-1.1.6/src/java/main/org/jaxen/pattern/UnionPattern.java0000664000175000017500000001126010371471320023452 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: UnionPattern.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.pattern; import org.jaxen.Context; import org.jaxen.JaxenException; /**

UnionPattern represents a union pattern.

* * @author James Strachan * @version $Revision: 1128 $ */ public class UnionPattern extends Pattern { private Pattern lhs; private Pattern rhs; private short nodeType = ANY_NODE; private String matchesNodeName = null; public UnionPattern() { } public UnionPattern(Pattern lhs, Pattern rhs) { this.lhs = lhs; this.rhs = rhs; init(); } public Pattern getLHS() { return lhs; } public void setLHS(Pattern lhs) { this.lhs = lhs; init(); } public Pattern getRHS() { return rhs; } public void setRHS(Pattern rhs) { this.rhs = rhs; init(); } // Pattern interface //------------------------------------------------------------------------- /** @return true if the pattern matches the given node */ public boolean matches( Object node, Context context ) throws JaxenException { return lhs.matches( node, context ) || rhs.matches( node, context ); } public Pattern[] getUnionPatterns() { return new Pattern[] { lhs, rhs }; } public short getMatchType() { return nodeType; } public String getMatchesNodeName() { return matchesNodeName; } public Pattern simplify() { this.lhs = lhs.simplify(); this.rhs = rhs.simplify(); init(); return this; } public String getText() { return lhs.getText() + " | " + rhs.getText(); } public String toString() { return super.toString() + "[ lhs: " + lhs + " rhs: " + rhs + " ]"; } // Implementation methods //------------------------------------------------------------------------- private void init() { short type1 = lhs.getMatchType(); short type2 = rhs.getMatchType(); this.nodeType = ( type1 == type2 ) ? type1 : ANY_NODE; String name1 = lhs.getMatchesNodeName(); String name2 = rhs.getMatchesNodeName(); this.matchesNodeName = null; if ( name1 != null && name2 != null && name1.equals( name2 ) ) { this.matchesNodeName = name1; } } } jaxen-1.1.6/src/java/main/org/jaxen/pattern/Pattern.java0000664000175000017500000001434410415516530022451 0ustar ebourgebourg/* * $Header$ * $Revision: 1134 $ * $Date: 2006-04-07 19:11:52 +0200 (Fri, 07 Apr 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: Pattern.java 1134 2006-04-07 17:11:52Z elharo $ */ package org.jaxen.pattern; import org.jaxen.Context; import org.jaxen.JaxenException; /**

Pattern defines the behaviour for pattern in * the XSLT processing model.

* * @author James Strachan * @version $Revision: 1134 $ */ public abstract class Pattern { // These node numbers are compatible with both DOM and dom4j's node types /** Matches Element nodes */ public static final short ELEMENT_NODE = 1; /** Matches attribute nodes */ public static final short ATTRIBUTE_NODE = 2; /** Matches text nodes */ public static final short TEXT_NODE = 3; /** Matches CDATA section nodes */ public static final short CDATA_SECTION_NODE = 4; /** Matches entity reference nodes */ public static final short ENTITY_REFERENCE_NODE = 5; /** Matches entity nodes */ //public static final short ENTITY_NODE = 6; /** Matches ProcessingInstruction */ public static final short PROCESSING_INSTRUCTION_NODE = 7; /** Matches comment nodes */ public static final short COMMENT_NODE = 8; /** Matches document nodes */ public static final short DOCUMENT_NODE = 9; /** Matches DocumentType nodes */ public static final short DOCUMENT_TYPE_NODE = 10; //public static final short DOCUMENT_FRAGMENT_NODE = 11; //public static final short NOTATION_NODE = 12; /** Matches a Namespace Node */ // This has the same value as the DOM Level 3 XPathNamespace type public static final short NAMESPACE_NODE = 13; /** Does not match any valid node */ public static final short UNKNOWN_NODE = 14; /** The maximum number of node types for sizing purposes */ public static final short MAX_NODE_TYPE = 14; /** Matches any node */ public static final short ANY_NODE = 0; /** Matches no nodes */ public static final short NO_NODE = 14; /** * * @param node ???? * @param context ???? * @return true if the pattern matches the given node * @throws JaxenException if ???? */ public abstract boolean matches( Object node, Context context ) throws JaxenException; /** Returns the default resolution policy of the pattern according to the * * XSLT conflict resolution rules. * * @return 0.5; the default priority defined in XSLT * * @see Section 5.5 of the XSLT specification * */ public double getPriority() { return 0.5; } /** If this pattern is a union pattern then this * method should return an array of patterns which * describe the union pattern, which should contain more than one pattern. * Otherwise this method should return null. * * @return an array of the patterns which make up this union pattern * or null if this pattern is not a union pattern */ public Pattern[] getUnionPatterns() { return null; } /** * Returns the type of node the pattern matches. * * @return ANY_NODE unless overridden */ public short getMatchType() { return ANY_NODE; } /** For patterns which only match an ATTRIBUTE_NODE or an * ELEMENT_NODE then this pattern may return the name of the * element or attribute it matches. This allows a more efficient * rule matching algorithm to be performed, rather than a brute * force approach of evaluating every pattern for a given Node. * * @return the name of the element or attribute this pattern matches * or null if this pattern matches any or more than one name */ public String getMatchesNodeName() { return null; } public Pattern simplify() { return this; } /** Returns a textual representation of this pattern * * @return the usual string form of this XSLT pattern */ public abstract String getText(); } jaxen-1.1.6/src/java/main/org/jaxen/pattern/NoNodeTest.java0000664000175000017500000000576210371471320023060 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: NoNodeTest.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.pattern; import org.jaxen.Context; /**

NoNodeTest matches no nodes.

* * @author James Strachan * @version $Revision: 1128 $ */ public class NoNodeTest extends NodeTest { private static NoNodeTest instance = new NoNodeTest(); public static NoNodeTest getInstance() { return instance; } public NoNodeTest() { } /** @return true if the pattern matches the given node */ public boolean matches( Object node, Context context ) { return false; } public double getPriority() { return -0.5; } public short getMatchType() { return NO_NODE; } public String getText() { return ""; } } jaxen-1.1.6/src/java/main/org/jaxen/pattern/NodeTypeTest.java0000664000175000017500000001067510371471320023424 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: NodeTypeTest.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.pattern; import org.jaxen.Context; /**

NodeTypeTest matches if the node is of a certain type * such as element, attribute, comment, text, processing instruction and so forth.

* * @author James Strachan * @version $Revision: 1128 $ */ public class NodeTypeTest extends NodeTest { public static final NodeTypeTest DOCUMENT_TEST = new NodeTypeTest( DOCUMENT_NODE ); public static final NodeTypeTest ELEMENT_TEST = new NodeTypeTest( ELEMENT_NODE ); public static final NodeTypeTest ATTRIBUTE_TEST = new NodeTypeTest( ATTRIBUTE_NODE ); public static final NodeTypeTest COMMENT_TEST = new NodeTypeTest( COMMENT_NODE ); public static final NodeTypeTest TEXT_TEST = new NodeTypeTest( TEXT_NODE ); public static final NodeTypeTest PROCESSING_INSTRUCTION_TEST = new NodeTypeTest( PROCESSING_INSTRUCTION_NODE ); public static final NodeTypeTest NAMESPACE_TEST = new NodeTypeTest( NAMESPACE_NODE ); private short nodeType; public NodeTypeTest(short nodeType) { this.nodeType = nodeType; } /** @return true if the pattern matches the given node */ public boolean matches( Object node, Context context ) { return nodeType == context.getNavigator().getNodeType( node ); } public double getPriority() { return -0.5; } public short getMatchType() { return nodeType; } public String getText() { switch (nodeType) { case ELEMENT_NODE: return "child()"; case ATTRIBUTE_NODE: return "@*"; case NAMESPACE_NODE: return "namespace()"; case DOCUMENT_NODE: return "/"; case COMMENT_NODE: return "comment()"; case TEXT_NODE: return "text()"; case PROCESSING_INSTRUCTION_NODE: return "processing-instruction()"; } return ""; } public String toString() { return super.toString() + "[ type: " + nodeType + " ]"; } } jaxen-1.1.6/src/java/main/org/jaxen/pattern/AnyNodeTest.java0000664000175000017500000000575510371471320023235 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: AnyNodeTest.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.pattern; import org.jaxen.Context; /**

AnyNodeTest matches any node.

* * @author James Strachan * @version $Revision: 1128 $ */ public class AnyNodeTest extends NodeTest { private static AnyNodeTest instance = new AnyNodeTest(); public static AnyNodeTest getInstance() { return instance; } private AnyNodeTest() {} /** @return true if the pattern matches the given node */ public boolean matches( Object node, Context context ) { return true; } public double getPriority() { return -0.5; } public short getMatchType() { return ANY_NODE; } public String getText() { return "*"; } } jaxen-1.1.6/src/java/main/org/jaxen/pattern/package.html0000664000175000017500000000026007472132404022445 0ustar ebourgebourg

Defines XSLT Pattern objects. The design of this library is greatly influenced by Michael Kay's SAXON implementation.

jaxen-1.1.6/src/java/main/org/jaxen/Context.java0000664000175000017500000002072210514521500020771 0ustar ebourgebourgpackage org.jaxen; /* $Id: Context.java 1219 2006-10-15 21:08:16Z elharo $ Copyright 2003 The Werken Company. All Rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Jaxen Project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.List; /** Wrapper around implementation-specific objects used * as the context of an expression evaluation. * *

* NOTE: This class is not typically used directly, * but is exposed for writers of implementation-specific * XPath packages. *

* *

* The Context bundles utilities together * for evaluation of the expression. It wraps the provided * objects for ease-of-passage through the expression * AST. *

* * @see ContextSupport * @see BaseXPath * @see org.jaxen.dom4j.Dom4jXPath XPath for dom4j * @see org.jaxen.jdom.JDOMXPath XPath for JDOM * @see org.jaxen.dom.DOMXPath XPath for W3C DOM * * @author bob mcwhirter */ public class Context implements Serializable { /** * */ private static final long serialVersionUID = 2315979994685591055L; // ---------------------------------------------------------------------- // Instance members // ---------------------------------------------------------------------- /** Context-support */ private ContextSupport contextSupport; /** Context node-set */ private List nodeSet; /** Current context size */ private int size; /** Current context position */ private int position; // ---------------------------------------------------------------------- // Constructors // ---------------------------------------------------------------------- /** Create a new context. * * @param contextSupport the context-support */ public Context(ContextSupport contextSupport) { this.contextSupport = contextSupport; this.nodeSet = Collections.EMPTY_LIST; this.size = 0; this.position = 0; } // ---------------------------------------------------------------------- // Instance methods // ---------------------------------------------------------------------- /** *

* Set the context node-set, and sets the current context size to the size * of this node-set.

* *

The actual list is stored in this object. A copy * is not made. This list should not be modified in other code after * calling this method.

* *

* After invoking this method, the client should immediately call * {@link #setSize(int) setSize} and {@link #setPosition(int) setPosition}. *

* * @param nodeSet the context node-set */ public void setNodeSet(List nodeSet) { this.nodeSet = nodeSet; this.size = nodeSet.size(); if (position >= size) this.position = 0; } /** Retrieve the context node-set. * This is a live list. It is not a copy. * Do not modify it. * * @return the context node-set */ public List getNodeSet() { return this.nodeSet; } /** Set the ContextSupport. * * @param contextSupport the context-support */ public void setContextSupport(ContextSupport contextSupport) { this.contextSupport = contextSupport; } /** Retrieve the ContextSupport. * * @return the context-support */ public ContextSupport getContextSupport() { return this.contextSupport; } /** Retrieve the current Navigator. * * @return the navigator */ public Navigator getNavigator() { return getContextSupport().getNavigator(); } /** Translate a namespace prefix to its URI. * * @param prefix the prefix * * @return the namespace URI mapped to the prefix */ public String translateNamespacePrefixToUri(String prefix) { return getContextSupport().translateNamespacePrefixToUri( prefix ); } /** Retrieve a variable value. * * @param namespaceURI the function namespace URI * @param prefix the function prefix * @param localName the function name * * @return the variable value * * @throws UnresolvableException if unable to locate a bound variable */ public Object getVariableValue(String namespaceURI, String prefix, String localName) throws UnresolvableException { return getContextSupport().getVariableValue( namespaceURI, prefix, localName ); } /** Retrieve a Function. * * @param namespaceURI the function namespace URI * @param prefix the function prefix * @param localName the function name * * @return the function object * * @throws UnresolvableException if unable to locate a bound function */ public Function getFunction(String namespaceURI, String prefix, String localName) throws UnresolvableException { return getContextSupport().getFunction( namespaceURI, prefix, localName ); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Properties // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /** Set the current size in the context node-set. * * @param size the size */ public void setSize(int size) { this.size = size; } /** Retrieve the size of the current context node-set. * * @return the size */ public int getSize() { return this.size; } /** Set the current position in the context node-set. * * @param position the position */ public void setPosition(int position) { this.position = position; } /** Retrieve current position in the context node-set. * * @return the current position */ public int getPosition() { return this.position; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Helpers // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /** Create a type-safe shallow copy. * * @return the duplicate */ public Context duplicate() { Context dupe = new Context( getContextSupport() ); List thisNodeSet = getNodeSet(); if ( thisNodeSet != null ) { List dupeNodeSet = new ArrayList( thisNodeSet.size() ); dupeNodeSet.addAll( thisNodeSet ); dupe.setNodeSet( dupeNodeSet ); dupe.setPosition(this.position); } return dupe; } } jaxen-1.1.6/src/java/main/org/jaxen/JaxenHandler.java0000664000175000017500000003733510412761307021730 0ustar ebourgebourg/* * $Header$ * $Revision: 1132 $ * $Date: 2006-03-30 15:53:11 +0200 (Thu, 30 Mar 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: JaxenHandler.java 1132 2006-03-30 13:53:11Z elharo $ */ package org.jaxen; import java.util.Iterator; import java.util.LinkedList; import org.jaxen.expr.DefaultXPathFactory; import org.jaxen.expr.Expr; import org.jaxen.expr.FilterExpr; import org.jaxen.expr.FunctionCallExpr; import org.jaxen.expr.LocationPath; import org.jaxen.expr.Predicate; import org.jaxen.expr.Predicated; import org.jaxen.expr.Step; import org.jaxen.expr.XPathExpr; import org.jaxen.expr.XPathFactory; import org.jaxen.saxpath.Operator; import org.jaxen.saxpath.XPathHandler; /** SAXPath XPathHandler implementation capable * of building Jaxen expression trees which can walk various * different object models. * * @author bob mcwhirter (bob@werken.com) */ public class JaxenHandler implements XPathHandler { private XPathFactory xpathFactory; private XPathExpr xpath; /** * ???? */ protected boolean simplified; /** * This may be changed to an ArrayList in the future (i.e. version >= 1.2). * You really shouldn't be accessing this field directly, but * if you are please try to use it as a generic List. Don't use the * methods that are only available in LinkedList. */ protected LinkedList stack; /** Constructor */ public JaxenHandler() { this.stack = new LinkedList(); this.xpathFactory = new DefaultXPathFactory(); } /** Set the Jaxen XPathFactory that constructs * the XPath expression tree during the parse. * * @param xpathFactory the factory to use during the parse */ public void setXPathFactory(XPathFactory xpathFactory) { this.xpathFactory = xpathFactory; } /** Retrieve the Jaxen XPathFactory used * during the parse to construct the XPath expression tree. * * @return the XPathFactory used during the parse. */ public XPathFactory getXPathFactory() { return this.xpathFactory; } /** Retrieve the simplified Jaxen XPath expression tree. * *

* This method is only valid once XPathReader.parse(...) * successfully returned. *

* * @return the XPath expression tree */ public XPathExpr getXPathExpr() { return getXPathExpr( true ); } /** Retrieve the Jaxen XPath expression tree, optionally * simplified. * *

* This method is only valid once XPathReader.parse(...) * successfully returned. *

* * @param shouldSimplify ???? * * @return the XPath expression tree */ public XPathExpr getXPathExpr(boolean shouldSimplify) { if ( shouldSimplify && ! this.simplified ) { this.xpath.simplify(); this.simplified = true; } return this.xpath; } public void startXPath() { this.simplified = false; pushFrame(); } public void endXPath() throws JaxenException { this.xpath = getXPathFactory().createXPath( (Expr) pop() ); popFrame(); } public void startPathExpr() { pushFrame(); } public void endPathExpr() throws JaxenException { // PathExpr ::= LocationPath // | FilterExpr // | FilterExpr / RelativeLocationPath // | FilterExpr // RelativeLocationPath // // If the current stack-frame has two items, it's a // FilterExpr and a LocationPath (of some flavor). // // If the current stack-frame has one item, it's simply // a FilterExpr, and more than likely boils down to a // primary expr of some flavor. But that's for another // method... FilterExpr filterExpr; LocationPath locationPath; Object popped; if ( stackSize() == 2 ) { locationPath = (LocationPath) pop(); filterExpr = (FilterExpr) pop(); } else { popped = pop(); if ( popped instanceof LocationPath ) { locationPath = (LocationPath) popped; filterExpr = null; } else { locationPath = null; filterExpr = (FilterExpr) popped; } } popFrame(); push( getXPathFactory().createPathExpr( filterExpr, locationPath ) ); } public void startAbsoluteLocationPath() throws JaxenException { pushFrame(); push( getXPathFactory().createAbsoluteLocationPath() ); } public void endAbsoluteLocationPath() throws JaxenException { endLocationPath(); } public void startRelativeLocationPath() throws JaxenException { pushFrame(); push( getXPathFactory().createRelativeLocationPath() ); } public void endRelativeLocationPath() throws JaxenException { endLocationPath(); } protected void endLocationPath() throws JaxenException { LocationPath path = (LocationPath) peekFrame().removeFirst(); addSteps( path, popFrame().iterator() ); push( path ); } protected void addSteps(LocationPath locationPath, Iterator stepIter) { while ( stepIter.hasNext() ) { locationPath.addStep( (Step) stepIter.next() ); } } public void startNameStep(int axis, String prefix, String localName) throws JaxenException { pushFrame(); push( getXPathFactory().createNameStep( axis, prefix, localName ) ); } public void endNameStep() { endStep(); } public void startTextNodeStep(int axis) throws JaxenException { //System.err.println("startTextNodeStep()"); pushFrame(); push( getXPathFactory().createTextNodeStep( axis ) ); } public void endTextNodeStep() { endStep(); } public void startCommentNodeStep(int axis) throws JaxenException { pushFrame(); push( getXPathFactory().createCommentNodeStep( axis ) ); } public void endCommentNodeStep() { endStep(); } public void startAllNodeStep(int axis) throws JaxenException { pushFrame(); push( getXPathFactory().createAllNodeStep( axis ) ); } public void endAllNodeStep() { endStep(); } public void startProcessingInstructionNodeStep(int axis, String name) throws JaxenException { pushFrame(); push( getXPathFactory().createProcessingInstructionNodeStep( axis, name ) ); } public void endProcessingInstructionNodeStep() { endStep(); } protected void endStep() { Step step = (Step) peekFrame().removeFirst(); addPredicates( step, popFrame().iterator() ); push( step ); } public void startPredicate() { pushFrame(); } public void endPredicate() throws JaxenException { Predicate predicate = getXPathFactory().createPredicate( (Expr) pop() ); popFrame(); push( predicate ); } public void startFilterExpr() { pushFrame(); } public void endFilterExpr() throws JaxenException { Expr expr = (Expr) peekFrame().removeFirst(); FilterExpr filter = getXPathFactory().createFilterExpr( expr ); Iterator predIter = popFrame().iterator(); addPredicates( filter, predIter ); push( filter ); } protected void addPredicates(Predicated obj, Iterator predIter) { while ( predIter.hasNext() ) { obj.addPredicate( (Predicate) predIter.next() ); } } protected void returnExpr() { Expr expr = (Expr) pop(); popFrame(); push( expr ); } public void startOrExpr() { } public void endOrExpr(boolean create) throws JaxenException { if ( create ) { Expr rhs = (Expr) pop(); Expr lhs = (Expr) pop(); push( getXPathFactory().createOrExpr( lhs, rhs ) ); } } public void startAndExpr() { } public void endAndExpr(boolean create) throws JaxenException { if ( create ) { Expr rhs = (Expr) pop(); Expr lhs = (Expr) pop(); push( getXPathFactory().createAndExpr( lhs, rhs ) ); } } public void startEqualityExpr() { } public void endEqualityExpr(int operator) throws JaxenException { if ( operator != Operator.NO_OP ) { Expr rhs = (Expr) pop(); Expr lhs = (Expr) pop(); push( getXPathFactory().createEqualityExpr( lhs, rhs, operator ) ); } } public void startRelationalExpr() { } public void endRelationalExpr(int operator) throws JaxenException { if ( operator != Operator.NO_OP ) { Expr rhs = (Expr) pop(); Expr lhs = (Expr) pop(); push( getXPathFactory().createRelationalExpr( lhs, rhs, operator ) ); } } public void startAdditiveExpr() { } public void endAdditiveExpr(int operator) throws JaxenException { if ( operator != Operator.NO_OP ) { Expr rhs = (Expr) pop(); Expr lhs = (Expr) pop(); push( getXPathFactory().createAdditiveExpr( lhs, rhs, operator ) ); } } public void startMultiplicativeExpr() { } public void endMultiplicativeExpr(int operator) throws JaxenException { if ( operator != Operator.NO_OP ) { Expr rhs = (Expr) pop(); Expr lhs = (Expr) pop(); push( getXPathFactory().createMultiplicativeExpr( lhs, rhs, operator ) ); } } public void startUnaryExpr() { } public void endUnaryExpr(int operator) throws JaxenException { if ( operator != Operator.NO_OP ) { push( getXPathFactory().createUnaryExpr( (Expr) pop(), operator ) ); } } public void startUnionExpr() { } public void endUnionExpr(boolean create) throws JaxenException { if ( create ) { Expr rhs = (Expr) pop(); Expr lhs = (Expr) pop(); push( getXPathFactory().createUnionExpr( lhs, rhs ) ); } } public void number(int number) throws JaxenException { push( getXPathFactory().createNumberExpr( number ) ); } public void number(double number) throws JaxenException { push( getXPathFactory().createNumberExpr( number ) ); } public void literal(String literal) throws JaxenException { push( getXPathFactory().createLiteralExpr( literal ) ); } public void variableReference(String prefix, String variableName) throws JaxenException { push( getXPathFactory().createVariableReferenceExpr( prefix, variableName ) ); } public void startFunction(String prefix, String functionName) throws JaxenException { pushFrame(); push( getXPathFactory().createFunctionCallExpr( prefix, functionName ) ); } public void endFunction() { FunctionCallExpr function = (FunctionCallExpr) peekFrame().removeFirst(); addParameters( function, popFrame().iterator() ); push( function ); } protected void addParameters(FunctionCallExpr function, Iterator paramIter) { while ( paramIter.hasNext() ) { function.addParameter( (Expr) paramIter.next() ); } } protected int stackSize() { return peekFrame().size(); } protected void push(Object obj) { peekFrame().addLast( obj ); } protected Object pop() { return peekFrame().removeLast(); } protected boolean canPop() { return ( peekFrame().size() > 0 ); } protected void pushFrame() { this.stack.addLast( new LinkedList() ); } protected LinkedList popFrame() { return (LinkedList) this.stack.removeLast(); } protected LinkedList peekFrame() { return (LinkedList) this.stack.getLast(); } } jaxen-1.1.6/src/java/main/org/jaxen/dom4j/0000775000175000017500000000000012174247550017532 5ustar ebourgebourgjaxen-1.1.6/src/java/main/org/jaxen/dom4j/DocumentNavigator.java0000664000175000017500000003432310452214352024022 0ustar ebourgebourgpackage org.jaxen.dom4j; /* * $Header$ * $Revision: 1171 $ * $Date: 2006-07-03 15:17:30 +0200 (Mon, 03 Jul 2006) $ * * ==================================================================== * * Copyright 2000-2005 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DocumentNavigator.java 1171 2006-07-03 13:17:30Z elharo $ */ import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; import org.dom4j.Attribute; import org.dom4j.Branch; import org.dom4j.CDATA; import org.dom4j.Comment; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.Element; import org.dom4j.Namespace; import org.dom4j.Node; import org.dom4j.ProcessingInstruction; import org.dom4j.QName; import org.dom4j.Text; import org.dom4j.io.SAXReader; import org.jaxen.DefaultNavigator; import org.jaxen.FunctionCallException; import org.jaxen.NamedAccessNavigator; import org.jaxen.Navigator; import org.jaxen.XPath; import org.jaxen.JaxenConstants; import org.jaxen.saxpath.SAXPathException; import org.jaxen.util.SingleObjectIterator; /** * Interface for navigating around the DOM4J object model. * *

* This class is not intended for direct usage, but is * used by the Jaxen engine during evaluation. *

* * @see XPath * * @author bob mcwhirter * @author Stephen Colebourne */ public class DocumentNavigator extends DefaultNavigator implements NamedAccessNavigator { /** * */ private static final long serialVersionUID = 5582300797286535936L; private transient SAXReader reader; /** Singleton implementation. */ private static class Singleton { /** Singleton instance. */ private static DocumentNavigator instance = new DocumentNavigator(); } /** Retrieve the singleton instance of this DocumentNavigator. */ public static Navigator getInstance() { return Singleton.instance; } public boolean isElement(Object obj) { return obj instanceof Element; } public boolean isComment(Object obj) { return obj instanceof Comment; } public boolean isText(Object obj) { return ( obj instanceof Text || obj instanceof CDATA ); } public boolean isAttribute(Object obj) { return obj instanceof Attribute; } public boolean isProcessingInstruction(Object obj) { return obj instanceof ProcessingInstruction; } public boolean isDocument(Object obj) { return obj instanceof Document; } public boolean isNamespace(Object obj) { return obj instanceof Namespace; } public String getElementName(Object obj) { Element elem = (Element) obj; return elem.getName(); } public String getElementNamespaceUri(Object obj) { Element elem = (Element) obj; String uri = elem.getNamespaceURI(); if ( uri == null) return ""; else return uri; } public String getElementQName(Object obj) { Element elem = (Element) obj; return elem.getQualifiedName(); } public String getAttributeName(Object obj) { Attribute attr = (Attribute) obj; return attr.getName(); } public String getAttributeNamespaceUri(Object obj) { Attribute attr = (Attribute) obj; String uri = attr.getNamespaceURI(); if ( uri == null) return ""; else return uri; } public String getAttributeQName(Object obj) { Attribute attr = (Attribute) obj; return attr.getQualifiedName(); } public Iterator getChildAxisIterator(Object contextNode) { Iterator result = null; if ( contextNode instanceof Branch ) { Branch node = (Branch) contextNode; result = node.nodeIterator(); } if (result != null) { return result; } return JaxenConstants.EMPTY_ITERATOR; } /** * Retrieves an Iterator over the child elements that * match the supplied name. * * @param contextNode the origin context node * @param localName the local name of the children to return, always present * @param namespacePrefix the prefix of the namespace of the children to return * @param namespaceURI the uri of the namespace of the children to return * * @return an Iterator that traverses the named children, or null if none */ public Iterator getChildAxisIterator( Object contextNode, String localName, String namespacePrefix, String namespaceURI) { if ( contextNode instanceof Element ) { Element node = (Element) contextNode; return node.elementIterator(QName.get(localName, namespacePrefix, namespaceURI)); } if ( contextNode instanceof Document ) { Document node = (Document) contextNode; Element el = node.getRootElement(); if (el == null || el.getName().equals(localName) == false) { return JaxenConstants.EMPTY_ITERATOR; } if (namespaceURI != null) { if (namespaceURI.equals(el.getNamespaceURI()) == false) { return JaxenConstants.EMPTY_ITERATOR; } } return new SingleObjectIterator(el); } return JaxenConstants.EMPTY_ITERATOR; } public Iterator getParentAxisIterator(Object contextNode) { if ( contextNode instanceof Document ) { return JaxenConstants.EMPTY_ITERATOR; } Node node = (Node) contextNode; Object parent = node.getParent(); if ( parent == null ) { parent = node.getDocument(); } return new SingleObjectIterator( parent ); } public Iterator getAttributeAxisIterator(Object contextNode) { if ( ! ( contextNode instanceof Element ) ) { return JaxenConstants.EMPTY_ITERATOR; } Element elem = (Element) contextNode; return elem.attributeIterator(); } /** * Retrieves an Iterator over the attribute elements that * match the supplied name. * * @param contextNode the origin context node * @param localName the local name of the attributes to return, always present * @param namespacePrefix the prefix of the namespace of the attributes to return * @param namespaceURI the URI of the namespace of the attributes to return * @return an Iterator that traverses the named attributes, not null */ public Iterator getAttributeAxisIterator( Object contextNode, String localName, String namespacePrefix, String namespaceURI) { if ( contextNode instanceof Element ) { Element node = (Element) contextNode; Attribute attr = node.attribute(QName.get(localName, namespacePrefix, namespaceURI)); if (attr == null) { return JaxenConstants.EMPTY_ITERATOR; } return new SingleObjectIterator(attr); } return JaxenConstants.EMPTY_ITERATOR; } public Iterator getNamespaceAxisIterator(Object contextNode) { if ( ! ( contextNode instanceof Element ) ) { return JaxenConstants.EMPTY_ITERATOR; } Element element = (Element) contextNode; List nsList = new ArrayList(); HashSet prefixes = new HashSet(); for ( Element context = element; context != null; context = context.getParent() ) { List declaredNS = new ArrayList(context.declaredNamespaces()); declaredNS.add(context.getNamespace()); for ( Iterator iter = context.attributes().iterator(); iter.hasNext(); ) { Attribute attr = (Attribute) iter.next(); declaredNS.add(attr.getNamespace()); } for ( Iterator iter = declaredNS.iterator(); iter.hasNext(); ) { Namespace namespace = (Namespace) iter.next(); if (namespace != Namespace.NO_NAMESPACE) { String prefix = namespace.getPrefix(); if ( ! prefixes.contains( prefix ) ) { prefixes.add( prefix ); nsList.add( namespace.asXPathResult( element ) ); } } } } nsList.add( Namespace.XML_NAMESPACE.asXPathResult( element ) ); return nsList.iterator(); } public Object getDocumentNode(Object contextNode) { if ( contextNode instanceof Document ) { return contextNode; } else if ( contextNode instanceof Node ) { Node node = (Node) contextNode; return node.getDocument(); } return null; } /** Returns a parsed form of the given XPath string, which will be suitable * for queries on DOM4J documents. */ public XPath parseXPath (String xpath) throws SAXPathException { return new Dom4jXPath(xpath); } public Object getParentNode(Object contextNode) { if ( contextNode instanceof Node ) { Node node = (Node) contextNode; Object answer = node.getParent(); if ( answer == null ) { answer = node.getDocument(); if (answer == contextNode) { return null; } } return answer; } return null; } public String getTextStringValue(Object obj) { return getNodeStringValue( (Node) obj ); } public String getElementStringValue(Object obj) { return getNodeStringValue( (Node) obj ); } public String getAttributeStringValue(Object obj) { return getNodeStringValue( (Node) obj ); } private String getNodeStringValue(Node node) { return node.getStringValue(); } public String getNamespaceStringValue(Object obj) { Namespace ns = (Namespace) obj; return ns.getURI(); } public String getNamespacePrefix(Object obj) { Namespace ns = (Namespace) obj; return ns.getPrefix(); } public String getCommentStringValue(Object obj) { Comment cmt = (Comment) obj; return cmt.getText(); } public String translateNamespacePrefixToUri(String prefix, Object context) { Element element = null; if ( context instanceof Element ) { element = (Element) context; } else if ( context instanceof Node ) { Node node = (Node) context; element = node.getParent(); } if ( element != null ) { Namespace namespace = element.getNamespaceForPrefix( prefix ); if ( namespace != null ) { return namespace.getURI(); } } return null; } public short getNodeType(Object node) { if ( node instanceof Node ) { return ((Node) node).getNodeType(); } return 0; } public Object getDocument(String uri) throws FunctionCallException { try { return getSAXReader().read( uri ); } catch (DocumentException e) { throw new FunctionCallException("Failed to parse document for URI: " + uri, e); } } public String getProcessingInstructionTarget(Object obj) { ProcessingInstruction pi = (ProcessingInstruction) obj; return pi.getTarget(); } public String getProcessingInstructionData(Object obj) { ProcessingInstruction pi = (ProcessingInstruction) obj; return pi.getText(); } // Properties //------------------------------------------------------------------------- public SAXReader getSAXReader() { if ( reader == null ) { reader = new SAXReader(); reader.setMergeAdjacentText( true ); } return reader; } public void setSAXReader(SAXReader reader) { this.reader = reader; } } jaxen-1.1.6/src/java/main/org/jaxen/dom4j/Dom4jXPath.java0000664000175000017500000000664710440373212022321 0ustar ebourgebourg/* * $Header$ * $Revision: 1162 $ * $Date: 2006-06-03 22:52:26 +0200 (Sat, 03 Jun 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: Dom4jXPath.java 1162 2006-06-03 20:52:26Z elharo $ */ package org.jaxen.dom4j; import org.jaxen.BaseXPath; import org.jaxen.JaxenException; /** An XPath implementation for the dom4j model * *

This is the main entry point for matching an XPath against a DOM * tree. You create a compiled XPath object, then match it against * one or more context nodes using the {@link #selectNodes(Object)} * method, as in the following example:

* *
 * Node node = ...;
 * XPath path = new Dom4jXPath("a/b/c");
 * List results = path.selectNodes(node);
 * 
* * @see BaseXPath * @see The dom4j website * * @author bob mcwhirter * @author James Strachan * * @version $Revision: 1162 $ */ public class Dom4jXPath extends BaseXPath { /** * */ private static final long serialVersionUID = -75510941087659775L; /** Construct given an XPath expression string. * * @param xpathExpr the XPath expression * * @throws JaxenException if there is a syntax error while * parsing the expression */ public Dom4jXPath(String xpathExpr) throws JaxenException { super( xpathExpr, DocumentNavigator.getInstance() ); } } jaxen-1.1.6/src/java/main/org/jaxen/dom4j/package.html0000664000175000017500000000024707327350513022014 0ustar ebourgebourg org.jaxen.dom4j.*

Navigation for dom4j trees.

jaxen-1.1.6/src/java/main/org/jaxen/javabean/0000775000175000017500000000000012174247547020272 5ustar ebourgebourgjaxen-1.1.6/src/java/main/org/jaxen/javabean/Element.java0000664000175000017500000000104210027430666022512 0ustar ebourgebourgpackage org.jaxen.javabean; public class Element { private Element parent; private String name; private Object object; public Element(Element parent, String name, Object object) { this.parent = parent; this.name = name; this.object = object; } public Element getParent() { return this.parent; } public String getName() { return this.name; } public Object getObject() { return this.object; } } jaxen-1.1.6/src/java/main/org/jaxen/javabean/DocumentNavigator.java0000664000175000017500000002364710440371260024562 0ustar ebourgebourg/* $Id: DocumentNavigator.java 1161 2006-06-03 20:36:00Z elharo $ Copyright 2003 The Werken Company. All Rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Jaxen Project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.jaxen.javabean; import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; import java.util.Iterator; import java.util.Collection; import org.jaxen.DefaultNavigator; import org.jaxen.FunctionCallException; import org.jaxen.NamedAccessNavigator; import org.jaxen.Navigator; import org.jaxen.XPath; import org.jaxen.JaxenConstants; import org.jaxen.util.SingleObjectIterator; /** * Interface for navigating around a JavaBean object model. * *

* This class is not intended for direct usage, but is * used by the Jaxen engine during evaluation. *

* * @see XPath * * @author bob mcwhirter */ public class DocumentNavigator extends DefaultNavigator implements NamedAccessNavigator { /** * */ private static final long serialVersionUID = -1768605107626726499L; /** Empty Class array. */ private static final Class[] EMPTY_CLASS_ARRAY = new Class[0]; /** Empty Object array. */ private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0]; /** Singleton implementation. */ private static final DocumentNavigator instance = new DocumentNavigator(); /** Retrieve the singleton instance of this DocumentNavigator. */ public static Navigator getInstance() { return instance; } public boolean isElement(Object obj) { return (obj instanceof Element); } public boolean isComment(Object obj) { return false; } public boolean isText(Object obj) { return ( obj instanceof String ); } public boolean isAttribute(Object obj) { return false; } public boolean isProcessingInstruction(Object obj) { return false; } public boolean isDocument(Object obj) { return false; } public boolean isNamespace(Object obj) { return false; } public String getElementName(Object obj) { return ((Element)obj).getName(); } public String getElementNamespaceUri(Object obj) { return ""; } public String getElementQName(Object obj) { return ""; } public String getAttributeName(Object obj) { return ""; } public String getAttributeNamespaceUri(Object obj) { return ""; } public String getAttributeQName(Object obj) { return ""; } public Iterator getChildAxisIterator(Object contextNode) { return JaxenConstants.EMPTY_ITERATOR; } /** * Retrieves an Iterator over the child elements that * match the supplied name. * * @param contextNode the origin context node * @param localName the local name of the children to return, always present * @param namespacePrefix the prefix of the namespace of the children to return * @param namespaceURI the namespace URI of the children to return * @return an Iterator that traverses the named children, or null if none */ public Iterator getChildAxisIterator(Object contextNode, String localName, String namespacePrefix, String namespaceURI) { Class cls = ((Element)contextNode).getObject().getClass(); String methodName = javacase( localName ); Method method = null; try { method = cls.getMethod( "get" + methodName, EMPTY_CLASS_ARRAY ); } catch (NoSuchMethodException e) { try { method = cls.getMethod( "get" + methodName + "s", EMPTY_CLASS_ARRAY ); } catch (NoSuchMethodException ee) { try { method = cls.getMethod( localName, EMPTY_CLASS_ARRAY ); } catch (NoSuchMethodException eee) { method = null; } } } if ( method == null ) { return JaxenConstants.EMPTY_ITERATOR; } try { Object result = method.invoke( ((Element)contextNode).getObject(), EMPTY_OBJECT_ARRAY ); if ( result == null ) { return JaxenConstants.EMPTY_ITERATOR; } if ( result instanceof Collection ) { return new ElementIterator( (Element) contextNode, localName, ((Collection)result).iterator() ); } if ( result.getClass().isArray() ) { return JaxenConstants.EMPTY_ITERATOR; } return new SingleObjectIterator( new Element( (Element) contextNode, localName, result ) ); } catch (IllegalAccessException e) { // swallow } catch (InvocationTargetException e) { // swallow } return JaxenConstants.EMPTY_ITERATOR; } public Iterator getParentAxisIterator(Object contextNode) { if ( contextNode instanceof Element ) { return new SingleObjectIterator( ((Element)contextNode).getParent() ); } return JaxenConstants.EMPTY_ITERATOR; } public Iterator getAttributeAxisIterator(Object contextNode) { return JaxenConstants.EMPTY_ITERATOR; } /** * Retrieves an Iterator over the attribute elements that * match the supplied name. * * @param contextNode the origin context node * @param localName the local name of the attributes to return, always present * @param namespacePrefix the prefix of the namespace of the attributes to return * @param namespaceURI the namespace URI of the attributes to return * @return an Iterator that traverses the named attributes, not null */ public Iterator getAttributeAxisIterator(Object contextNode, String localName, String namespacePrefix, String namespaceURI) { return JaxenConstants.EMPTY_ITERATOR; } public Iterator getNamespaceAxisIterator(Object contextNode) { return JaxenConstants.EMPTY_ITERATOR; } public Object getDocumentNode(Object contextNode) { return null; } public Object getParentNode(Object contextNode) { if ( contextNode instanceof Element ) { return ((Element)contextNode).getParent(); } return JaxenConstants.EMPTY_ITERATOR; } public String getTextStringValue(Object obj) { if ( obj instanceof Element ) { return ((Element)obj).getObject().toString(); } return obj.toString(); } public String getElementStringValue(Object obj) { if ( obj instanceof Element ) { return ((Element)obj).getObject().toString(); } return obj.toString(); } public String getAttributeStringValue(Object obj) { return obj.toString(); } public String getNamespaceStringValue(Object obj) { return obj.toString(); } public String getNamespacePrefix(Object obj) { return null; } public String getCommentStringValue(Object obj) { return null; } public String translateNamespacePrefixToUri(String prefix, Object context) { return null; } public short getNodeType(Object node) { return 0; } public Object getDocument(String uri) throws FunctionCallException { return null; } public String getProcessingInstructionTarget(Object obj) { return null; } public String getProcessingInstructionData(Object obj) { return null; } public XPath parseXPath(String xpath) throws org.jaxen.saxpath.SAXPathException { return new JavaBeanXPath( xpath ); } protected String javacase(String name) { if ( name.length() == 0 ) { return name; } else if ( name.length() == 1 ) { return name.toUpperCase(); } return name.substring( 0, 1 ).toUpperCase() + name.substring( 1 ); } } jaxen-1.1.6/src/java/main/org/jaxen/javabean/JavaBeanXPath.java0000664000175000017500000001170210440371260023532 0ustar ebourgebourg/* * $Header$ * $Revision: 1161 $ * $Date: 2006-06-03 22:36:00 +0200 (Sat, 03 Jun 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: JavaBeanXPath.java 1161 2006-06-03 20:36:00Z elharo $ */ package org.jaxen.javabean; import org.jaxen.Context; import org.jaxen.BaseXPath; import org.jaxen.JaxenException; import java.util.List; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; /** An XPath implementation for JavaBeans. * *

This is the main entry point for matching an XPath against a JavaBean * tree. You create a compiled XPath object, then match it against * one or more context nodes using the {@link #selectNodes(Object)} * method, as in the following example:

* *
 * Node node = ...;
 * XPath path = new JavaBeanXPath("a/b/c");
 * List results = path.selectNodes(node);
 * 
* * @see BaseXPath * * @author bob mcwhirter * * @version $Revision: 1161 $ */ public class JavaBeanXPath extends BaseXPath { /** * */ private static final long serialVersionUID = -1567521943360266313L; /** Construct given an XPath expression string. * * @param xpathExpr The XPath expression. * * @throws JaxenException if there is a syntax error while * parsing the expression */ public JavaBeanXPath(String xpathExpr) throws JaxenException { super( xpathExpr, DocumentNavigator.getInstance() ); } protected Context getContext(Object node) { if ( node instanceof Context ) { return (Context) node; } if ( node instanceof Element ) { return super.getContext( node ); } if ( node instanceof List ) { List newList = new ArrayList(); for ( Iterator listIter = ((List)node).iterator(); listIter.hasNext(); ) { newList.add( new Element( null, "root", listIter.next() ) ); } return super.getContext( newList ); } return super.getContext( new Element( null, "root", node ) ); } public Object evaluate(Object node) throws JaxenException { Object result = super.evaluate( node ); if ( result instanceof Element ) { return ((Element)result).getObject(); } else if ( result instanceof Collection ) { List newList = new ArrayList(); for ( Iterator listIter = ((Collection)result).iterator(); listIter.hasNext(); ) { Object member = listIter.next(); if ( member instanceof Element ) { newList.add( ((Element)member).getObject() ); } else { newList.add( member ); } } return newList; } return result; } } jaxen-1.1.6/src/java/main/org/jaxen/javabean/ElementIterator.java0000664000175000017500000000140510027430666024227 0ustar ebourgebourgpackage org.jaxen.javabean; import java.util.Iterator; public class ElementIterator implements Iterator { private Element parent; private String name; private Iterator iterator; public ElementIterator(Element parent, String name, Iterator iterator) { this.parent = parent; this.name = name; this.iterator = iterator; } public boolean hasNext() { return this.iterator.hasNext(); } public Object next() { return new Element( parent, this.name, this.iterator.next() ); } public void remove() { throw new UnsupportedOperationException(); } } jaxen-1.1.6/src/java/main/org/jaxen/javabean/package.html0000664000175000017500000000021110027430666022534 0ustar ebourgebourg org.jaxen.javabean.*

Navigation for JavaBeans.

jaxen-1.1.6/src/java/main/org/jaxen/util/0000775000175000017500000000000012174247550017472 5ustar ebourgebourgjaxen-1.1.6/src/java/main/org/jaxen/util/PrecedingAxisIterator.java0000664000175000017500000001674710526166501024606 0ustar ebourgebourgpackage org.jaxen.util; /* * $Header$ * $Revision: 1257 $ * $Date: 2006-11-13 23:10:09 +0100 (Mon, 13 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2005 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: PrecedingAxisIterator.java 1257 2006-11-13 22:10:09Z elharo $ */ import org.jaxen.JaxenConstants; import org.jaxen.JaxenRuntimeException; import org.jaxen.Navigator; import org.jaxen.UnsupportedAxisException; import java.util.ArrayList; import java.util.Iterator; import java.util.ListIterator; import java.util.NoSuchElementException; /** *

* Represents the XPath preceding axis. * The "preceding axis contains all nodes in the same document as the context * node that are before the context node in document order, excluding any ancestors * and excluding attribute nodes and namespace nodes." * *

* This implementation of 'preceding' works like so: * the preceding axis includes preceding siblings of this node and * their descendants. Also, for each ancestor node of this node, it includes * all preceding siblings of that ancestor, and their descendants. Finally, it * includes the ancestor nodes themselves. *

* *

* The reversed descendant-or-self axes that are required are calculated using a * stack of reversed 'child-or-self' axes. When asked for a node, it is always taken * from a child-or-self axis. If it was the last node on that axis, the node is returned. * Otherwise, this axis is pushed on the stack, and the process is repeated with the child-or-self * of the node. Eventually this recurses down to the last descendant of any node, then works * back up to the root. *

* *

* Most object models could provide a faster implementation of the reversed * 'children-or-self' used here.

* * @version 1.2b12 */ public class PrecedingAxisIterator implements Iterator { private Iterator ancestorOrSelf; private Iterator precedingSibling; private ListIterator childrenOrSelf; private ArrayList stack; private Navigator navigator; /** * Create a new preceding axis iterator. * * @param contextNode the node to start from * @param navigator the object model specific navigator */ public PrecedingAxisIterator(Object contextNode, Navigator navigator) throws UnsupportedAxisException { this.navigator = navigator; this.ancestorOrSelf = navigator.getAncestorOrSelfAxisIterator(contextNode); this.precedingSibling = JaxenConstants.EMPTY_ITERATOR; this.childrenOrSelf = JaxenConstants.EMPTY_LIST_ITERATOR; this.stack = new ArrayList(); } /** * Returns true if there are any preceding nodes remaining; false otherwise. * * @return true if any preceding nodes remain; false otherwise * * @see java.util.Iterator#hasNext() */ public boolean hasNext() { try { while (!childrenOrSelf.hasPrevious()) { if (stack.isEmpty()) { while (!precedingSibling.hasNext()) { if (!ancestorOrSelf.hasNext()) { return false; } Object contextNode = ancestorOrSelf.next(); precedingSibling = new PrecedingSiblingAxisIterator(contextNode, navigator); } Object node = precedingSibling.next(); childrenOrSelf = childrenOrSelf(node); } else { childrenOrSelf = (ListIterator) stack.remove(stack.size()-1); } } return true; } catch (UnsupportedAxisException e) { throw new JaxenRuntimeException(e); } } private ListIterator childrenOrSelf(Object node) { try { ArrayList reversed = new ArrayList(); reversed.add(node); Iterator childAxisIterator = navigator.getChildAxisIterator(node); if (childAxisIterator != null) { while (childAxisIterator.hasNext()) { reversed.add(childAxisIterator.next()); } } return reversed.listIterator(reversed.size()); } catch (UnsupportedAxisException e) { throw new JaxenRuntimeException(e); } } /** * Returns the next preceding node. * * @return the next preceding node * * @throws NoSuchElementException if no preceding nodes remain * * @see java.util.Iterator#next() */ public Object next() throws NoSuchElementException { if (!hasNext()) { throw new NoSuchElementException(); } while (true) { Object result = childrenOrSelf.previous(); if (childrenOrSelf.hasPrevious()) { // if this isn't 'self' construct 'descendant-or-self' stack.add(childrenOrSelf); childrenOrSelf = childrenOrSelf(result); continue; } return result; } } /** * This operation is not supported. * * @throws UnsupportedOperationException always */ public void remove() throws UnsupportedOperationException { throw new UnsupportedOperationException(); } } jaxen-1.1.6/src/java/main/org/jaxen/util/AncestorAxisIterator.java0000664000175000017500000000606710524670534024462 0ustar ebourgebourg/* * $Header$ * $Revision: 1255 $ * $Date: 2006-11-09 19:20:12 +0100 (Thu, 09 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: AncestorAxisIterator.java 1255 2006-11-09 18:20:12Z elharo $ */ package org.jaxen.util; import org.jaxen.Navigator; /** * Represents the XPath ancestor axis. * The "ancestor axis contains the ancestors of the context node; * the ancestors of the context node consist of the parent of context node and * the parent's parent and so on; thus, the ancestor axis will always include * the root node, unless the context node is the root node." * * @version 1.2b12 */ public class AncestorAxisIterator extends AncestorOrSelfAxisIterator { /** * Create a new ancestor axis iterator. * * @param contextNode the node to start from * @param navigator the object model specific navigator */ public AncestorAxisIterator(Object contextNode, Navigator navigator) { super( contextNode, navigator ); next(); } } jaxen-1.1.6/src/java/main/org/jaxen/util/StackedIterator.java0000664000175000017500000001171210371471320023416 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: StackedIterator.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.util; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.NoSuchElementException; import java.util.Set; import org.jaxen.Navigator; /** * @deprecated this iterator is no longer used to implement any of the Jaxen axes. If you have implemented * a navigator-specific axis based on this class, take a look at the DescendantAxisIterator for ideas * on how to remove that dependency. */ public abstract class StackedIterator implements Iterator { private LinkedList iteratorStack; private Navigator navigator; private Set created; public StackedIterator(Object contextNode, Navigator navigator) { this.iteratorStack = new LinkedList(); this.created = new HashSet(); init( contextNode, navigator ); } protected StackedIterator() { this.iteratorStack = new LinkedList(); this.created = new HashSet(); } protected void init(Object contextNode, Navigator navigator) { this.navigator = navigator; //pushIterator( internalCreateIterator( contextNode ) ); } protected Iterator internalCreateIterator(Object contextNode) { if ( this.created.contains( contextNode ) ) { return null; } this.created.add( contextNode ); return createIterator( contextNode ); } public boolean hasNext() { Iterator curIter = currentIterator(); if ( curIter == null ) { return false; } return curIter.hasNext(); } public Object next() throws NoSuchElementException { if ( ! hasNext() ) { throw new NoSuchElementException(); } Iterator curIter = currentIterator(); Object object = curIter.next(); pushIterator( internalCreateIterator( object ) ); return object; } public void remove() throws UnsupportedOperationException { throw new UnsupportedOperationException(); } abstract protected Iterator createIterator(Object contextNode); protected void pushIterator(Iterator iter) { if ( iter != null ) { this.iteratorStack.addFirst(iter); //addLast( iter ); } } private Iterator currentIterator() { while ( iteratorStack.size() > 0 ) { Iterator curIter = (Iterator) iteratorStack.getFirst(); if ( curIter.hasNext() ) { return curIter; } iteratorStack.removeFirst(); } return null; } protected Navigator getNavigator() { return this.navigator; } } jaxen-1.1.6/src/java/main/org/jaxen/util/DescendantAxisIterator.java0000664000175000017500000001150610524670534024746 0ustar ebourgebourgpackage org.jaxen.util; /* * $Header$ * $Revision: 1255 $ * $Date: 2006-11-09 19:20:12 +0100 (Thu, 09 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2005 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DescendantAxisIterator.java 1255 2006-11-09 18:20:12Z elharo $ */ import org.jaxen.Navigator; import org.jaxen.UnsupportedAxisException; import org.jaxen.JaxenRuntimeException; import java.util.Iterator; import java.util.NoSuchElementException; import java.util.ArrayList; /** * Represents the XPath descendant axis. * The "descendant axis contains the descendants of the context node; * a descendant is a child or a child of a child and so on; thus * the descendant axis never contains attribute or namespace nodes." * * @version 1.2b12 */ public class DescendantAxisIterator implements Iterator { private ArrayList stack = new ArrayList(); private Iterator children; private Navigator navigator; /** * Create a new descendant axis iterator. * * @param contextNode the node to start from * @param navigator the object model specific navigator */ public DescendantAxisIterator(Object contextNode, Navigator navigator) throws UnsupportedAxisException { this(navigator, navigator.getChildAxisIterator(contextNode)); } public DescendantAxisIterator(Navigator navigator, Iterator iterator) { this.navigator = navigator; this.children = iterator; } /** * Returns true if there are any descendants remaining; false otherwise. * * @return true if any descendants remain; false otherwise * * @see java.util.Iterator#hasNext() */ public boolean hasNext() { while (!children.hasNext()) { if (stack.isEmpty()) { return false; } children = (Iterator) stack.remove(stack.size()-1); } return true; } /** * Returns the next descendant node. * * @return the next descendant node * * @throws NoSuchElementException if no descendants remain * * @see java.util.Iterator#next() */ public Object next() { try { if (hasNext()) { Object node = children.next(); stack.add(children); children = navigator.getChildAxisIterator(node); return node; } throw new NoSuchElementException(); } catch (UnsupportedAxisException e) { throw new JaxenRuntimeException(e); } } /** * This operation is not supported. * * @throws UnsupportedOperationException always */ public void remove() { throw new UnsupportedOperationException(); } } jaxen-1.1.6/src/java/main/org/jaxen/util/AncestorOrSelfAxisIterator.java0000664000175000017500000001071710524670534025572 0ustar ebourgebourgpackage org.jaxen.util; /* * $Header$ * $Revision: 1255 $ * $Date: 2006-11-09 19:20:12 +0100 (Thu, 09 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2005 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: AncestorOrSelfAxisIterator.java 1255 2006-11-09 18:20:12Z elharo $ */ import java.util.Iterator; import java.util.NoSuchElementException; import org.jaxen.Navigator; import org.jaxen.UnsupportedAxisException; import org.jaxen.JaxenRuntimeException; /** *

* Represents the XPath ancestor-or-self axis. * The "ancestor-or-self axis contains the context node and * the ancestors of the context node; thus, the ancestor axis will * always include the root node." *

* * @version 1.2b12 */ public class AncestorOrSelfAxisIterator implements Iterator { private Object contextNode; private Navigator navigator; /** * Create a new ancestor-or-self axis iterator. * * @param contextNode the node to start from * @param navigator the object model specific navigator */ public AncestorOrSelfAxisIterator(Object contextNode, Navigator navigator) { // XXX should we throw a NullPointerException here if contextNode is null? this.contextNode = contextNode; this.navigator = navigator; } /** * Returns true if there are any nodes remaining * on the ancestor-or-self axis; false otherwise. * * @return true if any ancestors or self remain * * @see java.util.Iterator#hasNext() */ public boolean hasNext() { return contextNode != null; } /** * Returns the next ancestor-or-self node. * * @return the next ancestor-or-self node * * @throws NoSuchElementException if no ancestors remain * * @see java.util.Iterator#next() */ public Object next() { try { if (hasNext()) { Object result = contextNode; contextNode = navigator.getParentNode(contextNode); return result; } throw new NoSuchElementException("Exhausted ancestor-or-self axis"); } catch (UnsupportedAxisException e) { throw new JaxenRuntimeException(e); } } /** * This operation is not supported. * * @throws UnsupportedOperationException always */ public void remove() { throw new UnsupportedOperationException(); } } jaxen-1.1.6/src/java/main/org/jaxen/util/LinkedIterator.java0000664000175000017500000000712110524670534023255 0ustar ebourgebourg/* * $Header$ * $Revision: 1255 $ * $Date: 2006-11-09 19:20:12 +0100 (Thu, 09 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: LinkedIterator.java 1255 2006-11-09 18:20:12Z elharo $ */ package org.jaxen.util; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; /** * @deprecated This class is undocumented and untested. * It will be removed in a future release. */ public class LinkedIterator implements Iterator { private List iterators; private int cur; public LinkedIterator() { this.iterators = new ArrayList(); this.cur = 0; } public void addIterator(Iterator i) { this.iterators.add( i ); } public boolean hasNext() { boolean has = false; if ( this.cur < this.iterators.size() ) { has = ((Iterator)this.iterators.get( this.cur )).hasNext(); if ( ! has && this.cur < this.iterators.size() ) { ++this.cur; has = hasNext(); } } else { has = false; } return has; } public Object next() { if ( ! hasNext() ) { throw new NoSuchElementException(); } return ((Iterator)this.iterators.get( this.cur )).next(); } /** * This operation is not supported. * * @throws UnsupportedOperationException */ public void remove() { throw new UnsupportedOperationException(); } } jaxen-1.1.6/src/java/main/org/jaxen/util/FollowingAxisIterator.java0000664000175000017500000001313310524670534024634 0ustar ebourgebourgpackage org.jaxen.util; /* * $Header$ * $Revision: 1255 $ * $Date: 2006-11-09 19:20:12 +0100 (Thu, 09 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2005 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: FollowingAxisIterator.java 1255 2006-11-09 18:20:12Z elharo $ */ import java.util.Iterator; import java.util.NoSuchElementException; import org.jaxen.Navigator; import org.jaxen.UnsupportedAxisException; import org.jaxen.JaxenRuntimeException; import org.jaxen.JaxenConstants; /** * Represents the XPath following axis. * The "following axis contains all nodes in the same document as the context * node that are after the context node in document order, excluding any descendants * and excluding attribute nodes and namespace nodes." * * @version 1.2b12 */ public class FollowingAxisIterator implements Iterator { private Object contextNode; private Navigator navigator; private Iterator siblings; private Iterator currentSibling; /** * Create a new following axis iterator. * * @param contextNode the node to start from * @param navigator the object model specific navigator */ public FollowingAxisIterator(Object contextNode, Navigator navigator) throws UnsupportedAxisException { this.contextNode = contextNode; this.navigator = navigator; this.siblings = navigator.getFollowingSiblingAxisIterator(contextNode); this.currentSibling = JaxenConstants.EMPTY_ITERATOR; } private boolean goForward() { while ( ! siblings.hasNext() ) { if ( !goUp() ) { return false; } } Object nextSibling = siblings.next(); this.currentSibling = new DescendantOrSelfAxisIterator(nextSibling, navigator); return true; } private boolean goUp() { if ( contextNode == null || navigator.isDocument(contextNode) ) { return false; } try { contextNode = navigator.getParentNode( contextNode ); if ( contextNode != null && !navigator.isDocument(contextNode) ) { siblings = navigator.getFollowingSiblingAxisIterator(contextNode); return true; } else { return false; } } catch (UnsupportedAxisException e) { throw new JaxenRuntimeException(e); } } /** * Returns true if there are any following nodes remaining; * false otherwise. * * @return true if any following nodes remain * * @see java.util.Iterator#hasNext() */ public boolean hasNext() { while ( ! currentSibling.hasNext() ) { if ( ! goForward() ) { return false; } } return true; } /** * Returns the next following node. * * @return the next following node * * @throws NoSuchElementException if no following nodes remain * * @see java.util.Iterator#next() */ public Object next() throws NoSuchElementException { if ( ! hasNext() ) { throw new NoSuchElementException(); } return currentSibling.next(); } /** * This operation is not supported. * * @throws UnsupportedOperationException always */ public void remove() throws UnsupportedOperationException { throw new UnsupportedOperationException(); } } jaxen-1.1.6/src/java/main/org/jaxen/util/PrecedingSiblingAxisIterator.java0000664000175000017500000001264310526166501026105 0ustar ebourgebourg/* * $Header$ * $Revision: 1257 $ * $Date: 2006-11-13 23:10:09 +0100 (Mon, 13 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: PrecedingSiblingAxisIterator.java 1257 2006-11-13 22:10:09Z elharo $ */ package org.jaxen.util; import java.util.Iterator; import java.util.LinkedList; import java.util.NoSuchElementException; import org.jaxen.JaxenConstants; import org.jaxen.Navigator; import org.jaxen.UnsupportedAxisException; /** * * Represents the XPath preceding-sibling axis. * The "preceding-sibling axis contains all the * preceding siblings of the context node; if the context node is an * attribute node or namespace node, the preceding-sibling * axis is empty." * * @version 1.2b12 * */ public class PrecedingSiblingAxisIterator implements Iterator { private Object contextNode; private Navigator navigator; private Iterator siblingIter; private Object nextObj; /** * Create a new preceding-sibling axis iterator. * * @param contextNode the node to start from * @param navigator the object model specific navigator */ public PrecedingSiblingAxisIterator(Object contextNode, Navigator navigator) throws UnsupportedAxisException { this.contextNode = contextNode; this.navigator = navigator; init(); if ( siblingIter.hasNext() ) { this.nextObj = siblingIter.next(); } } private void init() throws UnsupportedAxisException { Object parent = this.navigator.getParentNode( this.contextNode ); if ( parent != null ) { Iterator childIter = this.navigator.getChildAxisIterator( parent ); LinkedList siblings = new LinkedList(); while ( childIter.hasNext() ) { Object eachChild = childIter.next(); if ( eachChild.equals(this.contextNode) ) { break; } siblings.addFirst( eachChild ); } this.siblingIter = siblings.iterator(); } else { this.siblingIter = JaxenConstants.EMPTY_ITERATOR; } } /** * Returns true if there are any preceding siblings remaining; false otherwise. * * @return true if any preceding siblings remain; false otherwise * * @see java.util.Iterator#hasNext() */ public boolean hasNext() { return ( this.nextObj != null ); } /** * Returns the next preceding sibling. * * @return the next preceding sibling * * @throws NoSuchElementException if no preceding siblings remain * * @see java.util.Iterator#next() */ public Object next() throws NoSuchElementException { if ( ! hasNext() ) { throw new NoSuchElementException(); } Object obj = this.nextObj; if ( siblingIter.hasNext() ) { this.nextObj = siblingIter.next(); } else { this.nextObj = null; } return obj; } /** * This operation is not supported. * * @throws UnsupportedOperationException */ public void remove() throws UnsupportedOperationException { throw new UnsupportedOperationException(); } } jaxen-1.1.6/src/java/main/org/jaxen/util/SingleObjectIterator.java0000664000175000017500000000737010524670534024425 0ustar ebourgebourg/* * $Header$ * $Revision: 1255 $ * $Date: 2006-11-09 19:20:12 +0100 (Thu, 09 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: SingleObjectIterator.java 1255 2006-11-09 18:20:12Z elharo $ */ package org.jaxen.util; import java.util.Iterator; import java.util.NoSuchElementException; /** * Simple utility class that wraps an iterator around one object. * This is a little more efficent than creating a one-object list. * */ public class SingleObjectIterator implements Iterator { private Object object; private boolean seen; /** * Creates a new single object iterator. * * @param object the object to iterate over */ public SingleObjectIterator(Object object) { this.object = object; this.seen = false; } /** * Returns true if this iterator's element has not yet been seen; false if it has. * * @return true if this iterator has another element; false if it doesn't * * @see java.util.Iterator#hasNext() */ public boolean hasNext() { return ! this.seen; } /** * Returns the single element in this iterator if it has not yet * been seen. * * @return the next element in this iterator * * @throws NoSuchElementException if the element has already been seen * * @see java.util.Iterator#next() */ public Object next() { if ( hasNext() ) { this.seen = true; return this.object; } throw new NoSuchElementException(); } /** * This operation is not supported. * * @throws UnsupportedOperationException always */ public void remove() { throw new UnsupportedOperationException(); } } jaxen-1.1.6/src/java/main/org/jaxen/util/FollowingSiblingAxisIterator.java0000664000175000017500000001135010524670534026143 0ustar ebourgebourg/* * $Header$ * $Revision: 1255 $ * $Date: 2006-11-09 19:20:12 +0100 (Thu, 09 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: FollowingSiblingAxisIterator.java 1255 2006-11-09 18:20:12Z elharo $ */ package org.jaxen.util; import java.util.Iterator; import java.util.NoSuchElementException; import org.jaxen.JaxenConstants; import org.jaxen.Navigator; import org.jaxen.UnsupportedAxisException; /** * * Represents the XPath following-sibling axis. * The "following-sibling axis contains all the * folowing siblings of the context node; if the context node is an * attribute node or namespace node, the following-sibling * axis is empty." * * @version 1.2b12 * */ public class FollowingSiblingAxisIterator implements Iterator { private Object contextNode; private Navigator navigator; private Iterator siblingIter; /** * Create a new following-sibling axis iterator. * * @param contextNode the node to start from * @param navigator the object model specific navigator */ public FollowingSiblingAxisIterator(Object contextNode, Navigator navigator) throws UnsupportedAxisException { this.contextNode = contextNode; this.navigator = navigator; init(); } private void init() throws UnsupportedAxisException { Object parent = this.navigator.getParentNode( this.contextNode ); if ( parent != null ) { siblingIter = this.navigator.getChildAxisIterator( parent ); while ( siblingIter.hasNext() ) { Object eachChild = siblingIter.next(); if ( eachChild.equals(this.contextNode) ) break; } } else { siblingIter = JaxenConstants.EMPTY_ITERATOR; } } /** * Returns true if there are any following siblings remain; false otherwise. * * @return true if any following siblings remain; false otherwise * * @see java.util.Iterator#hasNext() */ public boolean hasNext() { return siblingIter.hasNext(); } /** * Returns the next following sibling. * * @return the next following sibling * * @throws NoSuchElementException if no following siblings remain * * @see java.util.Iterator#next() */ public Object next() throws NoSuchElementException { return siblingIter.next(); } /** * This operation is not supported. * * @throws UnsupportedOperationException always */ public void remove() throws UnsupportedOperationException { throw new UnsupportedOperationException(); } } jaxen-1.1.6/src/java/main/org/jaxen/util/SelfAxisIterator.java0000664000175000017500000000516710616120471023565 0ustar ebourgebourg/* * $Header$ * $Revision: 1302 $ * $Date: 2007-05-02 16:33:29 +0200 (Wed, 02 May 2007) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: SelfAxisIterator.java 1302 2007-05-02 14:33:29Z elharo $ */ package org.jaxen.util; /** * * Represents the XPath self axis. The "self axis contains * just the context node itself." * * @version 1.1.1 * */ public class SelfAxisIterator extends SingleObjectIterator { /** * Create a new self axis iterator. * * @param node the node to start from */ public SelfAxisIterator(Object node) { super(node); } } jaxen-1.1.6/src/java/main/org/jaxen/util/SingletonList.java0000664000175000017500000000637510524654667023156 0ustar ebourgebourg/* * $Header$ * $Revision: 1253 $ * $Date: 2006-11-09 17:39:19 +0100 (Thu, 09 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: SingletonList.java 1253 2006-11-09 16:39:19Z elharo $ */ package org.jaxen.util; import java.util.AbstractList; /** * A utility class that implements singleton lists * (to avoid dependency on JDK 1.3). Many operations * including add() and remove() throw * UnsupportedOperationExceptions. * * @version 1.2b12 * @author Attila Szegedi * */ public class SingletonList extends AbstractList { private final Object element; /** * Creates a new singleton list. * * @param element the single member of the list */ public SingletonList(Object element) { this.element = element; } /** * Returns 1. * * @return 1 */ public int size() { return 1; } /** * Returns the single element in the list. * * @return the only element in the list * * @throws IndexOutOfBoundsException if index is not 0 * */ public Object get(int index) { if(index == 0) { return element; } throw new IndexOutOfBoundsException(index + " != 0"); } } jaxen-1.1.6/src/java/main/org/jaxen/util/package.html0000664000175000017500000000022607327350513021751 0ustar ebourgebourg org.jaxen.util.*

Utility objects for walking object models.

jaxen-1.1.6/src/java/main/org/jaxen/util/DescendantOrSelfAxisIterator.java0000664000175000017500000000566010524670534026065 0ustar ebourgebourgpackage org.jaxen.util; /* * $Header$ * $Revision: 1255 $ * $Date: 2006-11-09 19:20:12 +0100 (Thu, 09 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2005 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DescendantOrSelfAxisIterator.java 1255 2006-11-09 18:20:12Z elharo $ */ import org.jaxen.Navigator; /** * Represents the XPath descendant-or-self axis. * The "descendant-or-self axis contains the context node * and the descendants of the context node." * * @version 1.2b12 */ public class DescendantOrSelfAxisIterator extends DescendantAxisIterator { /** * Create a new desscendant-or-self axis iterator. * * @param contextNode the node to start from * @param navigator the object model specific navigator */ public DescendantOrSelfAxisIterator(Object contextNode, Navigator navigator) { super(navigator, new SingleObjectIterator(contextNode)); } } jaxen-1.1.6/src/java/main/org/jaxen/DefaultNavigator.java0000664000175000017500000002305310371471320022611 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultNavigator.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen; import java.util.Iterator; import org.jaxen.pattern.Pattern; import org.jaxen.util.AncestorAxisIterator; import org.jaxen.util.AncestorOrSelfAxisIterator; import org.jaxen.util.DescendantAxisIterator; import org.jaxen.util.DescendantOrSelfAxisIterator; import org.jaxen.util.FollowingAxisIterator; import org.jaxen.util.FollowingSiblingAxisIterator; import org.jaxen.util.PrecedingAxisIterator; import org.jaxen.util.PrecedingSiblingAxisIterator; import org.jaxen.util.SelfAxisIterator; /** Default implementation of {@link Navigator}. * *

* This implementation is an abstract class, since * some required operations cannot be implemented without * additional knowledge of the object model. *

* *

* When possible, default method implementations build * upon each other, to reduce the number of methods required * to be implemented for each object model. All methods, * of course, may be overridden, to provide more-efficient * implementations. *

* * @author bob mcwhirter (bob@werken.com) * @author Erwin Bolwidt (ejb@klomp.org) */ public abstract class DefaultNavigator implements Navigator { /** Throws UnsupportedAxisException * * @param contextNode * @return never returns * @throws UnsupportedAxisException always */ public Iterator getChildAxisIterator(Object contextNode) throws UnsupportedAxisException { throw new UnsupportedAxisException("child"); } /* (non-Javadoc) * @see org.jaxen.Navigator#getDescendantAxisIterator(java.lang.Object) */ public Iterator getDescendantAxisIterator(Object contextNode) throws UnsupportedAxisException { return new DescendantAxisIterator( contextNode, this ); } /** Throws UnsupportedAxisException * * @param contextNode * @return never returns * @throws UnsupportedAxisException */ public Iterator getParentAxisIterator(Object contextNode) throws UnsupportedAxisException { throw new UnsupportedAxisException("parent"); } public Iterator getAncestorAxisIterator(Object contextNode) throws UnsupportedAxisException { return new AncestorAxisIterator( contextNode, this ); } public Iterator getFollowingSiblingAxisIterator(Object contextNode) throws UnsupportedAxisException { return new FollowingSiblingAxisIterator( contextNode, this ); } public Iterator getPrecedingSiblingAxisIterator(Object contextNode) throws UnsupportedAxisException { return new PrecedingSiblingAxisIterator( contextNode, this ); } public Iterator getFollowingAxisIterator(Object contextNode) throws UnsupportedAxisException { return new FollowingAxisIterator( contextNode, this ); // throw new UnsupportedAxisException("following"); } public Iterator getPrecedingAxisIterator(Object contextNode) throws UnsupportedAxisException { return new PrecedingAxisIterator( contextNode, this ); // throw new UnsupportedAxisException("preceding"); } /** Throws UnsupportedAxisException. Subclasses that * support the attribute axis must override this method. * * @param contextNode * @return never returns * @throws UnsupportedAxisException */ public Iterator getAttributeAxisIterator(Object contextNode) throws UnsupportedAxisException { throw new UnsupportedAxisException("attribute"); } /** Throws UnsupportedAxisException. Subclasses that * support the namespace axis must override this method. * * @param contextNode * @return never returns * @throws UnsupportedAxisException */ public Iterator getNamespaceAxisIterator(Object contextNode) throws UnsupportedAxisException { throw new UnsupportedAxisException("namespace"); } public Iterator getSelfAxisIterator(Object contextNode) throws UnsupportedAxisException { return new SelfAxisIterator( contextNode ); } public Iterator getDescendantOrSelfAxisIterator(Object contextNode) throws UnsupportedAxisException { return new DescendantOrSelfAxisIterator( contextNode, this ); } public Iterator getAncestorOrSelfAxisIterator(Object contextNode) throws UnsupportedAxisException { return new AncestorOrSelfAxisIterator( contextNode, this ); } public Object getDocumentNode(Object contextNode) { return null; } public String translateNamespacePrefixToUri(String prefix, Object element) { return null; } public String getProcessingInstructionTarget(Object obj) { return null; } public String getProcessingInstructionData(Object obj) { return null; } public short getNodeType(Object node) { if ( isElement(node) ) { return Pattern.ELEMENT_NODE; } else if ( isAttribute(node) ) { return Pattern.ATTRIBUTE_NODE; } else if ( isText(node) ) { return Pattern.TEXT_NODE; } else if ( isComment(node) ) { return Pattern.COMMENT_NODE; } else if ( isDocument(node) ) { return Pattern.DOCUMENT_NODE; } else if ( isProcessingInstruction(node) ) { return Pattern.PROCESSING_INSTRUCTION_NODE; } else if ( isNamespace(node) ) { return Pattern.NAMESPACE_NODE; } else { return Pattern.UNKNOWN_NODE; } } /** * Default inefficient implementation. Subclasses * should override this method. * * @param contextNode the node whose parent to return * @return the parent node * @throws UnsupportedAxisException if the parent axis is not supported */ public Object getParentNode(Object contextNode) throws UnsupportedAxisException { Iterator iter = getParentAxisIterator( contextNode ); if ( iter != null && iter.hasNext() ) { return iter.next(); } return null; } /** * Default implementation that always returns null. Override in subclass * if the subclass can load documents. * * @param url the URL of the document to load * * @return null * @throws FunctionCallException if an error occurs while loading the * URL; e.g. an I/O error or the document is malformed */ public Object getDocument(String url) throws FunctionCallException { return null; } /** * Default implementation that cannot find elements. Override in subclass * if subclass does know about attribute types. * * @param contextNode a node from the document in which to look for the * id * @param elementId id to look for * * @return null */ public Object getElementById(Object contextNode, String elementId) { return null; } } jaxen-1.1.6/src/java/main/org/jaxen/XPathSyntaxException.java0000664000175000017500000001211710440371260023462 0ustar ebourgebourg/* * $Header$ * $Revision: 1161 $ * $Date: 2006-06-03 22:36:00 +0200 (Sat, 03 Jun 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: XPathSyntaxException.java 1161 2006-06-03 20:36:00Z elharo $ */ package org.jaxen; /** Indicates an error during parsing of an XPath expression. * * @author bob mcwhirter * @author James Strachan */ public class XPathSyntaxException extends JaxenException { /** * */ private static final long serialVersionUID = 1980601567207604059L; /** The textual XPath expression */ private String xpath; /** The position of the error */ private int position; /** * Create a new XPathSyntaxException wrapping an existing * org.jaxen.saxpath.XPathSyntaxException. * * @param e the exception that caused this exception */ public XPathSyntaxException(org.jaxen.saxpath.XPathSyntaxException e) { super( e ); this.xpath = e.getXPath(); this.position = e.getPosition(); } /** Constructor * * @param xpath the erroneous XPath expression * @param position the position of the error * @param message the error message */ public XPathSyntaxException(String xpath, int position, String message) { super( message ); this.xpath = xpath; this.position = position; } /** Retrieve the position of the error. * * @return the position of the error */ public int getPosition() { return this.position; } /** Retrieve the expression containing the error. * * @return the erroneous expression */ public String getXPath() { return this.xpath; } /** Retrieve a string useful for denoting where * the error occurred. * *

* This is a string composed of whitespace and * a marker at the position (see {@link #getPosition}) * of the error. This is useful for creating * friendly multi-line error displays. *

* * @return the error position marker */ public String getPositionMarker() { StringBuffer buf = new StringBuffer(); int pos = getPosition(); for ( int i = 0 ; i < pos ; ++i ) { buf.append(" "); } buf.append("^"); return buf.toString(); } /** Retrieve the friendly multi-line error message. * *

* This returns a multi-line string that contains * the original erroneous XPath expression with a * marker underneath indicating exactly where the * error occurred. *

* * @return the multi-line error message */ public String getMultilineMessage() { StringBuffer buf = new StringBuffer(getMessage()); buf.append( "\n" ); buf.append( getXPath() ); buf.append( "\n" ); buf.append( getPositionMarker() ); return buf.toString(); } } jaxen-1.1.6/src/java/main/org/jaxen/SimpleVariableContext.java0000664000175000017500000001207210440370076023620 0ustar ebourgebourg/* * $Header$ * $Revision: 1159 $ * $Date: 2006-06-03 22:25:34 +0200 (Sat, 03 Jun 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: SimpleVariableContext.java 1159 2006-06-03 20:25:34Z elharo $ */ package org.jaxen; import java.io.Serializable; import java.util.HashMap; import java.util.Map; /** Simple default implementation for VariableContext. * *

* This is a simple table-based key-lookup implementation * for VariableContext which can be programmatically * extended by setting additional variables. *

* * @author bob mcwhirter */ public class SimpleVariableContext implements VariableContext, Serializable { /** * */ private static final long serialVersionUID = 961322093794516518L; /** Table of variable bindings. */ private Map variables; /** Construct. * *

* Create a new empty variable context. *

*/ public SimpleVariableContext() { variables = new HashMap(); } /** Set the value associated with a variable. * *

* This method sets a variable that is * associated with a particular namespace. * These variables appear such as $prefix:foo * in an XPath expression. Prefix to URI resolution * is the responsibility of a NamespaceContext. * Variables within a VariableContext are * referred to purely based upon their namespace URI, * if any. *

* * @param namespaceURI the namespace URI of the variable * @param localName the local name of the variable * @param value The value to be bound to the variable */ public void setVariableValue( String namespaceURI, String localName, Object value ) { this.variables.put( new QualifiedName(namespaceURI, localName), value ); } /** Set the value associated with a variable. * *

* This method sets a variable that is not * associated with any particular namespace. * These variables look like $foo * in an XPath expression. *

* * @param localName the local name of the variable * @param value the value to be bound to the variable */ public void setVariableValue( String localName, Object value ) { this.variables.put( new QualifiedName(null, localName), value ); } public Object getVariableValue( String namespaceURI, String prefix, String localName ) throws UnresolvableException { QualifiedName key = new QualifiedName( namespaceURI, localName ); if ( this.variables.containsKey(key) ) { return this.variables.get( key ); } else { throw new UnresolvableException( "Variable " + key.getClarkForm() ); } } } jaxen-1.1.6/src/java/main/org/jaxen/JaxenRuntimeException.java0000664000175000017500000001137610440366577023665 0ustar ebourgebourgpackage org.jaxen; import java.io.PrintStream; import java.io.PrintWriter; /* * $Header: $ * $Revision: $ * $Date: $ * * ==================================================================== * * Copyright 2000-2005 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: $ */ /** * This class exists to wrap Jaxen exceptions that otherwise wouldn't be propagated * up through the axis iterators. */ public class JaxenRuntimeException extends RuntimeException { /** * */ private static final long serialVersionUID = -930309761511911193L; private Throwable cause; private boolean causeSet = false; /** * Create a new JaxenRuntimeException. * * @param cause the nested exception that's wrapped * inside this exception */ public JaxenRuntimeException(Throwable cause) { super(cause.getMessage()); initCause(cause); } /** * Create a new JaxenRuntimeException. * * @param message the detail message */ public JaxenRuntimeException(String message) { super(message); } /** * Returns the exception that caused this exception. * This is necessary to implement Java 1.4 chained exception * functionality in a Java 1.3-compatible way. * * @return the exception that caused this exception */ public Throwable getCause() { return cause; } /** * Sets the exception that caused this exception. * This is necessary to implement Java 1.4 chained exception * functionality in a Java 1.3-compatible way. * * @param cause the exception wrapped in this runtime exception * * @return this exception */ public Throwable initCause(Throwable cause) { if (causeSet) throw new IllegalStateException("Cause cannot be reset"); if (cause == this) throw new IllegalArgumentException("Exception cannot be its own cause"); causeSet = true; this.cause = cause; return this; } /** Print this exception's stack trace, followed by the * source exception's trace, if any. * * @param s the stream on which to print the stack trace */ public void printStackTrace ( PrintStream s ) { super.printStackTrace ( s ); if (JaxenException.javaVersion < 1.4 && getCause() != null) { s.print( "Caused by: " ); getCause().printStackTrace( s ); } } /** Print this exception's stack trace, followed by the * source exception's stack trace, if any. * * @param s the writer on which to print the stack trace */ public void printStackTrace ( PrintWriter s ) { super.printStackTrace( s ); if (JaxenException.javaVersion < 1.4 && getCause() != null) { s.print( "Caused by: " ); getCause().printStackTrace( s ); } } } jaxen-1.1.6/src/java/main/org/jaxen/overview.html0000664000175000017500000000237410224554661021255 0ustar ebourgebourg Jaxen: Java XPath Engine

Jaxen is a fast Java engine for XPath 1.0 that works on all XML object models.

Jaxen currently works with the following XML models: dom4j, JDOM, W3C DOM and XOM.

An XPath implementation is typically all that's required to get started with Jaxen.

Object Model Class
dom4j {@link org.jaxen.dom4j.Dom4jXPath org.jaxen.dom4j.Dom4jXPath}
JDOM {@link org.jaxen.jdom.JDOMXPath org.jaxen.jdom.JDOMXPath}
W3C DOM {@link org.jaxen.dom.DOMXPath org.jaxen.dom.DOMXPath}
XOM {@link org.jaxen.xom.XOMXPath org.jaxen.xom.XOMXPath}
jaxen-1.1.6/src/java/main/org/jaxen/Navigator.java0000664000175000017500000004574010440366011021310 0ustar ebourgebourgpackage org.jaxen; /* * $Header$ * $Revision: 1157 $ * $Date: 2006-06-03 22:07:37 +0200 (Sat, 03 Jun 2006) $ * * ==================================================================== * * Copyright 2000-2005 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: Navigator.java 1157 2006-06-03 20:07:37Z elharo $ */ import java.io.Serializable; import java.util.Iterator; import org.jaxen.saxpath.SAXPathException; /** Interface for navigating around an arbitrary object * model, using XPath semantics. * *

* There is a method to obtain a java.util.Iterator, * for each axis specified by XPath. If the target object model * does not support the semantics of a particular axis, an * {@link UnsupportedAxisException} is to be thrown. If there are * no nodes on that axis, an empty iterator should be returned. *

* * @author bob mcwhirter * @author James Strachan * * @version $Id: Navigator.java 1157 2006-06-03 20:07:37Z elharo $ */ public interface Navigator extends Serializable { // ---------------------------------------------------------------------- // Axis Iterators // ---------------------------------------------------------------------- /** Retrieve an Iterator matching the child * XPath axis. * * @param contextNode the original context node * * @return an Iterator capable of traversing the axis, not null * * @throws UnsupportedAxisException if the semantics of the child axis are * not supported by this object model */ Iterator getChildAxisIterator(Object contextNode) throws UnsupportedAxisException; /** Retrieve an Iterator matching the descendant * XPath axis. * * @param contextNode the original context node * * @return an Iterator capable of traversing the axis, not null * * @throws UnsupportedAxisException if the semantics of the desscendant axis are * not supported by this object model */ Iterator getDescendantAxisIterator(Object contextNode) throws UnsupportedAxisException; /** Retrieve an Iterator matching the parent XPath axis. * * @param contextNode the original context node * * @return an Iterator capable of traversing the axis, not null * * @throws UnsupportedAxisException if the semantics of the parent axis are * not supported by this object model */ Iterator getParentAxisIterator(Object contextNode) throws UnsupportedAxisException; /** Retrieve an Iterator matching the ancestor * XPath axis. * * @param contextNode the original context node * * @return an Iterator capable of traversing the axis, not null * * @throws UnsupportedAxisException if the semantics of the ancestor axis are * not supported by this object model */ Iterator getAncestorAxisIterator(Object contextNode) throws UnsupportedAxisException; /** Retrieve an Iterator matching the * following-sibling XPath axis. * * @param contextNode the original context node * * @return an Iterator capable of traversing the axis, not null * * @throws UnsupportedAxisException if the semantics of the following-sibling axis are * not supported by this object model */ Iterator getFollowingSiblingAxisIterator(Object contextNode) throws UnsupportedAxisException; /** Retrieve an Iterator matching the * preceding-sibling XPath axis. * * @param contextNode the original context node * * @return an Iterator capable of traversing the axis, not null * * @throws UnsupportedAxisException if the semantics of the preceding-sibling axis are * not supported by this object model */ Iterator getPrecedingSiblingAxisIterator(Object contextNode) throws UnsupportedAxisException; /** Retrieve an Iterator matching the following * XPath axis. * * @param contextNode the original context node * * @return an Iterator capable of traversing the axis, not null * * @throws UnsupportedAxisException if the semantics of the following axis are * not supported by this object model */ Iterator getFollowingAxisIterator(Object contextNode) throws UnsupportedAxisException; /** Retrieve an Iterator matching the preceding XPath axis. * * @param contextNode the original context node * * @return an Iterator capable of traversing the axis, not null * * @throws UnsupportedAxisException if the semantics of the preceding axis are * not supported by this object model */ Iterator getPrecedingAxisIterator(Object contextNode) throws UnsupportedAxisException; /** Retrieve an Iterator matching the attribute * XPath axis. * * @param contextNode the original context node * * @return an Iterator capable of traversing the axis, not null * * @throws UnsupportedAxisException if the semantics of the attribute axis are * not supported by this object model */ Iterator getAttributeAxisIterator(Object contextNode) throws UnsupportedAxisException; /** Retrieve an Iterator matching the namespace * XPath axis. * * @param contextNode the original context node * * @return an Iterator capable of traversing the axis, not null * * @throws UnsupportedAxisException if the semantics of the namespace axis are * not supported by this object model */ Iterator getNamespaceAxisIterator(Object contextNode) throws UnsupportedAxisException; /** Retrieve an Iterator matching the self XPath * axis. * * @param contextNode the original context node * * @return an Iterator capable of traversing the axis, not null * * @throws UnsupportedAxisException if the semantics of the self axis are * not supported by this object model */ Iterator getSelfAxisIterator(Object contextNode) throws UnsupportedAxisException; /** Retrieve an Iterator matching the * descendant-or-self XPath axis. * * @param contextNode the original context node * * @return an Iterator capable of traversing the axis, not null * * @throws UnsupportedAxisException if the semantics of the descendant-or-self axis are * not supported by this object model */ Iterator getDescendantOrSelfAxisIterator(Object contextNode) throws UnsupportedAxisException; /** Retrieve an Iterator matching the * ancestor-or-self XPath axis. * * @param contextNode the original context node * * @return an Iterator capable of traversing the axis, not null * * @throws UnsupportedAxisException if the semantics of the ancestor-or-self axis are * not supported by this object model */ Iterator getAncestorOrSelfAxisIterator(Object contextNode) throws UnsupportedAxisException; // ---------------------------------------------------------------------- // Extractors // ---------------------------------------------------------------------- /** Loads a document from the given URI * * @param uri the URI of the document to load * * @return the document * * @throws FunctionCallException if the document could not be loaded */ Object getDocument(String uri) throws FunctionCallException; /** Returns the document node that contains the given context node. * * @see #isDocument(Object) * * @param contextNode the context node * * @return the document of the context node */ Object getDocumentNode(Object contextNode); /** Returns the parent of the given context node. * *

* The parent of any node must either be a document * node or an element node. *

* * @see #isDocument * @see #isElement * * @param contextNode the context node * * @return the parent of the context node, or null if this is a document node. * * @throws UnsupportedAxisException if the parent axis is not * supported by the model */ Object getParentNode(Object contextNode) throws UnsupportedAxisException; /** Retrieve the namespace URI of the given element node. * * @param element the context element node * * @return the namespace URI of the element node */ String getElementNamespaceUri(Object element); /** Retrieve the local name of the given element node. * * @param element the context element node * * @return the local name of the element node */ String getElementName(Object element); /** Retrieve the qualified name of the given element node. * * @param element the context element node * * @return the qualified name of the element node */ String getElementQName(Object element); /** Retrieve the namespace URI of the given attribute node. * * @param attr the context attribute node * * @return the namespace URI of the attribute node */ String getAttributeNamespaceUri(Object attr); /** Retrieve the local name of the given attribute node. * * @param attr the context attribute node * * @return the local name of the attribute node */ String getAttributeName(Object attr); /** Retrieve the qualified name of the given attribute node. * * @param attr the context attribute node * * @return the qualified name of the attribute node */ String getAttributeQName(Object attr); /** Retrieve the target of a processing-instruction. * * @param pi the context processing-instruction node * * @return the target of the processing-instruction node */ String getProcessingInstructionTarget(Object pi); /** Retrieve the data of a processing-instruction. * * @param pi the context processing-instruction node * * @return the data of the processing-instruction node */ String getProcessingInstructionData(Object pi); // ---------------------------------------------------------------------- // isXXX testers // ---------------------------------------------------------------------- /** Returns whether the given object is a document node. A document node * is the node that is selected by the XPath expression /. * * @param object the object to test * * @return true if the object is a document node, * else false */ boolean isDocument(Object object); /** Returns whether the given object is an element node. * * @param object the object to test * * @return true if the object is an element node, * else false */ boolean isElement(Object object); /** Returns whether the given object is an attribute node. * * @param object the object to test * * @return true if the object is an attribute node, * else false */ boolean isAttribute(Object object); /** Returns whether the given object is a namespace node. * * @param object the object to test * * @return true if the object is a namespace node, * else false */ boolean isNamespace(Object object); /** Returns whether the given object is a comment node. * * @param object the object to test * * @return true if the object is a comment node, * else false */ boolean isComment(Object object); /** Returns whether the given object is a text node. * * @param object the object to test * * @return true if the object is a text node, * else false */ boolean isText(Object object); /** Returns whether the given object is a processing-instruction node. * * @param object the object to test * * @return true if the object is a processing-instruction node, * else false */ boolean isProcessingInstruction(Object object); // ---------------------------------------------------------------------- // String-Value extractors // ---------------------------------------------------------------------- /** Retrieve the string-value of a comment node. * This may be the empty string if the comment is empty, * but must not be null. * * @param comment the comment node * * @return the string-value of the node */ String getCommentStringValue(Object comment); /** Retrieve the string-value of an element node. * This may be the empty string if the element is empty, * but must not be null. * * @param element the comment node. * * @return the string-value of the node. */ String getElementStringValue(Object element); /** Retrieve the string-value of an attribute node. * This should be the XML 1.0 normalized attribute value. * This may be the empty string but must not be null. * * @param attr the attribute node * * @return the string-value of the node */ String getAttributeStringValue(Object attr); /** Retrieve the string-value of a namespace node. * This is generally the namespace URI. * This may be the empty string but must not be null. * * @param ns the namespace node * * @return the string-value of the node */ String getNamespaceStringValue(Object ns); /** Retrieve the string-value of a text node. * This must not be null and should not be the empty string. * The XPath data model does not allow empty text nodes. * * @param text the text node * * @return the string-value of the node */ String getTextStringValue(Object text); // ---------------------------------------------------------------------- // General utilities // ---------------------------------------------------------------------- /** Retrieve the namespace prefix of a namespace node. * * @param ns the namespace node * * @return the prefix associated with the node */ String getNamespacePrefix(Object ns); /** Translate a namespace prefix to a namespace URI, possibly * considering a particular element node. * *

* Strictly speaking, prefix-to-URI translation should occur * irrespective of any element in the document. This method * is provided to allow a non-conforming ease-of-use enhancement. *

* * @see NamespaceContext * * @param prefix the prefix to translate * @param element the element to consider during translation * * @return the namespace URI associated with the prefix */ String translateNamespacePrefixToUri(String prefix, Object element); /** Returns a parsed form of the given XPath string, which will be suitable * for queries on documents that use the same navigator as this one. * * @see XPath * * @param xpath the XPath expression * * @return a new XPath expression object * * @throws SAXPathException if the string is not a syntactically * correct XPath expression */ XPath parseXPath(String xpath) throws SAXPathException; /** * Returns the element whose ID is given by elementId. * If no such element exists, returns null. * Attributes with the name "ID" are not of type ID unless so defined. * Implementations that do not know whether attributes are of type ID or * not are expected to return null. * * @param contextNode a node from the document in which to look for the * id * @param elementId id to look for * * @return element whose ID is given by elementId, or null if no such * element exists in the document or if the implementation * does not know about attribute types */ Object getElementById(Object contextNode, String elementId); /** Returns a number that identifies the type of node that the given * object represents in this navigator. * * @param node ???? * @return ???? * * @see org.jaxen.pattern.Pattern */ short getNodeType(Object node); } jaxen-1.1.6/src/java/main/org/jaxen/UnsupportedAxisException.java0000664000175000017500000000601610440370132024402 0ustar ebourgebourg/* * $Header$ * $Revision: 1160 $ * $Date: 2006-06-03 22:26:02 +0200 (Sat, 03 Jun 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: UnsupportedAxisException.java 1160 2006-06-03 20:26:02Z elharo $ */ package org.jaxen; /** * Indicates attempt to evaluate an XPath axis that * is unsupported by the current object-model. If this is thrown * the XPath expressions cannot be evaluated correctly, unless there is a fallback * evaluation path. Hence you should not just catch this * and ignore it, nor should navigators throw it to indicate that * an axis is exhausted: instead return an empty iterator. * * @author bob mcwhirter */ public class UnsupportedAxisException extends JaxenException { /** * */ private static final long serialVersionUID = 3385500112257420949L; /** Create a new UnsupportedAxisException. * * @param message the error message */ public UnsupportedAxisException(String message) { super( message ); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/0000775000175000017500000000000012174247550017473 5ustar ebourgebourgjaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultExpr.java0000664000175000017500000000604710371471320022557 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultExpr.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.expr; import java.util.Iterator; import java.util.List; import org.jaxen.util.SingleObjectIterator; import org.jaxen.util.SingletonList; /** * @deprecated this class will become non-public in the future; * use the interface instead */ public abstract class DefaultExpr implements Expr { public Expr simplify() { return this; } static public Iterator convertToIterator(Object obj) { if ( obj instanceof Iterator ) { return (Iterator) obj; } if ( obj instanceof List ) { return ((List)obj).iterator(); } return new SingleObjectIterator( obj ); } static public List convertToList(Object obj) { if ( obj instanceof List ) { return (List) obj; } return new SingletonList(obj); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/IdentitySet.java0000664000175000017500000000477110371471320022603 0ustar ebourgebourg/* $Id$ Copyright 2005 Elliotte Rusty Harold. All Rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Jaxen Project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.jaxen.expr; import java.util.HashSet; /** *

* This is a set that uses identity rather than equality semantics. *

* * @author Elliotte Rusty Harold * */ final class IdentitySet { private HashSet contents = new HashSet(); IdentitySet() { super(); } void add(Object object) { IdentityWrapper wrapper = new IdentityWrapper(object); contents.add(wrapper); } public boolean contains(Object object) { IdentityWrapper wrapper = new IdentityWrapper(object); return contents.contains(wrapper); } private static class IdentityWrapper { private Object object; IdentityWrapper(Object object) { this.object = object; } public boolean equals(Object o) { IdentityWrapper w = (IdentityWrapper) o; return object == w.object; } public int hashCode() { return System.identityHashCode(object); } } } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultEqualsExpr.java0000664000175000017500000000601412074523431023727 0ustar ebourgebourg/* * $Header$ * $Revision: 1396 $ * $Date: 2013-01-13 13:22:49 +0100 (Sun, 13 Jan 2013) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultEqualsExpr.java 1396 2013-01-13 12:22:49Z elharo $ */ package org.jaxen.expr; class DefaultEqualsExpr extends DefaultEqualityExpr { /** * */ private static final long serialVersionUID = -8327599812627931648L; DefaultEqualsExpr( Expr lhs, Expr rhs ) { super( lhs, rhs ); } public String getOperator() { return "="; } public String toString() { return "[(DefaultEqualsExpr): " + getLHS() + ", " + getRHS() + "]"; } protected boolean evaluateObjectObject( Object lhs, Object rhs ) { if( eitherIsNumber( lhs, rhs ) ) { // Double.equals does not implement standard IEEE 754 comparisons but == does Double left = (Double) lhs; Double right = (Double) rhs; return left.doubleValue() == right.doubleValue(); } return lhs.equals( rhs ); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultModExpr.java0000664000175000017500000000621510533623667023231 0ustar ebourgebourg/* * $Header$ * $Revision: 1261 $ * $Date: 2006-11-30 19:49:27 +0100 (Thu, 30 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultModExpr.java 1261 2006-11-30 18:49:27Z elharo $ */ package org.jaxen.expr; import org.jaxen.Context; import org.jaxen.JaxenException; import org.jaxen.function.NumberFunction; class DefaultModExpr extends DefaultMultiplicativeExpr { /** * */ private static final long serialVersionUID = -5554964716492040687L; DefaultModExpr( Expr lhs, Expr rhs ) { super( lhs, rhs ); } public String getOperator() { return "mod"; } public Object evaluate( Context context ) throws JaxenException { Number lhsValue = NumberFunction.evaluate( getLHS().evaluate( context ), context.getNavigator() ); Number rhsValue = NumberFunction.evaluate( getRHS().evaluate( context ), context.getNavigator() ); double result = lhsValue.doubleValue() % rhsValue.doubleValue(); return new Double( result ); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultStep.java0000664000175000017500000001320510371471320022546 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultStep.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.expr; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.jaxen.Context; import org.jaxen.ContextSupport; import org.jaxen.JaxenException; import org.jaxen.UnsupportedAxisException; import org.jaxen.expr.iter.IterableAxis; import org.jaxen.saxpath.Axis; /** * @deprecated this class will become non-public in the future; * use the interface instead */ public abstract class DefaultStep implements Step { private IterableAxis axis; private PredicateSet predicates; public DefaultStep(IterableAxis axis, PredicateSet predicates) { this.axis = axis; this.predicates = predicates; } public void addPredicate(Predicate predicate) { this.predicates.addPredicate(predicate); } public List getPredicates() { return this.predicates.getPredicates(); } public PredicateSet getPredicateSet() { return this.predicates; } public int getAxis() { return this.axis.value(); } public IterableAxis getIterableAxis() { return this.axis; } public String getAxisName() { return Axis.lookup(getAxis()); } public String getText() { return this.predicates.getText(); } public String toString() { return getIterableAxis() + " " + super.toString(); } public void simplify() { this.predicates.simplify(); } public Iterator axisIterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException { return getIterableAxis().iterator(contextNode, support); } public List evaluate(final Context context) throws JaxenException { final List contextNodeSet = context.getNodeSet(); final IdentitySet unique = new IdentitySet(); final int contextSize = contextNodeSet.size(); // ???? try linked lists instead? // ???? initial size for these? final ArrayList interimSet = new ArrayList(); final ArrayList newNodeSet = new ArrayList(); final ContextSupport support = context.getContextSupport(); // ???? use iterator instead for ( int i = 0 ; i < contextSize ; ++i ) { Object eachContextNode = contextNodeSet.get( i ); /* See jaxen-106. Might be able to optimize this by doing * specific matching for individual axes. For instance on namespace axis * we should only get namespace nodes and on attribute axes we only get * attribute nodes. Self and parent axes have single members. * Children, descendant, ancestor, and sibling axes never * see any attributes or namespaces */ Iterator axisNodeIter = axis.iterator(eachContextNode, support); while ( axisNodeIter.hasNext() ) { Object eachAxisNode = axisNodeIter.next(); if ( ! unique.contains( eachAxisNode ) ) { if ( matches( eachAxisNode, support ) ) { unique.add( eachAxisNode ); interimSet.add( eachAxisNode ); } } } newNodeSet.addAll(getPredicateSet().evaluatePredicates( interimSet, support )); interimSet.clear(); } return newNodeSet; } } jaxen-1.1.6/src/java/main/org/jaxen/expr/AllNodeStep.java0000664000175000017500000000450210524375357022515 0ustar ebourgebourg/* * $Header$ * $Revision: 1225 $ * $Date: 2006-11-08 16:42:39 +0100 (Wed, 08 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: AllNodeStep.java 1225 2006-11-08 15:42:39Z elharo $ */ package org.jaxen.expr; /** * Represents the XPath node-test node(). * */ public interface AllNodeStep extends Step { } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultPlusExpr.java0000664000175000017500000000622410533623667023435 0ustar ebourgebourg/* * $Header$ * $Revision: 1261 $ * $Date: 2006-11-30 19:49:27 +0100 (Thu, 30 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultPlusExpr.java 1261 2006-11-30 18:49:27Z elharo $ */ package org.jaxen.expr; import org.jaxen.Context; import org.jaxen.JaxenException; import org.jaxen.function.NumberFunction; class DefaultPlusExpr extends DefaultAdditiveExpr { /** * */ private static final long serialVersionUID = -1426954461146769374L; DefaultPlusExpr(Expr lhs, Expr rhs) { super( lhs, rhs ); } public String getOperator() { return "+"; } public Object evaluate(Context context) throws JaxenException { Number lhsValue = NumberFunction.evaluate( getLHS().evaluate( context ), context.getNavigator() ); Number rhsValue = NumberFunction.evaluate( getRHS().evaluate( context ), context.getNavigator() ); double result = lhsValue.doubleValue() + rhsValue.doubleValue(); return new Double( result ); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/LiteralExpr.java0000664000175000017500000000527310524405042022565 0ustar ebourgebourg/* * $Header$ * $Revision: 1234 $ * $Date: 2006-11-08 17:47:30 +0100 (Wed, 08 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: LiteralExpr.java 1234 2006-11-08 16:47:30Z elharo $ */ package org.jaxen.expr; /** * Represents an XPath string literal. This is production 29 in the * XPath 1.0 specification: * *
[29] Literal ::= '"' [^"]* '"'   
 *               | "'" [^']* "'"
* */ public interface LiteralExpr extends Expr { /** * Returns the contents of the string literal, not including the * quote marks. * * @return the contents of the string literal */ public String getLiteral(); } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultMinusExpr.java0000664000175000017500000000621110533623667023601 0ustar ebourgebourg/* * $Header$ * $Revision: 1261 $ * $Date: 2006-11-30 19:49:27 +0100 (Thu, 30 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultMinusExpr.java 1261 2006-11-30 18:49:27Z elharo $ */ package org.jaxen.expr; import org.jaxen.Context; import org.jaxen.JaxenException; import org.jaxen.function.NumberFunction; class DefaultMinusExpr extends DefaultAdditiveExpr { /** * */ private static final long serialVersionUID = 6468563688098527800L; DefaultMinusExpr(Expr lhs, Expr rhs) { super( lhs, rhs ); } public String getOperator() { return "-"; } public Object evaluate(Context context) throws JaxenException { Number lhsValue = NumberFunction.evaluate( getLHS().evaluate( context ), context.getNavigator() ); Number rhsValue = NumberFunction.evaluate( getRHS().evaluate( context ), context.getNavigator() ); double result = lhsValue.doubleValue() - rhsValue.doubleValue(); return new Double( result ); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/NameStep.java0000664000175000017500000000570410524407552022055 0ustar ebourgebourg/* * $Header$ * $Revision: 1236 $ * $Date: 2006-11-08 18:10:02 +0100 (Wed, 08 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: NameStep.java 1236 2006-11-08 17:10:02Z elharo $ */ package org.jaxen.expr; /** * Represents an XPath name test such as para or * svg:rect. This is production 37 in the * XPath 1.0 specification: * *
[37] NameTest ::=  '*' 
 *                | NCName ':' '*'    
 *                | QName
* */ public interface NameStep extends Step { /** * Returns the namespace prefix of the matched node. This is the empty * string for nodes in the default namespace. * * @return the namespace prefix of the natched node */ public String getPrefix(); /** * Returns the local name of the matched node * * @return the local name of the test */ public String getLocalName();} jaxen-1.1.6/src/java/main/org/jaxen/expr/Expr.java0000664000175000017500000000752310533623667021267 0ustar ebourgebourg/* * $Header$ * $Revision: 1261 $ * $Date: 2006-11-30 19:49:27 +0100 (Thu, 30 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: Expr.java 1261 2006-11-30 18:49:27Z elharo $ */ package org.jaxen.expr; import java.io.Serializable; import org.jaxen.Context; import org.jaxen.JaxenException; /** * Represents an XPath expression. This is production 14 in the * XPath 1.0 specification: * *
[14]      Expr       ::=      OrExpr
* */ public interface Expr extends Serializable { /** * Returns a String containing the XPath expression. * * @return the text form of this XPath expression */ String getText(); /** * Simplifies the XPath expression. For example, the expression * //para[1 = 1] could be simplified to * //para. In practice, this is usually a noop. * Jaxen does not currently perform any simplification. * * @return the simplified expression */ Expr simplify(); /** * Evaluate the expression in the given context, and return the result. * The result will be a java.lang.Double for expressions that * return a number, a java.lang.String for expressions that * return a string, a java.lang.Boolean for expressions that * return a boolean, and a java.util.List for expressions that * return a node-set. In the latter case, the elements of the list are * the actual objects from the source document model. Copies are not made. * * @param context the context in which the expression is evaluated * @return an object representing the result of the evaluation * @throws JaxenException */ Object evaluate(Context context) throws JaxenException; } jaxen-1.1.6/src/java/main/org/jaxen/expr/FilterExpr.java0000664000175000017500000000657011004756472022431 0ustar ebourgebourg/* * $Header$ * $Revision: 1326 $ * $Date: 2008-04-27 03:56:10 +0200 (Sun, 27 Apr 2008) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: FilterExpr.java 1326 2008-04-27 01:56:10Z elharo $ */ package org.jaxen.expr; import org.jaxen.Context; import org.jaxen.JaxenException; /** * Represents an XPath filter expression. This is * production 20 in the * XPath 1.0 specification: * * * * * * * *
[20]   FilterExpr   ::=   PrimaryExpr
| FilterExpr Predicate
* */ public interface FilterExpr extends Expr, Predicated { /** * Evaluates the filter expression on the current context * and returns true if at least one node matches. * * @return true if a node matches; false if no node matches */ public boolean asBoolean(Context context) throws JaxenException; /** * @return the underlying filter expression */ public Expr getExpr(); } jaxen-1.1.6/src/java/main/org/jaxen/expr/NumberExpr.java0000664000175000017500000000531310524410454022417 0ustar ebourgebourg/* * $Header$ * $Revision: 1237 $ * $Date: 2006-11-08 18:17:32 +0100 (Wed, 08 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: NumberExpr.java 1237 2006-11-08 17:17:32Z elharo $ */ package org.jaxen.expr; /** * Represents an XPath floating point literal. This is production 30 in the * XPath 1.0 specification: * *
[30] Number ::=  Digits ('.' Digits?)?   
 *              | '.' Digits
* */ public interface NumberExpr extends Expr { /** * Returns a java.lang.Double representing the number. * * @return a java.lang.Double representing the number */ public Number getNumber(); } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultLiteralExpr.java0000664000175000017500000000610010547013156024066 0ustar ebourgebourg/* * $Header$ * $Revision: 1273 $ * $Date: 2007-01-03 21:47:42 +0100 (Wed, 03 Jan 2007) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultLiteralExpr.java 1273 2007-01-03 20:47:42Z elharo $ */ package org.jaxen.expr; import org.jaxen.Context; class DefaultLiteralExpr extends DefaultExpr implements LiteralExpr { /** * */ private static final long serialVersionUID = -953829179036273338L; private String literal; DefaultLiteralExpr(String literal) { this.literal = literal; } public String getLiteral() { return this.literal; } public String toString() { return "[(DefaultLiteralExpr): " + getLiteral() + "]"; } public String getText() { if (literal.indexOf('"') == -1 ) { return "\"" + getLiteral() + "\""; } else { // Not possible for string literal to contain both " and ' return "'" + getLiteral() + "'"; } } public Object evaluate(Context context) { return getLiteral(); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultXPathExpr.java0000664000175000017500000000650110440373212023515 0ustar ebourgebourg/* * $Header$ * $Revision: 1162 $ * $Date: 2006-06-03 22:52:26 +0200 (Sat, 03 Jun 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultXPathExpr.java 1162 2006-06-03 20:52:26Z elharo $ */ package org.jaxen.expr; import java.util.List; import org.jaxen.Context; import org.jaxen.JaxenException; /** * @deprecated this class will become non-public in the future; * use the interface instead */ public class DefaultXPathExpr implements XPathExpr { /** * */ private static final long serialVersionUID = 3007613096320896040L; private Expr rootExpr; public DefaultXPathExpr(Expr rootExpr) { this.rootExpr = rootExpr; } public Expr getRootExpr() { return this.rootExpr; } public void setRootExpr(Expr rootExpr) { this.rootExpr = rootExpr; } public String toString() { return "[(DefaultXPath): " + getRootExpr() + "]"; } public String getText() { return getRootExpr().getText(); } public void simplify() { setRootExpr( getRootExpr().simplify() ); } public List asList(Context context) throws JaxenException { Expr expr = getRootExpr(); Object value = expr.evaluate( context ); List result = DefaultExpr.convertToList( value ); return result; } } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultLogicalExpr.java0000664000175000017500000000465710371471320024057 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultLogicalExpr.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.expr; abstract class DefaultLogicalExpr extends DefaultTruthExpr implements LogicalExpr { DefaultLogicalExpr(Expr lhs, Expr rhs) { super( lhs, rhs ); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/XPathFactory.java0000664000175000017500000003031411115363662022710 0ustar ebourgebourg/* * $Header$ * $Revision: 1337 $ * $Date: 2008-12-03 02:58:10 +0100 (Wed, 03 Dec 2008) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: XPathFactory.java 1337 2008-12-03 01:58:10Z elharo $ */ package org.jaxen.expr; import org.jaxen.JaxenException; /** * An abstract factory used to create individual path component objects. * */ public interface XPathFactory { /** * Create a new XPathExpr from an Expr. * * @param rootExpr the expression wrapped by the resulting XPathExpr * @return an XPathExpr wrapping the root expression * @throws JaxenException */ XPathExpr createXPath( Expr rootExpr ) throws JaxenException; /** * Create a new path expression. * * @param filterExpr the filter expression that starts the path expression * @param locationPath the location path that follows the filter expression * @return a path expression formed by concatenating the two arguments * @throws JaxenException */ PathExpr createPathExpr( FilterExpr filterExpr, LocationPath locationPath ) throws JaxenException; /** * Create a new empty relative location path. * * @return an empty relative location path * @throws JaxenException */ LocationPath createRelativeLocationPath() throws JaxenException; /** * Create a new empty absolute location path. * * @return an empty absolute location path * @throws JaxenException */ LocationPath createAbsoluteLocationPath() throws JaxenException; /** * Returns a new XPath Or expression. * * @param lhs the left hand side of the expression * @param rhs the right hand side of the expression * @return lhs or rhs * @throws JaxenException */ BinaryExpr createOrExpr( Expr lhs, Expr rhs ) throws JaxenException; /** * Returns a new XPath And expression. * * @param lhs the left hand side of the expression * @param rhs the right hand side of the expression * @return lhs and rhs * @throws JaxenException */ BinaryExpr createAndExpr( Expr lhs, Expr rhs ) throws JaxenException; /** * Returns a new XPath equality expression. * * @param lhs the left hand side of the expression * @param rhs the right hand side of the expression * @param equalityOperator Operator.EQUALS or Operator.NOT_EQUALS * @return lhs = rhs or lhs != rhs * @throws JaxenException if the third argument is not * Operator.EQUALS or Operator.NOT_EQUALS */ BinaryExpr createEqualityExpr( Expr lhs, Expr rhs, int equalityOperator ) throws JaxenException; /** * Returns a new XPath relational expression. * * @param lhs the left hand side of the expression * @param rhs the right hand side of the expression * @param relationalOperator Operator.LESS_THAN, Operator.GREATER_THAN, * Operator.LESS_THAN_EQUALS, or Operator.GREATER_THAN_EQUALS * @return lhs relationalOperator rhs or lhs != rhs * @throws JaxenException if the third argument is not a relational operator constant */ BinaryExpr createRelationalExpr( Expr lhs, Expr rhs, int relationalOperator ) throws JaxenException; /** * Returns a new XPath additive expression. * * @param lhs the left hand side of the expression * @param rhs the right hand side of the expression * @param additiveOperator Operator.ADD or Operator.SUBTRACT * @return lhs + rhs or lhs - rhs * @throws JaxenException if the third argument is not * Operator.ADD or Operator.SUBTRACT */ BinaryExpr createAdditiveExpr( Expr lhs, Expr rhs, int additiveOperator ) throws JaxenException; /** * Returns a new XPath multiplicative expression. * * @param lhs the left hand side of the expression * @param rhs the right hand side of the expression * @param multiplicativeOperator Operator.MULTIPLY, * Operator.DIV, or Operator.MOD * @return lhs * rhs, lhs div rhs, * or lhs mod rhs * @throws JaxenException if the third argument is not a multiplicative operator constant */ BinaryExpr createMultiplicativeExpr( Expr lhs, Expr rhs, int multiplicativeOperator ) throws JaxenException; /** * Returns a new XPath unary expression. * * @param expr the expression to be negated * @param unaryOperator Operator.NEGATIVE * @return - expr or expr * @throws JaxenException */ Expr createUnaryExpr( Expr expr, int unaryOperator ) throws JaxenException; /** * Returns a new XPath union expression. * * @param lhs the left hand side of the expression * @param rhs the right hand side of the expression * @return lhs | rhs * @throws JaxenException */ UnionExpr createUnionExpr( Expr lhs, Expr rhs ) throws JaxenException; /** * Returns a new XPath filter expression. * * @param expr the basic expression to which the predicate will be added * @return the expression with an empty predicate set * @throws JaxenException */ FilterExpr createFilterExpr( Expr expr ) throws JaxenException; /** * Create a new function call expression. * * @param prefix the namespace prefix of the function * @param functionName the local name of the function * @return a function with an empty argument list * @throws JaxenException */ FunctionCallExpr createFunctionCallExpr( String prefix, String functionName ) throws JaxenException; /** * Create a number expression. * * @param number the value * @return a number expression wrapping that value * @throws JaxenException */ NumberExpr createNumberExpr( int number ) throws JaxenException; /** * Create a number expression. * * @param number the value * @return a number expression wrapping that value * @throws JaxenException */ NumberExpr createNumberExpr( double number ) throws JaxenException; /** * Create a string literal expression. * * @param literal the value * @return a literal expression wrapping that value * @throws JaxenException */ LiteralExpr createLiteralExpr( String literal ) throws JaxenException; /** * Create a new variable reference expression. * * @param prefix the namespace prefix of the variable * @param variableName the local name of the variable * @return a variable expression * @throws JaxenException */ VariableReferenceExpr createVariableReferenceExpr( String prefix, String variableName ) throws JaxenException; /** * Create a step with a named node-test. * * @param axis the axis to create the name-test on * @param prefix the namespace prefix for the test * @param localName the local name for the test * @return a name step * @throws JaxenException if axis is not one of the axis constants???? */ Step createNameStep( int axis, String prefix, String localName ) throws JaxenException; /** * Create a step with a node() node-test. * * @param axis the axis to create the node-test on * @return an all node step * @throws JaxenException if axis is not one of the axis constants???? */ Step createAllNodeStep( int axis ) throws JaxenException; /** * Create a step with a comment() node-test. * * @param axis the axis to create the comment() node-test on * @return a comment node step * @throws JaxenException if axis is not one of the axis constants???? */ Step createCommentNodeStep( int axis ) throws JaxenException; /** * Create a step with a text() node-test. * * @param axis the axis to create the text() node-test on * @return a text node step * @throws JaxenException if axis is not one of the axis constants???? */ Step createTextNodeStep( int axis ) throws JaxenException; /** * Create a step with a processing-instruction() node-test. * * @param axis the axis to create the processing-instruction() node-test on * @param name the target to match, may be empty * @return a processing instruction node step * @throws JaxenException if axis is not one of the axis constants???? */ Step createProcessingInstructionNodeStep( int axis, String name ) throws JaxenException; /** * Create from the supplied expression. * * @param predicateExpr the expression to evaluate in the predicate * @return a predicate * @throws JaxenException */ Predicate createPredicate( Expr predicateExpr ) throws JaxenException; /** * Create an empty predicate set. * * @return an empty predicate set * @throws JaxenException */ PredicateSet createPredicateSet() throws JaxenException; } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultXPathFactory.java0000664000175000017500000003104710524651472024223 0ustar ebourgebourg/* * $Header$ * $Revision: 1251 $ * $Date: 2006-11-09 17:11:38 +0100 (Thu, 09 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultXPathFactory.java 1251 2006-11-09 16:11:38Z elharo $ */ package org.jaxen.expr; import org.jaxen.JaxenException; import org.jaxen.expr.iter.IterableAncestorAxis; import org.jaxen.expr.iter.IterableAncestorOrSelfAxis; import org.jaxen.expr.iter.IterableAttributeAxis; import org.jaxen.expr.iter.IterableAxis; import org.jaxen.expr.iter.IterableChildAxis; import org.jaxen.expr.iter.IterableDescendantAxis; import org.jaxen.expr.iter.IterableDescendantOrSelfAxis; import org.jaxen.expr.iter.IterableFollowingAxis; import org.jaxen.expr.iter.IterableFollowingSiblingAxis; import org.jaxen.expr.iter.IterableNamespaceAxis; import org.jaxen.expr.iter.IterableParentAxis; import org.jaxen.expr.iter.IterablePrecedingAxis; import org.jaxen.expr.iter.IterablePrecedingSiblingAxis; import org.jaxen.expr.iter.IterableSelfAxis; import org.jaxen.saxpath.Axis; import org.jaxen.saxpath.Operator; /** * The concrete implementation of the XPathFactory anstract factory. * * * @see XPathFactory */ public class DefaultXPathFactory implements XPathFactory { public XPathExpr createXPath( Expr rootExpr ) throws JaxenException { return new DefaultXPathExpr( rootExpr ); } public PathExpr createPathExpr( FilterExpr filterExpr, LocationPath locationPath ) throws JaxenException { return new DefaultPathExpr( filterExpr, locationPath ); } public LocationPath createRelativeLocationPath() throws JaxenException { return new DefaultRelativeLocationPath(); } public LocationPath createAbsoluteLocationPath() throws JaxenException { return new DefaultAbsoluteLocationPath(); } public BinaryExpr createOrExpr( Expr lhs, Expr rhs ) throws JaxenException { return new DefaultOrExpr( lhs, rhs ); } public BinaryExpr createAndExpr( Expr lhs, Expr rhs ) throws JaxenException { return new DefaultAndExpr( lhs, rhs ); } public BinaryExpr createEqualityExpr( Expr lhs, Expr rhs, int equalityOperator ) throws JaxenException { switch( equalityOperator ) { case Operator.EQUALS: { return new DefaultEqualsExpr( lhs, rhs ); } case Operator.NOT_EQUALS: { return new DefaultNotEqualsExpr( lhs, rhs ); } } throw new JaxenException( "Unhandled operator in createEqualityExpr(): " + equalityOperator ); } public BinaryExpr createRelationalExpr( Expr lhs, Expr rhs, int relationalOperator ) throws JaxenException { switch( relationalOperator ) { case Operator.LESS_THAN: { return new DefaultLessThanExpr( lhs, rhs ); } case Operator.GREATER_THAN: { return new DefaultGreaterThanExpr( lhs, rhs ); } case Operator.LESS_THAN_EQUALS: { return new DefaultLessThanEqualExpr( lhs, rhs ); } case Operator.GREATER_THAN_EQUALS: { return new DefaultGreaterThanEqualExpr( lhs, rhs ); } } throw new JaxenException( "Unhandled operator in createRelationalExpr(): " + relationalOperator ); } public BinaryExpr createAdditiveExpr( Expr lhs, Expr rhs, int additiveOperator ) throws JaxenException { switch( additiveOperator ) { case Operator.ADD: { return new DefaultPlusExpr( lhs, rhs ); } case Operator.SUBTRACT: { return new DefaultMinusExpr( lhs, rhs ); } } throw new JaxenException( "Unhandled operator in createAdditiveExpr(): " + additiveOperator ); } public BinaryExpr createMultiplicativeExpr( Expr lhs, Expr rhs, int multiplicativeOperator ) throws JaxenException { switch( multiplicativeOperator ) { case Operator.MULTIPLY: { return new DefaultMultiplyExpr( lhs, rhs ); } case Operator.DIV: { return new DefaultDivExpr( lhs, rhs ); } case Operator.MOD: { return new DefaultModExpr( lhs, rhs ); } } throw new JaxenException( "Unhandled operator in createMultiplicativeExpr(): " + multiplicativeOperator ); } public Expr createUnaryExpr( Expr expr, int unaryOperator ) throws JaxenException { switch( unaryOperator ) { case Operator.NEGATIVE: { return new DefaultUnaryExpr( expr ); } } return expr; } public UnionExpr createUnionExpr( Expr lhs, Expr rhs ) throws JaxenException { return new DefaultUnionExpr( lhs, rhs ); } public FilterExpr createFilterExpr( Expr expr ) throws JaxenException { return new DefaultFilterExpr( expr, createPredicateSet() ); } public FunctionCallExpr createFunctionCallExpr( String prefix, String functionName ) throws JaxenException { return new DefaultFunctionCallExpr( prefix, functionName ); } public NumberExpr createNumberExpr( int number ) throws JaxenException { return new DefaultNumberExpr( new Double( number ) ); } public NumberExpr createNumberExpr( double number ) throws JaxenException { return new DefaultNumberExpr( new Double( number ) ); } public LiteralExpr createLiteralExpr( String literal ) throws JaxenException { return new DefaultLiteralExpr( literal ); } public VariableReferenceExpr createVariableReferenceExpr( String prefix, String variable ) throws JaxenException { return new DefaultVariableReferenceExpr( prefix, variable ); } public Step createNameStep( int axis, String prefix, String localName ) throws JaxenException { IterableAxis iter = getIterableAxis( axis ); return new DefaultNameStep( iter, prefix, localName, createPredicateSet() ); } public Step createTextNodeStep( int axis ) throws JaxenException { IterableAxis iter = getIterableAxis( axis ); return new DefaultTextNodeStep( iter, createPredicateSet() ); } public Step createCommentNodeStep( int axis ) throws JaxenException { IterableAxis iter = getIterableAxis( axis ); return new DefaultCommentNodeStep( iter, createPredicateSet() ); } public Step createAllNodeStep( int axis ) throws JaxenException { IterableAxis iter = getIterableAxis( axis ); return new DefaultAllNodeStep( iter, createPredicateSet() ); } public Step createProcessingInstructionNodeStep( int axis, String piName ) throws JaxenException { IterableAxis iter = getIterableAxis( axis ); return new DefaultProcessingInstructionNodeStep( iter, piName, createPredicateSet() ); } public Predicate createPredicate( Expr predicateExpr ) throws JaxenException { return new DefaultPredicate( predicateExpr ); } protected IterableAxis getIterableAxis( int axis ) throws JaxenException { switch( axis ) { case Axis.CHILD: return new IterableChildAxis( axis ); case Axis.DESCENDANT: return new IterableDescendantAxis( axis ); case Axis.PARENT: return new IterableParentAxis( axis ); case Axis.FOLLOWING_SIBLING: return new IterableFollowingSiblingAxis( axis ); case Axis.PRECEDING_SIBLING: return new IterablePrecedingSiblingAxis( axis ); case Axis.FOLLOWING: return new IterableFollowingAxis( axis ); case Axis.PRECEDING: return new IterablePrecedingAxis( axis ); case Axis.ATTRIBUTE: return new IterableAttributeAxis( axis ); case Axis.NAMESPACE: return new IterableNamespaceAxis( axis ); case Axis.SELF: return new IterableSelfAxis( axis ); case Axis.DESCENDANT_OR_SELF: return new IterableDescendantOrSelfAxis( axis ); case Axis.ANCESTOR_OR_SELF: return new IterableAncestorOrSelfAxis( axis ); case Axis.ANCESTOR: return new IterableAncestorAxis( axis ); default: throw new JaxenException("Unrecognized axis code: " + axis); } } public PredicateSet createPredicateSet() throws JaxenException { return new PredicateSet(); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/UnionExpr.java0000664000175000017500000000556210524377426022300 0ustar ebourgebourg/* * $Header$ * $Revision: 1228 $ * $Date: 2006-11-08 17:00:22 +0100 (Wed, 08 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: UnionExpr.java 1228 2006-11-08 16:00:22Z elharo $ */ package org.jaxen.expr; /** * Represents an XPath union expression. This is production 18 in the * XPath 1.0 specification: * * * * *
[18]   UnionExpr   ::=   PathExpr
| UnionExpr '|' PathExpr *
* */ public interface UnionExpr extends BinaryExpr { } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultFunctionCallExpr.java0000664000175000017500000001333711751251237025067 0ustar ebourgebourg/* * $Header$ * $Revision: 1366 $ * $Date: 2012-05-05 18:17:35 +0200 (Sat, 05 May 2012) $ * * ==================================================================== * * Copyright 2000-2004 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultFunctionCallExpr.java 1366 2012-05-05 16:17:35Z elharo $ */ package org.jaxen.expr; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.JaxenException; /** * @deprecated this class will become non-public in the future; * use the interface instead */ public class DefaultFunctionCallExpr extends DefaultExpr implements FunctionCallExpr { /** * */ private static final long serialVersionUID = -4747789292572193708L; private String prefix; private String functionName; private List parameters; public DefaultFunctionCallExpr(String prefix, String functionName) { this.prefix = prefix; this.functionName = functionName; this.parameters = new ArrayList(); } public void addParameter(Expr parameter) { this.parameters.add(parameter); } public List getParameters() { return this.parameters; } public String getPrefix() { return this.prefix; } public String getFunctionName() { return this.functionName; } public String getText() { StringBuffer buf = new StringBuffer(); String prefix = getPrefix(); if (prefix != null && prefix.length() > 0) { buf.append(prefix); buf.append(":"); } buf.append(getFunctionName()); buf.append("("); Iterator paramIter = getParameters().iterator(); while (paramIter.hasNext()) { Expr eachParam = (Expr) paramIter.next(); buf.append(eachParam.getText()); if (paramIter.hasNext()) { buf.append(", "); } } buf.append(")"); return buf.toString(); } public Expr simplify() { List paramExprs = getParameters(); int paramSize = paramExprs.size(); List newParams = new ArrayList(paramSize); for (int i = 0; i < paramSize; ++i) { Expr eachParam = (Expr) paramExprs.get(i); newParams.add(eachParam.simplify()); } this.parameters = newParams; return this; } public String toString() { String prefix = getPrefix(); if (prefix == null) { return "[(DefaultFunctionCallExpr): " + getFunctionName() + "(" + getParameters() + ") ]"; } return "[(DefaultFunctionCallExpr): " + getPrefix() + ":" + getFunctionName() + "(" + getParameters() + ") ]"; } public Object evaluate(Context context) throws JaxenException { String prefix = getPrefix(); String namespaceURI = null; // default namespace is not used within XPath expressions if (prefix != null && !"".equals(prefix)) { namespaceURI = context.translateNamespacePrefixToUri(prefix); } Function func = context.getFunction(namespaceURI, prefix, getFunctionName()); List paramValues = evaluateParams(context); return func.call(context, paramValues); } public List evaluateParams(Context context) throws JaxenException { List paramExprs = getParameters(); int paramSize = paramExprs.size(); List paramValues = new ArrayList(paramSize); for (int i = 0; i < paramSize; ++i) { Expr eachParam = (Expr) paramExprs.get(i); Object eachValue = eachParam.evaluate(context); paramValues.add(eachValue); } return paramValues; } } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultAndExpr.java0000664000175000017500000000667110533623667023222 0ustar ebourgebourg/* * $Header$ * $Revision: 1261 $ * $Date: 2006-11-30 19:49:27 +0100 (Thu, 30 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultAndExpr.java 1261 2006-11-30 18:49:27Z elharo $ */ package org.jaxen.expr; import org.jaxen.Context; import org.jaxen.JaxenException; import org.jaxen.Navigator; import org.jaxen.function.BooleanFunction; class DefaultAndExpr extends DefaultLogicalExpr { /** * */ private static final long serialVersionUID = -5237984010263103742L; DefaultAndExpr(Expr lhs, Expr rhs) { super( lhs, rhs ); } public String getOperator() { return "and"; } public String toString() { return "[(DefaultAndExpr): " + getLHS() + ", " + getRHS() + "]"; } public Object evaluate(Context context) throws JaxenException { Navigator nav = context.getNavigator(); Boolean lhsValue = BooleanFunction.evaluate( getLHS().evaluate( context ), nav ); if ( !lhsValue.booleanValue() ) { return Boolean.FALSE; } // Short circuits are required in XPath. "The right operand is not // evaluated if the left operand evaluates to false." Boolean rhsValue = BooleanFunction.evaluate( getRHS().evaluate( context ), nav ); if ( !rhsValue.booleanValue() ) { return Boolean.FALSE; } return Boolean.TRUE; } } jaxen-1.1.6/src/java/main/org/jaxen/expr/LogicalExpr.java0000664000175000017500000000663410524652561022557 0ustar ebourgebourg/* * $Header$ * $Revision: 1252 $ * $Date: 2006-11-09 17:21:05 +0100 (Thu, 09 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: LogicalExpr.java 1252 2006-11-09 16:21:05Z elharo $ */ package org.jaxen.expr; /** * Represents an XPath logical expression. This represents productions * 21 OrExpr and * 22 AndExpr in the XPath specification. * * * * * * * * * * * * *
[21]   OrExpr   ::=   AndExpr
| OrExpr 'or' AndExpr
[22]   AndExpr   ::=   EqualityExpr
| AndExpr 'and' EqualityExpr
* */ public interface LogicalExpr extends BinaryExpr { } jaxen-1.1.6/src/java/main/org/jaxen/expr/VariableReferenceExpr.java0000664000175000017500000000560510524426775024554 0ustar ebourgebourg/* * $Header$ * $Revision: 1248 $ * $Date: 2006-11-08 20:20:29 +0100 (Wed, 08 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: VariableReferenceExpr.java 1248 2006-11-08 19:20:29Z elharo $ */ package org.jaxen.expr; /** * Represents an XPath variable reference. This is production 36 in the * XPath 1.0 specification: * *
[36] VariableReference ::= '$' QName
* */ public interface VariableReferenceExpr extends Expr { /** * Returns the namespace prefix of the variable. This is the empty * string for variables with no namespace prefix. * * @return the namespace prefix of the variable */ public String getPrefix(); /** * Returns the local name of the variable. * * @return the local name of the variable */ public String getVariableName(); } jaxen-1.1.6/src/java/main/org/jaxen/expr/LocationPath.java0000664000175000017500000000636010524406635022726 0ustar ebourgebourg/* * $Header$ * $Revision: 1235 $ * $Date: 2006-11-08 18:02:21 +0100 (Wed, 08 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: LocationPath.java 1235 2006-11-08 17:02:21Z elharo $ */ package org.jaxen.expr; import java.util.List; /** * Represents an XPath location path such as //foo/bar * or pre:baz[position()=last()]. * This is production 1 in the * XPath 1.0 specification: * *
[1]  LocationPath ::= RelativeLocationPath    
 *                    | AbsoluteLocationPath
* */ public interface LocationPath extends Expr { /** * Add the next step to this location path. * * @param step */ void addStep(Step step); /** * Returns the ordered list of steps in this location path. * This list may be live. * * @return the ordered list of steps in this location path */ List getSteps(); /** * Returns true if this is an absolute location path; false if it isn't. * Absolute location paths all begiune with / * or //. * * @return true if this is an absol;ute location path; false if it isn't */ boolean isAbsolute(); } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultProcessingInstructionNodeStep.java0000664000175000017500000000775510547712070027675 0ustar ebourgebourg/* * $Header$ * $Revision: 1279 $ * $Date: 2007-01-06 13:21:12 +0100 (Sat, 06 Jan 2007) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultProcessingInstructionNodeStep.java 1279 2007-01-06 12:21:12Z elharo $ */ package org.jaxen.expr; import org.jaxen.ContextSupport; import org.jaxen.Navigator; import org.jaxen.expr.iter.IterableAxis; /** * @deprecated this class will become non-public in the future; * use the interface instead */ public class DefaultProcessingInstructionNodeStep extends DefaultStep implements ProcessingInstructionNodeStep { /** * */ private static final long serialVersionUID = -4825000697808126927L; private String name; public DefaultProcessingInstructionNodeStep(IterableAxis axis, String name, PredicateSet predicateSet) { super( axis, predicateSet ); this.name = name; } public String getName() { return this.name; } public String getText() { StringBuffer buf = new StringBuffer(); buf.append(getAxisName()); buf.append("::processing-instruction("); String name = getName(); if (name != null && name.length() != 0) { buf.append("'"); buf.append(name); buf.append("'"); } buf.append(")"); buf.append(super.getText()); return buf.toString(); } public boolean matches(Object node, ContextSupport support) { Navigator nav = support.getNavigator(); if ( nav.isProcessingInstruction( node ) ) { String name = getName(); if ( name == null || name.length() == 0 ) { return true; } else { return name.equals( nav.getProcessingInstructionTarget( node ) ); } } return false; } } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultUnaryExpr.java0000664000175000017500000000630410533623667023607 0ustar ebourgebourg/* * $Header$ * $Revision: 1261 $ * $Date: 2006-11-30 19:49:27 +0100 (Thu, 30 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultUnaryExpr.java 1261 2006-11-30 18:49:27Z elharo $ */ package org.jaxen.expr; import org.jaxen.Context; import org.jaxen.JaxenException; import org.jaxen.function.NumberFunction; class DefaultUnaryExpr extends DefaultExpr implements UnaryExpr { /** * */ private static final long serialVersionUID = 2303714238683092334L; private Expr expr; DefaultUnaryExpr(Expr expr) { this.expr = expr; } public Expr getExpr() { return this.expr; } public String toString() { return "[(DefaultUnaryExpr): " + getExpr() + "]"; } public String getText() { return "-(" + getExpr().getText() + ")"; } public Expr simplify() { expr = expr.simplify(); return this; } public Object evaluate(Context context) throws JaxenException { Number number = NumberFunction.evaluate( getExpr().evaluate( context ), context.getNavigator() ); return new Double( number.doubleValue() * -1 ); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultNotEqualsExpr.java0000664000175000017500000000605712074523431024417 0ustar ebourgebourg/* * $Header$ * $Revision: 1396 $ * $Date: 2013-01-13 13:22:49 +0100 (Sun, 13 Jan 2013) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultNotEqualsExpr.java 1396 2013-01-13 12:22:49Z elharo $ */ package org.jaxen.expr; class DefaultNotEqualsExpr extends DefaultEqualityExpr { /** * */ private static final long serialVersionUID = -8001267398136979152L; DefaultNotEqualsExpr( Expr lhs, Expr rhs ) { super( lhs, rhs ); } public String getOperator() { return "!="; } public String toString() { return "[(DefaultNotEqualsExpr): " + getLHS() + ", " + getRHS() + "]"; } protected boolean evaluateObjectObject( Object lhs, Object rhs ) { if( eitherIsNumber( lhs, rhs ) ) { // Double.equals does not implement standard IEEE 754 comparisons but != does Double left = (Double) lhs; Double right = (Double) rhs; return left.doubleValue() != right.doubleValue(); } return !lhs.equals( rhs ); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/UnaryExpr.java0000664000175000017500000000524210524425266022275 0ustar ebourgebourg/* * $Header$ * $Revision: 1247 $ * $Date: 2006-11-08 20:06:30 +0100 (Wed, 08 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: UnaryExpr.java 1247 2006-11-08 19:06:30Z elharo $ */ package org.jaxen.expr; /** * Represents an XPath unary expression such as -78. * This is production 27 in the * XPath 1.0 specification: * *
[27] UnaryExpr ::= UnionExpr | '-' UnaryExpr
* */ public interface UnaryExpr extends Expr { /** * Returns the expression following the minus sign. * * @return the expression following the minus sign */ Expr getExpr(); } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultMultiplyExpr.java0000664000175000017500000000623710533623667024335 0ustar ebourgebourg/* * $Header$ * $Revision: 1261 $ * $Date: 2006-11-30 19:49:27 +0100 (Thu, 30 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultMultiplyExpr.java 1261 2006-11-30 18:49:27Z elharo $ */ package org.jaxen.expr; import org.jaxen.Context; import org.jaxen.JaxenException; import org.jaxen.function.NumberFunction; class DefaultMultiplyExpr extends DefaultMultiplicativeExpr { /** * */ private static final long serialVersionUID = 2760053878102260365L; DefaultMultiplyExpr( Expr lhs, Expr rhs ) { super( lhs, rhs ); } public String getOperator() { return "*"; } public Object evaluate( Context context ) throws JaxenException { Number lhsValue = NumberFunction.evaluate( getLHS().evaluate( context ), context.getNavigator() ); Number rhsValue = NumberFunction.evaluate( getRHS().evaluate( context ), context.getNavigator() ); double result = lhsValue.doubleValue() * rhsValue.doubleValue(); return new Double( result ); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/TextNodeStep.java0000664000175000017500000000450310524423522022716 0ustar ebourgebourg/* * $Header$ * $Revision: 1245 $ * $Date: 2006-11-08 19:52:02 +0100 (Wed, 08 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: TextNodeStep.java 1245 2006-11-08 18:52:02Z elharo $ */ package org.jaxen.expr; /** * Represents the XPath node-test text(). * */ public interface TextNodeStep extends Step { } jaxen-1.1.6/src/java/main/org/jaxen/expr/BinaryExpr.java0000664000175000017500000000574110524652561022427 0ustar ebourgebourg/* * $Header$ * $Revision: 1252 $ * $Date: 2006-11-09 17:21:05 +0100 (Thu, 09 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: BinaryExpr.java 1252 2006-11-09 16:21:05Z elharo $ */ package org.jaxen.expr; /** * Represents a binary expression. * This does not match anything in the XPath 1.0 grammar, but in Jaxen * it includes the usual binary operations such as addition, multiplication, * logical and, logical or, and so forth. * */ public interface BinaryExpr extends Expr { /** * Returns the left-hand side of the binary expression. * * @return the left hand side expression */ Expr getLHS(); /** * Returns the right-hand side of the binary expression. * * @return the right-hand side expression */ Expr getRHS(); /** * Returns the operator for the binary expression such as "+" or * "div". * * @return the operator for the expression */ String getOperator(); } jaxen-1.1.6/src/java/main/org/jaxen/expr/PredicateSet.java0000664000175000017500000002354210526171731022714 0ustar ebourgebourg/* * $Header$ * $Revision: 1258 $ * $Date: 2006-11-13 23:38:17 +0100 (Mon, 13 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: PredicateSet.java 1258 2006-11-13 22:38:17Z elharo $ */ package org.jaxen.expr; import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; import org.jaxen.Context; import org.jaxen.ContextSupport; import org.jaxen.JaxenException; import org.jaxen.function.BooleanFunction; /** *

* Represents the collection of predicates that follow the node-test in a * location path. *

* *

* There is no rule that the same predicate may not * appear twice in an XPath expression, nor does this class enforce any such rule. * This is implemented more as a list than a set. However, adding the swme predicate * twice should have no effect on the final result other than slowing it down. *

*/ public class PredicateSet implements Serializable { private static final long serialVersionUID = -7166491740228977853L; private List predicates; /** * Create a new empty predicate set. */ public PredicateSet() { this.predicates = Collections.EMPTY_LIST; } /** * Add a predicate to the set. * * @param predicate the predicate to be inserted */ public void addPredicate(Predicate predicate) { if ( this.predicates == Collections.EMPTY_LIST ) { this.predicates = new ArrayList(); } this.predicates.add( predicate ); } /** * Returns the list containing the predicates. * This list is live, not a copy. * * @return a live list of predicates */ public List getPredicates() { return this.predicates; } /** * Simplify each of the predicates in the list. */ public void simplify() { Iterator predIter = this.predicates.iterator(); Predicate eachPred = null; while ( predIter.hasNext() ) { eachPred = (Predicate) predIter.next(); eachPred.simplify(); } } /** * Returns the XPath string containing each of the predicates. * * @return the XPath string containing each of the predicates */ public String getText() { StringBuffer buf = new StringBuffer(); Iterator predIter = this.predicates.iterator(); Predicate eachPred = null; while ( predIter.hasNext() ) { eachPred = (Predicate) predIter.next(); buf.append( eachPred.getText() ); } return buf.toString(); } /** *

Returns true if any of the supplied nodes satisfy * all the predicates in the set. Returns false if none of the supplied * nodes matches all the predicates in the set. Returns false if the * node-set is empty.

* * @param contextNodeSet the nodes to test against these predicates * @param support ???? * @return true if any node in the contextNodeSet matches all the predicates * @throws JaxenException */ protected boolean evaluateAsBoolean(List contextNodeSet, ContextSupport support) throws JaxenException { return anyMatchingNode( contextNodeSet, support ); } private boolean anyMatchingNode(List contextNodeSet, ContextSupport support) throws JaxenException { // Easy way out (necessary) if (predicates.size() == 0) { return false; } Iterator predIter = predicates.iterator(); // initial list to filter List nodes2Filter = contextNodeSet; // apply all predicates while(predIter.hasNext()) { final int nodes2FilterSize = nodes2Filter.size(); // Set up a dummy context with a list to hold each node Context predContext = new Context(support); List tempList = new ArrayList(1); predContext.setNodeSet(tempList); // loop through the current nodes to filter and add to the // filtered nodes list if the predicate succeeds for (int i = 0; i < nodes2FilterSize; ++i) { Object contextNode = nodes2Filter.get(i); tempList.clear(); tempList.add(contextNode); predContext.setNodeSet(tempList); // ???? predContext.setPosition(i + 1); predContext.setSize(nodes2FilterSize); Object predResult = ((Predicate)predIter.next()).evaluate(predContext); if (predResult instanceof Number) { // Here we assume nodes are in forward or reverse order // as appropriate for axis int proximity = ((Number) predResult).intValue(); if (proximity == (i + 1)) { return true; } } else { Boolean includes = BooleanFunction.evaluate(predResult, predContext.getNavigator()); if (includes.booleanValue()) { return true; } } } } return false; } /** *

Returns all of the supplied nodes that satisfy * all the predicates in the set.

* * @param contextNodeSet the nodes to test against these predicates * @param support ???? * @return all the nodes that match each of the predicates * @throws JaxenException */ protected List evaluatePredicates(List contextNodeSet, ContextSupport support) throws JaxenException { // Easy way out (necessary) if (predicates.size() == 0) { return contextNodeSet; } Iterator predIter = predicates.iterator(); // initial list to filter List nodes2Filter = contextNodeSet; // apply all predicates while(predIter.hasNext()) { nodes2Filter = applyPredicate((Predicate)predIter.next(), nodes2Filter, support); } return nodes2Filter; } public List applyPredicate(Predicate predicate, List nodes2Filter, ContextSupport support) throws JaxenException { final int nodes2FilterSize = nodes2Filter.size(); List filteredNodes = new ArrayList(nodes2FilterSize); // Set up a dummy context with a list to hold each node Context predContext = new Context(support); List tempList = new ArrayList(1); predContext.setNodeSet(tempList); // loop through the current nodes to filter and add to the // filtered nodes list if the predicate succeeds for (int i = 0; i < nodes2FilterSize; ++i) { Object contextNode = nodes2Filter.get(i); tempList.clear(); tempList.add(contextNode); predContext.setNodeSet(tempList); // ???? predContext.setPosition(i + 1); predContext.setSize(nodes2FilterSize); Object predResult = predicate.evaluate(predContext); if (predResult instanceof Number) { // Here we assume nodes are in forward or reverse order // as appropriate for axis int proximity = ((Number) predResult).intValue(); if (proximity == (i + 1)) { filteredNodes.add(contextNode); } } else { Boolean includes = BooleanFunction.evaluate(predResult, predContext.getNavigator()); if (includes.booleanValue()) { filteredNodes.add(contextNode); } } } return filteredNodes; } } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultTruthExpr.java0000664000175000017500000000755611114520466023616 0ustar ebourgebourg/* * $Header$ * $Revision: 1335 $ * $Date: 2008-11-30 15:20:38 +0100 (Sun, 30 Nov 2008) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultTruthExpr.java 1335 2008-11-30 14:20:38Z elharo $ */ package org.jaxen.expr; import java.util.List; abstract class DefaultTruthExpr extends DefaultBinaryExpr { DefaultTruthExpr(Expr lhs, Expr rhs) { super( lhs, rhs ); } public String toString() { return "[(DefaultTruthExpr): " + getLHS() + ", " + getRHS() + "]"; } protected boolean bothAreSets(Object lhs, Object rhs) { return ( lhs instanceof List && rhs instanceof List ); } protected boolean eitherIsSet(Object lhs, Object rhs) { return ( lhs instanceof List || rhs instanceof List ); } protected boolean isSet(Object obj) { return ( obj instanceof List ); } protected boolean isBoolean(Object obj) { return ( obj instanceof Boolean ); } protected boolean setIsEmpty( List set ) { return (set == null || set.size() == 0); } protected boolean eitherIsBoolean(Object lhs, Object rhs) { return ( lhs instanceof Boolean || rhs instanceof Boolean ); } protected boolean bothAreBoolean(Object lhs, Object rhs) { return ( lhs instanceof Boolean && rhs instanceof Boolean ); } protected boolean eitherIsNumber(Object lhs, Object rhs) { return ( lhs instanceof Number || rhs instanceof Number ); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultLessThanExpr.java0000664000175000017500000000520312074523431024215 0ustar ebourgebourg/* * $Header$ * $Revision: 1396 $ * $Date: 2013-01-13 13:22:49 +0100 (Sun, 13 Jan 2013) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultLessThanExpr.java 1396 2013-01-13 12:22:49Z elharo $ */ package org.jaxen.expr; class DefaultLessThanExpr extends DefaultRelationalExpr { /** * */ private static final long serialVersionUID = 8423816025305001283L; DefaultLessThanExpr( Expr lhs, Expr rhs ) { super( lhs, rhs ); } public String getOperator() { return "<"; } protected boolean evaluateDoubleDouble( Double lhs, Double rhs ) { return lhs.doubleValue() < rhs.doubleValue(); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/EqualityExpr.java0000664000175000017500000000622610524652561022777 0ustar ebourgebourg/* * $Header$ * $Revision: 1252 $ * $Date: 2006-11-09 17:21:05 +0100 (Thu, 09 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: EqualityExpr.java 1252 2006-11-09 16:21:05Z elharo $ */ package org.jaxen.expr; /** * Represents an XPath equality expression. This is production 23 in the * XPath 1.0 specification: * * * * * * * * *
[23]   EqualityExpr   ::=   RelationalExpr
| EqualityExpr '=' RelationalExpr
| EqualityExpr '!=' RelationalExpr
* */ public interface EqualityExpr extends BinaryExpr{ } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultPredicate.java0000664000175000017500000000603410533623667023552 0ustar ebourgebourg/* * $Header$ * $Revision: 1261 $ * $Date: 2006-11-30 19:49:27 +0100 (Thu, 30 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultPredicate.java 1261 2006-11-30 18:49:27Z elharo $ */ package org.jaxen.expr; import org.jaxen.Context; import org.jaxen.JaxenException; class DefaultPredicate implements Predicate { /** * */ private static final long serialVersionUID = -4140068594075364971L; private Expr expr; DefaultPredicate(Expr expr) { setExpr( expr ); } public Expr getExpr() { return this.expr; } public void setExpr(Expr expr) { this.expr = expr; } public String getText() { return "[" + getExpr().getText() + "]"; } public String toString() { return "[(DefaultPredicate): " + getExpr() + "]"; } public void simplify() { setExpr( getExpr().simplify() ); } public Object evaluate(Context context) throws JaxenException { return getExpr().evaluate( context ); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultUnionExpr.java0000664000175000017500000001012610533623667023576 0ustar ebourgebourg/* * $Header$ * $Revision: 1261 $ * $Date: 2006-11-30 19:49:27 +0100 (Thu, 30 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultUnionExpr.java 1261 2006-11-30 18:49:27Z elharo $ */ package org.jaxen.expr; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; import org.jaxen.Context; import org.jaxen.JaxenException; import org.jaxen.XPathSyntaxException; /** * @deprecated this class will become non-public in the future; * use the interface instead */ public class DefaultUnionExpr extends DefaultBinaryExpr implements UnionExpr { /** * */ private static final long serialVersionUID = 7629142718276852707L; public DefaultUnionExpr(Expr lhs, Expr rhs) { super( lhs, rhs ); } public String getOperator() { return "|"; } public String toString() { return "[(DefaultUnionExpr): " + getLHS() + ", " + getRHS() + "]"; } public Object evaluate(Context context) throws JaxenException { List results = new ArrayList(); try { List lhsResults = (List) getLHS().evaluate( context ); List rhsResults = (List) getRHS().evaluate( context ); Set unique = new HashSet(); results.addAll( lhsResults ); unique.addAll( lhsResults ); Iterator rhsIter = rhsResults.iterator(); while ( rhsIter.hasNext() ) { Object each = rhsIter.next(); if ( ! unique.contains( each ) ) { results.add( each ); unique.add( each ); } } Collections.sort(results, new NodeComparator(context.getNavigator())); return results; } catch (ClassCastException e) { throw new XPathSyntaxException(this.getText(), context.getPosition(), "Unions are only allowed over node-sets"); } } } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultAbsoluteLocationPath.java0000664000175000017500000000735510533623667025745 0ustar ebourgebourg/* * $Header$ * $Revision: 1261 $ * $Date: 2006-11-30 19:49:27 +0100 (Thu, 30 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultAbsoluteLocationPath.java 1261 2006-11-30 18:49:27Z elharo $ */ package org.jaxen.expr; import java.util.Collections; import java.util.List; import org.jaxen.Context; import org.jaxen.ContextSupport; import org.jaxen.JaxenException; import org.jaxen.Navigator; import org.jaxen.util.SingletonList; /** * @deprecated this class will become non-public in the future; * use the interface instead */ public class DefaultAbsoluteLocationPath extends DefaultLocationPath { /** * */ private static final long serialVersionUID = 2174836928310146874L; public DefaultAbsoluteLocationPath() { } public String toString() { return "[(DefaultAbsoluteLocationPath): " + super.toString() + "]"; } public boolean isAbsolute() { return true; } public String getText() { return "/" + super.getText(); } public Object evaluate(Context context) throws JaxenException { ContextSupport support = context.getContextSupport(); Navigator nav = support.getNavigator(); Context absContext = new Context( support ); List contextNodes = context.getNodeSet(); if ( contextNodes.isEmpty() ) { return Collections.EMPTY_LIST; } Object firstNode = contextNodes.get( 0 ); Object docNode = nav.getDocumentNode( firstNode ); if ( docNode == null ) { return Collections.EMPTY_LIST; } List list = new SingletonList(docNode); absContext.setNodeSet( list ); return super.evaluate( absContext ); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/iter/0000775000175000017500000000000012174247550020436 5ustar ebourgebourgjaxen-1.1.6/src/java/main/org/jaxen/expr/iter/IterableAttributeAxis.java0000664000175000017500000000765510440373212025543 0ustar ebourgebourg/* $Id: IterableAttributeAxis.java 1162 2006-06-03 20:52:26Z elharo $ Copyright 2003 The Werken Company. All Rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Jaxen Project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.jaxen.expr.iter; import java.util.Iterator; import org.jaxen.ContextSupport; import org.jaxen.NamedAccessNavigator; import org.jaxen.UnsupportedAxisException; /** * Provide access to the XPath attribute axis. * This axis does not include namespace declarations such as * xmlns and xmlns:prefix. * It does include attributes defaulted from the DTD. * * @author Bob McWhirter * @author James Strachan * @author Stephen Colebourne */ public class IterableAttributeAxis extends IterableAxis { /** * */ private static final long serialVersionUID = 1L; /** * Constructor. * * @param value the axis value */ public IterableAttributeAxis(int value) { super(value); } /** * Gets an iterator for the attribute axis. * * @param contextNode the current context node to work from * @param support the additional context information */ public Iterator iterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException { return support.getNavigator().getAttributeAxisIterator(contextNode); } /** * Gets the iterator for the attribute axis that supports named access. * * @param contextNode the current context node to work from * @param support the additional context information * @param localName the local name of the attributes to return * @param namespacePrefix the prefix of the namespace of the attributes to return * @param namespaceURI the uri of the namespace of the attributes to return */ public Iterator namedAccessIterator( Object contextNode, ContextSupport support, String localName, String namespacePrefix, String namespaceURI) throws UnsupportedAxisException { NamedAccessNavigator nav = (NamedAccessNavigator) support.getNavigator(); return nav.getAttributeAxisIterator(contextNode, localName, namespacePrefix, namespaceURI); } /** * Does this axis support named access? * * @param support the additional context information * @return true if named access is supported. If not iterator() will be used. */ public boolean supportsNamedAccess(ContextSupport support) { return (support.getNavigator() instanceof NamedAccessNavigator); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/iter/IterableAncestorOrSelfAxis.java0000664000175000017500000000543210440373212026460 0ustar ebourgebourg/* * $Header$ * $Revision: 1162 $ * $Date: 2006-06-03 22:52:26 +0200 (Sat, 03 Jun 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: IterableAncestorOrSelfAxis.java 1162 2006-06-03 20:52:26Z elharo $ */ package org.jaxen.expr.iter; import java.util.Iterator; import org.jaxen.ContextSupport; import org.jaxen.UnsupportedAxisException; public class IterableAncestorOrSelfAxis extends IterableAxis { /** * */ private static final long serialVersionUID = 1L; public IterableAncestorOrSelfAxis(int value) { super( value ); } public Iterator iterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException { return support.getNavigator().getAncestorOrSelfAxisIterator( contextNode ); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/iter/IterableAxis.java0000664000175000017500000000724610371471320023655 0ustar ebourgebourg/* $Id: IterableAxis.java 1128 2006-02-05 21:49:04Z elharo $ Copyright 2003 The Werken Company. All Rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Jaxen Project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.jaxen.expr.iter; import java.io.Serializable; import java.util.Iterator; import org.jaxen.ContextSupport; import org.jaxen.UnsupportedAxisException; /** * Provide access to the XPath axes. * * @author Bob McWhirter * @author James Strachan * @author Stephen Colebourne */ public abstract class IterableAxis implements Serializable { /** The axis type */ private int value; /** * Constructor. * * @param axisValue */ public IterableAxis(int axisValue) { this.value = axisValue; } /** * Gets the axis value. * * @return the axis value */ public int value() { return this.value; } /** * Gets the iterator for a specific XPath axis. * * @param contextNode the current context node to work from * @param support the additional context information * @return an iterator for the axis * @throws UnsupportedAxisException */ public abstract Iterator iterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException; /** * Gets the iterator for a specific XPath axis that supports named access. * * @param contextNode the current context node to work from * @param support the additional context information * @param localName the local name of the nodes to return * @param namespacePrefix the prefix of the namespace of the nodes to return * @param namespaceURI the URI of the namespace of the nodes to return */ public Iterator namedAccessIterator( Object contextNode, ContextSupport support, String localName, String namespacePrefix, String namespaceURI) throws UnsupportedAxisException { throw new UnsupportedOperationException("Named access unsupported"); } /** * Does this axis support named access? * * @param support the additional context information * @return true if named access supported. If not iterator() will be used */ public boolean supportsNamedAccess(ContextSupport support) { return false; } } jaxen-1.1.6/src/java/main/org/jaxen/expr/iter/IterablePrecedingSiblingAxis.java0000664000175000017500000000546510440373212027005 0ustar ebourgebourg/* * $Header$ * $Revision: 1162 $ * $Date: 2006-06-03 22:52:26 +0200 (Sat, 03 Jun 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: IterablePrecedingSiblingAxis.java 1162 2006-06-03 20:52:26Z elharo $ */ package org.jaxen.expr.iter; import java.util.Iterator; import org.jaxen.ContextSupport; import org.jaxen.UnsupportedAxisException; public class IterablePrecedingSiblingAxis extends IterableAxis { /** * */ private static final long serialVersionUID = -3140080721715120745L; public IterablePrecedingSiblingAxis(int value) { super( value ); } public Iterator iterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException { return support.getNavigator().getPrecedingSiblingAxisIterator( contextNode ); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/iter/IterableChildAxis.java0000664000175000017500000001000010440373212024575 0ustar ebourgebourg/* $Id: IterableChildAxis.java 1162 2006-06-03 20:52:26Z elharo $ Copyright 2003 The Werken Company. All Rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Jaxen Project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.jaxen.expr.iter; import java.util.Iterator; import org.jaxen.ContextSupport; import org.jaxen.NamedAccessNavigator; import org.jaxen.UnsupportedAxisException; /** * Provide access to the child xpath axis. * * @author Bob McWhirter * @author James Strachan * @author Stephen Colebourne */ public class IterableChildAxis extends IterableAxis { /** * */ private static final long serialVersionUID = 1L; /** * Constructor. * * @param value the axis value */ public IterableChildAxis(int value) { super(value); } /** * Gets the iterator for the child axis. * * @param contextNode the current context node to work from * @param support the additional context information * @return an iterator over the children of the context node * @throws UnsupportedAxisException if the child axis is not supported */ public Iterator iterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException { return support.getNavigator().getChildAxisIterator(contextNode); } /** * Gets an iterator for the child XPath axis that supports named access. * * @param contextNode the current context node to work from * @param support the additional context information * @param localName the local name of the children to return * @param namespacePrefix the prefix of the namespace of the children to return * @param namespaceURI the URI of the namespace of the children to return * @return an iterator over the children of the context node * @throws UnsupportedAxisException if the child axis is not supported by the model */ public Iterator namedAccessIterator( Object contextNode, ContextSupport support, String localName, String namespacePrefix, String namespaceURI) throws UnsupportedAxisException { NamedAccessNavigator nav = (NamedAccessNavigator) support.getNavigator(); return nav.getChildAxisIterator(contextNode, localName, namespacePrefix, namespaceURI); } /** * Does this axis support named access? * * @param support the additional context information * @return true if named access supported. If not iterator() will be used */ public boolean supportsNamedAccess(ContextSupport support) { return (support.getNavigator() instanceof NamedAccessNavigator); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/iter/IterableFollowingAxis.java0000664000175000017500000000543110440373212025526 0ustar ebourgebourg/* * $Header$ * $Revision: 1162 $ * $Date: 2006-06-03 22:52:26 +0200 (Sat, 03 Jun 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: IterableFollowingAxis.java 1162 2006-06-03 20:52:26Z elharo $ */ package org.jaxen.expr.iter; import java.util.Iterator; import org.jaxen.ContextSupport; import org.jaxen.UnsupportedAxisException; public class IterableFollowingAxis extends IterableAxis { /** * */ private static final long serialVersionUID = -7100245752300813209L; public IterableFollowingAxis(int value) { super( value ); } public Iterator iterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException { return support.getNavigator().getFollowingAxisIterator( contextNode ); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/iter/IterableNamespaceAxis.java0000664000175000017500000000543110440373212025462 0ustar ebourgebourg/* * $Header$ * $Revision: 1162 $ * $Date: 2006-06-03 22:52:26 +0200 (Sat, 03 Jun 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: IterableNamespaceAxis.java 1162 2006-06-03 20:52:26Z elharo $ */ package org.jaxen.expr.iter; import java.util.Iterator; import org.jaxen.ContextSupport; import org.jaxen.UnsupportedAxisException; public class IterableNamespaceAxis extends IterableAxis { /** * */ private static final long serialVersionUID = -8022585664651357087L; public IterableNamespaceAxis(int value) { super( value ); } public Iterator iterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException { return support.getNavigator().getNamespaceAxisIterator( contextNode ); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/iter/IterablePrecedingAxis.java0000664000175000017500000000542710440373212025473 0ustar ebourgebourg/* * $Header$ * $Revision: 1162 $ * $Date: 2006-06-03 22:52:26 +0200 (Sat, 03 Jun 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: IterablePrecedingAxis.java 1162 2006-06-03 20:52:26Z elharo $ */ package org.jaxen.expr.iter; import java.util.Iterator; import org.jaxen.ContextSupport; import org.jaxen.UnsupportedAxisException; public class IterablePrecedingAxis extends IterableAxis { /** * */ private static final long serialVersionUID = 587333938258540052L; public IterablePrecedingAxis(int value) { super( value ); } public Iterator iterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException { return support.getNavigator().getPrecedingAxisIterator( contextNode ); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/iter/IterableDescendantAxis.java0000664000175000017500000000543410440373212025641 0ustar ebourgebourg/* * $Header$ * $Revision: 1162 $ * $Date: 2006-06-03 22:52:26 +0200 (Sat, 03 Jun 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: IterableDescendantAxis.java 1162 2006-06-03 20:52:26Z elharo $ */ package org.jaxen.expr.iter; import java.util.Iterator; import org.jaxen.ContextSupport; import org.jaxen.UnsupportedAxisException; public class IterableDescendantAxis extends IterableAxis { /** * */ private static final long serialVersionUID = 7286715505909806723L; public IterableDescendantAxis(int value) { super( value ); } public Iterator iterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException { return support.getNavigator().getDescendantAxisIterator( contextNode ); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/iter/IterableSelfAxis.java0000664000175000017500000000540410440373212024457 0ustar ebourgebourg/* * $Header$ * $Revision: 1162 $ * $Date: 2006-06-03 22:52:26 +0200 (Sat, 03 Jun 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: IterableSelfAxis.java 1162 2006-06-03 20:52:26Z elharo $ */ package org.jaxen.expr.iter; import java.util.Iterator; import org.jaxen.ContextSupport; import org.jaxen.UnsupportedAxisException; public class IterableSelfAxis extends IterableAxis { /** * */ private static final long serialVersionUID = 8292222516706760134L; public IterableSelfAxis(int value) { super( value ); } public Iterator iterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException { return support.getNavigator().getSelfAxisIterator( contextNode ); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/iter/IterableFollowingSiblingAxis.java0000664000175000017500000000546410440373212027044 0ustar ebourgebourg/* * $Header$ * $Revision: 1162 $ * $Date: 2006-06-03 22:52:26 +0200 (Sat, 03 Jun 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: IterableFollowingSiblingAxis.java 1162 2006-06-03 20:52:26Z elharo $ */ package org.jaxen.expr.iter; import java.util.Iterator; import org.jaxen.ContextSupport; import org.jaxen.UnsupportedAxisException; public class IterableFollowingSiblingAxis extends IterableAxis { /** * */ private static final long serialVersionUID = 4412705219546610009L; public IterableFollowingSiblingAxis(int value) { super( value ); } public Iterator iterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException { return support.getNavigator().getFollowingSiblingAxisIterator( contextNode ); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/iter/IterableParentAxis.java0000664000175000017500000000541510440373212025021 0ustar ebourgebourg/* * $Header$ * $Revision: 1162 $ * $Date: 2006-06-03 22:52:26 +0200 (Sat, 03 Jun 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: IterableParentAxis.java 1162 2006-06-03 20:52:26Z elharo $ */ package org.jaxen.expr.iter; import java.util.Iterator; import org.jaxen.ContextSupport; import org.jaxen.UnsupportedAxisException; public class IterableParentAxis extends IterableAxis { /** * */ private static final long serialVersionUID = -7521574185875636490L; public IterableParentAxis(int value) { super( value ); } public Iterator iterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException { return support.getNavigator().getParentAxisIterator( contextNode ); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/iter/IterableAncestorAxis.java0000664000175000017500000000541010440373212025341 0ustar ebourgebourg/* * $Header$ * $Revision: 1162 $ * $Date: 2006-06-03 22:52:26 +0200 (Sat, 03 Jun 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: IterableAncestorAxis.java 1162 2006-06-03 20:52:26Z elharo $ */ package org.jaxen.expr.iter; import java.util.Iterator; import org.jaxen.ContextSupport; import org.jaxen.UnsupportedAxisException; public class IterableAncestorAxis extends IterableAxis { /** * */ private static final long serialVersionUID = 1L; public IterableAncestorAxis(int value) { super( value ); } public Iterator iterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException { return support.getNavigator().getAncestorAxisIterator( contextNode ); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/iter/IterableDescendantOrSelfAxis.java0000664000175000017500000000546410440373212026757 0ustar ebourgebourg/* * $Header$ * $Revision: 1162 $ * $Date: 2006-06-03 22:52:26 +0200 (Sat, 03 Jun 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: IterableDescendantOrSelfAxis.java 1162 2006-06-03 20:52:26Z elharo $ */ package org.jaxen.expr.iter; import java.util.Iterator; import org.jaxen.ContextSupport; import org.jaxen.UnsupportedAxisException; public class IterableDescendantOrSelfAxis extends IterableAxis { /** * */ private static final long serialVersionUID = 2956703237251023850L; public IterableDescendantOrSelfAxis(int value) { super( value ); } public Iterator iterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException { return support.getNavigator().getDescendantOrSelfAxisIterator( contextNode ); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/iter/package.html0000664000175000017500000000022107327350513022710 0ustar ebourgebourg org.jaxen.expr.iter.*

Axis iterator creation functors.

jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultAllNodeStep.java0000664000175000017500000000602210533623667024021 0ustar ebourgebourg/* * $Header$ * $Revision: 1261 $ * $Date: 2006-11-30 19:49:27 +0100 (Thu, 30 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultAllNodeStep.java 1261 2006-11-30 18:49:27Z elharo $ */ package org.jaxen.expr; import org.jaxen.ContextSupport; import org.jaxen.expr.iter.IterableAxis; /** * @deprecated this class will become non-public in the future; * use the interface instead */ public class DefaultAllNodeStep extends DefaultStep implements AllNodeStep { /** * */ private static final long serialVersionUID = 292886316770123856L; public DefaultAllNodeStep(IterableAxis axis, PredicateSet predicateSet) { super( axis, predicateSet ); } public String toString() { return "[(DefaultAllNodeStep): " + getAxisName() + "]"; } public String getText() { return getAxisName() + "::node()" + super.getText(); } public boolean matches(Object node, ContextSupport contextSupport) { return true; } } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultRelativeLocationPath.java0000664000175000017500000000516210533623667025734 0ustar ebourgebourg/* * $Header$ * $Revision: 1261 $ * $Date: 2006-11-30 19:49:27 +0100 (Thu, 30 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultRelativeLocationPath.java 1261 2006-11-30 18:49:27Z elharo $ */ package org.jaxen.expr; /** * @deprecated this class will become non-public in the future; * use the interface instead */ public class DefaultRelativeLocationPath extends DefaultLocationPath { /** * */ private static final long serialVersionUID = -1006862529366150615L; public String toString() { return "[(DefaultRelativeLocationPath): " + super.toString() + "]"; } } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultMultiplicativeExpr.java0000664000175000017500000000512510371471320025467 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultMultiplicativeExpr.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.expr; abstract class DefaultMultiplicativeExpr extends DefaultArithExpr implements MultiplicativeExpr { DefaultMultiplicativeExpr(Expr lhs, Expr rhs) { super( lhs, rhs ); } public String toString() { return "[(DefaultMultiplicativeExpr): " + getLHS() + ", " + getRHS() + "]"; } } jaxen-1.1.6/src/java/main/org/jaxen/expr/FunctionCallExpr.java0000664000175000017500000000652010524403747023560 0ustar ebourgebourg/* * $Header$ * $Revision: 1232 $ * $Date: 2006-11-08 17:37:59 +0100 (Wed, 08 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: FunctionCallExpr.java 1232 2006-11-08 16:37:59Z elharo $ */ package org.jaxen.expr; import java.util.List; /** * Represents an XPath function call expression. This is production 16 in the * XPath 1.0 specification: * * <
[16] FunctionCall ::= FunctionName '(' ( Argument ( ',' Argument )* )? ')'
* */ public interface FunctionCallExpr extends Expr { /** * Returns the namespace prefix of the function. This is the empty * string for XPath's built-in functions. * * @return the namespace prefix of the function */ public String getPrefix(); /** * Returns the local name of the function. * * @return the local name of the function */ public String getFunctionName(); /** * Add the next argument to the function. * * @param parameter a function argument */ public void addParameter(Expr parameter); /** * Returns the the ordered list of function arguments. * Each member of the list is an Expr object. * * @return the ordered list of function arguments */ public List getParameters(); } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultLocationPath.java0000664000175000017500000001222211270040443024213 0ustar ebourgebourg/* * $Header$ * $Revision: 1345 $ * $Date: 2009-10-22 13:25:23 +0200 (Thu, 22 Oct 2009) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultLocationPath.java 1345 2009-10-22 11:25:23Z elharo $ */ package org.jaxen.expr; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import org.jaxen.Context; import org.jaxen.ContextSupport; import org.jaxen.JaxenException; abstract class DefaultLocationPath extends DefaultExpr implements LocationPath { private List steps; /** * Create a new empty location path. */ DefaultLocationPath() { this.steps = new LinkedList(); } public void addStep(Step step) { getSteps().add(step); } public List getSteps() { return this.steps; } public Expr simplify() { Iterator stepIter = getSteps().iterator(); Step eachStep = null; while (stepIter.hasNext()) { eachStep = (Step) stepIter.next(); eachStep.simplify(); } return this; } public String getText() { StringBuffer buf = new StringBuffer(); Iterator stepIter = getSteps().iterator(); while (stepIter.hasNext()) { buf.append(((Step) stepIter.next()).getText()); if (stepIter.hasNext()) { buf.append("/"); } } return buf.toString(); } public String toString() { StringBuffer buf = new StringBuffer(); Iterator stepIter = getSteps().iterator(); while (stepIter.hasNext()) { buf.append(stepIter.next().toString()); if (stepIter.hasNext()) { buf.append("/"); } } return buf.toString(); } public boolean isAbsolute() { return false; } public Object evaluate(Context context) throws JaxenException { List nodeSet = context.getNodeSet(); List contextNodeSet = new ArrayList(nodeSet); ContextSupport support = context.getContextSupport(); Context stepContext = new Context(support); Iterator stepIter = getSteps().iterator(); while ( stepIter.hasNext() ) { Step eachStep = (Step) stepIter.next(); stepContext.setNodeSet(contextNodeSet); contextNodeSet = eachStep.evaluate(stepContext); // now we need to reverse the list if this is a reverse axis if (isReverseAxis(eachStep)) { Collections.reverse(contextNodeSet); } } if (getSteps().size() > 1 || nodeSet.size() > 1) { Collections.sort(contextNodeSet, new NodeComparator(support.getNavigator())); } return contextNodeSet; } private boolean isReverseAxis(Step step) { int axis = step.getAxis(); return axis == org.jaxen.saxpath.Axis.PRECEDING || axis == org.jaxen.saxpath.Axis.PRECEDING_SIBLING || axis == org.jaxen.saxpath.Axis.ANCESTOR || axis == org.jaxen.saxpath.Axis.ANCESTOR_OR_SELF; } } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultDivExpr.java0000664000175000017500000000622010533623667023230 0ustar ebourgebourg/* * $Header$ * $Revision: 1261 $ * $Date: 2006-11-30 19:49:27 +0100 (Thu, 30 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultDivExpr.java 1261 2006-11-30 18:49:27Z elharo $ */ package org.jaxen.expr; import org.jaxen.Context; import org.jaxen.JaxenException; import org.jaxen.function.NumberFunction; class DefaultDivExpr extends DefaultMultiplicativeExpr { /** * */ private static final long serialVersionUID = 6318739386201615441L; DefaultDivExpr(Expr lhs, Expr rhs) { super( lhs, rhs ); } public String getOperator() { return "div"; } public Object evaluate(Context context) throws JaxenException { Number lhsValue = NumberFunction.evaluate( getLHS().evaluate( context ), context.getNavigator() ); Number rhsValue = NumberFunction.evaluate( getRHS().evaluate( context ), context.getNavigator() ); double result = lhsValue.doubleValue() / rhsValue.doubleValue(); return new Double( result ); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultAdditiveExpr.java0000664000175000017500000000506410371471320024227 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultAdditiveExpr.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.expr; abstract class DefaultAdditiveExpr extends DefaultArithExpr implements AdditiveExpr { DefaultAdditiveExpr( Expr lhs, Expr rhs ) { super( lhs, rhs ); } public String toString() { return "[(" + getClass().getName() + "): " + getLHS() + ", " + getRHS() + "]"; } } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultBinaryExpr.java0000664000175000017500000000620310547514047023727 0ustar ebourgebourg/* * $Header$ * $Revision: 1277 $ * $Date: 2007-01-05 19:25:43 +0100 (Fri, 05 Jan 2007) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultBinaryExpr.java 1277 2007-01-05 18:25:43Z elharo $ */ package org.jaxen.expr; abstract class DefaultBinaryExpr extends DefaultExpr implements BinaryExpr { private Expr lhs; private Expr rhs; DefaultBinaryExpr(Expr lhs, Expr rhs) { this.lhs = lhs; this.rhs = rhs; } public Expr getLHS() { return this.lhs; } public Expr getRHS() { return this.rhs; } public void setLHS(Expr lhs) { this.lhs = lhs; } public void setRHS(Expr rhs) { this.rhs = rhs; } public abstract String getOperator(); public String getText() { return "(" + getLHS().getText() + " " + getOperator() + " " + getRHS().getText() +")"; } public String toString() { return "[" + getClass().getName() + ": " + getLHS() + ", " + getRHS() + "]"; } public Expr simplify() { setLHS( getLHS().simplify() ); setRHS( getRHS().simplify() ); return this; } } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultRelationalExpr.java0000664000175000017500000001124010371471320024561 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultRelationalExpr.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.expr; import java.util.Iterator; import java.util.List; import org.jaxen.Context; import org.jaxen.JaxenException; import org.jaxen.Navigator; import org.jaxen.function.NumberFunction; abstract class DefaultRelationalExpr extends DefaultTruthExpr implements RelationalExpr { DefaultRelationalExpr( Expr lhs, Expr rhs ) { super( lhs, rhs ); } public String toString() { return "[(DefaultRelationalExpr): " + getLHS() + ", " + getRHS() + "]"; } public Object evaluate( Context context ) throws JaxenException { Object lhsValue = getLHS().evaluate( context ); Object rhsValue = getRHS().evaluate( context ); Navigator nav = context.getNavigator(); if( bothAreSets( lhsValue, rhsValue ) ) { return evaluateSetSet( (List) lhsValue, (List) rhsValue, nav ); } if( eitherIsSet( lhsValue, rhsValue ) ) { if( isSet( lhsValue ) ) { return evaluateSetSet( (List) lhsValue, convertToList( rhsValue ), nav ); } else { return evaluateSetSet( convertToList( lhsValue ), (List) rhsValue, nav ); } } return evaluateObjectObject( lhsValue, rhsValue, nav ) ? Boolean.TRUE : Boolean.FALSE; } private Object evaluateSetSet( List lhsSet, List rhsSet, Navigator nav ) { if( setIsEmpty( lhsSet ) || setIsEmpty( rhsSet ) ) // return false if either is null or empty { return Boolean.FALSE; } for( Iterator lhsIterator = lhsSet.iterator(); lhsIterator.hasNext(); ) { Object lhs = lhsIterator.next(); for( Iterator rhsIterator = rhsSet.iterator(); rhsIterator.hasNext(); ) { Object rhs = rhsIterator.next(); if( evaluateObjectObject( lhs, rhs, nav ) ) { return Boolean.TRUE; } } } return Boolean.FALSE; } private boolean evaluateObjectObject( Object lhs, Object rhs, Navigator nav ) { if( lhs == null || rhs == null ) { return false; } Double lhsNum = NumberFunction.evaluate( lhs, nav ); Double rhsNum = NumberFunction.evaluate( rhs, nav ); if( NumberFunction.isNaN( lhsNum ) || NumberFunction.isNaN( rhsNum ) ) { return false; } return evaluateDoubleDouble( lhsNum, rhsNum ); } protected abstract boolean evaluateDoubleDouble( Double lhs, Double rhs ); } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultEqualityExpr.java0000664000175000017500000001412411076362270024276 0ustar ebourgebourg/* * $Header$ * $Revision: 1332 $ * $Date: 2008-10-18 15:29:28 +0200 (Sat, 18 Oct 2008) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultEqualityExpr.java 1332 2008-10-18 13:29:28Z elharo $ */ package org.jaxen.expr; import java.util.Iterator; import java.util.List; import org.jaxen.Context; import org.jaxen.JaxenException; import org.jaxen.Navigator; import org.jaxen.function.BooleanFunction; import org.jaxen.function.NumberFunction; import org.jaxen.function.StringFunction; abstract class DefaultEqualityExpr extends DefaultTruthExpr implements EqualityExpr { DefaultEqualityExpr( Expr lhs, Expr rhs ) { super( lhs, rhs ); } public String toString() { return "[(DefaultEqualityExpr): " + getLHS() + ", " + getRHS() + "]"; } public Object evaluate( Context context ) throws JaxenException { Object lhsValue = getLHS().evaluate( context ); Object rhsValue = getRHS().evaluate( context ); if( lhsValue == null || rhsValue == null ) { return Boolean.FALSE; } Navigator nav = context.getNavigator(); if( bothAreSets(lhsValue, rhsValue) ) { return evaluateSetSet( (List) lhsValue, (List) rhsValue, nav ); } else if (isSet(lhsValue ) && isBoolean(rhsValue)) { Boolean lhsBoolean = ((List) lhsValue).isEmpty() ? Boolean.FALSE : Boolean.TRUE; Boolean rhsBoolean = (Boolean) rhsValue; return Boolean.valueOf(evaluateObjectObject( lhsBoolean, rhsBoolean, nav ) ); } else if (isBoolean(lhsValue ) && isSet(rhsValue)) { Boolean lhsBoolean = (Boolean) lhsValue; Boolean rhsBoolean = ((List) rhsValue).isEmpty() ? Boolean.FALSE : Boolean.TRUE; return Boolean.valueOf(evaluateObjectObject( lhsBoolean, rhsBoolean, nav ) ); } else if (eitherIsSet(lhsValue, rhsValue) ) { if (isSet(lhsValue)) { return evaluateSetSet( (List) lhsValue, convertToList(rhsValue), nav ); } else { return evaluateSetSet( convertToList(lhsValue), (List) rhsValue, nav ); } } else { return Boolean.valueOf(evaluateObjectObject( lhsValue, rhsValue, nav ) ); } } private Boolean evaluateSetSet( List lhsSet, List rhsSet, Navigator nav ) { /* If both objects to be compared are node-sets, then the comparison will be * true if and only if there is a node in the first node-set and a node in * the second node-set such that the result of performing the comparison on * the string-values of the two nodes is true */ if( setIsEmpty( lhsSet ) || setIsEmpty( rhsSet ) ) { return Boolean.FALSE; } for( Iterator lhsIterator = lhsSet.iterator(); lhsIterator.hasNext(); ) { Object lhs = lhsIterator.next(); for( Iterator rhsIterator = rhsSet.iterator(); rhsIterator.hasNext(); ) { Object rhs = rhsIterator.next(); if( evaluateObjectObject( lhs, rhs, nav ) ) { return Boolean.TRUE; } } } return Boolean.FALSE; } private boolean evaluateObjectObject( Object lhs, Object rhs, Navigator nav ) { if( eitherIsBoolean( lhs, rhs ) ) { return evaluateObjectObject( BooleanFunction.evaluate( lhs, nav ), BooleanFunction.evaluate( rhs, nav ) ); } else if( eitherIsNumber( lhs, rhs ) ) { return evaluateObjectObject( NumberFunction.evaluate( lhs, nav ), NumberFunction.evaluate( rhs, nav ) ); } else { return evaluateObjectObject( StringFunction.evaluate( lhs, nav ), StringFunction.evaluate( rhs, nav ) ); } } protected abstract boolean evaluateObjectObject( Object lhs, Object rhs ); } jaxen-1.1.6/src/java/main/org/jaxen/expr/AdditiveExpr.java0000664000175000017500000000634110524652561022731 0ustar ebourgebourg/* * $Header$ * $Revision: 1252 $ * $Date: 2006-11-09 17:21:05 +0100 (Thu, 09 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: AdditiveExpr.java 1252 2006-11-09 16:21:05Z elharo $ */ package org.jaxen.expr; /** * Represents an XPath additive expression. This is production 25 in the * XPath 1.0 specification: * * * * * * * * *
[25]   AdditiveExpr   ::=   MultiplicativeExpr
| AdditiveExpr '+' MultiplicativeExpr
| AdditiveExpr '-' MultiplicativeExpr *
* */ public interface AdditiveExpr extends BinaryExpr { } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultFilterExpr.java0000664000175000017500000001227110533623667023736 0ustar ebourgebourg/* * $Header$ * $Revision: 1261 $ * $Date: 2006-11-30 19:49:27 +0100 (Thu, 30 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultFilterExpr.java 1261 2006-11-30 18:49:27Z elharo $ */ package org.jaxen.expr; import java.util.ArrayList; import java.util.List; import org.jaxen.Context; import org.jaxen.JaxenException; /** * @deprecated this class will become non-public in the future; * use the interface instead */ public class DefaultFilterExpr extends DefaultExpr implements FilterExpr, Predicated { /** * */ private static final long serialVersionUID = -549640659288005735L; private Expr expr; private PredicateSet predicates; public DefaultFilterExpr(PredicateSet predicateSet) { this.predicates = predicateSet; } public DefaultFilterExpr(Expr expr, PredicateSet predicateSet) { this.expr = expr; this.predicates = predicateSet; } public void addPredicate(Predicate predicate) { this.predicates.addPredicate( predicate ); } public List getPredicates() { return this.predicates.getPredicates(); } public PredicateSet getPredicateSet() { return this.predicates; } public Expr getExpr() { return this.expr; } public String toString() { return "[(DefaultFilterExpr): expr: " + expr + " predicates: " + predicates + " ]"; } public String getText() { String text = ""; if ( this.expr != null ) { text = this.expr.getText(); } text += predicates.getText(); return text; } public Expr simplify() { this.predicates.simplify(); if ( this.expr != null ) { this.expr = this.expr.simplify(); } if ( this.predicates.getPredicates().size() == 0 ) { return getExpr(); } return this; } /** Returns true if the current filter matches at least one of the context nodes */ public boolean asBoolean(Context context) throws JaxenException { Object results = null; if ( expr != null ) { results = expr.evaluate( context ); } else { List nodeSet = context.getNodeSet(); ArrayList list = new ArrayList(nodeSet.size()); list.addAll( nodeSet ); results = list; } if ( results instanceof Boolean ) { Boolean b = (Boolean) results; return b.booleanValue(); } if ( results instanceof List ) { return getPredicateSet().evaluateAsBoolean( (List) results, context.getContextSupport() ); } return false; } public Object evaluate(Context context) throws JaxenException { Object results = getExpr().evaluate( context ); if ( results instanceof List ) { List newresults = getPredicateSet().evaluatePredicates( (List) results, context.getContextSupport() ); results = newresults; } return results; } } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultArithExpr.java0000664000175000017500000000501010371471320023534 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultArithExpr.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.expr; abstract class DefaultArithExpr extends DefaultBinaryExpr { DefaultArithExpr(Expr lhs, Expr rhs) { super( lhs, rhs ); } public String toString() { return "[(DefaultArithExpr): " + getLHS() + ", " + getRHS() + "]"; } } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultLessThanEqualExpr.java0000664000175000017500000000520312074523431025205 0ustar ebourgebourg/* * $Header$ * $Revision: 1396 $ * $Date: 2013-01-13 13:22:49 +0100 (Sun, 13 Jan 2013) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultLessThanEqualExpr.java 1396 2013-01-13 12:22:49Z elharo $ */ package org.jaxen.expr; class DefaultLessThanEqualExpr extends DefaultRelationalExpr { private static final long serialVersionUID = 7980276649555334242L; DefaultLessThanEqualExpr( Expr lhs, Expr rhs ) { super( lhs, rhs ); } public String getOperator() { return "<="; } protected boolean evaluateDoubleDouble( Double lhs, Double rhs ) { return lhs.doubleValue() <= rhs.doubleValue(); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/Step.java0000664000175000017500000001074110537024176021252 0ustar ebourgebourg/* * $Header$ * $Revision: 1268 $ * $Date: 2006-12-10 16:32:14 +0100 (Sun, 10 Dec 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: Step.java 1268 2006-12-10 15:32:14Z elharo $ */ package org.jaxen.expr; import java.util.Iterator; import java.util.List; import org.jaxen.Context; import org.jaxen.ContextSupport; import org.jaxen.JaxenException; import org.jaxen.UnsupportedAxisException; /** *

Represents a location step in a LocationPath. The node-set selected by * the location step is the node-set that results from generating an initial * node-set from the axis and node-test, and then filtering that node-set by * each of the predicates in turn.

* *

* The initial node-set consists of the nodes having the relationship to the * context node specified by the axis, and having the node type and expanded-name * specified by the node test.

*/ public interface Step extends Predicated { /** * Performs the node-test part of evaluating the step for the given node * (which must be on the axis). * * @return true if the node matches this step; false if it doesn't */ boolean matches(Object node, ContextSupport contextSupport) throws JaxenException; /** * Returns a String containing the XPath expression. * * @return the text form of this step */ String getText(); /** * Simplifies the XPath step. In practice, this is usually a noop. * Jaxen does not currently perform any simplification. */ void simplify(); /** * Get an identifier for the current axis. * * @return the axis identifier * @see org.jaxen.saxpath.Axis */ public int getAxis(); /** * Get an Iterator for the current axis starting in the given contextNode. * * @param contextNode the node from which to follow this step * @param support the remaining context for the traversal * @return an iterator over the nodes along the axis * @throws UnsupportedAxisException if the navigator does not support this step's axis * */ Iterator axisIterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException; /** * For each node in the given context calls matches() for every node on the * axis, then filters the result by each of the predicates. * * @return a list of matching nodes */ List evaluate(Context context) throws JaxenException; } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultVariableReferenceExpr.java0000664000175000017500000000734611751252745026062 0ustar ebourgebourg/* * $Header$ * $Revision: 1367 $ * $Date: 2012-05-05 18:31:33 +0200 (Sat, 05 May 2012) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultVariableReferenceExpr.java 1367 2012-05-05 16:31:33Z elharo $ */ package org.jaxen.expr; import org.jaxen.Context; import org.jaxen.UnresolvableException; class DefaultVariableReferenceExpr extends DefaultExpr implements VariableReferenceExpr { /** * */ private static final long serialVersionUID = 8832095437149358674L; private String prefix; private String localName; DefaultVariableReferenceExpr(String prefix, String variableName) { this.prefix = prefix; this.localName = variableName; } public String getPrefix() { return this.prefix; } public String getVariableName() { return this.localName; } public String toString() { return "[(DefaultVariableReferenceExpr): " + getQName() + "]"; } private String getQName() { if ( "".equals(prefix) ) { return localName; } return prefix + ":" + localName; } public String getText() { return "$" + getQName(); } public Object evaluate(Context context) throws UnresolvableException { String prefix = getPrefix(); String namespaceURI = null; // default namespace is not used within XPath expressions if (prefix != null && !"".equals(prefix)) { namespaceURI = context.translateNamespacePrefixToUri( prefix ); } return context.getVariableValue( namespaceURI, prefix, localName ); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultGreaterThanEqualExpr.java0000664000175000017500000000522510533623667025706 0ustar ebourgebourg/* * $Header$ * $Revision: 1261 $ * $Date: 2006-11-30 19:49:27 +0100 (Thu, 30 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultGreaterThanEqualExpr.java 1261 2006-11-30 18:49:27Z elharo $ */ package org.jaxen.expr; class DefaultGreaterThanEqualExpr extends DefaultRelationalExpr { /** * */ private static final long serialVersionUID = -7848747981787197470L; DefaultGreaterThanEqualExpr( Expr lhs, Expr rhs ) { super( lhs, rhs ); } public String getOperator() { return ">="; } protected boolean evaluateDoubleDouble( Double lhs, Double rhs ) { return lhs.compareTo( rhs ) >= 0; } } jaxen-1.1.6/src/java/main/org/jaxen/expr/ProcessingInstructionNodeStep.java0000664000175000017500000000506110524375541026357 0ustar ebourgebourg/* * $Header$ * $Revision: 1226 $ * $Date: 2006-11-08 16:44:33 +0100 (Wed, 08 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: ProcessingInstructionNodeStep.java 1226 2006-11-08 15:44:33Z elharo $ */ package org.jaxen.expr; /** * Represents the XPath node-test processing-instruction(). * */ public interface ProcessingInstructionNodeStep extends Step { /** * Returns the target matched by this processing instruction node-step. * * @return the target of the processing instruction */ public String getName(); } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultGreaterThanExpr.java0000664000175000017500000000522512074523431024704 0ustar ebourgebourg/* * $Header$ * $Revision: 1396 $ * $Date: 2013-01-13 13:22:49 +0100 (Sun, 13 Jan 2013) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultGreaterThanExpr.java 1396 2013-01-13 12:22:49Z elharo $ */ package org.jaxen.expr; class DefaultGreaterThanExpr extends DefaultRelationalExpr { /** * */ private static final long serialVersionUID = 6379252220540222867L; DefaultGreaterThanExpr( Expr lhs, Expr rhs ) { super( lhs, rhs ); } public String getOperator() { return ">"; } protected boolean evaluateDoubleDouble( Double lhs, Double rhs ) { return lhs.doubleValue() > rhs.doubleValue(); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultNumberExpr.java0000664000175000017500000000553710533623667023750 0ustar ebourgebourg/* * $Header$ * $Revision: 1261 $ * $Date: 2006-11-30 19:49:27 +0100 (Thu, 30 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultNumberExpr.java 1261 2006-11-30 18:49:27Z elharo $ */ package org.jaxen.expr; import org.jaxen.Context; class DefaultNumberExpr extends DefaultExpr implements NumberExpr { /** * */ private static final long serialVersionUID = -6021898973386269611L; private Double number; DefaultNumberExpr( Double number ) { this.number = number; } public Number getNumber() { return this.number; } public String toString() { return "[(DefaultNumberExpr): " + getNumber() + "]"; } public String getText() { return getNumber().toString(); } public Object evaluate( Context context ) { return getNumber(); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultPathExpr.java0000664000175000017500000001106610533623667023406 0ustar ebourgebourg/* * $Header$ * $Revision: 1261 $ * $Date: 2006-11-30 19:49:27 +0100 (Thu, 30 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultPathExpr.java 1261 2006-11-30 18:49:27Z elharo $ */ package org.jaxen.expr; import org.jaxen.Context; import org.jaxen.JaxenException; class DefaultPathExpr extends DefaultExpr implements PathExpr { private static final long serialVersionUID = -6593934674727004281L; private Expr filterExpr; private LocationPath locationPath; DefaultPathExpr(Expr filterExpr, LocationPath locationPath) { this.filterExpr = filterExpr; this.locationPath = locationPath; } public Expr getFilterExpr() { return this.filterExpr; } public void setFilterExpr(Expr filterExpr) { this.filterExpr = filterExpr; } public LocationPath getLocationPath() { return this.locationPath; } public String toString() { if (getLocationPath() != null) { return "[(DefaultPathExpr): " + getFilterExpr() + ", " + getLocationPath() + "]"; } return "[(DefaultPathExpr): " + getFilterExpr() + "]"; } public String getText() { StringBuffer buf = new StringBuffer(); if (getFilterExpr() != null) { buf.append(getFilterExpr().getText()); } if (getLocationPath() != null) { if (!getLocationPath().getSteps().isEmpty()) buf.append("/"); buf.append(getLocationPath().getText()); } return buf.toString(); } public Expr simplify() { if (getFilterExpr() != null) { setFilterExpr(getFilterExpr().simplify()); } if (getLocationPath() != null) { getLocationPath().simplify(); } if (getFilterExpr() == null && getLocationPath() == null) { return null; } if (getLocationPath() == null) { return getFilterExpr(); } if (getFilterExpr() == null) { return getLocationPath(); } return this; } public Object evaluate(Context context) throws JaxenException { Object results = null; Context pathContext = null; if (getFilterExpr() != null) { results = getFilterExpr().evaluate(context); pathContext = new Context(context.getContextSupport()); pathContext.setNodeSet(convertToList(results)); } if (getLocationPath() != null) { return getLocationPath().evaluate(pathContext); } return results; } } jaxen-1.1.6/src/java/main/org/jaxen/expr/CommentNodeStep.java0000664000175000017500000000451410524375357023412 0ustar ebourgebourg/* * $Header$ * $Revision: 1225 $ * $Date: 2006-11-08 16:42:39 +0100 (Wed, 08 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: CommentNodeStep.java 1225 2006-11-08 15:42:39Z elharo $ */ package org.jaxen.expr; /** * Represents the XPath node-test comment(). * */ public interface CommentNodeStep extends Step { } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultTextNodeStep.java0000664000175000017500000000600310533623667024234 0ustar ebourgebourg/* * $Header$ * $Revision: 1261 $ * $Date: 2006-11-30 19:49:27 +0100 (Thu, 30 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultTextNodeStep.java 1261 2006-11-30 18:49:27Z elharo $ */ package org.jaxen.expr; import org.jaxen.ContextSupport; import org.jaxen.Navigator; import org.jaxen.expr.iter.IterableAxis; /** * @deprecated this class will become non-public in the future; * use the interface instead */ public class DefaultTextNodeStep extends DefaultStep implements TextNodeStep { /** * */ private static final long serialVersionUID = -3821960984972022948L; public DefaultTextNodeStep(IterableAxis axis, PredicateSet predicateSet ) { super( axis, predicateSet ); } public boolean matches(Object node, ContextSupport support) { Navigator nav = support.getNavigator(); return nav.isText( node ); } public String getText() { return getAxisName() + "::text()" + super.getText(); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/Predicated.java0000664000175000017500000000553710524416335022410 0ustar ebourgebourg/* * $Header$ * $Revision: 1241 $ * $Date: 2006-11-08 19:07:25 +0100 (Wed, 08 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: Predicated.java 1241 2006-11-08 18:07:25Z elharo $ */ package org.jaxen.expr; import java.io.Serializable; import java.util.List; /** * Interface for objects which can have one or more predicates. * */ public interface Predicated extends Serializable { /** * Add an additional predicate to this object. * * @param predicate the predicate to add */ void addPredicate(Predicate predicate); /** * Returns a possibly empty list of predicates. * * @return the list of predicates */ List getPredicates(); /** * Returns a possibly empty set of predicates. * * @return the set of predicates */ PredicateSet getPredicateSet(); } jaxen-1.1.6/src/java/main/org/jaxen/expr/PathExpr.java0000664000175000017500000000623410616117742022074 0ustar ebourgebourg/* * $Header$ * $Revision: 1300 $ * $Date: 2007-05-02 16:27:46 +0200 (Wed, 02 May 2007) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: PathExpr.java 1300 2007-05-02 14:27:46Z elharo $ */ package org.jaxen.expr; /** * Represents an XPath path expression. * This is production 19 in the * XPath 1.0 specification: * *
[19] PathExpr ::= LocationPath    
 *                | FilterExpr    
 *                | FilterExpr '/' RelativeLocationPath   
 *                | FilterExpr '//' RelativeLocationPath  
* */ public interface PathExpr extends Expr { /** * Returns the filter expression that starts the path expression. * * @return the filter expression that starts the path expression */ Expr getFilterExpr(); /** * Changes the expression's filter expression. * * @param filterExpr the new filter expression */ void setFilterExpr(Expr filterExpr); /** * Returns the location path part of this path expression. * * @return the location path part of this expression */ LocationPath getLocationPath(); } jaxen-1.1.6/src/java/main/org/jaxen/expr/MultiplicativeExpr.java0000664000175000017500000000704211004756371024170 0ustar ebourgebourg/* * $Header$ * $Revision: 1325 $ * $Date: 2008-04-27 03:55:05 +0200 (Sun, 27 Apr 2008) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: MultiplicativeExpr.java 1325 2008-04-27 01:55:05Z elharo $ */ package org.jaxen.expr; /** * Represents an XPath multiplicative expression. This is * production 26 in the * XPath 1.0 specification: * * * * * * * * * * * * * *
[26]   MultiplicativeExpr   ::=   UnaryExpr
| MultiplicativeExpr MultiplyOperator UnaryExpr
| MultiplicativeExpr 'div' UnaryExpr
| MultiplicativeExpr 'mod' UnaryExpr
* */ public interface MultiplicativeExpr extends BinaryExpr { } jaxen-1.1.6/src/java/main/org/jaxen/expr/XPathExpr.java0000664000175000017500000000711110616124216022211 0ustar ebourgebourg/* * $Header$ * $Revision: 1306 $ * $Date: 2007-05-02 17:04:46 +0200 (Wed, 02 May 2007) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: XPathExpr.java 1306 2007-05-02 15:04:46Z elharo $ */ package org.jaxen.expr; import java.io.Serializable; import java.util.List; import org.jaxen.Context; import org.jaxen.JaxenException; /** * A wrapper around an XPath expression. * */ public interface XPathExpr extends Serializable { /** * Returns the wrapped expression object. * * @return the wrapped Expr object */ Expr getRootExpr(); /** * Changes the wrapped expression object. * * @param rootExpr the new expression object to wrap */ void setRootExpr(Expr rootExpr); /** * Returns a String containing the XPath expression. * * @return the text form of this XPath expression */ String getText(); /** * Simplifies the XPath expression. For example, the expression * //para[1 = 1] could be simplified to * //para. In practice, this is usually a noop. * Jaxen does not currently perform any simplification. */ void simplify(); /** * Evaluates the expression and returns a list cintaing the resulting nodes, * or a singleton list containing a Double, String, * or Boolean. * * @param context the context in which to evaluate this expression * @return a list * @throws JaxenException */ List asList(Context context) throws JaxenException; } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultOrExpr.java0000664000175000017500000000666010533623667023076 0ustar ebourgebourg/* * $Header$ * $Revision: 1261 $ * $Date: 2006-11-30 19:49:27 +0100 (Thu, 30 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultOrExpr.java 1261 2006-11-30 18:49:27Z elharo $ */ package org.jaxen.expr; import org.jaxen.Context; import org.jaxen.JaxenException; import org.jaxen.Navigator; import org.jaxen.function.BooleanFunction; class DefaultOrExpr extends DefaultLogicalExpr { /** * */ private static final long serialVersionUID = 4894552680753026730L; DefaultOrExpr(Expr lhs, Expr rhs) { super( lhs, rhs ); } public String getOperator() { return "or"; } public String toString() { return "[(DefaultOrExpr): " + getLHS() + ", " + getRHS() + "]"; } public Object evaluate(Context context) throws JaxenException { Navigator nav = context.getNavigator(); Boolean lhsValue = BooleanFunction.evaluate( getLHS().evaluate( context ), nav ); if ( lhsValue.booleanValue() ) { return Boolean.TRUE; } // Short circuits are required in XPath. "The right operand is not // evaluated if the left operand evaluates to true." Boolean rhsValue = BooleanFunction.evaluate( getRHS().evaluate( context ), nav ); if ( rhsValue.booleanValue() ) { return Boolean.TRUE; } return Boolean.FALSE; } } jaxen-1.1.6/src/java/main/org/jaxen/expr/RelationalExpr.java0000664000175000017500000000724510524652561023276 0ustar ebourgebourg/* * $Header$ * $Revision: 1252 $ * $Date: 2006-11-09 17:21:05 +0100 (Thu, 09 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: RelationalExpr.java 1252 2006-11-09 16:21:05Z elharo $ */ package org.jaxen.expr; /** * Represents an XPath relational expression such as * count(//p) > count(//div). * This is production 24 in the * XPath 1.0 specification: * * * * * * * * * * * * v *
[24]   RelationalExpr   ::=   AdditiveExpr
| RelationalExpr '<' AdditiveExpr
| RelationalExpr '>' AdditiveExpr
| RelationalExpr '<=' AdditiveExpr
| RelationalExpr '>=' AdditiveExpr
* */ public interface RelationalExpr extends BinaryExpr { } jaxen-1.1.6/src/java/main/org/jaxen/expr/Predicate.java0000664000175000017500000001005110616117742022231 0ustar ebourgebourg/* * $Header$ * $Revision: 1300 $ * $Date: 2007-05-02 16:27:46 +0200 (Wed, 02 May 2007) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: Predicate.java 1300 2007-05-02 14:27:46Z elharo $ */ package org.jaxen.expr; import java.io.Serializable; import org.jaxen.Context; import org.jaxen.JaxenException; /** * Represents an XPath predicate such as [position() = last()]. * This is production 8 and 9 in the * XPath 1.0 specification: * *
 [8] Predicate     ::= '[' PredicateExpr ']'   
 * [9] PredicateExpr ::= Expr
* */ public interface Predicate extends Serializable { /** * Returns the expression in this predicate. * * @return the expression between the brackets */ Expr getExpr(); /** * Change the expression used by this predicate. * * @param expr the new expression */ void setExpr(Expr expr); /** * Simplify the expression in this predicate. * * @see Expr#simplify() */ void simplify(); /** * Returns the string form of the predicate, * including the square brackets. * * @return the bracketed form of this predicate */ String getText(); /** * Evaluates this predicate's expression and returns the result. * The result will be a java.lang.Double for expressions that * return a number, a java.lang.String for expressions that * return a string, a java.lang.Boolean for expressions that * return a boolean, and a java.util.List for expressions that * return a node-set. In the latter case, the elements of the list are * the actual objects from the source document model. Copies are not made. * * @param context the context in which the expression is evaluated * @return an object representing the result of the evaluation * @throws JaxenException * @see Expr#evaluate(Context) */ Object evaluate(Context context) throws JaxenException; } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultCommentNodeStep.java0000664000175000017500000000616410533623667024722 0ustar ebourgebourg/* * $Header$ * $Revision: 1261 $ * $Date: 2006-11-30 19:49:27 +0100 (Thu, 30 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultCommentNodeStep.java 1261 2006-11-30 18:49:27Z elharo $ */ package org.jaxen.expr; import org.jaxen.ContextSupport; import org.jaxen.Navigator; import org.jaxen.expr.iter.IterableAxis; /** * @deprecated this class will become non-public in the future; * use the interface instead */ public class DefaultCommentNodeStep extends DefaultStep implements CommentNodeStep { /** * */ private static final long serialVersionUID = 4340788283861875606L; public DefaultCommentNodeStep(IterableAxis axis, PredicateSet predicateSet) { super( axis, predicateSet ); } public String toString() { return "[(DefaultCommentNodeStep): " + getAxis() + "]"; } public String getText() { return getAxisName() + "::comment()"; } public boolean matches(Object node, ContextSupport contextSupport) { Navigator nav = contextSupport.getNavigator(); return nav.isComment( node ); } } jaxen-1.1.6/src/java/main/org/jaxen/expr/DefaultNameStep.java0000664000175000017500000003374010611021113023341 0ustar ebourgebourg/* $Id: DefaultNameStep.java 1290 2007-04-17 01:26:35Z bewins $ Copyright 2003 The Werken Company. All Rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Jaxen Project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.jaxen.expr; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; import org.jaxen.Context; import org.jaxen.ContextSupport; import org.jaxen.JaxenException; import org.jaxen.UnresolvableException; import org.jaxen.Navigator; import org.jaxen.expr.iter.IterableAxis; import org.jaxen.saxpath.Axis; /** * Expression object that represents any flavor * of name-test steps within an XPath. *

* This includes simple steps, such as "foo", * non-default-axis steps, such as "following-sibling::foo" * or "@foo", and namespace-aware steps, such * as "foo:bar". * * @author bob mcwhirter (bob@werken.com) * @author Stephen Colebourne * @deprecated this class will become non-public in the future; * use the interface instead */ public class DefaultNameStep extends DefaultStep implements NameStep { /** * */ private static final long serialVersionUID = 428414912247718390L; /** * Our prefix, bound through the current Context. * The empty-string ("") if no prefix was specified. * Decidedly NOT-NULL, due to SAXPath constraints. * This is the 'foo' in 'foo:bar'. */ private String prefix; /** * Our local-name. * This is the 'bar' in 'foo:bar'. */ private String localName; /** Quick flag denoting if the local name was '*' */ private boolean matchesAnyName; /** Quick flag denoting if we have a namespace prefix **/ private boolean hasPrefix; /** * Constructor. * * @param axis the axis to work through * @param prefix the name prefix * @param localName the local name * @param predicateSet the set of predicates */ public DefaultNameStep(IterableAxis axis, String prefix, String localName, PredicateSet predicateSet) { super(axis, predicateSet); this.prefix = prefix; this.localName = localName; this.matchesAnyName = "*".equals(localName); this.hasPrefix = (this.prefix != null && this.prefix.length() > 0); } /** * Gets the namespace prefix. * * @return the prefix */ public String getPrefix() { return this.prefix; } /** * Gets the local name. * * @return the local name */ public String getLocalName() { return this.localName; } /** * Does this step match any name? (i.e. Is it '*'?) * * @return true if it matches any name */ public boolean isMatchesAnyName() { return matchesAnyName; } /** * Gets the step as a fully defined XPath. * * @return the full XPath for this step */ public String getText() { StringBuffer buf = new StringBuffer(64); buf.append(getAxisName()).append("::"); if (getPrefix() != null && getPrefix().length() > 0) { buf.append(getPrefix()).append(':'); } return buf.append(getLocalName()).append(super.getText()).toString(); } /** * Evaluate the context node set to find the new node set. *

* This method overrides the version in DefaultStep for performance. */ public List evaluate(Context context) throws JaxenException { List contextNodeSet = context.getNodeSet(); int contextSize = contextNodeSet.size(); // optimize for context size 0 if (contextSize == 0) { return Collections.EMPTY_LIST; } ContextSupport support = context.getContextSupport(); IterableAxis iterableAxis = getIterableAxis(); boolean namedAccess = (!matchesAnyName && iterableAxis.supportsNamedAccess(support)); // optimize for context size 1 (common case, avoids lots of object creation) if (contextSize == 1) { Object contextNode = contextNodeSet.get(0); if (namedAccess) { // get the iterator over the nodes and check it String uri = null; if (hasPrefix) { uri = support.translateNamespacePrefixToUri(prefix); if (uri == null) { throw new UnresolvableException("XPath expression uses unbound namespace prefix " + prefix); } } Iterator axisNodeIter = iterableAxis.namedAccessIterator( contextNode, support, localName, prefix, uri); if (axisNodeIter == null || !axisNodeIter.hasNext()) { return Collections.EMPTY_LIST; } // convert iterator to list for predicate test // no need to filter as named access guarantees this List newNodeSet = new ArrayList(); while (axisNodeIter.hasNext()) { newNodeSet.add(axisNodeIter.next()); } // evaluate the predicates return getPredicateSet().evaluatePredicates(newNodeSet, support); } else { // get the iterator over the nodes and check it Iterator axisNodeIter = iterableAxis.iterator(contextNode, support); if (axisNodeIter == null || !axisNodeIter.hasNext()) { return Collections.EMPTY_LIST; } // run through iterator, filtering using matches() // adding to list for predicate test List newNodeSet = new ArrayList(contextSize); while (axisNodeIter.hasNext()) { Object eachAxisNode = axisNodeIter.next(); if (matches(eachAxisNode, support)) { newNodeSet.add(eachAxisNode); } } // evaluate the predicates return getPredicateSet().evaluatePredicates(newNodeSet, support); } } // full case IdentitySet unique = new IdentitySet(); List interimSet = new ArrayList(contextSize); List newNodeSet = new ArrayList(contextSize); if (namedAccess) { String uri = null; if (hasPrefix) { uri = support.translateNamespacePrefixToUri(prefix); if (uri == null) { throw new UnresolvableException("XPath expression uses unbound namespace prefix " + prefix); } } for (int i = 0; i < contextSize; ++i) { Object eachContextNode = contextNodeSet.get(i); Iterator axisNodeIter = iterableAxis.namedAccessIterator( eachContextNode, support, localName, prefix, uri); if (axisNodeIter == null || !axisNodeIter.hasNext()) { continue; } while (axisNodeIter.hasNext()) { Object eachAxisNode = axisNodeIter.next(); interimSet.add(eachAxisNode); } // evaluate the predicates List predicateNodes = getPredicateSet().evaluatePredicates(interimSet, support); // ensure only one of each node in the result Iterator predicateNodeIter = predicateNodes.iterator(); while (predicateNodeIter.hasNext()) { Object eachPredicateNode = predicateNodeIter.next(); if (! unique.contains(eachPredicateNode)) { unique.add(eachPredicateNode); newNodeSet.add(eachPredicateNode); } } interimSet.clear(); } } else { for (int i = 0; i < contextSize; ++i) { Object eachContextNode = contextNodeSet.get(i); Iterator axisNodeIter = axisIterator(eachContextNode, support); if (axisNodeIter == null || !axisNodeIter.hasNext()) { continue; } /* See jaxen-106. Might be able to optimize this by doing * specific matching for individual axes. For instance on namespace axis * we should only get namespace nodes and on attribute axes we only get * attribute nodes. Self and parent axes have single members. * Children, descendant, ancestor, and sibling axes never * see any attributes or namespaces */ // ensure only unique matching nodes in the result while (axisNodeIter.hasNext()) { Object eachAxisNode = axisNodeIter.next(); if (matches(eachAxisNode, support)) { interimSet.add(eachAxisNode); } } // evaluate the predicates List predicateNodes = getPredicateSet().evaluatePredicates(interimSet, support); // ensure only one of each node in the result Iterator predicateNodeIter = predicateNodes.iterator(); while (predicateNodeIter.hasNext()) { Object eachPredicateNode = predicateNodeIter.next(); if (! unique.contains(eachPredicateNode)) { unique.add(eachPredicateNode); newNodeSet.add(eachPredicateNode); } } interimSet.clear(); } } return newNodeSet; } /** * Checks whether the node matches this step. * * @param node the node to check * @param contextSupport the context support * @return true if matches * @throws JaxenException */ public boolean matches(Object node, ContextSupport contextSupport) throws JaxenException { Navigator nav = contextSupport.getNavigator(); String myUri = null; String nodeName = null; String nodeUri = null; if (nav.isElement(node)) { nodeName = nav.getElementName(node); nodeUri = nav.getElementNamespaceUri(node); } else if (nav.isText(node)) { return false; } else if (nav.isAttribute(node)) { if (getAxis() != Axis.ATTRIBUTE) { return false; } nodeName = nav.getAttributeName(node); nodeUri = nav.getAttributeNamespaceUri(node); } else if (nav.isDocument(node)) { return false; } else if (nav.isNamespace(node)) { if (getAxis() != Axis.NAMESPACE) { // Only works for namespace::* return false; } nodeName = nav.getNamespacePrefix(node); } else { return false; } if (hasPrefix) { myUri = contextSupport.translateNamespacePrefixToUri(this.prefix); if (myUri == null) { throw new UnresolvableException("Cannot resolve namespace prefix '"+this.prefix+"'"); } } else if (matchesAnyName) { return true; } // If we map to a non-empty namespace and the node does not // or vice-versa, fail-fast. if (hasNamespace(myUri) != hasNamespace(nodeUri)) { return false; } // To fail-fast, we check the equality of // local-names first. Shorter strings compare // quicker. if (matchesAnyName || nodeName.equals(getLocalName())) { return matchesNamespaceURIs(myUri, nodeUri); } return false; } /** * Checks whether the URI represents a namespace. * * @param uri the URI to check * @return true if non-null and non-empty */ private boolean hasNamespace(String uri) { return (uri != null && uri.length() > 0); } /** * Compares two namespace URIs, handling null. * * @param uri1 the first URI * @param uri2 the second URI * @return true if equal, where null=="" */ protected boolean matchesNamespaceURIs(String uri1, String uri2) { if (uri1 == uri2) { return true; } if (uri1 == null) { return (uri2.length() == 0); } if (uri2 == null) { return (uri1.length() == 0); } return uri1.equals(uri2); } /** * Returns a full information debugging string. * * @return a debugging string */ public String toString() { String prefix = getPrefix(); String qName = "".equals(prefix) ? getLocalName() : getPrefix() + ":" + getLocalName(); return "[(DefaultNameStep): " + qName + "]"; } } jaxen-1.1.6/src/java/main/org/jaxen/expr/package.html0000664000175000017500000000026607327350513021756 0ustar ebourgebourg org.jaxen.expr.*

Interfaces and default implementations for XPath expression components.

jaxen-1.1.6/src/java/main/org/jaxen/expr/NodeComparator.java0000664000175000017500000001334411751262036023254 0ustar ebourgebourg/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * Copyright 2005 Elliotte Rusty Harold. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id$ */ package org.jaxen.expr; import java.util.Comparator; import java.util.Iterator; import org.jaxen.Navigator; import org.jaxen.UnsupportedAxisException; class NodeComparator implements Comparator { private Navigator navigator; NodeComparator(Navigator navigator) { this.navigator = navigator; } public int compare(Object o1, Object o2) { if (o1 == o2) return 0; // treat all objects as equal if (navigator == null) return 0; if (isNonChild(o1) && isNonChild(o2)) { try { Object p1 = navigator.getParentNode(o1); Object p2 = navigator.getParentNode(o2); if (p1 == p2) { if (navigator.isNamespace(o1) && navigator.isAttribute(o2)) { return -1; } else if (navigator.isNamespace(o2) && navigator.isAttribute(o1)) { return 1; } else if (navigator.isNamespace(o1)) { String prefix1 = navigator.getNamespacePrefix(o1); String prefix2 = navigator.getNamespacePrefix(o2); return prefix1.compareTo(prefix2); } else if (navigator.isAttribute(o1)) { String name1 = navigator.getAttributeQName(o1); String name2 = navigator.getAttributeQName(o2); return name1.compareTo(name2); } } return compare(p1, p2); } catch (UnsupportedAxisException ex) { return 0; } } try { int depth1 = getDepth(o1); int depth2 = getDepth(o2); Object a1 = o1; Object a2 = o2; while (depth1 > depth2) { a1 = navigator.getParentNode(a1); depth1--; } if (a1 == o2) return 1; while (depth2 > depth1) { a2 = navigator.getParentNode(a2); depth2--; } if (a2 == o1) return -1; // a1 and a2 are now at same depth; and are not the same while (true) { Object p1 = navigator.getParentNode(a1); Object p2 = navigator.getParentNode(a2); if (p1 == p2) { return compareSiblings(a1, a2); } a1 = p1; a2 = p2; } } catch (UnsupportedAxisException ex) { return 0; // ???? should I throw an exception instead? } } private boolean isNonChild(Object o) { return navigator.isAttribute(o) || navigator.isNamespace(o); } private int compareSiblings(Object sib1, Object sib2) throws UnsupportedAxisException { // attributes and namespaces sort before child nodes if (isNonChild(sib1)) { return 1; } else if (isNonChild(sib2)) { return -1; } Iterator following = navigator.getFollowingSiblingAxisIterator(sib1); while (following.hasNext()) { Object next = following.next(); if (next.equals(sib2)) return -1; } return 1; } private int getDepth(Object o) throws UnsupportedAxisException { int depth = 0; Object parent = o; while ((parent = navigator.getParentNode(parent)) != null) { depth++; } return depth; } } jaxen-1.1.6/src/java/main/org/jaxen/.cvsignore0000664000175000017500000000000710415575201020503 0ustar ebourgebourgpantry jaxen-1.1.6/src/java/main/org/jaxen/ContextSupport.java0000664000175000017500000001674510440366011022402 0ustar ebourgebourgpackage org.jaxen; /* $Id: ContextSupport.java 1157 2006-06-03 20:07:37Z elharo $ Copyright 2003 The Werken Company. All Rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Jaxen Project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ import java.io.Serializable; /** Supporting context information for resolving * namespace prefixes, functions, and variables. * *

* NOTE: This class is not typically used directly, * but is exposed for writers of implementation-specific * XPath packages. *

* * @see org.jaxen.dom4j.Dom4jXPath XPath for dom4j * @see org.jaxen.jdom.JDOMXPath XPath for JDOM * @see org.jaxen.dom.DOMXPath XPath for W3C DOM * * @author bob mcwhirter * * @version $Id: ContextSupport.java 1157 2006-06-03 20:07:37Z elharo $ */ public class ContextSupport implements Serializable { /** * */ private static final long serialVersionUID = 4494082174713652559L; /** Function context. */ private transient FunctionContext functionContext; /** Namespace context. */ private NamespaceContext namespaceContext; /** Variable context. */ private VariableContext variableContext; /** Model navigator. */ private Navigator navigator; // ---------------------------------------------------------------------- // Constructors // ---------------------------------------------------------------------- /** Construct an empty ContextSupport. */ public ContextSupport() { // intentionally left blank } /** Create a new ContextSupport object. * * @param namespaceContext the NamespaceContext * @param functionContext the FunctionContext * @param variableContext the VariableContext * @param navigator the model navigator */ public ContextSupport(NamespaceContext namespaceContext, FunctionContext functionContext, VariableContext variableContext, Navigator navigator) { setNamespaceContext( namespaceContext ); setFunctionContext( functionContext ); setVariableContext( variableContext ); this.navigator = navigator; } // ---------------------------------------------------------------------- // Instance methods // ---------------------------------------------------------------------- /** Set the NamespaceContext. * * @param namespaceContext the namespace context */ public void setNamespaceContext(NamespaceContext namespaceContext) { this.namespaceContext = namespaceContext; } /** Retrieve the NamespaceContext. * * @return the namespace context */ public NamespaceContext getNamespaceContext() { return this.namespaceContext; } /** Set the FunctionContext. * * @param functionContext the function context */ public void setFunctionContext(FunctionContext functionContext) { this.functionContext = functionContext; } /** Retrieve the FunctionContext. * * @return the function context */ public FunctionContext getFunctionContext() { return this.functionContext; } /** Set the VariableContext. * * @param variableContext the variable context */ public void setVariableContext(VariableContext variableContext) { this.variableContext = variableContext; } /** Retrieve the VariableContext. * * @return the variable context */ public VariableContext getVariableContext() { return this.variableContext; } /** Retrieve the Navigator. * * @return the navigator */ public Navigator getNavigator() { return this.navigator; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /** Translate a namespace prefix to its URI. * * @param prefix The prefix * * @return the namespace URI mapped to the prefix */ public String translateNamespacePrefixToUri(String prefix) { if ("xml".equals(prefix)) { return "http://www.w3.org/XML/1998/namespace"; } NamespaceContext context = getNamespaceContext(); if ( context != null ) { return context.translateNamespacePrefixToUri( prefix ); } return null; } /** Retrieve a variable value. * * @param namespaceURI the function namespace URI * @param prefix the function prefix * @param localName the function name * * @return the variable value. * * @throws UnresolvableException if unable to locate a bound variable. */ public Object getVariableValue( String namespaceURI, String prefix, String localName ) throws UnresolvableException { VariableContext context = getVariableContext(); if ( context != null ) { return context.getVariableValue( namespaceURI, prefix, localName ); } else { throw new UnresolvableException( "No variable context installed" ); } } /** Retrieve a Function. * * @param namespaceURI the function namespace URI * @param prefix the function prefix * @param localName the function name * * @return the function object * * @throws UnresolvableException if unable to locate a bound function */ public Function getFunction( String namespaceURI, String prefix, String localName ) throws UnresolvableException { FunctionContext context = getFunctionContext(); if ( context != null ) { return context.getFunction( namespaceURI, prefix, localName ); } else { throw new UnresolvableException( "No function context installed" ); } } } jaxen-1.1.6/src/java/main/org/jaxen/XPathFunctionContext.java0000664000175000017500000002440710524361312023454 0ustar ebourgebourg/* * $Header$ * $Revision: 1222 $ * $Date: 2006-11-08 14:59:38 +0100 (Wed, 08 Nov 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: XPathFunctionContext.java 1222 2006-11-08 13:59:38Z elharo $ */ package org.jaxen; import org.jaxen.function.BooleanFunction; import org.jaxen.function.CeilingFunction; import org.jaxen.function.ConcatFunction; import org.jaxen.function.ContainsFunction; import org.jaxen.function.CountFunction; import org.jaxen.function.FalseFunction; import org.jaxen.function.FloorFunction; import org.jaxen.function.IdFunction; import org.jaxen.function.LangFunction; import org.jaxen.function.LastFunction; import org.jaxen.function.LocalNameFunction; import org.jaxen.function.NameFunction; import org.jaxen.function.NamespaceUriFunction; import org.jaxen.function.NormalizeSpaceFunction; import org.jaxen.function.NotFunction; import org.jaxen.function.NumberFunction; import org.jaxen.function.PositionFunction; import org.jaxen.function.RoundFunction; import org.jaxen.function.StartsWithFunction; import org.jaxen.function.StringFunction; import org.jaxen.function.StringLengthFunction; import org.jaxen.function.SubstringAfterFunction; import org.jaxen.function.SubstringBeforeFunction; import org.jaxen.function.SubstringFunction; import org.jaxen.function.SumFunction; import org.jaxen.function.TranslateFunction; import org.jaxen.function.TrueFunction; import org.jaxen.function.ext.EndsWithFunction; import org.jaxen.function.ext.EvaluateFunction; import org.jaxen.function.ext.LowerFunction; import org.jaxen.function.ext.UpperFunction; import org.jaxen.function.xslt.DocumentFunction; /** A FunctionContext implementing the core XPath * function library, plus Jaxen extensions. * *

* The core XPath function library is provided through this * implementation of FunctionContext. Additionally, * extension functions have been provided, as enumerated below. *

* *

* This class is re-entrant and thread-safe. If using the * default instance, it is inadvisable to call * {@link #registerFunction(String, String, Function)} * as that will extend the global function context, affecting other * users. *

* *

* Extension functions: *

* *
    *
  • evaluate(..)
  • *
  • upper-case(..)
  • *
  • lower-case(..)
  • *
  • ends-with(..)
  • *
* * @see FunctionContext * @see org.jaxen.function * @see org.jaxen.function.xslt * @see org.jaxen.function.ext * * @author bob mcwhirter */ public class XPathFunctionContext extends SimpleFunctionContext { private static XPathFunctionContext instance = new XPathFunctionContext(); /** Retrieve the default function context * * @return the default function context */ public static FunctionContext getInstance() { return instance; } /** Create a new XPath function context. * All core XPath and Jaxen extension functions are registered. */ public XPathFunctionContext() { this(true); } /** Create a new XPath function context. * All core XPath functions are registered. * * @param includeExtensionFunctions if true extension functions are included; * if false, they aren't */ public XPathFunctionContext(boolean includeExtensionFunctions) { registerXPathFunctions(); if (includeExtensionFunctions) { registerXSLTFunctions(); registerExtensionFunctions(); } } private void registerXPathFunctions() { registerFunction( null, // namespace URI "boolean", new BooleanFunction() ); registerFunction( null, // namespace URI "ceiling", new CeilingFunction() ); registerFunction( null, // namespace URI "concat", new ConcatFunction() ); registerFunction( null, // namespace URI "contains", new ContainsFunction() ); registerFunction( null, // namespace URI "count", new CountFunction() ); registerFunction( null, // namespace URI "false", new FalseFunction() ); registerFunction( null, // namespace URI "floor", new FloorFunction() ); registerFunction( null, // namespace URI "id", new IdFunction() ); registerFunction( null, // namespace URI "lang", new LangFunction() ); registerFunction( null, // namespace URI "last", new LastFunction() ); registerFunction( null, // namespace URI "local-name", new LocalNameFunction() ); registerFunction( null, // namespace URI "name", new NameFunction() ); registerFunction( null, // namespace URI "namespace-uri", new NamespaceUriFunction() ); registerFunction( null, // namespace URI "normalize-space", new NormalizeSpaceFunction() ); registerFunction( null, // namespace URI "not", new NotFunction() ); registerFunction( null, // namespace URI "number", new NumberFunction() ); registerFunction( null, // namespace URI "position", new PositionFunction() ); registerFunction( null, // namespace URI "round", new RoundFunction() ); registerFunction( null, // namespace URI "starts-with", new StartsWithFunction() ); registerFunction( null, // namespace URI "string", new StringFunction() ); registerFunction( null, // namespace URI "string-length", new StringLengthFunction() ); registerFunction( null, // namespace URI "substring-after", new SubstringAfterFunction() ); registerFunction( null, // namespace URI "substring-before", new SubstringBeforeFunction() ); registerFunction( null, // namespace URI "substring", new SubstringFunction() ); registerFunction( null, // namespace URI "sum", new SumFunction() ); registerFunction( null, // namespace URI "true", new TrueFunction() ); registerFunction( null, // namespace URI "translate", new TranslateFunction() ); } private void registerXSLTFunctions() { // extension functions defined in XSLT registerFunction( null, // namespace URI "document", new DocumentFunction() ); } private void registerExtensionFunctions() { // extension functions should go into a namespace, but which one? // for now, keep them in default namespace to not break any code registerFunction( null, // namespace URI "evaluate", new EvaluateFunction() ); registerFunction( null, // namespace URI "lower-case", new LowerFunction() ); registerFunction( null, // namespace URI "upper-case", new UpperFunction() ); registerFunction( null, // namespace URI "ends-with", new EndsWithFunction() ); } } jaxen-1.1.6/src/java/main/org/jaxen/XPath.java0000664000175000017500000003471010616123575020410 0ustar ebourgebourgpackage org.jaxen; /* $Id: XPath.java 1304 2007-05-02 15:00:13Z elharo $ Copyright 2003 The Werken Company. All Rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Jaxen Project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ import java.util.List; /** Represents an XPath 1.0 expression which * can be evaluated against a variety of different XML object models. * *

* Most of the evaluation methods take a context object. This is typically a * node or node-set object (which is typically a List * of node objects) or a Jaxen Context object. * A null context is allowed, meaning that * there are no XML nodes on which to evaluate. *

* * @see org.jaxen.dom4j.Dom4jXPath XPath for dom4j * @see org.jaxen.jdom.JDOMXPath XPath for JDOM * @see org.jaxen.dom.DOMXPath XPath for W3C DOM * * @author bob mcwhirter * @author James Strachan */ public interface XPath { // ---------------------------------------------------------------------- // Basic Evaluation // ---------------------------------------------------------------------- /** Evaluate this XPath against the given context. * *

* The context of evaluation my be a document, * an element, or a set of elements. *

* *

* If the expression evaluates to an XPath string, number, or boolean * type, then the equivalent Java object type is returned. * Otherwise, if the result is a node-set, then the returned value is a * List. *

* *

* When using this method, one must be careful to * test the class of the returned objects, and of * each of the composite members if a List * is returned. If the returned members are XML nodes, * they will be the actual Document, * Element or Attribute objects * as defined by the concrete XML object-model implementation, * directly from the context document. This method does not * return copies of anything. It merely returns * references to nodes within the source document. *

* * @param context the node, node-set or Context object for evaluation. * This value can be null. * * @return the result of evaluating the XPath expression * against the supplied context * * @throws JaxenException if an error occurs while attempting * to evaluate the expression */ Object evaluate(Object context) throws JaxenException; // ---------------------------------------------------------------------- // Advanced Evaluation // ---------------------------------------------------------------------- /** Retrieve a string-value interpretation of this XPath * expression when evaluated against the given context. * *

* The string-value of the expression is determined per * the string(..) core function as defined * in the XPath specification. This means that an expression * that selects more than one nodes will return the string value * of the first node in the node set.. *

* * @deprecated use {@link #stringValueOf(Object)} instead * * @param context the node, node-set or Context object for evaluation. * This value can be null. * * @return the string-value of this expression * * @throws JaxenException if an error occurs while attempting * to evaluate the expression */ String valueOf(Object context) throws JaxenException; /** Retrieve a string-value interpretation of this XPath * expression when evaluated against the given context. * *

* The string-value of the expression is determined per * the string(..) core function as defined * in the XPath specification. This means that an expression * that selects more than one nodes will return the string value * of the first node in the node set.. *

* * @param context the node, node-set or Context object for evaluation. * This value can be null * * @return the string-value interpretation of this expression * * @throws JaxenException if an error occurs while attempting * to evaluate the expression */ String stringValueOf(Object context) throws JaxenException; /** Retrieve the boolean value of the first node in document order * returned by this XPath expression when evaluated in * the given context. * *

* The boolean-value of the expression is determined per * the boolean() function defined * in the XPath specification. This means that an expression * that selects zero nodes will return false, * while an expression that selects one or more nodes will * return true. An expression that returns a string * returns false for empty strings and true for all other strings. * An expression that returns a number * returns false for zero and true for non-zero numbers. *

* * @param context the node, node-set or Context object for evaluation. This value can be null. * * @return the boolean-value of this expression * * @throws JaxenException if an error occurs while attempting * to evaluate the expression */ boolean booleanValueOf(Object context) throws JaxenException; /** Retrieve the number-value of the first node in document order * returned by this XPath expression when evaluated in * the given context. * *

* The number-value of the expression is determined per * the number(..) core function as defined * in the XPath specification. This means that if this * expression selects multiple nodes, the number-value * of the first node is returned. *

* * @param context the node, node-set or Context object for evaluation. This value can be null. * * @return the number-value interpretation of this expression * * @throws JaxenException if an error occurs while attempting * to evaluate the expression */ Number numberValueOf(Object context) throws JaxenException; // ---------------------------------------------------------------------- // Selection // ---------------------------------------------------------------------- /** Select all nodes that are selectable by this XPath * expression. If multiple nodes match, multiple nodes * will be returned. * *

* NOTE: In most cases, nodes will be returned * in document-order, as defined by the XML Canonicalization * specification. The exception occurs when using XPath * expressions involving the union operator * (denoted with the pipe '|' character). *

* * @see #selectSingleNode * * @param context the node, node-set or Context object for evaluation. * This value can be null. * * @return the node-set of all items selected * by this XPath expression. * * @throws JaxenException if an error occurs while attempting * to evaluate the expression */ List selectNodes(Object context) throws JaxenException; /** *

* Return the first node in document order that is selected by this * XPath expression. *

* * @see #selectNodes * * @param context the node, node-set or Context object for evaluation. * This value can be null. * * @return the first node in document order selected by this XPath expression * * @throws JaxenException if an error occurs while attempting * to evaluate the expression */ Object selectSingleNode(Object context) throws JaxenException; // ---------------------------------------------------------------------- // Helpers // ---------------------------------------------------------------------- /** Add a namespace prefix-to-URI mapping for this XPath * expression. * *

* Namespace prefix-to-URI mappings in an XPath are independent * of those used within any document. Only the mapping explicitly * added to this XPath will be available for resolving the * XPath expression. *

* *

* This is a convenience method for adding mappings to the * default {@link NamespaceContext} in place for this XPath. * If you have installed a specific custom NamespaceContext, * then this method will throw a JaxenException. *

* * @param prefix the namespace prefix * @param uri the namespace URI * * @throws JaxenException if a NamespaceContext * used by this XPath has been explicitly installed */ void addNamespace(String prefix, String uri) throws JaxenException; // ---------------------------------------------------------------------- // Properties // ---------------------------------------------------------------------- /** Set a NamespaceContext for this * XPath expression. * *

* A NamespaceContext is responsible for translating * namespace prefixes within the expression into namespace URIs. *

* * @see NamespaceContext * @see NamespaceContext#translateNamespacePrefixToUri * * @param namespaceContext the NamespaceContext to * install for this expression */ void setNamespaceContext(NamespaceContext namespaceContext); /** Set a FunctionContext for this XPath * expression. * *

* A FunctionContext is responsible for resolving * all function calls used within the expression. *

* * @see FunctionContext * @see FunctionContext#getFunction * * @param functionContext the FunctionContext to * install for this expression */ void setFunctionContext(FunctionContext functionContext); /** Set a VariableContext for this XPath * expression. * *

* A VariableContext is responsible for resolving * all variables referenced within the expression. *

* * @see VariableContext * @see VariableContext#getVariableValue * * @param variableContext the VariableContext to * install for this expression. */ void setVariableContext(VariableContext variableContext); /** Retrieve the NamespaceContext used by this XPath * expression. * *

* A FunctionContext is responsible for resolving * all function calls used within the expression. *

* *

* If this XPath expression has not previously had a NamespaceContext * installed, a new default NamespaceContext will be created, * installed and returned. *

* * @see NamespaceContext * * @return the NamespaceContext used by this expression */ NamespaceContext getNamespaceContext(); /** Retrieve the FunctionContext used by this XPath * expression. * *

* A FunctionContext is responsible for resolving * all function calls used within the expression. *

* *

* If this XPath expression has not previously had a FunctionContext * installed, a new default FunctionContext will be created, * installed and returned. *

* * @see FunctionContext * * @return the FunctionContext used by this expression */ FunctionContext getFunctionContext(); /** Retrieve the VariableContext used by this XPath * expression. * *

* A VariableContext is responsible for resolving * all variables referenced within the expression. *

* *

* If this XPath expression has not previously had a VariableContext * installed, a new default VariableContext will be created, * installed and returned. *

* * @see VariableContext * * @return the VariableContext used by this expression */ VariableContext getVariableContext(); /** Retrieve the XML object-model-specific {@link Navigator} * used to evaluate this XPath expression. * * @return the implementation-specific Navigator */ Navigator getNavigator(); } jaxen-1.1.6/src/java/main/org/jaxen/BaseXPath.java0000664000175000017500000005761311004744416021205 0ustar ebourgebourg/* * $Header$ * $Revision: 1321 $ * $Date: 2008-04-27 02:30:06 +0200 (Sun, 27 Apr 2008) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: BaseXPath.java 1321 2008-04-27 00:30:06Z elharo $ */ package org.jaxen; import java.io.Serializable; import java.util.List; import org.jaxen.expr.Expr; import org.jaxen.expr.XPathExpr; import org.jaxen.function.BooleanFunction; import org.jaxen.function.NumberFunction; import org.jaxen.function.StringFunction; import org.jaxen.saxpath.SAXPathException; import org.jaxen.saxpath.XPathReader; import org.jaxen.saxpath.helpers.XPathReaderFactory; import org.jaxen.util.SingletonList; /** Base functionality for all concrete, implementation-specific XPaths. * *

* This class provides generic functionality for further-defined * implementation-specific XPaths. *

* *

* If you want to adapt the Jaxen engine so that it can traverse your own * object model, then this is a good base class to derive from. * Typically you only really need to provide your own * {@link org.jaxen.Navigator} implementation. *

* * @see org.jaxen.dom4j.Dom4jXPath XPath for dom4j * @see org.jaxen.jdom.JDOMXPath XPath for JDOM * @see org.jaxen.dom.DOMXPath XPath for W3C DOM * * @author bob mcwhirter * @author James Strachan */ public class BaseXPath implements XPath, Serializable { private static final long serialVersionUID = -1993731281300293168L; /** Original expression text. */ private final String exprText; /** the parsed form of the XPath expression */ private final XPathExpr xpath; /** the support information and function, namespace and variable contexts */ private ContextSupport support; /** the implementation-specific Navigator for retrieving XML nodes **/ private Navigator navigator; /** Construct given an XPath expression string. * * @param xpathExpr the XPath expression * * @throws JaxenException if there is a syntax error while * parsing the expression */ protected BaseXPath(String xpathExpr) throws JaxenException { try { XPathReader reader = XPathReaderFactory.createReader(); JaxenHandler handler = new JaxenHandler(); reader.setXPathHandler( handler ); reader.parse( xpathExpr ); this.xpath = handler.getXPathExpr(); } catch (org.jaxen.saxpath.XPathSyntaxException e) { throw new org.jaxen.XPathSyntaxException( e ); } catch (SAXPathException e) { throw new JaxenException( e ); } this.exprText = xpathExpr; } /** Construct given an XPath expression string. * * @param xpathExpr the XPath expression * * @param navigator the XML navigator to use * * @throws JaxenException if there is a syntax error while * parsing the expression */ public BaseXPath(String xpathExpr, Navigator navigator) throws JaxenException { this( xpathExpr ); this.navigator = navigator; } /** Evaluate this XPath against a given context. * The context of evaluation may be any object type * the navigator recognizes as a node. * The return value is either a String, * Double, Boolean, or List * of nodes. * *

* When using this method, one must be careful to * test the class of the returned object. If the returned * object is a list, then the items in this * list will be the actual Document, * Element, Attribute, etc. objects * as defined by the concrete XML object-model implementation, * directly from the context document. This method does * not return copies of anything, but merely * returns references to objects within the source document. *

* * @param context the node, node-set or Context object for evaluation. * This value can be null. * * @return the result of evaluating the XPath expression * against the supplied context * @throws JaxenException if an XPath error occurs during expression evaluation * @throws ClassCastException if the context is not a node */ public Object evaluate(Object context) throws JaxenException { List answer = selectNodes(context); if ( answer != null && answer.size() == 1 ) { Object first = answer.get(0); if ( first instanceof String || first instanceof Number || first instanceof Boolean ) { return first; } } return answer; } /** Select all nodes that are selected by this XPath * expression. If multiple nodes match, multiple nodes * will be returned. Nodes will be returned * in document-order, as defined by the XPath * specification. If the expression selects a non-node-set * (i.e. a number, boolean, or string) then a List * containing just that one object is returned. *

* * @param node the node, node-set or Context object for evaluation. * This value can be null. * * @return the node-set of all items selected * by this XPath expression * @throws JaxenException if an XPath error occurs during expression evaluation * * @see #selectNodesForContext */ public List selectNodes(Object node) throws JaxenException { Context context = getContext( node ); return selectNodesForContext( context ); } /** Select only the first node selected by this XPath * expression. If multiple nodes match, only one node will be * returned. The selected node will be the first * selected node in document-order, as defined by the XPath * specification. *

* * @param node the node, node-set or Context object for evaluation. * This value can be null. * * @return the node-set of all items selected * by this XPath expression * @throws JaxenException if an XPath error occurs during expression evaluation * * @see #selectNodes */ public Object selectSingleNode(Object node) throws JaxenException { List results = selectNodes( node ); if ( results.isEmpty() ) { return null; } return results.get( 0 ); } /** * Returns the XPath string-value of the argument node. * * @param node the node whose value to take * @return the XPath string value of this node * @throws JaxenException if an XPath error occurs during expression evaluation * @deprecated replaced by {@link #stringValueOf} */ public String valueOf(Object node) throws JaxenException { return stringValueOf( node ); } /** Retrieves the string-value of the result of * evaluating this XPath expression when evaluated * against the specified context. * *

* The string-value of the expression is determined per * the string(..) core function defined * in the XPath specification. This means that an expression * that selects zero nodes will return the empty string, * while an expression that selects one-or-more nodes will * return the string-value of the first node. *

* * @param node the node, node-set or Context object for evaluation. This value can be null. * * @return the string-value of the result of evaluating this expression with the specified context node * @throws JaxenException if an XPath error occurs during expression evaluation */ public String stringValueOf(Object node) throws JaxenException { Context context = getContext( node ); Object result = selectSingleNodeForContext( context ); if ( result == null ) { return ""; } return StringFunction.evaluate( result, context.getNavigator() ); } /** Retrieve a boolean-value interpretation of this XPath * expression when evaluated against a given context. * *

* The boolean-value of the expression is determined per * the boolean(..) function defined * in the XPath specification. This means that an expression * that selects zero nodes will return false, * while an expression that selects one or more nodes will * return true. *

* * @param node the node, node-set or Context object for evaluation. This value can be null. * * @return the boolean-value of the result of evaluating this expression with the specified context node * @throws JaxenException if an XPath error occurs during expression evaluation */ public boolean booleanValueOf(Object node) throws JaxenException { Context context = getContext( node ); List result = selectNodesForContext( context ); if ( result == null ) return false; return BooleanFunction.evaluate( result, context.getNavigator() ).booleanValue(); } /** Retrieve a number-value interpretation of this XPath * expression when evaluated against a given context. * *

* The number-value of the expression is determined per * the number(..) core function as defined * in the XPath specification. This means that if this * expression selects multiple nodes, the number-value * of the first node is returned. *

* * @param node the node, node-set or Context object for evaluation. This value can be null. * * @return a Double indicating the numeric value of * evaluating this expression against the specified context * @throws JaxenException if an XPath error occurs during expression evaluation */ public Number numberValueOf(Object node) throws JaxenException { Context context = getContext( node ); Object result = selectSingleNodeForContext( context ); return NumberFunction.evaluate( result, context.getNavigator() ); } // Helpers /** Add a namespace prefix-to-URI mapping for this XPath * expression. * *

* Namespace prefix-to-URI mappings in an XPath are independent * of those used within any document. Only the mapping explicitly * added to this XPath will be available for resolving the * XPath expression. *

* *

* This is a convenience method for adding mappings to the * default {@link NamespaceContext} in place for this XPath. * If you have installed a custom NamespaceContext * that is not a SimpleNamespaceContext, * then this method will throw a JaxenException. *

* * @param prefix the namespace prefix * @param uri the namespace URI * * @throws JaxenException if the NamespaceContext * used by this XPath is not a SimpleNamespaceContext */ public void addNamespace(String prefix, String uri) throws JaxenException { NamespaceContext nsContext = getNamespaceContext(); if ( nsContext instanceof SimpleNamespaceContext ) { ((SimpleNamespaceContext)nsContext).addNamespace( prefix, uri ); return; } throw new JaxenException("Operation not permitted while using a non-simple namespace context."); } // ------------------------------------------------------------ // ------------------------------------------------------------ // Properties // ------------------------------------------------------------ // ------------------------------------------------------------ /** Set a NamespaceContext for use with this * XPath expression. * *

* A NamespaceContext is responsible for translating * namespace prefixes within the expression into namespace URIs. *

* * @param namespaceContext the NamespaceContext to * install for this expression * * @see NamespaceContext * @see NamespaceContext#translateNamespacePrefixToUri */ public void setNamespaceContext(NamespaceContext namespaceContext) { getContextSupport().setNamespaceContext(namespaceContext); } /** Set a FunctionContext for use with this XPath * expression. * *

* A FunctionContext is responsible for resolving * all function calls used within the expression. *

* * @param functionContext the FunctionContext to * install for this expression * * @see FunctionContext * @see FunctionContext#getFunction */ public void setFunctionContext(FunctionContext functionContext) { getContextSupport().setFunctionContext(functionContext); } /** Set a VariableContext for use with this XPath * expression. * *

* A VariableContext is responsible for resolving * all variables referenced within the expression. *

* * @param variableContext The VariableContext to * install for this expression * * @see VariableContext * @see VariableContext#getVariableValue */ public void setVariableContext(VariableContext variableContext) { getContextSupport().setVariableContext(variableContext); } /** Retrieve the NamespaceContext used by this XPath * expression. * *

* A NamespaceContext is responsible for mapping * prefixes used within the expression to namespace URIs. *

* *

* If this XPath expression has not previously had a NamespaceContext * installed, a new default NamespaceContext will be created, * installed and returned. *

* * @return the NamespaceContext used by this expression * * @see NamespaceContext */ public NamespaceContext getNamespaceContext() { return getContextSupport().getNamespaceContext(); } /** Retrieve the FunctionContext used by this XPath * expression. * *

* A FunctionContext is responsible for resolving * all function calls used within the expression. *

* *

* If this XPath expression has not previously had a FunctionContext * installed, a new default FunctionContext will be created, * installed and returned. *

* * @return the FunctionContext used by this expression * * @see FunctionContext */ public FunctionContext getFunctionContext() { return getContextSupport().getFunctionContext(); } /** Retrieve the VariableContext used by this XPath * expression. * *

* A VariableContext is responsible for resolving * all variables referenced within the expression. *

* *

* If this XPath expression has not previously had a VariableContext * installed, a new default VariableContext will be created, * installed and returned. *

* * @return the VariableContext used by this expression * * @see VariableContext */ public VariableContext getVariableContext() { return getContextSupport().getVariableContext(); } /** Retrieve the root expression of the internal * compiled form of this XPath expression. * *

* Internally, Jaxen maintains a form of Abstract Syntax * Tree (AST) to represent the structure of the XPath expression. * This is normally not required during normal consumer-grade * usage of Jaxen. This method is provided for hard-core users * who wish to manipulate or inspect a tree-based version of * the expression. *

* * @return the root of the AST of this expression */ public Expr getRootExpr() { return xpath.getRootExpr(); } /** Return the original expression text. * * @return the normalized XPath expression string */ public String toString() { return this.exprText; } /** Returns a string representation of the parse tree. * * @return a string representation of the parse tree. */ public String debug() { return this.xpath.toString(); } // ------------------------------------------------------------ // ------------------------------------------------------------ // Implementation methods // ------------------------------------------------------------ // ------------------------------------------------------------ /** Create a {@link Context} wrapper for the provided * implementation-specific object. * * @param node the implementation-specific object * to be used as the context * * @return a Context wrapper around the object */ protected Context getContext(Object node) { if ( node instanceof Context ) { return (Context) node; } Context fullContext = new Context( getContextSupport() ); if ( node instanceof List ) { fullContext.setNodeSet( (List) node ); } else { List list = new SingletonList(node); fullContext.setNodeSet( list ); } return fullContext; } /** Retrieve the {@link ContextSupport} aggregation of * NamespaceContext, FunctionContext, * VariableContext, and {@link Navigator}. * * @return aggregate ContextSupport for this * XPath expression */ protected ContextSupport getContextSupport() { if ( support == null ) { support = new ContextSupport( createNamespaceContext(), createFunctionContext(), createVariableContext(), getNavigator() ); } return support; } /** Retrieve the XML object-model-specific {@link Navigator} * for us in evaluating this XPath expression. * * @return the implementation-specific Navigator */ public Navigator getNavigator() { return navigator; } // ------------------------------------------------------------ // ------------------------------------------------------------ // Factory methods for default contexts // ------------------------------------------------------------ // ------------------------------------------------------------ /** Create a default FunctionContext. * * @return a default FunctionContext */ protected FunctionContext createFunctionContext() { return XPathFunctionContext.getInstance(); } /** Create a default NamespaceContext. * * @return a default NamespaceContext instance */ protected NamespaceContext createNamespaceContext() { return new SimpleNamespaceContext(); } /** Create a default VariableContext. * * @return a default VariableContext instance */ protected VariableContext createVariableContext() { return new SimpleVariableContext(); } /** Select all nodes that match this XPath * expression on the given Context object. * If multiple nodes match, multiple nodes * will be returned in document-order, as defined by the XPath * specification. If the expression selects a non-node-set * (i.e. a number, boolean, or string) then a List * containing just that one object is returned. *

* * @param context the Context which gets evaluated * * @return the node-set of all items selected * by this XPath expression * @throws JaxenException if an XPath error occurs during expression evaluation * */ protected List selectNodesForContext(Context context) throws JaxenException { List list = this.xpath.asList( context ); return list; } /** Return only the first node that is selected by this XPath * expression. If multiple nodes match, only one node will be * returned. The selected node will be the first * selected node in document-order, as defined by the XPath * specification. If the XPath expression selects a double, * String, or boolean, then that object is returned. *

* * @param context the Context against which this expression is evaluated * * @return the first node in document order of all nodes selected * by this XPath expression * @throws JaxenException if an XPath error occurs during expression evaluation * * @see #selectNodesForContext */ protected Object selectSingleNodeForContext(Context context) throws JaxenException { List results = selectNodesForContext( context ); if ( results.isEmpty() ) { return null; } return results.get( 0 ); } } jaxen-1.1.6/src/java/main/org/jaxen/dom/0000775000175000017500000000000012174247550017274 5ustar ebourgebourgjaxen-1.1.6/src/java/main/org/jaxen/dom/DOMXPath.java0000664000175000017500000000660510440373212021517 0ustar ebourgebourg/* * $Header$ * $Revision: 1162 $ * $Date: 2006-06-03 22:52:26 +0200 (Sat, 03 Jun 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DOMXPath.java 1162 2006-06-03 20:52:26Z elharo $ */ // XPath.java - top-level entry point for DOM XPath matching. package org.jaxen.dom; import org.jaxen.BaseXPath; import org.jaxen.JaxenException; /** An XPath implementation for the W3C DOM. * *

This is the main entry point for matching an XPath against a DOM * tree. You create a compiled XPath object, then match it against * one or more context nodes using the {@link #selectNodes(Object)} * method, as in the following example:

* *
 XPath path = new DOMXPath("a/b/c");
 * List results = path.selectNodes(domNode);
* * @see BaseXPath * * @author James Strachan * @author bob mcwhirter * * @version $Revision: 1162 $ */ public class DOMXPath extends BaseXPath { /** * */ private static final long serialVersionUID = 5551221776001439091L; /** Create a new DOMXPath from an XPath expression string. * * @param xpathExpr the XPath expression * * @throws JaxenException if there is a syntax error in the expression */ public DOMXPath(String xpathExpr) throws JaxenException { super( xpathExpr, DocumentNavigator.getInstance() ); } } jaxen-1.1.6/src/java/main/org/jaxen/dom/DocumentNavigator.java0000664000175000017500000010331111614751405023564 0ustar ebourgebourgpackage org.jaxen.dom; /* * $Header$ * $Revision: 1364 $ * $Date: 2011-07-30 11:46:45 +0200 (Sat, 30 Jul 2011) $ * * ==================================================================== * * Copyright 2000-2005 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DocumentNavigator.java 1364 2011-07-30 09:46:45Z elharo $ */ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.util.HashMap; import java.util.Iterator; import java.util.NoSuchElementException; import org.jaxen.DefaultNavigator; import org.jaxen.FunctionCallException; import org.jaxen.Navigator; import org.jaxen.XPath; import org.jaxen.JaxenConstants; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.w3c.dom.ProcessingInstruction; import org.xml.sax.SAXException; /** Interface for navigating around the W3C DOM Level 2 object model. * *

* This class is not intended for direct usage, but is * used by the Jaxen engine during evaluation. *

* *

This class implements the {@link org.jaxen.DefaultNavigator} interface * for the Jaxen XPath library. This adapter allows the Jaxen * library to be used to execute XPath queries against any object tree * that implements the DOM level 2 interfaces.

* *

Note: DOM level 2 does not include a node representing an XPath * namespace node. This navigator will return namespace nodes * as instances of the custom {@link NamespaceNode} class, and * users will have to check result sets to locate and isolate * these.

* * @author David Megginson * @author James Strachan * * @see XPath * @see NamespaceNode */ public class DocumentNavigator extends DefaultNavigator { //////////////////////////////////////////////////////////////////// // Constants. //////////////////////////////////////////////////////////////////// /** * */ private static final long serialVersionUID = 8460943068889528115L; private final static DocumentNavigator SINGLETON = new DocumentNavigator(); //////////////////////////////////////////////////////////////////// // Constructor. //////////////////////////////////////////////////////////////////// /** * Default constructor. */ public DocumentNavigator () { } /** * Get a constant DocumentNavigator for efficiency. * * @return a constant instance of a DocumentNavigator. */ public static Navigator getInstance () { return SINGLETON; } //////////////////////////////////////////////////////////////////// // Implementation of org.jaxen.DefaultNavigator. //////////////////////////////////////////////////////////////////// /** * Get an iterator over all of this node's children. * * @param contextNode the context node for the child axis. * @return a possibly-empty iterator (not null) */ public Iterator getChildAxisIterator (Object contextNode) { Node node = (Node) contextNode; if ( node.getNodeType() == Node.ELEMENT_NODE || node.getNodeType() == Node.DOCUMENT_NODE) { return new NodeIterator ((Node)contextNode) { protected Node getFirstNode (Node node) { return node.getFirstChild(); } protected Node getNextNode (Node node) { return node.getNextSibling(); } }; } return JaxenConstants.EMPTY_ITERATOR; } /** * Get a (single-member) iterator over this node's parent. * * @param contextNode the context node for the parent axis * @return a possibly-empty iterator (not null) */ public Iterator getParentAxisIterator (Object contextNode) { Node node = (Node)contextNode; if (node.getNodeType() == Node.ATTRIBUTE_NODE) { return new NodeIterator (node) { protected Node getFirstNode (Node n) { // We can assume castability here because we've already // tested the node type. return ((Attr)n).getOwnerElement(); } protected Node getNextNode (Node n) { return null; } }; } else { return new NodeIterator (node) { protected Node getFirstNode (Node n) { return n.getParentNode(); } protected Node getNextNode (Node n) { return null; } }; } } /** * Return the XPath parent of the supplied DOM node. * XPath has slightly different definition of parent than DOM does. * In particular, the parent of an attribute is not null. * * @param child the child node * * @return the parent of the specified node; or null if * the node does not have a parent */ public Object getParentNode(Object child) { Node node = (Node) child; if (node.getNodeType() == Node.ATTRIBUTE_NODE) { return ((Attr) node).getOwnerElement(); } return node.getParentNode(); } /** * Get an iterator over all following siblings. * * @param contextNode the context node for the sibling iterator * @return a possibly-empty iterator (not null) */ public Iterator getFollowingSiblingAxisIterator (Object contextNode) { return new NodeIterator ((Node)contextNode) { protected Node getFirstNode (Node node) { return getNextNode(node); } protected Node getNextNode (Node node) { return node.getNextSibling(); } }; } /** * Get an iterator over all preceding siblings. * * @param contextNode the context node for the preceding sibling axis * @return a possibly-empty iterator (not null) */ public Iterator getPrecedingSiblingAxisIterator (Object contextNode) { return new NodeIterator ((Node)contextNode) { protected Node getFirstNode (Node node) { return getNextNode(node); } protected Node getNextNode (Node node) { return node.getPreviousSibling(); } }; } /** * Get an iterator over all following nodes, depth-first. * * @param contextNode the context node for the following axis * @return a possibly-empty iterator (not null) */ public Iterator getFollowingAxisIterator (Object contextNode) { return new NodeIterator ((Node)contextNode) { protected Node getFirstNode (Node node) { if (node == null) { return null; } else { Node sibling = node.getNextSibling(); if (sibling == null) { return getFirstNode(node.getParentNode()); } else { return sibling; } } } protected Node getNextNode (Node node) { if (node == null) { return null; } else { Node n = node.getFirstChild(); if (n == null) n = node.getNextSibling(); if (n == null) return getFirstNode(node.getParentNode()); else return n; } } }; } /** * Get an iterator over all attributes. * * @param contextNode the context node for the attribute axis * @return a possibly-empty iterator (not null) */ public Iterator getAttributeAxisIterator (Object contextNode) { if (isElement(contextNode)) { return new AttributeIterator((Node)contextNode); } else { return JaxenConstants.EMPTY_ITERATOR; } } /** * Get an iterator over all declared namespaces. * *

Note: this iterator is not live: it takes a snapshot * and that snapshot remains static during the life of * the iterator (i.e. it won't reflect subsequent changes * to the DOM).

* *

* In the event that the DOM is inconsistent; for instance a * pre:foo element is declared by DOM to be in the * http://www.a.com/ namespace but also has an * xmlns:pre="http://www.b.com" attribute; then only * one of the namespaces will be counted. This will be the intrinsic * namespace of the Element or Attr object * rather than the one provide by the contradictory namespace * declaration attribute. In the event of a contradiction between two * attributes on the same element--e.g. pre:foo in the * http://www.a.com/ namespace and pre:bar in the * http://www.b.com/ namespace--it is undefined which namespace * will be returned. *

* * @param contextNode the context node for the namespace axis * @return a possibly-empty iterator (not null) */ public Iterator getNamespaceAxisIterator (Object contextNode) { // Only elements have namespace nodes if (isElement(contextNode)) { HashMap nsMap = new HashMap(); // Starting at the current node, walk // up to the root, noting the namespace // declarations in scope. for (Node n = (Node) contextNode; n != null; n = n.getParentNode()) { // 1. Look for the namespace of the element itself String myNamespace = n.getNamespaceURI(); if (myNamespace != null && ! "".equals(myNamespace)) { String myPrefix = n.getPrefix(); if (!nsMap.containsKey(myPrefix)) { NamespaceNode ns = new NamespaceNode((Node) contextNode, myPrefix, myNamespace); nsMap.put(myPrefix, ns); } } if (n.hasAttributes()) { NamedNodeMap atts = n.getAttributes(); int length = atts.getLength(); // 2. Look for namespaces of attributes for (int i = 0; i < length; i++) { Attr att = (Attr) atts.item(i); // Work around Crimson bug by testing URI rather than name String attributeNamespace = att.getNamespaceURI(); if ("http://www.w3.org/2000/xmlns/".equals(attributeNamespace)) { } else if (attributeNamespace != null) { String prefix = att.getPrefix(); NamespaceNode ns = new NamespaceNode((Node)contextNode, prefix, attributeNamespace); // Add only if there's not a closer declaration in force. if (!nsMap.containsKey(prefix)) nsMap.put(prefix, ns); } } // 3. Look for namespace declaration attributes for (int i = 0; i < length; i++) { Attr att = (Attr) atts.item(i); // work around crimson bug by testing URI rather than name String attributeNamespace = att.getNamespaceURI(); if ("http://www.w3.org/2000/xmlns/".equals(attributeNamespace)) { NamespaceNode ns = new NamespaceNode( (Node)contextNode, att); // Add only if there's not a closer declaration in force. String name = ns.getNodeName(); if (!nsMap.containsKey(name)) nsMap.put(name, ns); } } } } // Section 5.4 of the XPath rec requires // this to be present. nsMap.put("xml", new NamespaceNode((Node)contextNode, "xml", "http://www.w3.org/XML/1998/namespace")); // An empty default namespace cancels // any previous default. NamespaceNode defaultNS = (NamespaceNode)nsMap.get(""); if (defaultNS != null && defaultNS.getNodeValue().length() == 0) { nsMap.remove(""); } return nsMap.values().iterator(); } else { return JaxenConstants.EMPTY_ITERATOR; } } /** Returns a parsed form of the given XPath string, which will be suitable * for queries on DOM documents. * * @param xpath the XPath expression * @return a parsed form of the given XPath string * @throws org.jaxen.saxpath.SAXPathException if the string is syntactically incorrect */ public XPath parseXPath (String xpath) throws org.jaxen.saxpath.SAXPathException { return new DOMXPath(xpath); } /** * Get the top-level document node. * * @param contextNode any node in the document * @return the root node */ public Object getDocumentNode (Object contextNode) { if (isDocument(contextNode)) return contextNode; else return ((Node)contextNode).getOwnerDocument(); } // Why are there separate methods for getElementNamespaceURI and // getAttributeNamespaceURI when they do exactly the same thing? // This should be combined in a future version. /** * Get the namespace URI of an element. * * @param element the target node * @return a string (possibly empty) if the node is an element, * and null otherwise */ public String getElementNamespaceUri (Object element) { try { Node node = (Node) element; if (node.getNodeType() == Node.ELEMENT_NODE) { return node.getNamespaceURI(); } } catch (ClassCastException ex) { } return null; } /** * Get the local name of an element. * * @param element the target node * @return a string representing the unqualified local name * if the node is an element, or null otherwise */ public String getElementName (Object element) { if (isElement(element)) { String name = ((Node)element).getLocalName(); if (name == null) name = ((Node)element).getNodeName(); return name; } return null; } /** * Get the qualified name of an element. * * @param element the target node * @return a string representing the qualified (i.e. possibly * prefixed) name if the argument is an element, or null otherwise */ public String getElementQName (Object element) { try { Node node = (Node) element; if (node.getNodeType() == Node.ELEMENT_NODE) { return node.getNodeName(); } } catch (ClassCastException ex) { } return null; } /** * Get the namespace URI of an attribute. * * @param attribute the target node * * @return the namespace name of the specified node * */ public String getAttributeNamespaceUri (Object attribute) { try { Node node = (Node) attribute; if (node.getNodeType() == Node.ATTRIBUTE_NODE) { return node.getNamespaceURI(); } } catch (ClassCastException ex) { } return null; } /** * Get the local name of an attribute. * * @param attribute the target node * @return a string representing the unqualified local name * if the node is an attribute, or null otherwise */ public String getAttributeName (Object attribute) { if (isAttribute(attribute)) { String name = ((Node)attribute).getLocalName(); if (name == null) name = ((Node)attribute).getNodeName(); return name; } return null; } /** * Get the qualified name of an attribute. * * @param attribute the target node * * @return a string representing the qualified (i.e. possibly * prefixed) name if the argument is an attribute, or null otherwise */ public String getAttributeQName (Object attribute) { try { Node node = (Node) attribute; if (node.getNodeType() == Node.ATTRIBUTE_NODE) { return node.getNodeName(); } } catch (ClassCastException ex) { } return null; } /** * Test if a node is a top-level document. * * @param object the target node * @return true if the node is the document root, false otherwise */ public boolean isDocument (Object object) { return (object instanceof Node) && (((Node)object).getNodeType() == Node.DOCUMENT_NODE); } /** * Test if a node is a namespace. * * @param object the target node * @return true if the node is a namespace, false otherwise */ public boolean isNamespace (Object object) { return (object instanceof NamespaceNode); } /** * Test if a node is an element. * * @param object the target node * @return true if the node is an element, false otherwise */ public boolean isElement (Object object) { return (object instanceof Node) && (((Node)object).getNodeType() == Node.ELEMENT_NODE); } /** * Test if a node is an attribute. xmlns and * xmlns:pre attributes do not count as attributes * for the purposes of XPath. * * @param object the target node * @return true if the node is an attribute, false otherwise */ public boolean isAttribute (Object object) { return (object instanceof Node) && (((Node)object).getNodeType() == Node.ATTRIBUTE_NODE) && ! "http://www.w3.org/2000/xmlns/".equals(((Node) object).getNamespaceURI()); } /** * Test if a node is a comment. * * @param object the target node * @return true if the node is a comment, false otherwise */ public boolean isComment (Object object) { return (object instanceof Node) && (((Node)object).getNodeType() == Node.COMMENT_NODE); } /** * Test if a node is plain text. * * @param object the target node * @return true if the node is a text node, false otherwise */ public boolean isText (Object object) { if (object instanceof Node) { switch (((Node)object).getNodeType()) { case Node.TEXT_NODE: case Node.CDATA_SECTION_NODE: return true; default: return false; } } else { return false; } } /** * Test if a node is a processing instruction. * * @param object the target node * @return true if the node is a processing instruction, false otherwise */ public boolean isProcessingInstruction (Object object) { return (object instanceof Node) && (((Node)object).getNodeType() == Node.PROCESSING_INSTRUCTION_NODE); } /** * Get the string value of an element node. * * @param object the target node * @return the text inside the node and its descendants if the node * is an element, null otherwise */ public String getElementStringValue (Object object) { if (isElement(object)) { return getStringValue((Node)object, new StringBuffer()).toString(); } else { return null; } } /** * Construct a node's string value recursively. * * @param node the current node * @param buffer the buffer for building the text * @return the buffer passed as a parameter (for convenience) */ private StringBuffer getStringValue (Node node, StringBuffer buffer) { if (isText(node)) { buffer.append(node.getNodeValue()); } else { NodeList children = node.getChildNodes(); int length = children.getLength(); for (int i = 0; i < length; i++) { getStringValue(children.item(i), buffer); } } return buffer; } /** * Get the string value of an attribute node. * * @param object the target node * @return the text of the attribute value if the node is an * attribute, null otherwise */ public String getAttributeStringValue (Object object) { if (isAttribute(object)) return ((Node)object).getNodeValue(); else return null; } /** * Get the string value of text. * * @param object the target node * @return the string of text if the node is text, null otherwise */ public String getTextStringValue (Object object) { if (isText(object)) return ((Node)object).getNodeValue(); else return null; } /** * Get the string value of a comment node. * * @param object the target node * @return the text of the comment if the node is a comment, null otherwise */ public String getCommentStringValue (Object object) { if (isComment(object)) return ((Node)object).getNodeValue(); else return null; } /** * Get the string value of a namespace node. * * @param object the target node * @return the namespace URI as a (possibly empty) string if the * node is a namespace node, null otherwise */ public String getNamespaceStringValue (Object object) { if (isNamespace(object)) return ((NamespaceNode)object).getNodeValue(); else return null; } /** * Get the prefix value of a namespace node. * * @param object the target node * @return the namespace prefix a (possibly empty) string if the * node is a namespace node, null otherwise */ public String getNamespacePrefix (Object object) { if (isNamespace(object)) return ((NamespaceNode)object).getLocalName(); else return null; } /** * Translate a namespace prefix to a URI. * * @param prefix the namespace prefix * @param element the namespace context * @return the namespace URI bound to the prefix in the scope of element; * null if the prefix is not bound */ public String translateNamespacePrefixToUri (String prefix, Object element) { Iterator it = getNamespaceAxisIterator(element); while (it.hasNext()) { NamespaceNode ns = (NamespaceNode)it.next(); if (prefix.equals(ns.getNodeName())) return ns.getNodeValue(); } return null; } /** * Use JAXP to load a namespace aware document from a given URI. * * @param uri the URI of the document to load * @return the new W3C DOM Level 2 Document instance * @throws FunctionCallException containing a nested exception * if a problem occurs trying to parse the given document * * @todo Possibly we could make the factory a thread local. */ public Object getDocument(String uri) throws FunctionCallException { try { // We really do need to construct a new factory here each time. // DocumentBuilderFactory is not guaranteed to be thread safe? DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse( uri ); } catch (ParserConfigurationException e) { throw new FunctionCallException("JAXP setup error in document() function: " + e.getMessage(), e); } catch (SAXException e) { throw new FunctionCallException("XML error in document() function: " + e.getMessage(), e); } catch (IOException e) { throw new FunctionCallException("I/O error in document() function: " + e.getMessage(), e); } } /** * Get the target of a processing instruction node. * * @param obj the processing instruction * @return the target of the processing instruction * @throws ClassCastException if obj is not a processing instruction * */ public String getProcessingInstructionTarget(Object obj) { if (isProcessingInstruction(obj)) { ProcessingInstruction pi = (ProcessingInstruction) obj; return pi.getTarget(); } throw new ClassCastException(obj + " is not a processing instruction"); } /** * Get the data of a processing instruction node. * * @param obj the processing instruction * @return the target of the processing instruction * @throws ClassCastException if obj is not a processing instruction * */ public String getProcessingInstructionData(Object obj) { if (isProcessingInstruction(obj)) { ProcessingInstruction pi = (ProcessingInstruction) obj; return pi.getData(); } throw new ClassCastException(obj + " is not a processing instruction"); } //////////////////////////////////////////////////////////////////// // Inner class: iterate over DOM nodes. //////////////////////////////////////////////////////////////////// // FIXME: needs to recurse into // DocumentFragment and EntityReference // to use their children. /** * A generic iterator over DOM nodes. * *

Concrete subclasses must implement the {@link #getFirstNode} * and {@link #getNextNode} methods for a specific iteration * strategy.

*/ abstract class NodeIterator implements Iterator { /** * Constructor. * * @param contextNode the starting node */ public NodeIterator (Node contextNode) { node = getFirstNode(contextNode); while (!isXPathNode(node)) { node = getNextNode(node); } } public boolean hasNext () { return (node != null); } public Object next () { if (node == null) throw new NoSuchElementException(); Node ret = node; node = getNextNode(node); while (!isXPathNode(node)) { node = getNextNode(node); } return ret; } public void remove () { throw new UnsupportedOperationException(); } /** * Get the first node for iteration. * *

This method must derive an initial node for iteration * from a context node.

* * @param contextNode the starting node * @return the first node in the iteration * @see #getNextNode */ protected abstract Node getFirstNode (Node contextNode); /** * Get the next node for iteration. * *

This method must locate a following node from the * current context node.

* * @param contextNode the current node in the iteration * @return the following node in the iteration, or null * if there is none * @see #getFirstNode */ protected abstract Node getNextNode (Node contextNode); /** * Test whether a DOM node is usable by XPath. * * @param node the DOM node to test * @return true if the node is usable, false if it should be skipped */ private boolean isXPathNode (Node node) { // null is usable, because it means end if (node == null) return true; switch (node.getNodeType()) { case Node.DOCUMENT_FRAGMENT_NODE: case Node.DOCUMENT_TYPE_NODE: case Node.ENTITY_NODE: case Node.ENTITY_REFERENCE_NODE: case Node.NOTATION_NODE: return false; default: return true; } } private Node node; } //////////////////////////////////////////////////////////////////// // Inner class: iterate over a DOM named node map. //////////////////////////////////////////////////////////////////// /** * An iterator over an attribute list. */ private static class AttributeIterator implements Iterator { /** * Constructor. * * @param parent the parent DOM element for the attributes. */ AttributeIterator (Node parent) { this.map = parent.getAttributes(); this.pos = 0; for (int i = this.map.getLength()-1; i >= 0; i--) { Node node = map.item(i); if (! "http://www.w3.org/2000/xmlns/".equals(node.getNamespaceURI())) { this.lastAttribute = i; break; } } } public boolean hasNext () { return pos <= lastAttribute; } public Object next () { Node attr = map.item(pos++); if (attr == null) throw new NoSuchElementException(); else if ("http://www.w3.org/2000/xmlns/".equals(attr.getNamespaceURI())) { // XPath doesn't consider namespace declarations to be attributes // so skip it and go to the next one return next(); } else return attr; } public void remove () { throw new UnsupportedOperationException(); } private NamedNodeMap map; private int pos; private int lastAttribute = -1; } /** * Returns the element whose ID is given by elementId. * If no such element exists, returns null. * Attributes with the name "ID" are not of type ID unless so defined. * Attribute types are only known if when the parser understands DTD's or * schemas that declare attributes of type ID. When JAXP is used, you * must call setValidating(true) on the * DocumentBuilderFactory. * * @param object a node from the document in which to look for the id * @param elementId id to look for * * @return element whose ID is given by elementId, or null if no such * element exists in the document or if the implementation * does not know about attribute types * @see javax.xml.parsers.DocumentBuilderFactory * * @throws ClassCastException if object is not an org.w3c.dom.Node object * */ public Object getElementById(Object object, String elementId) { Document doc = (Document)getDocumentNode(object); if (doc != null) return doc.getElementById(elementId); else return null; } } // end of DocumentNavigator.java jaxen-1.1.6/src/java/main/org/jaxen/dom/NamespaceNode.java0000664000175000017500000005704211751607254022652 0ustar ebourgebourg/* * $Header$ * $Revision: 1370 $ * $Date: 2012-05-07 01:52:12 +0200 (Mon, 07 May 2012) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: NamespaceNode.java 1370 2012-05-06 23:52:12Z elharo $ */ //////////////////////////////////////////////////////////////////// // Inner class for a Namespace node. //////////////////////////////////////////////////////////////////// package org.jaxen.dom; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.HashMap; import org.jaxen.pattern.Pattern; import org.w3c.dom.DOMException; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.w3c.dom.UserDataHandler; /** * Extension DOM2/DOM3 node type for a namespace node. * *

This class implements the DOM2 and DOM3 {@link Node} interface * to allow namespace nodes to be included in the result * set of an XPath selectNodes operation, even though DOM does * not model namespaces in scope as separate nodes.

* *

* While all of the DOM2 methods are implemented with reasonable * defaults, there will be some unexpected surprises, so users are * advised to test for NamespaceNodes and filter them out from the * result sets as early as possible. *

* *
    * *
  1. The {@link #getNodeType} method returns {@link #NAMESPACE_NODE}, * which is not one of the usual DOM2 node types. Generic code may * fall unexpectedly out of switch statements, for example.
  2. * *
  3. The {@link #getOwnerDocument} method returns the owner document * of the parent node, but that owner document will know nothing about * the namespace node.

    * *
  4. The {@link #isSupported} method always returns false.
  5. * *
  6. The DOM3 methods sometimes throw UnsupportedOperationException. * They're here only to allow this class to be compiled with Java 1.5. * Do not call or rely on them.
  7. *
* *

All attempts to modify a NamespaceNode will fail with a {@link * DOMException} ({@link * DOMException#NO_MODIFICATION_ALLOWED_ERR}).

* * @author David Megginson * @author Elliotte Rusty Harold * @see DocumentNavigator */ public class NamespaceNode implements Node { /** * Constant: this is a NamespaceNode. * * @see #getNodeType */ public final static short NAMESPACE_NODE = Pattern.NAMESPACE_NODE; // FIXME "Note: Numeric codes up to 200 are reserved to W3C for possible future use." // We should be using higher codes. Here we're using 13, the same as DOM 3's type for XPathNamespace. // However, that's only a note not a recommendation. /** * Create a new NamespaceNode. * * @param parent the DOM node to which the namespace is attached * @param name the namespace prefix * @param value the namespace URI */ public NamespaceNode (Node parent, String name, String value) { this.parent = parent; this.name = name == null ? "" : name; this.value = value; } /** * Constructor. * * @param parent the DOM node to which the namespace is attached * @param attribute the DOM attribute object containing the * namespace declaration */ NamespaceNode (Node parent, Node attribute) { String attributeName = attribute.getNodeName(); if (attributeName.equals("xmlns")) { this.name = ""; } else if (attributeName.startsWith("xmlns:")) { this.name = attributeName.substring(6); // the part after "xmlns:" } else { // workaround for Crimson bug; Crimson incorrectly reports the prefix as the node name this.name = attributeName; } this.parent = parent; this.value = attribute.getNodeValue(); } //////////////////////////////////////////////////////////////////// // Implementation of org.w3c.dom.Node. //////////////////////////////////////////////////////////////////// /** * Get the namespace prefix. * * @return the namespace prefix, or "" for the default namespace */ public String getNodeName () { return name; } /** * Get the namespace URI. * * @return the namespace URI */ public String getNodeValue () { return value; } /** * Change the namespace URI (always fails). * * @param value the new URI * @throws DOMException always */ public void setNodeValue (String value) throws DOMException { disallowModification(); } /** * Get the node type. * * @return always {@link #NAMESPACE_NODE}. */ public short getNodeType () { return NAMESPACE_NODE; } /** * Get the parent node. * *

This method returns the element that was queried for Namespaces * in effect, not necessarily the actual element containing * the Namespace declaration.

* * @return the parent node (not null) */ public Node getParentNode () { return parent; } /** * Get the list of child nodes. * * @return an empty node list */ public NodeList getChildNodes () { return new EmptyNodeList(); } /** * Get the first child node. * * @return null */ public Node getFirstChild () { return null; } /** * Get the last child node. * * @return null */ public Node getLastChild () { return null; } /** * Get the previous sibling node. * * @return null */ public Node getPreviousSibling () { return null; } /** * Get the next sibling node. * * @return null */ public Node getNextSibling () { return null; } /** * Get the attribute nodes. * * @return null */ public NamedNodeMap getAttributes () { return null; } /** * Get the owner document. * * @return the owner document of the parent node */ public Document getOwnerDocument () { if (parent == null) return null; return parent.getOwnerDocument(); } /** * Insert a new child node (always fails). * * @param newChild the node to add * @param refChild ignored * @return never * @throws DOMException always * @see Node#insertBefore */ public Node insertBefore (Node newChild, Node refChild) throws DOMException { disallowModification(); return null; } /** * Replace a child node (always fails). * * @param newChild the node to add * @param oldChild the child node to replace * @return never * @throws DOMException always * @see Node#replaceChild */ public Node replaceChild (Node newChild, Node oldChild) throws DOMException { disallowModification(); return null; } /** * Remove a child node (always fails). * * @param oldChild the child node to remove * @return never * @throws DOMException always * @see Node#removeChild */ public Node removeChild(Node oldChild) throws DOMException { disallowModification(); return null; } /** * Append a new child node (always fails). * * @param newChild the node to add * @return never * @throws DOMException always * @see Node#appendChild */ public Node appendChild(Node newChild) throws DOMException { disallowModification(); return null; } /** * Test for child nodes. * * @return false */ public boolean hasChildNodes() { return false; } /** * Create a copy of this node. * * @param deep make a deep copy (no effect, since namespace nodes * don't have children). * @return a new copy of this namespace node */ public Node cloneNode (boolean deep) { return new NamespaceNode(parent, name, value); } /** * Normalize the text descendants of this node. * *

This method has no effect, since namespace nodes have no * descendants.

*/ public void normalize () { // no op } /** * Test if a DOM2 feature is supported. (None are.) * * @param feature the feature name * @param version the feature version * @return false */ public boolean isSupported(String feature, String version) { return false; } /** * Get the namespace URI of this node. * *

Namespace declarations are not themselves * Namespace-qualified.

* * @return null */ public String getNamespaceURI() { return null; } /** * Get the namespace prefix of this node. * *

Namespace declarations are not themselves * namespace-qualified.

* * @return null * @see #getLocalName */ public String getPrefix() { return null; } /** * Change the namespace prefix of this node (always fails). * * @param prefix the new prefix * @throws DOMException always thrown */ public void setPrefix(String prefix) throws DOMException { disallowModification(); } /** * Get the XPath name of the namespace node;; i.e. the * namespace prefix. * * @return the namespace prefix */ public String getLocalName () { return name; } /** * Test if this node has attributes. * * @return false */ public boolean hasAttributes () { return false; } /** * Throw a NO_MODIFICATION_ALLOWED_ERR DOMException. * * @throws DOMException always thrown */ private void disallowModification () throws DOMException { throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "Namespace node may not be modified"); } //////////////////////////////////////////////////////////////////// // Override default methods from java.lang.Object. //////////////////////////////////////////////////////////////////// /** * Generate a hash code for a namespace node. * * @return a hash code for this node */ public int hashCode () { return hashCode(parent) + hashCode(name) + hashCode(value); } /** * Test for equivalence with another object. * *

Two Namespace nodes are considered equivalent if their parents, * names, and values are equal.

* * @param o the object to test for equality * @return true if the object is equivalent to this node, false * otherwise */ public boolean equals (Object o) { if (o == this) return true; else if (o == null) return false; else if (o instanceof NamespaceNode) { NamespaceNode ns = (NamespaceNode)o; return (equals(parent, ns.getParentNode()) && equals(name, ns.getNodeName()) && equals(value, ns.getNodeValue())); } else { return false; } } /** * Helper method for generating a hash code. * * @param o the object for generating a hash code (possibly null) * @return the object's hash code, or 0 if the object is null * @see java.lang.Object#hashCode */ private int hashCode (Object o) { return (o == null ? 0 : o.hashCode()); } /** * Helper method for comparing two objects. * * @param a the first object to compare (possibly null) * @param b the second object to compare (possibly null) * @return true if the objects are equivalent or are both null * @see java.lang.Object#equals */ private boolean equals (Object a, Object b) { return ((a == null && b == null) || (a != null && a.equals(b))); } //////////////////////////////////////////////////////////////////// // Internal state. //////////////////////////////////////////////////////////////////// private Node parent; private String name; private String value; //////////////////////////////////////////////////////////////////// // Inner class: empty node list. //////////////////////////////////////////////////////////////////// /** * A node list with no members. * *

This class is necessary for the {@link Node#getChildNodes} * method, which must return an empty node list rather than * null when there are no children.

*/ private static class EmptyNodeList implements NodeList { /** * @see NodeList#getLength */ public int getLength () { return 0; } /** * @see NodeList#item */ public Node item(int index) { return null; } } //////////////////////////////////////////////////////////////////// // DOM Level 3 methods //////////////////////////////////////////////////////////////////// /** * Return the base URI of the document containing this node. * This only works in DOM 3. * * @return null */ public String getBaseURI() { Class clazz = Node.class; try { Class[] args = new Class[0]; Method getBaseURI = clazz.getMethod("getBaseURI", args); String base = (String) getBaseURI.invoke(this.getParentNode(), args); return base; } catch (Exception ex) { return null; } } /** * Compare relative position of this node to another nbode. (Always fails). * This method is included solely for compatibility with the superclass. * * @param other the node to compare to * * @return never * @throws DOMException NOT_SUPPORTED_ERR */ public short compareDocumentPosition(Node other) throws DOMException { DOMException ex = new DOMException( DOMException.NOT_SUPPORTED_ERR, "DOM level 3 interfaces are not fully implemented in Jaxen's NamespaceNode class" ); throw ex; } /** * Return the namespace URI. * * @return the namespace URI * @see #getNodeValue */ public String getTextContent() { return value; } /** * Change the value of this node (always fails). * This method is included solely for compatibility with the superclass. * * @param textContent the new content * @throws DOMException always */ public void setTextContent(String textContent) throws DOMException { disallowModification(); } /** * Returns true if and only if this object represents the same XPath namespace node * as the argument; that is, they have the same parent, the same prefix, and the * same URI. * * @param other the node to compare to * @return true if this object represents the same XPath namespace node * as other; false otherwise */ public boolean isSameNode(Node other) { boolean a = this.isEqualNode(other); // a bit flaky (should really be // this.getParentNode().isEqual(other.getParentNode()) // but we want this to compile in Java 1.4 without problems // Note that this will mess up code coverage since you can't cover both // branches in the same VM boolean b; Node thisParent = this.getParentNode(); Node thatParent = other.getParentNode(); try { Class clazz = Node.class; Class[] args = {clazz}; Method isEqual = clazz.getMethod("isEqual", args); Object[] args2 = new Object[1]; args2[0] = thatParent; Boolean result = (Boolean) isEqual.invoke(thisParent, args2); b = result.booleanValue(); } catch (NoSuchMethodException ex) { b = thisParent.equals(thatParent); } catch (InvocationTargetException ex) { b = thisParent.equals(thatParent); } catch (IllegalAccessException ex) { b = thisParent.equals(thatParent); } return a && b; } /** * Return the prefix bound to this namespace URI within the scope * of this node. * * @param namespaceURI the URI to find a prefix binding for * * @return a prefix matching this namespace URI * @throws UnsupportedOperationException in DOM 2 */ public String lookupPrefix(String namespaceURI) { // This could be fully implemented even in Java 1.4. See // http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/namespaces-algorithms.html#lookupNamespaceURIAlgo // It hardly seems worth the effort though. try { Class clazz = Node.class; Class[] argTypes = {String.class}; Method lookupPrefix = clazz.getMethod("lookupPrefix", argTypes); String[] args = {namespaceURI}; String result = (String) lookupPrefix.invoke(parent, args); return result; } catch (NoSuchMethodException ex) { throw new UnsupportedOperationException("Cannot lookup prefixes in DOM 2"); } catch (InvocationTargetException ex) { throw new UnsupportedOperationException("Cannot lookup prefixes in DOM 2"); } catch (IllegalAccessException ex) { throw new UnsupportedOperationException("Cannot lookup prefixes in DOM 2"); } } /** * Return true if the specified URI is the default namespace in * scope (always fails). This method is included solely for * compatibility with the superclass. * * @param namespaceURI the URI to check * * @return never * @throws UnsupportedOperationException always */ public boolean isDefaultNamespace(String namespaceURI) { return namespaceURI.equals(this.lookupNamespaceURI(null)); } /** * Return the namespace URI mapped to the specified * prefix within the scope of this namespace node. * * @param prefix the prefix to search for * * @return the namespace URI mapped to this prefix * @throws UnsupportedOperationException in DOM 2 */ public String lookupNamespaceURI(String prefix) { // This could be fully implemented even in Java 1.4. See // http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/namespaces-algorithms.html#lookupNamespaceURIAlgo // It hardly seems worth the effort though. try { Class clazz = Node.class; Class[] argTypes = {String.class}; Method lookupNamespaceURI = clazz.getMethod("lookupNamespaceURI", argTypes); String[] args = {prefix}; String result = (String) lookupNamespaceURI.invoke(parent, args); return result; } catch (NoSuchMethodException ex) { throw new UnsupportedOperationException("Cannot lookup namespace URIs in DOM 2"); } catch (InvocationTargetException ex) { throw new UnsupportedOperationException("Cannot lookup namespace URIs in DOM 2"); } catch (IllegalAccessException ex) { throw new UnsupportedOperationException("Cannot lookup namespace URIs in DOM 2"); } } /** * Returns true if this object binds the same prefix to the same URI. * That is, this object has the same prefix and URI as the argument. * * @param arg the node to compare to * @return true if this object has the same prefix and URI as the argument; false otherwise */ public boolean isEqualNode(Node arg) { if (arg.getNodeType() == this.getNodeType()) { NamespaceNode other = (NamespaceNode) arg; if (other.name == null && this.name != null) return false; else if (other.name != null && this.name == null) return false; else if (other.value == null && this.value != null) return false; else if (other.value != null && this.value == null) return false; else if (other.name == null && this.name == null) { return other.value.equals(this.value); } return other.name.equals(this.name) && other.value.equals(this.value); } return false; } /** * Returns the value of the requested feature. Always returns null. * * @return null */ public Object getFeature(String feature, String version) { return null; } // XXX userdata needs testing private HashMap userData = new HashMap(); /** * Associates an object with a key. * * @param key the key by which the data will be retrieved * @param data the object to store with the key * @param handler ignored since namespace nodes cannot be imported, cloned, or renamed * * @return the value previously associated with this key; or null * if there isn't any such previous value */ public Object setUserData(String key, Object data, UserDataHandler handler) { Object oldValue = getUserData(key); userData.put(key, data); return oldValue; } /** * Returns the user data associated with the given key. * * @param key the lookup key * * @return the object associated with the key; or null if no such object is available */ public Object getUserData(String key) { return userData.get(key); } } // end of NamespaceNode.java jaxen-1.1.6/src/java/main/org/jaxen/dom/package.html0000664000175000017500000000025507472132404021553 0ustar ebourgebourg org.jaxen.dom.*

Navigation for W3C DOM trees.

jaxen-1.1.6/src/java/main/org/jaxen/JaxenException.java0000664000175000017500000000734710440371260022305 0ustar ebourgebourg/* * $Header$ * $Revision: 1161 $ * $Date: 2006-06-03 22:36:00 +0200 (Sat, 03 Jun 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: JaxenException.java 1161 2006-06-03 20:36:00Z elharo $ */ package org.jaxen; /** * Generic Jaxen exception. * *

This is the root of all Jaxen exceptions. It may wrap other exceptions. * * @author bob mcwhirter */ public class JaxenException extends org.jaxen.saxpath.SAXPathException { /** * */ private static final long serialVersionUID = 7132891439526672639L; static double javaVersion = 1.4; static { try { String versionString = System.getProperty("java.version"); versionString = versionString.substring(0, 3); javaVersion = Double.valueOf(versionString).doubleValue(); } catch (RuntimeException ex) { // The version string format changed so presumably it's // 1.4 or later. } } /** * Create an exception with a detail message. * * @param message the error message */ public JaxenException( String message ) { super( message ); } /** * Create an exception caused by another exception. * * @param rootCause the root cause of this exception */ public JaxenException( Throwable rootCause ) { super( rootCause ); } /** * Create a new JaxenException with the specified detail message * and root cause. * * @param message the detail message * @param nestedException the cause of this exception */ public JaxenException(String message, Throwable nestedException) { super( message, nestedException ); } }jaxen-1.1.6/src/java/main/org/jaxen/Function.java0000664000175000017500000000651710371471320021145 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: Function.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen; import java.util.List; /** Interface for the extensible function framework. * *

* NOTE: This class is not typically used directly, * but is exposed for writers of extended XPath packages. *

* *

* Implementations of Function are functors * which are used to evaluate a function-call within an * XPath expression. *

* * @see FunctionContext * * @author bob mcwhirter */ public interface Function { /** Evaluate this function. * * @param context the context at the point in the * expression when the function is called * @param args arguments provided to the function * * @return the result of evaluating the function; a List * (node-set), Double, Boolean, or * String * * @throws FunctionCallException if an XPath error occurs during evaluation; * for instance, if the number or type of the arguments is incorrect */ Object call(Context context, List args) throws FunctionCallException; } jaxen-1.1.6/src/java/main/org/jaxen/saxpath/0000775000175000017500000000000012174247550020165 5ustar ebourgebourgjaxen-1.1.6/src/java/main/org/jaxen/saxpath/XPathSyntaxException.java0000664000175000017500000001170110440371260025130 0ustar ebourgebourg/* * $Header$ * $Revision: 1161 $ * $Date: 2006-06-03 22:36:00 +0200 (Sat, 03 Jun 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: XPathSyntaxException.java 1161 2006-06-03 20:36:00Z elharo $ */ package org.jaxen.saxpath; /** * Represents a syntax error in an XPath expression. * This is a compile-time error that is detectable irrespective of * the context in which the XPath expression is evaluated. */ public class XPathSyntaxException extends SAXPathException { /** * */ private static final long serialVersionUID = 3567675610742422397L; private String xpath; private int position; private final static String lineSeparator = System.getProperty("line.separator"); /** * Creates a new XPathSyntaxException. * * @param xpath the incorrect XPath expression * @param position the index of the character at which the syntax error was detected * @param message the detail message */ public XPathSyntaxException(String xpath, int position, String message) { super( message ); this.position = position; this.xpath = xpath; } /** *

* Returns the index of the character at which the syntax error was detected * in the XPath expression. *

* * @return the character index in the XPath expression * at which the syntax error was detected */ public int getPosition() { return this.position; } /** *

* Returns the syntactically incorrect XPath expression. *

* * @return the syntactically incorrect XPath expression */ public String getXPath() { return this.xpath; } public String toString() { return getClass() + ": " + getXPath() + ": " + getPosition() + ": " + getMessage(); } /** *

* Returns a string in the form " ^" which, when placed on the line * below the XPath expression in a monospaced font, should point to the * location of the error. *

* * @return the position marker */ private String getPositionMarker() { int pos = getPosition(); StringBuffer buf = new StringBuffer(pos+1); for ( int i = 0 ; i < pos ; ++i ) { buf.append(" "); } buf.append("^"); return buf.toString(); } /** *

* Returns a long formatted description of the error, * including line breaks. *

* * @return a longer description of the error on multiple lines */ public String getMultilineMessage() { StringBuffer buf = new StringBuffer(); buf.append( getMessage() ); buf.append( lineSeparator ); buf.append( getXPath() ); buf.append( lineSeparator ); buf.append( getPositionMarker() ); return buf.toString(); } } jaxen-1.1.6/src/java/main/org/jaxen/saxpath/Operator.java0000664000175000017500000001046510371471320022620 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: Operator.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.saxpath; /** * Constants used to represent XPath operators. */ public interface Operator { /** * Indicates that we're passing through a grammar production without * actually activating it. For example in the expression * 1 is matches AdditiveExpr and MultiplicativeExpr in * the XPath grammar, even though it has neither a plus, * minus, multiplication, or other sign. */ final static int NO_OP = 0; // Equality /** * The equal to operator =. This is equivalent to == * in Java. This is a comparison operator, not an assignment operator. */ final static int EQUALS = 1; /** * The not equal to operator != */ final static int NOT_EQUALS = 2; // Relational /** * The less-than operator < */ final static int LESS_THAN = 3; /** * The less-than-or-equal-to operator <= */ final static int LESS_THAN_EQUALS = 4; /** * The greater-than operator > */ final static int GREATER_THAN = 5; /** * The greater-than or equals operator >= */ final static int GREATER_THAN_EQUALS = 6; // Additive /** * The addition operator + */ final static int ADD = 7; /** * The subtraction operator - */ final static int SUBTRACT = 8; // Multiplicative /** * The multiplication operator * */ final static int MULTIPLY = 9; /** * The remainder operator mod. This is equivalent to * % in Java. */ final static int MOD = 10; /** * The floating point division operator div. This is equivalent to * / in Java. */ final static int DIV = 11; // Unary /** * Unary - */ final static int NEGATIVE = 12; } jaxen-1.1.6/src/java/main/org/jaxen/saxpath/SAXPathException.java0000664000175000017500000001300410440371260024143 0ustar ebourgebourg/* * $Header$ * $Revision: 1161 $ * $Date: 2006-06-03 22:36:00 +0200 (Sat, 03 Jun 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: SAXPathException.java 1161 2006-06-03 20:36:00Z elharo $ */ package org.jaxen.saxpath; import java.io.PrintStream; import java.io.PrintWriter; /** Base of all SAXPath exceptions. * * @author bob mcwhirter (bob@werken.com) */ public class SAXPathException extends Exception { /** * */ private static final long serialVersionUID = 4826444568928720706L; private static double javaVersion = 1.4; static { try { String versionString = System.getProperty("java.version"); versionString = versionString.substring(0, 3); javaVersion = Double.valueOf(versionString).doubleValue(); } catch (Exception ex) { // The version string format changed so presumably it's // 1.4 or later. } } /** Create a new SAXPathException with a given message. * * @param message the error message */ public SAXPathException(String message) { super( message ); } /** Create a new SAXPathException based on another exception * * @param cause the error source */ public SAXPathException(Throwable cause) { super ( cause.getMessage() ); initCause(cause); } /** * Create a new SAXPathException with the specified detail message * and root cause. * * @param message the detail message * @param cause the cause of this exception */ public SAXPathException(String message, Throwable cause) { super( message ); initCause(cause); } private Throwable cause; private boolean causeSet = false; /** * Returns the exception that caused this exception. * This is necessary to implement Java 1.4 chained exception * functionality in a Java 1.3-compatible way. * * @return the exception that caused this exception */ public Throwable getCause() { return cause; } /** * Sets the exception that caused this exception. * This is necessary to implement Java 1.4 chained exception * functionality in a Java 1.3-compatible way. * * @param cause the exception wrapped in this runtime exception * * @return this exception */ public Throwable initCause(Throwable cause) { if (causeSet) throw new IllegalStateException("Cause cannot be reset"); if (cause == this) throw new IllegalArgumentException("Exception cannot be its own cause"); causeSet = true; this.cause = cause; return this; } /** Print this exception's stack trace, followed by the * source exception's trace, if any. * * @param s the stream on which to print the stack trace */ public void printStackTrace ( PrintStream s ) { super.printStackTrace ( s ); if (javaVersion < 1.4 && getCause() != null) { s.print( "Caused by: " ); getCause().printStackTrace( s ); } } /** Print this exception's stack trace, followed by the * source exception's stack trace, if any. * * @param s the writer on which to print the stack trace */ public void printStackTrace ( PrintWriter s ) { super.printStackTrace( s ); if (javaVersion < 1.4 && getCause() != null) { s.print( "Caused by: " ); getCause().printStackTrace( s ); } } } jaxen-1.1.6/src/java/main/org/jaxen/saxpath/base/0000775000175000017500000000000012174247550021077 5ustar ebourgebourgjaxen-1.1.6/src/java/main/org/jaxen/saxpath/base/Verifier.java0000664000175000017500000006333310415546172023523 0ustar ebourgebourg/*-- * * $Id$ * * Copyright 2000-2004 Jason Hunter & Brett McLaughlin. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * */ package org.jaxen.saxpath.base; /** * A utility class to handle well-formedness checks on names. * * @author Brett McLaughlin * @author Elliotte Rusty Harold * @author Jason Hunter * @author Bradley S. Huffman */ final class Verifier { /** * This is a utility function for determining whether a specified * character is a name character according to production 4 of the * XML 1.0 specification. * * @param c char to check for XML name compliance. * @return boolean true if it's a name character, * false otherwise */ static boolean isXMLNCNameCharacter(char c) { return (isXMLLetter(c) || isXMLDigit(c) || c == '.' || c == '-' || c == '_' || isXMLCombiningChar(c) || isXMLExtender(c)); } /** * This is a utility function for determining whether a specified * character is a legal name start character according to production 5 * of the XML 1.0 specification. This production does allow names * to begin with colons which the Namespaces in XML Recommendation * disallows. * * @param c char to check for XML name start compliance * @return true if it's a name start character, false otherwise */ static boolean isXMLNCNameStartCharacter(char c) { return (isXMLLetter(c) || c == '_'); } /** * Determine whether a specified character * is a letter according to production 84 of the XML 1.0 specification. * * @param c char to check for XML name compliance * @return String true if it's a letter, false otherwise */ static boolean isXMLLetter(char c) { // Note that order is very important here. The search proceeds // from lowest to highest values, so that no searching occurs // above the character's value. BTW, the first line is equivalent to: // if (c >= 0x0041 && c <= 0x005A) return true; if (c < 0x0041) return false; if (c <= 0x005a) return true; if (c < 0x0061) return false; if (c <= 0x007A) return true; if (c < 0x00C0) return false; if (c <= 0x00D6) return true; if (c < 0x00D8) return false; if (c <= 0x00F6) return true; if (c < 0x00F8) return false; if (c <= 0x00FF) return true; if (c < 0x0100) return false; if (c <= 0x0131) return true; if (c < 0x0134) return false; if (c <= 0x013E) return true; if (c < 0x0141) return false; if (c <= 0x0148) return true; if (c < 0x014A) return false; if (c <= 0x017E) return true; if (c < 0x0180) return false; if (c <= 0x01C3) return true; if (c < 0x01CD) return false; if (c <= 0x01F0) return true; if (c < 0x01F4) return false; if (c <= 0x01F5) return true; if (c < 0x01FA) return false; if (c <= 0x0217) return true; if (c < 0x0250) return false; if (c <= 0x02A8) return true; if (c < 0x02BB) return false; if (c <= 0x02C1) return true; if (c == 0x0386) return true; if (c < 0x0388) return false; if (c <= 0x038A) return true; if (c == 0x038C) return true; if (c < 0x038E) return false; if (c <= 0x03A1) return true; if (c < 0x03A3) return false; if (c <= 0x03CE) return true; if (c < 0x03D0) return false; if (c <= 0x03D6) return true; if (c == 0x03DA) return true; if (c == 0x03DC) return true; if (c == 0x03DE) return true; if (c == 0x03E0) return true; if (c < 0x03E2) return false; if (c <= 0x03F3) return true; if (c < 0x0401) return false; if (c <= 0x040C) return true; if (c < 0x040E) return false; if (c <= 0x044F) return true; if (c < 0x0451) return false; if (c <= 0x045C) return true; if (c < 0x045E) return false; if (c <= 0x0481) return true; if (c < 0x0490) return false; if (c <= 0x04C4) return true; if (c < 0x04C7) return false; if (c <= 0x04C8) return true; if (c < 0x04CB) return false; if (c <= 0x04CC) return true; if (c < 0x04D0) return false; if (c <= 0x04EB) return true; if (c < 0x04EE) return false; if (c <= 0x04F5) return true; if (c < 0x04F8) return false; if (c <= 0x04F9) return true; if (c < 0x0531) return false; if (c <= 0x0556) return true; if (c == 0x0559) return true; if (c < 0x0561) return false; if (c <= 0x0586) return true; if (c < 0x05D0) return false; if (c <= 0x05EA) return true; if (c < 0x05F0) return false; if (c <= 0x05F2) return true; if (c < 0x0621) return false; if (c <= 0x063A) return true; if (c < 0x0641) return false; if (c <= 0x064A) return true; if (c < 0x0671) return false; if (c <= 0x06B7) return true; if (c < 0x06BA) return false; if (c <= 0x06BE) return true; if (c < 0x06C0) return false; if (c <= 0x06CE) return true; if (c < 0x06D0) return false; if (c <= 0x06D3) return true; if (c == 0x06D5) return true; if (c < 0x06E5) return false; if (c <= 0x06E6) return true; if (c < 0x0905) return false; if (c <= 0x0939) return true; if (c == 0x093D) return true; if (c < 0x0958) return false; if (c <= 0x0961) return true; if (c < 0x0985) return false; if (c <= 0x098C) return true; if (c < 0x098F) return false; if (c <= 0x0990) return true; if (c < 0x0993) return false; if (c <= 0x09A8) return true; if (c < 0x09AA) return false; if (c <= 0x09B0) return true; if (c == 0x09B2) return true; if (c < 0x09B6) return false; if (c <= 0x09B9) return true; if (c < 0x09DC) return false; if (c <= 0x09DD) return true; if (c < 0x09DF) return false; if (c <= 0x09E1) return true; if (c < 0x09F0) return false; if (c <= 0x09F1) return true; if (c < 0x0A05) return false; if (c <= 0x0A0A) return true; if (c < 0x0A0F) return false; if (c <= 0x0A10) return true; if (c < 0x0A13) return false; if (c <= 0x0A28) return true; if (c < 0x0A2A) return false; if (c <= 0x0A30) return true; if (c < 0x0A32) return false; if (c <= 0x0A33) return true; if (c < 0x0A35) return false; if (c <= 0x0A36) return true; if (c < 0x0A38) return false; if (c <= 0x0A39) return true; if (c < 0x0A59) return false; if (c <= 0x0A5C) return true; if (c == 0x0A5E) return true; if (c < 0x0A72) return false; if (c <= 0x0A74) return true; if (c < 0x0A85) return false; if (c <= 0x0A8B) return true; if (c == 0x0A8D) return true; if (c < 0x0A8F) return false; if (c <= 0x0A91) return true; if (c < 0x0A93) return false; if (c <= 0x0AA8) return true; if (c < 0x0AAA) return false; if (c <= 0x0AB0) return true; if (c < 0x0AB2) return false; if (c <= 0x0AB3) return true; if (c < 0x0AB5) return false; if (c <= 0x0AB9) return true; if (c == 0x0ABD) return true; if (c == 0x0AE0) return true; if (c < 0x0B05) return false; if (c <= 0x0B0C) return true; if (c < 0x0B0F) return false; if (c <= 0x0B10) return true; if (c < 0x0B13) return false; if (c <= 0x0B28) return true; if (c < 0x0B2A) return false; if (c <= 0x0B30) return true; if (c < 0x0B32) return false; if (c <= 0x0B33) return true; if (c < 0x0B36) return false; if (c <= 0x0B39) return true; if (c == 0x0B3D) return true; if (c < 0x0B5C) return false; if (c <= 0x0B5D) return true; if (c < 0x0B5F) return false; if (c <= 0x0B61) return true; if (c < 0x0B85) return false; if (c <= 0x0B8A) return true; if (c < 0x0B8E) return false; if (c <= 0x0B90) return true; if (c < 0x0B92) return false; if (c <= 0x0B95) return true; if (c < 0x0B99) return false; if (c <= 0x0B9A) return true; if (c == 0x0B9C) return true; if (c < 0x0B9E) return false; if (c <= 0x0B9F) return true; if (c < 0x0BA3) return false; if (c <= 0x0BA4) return true; if (c < 0x0BA8) return false; if (c <= 0x0BAA) return true; if (c < 0x0BAE) return false; if (c <= 0x0BB5) return true; if (c < 0x0BB7) return false; if (c <= 0x0BB9) return true; if (c < 0x0C05) return false; if (c <= 0x0C0C) return true; if (c < 0x0C0E) return false; if (c <= 0x0C10) return true; if (c < 0x0C12) return false; if (c <= 0x0C28) return true; if (c < 0x0C2A) return false; if (c <= 0x0C33) return true; if (c < 0x0C35) return false; if (c <= 0x0C39) return true; if (c < 0x0C60) return false; if (c <= 0x0C61) return true; if (c < 0x0C85) return false; if (c <= 0x0C8C) return true; if (c < 0x0C8E) return false; if (c <= 0x0C90) return true; if (c < 0x0C92) return false; if (c <= 0x0CA8) return true; if (c < 0x0CAA) return false; if (c <= 0x0CB3) return true; if (c < 0x0CB5) return false; if (c <= 0x0CB9) return true; if (c == 0x0CDE) return true; if (c < 0x0CE0) return false; if (c <= 0x0CE1) return true; if (c < 0x0D05) return false; if (c <= 0x0D0C) return true; if (c < 0x0D0E) return false; if (c <= 0x0D10) return true; if (c < 0x0D12) return false; if (c <= 0x0D28) return true; if (c < 0x0D2A) return false; if (c <= 0x0D39) return true; if (c < 0x0D60) return false; if (c <= 0x0D61) return true; if (c < 0x0E01) return false; if (c <= 0x0E2E) return true; if (c == 0x0E30) return true; if (c < 0x0E32) return false; if (c <= 0x0E33) return true; if (c < 0x0E40) return false; if (c <= 0x0E45) return true; if (c < 0x0E81) return false; if (c <= 0x0E82) return true; if (c == 0x0E84) return true; if (c < 0x0E87) return false; if (c <= 0x0E88) return true; if (c == 0x0E8A) return true; if (c == 0x0E8D) return true; if (c < 0x0E94) return false; if (c <= 0x0E97) return true; if (c < 0x0E99) return false; if (c <= 0x0E9F) return true; if (c < 0x0EA1) return false; if (c <= 0x0EA3) return true; if (c == 0x0EA5) return true; if (c == 0x0EA7) return true; if (c < 0x0EAA) return false; if (c <= 0x0EAB) return true; if (c < 0x0EAD) return false; if (c <= 0x0EAE) return true; if (c == 0x0EB0) return true; if (c < 0x0EB2) return false; if (c <= 0x0EB3) return true; if (c == 0x0EBD) return true; if (c < 0x0EC0) return false; if (c <= 0x0EC4) return true; if (c < 0x0F40) return false; if (c <= 0x0F47) return true; if (c < 0x0F49) return false; if (c <= 0x0F69) return true; if (c < 0x10A0) return false; if (c <= 0x10C5) return true; if (c < 0x10D0) return false; if (c <= 0x10F6) return true; if (c == 0x1100) return true; if (c < 0x1102) return false; if (c <= 0x1103) return true; if (c < 0x1105) return false; if (c <= 0x1107) return true; if (c == 0x1109) return true; if (c < 0x110B) return false; if (c <= 0x110C) return true; if (c < 0x110E) return false; if (c <= 0x1112) return true; if (c == 0x113C) return true; if (c == 0x113E) return true; if (c == 0x1140) return true; if (c == 0x114C) return true; if (c == 0x114E) return true; if (c == 0x1150) return true; if (c < 0x1154) return false; if (c <= 0x1155) return true; if (c == 0x1159) return true; if (c < 0x115F) return false; if (c <= 0x1161) return true; if (c == 0x1163) return true; if (c == 0x1165) return true; if (c == 0x1167) return true; if (c == 0x1169) return true; if (c < 0x116D) return false; if (c <= 0x116E) return true; if (c < 0x1172) return false; if (c <= 0x1173) return true; if (c == 0x1175) return true; if (c == 0x119E) return true; if (c == 0x11A8) return true; if (c == 0x11AB) return true; if (c < 0x11AE) return false; if (c <= 0x11AF) return true; if (c < 0x11B7) return false; if (c <= 0x11B8) return true; if (c == 0x11BA) return true; if (c < 0x11BC) return false; if (c <= 0x11C2) return true; if (c == 0x11EB) return true; if (c == 0x11F0) return true; if (c == 0x11F9) return true; if (c < 0x1E00) return false; if (c <= 0x1E9B) return true; if (c < 0x1EA0) return false; if (c <= 0x1EF9) return true; if (c < 0x1F00) return false; if (c <= 0x1F15) return true; if (c < 0x1F18) return false; if (c <= 0x1F1D) return true; if (c < 0x1F20) return false; if (c <= 0x1F45) return true; if (c < 0x1F48) return false; if (c <= 0x1F4D) return true; if (c < 0x1F50) return false; if (c <= 0x1F57) return true; if (c == 0x1F59) return true; if (c == 0x1F5B) return true; if (c == 0x1F5D) return true; if (c < 0x1F5F) return false; if (c <= 0x1F7D) return true; if (c < 0x1F80) return false; if (c <= 0x1FB4) return true; if (c < 0x1FB6) return false; if (c <= 0x1FBC) return true; if (c == 0x1FBE) return true; if (c < 0x1FC2) return false; if (c <= 0x1FC4) return true; if (c < 0x1FC6) return false; if (c <= 0x1FCC) return true; if (c < 0x1FD0) return false; if (c <= 0x1FD3) return true; if (c < 0x1FD6) return false; if (c <= 0x1FDB) return true; if (c < 0x1FE0) return false; if (c <= 0x1FEC) return true; if (c < 0x1FF2) return false; if (c <= 0x1FF4) return true; if (c < 0x1FF6) return false; if (c <= 0x1FFC) return true; if (c == 0x2126) return true; if (c < 0x212A) return false; if (c <= 0x212B) return true; if (c == 0x212E) return true; if (c < 0x2180) return false; if (c <= 0x2182) return true; if (c == 0x3007) return true; if (c < 0x3021) return false; if (c <= 0x3029) return true; if (c < 0x3041) return false; if (c <= 0x3094) return true; if (c < 0x30A1) return false; if (c <= 0x30FA) return true; if (c < 0x3105) return false; if (c <= 0x312C) return true; if (c < 0x4E00) return false; if (c <= 0x9FA5) return true; if (c < 0xAC00) return false; if (c <= 0xD7A3) return true; return false; } /** * Determine whether a specified character * is a combining character according to production 87 * of the XML 1.0 specification. * * @param c char to check * @return boolean true if it's a combining character, * false otherwise */ static boolean isXMLCombiningChar(char c) { // CombiningChar if (c < 0x0300) return false; if (c <= 0x0345) return true; if (c < 0x0360) return false; if (c <= 0x0361) return true; if (c < 0x0483) return false; if (c <= 0x0486) return true; if (c < 0x0591) return false; if (c <= 0x05A1) return true; if (c < 0x05A3) return false; if (c <= 0x05B9) return true; if (c < 0x05BB) return false; if (c <= 0x05BD) return true; if (c == 0x05BF) return true; if (c < 0x05C1) return false; if (c <= 0x05C2) return true; if (c == 0x05C4) return true; if (c < 0x064B) return false; if (c <= 0x0652) return true; if (c == 0x0670) return true; if (c < 0x06D6) return false; if (c <= 0x06DC) return true; if (c < 0x06DD) return false; if (c <= 0x06DF) return true; if (c < 0x06E0) return false; if (c <= 0x06E4) return true; if (c < 0x06E7) return false; if (c <= 0x06E8) return true; if (c < 0x06EA) return false; if (c <= 0x06ED) return true; if (c < 0x0901) return false; if (c <= 0x0903) return true; if (c == 0x093C) return true; if (c < 0x093E) return false; if (c <= 0x094C) return true; if (c == 0x094D) return true; if (c < 0x0951) return false; if (c <= 0x0954) return true; if (c < 0x0962) return false; if (c <= 0x0963) return true; if (c < 0x0981) return false; if (c <= 0x0983) return true; if (c == 0x09BC) return true; if (c == 0x09BE) return true; if (c == 0x09BF) return true; if (c < 0x09C0) return false; if (c <= 0x09C4) return true; if (c < 0x09C7) return false; if (c <= 0x09C8) return true; if (c < 0x09CB) return false; if (c <= 0x09CD) return true; if (c == 0x09D7) return true; if (c < 0x09E2) return false; if (c <= 0x09E3) return true; if (c == 0x0A02) return true; if (c == 0x0A3C) return true; if (c == 0x0A3E) return true; if (c == 0x0A3F) return true; if (c < 0x0A40) return false; if (c <= 0x0A42) return true; if (c < 0x0A47) return false; if (c <= 0x0A48) return true; if (c < 0x0A4B) return false; if (c <= 0x0A4D) return true; if (c < 0x0A70) return false; if (c <= 0x0A71) return true; if (c < 0x0A81) return false; if (c <= 0x0A83) return true; if (c == 0x0ABC) return true; if (c < 0x0ABE) return false; if (c <= 0x0AC5) return true; if (c < 0x0AC7) return false; if (c <= 0x0AC9) return true; if (c < 0x0ACB) return false; if (c <= 0x0ACD) return true; if (c < 0x0B01) return false; if (c <= 0x0B03) return true; if (c == 0x0B3C) return true; if (c < 0x0B3E) return false; if (c <= 0x0B43) return true; if (c < 0x0B47) return false; if (c <= 0x0B48) return true; if (c < 0x0B4B) return false; if (c <= 0x0B4D) return true; if (c < 0x0B56) return false; if (c <= 0x0B57) return true; if (c < 0x0B82) return false; if (c <= 0x0B83) return true; if (c < 0x0BBE) return false; if (c <= 0x0BC2) return true; if (c < 0x0BC6) return false; if (c <= 0x0BC8) return true; if (c < 0x0BCA) return false; if (c <= 0x0BCD) return true; if (c == 0x0BD7) return true; if (c < 0x0C01) return false; if (c <= 0x0C03) return true; if (c < 0x0C3E) return false; if (c <= 0x0C44) return true; if (c < 0x0C46) return false; if (c <= 0x0C48) return true; if (c < 0x0C4A) return false; if (c <= 0x0C4D) return true; if (c < 0x0C55) return false; if (c <= 0x0C56) return true; if (c < 0x0C82) return false; if (c <= 0x0C83) return true; if (c < 0x0CBE) return false; if (c <= 0x0CC4) return true; if (c < 0x0CC6) return false; if (c <= 0x0CC8) return true; if (c < 0x0CCA) return false; if (c <= 0x0CCD) return true; if (c < 0x0CD5) return false; if (c <= 0x0CD6) return true; if (c < 0x0D02) return false; if (c <= 0x0D03) return true; if (c < 0x0D3E) return false; if (c <= 0x0D43) return true; if (c < 0x0D46) return false; if (c <= 0x0D48) return true; if (c < 0x0D4A) return false; if (c <= 0x0D4D) return true; if (c == 0x0D57) return true; if (c == 0x0E31) return true; if (c < 0x0E34) return false; if (c <= 0x0E3A) return true; if (c < 0x0E47) return false; if (c <= 0x0E4E) return true; if (c == 0x0EB1) return true; if (c < 0x0EB4) return false; if (c <= 0x0EB9) return true; if (c < 0x0EBB) return false; if (c <= 0x0EBC) return true; if (c < 0x0EC8) return false; if (c <= 0x0ECD) return true; if (c < 0x0F18) return false; if (c <= 0x0F19) return true; if (c == 0x0F35) return true; if (c == 0x0F37) return true; if (c == 0x0F39) return true; if (c == 0x0F3E) return true; if (c == 0x0F3F) return true; if (c < 0x0F71) return false; if (c <= 0x0F84) return true; if (c < 0x0F86) return false; if (c <= 0x0F8B) return true; if (c < 0x0F90) return false; if (c <= 0x0F95) return true; if (c == 0x0F97) return true; if (c < 0x0F99) return false; if (c <= 0x0FAD) return true; if (c < 0x0FB1) return false; if (c <= 0x0FB7) return true; if (c == 0x0FB9) return true; if (c < 0x20D0) return false; if (c <= 0x20DC) return true; if (c == 0x20E1) return true; if (c < 0x302A) return false; if (c <= 0x302F) return true; if (c == 0x3099) return true; if (c == 0x309A) return true; return false; } /** * Determine whether a specified * character is an extender according to production 88 of the XML 1.0 * specification. * * @param c char to check * @return true if it's an extender, false otherwise */ static boolean isXMLExtender(char c) { if (c < 0x00B6) return false; // quick short circuit // Extenders if (c == 0x00B7) return true; if (c == 0x02D0) return true; if (c == 0x02D1) return true; if (c == 0x0387) return true; if (c == 0x0640) return true; if (c == 0x0E46) return true; if (c == 0x0EC6) return true; if (c == 0x3005) return true; if (c < 0x3031) return false; if (c <= 0x3035) return true; if (c < 0x309D) return false; if (c <= 0x309E) return true; if (c < 0x30FC) return false; if (c <= 0x30FE) return true; return false; } /** * Determine whether a specified Unicode character * is a digit according to production 88 of the XML 1.0 specification. * * @param c char to check for XML digit compliance * @return boolean true if it's a digit, false otherwise */ static boolean isXMLDigit(char c) { if (c < 0x0030) return false; if (c <= 0x0039) return true; if (c < 0x0660) return false; if (c <= 0x0669) return true; if (c < 0x06F0) return false; if (c <= 0x06F9) return true; if (c < 0x0966) return false; if (c <= 0x096F) return true; if (c < 0x09E6) return false; if (c <= 0x09EF) return true; if (c < 0x0A66) return false; if (c <= 0x0A6F) return true; if (c < 0x0AE6) return false; if (c <= 0x0AEF) return true; if (c < 0x0B66) return false; if (c <= 0x0B6F) return true; if (c < 0x0BE7) return false; if (c <= 0x0BEF) return true; if (c < 0x0C66) return false; if (c <= 0x0C6F) return true; if (c < 0x0CE6) return false; if (c <= 0x0CEF) return true; if (c < 0x0D66) return false; if (c <= 0x0D6F) return true; if (c < 0x0E50) return false; if (c <= 0x0E59) return true; if (c < 0x0ED0) return false; if (c <= 0x0ED9) return true; if (c < 0x0F20) return false; if (c <= 0x0F29) return true; return false; } } jaxen-1.1.6/src/java/main/org/jaxen/saxpath/base/Token.java0000664000175000017500000000665010371471320023020 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: Token.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.saxpath.base; class Token { private int tokenType; private String parseText; private int tokenBegin; private int tokenEnd; Token(int tokenType, String parseText, int tokenBegin, int tokenEnd) { setTokenType( tokenType ); setParseText( parseText ); setTokenBegin( tokenBegin ); setTokenEnd( tokenEnd ); } private void setTokenType(int tokenType) { this.tokenType = tokenType; } int getTokenType() { return this.tokenType; } private void setParseText(String parseText) { this.parseText = parseText; } String getTokenText() { return this.parseText.substring( getTokenBegin(), getTokenEnd() ); } private void setTokenBegin(int tokenBegin) { this.tokenBegin = tokenBegin; } int getTokenBegin() { return this.tokenBegin; } private void setTokenEnd(int tokenEnd) { this.tokenEnd = tokenEnd; } int getTokenEnd() { return this.tokenEnd; } public String toString() { return ("[ (" + tokenType + ") (" + getTokenText() + ")"); } } jaxen-1.1.6/src/java/main/org/jaxen/saxpath/base/XPathReader.java0000664000175000017500000007316311114301330024077 0ustar ebourgebourg/* * $Header$ * $Revision: 1334 $ * $Date: 2008-11-29 18:58:48 +0100 (Sat, 29 Nov 2008) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: XPathReader.java 1334 2008-11-29 17:58:48Z elharo $ */ package org.jaxen.saxpath.base; import java.util.ArrayList; import org.jaxen.saxpath.Axis; import org.jaxen.saxpath.Operator; import org.jaxen.saxpath.SAXPathException; import org.jaxen.saxpath.XPathHandler; import org.jaxen.saxpath.XPathSyntaxException; import org.jaxen.saxpath.helpers.DefaultXPathHandler; /** Implementation of SAXPath's XPathReader which * generates callbacks to an XPathHandler. * * @author bob mcwhirter (bob@werken.com) */ public class XPathReader implements org.jaxen.saxpath.XPathReader { private ArrayList tokens; private XPathLexer lexer; private XPathHandler handler; private static XPathHandler defaultHandler = new DefaultXPathHandler(); /** * Create a new XPathReader with a do-nothing * XPathHandler. */ public XPathReader() { setXPathHandler( defaultHandler ); } public void setXPathHandler(XPathHandler handler) { this.handler = handler; } public XPathHandler getXPathHandler() { return this.handler; } public void parse(String xpath) throws SAXPathException { setUpParse( xpath ); getXPathHandler().startXPath(); expr(); getXPathHandler().endXPath(); if ( LA(1) != TokenTypes.EOF ) { XPathSyntaxException ex = createSyntaxException( "Unexpected '" + LT(1).getTokenText() + "'" ); throw ex; } lexer = null; tokens = null; } void setUpParse(String xpath) { this.tokens = new ArrayList(); this.lexer = new XPathLexer( xpath ); } private void pathExpr() throws SAXPathException { getXPathHandler().startPathExpr(); switch ( LA(1) ) { case TokenTypes.DOUBLE: case TokenTypes.LITERAL: { filterExpr(); if ( LA(1) == TokenTypes.SLASH || LA(1) == TokenTypes.DOUBLE_SLASH ) { XPathSyntaxException ex = createSyntaxException("Node-set expected"); throw ex; } break; } case TokenTypes.LEFT_PAREN: case TokenTypes.DOLLAR: { filterExpr(); if ( LA(1) == TokenTypes.SLASH || LA(1) == TokenTypes.DOUBLE_SLASH) { locationPath( false ); } break; } case TokenTypes.IDENTIFIER: { if ( ( LA(2) == TokenTypes.LEFT_PAREN && ! isNodeTypeName( LT(1) ) ) || ( LA(2) == TokenTypes.COLON && LA(4) == TokenTypes.LEFT_PAREN) ) { filterExpr(); if ( LA(1) == TokenTypes.SLASH || LA(1) == TokenTypes.DOUBLE_SLASH) { locationPath( false ); } } else { locationPath( false ); } break; } case TokenTypes.DOT: case TokenTypes.DOT_DOT: case TokenTypes.STAR: case TokenTypes.AT: { locationPath( false ); break; } case TokenTypes.SLASH: case TokenTypes.DOUBLE_SLASH: { locationPath( true ); break; } default: { XPathSyntaxException ex = createSyntaxException( "Unexpected '" + LT(1).getTokenText() + "'" ); throw ex; } } getXPathHandler().endPathExpr(); } private void literal() throws SAXPathException { Token token = match( TokenTypes.LITERAL ); getXPathHandler().literal( token.getTokenText() ); } private void functionCall() throws SAXPathException { String prefix = null; String functionName = null; if ( LA(2) == TokenTypes.COLON ) { prefix = match( TokenTypes.IDENTIFIER ).getTokenText(); match( TokenTypes.COLON ); } else { prefix = ""; } functionName = match( TokenTypes.IDENTIFIER ).getTokenText(); getXPathHandler().startFunction( prefix, functionName ); match ( TokenTypes.LEFT_PAREN ); arguments(); match ( TokenTypes.RIGHT_PAREN ); getXPathHandler().endFunction(); } private void arguments() throws SAXPathException { while ( LA(1) != TokenTypes.RIGHT_PAREN ) { expr(); if ( LA(1) == TokenTypes.COMMA ) { match( TokenTypes.COMMA ); } else { break; } } } private void filterExpr() throws SAXPathException { getXPathHandler().startFilterExpr(); switch ( LA(1) ) { case TokenTypes.DOUBLE: { Token token = match( TokenTypes.DOUBLE ); getXPathHandler().number( Double.parseDouble( token.getTokenText() ) ); break; } case TokenTypes.LITERAL: { literal(); break; } case TokenTypes.LEFT_PAREN: { match( TokenTypes.LEFT_PAREN ); expr(); match( TokenTypes.RIGHT_PAREN ); break; } case TokenTypes.IDENTIFIER: { functionCall(); break; } case TokenTypes.DOLLAR: { variableReference(); break; } } predicates(); getXPathHandler().endFilterExpr(); } private void variableReference() throws SAXPathException { match( TokenTypes.DOLLAR ); String prefix = null; String variableName = null; if ( LA(2) == TokenTypes.COLON ) { prefix = match( TokenTypes.IDENTIFIER ).getTokenText(); match( TokenTypes.COLON ); } else { prefix = ""; } variableName = match( TokenTypes.IDENTIFIER ).getTokenText(); getXPathHandler().variableReference( prefix, variableName ); } void locationPath(boolean isAbsolute) throws SAXPathException { switch ( LA(1) ) { case TokenTypes.SLASH: case TokenTypes.DOUBLE_SLASH: { if ( isAbsolute ) { absoluteLocationPath(); } else { relativeLocationPath(); } break; } case TokenTypes.AT: case TokenTypes.IDENTIFIER: case TokenTypes.DOT: case TokenTypes.DOT_DOT: case TokenTypes.STAR: { relativeLocationPath(); break; } default: { XPathSyntaxException ex = createSyntaxException( "Unexpected '" + LT(1).getTokenText() + "'" ); throw ex; } } } private void absoluteLocationPath() throws SAXPathException { getXPathHandler().startAbsoluteLocationPath(); switch ( LA(1) ) { case TokenTypes.SLASH: { match( TokenTypes.SLASH ); switch ( LA(1) ) { case TokenTypes.DOT: case TokenTypes.DOT_DOT: case TokenTypes.AT: case TokenTypes.IDENTIFIER: case TokenTypes.STAR: { steps(); break; } } break; } case TokenTypes.DOUBLE_SLASH: { getXPathHandler().startAllNodeStep( Axis.DESCENDANT_OR_SELF ); getXPathHandler().endAllNodeStep(); match( TokenTypes.DOUBLE_SLASH ); switch ( LA(1) ) { case TokenTypes.DOT: case TokenTypes.DOT_DOT: case TokenTypes.AT: case TokenTypes.IDENTIFIER: case TokenTypes.STAR: { steps(); break; } default: XPathSyntaxException ex = this.createSyntaxException("Location path cannot end with //"); throw ex; } break; } } getXPathHandler().endAbsoluteLocationPath(); } private void relativeLocationPath() throws SAXPathException { getXPathHandler().startRelativeLocationPath(); switch ( LA(1) ) { case TokenTypes.SLASH: { match( TokenTypes.SLASH ); break; } case TokenTypes.DOUBLE_SLASH: { getXPathHandler().startAllNodeStep( Axis.DESCENDANT_OR_SELF ); getXPathHandler().endAllNodeStep(); match( TokenTypes.DOUBLE_SLASH ); break; } } steps(); getXPathHandler().endRelativeLocationPath(); } private void steps() throws SAXPathException { switch ( LA(1) ) { case TokenTypes.DOT: case TokenTypes.DOT_DOT: case TokenTypes.AT: case TokenTypes.IDENTIFIER: case TokenTypes.STAR: { step(); break; } case TokenTypes.EOF: { return; } default: { XPathSyntaxException ex = createSyntaxException( "Expected one of '.', '..', '@', '*', " ); throw ex; } } do { if ( ( LA(1) == TokenTypes.SLASH) || ( LA(1) == TokenTypes.DOUBLE_SLASH ) ) { switch ( LA(1) ) { case TokenTypes.SLASH: { match( TokenTypes.SLASH ); break; } case TokenTypes.DOUBLE_SLASH: { getXPathHandler().startAllNodeStep( Axis.DESCENDANT_OR_SELF ); getXPathHandler().endAllNodeStep(); match( TokenTypes.DOUBLE_SLASH ); break; } } } else { return; } switch ( LA(1) ) { case TokenTypes.DOT: case TokenTypes.DOT_DOT: case TokenTypes.AT: case TokenTypes.IDENTIFIER: case TokenTypes.STAR: { step(); break; } default: { XPathSyntaxException ex = createSyntaxException( "Expected one of '.', '..', '@', '*', " ); throw ex; } } } while ( true ); } void step() throws SAXPathException { int axis = 0; switch ( LA(1) ) { case TokenTypes.DOT: case TokenTypes.DOT_DOT: { abbrStep(); return; } case TokenTypes.AT: { axis = axisSpecifier(); break; } case TokenTypes.IDENTIFIER: { if ( LA(2) == TokenTypes.DOUBLE_COLON ) { axis = axisSpecifier(); } else { axis = Axis.CHILD; } break; } case TokenTypes.STAR: { axis = Axis.CHILD; break; } } nodeTest( axis ); } private int axisSpecifier() throws SAXPathException { int axis = 0; switch ( LA(1) ) { case TokenTypes.AT: { match( TokenTypes.AT ); axis = Axis.ATTRIBUTE; break; } case TokenTypes.IDENTIFIER: { Token token = LT( 1 ); axis = Axis.lookup( token.getTokenText() ); if ( axis == Axis.INVALID_AXIS ) { throwInvalidAxis( token.getTokenText() ); } match( TokenTypes.IDENTIFIER ); match( TokenTypes.DOUBLE_COLON ); break; } } return axis; } private void nodeTest(int axis) throws SAXPathException { switch ( LA(1) ) { case TokenTypes.IDENTIFIER: { switch ( LA(2) ) { case TokenTypes.LEFT_PAREN: { nodeTypeTest( axis ); break; } default: { nameTest( axis ); break; } } break; } case TokenTypes.STAR: { nameTest( axis ); break; } default: XPathSyntaxException ex = createSyntaxException("Expected or *"); throw ex; } } private void nodeTypeTest(int axis) throws SAXPathException { Token nodeTypeToken = match( TokenTypes.IDENTIFIER ); String nodeType = nodeTypeToken.getTokenText(); match( TokenTypes.LEFT_PAREN ); if ( "processing-instruction".equals( nodeType ) ) { String piName = ""; if ( LA(1) == TokenTypes.LITERAL ) { piName = match( TokenTypes.LITERAL ).getTokenText(); } match( TokenTypes.RIGHT_PAREN ); getXPathHandler().startProcessingInstructionNodeStep( axis, piName ); predicates(); getXPathHandler().endProcessingInstructionNodeStep(); } else if ( "node".equals( nodeType ) ) { match( TokenTypes.RIGHT_PAREN ); getXPathHandler().startAllNodeStep( axis ); predicates(); getXPathHandler().endAllNodeStep(); } else if ( "text".equals( nodeType ) ) { match( TokenTypes.RIGHT_PAREN ); getXPathHandler().startTextNodeStep( axis ); predicates(); getXPathHandler().endTextNodeStep(); } else if ( "comment".equals( nodeType ) ) { match( TokenTypes.RIGHT_PAREN ); getXPathHandler().startCommentNodeStep( axis ); predicates(); getXPathHandler().endCommentNodeStep(); } else { XPathSyntaxException ex = createSyntaxException( "Expected node-type" ); throw ex; } } private void nameTest(int axis) throws SAXPathException { String prefix = null; String localName = null; switch ( LA(2) ) { case TokenTypes.COLON: { switch ( LA(1) ) { case TokenTypes.IDENTIFIER: { prefix = match( TokenTypes.IDENTIFIER ).getTokenText(); match( TokenTypes.COLON ); break; } } break; } } switch ( LA(1) ) { case TokenTypes.IDENTIFIER: { localName = match( TokenTypes.IDENTIFIER ).getTokenText(); break; } case TokenTypes.STAR: { match( TokenTypes.STAR ); localName = "*"; break; } } if ( prefix == null ) { prefix = ""; } getXPathHandler().startNameStep( axis, prefix, localName ); predicates(); getXPathHandler().endNameStep(); } private void abbrStep() throws SAXPathException { switch ( LA(1) ) { case TokenTypes.DOT: { match( TokenTypes.DOT ); getXPathHandler().startAllNodeStep( Axis.SELF ); predicates(); getXPathHandler().endAllNodeStep(); break; } case TokenTypes.DOT_DOT: { match( TokenTypes.DOT_DOT ); getXPathHandler().startAllNodeStep( Axis.PARENT ); predicates(); getXPathHandler().endAllNodeStep(); break; } } } private void predicates() throws SAXPathException { while (true ) { if ( LA(1) == TokenTypes.LEFT_BRACKET ) { predicate(); } else { break; } } } void predicate() throws SAXPathException { getXPathHandler().startPredicate(); match( TokenTypes.LEFT_BRACKET ); predicateExpr(); match( TokenTypes.RIGHT_BRACKET ); getXPathHandler().endPredicate(); } private void predicateExpr() throws SAXPathException { expr(); } private void expr() throws SAXPathException { orExpr(); } private void orExpr() throws SAXPathException { getXPathHandler().startOrExpr(); andExpr(); boolean create = false; switch ( LA(1) ) { case TokenTypes.OR: { create = true; match( TokenTypes.OR ); orExpr(); break; } } getXPathHandler().endOrExpr( create ); } private void andExpr() throws SAXPathException { getXPathHandler().startAndExpr(); equalityExpr(); boolean create = false; switch ( LA(1) ) { case TokenTypes.AND: { create = true; match( TokenTypes.AND ); andExpr(); break; } } getXPathHandler().endAndExpr( create ); } private void equalityExpr() throws SAXPathException { relationalExpr(); int la = LA(1); while (la == TokenTypes.EQUALS || la == TokenTypes.NOT_EQUALS) { switch ( la ) { case TokenTypes.EQUALS: { match( TokenTypes.EQUALS ); getXPathHandler().startEqualityExpr(); relationalExpr(); getXPathHandler().endEqualityExpr( Operator.EQUALS ); break; } case TokenTypes.NOT_EQUALS: { match( TokenTypes.NOT_EQUALS ); getXPathHandler().startEqualityExpr(); relationalExpr(); getXPathHandler().endEqualityExpr( Operator.NOT_EQUALS ); break; } } la = LA(1); } } private void relationalExpr() throws SAXPathException { additiveExpr(); int la = LA(1); // Very important: TokenTypes.LESS_THAN != Operator.LESS_THAN // TokenTypes.GREATER_THAN != Operator.GREATER_THAN // TokenTypes.GREATER_THAN_EQUALS != Operator.GREATER_THAN_EQUALS // TokenTypes.LESS_THAN_EQUALS != Operator.LESS_THAN_EQUALS while (la == TokenTypes.LESS_THAN_SIGN || la == TokenTypes.GREATER_THAN_SIGN || la == TokenTypes.LESS_THAN_OR_EQUALS_SIGN || la == TokenTypes.GREATER_THAN_OR_EQUALS_SIGN ) { switch ( la ) { case TokenTypes.LESS_THAN_SIGN: { match( TokenTypes.LESS_THAN_SIGN ); getXPathHandler().startRelationalExpr(); additiveExpr(); getXPathHandler().endRelationalExpr( Operator.LESS_THAN ); break; } case TokenTypes.GREATER_THAN_SIGN: { match( TokenTypes.GREATER_THAN_SIGN ); getXPathHandler().startRelationalExpr(); additiveExpr(); getXPathHandler().endRelationalExpr( Operator.GREATER_THAN ); break; } case TokenTypes.GREATER_THAN_OR_EQUALS_SIGN: { match( TokenTypes.GREATER_THAN_OR_EQUALS_SIGN ); getXPathHandler().startRelationalExpr(); additiveExpr(); getXPathHandler().endRelationalExpr( Operator.GREATER_THAN_EQUALS ); break; } case TokenTypes.LESS_THAN_OR_EQUALS_SIGN: { match( TokenTypes.LESS_THAN_OR_EQUALS_SIGN ); getXPathHandler().startRelationalExpr(); additiveExpr(); getXPathHandler().endRelationalExpr( Operator.LESS_THAN_EQUALS ); break; } } la = LA(1); } } private void additiveExpr() throws SAXPathException { multiplicativeExpr(); int la = LA(1); while (la == TokenTypes.PLUS || la == TokenTypes.MINUS) { switch ( la ) { case TokenTypes.PLUS: { match( TokenTypes.PLUS ); getXPathHandler().startAdditiveExpr(); multiplicativeExpr(); getXPathHandler().endAdditiveExpr( Operator.ADD ); break; } case TokenTypes.MINUS: { match( TokenTypes.MINUS ); getXPathHandler().startAdditiveExpr(); multiplicativeExpr(); getXPathHandler().endAdditiveExpr( Operator.SUBTRACT ); break; } } la = LA(1); } } private void multiplicativeExpr() throws SAXPathException { unaryExpr(); int la = LA(1); while (la == TokenTypes.STAR_OPERATOR || la == TokenTypes.DIV || la == TokenTypes.MOD) { switch ( la ) { case TokenTypes.STAR: case TokenTypes.STAR_OPERATOR: { match( TokenTypes.STAR_OPERATOR ); getXPathHandler().startMultiplicativeExpr(); unaryExpr(); getXPathHandler().endMultiplicativeExpr( Operator.MULTIPLY ); break; } case TokenTypes.DIV: { match( TokenTypes.DIV ); getXPathHandler().startMultiplicativeExpr(); unaryExpr(); getXPathHandler().endMultiplicativeExpr( Operator.DIV ); break; } case TokenTypes.MOD: { match( TokenTypes.MOD ); getXPathHandler().startMultiplicativeExpr(); unaryExpr(); getXPathHandler().endMultiplicativeExpr( Operator.MOD ); break; } } la = LA(1); } } private void unaryExpr() throws SAXPathException { switch ( LA(1) ) { case TokenTypes.MINUS: { getXPathHandler().startUnaryExpr(); match( TokenTypes.MINUS ); unaryExpr(); getXPathHandler().endUnaryExpr( Operator.NEGATIVE ); break; } default: { unionExpr(); break; } } } private void unionExpr() throws SAXPathException { getXPathHandler().startUnionExpr(); pathExpr(); boolean create = false; switch ( LA(1) ) { case TokenTypes.PIPE: { match( TokenTypes.PIPE ); create = true; expr(); break; } } getXPathHandler().endUnionExpr( create ); } private Token match(int tokenType) throws XPathSyntaxException { LT(1); Token token = (Token) tokens.get( 0 ); if ( token.getTokenType() == tokenType ) { tokens.remove(0); return token; } XPathSyntaxException ex = createSyntaxException( "Expected: " + TokenTypes.getTokenText( tokenType ) ); throw ex; } private int LA(int position) { return LT(position).getTokenType(); } // XXX This method's a HotSpot; could we improve it? private Token LT(int position) { if ( tokens.size() <= ( position - 1 ) ) { for ( int i = 0 ; i < position ; ++i ) { tokens.add( lexer.nextToken() ); } } return (Token) tokens.get( position - 1 ); } private boolean isNodeTypeName(Token name) { String text = name.getTokenText(); if ( "node".equals( text ) || "comment".equals( text ) || "text".equals( text ) || "processing-instruction".equals( text ) ) { return true; } return false; } private XPathSyntaxException createSyntaxException(String message) { String xpath = this.lexer.getXPath(); int position = LT(1).getTokenBegin(); return new XPathSyntaxException( xpath, position, message ); } private void throwInvalidAxis(String invalidAxis) throws SAXPathException { String xpath = this.lexer.getXPath(); int position = LT(1).getTokenBegin(); String message = "Expected valid axis name instead of [" + invalidAxis + "]"; throw new XPathSyntaxException( xpath, position, message ); } } jaxen-1.1.6/src/java/main/org/jaxen/saxpath/base/XPathLexer.java0000664000175000017500000005674411114301330023762 0ustar ebourgebourg/* * $Header$ * $Revision: 1334 $ * $Date: 2008-11-29 18:58:48 +0100 (Sat, 29 Nov 2008) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: XPathLexer.java 1334 2008-11-29 17:58:48Z elharo $ */ package org.jaxen.saxpath.base; class XPathLexer { private String xpath; private int currentPosition; private int endPosition; private boolean expectOperator = false; XPathLexer(String xpath) { setXPath( xpath ); } private void setXPath(String xpath) { this.xpath = xpath; this.currentPosition = 0; this.endPosition = xpath.length(); } String getXPath() { return this.xpath; } Token nextToken() { Token token = null; do { token = null; switch ( LA(1) ) { case '$': { token = dollar(); break; } case '"': case '\'': { token = literal(); break; } case '/': { token = slashes(); break; } case ',': { token = comma(); break; } case '(': { token = leftParen(); break; } case ')': { token = rightParen(); break; } case '[': { token = leftBracket(); break; } case ']': { token = rightBracket(); break; } case '+': { token = plus(); break; } case '-': { token = minus(); break; } case '<': case '>': { token = relationalOperator(); break; } case '=': { token = equals(); break; } case '!': { if ( LA(2) == '=' ) { token = notEquals(); } break; } case '|': { token = pipe(); break; } case '@': { token = at(); break; } case ':': { if ( LA(2) == ':' ) { token = doubleColon(); } else { token = colon(); } break; } case '*': { token = star(); break; } case '.': { switch ( LA(2) ) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { token = number(); break; } default: { token = dots(); break; } } break; } case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { token = number(); break; } case ' ': case '\t': case '\n': case '\r': { token = whitespace(); break; } default: { if ( Verifier.isXMLNCNameStartCharacter( LA(1) ) ) { token = identifierOrOperatorName(); } } } if ( token == null ) { if (!hasMoreChars()) { token = new Token( TokenTypes.EOF, getXPath(), this.currentPosition, this.endPosition ); } else { token = new Token( TokenTypes.ERROR, getXPath(), this.currentPosition, this.endPosition ); } } } while (token.getTokenType() == TokenTypes.SKIP ); // For some reason, section 3.7, Lexical structure, // doesn't seem to feel like it needs to mention the // SLASH, DOUBLE_SLASH, and COLON tokens for the test // if an NCName is an operator or not. // // According to section 3.7, "/foo" should be considered // as a SLASH following by an OperatorName being 'foo'. // Which is just simply, clearly, wrong, in my mind. // // -bob switch ( token.getTokenType() ) { case TokenTypes.AT: case TokenTypes.DOUBLE_COLON: case TokenTypes.LEFT_PAREN: case TokenTypes.LEFT_BRACKET: case TokenTypes.AND: case TokenTypes.OR: case TokenTypes.MOD: case TokenTypes.DIV: case TokenTypes.COLON: case TokenTypes.SLASH: case TokenTypes.DOUBLE_SLASH: case TokenTypes.PIPE: case TokenTypes.DOLLAR: case TokenTypes.PLUS: case TokenTypes.MINUS: case TokenTypes.STAR_OPERATOR: case TokenTypes.COMMA: case TokenTypes.LESS_THAN_SIGN: case TokenTypes.GREATER_THAN_SIGN: case TokenTypes.LESS_THAN_OR_EQUALS_SIGN: case TokenTypes.GREATER_THAN_OR_EQUALS_SIGN: case TokenTypes.EQUALS: case TokenTypes.NOT_EQUALS: { expectOperator = false; break; } default: { expectOperator = true; break; } } return token; } private Token identifierOrOperatorName() { Token token = null; if ( expectOperator ) { token = operatorName(); } else { token = identifier(); } return token; } private Token identifier() { Token token = null; int start = this.currentPosition; while ( hasMoreChars() ) { if ( Verifier.isXMLNCNameCharacter( LA(1) ) ) { consume(); } else { break; } } token = new Token( TokenTypes.IDENTIFIER, getXPath(), start, this.currentPosition ); return token; } private Token operatorName() { Token token = null; switch ( LA(1) ) { case 'a': { token = and(); break; } case 'o': { token = or(); break; } case 'm': { token = mod(); break; } case 'd': { token = div(); break; } } return token; } private Token mod() { Token token = null; if ( ( LA(1) == 'm' ) && ( LA(2) == 'o' ) && ( LA(3) == 'd' ) ) { token = new Token( TokenTypes.MOD, getXPath(), this.currentPosition, this.currentPosition+3 ); consume(); consume(); consume(); } return token; } private Token div() { Token token = null; if ( ( LA(1) == 'd' ) && ( LA(2) == 'i' ) && ( LA(3) == 'v' ) ) { token = new Token( TokenTypes.DIV, getXPath(), this.currentPosition, this.currentPosition+3 ); consume(); consume(); consume(); } return token; } private Token and() { Token token = null; if ( ( LA(1) == 'a' ) && ( LA(2) == 'n' ) && ( LA(3) == 'd' ) ) { token = new Token( TokenTypes.AND, getXPath(), this.currentPosition, this.currentPosition+3 ); consume(); consume(); consume(); } return token; } private Token or() { Token token = null; if ( ( LA(1) == 'o' ) && ( LA(2) == 'r' ) ) { token = new Token( TokenTypes.OR, getXPath(), this.currentPosition, this.currentPosition+2 ); consume(); consume(); } return token; } private Token number() { int start = this.currentPosition; boolean periodAllowed = true; loop: while( true ) { switch ( LA(1) ) { case '.': if ( periodAllowed ) { periodAllowed = false; consume(); } else { break loop; } break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': consume(); break; default: break loop; } } return new Token( TokenTypes.DOUBLE, getXPath(), start, this.currentPosition ); } private Token whitespace() { consume(); loop: while( hasMoreChars() ) { switch ( LA(1) ) { case ' ': case '\t': case '\n': case '\r': { consume(); break; } default: { break loop; } } } return new Token( TokenTypes.SKIP, getXPath(), 0, 0 ); } private Token comma() { Token token = new Token( TokenTypes.COMMA, getXPath(), this.currentPosition, this.currentPosition+1 ); consume(); return token; } private Token equals() { Token token = new Token( TokenTypes.EQUALS, getXPath(), this.currentPosition, this.currentPosition+1 ); consume(); return token; } private Token minus() { Token token = new Token( TokenTypes.MINUS, getXPath(), this.currentPosition, this.currentPosition+1 ); consume(); return token; } private Token plus() { Token token = new Token( TokenTypes.PLUS, getXPath(), this.currentPosition, this.currentPosition+1 ); consume(); return token; } private Token dollar() { Token token = new Token( TokenTypes.DOLLAR, getXPath(), this.currentPosition, this.currentPosition+1 ); consume(); return token; } private Token pipe() { Token token = new Token( TokenTypes.PIPE, getXPath(), this.currentPosition, this.currentPosition+1 ); consume(); return token; } private Token at() { Token token = new Token( TokenTypes.AT, getXPath(), this.currentPosition, this.currentPosition+1 ); consume(); return token; } private Token colon() { Token token = new Token( TokenTypes.COLON, getXPath(), this.currentPosition, this.currentPosition+1 ); consume(); return token; } private Token doubleColon() { Token token = new Token( TokenTypes.DOUBLE_COLON, getXPath(), this.currentPosition, this.currentPosition+2 ); consume(); consume(); return token; } private Token notEquals() { Token token = new Token( TokenTypes.NOT_EQUALS, getXPath(), this.currentPosition, this.currentPosition + 2 ); consume(); consume(); return token; } private Token relationalOperator() { Token token = null; switch ( LA(1) ) { case '<': { if ( LA(2) == '=' ) { token = new Token( TokenTypes.LESS_THAN_OR_EQUALS_SIGN, getXPath(), this.currentPosition, this.currentPosition + 2 ); consume(); } else { token = new Token( TokenTypes.LESS_THAN_SIGN, getXPath(), this.currentPosition, this.currentPosition + 1); } consume(); break; } case '>': { if ( LA(2) == '=' ) { token = new Token( TokenTypes.GREATER_THAN_OR_EQUALS_SIGN, getXPath(), this.currentPosition, this.currentPosition + 2 ); consume(); } else { token = new Token( TokenTypes.GREATER_THAN_SIGN, getXPath(), this.currentPosition, this.currentPosition + 1 ); } consume(); break; } } return token; } // ???? private Token star() { int tokenType = expectOperator ? TokenTypes.STAR_OPERATOR : TokenTypes.STAR; Token token = new Token( tokenType, getXPath(), this.currentPosition, this.currentPosition+1 ); consume(); return token; } private Token literal() { Token token = null; char match = LA(1); consume(); int start = this.currentPosition; while ( ( token == null ) && hasMoreChars() ) { if ( LA(1) == match ) { token = new Token( TokenTypes.LITERAL, getXPath(), start, this.currentPosition ); } consume(); } return token; } private Token dots() { Token token = null; switch ( LA(2) ) { case '.': { token = new Token( TokenTypes.DOT_DOT, getXPath(), this.currentPosition, this.currentPosition+2 ) ; consume(); consume(); break; } default: { token = new Token( TokenTypes.DOT, getXPath(), this.currentPosition, this.currentPosition+1 ); consume(); break; } } return token; } private Token leftBracket() { Token token = new Token( TokenTypes.LEFT_BRACKET, getXPath(), this.currentPosition, this.currentPosition+1 ); consume(); return token; } private Token rightBracket() { Token token = new Token( TokenTypes.RIGHT_BRACKET, getXPath(), this.currentPosition, this.currentPosition+1 ); consume(); return token; } private Token leftParen() { Token token = new Token( TokenTypes.LEFT_PAREN, getXPath(), this.currentPosition, this.currentPosition+1 ); consume(); return token; } private Token rightParen() { Token token = new Token( TokenTypes.RIGHT_PAREN, getXPath(), this.currentPosition, this.currentPosition+1 ); consume(); return token; } private Token slashes() { Token token = null; switch ( LA(2) ) { case '/': { token = new Token( TokenTypes.DOUBLE_SLASH, getXPath(), this.currentPosition, this.currentPosition+2 ); consume(); consume(); break; } default: { token = new Token( TokenTypes.SLASH, getXPath(), this.currentPosition, this.currentPosition+1 ); consume(); } } return token; } private char LA(int i) { if ( currentPosition + ( i - 1 ) >= this.endPosition ) { return (char) -1; } return getXPath().charAt( this.currentPosition + (i - 1) ); } private void consume() { ++this.currentPosition; } private boolean hasMoreChars() { return this.currentPosition < this.endPosition; } } jaxen-1.1.6/src/java/main/org/jaxen/saxpath/base/TokenTypes.java0000664000175000017500000001444011114301330024026 0ustar ebourgebourg/* * $Header$ * $Revision: 1334 $ * $Date: 2008-11-29 18:58:48 +0100 (Sat, 29 Nov 2008) $ * * ==================================================================== * * Copyright 2000-2004 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: TokenTypes.java 1334 2008-11-29 17:58:48Z elharo $ */ package org.jaxen.saxpath.base; class TokenTypes { static final int EOF = -1; static final int SKIP = -2; static final int ERROR = -3; static final int EQUALS = 1; static final int NOT_EQUALS = 2; static final int LESS_THAN_SIGN = 3; static final int LESS_THAN_OR_EQUALS_SIGN = 4; static final int GREATER_THAN_SIGN = 5; static final int GREATER_THAN_OR_EQUALS_SIGN = 6; static final int PLUS = 7; static final int MINUS = 8; static final int STAR = 9; static final int MOD = 10; static final int DIV = 11; static final int SLASH = 12; static final int DOUBLE_SLASH = 13; static final int DOT = 14; static final int DOT_DOT = 15; static final int IDENTIFIER = 16; static final int AT = 17; static final int PIPE = 18; static final int COLON = 19; static final int DOUBLE_COLON = 20; static final int LEFT_BRACKET = 21; static final int RIGHT_BRACKET = 22; static final int LEFT_PAREN = 23; static final int RIGHT_PAREN = 24; // 25 was NOT but there is no such token in XPath static final int DOLLAR = 25; static final int LITERAL = 26; static final int AND = 27; static final int OR = 28; // No need for an integer token type. All numbers // in XPath are doubles. static final int DOUBLE = 29; static final int COMMA = 30; // split star into two token types static final int STAR_OPERATOR = 31; static String getTokenText( int tokenType ) { switch( tokenType ) { case ERROR: return "(error)"; case SKIP: return "(skip)"; case EOF: return "(eof)"; case 0: return "Unrecognized token type: 0"; case EQUALS: return "="; case NOT_EQUALS: return "!="; case LESS_THAN_SIGN: return "<"; case LESS_THAN_OR_EQUALS_SIGN: return "<="; case GREATER_THAN_SIGN: return ">"; case GREATER_THAN_OR_EQUALS_SIGN: return ">="; case PLUS: return "+"; case MINUS: return "-"; case STAR: return "*"; case STAR_OPERATOR: return "*"; case DIV: return "div"; case MOD: return "mod"; case SLASH: return "/"; case DOUBLE_SLASH: return "//"; case DOT: return "."; case DOT_DOT: return ".."; case IDENTIFIER: return "(identifier)"; case AT: return "@"; case PIPE: return "|"; case COLON: return ":"; case DOUBLE_COLON: return "::"; case LEFT_BRACKET: return "["; case RIGHT_BRACKET: return "]"; case LEFT_PAREN: return "("; case RIGHT_PAREN: return ")"; case DOLLAR: return "$"; case LITERAL: return "(literal)"; case AND: return "and"; case OR: return "or"; case DOUBLE: return "(double)"; case COMMA: return ","; default: // This method is only called from an error handler, and only // to provide an exception message. In other words, the string // returned by this method is only used in an exception message. // Something has already gone wrong, and is being reported. // Thus there's no real reason to throw another exception here. // Just return a string and this message will be reported in an // exception anyway. return("Unrecognized token type: " + tokenType); } } } jaxen-1.1.6/src/java/main/org/jaxen/saxpath/base/package.html0000664000175000017500000000030307677626263023372 0ustar ebourgebourg com.jaxen.saxpath.*

jaxen implementation of the SAXPath functionality.

jaxen-1.1.6/src/java/main/org/jaxen/saxpath/XPathReader.java0000664000175000017500000000543710371471320023177 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: XPathReader.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.saxpath; /** Interface for readers which can parse textual * XPath expressions, and produce callbacks to * {@link org.jaxen.saxpath.XPathHandler} objects. * * @author bob mcwhirter (bob@werken.com) */ public interface XPathReader extends SAXPathEventSource { /** Parse an XPath expression, * and send event callbacks to an {@link org.jaxen.saxpath.XPathHandler}. * * @param xpath the textual XPath expression to parse * * @throws SAXPathException if the expression is syntactically incorrect */ void parse(String xpath) throws SAXPathException; } jaxen-1.1.6/src/java/main/org/jaxen/saxpath/XPathHandler.java0000664000175000017500000003061410371471320023345 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: XPathHandler.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.saxpath; /** Interface for event-based XPath parsing. * *

* A {@link org.jaxen.saxpath.XPathReader} generates callbacks into * an XPathHandler to allow for custom * handling of the parse. *

* *

* The callbacks very closely match the productions * listed in the W3C XPath specification. Gratuitous * productions (e.g. Expr/startExpr()/endExpr()) are not * included in this API. *

* * @author bob mcwhirter (bob@werken.com) */ public interface XPathHandler { /** Receive notification of the start of an XPath expression parse. */ void startXPath() throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the end of an XPath expression parse. */ void endXPath() throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the start of a path expression. */ void startPathExpr() throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the end of a path expression. */ void endPathExpr() throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the start of an absolute location path expression. */ void startAbsoluteLocationPath() throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the end of an absolute location path expression. */ void endAbsoluteLocationPath() throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the start of a relative location path expression. */ void startRelativeLocationPath() throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the end of a relative location path expression. */ void endRelativeLocationPath() throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the start of a name step. * * @param axis the axis of this step * @param prefix the namespace prefix for the name to test, * or the empty string if no prefix is specified * @param localName the local part of the name to test */ void startNameStep(int axis, String prefix, String localName) throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the end of a NameStep */ void endNameStep() throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the start of a text() step. * * @param axis the axis of this step */ void startTextNodeStep(int axis) throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the end of a text() step. */ void endTextNodeStep() throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the start of a comment() step. * * @param axis the axis of this step */ void startCommentNodeStep(int axis) throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the end of a comment() step. */ void endCommentNodeStep() throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the start of a node() step. * * @param axis the axis of this step */ void startAllNodeStep(int axis) throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the end of a node() step. */ void endAllNodeStep() throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the start of a processing-instruction(...) step. * * @param axis the axis of this step * @param name the name of the processing-instruction, or * the empty string if none is specified */ void startProcessingInstructionNodeStep(int axis, String name) throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the end of a processing-instruction(...) step. */ void endProcessingInstructionNodeStep() throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the start of a predicate. */ void startPredicate() throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the end of a predicate. */ void endPredicate() throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the start of a filter expression. */ void startFilterExpr() throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the end of a filter expression. */ void endFilterExpr() throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the start of an 'or' expression. */ void startOrExpr() throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the end of an 'or' expression. * * @param create flag that indicates if this expression * should truly be instantiated, or if it was just * a pass-through, based upon the grammar productions */ void endOrExpr(boolean create) throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the start of an 'and' expression. */ void startAndExpr() throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the end of an 'and' expression. * * @param create flag that indicates if this expression * should truly be instantiated, or if it was just * a pass-through, based upon the grammar productions */ void endAndExpr(boolean create) throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the start of an equality ('=' or '!=') expression. */ void startEqualityExpr() throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the end of an equality ('=' or '!=') expression. * * @param equalityOperator the operator specific to this particular * equality expression. If null, this expression * is only a pass-through, and should not actually * be instantiated. */ void endEqualityExpr(int equalityOperator) throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the start of a relational ('<', '>', '<=', or '>=') expression. */ void startRelationalExpr() throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the start of a relational ('<', '>', '<=', or '>=') expression. * * @param relationalOperator the operator specific to this particular * relational expression. If NO_OP, this expression * is only a pass-through, and should not actually * be instantiated. */ void endRelationalExpr(int relationalOperator) throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the start of an additive ('+' or '-') expression. */ void startAdditiveExpr() throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the end of an additive ('+' or '-') expression. * * @param additiveOperator the operator specific to this particular * additive expression. If NO_OP, this expression * is only a pass-through, and should not actually * be instantiated. */ void endAdditiveExpr(int additiveOperator) throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the start of a multiplicative ('*', 'div' or 'mod') expression. */ void startMultiplicativeExpr() throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the start of a multiplicative ('*', 'div' or 'mod') expression. * * @param multiplicativeOperator the operator specific to this particular * multiplicative expression. If null, this expression * is only a pass-through, and should not actually * be instantiated. */ void endMultiplicativeExpr(int multiplicativeOperator) throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the start of a unary ('+' or '-') expression. */ void startUnaryExpr() throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the end of a unary ('+' or '-') expression. * * @param unaryOperator the operator specific to this particular * unary expression. If NO_OP, this expression is only * a pass-through, and should not actually be instantiated. * If not {@link org.jaxen.saxpath.Operator#NO_OP}, it will * always be {@link org.jaxen.saxpath.Operator#NEGATIVE}. */ void endUnaryExpr(int unaryOperator) throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the start of a union ('|') expression. */ void startUnionExpr() throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the end of a union ('|') expression. * * @param create flag that indicates if this expression * should truly be instantiated, or if it was just * a pass-through, based upon the grammar productions */ void endUnionExpr(boolean create) throws org.jaxen.saxpath.SAXPathException; /** Receive notification of a number expression. * * @param number the number value */ void number(int number) throws org.jaxen.saxpath.SAXPathException; /** Receive notification of a number expression. * * @param number the number value */ void number(double number) throws org.jaxen.saxpath.SAXPathException; /** Receive notification of a literal expression. * * @param literal the string literal value */ void literal(String literal) throws org.jaxen.saxpath.SAXPathException; /** Receive notification of a variable-reference expression. * * @param prefix the namespace prefix of the variable * @param variableName the local name of the variable */ void variableReference(String prefix, String variableName) throws org.jaxen.saxpath.SAXPathException; /** Receive notification of a function call. * * @param prefix the namespace prefix of the function * @param functionName the local name of the function */ void startFunction(String prefix, String functionName) throws org.jaxen.saxpath.SAXPathException; /** Receive notification of the end of a function call */ void endFunction() throws org.jaxen.saxpath.SAXPathException; } jaxen-1.1.6/src/java/main/org/jaxen/saxpath/helpers/0000775000175000017500000000000012174247550021627 5ustar ebourgebourgjaxen-1.1.6/src/java/main/org/jaxen/saxpath/helpers/XPathReaderFactory.java0000664000175000017500000001357710502610002026161 0ustar ebourgebourg/* * $Header$ * $Revision: 1193 $ * $Date: 2006-09-15 22:41:38 +0200 (Fri, 15 Sep 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: XPathReaderFactory.java 1193 2006-09-15 20:41:38Z elharo $ */ package org.jaxen.saxpath.helpers; import org.jaxen.saxpath.SAXPathException; import org.jaxen.saxpath.XPathReader; /** Create an {@link org.jaxen.saxpath.XPathReader} from * either a system property, or a named class. * *

* Similar to the SAX API, the XPathReaderFactory * can create an XPathReader from a name of a * class passed in directly, or by inspecting the system * property org.saxpath.driver. * * @author bob mcwhirter (bob@werken.com) */ public class XPathReaderFactory { /** The org.saxpath.driver property name. */ public static final String DRIVER_PROPERTY = "org.saxpath.driver"; /** The default driver to use if none is configured. */ protected static final String DEFAULT_DRIVER = "org.jaxen.saxpath.base.XPathReader"; private XPathReaderFactory() {} /** Create an XPathReader using the value of * the org.saxpath.driver system property. * * @return an instance of the XPathReader specified * by the org.saxpath.driver property * * @throws SAXPathException if the property is not set, or if * the class can not be instantiated for some reason, * or if the class doesn't implement the XPathReader * interface */ public static XPathReader createReader() throws SAXPathException { String className = null; try { className = System.getProperty( DRIVER_PROPERTY ); } catch (SecurityException e) { // we'll use the default } if ( className == null || className.length() == 0 ) { className = DEFAULT_DRIVER; } return createReader( className ); } /** Create an XPathReader using the passed * in class name. * * @param className the name of the class that implements * the XPathReader interface. * * @return an XPathReader * * @throws SAXPathException if the class cannot be * instantiated for some reason, or if the * class doesn't implement the XPathReader * interface */ public static XPathReader createReader(String className) throws SAXPathException { Class readerClass = null; XPathReader reader = null; try { // Use the full version of Class.forName(), so as to // work better in sandboxed environments, such as // servlet containers and applets. readerClass = Class.forName( className, true, XPathReaderFactory.class.getClassLoader() ); // Double-check that it's actually the right kind of class // before attempting instantiation. if ( ! XPathReader.class.isAssignableFrom( readerClass ) ) { throw new SAXPathException( "Class [" + className + "] does not implement the org.jaxen.saxpath.XPathReader interface." ); } } catch (ClassNotFoundException e) { throw new SAXPathException( e ); } try { reader = (XPathReader) readerClass.newInstance(); } catch (IllegalAccessException e) { throw new SAXPathException( e ); } catch (InstantiationException e) { throw new SAXPathException( e ); } return reader; } } jaxen-1.1.6/src/java/main/org/jaxen/saxpath/helpers/DefaultXPathHandler.java0000664000175000017500000001467510371471320026325 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DefaultXPathHandler.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.saxpath.helpers; import org.jaxen.saxpath.SAXPathException; import org.jaxen.saxpath.XPathHandler; /** Default base class for SAXPath event handlers. This class is available as a convenience base class for SAXPath applications: it provides a default do-nothing implementation for all of the callbacks in the core SAXPath handler class, {@link org.jaxen.saxpath.XPathHandler}. Application writers can extend this class when they need to implement only part of the XPathHandler interface. Parser writers can instantiate this class to provide default handlers when the application has not supplied its own. */ public class DefaultXPathHandler implements XPathHandler { public void startXPath() throws SAXPathException { } public void endXPath() throws SAXPathException { } public void startPathExpr() throws SAXPathException { } public void endPathExpr() throws SAXPathException { } public void startAbsoluteLocationPath() throws SAXPathException { } public void endAbsoluteLocationPath() throws SAXPathException { } public void startRelativeLocationPath() throws SAXPathException { } public void endRelativeLocationPath() throws SAXPathException { } public void startNameStep(int axis, String prefix, String localName) throws SAXPathException { } public void endNameStep() throws SAXPathException { } public void startTextNodeStep(int axis) throws SAXPathException { } public void endTextNodeStep() throws SAXPathException { } public void startCommentNodeStep(int axis) throws SAXPathException { } public void endCommentNodeStep() throws SAXPathException { } public void startAllNodeStep(int axis) throws SAXPathException { } public void endAllNodeStep() throws SAXPathException { } public void startProcessingInstructionNodeStep(int axis, String name) throws SAXPathException { } public void endProcessingInstructionNodeStep() throws SAXPathException { } public void startPredicate() throws SAXPathException { } public void endPredicate() throws SAXPathException { } public void startFilterExpr() throws SAXPathException { } public void endFilterExpr() throws SAXPathException { } public void startOrExpr() throws SAXPathException { } public void endOrExpr(boolean create) throws SAXPathException { } public void startAndExpr() throws SAXPathException { } public void endAndExpr(boolean create) throws SAXPathException { } public void startEqualityExpr() throws SAXPathException { } public void endEqualityExpr(int operator) throws SAXPathException { } public void startRelationalExpr() throws SAXPathException { } public void endRelationalExpr(int operator) throws SAXPathException { } public void startAdditiveExpr() throws SAXPathException { } public void endAdditiveExpr(int operator) throws SAXPathException { } public void startMultiplicativeExpr() throws SAXPathException { } public void endMultiplicativeExpr(int operator) throws SAXPathException { } public void startUnaryExpr() throws SAXPathException { } public void endUnaryExpr(int operator) throws SAXPathException { } public void startUnionExpr() throws SAXPathException { } public void endUnionExpr(boolean create) throws SAXPathException { } public void number(int number) throws SAXPathException { } public void number(double number) throws SAXPathException { } public void literal(String literal) throws SAXPathException { } public void variableReference(String prefix, String variableName) throws SAXPathException { } public void startFunction(String prefix, String functionName) throws SAXPathException { } public void endFunction() throws SAXPathException { } } jaxen-1.1.6/src/java/main/org/jaxen/saxpath/helpers/package.html0000664000175000017500000000024507677626263024127 0ustar ebourgebourg org.jaxen.saxpath.helpers.*

Helper classes for instantiating XPathReaders.

jaxen-1.1.6/src/java/main/org/jaxen/saxpath/Axis.java0000664000175000017500000001556310412761624021742 0ustar ebourgebourg/* * $Header$ * $Revision: 1133 $ * $Date: 2006-03-30 15:56:36 +0200 (Thu, 30 Mar 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: Axis.java 1133 2006-03-30 13:56:36Z elharo $ */ package org.jaxen.saxpath; import org.jaxen.JaxenRuntimeException; /** * * Internal SAXPath class that contains constants representing * XPath operators to avoid a lot of string comparisons. */ public class Axis { private Axis() {} // XXX Ultimately these should use the type-safe enum pattern instead /** Marker for an invalid axis */ public final static int INVALID_AXIS = 0; /** The child axis */ public final static int CHILD = 1; /** The descendant axis */ public final static int DESCENDANT = 2; /** The parent axis */ public final static int PARENT = 3; /** The ancestor axis */ public final static int ANCESTOR = 4; /** The following-sibling axis */ public final static int FOLLOWING_SIBLING = 5; /** The preceding-sibling axis */ public final static int PRECEDING_SIBLING = 6; /** The following axis */ public final static int FOLLOWING = 7; /** The preceding axis */ public final static int PRECEDING = 8; /** The attribute axis */ public final static int ATTRIBUTE = 9; /** The namespace axis */ public final static int NAMESPACE = 10; /** The self axis */ public final static int SELF = 11; /** The descendant-or-self axis */ public final static int DESCENDANT_OR_SELF = 12; /** The ancestor-or-self axis */ public final static int ANCESTOR_OR_SELF = 13; /** *

* Returns the name of the axis. *

* * @param axisNum the axis code * @return the name of the axis such as might be used in an XPath expression * @throws JaxenRuntimeException if the number does not represent one of the 13 * XPath axes */ public static String lookup(int axisNum) { switch ( axisNum ) { case CHILD: return "child"; case DESCENDANT: return "descendant"; case PARENT: return "parent"; case ANCESTOR: return "ancestor"; case FOLLOWING_SIBLING: return "following-sibling"; case PRECEDING_SIBLING: return "preceding-sibling"; case FOLLOWING: return "following"; case PRECEDING: return "preceding"; case ATTRIBUTE: return "attribute"; case NAMESPACE: return "namespace"; case SELF: return "self"; case DESCENDANT_OR_SELF: return "descendant-or-self"; case ANCESTOR_OR_SELF: return "ancestor-or-self"; } throw new JaxenRuntimeException("Illegal Axis Number"); } /** *

* Returns the code for an axis given its name. *

* * @param axisName the name of the axis: child, parent, descendant, descendant-or-self, etc. * @return the axis code */ public static int lookup(String axisName) { // XXX All these equals calls are a small HotSpot; // Need to replace this with a static HashMap if ( "child".equals( axisName ) ) { return CHILD; } if ( "descendant".equals( axisName ) ) { return DESCENDANT; } if ( "parent".equals( axisName ) ) { return PARENT; } if ( "ancestor".equals( axisName ) ) { return ANCESTOR; } if ( "following-sibling".equals( axisName ) ) { return FOLLOWING_SIBLING; } if ( "preceding-sibling".equals( axisName ) ) { return PRECEDING_SIBLING; } if ( "following".equals( axisName ) ) { return FOLLOWING; } if ( "preceding".equals( axisName ) ) { return PRECEDING; } if ( "attribute".equals( axisName ) ) { return ATTRIBUTE; } if ( "namespace".equals( axisName ) ) { return NAMESPACE; } if ( "self".equals( axisName ) ) { return SELF; } if ( "descendant-or-self".equals( axisName ) ) { return DESCENDANT_OR_SELF; } if ( "ancestor-or-self".equals( axisName ) ) { return ANCESTOR_OR_SELF; } return INVALID_AXIS; } } jaxen-1.1.6/src/java/main/org/jaxen/saxpath/package.html0000664000175000017500000000027707677626263022472 0ustar ebourgebourg org.jaxen.saxpath.*

Classes related to the event-based parsing and handling of XPath expressions.

jaxen-1.1.6/src/java/main/org/jaxen/saxpath/SAXPathEventSource.java0000664000175000017500000000557610371471320024467 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: SAXPathEventSource.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.saxpath; /** Interface for any object capable of generating * SAXPath events to an {@link org.jaxen.saxpath.XPathHandler}. * * @author bob mcwhirter (bob@werken.com) */ public interface SAXPathEventSource { /** Set the {@link org.jaxen.saxpath.XPathHandler} to receive * event callbacks during the parse. * * @param handler the handler to receive callbacks */ void setXPathHandler(XPathHandler handler); /** Retrieve the current {@link org.jaxen.saxpath.XPathHandler} * which receives the event callbacks. * * @return the currently installed XPathHandler */ XPathHandler getXPathHandler(); } jaxen-1.1.6/src/java/main/org/jaxen/JaxenConstants.java0000664000175000017500000000545310371471320022320 0ustar ebourgebourgpackage org.jaxen; /* * $Header: $ * $Revision: $ * $Date: $ * * ==================================================================== * * Copyright 2000-2005 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: $ */ import java.util.Collections; import java.util.Iterator; import java.util.ListIterator; /** * Thread-safe constant iterators used to avoid the overhead of creating * empty lists. */ public class JaxenConstants { private JaxenConstants() {} /** * An iterator with no elements. hasNext() always * returns false. This is thread-safe. */ public static final Iterator EMPTY_ITERATOR = Collections.EMPTY_LIST.iterator(); /** * A list iterator with no elements. hasNext() always * returns false. This is thread-safe. */ public static final ListIterator EMPTY_LIST_ITERATOR = Collections.EMPTY_LIST.listIterator(); } jaxen-1.1.6/src/java/main/org/jaxen/NamespaceContext.java0000664000175000017500000000741510452203147022617 0ustar ebourgebourg/* * $Header$ * $Revision: 1168 $ * $Date: 2006-07-03 13:58:31 +0200 (Mon, 03 Jul 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: NamespaceContext.java 1168 2006-07-03 11:58:31Z elharo $ */ package org.jaxen; /** Resolves namespace prefixes to namespace URIs. * *

* The prefixes used within an XPath expression are * independent of those used within any target document. * When evaluating an XPath against a document, only * the resolved namespace URIs are compared, not their * prefixes. *

* *

* A NamespaceContext is responsible for * translating prefixes as they appear in XPath expressions * into URIs for comparison. A document's prefixes are * resolved internal to the document based upon its own * namespace nodes. *

* *

* Implementations of this interface should implement Serializable. *

* * @see BaseXPath * @see Navigator#getElementNamespaceUri * @see Navigator#getAttributeNamespaceUri * * @author bob mcwhirter */ public interface NamespaceContext { /** Translate the provided namespace prefix into * the matching bound namespace URI. * *

* In XPath, there is no such thing as a 'default namespace'. * The empty prefix always resolves to the empty * namespace URI. This method should return null for the * empty prefix. * Similarly, the prefix "xml" always resolves to * the URI "http://www.w3.org/XML/1998/namespace". *

* * @param prefix the namespace prefix to resolve * * @return the namespace URI bound to the prefix; or null if there * is no such namespace */ String translateNamespacePrefixToUri(String prefix); } jaxen-1.1.6/src/java/main/org/jaxen/UnresolvableException.java0000664000175000017500000000537010440370076023677 0ustar ebourgebourg/* * $Header$ * $Revision: 1159 $ * $Date: 2006-06-03 22:25:34 +0200 (Sat, 03 Jun 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: UnresolvableException.java 1159 2006-06-03 20:25:34Z elharo $ */ package org.jaxen; /** Thrown when a function-call or variable-reference, or any other lookup * based on namespace and local name, couldn't be resolved. * * @author Erwin Bolwidt (ejb @ klomp.org) */ public class UnresolvableException extends JaxenException { /** * */ private static final long serialVersionUID = 953578478331961473L; /** * Create a new UnresolvableException. * * @param message the detail message */ public UnresolvableException(String message) { super( message ); } } jaxen-1.1.6/src/java/main/org/jaxen/FunctionContext.java0000664000175000017500000001000110371471320022471 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: FunctionContext.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen; /** Implemented by classes that know how to resolve XPath function names and * namespaces to implementations of these functions. * *

* By using a custom FunctionContext, new or different * functions may be installed and available to XPath expression writers. *

* * @see XPathFunctionContext * * @author bob mcwhirter */ public interface FunctionContext { /** An implementation should return a Function implementation object * based on the namespace URI and local name of the function-call * expression. * *

* It must not use the prefix parameter to select an implementation, * because a prefix could be bound to any namespace; the prefix parameter * could be used in debugging output or other generated information. * The prefix may otherwise be completely ignored. *

* * @param namespaceURI the namespace URI to which the prefix parameter * is bound in the XPath expression. If the function * call expression had no prefix, the namespace URI * is null. * @param prefix the prefix that was used in the function call * expression * @param localName the local name of the function-call expression. * If there is no prefix, then this is the whole * name of the function. * * @return a Function implementation object. * @throws UnresolvableException when the function cannot be resolved */ Function getFunction( String namespaceURI, String prefix, String localName ) throws UnresolvableException; } jaxen-1.1.6/src/java/main/org/jaxen/jdom/0000775000175000017500000000000012174247547017454 5ustar ebourgebourgjaxen-1.1.6/src/java/main/org/jaxen/jdom/DocumentNavigator.java0000664000175000017500000004144510504475765023760 0ustar ebourgebourgpackage org.jaxen.jdom; /* * $Header$ * $Revision: 1198 $ * $Date: 2006-09-21 13:48:05 +0200 (Thu, 21 Sep 2006) $ * * ==================================================================== * * Copyright 2000-2005 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DocumentNavigator.java 1198 2006-09-21 11:48:05Z elharo $ */ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import org.jaxen.DefaultNavigator; import org.jaxen.FunctionCallException; import org.jaxen.NamedAccessNavigator; import org.jaxen.Navigator; import org.jaxen.XPath; import org.jaxen.JaxenConstants; import org.jaxen.saxpath.SAXPathException; import org.jaxen.util.SingleObjectIterator; import org.jdom.Attribute; import org.jdom.CDATA; import org.jdom.Comment; import org.jdom.Document; import org.jdom.Element; import org.jdom.Namespace; import org.jdom.ProcessingInstruction; import org.jdom.Text; import org.jdom.input.SAXBuilder; /** * Interface for navigating around the JDOM object model. * *

* This class is not intended for direct usage, but is * used by the Jaxen engine during evaluation. *

* * @see XPath * * @author bob mcwhirter * @author Stephen Colebourne */ public class DocumentNavigator extends DefaultNavigator implements NamedAccessNavigator { /** * */ private static final long serialVersionUID = -1636727587303584165L; /** Singleton implementation. */ private static class Singleton { /** Singleton instance. */ private static DocumentNavigator instance = new DocumentNavigator(); } public static Navigator getInstance() { return Singleton.instance; } public boolean isElement(Object obj) { return obj instanceof Element; } public boolean isComment(Object obj) { return obj instanceof Comment; } public boolean isText(Object obj) { return ( obj instanceof Text || obj instanceof CDATA ); } public boolean isAttribute(Object obj) { return obj instanceof Attribute; } public boolean isProcessingInstruction(Object obj) { return obj instanceof ProcessingInstruction; } public boolean isDocument(Object obj) { return obj instanceof Document; } public boolean isNamespace(Object obj) { return obj instanceof Namespace || obj instanceof XPathNamespace; } public String getElementName(Object obj) { Element elem = (Element) obj; return elem.getName(); } public String getElementNamespaceUri(Object obj) { Element elem = (Element) obj; String uri = elem.getNamespaceURI(); if ( uri != null && uri.length() == 0 ) return null; else return uri; } public String getAttributeName(Object obj) { Attribute attr = (Attribute) obj; return attr.getName(); } public String getAttributeNamespaceUri(Object obj) { Attribute attr = (Attribute) obj; String uri = attr.getNamespaceURI(); if ( uri != null && uri.length() == 0 ) return null; else return uri; } public Iterator getChildAxisIterator(Object contextNode) { if ( contextNode instanceof Element ) { return ((Element)contextNode).getContent().iterator(); } else if ( contextNode instanceof Document ) { return ((Document)contextNode).getContent().iterator(); } return JaxenConstants.EMPTY_ITERATOR; } /** * Retrieves an Iterator over the child elements that * match the supplied local name and namespace URI. * * @param contextNode the origin context node * @param localName the local name of the children to return, always present * @param namespacePrefix ignored; prefixes are not used when matching in XPath * @param namespaceURI the URI of the namespace of the children to return * @return an Iterator that traverses the named children, or null if none */ public Iterator getChildAxisIterator( Object contextNode, String localName, String namespacePrefix, String namespaceURI) { if ( contextNode instanceof Element ) { Element node = (Element) contextNode; if (namespaceURI == null) { return node.getChildren(localName).iterator(); } return node.getChildren(localName, Namespace.getNamespace(namespacePrefix, namespaceURI)).iterator(); } if ( contextNode instanceof Document ) { Document node = (Document) contextNode; Element el = node.getRootElement(); if (el.getName().equals(localName) == false) { return JaxenConstants.EMPTY_ITERATOR; } if (namespaceURI != null) { // JDOM's equals method does not consider the prefix when comparing namespace objects if (!Namespace.getNamespace(namespacePrefix, namespaceURI).equals(el.getNamespace())) { return JaxenConstants.EMPTY_ITERATOR; } } else if(el.getNamespace() != Namespace.NO_NAMESPACE) { return JaxenConstants.EMPTY_ITERATOR; } return new SingleObjectIterator(el); } return JaxenConstants.EMPTY_ITERATOR; } public Iterator getNamespaceAxisIterator(Object contextNode) { if ( ! ( contextNode instanceof Element ) ) { return JaxenConstants.EMPTY_ITERATOR; } Element elem = (Element) contextNode; Map nsMap = new HashMap(); Element current = elem; while ( current != null ) { Namespace ns = current.getNamespace(); if ( ns != Namespace.NO_NAMESPACE ) { if ( !nsMap.containsKey(ns.getPrefix()) ) nsMap.put( ns.getPrefix(), new XPathNamespace(elem, ns) ); } Iterator additional = current.getAdditionalNamespaces().iterator(); while ( additional.hasNext() ) { ns = (Namespace)additional.next(); if ( !nsMap.containsKey(ns.getPrefix()) ) nsMap.put( ns.getPrefix(), new XPathNamespace(elem, ns) ); } Iterator attributes = current.getAttributes().iterator(); while ( attributes.hasNext() ) { Attribute attribute = (Attribute)attributes.next(); Namespace attrNS = attribute.getNamespace(); if ( attrNS != Namespace.NO_NAMESPACE ) { if ( !nsMap.containsKey(attrNS.getPrefix()) ) nsMap.put( attrNS.getPrefix(), new XPathNamespace(elem, attrNS) ); } } if (current.getParent() instanceof Element) { current = (Element)current.getParent(); } else { current = null; } } nsMap.put( "xml", new XPathNamespace(elem, Namespace.XML_NAMESPACE) ); return nsMap.values().iterator(); } public Iterator getParentAxisIterator(Object contextNode) { Object parent = null; if ( contextNode instanceof Document ) { return JaxenConstants.EMPTY_ITERATOR; } else if ( contextNode instanceof Element ) { parent = ((Element)contextNode).getParent(); if ( parent == null ) { if ( ((Element)contextNode).isRootElement() ) { parent = ((Element)contextNode).getDocument(); } } } else if ( contextNode instanceof Attribute ) { parent = ((Attribute)contextNode).getParent(); } else if ( contextNode instanceof XPathNamespace ) { parent = ((XPathNamespace)contextNode).getJDOMElement(); } else if ( contextNode instanceof ProcessingInstruction ) { parent = ((ProcessingInstruction)contextNode).getParent(); } else if ( contextNode instanceof Comment ) { parent = ((Comment)contextNode).getParent(); } else if ( contextNode instanceof Text ) { parent = ((Text)contextNode).getParent(); } if ( parent != null ) { return new SingleObjectIterator( parent ); } return JaxenConstants.EMPTY_ITERATOR; } public Iterator getAttributeAxisIterator(Object contextNode) { if ( ! ( contextNode instanceof Element ) ) { return JaxenConstants.EMPTY_ITERATOR; } Element elem = (Element) contextNode; return elem.getAttributes().iterator(); } /** * Retrieves an Iterator over the attribute elements that * match the supplied name. * * @param contextNode the origin context node * @param localName the local name of the attributes to return, always present * @param namespacePrefix the prefix of the namespace of the attributes to return * @param namespaceURI the URI of the namespace of the attributes to return * @return an Iterator that traverses the named attributes, not null */ public Iterator getAttributeAxisIterator( Object contextNode, String localName, String namespacePrefix, String namespaceURI) { if ( contextNode instanceof Element ) { Element node = (Element) contextNode; Namespace namespace = (namespaceURI == null ? Namespace.NO_NAMESPACE : Namespace.getNamespace(namespacePrefix, namespaceURI)); Attribute attr = node.getAttribute(localName, namespace); if (attr != null) { return new SingleObjectIterator(attr); } } return JaxenConstants.EMPTY_ITERATOR; } /** Returns a parsed form of the given XPath string, which will be suitable * for queries on JDOM documents. */ public XPath parseXPath (String xpath) throws SAXPathException { return new JDOMXPath(xpath); } public Object getDocumentNode(Object contextNode) { if ( contextNode instanceof Document ) { return contextNode; } Element elem = (Element) contextNode; return elem.getDocument(); } public String getElementQName(Object obj) { Element elem = (Element) obj; String prefix = elem.getNamespacePrefix(); if ( prefix == null || prefix.length() == 0 ) { return elem.getName(); } return prefix + ":" + elem.getName(); } public String getAttributeQName(Object obj) { Attribute attr = (Attribute) obj; String prefix = attr.getNamespacePrefix(); if ( prefix == null || "".equals( prefix ) ) { return attr.getName(); } return prefix + ":" + attr.getName(); } public String getNamespaceStringValue(Object obj) { if (obj instanceof Namespace) { Namespace ns = (Namespace) obj; return ns.getURI(); } else { XPathNamespace ns = (XPathNamespace) obj; return ns.getJDOMNamespace().getURI(); } } public String getNamespacePrefix(Object obj) { if (obj instanceof Namespace) { Namespace ns = (Namespace) obj; return ns.getPrefix(); } else { XPathNamespace ns = (XPathNamespace) obj; return ns.getJDOMNamespace().getPrefix(); } } public String getTextStringValue(Object obj) { if ( obj instanceof Text ) { return ((Text)obj).getText(); } if ( obj instanceof CDATA ) { return ((CDATA)obj).getText(); } return ""; } public String getAttributeStringValue(Object obj) { Attribute attr = (Attribute) obj; return attr.getValue(); } public String getElementStringValue(Object obj) { Element elem = (Element) obj; StringBuffer buf = new StringBuffer(); List content = elem.getContent(); Iterator contentIter = content.iterator(); Object each = null; while ( contentIter.hasNext() ) { each = contentIter.next(); if ( each instanceof Text ) { buf.append( ((Text)each).getText() ); } else if ( each instanceof CDATA ) { buf.append( ((CDATA)each).getText() ); } else if ( each instanceof Element ) { buf.append( getElementStringValue( each ) ); } } return buf.toString(); } public String getProcessingInstructionTarget(Object obj) { ProcessingInstruction pi = (ProcessingInstruction) obj; return pi.getTarget(); } public String getProcessingInstructionData(Object obj) { ProcessingInstruction pi = (ProcessingInstruction) obj; return pi.getData(); } public String getCommentStringValue(Object obj) { Comment cmt = (Comment) obj; return cmt.getText(); } public String translateNamespacePrefixToUri(String prefix, Object context) { Element element = null; if ( context instanceof Element ) { element = (Element) context; } else if ( context instanceof Text ) { element = (Element)((Text)context).getParent(); } else if ( context instanceof Attribute ) { element = ((Attribute)context).getParent(); } else if ( context instanceof XPathNamespace ) { element = ((XPathNamespace)context).getJDOMElement(); } else if ( context instanceof Comment ) { element = (Element)((Comment)context).getParent(); } else if ( context instanceof ProcessingInstruction ) { element = (Element)((ProcessingInstruction)context).getParent(); } if ( element != null ) { Namespace namespace = element.getNamespace( prefix ); if ( namespace != null ) { return namespace.getURI(); } } return null; } public Object getDocument(String url) throws FunctionCallException { try { SAXBuilder builder = new SAXBuilder(); return builder.build( url ); } catch (Exception e) { throw new FunctionCallException( e.getMessage() ); } } } jaxen-1.1.6/src/java/main/org/jaxen/jdom/XPathNamespace.java0000664000175000017500000000763410371471320023153 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: XPathNamespace.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.jdom; import org.jdom.Element; import org.jdom.Namespace; /** Wrapper for JDOM namespace nodes to give them a parent, as required * by the XPath data model. * * @author Erwin Bolwidt */ public class XPathNamespace { private Element jdomElement; private Namespace jdomNamespace; /** Creates a namespace-node wrapper for a namespace node that hasn't been * assigned to an element yet. */ public XPathNamespace( Namespace jdomNamespace ) { this.jdomNamespace = jdomNamespace; } /** Creates a namespace-node wrapper for a namespace node that is assigned * to the given JDOM element. */ public XPathNamespace( Element jdomElement, Namespace jdomNamespace ) { this.jdomElement = jdomElement; this.jdomNamespace = jdomNamespace; } /** Returns the JDOM element from which this namespace node has been * retrieved. The result may be null when the namespace node has not yet * been assigned to an element. */ public Element getJDOMElement() { return jdomElement; } /** Sets or changes the element to which this namespace node is assigned. */ public void setJDOMElement( Element jdomElement ) { this.jdomElement = jdomElement; } /** Returns the JDOM namespace object of this namespace node; the JDOM * namespace object contains the prefix and URI of the namespace. */ public Namespace getJDOMNamespace() { return jdomNamespace; } public String toString() { return ( "[xmlns:" + jdomNamespace.getPrefix() + "=\"" + jdomNamespace.getURI() + "\", element=" + jdomElement.getName() + "]" ); } } jaxen-1.1.6/src/java/main/org/jaxen/jdom/JDOMXPath.java0000664000175000017500000000670410440371260022004 0ustar ebourgebourg/* * $Header$ * $Revision: 1161 $ * $Date: 2006-06-03 22:36:00 +0200 (Sat, 03 Jun 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: JDOMXPath.java 1161 2006-06-03 20:36:00Z elharo $ */ package org.jaxen.jdom; import org.jaxen.BaseXPath; import org.jaxen.JaxenException; /** An XPath implementation for the JDOM model * *

This is the main entry point for matching an XPath against a DOM * tree. You create a compiled XPath object, then match it against * one or more context nodes using the {@link #selectNodes(Object)} * method, as in the following example:

* *
 * Object jdomNode = ...; // Document, Element etc.
 * XPath path = new JDOMXPath("a/b/c");
 * List results = path.selectNodes(jdomNode);
 * 
* * @see BaseXPath * @see The JDOM website * * @author bob mcwhirter * @author James Strachan * * @version $Revision: 1161 $ */ public class JDOMXPath extends BaseXPath { /** * */ private static final long serialVersionUID = 6426091824802286928L; /** Construct given an XPath expression string. * * @param xpathExpr the XPath expression. * * @throws JaxenException if there is a syntax error while * parsing the expression */ public JDOMXPath(String xpathExpr) throws JaxenException { super( xpathExpr, DocumentNavigator.getInstance() ); } } jaxen-1.1.6/src/java/main/org/jaxen/jdom/package.html0000664000175000017500000000024407327350513021725 0ustar ebourgebourg org.jaxen.jdom.*

Navigation for JDOM trees.

jaxen-1.1.6/src/java/main/org/jaxen/SimpleNamespaceContext.java0000664000175000017500000001263110440370076023770 0ustar ebourgebourg/* * $Header$ * $Revision: 1159 $ * $Date: 2006-06-03 22:25:34 +0200 (Sat, 03 Jun 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: SimpleNamespaceContext.java 1159 2006-06-03 20:25:34Z elharo $ */ package org.jaxen; import java.io.Serializable; import java.util.HashMap; import java.util.Iterator; import java.util.Map; /** * Provides mappings from namespace prefix to namespace URI to the XPath * engine. */ public class SimpleNamespaceContext implements NamespaceContext, Serializable { /** * */ private static final long serialVersionUID = -808928409643497762L; // XXX should this prebind the xml prefix? private Map namespaces; /** * Creates a new empty namespace context. */ public SimpleNamespaceContext() { this.namespaces = new HashMap(); } /** * Creates a new namespace context pre-populated with the specified bindings. * * @param namespaces the initial namespace bindings in scope. The keys in this * must be strings containing the prefixes and the values are strings * containing the namespace URIs. * * @throws NullPointerException if the argument is null * @throws ClassCastException if any keys or values in the map are not strings */ public SimpleNamespaceContext(Map namespaces) { Iterator entries = namespaces.entrySet().iterator(); while (entries.hasNext()) { Map.Entry entry = (Map.Entry) entries.next(); if (! (entry.getKey() instanceof String) || ! (entry.getValue() instanceof String)) { throw new ClassCastException("Non-string namespace binding"); } } this.namespaces = new HashMap(namespaces); } /** * Adds all the namespace declarations that are in scope on the given * element. In the case of an XSLT stylesheet, this would be the element * that has the XPath expression in one of its attributes; e.g. * <xsl:if test="condition/xpath/expression">. * * @param nav the navigator for use in conjunction with * element * @param element the element to copy the namespaces from * @throws UnsupportedAxisException if the navigator does not support the * namespace axis */ public void addElementNamespaces( Navigator nav, Object element ) throws UnsupportedAxisException { Iterator namespaceAxis = nav.getNamespaceAxisIterator( element ); while ( namespaceAxis.hasNext() ) { Object namespace = namespaceAxis.next(); String prefix = nav.getNamespacePrefix( namespace ); String uri = nav.getNamespaceStringValue( namespace ); if ( translateNamespacePrefixToUri(prefix) == null ) { addNamespace( prefix, uri ); } } } // ???? What if prefix or URI is null, or both? /** * Binds a prefix to a URI in this context. * * @param prefix the namespace prefix * @param URI the namespace URI */ public void addNamespace(String prefix, String URI) { this.namespaces.put( prefix, URI ); } public String translateNamespacePrefixToUri(String prefix) { if ( this.namespaces.containsKey( prefix ) ) { return (String) this.namespaces.get( prefix ); } return null; } } jaxen-1.1.6/src/java/main/org/jaxen/FunctionCallException.java0000664000175000017500000000767010456416755023640 0ustar ebourgebourg/* * $Header$ * $Revision: 1179 $ * $Date: 2006-07-16 13:07:25 +0200 (Sun, 16 Jul 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: FunctionCallException.java 1179 2006-07-16 11:07:25Z elharo $ */ package org.jaxen; /** * Thrown if an exception occurs during the evaluation of a function. * This exception may include a root exception--for instance an * IOException if the real problem was failure to * load an XML document via the XSLT document() function. * * @author bob mcwhirter (bob @ werken.com) * @author James Strachan */ public class FunctionCallException extends JaxenException { /** * */ private static final long serialVersionUID = 7908649612495640943L; /** * Create a new FunctionCallException with the specified detail message. * * @param message the detail message */ public FunctionCallException(String message) { super( message ); } /** * Create a new FunctionCallException with the specified root cause. * * @param nestedException the cause of this exception */ public FunctionCallException(Throwable nestedException) { super( nestedException ); } /** * Create a new FunctionCallException with the specified detail message * and root cause. * * @param message the detail message * @param nestedException the cause of this exception */ public FunctionCallException(String message, Exception nestedException) { super( message, nestedException ); } /** *

* Returns the exception that caused this function call to fail. * Use getCause instead. *

* * @return the exception that caused this function call to fail * * @deprecated replaced by {@link #getCause()} */ public Throwable getNestedException() { return getCause(); } } jaxen-1.1.6/src/java/main/org/jaxen/QualifiedName.java0000664000175000017500000000756710437564542022106 0ustar ebourgebourg/* * $Header$ * $Revision: 1154 $ * $Date: 2006-06-01 15:19:30 +0200 (Thu, 01 Jun 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: QualifiedName.java 1154 2006-06-01 13:19:30Z elharo $ */ package org.jaxen; import java.io.Serializable; /** A local name (that matches the XML NCName production) and a namespace URI * with which the local name is qualified. * * @author Erwin Bolwidt ( ejb@klomp.org ) */ class QualifiedName implements Serializable { private static final long serialVersionUID = 2734958615642751535L; private String namespaceURI; private String localName; /** Constructs a QualifiedName object. * * @param namespaceURI namespace URI that qualifies the name, or * null for default namespace * @param localName local name that is qualified by the namespace uri; * must not be null */ QualifiedName( String namespaceURI, String localName ) { if (namespaceURI == null) namespaceURI = ""; this.namespaceURI = namespaceURI; this.localName = localName; } public int hashCode() { return ( localName.hashCode() ^ namespaceURI.hashCode() ); } public boolean equals( Object o ) { // Because this class is package protected and used in only // two other classes, it's never actually compared to anything // other than another QualifiedName. No instanceof test is // necessary here. QualifiedName other = (QualifiedName) o; return ( namespaceURI.equals(other.namespaceURI) && other.localName.equals(localName) ); } /** * @return James Clark's namespace form */ String getClarkForm() { if ("".equals(namespaceURI)) return localName; else return "{" + namespaceURI + "}" + ":" + localName; } } jaxen-1.1.6/src/java/main/org/jaxen/xom/0000775000175000017500000000000012174247550017320 5ustar ebourgebourgjaxen-1.1.6/src/java/main/org/jaxen/xom/DocumentNavigator.java0000664000175000017500000002754410440365465023630 0ustar ebourgebourg/* * $Header$ * $Revision: 1156 $ * $Date: 2006-06-03 22:04:05 +0200 (Sat, 03 Jun 2006) $ * * ==================================================================== * * Copyright 2000-2003 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DocumentNavigator.java 1156 2006-06-03 20:04:05Z elharo $ */ package org.jaxen.xom; import nu.xom.Attribute; import nu.xom.Comment; import nu.xom.Document; import nu.xom.Element; import nu.xom.ProcessingInstruction; import nu.xom.Text; import nu.xom.Node; import nu.xom.Builder; import nu.xom.NodeFactory; import nu.xom.ParentNode; import org.jaxen.XPath; import org.jaxen.UnsupportedAxisException; import org.jaxen.FunctionCallException; import org.jaxen.BaseXPath; import org.jaxen.JaxenConstants; import org.jaxen.util.SingleObjectIterator; import org.jaxen.saxpath.SAXPathException; import java.util.Iterator; import java.util.HashMap; import java.util.Map; /** * Interface for navigating around the XOM object model. * *

* This class is not intended for direct usage, but is * used by the Jaxen engine during evaluation. *

* * @see XPath * */ public class DocumentNavigator extends org.jaxen.DefaultNavigator { /** * */ private static final long serialVersionUID = 3159311338575942877L; public boolean isAttribute(Object o) { return o instanceof Attribute; } public boolean isComment(Object o) { return o instanceof Comment; } public boolean isDocument(Object o) { return o instanceof Document; } public boolean isElement(Object o) { return o instanceof Element; } public boolean isNamespace(Object o) { return o instanceof XPathNamespace; } public boolean isProcessingInstruction(Object o) { return o instanceof ProcessingInstruction; } public boolean isText(Object o) { return o instanceof Text; } // public String getAttributeName(Object o) { return (isAttribute(o) ? ((Attribute)o).getLocalName() : null); } public String getAttributeNamespaceUri(Object o) { return (isAttribute(o) ? ((Attribute)o).getNamespaceURI() : null); } public String getAttributeQName(Object o) { return (isAttribute(o) ? ((Attribute)o).getQualifiedName() : null); } public String getAttributeStringValue(Object o) { return (isAttribute(o) ? ((Attribute)o).getValue() : null); } // public String getCommentStringValue(Object o) { return (isComment(o) ? ((Comment)o).getValue() : null); } public String getElementName(Object o) { return (isElement(o) ? ((Element)o).getLocalName() : null); } public String getElementNamespaceUri(Object o) { return (isElement(o) ? ((Element)o).getNamespaceURI() : null); } public String getElementQName(Object o) { return (isElement(o) ? ((Element)o).getQualifiedName() : null); } public String getElementStringValue(Object o) { return (o instanceof Node ? ((Node)o).getValue() : null); } // public String getNamespacePrefix(Object o) { if (isElement(o)) { return ((Element)o).getNamespacePrefix(); } else if (isAttribute(o)) { return ((Attribute)o).getNamespacePrefix(); } else if (o instanceof XPathNamespace) { return ((XPathNamespace)o).getNamespacePrefix(); } return null; } public String getNamespaceStringValue(Object o) { if (isElement(o)) { return ((Element)o).getNamespaceURI(); } else if (isAttribute(o)) { return ((Attribute)o).getNamespaceURI(); } else if (o instanceof XPathNamespace) { return ((XPathNamespace)o).getNamespaceURI(); } return null; } // public String getTextStringValue(Object o) { return (o instanceof Text ? ((Text)o).getValue() : null); } // public Object getDocument(String s) throws FunctionCallException { try { return new Builder(new NodeFactory()).build(s); } catch (Exception pe) { throw new FunctionCallException(pe); } } public Object getDocumentNode(Object o) { ParentNode parent = null; if (o instanceof ParentNode) { parent = (ParentNode)o; } else if (o instanceof Node) { parent = ((Node)o).getParent(); } return parent.getDocument(); } // private abstract static class IndexIterator implements Iterator { private Object o = null; private int pos = 0, end = -1; public IndexIterator(Object o, int pos, int end) { this.o = o; this.pos = pos; this.end = end; } public boolean hasNext() { return pos < end; } public abstract Object get(Object o, int i); public Object next() { return get(o, pos++); } public void remove() { throw new UnsupportedOperationException(); } } // public Iterator getAttributeAxisIterator(Object o) { if (isElement(o)) { return new IndexIterator(o, 0, ((Element)o).getAttributeCount()) { public Object get(Object o, int i) { return ((Element)o).getAttribute(i); } }; } return JaxenConstants.EMPTY_ITERATOR; } public Iterator getChildAxisIterator(Object o) { if (isElement(o) || (o instanceof Document)) { return new IndexIterator(o, 0, ((ParentNode)o).getChildCount()) { public Object get(Object o, int i) { return ((ParentNode)o).getChild(i); } }; } return JaxenConstants.EMPTY_ITERATOR; } // public Iterator getParentAxisIterator(Object o) { Object parent = null; if (o instanceof Node) { parent = ((Node)o).getParent(); } else if (isNamespace(o)) { parent = ((XPathNamespace)o).getElement(); } return (parent != null ? new SingleObjectIterator(parent) : null); } public Object getParentNode(Object o) { return (o instanceof Node ? ((Node)o).getParent() : null); } // public Iterator getPrecedingAxisIterator(Object o) throws UnsupportedAxisException { return super.getPrecedingAxisIterator(o); } public Iterator getPrecedingSiblingAxisIterator(Object o) throws UnsupportedAxisException { return super.getPrecedingSiblingAxisIterator(o); } // public String getProcessingInstructionData(Object o) { return (o instanceof ProcessingInstruction ? ((ProcessingInstruction)o).getValue() : null); } public String getProcessingInstructionTarget(Object o) { return (o instanceof ProcessingInstruction ? ((ProcessingInstruction)o).getTarget() : null); } // public String translateNamespacePrefixToUri(String s, Object o) { Element element = null; if (o instanceof Element) { element = (Element) o; } else if (o instanceof ParentNode) { } else if (o instanceof Node) { element = (Element)((Node)o).getParent(); } else if (o instanceof XPathNamespace) { element = ((XPathNamespace)o).getElement(); } if (element != null) { return element.getNamespaceURI(s); } return null; } // public XPath parseXPath(String s) throws SAXPathException { return new BaseXPath(s, this); } // /** Wrapper for XOM namespace nodes to give them a parent, * as required by the XPath data model. * * @author Erwin Bolwidt */ private static class XPathNamespace { private Element element; private String uri, prefix; public XPathNamespace(Element elt, String uri, String prefix) { element = elt; this.uri = uri; this.prefix = prefix; } /** Returns the XOM element from which this namespace node has been * retrieved. The result may be null when the namespace node has not yet * been assigned to an element. */ public Element getElement() { return element; } public String getNamespaceURI() { return uri; } public String getNamespacePrefix() { return prefix; } public String toString() { return ( "[xmlns:" + prefix + "=\"" + uri + "\", element=" + element.getLocalName() + "]" ); } } // private boolean addNamespaceForElement(Element elt, String uri, String prefix, Map map) { if (uri != null && uri.length() > 0 && (! map.containsKey(prefix))) { map.put(prefix, new XPathNamespace(elt, uri, prefix)); return true; } return false; } public Iterator getNamespaceAxisIterator(Object o) { if (! isElement(o)) { return JaxenConstants.EMPTY_ITERATOR; } Map nsMap = new HashMap(); Element elt = (Element)o; ParentNode parent = elt; while (parent instanceof Element) { elt = (Element)parent; String uri = elt.getNamespaceURI(); String prefix = elt.getNamespacePrefix(); addNamespaceForElement(elt, uri, prefix, nsMap); int count = elt.getNamespaceDeclarationCount(); for (int i = 0; i < count; i++) { prefix = elt.getNamespacePrefix(i); uri = elt.getNamespaceURI(prefix); addNamespaceForElement(elt, uri, prefix, nsMap); } parent = elt.getParent(); } addNamespaceForElement(elt, "http://www.w3.org/XML/1998/namespace", "xml", nsMap); return nsMap.values().iterator(); } } jaxen-1.1.6/src/java/main/org/jaxen/xom/XOMXPath.java0000664000175000017500000000646210440371260021571 0ustar ebourgebourg/* * $Header$ * $Revision: 1161 $ * $Date: 2006-06-03 22:36:00 +0200 (Sat, 03 Jun 2006) $ * * ==================================================================== * * Copyright 2000-2003 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: XOMXPath.java 1161 2006-06-03 20:36:00Z elharo $ */ package org.jaxen.xom; import org.jaxen.BaseXPath; import org.jaxen.JaxenException; /** An XPath implementation for the XOM model * *

This is the main entry point for matching an XPath against a DOM * tree. You create a compiled XPath object, then match it against * one or more context nodes using the {@link #selectNodes(Object)} * method, as in the following example:

* *
 * Object xomNode = ...; // Document, Element etc.
 * XPath path = new XOMXPath("a/b/c");
 * List results = path.selectNodes(xomNode);
 * 
* * @see BaseXPath * @see The XOM website * * @version $Revision: 1161 $ */ public class XOMXPath extends BaseXPath { /** * */ private static final long serialVersionUID = -5332108546921857671L; /** Construct given an XPath expression string. * * @param xpathExpr the XPath expression. * * @throws JaxenException if there is a syntax error while * parsing the expression */ public XOMXPath(String xpathExpr) throws JaxenException { super( xpathExpr, new DocumentNavigator()); } } jaxen-1.1.6/src/java/main/org/jaxen/xom/package.html0000664000175000017500000000050410616121705021570 0ustar ebourgebourg org.jaxen.xom.*

Navigation for XOM trees. Note that XOM includes its own navigator which is likely faster and less buggy than this one, though it doesn't provide access to the full Jaxen API.

jaxen-1.1.6/src/java/main/org/jaxen/SimpleFunctionContext.java0000664000175000017500000001133310371471320023654 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: SimpleFunctionContext.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen; import java.util.HashMap; /** Simple default implementation of FunctionContext. * *

* This is a simple table-based key-lookup implementation * for FunctionContext which can be programmatically * extended by registering additional functions. *

* * @see XPathFunctionContext * * @author bob mcwhirter */ public class SimpleFunctionContext implements FunctionContext { /** Table of functions. */ private HashMap functions; /** *

* Construct an empty function context. *

*/ public SimpleFunctionContext() { this.functions = new HashMap(); } /** Register a new function. * *

* By registering a new function, any XPath expression * that utilizes this FunctionContext may * refer to and use the new function. *

* *

* Functions may exist either in a namespace or not. * Namespace prefix-to-URI resolution is the responsibility * of a {@link NamespaceContext}. Within this FunctionContext * functions are only referenced using the URI, not * the prefix. *

* *

* The namespace URI of a function may be null * to indicate that it exists without a namespace. *

* * @param namespaceURI the namespace URI of the function to * be registered with this context * @param localName the non-prefixed local portion of the * function to be registered with this context * @param function a {@link Function} implementation object * to be used when evaluating the function */ public void registerFunction(String namespaceURI, String localName, Function function ) { this.functions.put( new QualifiedName(namespaceURI, localName), function ); } public Function getFunction(String namespaceURI, String prefix, String localName ) throws UnresolvableException { QualifiedName key = new QualifiedName( namespaceURI, localName ); if ( this.functions.containsKey(key) ) { return (Function) this.functions.get( key ); } else { throw new UnresolvableException( "No Such Function " + key.getClarkForm() ); } } } jaxen-1.1.6/src/java/main/org/jaxen/function/0000775000175000017500000000000012174247547020350 5ustar ebourgebourgjaxen-1.1.6/src/java/main/org/jaxen/function/LangFunction.java0000664000175000017500000001611110371471320023563 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: LangFunction.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function; import java.util.Iterator; import java.util.List; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.FunctionCallException; import org.jaxen.Navigator; import org.jaxen.UnsupportedAxisException; /** *

* 4.3 boolean lang(string) *

* *
*

* The lang function returns true or false depending on whether * the language of the context node as specified by * xml:lang attributes is the same as or is a sublanguage * of the language specified by the argument string. The language of the * context node is determined by the value of the xml:lang * * attribute on the context node, or, if the context node has no * xml:lang attribute, by the value of the * xml:lang attribute on the nearest ancestor of the * context node that has an xml:lang attribute. If there * is no such attribute, then lang * returns false. If there is such an attribute, then lang returns true if the attribute * value is equal to the argument ignoring case, or if there is some * suffix starting with - such that the attribute value * is equal to the argument ignoring that suffix of the attribute value * and ignoring case. For example, lang("en") would * return true if the context node is any of these five elements: *

* *
 *  <para xml:lang="en"/>
 *  <div xml:lang="en"><para/></div>
 *  <para xml:lang="EN"/>
 *  <para xml:lang="en-us"/>
 * 
* *
* * @author Attila Szegedi (szegedia @ freemail.hu) * @see XPath Specification */ public class LangFunction implements Function { private static final String LANG_LOCALNAME = "lang"; private static final String XMLNS_URI = "http://www.w3.org/XML/1998/namespace"; /** * Create a new LangFunction object. */ public LangFunction() {} /** *

* Determines whether or not the context node is written in the language specified * by the XPath string-value of args.get(0), * as determined by the nearest xml:lang attribute in scope. *

* * @param context the context in which to evaluate the lang() function * @param args the arguments to the lang function * @return a Boolean indicating whether the context node is written in * the specified language * @throws FunctionCallException if args does not have length one * */ public Object call(Context context, List args) throws FunctionCallException { if (args.size() != 1) { throw new FunctionCallException("lang() requires exactly one argument."); } Object arg = args.get(0); try { return evaluate(context.getNodeSet(), arg, context.getNavigator() ); } catch(UnsupportedAxisException e) { throw new FunctionCallException("Can't evaluate lang()", e); } } private static Boolean evaluate(List contextNodes, Object lang, Navigator nav) throws UnsupportedAxisException { return evaluate(contextNodes.get(0), StringFunction.evaluate(lang, nav), nav) ? Boolean.TRUE : Boolean.FALSE; } private static boolean evaluate(Object node, String lang, Navigator nav) throws UnsupportedAxisException { Object element = node; if (! nav.isElement(element)) { element = nav.getParentNode(node); } while (element != null && nav.isElement(element)) { Iterator attrs = nav.getAttributeAxisIterator(element); while(attrs.hasNext()) { Object attr = attrs.next(); if(LANG_LOCALNAME.equals(nav.getAttributeName(attr)) && XMLNS_URI.equals(nav.getAttributeNamespaceUri(attr))) { return isSublang(nav.getAttributeStringValue(attr), lang); } } element = nav.getParentNode(element); } return false; } private static boolean isSublang(String sublang, String lang) { if(sublang.equalsIgnoreCase(lang)) { return true; } int ll = lang.length(); return sublang.length() > ll && sublang.charAt(ll) == '-' && sublang.substring(0, ll).equalsIgnoreCase(lang); } } jaxen-1.1.6/src/java/main/org/jaxen/function/ConcatFunction.java0000664000175000017500000001110710371471320024111 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: ConcatFunction.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function; import java.util.Iterator; import java.util.List; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.FunctionCallException; import org.jaxen.Navigator; /** * 4.2 string concat(string,string,string*) *

* Concatenates its arguments and returns the resulting string. *

* * @author bob mcwhirter (bob@werken.com) * * @see Section 4.2 of the XPath Specification */ public class ConcatFunction implements Function { /** * Create a new ConcatFunction object. */ public ConcatFunction() {} /** * Concatenates the arguments and returns the resulting string. * Non-string items are first converted to strings as if by the * XPath string() function. * * @param context the context at the point in the * expression when the function is called * @param args the list of strings to be concatenated * * @return a String containing the concatenation of the items * of args * * @throws FunctionCallException if args has less than two items */ public Object call(Context context, List args) throws FunctionCallException { if ( args.size() >= 2 ) { return evaluate( args, context.getNavigator() ); } throw new FunctionCallException("concat() requires at least two arguments"); } /** * Converts each item in the list to a string and returns the * concatenation of these strings. * If necessary, each item is first converted to a String * as if by the XPath string() function. * * @param list the items to be concatenated * @param nav ignored * * @return the concatenation of the arguments */ public static String evaluate(List list, Navigator nav) { StringBuffer result = new StringBuffer(); Iterator argIter = list.iterator(); while ( argIter.hasNext() ) { result.append( StringFunction.evaluate( argIter.next(), nav ) ); } return result.toString(); } } jaxen-1.1.6/src/java/main/org/jaxen/function/StringFunction.java0000664000175000017500000002535610371471320024163 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: StringFunction.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.FunctionCallException; import org.jaxen.Navigator; import org.jaxen.UnsupportedAxisException; import org.jaxen.JaxenRuntimeException; import java.text.DecimalFormat; import java.text.NumberFormat; import java.text.DecimalFormatSymbols; import java.util.List; import java.util.Iterator; import java.util.Locale; /** *

* 4.2 string string(object) *

* * *
*

* The string function converts * an object to a string as follows: *

* *
    * *
  • *

    * A node-set is converted to a string by returning the string-value of the node in the node-set * that is first in document order. If * the node-set is empty, an empty string is returned. *

    *
  • * *
  • *

    * A number is converted to a string as follows *

    * *
      * *
    • *

      * NaN is converted to the string NaN *

      *
    • * *
    • *

      * positive zero is converted to the string 0 *

      *
    • * *
    • * *

      * negative zero is converted to the string 0 *

      *
    • * *
    • *

      * positive infinity is converted to the string Infinity *

      *
    • * *
    • *

      * negative infinity is converted to the string -Infinity * *

      *
    • * *
    • *

      * if the number is an integer, the number is represented in decimal * form as a Number with no decimal point and * no leading zeros, preceded by a minus sign (-) if * the number is negative *

      *
    • * *
    • *

      * otherwise, the number is represented in decimal form as a Number including a decimal point with at least * one digit before the decimal point and at least one digit after the * decimal point, preceded by a minus sign (-) if the * number is negative; there must be no leading zeros before the decimal * point apart possibly from the one required digit immediately before * the decimal point; beyond the one required digit after the decimal * point there must be as many, but only as many, more digits as are * needed to uniquely distinguish the number from all other IEEE 754 * numeric values. *

      * *
    • * *
    * *
  • * *
  • *

    * The boolean false value is converted to the string false. * The boolean true value is converted to the string true. *

    *
  • * *
  • *

    * An object of a type other than the four basic types is converted to a * string in a way that is dependent on that type. *

    * *
  • * *
* *

* If the argument is omitted, it defaults to a node-set with the * context node as its only member. *

* *
* * @author bob mcwhirter (bob @ werken.com) * @see Section 4.2 of the XPath Specification */ public class StringFunction implements Function { private static DecimalFormat format = (DecimalFormat) NumberFormat.getInstance(Locale.ENGLISH); static { DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.ENGLISH); symbols.setNaN("NaN"); symbols.setInfinity("Infinity"); format.setGroupingUsed(false); format.setMaximumFractionDigits(32); format.setDecimalFormatSymbols(symbols); } /** * Create a new StringFunction object. */ public StringFunction() {} /** * Returns the string-value of args.get(0) * or of the context node if args is empty. * * @param context the context at the point in the * expression where the function is called * @param args list with zero or one element * * @return a String * * @throws FunctionCallException if args has more than one item */ public Object call(Context context, List args) throws FunctionCallException { int size = args.size(); if ( size == 0 ) { return evaluate( context.getNodeSet(), context.getNavigator() ); } else if ( size == 1 ) { return evaluate( args.get(0), context.getNavigator() ); } throw new FunctionCallException( "string() takes at most argument." ); } /** * Returns the XPath string-value of obj. * This operation is only defined if obj is a node, node-set, * String, Number, or * Boolean. For other types this function * returns the empty string. * * @param obj the node, node-set, string, number, or boolean * whose string-value is calculated * @param nav the navigator used to calculate the string-value * * @return a String. May be empty but is never null. */ public static String evaluate(Object obj, Navigator nav) { try { // Workaround because XOM uses lists for Text nodes // so we need to check for that first if (nav != null && nav.isText(obj)) { return nav.getTextStringValue(obj); } if (obj instanceof List) { List list = (List) obj; if (list.isEmpty()) { return ""; } // do not recurse: only first list should unwrap obj = list.get(0); } if (nav != null) { // This stack of instanceof really suggests there's // a failure to take advantage of polymorphism here if (nav.isElement(obj)) { return nav.getElementStringValue(obj); } else if (nav.isAttribute(obj)) { return nav.getAttributeStringValue(obj); } else if (nav.isDocument(obj)) { Iterator childAxisIterator = nav.getChildAxisIterator(obj); while (childAxisIterator.hasNext()) { Object descendant = childAxisIterator.next(); if (nav.isElement(descendant)) { return nav.getElementStringValue(descendant); } } } else if (nav.isProcessingInstruction(obj)) { return nav.getProcessingInstructionData(obj); } else if (nav.isComment(obj)) { return nav.getCommentStringValue(obj); } else if (nav.isText(obj)) { return nav.getTextStringValue(obj); } else if (nav.isNamespace(obj)) { return nav.getNamespaceStringValue(obj); } } if (obj instanceof String) { return (String) obj; } else if (obj instanceof Boolean) { return stringValue(((Boolean) obj).booleanValue()); } else if (obj instanceof Number) { return stringValue(((Number) obj).doubleValue()); } } catch (UnsupportedAxisException e) { throw new JaxenRuntimeException(e); } return ""; } private static String stringValue(double value) { // DecimalFormat formats negative zero as "-0". // Therefore we need to test for zero explicitly here. if (value == 0) return "0"; // need to synchronize object for thread-safety String result = null; synchronized (format) { result = format.format(value); } return result; } private static String stringValue(boolean value) { return value ? "true" : "false"; } } jaxen-1.1.6/src/java/main/org/jaxen/function/SubstringAfterFunction.java0000664000175000017500000001313710371471320025651 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: SubstringAfterFunction.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function; import java.util.List; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.FunctionCallException; import org.jaxen.Navigator; /** *

4.2 string substring-after(string,string)

* * *
* The substring-after function returns the substring of the first argument string * that follows the first occurrence of the second argument string in the first * argument string, or the empty string if the first argument string does not contain the second argument string. * For example, substring-after("1999/04/01","/") returns 04/01, * and substring-after("1999/04/01","19") returns 99/04/01. *
* * @author bob mcwhirter (bob @ werken.com) * @see Section 4.2 of the XPath Specification */ public class SubstringAfterFunction implements Function { /** * Create a new SubstringAfterFunction object. */ public SubstringAfterFunction() {} /** * Returns the part of the string-value of the first item in args * that follows the string-value of the second item in args; * or the empty string if the second string is not a substring of the first string. * * @param context the context at the point in the * expression when the function is called * @param args a list that contains two items * * @return a String containing that * part of the string-value of the first item in args * that comes before the string-value of the second item in args * * @throws FunctionCallException if args does not have length two */ public Object call(Context context, List args) throws FunctionCallException { if (args.size() == 2) { return evaluate( args.get(0), args.get(1), context.getNavigator() ); } throw new FunctionCallException( "substring-after() requires two arguments." ); } /** * Returns the part of strArg that follows the first occurence * of matchArg; or the empty string if the * strArg does not contain matchArg * * @param strArg the string from which the substring is extracted * @param matchArg the string that marks the boundary of the substring * @param nav the Navigator used to calculate the string-values of * the first two arguments * * @return a String containing * the part of strArg that precedes the first occurence * of matchArg * */ public static String evaluate(Object strArg, Object matchArg, Navigator nav) { String str = StringFunction.evaluate( strArg, nav ); String match = StringFunction.evaluate( matchArg, nav ); int loc = str.indexOf(match); if ( loc < 0 ) { return ""; } return str.substring(loc+match.length()); } } jaxen-1.1.6/src/java/main/org/jaxen/function/NameFunction.java0000664000175000017500000001412010371471320023560 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: NameFunction.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function; import java.util.List; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.FunctionCallException; import org.jaxen.Navigator; /** *

4.1 string name(node-set?)

* * *
* The name function returns a string containing a QName representing * the expanded-name of the node in the argument node-set that is first in document order. * The QName must represent the expanded-name with respect to the namespace declarations * in effect on the node whose expanded-name is being represented. Typically, this will * be the QName that occurred in the XML source....If * the argument node-set is empty or the first node has * no expanded-name, an empty string is returned. * If the argument it omitted, it defaults to a node-set with the context node as its only member. *
* * @author bob mcwhirter (bob @ werken.com) * * @see Section 4.1 of the XPath Specification */ public class NameFunction implements Function { /** * Create a new NameFunction object. */ public NameFunction() {} /** * Returns the name of the specified node or the name of the context node if * no arguments are provided. * * @param context the context at the point in the * expression where the function is called * @param args a List containing zero or one items * * @return a String containing the name * * @throws FunctionCallException if args has more than one item */ public Object call(Context context, List args) throws FunctionCallException { if ( args.size() == 0 ) { return evaluate( context.getNodeSet(), context.getNavigator() ); } if ( args.size() == 1 ) { return evaluate( args, context.getNavigator() ); } throw new FunctionCallException( "name() requires zero or one argument." ); } /** * Returns the name of list.get(0) * * @param list a list of nodes * @param nav the Navigator used to retrieve the name * * @return the name of list.get(0) * * @throws FunctionCallException if list.get(0) is not a node */ public static String evaluate(List list, Navigator nav) throws FunctionCallException { if ( ! list.isEmpty() ) { Object first = list.get(0); if (first instanceof List) { return evaluate( (List) first, nav ); } else if ( nav.isElement( first ) ) { return nav.getElementQName( first ); } else if ( nav.isAttribute( first ) ) { return nav.getAttributeQName( first ); } else if ( nav.isProcessingInstruction( first ) ) { return nav.getProcessingInstructionTarget( first ); } else if ( nav.isNamespace( first ) ) { return nav.getNamespacePrefix( first ); } else if ( nav.isDocument( first ) ) { return ""; } else if ( nav.isComment( first ) ) { return ""; } else if ( nav.isText( first ) ) { return ""; } else { throw new FunctionCallException("The argument to the name function must be a node-set"); } } return ""; } } jaxen-1.1.6/src/java/main/org/jaxen/function/StringLengthFunction.java0000664000175000017500000001361211004755613025321 0ustar ebourgebourg/* * $Header$ * $Revision: 1324 $ * $Date: 2008-04-27 03:48:59 +0200 (Sun, 27 Apr 2008) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: StringLengthFunction.java 1324 2008-04-27 01:48:59Z elharo $ */ package org.jaxen.function; import java.util.List; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.FunctionCallException; import org.jaxen.Navigator; /** *

4.2 number string-length(string)

* *

* The string-length function returns the number of Unicode characters * in its argument. This is not necessarily * the same as the number Java chars * in the corresponding Java string. In particular, if the Java String * contains surrogate pairs each such pair will be counted as only one character * by this function. If the argument is omitted, * it returns the length of the string-value of the context node. *

* * @author bob mcwhirter (bob @ werken.com) * @see Section * 4.2 of the XPath Specification */ public class StringLengthFunction implements Function { /** * Create a new StringLengthFunction object. */ public StringLengthFunction() {} /** *

* Returns the number of Unicode characters in the string-value of the argument. *

* * @param context the context at the point in the * expression when the function is called * @param args a list containing the item whose string-value is to be counted. * If empty, the length of the context node's string-value is returned. * * @return a Double giving the number of Unicode characters * * @throws FunctionCallException if args has more than one item */ public Object call(Context context, List args) throws FunctionCallException { if (args.size() == 0) { return evaluate( context.getNodeSet(), context.getNavigator() ); } else if (args.size() == 1) { return evaluate( args.get(0), context.getNavigator() ); } throw new FunctionCallException( "string-length() requires one argument." ); } /** *

* Returns the number of Unicode characters in the string-value of * an object. *

* * @param obj the object whose string-value is counted * @param nav used to calculate the string-values of the first two arguments * * @return a Double giving the number of Unicode characters * * @throws FunctionCallException if the string contains mismatched surrogates */ public static Double evaluate(Object obj, Navigator nav) throws FunctionCallException { String str = StringFunction.evaluate( obj, nav ); // String.length() counts UTF-16 code points; not Unicode characters char[] data = str.toCharArray(); int length = 0; for (int i = 0; i < data.length; i++) { char c = data[i]; length++; // if this is a high surrogate; assume the next character is // is a low surrogate and skip it if (c >= 0xD800 && c <= 0xDFFF) { try { char low = data[i+1]; if (low < 0xDC00 || low > 0xDFFF) { throw new FunctionCallException("Bad surrogate pair in string " + str); } i++; // increment past low surrogate } catch (ArrayIndexOutOfBoundsException ex) { throw new FunctionCallException("Bad surrogate pair in string " + str); } } } return new Double(length); } } jaxen-1.1.6/src/java/main/org/jaxen/function/FloorFunction.java0000664000175000017500000001213210371471320023762 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: FloorFunction.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function; import java.util.List; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.FunctionCallException; import org.jaxen.Navigator; /** *

4.4 number floor(number)

* * *
* The floor function returns the largest (closest to positive infinity) * number that is not greater than the argument and that is an integer.... * If the argument is NaN, then NaN is returned. * If the argument is positive infinity, then positive infinity is returned. * If the argument is negative infinity, then negative infinity is returned. * If the argument is positive zero, then positive zero is returned. * If the argument is negative zero, then negative zero is returned. * If the argument is greater than zero, but less than 1, then positive zero is returned. *
* * @author bob mcwhirter (bob @ werken.com) * * @see Section 4.4 of the XPath Specification * @see XPath Errata */ public class FloorFunction implements Function { /** * Create a new FloorFunction object. */ public FloorFunction() {} /** Returns the largest integer less than or equal to a number. * * @param context the context at the point in the * expression when the function is called * @param args a list with exactly one item which will be converted to a * Double as if by the XPath number() function * * @return a Double containing the largest integer less than or equal * to args.get(0) * * @throws FunctionCallException if args has more or less than one item */ public Object call(Context context, List args) throws FunctionCallException { if (args.size() == 1) { return evaluate( args.get(0), context.getNavigator() ); } throw new FunctionCallException( "floor() requires one argument." ); } /** Returns the largest integer less than or equal to the argument. * If necessary, the argument is first converted to a Double * as if by the XPath number() function. * * @param obj the object whose floor is returned * @param nav ignored * * @return a Double containing the largest integer less * than or equal to obj */ public static Double evaluate(Object obj, Navigator nav) { Double value = NumberFunction.evaluate( obj, nav ); return new Double( Math.floor( value.doubleValue() ) ); } } jaxen-1.1.6/src/java/main/org/jaxen/function/SubstringBeforeFunction.java0000664000175000017500000001307110371471320026007 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: SubstringBeforeFunction.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function; import java.util.List; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.FunctionCallException; import org.jaxen.Navigator; /** *

4.2 string substring-before(string,string)

* * *
* The substring-before function returns the substring of the first argument * string that precedes the first occurrence of the second argument string * in the first argument string, or the empty string if the * first argument string does not contain the second argument string. * For example, substring-before("1999/04/01","/") returns 1999. *
* * @author bob mcwhirter (bob @ werken.com) * * @see Section 4.2 of the XPath Specification */ public class SubstringBeforeFunction implements Function { /** * Create a new SubstringBeforeFunction object. */ public SubstringBeforeFunction() {} /** * Returns the part of the string-value of the first item in args * that comes before the string-value of the second item in args; * or the empty string if the second string is not a substring of the first string. * * @param context the context at the point in the * expression when the function is called * @param args a list that contains two items * * @return a String containing that * part of the string-value of the first item in args * that comes before the string-value of the second item in args * * @throws FunctionCallException if args does not have length two */ public Object call(Context context, List args) throws FunctionCallException { if (args.size() == 2) { return evaluate( args.get(0), args.get(1), context.getNavigator() ); } throw new FunctionCallException( "substring-before() requires two arguments." ); } /** * Returns the part of strArg that precedes the first occurence * of matchArg; or the empty string if the * strArg does not contain matchArg * * @param strArg the string from which the substring is extracted * @param matchArg the string that marks the boundary of the substring * @param nav the Navigator used to calculate the string-values of * the first two arguments * * @return a String containing the part of strArg that precedes the first occurence * of matchArg * */ public static String evaluate(Object strArg, Object matchArg, Navigator nav) { String str = StringFunction.evaluate( strArg, nav ); String match = StringFunction.evaluate( matchArg, nav ); int loc = str.indexOf(match); if ( loc < 0 ) { return ""; } return str.substring(0, loc); } } jaxen-1.1.6/src/java/main/org/jaxen/function/IdFunction.java0000664000175000017500000001363610371471320023247 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: IdFunction.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.StringTokenizer; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.FunctionCallException; import org.jaxen.Navigator; /** *

4.1 node-set id(object)

* *

The id function returns a List * of all the elements in the context document that have an ID * matching one of a specified list of IDs. How an attribute is determined * to be of type ID depends on the navigator, but it normally requires that * the attribute be declared to have type ID in the DTD. *

* *

* There should be no more than one element in any document with a * certain ID. However, if there are multiple such elements--i.e. if * there are duplicate IDs--then this function selects only the first element * in document order with the specified ID. *

* * @author Erwin Bolwidt (ejb @ klomp.org) * @author J\u00e9r\u00f4me N\u00e8gre (jerome.negre @ e-xmlmedia.fr) * * @see Section 4.1 of the XPath Specification */ public class IdFunction implements Function { /** * Create a new IdFunction object. */ public IdFunction() {} /** * Returns a list of the nodes with the specified IDs. * * @param context the context at the point in the * expression when the function is called * @param args a list with exactly one item which is either a string * a node-set * * @return a List containing the first node in document * with each of the specified IDs; or * an empty list if there are no such nodes * * @throws FunctionCallException if args has more or less than one item */ public Object call(Context context, List args) throws FunctionCallException { if ( args.size() == 1 ) { return evaluate( context.getNodeSet(), args.get(0), context.getNavigator() ); } throw new FunctionCallException( "id() requires one argument" ); } /** * Returns a list of the nodes with the specified IDs. * * @param contextNodes the context node-set. The first item in this list * determines the document in which the search is performed. * @param arg the ID or IDs to search for * @param nav the navigator used to calculate string-values and search * by ID * * @return a List containing the first node in document * with each of the specified IDs; or * an empty list if there are no such nodes * */ public static List evaluate(List contextNodes, Object arg, Navigator nav) { if (contextNodes.size() == 0) return Collections.EMPTY_LIST; List nodes = new ArrayList(); Object contextNode = contextNodes.get(0); if (arg instanceof List) { Iterator iter = ((List)arg).iterator(); while (iter.hasNext()) { String id = StringFunction.evaluate(iter.next(), nav); nodes.addAll( evaluate( contextNodes, id, nav ) ); } } else { String ids = StringFunction.evaluate(arg, nav); StringTokenizer tok = new StringTokenizer(ids, " \t\n\r"); while (tok.hasMoreTokens()) { String id = tok.nextToken(); Object node = nav.getElementById(contextNode, id); if (node != null) { nodes.add(node); } } } return nodes; } } jaxen-1.1.6/src/java/main/org/jaxen/function/NumberFunction.java0000664000175000017500000001726612005235251024143 0ustar ebourgebourg/* * $Header$ * $Revision: 1386 $ * $Date: 2012-07-29 15:29:13 +0200 (Sun, 29 Jul 2012) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: NumberFunction.java 1386 2012-07-29 13:29:13Z elharo $ */ package org.jaxen.function; import java.util.Iterator; import java.util.List; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.FunctionCallException; import org.jaxen.Navigator; /** *

* 4.4 number number(object) * * *

*

* The number function converts * its argument to a number as follows: *

* *
    * *
  • *

    * a string that consists of optional whitespace followed by an optional * minus sign followed by a Number followed by * whitespace is converted to the IEEE 754 number that is nearest * (according to the IEEE 754 round-to-nearest rule) to the mathematical * value represented by the string; any other string is converted to NaN *

    *
  • * *
  • *

    * boolean true is converted to 1; boolean false is converted to 0 *

    *
  • * *
  • * *

    * a node-set is first converted to a string as if by a call to the string function and then converted * in the same way as a string argument *

    * *
  • * *
  • *

    * an object of a type other than the four basic types is converted to a * number in a way that is dependent on that type *

    *
  • * *
* *

* If the argument is omitted, it defaults to a node-set with the * context node as its only member. *

* *
NOTE: The number * function should not be used for conversion of numeric data occurring * in an element in an XML document unless the element is of a type that * represents numeric data in a language-neutral format (which would * typically be transformed into a language-specific format for * presentation to a user). In addition, the number function cannot be used * unless the language-neutral format used by the element is consistent * with the XPath syntax for a Number.
* *
* * @author bob mcwhirter (bob @ werken.com) * * @see Section 4.4 of the XPath Specification */ public class NumberFunction implements Function { private final static Double NaN = new Double( Double.NaN ); /** * Create a new NumberFunction object. */ public NumberFunction() {} /** * Returns the number value of args.get(0), * or the number value of the context node if args * is empty. * * @param context the context at the point in the * expression when the function is called * @param args a list containing the single item to be converted to a * Double * * @return a Double * * @throws FunctionCallException if args has more than one item */ public Object call(Context context, List args) throws FunctionCallException { if (args.size() == 1) { return evaluate( args.get(0), context.getNavigator() ); } else if (args.size() == 0) { return evaluate( context.getNodeSet(), context.getNavigator() ); } throw new FunctionCallException( "number() takes at most one argument." ); } /** * Returns the number value of obj. * * @param obj the object to be converted to a number * @param nav the Navigator used to calculate the string-value * of node-sets * * @return a Double */ public static Double evaluate(Object obj, Navigator nav) { if( obj instanceof Double ) { return (Double) obj; } else if ( obj instanceof String ) { String str = (String) obj; try { Double doubleValue = new Double( str ); return doubleValue; } catch (NumberFormatException e) { return NaN; } } else if ( obj instanceof List || obj instanceof Iterator ) { return evaluate( StringFunction.evaluate( obj, nav ), nav ); } else if ( nav.isElement( obj ) || nav.isAttribute( obj ) || nav.isText( obj ) || nav.isComment( obj ) || nav.isProcessingInstruction( obj ) || nav.isDocument( obj ) || nav.isNamespace( obj )) { return evaluate( StringFunction.evaluate( obj, nav ), nav ); } else if ( obj instanceof Boolean ) { if ( Boolean.TRUE.equals(obj) ) { return new Double( 1 ); } else { return new Double( 0 ); } } return NaN; } /** * Determines whether the argument is not a number (NaN) as defined * by IEEE 754. * * @param val the double to test * @return true if the value is NaN, false otherwise */ public static boolean isNaN( double val ) { return Double.isNaN(val); } /** * Determines whether the argument is not a number (NaN) as defined * by IEEE 754. * * @param val the Double to test * @return true if the value is NaN, false otherwise */ public static boolean isNaN( Double val ) { return val.equals( NaN ); } } jaxen-1.1.6/src/java/main/org/jaxen/function/NotFunction.java0000664000175000017500000001123510371471320023444 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: NotFunction.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function; import java.util.List; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.FunctionCallException; import org.jaxen.Navigator; /** *

4.3 boolean not(boolean)

* * *
* The not function returns true if its argument is false, and false otherwise. *
* * @author bob mcwhirter (bob @ werken.com) * @see Section 4.3 of the XPath Specification */ public class NotFunction implements Function { /** * Create a new NotFunction object. */ public NotFunction() {} /** * Returns Boolean.TRUE if the boolean value of * args.get(0) is false, and Boolean.FALSE otherwise. * The boolean value is calculated as if by the XPath boolean * function. * * @param context the context at the point in the * expression where the function is called * @param args a single element list * * @return Boolean.TRUE if the boolean value of * obj is false, and Boolean.FALSE otherwise * * @throws FunctionCallException if args does not have exactly one argument */ public Object call(Context context, List args) throws FunctionCallException { if (args.size() == 1) { return evaluate( args.get(0), context.getNavigator() ); } throw new FunctionCallException( "not() requires one argument." ); } /** * Returns Boolean.TRUE if the boolean value of * obj is false, and Boolean.FALSE otherwise. * The boolean value is calculated as if by the XPath boolean * function. * * @param obj the object whose boolean value is inverted * @param nav the Navigator used to calculate the boolean value of obj * * @return Boolean.TRUE if the boolean value of * obj is false, and Boolean.FALSE otherwise */ public static Boolean evaluate(Object obj, Navigator nav) { return ( ( BooleanFunction.evaluate( obj, nav ).booleanValue() ) ? Boolean.FALSE : Boolean.TRUE ); } }jaxen-1.1.6/src/java/main/org/jaxen/function/CeilingFunction.java0000664000175000017500000001221010371471320024250 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: CeilingFunction.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function; import java.util.List; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.FunctionCallException; import org.jaxen.Navigator; /** *

4.4 number ceiling(number) *

*

* *

The ceiling function returns the smallest * (closest to negative infinity) number that is not less * than the argument and that is an integer....If the argument * is NaN, then NaN is returned. If the argument is positive infinity, * then positive infinity is returned. If the argument is negative infinity, * then negative infinity is returned. If the argument is positive zero, * then positive zero is returned. * If the argument is negative zero, then negative zero is returned. * If the argument is less than zero, but greater than -1, * then negative zero is returned. *

* * @author bob mcwhirter (bob @ werken.com) * * @see Section 4.4 of the XPath Specification * @see XPath Specification Errata * */ public class CeilingFunction implements Function { /** * Create a new CeilingFunction object. */ public CeilingFunction() {} /** Returns the smallest integer greater than or equal to a number. * * @param context the context at the point in the * expression when the function is called * @param args a list with exactly one item which will be converted to a * Double as if by the XPath number() function * * @return a Double containing the smallest integer greater than or equal * args.get(0) * * @throws FunctionCallException if args has more or less than one item */ public Object call(Context context, List args) throws FunctionCallException { if (args.size() == 1) { return evaluate( args.get(0), context.getNavigator() ); } throw new FunctionCallException("ceiling() requires one argument."); } /** Returns the smallest integer greater than or equal to the argument. * If necessary, the argument is first converted to a Double * as if by the XPath number() function. * * @param obj the object whose ceiling is returned * @param nav ignored * * @return a Double containing the smallest integer * greater than or equal to obj */ public static Double evaluate(Object obj, Navigator nav) { Double value = NumberFunction.evaluate( obj, nav ); return new Double( Math.ceil( value.doubleValue() ) ); } } jaxen-1.1.6/src/java/main/org/jaxen/function/StartsWithFunction.java0000664000175000017500000001233010371471320025015 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: StartsWithFunction.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function; import java.util.List; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.FunctionCallException; import org.jaxen.Navigator; /** *

4.2 boolean starts-with(string,string)

* * *
* The starts-with function returns true if the first argument string starts * with the second argument string, and otherwise returns false. *
* * @author bob mcwhirter (bob @ werken.com) * @see Section 4.2 of the XPath Specification */ public class StartsWithFunction implements Function { /** * Create a new StartsWithFunction object. */ public StartsWithFunction() {} /** * Returns true if the string-value of the first item in args * starts with the string-value of the second item in args. * Otherwise it returns false. * * @param context the context at the point in the * expression when the function is called * @param args a list that contains two items * * @return Boolean.TRUE if the first item in args * starts with the string-value of the second item in args; * otherwise Boolean.FALSE * * @throws FunctionCallException if args does not have length two */ public Object call(Context context, List args) throws FunctionCallException { if (args.size() == 2) { return evaluate( args.get(0), args.get(1), context.getNavigator() ); } throw new FunctionCallException( "starts-with() requires two arguments." ); } /** * Returns true if the string-value of strArg * starts with the string-value of matchArg. * Otherwise it returns false. * * @param strArg the object whose string-value searched for the prefix * @param matchArg the object whose string-value becomes the prefix string to compare against * @param nav the navigator used to calculate the string-values of the arguments * * @return Boolean.TRUE if the string-value of strArg * starts with the string-value of matchArg; * otherwise Boolean.FALSE * */ public static Boolean evaluate(Object strArg, Object matchArg, Navigator nav) { String str = StringFunction.evaluate( strArg, nav ); String match = StringFunction.evaluate( matchArg, nav ); return ( str.startsWith(match) ? Boolean.TRUE : Boolean.FALSE ); } } jaxen-1.1.6/src/java/main/org/jaxen/function/ContainsFunction.java0000664000175000017500000001217310371471320024464 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: ContainsFunction.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function; import java.util.List; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.FunctionCallException; import org.jaxen.Navigator; /** *

4.2 boolean contains(string,string)

* *
* The contains function returns true if the first argument * string contains the second argument string, and otherwise returns false. *
* * @author bob mcwhirter (bob @ werken.com) * * @see Section 4.2 of the XPath Specification */ public class ContainsFunction implements Function { /** * Create a new ContainsFunction object. */ public ContainsFunction() {} /** *

* Returns true if the string-value of the * first item in args contains string-value of the second * item; false otherwise. * If necessary one or both items are converted to a string as if by the XPath * string() function. *

* * @param context the context at the point in the * expression when the function is called * @param args a list containing exactly two items * * @return the result of evaluating the function; * Boolean.TRUE or Boolean.FALSE * * @throws FunctionCallException if args does not have exactly two items */ public Object call(Context context, List args) throws FunctionCallException { if (args.size() == 2) { return evaluate(args.get(0), args.get(1), context.getNavigator() ); } throw new FunctionCallException("contains() requires two arguments."); } /** *

Returns true if the first string contains the second string; false otherwise. * If necessary one or both arguments are converted to a string as if by the XPath * string() function. *

* * @param strArg the containing string * @param matchArg the contained string * @param nav used to calculate the string-values of the first two arguments * * @return Boolean.TRUE if true if the first string contains * the second string; Boolean.FALSE otherwise. */ public static Boolean evaluate(Object strArg, Object matchArg, Navigator nav) { String str = StringFunction.evaluate( strArg, nav ); String match = StringFunction.evaluate( matchArg, nav ); return ( ( str.indexOf(match) >= 0) ? Boolean.TRUE : Boolean.FALSE ); } } jaxen-1.1.6/src/java/main/org/jaxen/function/PositionFunction.java0000664000175000017500000001006310371471320024506 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: PositionFunction.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function; import java.util.List; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.FunctionCallException; /** *

4.1 number position()

* * *
* The position function returns a number equal to the context position from the expression evaluation context. *
* * @author bob mcwhirter (bob @ werken.com) * @see Section 4.1 of the XPath Specification */ public class PositionFunction implements Function { /** * Create a new PositionFunction object. */ public PositionFunction() {} /** * Returns the position of the context node in the context node-set. * * @param context the context at the point in the * expression where the function is called * @param args an empty list * * @return a Double containing the context position * * @throws FunctionCallException if args is not empty * * @see Context#getSize() */ public Object call(Context context, List args) throws FunctionCallException { if ( args.size() == 0 ) { return evaluate( context ); } throw new FunctionCallException( "position() does not take any arguments." ); } /** * * Returns the position of the context node in the context node-set. * * @param context the context at the point in the * expression where the function is called * * @return a Double containing the context position * * @see Context#getPosition() */ public static Double evaluate(Context context) { return new Double( context.getPosition() ); } } jaxen-1.1.6/src/java/main/org/jaxen/function/NamespaceUriFunction.java0000664000175000017500000001500010371471320025252 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: NamespaceUriFunction.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function; import java.util.List; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.FunctionCallException; import org.jaxen.Navigator; /** *

* 4.1 * string namespace-uri(node-set?) *

* *
*

* The namespace-uri * function returns the namespace URI of the expanded-name of the node in the * argument node-set that is first in document order. If the argument * node-set is empty, the first node has no expanded-name, or the namespace URI of * the expanded-name is null, an empty * string is returned. If the argument is omitted, it defaults to a * node-set with the context node as its only member. *

* *
NOTE: The string returned by the namespace-uri function will * be empty except for element nodes and attribute nodes.
* *
* * @author bob mcwhirter (bob @ werken.com) * @see Section 4.1 of the XPath Specification */ public class NamespaceUriFunction implements Function { /** * Create a new NamespaceUriFunction object. */ public NamespaceUriFunction() {} /** * Returns the namespace URI of the specified node or the namespace URI of the context node if * no arguments are provided. * * @param context the context at the point in the * expression where the function is called * @param args a List containing zero or one items * * @return a String containing the namespace URI * * @throws FunctionCallException if args has more than one item */ public Object call(Context context, List args) throws FunctionCallException { if (args.size() == 0) { return evaluate( context.getNodeSet(), context.getNavigator() ); } if ( args.size() == 1 ) { return evaluate( args, context.getNavigator() ); } throw new FunctionCallException( "namespace-uri() requires zero or one argument." ); } /** * Returns the namespace URI of list.get(0) * * @param list a list of nodes * @param nav the Navigator used to retrieve the namespace * * @return the namespace URI of list.get(0) * * @throws FunctionCallException if list.get(0) is not a node */ public static String evaluate(List list, Navigator nav) throws FunctionCallException { if ( ! list.isEmpty() ) { Object first = list.get(0); if ( first instanceof List ) { return evaluate( (List) first, nav ); } else if ( nav.isElement( first ) ) { return nav.getElementNamespaceUri( first ); } else if ( nav.isAttribute( first ) ) { String uri = nav.getAttributeNamespaceUri( first ); if (uri == null) return ""; return uri; } else if ( nav.isProcessingInstruction( first ) ) { return ""; } else if ( nav.isNamespace( first ) ) { return ""; } else if ( nav.isDocument( first ) ) { return ""; } else if ( nav.isComment( first ) ) { return ""; } else if ( nav.isText( first ) ) { return ""; } else { throw new FunctionCallException( "The argument to the namespace-uri function must be a node-set"); } } return ""; } } jaxen-1.1.6/src/java/main/org/jaxen/function/FalseFunction.java0000664000175000017500000000674410371471320023747 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: FalseFunction.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function; import java.util.List; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.FunctionCallException; /** *

4.3 boolean false() * *

Returns false.

* * @author bob mcwhirter (bob @ werken.com) * * @see Section 4.3 of the XPath Specification */ public class FalseFunction implements Function { /** * Create a new FalseFunction object. */ public FalseFunction() {} /** Returns Boolean.FALSE * * @param context the context at the point in the * expression when the function is called * @param args an empty list * * @return Boolean.FALSE * * @throws FunctionCallException if args is not empty */ public Object call(Context context, List args) throws FunctionCallException { if (args.size() == 0) { return evaluate(); } throw new FunctionCallException( "false() requires no arguments." ); } /** * Returns false. * * @return Boolean.FALSE */ public static Boolean evaluate() { return Boolean.FALSE; } } jaxen-1.1.6/src/java/main/org/jaxen/function/LocalNameFunction.java0000664000175000017500000001361510371471320024543 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: LocalNameFunction.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function; import java.util.List; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.FunctionCallException; import org.jaxen.Navigator; /** *

4.1 string local-name(node-set?)

* * *
* The local-name function returns the local part of the * expanded-name of the node in the argument node-set that is first in document order. * If the argument node-set is empty or the first node has no expanded-name, an * empty string is returned. If the argument is omitted, it defaults to a node-set with the context node as its only member. * *
* * @author bob mcwhirter (bob @ werken.com) * @see Section 4.1 of the XPath Specification */ public class LocalNameFunction implements Function { /** * Create a new LocalNameFunction object. */ public LocalNameFunction() {} /** * Returns the local-name of the specified node or the context node if * no arguments are provided. * * @param context the context at the point in the * expression where the function is called * @param args a List containing zero or one items * * @return a String containing the local-name * * @throws FunctionCallException if args has more than one item */ public Object call(Context context, List args) throws FunctionCallException { if ( args.size() == 0 ) { return evaluate( context.getNodeSet(), context.getNavigator() ); } if ( args.size() == 1 ) { return evaluate( args, context.getNavigator() ); } throw new FunctionCallException( "local-name() requires zero or one argument." ); } /** * Returns the local-name of list.get(0) * * @param list a list of nodes * @param nav the Navigator used to retrieve the local name * * @return the local-name of list.get(0) * * @throws FunctionCallException if list.get(0) is not a node */ public static String evaluate(List list, Navigator nav) throws FunctionCallException { if ( ! list.isEmpty() ) { Object first = list.get(0); if (first instanceof List) { return evaluate( (List) first, nav ); } else if ( nav.isElement( first ) ) { return nav.getElementName( first ); } else if ( nav.isAttribute( first ) ) { return nav.getAttributeName( first ); } else if ( nav.isProcessingInstruction( first ) ) { return nav.getProcessingInstructionTarget( first ); } else if ( nav.isNamespace( first ) ) { return nav.getNamespacePrefix( first ); } else if ( nav.isDocument( first ) ) { return ""; } else if ( nav.isComment( first ) ) { return ""; } else if ( nav.isText( first ) ) { return ""; } else { throw new FunctionCallException("The argument to the local-name function must be a node-set"); } } return ""; } } jaxen-1.1.6/src/java/main/org/jaxen/function/TrueFunction.java0000664000175000017500000000657210371471320023633 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: TrueFunction.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function; import java.util.List; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.FunctionCallException; /** *

4.3 boolean true()

* *

Returns true.

* * @author bob mcwhirter (bob @ werken.com) * * @see XPath Specification */ public class TrueFunction implements Function { /** * Create a new TrueFunction object. */ public TrueFunction() {} /** Returns Boolean.TRUE * * @param context ignored * @param args an empty list * * @return Boolean.TRUE * * @throws FunctionCallException if args is not empty */ public Object call(Context context, List args) throws FunctionCallException { if (args.size() == 0) { return evaluate(); } throw new FunctionCallException( "true() requires no arguments." ); } /** * Returns true. * * @return Boolean.TRUE */ public static Boolean evaluate() { return Boolean.TRUE; } } jaxen-1.1.6/src/java/main/org/jaxen/function/xslt/0000775000175000017500000000000012174247547021342 5ustar ebourgebourgjaxen-1.1.6/src/java/main/org/jaxen/function/xslt/DocumentFunction.java0000664000175000017500000000636010371471320025457 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: DocumentFunction.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function.xslt; import java.util.List; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.FunctionCallException; import org.jaxen.Navigator; import org.jaxen.function.StringFunction; /** * Implements the XSLT document() function * * @author James Strachan */ public class DocumentFunction implements Function { public Object call(Context context, List args) throws FunctionCallException { if (args.size() == 1) { Navigator nav = context.getNavigator(); String url = StringFunction.evaluate( args.get( 0 ), nav ); return evaluate( url, nav ); } throw new FunctionCallException( "document() requires one argument." ); } public static Object evaluate(String url, Navigator nav) throws FunctionCallException { return nav.getDocument( url ); } } jaxen-1.1.6/src/java/main/org/jaxen/function/xslt/package.html0000664000175000017500000000023707463240455023621 0ustar ebourgebourg org.jaxen.function.xslt.*

XPath functions which are defined in XSLT.

jaxen-1.1.6/src/java/main/org/jaxen/function/SubstringFunction.java0000664000175000017500000002022510371471320024663 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * */ package org.jaxen.function; import java.util.List; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.FunctionCallException; import org.jaxen.Navigator; /** *

* 4.2 * string substring(string,number,number?) *

* *
*

The substring function returns the * substring of the first argument starting at the position specified in * the second argument with length specified in the third argument. For * example, * * substring("12345",2,3) returns "234". * If the third argument is not specified, it returns the substring * starting at the position specified in the second argument and * continuing to the end of the string. For example, * substring("12345",2) returns "2345". *

* *

* More precisely, each character in the string (see [3.6 Strings]) is considered to have a * numeric position: the position of the first character is 1, the * position of the second character is 2 and so on. *

* *
NOTE: This differs from Java and ECMAScript, in * which the String.substring method treats the position * of the first character as 0.
* *

* The returned substring contains those characters for which the * position of the character is greater than or equal to the rounded * value of the second argument and, if the third argument is specified, * less than the sum of the rounded value of the second argument and the * rounded value of the third argument; the comparisons and addition * used for the above follow the standard IEEE 754 rules; rounding is * done as if by a call to the round * function. The following examples illustrate various unusual cases: *

* *
    * *
  • *

    * substring("12345", 1.5, 2.6) returns * "234" *

    *
  • * *
  • *

    * substring("12345", 0, 3) returns "12" * *

    *
  • * *
  • *

    * substring("12345", 0 div 0, 3) returns "" *

    *
  • * *
  • *

    . * substring("12345", 1, 0 div 0) returns * * "" *

    *
  • * *
  • *

    * substring("12345", -42, 1 div 0) returns * "12345" *

    *
  • * *
  • *

    * * substring("12345", -1 div 0, 1 div 0) returns * ""

* * @author bob mcwhirter (bob @ werken.com) * * @see Section 4.2 of the XPath Specification */ public class SubstringFunction implements Function { /** * Create a new SubstringFunction object. */ public SubstringFunction() {} /** Returns a substring of an XPath string-value by character index. * * @param context the context at the point in the * expression when the function is called * @param args a list that contains two or three items * * @return a String containing the specifed character subsequence of * the original string or the string-value of the context node * * @throws FunctionCallException if args has more than three * or less than two items */ public Object call(Context context, List args) throws FunctionCallException { final int argc = args.size(); if (argc < 2 || argc > 3){ throw new FunctionCallException( "substring() requires two or three arguments." ); } final Navigator nav = context.getNavigator(); final String str = StringFunction.evaluate(args.get(0), nav ); // The spec doesn't really address this case if (str == null) { return ""; } final int stringLength = (StringLengthFunction.evaluate(args.get(0), nav )).intValue(); if (stringLength == 0) { return ""; } Double d1 = NumberFunction.evaluate(args.get(1), nav); if (d1.isNaN()){ return ""; } // Round the value and subtract 1 as Java strings are zero based int start = RoundFunction.evaluate(d1, nav).intValue() - 1; int substringLength = stringLength; if (argc == 3){ Double d2 = NumberFunction.evaluate(args.get(2), nav); if (!d2.isNaN()){ substringLength = RoundFunction.evaluate(d2, nav ).intValue(); } else { substringLength = 0; } } if (substringLength < 0) return ""; int end = start + substringLength; if (argc == 2) end = stringLength; // negative start is treated as 0 if ( start < 0){ start = 0; } else if (start > stringLength){ return ""; } if (end > stringLength){ end = stringLength; } else if (end < start) return ""; if (stringLength == str.length()) { // easy case; no surrogate pairs return str.substring(start, end); } else { return unicodeSubstring(str, start, end); } } private static String unicodeSubstring(String s, int start, int end) { StringBuffer result = new StringBuffer(s.length()); for (int jChar = 0, uChar=0; uChar < end; jChar++, uChar++) { char c = s.charAt(jChar); if (uChar >= start) result.append(c); if (c >= 0xD800) { // get the low surrogate // ???? we could check here that this is indeed a low surroagte // we could also catch StringIndexOutOfBoundsException jChar++; if (uChar >= start) result.append(s.charAt(jChar)); } } return result.toString(); } } jaxen-1.1.6/src/java/main/org/jaxen/function/LastFunction.java0000664000175000017500000000772610371471320023621 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: LastFunction.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function; import java.util.List; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.FunctionCallException; /** *

4.1 number last()

* *
* The last function returns a number equal to * the context size from the expression evaluation context. *
* * @author bob mcwhirter (bob @ werken.com) * @see Section 4.1 of the XPath Specification */ public class LastFunction implements Function { /** * Create a new LastFunction object. */ public LastFunction() {} /** * Returns the number of nodes in the context node-set. * * @param context the context at the point in the * expression where the function is called * @param args an empty list * * @return a Double containing the context size * * @throws FunctionCallException if args is not empty * * @see Context#getSize() */ public Object call(Context context, List args) throws FunctionCallException { if (args.size() == 0) { return evaluate( context ); } throw new FunctionCallException( "last() requires no arguments." ); } /** * Returns the number of nodes in the context node-set. * * @param context the context at the point in the * expression where the function is called * * @return the context size * * @see Context#getSize() */ public static Double evaluate(Context context) { return new Double( context.getSize() ); } } jaxen-1.1.6/src/java/main/org/jaxen/function/SumFunction.java0000664000175000017500000001165610371471320023457 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: SumFunction.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function; import java.util.Iterator; import java.util.List; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.FunctionCallException; import org.jaxen.Navigator; /** *

4.4 number sum(node-set)

* *
* The sum function returns the sum, for each node in the argument node-set, * of the result of converting the string-values of the node to a number. *
* * @author bob mcwhirter (bob @ werken.com) * @see Section 4.4 of the XPath Specification */ public class SumFunction implements Function { /** * Create a new SumFunction object. */ public SumFunction() {} /** Returns the sum of its arguments. * * @param context the context at the point in the * expression when the function is called * @param args a list that contains exactly one item, also a List * * @return a Double containing the sum of the items in args.get(0) * * @throws FunctionCallException if args has more or less than one item; * or if the first argument is not a List */ public Object call(Context context, List args) throws FunctionCallException { if (args.size() == 1) { return evaluate( args.get(0), context.getNavigator() ); } throw new FunctionCallException( "sum() requires one argument." ); } /** * Returns the sum of the items in a list. * If necessary, each item in the list is first converted to a Double * as if by the XPath number() function. * * @param obj a List of numbers to be summed * @param nav ignored * * @return the sum of the list * * @throws FunctionCallException if obj is not a List */ public static Double evaluate(Object obj, Navigator nav) throws FunctionCallException { double sum = 0; if (obj instanceof List) { Iterator nodeIter = ((List)obj).iterator(); while ( nodeIter.hasNext() ) { double term = NumberFunction.evaluate( nodeIter.next(), nav ).doubleValue(); sum += term; } } else { throw new FunctionCallException("The argument to the sum function must be a node-set"); } return new Double(sum); } } jaxen-1.1.6/src/java/main/org/jaxen/function/CountFunction.java0000664000175000017500000001021210371471320023766 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: CountFunction.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function; import java.util.List; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.FunctionCallException; /** *

4.1 number count(node-set)

* *
* The count function returns the number of nodes in the argument node-set. *
* @author bob mcwhirter (bob @ werken.com) * @see Section 4.1 of the XPath Specification */ public class CountFunction implements Function { /** * Create a new CountFunction object. */ public CountFunction() {} /** *

* Returns the number of nodes in the specified node-set. *

* @param context ignored * @param args the function arguments * * @return a Double giving the integral number of items in the first argument * * @throws FunctionCallException if args does not have exactly one * item; or that item is not a List */ public Object call(Context context, List args) throws FunctionCallException { if (args.size() == 1) { return evaluate( args.get(0) ); } throw new FunctionCallException( "count() requires one argument." ); } /** *

* Returns the number of nodes in the specified node-set. *

* * @param obj a List of nodes * @return the integral number of items in the list * @throws FunctionCallException if obj is not a List */ public static Double evaluate(Object obj) throws FunctionCallException { if (obj instanceof List) { return new Double( ((List) obj).size() ); } throw new FunctionCallException("count() function can only be used for node-sets"); } } jaxen-1.1.6/src/java/main/org/jaxen/function/TranslateFunction.java0000664000175000017500000002344510371471320024647 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: TranslateFunction.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function; import java.util.HashMap; import java.util.List; import java.util.Map; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.FunctionCallException; import org.jaxen.Navigator; /** *

* 4.2 * string translate(string,string,string) *

* *
*

* The translate function * returns the first argument string with occurrences of characters in * the second argument string replaced by the character at the * corresponding position in the third argument string. For example, * translate("bar","abc","ABC") returns the string * BAr. If there is a character in the second argument * string with no character at a corresponding position in the third * argument string (because the second argument string is longer than * the third argument string), then occurrences of that character in the * first argument string are removed. For example, * translate("--aaa--","abc-","ABC") returns * "AAA". If a character occurs more than once in the * second argument string, then the first occurrence determines the * replacement character. If the third argument string is longer than * the second argument string, then excess characters are ignored. *

* *
NOTE: The translate function is not a * sufficient solution for case conversion in all languages. A future * version of XPath may provide additional functions for case * conversion.
* *
* * @author Jan Dvorak ( jan.dvorak @ mathan.cz ) * * @see Section 4.2 of the XPath Specification */ public class TranslateFunction implements Function { /* The translation is done thru a HashMap. Performance tip (for anyone * who needs to improve the performance of this particular function): * Cache the HashMaps, once they are constructed. */ /** * Create a new TranslateFunction object. */ public TranslateFunction() {} /** Returns a copy of the first argument in which * characters found in the second argument are replaced by * corresponding characters from the third argument. * * @param context the context at the point in the * expression when the function is called * @param args a list that contains exactly three items * * @return a String built from args.get(0) * in which occurrences of characters in args.get(1) * are replaced by the corresponding characters in args.get(2) * * @throws FunctionCallException if args does not have exactly three items */ public Object call(Context context, List args) throws FunctionCallException { if (args.size() == 3) { return evaluate( args.get(0), args.get(1), args.get(2), context.getNavigator() ); } throw new FunctionCallException( "translate() requires three arguments." ); } /** * Returns a copy of strArg in which * characters found in fromArg are replaced by * corresponding characters from toArg. * If necessary each argument is first converted to it string-value * as if by the XPath string() function. * * @param strArg the base string * @param fromArg the characters to be replaced * @param toArg the characters they will be replaced by * @param nav the Navigator used to calculate the string-values of the arguments. * * @return a copy of strArg in which * characters found in fromArg are replaced by * corresponding characters from toArg * * @throws FunctionCallException if one of the arguments is a malformed Unicode string; * that is, if surrogate characters don't line up properly * */ public static String evaluate(Object strArg, Object fromArg, Object toArg, Navigator nav) throws FunctionCallException { String inStr = StringFunction.evaluate( strArg, nav ); String fromStr = StringFunction.evaluate( fromArg, nav ); String toStr = StringFunction.evaluate( toArg, nav ); // Initialize the mapping in a HashMap Map characterMap = new HashMap(); String[] fromCharacters = toUnicodeCharacters(fromStr); String[] toCharacters = toUnicodeCharacters(toStr); int fromLen = fromCharacters.length; int toLen = toCharacters.length; for ( int i = 0; i < fromLen; i++ ) { String cFrom = fromCharacters[i]; if ( characterMap.containsKey( cFrom ) ) { // We've seen the character before, ignore continue; } if ( i < toLen ) { // Will change characterMap.put( cFrom, toCharacters[i] ); } else { // Will delete characterMap.put( cFrom, null ); } } // Process the input string thru the map StringBuffer outStr = new StringBuffer( inStr.length() ); String[] inCharacters = toUnicodeCharacters(inStr); int inLen = inCharacters.length; for ( int i = 0; i < inLen; i++ ) { String cIn = inCharacters[i]; if ( characterMap.containsKey( cIn ) ) { String cTo = (String) characterMap.get( cIn ); if ( cTo != null ) { outStr.append( cTo ); } } else { outStr.append( cIn ); } } return outStr.toString(); } private static String[] toUnicodeCharacters(String s) throws FunctionCallException { String[] result = new String[s.length()]; int stringLength = 0; for (int i = 0; i < s.length(); i++) { char c1 = s.charAt(i); if (isHighSurrogate(c1)) { try { char c2 = s.charAt(i+1); if (isLowSurrogate(c2)) { result[stringLength] = (c1 + "" + c2).intern(); i++; } else { throw new FunctionCallException("Mismatched surrogate pair in translate function"); } } catch (StringIndexOutOfBoundsException ex) { throw new FunctionCallException("High surrogate without low surrogate at end of string passed to translate function"); } } else { result[stringLength]=String.valueOf(c1).intern(); } stringLength++; } if (stringLength == result.length) return result; // trim array String[] trimmed = new String[stringLength]; System.arraycopy(result, 0, trimmed, 0, stringLength); return trimmed; } private static boolean isHighSurrogate(char c) { return c >= 0xD800 && c <= 0xDBFF; } private static boolean isLowSurrogate(char c) { return c >= 0xDC00 && c <= 0xDFFF; } }jaxen-1.1.6/src/java/main/org/jaxen/function/ext/0000775000175000017500000000000012174247547021150 5ustar ebourgebourgjaxen-1.1.6/src/java/main/org/jaxen/function/ext/EvaluateFunction.java0000664000175000017500000000766610371471320025267 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: EvaluateFunction.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function.ext; import java.util.Collections; import java.util.List; import org.jaxen.Context; import org.jaxen.ContextSupport; import org.jaxen.Function; import org.jaxen.FunctionCallException; import org.jaxen.Navigator; import org.jaxen.XPath; import org.jaxen.function.StringFunction; /** * node-set evaluate(string) * * @author Erwin Bolwidt (ejb @ klomp.org) */ public class EvaluateFunction implements Function { public Object call( Context context, List args ) throws FunctionCallException { if ( args.size() == 1 ) { return evaluate( context, args.get(0)); } throw new FunctionCallException( "evaluate() requires one argument" ); } public static List evaluate (Context context, Object arg) throws FunctionCallException { List contextNodes = context.getNodeSet(); if (contextNodes.size() == 0) return Collections.EMPTY_LIST; Navigator nav = context.getNavigator(); String xpathString; if ( arg instanceof String ) xpathString = (String)arg; else xpathString = StringFunction.evaluate(arg, nav); try { XPath xpath = nav.parseXPath(xpathString); ContextSupport support = context.getContextSupport(); xpath.setVariableContext( support.getVariableContext() ); xpath.setFunctionContext( support.getFunctionContext() ); xpath.setNamespaceContext( support.getNamespaceContext() ); return xpath.selectNodes( context.duplicate() ); } catch ( org.jaxen.saxpath.SAXPathException e ) { throw new FunctionCallException(e.toString()); } } } jaxen-1.1.6/src/java/main/org/jaxen/function/ext/UpperFunction.java0000664000175000017500000001031310371471320024573 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: UpperFunction.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function.ext; import java.util.List; import java.util.Locale; import org.jaxen.Context; import org.jaxen.FunctionCallException; import org.jaxen.Navigator; import org.jaxen.function.StringFunction; /** *

string upper-case(string) * * This function can take a second parameter of the * Locale to use for the String conversion. *

* *

* For example * * upper-case( /foo/bar ) * upper-case( /foo/@name, $myLocale ) *

* * @author mark wilson (markw@wilsoncom.de) * @author James Strachan */ public class UpperFunction extends LocaleFunctionSupport { public Object call(Context context, List args) throws FunctionCallException { Navigator navigator = context.getNavigator(); int size = args.size(); if (size > 0) { Object text = args.get(0); Locale locale = null; if (size > 1) { locale = getLocale( args.get(1), navigator ); } return evaluate( text, locale, navigator ); } throw new FunctionCallException( "upper-case() requires at least one argument." ); } /** * Converts the given string value to upper case using an optional Locale * * @param strArg the value which gets converted to a String * @param locale the Locale to use for the conversion or null if * English should be used * @param nav the Navigator to use */ public static String evaluate(Object strArg, Locale locale, Navigator nav) { String str = StringFunction.evaluate( strArg, nav ); // it might be possible to use the xml:lang attribute to // pick a default locale if (locale == null) locale = Locale.ENGLISH; return str.toUpperCase(locale); } } jaxen-1.1.6/src/java/main/org/jaxen/function/ext/LowerFunction.java0000664000175000017500000001032210371471320024570 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: LowerFunction.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function.ext; import java.util.List; import java.util.Locale; import org.jaxen.Context; import org.jaxen.FunctionCallException; import org.jaxen.Navigator; import org.jaxen.function.StringFunction; /** *

string lower-case(string) * * This function can take a second parameter of the * Locale to use for the String conversion. *

* *

* For example * * lower-case( /foo/bar ) * lower-case( /foo/@name, $myLocale ) *

* * @author mark wilson (markw@wilsoncom.de) * @author James Strachan */ public class LowerFunction extends LocaleFunctionSupport { public Object call(Context context, List args) throws FunctionCallException { Navigator navigator = context.getNavigator(); int size = args.size(); if (size > 0) { Object text = args.get(0); Locale locale = null; if (size > 1) { locale = getLocale( args.get(1), navigator ); } return evaluate( text, locale, navigator ); } throw new FunctionCallException( "lower-case() requires at least one argument." ); } /** * Converts the given string value to lower case using an optional Locale * * @param strArg the value which gets converted to a String * @param locale the Locale to use for the conversion or null * English should be used * @param nav the Navigator to use */ public static String evaluate(Object strArg, Locale locale, Navigator nav) { String str = StringFunction.evaluate( strArg, nav ); // it might be possible to use the xml:lang attribute to // pick a default locale if (locale == null) locale = Locale.ENGLISH; return str.toLowerCase(locale); } } jaxen-1.1.6/src/java/main/org/jaxen/function/ext/LocaleFunctionSupport.java0000664000175000017500000001402210371471320026275 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: LocaleFunctionSupport.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function.ext; import java.util.List; import java.util.Locale; import java.util.StringTokenizer; import org.jaxen.Function; import org.jaxen.Navigator; import org.jaxen.function.StringFunction; /** *

An abstract base class for Locale-specific extension * functions. This class provides convenience methods that * can be inherited, specifically to find a Locale from * an XPath function argument value. *

* * @author James Strachan */ public abstract class LocaleFunctionSupport implements Function { /** * Attempts to convert the given function argument value * into a Locale either via casting, extracting it from a List * or looking up the named Locale using reflection. * * @param value is either a Locale, a List containing a Locale * or a String containing the name of a Locale * as defined by the Locale static members. * * @return the Locale for the value or null if one could * not be deduced */ protected Locale getLocale(Object value, Navigator navigator) { if (value instanceof Locale) { return (Locale) value; } else if(value instanceof List) { List list = (List) value; if ( ! list.isEmpty() ) { return getLocale( list.get(0), navigator ); } } else { String text = StringFunction.evaluate( value, navigator ); if (text != null && text.length() > 0) { return findLocale( text ); } } return null; } /** * Tries to find a Locale instance by name using * RFC 3066 * language tags such as 'en', 'en-US', 'en-US-Brooklyn'. * * @param localeText the RFC 3066 language tag * @return the locale for the given text or null if one could not * be found */ protected Locale findLocale(String localeText) { StringTokenizer tokens = new StringTokenizer( localeText, "-" ); if (tokens.hasMoreTokens()) { String language = tokens.nextToken(); if (! tokens.hasMoreTokens()) { return findLocaleForLanguage(language); } else { String country = tokens.nextToken(); if (! tokens.hasMoreTokens()) { return new Locale(language, country); } else { String variant = tokens.nextToken(); return new Locale(language, country, variant); } } } return null; } /** * Finds the locale with the given language name with no country * or variant, such as Locale.ENGLISH or Locale.FRENCH * * @param language the language code to look for * @return the locale for the given language or null if one could not * be found */ protected Locale findLocaleForLanguage(String language) { Locale[] locales = Locale.getAvailableLocales(); for ( int i = 0, size = locales.length; i < size; i++ ) { Locale locale = locales[i]; if ( language.equals( locale.getLanguage() ) ) { String country = locale.getCountry(); if ( country == null || country.length() == 0 ) { String variant = locale.getVariant(); if ( variant == null || variant.length() == 0 ) { return locale; } } } } return null; } } jaxen-1.1.6/src/java/main/org/jaxen/function/ext/EndsWithFunction.java0000664000175000017500000000672710371471320025243 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: EndsWithFunction.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function.ext; import java.util.List; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.FunctionCallException; import org.jaxen.Navigator; import org.jaxen.function.StringFunction; /** *

boolean ends-with(string,string) * * @author mark wilson (markw @ wilsoncom.de) */ public class EndsWithFunction implements Function { public Object call(Context context, List args) throws FunctionCallException { if (args.size() == 2) { return evaluate( args.get(0), args.get(1), context.getNavigator() ); } throw new FunctionCallException( "ends-with() requires two arguments." ); } public static Boolean evaluate(Object strArg, Object matchArg, Navigator nav) { String str = StringFunction.evaluate( strArg, nav ); String match = StringFunction.evaluate( matchArg, nav ); return ( str.endsWith(match) ? Boolean.TRUE : Boolean.FALSE ); } } jaxen-1.1.6/src/java/main/org/jaxen/function/ext/package.html0000664000175000017500000000025707472132404023423 0ustar ebourgebourg org.jaxen.function.ext.*

Extension functions to the standard XPath function library.

jaxen-1.1.6/src/java/main/org/jaxen/function/BooleanFunction.java0000664000175000017500000001455310371471320024271 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: BooleanFunction.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function; import java.util.List; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.FunctionCallException; import org.jaxen.Navigator; /** *

* 4.3 boolean boolean(object) *

* *
*

* The boolean * function converts its argument to a boolean as follows: *

* *
    * *
  • *

    * a number is true if and only if it is neither positive or negative * zero nor NaN *

    *
  • * *
  • *

    * a node-set is true if and only if it is non-empty *

    *
  • * *
  • *

    * a string is true if and only if its length is non-zero *

    *
  • * *
  • * *

    * an object of a type other than the four basic types is converted to a * boolean in a way that is dependent on that type *

*
* * @author bob mcwhirter (bob @ werken.com) * @see Section 4.3 of the XPath Specification */ public class BooleanFunction implements Function { /** * Create a new BooleanFunction object. */ public BooleanFunction() {} /** Convert the argument to a Boolean * * @param context the context at the point in the * expression when the function is called * @param args a list with exactly one item which will be converted to a * Boolean * * @return the result of evaluating the function; * Boolean.TRUE or Boolean.FALSE * * @throws FunctionCallException if args has more or less than one item */ public Object call(Context context, List args) throws FunctionCallException { if ( args.size() == 1 ) { return evaluate( args.get(0), context.getNavigator() ); } throw new FunctionCallException("boolean() requires one argument"); } /** *

Convert the argument obj to a Boolean * according to the following rules:

* *
    *
  • Lists are false if they're empty; true if they're not.
  • *
  • Booleans are false if they're false; true if they're true.
  • *
  • Strings are false if they're empty; true if they're not.
  • *
  • Numbers are false if they're 0 or NaN; true if they're not.
  • *
  • All other objects are true.
  • *
* * @param obj the object to convert to a boolean * @param nav ignored * * @return Boolean.TRUE or Boolean.FALSE */ public static Boolean evaluate(Object obj, Navigator nav) { if ( obj instanceof List ) { List list = (List) obj; // if it's an empty list, then we have a null node-set -> false if (list.size() == 0) { return Boolean.FALSE; } // otherwise, unwrap the list and check the primitive obj = list.get(0); } // now check for primitive types // otherwise a non-empty node-set is true // if it's a Boolean, let it decide if ( obj instanceof Boolean ) { return (Boolean) obj; } // if it's a Number, != 0 -> true else if ( obj instanceof Number ) { double d = ((Number) obj).doubleValue(); if ( d == 0 || Double.isNaN(d) ) { return Boolean.FALSE; } return Boolean.TRUE; } // if it's a String, "" -> false else if ( obj instanceof String ) { return ( ((String)obj).length() > 0 ? Boolean.TRUE : Boolean.FALSE ); } else { // assume it's a node so that this node-set is non-empty // and so it's true return ( obj != null ) ? Boolean.TRUE : Boolean.FALSE; } } } jaxen-1.1.6/src/java/main/org/jaxen/function/RoundFunction.java0000664000175000017500000001204710371471320023775 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: RoundFunction.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function; import java.util.List; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.FunctionCallException; import org.jaxen.Navigator; /** *

4.4 number round(number)

* * *
* The round function returns the number that is closest to the argument and that is an integer. * If there are two such numbers, then the one that is closest to positive infinity is returned. * If the argument is NaN, then NaN is returned. If the argument is positive infinity, then positive infinity is returned. * If the argument is negative infinity, then negative infinity is returned. * If the argument is positive zero, then positive zero is returned. * If the argument is negative zero, then negative zero is returned. * If the argument is less than zero, but greater than or equal to -0.5, then negative zero is returned. *
* * @author bob mcwhirter (bob @ werken.com) * * @see Section 4.4 of the XPath Specification */ public class RoundFunction implements Function { /** * Create a new RoundFunction object. */ public RoundFunction() {} /** Returns the nearest integer to the number. * * @param context the context at the point in the * expression when the function is called * @param args a list with exactly one item which will be converted to a * Double as if by the XPath number() function * * @return a Double containing the integer nearest to * args.get(0) * * @throws FunctionCallException if args has more or less than one item */ public Object call(Context context, List args) throws FunctionCallException { if (args.size() == 1) { return evaluate( args.get(0), context.getNavigator() ); } throw new FunctionCallException( "round() requires one argument." ); } /** * Returns the integer nearest to the argument. * If necessary, the argument is first converted to a Double * as if by the XPath number() function. * * @param obj the object to be rounded * @param nav ignored * * @return the integer nearest to obj */ public static Double evaluate(Object obj, Navigator nav) { Double d = NumberFunction.evaluate( obj, nav ); if (d.isNaN() || d.isInfinite()) { return d; } double value = d.doubleValue(); return new Double( Math.round( value ) ); } } jaxen-1.1.6/src/java/main/org/jaxen/function/NormalizeSpaceFunction.java0000664000175000017500000001442610371471320025625 0ustar ebourgebourg/* * $Header$ * $Revision: 1128 $ * $Date: 2006-02-05 22:49:04 +0100 (Sun, 05 Feb 2006) $ * * ==================================================================== * * Copyright 2000-2002 bob mcwhirter & James Strachan. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of the Jaxen Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Jaxen Project and was originally * created by bob mcwhirter and * James Strachan . For more information on the * Jaxen Project, please see . * * $Id: NormalizeSpaceFunction.java 1128 2006-02-05 21:49:04Z elharo $ */ package org.jaxen.function; import java.util.List; import org.jaxen.Context; import org.jaxen.Function; import org.jaxen.FunctionCallException; import org.jaxen.Navigator; /** *

* 4.2 string normalize-space(string) *

* *
* The normalize-space function * returns the argument string with whitespace normalized by stripping * leading and trailing whitespace and replacing sequences of whitespace * characters by a single space. Whitespace characters are the same as * those allowed by the S * production in XML. If the argument is omitted, it defaults to the * context node converted to a string, in other words the string-value of the context node. *
* * @author James Strachan (james@metastuff.com) * @see Section 4.2 of the XPath Specification */ public class NormalizeSpaceFunction implements Function { /** * Create a new NormalizeSpaceFunction object. */ public NormalizeSpaceFunction() {} /** * Returns the string-value of the first item in args * after removing all leading and trailing white space, and * replacing each other sequence of whitespace by a single space. * Whitespace consists of the characters space (0x32), carriage return (0x0D), * linefeed (0x0A), and tab (0x09). * * @param context the context at the point in the * expression when the function is called * @param args a list that contains exactly one item * * @return a normalized String * * @throws FunctionCallException if args does not have length one */ public Object call(Context context, List args) throws FunctionCallException { if (args.size() == 0) { return evaluate( context.getNodeSet(), context.getNavigator() ); } else if (args.size() == 1) { return evaluate( args.get(0), context.getNavigator() ); } throw new FunctionCallException( "normalize-space() cannot have more than one argument" ); } /** * Returns the string-value of strArg after removing * all leading and trailing white space, and * replacing each other sequence of whitespace by a single space. * Whitespace consists of the characters space (0x32), carriage return (0x0D), * linefeed (0x0A), and tab (0x09). * * @param strArg the object whose string-value is normalized * @param nav the context at the point in the * expression when the function is called * * @return the normalized string-value */ public static String evaluate(Object strArg, Navigator nav) { String str = StringFunction.evaluate( strArg, nav ); char[] buffer = str.toCharArray(); int write = 0; int lastWrite = 0; boolean wroteOne = false; int read = 0; while (read < buffer.length) { if (isXMLSpace(buffer[read])) { if (wroteOne) { buffer[write++] = ' '; } do { read++; } while(read < buffer.length && isXMLSpace(buffer[read])); } else { buffer[write++] = buffer[read++]; wroteOne = true; lastWrite = write; } } return new String(buffer, 0, lastWrite); } private static boolean isXMLSpace(char c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t'; } } jaxen-1.1.6/src/java/main/org/jaxen/function/package.html0000664000175000017500000000022007327350513022613 0ustar ebourgebourg org.jaxen.function.*

Standard XPath function library.

jaxen-1.1.6/src/java/main/org/jaxen/package.html0000664000175000017500000000036707460140325020776 0ustar ebourgebourg org.jaxen.*

This package defines the core Jaxen API to the XPath engine. Using this API you can work with XPath on any object model.

jaxen-1.1.6/src/java/main/org/jaxen/NamedAccessNavigator.java0000664000175000017500000001010010371471320023360 0ustar ebourgebourg/* $Id: NamedAccessNavigator.java 1128 2006-02-05 21:49:04Z elharo $ Copyright 2003 The Werken Company. All Rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Jaxen Project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.jaxen; import java.util.Iterator; /** * Interface for navigating around an arbitrary object model * accessing certain parts by name for performance. *

* This interface must only be implemented by those models that * can support this named access behavior. * * @author Stephen Colebourne */ public interface NamedAccessNavigator extends Navigator { /** * Retrieve an Iterator that returns the child * XPath axis where the names of the children match the supplied name * and optional namespace. *

* This method must only return element nodes with the correct name. *

* If the namespaceURI is null, no namespace should be used. * The prefix will never be null. * * @param contextNode the origin context node * @param localName the local name of the children to return, always present * @param namespacePrefix the prefix of the namespace of the children to return * @param namespaceURI the namespace URI of the children to return * * @return an Iterator capable of traversing the named children, or null if none * * @throws UnsupportedAxisException if the child axis is * not supported by this object model */ Iterator getChildAxisIterator( Object contextNode, String localName, String namespacePrefix, String namespaceURI) throws UnsupportedAxisException; /** * Retrieve an Iterator that returns the attribute * XPath axis where the names of the attributes match the supplied name * and optional namespace. *

* This method must only return attribute nodes with the correct name. *

* If the namespaceURI is null, no namespace should be used. * The prefix will never be null. * * @param contextNode the origin context node * @param localName the local name of the attributes to return, always present * @param namespacePrefix the prefix of the namespace of the attributes to return * @param namespaceURI the URI of the namespace of the attributes to return * * @return an Iterator capable of traversing the named attributes, or null if none * * @throws UnsupportedAxisException if the attribute axis is * not supported by this object model */ Iterator getAttributeAxisIterator( Object contextNode, String localName, String namespacePrefix, String namespaceURI) throws UnsupportedAxisException; } jaxen-1.1.6/src/java/main/org/w3c/0000775000175000017500000000000012174247550016104 5ustar ebourgebourgjaxen-1.1.6/src/java/main/org/w3c/dom/0000775000175000017500000000000012174247550016663 5ustar ebourgebourgjaxen-1.1.6/src/java/main/org/w3c/dom/UserDataHandler.java0000664000175000017500000000153011465764417022543 0ustar ebourgebourg/** This is a W3C interface we include here so that NamespaceNode can compile in both * Java 1.4 and 1.5. It's owned by the W3C, and available under their usual * extremely liberal license so this shouldn't bother anyone. (XPath itself * is under the same license after all.) */ package org.w3c.dom; public interface UserDataHandler { // OperationType public static final short NODE_CLONED = 1; public static final short NODE_IMPORTED = 2; public static final short NODE_DELETED = 3; public static final short NODE_RENAMED = 4; public static final short NODE_ADOPTED = 5; public void handle(short operation, String key, Object data, Node src, Node dst); }jaxen-1.1.6/xml/0000775000175000017500000000000012174247547012773 5ustar ebourgebourgjaxen-1.1.6/xml/namespaces.xml0000664000175000017500000000047307735710460015634 0ustar ebourgebourg Hello Hey Hey2 Hey3 jaxen-1.1.6/xml/text.xml0000664000175000017500000000014307722735347014502 0ustar ebourgebourg baz baz baz jaxen-1.1.6/xml/testNamespaces.xml0000664000175000017500000000103210173336637016464 0ustar ebourgebourg jaxen-1.1.6/xml/web.xml0000664000175000017500000000152007472132404014256 0ustar ebourgebourg snoop SnoopServlet file ViewFile initial 1000 The initial value for the counter mv *.wm manager director president jaxen-1.1.6/xml/jaxen3.xml0000664000175000017500000000051210122411121014647 0ustar ebourgebourg 2 CE-A 1 CE-B jaxen-1.1.6/xml/jaxen24.xml0000664000175000017500000000013210173336637014760 0ustar ebourgebourg

jaxen-1.1.6/xml/pi2.xml0000664000175000017500000000012007460010231014154 0ustar ebourgebourg foo bar jaxen-1.1.6/xml/moreover.xml0000664000175000017500000002706607472132404015354 0ustar ebourgebourg
http://c.moreover.com/click/here.pl?x13563273 e-Commerce Operators Present Version 1.0 of the XML Standard StockAccess text moreover... http://www.stockaccess.com/index.html Dec 24 2000 6:28AM
http://c.moreover.com/click/here.pl?x13560995 W3C Publishes XML Protocol Requirements Document Xml text moreover... http://www.xml.com/ Dec 24 2000 12:22AM
http://c.moreover.com/click/here.pl?x13553521 Prowler: Open Source XML-Based Content Management Framework Xml text moreover... http://www.xml.com/ Dec 23 2000 2:05PM
http://c.moreover.com/click/here.pl?x13549013 The Middleware Company Debuts Public Training Courses in Ejb, J2ee And Xml Java Industry Connection text moreover... http://industry.java.sun.com/javanews/more/hotnews/ Dec 23 2000 12:15PM
http://c.moreover.com/click/here.pl?x13544467 Revised Working Draft for the W3C XML Information Set Xml text moreover... http://www.xml.com/ Dec 23 2000 5:50AM
http://c.moreover.com/click/here.pl?x13534836 XML: Its The Great Peacemaker ZDNet text moreover... http://www.zdnet.com/intweek/ Dec 22 2000 9:05PM
http://c.moreover.com/click/here.pl?x13533485 Project eL - The XML Leningrad Codex Markup Project Xml text moreover... http://www.xml.com/ Dec 22 2000 8:34PM
http://c.moreover.com/click/here.pl?x13533488 XML Linking Language (XLink) and XML Base Specifications Issued as W3C Proposed Recommenda Xml text moreover... http://www.xml.com/ Dec 22 2000 8:34PM
http://c.moreover.com/click/here.pl?x13533492 W3C Releases XHTML Basic Specification as a W3C Recommendation Xml text moreover... http://www.xml.com/ Dec 22 2000 8:34PM
http://c.moreover.com/click/here.pl?x13521827 Java, Xml And Oracle9i(TM) Make A Great Team Java Industry Connection text moreover... http://industry.java.sun.com/javanews/more/hotnews/ Dec 22 2000 3:21PM
http://c.moreover.com/click/here.pl?x13511233 Competing initiatives to vie for security standard ZDNet text moreover... http://www.zdnet.com/eweek/filters/news/ Dec 22 2000 10:54AM
http://c.moreover.com/click/here.pl?x13492397 Oracle Provides Developers with Great Xml Reading This Holiday Season Java Industry Connection text moreover... http://industry.java.sun.com/javanews/more/hotnews/ Dec 21 2000 8:08PM
http://c.moreover.com/click/here.pl?x13491292 XML as the great peacemaker - Extensible Markup Language Accomplished The Seemingly Impossible This Year: It B Hospitality Net text moreover... http://www.hospitalitynet.org/news/list.htm?c=2000 Dec 21 2000 7:45PM
http://c.moreover.com/click/here.pl?x13484758 XML as the great peacemaker CNET text moreover... http://news.cnet.com/news/0-1003.html?tag=st.ne.1002.dir.1003 Dec 21 2000 4:41PM
http://c.moreover.com/click/here.pl?x13480896 COOP Switzerland Selects Mercator as Integration Platform Stockhouse Canada text moreover... http://www.stockhouse.ca/news/ Dec 21 2000 1:55PM
http://c.moreover.com/click/here.pl?x13471023 Competing XML Specs Move Toward a Union Internet World text moreover... http://www.internetworld.com/ Dec 21 2000 11:14AM
http://c.moreover.com/click/here.pl?x13452280 Next-generation XHTML stripped down for handhelds CNET text moreover... http://news.cnet.com/news/0-1005.html?tag=st.ne.1002.dir.1005 Dec 20 2000 9:11PM
http://c.moreover.com/click/here.pl?x13451789 Xml Powers Oracle9i(TM) Dynamic Services Java Industry Connection text moreover... http://industry.java.sun.com/javanews/more/hotnews/ Dec 20 2000 9:05PM
http://c.moreover.com/click/here.pl?x13442097 XML DOM reference guide ASPWire text moreover... http://aspwire.com/ Dec 20 2000 6:26PM
http://c.moreover.com/click/here.pl?x13424117 Repeat/Xqsite And Bowstreet Team to Deliver Integrated Xml Solutions Java Industry Connection text moreover... http://industry.java.sun.com/javanews/more/hotnews/ Dec 20 2000 9:04AM
jaxen-1.1.6/xml/test/0000775000175000017500000000000012174247546013751 5ustar ebourgebourgjaxen-1.1.6/xml/test/tests.xml0000664000175000017500000006505411127416005015630 0ustar ebourgebourg span abd abd a d 1 2 1 2 true true true true true true true true true true true true 0 1 3 false false false false true true order-by="x" foo order-by="x" foobar is tasty true true false true true false a.2 a.1 a.4 a.5 snoop snoop file file snoop snoop web-app web-app web-app web-app web-app web-app web-app web-app web-app web-app web-app web-app web-app web-app web-app web-app web-app web-app web-app http://c.moreover.com/click/here.pl?x13563273 http://c.moreover.com/click/here.pl?x13563273 http://c.moreover.com/click/here.pl?x13563273 http://c.moreover.com/click/here.pl?x13563273 http://c.moreover.com/click/here.pl?x13563273 http://c.moreover.com/click/here.pl?x13563273 196417 325 1 75025 46368 2 2 Much Ado about Nothing 4 21 5 35 75 646 142 2 1 3 1 6 5 snoop snoop snoop 3foo3 3snoop3 Pruefgebiete Pruefgebiete ab ba ba db abcd abcd abcd dcba ab cd xy abcd abcd 234 12 12345 345 12345 abc a b c a b c SNOOPSERVLET snoopservlet SNOOPSERVLET SNOOPSERVLET SNOOPSERVLET true false Hello Hey Hey3 Hey3 Hey3 baz jaxen-1.1.6/xml/test/tests.xsl0000664000175000017500000003313110254351622015630 0ustar ebourgebourg jaxen-1.1.6/xml/nitf.xml0000664000175000017500000000106311034237622014440 0ustar ebourgebourg jaxen-1.1.6/xml/numbers.xml0000664000175000017500000000040307350653325015160 0ustar ebourgebourg 3 24 55 11 2 -3 jaxen-1.1.6/xml/lang.xml0000664000175000017500000000024107564217646014437 0ustar ebourgebourg jaxen-1.1.6/xml/id.xml0000664000175000017500000000057507347412526014115 0ustar ebourgebourg ]> baz gouda baz cheddar baz jaxen-1.1.6/xml/evaluate.xml0000664000175000017500000000117507350230720015310 0ustar ebourgebourg brown moderate jaxen-1.1.6/xml/axis.xml0000664000175000017500000000033507341267676014467 0ustar ebourgebourg jaxen-1.1.6/xml/simplevariablecontext.ser0000664000175000017500000000065410437564455020117 0ustar ebourgebourgsrorg.jaxen.SimpleVariableContext WMY[^&L variablestLjava/util/Map;xpsrjava.util.HashMap`F loadFactorI thresholdxp?@ wsrorg.jaxen.QualifiedName%^/L localNametLjava/lang/String;L namespaceURIq~xptbtsrjava.lang.Boolean r՜Zvaluexpsq~txq~ srjava.lang.DoubleJ)kDvaluexrjava.lang.Number xp@ !nsq~tsq~ t String Valuexjaxen-1.1.6/xml/simple.xml0000664000175000017500000000010410173336637014775 0ustar ebourgebourg abd jaxen-1.1.6/xml/contents.xml0000664000175000017500000000500007472132404015333 0ustar ebourgebourg Java and XML Introduction What Is It? How Do I Use It? Why Should I Use It? What's Next? Creating XML An XML Document The Header The Content What's Next? Parsing XML Getting Prepared SAX Readers Content Handlers Error Handlers A Better Way to Load a Parser "Gotcha!" What's Next? Web Publishing Frameworks Selecting a Framework Installation Using a Publishing Framework XSP Cocoon 2.0 and Beyond What's Next? jaxen-1.1.6/xml/pi.xml0000664000175000017500000000024407345166226014123 0ustar ebourgebourg jaxen-1.1.6/xml/defaultNamespace.xml0000664000175000017500000000013407735710460016750 0ustar ebourgebourg Hello jaxen-1.1.6/xml/message.xml0000664000175000017500000000107107340224470015125 0ustar ebourgebourg
lookupformservice 9 stammdaten new
iteminfo ELE parentinfo Pruefgebiete id 1
jaxen-1.1.6/xml/much_ado.xml0000664000175000017500000057515307472132404015302 0ustar ebourgebourg Much Ado about Nothing

Text placed in the public domain by Moby Lexical Tools, 1992.

SGML markup by Jon Bosak, 1992-1994.

XML version by Jon Bosak, 1996-1998.

This work may be freely copied and distributed worldwide.

Dramatis Personae DON PEDRO, prince of Arragon. DON JOHN, his bastard brother. CLAUDIO, a young lord of Florence. BENEDICK, a young lord of Padua. LEONATO, governor of Messina. ANTONIO, his brother. BALTHASAR, attendant on Don Pedro. CONRADE BORACHIO followers of Don John. FRIAR FRANCIS DOGBERRY, a constable. VERGES, a headborough. A Sexton. A Boy. HERO, daughter to Leonato. BEATRICE, niece to Leonato. MARGARET URSULA gentlewomen attending on Hero. Messengers, Watch, Attendants, &c. SCENE Messina. MUCH ADO ABOUT NOTHING ACT I SCENE I. Before LEONATO'S house. Enter LEONATO, HERO, and BEATRICE, with a Messenger LEONATO I learn in this letter that Don Peter of Arragon comes this night to Messina. Messenger He is very near by this: he was not three leagues off when I left him. LEONATO How many gentlemen have you lost in this action? Messenger But few of any sort, and none of name. LEONATO A victory is twice itself when the achiever brings home full numbers. I find here that Don Peter hath bestowed much honour on a young Florentine called Claudio. Messenger Much deserved on his part and equally remembered by Don Pedro: he hath borne himself beyond the promise of his age, doing, in the figure of a lamb, the feats of a lion: he hath indeed better bettered expectation than you must expect of me to tell you how. LEONATO He hath an uncle here in Messina will be very much glad of it. Messenger I have already delivered him letters, and there appears much joy in him; even so much that joy could not show itself modest enough without a badge of bitterness. LEONATO Did he break out into tears? Messenger In great measure. LEONATO A kind overflow of kindness: there are no faces truer than those that are so washed. How much better is it to weep at joy than to joy at weeping! BEATRICE I pray you, is Signior Mountanto returned from the wars or no? Messenger I know none of that name, lady: there was none such in the army of any sort. LEONATO What is he that you ask for, niece? HERO My cousin means Signior Benedick of Padua. Messenger O, he's returned; and as pleasant as ever he was. BEATRICE He set up his bills here in Messina and challenged Cupid at the flight; and my uncle's fool, reading the challenge, subscribed for Cupid, and challenged him at the bird-bolt. I pray you, how many hath he killed and eaten in these wars? But how many hath he killed? for indeed I promised to eat all of his killing. LEONATO Faith, niece, you tax Signior Benedick too much; but he'll be meet with you, I doubt it not. Messenger He hath done good service, lady, in these wars. BEATRICE You had musty victual, and he hath holp to eat it: he is a very valiant trencherman; he hath an excellent stomach. Messenger And a good soldier too, lady. BEATRICE And a good soldier to a lady: but what is he to a lord? Messenger A lord to a lord, a man to a man; stuffed with all honourable virtues. BEATRICE It is so, indeed; he is no less than a stuffed man: but for the stuffing,--well, we are all mortal. LEONATO You must not, sir, mistake my niece. There is a kind of merry war betwixt Signior Benedick and her: they never meet but there's a skirmish of wit between them. BEATRICE Alas! he gets nothing by that. In our last conflict four of his five wits went halting off, and now is the whole man governed with one: so that if he have wit enough to keep himself warm, let him bear it for a difference between himself and his horse; for it is all the wealth that he hath left, to be known a reasonable creature. Who is his companion now? He hath every month a new sworn brother. Messenger Is't possible? BEATRICE Very easily possible: he wears his faith but as the fashion of his hat; it ever changes with the next block. Messenger I see, lady, the gentleman is not in your books. BEATRICE No; an he were, I would burn my study. But, I pray you, who is his companion? Is there no young squarer now that will make a voyage with him to the devil? Messenger He is most in the company of the right noble Claudio. BEATRICE O Lord, he will hang upon him like a disease: he is sooner caught than the pestilence, and the taker runs presently mad. God help the noble Claudio! if he have caught the Benedick, it will cost him a thousand pound ere a' be cured. Messenger I will hold friends with you, lady. BEATRICE Do, good friend. LEONATO You will never run mad, niece. BEATRICE No, not till a hot January. Messenger Don Pedro is approached. Enter DON PEDRO, DON JOHN, CLAUDIO, BENEDICK, and BALTHASAR DON PEDRO Good Signior Leonato, you are come to meet your trouble: the fashion of the world is to avoid cost, and you encounter it. LEONATO Never came trouble to my house in the likeness of your grace: for trouble being gone, comfort should remain; but when you depart from me, sorrow abides and happiness takes his leave. DON PEDRO You embrace your charge too willingly. I think this is your daughter. LEONATO Her mother hath many times told me so. BENEDICK Were you in doubt, sir, that you asked her? LEONATO Signior Benedick, no; for then were you a child. DON PEDRO You have it full, Benedick: we may guess by this what you are, being a man. Truly, the lady fathers herself. Be happy, lady; for you are like an honourable father. BENEDICK If Signior Leonato be her father, she would not have his head on her shoulders for all Messina, as like him as she is. BEATRICE I wonder that you will still be talking, Signior Benedick: nobody marks you. BENEDICK What, my dear Lady Disdain! are you yet living? BEATRICE Is it possible disdain should die while she hath such meet food to feed it as Signior Benedick? Courtesy itself must convert to disdain, if you come in her presence. BENEDICK Then is courtesy a turncoat. But it is certain I am loved of all ladies, only you excepted: and I would I could find in my heart that I had not a hard heart; for, truly, I love none. BEATRICE A dear happiness to women: they would else have been troubled with a pernicious suitor. I thank God and my cold blood, I am of your humour for that: I had rather hear my dog bark at a crow than a man swear he loves me. BENEDICK God keep your ladyship still in that mind! so some gentleman or other shall 'scape a predestinate scratched face. BEATRICE Scratching could not make it worse, an 'twere such a face as yours were. BENEDICK Well, you are a rare parrot-teacher. BEATRICE A bird of my tongue is better than a beast of yours. BENEDICK I would my horse had the speed of your tongue, and so good a continuer. But keep your way, i' God's name; I have done. BEATRICE You always end with a jade's trick: I know you of old. DON PEDRO That is the sum of all, Leonato. Signior Claudio and Signior Benedick, my dear friend Leonato hath invited you all. I tell him we shall stay here at the least a month; and he heartily prays some occasion may detain us longer. I dare swear he is no hypocrite, but prays from his heart. LEONATO If you swear, my lord, you shall not be forsworn. To DON JOHN Let me bid you welcome, my lord: being reconciled to the prince your brother, I owe you all duty. DON JOHN I thank you: I am not of many words, but I thank you. LEONATO Please it your grace lead on? DON PEDRO Your hand, Leonato; we will go together. Exeunt all except BENEDICK and CLAUDIO CLAUDIO Benedick, didst thou note the daughter of Signior Leonato? BENEDICK I noted her not; but I looked on her. CLAUDIO Is she not a modest young lady? BENEDICK Do you question me, as an honest man should do, for my simple true judgment; or would you have me speak after my custom, as being a professed tyrant to their sex? CLAUDIO No; I pray thee speak in sober judgment. BENEDICK Why, i' faith, methinks she's too low for a high praise, too brown for a fair praise and too little for a great praise: only this commendation I can afford her, that were she other than she is, she were unhandsome; and being no other but as she is, I do not like her. CLAUDIO Thou thinkest I am in sport: I pray thee tell me truly how thou likest her. BENEDICK Would you buy her, that you inquire after her? CLAUDIO Can the world buy such a jewel? BENEDICK Yea, and a case to put it into. But speak you this with a sad brow? or do you play the flouting Jack, to tell us Cupid is a good hare-finder and Vulcan a rare carpenter? Come, in what key shall a man take you, to go in the song? CLAUDIO In mine eye she is the sweetest lady that ever I looked on. BENEDICK I can see yet without spectacles and I see no such matter: there's her cousin, an she were not possessed with a fury, exceeds her as much in beauty as the first of May doth the last of December. But I hope you have no intent to turn husband, have you? CLAUDIO I would scarce trust myself, though I had sworn the contrary, if Hero would be my wife. BENEDICK Is't come to this? In faith, hath not the world one man but he will wear his cap with suspicion? Shall I never see a bachelor of three-score again? Go to, i' faith; an thou wilt needs thrust thy neck into a yoke, wear the print of it and sigh away Sundays. Look Don Pedro is returned to seek you. Re-enter DON PEDRO DON PEDRO What secret hath held you here, that you followed not to Leonato's? BENEDICK I would your grace would constrain me to tell. DON PEDRO I charge thee on thy allegiance. BENEDICK You hear, Count Claudio: I can be secret as a dumb man; I would have you think so; but, on my allegiance, mark you this, on my allegiance. He is in love. With who? now that is your grace's part. Mark how short his answer is;--With Hero, Leonato's short daughter. CLAUDIO If this were so, so were it uttered. BENEDICK Like the old tale, my lord: 'it is not so, nor 'twas not so, but, indeed, God forbid it should be so.' CLAUDIO If my passion change not shortly, God forbid it should be otherwise. DON PEDRO Amen, if you love her; for the lady is very well worthy. CLAUDIO You speak this to fetch me in, my lord. DON PEDRO By my troth, I speak my thought. CLAUDIO And, in faith, my lord, I spoke mine. BENEDICK And, by my two faiths and troths, my lord, I spoke mine. CLAUDIO That I love her, I feel. DON PEDRO That she is worthy, I know. BENEDICK That I neither feel how she should be loved nor know how she should be worthy, is the opinion that fire cannot melt out of me: I will die in it at the stake. DON PEDRO Thou wast ever an obstinate heretic in the despite of beauty. CLAUDIO And never could maintain his part but in the force of his will. BENEDICK That a woman conceived me, I thank her; that she brought me up, I likewise give her most humble thanks: but that I will have a recheat winded in my forehead, or hang my bugle in an invisible baldrick, all women shall pardon me. Because I will not do them the wrong to mistrust any, I will do myself the right to trust none; and the fine is, for the which I may go the finer, I will live a bachelor. DON PEDRO I shall see thee, ere I die, look pale with love. BENEDICK With anger, with sickness, or with hunger, my lord, not with love: prove that ever I lose more blood with love than I will get again with drinking, pick out mine eyes with a ballad-maker's pen and hang me up at the door of a brothel-house for the sign of blind Cupid. DON PEDRO Well, if ever thou dost fall from this faith, thou wilt prove a notable argument. BENEDICK If I do, hang me in a bottle like a cat and shoot at me; and he that hits me, let him be clapped on the shoulder, and called Adam. DON PEDRO Well, as time shall try: 'In time the savage bull doth bear the yoke.' BENEDICK The savage bull may; but if ever the sensible Benedick bear it, pluck off the bull's horns and set them in my forehead: and let me be vilely painted, and in such great letters as they write 'Here is good horse to hire,' let them signify under my sign 'Here you may see Benedick the married man.' CLAUDIO If this should ever happen, thou wouldst be horn-mad. DON PEDRO Nay, if Cupid have not spent all his quiver in Venice, thou wilt quake for this shortly. BENEDICK I look for an earthquake too, then. DON PEDRO Well, you temporize with the hours. In the meantime, good Signior Benedick, repair to Leonato's: commend me to him and tell him I will not fail him at supper; for indeed he hath made great preparation. BENEDICK I have almost matter enough in me for such an embassage; and so I commit you-- CLAUDIO To the tuition of God: From my house, if I had it,-- DON PEDRO The sixth of July: Your loving friend, Benedick. BENEDICK Nay, mock not, mock not. The body of your discourse is sometime guarded with fragments, and the guards are but slightly basted on neither: ere you flout old ends any further, examine your conscience: and so I leave you. Exit CLAUDIO My liege, your highness now may do me good. DON PEDRO My love is thine to teach: teach it but how, And thou shalt see how apt it is to learn Any hard lesson that may do thee good. CLAUDIO Hath Leonato any son, my lord? DON PEDRO No child but Hero; she's his only heir. Dost thou affect her, Claudio? CLAUDIO O, my lord, When you went onward on this ended action, I look'd upon her with a soldier's eye, That liked, but had a rougher task in hand Than to drive liking to the name of love: But now I am return'd and that war-thoughts Have left their places vacant, in their rooms Come thronging soft and delicate desires, All prompting me how fair young Hero is, Saying, I liked her ere I went to wars. DON PEDRO Thou wilt be like a lover presently And tire the hearer with a book of words. If thou dost love fair Hero, cherish it, And I will break with her and with her father, And thou shalt have her. Was't not to this end That thou began'st to twist so fine a story? CLAUDIO How sweetly you do minister to love, That know love's grief by his complexion! But lest my liking might too sudden seem, I would have salved it with a longer treatise. DON PEDRO What need the bridge much broader than the flood? The fairest grant is the necessity. Look, what will serve is fit: 'tis once, thou lovest, And I will fit thee with the remedy. I know we shall have revelling to-night: I will assume thy part in some disguise And tell fair Hero I am Claudio, And in her bosom I'll unclasp my heart And take her hearing prisoner with the force And strong encounter of my amorous tale: Then after to her father will I break; And the conclusion is, she shall be thine. In practise let us put it presently. Exeunt SCENE II. A room in LEONATO's house. Enter LEONATO and ANTONIO, meeting LEONATO How now, brother! Where is my cousin, your son? hath he provided this music? ANTONIO He is very busy about it. But, brother, I can tell you strange news that you yet dreamt not of. LEONATO Are they good? ANTONIO As the event stamps them: but they have a good cover; they show well outward. The prince and Count Claudio, walking in a thick-pleached alley in mine orchard, were thus much overheard by a man of mine: the prince discovered to Claudio that he loved my niece your daughter and meant to acknowledge it this night in a dance: and if he found her accordant, he meant to take the present time by the top and instantly break with you of it. LEONATO Hath the fellow any wit that told you this? ANTONIO A good sharp fellow: I will send for him; and question him yourself. LEONATO No, no; we will hold it as a dream till it appear itself: but I will acquaint my daughter withal, that she may be the better prepared for an answer, if peradventure this be true. Go you and tell her of it. Enter Attendants Cousins, you know what you have to do. O, I cry you mercy, friend; go you with me, and I will use your skill. Good cousin, have a care this busy time. Exeunt SCENE III. The same. Enter DON JOHN and CONRADE CONRADE What the good-year, my lord! why are you thus out of measure sad? DON JOHN There is no measure in the occasion that breeds; therefore the sadness is without limit. CONRADE You should hear reason. DON JOHN And when I have heard it, what blessing brings it? CONRADE If not a present remedy, at least a patient sufferance. DON JOHN I wonder that thou, being, as thou sayest thou art, born under Saturn, goest about to apply a moral medicine to a mortifying mischief. I cannot hide what I am: I must be sad when I have cause and smile at no man's jests, eat when I have stomach and wait for no man's leisure, sleep when I am drowsy and tend on no man's business, laugh when I am merry and claw no man in his humour. CONRADE Yea, but you must not make the full show of this till you may do it without controlment. You have of late stood out against your brother, and he hath ta'en you newly into his grace; where it is impossible you should take true root but by the fair weather that you make yourself: it is needful that you frame the season for your own harvest. DON JOHN I had rather be a canker in a hedge than a rose in his grace, and it better fits my blood to be disdained of all than to fashion a carriage to rob love from any: in this, though I cannot be said to be a flattering honest man, it must not be denied but I am a plain-dealing villain. I am trusted with a muzzle and enfranchised with a clog; therefore I have decreed not to sing in my cage. If I had my mouth, I would bite; if I had my liberty, I would do my liking: in the meantime let me be that I am and seek not to alter me. CONRADE Can you make no use of your discontent? DON JOHN I make all use of it, for I use it only. Who comes here? Enter BORACHIO What news, Borachio? BORACHIO I came yonder from a great supper: the prince your brother is royally entertained by Leonato: and I can give you intelligence of an intended marriage. DON JOHN Will it serve for any model to build mischief on? What is he for a fool that betroths himself to unquietness? BORACHIO Marry, it is your brother's right hand. DON JOHN Who? the most exquisite Claudio? BORACHIO Even he. DON JOHN A proper squire! And who, and who? which way looks he? BORACHIO Marry, on Hero, the daughter and heir of Leonato. DON JOHN A very forward March-chick! How came you to this? BORACHIO Being entertained for a perfumer, as I was smoking a musty room, comes me the prince and Claudio, hand in hand in sad conference: I whipt me behind the arras; and there heard it agreed upon that the prince should woo Hero for himself, and having obtained her, give her to Count Claudio. DON JOHN Come, come, let us thither: this may prove food to my displeasure. That young start-up hath all the glory of my overthrow: if I can cross him any way, I bless myself every way. You are both sure, and will assist me? CONRADE To the death, my lord. DON JOHN Let us to the great supper: their cheer is the greater that I am subdued. Would the cook were of my mind! Shall we go prove what's to be done? BORACHIO We'll wait upon your lordship. Exeunt ACT II SCENE I. A hall in LEONATO'S house. Enter LEONATO, ANTONIO, HERO, BEATRICE, and others LEONATO Was not Count John here at supper? ANTONIO I saw him not. BEATRICE How tartly that gentleman looks! I never can see him but I am heart-burned an hour after. HERO He is of a very melancholy disposition. BEATRICE He were an excellent man that were made just in the midway between him and Benedick: the one is too like an image and says nothing, and the other too like my lady's eldest son, evermore tattling. LEONATO Then half Signior Benedick's tongue in Count John's mouth, and half Count John's melancholy in Signior Benedick's face,-- BEATRICE With a good leg and a good foot, uncle, and money enough in his purse, such a man would win any woman in the world, if a' could get her good-will. LEONATO By my troth, niece, thou wilt never get thee a husband, if thou be so shrewd of thy tongue. ANTONIO In faith, she's too curst. BEATRICE Too curst is more than curst: I shall lessen God's sending that way; for it is said, 'God sends a curst cow short horns;' but to a cow too curst he sends none. LEONATO So, by being too curst, God will send you no horns. BEATRICE Just, if he send me no husband; for the which blessing I am at him upon my knees every morning and evening. Lord, I could not endure a husband with a beard on his face: I had rather lie in the woollen. LEONATO You may light on a husband that hath no beard. BEATRICE What should I do with him? dress him in my apparel and make him my waiting-gentlewoman? He that hath a beard is more than a youth, and he that hath no beard is less than a man: and he that is more than a youth is not for me, and he that is less than a man, I am not for him: therefore, I will even take sixpence in earnest of the bear-ward, and lead his apes into hell. LEONATO Well, then, go you into hell? BEATRICE No, but to the gate; and there will the devil meet me, like an old cuckold, with horns on his head, and say 'Get you to heaven, Beatrice, get you to heaven; here's no place for you maids:' so deliver I up my apes, and away to Saint Peter for the heavens; he shows me where the bachelors sit, and there live we as merry as the day is long. ANTONIO To HERO Well, niece, I trust you will be ruled by your father. BEATRICE Yes, faith; it is my cousin's duty to make curtsy and say 'Father, as it please you.' But yet for all that, cousin, let him be a handsome fellow, or else make another curtsy and say 'Father, as it please me.' LEONATO Well, niece, I hope to see you one day fitted with a husband. BEATRICE Not till God make men of some other metal than earth. Would it not grieve a woman to be overmastered with a pierce of valiant dust? to make an account of her life to a clod of wayward marl? No, uncle, I'll none: Adam's sons are my brethren; and, truly, I hold it a sin to match in my kindred. LEONATO Daughter, remember what I told you: if the prince do solicit you in that kind, you know your answer. BEATRICE The fault will be in the music, cousin, if you be not wooed in good time: if the prince be too important, tell him there is measure in every thing and so dance out the answer. For, hear me, Hero: wooing, wedding, and repenting, is as a Scotch jig, a measure, and a cinque pace: the first suit is hot and hasty, like a Scotch jig, and full as fantastical; the wedding, mannerly-modest, as a measure, full of state and ancientry; and then comes repentance and, with his bad legs, falls into the cinque pace faster and faster, till he sink into his grave. LEONATO Cousin, you apprehend passing shrewdly. BEATRICE I have a good eye, uncle; I can see a church by daylight. LEONATO The revellers are entering, brother: make good room. All put on their masks Enter DON PEDRO, CLAUDIO, BENEDICK, BALTHASAR, DON JOHN, BORACHIO, MARGARET, URSULA and others, masked DON PEDRO Lady, will you walk about with your friend? HERO So you walk softly and look sweetly and say nothing, I am yours for the walk; and especially when I walk away. DON PEDRO With me in your company? HERO I may say so, when I please. DON PEDRO And when please you to say so? HERO When I like your favour; for God defend the lute should be like the case! DON PEDRO My visor is Philemon's roof; within the house is Jove. HERO Why, then, your visor should be thatched. DON PEDRO Speak low, if you speak love. Drawing her aside BALTHASAR Well, I would you did like me. MARGARET So would not I, for your own sake; for I have many ill-qualities. BALTHASAR Which is one? MARGARET I say my prayers aloud. BALTHASAR I love you the better: the hearers may cry, Amen. MARGARET God match me with a good dancer! BALTHASAR Amen. MARGARET And God keep him out of my sight when the dance is done! Answer, clerk. BALTHASAR No more words: the clerk is answered. URSULA I know you well enough; you are Signior Antonio. ANTONIO At a word, I am not. URSULA I know you by the waggling of your head. ANTONIO To tell you true, I counterfeit him. URSULA You could never do him so ill-well, unless you were the very man. Here's his dry hand up and down: you are he, you are he. ANTONIO At a word, I am not. URSULA Come, come, do you think I do not know you by your excellent wit? can virtue hide itself? Go to, mum, you are he: graces will appear, and there's an end. BEATRICE Will you not tell me who told you so? BENEDICK No, you shall pardon me. BEATRICE Nor will you not tell me who you are? BENEDICK Not now. BEATRICE That I was disdainful, and that I had my good wit out of the 'Hundred Merry Tales:'--well this was Signior Benedick that said so. BENEDICK What's he? BEATRICE I am sure you know him well enough. BENEDICK Not I, believe me. BEATRICE Did he never make you laugh? BENEDICK I pray you, what is he? BEATRICE Why, he is the prince's jester: a very dull fool; only his gift is in devising impossible slanders: none but libertines delight in him; and the commendation is not in his wit, but in his villany; for he both pleases men and angers them, and then they laugh at him and beat him. I am sure he is in the fleet: I would he had boarded me. BENEDICK When I know the gentleman, I'll tell him what you say. BEATRICE Do, do: he'll but break a comparison or two on me; which, peradventure not marked or not laughed at, strikes him into melancholy; and then there's a partridge wing saved, for the fool will eat no supper that night. Music We must follow the leaders. BENEDICK In every good thing. BEATRICE Nay, if they lead to any ill, I will leave them at the next turning. Dance. Then exeunt all except DON JOHN, BORACHIO, and CLAUDIO DON JOHN Sure my brother is amorous on Hero and hath withdrawn her father to break with him about it. The ladies follow her and but one visor remains. BORACHIO And that is Claudio: I know him by his bearing. DON JOHN Are not you Signior Benedick? CLAUDIO You know me well; I am he. DON JOHN Signior, you are very near my brother in his love: he is enamoured on Hero; I pray you, dissuade him from her: she is no equal for his birth: you may do the part of an honest man in it. CLAUDIO How know you he loves her? DON JOHN I heard him swear his affection. BORACHIO So did I too; and he swore he would marry her to-night. DON JOHN Come, let us to the banquet. Exeunt DON JOHN and BORACHIO CLAUDIO Thus answer I in the name of Benedick, But hear these ill news with the ears of Claudio. 'Tis certain so; the prince wooes for himself. Friendship is constant in all other things Save in the office and affairs of love: Therefore, all hearts in love use their own tongues; Let every eye negotiate for itself And trust no agent; for beauty is a witch Against whose charms faith melteth into blood. This is an accident of hourly proof, Which I mistrusted not. Farewell, therefore, Hero! Re-enter BENEDICK BENEDICK Count Claudio? CLAUDIO Yea, the same. BENEDICK Come, will you go with me? CLAUDIO Whither? BENEDICK Even to the next willow, about your own business, county. What fashion will you wear the garland of? about your neck, like an usurer's chain? or under your arm, like a lieutenant's scarf? You must wear it one way, for the prince hath got your Hero. CLAUDIO I wish him joy of her. BENEDICK Why, that's spoken like an honest drovier: so they sell bullocks. But did you think the prince would have served you thus? CLAUDIO I pray you, leave me. BENEDICK Ho! now you strike like the blind man: 'twas the boy that stole your meat, and you'll beat the post. CLAUDIO If it will not be, I'll leave you. Exit BENEDICK Alas, poor hurt fowl! now will he creep into sedges. But that my Lady Beatrice should know me, and not know me! The prince's fool! Ha? It may be I go under that title because I am merry. Yea, but so I am apt to do myself wrong; I am not so reputed: it is the base, though bitter, disposition of Beatrice that puts the world into her person and so gives me out. Well, I'll be revenged as I may. Re-enter DON PEDRO DON PEDRO Now, signior, where's the count? did you see him? BENEDICK Troth, my lord, I have played the part of Lady Fame. I found him here as melancholy as a lodge in a warren: I told him, and I think I told him true, that your grace had got the good will of this young lady; and I offered him my company to a willow-tree, either to make him a garland, as being forsaken, or to bind him up a rod, as being worthy to be whipped. DON PEDRO To be whipped! What's his fault? BENEDICK The flat transgression of a schoolboy, who, being overjoyed with finding a birds' nest, shows it his companion, and he steals it. DON PEDRO Wilt thou make a trust a transgression? The transgression is in the stealer. BENEDICK Yet it had not been amiss the rod had been made, and the garland too; for the garland he might have worn himself, and the rod he might have bestowed on you, who, as I take it, have stolen his birds' nest. DON PEDRO I will but teach them to sing, and restore them to the owner. BENEDICK If their singing answer your saying, by my faith, you say honestly. DON PEDRO The Lady Beatrice hath a quarrel to you: the gentleman that danced with her told her she is much wronged by you. BENEDICK O, she misused me past the endurance of a block! an oak but with one green leaf on it would have answered her; my very visor began to assume life and scold with her. She told me, not thinking I had been myself, that I was the prince's jester, that I was duller than a great thaw; huddling jest upon jest with such impossible conveyance upon me that I stood like a man at a mark, with a whole army shooting at me. She speaks poniards, and every word stabs: if her breath were as terrible as her terminations, there were no living near her; she would infect to the north star. I would not marry her, though she were endowed with all that Adam bad left him before he transgressed: she would have made Hercules have turned spit, yea, and have cleft his club to make the fire too. Come, talk not of her: you shall find her the infernal Ate in good apparel. I would to God some scholar would conjure her; for certainly, while she is here, a man may live as quiet in hell as in a sanctuary; and people sin upon purpose, because they would go thither; so, indeed, all disquiet, horror and perturbation follows her. DON PEDRO Look, here she comes. Enter CLAUDIO, BEATRICE, HERO, and LEONATO BENEDICK Will your grace command me any service to the world's end? I will go on the slightest errand now to the Antipodes that you can devise to send me on; I will fetch you a tooth-picker now from the furthest inch of Asia, bring you the length of Prester John's foot, fetch you a hair off the great Cham's beard, do you any embassage to the Pigmies, rather than hold three words' conference with this harpy. You have no employment for me? DON PEDRO None, but to desire your good company. BENEDICK O God, sir, here's a dish I love not: I cannot endure my Lady Tongue. Exit DON PEDRO Come, lady, come; you have lost the heart of Signior Benedick. BEATRICE Indeed, my lord, he lent it me awhile; and I gave him use for it, a double heart for his single one: marry, once before he won it of me with false dice, therefore your grace may well say I have lost it. DON PEDRO You have put him down, lady, you have put him down. BEATRICE So I would not he should do me, my lord, lest I should prove the mother of fools. I have brought Count Claudio, whom you sent me to seek. DON PEDRO Why, how now, count! wherefore are you sad? CLAUDIO Not sad, my lord. DON PEDRO How then? sick? CLAUDIO Neither, my lord. BEATRICE The count is neither sad, nor sick, nor merry, nor well; but civil count, civil as an orange, and something of that jealous complexion. DON PEDRO I' faith, lady, I think your blazon to be true; though, I'll be sworn, if he be so, his conceit is false. Here, Claudio, I have wooed in thy name, and fair Hero is won: I have broke with her father, and his good will obtained: name the day of marriage, and God give thee joy! LEONATO Count, take of me my daughter, and with her my fortunes: his grace hath made the match, and an grace say Amen to it. BEATRICE Speak, count, 'tis your cue. CLAUDIO Silence is the perfectest herald of joy: I were but little happy, if I could say how much. Lady, as you are mine, I am yours: I give away myself for you and dote upon the exchange. BEATRICE Speak, cousin; or, if you cannot, stop his mouth with a kiss, and let not him speak neither. DON PEDRO In faith, lady, you have a merry heart. BEATRICE Yea, my lord; I thank it, poor fool, it keeps on the windy side of care. My cousin tells him in his ear that he is in her heart. CLAUDIO And so she doth, cousin. BEATRICE Good Lord, for alliance! Thus goes every one to the world but I, and I am sunburnt; I may sit in a corner and cry heigh-ho for a husband! DON PEDRO Lady Beatrice, I will get you one. BEATRICE I would rather have one of your father's getting. Hath your grace ne'er a brother like you? Your father got excellent husbands, if a maid could come by them. DON PEDRO Will you have me, lady? BEATRICE No, my lord, unless I might have another for working-days: your grace is too costly to wear every day. But, I beseech your grace, pardon me: I was born to speak all mirth and no matter. DON PEDRO Your silence most offends me, and to be merry best becomes you; for, out of question, you were born in a merry hour. BEATRICE No, sure, my lord, my mother cried; but then there was a star danced, and under that was I born. Cousins, God give you joy! LEONATO Niece, will you look to those things I told you of? BEATRICE I cry you mercy, uncle. By your grace's pardon. Exit DON PEDRO By my troth, a pleasant-spirited lady. LEONATO There's little of the melancholy element in her, my lord: she is never sad but when she sleeps, and not ever sad then; for I have heard my daughter say, she hath often dreamed of unhappiness and waked herself with laughing. DON PEDRO She cannot endure to hear tell of a husband. LEONATO O, by no means: she mocks all her wooers out of suit. DON PEDRO She were an excellent wife for Benedict. LEONATO O Lord, my lord, if they were but a week married, they would talk themselves mad. DON PEDRO County Claudio, when mean you to go to church? CLAUDIO To-morrow, my lord: time goes on crutches till love have all his rites. LEONATO Not till Monday, my dear son, which is hence a just seven-night; and a time too brief, too, to have all things answer my mind. DON PEDRO Come, you shake the head at so long a breathing: but, I warrant thee, Claudio, the time shall not go dully by us. I will in the interim undertake one of Hercules' labours; which is, to bring Signior Benedick and the Lady Beatrice into a mountain of affection the one with the other. I would fain have it a match, and I doubt not but to fashion it, if you three will but minister such assistance as I shall give you direction. LEONATO My lord, I am for you, though it cost me ten nights' watchings. CLAUDIO And I, my lord. DON PEDRO And you too, gentle Hero? HERO I will do any modest office, my lord, to help my cousin to a good husband. DON PEDRO And Benedick is not the unhopefullest husband that I know. Thus far can I praise him; he is of a noble strain, of approved valour and confirmed honesty. I will teach you how to humour your cousin, that she shall fall in love with Benedick; and I, with your two helps, will so practise on Benedick that, in despite of his quick wit and his queasy stomach, he shall fall in love with Beatrice. If we can do this, Cupid is no longer an archer: his glory shall be ours, for we are the only love-gods. Go in with me, and I will tell you my drift. Exeunt SCENE II. The same. Enter DON JOHN and BORACHIO DON JOHN It is so; the Count Claudio shall marry the daughter of Leonato. BORACHIO Yea, my lord; but I can cross it. DON JOHN Any bar, any cross, any impediment will be medicinable to me: I am sick in displeasure to him, and whatsoever comes athwart his affection ranges evenly with mine. How canst thou cross this marriage? BORACHIO Not honestly, my lord; but so covertly that no dishonesty shall appear in me. DON JOHN Show me briefly how. BORACHIO I think I told your lordship a year since, how much I am in the favour of Margaret, the waiting gentlewoman to Hero. DON JOHN I remember. BORACHIO I can, at any unseasonable instant of the night, appoint her to look out at her lady's chamber window. DON JOHN What life is in that, to be the death of this marriage? BORACHIO The poison of that lies in you to temper. Go you to the prince your brother; spare not to tell him that he hath wronged his honour in marrying the renowned Claudio--whose estimation do you mightily hold up--to a contaminated stale, such a one as Hero. DON JOHN What proof shall I make of that? BORACHIO Proof enough to misuse the prince, to vex Claudio, to undo Hero and kill Leonato. Look you for any other issue? DON JOHN Only to despite them, I will endeavour any thing. BORACHIO Go, then; find me a meet hour to draw Don Pedro and the Count Claudio alone: tell them that you know that Hero loves me; intend a kind of zeal both to the prince and Claudio, as,--in love of your brother's honour, who hath made this match, and his friend's reputation, who is thus like to be cozened with the semblance of a maid,--that you have discovered thus. They will scarcely believe this without trial: offer them instances; which shall bear no less likelihood than to see me at her chamber-window, hear me call Margaret Hero, hear Margaret term me Claudio; and bring them to see this the very night before the intended wedding,--for in the meantime I will so fashion the matter that Hero shall be absent,--and there shall appear such seeming truth of Hero's disloyalty that jealousy shall be called assurance and all the preparation overthrown. DON JOHN Grow this to what adverse issue it can, I will put it in practise. Be cunning in the working this, and thy fee is a thousand ducats. BORACHIO Be you constant in the accusation, and my cunning shall not shame me. DON JOHN I will presently go learn their day of marriage. Exeunt SCENE III. LEONATO'S orchard. Enter BENEDICK BENEDICK Boy! Enter Boy Boy Signior? BENEDICK In my chamber-window lies a book: bring it hither to me in the orchard. Boy I am here already, sir. BENEDICK I know that; but I would have thee hence, and here again. Exit Boy I do much wonder that one man, seeing how much another man is a fool when he dedicates his behaviors to love, will, after he hath laughed at such shallow follies in others, become the argument of his own scorn by failing in love: and such a man is Claudio. I have known when there was no music with him but the drum and the fife; and now had he rather hear the tabour and the pipe: I have known when he would have walked ten mile a-foot to see a good armour; and now will he lie ten nights awake, carving the fashion of a new doublet. He was wont to speak plain and to the purpose, like an honest man and a soldier; and now is he turned orthography; his words are a very fantastical banquet, just so many strange dishes. May I be so converted and see with these eyes? I cannot tell; I think not: I will not be sworn, but love may transform me to an oyster; but I'll take my oath on it, till he have made an oyster of me, he shall never make me such a fool. One woman is fair, yet I am well; another is wise, yet I am well; another virtuous, yet I am well; but till all graces be in one woman, one woman shall not come in my grace. Rich she shall be, that's certain; wise, or I'll none; virtuous, or I'll never cheapen her; fair, or I'll never look on her; mild, or come not near me; noble, or not I for an angel; of good discourse, an excellent musician, and her hair shall be of what colour it please God. Ha! the prince and Monsieur Love! I will hide me in the arbour. Withdraws Enter DON PEDRO, CLAUDIO, and LEONATO DON PEDRO Come, shall we hear this music? CLAUDIO Yea, my good lord. How still the evening is, As hush'd on purpose to grace harmony! DON PEDRO See you where Benedick hath hid himself? CLAUDIO O, very well, my lord: the music ended, We'll fit the kid-fox with a pennyworth. Enter BALTHASAR with Music DON PEDRO Come, Balthasar, we'll hear that song again. BALTHASAR O, good my lord, tax not so bad a voice To slander music any more than once. DON PEDRO It is the witness still of excellency To put a strange face on his own perfection. I pray thee, sing, and let me woo no more. BALTHASAR Because you talk of wooing, I will sing; Since many a wooer doth commence his suit To her he thinks not worthy, yet he wooes, Yet will he swear he loves. DON PEDRO Now, pray thee, come; Or, if thou wilt hold longer argument, Do it in notes. BALTHASAR Note this before my notes; There's not a note of mine that's worth the noting. DON PEDRO Why, these are very crotchets that he speaks; Note, notes, forsooth, and nothing. Air BENEDICK Now, divine air! now is his soul ravished! Is it not strange that sheeps' guts should hale souls out of men's bodies? Well, a horn for my money, when all's done. The Song BALTHASAR Sigh no more, ladies, sigh no more, Men were deceivers ever, One foot in sea and one on shore, To one thing constant never: Then sigh not so, but let them go, And be you blithe and bonny, Converting all your sounds of woe Into Hey nonny, nonny. Sing no more ditties, sing no moe, Of dumps so dull and heavy; The fraud of men was ever so, Since summer first was leafy: Then sigh not so, &c. DON PEDRO By my troth, a good song. BALTHASAR And an ill singer, my lord. DON PEDRO Ha, no, no, faith; thou singest well enough for a shift. BENEDICK An he had been a dog that should have howled thus, they would have hanged him: and I pray God his bad voice bode no mischief. I had as lief have heard the night-raven, come what plague could have come after it. DON PEDRO Yea, marry, dost thou hear, Balthasar? I pray thee, get us some excellent music; for to-morrow night we would have it at the Lady Hero's chamber-window. BALTHASAR The best I can, my lord. DON PEDRO Do so: farewell. Exit BALTHASAR Come hither, Leonato. What was it you told me of to-day, that your niece Beatrice was in love with Signior Benedick? CLAUDIO O, ay: stalk on. stalk on; the fowl sits. I did never think that lady would have loved any man. LEONATO No, nor I neither; but most wonderful that she should so dote on Signior Benedick, whom she hath in all outward behaviors seemed ever to abhor. BENEDICK Is't possible? Sits the wind in that corner? LEONATO By my troth, my lord, I cannot tell what to think of it but that she loves him with an enraged affection: it is past the infinite of thought. DON PEDRO May be she doth but counterfeit. CLAUDIO Faith, like enough. LEONATO O God, counterfeit! There was never counterfeit of passion came so near the life of passion as she discovers it. DON PEDRO Why, what effects of passion shows she? CLAUDIO Bait the hook well; this fish will bite. LEONATO What effects, my lord? She will sit you, you heard my daughter tell you how. CLAUDIO She did, indeed. DON PEDRO How, how, pray you? You amaze me: I would have I thought her spirit had been invincible against all assaults of affection. LEONATO I would have sworn it had, my lord; especially against Benedick. BENEDICK I should think this a gull, but that the white-bearded fellow speaks it: knavery cannot, sure, hide himself in such reverence. CLAUDIO He hath ta'en the infection: hold it up. DON PEDRO Hath she made her affection known to Benedick? LEONATO No; and swears she never will: that's her torment. CLAUDIO 'Tis true, indeed; so your daughter says: 'Shall I,' says she, 'that have so oft encountered him with scorn, write to him that I love him?' LEONATO This says she now when she is beginning to write to him; for she'll be up twenty times a night, and there will she sit in her smock till she have writ a sheet of paper: my daughter tells us all. CLAUDIO Now you talk of a sheet of paper, I remember a pretty jest your daughter told us of. LEONATO O, when she had writ it and was reading it over, she found Benedick and Beatrice between the sheet? CLAUDIO That. LEONATO O, she tore the letter into a thousand halfpence; railed at herself, that she should be so immodest to write to one that she knew would flout her; 'I measure him,' says she, 'by my own spirit; for I should flout him, if he writ to me; yea, though I love him, I should.' CLAUDIO Then down upon her knees she falls, weeps, sobs, beats her heart, tears her hair, prays, curses; 'O sweet Benedick! God give me patience!' LEONATO She doth indeed; my daughter says so: and the ecstasy hath so much overborne her that my daughter is sometime afeared she will do a desperate outrage to herself: it is very true. DON PEDRO It were good that Benedick knew of it by some other, if she will not discover it. CLAUDIO To what end? He would make but a sport of it and torment the poor lady worse. DON PEDRO An he should, it were an alms to hang him. She's an excellent sweet lady; and, out of all suspicion, she is virtuous. CLAUDIO And she is exceeding wise. DON PEDRO In every thing but in loving Benedick. LEONATO O, my lord, wisdom and blood combating in so tender a body, we have ten proofs to one that blood hath the victory. I am sorry for her, as I have just cause, being her uncle and her guardian. DON PEDRO I would she had bestowed this dotage on me: I would have daffed all other respects and made her half myself. I pray you, tell Benedick of it, and hear what a' will say. LEONATO Were it good, think you? CLAUDIO Hero thinks surely she will die; for she says she will die, if he love her not, and she will die, ere she make her love known, and she will die, if he woo her, rather than she will bate one breath of her accustomed crossness. DON PEDRO She doth well: if she should make tender of her love, 'tis very possible he'll scorn it; for the man, as you know all, hath a contemptible spirit. CLAUDIO He is a very proper man. DON PEDRO He hath indeed a good outward happiness. CLAUDIO Before God! and, in my mind, very wise. DON PEDRO He doth indeed show some sparks that are like wit. CLAUDIO And I take him to be valiant. DON PEDRO As Hector, I assure you: and in the managing of quarrels you may say he is wise; for either he avoids them with great discretion, or undertakes them with a most Christian-like fear. LEONATO If he do fear God, a' must necessarily keep peace: if he break the peace, he ought to enter into a quarrel with fear and trembling. DON PEDRO And so will he do; for the man doth fear God, howsoever it seems not in him by some large jests he will make. Well I am sorry for your niece. Shall we go seek Benedick, and tell him of her love? CLAUDIO Never tell him, my lord: let her wear it out with good counsel. LEONATO Nay, that's impossible: she may wear her heart out first. DON PEDRO Well, we will hear further of it by your daughter: let it cool the while. I love Benedick well; and I could wish he would modestly examine himself, to see how much he is unworthy so good a lady. LEONATO My lord, will you walk? dinner is ready. CLAUDIO If he do not dote on her upon this, I will never trust my expectation. DON PEDRO Let there be the same net spread for her; and that must your daughter and her gentlewomen carry. The sport will be, when they hold one an opinion of another's dotage, and no such matter: that's the scene that I would see, which will be merely a dumb-show. Let us send her to call him in to dinner. Exeunt DON PEDRO, CLAUDIO, and LEONATO BENEDICK Coming forward This can be no trick: the conference was sadly borne. They have the truth of this from Hero. They seem to pity the lady: it seems her affections have their full bent. Love me! why, it must be requited. I hear how I am censured: they say I will bear myself proudly, if I perceive the love come from her; they say too that she will rather die than give any sign of affection. I did never think to marry: I must not seem proud: happy are they that hear their detractions and can put them to mending. They say the lady is fair; 'tis a truth, I can bear them witness; and virtuous; 'tis so, I cannot reprove it; and wise, but for loving me; by my troth, it is no addition to her wit, nor no great argument of her folly, for I will be horribly in love with her. I may chance have some odd quirks and remnants of wit broken on me, because I have railed so long against marriage: but doth not the appetite alter? a man loves the meat in his youth that he cannot endure in his age. Shall quips and sentences and these paper bullets of the brain awe a man from the career of his humour? No, the world must be peopled. When I said I would die a bachelor, I did not think I should live till I were married. Here comes Beatrice. By this day! she's a fair lady: I do spy some marks of love in her. Enter BEATRICE BEATRICE Against my will I am sent to bid you come in to dinner. BENEDICK Fair Beatrice, I thank you for your pains. BEATRICE I took no more pains for those thanks than you take pains to thank me: if it had been painful, I would not have come. BENEDICK You take pleasure then in the message? BEATRICE Yea, just so much as you may take upon a knife's point and choke a daw withal. You have no stomach, signior: fare you well. Exit BENEDICK Ha! 'Against my will I am sent to bid you come in to dinner;' there's a double meaning in that 'I took no more pains for those thanks than you took pains to thank me.' that's as much as to say, Any pains that I take for you is as easy as thanks. If I do not take pity of her, I am a villain; if I do not love her, I am a Jew. I will go get her picture. Exit ACT III SCENE I. LEONATO'S garden. Enter HERO, MARGARET, and URSULA HERO Good Margaret, run thee to the parlor; There shalt thou find my cousin Beatrice Proposing with the prince and Claudio: Whisper her ear and tell her, I and Ursula Walk in the orchard and our whole discourse Is all of her; say that thou overheard'st us; And bid her steal into the pleached bower, Where honeysuckles, ripen'd by the sun, Forbid the sun to enter, like favourites, Made proud by princes, that advance their pride Against that power that bred it: there will she hide her, To listen our purpose. This is thy office; Bear thee well in it and leave us alone. MARGARET I'll make her come, I warrant you, presently. Exit HERO Now, Ursula, when Beatrice doth come, As we do trace this alley up and down, Our talk must only be of Benedick. When I do name him, let it be thy part To praise him more than ever man did merit: My talk to thee must be how Benedick Is sick in love with Beatrice. Of this matter Is little Cupid's crafty arrow made, That only wounds by hearsay. Enter BEATRICE, behind Now begin; For look where Beatrice, like a lapwing, runs Close by the ground, to hear our conference. URSULA The pleasant'st angling is to see the fish Cut with her golden oars the silver stream, And greedily devour the treacherous bait: So angle we for Beatrice; who even now Is couched in the woodbine coverture. Fear you not my part of the dialogue. HERO Then go we near her, that her ear lose nothing Of the false sweet bait that we lay for it. Approaching the bower No, truly, Ursula, she is too disdainful; I know her spirits are as coy and wild As haggerds of the rock. URSULA But are you sure That Benedick loves Beatrice so entirely? HERO So says the prince and my new-trothed lord. URSULA And did they bid you tell her of it, madam? HERO They did entreat me to acquaint her of it; But I persuaded them, if they loved Benedick, To wish him wrestle with affection, And never to let Beatrice know of it. URSULA Why did you so? Doth not the gentleman Deserve as full as fortunate a bed As ever Beatrice shall couch upon? HERO O god of love! I know he doth deserve As much as may be yielded to a man: But Nature never framed a woman's heart Of prouder stuff than that of Beatrice; Disdain and scorn ride sparkling in her eyes, Misprising what they look on, and her wit Values itself so highly that to her All matter else seems weak: she cannot love, Nor take no shape nor project of affection, She is so self-endeared. URSULA Sure, I think so; And therefore certainly it were not good She knew his love, lest she make sport at it. HERO Why, you speak truth. I never yet saw man, How wise, how noble, young, how rarely featured, But she would spell him backward: if fair-faced, She would swear the gentleman should be her sister; If black, why, Nature, drawing of an antique, Made a foul blot; if tall, a lance ill-headed; If low, an agate very vilely cut; If speaking, why, a vane blown with all winds; If silent, why, a block moved with none. So turns she every man the wrong side out And never gives to truth and virtue that Which simpleness and merit purchaseth. URSULA Sure, sure, such carping is not commendable. HERO No, not to be so odd and from all fashions As Beatrice is, cannot be commendable: But who dare tell her so? If I should speak, She would mock me into air; O, she would laugh me Out of myself, press me to death with wit. Therefore let Benedick, like cover'd fire, Consume away in sighs, waste inwardly: It were a better death than die with mocks, Which is as bad as die with tickling. URSULA Yet tell her of it: hear what she will say. HERO No; rather I will go to Benedick And counsel him to fight against his passion. And, truly, I'll devise some honest slanders To stain my cousin with: one doth not know How much an ill word may empoison liking. URSULA O, do not do your cousin such a wrong. She cannot be so much without true judgment-- Having so swift and excellent a wit As she is prized to have--as to refuse So rare a gentleman as Signior Benedick. HERO He is the only man of Italy. Always excepted my dear Claudio. URSULA I pray you, be not angry with me, madam, Speaking my fancy: Signior Benedick, For shape, for bearing, argument and valour, Goes foremost in report through Italy. HERO Indeed, he hath an excellent good name. URSULA His excellence did earn it, ere he had it. When are you married, madam? HERO Why, every day, to-morrow. Come, go in: I'll show thee some attires, and have thy counsel Which is the best to furnish me to-morrow. URSULA She's limed, I warrant you: we have caught her, madam. HERO If it proves so, then loving goes by haps: Some Cupid kills with arrows, some with traps. Exeunt HERO and URSULA BEATRICE Coming forward What fire is in mine ears? Can this be true? Stand I condemn'd for pride and scorn so much? Contempt, farewell! and maiden pride, adieu! No glory lives behind the back of such. And, Benedick, love on; I will requite thee, Taming my wild heart to thy loving hand: If thou dost love, my kindness shall incite thee To bind our loves up in a holy band; For others say thou dost deserve, and I Believe it better than reportingly. Exit SCENE II. A room in LEONATO'S house Enter DON PEDRO, CLAUDIO, BENEDICK, and LEONATO DON PEDRO I do but stay till your marriage be consummate, and then go I toward Arragon. CLAUDIO I'll bring you thither, my lord, if you'll vouchsafe me. DON PEDRO Nay, that would be as great a soil in the new gloss of your marriage as to show a child his new coat and forbid him to wear it. I will only be bold with Benedick for his company; for, from the crown of his head to the sole of his foot, he is all mirth: he hath twice or thrice cut Cupid's bow-string and the little hangman dare not shoot at him; he hath a heart as sound as a bell and his tongue is the clapper, for what his heart thinks his tongue speaks. BENEDICK Gallants, I am not as I have been. LEONATO So say I methinks you are sadder. CLAUDIO I hope he be in love. DON PEDRO Hang him, truant! there's no true drop of blood in him, to be truly touched with love: if he be sad, he wants money. BENEDICK I have the toothache. DON PEDRO Draw it. BENEDICK Hang it! CLAUDIO You must hang it first, and draw it afterwards. DON PEDRO What! sigh for the toothache? LEONATO Where is but a humour or a worm. BENEDICK Well, every one can master a grief but he that has it. CLAUDIO Yet say I, he is in love. DON PEDRO There is no appearance of fancy in him, unless it be a fancy that he hath to strange disguises; as, to be a Dutchman today, a Frenchman to-morrow, or in the shape of two countries at once, as, a German from the waist downward, all slops, and a Spaniard from the hip upward, no doublet. Unless he have a fancy to this foolery, as it appears he hath, he is no fool for fancy, as you would have it appear he is. CLAUDIO If he be not in love with some woman, there is no believing old signs: a' brushes his hat o' mornings; what should that bode? DON PEDRO Hath any man seen him at the barber's? CLAUDIO No, but the barber's man hath been seen with him, and the old ornament of his cheek hath already stuffed tennis-balls. LEONATO Indeed, he looks younger than he did, by the loss of a beard. DON PEDRO Nay, a' rubs himself with civet: can you smell him out by that? CLAUDIO That's as much as to say, the sweet youth's in love. DON PEDRO The greatest note of it is his melancholy. CLAUDIO And when was he wont to wash his face? DON PEDRO Yea, or to paint himself? for the which, I hear what they say of him. CLAUDIO Nay, but his jesting spirit; which is now crept into a lute-string and now governed by stops. DON PEDRO Indeed, that tells a heavy tale for him: conclude, conclude he is in love. CLAUDIO Nay, but I know who loves him. DON PEDRO That would I know too: I warrant, one that knows him not. CLAUDIO Yes, and his ill conditions; and, in despite of all, dies for him. DON PEDRO She shall be buried with her face upwards. BENEDICK Yet is this no charm for the toothache. Old signior, walk aside with me: I have studied eight or nine wise words to speak to you, which these hobby-horses must not hear. Exeunt BENEDICK and LEONATO DON PEDRO For my life, to break with him about Beatrice. CLAUDIO 'Tis even so. Hero and Margaret have by this played their parts with Beatrice; and then the two bears will not bite one another when they meet. Enter DON JOHN DON JOHN My lord and brother, God save you! DON PEDRO Good den, brother. DON JOHN If your leisure served, I would speak with you. DON PEDRO In private? DON JOHN If it please you: yet Count Claudio may hear; for what I would speak of concerns him. DON PEDRO What's the matter? DON JOHN To CLAUDIO Means your lordship to be married to-morrow? DON PEDRO You know he does. DON JOHN I know not that, when he knows what I know. CLAUDIO If there be any impediment, I pray you discover it. DON JOHN You may think I love you not: let that appear hereafter, and aim better at me by that I now will manifest. For my brother, I think he holds you well, and in dearness of heart hath holp to effect your ensuing marriage;--surely suit ill spent and labour ill bestowed. DON PEDRO Why, what's the matter? DON JOHN I came hither to tell you; and, circumstances shortened, for she has been too long a talking of, the lady is disloyal. CLAUDIO Who, Hero? DON PEDRO Even she; Leonato's Hero, your Hero, every man's Hero: CLAUDIO Disloyal? DON JOHN The word is too good to paint out her wickedness; I could say she were worse: think you of a worse title, and I will fit her to it. Wonder not till further warrant: go but with me to-night, you shall see her chamber-window entered, even the night before her wedding-day: if you love her then, to-morrow wed her; but it would better fit your honour to change your mind. CLAUDIO May this be so? DON PEDRO I will not think it. DON JOHN If you dare not trust that you see, confess not that you know: if you will follow me, I will show you enough; and when you have seen more and heard more, proceed accordingly. CLAUDIO If I see any thing to-night why I should not marry her to-morrow in the congregation, where I should wed, there will I shame her. DON PEDRO And, as I wooed for thee to obtain her, I will join with thee to disgrace her. DON JOHN I will disparage her no farther till you are my witnesses: bear it coldly but till midnight, and let the issue show itself. DON PEDRO O day untowardly turned! CLAUDIO O mischief strangely thwarting! DON JOHN O plague right well prevented! so will you say when you have seen the sequel. Exeunt SCENE III. A street. Enter DOGBERRY and VERGES with the Watch DOGBERRY Are you good men and true? VERGES Yea, or else it were pity but they should suffer salvation, body and soul. DOGBERRY Nay, that were a punishment too good for them, if they should have any allegiance in them, being chosen for the prince's watch. VERGES Well, give them their charge, neighbour Dogberry. DOGBERRY First, who think you the most desertless man to be constable? First Watchman Hugh Otecake, sir, or George Seacole; for they can write and read. DOGBERRY Come hither, neighbour Seacole. God hath blessed you with a good name: to be a well-favoured man is the gift of fortune; but to write and read comes by nature. Second Watchman Both which, master constable,-- DOGBERRY You have: I knew it would be your answer. Well, for your favour, sir, why, give God thanks, and make no boast of it; and for your writing and reading, let that appear when there is no need of such vanity. You are thought here to be the most senseless and fit man for the constable of the watch; therefore bear you the lantern. This is your charge: you shall comprehend all vagrom men; you are to bid any man stand, in the prince's name. Second Watchman How if a' will not stand? DOGBERRY Why, then, take no note of him, but let him go; and presently call the rest of the watch together and thank God you are rid of a knave. VERGES If he will not stand when he is bidden, he is none of the prince's subjects. DOGBERRY True, and they are to meddle with none but the prince's subjects. You shall also make no noise in the streets; for, for the watch to babble and to talk is most tolerable and not to be endured. Watchman We will rather sleep than talk: we know what belongs to a watch. DOGBERRY Why, you speak like an ancient and most quiet watchman; for I cannot see how sleeping should offend: only, have a care that your bills be not stolen. Well, you are to call at all the ale-houses, and bid those that are drunk get them to bed. Watchman How if they will not? DOGBERRY Why, then, let them alone till they are sober: if they make you not then the better answer, you may say they are not the men you took them for. Watchman Well, sir. DOGBERRY If you meet a thief, you may suspect him, by virtue of your office, to be no true man; and, for such kind of men, the less you meddle or make with them, why the more is for your honesty. Watchman If we know him to be a thief, shall we not lay hands on him? DOGBERRY Truly, by your office, you may; but I think they that touch pitch will be defiled: the most peaceable way for you, if you do take a thief, is to let him show himself what he is and steal out of your company. VERGES You have been always called a merciful man, partner. DOGBERRY Truly, I would not hang a dog by my will, much more a man who hath any honesty in him. VERGES If you hear a child cry in the night, you must call to the nurse and bid her still it. Watchman How if the nurse be asleep and will not hear us? DOGBERRY Why, then, depart in peace, and let the child wake her with crying; for the ewe that will not hear her lamb when it baes will never answer a calf when he bleats. VERGES 'Tis very true. DOGBERRY This is the end of the charge:--you, constable, are to present the prince's own person: if you meet the prince in the night, you may stay him. VERGES Nay, by'r our lady, that I think a' cannot. DOGBERRY Five shillings to one on't, with any man that knows the statutes, he may stay him: marry, not without the prince be willing; for, indeed, the watch ought to offend no man; and it is an offence to stay a man against his will. VERGES By'r lady, I think it be so. DOGBERRY Ha, ha, ha! Well, masters, good night: an there be any matter of weight chances, call up me: keep your fellows' counsels and your own; and good night. Come, neighbour. Watchman Well, masters, we hear our charge: let us go sit here upon the church-bench till two, and then all to bed. DOGBERRY One word more, honest neighbours. I pray you watch about Signior Leonato's door; for the wedding being there to-morrow, there is a great coil to-night. Adieu: be vigitant, I beseech you. Exeunt DOGBERRY and VERGES Enter BORACHIO and CONRADE BORACHIO What Conrade! Watchman Aside Peace! stir not. BORACHIO Conrade, I say! CONRADE Here, man; I am at thy elbow. BORACHIO Mass, and my elbow itched; I thought there would a scab follow. CONRADE I will owe thee an answer for that: and now forward with thy tale. BORACHIO Stand thee close, then, under this pent-house, for it drizzles rain; and I will, like a true drunkard, utter all to thee. Watchman Aside Some treason, masters: yet stand close. BORACHIO Therefore know I have earned of Don John a thousand ducats. CONRADE Is it possible that any villany should be so dear? BORACHIO Thou shouldst rather ask if it were possible any villany should be so rich; for when rich villains have need of poor ones, poor ones may make what price they will. CONRADE I wonder at it. BORACHIO That shows thou art unconfirmed. Thou knowest that the fashion of a doublet, or a hat, or a cloak, is nothing to a man. CONRADE Yes, it is apparel. BORACHIO I mean, the fashion. CONRADE Yes, the fashion is the fashion. BORACHIO Tush! I may as well say the fool's the fool. But seest thou not what a deformed thief this fashion is? Watchman Aside I know that Deformed; a' has been a vile thief this seven year; a' goes up and down like a gentleman: I remember his name. BORACHIO Didst thou not hear somebody? CONRADE No; 'twas the vane on the house. BORACHIO Seest thou not, I say, what a deformed thief this fashion is? how giddily a' turns about all the hot bloods between fourteen and five-and-thirty? sometimes fashioning them like Pharaoh's soldiers in the reeky painting, sometime like god Bel's priests in the old church-window, sometime like the shaven Hercules in the smirched worm-eaten tapestry, where his codpiece seems as massy as his club? CONRADE All this I see; and I see that the fashion wears out more apparel than the man. But art not thou thyself giddy with the fashion too, that thou hast shifted out of thy tale into telling me of the fashion? BORACHIO Not so, neither: but know that I have to-night wooed Margaret, the Lady Hero's gentlewoman, by the name of Hero: she leans me out at her mistress' chamber-window, bids me a thousand times good night,--I tell this tale vilely:--I should first tell thee how the prince, Claudio and my master, planted and placed and possessed by my master Don John, saw afar off in the orchard this amiable encounter. CONRADE And thought they Margaret was Hero? BORACHIO Two of them did, the prince and Claudio; but the devil my master knew she was Margaret; and partly by his oaths, which first possessed them, partly by the dark night, which did deceive them, but chiefly by my villany, which did confirm any slander that Don John had made, away went Claudio enraged; swore he would meet her, as he was appointed, next morning at the temple, and there, before the whole congregation, shame her with what he saw o'er night and send her home again without a husband. First Watchman We charge you, in the prince's name, stand! Second Watchman Call up the right master constable. We have here recovered the most dangerous piece of lechery that ever was known in the commonwealth. First Watchman And one Deformed is one of them: I know him; a' wears a lock. CONRADE Masters, masters,-- Second Watchman You'll be made bring Deformed forth, I warrant you. CONRADE Masters,-- First Watchman Never speak: we charge you let us obey you to go with us. BORACHIO We are like to prove a goodly commodity, being taken up of these men's bills. CONRADE A commodity in question, I warrant you. Come, we'll obey you. Exeunt SCENE IV. HERO's apartment. Enter HERO, MARGARET, and URSULA HERO Good Ursula, wake my cousin Beatrice, and desire her to rise. URSULA I will, lady. HERO And bid her come hither. URSULA Well. Exit MARGARET Troth, I think your other rabato were better. HERO No, pray thee, good Meg, I'll wear this. MARGARET By my troth, 's not so good; and I warrant your cousin will say so. HERO My cousin's a fool, and thou art another: I'll wear none but this. MARGARET I like the new tire within excellently, if the hair were a thought browner; and your gown's a most rare fashion, i' faith. I saw the Duchess of Milan's gown that they praise so. HERO O, that exceeds, they say. MARGARET By my troth, 's but a night-gown in respect of yours: cloth o' gold, and cuts, and laced with silver, set with pearls, down sleeves, side sleeves, and skirts, round underborne with a bluish tinsel: but for a fine, quaint, graceful and excellent fashion, yours is worth ten on 't. HERO God give me joy to wear it! for my heart is exceeding heavy. MARGARET 'Twill be heavier soon by the weight of a man. HERO Fie upon thee! art not ashamed? MARGARET Of what, lady? of speaking honourably? Is not marriage honourable in a beggar? Is not your lord honourable without marriage? I think you would have me say, 'saving your reverence, a husband:' and bad thinking do not wrest true speaking, I'll offend nobody: is there any harm in 'the heavier for a husband'? None, I think, and it be the right husband and the right wife; otherwise 'tis light, and not heavy: ask my Lady Beatrice else; here she comes. Enter BEATRICE HERO Good morrow, coz. BEATRICE Good morrow, sweet Hero. HERO Why how now? do you speak in the sick tune? BEATRICE I am out of all other tune, methinks. MARGARET Clap's into 'Light o' love;' that goes without a burden: do you sing it, and I'll dance it. BEATRICE Ye light o' love, with your heels! then, if your husband have stables enough, you'll see he shall lack no barns. MARGARET O illegitimate construction! I scorn that with my heels. BEATRICE 'Tis almost five o'clock, cousin; tis time you were ready. By my troth, I am exceeding ill: heigh-ho! MARGARET For a hawk, a horse, or a husband? BEATRICE For the letter that begins them all, H. MARGARET Well, and you be not turned Turk, there's no more sailing by the star. BEATRICE What means the fool, trow? MARGARET Nothing I; but God send every one their heart's desire! HERO These gloves the count sent me; they are an excellent perfume. BEATRICE I am stuffed, cousin; I cannot smell. MARGARET A maid, and stuffed! there's goodly catching of cold. BEATRICE O, God help me! God help me! how long have you professed apprehension? MARGARET Even since you left it. Doth not my wit become me rarely? BEATRICE It is not seen enough, you should wear it in your cap. By my troth, I am sick. MARGARET Get you some of this distilled Carduus Benedictus, and lay it to your heart: it is the only thing for a qualm. HERO There thou prickest her with a thistle. BEATRICE Benedictus! why Benedictus? you have some moral in this Benedictus. MARGARET Moral! no, by my troth, I have no moral meaning; I meant, plain holy-thistle. You may think perchance that I think you are in love: nay, by'r lady, I am not such a fool to think what I list, nor I list not to think what I can, nor indeed I cannot think, if I would think my heart out of thinking, that you are in love or that you will be in love or that you can be in love. Yet Benedick was such another, and now is he become a man: he swore he would never marry, and yet now, in despite of his heart, he eats his meat without grudging: and how you may be converted I know not, but methinks you look with your eyes as other women do. BEATRICE What pace is this that thy tongue keeps? MARGARET Not a false gallop. Re-enter URSULA URSULA Madam, withdraw: the prince, the count, Signior Benedick, Don John, and all the gallants of the town, are come to fetch you to church. HERO Help to dress me, good coz, good Meg, good Ursula. Exeunt SCENE V. Another room in LEONATO'S house. Enter LEONATO, with DOGBERRY and VERGES LEONATO What would you with me, honest neighbour? DOGBERRY Marry, sir, I would have some confidence with you that decerns you nearly. LEONATO Brief, I pray you; for you see it is a busy time with me. DOGBERRY Marry, this it is, sir. VERGES Yes, in truth it is, sir. LEONATO What is it, my good friends? DOGBERRY Goodman Verges, sir, speaks a little off the matter: an old man, sir, and his wits are not so blunt as, God help, I would desire they were; but, in faith, honest as the skin between his brows. VERGES Yes, I thank God I am as honest as any man living that is an old man and no honester than I. DOGBERRY Comparisons are odorous: palabras, neighbour Verges. LEONATO Neighbours, you are tedious. DOGBERRY It pleases your worship to say so, but we are the poor duke's officers; but truly, for mine own part, if I were as tedious as a king, I could find it in my heart to bestow it all of your worship. LEONATO All thy tediousness on me, ah? DOGBERRY Yea, an 'twere a thousand pound more than 'tis; for I hear as good exclamation on your worship as of any man in the city; and though I be but a poor man, I am glad to hear it. VERGES And so am I. LEONATO I would fain know what you have to say. VERGES Marry, sir, our watch to-night, excepting your worship's presence, ha' ta'en a couple of as arrant knaves as any in Messina. DOGBERRY A good old man, sir; he will be talking: as they say, when the age is in, the wit is out: God help us! it is a world to see. Well said, i' faith, neighbour Verges: well, God's a good man; an two men ride of a horse, one must ride behind. An honest soul, i' faith, sir; by my troth he is, as ever broke bread; but God is to be worshipped; all men are not alike; alas, good neighbour! LEONATO Indeed, neighbour, he comes too short of you. DOGBERRY Gifts that God gives. LEONATO I must leave you. DOGBERRY One word, sir: our watch, sir, have indeed comprehended two aspicious persons, and we would have them this morning examined before your worship. LEONATO Take their examination yourself and bring it me: I am now in great haste, as it may appear unto you. DOGBERRY It shall be suffigance. LEONATO Drink some wine ere you go: fare you well. Enter a Messenger Messenger My lord, they stay for you to give your daughter to her husband. LEONATO I'll wait upon them: I am ready. Exeunt LEONATO and Messenger DOGBERRY Go, good partner, go, get you to Francis Seacole; bid him bring his pen and inkhorn to the gaol: we are now to examination these men. VERGES And we must do it wisely. DOGBERRY We will spare for no wit, I warrant you; here's that shall drive some of them to a non-come: only get the learned writer to set down our excommunication and meet me at the gaol. Exeunt ACT IV SCENE I. A church. Enter DON PEDRO, DON JOHN, LEONATO, FRIAR FRANCIS, CLAUDIO, BENEDICK, HERO, BEATRICE, and Attendants LEONATO Come, Friar Francis, be brief; only to the plain form of marriage, and you shall recount their particular duties afterwards. FRIAR FRANCIS You come hither, my lord, to marry this lady. CLAUDIO No. LEONATO To be married to her: friar, you come to marry her. FRIAR FRANCIS Lady, you come hither to be married to this count. HERO I do. FRIAR FRANCIS If either of you know any inward impediment why you should not be conjoined, charge you, on your souls, to utter it. CLAUDIO Know you any, Hero? HERO None, my lord. FRIAR FRANCIS Know you any, count? LEONATO I dare make his answer, none. CLAUDIO O, what men dare do! what men may do! what men daily do, not knowing what they do! BENEDICK How now! interjections? Why, then, some be of laughing, as, ah, ha, he! CLAUDIO Stand thee by, friar. Father, by your leave: Will you with free and unconstrained soul Give me this maid, your daughter? LEONATO As freely, son, as God did give her me. CLAUDIO And what have I to give you back, whose worth May counterpoise this rich and precious gift? DON PEDRO Nothing, unless you render her again. CLAUDIO Sweet prince, you learn me noble thankfulness. There, Leonato, take her back again: Give not this rotten orange to your friend; She's but the sign and semblance of her honour. Behold how like a maid she blushes here! O, what authority and show of truth Can cunning sin cover itself withal! Comes not that blood as modest evidence To witness simple virtue? Would you not swear, All you that see her, that she were a maid, By these exterior shows? But she is none: She knows the heat of a luxurious bed; Her blush is guiltiness, not modesty. LEONATO What do you mean, my lord? CLAUDIO Not to be married, Not to knit my soul to an approved wanton. LEONATO Dear my lord, if you, in your own proof, Have vanquish'd the resistance of her youth, And made defeat of her virginity,-- CLAUDIO I know what you would say: if I have known her, You will say she did embrace me as a husband, And so extenuate the 'forehand sin: No, Leonato, I never tempted her with word too large; But, as a brother to his sister, show'd Bashful sincerity and comely love. HERO And seem'd I ever otherwise to you? CLAUDIO Out on thee! Seeming! I will write against it: You seem to me as Dian in her orb, As chaste as is the bud ere it be blown; But you are more intemperate in your blood Than Venus, or those pamper'd animals That rage in savage sensuality. HERO Is my lord well, that he doth speak so wide? LEONATO Sweet prince, why speak not you? DON PEDRO What should I speak? I stand dishonour'd, that have gone about To link my dear friend to a common stale. LEONATO Are these things spoken, or do I but dream? DON JOHN Sir, they are spoken, and these things are true. BENEDICK This looks not like a nuptial. HERO True! O God! CLAUDIO Leonato, stand I here? Is this the prince? is this the prince's brother? Is this face Hero's? are our eyes our own? LEONATO All this is so: but what of this, my lord? CLAUDIO Let me but move one question to your daughter; And, by that fatherly and kindly power That you have in her, bid her answer truly. LEONATO I charge thee do so, as thou art my child. HERO O, God defend me! how am I beset! What kind of catechising call you this? CLAUDIO To make you answer truly to your name. HERO Is it not Hero? Who can blot that name With any just reproach? CLAUDIO Marry, that can Hero; Hero itself can blot out Hero's virtue. What man was he talk'd with you yesternight Out at your window betwixt twelve and one? Now, if you are a maid, answer to this. HERO I talk'd with no man at that hour, my lord. DON PEDRO Why, then are you no maiden. Leonato, I am sorry you must hear: upon mine honour, Myself, my brother and this grieved count Did see her, hear her, at that hour last night Talk with a ruffian at her chamber-window Who hath indeed, most like a liberal villain, Confess'd the vile encounters they have had A thousand times in secret. DON JOHN Fie, fie! they are not to be named, my lord, Not to be spoke of; There is not chastity enough in language Without offence to utter them. Thus, pretty lady, I am sorry for thy much misgovernment. CLAUDIO O Hero, what a Hero hadst thou been, If half thy outward graces had been placed About thy thoughts and counsels of thy heart! But fare thee well, most foul, most fair! farewell, Thou pure impiety and impious purity! For thee I'll lock up all the gates of love, And on my eyelids shall conjecture hang, To turn all beauty into thoughts of harm, And never shall it more be gracious. LEONATO Hath no man's dagger here a point for me? HERO swoons BEATRICE Why, how now, cousin! wherefore sink you down? DON JOHN Come, let us go. These things, come thus to light, Smother her spirits up. Exeunt DON PEDRO, DON JOHN, and CLAUDIO BENEDICK How doth the lady? BEATRICE Dead, I think. Help, uncle! Hero! why, Hero! Uncle! Signior Benedick! Friar! LEONATO O Fate! take not away thy heavy hand. Death is the fairest cover for her shame That may be wish'd for. BEATRICE How now, cousin Hero! FRIAR FRANCIS Have comfort, lady. LEONATO Dost thou look up? FRIAR FRANCIS Yea, wherefore should she not? LEONATO Wherefore! Why, doth not every earthly thing Cry shame upon her? Could she here deny The story that is printed in her blood? Do not live, Hero; do not ope thine eyes: For, did I think thou wouldst not quickly die, Thought I thy spirits were stronger than thy shames, Myself would, on the rearward of reproaches, Strike at thy life. Grieved I, I had but one? Chid I for that at frugal nature's frame? O, one too much by thee! Why had I one? Why ever wast thou lovely in my eyes? Why had I not with charitable hand Took up a beggar's issue at my gates, Who smirch'd thus and mired with infamy, I might have said 'No part of it is mine; This shame derives itself from unknown loins'? But mine and mine I loved and mine I praised And mine that I was proud on, mine so much That I myself was to myself not mine, Valuing of her,--why, she, O, she is fallen Into a pit of ink, that the wide sea Hath drops too few to wash her clean again And salt too little which may season give To her foul-tainted flesh! BENEDICK Sir, sir, be patient. For my part, I am so attired in wonder, I know not what to say. BEATRICE O, on my soul, my cousin is belied! BENEDICK Lady, were you her bedfellow last night? BEATRICE No, truly not; although, until last night, I have this twelvemonth been her bedfellow. LEONATO Confirm'd, confirm'd! O, that is stronger made Which was before barr'd up with ribs of iron! Would the two princes lie, and Claudio lie, Who loved her so, that, speaking of her foulness, Wash'd it with tears? Hence from her! let her die. FRIAR FRANCIS Hear me a little; for I have only been Silent so long and given way unto This course of fortune By noting of the lady. I have mark'd A thousand blushing apparitions To start into her face, a thousand innocent shames In angel whiteness beat away those blushes; And in her eye there hath appear'd a fire, To burn the errors that these princes hold Against her maiden truth. Call me a fool; Trust not my reading nor my observations, Which with experimental seal doth warrant The tenor of my book; trust not my age, My reverence, calling, nor divinity, If this sweet lady lie not guiltless here Under some biting error. LEONATO Friar, it cannot be. Thou seest that all the grace that she hath left Is that she will not add to her damnation A sin of perjury; she not denies it: Why seek'st thou then to cover with excuse That which appears in proper nakedness? FRIAR FRANCIS Lady, what man is he you are accused of? HERO They know that do accuse me; I know none: If I know more of any man alive Than that which maiden modesty doth warrant, Let all my sins lack mercy! O my father, Prove you that any man with me conversed At hours unmeet, or that I yesternight Maintain'd the change of words with any creature, Refuse me, hate me, torture me to death! FRIAR FRANCIS There is some strange misprision in the princes. BENEDICK Two of them have the very bent of honour; And if their wisdoms be misled in this, The practise of it lives in John the bastard, Whose spirits toil in frame of villanies. LEONATO I know not. If they speak but truth of her, These hands shall tear her; if they wrong her honour, The proudest of them shall well hear of it. Time hath not yet so dried this blood of mine, Nor age so eat up my invention, Nor fortune made such havoc of my means, Nor my bad life reft me so much of friends, But they shall find, awaked in such a kind, Both strength of limb and policy of mind, Ability in means and choice of friends, To quit me of them throughly. FRIAR FRANCIS Pause awhile, And let my counsel sway you in this case. Your daughter here the princes left for dead: Let her awhile be secretly kept in, And publish it that she is dead indeed; Maintain a mourning ostentation And on your family's old monument Hang mournful epitaphs and do all rites That appertain unto a burial. LEONATO What shall become of this? what will this do? FRIAR FRANCIS Marry, this well carried shall on her behalf Change slander to remorse; that is some good: But not for that dream I on this strange course, But on this travail look for greater birth. She dying, as it must so be maintain'd, Upon the instant that she was accused, Shall be lamented, pitied and excused Of every hearer: for it so falls out That what we have we prize not to the worth Whiles we enjoy it, but being lack'd and lost, Why, then we rack the value, then we find The virtue that possession would not show us Whiles it was ours. So will it fare with Claudio: When he shall hear she died upon his words, The idea of her life shall sweetly creep Into his study of imagination, And every lovely organ of her life Shall come apparell'd in more precious habit, More moving-delicate and full of life, Into the eye and prospect of his soul, Than when she lived indeed; then shall he mourn, If ever love had interest in his liver, And wish he had not so accused her, No, though he thought his accusation true. Let this be so, and doubt not but success Will fashion the event in better shape Than I can lay it down in likelihood. But if all aim but this be levell'd false, The supposition of the lady's death Will quench the wonder of her infamy: And if it sort not well, you may conceal her, As best befits her wounded reputation, In some reclusive and religious life, Out of all eyes, tongues, minds and injuries. BENEDICK Signior Leonato, let the friar advise you: And though you know my inwardness and love Is very much unto the prince and Claudio, Yet, by mine honour, I will deal in this As secretly and justly as your soul Should with your body. LEONATO Being that I flow in grief, The smallest twine may lead me. FRIAR FRANCIS 'Tis well consented: presently away; For to strange sores strangely they strain the cure. Come, lady, die to live: this wedding-day Perhaps is but prolong'd: have patience and endure. Exeunt all but BENEDICK and BEATRICE BENEDICK Lady Beatrice, have you wept all this while? BEATRICE Yea, and I will weep a while longer. BENEDICK I will not desire that. BEATRICE You have no reason; I do it freely. BENEDICK Surely I do believe your fair cousin is wronged. BEATRICE Ah, how much might the man deserve of me that would right her! BENEDICK Is there any way to show such friendship? BEATRICE A very even way, but no such friend. BENEDICK May a man do it? BEATRICE It is a man's office, but not yours. BENEDICK I do love nothing in the world so well as you: is not that strange? BEATRICE As strange as the thing I know not. It were as possible for me to say I loved nothing so well as you: but believe me not; and yet I lie not; I confess nothing, nor I deny nothing. I am sorry for my cousin. BENEDICK By my sword, Beatrice, thou lovest me. BEATRICE Do not swear, and eat it. BENEDICK I will swear by it that you love me; and I will make him eat it that says I love not you. BEATRICE Will you not eat your word? BENEDICK With no sauce that can be devised to it. I protest I love thee. BEATRICE Why, then, God forgive me! BENEDICK What offence, sweet Beatrice? BEATRICE You have stayed me in a happy hour: I was about to protest I loved you. BENEDICK And do it with all thy heart. BEATRICE I love you with so much of my heart that none is left to protest. BENEDICK Come, bid me do any thing for thee. BEATRICE Kill Claudio. BENEDICK Ha! not for the wide world. BEATRICE You kill me to deny it. Farewell. BENEDICK Tarry, sweet Beatrice. BEATRICE I am gone, though I am here: there is no love in you: nay, I pray you, let me go. BENEDICK Beatrice,-- BEATRICE In faith, I will go. BENEDICK We'll be friends first. BEATRICE You dare easier be friends with me than fight with mine enemy. BENEDICK Is Claudio thine enemy? BEATRICE Is he not approved in the height a villain, that hath slandered, scorned, dishonoured my kinswoman? O that I were a man! What, bear her in hand until they come to take hands; and then, with public accusation, uncovered slander, unmitigated rancour, --O God, that I were a man! I would eat his heart in the market-place. BENEDICK Hear me, Beatrice,-- BEATRICE Talk with a man out at a window! A proper saying! BENEDICK Nay, but, Beatrice,-- BEATRICE Sweet Hero! She is wronged, she is slandered, she is undone. BENEDICK Beat-- BEATRICE Princes and counties! Surely, a princely testimony, a goodly count, Count Comfect; a sweet gallant, surely! O that I were a man for his sake! or that I had any friend would be a man for my sake! But manhood is melted into courtesies, valour into compliment, and men are only turned into tongue, and trim ones too: he is now as valiant as Hercules that only tells a lie and swears it. I cannot be a man with wishing, therefore I will die a woman with grieving. BENEDICK Tarry, good Beatrice. By this hand, I love thee. BEATRICE Use it for my love some other way than swearing by it. BENEDICK Think you in your soul the Count Claudio hath wronged Hero? BEATRICE Yea, as sure as I have a thought or a soul. BENEDICK Enough, I am engaged; I will challenge him. I will kiss your hand, and so I leave you. By this hand, Claudio shall render me a dear account. As you hear of me, so think of me. Go, comfort your cousin: I must say she is dead: and so, farewell. Exeunt SCENE II. A prison. Enter DOGBERRY, VERGES, and Sexton, in gowns; and the Watch, with CONRADE and BORACHIO DOGBERRY Is our whole dissembly appeared? VERGES O, a stool and a cushion for the sexton. Sexton Which be the malefactors? DOGBERRY Marry, that am I and my partner. VERGES Nay, that's certain; we have the exhibition to examine. Sexton But which are the offenders that are to be examined? let them come before master constable. DOGBERRY Yea, marry, let them come before me. What is your name, friend? BORACHIO Borachio. DOGBERRY Pray, write down, Borachio. Yours, sirrah? CONRADE I am a gentleman, sir, and my name is Conrade. DOGBERRY Write down, master gentleman Conrade. Masters, do you serve God? CONRADE BORACHIO Yea, sir, we hope. DOGBERRY Write down, that they hope they serve God: and write God first; for God defend but God should go before such villains! Masters, it is proved already that you are little better than false knaves; and it will go near to be thought so shortly. How answer you for yourselves? CONRADE Marry, sir, we say we are none. DOGBERRY A marvellous witty fellow, I assure you: but I will go about with him. Come you hither, sirrah; a word in your ear: sir, I say to you, it is thought you are false knaves. BORACHIO Sir, I say to you we are none. DOGBERRY Well, stand aside. 'Fore God, they are both in a tale. Have you writ down, that they are none? Sexton Master constable, you go not the way to examine: you must call forth the watch that are their accusers. DOGBERRY Yea, marry, that's the eftest way. Let the watch come forth. Masters, I charge you, in the prince's name, accuse these men. First Watchman This man said, sir, that Don John, the prince's brother, was a villain. DOGBERRY Write down Prince John a villain. Why, this is flat perjury, to call a prince's brother villain. BORACHIO Master constable,-- DOGBERRY Pray thee, fellow, peace: I do not like thy look, I promise thee. Sexton What heard you him say else? Second Watchman Marry, that he had received a thousand ducats of Don John for accusing the Lady Hero wrongfully. DOGBERRY Flat burglary as ever was committed. VERGES Yea, by mass, that it is. Sexton What else, fellow? First Watchman And that Count Claudio did mean, upon his words, to disgrace Hero before the whole assembly. and not marry her. DOGBERRY O villain! thou wilt be condemned into everlasting redemption for this. Sexton What else? Watchman This is all. Sexton And this is more, masters, than you can deny. Prince John is this morning secretly stolen away; Hero was in this manner accused, in this very manner refused, and upon the grief of this suddenly died. Master constable, let these men be bound, and brought to Leonato's: I will go before and show him their examination. Exit DOGBERRY Come, let them be opinioned. VERGES Let them be in the hands-- CONRADE Off, coxcomb! DOGBERRY God's my life, where's the sexton? let him write down the prince's officer coxcomb. Come, bind them. Thou naughty varlet! CONRADE Away! you are an ass, you are an ass. DOGBERRY Dost thou not suspect my place? dost thou not suspect my years? O that he were here to write me down an ass! But, masters, remember that I am an ass; though it be not written down, yet forget not that I am an ass. No, thou villain, thou art full of piety, as shall be proved upon thee by good witness. I am a wise fellow, and, which is more, an officer, and, which is more, a householder, and, which is more, as pretty a piece of flesh as any is in Messina, and one that knows the law, go to; and a rich fellow enough, go to; and a fellow that hath had losses, and one that hath two gowns and every thing handsome about him. Bring him away. O that I had been writ down an ass! Exeunt ACT V SCENE I. Before LEONATO'S house. Enter LEONATO and ANTONIO ANTONIO If you go on thus, you will kill yourself: And 'tis not wisdom thus to second grief Against yourself. LEONATO I pray thee, cease thy counsel, Which falls into mine ears as profitless As water in a sieve: give not me counsel; Nor let no comforter delight mine ear But such a one whose wrongs do suit with mine. Bring me a father that so loved his child, Whose joy of her is overwhelm'd like mine, And bid him speak of patience; Measure his woe the length and breadth of mine And let it answer every strain for strain, As thus for thus and such a grief for such, In every lineament, branch, shape, and form: If such a one will smile and stroke his beard, Bid sorrow wag, cry 'hem!' when he should groan, Patch grief with proverbs, make misfortune drunk With candle-wasters; bring him yet to me, And I of him will gather patience. But there is no such man: for, brother, men Can counsel and speak comfort to that grief Which they themselves not feel; but, tasting it, Their counsel turns to passion, which before Would give preceptial medicine to rage, Fetter strong madness in a silken thread, Charm ache with air and agony with words: No, no; 'tis all men's office to speak patience To those that wring under the load of sorrow, But no man's virtue nor sufficiency To be so moral when he shall endure The like himself. Therefore give me no counsel: My griefs cry louder than advertisement. ANTONIO Therein do men from children nothing differ. LEONATO I pray thee, peace. I will be flesh and blood; For there was never yet philosopher That could endure the toothache patiently, However they have writ the style of gods And made a push at chance and sufferance. ANTONIO Yet bend not all the harm upon yourself; Make those that do offend you suffer too. LEONATO There thou speak'st reason: nay, I will do so. My soul doth tell me Hero is belied; And that shall Claudio know; so shall the prince And all of them that thus dishonour her. ANTONIO Here comes the prince and Claudio hastily. Enter DON PEDRO and CLAUDIO DON PEDRO Good den, good den. CLAUDIO Good day to both of you. LEONATO Hear you. my lords,-- DON PEDRO We have some haste, Leonato. LEONATO Some haste, my lord! well, fare you well, my lord: Are you so hasty now? well, all is one. DON PEDRO Nay, do not quarrel with us, good old man. ANTONIO If he could right himself with quarreling, Some of us would lie low. CLAUDIO Who wrongs him? LEONATO Marry, thou dost wrong me; thou dissembler, thou:-- Nay, never lay thy hand upon thy sword; I fear thee not. CLAUDIO Marry, beshrew my hand, If it should give your age such cause of fear: In faith, my hand meant nothing to my sword. LEONATO Tush, tush, man; never fleer and jest at me: I speak not like a dotard nor a fool, As under privilege of age to brag What I have done being young, or what would do Were I not old. Know, Claudio, to thy head, Thou hast so wrong'd mine innocent child and me That I am forced to lay my reverence by And, with grey hairs and bruise of many days, Do challenge thee to trial of a man. I say thou hast belied mine innocent child; Thy slander hath gone through and through her heart, And she lies buried with her ancestors; O, in a tomb where never scandal slept, Save this of hers, framed by thy villany! CLAUDIO My villany? LEONATO Thine, Claudio; thine, I say. DON PEDRO You say not right, old man. LEONATO My lord, my lord, I'll prove it on his body, if he dare, Despite his nice fence and his active practise, His May of youth and bloom of lustihood. CLAUDIO Away! I will not have to do with you. LEONATO Canst thou so daff me? Thou hast kill'd my child: If thou kill'st me, boy, thou shalt kill a man. ANTONIO He shall kill two of us, and men indeed: But that's no matter; let him kill one first; Win me and wear me; let him answer me. Come, follow me, boy; come, sir boy, come, follow me: Sir boy, I'll whip you from your foining fence; Nay, as I am a gentleman, I will. LEONATO Brother,-- ANTONIO Content yourself. God knows I loved my niece; And she is dead, slander'd to death by villains, That dare as well answer a man indeed As I dare take a serpent by the tongue: Boys, apes, braggarts, Jacks, milksops! LEONATO Brother Antony,-- ANTONIO Hold you content. What, man! I know them, yea, And what they weigh, even to the utmost scruple,-- Scrambling, out-facing, fashion-monging boys, That lie and cog and flout, deprave and slander, Go anticly, show outward hideousness, And speak off half a dozen dangerous words, How they might hurt their enemies, if they durst; And this is all. LEONATO But, brother Antony,-- ANTONIO Come, 'tis no matter: Do not you meddle; let me deal in this. DON PEDRO Gentlemen both, we will not wake your patience. My heart is sorry for your daughter's death: But, on my honour, she was charged with nothing But what was true and very full of proof. LEONATO My lord, my lord,-- DON PEDRO I will not hear you. LEONATO No? Come, brother; away! I will be heard. ANTONIO And shall, or some of us will smart for it. Exeunt LEONATO and ANTONIO DON PEDRO See, see; here comes the man we went to seek. Enter BENEDICK CLAUDIO Now, signior, what news? BENEDICK Good day, my lord. DON PEDRO Welcome, signior: you are almost come to part almost a fray. CLAUDIO We had like to have had our two noses snapped off with two old men without teeth. DON PEDRO Leonato and his brother. What thinkest thou? Had we fought, I doubt we should have been too young for them. BENEDICK In a false quarrel there is no true valour. I came to seek you both. CLAUDIO We have been up and down to seek thee; for we are high-proof melancholy and would fain have it beaten away. Wilt thou use thy wit? BENEDICK It is in my scabbard: shall I draw it? DON PEDRO Dost thou wear thy wit by thy side? CLAUDIO Never any did so, though very many have been beside their wit. I will bid thee draw, as we do the minstrels; draw, to pleasure us. DON PEDRO As I am an honest man, he looks pale. Art thou sick, or angry? CLAUDIO What, courage, man! What though care killed a cat, thou hast mettle enough in thee to kill care. BENEDICK Sir, I shall meet your wit in the career, and you charge it against me. I pray you choose another subject. CLAUDIO Nay, then, give him another staff: this last was broke cross. DON PEDRO By this light, he changes more and more: I think he be angry indeed. CLAUDIO If he be, he knows how to turn his girdle. BENEDICK Shall I speak a word in your ear? CLAUDIO God bless me from a challenge! BENEDICK Aside to CLAUDIO You are a villain; I jest not: I will make it good how you dare, with what you dare, and when you dare. Do me right, or I will protest your cowardice. You have killed a sweet lady, and her death shall fall heavy on you. Let me hear from you. CLAUDIO Well, I will meet you, so I may have good cheer. DON PEDRO What, a feast, a feast? CLAUDIO I' faith, I thank him; he hath bid me to a calf's head and a capon; the which if I do not carve most curiously, say my knife's naught. Shall I not find a woodcock too? BENEDICK Sir, your wit ambles well; it goes easily. DON PEDRO I'll tell thee how Beatrice praised thy wit the other day. I said, thou hadst a fine wit: 'True,' said she, 'a fine little one.' 'No,' said I, 'a great wit:' 'Right,' says she, 'a great gross one.' 'Nay,' said I, 'a good wit:' 'Just,' said she, 'it hurts nobody.' 'Nay,' said I, 'the gentleman is wise:' 'Certain,' said she, 'a wise gentleman.' 'Nay,' said I, 'he hath the tongues:' 'That I believe,' said she, 'for he swore a thing to me on Monday night, which he forswore on Tuesday morning; there's a double tongue; there's two tongues.' Thus did she, an hour together, transshape thy particular virtues: yet at last she concluded with a sigh, thou wast the properest man in Italy. CLAUDIO For the which she wept heartily and said she cared not. DON PEDRO Yea, that she did: but yet, for all that, an if she did not hate him deadly, she would love him dearly: the old man's daughter told us all. CLAUDIO All, all; and, moreover, God saw him when he was hid in the garden. DON PEDRO But when shall we set the savage bull's horns on the sensible Benedick's head? CLAUDIO Yea, and text underneath, 'Here dwells Benedick the married man'? BENEDICK Fare you well, boy: you know my mind. I will leave you now to your gossip-like humour: you break jests as braggarts do their blades, which God be thanked, hurt not. My lord, for your many courtesies I thank you: I must discontinue your company: your brother the bastard is fled from Messina: you have among you killed a sweet and innocent lady. For my Lord Lackbeard there, he and I shall meet: and, till then, peace be with him. Exit DON PEDRO He is in earnest. CLAUDIO In most profound earnest; and, I'll warrant you, for the love of Beatrice. DON PEDRO And hath challenged thee. CLAUDIO Most sincerely. DON PEDRO What a pretty thing man is when he goes in his doublet and hose and leaves off his wit! CLAUDIO He is then a giant to an ape; but then is an ape a doctor to such a man. DON PEDRO But, soft you, let me be: pluck up, my heart, and be sad. Did he not say, my brother was fled? Enter DOGBERRY, VERGES, and the Watch, with CONRADE and BORACHIO DOGBERRY Come you, sir: if justice cannot tame you, she shall ne'er weigh more reasons in her balance: nay, an you be a cursing hypocrite once, you must be looked to. DON PEDRO How now? two of my brother's men bound! Borachio one! CLAUDIO Hearken after their offence, my lord. DON PEDRO Officers, what offence have these men done? DOGBERRY Marry, sir, they have committed false report; moreover, they have spoken untruths; secondarily, they are slanders; sixth and lastly, they have belied a lady; thirdly, they have verified unjust things; and, to conclude, they are lying knaves. DON PEDRO First, I ask thee what they have done; thirdly, I ask thee what's their offence; sixth and lastly, why they are committed; and, to conclude, what you lay to their charge. CLAUDIO Rightly reasoned, and in his own division: and, by my troth, there's one meaning well suited. DON PEDRO Who have you offended, masters, that you are thus bound to your answer? this learned constable is too cunning to be understood: what's your offence? BORACHIO Sweet prince, let me go no farther to mine answer: do you hear me, and let this count kill me. I have deceived even your very eyes: what your wisdoms could not discover, these shallow fools have brought to light: who in the night overheard me confessing to this man how Don John your brother incensed me to slander the Lady Hero, how you were brought into the orchard and saw me court Margaret in Hero's garments, how you disgraced her, when you should marry her: my villany they have upon record; which I had rather seal with my death than repeat over to my shame. The lady is dead upon mine and my master's false accusation; and, briefly, I desire nothing but the reward of a villain. DON PEDRO Runs not this speech like iron through your blood? CLAUDIO I have drunk poison whiles he utter'd it. DON PEDRO But did my brother set thee on to this? BORACHIO Yea, and paid me richly for the practise of it. DON PEDRO He is composed and framed of treachery: And fled he is upon this villany. CLAUDIO Sweet Hero! now thy image doth appear In the rare semblance that I loved it first. DOGBERRY Come, bring away the plaintiffs: by this time our sexton hath reformed Signior Leonato of the matter: and, masters, do not forget to specify, when time and place shall serve, that I am an ass. VERGES Here, here comes master Signior Leonato, and the Sexton too. Re-enter LEONATO and ANTONIO, with the Sexton LEONATO Which is the villain? let me see his eyes, That, when I note another man like him, I may avoid him: which of these is he? BORACHIO If you would know your wronger, look on me. LEONATO Art thou the slave that with thy breath hast kill'd Mine innocent child? BORACHIO Yea, even I alone. LEONATO No, not so, villain; thou beliest thyself: Here stand a pair of honourable men; A third is fled, that had a hand in it. I thank you, princes, for my daughter's death: Record it with your high and worthy deeds: 'Twas bravely done, if you bethink you of it. CLAUDIO I know not how to pray your patience; Yet I must speak. Choose your revenge yourself; Impose me to what penance your invention Can lay upon my sin: yet sinn'd I not But in mistaking. DON PEDRO By my soul, nor I: And yet, to satisfy this good old man, I would bend under any heavy weight That he'll enjoin me to. LEONATO I cannot bid you bid my daughter live; That were impossible: but, I pray you both, Possess the people in Messina here How innocent she died; and if your love Can labour ought in sad invention, Hang her an epitaph upon her tomb And sing it to her bones, sing it to-night: To-morrow morning come you to my house, And since you could not be my son-in-law, Be yet my nephew: my brother hath a daughter, Almost the copy of my child that's dead, And she alone is heir to both of us: Give her the right you should have given her cousin, And so dies my revenge. CLAUDIO O noble sir, Your over-kindness doth wring tears from me! I do embrace your offer; and dispose For henceforth of poor Claudio. LEONATO To-morrow then I will expect your coming; To-night I take my leave. This naughty man Shall face to face be brought to Margaret, Who I believe was pack'd in all this wrong, Hired to it by your brother. BORACHIO No, by my soul, she was not, Nor knew not what she did when she spoke to me, But always hath been just and virtuous In any thing that I do know by her. DOGBERRY Moreover, sir, which indeed is not under white and black, this plaintiff here, the offender, did call me ass: I beseech you, let it be remembered in his punishment. And also, the watch heard them talk of one Deformed: they say be wears a key in his ear and a lock hanging by it, and borrows money in God's name, the which he hath used so long and never paid that now men grow hard-hearted and will lend nothing for God's sake: pray you, examine him upon that point. LEONATO I thank thee for thy care and honest pains. DOGBERRY Your worship speaks like a most thankful and reverend youth; and I praise God for you. LEONATO There's for thy pains. DOGBERRY God save the foundation! LEONATO Go, I discharge thee of thy prisoner, and I thank thee. DOGBERRY I leave an arrant knave with your worship; which I beseech your worship to correct yourself, for the example of others. God keep your worship! I wish your worship well; God restore you to health! I humbly give you leave to depart; and if a merry meeting may be wished, God prohibit it! Come, neighbour. Exeunt DOGBERRY and VERGES LEONATO Until to-morrow morning, lords, farewell. ANTONIO Farewell, my lords: we look for you to-morrow. DON PEDRO We will not fail. CLAUDIO To-night I'll mourn with Hero. LEONATO To the Watch Bring you these fellows on. We'll talk with Margaret, How her acquaintance grew with this lewd fellow. Exeunt, severally SCENE II. LEONATO'S garden. Enter BENEDICK and MARGARET, meeting BENEDICK Pray thee, sweet Mistress Margaret, deserve well at my hands by helping me to the speech of Beatrice. MARGARET Will you then write me a sonnet in praise of my beauty? BENEDICK In so high a style, Margaret, that no man living shall come over it; for, in most comely truth, thou deservest it. MARGARET To have no man come over me! why, shall I always keep below stairs? BENEDICK Thy wit is as quick as the greyhound's mouth; it catches. MARGARET And yours as blunt as the fencer's foils, which hit, but hurt not. BENEDICK A most manly wit, Margaret; it will not hurt a woman: and so, I pray thee, call Beatrice: I give thee the bucklers. MARGARET Give us the swords; we have bucklers of our own. BENEDICK If you use them, Margaret, you must put in the pikes with a vice; and they are dangerous weapons for maids. MARGARET Well, I will call Beatrice to you, who I think hath legs. BENEDICK And therefore will come. Exit MARGARET Sings The god of love, That sits above, And knows me, and knows me, How pitiful I deserve,-- I mean in singing; but in loving, Leander the good swimmer, Troilus the first employer of panders, and a whole bookful of these quondam carpet-mangers, whose names yet run smoothly in the even road of a blank verse, why, they were never so truly turned over and over as my poor self in love. Marry, I cannot show it in rhyme; I have tried: I can find out no rhyme to 'lady' but 'baby,' an innocent rhyme; for 'scorn,' 'horn,' a hard rhyme; for, 'school,' 'fool,' a babbling rhyme; very ominous endings: no, I was not born under a rhyming planet, nor I cannot woo in festival terms. Enter BEATRICE Sweet Beatrice, wouldst thou come when I called thee? BEATRICE Yea, signior, and depart when you bid me. BENEDICK O, stay but till then! BEATRICE 'Then' is spoken; fare you well now: and yet, ere I go, let me go with that I came; which is, with knowing what hath passed between you and Claudio. BENEDICK Only foul words; and thereupon I will kiss thee. BEATRICE Foul words is but foul wind, and foul wind is but foul breath, and foul breath is noisome; therefore I will depart unkissed. BENEDICK Thou hast frighted the word out of his right sense, so forcible is thy wit. But I must tell thee plainly, Claudio undergoes my challenge; and either I must shortly hear from him, or I will subscribe him a coward. And, I pray thee now, tell me for which of my bad parts didst thou first fall in love with me? BEATRICE For them all together; which maintained so politic a state of evil that they will not admit any good part to intermingle with them. But for which of my good parts did you first suffer love for me? BENEDICK Suffer love! a good epithet! I do suffer love indeed, for I love thee against my will. BEATRICE In spite of your heart, I think; alas, poor heart! If you spite it for my sake, I will spite it for yours; for I will never love that which my friend hates. BENEDICK Thou and I are too wise to woo peaceably. BEATRICE It appears not in this confession: there's not one wise man among twenty that will praise himself. BENEDICK An old, an old instance, Beatrice, that lived in the lime of good neighbours. If a man do not erect in this age his own tomb ere he dies, he shall live no longer in monument than the bell rings and the widow weeps. BEATRICE And how long is that, think you? BENEDICK Question: why, an hour in clamour and a quarter in rheum: therefore is it most expedient for the wise, if Don Worm, his conscience, find no impediment to the contrary, to be the trumpet of his own virtues, as I am to myself. So much for praising myself, who, I myself will bear witness, is praiseworthy: and now tell me, how doth your cousin? BEATRICE Very ill. BENEDICK And how do you? BEATRICE Very ill too. BENEDICK Serve God, love me and mend. There will I leave you too, for here comes one in haste. Enter URSULA URSULA Madam, you must come to your uncle. Yonder's old coil at home: it is proved my Lady Hero hath been falsely accused, the prince and Claudio mightily abused; and Don John is the author of all, who is fed and gone. Will you come presently? BEATRICE Will you go hear this news, signior? BENEDICK I will live in thy heart, die in thy lap, and be buried in thy eyes; and moreover I will go with thee to thy uncle's. Exeunt SCENE III. A church. Enter DON PEDRO, CLAUDIO, and three or four with tapers CLAUDIO Is this the monument of Leonato? Lord It is, my lord. CLAUDIO Reading out of a scroll Done to death by slanderous tongues Was the Hero that here lies: Death, in guerdon of her wrongs, Gives her fame which never dies. So the life that died with shame Lives in death with glorious fame. Hang thou there upon the tomb, Praising her when I am dumb. Now, music, sound, and sing your solemn hymn. SONG. Pardon, goddess of the night, Those that slew thy virgin knight; For the which, with songs of woe, Round about her tomb they go. Midnight, assist our moan; Help us to sigh and groan, Heavily, heavily: Graves, yawn and yield your dead, Till death be uttered, Heavily, heavily. CLAUDIO Now, unto thy bones good night! Yearly will I do this rite. DON PEDRO Good morrow, masters; put your torches out: The wolves have prey'd; and look, the gentle day, Before the wheels of Phoebus, round about Dapples the drowsy east with spots of grey. Thanks to you all, and leave us: fare you well. CLAUDIO Good morrow, masters: each his several way. DON PEDRO Come, let us hence, and put on other weeds; And then to Leonato's we will go. CLAUDIO And Hymen now with luckier issue speed's Than this for whom we render'd up this woe. Exeunt SCENE IV. A room in LEONATO'S house. Enter LEONATO, ANTONIO, BENEDICK, BEATRICE, MARGARET, URSULA, FRIAR FRANCIS, and HERO FRIAR FRANCIS Did I not tell you she was innocent? LEONATO So are the prince and Claudio, who accused her Upon the error that you heard debated: But Margaret was in some fault for this, Although against her will, as it appears In the true course of all the question. ANTONIO Well, I am glad that all things sort so well. BENEDICK And so am I, being else by faith enforced To call young Claudio to a reckoning for it. LEONATO Well, daughter, and you gentle-women all, Withdraw into a chamber by yourselves, And when I send for you, come hither mask'd. Exeunt Ladies The prince and Claudio promised by this hour To visit me. You know your office, brother: You must be father to your brother's daughter And give her to young Claudio. ANTONIO Which I will do with confirm'd countenance. BENEDICK Friar, I must entreat your pains, I think. FRIAR FRANCIS To do what, signior? BENEDICK To bind me, or undo me; one of them. Signior Leonato, truth it is, good signior, Your niece regards me with an eye of favour. LEONATO That eye my daughter lent her: 'tis most true. BENEDICK And I do with an eye of love requite her. LEONATO The sight whereof I think you had from me, From Claudio and the prince: but what's your will? BENEDICK Your answer, sir, is enigmatical: But, for my will, my will is your good will May stand with ours, this day to be conjoin'd In the state of honourable marriage: In which, good friar, I shall desire your help. LEONATO My heart is with your liking. FRIAR FRANCIS And my help. Here comes the prince and Claudio. Enter DON PEDRO and CLAUDIO, and two or three others DON PEDRO Good morrow to this fair assembly. LEONATO Good morrow, prince; good morrow, Claudio: We here attend you. Are you yet determined To-day to marry with my brother's daughter? CLAUDIO I'll hold my mind, were she an Ethiope. LEONATO Call her forth, brother; here's the friar ready. Exit ANTONIO DON PEDRO Good morrow, Benedick. Why, what's the matter, That you have such a February face, So full of frost, of storm and cloudiness? CLAUDIO I think he thinks upon the savage bull. Tush, fear not, man; we'll tip thy horns with gold And all Europa shall rejoice at thee, As once Europa did at lusty Jove, When he would play the noble beast in love. BENEDICK Bull Jove, sir, had an amiable low; And some such strange bull leap'd your father's cow, And got a calf in that same noble feat Much like to you, for you have just his bleat. CLAUDIO For this I owe you: here comes other reckonings. Re-enter ANTONIO, with the Ladies masked Which is the lady I must seize upon? ANTONIO This same is she, and I do give you her. CLAUDIO Why, then she's mine. Sweet, let me see your face. LEONATO No, that you shall not, till you take her hand Before this friar and swear to marry her. CLAUDIO Give me your hand: before this holy friar, I am your husband, if you like of me. HERO And when I lived, I was your other wife: Unmasking And when you loved, you were my other husband. CLAUDIO Another Hero! HERO Nothing certainer: One Hero died defiled, but I do live, And surely as I live, I am a maid. DON PEDRO The former Hero! Hero that is dead! LEONATO She died, my lord, but whiles her slander lived. FRIAR FRANCIS All this amazement can I qualify: When after that the holy rites are ended, I'll tell you largely of fair Hero's death: Meantime let wonder seem familiar, And to the chapel let us presently. BENEDICK Soft and fair, friar. Which is Beatrice? BEATRICE Unmasking I answer to that name. What is your will? BENEDICK Do not you love me? BEATRICE Why, no; no more than reason. BENEDICK Why, then your uncle and the prince and Claudio Have been deceived; they swore you did. BEATRICE Do not you love me? BENEDICK Troth, no; no more than reason. BEATRICE Why, then my cousin Margaret and Ursula Are much deceived; for they did swear you did. BENEDICK They swore that you were almost sick for me. BEATRICE They swore that you were well-nigh dead for me. BENEDICK 'Tis no such matter. Then you do not love me? BEATRICE No, truly, but in friendly recompense. LEONATO Come, cousin, I am sure you love the gentleman. CLAUDIO And I'll be sworn upon't that he loves her; For here's a paper written in his hand, A halting sonnet of his own pure brain, Fashion'd to Beatrice. HERO And here's another Writ in my cousin's hand, stolen from her pocket, Containing her affection unto Benedick. BENEDICK A miracle! here's our own hands against our hearts. Come, I will have thee; but, by this light, I take thee for pity. BEATRICE I would not deny you; but, by this good day, I yield upon great persuasion; and partly to save your life, for I was told you were in a consumption. BENEDICK Peace! I will stop your mouth. Kissing her DON PEDRO How dost thou, Benedick, the married man? BENEDICK I'll tell thee what, prince; a college of wit-crackers cannot flout me out of my humour. Dost thou think I care for a satire or an epigram? No: if a man will be beaten with brains, a' shall wear nothing handsome about him. In brief, since I do purpose to marry, I will think nothing to any purpose that the world can say against it; and therefore never flout at me for what I have said against it; for man is a giddy thing, and this is my conclusion. For thy part, Claudio, I did think to have beaten thee, but in that thou art like to be my kinsman, live unbruised and love my cousin. CLAUDIO I had well hoped thou wouldst have denied Beatrice, that I might have cudgelled thee out of thy single life, to make thee a double-dealer; which, out of question, thou wilt be, if my cousin do not look exceedingly narrowly to thee. BENEDICK Come, come, we are friends: let's have a dance ere we are married, that we may lighten our own hearts and our wives' heels. LEONATO We'll have dancing afterward. BENEDICK First, of my word; therefore play, music. Prince, thou art sad; get thee a wife, get thee a wife: there is no staff more reverend than one tipped with horn. Enter a Messenger Messenger My lord, your brother John is ta'en in flight, And brought with armed men back to Messina. BENEDICK Think not on him till to-morrow: I'll devise thee brave punishments for him. Strike up, pipers. Dance Exeunt
jaxen-1.1.6/xml/web2.xml0000664000175000017500000000013210226777637014354 0ustar ebourgebourg jaxen-1.1.6/xml/basic.xml0000664000175000017500000000024007353613615014566 0ustar ebourgebourg jaxen-1.1.6/xml/fibo.xml0000664000175000017500000000212107330307422014413 0ustar ebourgebourg 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 jaxen-1.1.6/xml/cdata.xml0000664000175000017500000000003510371462644014561 0ustar ebourgebourg

ab

jaxen-1.1.6/xml/basicupdate.xml0000664000175000017500000000220207353613615015771 0ustar ebourgebourg Goudse kaas Rond More cheese! Even more cheese! No sausages today jaxen-1.1.6/xml/underscore.xml0000664000175000017500000000011607472132404015652 0ustar ebourgebourg 1 <_b>2