jaxen-1.1.6/ 0000775 0001750 0001750 00000000000 12174247550 012165 5 ustar ebourg ebourg jaxen-1.1.6/LICENSE.txt 0000664 0001750 0001750 00000003051 10371471320 013776 0 ustar ebourg ebourg /*
$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/INSTALL 0000664 0001750 0001750 00000000436 12005262277 013215 0 ustar ebourg ebourg
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/ 0000775 0001750 0001750 00000000000 12174247546 013312 5 ustar ebourg ebourg jaxen-1.1.6/xdocs/jaxen.gif 0000664 0001750 0001750 00000001337 10440364260 015075 0 ustar ebourg ebourg GIF89a[ " UUU ݪҎ99 rrUU999!Created with The GIMP , [ " B)blp,aì|oH,6qԑLtJZldC]n8h VtjYkm_ 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͖#KvBdntR\Fgȥ)|(41}GW(c5+Zm̩ʃӓ=i¬]9maS:.Z ߁\Q2T2S =QC \ۘmł|;9]QgR9Ͱhm@r
8H 0% ˘,x)ܛZ[P -"wJ ?CfSS)ɩʼ@YV`urIM@2 yE7jY 5{a"8 $h 0b,1
بc\68#@@ ; jaxen-1.1.6/xdocs/extensions.xml 0000664 0001750 0001750 00000012610 10416452640 016221 0 ustar ebourg ebourg
Elliotte Rusty HaroldWriting Jaxen Extension FunctionsWriting 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:
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:
Update xdocs/releases.xml, xdocs/status.xml, and xdocs/index.xml with the new version number and information.
Update project.xml and INSTALL with the new version number.
Make sure all changes are committed.
Check that all tests pass by running mvn test.
Tag the release in Subversion.
Generate the release files by running
mvn package, mvn javadoc:javadoc, mvn assembly:single, and mvn site.
Using a WebDAV client, open https://dav.codehaus.org/dist/jaxen/.
(In the Mac OS X Finder, this is Go/Connect to Server...)
Copy the .zip, .bz2 and .tar.gz files from target to https://dav.codehaus.org/dist/jaxen/distributions.
Copy the .jar file from target to https://dav.codehaus.org/dist/jaxen/jars/.
Copy the .pom file from target to https://dav.codehaus.org/dist/jaxen/poms/.
Using the Mac Finder, or another WebDAV client, open https://dav.codehaus.org/jaxen/.
Copy all files from target/site into this directory, overwriting the existing files.
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.
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.
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 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.
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 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.
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.xml 0000664 0001750 0001750 00000032545 12074524256 013513 0 ustar ebourg ebourg
4.0.0oss-parentorg.sonatype.oss7jaxenjaxenbundlejaxen1.1.6Jaxen is a universal Java XPath engine.http://jaxen.codehaus.org/http://jaxen.codehaus.org/license.htmlJIRAhttp://jira.codehaus.org/BrowseProject.jspa?id=10022
dev@jaxen.codehaus.org
2001UTF-8UTF-8Jaxen Users Listuser-subscribe@jaxen.codehaus.orguser-unsubscribe@jaxen.codehaus.orghttp://archive.jaxen.codehaus.org/user/Jaxen Developers Listdev-subscribe@jaxen.codehaus.orgdev-unsubscribe@jaxen.codehaus.orghttp://archive.jaxen.codehaus.org/dev/Jaxen Commits Listscm-subscribe@jaxen.codehaus.orgscm-unsubscribe@jaxen.codehaus.orghttp://archive.jaxen.codehaus.org/scm/bobBob McWhirterbob@eng.werken.comThe Werken CompanyjstrachanJames Strachanjames_strachan@yahoo.co.ukSpiritsoftdmegginsonDavid Megginsoncontact@megginson.comMegginson TechnologieseboldwidtErwin Bolwidterwin@klomp.orgmbelongaMark A. Belongambelonga@users.sourceforge.netcnentwichChristian Nentwichxcut@users.sourceforge.netpurpletechAlexander Day Chaffeepurpletech@users.sourceforge.netPurple TechnologiesjdvorakJan Dvorakjdvorak@users.sourceforge.netszegediaAttila Szegediszegedia@users.sourceforge.netproyalPeter Royalpeter.royal@pobox.comhttp://fotap.org/~osissandersScott Sandersscott@dotnot.orghttp://dotnot.org/blogdotnotbewinsBrian Ewinsbrian.ewins@gmail.comelharoElliotte Rusty Haroldelharo@ibiblio.orghttp://www.elharo.com/Cafe au LaitRyan Gustafsonrgustav@users.sourceforge.netDavid Petersondavid@randombits.orgMark Wilsonmark.wilson@wilsoncom.deJacob Kjomehoju@visi.comMichael Brennanmpbrennan@earthlink.netJason Hunterjhunter@xquery.comBrett Mclaughlinbrett.mclaughlin@lutris.comBradley S. Huffmanhip@cs.okstate.eduK. Ari Krupnikovari@lib.aeroPaul R. Brownprb@fivesight.comGuoliang Caocao@ispsoft.comJérôme Nègrejerome.negre@e-xmlmedia.frEddie McGrealemcgreal@BlackPearl.comSteen Lehmannslehmann@users.sourceforge.netBen McCannbenjamin.j.mccann@gmail.comDon Corleydon@donandann.comscm:svn:https://svn.codehaus.org/jaxen/trunk/jaxen/http://fisheye.codehaus.org/browse/jaxen/Codehaushttp://codehaus.orgsrc/java/mainsrc/java/testmaven-compiler-plugin2.5.1truetruetrue1.31.2org.apache.felixmaven-bundle-plugin2.3.7true2${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.domorg.apache.maven.pluginsmaven-assembly-plugin2.3packagesinglejavadocsiteprojectsrcbinmaven-repository-plugin2.3.1maven-javadoc-plugin2.8.1org.jaxen.saxpath.base,org.jaxen.saxpath.helpers
http://java.sun.com/j2se/1.4.2/docs/api/
${basedir}/src/site/resources/css/javadoc-style.cssUTF-8./xdocs/stylesheets/javadoc-style.css
To Do:
todoXaUTF-8maven-surefire-plugin2.12**/*Test.javaorg.codehaus.mojocobertura-maven-plugin2.5.1org.codehaus.mojofindbugs-maven-plugin2.4.0dom4jdom4j1.6.1truejdomjdom1.0truexml-apisxml-apis1.3.02providedxercesxercesImpl2.6.2providedxomxom1.0truejunitjunit3.8.2testmaven-changelog-plugin2.2date2007-05-06UTF-8maven-checkstyle-plugin2.9.1maven-javadoc-plugin2.6.1org.apache.maven.pluginsmaven-jxr-plugin2.1org.apache.maven.pluginsmaven-pmd-plugin2.4org.apache.maven.pluginsmaven-surefire-report-plugin2.4.3org.codehaus.mojocobertura-maven-plugin2.5.1org.codehaus.mojofindbugs-maven-plugin2.4.0org.codehaus.mojojdepend-maven-plugin2.0-beta-2org.apache.maven.pluginsmaven-project-info-reports-plugin2.4falsefalsedependenciesscmdefaultDefault Sitescp://jaxen.codehaus.org/home/projects/jaxen/public_html
jaxen-1.1.6/src/ 0000775 0001750 0001750 00000000000 12174247550 012754 5 ustar ebourg ebourg jaxen-1.1.6/src/latex/ 0000775 0001750 0001750 00000000000 12174247550 014071 5 ustar ebourg ebourg jaxen-1.1.6/src/latex/intro-slides.tex 0000664 0001750 0001750 00000241154 10260255514 017227 0 ustar ebourg ebourg \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{\hiblue{mycompany:insert-random-bugs true}?>}
\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}
...BobMcWhirter...JamesStrachan
\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{}
...BobMcWhirter...JamesStrachan
\hiblue{}}
\end{codelisting}
%% ----------------------------------------------------------------------
%% ----------------------------------------------------------------------
\subslide{Location Paths - Processing Logic - Article }
\egxpath{/journal/\hiblue{article}/author/last}
\begin{codelisting}
\hifade{
\hiblue{}
...BobMcWhirter
\hiblue{}
\hiblue{}
...JamesStrachan
\hiblue{}
}
\end{codelisting}
%% ----------------------------------------------------------------------
%% ----------------------------------------------------------------------
\subslide{Location Paths - Processing Logic - Author }
\egxpath{/journal/article/\hiblue{author}/last}
\begin{codelisting}
\hifade{...
\hiblue{}
BobMcWhirter
\hiblue{}
...
\hiblue{}
JamesStrachan
\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}
...BobMcWhirter...JamesStrachan
\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{}
...BobMcWhirter
\hiblue{}
\hiblue{}
...JamesStrachan
\hiblue{}
\end{codelisting}
%% ----------------------------------------------------------------------
%% ----------------------------------------------------------------------
\subslide{Location Paths - Predicates - 1st article}
\egxpath{/journal/article[\hiblue{@id='article.2'}]}
\begin{codelisting}
\hiblue{}
...BobMcWhirter
\hiblue{}
...JamesStrachan
\end{codelisting}
%% ----------------------------------------------------------------------
%% ----------------------------------------------------------------------
\subslide{Location Paths - Predicates - 2nd article}
\egxpath{/journal/article[\hiblue{@id='article.2'}]}
\begin{codelisting}
...BobMcWhirter
\hiblue{}
...JamesStrachan
\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}
...BobMcWhirter
\hiblue{}
...JamesStrachan
\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{}
...JamesStrachanBobMcWhirter
\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/ 0000775 0001750 0001750 00000000000 12174247550 013675 5 ustar ebourg ebourg jaxen-1.1.6/src/java/test/ 0000775 0001750 0001750 00000000000 12174247547 014662 5 ustar ebourg ebourg jaxen-1.1.6/src/java/test/org/ 0000775 0001750 0001750 00000000000 12174247547 015451 5 ustar ebourg ebourg jaxen-1.1.6/src/java/test/org/jaxen/ 0000775 0001750 0001750 00000000000 12174247547 016556 5 ustar ebourg ebourg jaxen-1.1.6/src/java/test/org/jaxen/test/ 0000775 0001750 0001750 00000000000 12174247547 017535 5 ustar ebourg ebourg jaxen-1.1.6/src/java/test/org/jaxen/test/DefaultNamestepTest.java 0000664 0001750 0001750 00000010127 10610716306 024305 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000006516 10547514047 023325 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000126021 11270037767 023056 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000007143 10371471320 025525 0 ustar ebourg ebourg /* $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.java 0000664 0001750 0001750 00000013715 12074523431 023324 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000007001 10371471320 025626 0 ustar ebourg ebourg /* $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.java 0000664 0001750 0001750 00000015324 10371471320 022474 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000020443 10371471320 023204 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000011677 10416453131 024717 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000004776 10371471320 023037 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000005753 10371471320 023540 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000006623 10371471320 022640 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000006265 10371471320 025522 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000005056 10371471320 026263 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000015020 11102333372 024333 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000015343 10371471320 023123 0 ustar ebourg ebourg /* $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.java 0000664 0001750 0001750 00000011647 10371471320 022135 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000013457 10371471320 023347 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000005002 10371471320 022253 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000007143 10371471320 025465 0 ustar ebourg ebourg /* $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.java 0000664 0001750 0001750 00000005016 10371471320 023010 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000014727 10443564523 022742 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000005042 10371471320 022655 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000007006 10547514047 023470 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000007302 10371471320 021767 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000002325 10317472755 024562 0 ustar ebourg ebourg package 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.java 0000664 0001750 0001750 00000006476 10371471320 022155 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000007564 10371471320 024150 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000010562 10513271423 024415 0 ustar ebourg ebourg /*
* $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;
/**
*
*
* @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.java 0000664 0001750 0001750 00000011020 10371471320 023034 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000017043 10371471320 021562 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000006672 10371471320 026464 0 ustar ebourg ebourg /* $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.java 0000664 0001750 0001750 00000004762 10371471320 023371 0 ustar ebourg ebourg /*
$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.java 0000664 0001750 0001750 00000005502 10371471320 025305 0 ustar ebourg ebourg /* $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.java 0000664 0001750 0001750 00000012721 10371471320 023567 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000005774 10371471320 022336 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000011005 10520367563 025473 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000011056 11753411260 023545 0 ustar ebourg ebourg /* $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.java 0000664 0001750 0001750 00000005001 10371471320 023047 0 ustar ebourg ebourg /*
* $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/ 0000775 0001750 0001750 00000000000 12174247550 015341 5 ustar ebourg ebourg jaxen-1.1.6/src/java/samples/Dom4jDemo.java 0000664 0001750 0001750 00000007745 10371471320 017772 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000007651 10371471320 017430 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000007427 10371471320 017543 0 ustar ebourg ebourg /*
* $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/ 0000775 0001750 0001750 00000000000 12174247547 014627 5 ustar ebourg ebourg jaxen-1.1.6/src/java/main/org/ 0000775 0001750 0001750 00000000000 12174247550 015410 5 ustar ebourg ebourg jaxen-1.1.6/src/java/main/org/jaxen/ 0000775 0001750 0001750 00000000000 12174247550 016515 5 ustar ebourg ebourg jaxen-1.1.6/src/java/main/org/jaxen/VariableContext.java 0000664 0001750 0001750 00000011476 10452203147 022452 0 ustar ebourg ebourg /*
* $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/ 0000775 0001750 0001750 00000000000 12174247550 020172 5 ustar ebourg ebourg jaxen-1.1.6/src/java/main/org/jaxen/pattern/LocationPathPattern.java 0000664 0001750 0001750 00000022033 10371471320 024747 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000010517 10371471320 023564 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000005744 10371471320 023430 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000024623 10371471320 023625 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000006325 10371471320 024173 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000004661 10371471320 022560 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000025021 10371471320 023737 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000010227 10371471320 022546 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000011260 10371471320 023452 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000014344 10415516530 022451 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000005762 10371471320 023060 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000010675 10371471320 023424 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000005755 10371471320 023235 0 ustar ebourg ebourg /*
* $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.html 0000664 0001750 0001750 00000000260 07472132404 022445 0 ustar ebourg ebourg
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.java 0000664 0001750 0001750 00000020722 10514521500 020771 0 ustar ebourg ebourg package 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.java 0000664 0001750 0001750 00000037335 10412761307 021730 0 ustar ebourg ebourg /*
* $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/ 0000775 0001750 0001750 00000000000 12174247550 017532 5 ustar ebourg ebourg jaxen-1.1.6/src/java/main/org/jaxen/dom4j/DocumentNavigator.java 0000664 0001750 0001750 00000034323 10452214352 024022 0 ustar ebourg ebourg package 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.java 0000664 0001750 0001750 00000006647 10440373212 022321 0 ustar ebourg ebourg /*
* $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.html 0000664 0001750 0001750 00000000247 07327350513 022014 0 ustar ebourg ebourg
org.jaxen.dom4j.*
jaxen-1.1.6/src/java/main/org/jaxen/javabean/ 0000775 0001750 0001750 00000000000 12174247547 020272 5 ustar ebourg ebourg jaxen-1.1.6/src/java/main/org/jaxen/javabean/Element.java 0000664 0001750 0001750 00000001042 10027430666 022512 0 ustar ebourg ebourg package 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.java 0000664 0001750 0001750 00000023647 10440371260 024562 0 ustar ebourg ebourg /*
$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.java 0000664 0001750 0001750 00000011702 10440371260 023532 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000001405 10027430666 024227 0 ustar ebourg ebourg package 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.html 0000664 0001750 0001750 00000000211 10027430666 022534 0 ustar ebourg ebourg
org.jaxen.javabean.*
Navigation for JavaBeans.
jaxen-1.1.6/src/java/main/org/jaxen/util/ 0000775 0001750 0001750 00000000000 12174247550 017472 5 ustar ebourg ebourg jaxen-1.1.6/src/java/main/org/jaxen/util/PrecedingAxisIterator.java 0000664 0001750 0001750 00000016747 10526166501 024606 0 ustar ebourg ebourg package 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.java 0000664 0001750 0001750 00000006067 10524670534 024462 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000011712 10371471320 023416 0 ustar ebourg ebourg /*
* $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.java 0000664 0001750 0001750 00000011506 10524670534 024746 0 ustar ebourg ebourg package 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.java 0000664 0001750 0001750 00000010717 10524670534 025572 0 ustar ebourg ebourg package 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