commons-jxpath-1.3-src/src/ 40755 0 0 0 11044113546 12731 5ustar 0 0 commons-jxpath-1.3-src/src/assembly/ 40755 0 0 0 11044113516 14545 5ustar 0 0 commons-jxpath-1.3-src/src/conf/ 40755 0 0 0 11044113546 13656 5ustar 0 0 commons-jxpath-1.3-src/src/java/ 40755 0 0 0 11044113525 13647 5ustar 0 0 commons-jxpath-1.3-src/src/java/org/ 40755 0 0 0 11044113525 14436 5ustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/ 40755 0 0 0 11044113525 15657 5ustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/ 40755 0 0 0 11044113525 17332 5ustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ 40755 0 0 0 11044113545 20632 5ustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/functions/ 40755 0 0 0 11044113543 22640 5ustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/ 40755 0 0 0 11044113541 21240 5ustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/axes/ 40755 0 0 0 11044113530 22176 5ustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/ 40755 0 0 0 11044113540 23051 5ustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/ 40755 0 0 0 11044113535 22343 5ustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/beans/ 40755 0 0 0 11044113534 23432 5ustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/container/ 40755 0 0 0 11044113531 24321 5ustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/dom/ 40755 0 0 0 11044113531 23116 5ustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/dynabeans/ 40755 0 0 0 11044113531 24303 5ustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/dynamic/ 40755 0 0 0 11044113532 23764 5ustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/jdom/ 40755 0 0 0 11044113535 23274 5ustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/parser/ 40755 0 0 0 11044113541 22534 5ustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/servlet/ 40755 0 0 0 11044113526 22315 5ustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/util/ 40755 0 0 0 11044113545 21607 5ustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/xml/ 40755 0 0 0 11044113543 21430 5ustar 0 0 commons-jxpath-1.3-src/src/site/ 40755 0 0 0 11044113546 13675 5ustar 0 0 commons-jxpath-1.3-src/src/site/resources/ 40755 0 0 0 11044113546 15707 5ustar 0 0 commons-jxpath-1.3-src/src/site/resources/images/ 40755 0 0 0 11044113546 17154 5ustar 0 0 commons-jxpath-1.3-src/src/test/ 40755 0 0 0 11044113516 13705 5ustar 0 0 commons-jxpath-1.3-src/src/test/org/ 40755 0 0 0 11044113516 14474 5ustar 0 0 commons-jxpath-1.3-src/src/test/org/apache/ 40755 0 0 0 11044113516 15715 5ustar 0 0 commons-jxpath-1.3-src/src/test/org/apache/commons/ 40755 0 0 0 11044113516 17370 5ustar 0 0 commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ 40755 0 0 0 11044113525 20666 5ustar 0 0 commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/ 40755 0 0 0 11044113525 21300 5ustar 0 0 commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/axes/ 40755 0 0 0 11044113517 22241 5ustar 0 0 commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/compiler/ 40755 0 0 0 11044113523 23110 5ustar 0 0 commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/ 40755 0 0 0 11044113523 22376 5ustar 0 0 commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/beans/ 40755 0 0 0 11044113517 23471 5ustar 0 0 commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/container/ 40755 0 0 0 11044113517 24363 5ustar 0 0 commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/dom/ 40755 0 0 0 11044113517 23160 5ustar 0 0 commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/dynabeans/ 40755 0 0 0 11044113523 24342 5ustar 0 0 commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/dynamic/ 40755 0 0 0 11044113517 24025 5ustar 0 0 commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/jdom/ 40755 0 0 0 11044113517 23332 5ustar 0 0 commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/servlet/ 40755 0 0 0 11044113516 22352 5ustar 0 0 commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/util/ 40755 0 0 0 11044113525 21643 5ustar 0 0 commons-jxpath-1.3-src/xdocs/ 40755 0 0 0 11044113515 13256 5ustar 0 0 commons-jxpath-1.3-src/xdocs/images/ 40755 0 0 0 11044113511 14517 5ustar 0 0 commons-jxpath-1.3-src/xdocs/style/ 40755 0 0 0 11044113510 14411 5ustar 0 0 commons-jxpath-1.3-src/conf/ 40755 0 0 0 11044113515 13063 5ustar 0 0 commons-jxpath-1.3-src/build.properties.sample100644 0 0 4122 11044113546 16733 0ustar 0 0 # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ------------------------------------------------------------------- # build.properties.sample # # This is an example "build.properties" file, used to customize # building various Commons components for your local environment. # Make any changes you need, and rename this file to # "build.properties" # # $Id: build.properties.sample 480417 2006-11-29 05:37:40Z bayard $ # ------------------------------------------------------------------- # ------------------------------------------------------------------- # EXTERNAL DEPENDENCIES # ------------------------------------------------------------------- junit.jar=${lib.repo}/junit-3.7.jar jaxp.jaxp.jar=${lib.repo}/jaxp-1.1.jar jaxp.xslt.jar=${lib.repo}/xalan-2.1.0.jar commons-beanutils.jar=${lib.repo}/commons-beanutils.jar commons-logging.jar=${lib.repo}/commons-logging.jar # The Servlet API (See http://java.sun.com/products/servlet) servlet.jar=${lib.repo}/servlet.jar # =================================================================== # Anakia Properties (used by the xdoc target) # =================================================================== velocity.jar=${lib.repo}/velocity-1.3-dev.jar jdom.jar=${lib.repo}/jdom-b7.jar xerces.jar=${lib.repo}/xerces-1.4.3.jar commons-collections.jar=${lib.repo}/commons-collections.jar logkit.jar=${lib.repo}/logkit-1.0.jarcommons-jxpath-1.3-src/build.xml100644 0 0 16116 11044113546 14105 0ustar 0 0 commons-jxpath-1.3-src/checkstyle.properties100644 0 0 1526 11044113546 16517 0ustar 0 0 # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. checkstyle.cache.file=C:/temp/cache basedir=D:/jakarta-commons/jxpathcommons-jxpath-1.3-src/checkstyle.xml100644 0 0 17055 11044113546 15147 0ustar 0 0 commons-jxpath-1.3-src/LICENSE.txt100644 0 0 26136 11044113546 14112 0ustar 0 0 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. commons-jxpath-1.3-src/maven.xml100644 0 0 13331 11044113546 14110 0ustar 0 0 commons-jxpath-1.3-src/NOTICE.txt100644 0 0 257 11044113546 13745 0ustar 0 0 Apache Commons JXPath Copyright 2001-2008 The Apache Software Foundation This product includes software developed by The Apache Software Foundation (http://www.apache.org/). commons-jxpath-1.3-src/pom.xml100644 0 0 21724 11044113546 13602 0ustar 0 0 org.apache.commons commons-parent 11 4.0.0 commons-jxpath commons-jxpath Commons JXPath 1.3 A Java-based implementation of XPath 1.0 that, in addition to XML processing, can inspect/modify Java object graphs (the library's explicit purpose) and even mixed Java/XML structures. http://commons.apache.org/jxpath/ jira http://issues.apache.org/jira/browse/JXPATH 2001 dmitri Dmitri Plotnikov dmitri@apache.org craigmcc Craig McClanahan Craig.McClanahan@eng.sun.com Sun Microsystems mbenson Matt Benson mbenson@apache.org scm:svn:http://svn.apache.org/repos/asf/commons/proper/jxpath/trunk scm:svn:https://svn.apache.org/repos/asf/commons/proper/jxpath/trunk http://svn.apache.org/repos/asf/commons/proper/jxpath/trunk jxpath 1.3 JXPATH 12310480 src/java src/test src/test **/*.xml maven-surefire-plugin **/*Test.java maven-assembly-plugin src/assembly/bin.xml src/assembly/src.xml gnu commons-logging commons-logging 1.1.1 runtime xerces xercesImpl 2.4.0 provided true javax.servlet servlet-api 2.4 provided true javax.servlet jsp-api 2.0 provided true junit junit 3.8.1 test xml-apis xml-apis 1.3.04 provided true jdom jdom 1.0 true commons-beanutils commons-beanutils 1.7.0 true com.mockrunner mockrunner-jdk1.3-j2ee1.3 0.4 test cglib-nodep cglib-nodep jboss jboss-jee nekohtml nekohtml struts struts oro oro commons-validator commons-validator commons-digester commons-digester org.codehaus.mojo taglist-maven-plugin 2.2 maven-checkstyle-plugin 2.1 ${basedir}/checkstyle.xml org/apache/commons/jxpath/ri/parser/* org.apache.maven.plugins maven-pmd-plugin 2.3 1.3 org/apache/commons/jxpath/ri/parser/* org.codehaus.mojo findbugs-maven-plugin 1.2 conf/findbugs-exclude-filter.xml true org.apache.maven.plugins maven-javadoc-plugin 2.4 true http://java.sun.com/j2se/1.3/docs/api/ http://java.sun.com/javaee/5/docs/api/ http://commons.apache.org/beanutils/apidocs/ http://www.jdom.org/docs/apidocs/ org.codehaus.mojo rat-maven-plugin 1.0-alpha-3 src/java/org/apache/commons/jxpath/ri/parser/* src/conf/MANIFEST.MF xdocs/style/project.css apache.website Default Site scp://people.apache.org/www/commons.apache.org/jxpath/ commons-jxpath-1.3-src/project.properties100644 0 0 3676 11044113546 16037 0ustar 0 0 # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ## # Properties that override Maven build defaults ## maven.repo.remote=http://repo1.maven.org/maven maven.changelog.factory=org.apache.maven.svnlib.SvnChangeLogFactory maven.changelog.range=120 maven.checkstyle.properties=${basedir}/checkstyle.xml maven.checkstyle.excludes=**/parser/* maven.test.failure = false maven.junit.fork=true maven.linkcheck.enable=true maven.compile.source=1.3 maven.compile.target=1.3 # Jar Manifest Additional Attributes maven.jar.manifest.attributes.list=Implementation-Vendor-Id,X-Compile-Source-JDK,X-Compile-Target-JDK maven.jar.manifest.attribute.Implementation-Vendor-Id=org.apache maven.jar.manifest.attribute.X-Compile-Source-JDK=${maven.compile.source} maven.jar.manifest.attribute.X-Compile-Target-JDK=${maven.compile.target} # commons site L&F maven.xdoc.date=left maven.xdoc.poweredby.image=maven-feather.png maven.xdoc.version=${pom.currentVersion} maven.xdoc.developmentProcessUrl=http://commons.apache.org/charter.html # Make the source distro unzip to a different directory maven.dist.src.assembly.dir=${maven.dist.assembly.dir}/src/${maven.final.name}-src #maven.proxy.host= #maven.proxy.port=80 #maven.proxy.username= #maven.proxy.password= commons-jxpath-1.3-src/project.xml100644 0 0 21141 11044113546 14446 0ustar 0 0 3 JXPath commons-jxpath commons-jxpath 1.3-SNAPSHOT 2001 XPath for Java Objects A Java-based implementation of XPath 1.0 that, in addition to XML processing, can inspect/modify Java object graphs (the library's explicit purpose) and even mixed Java/XML structures. /images/logo-wbg.jpg http://commons.apache.org/${pom.artifactId.substring(8)}/ org.apache.commons.${pom.artifactId.substring(8)} The Apache Software Foundation http://commons.apache.org/ http://commons.apache.org/images/logo.png The Apache Software License, Version 2.0 /LICENSE.txt repo commons http://issues.apache.org/jira/ people.apache.org /www/commons.apache.org/${pom.artifactId.substring(8)}/ /www/people.apache.org/builds/commons/${pom.artifactId.substring(8)}/ scm:svn:http://svn.apache.org/repos/asf/commons/proper/${pom.artifactId.substring(8)}/trunk http://svn.apache.org/repos/asf/commons/proper/${pom.artifactId.substring(8)}/trunk Commons Dev List dev-subscribe@commons.apache.org dev-unsubscribe@commons.apache.org http://mail-archives.apache.org/mod_mbox/commons-dev/ Commons User List user-subscribe@commons.apache.org user-unsubscribe@commons.apache.org http://mail-archives.apache.org/mod_mbox/commons-user/ 1.2 1.2 JXPATH_1_2 Dmitri Plotnikov dmitri dmitri@apache.org Craig McClanahan craigmcc Craig.McClanahan@eng.sun.com Sun Microsystems Matt Benson mbenson mbenson@apache.org commons-logging commons-logging 1.1 http://commons.apache.org/logging/ Required xerces xerces 2.4.0 true needed for XML support servletapi servletapi 2.4 true provided needed for JSP support jspapi jsp-api 2.0 http://java.sun.com/products/servlet/2.3/javadoc/index.html true provided needed for JSP support junit junit jar 3.8.1 http://www.junit.org/ test testing only xml-apis xml-apis 2.0.2 http://xml.apache.org/commons/ provided true needed for XML support; provided starting with Java 1.4 jdom jdom 1.0 http://www.jdom.org true needed for XML support commons-beanutils commons-beanutils 1.7.0 http://commons.apache.org/beanutils/ true needed for dynabean support commons-collections commons-collections 3.2 http://commons.apache.org/collections/ runtime dependency of beanutils com.mockrunner mockrunner-jdk1.3-j2ee1.3 0.4 test testing only maven maven-xdoc-plugin 1.9.2 http://maven.apache.org/reference/plugins/xdoc/ plugin true <strong>Site Only</strong> - v1.9.2 (minimum) required for building the Site documentation. dev@commons.apache.org src/java src/test **/*Test.java ${pom.build.unitTestSourceDirectory} **/*.xml ${basedir} META-INF NOTICE.txt maven-junit-report-plugin maven-jdepend-plugin maven-changelog-plugin maven-javadoc-plugin maven-jxr-plugin maven-license-plugin maven-tasklist-plugin maven-junit-report-plugin commons-jxpath-1.3-src/PROPOSAL.html100644 0 0 7665 11044113546 14402 0ustar 0 0 Proposal for BeanUtils Package

Proposal for JXPath Package

(0) Rationale

In heterogenous techologies like Struts, XML documents are combined with object graphs consisting of JavaBeans, collections, arrays, maps and primitive values. In such systems there is a need for a consistent way of referencing both parts of XML documents and elements of object graphs.  XPath is a powerful language introduced by W3C (XML Path Language) as a common format for addressing elements of XML documents.  The proposed JXPath component provides a mechanism for applying the same XPath language to generic object graphs.

(1) Scope of the Package

This proposal is to create a package of Java utility methods for accessing and modifying the elements of arbitrary graphs consisting of JavaBeans, collections, arrays, maps and primitive values using the XPath syntax. This package will (at least initially) depend on an external implementation of an XPath expression processor.

This package augments BeanUtils, which provides a lighter-weight reference format.

(1.5) Interaction With Other Packages

JXPath relies on
  • Java Development Kit (Version 1.2 or later)
  • A JAXP 1.1 implementation
  • An XPath interpreter implementation. Initially the package will only support the interpreter provided by the Apache Xalan project, but will have an extensibility mechanism that will allow adding alternative XPath processors later.
No external configuration files are utilized.

(2) Initial Source of the Package

The original source of the component was donated by PLOTNIX, Inc (www.plotnix.com).

The proposed package names for the new component are

  • org.apache.commons.jxpath for the main API package
  • org.apache.commons.jxpath.tree for a light-weight DOM-JavaBeans API adapter
  • org.apache.commons.jxpath.xalan for a Xalan XPath interpreter adapter

(3) Required Jakarta-Commons Resources

  • CVS Repository - New directory jxpath in the jakarta-commons CVS repository. There is a requirement to setup an additional committer: Dmitri Plotnikov.
  • Mailing List - Discussions will take place on the general jakarta-commons@jakarta.apache.org mailing list. To help list subscribers identify messages of interest, it is suggested that the message subject of messages about this component be prefixed with [JXPath].
  • Bugzilla - New component "JXPath" under the "Commons" product category, with appropriate version identifiers as needed.
  • Jyve FAQ - New category "commons-jxpath" (when available).

(4) Initial Committers

The initial committers on the JXPath component shall be Dmitri Plotnikov and Craig McClanahan. commons-jxpath-1.3-src/rat.xml100644 0 0 2126 11044113546 13550 0ustar 0 0 commons-jxpath-1.3-src/src/assembly/bin.xml100644 0 0 2774 11044113516 16146 0ustar 0 0 bin tar.gz zip false LICENSE.txt NOTICE.txt target *.jar target/site/apidocs apidocs commons-jxpath-1.3-src/src/assembly/src.xml100644 0 0 3576 11044113516 16166 0ustar 0 0 src tar.gz zip ${project.artifactId}-${project.version}-src build.properties.sample build.xml checkstyle.properties checkstyle.xml LICENSE.txt maven.xml NOTICE.txt pom.xml project.properties project.xml PROPOSAL.html rat.xml src xdocs conf commons-jxpath-1.3-src/src/conf/MANIFEST.MF100644 0 0 424 11044113546 15365 0ustar 0 0 Extension-Name: @name@ Specification-Title: Jakarta Commons JXPath Specification-Vendor: Apache Software Foundation Specification-Version: 1.0 Implementation-Title: org.apache.commons.jxpath Implementation-Vendor: Apache Software Foundation Implementation-Version: @version@ commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/AbstractFactory.java100644 0 0 6015 11044113545 24667 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; /** * The {@link JXPathContext#createPath JXPathContext.createPath()} method of * JXPathContext can create missing objects as it traverses an XPath; it * utilizes an AbstractFactory for that purpose. Install a factory on * JXPathContext by calling {@link JXPathContext#setFactory JXPathContext. * setFactory()}. *

* All methods of this class return false. Override any of them to return true * to indicate that the factory has successfully created the described object. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public abstract class AbstractFactory { /** * The parameters may describe a collection element or an individual * object. It is up to the factory to infer which one it is. If it is a * collection, the factory should check if the collection exists. If not, * it should create the collection. Then it should create the index'th * element of the collection and return true. *

* * @param context can be used to evaluate other XPaths, get to variables * etc. * @param pointer describes the location of the node to be created * @param parent is the object that will serve as a parent of the new * object * @param name is the name of the child of the parent that needs to be * created. In the case of DOM may be qualified. * @param index is used if the pointer represents a collection element. You * may need to expand or even create the collection to accommodate the new * element. * * @return true if the object was successfully created */ public boolean createObject(JXPathContext context, Pointer pointer, Object parent, String name, int index) { return false; } /** * Declare the specified variable * * @param context hosts variable pools. See * {@link JXPathContext#getVariables() JXPathContext.getVariables()} * @param name is the name of the variable without the "$" sign * * @return true if the variable was successfully defined */ public boolean declareVariable(JXPathContext context, String name) { return false; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/BasicNodeSet.java100644 0 0 6215 11044113545 24101 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; import java.util.ArrayList; import java.util.Collections; import java.util.List; /** * A simple implementation of {@link NodeSet} that behaves as a collection * of pointers. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class BasicNodeSet implements NodeSet { private List pointers = new ArrayList(); private List readOnlyPointers; private List nodes; private List values; /** * Add a pointer to this NodeSet. * @param pointer to add */ public void add(Pointer pointer) { if (pointers.add(pointer)) { clearCacheLists(); } } /** * Add the specified NodeSet to this NodeSet. * @param nodeSet to add */ public void add(NodeSet nodeSet) { if (pointers.addAll(nodeSet.getPointers())) { clearCacheLists(); } } /** * Remove a pointer from this NodeSet. * @param pointer to remove */ public void remove(Pointer pointer) { if (pointers.remove(pointer)) { clearCacheLists(); } } public synchronized List getPointers() { if (readOnlyPointers == null) { readOnlyPointers = Collections.unmodifiableList(pointers); } return readOnlyPointers; } public synchronized List getNodes() { if (nodes == null) { nodes = new ArrayList(); for (int i = 0; i < pointers.size(); i++) { Pointer pointer = (Pointer) pointers.get(i); nodes.add(pointer.getNode()); } nodes = Collections.unmodifiableList(nodes); } return nodes; } public synchronized List getValues() { if (values == null) { values = new ArrayList(); for (int i = 0; i < pointers.size(); i++) { Pointer pointer = (Pointer) pointers.get(i); values.add(pointer.getValue()); } values = Collections.unmodifiableList(values); } return values; } public String toString() { return pointers.toString(); } /** * Clear cache list members. */ private synchronized void clearCacheLists() { readOnlyPointers = null; nodes = null; values = null; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/BasicVariables.java100644 0 0 5510 11044113545 24445 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; import java.util.HashMap; /** * A basic implementation of the Variables interface that uses a HashMap. * * @author Dmitri Plotnikov * @version $Revision: 652925 $ $Date: 2008-05-02 17:05:41 -0500 (Fri, 02 May 2008) $ */ public class BasicVariables implements Variables { private static final long serialVersionUID = 2708263960832062725L; /** * Contains the values of declared variables */ private HashMap vars = new HashMap(); /** * Returns true if the variable has been defined, even if the * value of the variable is null. * * @param varName is a variable name without the "$" sign * * @return true if the variable is declared */ public boolean isDeclaredVariable(String varName) { return vars.containsKey(varName); } /** * Returns the value of the variable if it is defined, * otherwise, throws IllegalArgumentException * * @param varName is a variable name without the "$" sign * * @return the value of the variable */ public Object getVariable(String varName) { // Note that a variable may be defined with a null value if (vars.containsKey(varName)) { return vars.get(varName); } throw new IllegalArgumentException( "No such variable: '" + varName + "'"); } /** * Defines a new variable with the specified value or modifies * the value of an existing variable. * * @param varName is a variable name without the "$" sign * @param value is the new value for the variable, which can be null */ public void declareVariable(String varName, Object value) { vars.put(varName, value); } /** * Removes an existing variable. May throw UnsupportedOperationException. * * @param varName is a variable name without the "$" sign */ public void undeclareVariable(String varName) { vars.remove(varName); } public String toString() { return vars.toString(); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ClassFunctions.java100644 0 0 10371 11044113545 24552 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.util.Collections; import java.util.Set; import org.apache.commons.jxpath.functions.ConstructorFunction; import org.apache.commons.jxpath.functions.MethodFunction; import org.apache.commons.jxpath.util.MethodLookupUtils; /** * Extension functions provided by a Java class. * * Let's say we declared a ClassFunction like this: *

 *     new ClassFunctions(Integer.class, "int")
 * 
* * We can now use XPaths like: *
*
"int:new(3)"
*
Equivalent to new Integer(3)
*
"int:getInteger('foo')"
*
Equivalent to Integer.getInteger("foo")
*
"int:floatValue(int:new(4))"
*
Equivalent to new Integer(4).floatValue()
*
* *

* If the first argument of a method is {@link ExpressionContext}, the * expression context in which the function is evaluated is passed to * the method. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class ClassFunctions implements Functions { private static final Object[] EMPTY_ARRAY = new Object[0]; private Class functionClass; private String namespace; /** * Create a new ClassFunctions. * @param functionClass Class providing the functions * @param namespace assigned ns */ public ClassFunctions(Class functionClass, String namespace) { this.functionClass = functionClass; this.namespace = namespace; } /** * Returns a set of one namespace - the one specified in the constructor. * * @return a singleton */ public Set getUsedNamespaces() { return Collections.singleton(namespace); } /** * Returns a {@link Function}, if any, for the specified namespace, * name and parameter types. * * @param namespace if it is not the namespace specified in the constructor, * the method returns null * @param name is a function name or "new" for a constructor. * @param parameters Object[] of parameters * * @return a MethodFunction, a ConstructorFunction or null if there is no * such function. */ public Function getFunction( String namespace, String name, Object[] parameters) { if (namespace == null) { if (this.namespace != null) { return null; } } else if (!namespace.equals(this.namespace)) { return null; } if (parameters == null) { parameters = EMPTY_ARRAY; } if (name.equals("new")) { Constructor constructor = MethodLookupUtils.lookupConstructor(functionClass, parameters); if (constructor != null) { return new ConstructorFunction(constructor); } } else { Method method = MethodLookupUtils. lookupStaticMethod(functionClass, name, parameters); if (method != null) { return new MethodFunction(method); } method = MethodLookupUtils. lookupMethod(functionClass, name, parameters); if (method != null) { return new MethodFunction(method); } } return null; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/CompiledExpression.java100644 0 0 11634 11044113545 25433 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; import java.util.Iterator; /** * Represents a compiled XPath. The interpretation of compiled XPaths * may be faster, because it bypasses the compilation step. The reference * implementation of {@link JXPathContext} also globally caches some of the * results of compilation, so the direct use of JXPathContext is not * always less efficient than the use of CompiledExpression. *

* Use CompiledExpression only when there is a need to evaluate the * same expression multiple times and the CompiledExpression can be * conveniently cached. *

* To acquire a CompiledExpression, call {@link JXPathContext#compile * JXPathContext.compile} * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public interface CompiledExpression { /** * Evaluates the xpath and returns the resulting object. Primitive * types are wrapped into objects. * @param context to evaluate * @return Object */ Object getValue(JXPathContext context); /** * Evaluates the xpath, converts the result to the specified class and * returns the resulting object. * @param context to evaluate * @param requiredType return type * @return Object */ Object getValue(JXPathContext context, Class requiredType); /** * Modifies the value of the property described by the supplied xpath. * Will throw an exception if one of the following conditions occurs: *

    *
  • The xpath does not in fact describe an existing property *
  • The property is not writable (no public, non-static set method) *
* @param context base * @param value to set */ void setValue(JXPathContext context, Object value); /** * Creates intermediate elements of * the path by invoking an {@link AbstractFactory}, which should first be * installed on the context by calling {@link JXPathContext#setFactory}. * @param context base * @return Pointer created */ Pointer createPath(JXPathContext context); /** * The same as setValue, except it creates intermediate elements of * the path by invoking an {@link AbstractFactory}, which should first be * installed on the context by calling {@link JXPathContext#setFactory}. *

* Will throw an exception if one of the following conditions occurs: *

    *
  • Elements of the xpath aleady exist, by the path does not in * fact describe an existing property *
  • The AbstractFactory fails to create an instance for an intermediate * element. *
  • The property is not writable (no public, non-static set method) *
* @param context base * @param value to set * @return Pointer created */ Pointer createPathAndSetValue(JXPathContext context, Object value); /** * Traverses the xpath and returns a Iterator of all results found * for the path. If the xpath matches no properties * in the graph, the Iterator will not be null. * @param context base * @return Iterator */ Iterator iterate(JXPathContext context); /** * Traverses the xpath and returns a Pointer. * A Pointer provides easy access to a property. * If the xpath matches no properties * in the graph, the pointer will be null. * @param context base * @param xpath string * @return Pointer found */ Pointer getPointer(JXPathContext context, String xpath); /** * Traverses the xpath and returns an Iterator of Pointers. * A Pointer provides easy access to a property. * If the xpath matches no properties * in the graph, the Iterator be empty, but not null. * @param context to iterate * @return Iterator */ Iterator iteratePointers(JXPathContext context); /** * Remove the graph element described by this expression. * @param context base */ void removePath(JXPathContext context); /** * Remove all graph elements described by this expression. * @param context base */ void removeAll(JXPathContext context); } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/Container.java100644 0 0 3126 11044113545 23516 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; import java.io.Serializable; /** * A Container is an object implementing an indirection * mechanism transparent to JXPath. For example, if property * "foo" of the context node has a Container as its value, * the XPath "foo" will produce the contents of that Container, * rather than the container itself. * * @author Dmitri Plotnikov * @version $Revision: 652925 $ $Date: 2008-05-02 17:05:41 -0500 (Fri, 02 May 2008) $ */ public interface Container extends Serializable { /** * Returns the contained value. * @return Object value */ Object getValue(); /** * Modifies the value contained by this container. May throw * UnsupportedOperationException. * @param value Object value to set. */ void setValue(Object value); } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/DynamicPropertyHandler.java100644 0 0 4577 11044113545 26236 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; /** * A generic mechanism for accessing collections of name/value pairs. * Examples of such collections are HashMap, Properties, * ServletContext. In order to add support for a new such collection * type to JXPath, perform the following two steps: *
    *
  1. Build an implementation of the DynamicPropertyHandler interface * for the desired collection type.
  2. *
  3. Invoke the static method {@link JXPathIntrospector#registerDynamicClass * JXPathIntrospector.registerDynamicClass(class, handlerClass)}
  4. *
* JXPath allows access to dynamic properties using these three formats: *
    *
  • "myMap/myKey"
  • *
  • "myMap[@name = 'myKey']"
  • *
  • "myMap[name(.) = 'myKey']"
  • *
* * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public interface DynamicPropertyHandler { /** * Returns a list of dynamic property names for the supplied object. * @param object to inspect * @return String[] */ String[] getPropertyNames(Object object); /** * Returns the value of the specified dynamic property. * @param object to search * @param propertyName to retrieve * @return Object */ Object getProperty(Object object, String propertyName); /** * Modifies the value of the specified dynamic property. * @param object to modify * @param propertyName to modify * @param value to set */ void setProperty(Object object, String propertyName, Object value); } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ExpressionContext.java100644 0 0 4520 11044113545 25277 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; import java.util.List; /** * If an extenstion function has an argument of type ExpressionContext, * it can gain access to the current node of an XPath expression context. *

* Example: *

 * public class MyExtenstionFunctions {
 *    public static String objectType(ExpressionContext context){
 *       Object value = context.getContextNodePointer().getValue();
 *       if (value == null){
 *           return "null";
 *       }
 *       return value.getClass().getName();
 *    }
 * }
 * 
* * You can then register this extension function using a {@link ClassFunctions * ClassFunctions} object and call it like this: *
 *   "/descendent-or-self::node()[ns:objectType() = 'java.util.Date']"
 * 
* This expression will find all nodes of the graph that are dates. */ public interface ExpressionContext { /** * Get the JXPathContext in which this function is being evaluated. * * @return A list representing the current context nodes. */ JXPathContext getJXPathContext(); /** * Get the current context node. * * @return The current context node pointer. */ Pointer getContextNodePointer(); /** * Get the current context node list. Each element of the list is * a Pointer. * * @return A list representing the current context nodes. */ List getContextNodeList(); /** * Returns the current context position. * @return int */ int getPosition(); } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ExtendedKeyManager.java100644 0 0 2715 11044113545 25303 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; /** * More complete implementation for the XPath "key()" function. * Returns NodeSet results and allows Object values for better compatibility * with non-XML graphs. * * @author Sergey Vladimirov * @author Matt Benson * @since JXPath 1.3 * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public interface ExtendedKeyManager extends KeyManager { /** * Find a NodeSet by key/value. * @param context base * @param key String * @param value Object * @return NodeSet found */ NodeSet getNodeSetByKey(JXPathContext context, String key, Object value); } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/Function.java100644 0 0 3570 11044113545 23364 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; /** * Extension function interface. Extension functions are grouped into * {@link Functions Functions} objects, which are installed on * JXPathContexts using the * {@link JXPathContext#setFunctions JXPathContext.setFunctions()} * call. *

* The Function interface can be implemented directly. However, * most of the time JXPath's built-in implementations should suffice. * See {@link ClassFunctions ClassFunctions} and * {@link PackageFunctions PackageFunctions}. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public interface Function { /** * Computes the value of the function. Each implementation of Function * is responsible for conversion of supplied parameters to the required * argument types. * * @param context can be used to acquire the context in which the * function is being evaluted. * @param parameters function arguments * @return Object result */ Object invoke(ExpressionContext context, Object[] parameters); } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/FunctionLibrary.java100644 0 0 10422 11044113545 24723 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Set; /** * An object that aggregates {@link Functions} objects into a group Functions * object. Since {@link JXPathContext} can only register a single Functions * object, FunctionLibrary should always be used to group all Functions objects * that need to be registered. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class FunctionLibrary implements Functions { private List allFunctions = new ArrayList(); private HashMap byNamespace = null; /** * Add functions to the library * @param functions to add */ public void addFunctions(Functions functions) { allFunctions.add(functions); byNamespace = null; } /** * Remove functions from the library. * @param functions to remove */ public void removeFunctions(Functions functions) { allFunctions.remove(functions); byNamespace = null; } /** * Returns a set containing all namespaces used by the aggregated * Functions. * @return Set */ public Set getUsedNamespaces() { if (byNamespace == null) { prepareCache(); } return byNamespace.keySet(); } /** * Returns a Function, if any, for the specified namespace, * name and parameter types. * @param namespace function namespace * @param name function name * @param parameters parameters * @return Function found */ public Function getFunction(String namespace, String name, Object[] parameters) { if (byNamespace == null) { prepareCache(); } Object candidates = byNamespace.get(namespace); if (candidates instanceof Functions) { return ((Functions) candidates).getFunction( namespace, name, parameters); } if (candidates instanceof List) { List list = (List) candidates; int count = list.size(); for (int i = 0; i < count; i++) { Function function = ((Functions) list.get(i)).getFunction( namespace, name, parameters); if (function != null) { return function; } } } return null; } /** * Prepare the cache. */ private void prepareCache() { byNamespace = new HashMap(); int count = allFunctions.size(); for (int i = 0; i < count; i++) { Functions funcs = (Functions) allFunctions.get(i); Set namespaces = funcs.getUsedNamespaces(); for (Iterator it = namespaces.iterator(); it.hasNext();) { String ns = (String) it.next(); Object candidates = byNamespace.get(ns); if (candidates == null) { byNamespace.put(ns, funcs); } else if (candidates instanceof Functions) { List lst = new ArrayList(); lst.add(candidates); lst.add(funcs); byNamespace.put(ns, lst); } else { ((List) candidates).add(funcs); } } } } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/functions/ConstructorFunction.java100644 0 0 5723 11044113543 27642 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.functions; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import org.apache.commons.jxpath.ExpressionContext; import org.apache.commons.jxpath.Function; import org.apache.commons.jxpath.JXPathInvalidAccessException; import org.apache.commons.jxpath.util.TypeUtils; /** * An extension function that creates an instance using a constructor. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class ConstructorFunction implements Function { private static final Object[] EMPTY_ARRAY = new Object[0]; private Constructor constructor; /** * Create a new ConstructorFunction. * @param constructor the constructor to call. */ public ConstructorFunction(Constructor constructor) { this.constructor = constructor; } /** * Converts parameters to suitable types and invokes the constructor. * @param context evaluation context * @param parameters constructor args * @return new instance */ public Object invoke(ExpressionContext context, Object[] parameters) { try { Object[] args; if (parameters == null) { parameters = EMPTY_ARRAY; } int pi = 0; Class[] types = constructor.getParameterTypes(); if (types.length > 0 && ExpressionContext.class.isAssignableFrom(types[0])) { pi = 1; } args = new Object[parameters.length + pi]; if (pi == 1) { args[0] = context; } for (int i = 0; i < parameters.length; i++) { args[i + pi] = TypeUtils.convert(parameters[i], types[i + pi]); } return constructor.newInstance(args); } catch (Throwable ex) { if (ex instanceof InvocationTargetException) { ex = ((InvocationTargetException) ex).getTargetException(); } throw new JXPathInvalidAccessException( "Cannot invoke constructor " + constructor, ex); } } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/functions/MethodFunction.java100644 0 0 7527 11044113543 26541 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.functions; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import org.apache.commons.jxpath.ExpressionContext; import org.apache.commons.jxpath.Function; import org.apache.commons.jxpath.JXPathInvalidAccessException; import org.apache.commons.jxpath.util.TypeUtils; import org.apache.commons.jxpath.util.ValueUtils; /** * An XPath extension function implemented as an individual Java method. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class MethodFunction implements Function { private Method method; private static final Object[] EMPTY_ARRAY = new Object[0]; /** * Create a new MethodFunction. * @param method implementing Method */ public MethodFunction(Method method) { this.method = ValueUtils.getAccessibleMethod(method); } public Object invoke(ExpressionContext context, Object[] parameters) { try { Object target; Object[] args; if (Modifier.isStatic(method.getModifiers())) { target = null; if (parameters == null) { parameters = EMPTY_ARRAY; } int pi = 0; Class[] types = method.getParameterTypes(); if (types.length >= 1 && ExpressionContext.class.isAssignableFrom(types[0])) { pi = 1; } args = new Object[parameters.length + pi]; if (pi == 1) { args[0] = context; } for (int i = 0; i < parameters.length; i++) { args[i + pi] = TypeUtils.convert(parameters[i], types[i + pi]); } } else { int pi = 0; Class[] types = method.getParameterTypes(); if (types.length >= 1 && ExpressionContext.class.isAssignableFrom(types[0])) { pi = 1; } target = TypeUtils.convert( parameters[0], method.getDeclaringClass()); args = new Object[parameters.length - 1 + pi]; if (pi == 1) { args[0] = context; } for (int i = 1; i < parameters.length; i++) { args[pi + i - 1] = TypeUtils.convert(parameters[i], types[i + pi - 1]); } } return method.invoke(target, args); } catch (Throwable ex) { if (ex instanceof InvocationTargetException) { ex = ((InvocationTargetException) ex).getTargetException(); } throw new JXPathInvalidAccessException("Cannot invoke " + method, ex); } } public String toString() { return method.toString(); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/functions/package.html100644 0 0 1544 11044113543 25222 0ustar 0 0 Implementations of Java class-based extension functions. commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/Functions.java100644 0 0 3320 11044113545 23540 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; import java.util.Set; /** * A group of Function objects sharing a common namespace or a set of * common namespaces. Use the classes * {@link ClassFunctions ClassFunctions} and * {@link PackageFunctions PackageFunctions} * to register extension functions implemented as Java methods. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public interface Functions { /** * Returns all namespaces in which this function collection defines * functions. * @return Set */ Set getUsedNamespaces(); /** * Returns a Function, if any, for the specified namespace, * name and parameter types. * @param namespace ns * @param name function name * @param parameters Object[] * @return Function */ Function getFunction(String namespace, String name, Object[] parameters); } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/IdentityManager.java100644 0 0 2706 11044113545 24663 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; /** * A delegate of {@link JXPathContext} that implements the XPath "id()" * function. This delegate is only used when there is no default implementation * of the id() function. For example, it is not used * when the root of the context is a DOM Node. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public interface IdentityManager { /** * Finds a node by its ID. * @param context JXPathContext * @param id String * @return Pointer */ Pointer getPointerByID(JXPathContext context, String id); } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/JXPathAbstractFactoryException.java100644 0 0 2574 11044113545 27633 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; /** * Thrown when an {@link AbstractFactory} cannot generate an object for * the requested path. * * @author Dmitri Plotnikov * @version $Revision: 658784 $ $Date: 2008-05-21 12:44:55 -0500 (Wed, 21 May 2008) $ */ public class JXPathAbstractFactoryException extends JXPathException { private static final long serialVersionUID = -4403564377958943239L; /** * Create a new JXPathAbstractFactoryException. * @param message exception message */ public JXPathAbstractFactoryException(String message) { super(message); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/JXPathBasicBeanInfo.java100644 0 0 14153 11044113545 25320 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; import java.beans.BeanInfo; import java.beans.IntrospectionException; import java.beans.Introspector; import java.beans.PropertyDescriptor; import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; /** * An implementation of JXPathBeanInfo based on JavaBeans' BeanInfo. Properties * advertised by JXPathBasicBeanInfo are the same as those advertised by * BeanInfo for the corresponding class. * * @see java.beans.BeanInfo * @see java.beans.Introspector * * @author Dmitri Plotnikov * @version $Revision: 668329 $ $Date: 2008-06-16 16:59:48 -0500 (Mon, 16 Jun 2008) $ */ public class JXPathBasicBeanInfo implements JXPathBeanInfo { private static final long serialVersionUID = -3863803443111484155L; private static final Comparator PROPERTY_DESCRIPTOR_COMPARATOR = new Comparator() { public int compare(Object left, Object right) { return ((PropertyDescriptor) left).getName().compareTo( ((PropertyDescriptor) right).getName()); } }; private boolean atomic = false; private Class clazz; private Class dynamicPropertyHandlerClass; private transient PropertyDescriptor[] propertyDescriptors; private transient HashMap propertyDescriptorMap; /** * Create a new JXPathBasicBeanInfo. * @param clazz bean class */ public JXPathBasicBeanInfo(Class clazz) { this.clazz = clazz; } /** * Create a new JXPathBasicBeanInfo. * @param clazz bean class * @param atomic whether objects of this class are treated as atomic * objects which have no properties of their own. */ public JXPathBasicBeanInfo(Class clazz, boolean atomic) { this.clazz = clazz; this.atomic = atomic; } /** * Create a new JXPathBasicBeanInfo. * @param clazz bean class * @param dynamicPropertyHandlerClass dynamic property handler class */ public JXPathBasicBeanInfo(Class clazz, Class dynamicPropertyHandlerClass) { this.clazz = clazz; this.atomic = false; this.dynamicPropertyHandlerClass = dynamicPropertyHandlerClass; } /** * Returns true if objects of this class are treated as atomic * objects which have no properties of their own. * @return boolean */ public boolean isAtomic() { return atomic; } /** * Return true if the corresponding objects have dynamic properties. * @return boolean */ public boolean isDynamic() { return dynamicPropertyHandlerClass != null; } public synchronized PropertyDescriptor[] getPropertyDescriptors() { if (propertyDescriptors == null) { if (clazz == Object.class) { propertyDescriptors = new PropertyDescriptor[0]; } else { try { BeanInfo bi = null; if (clazz.isInterface()) { bi = Introspector.getBeanInfo(clazz); } else { bi = Introspector.getBeanInfo(clazz, Object.class); } PropertyDescriptor[] pds = bi.getPropertyDescriptors(); PropertyDescriptor[] descriptors = new PropertyDescriptor[pds.length]; System.arraycopy(pds, 0, descriptors, 0, pds.length); Arrays.sort(descriptors, PROPERTY_DESCRIPTOR_COMPARATOR); propertyDescriptors = descriptors; } catch (IntrospectionException ex) { ex.printStackTrace(); } } } if (propertyDescriptors.length == 0) { return propertyDescriptors; } PropertyDescriptor[] result = new PropertyDescriptor[propertyDescriptors.length]; System.arraycopy(propertyDescriptors, 0, result, 0, propertyDescriptors.length); return result; } public synchronized PropertyDescriptor getPropertyDescriptor(String propertyName) { if (propertyDescriptorMap == null) { propertyDescriptorMap = new HashMap(); PropertyDescriptor[] pds = getPropertyDescriptors(); for (int i = 0; i < pds.length; i++) { propertyDescriptorMap.put(pds[i].getName(), pds[i]); } } return (PropertyDescriptor) propertyDescriptorMap.get(propertyName); } /** * For a dynamic class, returns the corresponding DynamicPropertyHandler * class. * @return Class */ public Class getDynamicPropertyHandlerClass() { return dynamicPropertyHandlerClass; } public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append("BeanInfo [class = "); buffer.append(clazz.getName()); if (isDynamic()) { buffer.append(", dynamic"); } if (isAtomic()) { buffer.append(", atomic"); } buffer.append(", properties = "); PropertyDescriptor[] jpds = getPropertyDescriptors(); for (int i = 0; i < jpds.length; i++) { buffer.append("\n "); buffer.append(jpds[i].getPropertyType()); buffer.append(": "); buffer.append(jpds[i].getName()); } buffer.append("]"); return buffer.toString(); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/JXPathBeanInfo.java100644 0 0 6257 11044113545 24344 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; import java.beans.PropertyDescriptor; import java.io.Serializable; /** * JXPathBeanInfo is similar to {@link java.beans.BeanInfo} in that it describes * properties of a JavaBean class. By default, JXPathBeanInfo classes are * automatically generated by {@link JXPathIntrospector JXPathIntrospector} * based on the java.beans.BeanInfo. As with JavaBeans, the user can supply an * alternative implementation of JXPathBeanInfo for a custom class. The * alternative implementation is located by class name, which is the same as the * name of the class it represents with the suffix "XBeanInfo". So, for * example, if you need to provide an alternative JXPathBeanInfo class for class * "com.foo.Bar", write a class "com.foo.BarXBeanInfo" and make it implement the * JXPathBeanInfo interface. * * @author Dmitri Plotnikov * @version $Revision: 668329 $ $Date: 2008-06-16 16:59:48 -0500 (Mon, 16 Jun 2008) $ */ public interface JXPathBeanInfo extends Serializable { /** * Returns true if objects of this class are treated as atomic * objects which have no properties of their own. * For example, {@link String} and {@link Number} are atomic. * @return boolean */ boolean isAtomic(); /** * Returns true if the objects of this class have dynamic properties * (e.g. java.util.Map). If this method returns true, {@link #getPropertyDescriptors} * should return null and {@link #getDynamicPropertyHandlerClass} should return * a valid class name. An object cannot have both static and dynamic * properties at the same time. * @return boolean */ boolean isDynamic(); /** * Returns a list of property descriptors for the beans described by this * bean info object. Returns null for atomic beans. * @return PropertyDescriptor[] */ PropertyDescriptor[] getPropertyDescriptors(); /** * Returns a PropertyDescriptor for the specified name or null if there * is no such property. * @param propertyName property name * @return PropertyDescriptor */ PropertyDescriptor getPropertyDescriptor(String propertyName); /** * For dynamic objects, returns the class implementing * the {@link DynamicPropertyHandler} interface. That class can * be used to access dynamic properties. * @return Class */ Class getDynamicPropertyHandlerClass(); } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/JXPathContext.java100644 0 0 76036 11044113545 24331 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; import java.text.DecimalFormatSymbols; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Locale; import org.apache.commons.jxpath.util.KeyManagerUtils; /** * JXPathContext provides APIs for the traversal of graphs of JavaBeans using * the XPath syntax. Using JXPathContext, you can read and write properties of * JavaBeans, arrays, collections and maps. JXPathContext uses JavaBeans * introspection to enumerate and access JavaBeans properties. *

* JXPathContext allows alternative implementations. This is why instead of * allocating JXPathContext directly, you should call a static * newContext method. This method will utilize the * {@link JXPathContextFactory} API to locate a suitable implementation of * JXPath. Bundled with JXPath comes a default implementation called Reference * Implementation. *

* *

JXPath Interprets XPath Syntax on Java Object Graphs

* * JXPath uses an intuitive interpretation of the xpath syntax in the context * of Java object graphs. Here are some examples: * *

Example 1: JavaBean Property Access

* * JXPath can be used to access properties of a JavaBean. * *
* public class Employee { * public String getFirstName(){ * ... * } * } * * Employee emp = new Employee(); * ... * * JXPathContext context = JXPathContext.newContext(emp); * String fName = (String)context.getValue("firstName"); *
* * In this example, we are using JXPath to access a property of the * emp bean. In this simple case the invocation of JXPath is * equivalent to invocation of getFirstName() on the bean. * *

Example 2: Nested Bean Property Access

* JXPath can traverse object graphs: * *
* public class Employee { * public Address getHomeAddress(){ * ... * } * } * public class Address { * public String getStreetNumber(){ * ... * } * } * * Employee emp = new Employee(); * ... * * JXPathContext context = JXPathContext.newContext(emp); * String sNumber = (String)context.getValue("homeAddress/streetNumber"); *
* * In this case XPath is used to access a property of a nested bean. *

* A property identified by the xpath does not have to be a "leaf" property. * For instance, we can extract the whole Address object in above example: * *

* Address addr = (Address)context.getValue("homeAddress"); *
*

* *

Example 3: Collection Subscripts

* JXPath can extract elements from arrays and collections. * *
* public class Integers { * public int[] getNumbers(){ * ... * } * } * * Integers ints = new Integers(); * ... * * JXPathContext context = JXPathContext.newContext(ints); * Integer thirdInt = (Integer)context.getValue("numbers[3]"); *
* A collection can be an arbitrary array or an instance of java.util. * Collection. *

* Note: in XPath the first element of a collection has index 1, not 0.
* *

Example 4: Map Element Access

* * JXPath supports maps. To get a value use its key. * *
* public class Employee { * public Map getAddresses(){ * return addressMap; * } * * public void addAddress(String key, Address address){ * addressMap.put(key, address); * } * ... * } * * Employee emp = new Employee(); * emp.addAddress("home", new Address(...)); * emp.addAddress("office", new Address(...)); * ... * * JXPathContext context = JXPathContext.newContext(emp); * String homeZipCode = (String)context.getValue("addresses/home/zipCode"); *
* * Often you will need to use the alternative syntax for accessing Map * elements: * *
* String homeZipCode = * (String) context.getValue("addresses[@name='home']/zipCode"); *
* * In this case, the key can be an expression, e.g. a variable.
* * Note: At this point JXPath only supports Maps that use strings for keys.
* Note: JXPath supports the extended notion of Map: any object with * dynamic properties can be handled by JXPath provided that its * class is registered with the {@link JXPathIntrospector}. * *

Example 5: Retrieving Multiple Results

* * JXPath can retrieve multiple objects from a graph. Note that the method * called in this case is not getValue, but iterate. * *
* public class Author { * public Book[] getBooks(){ * ... * } * } * * Author auth = new Author(); * ... * * JXPathContext context = JXPathContext.newContext(auth); * Iterator threeBooks = context.iterate("books[position() < 4]"); *
* * This returns a list of at most three books from the array of all books * written by the author. * *

Example 6: Setting Properties

* JXPath can be used to modify property values. * *
* public class Employee { * public Address getAddress() { * ... * } * * public void setAddress(Address address) { * ... * } * } * * Employee emp = new Employee(); * Address addr = new Address(); * ... * * JXPathContext context = JXPathContext.newContext(emp); * context.setValue("address", addr); * context.setValue("address/zipCode", "90190"); * *
* *

Example 7: Creating objects

* JXPath can be used to create new objects. First, create a subclass of {@link * AbstractFactory AbstractFactory} and install it on the JXPathContext. Then * call {@link JXPathContext#createPath createPathAndSetValue()} instead of * "setValue". JXPathContext will invoke your AbstractFactory when it discovers * that an intermediate node of the path is null. It will not override * existing nodes. * *
* public class AddressFactory extends AbstractFactory { * public boolean createObject(JXPathContext context, * Pointer pointer, Object parent, String name, int index){ * if ((parent instanceof Employee) && name.equals("address"){ * ((Employee)parent).setAddress(new Address()); * return true; * } * return false; * } * } * * JXPathContext context = JXPathContext.newContext(emp); * context.setFactory(new AddressFactory()); * context.createPathAndSetValue("address/zipCode", "90190"); *
* *

Example 8: Using Variables

* JXPath supports the notion of variables. The XPath syntax for accessing * variables is "$varName". * *
* public class Author { * public Book[] getBooks(){ * ... * } * } * * Author auth = new Author(); * ... * * JXPathContext context = JXPathContext.newContext(auth); * context.getVariables().declareVariable("index", new Integer(2)); * * Book secondBook = (Book)context.getValue("books[$index]"); *
* * You can also set variables using JXPath: * *
* context.setValue("$index", new Integer(3)); *
* * Note: you can only change the value of an existing variable this * way, you cannot define a new variable. * *

* When a variable contains a JavaBean or a collection, you can * traverse the bean or collection as well: *

* ... * context.getVariables().declareVariable("book", myBook); * String title = (String)context.getValue("$book/title); * * Book array[] = new Book[]{...}; * * context.getVariables().declareVariable("books", array); * * String title = (String)context.getValue("$books[2]/title); *
* *

Example 9: Using Nested Contexts

* If you need to use the same set of variable while interpreting XPaths with * different beans, it makes sense to put the variables in a separate context * and specify that context as a parent context every time you allocate a new * JXPathContext for a JavaBean. * *
* JXPathContext varContext = JXPathContext.newContext(null); * varContext.getVariables().declareVariable("title", "Java"); * * JXPathContext context = JXPathContext.newContext(varContext, auth); * * Iterator javaBooks = context.iterate("books[title = $title]"); *
* *

Using Custom Variable Pools

* By default, JXPathContext creates a HashMap of variables. However, * you can substitute a custom implementation of the Variables * interface to make JXPath work with an alternative source of variables. * For example, you can define implementations of Variables that * cover a servlet context, HTTP request or any similar structure. * *

Example 10: Using Standard Extension Functions

* Using the standard extension functions, you can call methods on objects, * static methods on classes and create objects using any constructor. * The class names should be fully qualified. *

* Here's how you can create new objects: *

* Book book = * (Book) context.getValue( * "org.apache.commons.jxpath.example.Book.new ('John Updike')"); *
* * Here's how you can call static methods: *
* Book book = * (Book) context.getValue( * "org. apache.commons.jxpath.example.Book.getBestBook('John Updike')"); *
* * Here's how you can call regular methods: *
* String firstName = (String)context.getValue("getAuthorsFirstName($book)"); *
* As you can see, the target of the method is specified as the first parameter * of the function. * *

Example 11: Using Custom Extension Functions

* Collections of custom extension functions can be implemented * as {@link Functions Functions} objects or as Java classes, whose methods * become extenstion functions. *

* Let's say the following class implements various formatting operations: *

* public class Formats { * public static String date(Date d, String pattern){ * return new SimpleDateFormat(pattern).format(d); * } * ... * } *
* * We can register this class with a JXPathContext: * *
* context.setFunctions(new ClassFunctions(Formats.class, "format")); * ... * * context.getVariables().declareVariable("today", new Date()); * String today = (String)context.getValue("format:date($today, 'MM/dd/yyyy')"); * *
* You can also register whole packages of Java classes using PackageFunctions. *

* Also, see {@link FunctionLibrary FunctionLibrary}, which is a class * that allows you to register multiple sets of extension functions with * the same JXPathContext. * *

Configuring JXPath

* * JXPath uses JavaBeans introspection to discover properties of JavaBeans. * You can provide alternative property lists by supplying * custom JXPathBeanInfo classes (see {@link JXPathBeanInfo JXPathBeanInfo}). * *

Notes

*
    *
  • JXPath does not support DOM attributes for non-DOM objects. Even though * XPaths like "para[@type='warning']" are legitimate, they will always produce * empty results. The only attribute supported for JavaBeans is "name". The * XPath "foo/bar" is equivalent to "foo[@name='bar']". *
* * See XPath Tutorial by * W3Schools
. Also see XML Path * Language (XPath) Version 1.0

* * You will also find more information and examples in * * JXPath User's Guide * * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public abstract class JXPathContext { private static JXPathContextFactory contextFactory; private static JXPathContext compilationContext; private static final PackageFunctions GENERIC_FUNCTIONS = new PackageFunctions("", null); /** parent context */ protected JXPathContext parentContext; /** context bean */ protected Object contextBean; /** variables */ protected Variables vars; /** functions */ protected Functions functions; /** AbstractFactory */ protected AbstractFactory factory; /** IdentityManager */ protected IdentityManager idManager; /** KeyManager */ protected KeyManager keyManager; /** decimal format map */ protected HashMap decimalFormats; private Locale locale; private boolean lenientSet = false; private boolean lenient = false; /** * Creates a new JXPathContext with the specified object as the root node. * @param contextBean Object * @return JXPathContext */ public static JXPathContext newContext(Object contextBean) { return getContextFactory().newContext(null, contextBean); } /** * Creates a new JXPathContext with the specified bean as the root node and * the specified parent context. Variables defined in a parent context can * be referenced in XPaths passed to the child context. * @param parentContext parent context * @param contextBean Object * @return JXPathContext */ public static JXPathContext newContext( JXPathContext parentContext, Object contextBean) { return getContextFactory().newContext(parentContext, contextBean); } /** * Acquires a context factory and caches it. * @return JXPathContextFactory */ private static JXPathContextFactory getContextFactory () { if (contextFactory == null) { contextFactory = JXPathContextFactory.newInstance(); } return contextFactory; } /** * This constructor should remain protected - it is to be overridden by * subclasses, but never explicitly invoked by clients. * @param parentContext parent context * @param contextBean Object */ protected JXPathContext(JXPathContext parentContext, Object contextBean) { this.parentContext = parentContext; this.contextBean = contextBean; } /** * Returns the parent context of this context or null. * @return JXPathContext */ public JXPathContext getParentContext() { return parentContext; } /** * Returns the JavaBean associated with this context. * @return Object */ public Object getContextBean() { return contextBean; } /** * Returns a Pointer for the context bean. * @return Pointer */ public abstract Pointer getContextPointer(); /** * Returns a JXPathContext that is relative to the current JXPathContext. * The supplied pointer becomes the context pointer of the new context. * The relative context inherits variables, extension functions, locale etc * from the parent context. * @param pointer Pointer * @return JXPathContext */ public abstract JXPathContext getRelativeContext(Pointer pointer); /** * Installs a custom implementation of the Variables interface. * @param vars Variables */ public void setVariables(Variables vars) { this.vars = vars; } /** * Returns the variable pool associated with the context. If no such * pool was specified with the {@link #setVariables} method, * returns the default implementation of Variables, * {@link BasicVariables BasicVariables}. * @return Variables */ public Variables getVariables() { if (vars == null) { vars = new BasicVariables(); } return vars; } /** * Install a library of extension functions. * @param functions Functions * @see FunctionLibrary */ public void setFunctions(Functions functions) { this.functions = functions; } /** * Returns the set of functions installed on the context. * @return Functions */ public Functions getFunctions() { if (functions != null) { return functions; } if (parentContext == null) { return GENERIC_FUNCTIONS; } return null; } /** * Install an abstract factory that should be used by the * createPath() and createPathAndSetValue() * methods. * @param factory AbstractFactory */ public void setFactory(AbstractFactory factory) { this.factory = factory; } /** * Returns the AbstractFactory installed on this context. * If none has been installed and this context has a parent context, * returns the parent's factory. Otherwise returns null. * @return AbstractFactory */ public AbstractFactory getFactory() { if (factory == null && parentContext != null) { return parentContext.getFactory(); } return factory; } /** * Set the locale for this context. The value of the "lang" * attribute as well as the the lang() function will be * affected by the locale. By default, JXPath uses * Locale.getDefault() * @param locale Locale */ public synchronized void setLocale(Locale locale) { this.locale = locale; } /** * Returns the locale set with setLocale. If none was set and * the context has a parent, returns the parent's locale. * Otherwise, returns Locale.getDefault(). * @return Locale */ public synchronized Locale getLocale() { if (locale == null) { if (parentContext != null) { return parentContext.getLocale(); } locale = Locale.getDefault(); } return locale; } /** * Sets {@link DecimalFormatSymbols} for a given name. The DecimalFormatSymbols * can be referenced as the third, optional argument in the invocation of * format-number (number,format,decimal-format-name) function. * By default, JXPath uses the symbols for the current locale. * * @param name the format name or null for default format. * @param symbols DecimalFormatSymbols */ public synchronized void setDecimalFormatSymbols(String name, DecimalFormatSymbols symbols) { if (decimalFormats == null) { decimalFormats = new HashMap(); } decimalFormats.put(name, symbols); } /** * Get the named DecimalFormatSymbols. * @param name key * @return DecimalFormatSymbols * @see #setDecimalFormatSymbols(String, DecimalFormatSymbols) */ public synchronized DecimalFormatSymbols getDecimalFormatSymbols(String name) { if (decimalFormats == null) { return parentContext == null ? null : parentContext.getDecimalFormatSymbols(name); } return (DecimalFormatSymbols) decimalFormats.get(name); } /** * If the context is in the lenient mode, then getValue() returns null * for inexistent paths. Otherwise, a path that does not map to * an existing property will throw an exception. Note that if the * property exists, but its value is null, the exception is not * thrown. *

* By default, lenient = false * @param lenient flag */ public synchronized void setLenient(boolean lenient) { this.lenient = lenient; lenientSet = true; } /** * Learn whether this JXPathContext is lenient. * @return boolean * @see #setLenient(boolean) */ public synchronized boolean isLenient() { if (!lenientSet && parentContext != null) { return parentContext.isLenient(); } return lenient; } /** * Compiles the supplied XPath and returns an internal representation * of the path that can then be evaluated. Use CompiledExpressions * when you need to evaluate the same expression multiple times * and there is a convenient place to cache CompiledExpression * between invocations. * @param xpath to compile * @return CompiledExpression */ public static CompiledExpression compile(String xpath) { if (compilationContext == null) { compilationContext = JXPathContext.newContext(null); } return compilationContext.compilePath(xpath); } /** * Overridden by each concrete implementation of JXPathContext * to perform compilation. Is called by compile(). * @param xpath to compile * @return CompiledExpression */ protected abstract CompiledExpression compilePath(String xpath); /** * Finds the first object that matches the specified XPath. It is equivalent * to getPointer(xpath).getNode(). Note that this method * produces the same result as getValue() on object models * like JavaBeans, but a different result for DOM/JDOM etc., because it * returns the Node itself, rather than its textual contents. * * @param xpath the xpath to be evaluated * @return the found object */ public Object selectSingleNode(String xpath) { Pointer pointer = getPointer(xpath); return pointer == null ? null : pointer.getNode(); } /** * Finds all nodes that match the specified XPath. * * @param xpath the xpath to be evaluated * @return a list of found objects */ public List selectNodes(String xpath) { ArrayList list = new ArrayList(); Iterator iterator = iteratePointers(xpath); while (iterator.hasNext()) { Pointer pointer = (Pointer) iterator.next(); list.add(pointer.getNode()); } return list; } /** * Evaluates the xpath and returns the resulting object. Primitive * types are wrapped into objects. * @param xpath to evaluate * @return Object found */ public abstract Object getValue(String xpath); /** * Evaluates the xpath, converts the result to the specified class and * returns the resulting object. * @param xpath to evaluate * @param requiredType required type * @return Object found */ public abstract Object getValue(String xpath, Class requiredType); /** * Modifies the value of the property described by the supplied xpath. * Will throw an exception if one of the following conditions occurs: *

    *
  • The xpath does not in fact describe an existing property *
  • The property is not writable (no public, non-static set method) *
* @param xpath indicating position * @param value to set */ public abstract void setValue(String xpath, Object value); /** * Creates missing elements of the path by invoking an {@link AbstractFactory}, * which should first be installed on the context by calling {@link #setFactory}. *

* Will throw an exception if the AbstractFactory fails to create * an instance for a path element. * @param xpath indicating destination to create * @return pointer to new location */ public abstract Pointer createPath(String xpath); /** * The same as setValue, except it creates intermediate elements of * the path by invoking an {@link AbstractFactory}, which should first be * installed on the context by calling {@link #setFactory}. *

* Will throw an exception if one of the following conditions occurs: *

    *
  • Elements of the xpath aleady exist, but the path does not in * fact describe an existing property *
  • The AbstractFactory fails to create an instance for an intermediate * element. *
  • The property is not writable (no public, non-static set method) *
* @param xpath indicating position to create * @param value to set * @return pointer to new location */ public abstract Pointer createPathAndSetValue(String xpath, Object value); /** * Removes the element of the object graph described by the xpath. * @param xpath indicating position to remove */ public abstract void removePath(String xpath); /** * Removes all elements of the object graph described by the xpath. * @param xpath indicating positions to remove */ public abstract void removeAll(String xpath); /** * Traverses the xpath and returns an Iterator of all results found * for the path. If the xpath matches no properties * in the graph, the Iterator will be empty, but not null. * @param xpath to iterate * @return Iterator */ public abstract Iterator iterate(String xpath); /** * Traverses the xpath and returns a Pointer. * A Pointer provides easy access to a property. * If the xpath matches no properties * in the graph, the pointer will be null. * @param xpath desired * @return Pointer */ public abstract Pointer getPointer(String xpath); /** * Traverses the xpath and returns an Iterator of Pointers. * A Pointer provides easy access to a property. * If the xpath matches no properties * in the graph, the Iterator be empty, but not null. * @param xpath to iterate * @return Iterator */ public abstract Iterator iteratePointers(String xpath); /** * Install an identity manager that will be used by the context * to look up a node by its ID. * @param idManager IdentityManager to set */ public void setIdentityManager(IdentityManager idManager) { this.idManager = idManager; } /** * Returns this context's identity manager. If none has been installed, * returns the identity manager of the parent context. * @return IdentityManager */ public IdentityManager getIdentityManager() { if (idManager == null && parentContext != null) { return parentContext.getIdentityManager(); } return idManager; } /** * Locates a Node by its ID. * * @param id is the ID of the sought node. * @return Pointer */ public Pointer getPointerByID(String id) { IdentityManager manager = getIdentityManager(); if (manager != null) { return manager.getPointerByID(this, id); } throw new JXPathException( "Cannot find an element by ID - " + "no IdentityManager has been specified"); } /** * Install a key manager that will be used by the context * to look up a node by a key value. * @param keyManager KeyManager */ public void setKeyManager(KeyManager keyManager) { this.keyManager = keyManager; } /** * Returns this context's key manager. If none has been installed, * returns the key manager of the parent context. * @return KeyManager */ public KeyManager getKeyManager() { if (keyManager == null && parentContext != null) { return parentContext.getKeyManager(); } return keyManager; } /** * Locates a Node by a key value. * @param key string * @param value string * @return Pointer found */ public Pointer getPointerByKey(String key, String value) { KeyManager manager = getKeyManager(); if (manager != null) { return manager.getPointerByKey(this, key, value); } throw new JXPathException( "Cannot find an element by key - " + "no KeyManager has been specified"); } /** * Locates a NodeSet by key/value. * @param key string * @param value object * @return NodeSet found */ public NodeSet getNodeSetByKey(String key, Object value) { KeyManager manager = getKeyManager(); if (manager != null) { return KeyManagerUtils.getExtendedKeyManager(manager) .getNodeSetByKey(this, key, value); } throw new JXPathException("Cannot find an element by key - " + "no KeyManager has been specified"); } /** * Registers a namespace prefix. * * @param prefix A namespace prefix * @param namespaceURI A URI for that prefix */ public void registerNamespace(String prefix, String namespaceURI) { throw new UnsupportedOperationException( "Namespace registration is not implemented by " + getClass()); } /** * Given a prefix, returns a registered namespace URI. If the requested * prefix was not defined explicitly using the registerNamespace method, * JXPathContext will then check the context node to see if the prefix is * defined there. See * {@link #setNamespaceContextPointer(Pointer) setNamespaceContextPointer}. * * @param prefix The namespace prefix to look up * @return namespace URI or null if the prefix is undefined. */ public String getNamespaceURI(String prefix) { throw new UnsupportedOperationException( "Namespace registration is not implemented by " + getClass()); } /** * Get the prefix associated with the specifed namespace URI. * @param namespaceURI the ns URI to check. * @return String prefix * @since JXPath 1.3 */ public String getPrefix(String namespaceURI) { throw new UnsupportedOperationException( "Namespace registration is not implemented by " + getClass()); } /** * Namespace prefixes can be defined implicitly by specifying a pointer to a * context where the namespaces are defined. By default, * NamespaceContextPointer is the same as the Context Pointer, see * {@link #getContextPointer() getContextPointer()} * * @param namespaceContextPointer The pointer to the context where prefixes used in * XPath expressions should be resolved. */ public void setNamespaceContextPointer(Pointer namespaceContextPointer) { throw new UnsupportedOperationException( "Namespace registration is not implemented by " + getClass()); } /** * Returns the namespace context pointer set with * {@link #setNamespaceContextPointer(Pointer) setNamespaceContextPointer()} * or, if none has been specified, the context pointer otherwise. * * @return The namespace context pointer. */ public Pointer getNamespaceContextPointer() { throw new UnsupportedOperationException( "Namespace registration is not implemented by " + getClass()); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/JXPathContextFactory.java100644 0 0 22530 11044113545 25647 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Properties; /** * Defines a factory API that enables applications to obtain a * {@link JXPathContext} instance. To acquire a JXPathContext, first call the * static {@link #newInstance} method of JXPathContextFactory. * This method returns a concrete JXPathContextFactory. * Then call {@link #newContext} on that instance. You will rarely * need to perform these steps explicitly: usually you can call one of the * JXPathContex.newContext methods, which will perform these steps * for you. * * @see JXPathContext#newContext(Object) * @see JXPathContext#newContext(JXPathContext,Object) * * @author Dmitri Plotnikov * @version $Revision: 670727 $ $Date: 2008-06-23 15:10:38 -0500 (Mon, 23 Jun 2008) $ */ public abstract class JXPathContextFactory { /** The default property */ public static final String FACTORY_NAME_PROPERTY = "org.apache.commons.jxpath.JXPathContextFactory"; /** The default factory class */ private static final String DEFAULT_FACTORY_CLASS = "org.apache.commons.jxpath.ri.JXPathContextFactoryReferenceImpl"; /** Avoid reading all the files when the findFactory method is called the second time ( cache the result of finding the default impl ) */ private static String factoryImplName = null; /** * Create a new JXPathContextFactory. */ protected JXPathContextFactory () { } /** * Obtain a new instance of a JXPathContextFactory. * This static method creates a new factory instance. * This method uses the following ordered lookup procedure to determine * the JXPathContextFactory implementation class to load: *
    *
  • * Use the org.apache.commons.jxpath.JXPathContextFactory * system property. *
  • *
  • * Alternatively, use the JAVA_HOME (the parent directory where jdk is * installed)/lib/jxpath.properties for a property file that contains the * name of the implementation class keyed on * org.apache.commons.jxpath.JXPathContextFactory. *
  • *
  • * Use the Services API (as detailed in the JAR specification), if * available, to determine the classname. The Services API will look * for a classname in the file * META- INF/services/org.apache.commons.jxpath. * JXPathContextFactory in jars available to the runtime. *
  • *
  • * Platform default JXPathContextFactory instance. *
  • *
* * Once an application has obtained a reference to a * JXPathContextFactory it can use the factory to * obtain JXPathContext instances. * * @return JXPathContextFactory * @exception JXPathContextFactoryConfigurationError if the implementation * is not available or cannot be instantiated. */ public static JXPathContextFactory newInstance() { if (factoryImplName == null) { factoryImplName = findFactory(FACTORY_NAME_PROPERTY, DEFAULT_FACTORY_CLASS); } JXPathContextFactory factoryImpl; try { Class clazz = Class.forName(factoryImplName); factoryImpl = (JXPathContextFactory) clazz.newInstance(); } catch (ClassNotFoundException cnfe) { throw new JXPathContextFactoryConfigurationError(cnfe); } catch (IllegalAccessException iae) { throw new JXPathContextFactoryConfigurationError(iae); } catch (InstantiationException ie) { throw new JXPathContextFactoryConfigurationError(ie); } return factoryImpl; } /** * Creates a new instance of a JXPathContext using the * currently configured parameters. * @param parentContext parent context * @param contextBean Object bean * @return JXPathContext * @exception JXPathContextFactoryConfigurationError if a JXPathContext * cannot be created which satisfies the configuration requested */ public abstract JXPathContext newContext( JXPathContext parentContext, Object contextBean); // -------------------- private methods -------------------- // This code is duplicated in all factories. // Keep it in sync or move it to a common place // Because it's small probably it's easier to keep it here /** Temp debug code - this will be removed after we test everything */ private static boolean debug = false; static { try { debug = System.getProperty("jxpath.debug") != null; } catch (SecurityException se) { //NOPMD // This is ok } } /** * Private implementation method - will find the implementation * class in the specified order. * @param property Property name * @param defaultFactory Default implementation, if nothing else is found * * @return class name of the JXPathContextFactory */ private static String findFactory(String property, String defaultFactory) { // Use the factory ID system property first try { String systemProp = System.getProperty(property); if (systemProp != null) { if (debug) { System.err.println( "JXPath: found system property" + systemProp); } return systemProp; } } catch (SecurityException se) { //NOPMD // Ignore } // try to read from $java.home/lib/xml.properties try { String javah = System.getProperty("java.home"); String configFile = javah + File.separator + "lib" + File.separator + "jxpath.properties"; File f = new File(configFile); if (f.exists()) { Properties props = new Properties(); FileInputStream fis = new FileInputStream(f); try { props.load(fis); } finally { if (fis != null) { try { fis.close(); } catch (IOException e) { //NOPMD //swallow } } } String factory = props.getProperty(property); if (factory != null) { if (debug) { System.err.println( "JXPath: found java.home property " + factory); } return factory; } } } catch (IOException ex) { if (debug) { ex.printStackTrace(); } } String serviceId = "META-INF/services/" + property; // try to find services in CLASSPATH try { ClassLoader cl = JXPathContextFactory.class.getClassLoader(); InputStream is = null; if (cl == null) { is = ClassLoader.getSystemResourceAsStream(serviceId); } else { is = cl.getResourceAsStream(serviceId); } if (is != null) { if (debug) { System.err.println("JXPath: found " + serviceId); } BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String factory = null; try { factory = rd.readLine(); } finally { try { rd.close(); } catch (IOException e) { //NOPMD //swallow } } if (factory != null && !"".equals(factory)) { if (debug) { System.err.println( "JXPath: loaded from services: " + factory); } return factory; } } } catch (Exception ex) { if (debug) { ex.printStackTrace(); } } return defaultFactory; } } ././@LongLink100644 0 0 146 11044114245 10250 Lustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/JXPathContextFactoryConfigurationError.javacommons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/JXPathContextFactoryConfigurationError.jav100644 0 0 6622 11044113545 31234 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; /** * Thrown when a problem with configuration with the {@link JXPathContextFactory JXPathContextFactories} * exists. This error will typically be thrown when the class of a * factory specified in the system properties cannot be found * or instantiated. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class JXPathContextFactoryConfigurationError extends Error { /** @serial */ private Exception exception; /** * Create a new JXPathContextFactoryConfigurationError with no * detail mesage. */ public JXPathContextFactoryConfigurationError() { super(); this.exception = null; } /** * Create a new JXPathContextFactoryConfigurationError with * the String specified as an error message. * * @param msg The error message for the exception. */ public JXPathContextFactoryConfigurationError(String msg) { super(msg); this.exception = null; } /** * Create a new JXPathContextFactoryConfigurationError with a * given Exception base cause of the error. * * @param e The exception to be encapsulated in a * JXPathContextFactoryConfigurationError. */ public JXPathContextFactoryConfigurationError(Exception e) { super(e.toString()); this.exception = e; } /** * Create a new JXPathContextFactoryConfigurationError with the * given Exception base cause and detail message. * * @param e The exception to be encapsulated in a * JXPathContextFactoryConfigurationError * @param msg The detail message. */ public JXPathContextFactoryConfigurationError(Exception e, String msg) { super(msg); this.exception = e; } /** * Return the message (if any) for this error . If there is no * message for the exception and there is an encapsulated * exception then the message of that exception will be returned. * * @return The error message. */ public String getMessage () { String message = super.getMessage(); if (message == null && exception != null) { return exception.getMessage(); } return message; } /** * Return the actual exception (if any) that caused this exception to * be raised. * * @return The encapsulated exception, or null if there is none. */ public Exception getException () { return exception; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/JXPathException.java100644 0 0 6737 11044113545 24624 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; /** * Thrown in various situations by JXPath; may contain a nested exception. * * @author Dmitri Plotnikov * @version $Revision: 618149 $ $Date: 2008-02-03 20:04:13 -0600 (Sun, 03 Feb 2008) $ */ public class JXPathException extends RuntimeException { private static final long serialVersionUID = 4306409701468017766L; /** @serial */ private Throwable exception; /** * Create a new JXPathException with no * detail mesage. */ public JXPathException() { super(); this.exception = null; } /** * Create a new JXPathException with * the String specified as an error message. * * @param msg The error message for the exception. */ public JXPathException(String msg) { super(msg); this.exception = null; } /** * Create a new JXPathException with a * given Throwable base cause of the error. * * @param e The exception to be encapsulated in a * JXPathException. */ public JXPathException(Throwable e) { super(e.toString()); this.exception = e; } /** * Create a new JXPathException with the * given Exception base cause and detail message. * * @param msg The detail message. * @param e The exception to be encapsulated in a JXPathException */ public JXPathException(String msg, Throwable e) { super(msg); this.exception = e; } /** * Return the message (if any) for this error . If there is no * message for the exception and there is an encapsulated * exception then the message of that exception will be returned. * * @return The error message. */ public String getMessage() { String message = super.getMessage(); if (exception == null) { return message; } StringBuffer buf = new StringBuffer(); if (message != null) { buf.append(message).append("; "); } String eMsg = exception.getMessage(); buf.append(eMsg == null ? exception.getClass().getName() : eMsg); return buf.toString(); } /** * Return the actual exception (if any) that caused this exception to * be raised. * * @return The encapsulated exception, or null if there is none. */ public Throwable getException() { return exception; } /** * Same as {@link #getException() getException()} * @return The encapsulated exception, or null if there is none. */ public Throwable getCause() { return exception; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/JXPathFunctionNotFoundException.java100644 0 0 2540 11044113545 27773 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; /** * Thrown when JXPath encounters an unknown extension function. * * @author Dmitri Plotnikov * @version $Revision: 658784 $ $Date: 2008-05-21 12:44:55 -0500 (Wed, 21 May 2008) $ */ public class JXPathFunctionNotFoundException extends JXPathException { private static final long serialVersionUID = -8875537628056117241L; /** * Create a new JXPathFunctionNotFoundException. * @param message exception message */ public JXPathFunctionNotFoundException(String message) { super(message); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/JXPathIntrospector.java100644 0 0 17116 11044113545 25372 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; import java.util.Date; import java.util.Map; import java.util.HashMap; /** * JXPathIntrospector maintains a registry of {@link JXPathBeanInfo * JXPathBeanInfo} objects for Java classes. * * @author Dmitri Plotnikov * @version $Revision: 670727 $ $Date: 2008-06-23 15:10:38 -0500 (Mon, 23 Jun 2008) $ */ public class JXPathIntrospector { private static HashMap byClass = new HashMap(); private static HashMap byInterface = new HashMap(); static { registerAtomicClass(Class.class); registerAtomicClass(Boolean.TYPE); registerAtomicClass(Boolean.class); registerAtomicClass(Byte.TYPE); registerAtomicClass(Byte.class); registerAtomicClass(Character.TYPE); registerAtomicClass(Character.class); registerAtomicClass(Short.TYPE); registerAtomicClass(Short.class); registerAtomicClass(Integer.TYPE); registerAtomicClass(Integer.class); registerAtomicClass(Long.TYPE); registerAtomicClass(Long.class); registerAtomicClass(Float.TYPE); registerAtomicClass(Float.class); registerAtomicClass(Double.TYPE); registerAtomicClass(Double.class); registerAtomicClass(String.class); registerAtomicClass(Date.class); registerAtomicClass(java.sql.Date.class); registerAtomicClass(java.sql.Time.class); registerAtomicClass(java.sql.Timestamp.class); registerDynamicClass(Map.class, MapDynamicPropertyHandler.class); } /** * Automatically creates and registers a JXPathBeanInfo object * for the specified class. That object returns true to isAtomic(). * @param beanClass to register */ public static void registerAtomicClass(Class beanClass) { byClass.put(beanClass, new JXPathBasicBeanInfo(beanClass, true)); } /** * Automatically creates and registers a {@link JXPathBeanInfo} object * for the specified class. That object returns true to * {@link JXPathBeanInfo#isDynamic()}. * * @param beanClass to register * @param dynamicPropertyHandlerClass to handle beanClass */ public static void registerDynamicClass(Class beanClass, Class dynamicPropertyHandlerClass) { JXPathBasicBeanInfo bi = new JXPathBasicBeanInfo(beanClass, dynamicPropertyHandlerClass); if (beanClass.isInterface()) { byInterface.put(beanClass, bi); } else { byClass.put(beanClass, bi); } } /** * Creates and registers a JXPathBeanInfo object for the supplied class. If * the class has already been registered, returns the registered * JXPathBeanInfo object. *

* The process of creation of JXPathBeanInfo is as follows: *

    *
  • If class named <beanClass>XBeanInfo exists, * an instance of that class is allocated. *
  • Otherwise, an instance of {@link JXPathBasicBeanInfo * JXPathBasicBeanInfo} is allocated. *
* @param beanClass whose info to get * @return JXPathBeanInfo */ public static JXPathBeanInfo getBeanInfo(Class beanClass) { JXPathBeanInfo beanInfo = (JXPathBeanInfo) byClass.get(beanClass); if (beanInfo == null) { beanInfo = findDynamicBeanInfo(beanClass); if (beanInfo == null) { beanInfo = findInformant(beanClass); if (beanInfo == null) { beanInfo = new JXPathBasicBeanInfo(beanClass); } } byClass.put(beanClass, beanInfo); } return beanInfo; } /** * Find a dynamic bean info if available for any superclasses or * interfaces. * @param beanClass to search for * @return JXPathBeanInfo */ private static JXPathBeanInfo findDynamicBeanInfo(Class beanClass) { JXPathBeanInfo beanInfo = null; if (beanClass.isInterface()) { beanInfo = (JXPathBeanInfo) byInterface.get(beanClass); if (beanInfo != null && beanInfo.isDynamic()) { return beanInfo; } } Class[] interfaces = beanClass.getInterfaces(); if (interfaces != null) { for (int i = 0; i < interfaces.length; i++) { beanInfo = findDynamicBeanInfo(interfaces[i]); if (beanInfo != null && beanInfo.isDynamic()) { return beanInfo; } } } Class sup = beanClass.getSuperclass(); if (sup != null) { beanInfo = (JXPathBeanInfo) byClass.get(sup); if (beanInfo != null && beanInfo.isDynamic()) { return beanInfo; } return findDynamicBeanInfo(sup); } return null; } /** * find a JXPathBeanInfo instance for the specified class. * Similar to javax.beans property handler discovery; search for a * class with "XBeanInfo" appended to beanClass.name, then check * whether beanClass implements JXPathBeanInfo for itself. * Invokes the default constructor for any class it finds. * @param beanClass for which to look for an info provider * @return JXPathBeanInfo instance or null if none found */ private static synchronized JXPathBeanInfo findInformant(Class beanClass) { String name = beanClass.getName() + "XBeanInfo"; try { return (JXPathBeanInfo) instantiate(beanClass, name); } catch (Exception ex) { //NOPMD // Just drop through } // Now try checking if the bean is its own JXPathBeanInfo. try { if (JXPathBeanInfo.class.isAssignableFrom(beanClass)) { return (JXPathBeanInfo) beanClass.newInstance(); } } catch (Exception ex) { //NOPMD // Just drop through } return null; } /** * Try to create an instance of a named class. * First try the classloader of "sibling", then try the system * classloader. * @param sibling Class * @param className to instantiate * @return new Object * @throws Exception if instantiation fails */ private static Object instantiate(Class sibling, String className) throws Exception { // First check with sibling's classloader (if any). ClassLoader cl = sibling.getClassLoader(); if (cl != null) { try { Class cls = cl.loadClass(className); return cls.newInstance(); } catch (Exception ex) { //NOPMD // Just drop through and try the system classloader. } } // Now try the bootstrap classloader. Class cls = Class.forName(className); return cls.newInstance(); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/JXPathInvalidAccessException.java100644 0 0 3303 11044113545 27237 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; /** * Similary to {@link java.lang.reflect.InvocationTargetException} in that * it is thrown when JXPath cannot access properties, collection etc on the * target object model. * * @author Dmitri Plotnikov * @version $Revision: 658784 $ $Date: 2008-05-21 12:44:55 -0500 (Wed, 21 May 2008) $ */ public class JXPathInvalidAccessException extends JXPathException { private static final long serialVersionUID = -8875537628056117241L; /** * Create a new JXPathInvalidAccessException. * @param message exception message */ public JXPathInvalidAccessException(String message) { super(message); } /** * Create a new JXPathInvalidAccessException. * @param message exception message * @param ex precipitating exception */ public JXPathInvalidAccessException(String message, Throwable ex) { super(message, ex); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/JXPathInvalidSyntaxException.java100644 0 0 2510 11044113545 27323 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; /** * Thrown when JXPath cannot parse a supplied XPath. * * @author Dmitri Plotnikov * @version $Revision: 658784 $ $Date: 2008-05-21 12:44:55 -0500 (Wed, 21 May 2008) $ */ public class JXPathInvalidSyntaxException extends JXPathException { private static final long serialVersionUID = 504555366032561816L; /** * Create a new JXPathInvalidSyntaxException. * @param message relevant message */ public JXPathInvalidSyntaxException(String message) { super(message); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/JXPathNotFoundException.java100644 0 0 2473 11044113545 26272 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; /** * Thrown when JXPath cannot find a requested path. * * @author Dmitri Plotnikov * @version $Revision: 658784 $ $Date: 2008-05-21 12:44:55 -0500 (Wed, 21 May 2008) $ */ public class JXPathNotFoundException extends JXPathException { private static final long serialVersionUID = -8875537628056117241L; /** * Create a new JXPathNotFoundException. * @param message exception detail */ public JXPathNotFoundException(String message) { super(message); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/JXPathTypeConversionException.java100644 0 0 3127 11044113545 27522 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; /** * Thrown when JXPath cannot convert supplied value to the required type. * * @author Dmitri Plotnikov * @version $Revision: 658784 $ $Date: 2008-05-21 12:44:55 -0500 (Wed, 21 May 2008) $ */ public class JXPathTypeConversionException extends JXPathException { private static final long serialVersionUID = -4403564377958943239L; /** * Create a new JXPathTypeConversionException. * @param message exception text */ public JXPathTypeConversionException(String message) { super(message); } /** * Create a new JXPathTypeConversionException. * @param message exception text * @param ex underlying cause */ public JXPathTypeConversionException(String message, Exception ex) { super(message, ex); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/KeyManager.java100644 0 0 2537 11044113545 23624 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; /** * A delegate of {@link JXPathContext} that implements the XPath "key()" * function. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public interface KeyManager { /** * Find a node by key/value. * * @param context to search * @param keyName String * @param keyValue String * @return Pointer */ Pointer getPointerByKey( JXPathContext context, String keyName, String keyValue); } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/MapDynamicPropertyHandler.java100644 0 0 3401 11044113545 26655 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; import java.util.Iterator; import java.util.Map; import java.util.Set; /** * Implements the DynamicPropertyHandler interface for {@link java.util.Map}. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class MapDynamicPropertyHandler implements DynamicPropertyHandler { public String[] getPropertyNames(Object object) { Map map = (Map) object; Set set = map.keySet(); String[] names = new String[set.size()]; Iterator it = set.iterator(); for (int i = 0; i < names.length; i++) { names[i] = String.valueOf(it.next()); } return names; } public Object getProperty(Object object, String propertyName) { return ((Map) object).get(propertyName); } public void setProperty(Object object, String propertyName, Object value) { ((Map) object).put(propertyName, value); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/NodeSet.java100644 0 0 3136 11044113545 23136 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; import java.util.List; /** * NodeSet interface can be used as the type of an argument of an extension * function. Alternatively, the function can declare the argument as * a Collection (or List or Set), in which case it will be given a collection * of values matching the path. * * @author Dmitri Plotnikov * @version $Id: NodeSet.java 618149 2008-02-04 02:04:13Z mbenson $ */ public interface NodeSet { /** * Returns a list of nodes. * @return List */ List getNodes(); /** * Returns a list of pointers for all nodes in the set. * @return List */ List getPointers(); /** * Returns a list of values of all contained pointers. * @return List */ List getValues(); } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/package.html100644 0 0 2065 11044113545 23213 0ustar 0 0 Public, abstract part of JXPath: interfaces and configuration. If you are a user of JXPath and don't plan to modify its implementation, this is the only package you'll need to use. Start with the {@link org.apache.commons.jxpath.JXPathContext} class. commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/PackageFunctions.java100644 0 0 17421 11044113545 25043 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.Set; import org.apache.commons.jxpath.functions.ConstructorFunction; import org.apache.commons.jxpath.functions.MethodFunction; import org.apache.commons.jxpath.util.MethodLookupUtils; import org.apache.commons.jxpath.util.TypeUtils; /** * Extension functions provided by Java classes. The class prefix specified * in the constructor is used when a constructor or a static method is called. * Usually, a class prefix is a package name (hence the name of this class). * * Let's say, we declared a PackageFunction like this: *
 *     new PackageFunctions("java.util.", "util")
 * 
* * We can now use XPaths like: *
*
"util:Date.new()"
*
Equivalent to new java.util.Date()
*
"util:Collections.singleton('foo')"
*
Equivalent to java.util.Collections.singleton("foo")
*
"util:substring('foo', 1, 2)"
*
Equivalent to "foo".substring(1, 2). Note that in * this case, the class prefix is not used. JXPath does not check that * the first parameter of the function (the method target) is in fact * a member of the package described by this PackageFunctions object.
*
* *

* If the first argument of a method or constructor is {@link ExpressionContext}, * the expression context in which the function is evaluated is passed to * the method. *

*

* There is one PackageFunctions object registered by default with each * JXPathContext. It does not have a namespace and uses no class prefix. * The existence of this object allows us to use XPaths like: * "java.util.Date.new()" and "length('foo')" * without the explicit registration of any extension functions. *

* * @author Dmitri Plotnikov * @version $Revision: 670727 $ $Date: 2008-06-23 15:10:38 -0500 (Mon, 23 Jun 2008) $ */ public class PackageFunctions implements Functions { private String classPrefix; private String namespace; private static final Object[] EMPTY_ARRAY = new Object[0]; /** * Create a new PackageFunctions. * @param classPrefix class prefix * @param namespace namespace String */ public PackageFunctions(String classPrefix, String namespace) { this.classPrefix = classPrefix; this.namespace = namespace; } /** * Returns the namespace specified in the constructor * @return (singleton) namespace Set */ public Set getUsedNamespaces() { return Collections.singleton(namespace); } /** * Returns a {@link Function}, if found, for the specified namespace, * name and parameter types. *

* @param namespace - if it is not the same as specified in the * construction, this method returns null * @param name - name of the method, which can one these forms: *

    *
  • methodname, if invoking a method on an object passed as the * first parameter
  • *
  • Classname.new, if looking for a constructor
  • *
  • subpackage.subpackage.Classname.new, if looking for a * constructor in a subpackage
  • *
  • Classname.methodname, if looking for a static method
  • *
  • subpackage.subpackage.Classname.methodname, if looking for a * static method of a class in a subpackage
  • *
* @param parameters Object[] of parameters * @return a MethodFunction, a ConstructorFunction or null if no function * is found */ public Function getFunction( String namespace, String name, Object[] parameters) { if ((namespace == null && this.namespace != null) //NOPMD || (namespace != null && !namespace.equals(this.namespace))) { return null; } if (parameters == null) { parameters = EMPTY_ARRAY; } if (parameters.length >= 1) { Object target = TypeUtils.convert(parameters[0], Object.class); if (target != null) { Method method = MethodLookupUtils.lookupMethod( target.getClass(), name, parameters); if (method != null) { return new MethodFunction(method); } if (target instanceof NodeSet) { target = ((NodeSet) target).getPointers(); } method = MethodLookupUtils.lookupMethod( target.getClass(), name, parameters); if (method != null) { return new MethodFunction(method); } if (target instanceof Collection) { Iterator iter = ((Collection) target).iterator(); if (iter.hasNext()) { target = iter.next(); if (target instanceof Pointer) { target = ((Pointer) target).getValue(); } } else { target = null; } } } if (target != null) { Method method = MethodLookupUtils.lookupMethod( target.getClass(), name, parameters); if (method != null) { return new MethodFunction(method); } } } String fullName = classPrefix + name; int inx = fullName.lastIndexOf('.'); if (inx == -1) { return null; } String className = fullName.substring(0, inx); String methodName = fullName.substring(inx + 1); Class functionClass; try { functionClass = Class.forName(className); } catch (ClassNotFoundException ex) { throw new JXPathException( "Cannot invoke extension function " + (namespace != null ? namespace + ":" + name : name), ex); } if (methodName.equals("new")) { Constructor constructor = MethodLookupUtils.lookupConstructor(functionClass, parameters); if (constructor != null) { return new ConstructorFunction(constructor); } } else { Method method = MethodLookupUtils.lookupStaticMethod( functionClass, methodName, parameters); if (method != null) { return new MethodFunction(method); } } return null; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/Pointer.java100644 0 0 7333 11044113545 23220 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; import java.io.Serializable; /** * Pointers represent locations of objects and their properties * in Java object graphs. JXPathContext has methods * ({@link JXPathContext#getPointer(java.lang.String) getPointer()} * and ({@link JXPathContext#iteratePointers(java.lang.String) * iteratePointers()}, which, given an XPath, produce Pointers for the objects * or properties described the the path. For example, ctx.getPointer * ("foo/bar") will produce a Pointer that can get and set the property * "bar" of the object which is the value of the property "foo" of the root * object. The value of ctx.getPointer("aMap/aKey[3]") will be a * pointer to the 3'rd element of the array, which is the value for the key * "aKey" of the map, which is the value of the property "aMap" of the root * object. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public interface Pointer extends Cloneable, Comparable, Serializable { /** * Returns the value of the object, property or collection element * this pointer represents. May convert the value to one of the * canonical InfoSet types: String, Number, Boolean, Set. * * For example, in the case of an XML element, getValue() will * return the text contained by the element rather than * the element itself. * @return Object value */ Object getValue(); /** * Returns the raw value of the object, property or collection element * this pointer represents. Never converts the object to a * canonical type: returns it as is. * * For example, for an XML element, getNode() will * return the element itself rather than the text it contains. * @return Object node */ Object getNode(); /** * Modifies the value of the object, property or collection element * this pointer represents. * @param value value to set */ void setValue(Object value); /** * Returns the node this pointer is based on. * @return Object */ Object getRootNode(); /** * Returns a string that is a proper "canonical" XPath that corresponds to * this pointer. Consider this example: *

Pointer ptr = ctx.getPointer("//employees[firstName = 'John']") * *

The value of ptr.asPath() will look something like * "/departments[2]/employees[3]", so, basically, it represents * the concrete location(s) of the result of a search performed by JXPath. * If an object in the pointer's path is a Dynamic Property object (like a * Map), the asPath method generates an XPath that looks like this: " * /departments[@name = 'HR']/employees[3]". * @return String path */ String asPath(); /** * Pointers are cloneable. * @return cloned Object */ Object clone(); } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/axes/AncestorContext.java100644 0 0 6077 11044113530 26273 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.model.NodePointer; /** * EvalContext that walks the "ancestor::" and "ancestor-or-self::" axes. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class AncestorContext extends EvalContext { private NodeTest nodeTest; private boolean setStarted = false; private NodePointer currentNodePointer; private boolean includeSelf; /** * Create a new AncestorContext. * @param parentContext represents the previous step on the path * @param includeSelf differentiates between "ancestor::" and * "ancestor-or-self::" axes * @param nodeTest is the name of the element(s) we are looking for */ public AncestorContext( EvalContext parentContext, boolean includeSelf, NodeTest nodeTest) { super(parentContext); this.includeSelf = includeSelf; this.nodeTest = nodeTest; } public NodePointer getCurrentNodePointer() { return currentNodePointer; } public int getDocumentOrder() { return -1; } public void reset() { super.reset(); setStarted = false; } public boolean setPosition(int position) { if (position < getCurrentPosition()) { reset(); } while (getCurrentPosition() < position) { if (!nextNode()) { return false; } } return true; } public boolean nextNode() { if (!setStarted) { setStarted = true; currentNodePointer = parentContext.getCurrentNodePointer(); if (includeSelf && currentNodePointer.testNode(nodeTest)) { position++; return true; } } while (true) { currentNodePointer = currentNodePointer.getImmediateParentPointer(); if (currentNodePointer == null) { return false; } if (currentNodePointer.testNode(nodeTest)) { position++; return true; } } } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/axes/AttributeContext.java100644 0 0 6750 11044113530 26456 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import org.apache.commons.jxpath.ri.Compiler; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.compiler.NodeNameTest; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.compiler.NodeTypeTest; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; /** * EvalContext that walks the "attribute::" axis. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class AttributeContext extends EvalContext { private static final QName WILDCARD = new QName(null, "*"); private NodeTest nodeTest; private boolean setStarted = false; private NodeIterator iterator; private NodePointer currentNodePointer; /** * Create a new AttributeContext. * @param parentContext represents the previous step on the path * @param nodeTest is the name of the attribute we are looking for */ public AttributeContext(EvalContext parentContext, NodeTest nodeTest) { super(parentContext); this.nodeTest = nodeTest; } public NodePointer getCurrentNodePointer() { return currentNodePointer; } public void reset() { setStarted = false; iterator = null; super.reset(); } public boolean setPosition(int position) { if (position < getCurrentPosition()) { reset(); } while (getCurrentPosition() < position) { if (!nextNode()) { return false; } } return true; } public boolean nextNode() { super.setPosition(getCurrentPosition() + 1); if (!setStarted) { setStarted = true; QName name; if (nodeTest instanceof NodeNameTest) { name = ((NodeNameTest) nodeTest).getNodeName(); } else { if (nodeTest instanceof NodeTypeTest && ((NodeTypeTest) nodeTest).getNodeType() == Compiler.NODE_TYPE_NODE) { name = WILDCARD; } else { iterator = null; return false; } } iterator = parentContext.getCurrentNodePointer().attributeIterator( name); } if (iterator == null) { return false; } if (!iterator.setPosition(iterator.getPosition() + 1)) { return false; } currentNodePointer = iterator.getNodePointer(); return true; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/axes/ChildContext.java100644 0 0 10021 11044113530 25540 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; /** * EvalContext that can walk the "child::", "following-sibling::" and * "preceding-sibling::" axes. * * @author Dmitri Plotnikov * @version $Revision: 652903 $ $Date: 2008-05-02 15:46:32 -0500 (Fri, 02 May 2008) $ */ public class ChildContext extends EvalContext { private NodeTest nodeTest; private boolean startFromParentLocation; private boolean reverse; private NodeIterator iterator; /** * Create a new ChildContext. * @param parentContext parent EvalContext * @param nodeTest NodeTest * @param startFromParentLocation whether to start from parent location * @param reverse whether to iterate in reverse */ public ChildContext(EvalContext parentContext, NodeTest nodeTest, boolean startFromParentLocation, boolean reverse) { super(parentContext); this.nodeTest = nodeTest; this.startFromParentLocation = startFromParentLocation; this.reverse = reverse; } public NodePointer getCurrentNodePointer() { if (position == 0 && !setPosition(1)) { return null; } return iterator == null ? null : iterator.getNodePointer(); } /** * This method is called on the last context on the path when only * one value is needed. Note that this will return the whole property, * even if it is a collection. It will not extract the first element * of the collection. For example, "books" will return the collection * of books rather than the first book from that collection. * @return Pointer */ public Pointer getSingleNodePointer() { if (position == 0) { while (nextSet()) { prepare(); if (iterator == null) { return null; } // See if there is a property there, singular or collection NodePointer pointer = iterator.getNodePointer(); if (pointer != null) { return pointer; } } return null; } return getCurrentNodePointer(); } public boolean nextNode() { return setPosition(getCurrentPosition() + 1); } public void reset() { super.reset(); iterator = null; } public boolean setPosition(int position) { int oldPosition = getCurrentPosition(); super.setPosition(position); if (oldPosition == 0) { prepare(); } return iterator == null ? false : iterator.setPosition(position); } /** * Allocates a PropertyIterator. */ private void prepare() { NodePointer parent = parentContext.getCurrentNodePointer(); if (parent == null) { return; } NodePointer useParent = startFromParentLocation ? parent.getParent() : parent; iterator = useParent.childIterator(nodeTest, reverse, startFromParentLocation ? parent : null); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/axes/DescendantContext.java100644 0 0 12010 11044113530 26565 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import java.util.Stack; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.Compiler; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.compiler.NodeTypeTest; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; /** * An EvalContext that walks the "descendant::" and "descendant-or-self::" * axes. * * @author Dmitri Plotnikov * @version $Revision: 670727 $ $Date: 2008-06-23 15:10:38 -0500 (Mon, 23 Jun 2008) $ */ public class DescendantContext extends EvalContext { private NodeTest nodeTest; private boolean setStarted = false; private Stack stack = null; private NodePointer currentNodePointer = null; private boolean includeSelf; private static final NodeTest ELEMENT_NODE_TEST = new NodeTypeTest(Compiler.NODE_TYPE_NODE); /** * Create a new DescendantContext. * @param parentContext parent context * @param includeSelf whether to include this node * @param nodeTest test */ public DescendantContext(EvalContext parentContext, boolean includeSelf, NodeTest nodeTest) { super(parentContext); this.includeSelf = includeSelf; this.nodeTest = nodeTest; } public boolean isChildOrderingRequired() { return true; } public NodePointer getCurrentNodePointer() { if (position == 0 && !setPosition(1)) { return null; } return currentNodePointer; } public void reset() { super.reset(); setStarted = false; } public boolean setPosition(int position) { if (position < this.position) { reset(); } while (this.position < position) { if (!nextNode()) { return false; } } return true; } public boolean nextNode() { if (!setStarted) { setStarted = true; if (stack == null) { stack = new Stack(); } else { stack.clear(); } currentNodePointer = parentContext.getCurrentNodePointer(); if (currentNodePointer != null) { if (!currentNodePointer.isLeaf()) { stack.push( currentNodePointer.childIterator( ELEMENT_NODE_TEST, false, null)); } if (includeSelf && currentNodePointer.testNode(nodeTest)) { position++; return true; } } } while (!stack.isEmpty()) { NodeIterator it = (NodeIterator) stack.peek(); if (it.setPosition(it.getPosition() + 1)) { currentNodePointer = it.getNodePointer(); if (!isRecursive()) { if (!currentNodePointer.isLeaf()) { stack.push( currentNodePointer.childIterator( ELEMENT_NODE_TEST, false, null)); } if (currentNodePointer.testNode(nodeTest)) { position++; return true; } } } else { // We get here only if the name test failed // and the iterator ended stack.pop(); } } return false; } /** * Checks if we are reentering a bean we have already seen and if so * returns true to prevent infinite recursion. * @return boolean */ private boolean isRecursive() { Object node = currentNodePointer.getNode(); for (int i = stack.size() - 1; --i >= 0;) { NodeIterator it = (NodeIterator) stack.get(i); Pointer pointer = it.getNodePointer(); if (pointer != null && pointer.getNode() == node) { return true; } } return false; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/axes/InitialContext.java100644 0 0 5175 11044113530 26104 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.model.NodePointer; /** * A single-set EvalContext that provides access to the current node of * the parent context and nothing else. It does not pass the iteration * on to the parent context. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class InitialContext extends EvalContext { private boolean started = false; private boolean collection; private NodePointer nodePointer; /** * Create a new InitialContext. * @param parentContext parent context */ public InitialContext(EvalContext parentContext) { super(parentContext); nodePointer = (NodePointer) parentContext.getCurrentNodePointer().clone(); if (nodePointer != null) { collection = (nodePointer.getIndex() == NodePointer.WHOLE_COLLECTION); } } public Pointer getSingleNodePointer() { return nodePointer; } public NodePointer getCurrentNodePointer() { return nodePointer; } public Object getValue() { return nodePointer.getValue(); } public boolean nextNode() { return setPosition(position + 1); } public boolean setPosition(int position) { this.position = position; if (collection) { if (position >= 1 && position <= nodePointer.getLength()) { nodePointer.setIndex(position - 1); return true; } return false; } return position == 1; } public boolean nextSet() { if (started) { return false; } started = true; return true; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/axes/NamespaceContext.java100644 0 0 6613 11044113530 26405 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.compiler.NodeNameTest; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; /** * EvalContext that walks the "namespace::" axis. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class NamespaceContext extends EvalContext { private NodeTest nodeTest; private boolean setStarted = false; private NodeIterator iterator; private NodePointer currentNodePointer; /** * @param parentContext represents the previous step on the path * @param nodeTest is the name of the namespace we are looking for */ public NamespaceContext(EvalContext parentContext, NodeTest nodeTest) { super(parentContext); this.nodeTest = nodeTest; } public NodePointer getCurrentNodePointer() { return currentNodePointer; } public void reset() { setStarted = false; iterator = null; super.reset(); } public boolean setPosition(int position) { if (position < getCurrentPosition()) { reset(); } while (getCurrentPosition() < position) { if (!nextNode()) { return false; } } return true; } public boolean nextNode() { super.setPosition(getCurrentPosition() + 1); if (!setStarted) { setStarted = true; if (!(nodeTest instanceof NodeNameTest)) { return false; } NodeNameTest nodeNameTest = (NodeNameTest) nodeTest; QName testName = nodeNameTest.getNodeName(); if (testName.getPrefix() != null) { return false; } if (nodeNameTest.isWildcard()) { iterator = parentContext.getCurrentNodePointer().namespaceIterator(); } else { currentNodePointer = parentContext.getCurrentNodePointer().namespacePointer( testName.getName()); return currentNodePointer != null; } } if (iterator == null) { return false; } if (!iterator.setPosition(iterator.getPosition() + 1)) { return false; } currentNodePointer = iterator.getNodePointer(); return true; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/axes/NodeSetContext.java100644 0 0 4300 11044113530 26041 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import org.apache.commons.jxpath.NodeSet; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.model.NodePointer; /** * A simple context that is based on a {@link NodeSet}. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class NodeSetContext extends EvalContext { private boolean startedSet = false; private NodeSet nodeSet; /** * Create a new NodeSetContext. * @param parentContext parent context * @param nodeSet associated NodeSet */ public NodeSetContext(EvalContext parentContext, NodeSet nodeSet) { super(parentContext); this.nodeSet = nodeSet; } public NodeSet getNodeSet() { return nodeSet; } public NodePointer getCurrentNodePointer() { if (position == 0 && !setPosition(1)) { return null; } return (NodePointer) nodeSet.getPointers().get(position - 1); } public boolean setPosition(int position) { super.setPosition(position); return position >= 1 && position <= nodeSet.getPointers().size(); } public boolean nextSet() { if (startedSet) { return false; } startedSet = true; return true; } public boolean nextNode() { return setPosition(position + 1); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/axes/package.html100644 0 0 1741 11044113530 24557 0ustar 0 0 Implementations of EvalContext used for different XPath axes (child::, parent:: etc). In order to evaluate a path, RI creates a chain of EvalContexts, one for each step in the path. commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/axes/ParentContext.java100644 0 0 5242 11044113530 25737 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.model.NodePointer; /** * EvalContext that walks the "parent::" axis. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class ParentContext extends EvalContext { private NodeTest nodeTest; private boolean setStarted = false; private NodePointer currentNodePointer; /** * Create a new ParentContext. * @param parentContext parent context * @param nodeTest test */ public ParentContext(EvalContext parentContext, NodeTest nodeTest) { super(parentContext); this.nodeTest = nodeTest; } public NodePointer getCurrentNodePointer() { return currentNodePointer; } public int getCurrentPosition() { return 1; } public int getDocumentOrder() { return -1; } public void reset() { super.reset(); setStarted = false; } public boolean setPosition(int position) { super.setPosition(position); return position == 1; } public boolean nextNode() { // Each set contains exactly one node: the parent if (setStarted) { return false; } setStarted = true; NodePointer thisLocation = parentContext.getCurrentNodePointer(); currentNodePointer = thisLocation.getImmediateParentPointer(); while (currentNodePointer != null && currentNodePointer.isContainer()) { currentNodePointer = currentNodePointer.getImmediateParentPointer(); } if (currentNodePointer != null && currentNodePointer.testNode(nodeTest)) { position++; return true; } return false; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/axes/PrecedingOrFollowingContext.java100644 0 0 13757 11044113530 30622 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import java.util.Stack; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; /** * EvalContext that walks the "preceding::" and "following::" axes. * * @author Dmitri Plotnikov * @version $Revision: 670727 $ $Date: 2008-06-23 15:10:38 -0500 (Mon, 23 Jun 2008) $ */ public class PrecedingOrFollowingContext extends EvalContext { private NodeTest nodeTest; private boolean setStarted = false; private Stack stack = null; private NodePointer currentNodePointer; private NodePointer currentRootLocation; private boolean reverse; /** * Create a new PrecedingOrFollowingContext. * @param parentContext parent context * @param nodeTest test * @param reverse whether to iterate in reverse order */ public PrecedingOrFollowingContext( EvalContext parentContext, NodeTest nodeTest, boolean reverse) { super(parentContext); this.nodeTest = nodeTest; this.reverse = reverse; } public NodePointer getCurrentNodePointer() { return currentNodePointer; } public int getDocumentOrder() { return reverse ? -1 : 1; } public void reset() { super.reset(); setStarted = false; } public boolean setPosition(int position) { if (position < this.position) { reset(); } while (this.position < position) { if (!nextNode()) { return false; } } return true; } public boolean nextNode() { if (!setStarted) { setStarted = true; if (stack == null) { stack = new Stack(); } else { stack.clear(); } currentRootLocation = parentContext.getCurrentNodePointer(); NodePointer parent = currentRootLocation.getParent(); if (parent != null) { // TBD: check type stack.push( parent.childIterator(null, reverse, currentRootLocation)); } } while (true) { if (stack.isEmpty()) { currentRootLocation = currentRootLocation.getParent(); if (currentRootLocation == null || currentRootLocation.isRoot()) { break; } NodePointer parent = currentRootLocation.getParent(); if (parent != null) { stack.push( parent.childIterator( null, reverse, currentRootLocation)); } } while (!stack.isEmpty()) { if (!reverse) { NodeIterator it = (NodeIterator) stack.peek(); if (it.setPosition(it.getPosition() + 1)) { currentNodePointer = it.getNodePointer(); if (!currentNodePointer.isLeaf()) { stack.push( currentNodePointer.childIterator( null, reverse, null)); } if (currentNodePointer.testNode(nodeTest)) { super.setPosition(getCurrentPosition() + 1); return true; } } else { // We get here only if the name test failed // and the iterator ended stack.pop(); } } else { NodeIterator it = (NodeIterator) stack.peek(); if (it.setPosition(it.getPosition() + 1)) { currentNodePointer = it.getNodePointer(); if (!currentNodePointer.isLeaf()) { stack.push( currentNodePointer.childIterator( null, reverse, null)); } else if (currentNodePointer.testNode(nodeTest)) { super.setPosition(getCurrentPosition() + 1); return true; } } else { stack.pop(); if (!stack.isEmpty()) { it = (NodeIterator) stack.peek(); currentNodePointer = it.getNodePointer(); if (currentNodePointer.testNode(nodeTest)) { super.setPosition(getCurrentPosition() + 1); return true; } } } } } } return false; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/axes/PredicateContext.java100644 0 0 14730 11044113530 26430 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import java.util.Iterator; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; import org.apache.commons.jxpath.ri.compiler.Expression; import org.apache.commons.jxpath.ri.compiler.NameAttributeTest; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.beans.PropertyOwnerPointer; import org.apache.commons.jxpath.ri.model.beans.PropertyPointer; /** * EvalContext that checks predicates. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class PredicateContext extends EvalContext { private Expression expression; private boolean done = false; private Expression nameTestExpression; private PropertyPointer dynamicPropertyPointer; /** * Create a new PredicateContext. * @param parentContext parent context * @param expression compiled Expression */ public PredicateContext(EvalContext parentContext, Expression expression) { super(parentContext); this.expression = expression; if (expression instanceof NameAttributeTest) { nameTestExpression = ((NameAttributeTest) expression).getNameTestExpression(); } } public boolean nextNode() { if (done) { return false; } while (parentContext.nextNode()) { if (setupDynamicPropertyPointer()) { Object pred = nameTestExpression.computeValue(parentContext); String propertyName = InfoSetUtil.stringValue(pred); // At this point it would be nice to say: // dynamicPropertyPointer.setPropertyName(propertyName) // and then: dynamicPropertyPointer.isActual(). // However some PropertyPointers, e.g. DynamicPropertyPointer // will declare that any property you ask for is actual. // That's not acceptable for us: we really need to know // if the property is currently declared. Thus, // we'll need to perform a search. boolean ok = false; String[] names = dynamicPropertyPointer.getPropertyNames(); for (int i = 0; i < names.length; i++) { if (names[i].equals(propertyName)) { ok = true; break; } } if (ok) { dynamicPropertyPointer.setPropertyName(propertyName); position++; return true; } } else { Object pred = expression.computeValue(parentContext); if (pred instanceof Iterator) { if (!((Iterator) pred).hasNext()) { return false; } pred = ((Iterator) pred).next(); } if (pred instanceof NodePointer) { pred = ((NodePointer) pred).getNode(); } if (pred instanceof Number) { int pos = (int) InfoSetUtil.doubleValue(pred); position++; done = true; return parentContext.setPosition(pos); } if (InfoSetUtil.booleanValue(pred)) { position++; return true; } } } return false; } /** * Used for an optimized access to dynamic properties using the * "map[@name = 'name']" syntax * @return whether valid */ private boolean setupDynamicPropertyPointer() { if (nameTestExpression == null) { return false; } NodePointer parent = parentContext.getCurrentNodePointer(); if (parent == null) { return false; } parent = parent.getValuePointer(); if (!(parent instanceof PropertyOwnerPointer)) { return false; } dynamicPropertyPointer = (PropertyPointer) ((PropertyOwnerPointer) parent) .getPropertyPointer() .clone(); return true; } public boolean setPosition(int position) { if (nameTestExpression == null) { return setPositionStandard(position); } else { if (dynamicPropertyPointer == null && !setupDynamicPropertyPointer()) { return setPositionStandard(position); } if (position < 1 || position > dynamicPropertyPointer.getLength()) { return false; } dynamicPropertyPointer.setIndex(position - 1); return true; } } public NodePointer getCurrentNodePointer() { if (position == 0 && !setPosition(1)) { return null; } if (dynamicPropertyPointer != null) { return dynamicPropertyPointer.getValuePointer(); } return parentContext.getCurrentNodePointer(); } public void reset() { super.reset(); parentContext.reset(); done = false; } public boolean nextSet() { reset(); return parentContext.nextSet(); } /** * Basic setPosition * @param position to set * @return whether valid */ private boolean setPositionStandard(int position) { if (this.position > position) { reset(); } while (this.position < position) { if (!nextNode()) { return false; } } return true; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/axes/RootContext.java100644 0 0 12420 11044113530 25445 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import org.apache.commons.jxpath.Function; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.NodeSet; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.JXPathContextReferenceImpl; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; /** * EvalContext that is used to hold the root node for the path traversal. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class RootContext extends EvalContext { private JXPathContextReferenceImpl jxpathContext; private NodePointer pointer; private Object[] registers; private int availableRegister = 0; public static final Object UNKNOWN_VALUE = new Object(); private static final int MAX_REGISTER = 4; /** * Create a new RootContext. * @param jxpathContext context * @param pointer pointer */ public RootContext(JXPathContextReferenceImpl jxpathContext, NodePointer pointer) { super(null); this.jxpathContext = jxpathContext; this.pointer = pointer; if (pointer != null) { pointer.setNamespaceResolver(jxpathContext.getNamespaceResolver()); } } public JXPathContext getJXPathContext() { return jxpathContext; } public RootContext getRootContext() { return this; } /** * Get absolute root context * @return EvalContext */ public EvalContext getAbsoluteRootContext() { return jxpathContext.getAbsoluteRootContext(); } public NodePointer getCurrentNodePointer() { return pointer; } public Object getValue() { return pointer; } public int getCurrentPosition() { throw new UnsupportedOperationException(); } public boolean nextNode() { throw new UnsupportedOperationException(); } public boolean nextSet() { throw new UnsupportedOperationException(); } public boolean setPosition(int position) { throw new UnsupportedOperationException(); } /** * Get a context that points to the specified object. * @param constant object * @return EvalContext */ public EvalContext getConstantContext(Object constant) { if (constant instanceof NodeSet) { return new NodeSetContext( new RootContext(jxpathContext, null), (NodeSet) constant); } NodePointer pointer; if (constant instanceof NodePointer) { pointer = (NodePointer) constant; } else { pointer = NodePointer.newNodePointer( new QName(null, ""), constant, null); } return new InitialContext(new RootContext(jxpathContext, pointer)); } /** * Get variable context. * @param variableName variable name * @return EvalContext */ public EvalContext getVariableContext(QName variableName) { return new InitialContext( new RootContext( jxpathContext, jxpathContext.getVariablePointer(variableName))); } /** * Get the specified function from the context. * @param functionName QName * @param parameters Object[] * @return Function */ public Function getFunction(QName functionName, Object[] parameters) { return jxpathContext.getFunction(functionName, parameters); } /** * Get a registered value. * @param id int * @return Object */ public Object getRegisteredValue(int id) { if (registers == null || id >= MAX_REGISTER || id == -1) { return UNKNOWN_VALUE; } return registers[id]; } /** * Set the next registered value. * @param value Object * @return the id that can reclaim value. */ public int setRegisteredValue(Object value) { if (registers == null) { registers = new Object[MAX_REGISTER]; for (int i = 0; i < MAX_REGISTER; i++) { registers[i] = UNKNOWN_VALUE; } } if (availableRegister >= MAX_REGISTER) { return -1; } registers[availableRegister] = value; availableRegister++; return availableRegister - 1; } public String toString() { return super.toString() + ":" + pointer.asPath(); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/axes/SelfContext.java100644 0 0 5017 11044113530 25377 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.model.NodePointer; /** * EvalContext that returns the current node from the parent context if the * test succeeds. * * @author Dmitri Plotnikov * @version $Revision: 670727 $ $Date: 2008-06-23 15:10:38 -0500 (Mon, 23 Jun 2008) $ */ public class SelfContext extends EvalContext { private NodeTest nodeTest; private boolean startedSet = false; private NodePointer nodePointer; /** * Create a new SelfContext. * @param parentContext EvalContext * @param nodeTest guard */ public SelfContext(EvalContext parentContext, NodeTest nodeTest) { super(parentContext); this.nodeTest = nodeTest; } public Pointer getSingleNodePointer() { return parentContext.getSingleNodePointer(); } public NodePointer getCurrentNodePointer() { if (position == 0 && !setPosition(1)) { return null; } return nodePointer; } public boolean nextNode() { return setPosition(getCurrentPosition() + 1); } public void reset() { super.reset(); startedSet = false; } public boolean setPosition(int position) { if (position != 1) { return false; } super.setPosition(position); if (!startedSet) { startedSet = true; nodePointer = (NodePointer) parentContext.getCurrentNodePointer(); } if (nodePointer == null) { return false; } return nodeTest == null || nodePointer.testNode(nodeTest); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/axes/SimplePathInterpreter.java100644 0 0 103721 11044113530 27474 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.apache.commons.jxpath.JXPathException; import org.apache.commons.jxpath.ri.Compiler; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.compiler.Expression; import org.apache.commons.jxpath.ri.compiler.NameAttributeTest; import org.apache.commons.jxpath.ri.compiler.NodeNameTest; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.compiler.Step; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.beans.LangAttributePointer; import org.apache.commons.jxpath.ri.model.beans.NullElementPointer; import org.apache.commons.jxpath.ri.model.beans.NullPropertyPointer; import org.apache.commons.jxpath.ri.model.beans.PropertyOwnerPointer; import org.apache.commons.jxpath.ri.model.beans.PropertyPointer; /** * An evaluation mechanism for simple XPaths, which * is much faster than the usual process. It is only used for * xpaths which have no context-dependent parts, consist entirely of * child::name and self::node() steps with * predicates that either integer or have the form [@name = ...]. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class SimplePathInterpreter { // Because of the complexity caused by the variety of situations // that need to be addressed by this class, we attempt to break up // the class into individual methods addressing those situations // individually. The names of the methods are supposed to // give brief descriptions of those situations. private static final QName QNAME_NAME = new QName(null, "name"); private static final int PERFECT_MATCH = 1000; // Uncomment this variable and the PATH = ... lines in // the two following methods in order to be able to print the // currently evaluated path for debugging of this class // private static String PATH; // Debugging /** * Interpret a simple path that starts with the given root and * follows the given steps. All steps must have the axis "child::" * and a name test. They can also optionally have predicates * of type [@name=expression] or simply [expression] interpreted * as an index. * @param context evaluation context * @param root root pointer * @param steps path steps * @return NodePointer */ public static NodePointer interpretSimpleLocationPath( EvalContext context, NodePointer root, Step[] steps) { // PATH = createNullPointer(context, root, steps, 0).toString(); // Dbg NodePointer pointer = doStep(context, root, steps, 0); // return valuePointer(pointer); return pointer; } /** * Interpret the steps of a simple expression path that * starts with the given root, which is the result of evaluation * of the root expression of the expression path, applies the * given predicates to it and then follows the given steps. * All steps must have the axis "child::" or "attribute::" * and a name test. They can also optionally have predicates * of type [@name=...] or simply [...] interpreted as an index. * @param context evaluation context * @param root root pointer * @param predicates predicates corresponding to steps * @param steps path steps * @return NodePointer */ public static NodePointer interpretSimpleExpressionPath( EvalContext context, NodePointer root, Expression[] predicates, Step[] steps) { // PATH = createNullPointerForPredicates(context, root, // steps, -1, predicates, 0).toString(); // Debugging NodePointer pointer = doPredicate(context, root, steps, -1, predicates, 0); // return valuePointer(pointer); return pointer; } /** * Recursive evaluation of a path. The general plan is: * Look at the current step, * find nodes that match it, * iterate over those nodes and * for each of them call doStep again for subsequent steps. * @param context evaluation context * @param parent parent pointer * @param steps path steps * @param currentStep step number * @return NodePointer */ private static NodePointer doStep( EvalContext context, NodePointer parent, Step[] steps, int currentStep) { if (parent == null) { return null; } if (currentStep == steps.length) { // We have reached the end of the list of steps return parent; } // Open all containers parent = valuePointer(parent); Step step = steps[currentStep]; Expression[] predicates = step.getPredicates(); // Divide and conquer: the process is broken out into // four major use cases. // 1. Current step has no predicates and // the root is a property owner (e.g. bean or map) // 2. Current step has predicates and // the root is a property owner (e.g. bean or map) // 3. Current step has no predicates and // the root is an InfoSet standard node (e.g. DOM Node) // 4. Current step has predicates and // the root is an InfoSet standard node (e.g. DOM Node) if (parent instanceof PropertyOwnerPointer) { if (predicates == null || predicates.length == 0) { return doStepNoPredicatesPropertyOwner( context, (PropertyOwnerPointer) parent, steps, currentStep); } return doStepPredicatesPropertyOwner( context, (PropertyOwnerPointer) parent, steps, currentStep); } if (predicates == null || predicates.length == 0) { return doStepNoPredicatesStandard( context, parent, steps, currentStep); } return doStepPredicatesStandard( context, parent, steps, currentStep); } /** * We have a step that starts with a property owner (bean, map, etc) and has * no predicates. The name test of the step may map to a scalar property * or to a collection. If it is a collection, we should apply the tail of * the path to each element until we find a match. If we don't find * a perfect match, we should return the "best quality" pointer, which * has the longest chain of steps mapping to existing nodes and the shortes * tail of Null* pointers. * @param context evaluation context * @param parentPointer property owner pointer * @param steps path steps * @param currentStep step number * @return NodePointer */ private static NodePointer doStepNoPredicatesPropertyOwner( EvalContext context, PropertyOwnerPointer parentPointer, Step[] steps, int currentStep) { Step step = steps[currentStep]; NodePointer childPointer = createChildPointerForStep(parentPointer, step); if (childPointer == null) { return null; } if (!childPointer.isActual()) { // The property does not exist - create a null pointer. return createNullPointer( context, parentPointer, steps, currentStep); } if (currentStep == steps.length - 1) { // If this is the last step - we are done, we found it return childPointer; } if (childPointer.isCollection()) { // Iterate over all values and // execute remaining steps for each node, // looking for the best quality match int bestQuality = 0; childPointer = (NodePointer) childPointer.clone(); NodePointer bestMatch = null; int count = childPointer.getLength(); for (int i = 0; i < count; i++) { childPointer.setIndex(i); NodePointer pointer = doStep(context, childPointer, steps, currentStep + 1); int quality = computeQuality(pointer); if (quality == PERFECT_MATCH) { return pointer; } else if (quality > bestQuality) { bestQuality = quality; bestMatch = (NodePointer) pointer.clone(); } } if (bestMatch != null) { return bestMatch; } // This step did not find anything - return a null pointer return createNullPointer(context, childPointer, steps, currentStep); } // Evaluate subsequent steps return doStep(context, childPointer, steps, currentStep + 1); } /** * A path that starts with a standard InfoSet node (e.g. DOM Node) and * has no predicates. Get a child iterator and apply the tail of * the path to each element until we find a match. If we don't find * a perfect match, we should return the "best quality" pointer, which * has the longest chain of steps mapping to existing nodes and the shortes * tail of Null* pointers. * @param context evaluation context * @param parentPointer parent pointer * @param steps path steps * @param currentStep step number * @return NodePointer */ private static NodePointer doStepNoPredicatesStandard( EvalContext context, NodePointer parentPointer, Step[] steps, int currentStep) { Step step = steps[currentStep]; if (step.getAxis() == Compiler.AXIS_SELF) { return doStep(context, parentPointer, steps, currentStep + 1); } int bestQuality = 0; NodePointer bestMatch = null; NodeIterator it = getNodeIterator(context, parentPointer, step); if (it != null) { for (int i = 1; it.setPosition(i); i++) { NodePointer childPointer = it.getNodePointer(); if (steps.length == currentStep + 1) { // If this is the last step - we are done, we found it return childPointer; } NodePointer pointer = doStep( context, childPointer, steps, currentStep + 1); int quality = computeQuality(pointer); if (quality == PERFECT_MATCH) { return pointer; } if (quality > bestQuality) { bestQuality = quality; bestMatch = (NodePointer) pointer.clone(); } } } return bestMatch != null ? bestMatch : createNullPointer(context, parentPointer, steps, currentStep); } /** * A path that starts with a property owner. The method evaluates * the first predicate in a special way and then forwards to * a general predicate processing method. * @param context evaluation context * @param parentPointer parent pointer * @param steps path steps * @param currentStep step number * @return NodePointer */ private static NodePointer doStepPredicatesPropertyOwner( EvalContext context, PropertyOwnerPointer parentPointer, Step[] steps, int currentStep) { Step step = steps[currentStep]; Expression[] predicates = step.getPredicates(); NodePointer childPointer = createChildPointerForStep(parentPointer, step); if (!childPointer.isActual()) { // Property does not exist - return a null pointer return createNullPointer( context, parentPointer, steps, currentStep); } // Evaluate predicates return doPredicate( context, childPointer, steps, currentStep, predicates, 0); } /** * Create the child pointer for a given step. * @param parentPointer parent pointer * @param step associated step * @return NodePointer */ private static NodePointer createChildPointerForStep( PropertyOwnerPointer parentPointer, Step step) { int axis = step.getAxis(); if (axis == Compiler.AXIS_CHILD || axis == Compiler.AXIS_ATTRIBUTE) { QName name = ((NodeNameTest) step.getNodeTest()).getNodeName(); if (axis == Compiler.AXIS_ATTRIBUTE && isLangAttribute(name)) { return new LangAttributePointer(parentPointer); } if (parentPointer.isValidProperty(name)) { NodePointer childPointer = parentPointer.getPropertyPointer(); ((PropertyPointer) childPointer).setPropertyName( name.toString()); childPointer.setAttribute(axis == Compiler.AXIS_ATTRIBUTE); return childPointer; } //invalid property gets nothing, not even a NullPointer return null; } return parentPointer; } /** * A path that starts with a standard InfoSet node, e.g. a DOM Node. * The method evaluates the first predicate in a special way and * then forwards to a general predicate processing method. * @param context evaluation context * @param parent parent pointer * @param steps path steps * @param currentStep step number * @return NodePointer */ private static NodePointer doStepPredicatesStandard( EvalContext context, NodePointer parent, Step[] steps, int currentStep) { Step step = steps[currentStep]; Expression[] predicates = step.getPredicates(); int axis = step.getAxis(); if (axis == Compiler.AXIS_SELF) { return doPredicate( context, parent, steps, currentStep, predicates, 0); } Expression predicate = predicates[0]; // Optimize for a single predicate to avoid building a list // and to allow the direct access to the index'th element // in the case of a simple subscript predecate // It is a very common use case, so it deserves individual // attention if (predicates.length == 1) { NodeIterator it = getNodeIterator(context, parent, step); NodePointer pointer = null; if (it != null) { if (predicate instanceof NameAttributeTest) { // [@name = key] String key = keyFromPredicate(context, predicate); for (int i = 1; it.setPosition(i); i++) { NodePointer ptr = it.getNodePointer(); if (isNameAttributeEqual(ptr, key)) { pointer = ptr; break; } } } else { int index = indexFromPredicate(context, predicate); if (it.setPosition(index + 1)) { pointer = it.getNodePointer(); } } } if (pointer != null) { return doStep(context, pointer, steps, currentStep + 1); } } else { NodeIterator it = getNodeIterator(context, parent, step); if (it != null) { List list = new ArrayList(); for (int i = 1; it.setPosition(i); i++) { list.add(it.getNodePointer()); } NodePointer pointer = doPredicatesStandard( context, list, steps, currentStep, predicates, 0); if (pointer != null) { return pointer; } } } return createNullPointer(context, parent, steps, currentStep); } /** * Evaluates predicates and proceeds with the subsequent steps * of the path. * @param context evaluation context * @param parent parent pointer * @param steps path steps * @param currentStep step number * @param predicates predicate expressions * @param currentPredicate int predicate number * @return NodePointer */ private static NodePointer doPredicate( EvalContext context, NodePointer parent, Step[] steps, int currentStep, Expression[] predicates, int currentPredicate) { if (currentPredicate == predicates.length) { return doStep(context, parent, steps, currentStep + 1); } Expression predicate = predicates[currentPredicate]; if (predicate instanceof NameAttributeTest) { // [@name = key1] return doPredicateName( context, parent, steps, currentStep, predicates, currentPredicate); } // else [index] return doPredicateIndex( context, parent, steps, currentStep, predicates, currentPredicate); } /** * Execute a NameAttributeTest predicate * @param context evaluation context * @param parent parent pointer * @param steps path steps * @param currentStep int step number * @param predicates predicates * @param currentPredicate int predicate number * @return NodePointer */ private static NodePointer doPredicateName( EvalContext context, NodePointer parent, Step[] steps, int currentStep, Expression[] predicates, int currentPredicate) { Expression predicate = predicates[currentPredicate]; String key = keyFromPredicate(context, predicate); NodePointer child = valuePointer(parent); if (child instanceof PropertyOwnerPointer) { PropertyPointer pointer = ((PropertyOwnerPointer) child).getPropertyPointer(); pointer.setPropertyName(key); if (pointer.isActual()) { return doPredicate( context, pointer, steps, currentStep, predicates, currentPredicate + 1); } } else if (child.isCollection()) { // For each node in the collection, perform the following: // if the node is a property owner, apply this predicate to it; // if the node is a collection, apply this predicate to each elem.; // if the node is not a prop owner or a collection, // see if it has the attribute "name" with the right value, // if so - proceed to the next predicate NodePointer bestMatch = null; int bestQuality = 0; child = (NodePointer) child.clone(); int count = child.getLength(); for (int i = 0; i < count; i++) { child.setIndex(i); NodePointer valuePointer = valuePointer(child); NodePointer pointer; if ((valuePointer instanceof PropertyOwnerPointer) || valuePointer.isCollection()) { pointer = doPredicateName( context, valuePointer, steps, currentStep, predicates, currentPredicate); } else if (isNameAttributeEqual(valuePointer, key)) { pointer = doPredicate( context, valuePointer, steps, currentStep, predicates, currentPredicate + 1); } else { pointer = null; } if (pointer != null) { int quality = computeQuality(pointer); if (quality == PERFECT_MATCH) { return pointer; } if (quality > bestQuality) { bestMatch = (NodePointer) pointer.clone(); bestQuality = quality; } } } if (bestMatch != null) { return bestMatch; } } else { // If the node is a standard InfoSet node (e.g. DOM Node), // employ doPredicates_standard, which will iterate through // the node's children and apply all predicates NodePointer found = doPredicatesStandard( context, Collections.singletonList(child), steps, currentStep, predicates, currentPredicate); if (found != null) { return found; } } // If nothing worked - return a null pointer return createNullPointerForPredicates( context, child, steps, currentStep, predicates, currentPredicate); } /** * Called exclusively for standard InfoSet nodes, e.g. DOM nodes * to evaluate predicate sequences like [@name=...][@name=...][index]. * @param context evaluation context * @param parents List of parent pointers * @param steps path steps * @param currentStep step number * @param predicates predicates * @param currentPredicate int predicate number * @return NodePointer */ private static NodePointer doPredicatesStandard( EvalContext context, List parents, Step[] steps, int currentStep, Expression[] predicates, int currentPredicate) { if (parents.size() == 0) { return null; } // If all predicates have been processed, take the first // element from the list of results and proceed to the // remaining steps with that element. if (currentPredicate == predicates.length) { NodePointer pointer = (NodePointer) parents.get(0); return doStep(context, pointer, steps, currentStep + 1); } Expression predicate = predicates[currentPredicate]; if (predicate instanceof NameAttributeTest) { String key = keyFromPredicate(context, predicate); List newList = new ArrayList(); for (int i = 0; i < parents.size(); i++) { NodePointer pointer = (NodePointer) parents.get(i); if (isNameAttributeEqual(pointer, key)) { newList.add(pointer); } } if (newList.size() == 0) { return null; } return doPredicatesStandard( context, newList, steps, currentStep, predicates, currentPredicate + 1); } else { // For a subscript, simply take the corresponding // element from the list of results and // proceed to the remaining predicates with that element int index = indexFromPredicate(context, predicate); if (index < 0 || index >= parents.size()) { return null; } NodePointer ptr = (NodePointer) parents.get(index); return doPredicate( context, ptr, steps, currentStep, predicates, currentPredicate + 1); } } /** * Evaluate a subscript predicate: see if the node is a collection and * if the index is inside the collection. * @param context evaluation context * @param parent parent pointer * @param steps path steps * @param currentStep step number * @param predicates predicates * @param currentPredicate int predicate number * @return NodePointer */ private static NodePointer doPredicateIndex( EvalContext context, NodePointer parent, Step[] steps, int currentStep, Expression[] predicates, int currentPredicate) { Expression predicate = predicates[currentPredicate]; int index = indexFromPredicate(context, predicate); NodePointer pointer = parent; if (isCollectionElement(pointer, index)) { pointer = (NodePointer) pointer.clone(); pointer.setIndex(index); return doPredicate( context, pointer, steps, currentStep, predicates, currentPredicate + 1); } return createNullPointerForPredicates( context, parent, steps, currentStep, predicates, currentPredicate); } /** * Extract an integer from a subscript predicate. The returned index * starts with 0, even though the subscript starts with 1. * @param context evaluation context * @param predicate to evaluate * @return calculated index */ private static int indexFromPredicate( EvalContext context, Expression predicate) { Object value = predicate.computeValue(context); if (value instanceof EvalContext) { value = ((EvalContext) value).getSingleNodePointer(); } if (value instanceof NodePointer) { value = ((NodePointer) value).getValue(); } if (value == null) { throw new JXPathException("Predicate value is null: " + predicate); } if (value instanceof Number) { final double round = 0.5; return (int) (InfoSetUtil.doubleValue(value) + round) - 1; } return InfoSetUtil.booleanValue(value) ? 0 : -1; } /** * Extracts the string value of the expression from a predicate like * [@name=expression]. * @param context evaluation context * @param predicate predicate to evaluate * @return String key extracted */ private static String keyFromPredicate(EvalContext context, Expression predicate) { Expression expr = ((NameAttributeTest) predicate).getNameTestExpression(); return InfoSetUtil.stringValue(expr.computeValue(context)); } /** * For a pointer that matches an actual node, returns 0. * For a pointer that does not match an actual node, but whose * parent pointer does returns -1, etc. * @param pointer input pointer * @return int match quality code */ private static int computeQuality(NodePointer pointer) { int quality = PERFECT_MATCH; while (pointer != null && !pointer.isActual()) { quality--; pointer = pointer.getImmediateParentPointer(); } return quality; } /** * Returns true if the pointer has an attribute called "name" and * its value is equal to the supplied string. * @param pointer input pointer * @param name name to check * @return boolean */ private static boolean isNameAttributeEqual( NodePointer pointer, String name) { NodeIterator it = pointer.attributeIterator(QNAME_NAME); return it != null && it.setPosition(1) && name.equals(it.getNodePointer().getValue()); } /** * Returns true if the pointer is a collection and the index is * withing the bounds of the collection. * @param pointer input pointer * @param index to check * @return boolean */ private static boolean isCollectionElement( NodePointer pointer, int index) { return pointer.isActual() && (index == 0 || (pointer.isCollection() && index >= 0 && index < pointer.getLength())); } /** * For an intermediate pointer (e.g. PropertyPointer, ContainerPointer) * returns a pointer for the contained value. * @param pointer input pointer * @return NodePointer */ private static NodePointer valuePointer(NodePointer pointer) { return pointer == null ? null : pointer.getValuePointer(); } /** * Creates a "null pointer" that * a) represents the requested path and * b) can be used for creation of missing nodes in the path. * @param context evaluation context * @param parent parent pointer * @param steps path steps * @param currentStep step number * @return NodePointer */ public static NodePointer createNullPointer( EvalContext context, NodePointer parent, Step[] steps, int currentStep) { if (currentStep == steps.length) { return parent; } parent = valuePointer(parent); Step step = steps[currentStep]; int axis = step.getAxis(); if (axis == Compiler.AXIS_CHILD || axis == Compiler.AXIS_ATTRIBUTE) { NullPropertyPointer pointer = new NullPropertyPointer(parent); QName name = ((NodeNameTest) step.getNodeTest()).getNodeName(); pointer.setPropertyName(name.toString()); pointer.setAttribute(axis == Compiler.AXIS_ATTRIBUTE); parent = pointer; } // else { it is self::node() } Expression[] predicates = step.getPredicates(); return createNullPointerForPredicates( context, parent, steps, currentStep, predicates, 0); } /** * Creates a "null pointer" that starts with predicates. * @param context evaluation context * @param parent parent pointer * @param steps path steps * @param currentStep step number * @param predicates predicates * @param currentPredicate int predicate number * @return NodePointer */ private static NodePointer createNullPointerForPredicates( EvalContext context, NodePointer parent, Step[] steps, int currentStep, Expression[] predicates, int currentPredicate) { for (int i = currentPredicate; i < predicates.length; i++) { Expression predicate = predicates[i]; if (predicate instanceof NameAttributeTest) { String key = keyFromPredicate(context, predicate); parent = valuePointer(parent); NullPropertyPointer pointer = new NullPropertyPointer(parent); pointer.setNameAttributeValue(key); parent = pointer; } else { int index = indexFromPredicate(context, predicate); if (parent instanceof NullPropertyPointer) { parent.setIndex(index); } else { parent = new NullElementPointer(parent, index); } } } // Proceed with the remaining steps return createNullPointer( context, parent, steps, currentStep + 1); } /** * Get a NodeIterator. * @param context evaluation context * @param pointer owning pointer * @param step triggering step * @return NodeIterator */ private static NodeIterator getNodeIterator( EvalContext context, NodePointer pointer, Step step) { if (step.getAxis() == Compiler.AXIS_CHILD) { NodeTest nodeTest = step.getNodeTest(); QName qname = ((NodeNameTest) nodeTest).getNodeName(); String prefix = qname.getPrefix(); if (prefix != null) { String namespaceURI = context.getJXPathContext() .getNamespaceURI(prefix); nodeTest = new NodeNameTest(qname, namespaceURI); } return pointer.childIterator(nodeTest, false, null); } // else Compiler.AXIS_ATTRIBUTE if (!(step.getNodeTest() instanceof NodeNameTest)) { throw new UnsupportedOperationException( "Not supported node test for attributes: " + step.getNodeTest()); } return pointer.attributeIterator( ((NodeNameTest) step.getNodeTest()).getNodeName()); } /** * Learn whether name is a lang attribute. * @param name to compare * @return boolean */ private static boolean isLangAttribute(QName name) { return name.getPrefix() != null && name.getPrefix().equals("xml") && name.getName().equals("lang"); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/axes/UnionContext.java100644 0 0 5306 11044113530 25577 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import java.util.ArrayList; import java.util.Iterator; import org.apache.commons.jxpath.BasicNodeSet; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.model.NodePointer; /** * EvalContext that represents a union between other contexts - result * of a union operation like (a | b) * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class UnionContext extends NodeSetContext { private EvalContext[] contexts; private boolean prepared; /** * Create a new UnionContext. * @param parentContext parent context * @param contexts child contexts */ public UnionContext(EvalContext parentContext, EvalContext[] contexts) { super(parentContext, new BasicNodeSet()); this.contexts = contexts; } public int getDocumentOrder() { return contexts.length > 1 ? 1 : super.getDocumentOrder(); } public boolean setPosition(int position) { if (!prepared) { prepared = true; BasicNodeSet nodeSet = (BasicNodeSet) getNodeSet(); ArrayList pointers = new ArrayList(); for (int i = 0; i < contexts.length; i++) { EvalContext ctx = (EvalContext) contexts[i]; while (ctx.nextSet()) { while (ctx.nextNode()) { NodePointer ptr = ctx.getCurrentNodePointer(); if (!pointers.contains(ptr)) { pointers.add(ptr); } } } } sortPointers(pointers); for (Iterator it = pointers.iterator(); it.hasNext();) { nodeSet.add((Pointer) it.next()); } } return super.setPosition(position); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/Constant.java100644 0 0 4072 11044113540 25605 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; /** * A compile tree element containing a constant number or string. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class Constant extends Expression { private Object value; /** * Create a new Constant. * @param number constant */ public Constant(Number number) { this.value = number; } /** * Create a new Constant. * @param string constant */ public Constant(String string) { this.value = string; } public Object compute(EvalContext context) { return value; } public Object computeValue(EvalContext context) { return value; } /** * Returns false * @return false */ public boolean isContextDependent() { return false; } /** * Returns false * @return false */ public boolean computeContextDependent() { return false; } public String toString() { if (value instanceof Number) { return InfoSetUtil.stringValue(value); } return "'" + value + "'"; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/CoreFunction.java100644 0 0 71454 11044113540 26442 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.text.NumberFormat; import java.util.Collection; import java.util.Locale; import org.apache.commons.jxpath.BasicNodeSet; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathException; import org.apache.commons.jxpath.JXPathInvalidSyntaxException; import org.apache.commons.jxpath.NodeSet; import org.apache.commons.jxpath.ri.Compiler; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; import org.apache.commons.jxpath.ri.axes.NodeSetContext; import org.apache.commons.jxpath.ri.model.NodePointer; /** * An element of the compile tree representing one of built-in functions * like "position()" or "number()". * * @author Dmitri Plotnikov * @version $Revision: 668329 $ $Date: 2008-06-16 16:59:48 -0500 (Mon, 16 Jun 2008) $ */ public class CoreFunction extends Operation { private static final Double ZERO = new Double(0); private int functionCode; /** * Create a new CoreFunction. * @param functionCode int function code * @param args argument Expressions */ public CoreFunction(int functionCode, Expression[] args) { super(args); this.functionCode = functionCode; } /** * Get the function code. * @return int function code */ public int getFunctionCode() { return functionCode; } /** * Get the name of this function. * @return String function name */ protected String getFunctionName() { switch (functionCode) { case Compiler.FUNCTION_LAST : return "last"; case Compiler.FUNCTION_POSITION : return "position"; case Compiler.FUNCTION_COUNT : return "count"; case Compiler.FUNCTION_ID : return "id"; case Compiler.FUNCTION_LOCAL_NAME : return "local-name"; case Compiler.FUNCTION_NAMESPACE_URI : return "namespace-uri"; case Compiler.FUNCTION_NAME : return "name"; case Compiler.FUNCTION_STRING : return "string"; case Compiler.FUNCTION_CONCAT : return "concat"; case Compiler.FUNCTION_STARTS_WITH : return "starts-with"; case Compiler.FUNCTION_CONTAINS : return "contains"; case Compiler.FUNCTION_SUBSTRING_BEFORE : return "substring-before"; case Compiler.FUNCTION_SUBSTRING_AFTER : return "substring-after"; case Compiler.FUNCTION_SUBSTRING : return "substring"; case Compiler.FUNCTION_STRING_LENGTH : return "string-length"; case Compiler.FUNCTION_NORMALIZE_SPACE : return "normalize-space"; case Compiler.FUNCTION_TRANSLATE : return "translate"; case Compiler.FUNCTION_BOOLEAN : return "boolean"; case Compiler.FUNCTION_NOT : return "not"; case Compiler.FUNCTION_TRUE : return "true"; case Compiler.FUNCTION_FALSE : return "false"; case Compiler.FUNCTION_LANG : return "lang"; case Compiler.FUNCTION_NUMBER : return "number"; case Compiler.FUNCTION_SUM : return "sum"; case Compiler.FUNCTION_FLOOR : return "floor"; case Compiler.FUNCTION_CEILING : return "ceiling"; case Compiler.FUNCTION_ROUND : return "round"; case Compiler.FUNCTION_KEY : return "key"; case Compiler.FUNCTION_FORMAT_NUMBER: return "format-number"; default: return "unknownFunction" + functionCode + "()"; } } /** * Convenience method to return the first argument. * @return Expression */ public Expression getArg1() { return args[0]; } /** * Convenience method to return the second argument. * @return Expression */ public Expression getArg2() { return args[1]; } /** * Convenience method to return the third argument. * @return Expression */ public Expression getArg3() { return args[2]; } /** * Return the number of argument Expressions. * @return int count */ public int getArgumentCount() { if (args == null) { return 0; } return args.length; } /** * Returns true if any argument is context dependent or if * the function is last(), position(), boolean(), local-name(), * name(), string(), lang(), number(). * @return boolean */ public boolean computeContextDependent() { if (super.computeContextDependent()) { return true; } switch (functionCode) { case Compiler.FUNCTION_LAST: case Compiler.FUNCTION_POSITION: return true; case Compiler.FUNCTION_BOOLEAN: case Compiler.FUNCTION_LOCAL_NAME: case Compiler.FUNCTION_NAME: case Compiler.FUNCTION_NAMESPACE_URI: case Compiler.FUNCTION_STRING: case Compiler.FUNCTION_LANG: case Compiler.FUNCTION_NUMBER: return args == null || args.length == 0; case Compiler.FUNCTION_FORMAT_NUMBER: return args != null && args.length == 2; case Compiler.FUNCTION_COUNT: case Compiler.FUNCTION_ID: case Compiler.FUNCTION_CONCAT: case Compiler.FUNCTION_STARTS_WITH: case Compiler.FUNCTION_CONTAINS: case Compiler.FUNCTION_SUBSTRING_BEFORE: case Compiler.FUNCTION_SUBSTRING_AFTER: case Compiler.FUNCTION_SUBSTRING: case Compiler.FUNCTION_STRING_LENGTH: case Compiler.FUNCTION_NORMALIZE_SPACE: case Compiler.FUNCTION_TRANSLATE: case Compiler.FUNCTION_NOT: case Compiler.FUNCTION_TRUE: case Compiler.FUNCTION_FALSE: case Compiler.FUNCTION_SUM: case Compiler.FUNCTION_FLOOR: case Compiler.FUNCTION_CEILING: case Compiler.FUNCTION_ROUND: default: return false; } } public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append(getFunctionName()); buffer.append('('); Expression[] args = getArguments(); if (args != null) { for (int i = 0; i < args.length; i++) { if (i > 0) { buffer.append(", "); } buffer.append(args[i]); } } buffer.append(')'); return buffer.toString(); } public Object compute(EvalContext context) { return computeValue(context); } public Object computeValue(EvalContext context) { switch (functionCode) { case Compiler.FUNCTION_LAST : return functionLast(context); case Compiler.FUNCTION_POSITION : return functionPosition(context); case Compiler.FUNCTION_COUNT : return functionCount(context); case Compiler.FUNCTION_LANG : return functionLang(context); case Compiler.FUNCTION_ID : return functionID(context); case Compiler.FUNCTION_LOCAL_NAME : return functionLocalName(context); case Compiler.FUNCTION_NAMESPACE_URI : return functionNamespaceURI(context); case Compiler.FUNCTION_NAME : return functionName(context); case Compiler.FUNCTION_STRING : return functionString(context); case Compiler.FUNCTION_CONCAT : return functionConcat(context); case Compiler.FUNCTION_STARTS_WITH : return functionStartsWith(context); case Compiler.FUNCTION_CONTAINS : return functionContains(context); case Compiler.FUNCTION_SUBSTRING_BEFORE : return functionSubstringBefore(context); case Compiler.FUNCTION_SUBSTRING_AFTER : return functionSubstringAfter(context); case Compiler.FUNCTION_SUBSTRING : return functionSubstring(context); case Compiler.FUNCTION_STRING_LENGTH : return functionStringLength(context); case Compiler.FUNCTION_NORMALIZE_SPACE : return functionNormalizeSpace(context); case Compiler.FUNCTION_TRANSLATE : return functionTranslate(context); case Compiler.FUNCTION_BOOLEAN : return functionBoolean(context); case Compiler.FUNCTION_NOT : return functionNot(context); case Compiler.FUNCTION_TRUE : return functionTrue(context); case Compiler.FUNCTION_FALSE : return functionFalse(context); case Compiler.FUNCTION_NULL : return functionNull(context); case Compiler.FUNCTION_NUMBER : return functionNumber(context); case Compiler.FUNCTION_SUM : return functionSum(context); case Compiler.FUNCTION_FLOOR : return functionFloor(context); case Compiler.FUNCTION_CEILING : return functionCeiling(context); case Compiler.FUNCTION_ROUND : return functionRound(context); case Compiler.FUNCTION_KEY : return functionKey(context); case Compiler.FUNCTION_FORMAT_NUMBER : return functionFormatNumber(context); default: return null; } } /** * last() implementation. * @param context evaluation context * @return Number */ protected Object functionLast(EvalContext context) { assertArgCount(0); // Move the position to the beginning and iterate through // the context to count nodes. int old = context.getCurrentPosition(); context.reset(); int count = 0; while (context.nextNode()) { count++; } // Restore the current position. if (old != 0) { context.setPosition(old); } return new Double(count); } /** * position() implementation. * @param context evaluation context * @return Number */ protected Object functionPosition(EvalContext context) { assertArgCount(0); return new Integer(context.getCurrentPosition()); } /** * count() implementation. * @param context evaluation context * @return Number */ protected Object functionCount(EvalContext context) { assertArgCount(1); Expression arg1 = getArg1(); int count = 0; Object value = arg1.compute(context); if (value instanceof NodePointer) { value = ((NodePointer) value).getValue(); } if (value instanceof EvalContext) { EvalContext ctx = (EvalContext) value; while (ctx.hasNext()) { ctx.next(); count++; } } else if (value instanceof Collection) { count = ((Collection) value).size(); } else if (value == null) { count = 0; } else { count = 1; } return new Double(count); } /** * lang() implementation. * @param context evaluation context * @return Boolean */ protected Object functionLang(EvalContext context) { assertArgCount(1); String lang = InfoSetUtil.stringValue(getArg1().computeValue(context)); NodePointer pointer = (NodePointer) context.getSingleNodePointer(); if (pointer == null) { return Boolean.FALSE; } return pointer.isLanguage(lang) ? Boolean.TRUE : Boolean.FALSE; } /** * id() implementation. * @param context evaluation context * @return Pointer */ protected Object functionID(EvalContext context) { assertArgCount(1); String id = InfoSetUtil.stringValue(getArg1().computeValue(context)); JXPathContext jxpathContext = context.getJXPathContext(); NodePointer pointer = (NodePointer) jxpathContext.getContextPointer(); return pointer.getPointerByID(jxpathContext, id); } /** * key() implementation. * @param context evaluation context * @return various Object */ protected Object functionKey(EvalContext context) { assertArgCount(2); String key = InfoSetUtil.stringValue(getArg1().computeValue(context)); Object value = getArg2().compute(context); EvalContext ec = null; if (value instanceof EvalContext) { ec = (EvalContext) value; if (ec.hasNext()) { value = ((NodePointer) ec.next()).getValue(); } else { // empty context -> empty results return new NodeSetContext(context, new BasicNodeSet()); } } JXPathContext jxpathContext = context.getJXPathContext(); NodeSet nodeSet = jxpathContext.getNodeSetByKey(key, value); if (ec != null && ec.hasNext()) { BasicNodeSet accum = new BasicNodeSet(); accum.add(nodeSet); while (ec.hasNext()) { value = ((NodePointer) ec.next()).getValue(); accum.add(jxpathContext.getNodeSetByKey(key, value)); } nodeSet = accum; } return new NodeSetContext(context, nodeSet); } /** * namespace-uri() implementation. * @param context evaluation context * @return String */ protected Object functionNamespaceURI(EvalContext context) { if (getArgumentCount() == 0) { NodePointer ptr = context.getCurrentNodePointer(); String str = ptr.getNamespaceURI(); return str == null ? "" : str; } assertArgCount(1); Object set = getArg1().compute(context); if (set instanceof EvalContext) { EvalContext ctx = (EvalContext) set; if (ctx.hasNext()) { NodePointer ptr = (NodePointer) ctx.next(); String str = ptr.getNamespaceURI(); return str == null ? "" : str; } } return ""; } /** * local-name() implementation. * @param context evaluation context * @return String */ protected Object functionLocalName(EvalContext context) { if (getArgumentCount() == 0) { NodePointer ptr = context.getCurrentNodePointer(); return ptr.getName().getName(); } assertArgCount(1); Object set = getArg1().compute(context); if (set instanceof EvalContext) { EvalContext ctx = (EvalContext) set; if (ctx.hasNext()) { NodePointer ptr = (NodePointer) ctx.next(); return ptr.getName().getName(); } } return ""; } /** * name() implementation. * @param context evaluation context * @return String */ protected Object functionName(EvalContext context) { if (getArgumentCount() == 0) { NodePointer ptr = context.getCurrentNodePointer(); return ptr.getName().toString(); } assertArgCount(1); Object set = getArg1().compute(context); if (set instanceof EvalContext) { EvalContext ctx = (EvalContext) set; if (ctx.hasNext()) { NodePointer ptr = (NodePointer) ctx.next(); return ptr.getName().toString(); } } return ""; } /** * string() implementation. * @param context evaluation context * @return String */ protected Object functionString(EvalContext context) { if (getArgumentCount() == 0) { return InfoSetUtil.stringValue(context.getCurrentNodePointer()); } assertArgCount(1); return InfoSetUtil.stringValue(getArg1().computeValue(context)); } /** * concat() implementation. * @param context evaluation context * @return String */ protected Object functionConcat(EvalContext context) { if (getArgumentCount() < 2) { assertArgCount(2); } StringBuffer buffer = new StringBuffer(); Expression[] args = getArguments(); for (int i = 0; i < args.length; i++) { buffer.append(InfoSetUtil.stringValue(args[i].compute(context))); } return buffer.toString(); } /** * starts-with() implementation. * @param context evaluation context * @return Boolean */ protected Object functionStartsWith(EvalContext context) { assertArgCount(2); String s1 = InfoSetUtil.stringValue(getArg1().computeValue(context)); String s2 = InfoSetUtil.stringValue(getArg2().computeValue(context)); return s1.startsWith(s2) ? Boolean.TRUE : Boolean.FALSE; } /** * contains() implementation. * @param context evaluation context * @return Boolean */ protected Object functionContains(EvalContext context) { assertArgCount(2); String s1 = InfoSetUtil.stringValue(getArg1().computeValue(context)); String s2 = InfoSetUtil.stringValue(getArg2().computeValue(context)); return s1.indexOf(s2) != -1 ? Boolean.TRUE : Boolean.FALSE; } /** * substring-before() implementation. * @param context evaluation context * @return String */ protected Object functionSubstringBefore(EvalContext context) { assertArgCount(2); String s1 = InfoSetUtil.stringValue(getArg1().computeValue(context)); String s2 = InfoSetUtil.stringValue(getArg2().computeValue(context)); int index = s1.indexOf(s2); if (index == -1) { return ""; } return s1.substring(0, index); } /** * substring-after() implementation. * @param context evaluation context * @return String */ protected Object functionSubstringAfter(EvalContext context) { assertArgCount(2); String s1 = InfoSetUtil.stringValue(getArg1().computeValue(context)); String s2 = InfoSetUtil.stringValue(getArg2().computeValue(context)); int index = s1.indexOf(s2); if (index == -1) { return ""; } return s1.substring(index + s2.length()); } /** * substring() implementation. * @param context evaluation context * @return String */ protected Object functionSubstring(EvalContext context) { final int minArgs = 2; final int maxArgs = 3; assertArgRange(minArgs, maxArgs); int ac = getArgumentCount(); String s1 = InfoSetUtil.stringValue(getArg1().computeValue(context)); double from = InfoSetUtil.doubleValue(getArg2().computeValue(context)); if (Double.isNaN(from)) { return ""; } from = Math.round(from); if (from > s1.length() + 1) { return ""; } if (ac == 2) { if (from < 1) { from = 1; } return s1.substring((int) from - 1); } double length = InfoSetUtil.doubleValue(getArg3().computeValue(context)); length = Math.round(length); if (length < 0) { return ""; } double to = from + length; if (to < 1) { return ""; } if (to > s1.length() + 1) { if (from < 1) { from = 1; } return s1.substring((int) from - 1); } if (from < 1) { from = 1; } return s1.substring((int) from - 1, (int) (to - 1)); } /** * string-length() implementation. * @param context evaluation context * @return Number */ protected Object functionStringLength(EvalContext context) { String s; if (getArgumentCount() == 0) { s = InfoSetUtil.stringValue(context.getCurrentNodePointer()); } else { assertArgCount(1); s = InfoSetUtil.stringValue(getArg1().computeValue(context)); } return new Double(s.length()); } /** * normalize-space() implementation. * @param context evaluation context * @return String */ protected Object functionNormalizeSpace(EvalContext context) { assertArgCount(1); String s = InfoSetUtil.stringValue(getArg1().computeValue(context)); char[] chars = s.toCharArray(); int out = 0; int phase = 0; for (int in = 0; in < chars.length; in++) { switch (chars[in]) { case ' ': case '\t': case '\r': case '\n': if (phase == 1) { // non-space phase = 2; chars[out++] = ' '; } break; default: chars[out++] = chars[in]; phase = 1; } } if (phase == 2) { // trailing-space out--; } return new String(chars, 0, out); } /** * translate() implementation. * @param context evaluation context * @return String */ protected Object functionTranslate(EvalContext context) { final int argCount = 3; assertArgCount(argCount); String s1 = InfoSetUtil.stringValue(getArg1().computeValue(context)); String s2 = InfoSetUtil.stringValue(getArg2().computeValue(context)); String s3 = InfoSetUtil.stringValue(getArg3().computeValue(context)); char[] chars = s1.toCharArray(); int out = 0; for (int in = 0; in < chars.length; in++) { char c = chars[in]; int inx = s2.indexOf(c); if (inx != -1) { if (inx < s3.length()) { chars[out++] = s3.charAt(inx); } } else { chars[out++] = c; } } return new String(chars, 0, out); } /** * boolean() implementation. * @param context evaluation context * @return Boolean */ protected Object functionBoolean(EvalContext context) { assertArgCount(1); return InfoSetUtil.booleanValue(getArg1().computeValue(context)) ? Boolean.TRUE : Boolean.FALSE; } /** * not() implementation. * @param context evaluation context * @return Boolean */ protected Object functionNot(EvalContext context) { assertArgCount(1); return InfoSetUtil.booleanValue(getArg1().computeValue(context)) ? Boolean.FALSE : Boolean.TRUE; } /** * true() implementation. * @param context evaluation context * @return Boolean.TRUE */ protected Object functionTrue(EvalContext context) { assertArgCount(0); return Boolean.TRUE; } /** * false() implementation. * @param context evaluation context * @return Boolean.FALSE */ protected Object functionFalse(EvalContext context) { assertArgCount(0); return Boolean.FALSE; } /** * null() implementation. * @param context evaluation context * @return null */ protected Object functionNull(EvalContext context) { assertArgCount(0); return null; } /** * number() implementation. * @param context evaluation context * @return Number */ protected Object functionNumber(EvalContext context) { if (getArgumentCount() == 0) { return InfoSetUtil.number(context.getCurrentNodePointer()); } assertArgCount(1); return InfoSetUtil.number(getArg1().computeValue(context)); } /** * sum() implementation. * @param context evaluation context * @return Number */ protected Object functionSum(EvalContext context) { assertArgCount(1); Object v = getArg1().compute(context); if (v == null) { return ZERO; } if (v instanceof EvalContext) { double sum = 0.0; EvalContext ctx = (EvalContext) v; while (ctx.hasNext()) { NodePointer ptr = (NodePointer) ctx.next(); sum += InfoSetUtil.doubleValue(ptr); } return new Double(sum); } throw new JXPathException( "Invalid argument type for 'sum': " + v.getClass().getName()); } /** * floor() implementation. * @param context evaluation context * @return Number */ protected Object functionFloor(EvalContext context) { assertArgCount(1); double v = InfoSetUtil.doubleValue(getArg1().computeValue(context)); if (Double.isNaN(v) || Double.isInfinite(v)) { return new Double(v); } return new Double(Math.floor(v)); } /** * ceiling() implementation. * @param context evaluation context * @return Number */ protected Object functionCeiling(EvalContext context) { assertArgCount(1); double v = InfoSetUtil.doubleValue(getArg1().computeValue(context)); if (Double.isNaN(v) || Double.isInfinite(v)) { return new Double(v); } return new Double(Math.ceil(v)); } /** * round() implementation. * @param context evaluation context * @return Number */ protected Object functionRound(EvalContext context) { assertArgCount(1); double v = InfoSetUtil.doubleValue(getArg1().computeValue(context)); if (Double.isNaN(v) || Double.isInfinite(v)) { return new Double(v); } return new Double(Math.round(v)); } /** * format-number() implementation. * @param context evaluation context * @return String */ private Object functionFormatNumber(EvalContext context) { final int minArgs = 2; final int maxArgs = 3; assertArgRange(minArgs, maxArgs); double number = InfoSetUtil.doubleValue(getArg1().computeValue(context)); String pattern = InfoSetUtil.stringValue(getArg2().computeValue(context)); DecimalFormatSymbols symbols = null; if (getArgumentCount() == maxArgs) { String symbolsName = InfoSetUtil.stringValue(getArg3().computeValue(context)); symbols = context.getJXPathContext().getDecimalFormatSymbols(symbolsName); } else { NodePointer pointer = context.getCurrentNodePointer(); Locale locale; if (pointer != null) { locale = pointer.getLocale(); } else { locale = context.getJXPathContext().getLocale(); } symbols = new DecimalFormatSymbols(locale); } DecimalFormat format = (DecimalFormat) NumberFormat.getInstance(); format.setDecimalFormatSymbols(symbols); format.applyLocalizedPattern(pattern); return format.format(number); } /** * Assert count args. * @param count int */ private void assertArgCount(int count) { assertArgRange(count, count); } /** * Assert at least min/at most max args. * @param min int * @param max int */ private void assertArgRange(int min, int max) { int ct = getArgumentCount(); if (ct < min || ct > max) { throw new JXPathInvalidSyntaxException( "Incorrect number of arguments: " + this); } } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperation.java100644 0 0 7470 11044113540 26572 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.ri.EvalContext; /** * The common subclass for tree elements representing core operations like "+", * "- ", "*" etc. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public abstract class CoreOperation extends Operation { /** or precedence */ protected static final int OR_PRECEDENCE = 0; /** and precedence */ protected static final int AND_PRECEDENCE = 1; /** compare precedence */ protected static final int COMPARE_PRECEDENCE = 2; /** relational expression precedence */ protected static final int RELATIONAL_EXPR_PRECEDENCE = 3; /** add/subtract precedence */ protected static final int ADD_PRECEDENCE = 4; /** multiply/divide/mod precedence */ protected static final int MULTIPLY_PRECEDENCE = 5; /** negate precedence */ protected static final int NEGATE_PRECEDENCE = 6; /** union precedence */ protected static final int UNION_PRECEDENCE = 7; /** * Create a new CoreOperation. * @param args Expression[] */ public CoreOperation(Expression[] args) { super(args); } public Object compute(EvalContext context) { return computeValue(context); } public abstract Object computeValue(EvalContext context); /** * Returns the XPath symbol for this operation, e.g. "+", "div", etc. * @return String symbol */ public abstract String getSymbol(); /** * Returns true if the operation is not sensitive to the order of arguments, * e.g. "=", "and" etc, and false if it is, e.g. "<=", "div". * @return boolean */ protected abstract boolean isSymmetric(); /** * Computes the precedence of the operation. * @return int precedence */ protected abstract int getPrecedence(); public String toString() { if (args.length == 1) { return getSymbol() + parenthesize(args[0], false); } StringBuffer buffer = new StringBuffer(); for (int i = 0; i < args.length; i++) { if (i > 0) { buffer.append(' '); buffer.append(getSymbol()); buffer.append(' '); } buffer.append(parenthesize(args[i], i == 0)); } return buffer.toString(); } /** * Wrap an expression in parens if necessary. * @param expression other Expression * @param left whether expression is left of this one. * @return String */ private String parenthesize(Expression expression, boolean left) { String s = expression.toString(); if (!(expression instanceof CoreOperation)) { return s; } int compared = getPrecedence() - ((CoreOperation) expression).getPrecedence(); if (compared < 0) { return s; } if (compared == 0 && (isSymmetric() || left)) { return s; } return '(' + s + ')'; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationAdd.java100644 0 0 3442 11044113540 27176 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; /** * Implementation of {@link Expression} for the operation "+". * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class CoreOperationAdd extends CoreOperation { /** * Create a new CoreOperationAdd. * @param args Expression arguments to add together. */ public CoreOperationAdd(Expression[] args) { super(args); } public Object computeValue(EvalContext context) { double s = 0.0; for (int i = 0; i < args.length; i++) { s += InfoSetUtil.doubleValue(args[i].computeValue(context)); } return new Double(s); } protected int getPrecedence() { return ADD_PRECEDENCE; } protected boolean isSymmetric() { return true; } public String getSymbol() { return "+"; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationAnd.java100644 0 0 3451 11044113540 27210 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; /** * Implementation of {@link Expression} for the operation "and". * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class CoreOperationAnd extends CoreOperation { /** * Create a new CoreOperationAnd. * @param args to combine */ public CoreOperationAnd(Expression[] args) { super(args); } public Object computeValue(EvalContext context) { for (int i = 0; i < args.length; i++) { if (!InfoSetUtil.booleanValue(args[i].computeValue(context))) { return Boolean.FALSE; } } return Boolean.TRUE; } protected int getPrecedence() { return AND_PRECEDENCE; } protected boolean isSymmetric() { return true; } public String getSymbol() { return "and"; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationCompare.java100644 0 0 13413 11044113540 30113 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; import org.apache.commons.jxpath.ri.axes.InitialContext; import org.apache.commons.jxpath.ri.axes.SelfContext; /** * Common superclass for the implementations of Expression for the operations * "=" and "!=". * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public abstract class CoreOperationCompare extends CoreOperation { private boolean invert; /** * Create a new CoreOperationCompare. * @param arg1 left operand * @param arg2 right operand */ public CoreOperationCompare(Expression arg1, Expression arg2) { this(arg1, arg2, false); } /** * Create a new CoreOperationCompare. * @param arg1 left operand * @param arg2 right operand * @param invert whether to invert (not) the comparison */ protected CoreOperationCompare(Expression arg1, Expression arg2, boolean invert) { super(new Expression[] { arg1, arg2 }); this.invert = invert; } public Object computeValue(EvalContext context) { return equal(context, args[0], args[1]) ? Boolean.TRUE : Boolean.FALSE; } protected int getPrecedence() { return COMPARE_PRECEDENCE; } protected boolean isSymmetric() { return true; } /** * Compares two values. * @param context evaluation context * @param left operand * @param right operand * @return whether left = right in XPath terms */ protected boolean equal(EvalContext context, Expression left, Expression right) { Object l = left.compute(context); Object r = right.compute(context); if (l instanceof InitialContext) { ((EvalContext) l).reset(); } if (l instanceof SelfContext) { l = ((EvalContext) l).getSingleNodePointer(); } if (r instanceof InitialContext) { ((EvalContext) r).reset(); } if (r instanceof SelfContext) { r = ((EvalContext) r).getSingleNodePointer(); } if (l instanceof Collection) { l = ((Collection) l).iterator(); } if (r instanceof Collection) { r = ((Collection) r).iterator(); } if (l instanceof Iterator && r instanceof Iterator) { return findMatch((Iterator) l, (Iterator) r); } if (l instanceof Iterator) { return contains((Iterator) l, r); } if (r instanceof Iterator) { return contains((Iterator) r, l); } return equal(l, r); } /** * Learn whether it contains value. * @param it Iterator to check * @param value for which to look * @return whether value was found */ protected boolean contains(Iterator it, Object value) { while (it.hasNext()) { Object element = it.next(); if (equal(element, value)) { return true; } } return false; } /** * Learn whether lit intersects rit. * @param lit left Iterator * @param rit right Iterator * @return boolean */ protected boolean findMatch(Iterator lit, Iterator rit) { HashSet left = new HashSet(); while (lit.hasNext()) { left.add(lit.next()); } while (rit.hasNext()) { if (contains(left.iterator(), rit.next())) { return true; } } return false; } /** * Learn whether l equals r in XPath terms. * @param l left operand * @param r right operand * @return whether l = r */ protected boolean equal(Object l, Object r) { if (l instanceof Pointer) { l = ((Pointer) l).getValue(); } if (r instanceof Pointer) { r = ((Pointer) r).getValue(); } boolean result; if (l instanceof Boolean || r instanceof Boolean) { result = l == r || InfoSetUtil.booleanValue(l) == InfoSetUtil.booleanValue(r); } else if (l instanceof Number || r instanceof Number) { //if either side is NaN, no comparison returns true: double ld = InfoSetUtil.doubleValue(l); if (Double.isNaN(ld)) { return false; } double rd = InfoSetUtil.doubleValue(r); if (Double.isNaN(rd)) { return false; } result = ld == rd; } else { if (l instanceof String || r instanceof String) { l = InfoSetUtil.stringValue(l); r = InfoSetUtil.stringValue(r); } result = l == r || l != null && l.equals(r); } return result ^ invert; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationDivide.java100644 0 0 3534 11044113540 27714 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; /** * Implementation of {@link Expression} for the operation "div". * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class CoreOperationDivide extends CoreOperation { /** * Create a new CoreOperationDivide. * @param arg1 dividend * @param arg2 divisor */ public CoreOperationDivide(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return new Double(l / r); } protected int getPrecedence() { return MULTIPLY_PRECEDENCE; } protected boolean isSymmetric() { return false; } public String getSymbol() { return "div"; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationEqual.java100644 0 0 2604 11044113540 27554 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; /** * Implementation of {@link Expression} for the operation "=". * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class CoreOperationEqual extends CoreOperationCompare { /** * Create a new CoreOperationEqual * @param arg1 first comparison Expression * @param arg2 second comparison Expression */ public CoreOperationEqual(Expression arg1, Expression arg2) { super(arg1, arg2); } public String getSymbol() { return "="; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationGreaterThan.java100644 0 0 2766 11044113540 30722 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; /** * Implementation of {@link Expression} for the operation ">". * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression { /** * Create a new CoreOperationGreaterThan. * @param arg1 left operand * @param arg2 right operand */ public CoreOperationGreaterThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } protected boolean evaluateCompare(int compare) { return compare > 0; } public String getSymbol() { return ">"; } } ././@LongLink100644 0 0 153 11044114245 10246 Lustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationGreaterThanOrEqual.javacommons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationGreaterThanOrEqua100644 0 0 3017 11044113540 31105 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; /** * Implementation of {@link Expression} for the operation ">=". * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class CoreOperationGreaterThanOrEqual extends CoreOperationRelationalExpression { /** * Create a new CoreOperationGreaterThanOrEqual. * @param arg1 operand 1 * @param arg2 operand 2 */ public CoreOperationGreaterThanOrEqual(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } protected boolean evaluateCompare(int compare) { return compare >= 0; } public String getSymbol() { return ">="; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationLessThan.java100644 0 0 2763 11044113540 30234 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; /** * Implementation of {@link Expression} for the operation "<". * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class CoreOperationLessThan extends CoreOperationRelationalExpression { /** * Create a new CoreOperationLessThan. * @param arg1 left Expression * @param arg2 right Expression */ public CoreOperationLessThan(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } protected boolean evaluateCompare(int compare) { return compare < 0; } public String getSymbol() { return "<"; } } ././@LongLink100644 0 0 150 11044114245 10243 Lustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationLessThanOrEqual.javacommons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationLessThanOrEqual.j100644 0 0 3023 11044113540 31023 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; /** * Implementation of {@link Expression} for the operation "<=". * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class CoreOperationLessThanOrEqual extends CoreOperationRelationalExpression { /** * Create a new CoreOperationLessThanOrEqual. * @param arg1 left Expression * @param arg2 right Expression */ public CoreOperationLessThanOrEqual(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } protected boolean evaluateCompare(int compare) { return compare <= 0; } public String getSymbol() { return "<="; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationMod.java100644 0 0 3535 11044113540 27230 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; /** * Implementation of {@link Expression} for the operation "mod". * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class CoreOperationMod extends CoreOperation { /** * Create a new CoreOperationMod. * @param arg1 dividend * @param arg2 divisor */ public CoreOperationMod(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } public Object computeValue(EvalContext context) { long l = (long) InfoSetUtil.doubleValue(args[0].computeValue(context)); long r = (long) InfoSetUtil.doubleValue(args[1].computeValue(context)); return new Double(l % r); } protected int getPrecedence() { return MULTIPLY_PRECEDENCE; } protected boolean isSymmetric() { return false; } public String getSymbol() { return "mod"; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationMultiply.java100644 0 0 3536 11044113540 30331 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; /** * Implementation of {@link Expression} for the operation "*". * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class CoreOperationMultiply extends CoreOperation { /** * Create a new CoreOperationMultiply. * @param arg1 factor 1 * @param arg2 factor 2 */ public CoreOperationMultiply(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return new Double(l * r); } protected int getPrecedence() { return MULTIPLY_PRECEDENCE; } protected boolean isSymmetric() { return true; } public String getSymbol() { return "*"; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationNegate.java100644 0 0 3351 11044113540 27710 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; /** * Implementation of {@link Expression} for the operation unary "-". * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class CoreOperationNegate extends CoreOperation { /** * Create a new CoreOperationNegate. * @param arg the Expression to negate */ public CoreOperationNegate(Expression arg) { super(new Expression[] { arg }); } public Object computeValue(EvalContext context) { double a = InfoSetUtil.doubleValue(args[0].computeValue(context)); return new Double(-a); } protected int getPrecedence() { return NEGATE_PRECEDENCE; } protected boolean isSymmetric() { return false; } public String getSymbol() { return "-"; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationNotEqual.java100644 0 0 2570 11044113540 30237 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; /** * Implementation of {@link Expression} for the operation "!=". * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class CoreOperationNotEqual extends CoreOperationCompare { /** * Create a new CoreOperationNotEqual. * @param arg1 left operand * @param arg2 right operand */ public CoreOperationNotEqual(Expression arg1, Expression arg2) { super(arg1, arg2, true); } public String getSymbol() { return "!="; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationOr.java100644 0 0 3462 11044113540 27070 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; /** * Implementation of {@link Expression} for the operation "or". * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class CoreOperationOr extends CoreOperation { /** * Create a new CoreOperationOr. * @param args or'd Expression components */ public CoreOperationOr(Expression[] args) { super(args); } public Object computeValue(EvalContext context) { for (int i = 0; i < args.length; i++) { if (InfoSetUtil.booleanValue(args[i].computeValue(context))) { return Boolean.TRUE; } } return Boolean.FALSE; } protected int getPrecedence() { return OR_PRECEDENCE; } protected boolean isSymmetric() { return true; } public String getSymbol() { return "or"; } } ././@LongLink100644 0 0 155 11044114245 10250 Lustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationRelationalExpression.javacommons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationRelationalExpress100644 0 0 11300 11044113540 31242 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; import org.apache.commons.jxpath.ri.axes.InitialContext; import org.apache.commons.jxpath.ri.axes.SelfContext; /** * Base implementation of Expression for the operations ">", ">=", "<", "<=". * @since JXPath 1.3 * * @author Matt Benson * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public abstract class CoreOperationRelationalExpression extends CoreOperation { /** * Create a new CoreOperationRelationalExpression. * @param args arguments */ protected CoreOperationRelationalExpression(Expression[] args) { super(args); } public final Object computeValue(EvalContext context) { return compute(args[0].compute(context), args[1].compute(context)) ? Boolean.TRUE : Boolean.FALSE; } protected final int getPrecedence() { return RELATIONAL_EXPR_PRECEDENCE; } protected final boolean isSymmetric() { return false; } /** * Template method for subclasses to evaluate the result of a comparison. * @param compare result of comparison to evaluate * @return ultimate operation success/failure */ protected abstract boolean evaluateCompare(int compare); /** * Compare left to right. * @param left left operand * @param right right operand * @return operation success/failure */ private boolean compute(Object left, Object right) { left = reduce(left); right = reduce(right); if (left instanceof InitialContext) { ((InitialContext) left).reset(); } if (right instanceof InitialContext) { ((InitialContext) right).reset(); } if (left instanceof Iterator && right instanceof Iterator) { return findMatch((Iterator) left, (Iterator) right); } if (left instanceof Iterator) { return containsMatch((Iterator) left, right); } if (right instanceof Iterator) { return containsMatch((Iterator) right, left); } double ld = InfoSetUtil.doubleValue(left); if (Double.isNaN(ld)) { return false; } double rd = InfoSetUtil.doubleValue(right); if (Double.isNaN(rd)) { return false; } return evaluateCompare(ld == rd ? 0 : ld < rd ? -1 : 1); } /** * Reduce an operand for comparison. * @param o Object to reduce * @return reduced operand */ private Object reduce(Object o) { if (o instanceof SelfContext) { o = ((EvalContext) o).getSingleNodePointer(); } if (o instanceof Collection) { o = ((Collection) o).iterator(); } return o; } /** * Learn whether any element returned from an Iterator matches a given value. * @param it Iterator * @param value to look for * @return whether a match was found */ private boolean containsMatch(Iterator it, Object value) { while (it.hasNext()) { Object element = it.next(); if (compute(element, value)) { return true; } } return false; } /** * Learn whether there is an intersection between two Iterators. * @param lit left Iterator * @param rit right Iterator * @return whether a match was found */ private boolean findMatch(Iterator lit, Iterator rit) { HashSet left = new HashSet(); while (lit.hasNext()) { left.add(lit.next()); } while (rit.hasNext()) { if (containsMatch(left.iterator(), rit.next())) { return true; } } return false; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationSubtract.java100644 0 0 3533 11044113540 30276 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.InfoSetUtil; /** * Implementation of {@link Expression} for the operation "-". * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class CoreOperationSubtract extends CoreOperation { /** * Create a new CoreOperationSubtract. * @param arg1 minuend * @param arg2 subtrahend */ public CoreOperationSubtract(Expression arg1, Expression arg2) { super(new Expression[] { arg1, arg2 }); } public Object computeValue(EvalContext context) { double l = InfoSetUtil.doubleValue(args[0].computeValue(context)); double r = InfoSetUtil.doubleValue(args[1].computeValue(context)); return new Double(l - r); } protected int getPrecedence() { return ADD_PRECEDENCE; } protected boolean isSymmetric() { return false; } public String getSymbol() { return "-"; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationUnion.java100644 0 0 4061 11044113540 27574 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.axes.UnionContext; /** * Implementation of {@link Expression} for the operation "|". * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class CoreOperationUnion extends CoreOperation { /** * Create a new CoreOperationUnion. * @param args Expression[] */ public CoreOperationUnion(Expression[] args) { super(args); } public Object computeValue(EvalContext context) { EvalContext[] argCtxs = new EvalContext[args.length]; for (int i = 0; i < args.length; i++) { Object value = args[i].compute(context); if (value instanceof EvalContext) { argCtxs[i] = (EvalContext) value; } else { argCtxs[i] = context.getRootContext().getConstantContext(value); } } return new UnionContext(context.getRootContext(), argCtxs); } protected int getPrecedence() { return UNION_PRECEDENCE; } protected boolean isSymmetric() { return true; } public String getSymbol() { return "|"; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/Expression.java100644 0 0 14403 11044113540 26172 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.NodeSet; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.util.ValueUtils; import java.util.Collections; import java.util.Iterator; import java.util.Locale; /** * Common superclass for several types of nodes in the parse tree. Provides * APIs for optimization of evaluation of expressions. Specifically, an * expression only needs to executed once during the evaluation of an xpath * if that expression is context-independent. Expression.isContextDependent() * provides that hint. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public abstract class Expression { /** zero */ protected static final Double ZERO = new Double(0); /** one */ protected static final Double ONE = new Double(1); /** NaN */ protected static final Double NOT_A_NUMBER = new Double(Double.NaN); private boolean contextDependencyKnown = false; private boolean contextDependent; /** * Returns true if this expression should be re-evaluated * each time the current position in the context changes. * @return boolean */ public synchronized boolean isContextDependent() { if (!contextDependencyKnown) { contextDependent = computeContextDependent(); contextDependencyKnown = true; } return contextDependent; } /** * Implemented by subclasses and result is cached by isContextDependent() * @return calculated context-dependentness as boolean */ public abstract boolean computeContextDependent(); /** * Evaluates the expression. If the result is a node set, returns * the first element of the node set. * @param context evaluation context * @return Object */ public abstract Object computeValue(EvalContext context); /** * Evaluates the expression. If the result is a node set, returns * the first element of the node set. * @param context evaluation context * @return Object */ public abstract Object compute(EvalContext context); /** * Iterate over the values from the specified context. * @param context evaluation context * @return value Iterator */ public Iterator iterate(EvalContext context) { Object result = compute(context); if (result instanceof EvalContext) { return new ValueIterator((EvalContext) result); } if (result instanceof NodeSet) { return new ValueIterator(((NodeSet) result).getPointers().iterator()); } return ValueUtils.iterate(result); } /** * Iterate over the pointers from the specified context. * @param context evaluation context * @return pointer Iterator */ public Iterator iteratePointers(EvalContext context) { Object result = compute(context); if (result == null) { return Collections.EMPTY_LIST.iterator(); } if (result instanceof EvalContext) { return (EvalContext) result; } if (result instanceof NodeSet) { return new PointerIterator(((NodeSet) result).getPointers().iterator(), new QName(null, "value"), context.getRootContext().getCurrentNodePointer().getLocale()); } return new PointerIterator(ValueUtils.iterate(result), new QName(null, "value"), context.getRootContext().getCurrentNodePointer().getLocale()); } /** * Pointer iterator */ public static class PointerIterator implements Iterator { private Iterator iterator; private QName qname; private Locale locale; //to what method does the following comment refer? /** * Create a new PointerIterator * @param it underlying Iterator * @param qname name * @param locale Locale * @deprecated Use the method that takes a NamespaceManager */ public PointerIterator(Iterator it, QName qname, Locale locale) { this.iterator = it; this.qname = qname; this.locale = locale; } public boolean hasNext() { return iterator.hasNext(); } public Object next() { Object o = iterator.next(); return o instanceof Pointer ? o : NodePointer.newNodePointer(qname, o, locale); } /** * Unsupported. */ public void remove() { throw new UnsupportedOperationException(); } } /** * Value Iterator */ public static class ValueIterator implements Iterator { private Iterator iterator; /** * Create a new ValueIterator. * @param it underlying Iterator, may contain pointers */ public ValueIterator(Iterator it) { this.iterator = it; } public boolean hasNext() { return iterator.hasNext(); } public Object next() { Object o = iterator.next(); return o instanceof Pointer ? ((Pointer) o).getValue() : o; } /** * Unsupported. */ public void remove() { throw new UnsupportedOperationException(); } } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/ExpressionPath.java100644 0 0 15067 11044113540 27016 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.axes.InitialContext; import org.apache.commons.jxpath.ri.axes.NodeSetContext; import org.apache.commons.jxpath.ri.axes.PredicateContext; import org.apache.commons.jxpath.ri.axes.SimplePathInterpreter; import org.apache.commons.jxpath.ri.axes.UnionContext; import org.apache.commons.jxpath.ri.model.NodePointer; /** * An element of the parse tree that represents an expression path, which is a * path that starts with an expression like a function call: getFoo(.) * /bar. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class ExpressionPath extends Path { private Expression expression; private Expression[] predicates; private boolean basicKnown = false; private boolean basic; /** * Create a new ExpressionPath. * @param expression Expression * @param predicates to execute * @param steps navigation */ public ExpressionPath(Expression expression, Expression[] predicates, Step[] steps) { super(steps); this.expression = expression; this.predicates = predicates; } /** * Get the expression. * @return Expression */ public Expression getExpression() { return expression; } /** * Predicates are the expressions in brackets that may follow * the root expression of the path. * @return Expression[] */ public Expression[] getPredicates() { return predicates; } /** * Returns true if the root expression or any of the * predicates or the path steps are context dependent. * @return boolean */ public boolean computeContextDependent() { if (expression.isContextDependent()) { return true; } if (predicates != null) { for (int i = 0; i < predicates.length; i++) { if (predicates[i].isContextDependent()) { return true; } } } return super.computeContextDependent(); } /** * Recognized paths formatted as $x[3]/foo[2]. The * evaluation of such "simple" paths is optimized and streamlined. * @return boolean */ public synchronized boolean isSimpleExpressionPath() { if (!basicKnown) { basicKnown = true; basic = isSimplePath() && areBasicPredicates(getPredicates()); } return basic; } public String toString() { StringBuffer buffer = new StringBuffer(); if (expression instanceof CoreOperation || expression instanceof ExpressionPath || expression instanceof LocationPath) { buffer.append('('); buffer.append(expression); buffer.append(')'); } else { buffer.append(expression); } if (predicates != null) { for (int i = 0; i < predicates.length; i++) { buffer.append('['); buffer.append(predicates[i]); buffer.append(']'); } } Step[] steps = getSteps(); if (steps != null) { for (int i = 0; i < steps.length; i++) { buffer.append("/"); buffer.append(steps[i]); } } return buffer.toString(); } public Object compute(EvalContext context) { return expressionPath(context, false); } public Object computeValue(EvalContext context) { return expressionPath(context, true); } /** * Walks an expression path (a path that starts with an expression) * @param evalContext base context * @param firstMatch whether to return the first match found * @return Object found */ protected Object expressionPath(EvalContext evalContext, boolean firstMatch) { Object value = expression.compute(evalContext); EvalContext context; if (value instanceof InitialContext) { // This is an optimization. We can avoid iterating through a // collection if the context bean is in fact one. context = (InitialContext) value; } else if (value instanceof EvalContext) { // UnionContext will collect all values from the "value" context // and treat the whole thing as a big collection. context = new UnionContext( evalContext, new EvalContext[] {(EvalContext) value }); } else { context = evalContext.getRootContext().getConstantContext(value); } if (firstMatch && isSimpleExpressionPath() && !(context instanceof NodeSetContext)) { EvalContext ctx = context; NodePointer ptr = (NodePointer) ctx.getSingleNodePointer(); if (ptr != null && (ptr.getIndex() == NodePointer.WHOLE_COLLECTION || predicates == null || predicates.length == 0)) { return SimplePathInterpreter.interpretSimpleExpressionPath( evalContext, ptr, predicates, getSteps()); } } if (predicates != null) { for (int j = 0; j < predicates.length; j++) { if (j != 0) { context = new UnionContext(context, new EvalContext[]{context}); } context = new PredicateContext(context, predicates[j]); } } return firstMatch ? (Object) getSingleNodePointerForSteps(context) : evalSteps(context); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/ExtensionFunction.java100644 0 0 7321 11044113540 27476 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import java.util.Arrays; import org.apache.commons.jxpath.Function; import org.apache.commons.jxpath.JXPathFunctionNotFoundException; import org.apache.commons.jxpath.NodeSet; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.axes.NodeSetContext; /** * Represents an element of the parse tree representing an extension function * call. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class ExtensionFunction extends Operation { private QName functionName; /** * Create a new ExtensionFunction. * @param functionName name of the function * @param args Expression[] of function args */ public ExtensionFunction(QName functionName, Expression[] args) { super(args); this.functionName = functionName; } /** * Get the function name * @return QName */ public QName getFunctionName() { return functionName; } /** * An extension function gets the current context, therefore it MAY be * context dependent. * @return true */ public boolean computeContextDependent() { return true; } public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append(functionName); buffer.append('('); Expression[] args = getArguments(); if (args != null) { for (int i = 0; i < args.length; i++) { if (i > 0) { buffer.append(", "); } buffer.append(args[i]); } } buffer.append(')'); return buffer.toString(); } public Object compute(EvalContext context) { return computeValue(context); } public Object computeValue(EvalContext context) { Object[] parameters = null; if (args != null) { parameters = new Object[args.length]; for (int i = 0; i < args.length; i++) { parameters[i] = convert(args[i].compute(context)); } } Function function = context.getRootContext().getFunction(functionName, parameters); if (function == null) { throw new JXPathFunctionNotFoundException("No such function: " + functionName + Arrays.asList(parameters)); } Object result = function.invoke(context, parameters); return result instanceof NodeSet ? new NodeSetContext(context, (NodeSet) result) : result; } /** * Convert any incoming context to a value. * @param object Object to convert * @return context value or object unscathed. */ private Object convert(Object object) { return object instanceof EvalContext ? ((EvalContext) object).getValue() : object; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/LocationPath.java100644 0 0 5421 11044113540 26400 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.axes.InitialContext; /** * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class LocationPath extends Path { private boolean absolute; /** * Create a new LocationPath. * @param absolute whether this is an absolute path * @param steps to evaluate */ public LocationPath(boolean absolute, Step[] steps) { super(steps); this.absolute = absolute; } /** * Learn whether this LocationPath is absolute. * @return boolean */ public boolean isAbsolute() { return absolute; } public boolean computeContextDependent() { return !absolute || super.computeContextDependent(); } public String toString() { StringBuffer buffer = new StringBuffer(); Step[] steps = getSteps(); if (steps != null) { for (int i = 0; i < steps.length; i++) { if (i > 0 || absolute) { buffer.append('/'); } buffer.append(steps[i]); } } return buffer.toString(); } public Object compute(EvalContext context) { // Create a chain of contexts EvalContext rootContext; if (isAbsolute()) { rootContext = context.getRootContext().getAbsoluteRootContext(); } else { rootContext = new InitialContext(context); } return evalSteps(rootContext); } public Object computeValue(EvalContext context) { // Create a chain of contexts EvalContext rootContext; if (isAbsolute()) { rootContext = context.getRootContext().getAbsoluteRootContext(); } else { rootContext = new InitialContext(context); } return getSingleNodePointerForSteps(rootContext); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/NameAttributeTest.java100644 0 0 3173 11044113540 27421 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; /** * Captures the foo[@name=expr] expression. These * expressions are handled in a special way when applied to beans * or maps. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class NameAttributeTest extends CoreOperationEqual { /** * Create a new NameAttributeTest. * @param namePath Expression * @param nameValue Expression */ public NameAttributeTest(Expression namePath, Expression nameValue) { super(namePath, nameValue); } /** * Get the name test expression. * @return Expression */ public Expression getNameTestExpression() { return args[1]; } public boolean computeContextDependent() { return true; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/NodeNameTest.java100644 0 0 4034 11044113540 26340 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.ri.QName; /** * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class NodeNameTest extends NodeTest { private QName qname; private String namespaceURI; /** * Create a new NodeNameTest. * @param qname name to match */ public NodeNameTest(QName qname) { this.qname = qname; } /** * Create a new NodeNameTest. * @param qname name to match * @param namespaceURI uri to match */ public NodeNameTest(QName qname, String namespaceURI) { this.qname = qname; this.namespaceURI = namespaceURI; } /** * Get the node name. * @return QName */ public QName getNodeName() { return qname; } /** * Get the ns URI. * @return String */ public String getNamespaceURI() { return namespaceURI; } /** * Learn whether this is a wildcard test. * @return true if the node name is "*". */ public boolean isWildcard() { return qname.getName().equals("*"); } public String toString() { return qname.toString(); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/NodeTest.java100644 0 0 1757 11044113540 25550 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; /** * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public abstract class NodeTest { } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/NodeTypeTest.java100644 0 0 3772 11044113540 26411 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.ri.Compiler; /** * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class NodeTypeTest extends NodeTest { private int nodeType; /** * Create a new NodeTypeTest. * @param nodeType to match */ public NodeTypeTest(int nodeType) { this.nodeType = nodeType; } /** * Get the nodeType. * @return int */ public int getNodeType() { return nodeType; } public String toString() { return nodeTypeToString(nodeType) + "()"; } /** * Render the given node type as a String. * @param code int * @return String */ public static String nodeTypeToString(int code) { switch (code) { case Compiler.NODE_TYPE_NODE : return "node"; case Compiler.NODE_TYPE_TEXT : return "text"; case Compiler.NODE_TYPE_COMMENT : return "comment"; case Compiler.NODE_TYPE_PI : return "processing-instruction"; default: return "UNKNOWN"; } } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/Operation.java100644 0 0 3212 11044113540 25747 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; /** * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public abstract class Operation extends Expression { /** Expression[] of arguments */ protected Expression[] args; /** * Create a new Operation. * @param args Expression[] */ public Operation(Expression[] args) { this.args = args; } /** * Get the arguments. * @return Expression[] */ public Expression[] getArguments() { return args; } public boolean computeContextDependent() { if (args != null) { for (int i = 0; i < args.length; i++) { if (args[i].isContextDependent()) { return true; } } } return false; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/package.html100644 0 0 1644 11044113540 25434 0ustar 0 0 XPath parse tree. TreeCompiler is the class responsible for the construction of a parse tree out of individual elements. commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/Path.java100644 0 0 27602 11044113540 24734 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.Compiler; import org.apache.commons.jxpath.ri.EvalContext; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.axes.AncestorContext; import org.apache.commons.jxpath.ri.axes.AttributeContext; import org.apache.commons.jxpath.ri.axes.ChildContext; import org.apache.commons.jxpath.ri.axes.DescendantContext; import org.apache.commons.jxpath.ri.axes.InitialContext; import org.apache.commons.jxpath.ri.axes.NamespaceContext; import org.apache.commons.jxpath.ri.axes.ParentContext; import org.apache.commons.jxpath.ri.axes.PrecedingOrFollowingContext; import org.apache.commons.jxpath.ri.axes.PredicateContext; import org.apache.commons.jxpath.ri.axes.SelfContext; import org.apache.commons.jxpath.ri.axes.SimplePathInterpreter; import org.apache.commons.jxpath.ri.axes.UnionContext; import org.apache.commons.jxpath.ri.model.NodePointer; /** * @author Dmitri Plotnikov * @version $Revision: 681111 $ $Date: 2008-07-30 11:30:29 -0500 (Wed, 30 Jul 2008) $ */ public abstract class Path extends Expression { private Step[] steps; private boolean basicKnown = false; private boolean basic; /** * Create a new Path. * @param steps that compose the Path */ public Path(Step[] steps) { this.steps = steps; } /** * Get the steps. * @return Step[] */ public Step[] getSteps() { return steps; } public boolean computeContextDependent() { if (steps != null) { for (int i = 0; i < steps.length; i++) { if (steps[i].isContextDependent()) { return true; } } } return false; } /** * Recognizes paths formatted as foo/bar[3]/baz[@name = 'biz']. * The evaluation of such "simple" paths is optimized and * streamlined. * @return true if this path is simple */ public synchronized boolean isSimplePath() { if (!basicKnown) { basicKnown = true; basic = true; Step[] steps = getSteps(); for (int i = 0; i < steps.length; i++) { if (!isSimpleStep(steps[i])) { basic = false; break; } } } return basic; } /** * A Step is "simple" if it takes one of these forms: ".", "/foo", * "@bar", "/foo[3]". If there are predicates, they should be * context independent for the step to still be considered simple. * @param step the step to check * @return boolean */ protected boolean isSimpleStep(Step step) { if (step.getAxis() == Compiler.AXIS_SELF) { NodeTest nodeTest = step.getNodeTest(); if (!(nodeTest instanceof NodeTypeTest)) { return false; } int nodeType = ((NodeTypeTest) nodeTest).getNodeType(); if (nodeType != Compiler.NODE_TYPE_NODE) { return false; } return areBasicPredicates(step.getPredicates()); } if (step.getAxis() == Compiler.AXIS_CHILD || step.getAxis() == Compiler.AXIS_ATTRIBUTE) { NodeTest nodeTest = step.getNodeTest(); if (!(nodeTest instanceof NodeNameTest)) { return false; } if (((NodeNameTest) nodeTest).isWildcard()) { return false; } return areBasicPredicates(step.getPredicates()); } return false; } /** * Learn whether the elements of the specified array are "basic" predicates. * @param predicates the Expression[] to check * @return boolean */ protected boolean areBasicPredicates(Expression[] predicates) { if (predicates != null && predicates.length != 0) { boolean firstIndex = true; for (int i = 0; i < predicates.length; i++) { if (predicates[i] instanceof NameAttributeTest) { if (((NameAttributeTest) predicates[i]) .getNameTestExpression() .isContextDependent()) { return false; } } else if (predicates[i].isContextDependent()) { return false; } else { if (!firstIndex) { return false; } firstIndex = false; } } } return true; } /** * Given a root context, walks a path therefrom and finds the * pointer to the first element matching the path. * @param context evaluation context * @return Pointer */ protected Pointer getSingleNodePointerForSteps(EvalContext context) { if (steps.length == 0) { return context.getSingleNodePointer(); } if (isSimplePath()) { NodePointer ptr = (NodePointer) context.getSingleNodePointer(); return SimplePathInterpreter.interpretSimpleLocationPath( context, ptr, steps); } return searchForPath(context); } /** * The idea here is to return a NullPointer rather than null if that's at * all possible. Take for example this path: "//map/key". Let's say, "map" * is an existing node, but "key" is not there. We will create a * NullPointer that can be used to set/create the "key" property. *

* However, a path like "//key" would still produce null, because we have * no way of knowing where "key" would be if it existed. *

*

* To accomplish this, we first try the path itself. If it does not find * anything, we chop off last step of the path, as long as it is a simple * one like child:: or attribute:: and try to evaluate the truncated path. * If it finds exactly one node - create a NullPointer and return. If it * fails, chop off another step and repeat. If it finds more than one * location - return null. *

* @param context evaluation context * @return Pointer */ protected Pointer searchForPath(EvalContext context) { EvalContext ctx = buildContextChain(context, steps.length, true); Pointer pointer = ctx.getSingleNodePointer(); if (pointer != null) { return pointer; } for (int i = steps.length; --i > 0;) { if (!isSimpleStep(steps[i])) { return null; } ctx = buildContextChain(context, i, true); if (ctx.hasNext()) { Pointer partial = (Pointer) ctx.next(); if (ctx.hasNext()) { // If we find another location - the search is // ambiguous, so we report failure return null; } if (partial instanceof NodePointer) { return SimplePathInterpreter.createNullPointer( context, (NodePointer) partial, steps, i); } } } return null; } /** * Given a root context, walks a path therefrom and builds a context * that contains all nodes matching the path. * @param context evaluation context * @return EvaluationContext */ protected EvalContext evalSteps(EvalContext context) { return buildContextChain(context, steps.length, false); } /** * Build a context from a chain of contexts. * @param context evaluation context * @param stepCount number of steps to descend * @param createInitialContext whether to create the initial context * @return created context */ protected EvalContext buildContextChain( EvalContext context, int stepCount, boolean createInitialContext) { if (createInitialContext) { context = new InitialContext(context); } if (steps.length == 0) { return context; } for (int i = 0; i < stepCount; i++) { context = createContextForStep( context, steps[i].getAxis(), steps[i].getNodeTest()); Expression[] predicates = steps[i].getPredicates(); if (predicates != null) { for (int j = 0; j < predicates.length; j++) { if (j != 0) { context = new UnionContext(context, new EvalContext[]{context}); } context = new PredicateContext(context, predicates[j]); } } } return context; } /** * Different axes are serviced by different contexts. This method * allocates the right context for the supplied step. * @param context evaluation context * @param axis code * @param nodeTest node test * @return EvalContext */ protected EvalContext createContextForStep( EvalContext context, int axis, NodeTest nodeTest) { if (nodeTest instanceof NodeNameTest) { QName qname = ((NodeNameTest) nodeTest).getNodeName(); String prefix = qname.getPrefix(); if (prefix != null) { String namespaceURI = context.getJXPathContext() .getNamespaceURI(prefix); nodeTest = new NodeNameTest(qname, namespaceURI); } } switch (axis) { case Compiler.AXIS_ANCESTOR : return new AncestorContext(context, false, nodeTest); case Compiler.AXIS_ANCESTOR_OR_SELF : return new AncestorContext(context, true, nodeTest); case Compiler.AXIS_ATTRIBUTE : return new AttributeContext(context, nodeTest); case Compiler.AXIS_CHILD : return new ChildContext(context, nodeTest, false, false); case Compiler.AXIS_DESCENDANT : return new DescendantContext(context, false, nodeTest); case Compiler.AXIS_DESCENDANT_OR_SELF : return new DescendantContext(context, true, nodeTest); case Compiler.AXIS_FOLLOWING : return new PrecedingOrFollowingContext(context, nodeTest, false); case Compiler.AXIS_FOLLOWING_SIBLING : return new ChildContext(context, nodeTest, true, false); case Compiler.AXIS_NAMESPACE : return new NamespaceContext(context, nodeTest); case Compiler.AXIS_PARENT : return new ParentContext(context, nodeTest); case Compiler.AXIS_PRECEDING : return new PrecedingOrFollowingContext(context, nodeTest, true); case Compiler.AXIS_PRECEDING_SIBLING : return new ChildContext(context, nodeTest, true, true); case Compiler.AXIS_SELF : return new SelfContext(context, nodeTest); default: return null; // Never happens } } } ././@LongLink100644 0 0 145 11044114245 10247 Lustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/ProcessingInstructionTest.javacommons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/ProcessingInstructionTest.java100644 0 0 2665 11044113540 31240 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; /** * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class ProcessingInstructionTest extends NodeTest { private String target; /** * Create a new ProcessingInstructionTest. * @param target string */ public ProcessingInstructionTest(String target) { this.target = target; } /** * Get the target. * @return String */ public String getTarget() { return target; } public String toString() { return "processing-instruction('" + target + "')"; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/Step.java100644 0 0 12250 11044113540 24744 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.ri.Compiler; /** * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class Step { private int axis; private NodeTest nodeTest; private Expression[] predicates; /** * Create a new Step. * @param axis axis code * @param nodeTest step test * @param predicates predicate expressions */ protected Step(int axis, NodeTest nodeTest, Expression[] predicates) { this.axis = axis; this.nodeTest = nodeTest; this.predicates = predicates; } /** * Get the axis code. * @return int */ public int getAxis() { return axis; } /** * Get the step test. * @return NodeTest */ public NodeTest getNodeTest() { return nodeTest; } /** * Get the predicates. * @return Expression[] */ public Expression[] getPredicates() { return predicates; } /** * Learn whether this step contains any predicate that is context dependent. * @return boolean */ public boolean isContextDependent() { if (predicates != null) { for (int i = 0; i < predicates.length; i++) { if (predicates[i].isContextDependent()) { return true; } } } return false; } public String toString() { StringBuffer buffer = new StringBuffer(); int axis = getAxis(); if (axis == Compiler.AXIS_CHILD) { buffer.append(nodeTest); } else if (axis == Compiler.AXIS_ATTRIBUTE) { buffer.append('@'); buffer.append(nodeTest); } else if (axis == Compiler.AXIS_SELF && nodeTest instanceof NodeTypeTest && ((NodeTypeTest) nodeTest).getNodeType() == Compiler.NODE_TYPE_NODE) { buffer.append("."); } else if (axis == Compiler.AXIS_PARENT && nodeTest instanceof NodeTypeTest && ((NodeTypeTest) nodeTest).getNodeType() == Compiler.NODE_TYPE_NODE) { buffer.append(".."); } else if (axis == Compiler.AXIS_DESCENDANT_OR_SELF && nodeTest instanceof NodeTypeTest && ((NodeTypeTest) nodeTest).getNodeType() == Compiler.NODE_TYPE_NODE && (predicates == null || predicates.length == 0)) { buffer.append(""); } else { buffer.append(axisToString(axis)); buffer.append("::"); buffer.append(nodeTest); } Expression[] predicates = getPredicates(); if (predicates != null) { for (int i = 0; i < predicates.length; i++) { buffer.append('['); buffer.append(predicates[i]); buffer.append(']'); } } return buffer.toString(); } /** * Decode an axis code to its name. * @param axis int code * @return String name. * @see Compiler * @see http://www.w3.org/TR/xpath#axes */ public static String axisToString(int axis) { switch (axis) { case Compiler.AXIS_SELF : return "self"; case Compiler.AXIS_CHILD : return "child"; case Compiler.AXIS_PARENT : return "parent"; case Compiler.AXIS_ANCESTOR : return "ancestor"; case Compiler.AXIS_ATTRIBUTE : return "attribute"; case Compiler.AXIS_NAMESPACE : return "namespace"; case Compiler.AXIS_PRECEDING : return "preceding"; case Compiler.AXIS_FOLLOWING : return "following"; case Compiler.AXIS_DESCENDANT : return "descendant"; case Compiler.AXIS_ANCESTOR_OR_SELF : return "ancestor-or-self"; case Compiler.AXIS_FOLLOWING_SIBLING : return "following-sibling"; case Compiler.AXIS_PRECEDING_SIBLING : return "preceding-sibling"; case Compiler.AXIS_DESCENDANT_OR_SELF : return "descendant-or-self"; default: return "UNKNOWN"; } } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/TreeCompiler.java100644 0 0 15042 11044113540 26425 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.ri.Compiler; import org.apache.commons.jxpath.ri.QName; /** * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class TreeCompiler implements Compiler { private static final QName QNAME_NAME = new QName(null, "name"); public Object number(String value) { return new Constant(new Double(value)); } public Object literal(String value) { return new Constant(value); } public Object qname(String prefix, String name) { return new QName(prefix, name); } public Object sum(Object[] arguments) { return new CoreOperationAdd(toExpressionArray(arguments)); } public Object minus(Object left, Object right) { return new CoreOperationSubtract( (Expression) left, (Expression) right); } public Object multiply(Object left, Object right) { return new CoreOperationMultiply((Expression) left, (Expression) right); } public Object divide(Object left, Object right) { return new CoreOperationDivide((Expression) left, (Expression) right); } public Object mod(Object left, Object right) { return new CoreOperationMod((Expression) left, (Expression) right); } public Object lessThan(Object left, Object right) { return new CoreOperationLessThan((Expression) left, (Expression) right); } public Object lessThanOrEqual(Object left, Object right) { return new CoreOperationLessThanOrEqual( (Expression) left, (Expression) right); } public Object greaterThan(Object left, Object right) { return new CoreOperationGreaterThan( (Expression) left, (Expression) right); } public Object greaterThanOrEqual(Object left, Object right) { return new CoreOperationGreaterThanOrEqual( (Expression) left, (Expression) right); } public Object equal(Object left, Object right) { return isNameAttributeTest((Expression) left) ? new NameAttributeTest((Expression) left, (Expression) right) : new CoreOperationEqual((Expression) left, (Expression) right); } public Object notEqual(Object left, Object right) { return new CoreOperationNotEqual((Expression) left, (Expression) right); } public Object minus(Object argument) { return new CoreOperationNegate((Expression) argument); } public Object variableReference(Object qName) { return new VariableReference((QName) qName); } public Object function(int code, Object[] args) { return new CoreFunction(code, toExpressionArray(args)); } public Object function(Object name, Object[] args) { return new ExtensionFunction((QName) name, toExpressionArray(args)); } public Object and(Object[] arguments) { return new CoreOperationAnd(toExpressionArray(arguments)); } public Object or(Object[] arguments) { return new CoreOperationOr(toExpressionArray(arguments)); } public Object union(Object[] arguments) { return new CoreOperationUnion(toExpressionArray(arguments)); } public Object locationPath(boolean absolute, Object[] steps) { return new LocationPath(absolute, toStepArray(steps)); } public Object expressionPath(Object expression, Object[] predicates, Object[] steps) { return new ExpressionPath( (Expression) expression, toExpressionArray(predicates), toStepArray(steps)); } public Object nodeNameTest(Object qname) { return new NodeNameTest((QName) qname); } public Object nodeTypeTest(int nodeType) { return new NodeTypeTest(nodeType); } public Object processingInstructionTest(String instruction) { return new ProcessingInstructionTest(instruction); } public Object step(int axis, Object nodeTest, Object[] predicates) { return new Step( axis, (NodeTest) nodeTest, toExpressionArray(predicates)); } /** * Get an Object[] as an Expression[]. * @param array Object[] * @return Expression[] */ private Expression[] toExpressionArray(Object[] array) { Expression[] expArray = null; if (array != null) { expArray = new Expression[array.length]; for (int i = 0; i < expArray.length; i++) { expArray[i] = (Expression) array[i]; } } return expArray; } /** * Get an Object[] as a Step[]. * @param array Object[] * @return Step[] */ private Step[] toStepArray(Object[] array) { Step[] stepArray = null; if (array != null) { stepArray = new Step[array.length]; for (int i = 0; i < stepArray.length; i++) { stepArray[i] = (Step) array[i]; } } return stepArray; } /** * Learn whether arg is a name attribute test. * @param arg Expression to test * @return boolean */ private boolean isNameAttributeTest(Expression arg) { if (!(arg instanceof LocationPath)) { return false; } Step[] steps = ((LocationPath) arg).getSteps(); if (steps.length != 1) { return false; } if (steps[0].getAxis() != Compiler.AXIS_ATTRIBUTE) { return false; } NodeTest test = steps[0].getNodeTest(); if (!(test instanceof NodeNameTest)) { return false; } if (!((NodeNameTest) test).getNodeName().equals(QNAME_NAME)) { return false; } return true; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/compiler/VariableReference.java100644 0 0 4115 11044113540 27356 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.EvalContext; /** * An element of the compile tree holding a variable reference. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class VariableReference extends Expression { private QName varName; /** * Create a new VariableReference. * @param varName variable name */ public VariableReference(QName varName) { this.varName = varName; } /** * Get the variable name. * @return QName */ public QName getVariableName() { return varName; } public String toString() { return "$" + varName; } public boolean isContextDependent() { return false; } public boolean computeContextDependent() { return false; } public Object compute(EvalContext context) { return computeValue(context); } /** * Returns the value of the variable. * @param context EvalContext against which to compute the variable's value. * @return Object */ public Object computeValue(EvalContext context) { return context.getRootContext().getVariableContext(varName); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/Compiler.java100644 0 0 26444 11044113541 24004 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri; /** * The Compiler APIs are completely agnostic to the actual types of objects * produced and consumed by the APIs. Arguments and return values are * declared as java.lang.Object. *

* Since objects returned by Compiler methods are passed as arguments to other * Compiler methods, the descriptions of these methods use virtual types. There * are four virtual object types: EXPRESSION, QNAME, STEP and NODE_TEST. *

* The following example illustrates this notion. This sequence compiles * the xpath "foo[round(1 div 2)]/text()": *

 *      Object qname1 = compiler.qname(null, "foo")
 *      Object expr1 = compiler.number("1");
 *      Object expr2 = compiler.number("2");
 *      Object expr3 = compiler.div(expr1, expr2);
 *      Object expr4 = compiler.
 *              coreFunction(Compiler.FUNCTION_ROUND, new Object[]{expr3});
 *      Object test1 = compiler.nodeNameTest(qname1);
 *      Object step1 = compiler.
 *              step(Compiler.AXIS_CHILD, test1, new Object[]{expr4});
 *      Object test2 = compiler.nodeTypeTest(Compiler.NODE_TYPE_TEXT);
 *      Object step2 = compiler.nodeTypeTest(Compiler.AXIS_CHILD, test2, null);
 *      Object expr5 = compiler.locationPath(false, new Object[]{step1, step2});
 * 
* * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public interface Compiler { public static final int NODE_TYPE_NODE = 1; public static final int NODE_TYPE_TEXT = 2; public static final int NODE_TYPE_COMMENT = 3; public static final int NODE_TYPE_PI = 4; public static final int AXIS_SELF = 1; public static final int AXIS_CHILD = 2; public static final int AXIS_PARENT = 3; public static final int AXIS_ANCESTOR = 4; public static final int AXIS_ATTRIBUTE = 5; public static final int AXIS_NAMESPACE = 6; public static final int AXIS_PRECEDING = 7; public static final int AXIS_FOLLOWING = 8; public static final int AXIS_DESCENDANT = 9; public static final int AXIS_ANCESTOR_OR_SELF = 10; public static final int AXIS_FOLLOWING_SIBLING = 11; public static final int AXIS_PRECEDING_SIBLING = 12; public static final int AXIS_DESCENDANT_OR_SELF = 13; public static final int FUNCTION_LAST = 1; public static final int FUNCTION_POSITION = 2; public static final int FUNCTION_COUNT = 3; public static final int FUNCTION_ID = 4; public static final int FUNCTION_LOCAL_NAME = 5; public static final int FUNCTION_NAMESPACE_URI = 6; public static final int FUNCTION_NAME = 7; public static final int FUNCTION_STRING = 8; public static final int FUNCTION_CONCAT = 9; public static final int FUNCTION_STARTS_WITH = 10; public static final int FUNCTION_CONTAINS = 11; public static final int FUNCTION_SUBSTRING_BEFORE = 12; public static final int FUNCTION_SUBSTRING_AFTER = 13; public static final int FUNCTION_SUBSTRING = 14; public static final int FUNCTION_STRING_LENGTH = 15; public static final int FUNCTION_NORMALIZE_SPACE = 16; public static final int FUNCTION_TRANSLATE = 17; public static final int FUNCTION_BOOLEAN = 18; public static final int FUNCTION_NOT = 19; public static final int FUNCTION_TRUE = 20; public static final int FUNCTION_FALSE = 21; public static final int FUNCTION_LANG = 22; public static final int FUNCTION_NUMBER = 23; public static final int FUNCTION_SUM = 24; public static final int FUNCTION_FLOOR = 25; public static final int FUNCTION_CEILING = 26; public static final int FUNCTION_ROUND = 27; public static final int FUNCTION_NULL = 28; public static final int FUNCTION_KEY = 29; public static final int FUNCTION_FORMAT_NUMBER = 30; /** * Produces an EXPRESSION object that represents a numeric constant. * @param value numeric String * @return Object */ Object number(String value); /** * Produces an EXPRESSION object that represents a string constant. * @param value String literal * @return Object */ Object literal(String value); /** * Produces an QNAME that represents a name with an optional prefix. * @param prefix String prefix * @param name String name * @return Object */ Object qname(String prefix, String name); /** * Produces an EXPRESSION object representing the sum of all argumens * * @param arguments are EXPRESSION objects * @return Object */ Object sum(Object[] arguments); /** * Produces an EXPRESSION object representing left minus right * * @param left is an EXPRESSION object * @param right is an EXPRESSION object * @return Object */ Object minus(Object left, Object right); /** * Produces an EXPRESSION object representing left multiplied by * right * * @param left is an EXPRESSION object * @param right is an EXPRESSION object * @return Object */ Object multiply(Object left, Object right); /** * Produces an EXPRESSION object representing left divided by * right * * @param left is an EXPRESSION object * @param right is an EXPRESSION object * @return Object */ Object divide(Object left, Object right); /** * Produces an EXPRESSION object representing left modulo * right * * @param left is an EXPRESSION object * @param right is an EXPRESSION object * @return Object */ Object mod(Object left, Object right); /** * Produces an EXPRESSION object representing the comparison: * left less than right * * @param left is an EXPRESSION object * @param right is an EXPRESSION object * @return Object */ Object lessThan(Object left, Object right); /** * Produces an EXPRESSION object representing the comparison: * left less than or equal to right * * @param left is an EXPRESSION object * @param right is an EXPRESSION object * @return Object */ Object lessThanOrEqual(Object left, Object right); /** * Produces an EXPRESSION object representing the comparison: * left greater than right * * @param left is an EXPRESSION object * @param right is an EXPRESSION object * @return Object */ Object greaterThan(Object left, Object right); /** * Produces an EXPRESSION object representing the comparison: * left greater than or equal to right * * @param left is an EXPRESSION object * @param right is an EXPRESSION object * @return Object */ Object greaterThanOrEqual(Object left, Object right); /** * Produces an EXPRESSION object representing the comparison: * left equals to right * * @param left is an EXPRESSION object * @param right is an EXPRESSION object * @return Object */ Object equal(Object left, Object right); /** * Produces an EXPRESSION object representing the comparison: * left is not equal to right * * @param left is an EXPRESSION object * @param right is an EXPRESSION object * @return Object */ Object notEqual(Object left, Object right); /** * Produces an EXPRESSION object representing unary negation of the argument * * @param argument is an EXPRESSION object * @return Object */ Object minus(Object argument); /** * Produces an EXPRESSION object representing variable reference * * @param qname is a QNAME object * @return Object */ Object variableReference(Object qname); /** * Produces an EXPRESSION object representing the computation of * a core function with the supplied arguments. * * @param code is one of FUNCTION_... constants * @param args are EXPRESSION objects * @return Object */ Object function(int code, Object[] args); /** * Produces an EXPRESSION object representing the computation of * a library function with the supplied arguments. * * @param name is a QNAME object (function name) * @param args are EXPRESSION objects * @return Object */ Object function(Object name, Object[] args); /** * Produces an EXPRESSION object representing logical conjunction of * all arguments * * @param arguments are EXPRESSION objects * @return Object */ Object and(Object[] arguments); /** * Produces an EXPRESSION object representing logical disjunction of * all arguments * * @param arguments are EXPRESSION objects * @return Object */ Object or(Object[] arguments); /** * Produces an EXPRESSION object representing union of all node sets * * @param arguments are EXPRESSION objects * @return Object */ Object union(Object[] arguments); /** * Produces a NODE_TEST object that represents a node name test. * * @param qname is a QNAME object * @return Object */ Object nodeNameTest(Object qname); /** * Produces a NODE_TEST object that represents a node type test. * * @param nodeType is a NODE_TEST object * @return Object */ Object nodeTypeTest(int nodeType); /** * Produces a NODE_TEST object that represents a processing instruction * test. * * @param instruction is a NODE_TEST object * @return Object */ Object processingInstructionTest(String instruction); /** * Produces a STEP object that represents a node test. * * @param axis is one of the AXIS_... constants * @param nodeTest is a NODE_TEST object * @param predicates are EXPRESSION objects * @return Object */ Object step(int axis, Object nodeTest, Object[] predicates); /** * Produces an EXPRESSION object representing a location path * * @param absolute indicates whether the path is absolute * @param steps are STEP objects * @return Object */ Object locationPath(boolean absolute, Object[] steps); /** * Produces an EXPRESSION object representing a filter expression * * @param expression is an EXPRESSION object * @param predicates are EXPRESSION objects * @param steps are STEP objects * @return Object */ Object expressionPath( Object expression, Object[] predicates, Object[] steps); } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/EvalContext.java100644 0 0 25577 11044113541 24474 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; import org.apache.commons.jxpath.BasicNodeSet; import org.apache.commons.jxpath.ExpressionContext; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathException; import org.apache.commons.jxpath.NodeSet; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.axes.RootContext; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.util.ReverseComparator; /** * An XPath evaluation context. * * When evaluating a path, a chain of EvalContexts is created, each context in * the chain representing a step of the path. Subclasses of EvalContext * implement behavior of various XPath axes: "child::", "parent::" etc. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public abstract class EvalContext implements ExpressionContext, Iterator { /** parent context */ protected EvalContext parentContext; /** root context */ protected RootContext rootContext; /** position */ protected int position = 0; private boolean startedSetIteration = false; private boolean done = false; private boolean hasPerformedIteratorStep = false; private Iterator pointerIterator; /** * Create a new EvalContext. * @param parentContext parent context */ public EvalContext(EvalContext parentContext) { this.parentContext = parentContext; } public Pointer getContextNodePointer() { return getCurrentNodePointer(); } public JXPathContext getJXPathContext() { return getRootContext().getJXPathContext(); } public int getPosition() { return position; } /** * Determines the document order for this context. * * @return 1 ascending order, -1 descending order, * 0 - does not require ordering */ public int getDocumentOrder() { return parentContext != null && parentContext.isChildOrderingRequired() ? 1 : 0; } /** * Even if this context has the natural ordering and therefore does * not require collecting and sorting all nodes prior to returning them, * such operation may be required for any child context. * @return boolean */ public boolean isChildOrderingRequired() { // Default behavior: if this context needs to be ordered, // the children need to be ordered too return getDocumentOrder() != 0; } /** * Returns true if there are mode nodes matching the context's constraints. * @return boolean */ public boolean hasNext() { if (pointerIterator != null) { return pointerIterator.hasNext(); } if (getDocumentOrder() != 0) { return constructIterator(); } if (!done && !hasPerformedIteratorStep) { performIteratorStep(); } return !done; } /** * Returns the next node pointer in the context * @return Object */ public Object next() { if (pointerIterator != null) { return pointerIterator.next(); } if (getDocumentOrder() != 0) { if (!constructIterator()) { throw new NoSuchElementException(); } return pointerIterator.next(); } if (!done && !hasPerformedIteratorStep) { performIteratorStep(); } if (done) { throw new NoSuchElementException(); } hasPerformedIteratorStep = false; return getCurrentNodePointer(); } /** * Moves the iterator forward by one position */ private void performIteratorStep() { done = true; if (position != 0 && nextNode()) { done = false; } else { while (nextSet()) { if (nextNode()) { done = false; break; } } } hasPerformedIteratorStep = true; } /** * Operation is not supported * @throws UnsupportedOperationException */ public void remove() { throw new UnsupportedOperationException( "JXPath iterators cannot remove nodes"); } /** * Construct an iterator. * @return whether the Iterator was constructed */ private boolean constructIterator() { HashSet set = new HashSet(); ArrayList list = new ArrayList(); while (nextSet()) { while (nextNode()) { NodePointer pointer = getCurrentNodePointer(); if (!set.contains(pointer)) { set.add(pointer); list.add(pointer); } } } if (list.isEmpty()) { return false; } sortPointers(list); pointerIterator = list.iterator(); return true; } /** * Sort a list of pointers based on document order. * @param l the list to sort. */ protected void sortPointers(List l) { switch (getDocumentOrder()) { case 1: Collections.sort(l); break; case -1: Collections.sort(l, ReverseComparator.INSTANCE); break; default: } } /** * Returns the list of all Pointers in this context for the current * position of the parent context. * @return List */ public List getContextNodeList() { int pos = position; if (pos != 0) { reset(); } List list = new ArrayList(); while (nextNode()) { list.add(getCurrentNodePointer()); } if (pos != 0) { setPosition(pos); } else { reset(); } return list; } /** * Returns the list of all Pointers in this context for all positions * of the parent contexts. If there was an ongoing iteration over * this context, the method should not be called. * @return NodeSet */ public NodeSet getNodeSet() { if (position != 0) { throw new JXPathException( "Simultaneous operations: " + "should not request pointer list while " + "iterating over an EvalContext"); } BasicNodeSet set = new BasicNodeSet(); while (nextSet()) { while (nextNode()) { set.add((Pointer) getCurrentNodePointer().clone()); } } return set; } /** * Typically returns the NodeSet by calling getNodeSet(), * but will be overridden for contexts that more naturally produce * individual values, e.g. VariableContext * @return Object */ public Object getValue() { return getNodeSet(); } public String toString() { Pointer ptr = getContextNodePointer(); return ptr == null ? "Empty expression context" : "Expression context [" + getPosition() + "] " + ptr.asPath(); } /** * Returns the root context of the path, which provides easy * access to variables and functions. * @return RootContext */ public RootContext getRootContext() { if (rootContext == null) { rootContext = parentContext.getRootContext(); } return rootContext; } /** * Sets current position = 0, which is the pre-iteration state. */ public void reset() { position = 0; } /** * Get the current position. * @return int position. */ public int getCurrentPosition() { return position; } /** * Returns the first encountered Pointer that matches the current * context's criteria. * @return Pointer */ public Pointer getSingleNodePointer() { reset(); while (nextSet()) { if (nextNode()) { return getCurrentNodePointer(); } } return null; } /** * Returns the current context node. Undefined before the beginning * of the iteration. * @return NodePoiner */ public abstract NodePointer getCurrentNodePointer(); /** * Returns true if there is another sets of objects to interate over. * Resets the current position and node. * @return boolean */ public boolean nextSet() { reset(); // Restart iteration within the set // Most of the time you have one set per parent node // First time this method is called, we should look for // the first parent set that contains at least one node. if (!startedSetIteration) { startedSetIteration = true; while (parentContext.nextSet()) { if (parentContext.nextNode()) { return true; } } return false; } // In subsequent calls, we see if the parent context // has any nodes left in the current set if (parentContext.nextNode()) { return true; } // If not, we look for the next set that contains // at least one node while (parentContext.nextSet()) { if (parentContext.nextNode()) { return true; } } return false; } /** * Returns true if there is another object in the current set. * Switches the current position and node to the next object. * @return boolean */ public abstract boolean nextNode(); /** * Moves the current position to the specified index. Used with integer * predicates to quickly get to the n'th element of the node set. * Returns false if the position is out of the node set range. * You can call it with 0 as the position argument to restart the iteration. * @param position to set * @return boolean */ public boolean setPosition(int position) { this.position = position; return true; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/InfoSetUtil.java100644 0 0 13127 11044113541 24431 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.VariablePointer; /** * Type conversions, XPath style. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class InfoSetUtil { private static final Double ZERO = new Double(0); private static final Double ONE = new Double(1); private static final Double NOT_A_NUMBER = new Double(Double.NaN); /** * Converts the supplied object to String. * @param object to convert * @return String value */ public static String stringValue(Object object) { if (object instanceof String) { return (String) object; } if (object instanceof Number) { double d = ((Number) object).doubleValue(); long l = ((Number) object).longValue(); return d == l ? String.valueOf(l) : String.valueOf(d); } if (object instanceof Boolean) { return ((Boolean) object).booleanValue() ? "true" : "false"; } if (object == null) { return ""; } if (object instanceof NodePointer) { return stringValue(((NodePointer) object).getValue()); } if (object instanceof EvalContext) { EvalContext ctx = (EvalContext) object; Pointer ptr = ctx.getSingleNodePointer(); return ptr == null ? "" : stringValue(ptr); } return String.valueOf(object); } /** * Converts the supplied object to Number. * @param object to convert * @return Number result */ public static Number number(Object object) { if (object instanceof Number) { return (Number) object; } if (object instanceof Boolean) { return ((Boolean) object).booleanValue() ? ONE : ZERO; } if (object instanceof String) { try { return new Double((String) object); } catch (NumberFormatException ex) { return NOT_A_NUMBER; } } if (object instanceof EvalContext) { EvalContext ctx = (EvalContext) object; Pointer ptr = ctx.getSingleNodePointer(); return ptr == null ? NOT_A_NUMBER : number(ptr); } if (object instanceof NodePointer) { return number(((NodePointer) object).getValue()); } return number(stringValue(object)); } /** * Converts the supplied object to double. * @param object to convert * @return double */ public static double doubleValue(Object object) { if (object instanceof Number) { return ((Number) object).doubleValue(); } if (object instanceof Boolean) { return ((Boolean) object).booleanValue() ? 0.0 : 1.0; } if (object instanceof String) { if (object.equals("")) { return 0.0; } try { return Double.parseDouble((String) object); } catch (NumberFormatException ex) { return Double.NaN; } } if (object instanceof NodePointer) { return doubleValue(((NodePointer) object).getValue()); } if (object instanceof EvalContext) { EvalContext ctx = (EvalContext) object; Pointer ptr = ctx.getSingleNodePointer(); return ptr == null ? Double.NaN : doubleValue(ptr); } return doubleValue(stringValue(object)); } /** * Converts the supplied object to boolean. * @param object to convert * @return boolean */ public static boolean booleanValue(Object object) { if (object instanceof Number) { double value = ((Number) object).doubleValue(); final int negZero = -0; return value != 0 && value != negZero && !Double.isNaN(value); } if (object instanceof Boolean) { return ((Boolean) object).booleanValue(); } if (object instanceof EvalContext) { EvalContext ctx = (EvalContext) object; Pointer ptr = ctx.getSingleNodePointer(); return ptr == null ? false : booleanValue(ptr); } if (object instanceof String) { return ((String) object).length() != 0; } if (object instanceof NodePointer) { NodePointer pointer = (NodePointer) object; if (pointer instanceof VariablePointer) { return booleanValue(pointer.getNode()); } pointer = pointer.getValuePointer(); return pointer.isActual(); } return object != null; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/JXPathCompiledExpression.java100644 0 0 7151 11044113541 27077 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri; import java.util.Iterator; import org.apache.commons.jxpath.ri.compiler.Expression; import org.apache.commons.jxpath.CompiledExpression; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.Pointer; /** * RI of CompiledExpression. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class JXPathCompiledExpression implements CompiledExpression { private String xpath; private Expression expression; /** * Create a new JXPathCompiledExpression. * @param xpath source * @param expression compiled */ public JXPathCompiledExpression(String xpath, Expression expression) { this.xpath = xpath; this.expression = expression; } /** * Get the source expression. * @return String */ protected String getXPath() { return xpath; } /** * Get the compiled expression. * @return Expression */ protected Expression getExpression() { return expression; } public String toString() { return xpath; } public Object getValue(JXPathContext context) { return ((JXPathContextReferenceImpl) context). getValue(xpath, expression); } public Object getValue(JXPathContext context, Class requiredType) { return ((JXPathContextReferenceImpl) context). getValue(xpath, expression, requiredType); } public void setValue(JXPathContext context, Object value) { ((JXPathContextReferenceImpl) context). setValue(xpath, expression, value); } public Pointer createPath(JXPathContext context) { return ((JXPathContextReferenceImpl) context). createPath(xpath, expression); } public Pointer createPathAndSetValue(JXPathContext context, Object value) { return ((JXPathContextReferenceImpl) context). createPathAndSetValue(xpath, expression, value); } public Iterator iterate(JXPathContext context) { return ((JXPathContextReferenceImpl) context). iterate(xpath, expression); } public Pointer getPointer(JXPathContext context, String xpath) { return ((JXPathContextReferenceImpl) context). getPointer(xpath, expression); } public Iterator iteratePointers(JXPathContext context) { return ((JXPathContextReferenceImpl) context). iteratePointers(xpath, expression); } public void removePath(JXPathContext context) { ((JXPathContextReferenceImpl) context).removePath(xpath, expression); } public void removeAll(JXPathContext context) { ((JXPathContextReferenceImpl) context).removeAll(xpath, expression); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/JXPathContextFactoryReferenceImpl.java100644 0 0 2752 11044113541 30702 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathContextFactory; /** * Default implementation of JXPathContextFactory. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class JXPathContextFactoryReferenceImpl extends JXPathContextFactory { /** * Create a new JXPathContextFactoryReferenceImpl. */ public JXPathContextFactoryReferenceImpl() { } public JXPathContext newContext( JXPathContext parentContext, Object contextBean) { return new JXPathContextReferenceImpl(parentContext, contextBean); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java100644 0 0 67100 11044113541 27370 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri; import java.lang.ref.SoftReference; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Vector; import java.util.Map.Entry; import org.apache.commons.jxpath.CompiledExpression; import org.apache.commons.jxpath.Function; import org.apache.commons.jxpath.Functions; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathException; import org.apache.commons.jxpath.JXPathFunctionNotFoundException; import org.apache.commons.jxpath.JXPathInvalidSyntaxException; import org.apache.commons.jxpath.JXPathNotFoundException; import org.apache.commons.jxpath.JXPathTypeConversionException; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.axes.InitialContext; import org.apache.commons.jxpath.ri.axes.RootContext; import org.apache.commons.jxpath.ri.compiler.Expression; import org.apache.commons.jxpath.ri.compiler.LocationPath; import org.apache.commons.jxpath.ri.compiler.Path; import org.apache.commons.jxpath.ri.compiler.TreeCompiler; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.NodePointerFactory; import org.apache.commons.jxpath.ri.model.VariablePointerFactory; import org.apache.commons.jxpath.ri.model.beans.BeanPointerFactory; import org.apache.commons.jxpath.ri.model.beans.CollectionPointerFactory; import org.apache.commons.jxpath.ri.model.container.ContainerPointerFactory; import org.apache.commons.jxpath.ri.model.dynamic.DynamicPointerFactory; import org.apache.commons.jxpath.util.ReverseComparator; import org.apache.commons.jxpath.util.TypeUtils; /** * The reference implementation of JXPathContext. * * @author Dmitri Plotnikov * @version $Revision: 670727 $ $Date: 2008-06-23 15:10:38 -0500 (Mon, 23 Jun 2008) $ */ public class JXPathContextReferenceImpl extends JXPathContext { /** * Change this to false to disable soft caching of * CompiledExpressions. */ public static final boolean USE_SOFT_CACHE = true; private static final Compiler COMPILER = new TreeCompiler(); private static Map compiled = new HashMap(); private static int cleanupCount = 0; private static NodePointerFactory[] nodeFactoryArray = null; // The frequency of the cache cleanup private static final int CLEANUP_THRESHOLD = 500; private static final Vector nodeFactories = new Vector(); static { nodeFactories.add(new CollectionPointerFactory()); nodeFactories.add(new BeanPointerFactory()); nodeFactories.add(new DynamicPointerFactory()); nodeFactories.add(new VariablePointerFactory()); // DOM factory is only registered if DOM support is on the classpath Object domFactory = allocateConditionally( "org.apache.commons.jxpath.ri.model.dom.DOMPointerFactory", "org.w3c.dom.Node"); if (domFactory != null) { nodeFactories.add(domFactory); } // JDOM factory is only registered if JDOM is on the classpath Object jdomFactory = allocateConditionally( "org.apache.commons.jxpath.ri.model.jdom.JDOMPointerFactory", "org.jdom.Document"); if (jdomFactory != null) { nodeFactories.add(jdomFactory); } // DynaBean factory is only registered if BeanUtils are on the classpath Object dynaBeanFactory = allocateConditionally( "org.apache.commons.jxpath.ri.model.dynabeans." + "DynaBeanPointerFactory", "org.apache.commons.beanutils.DynaBean"); if (dynaBeanFactory != null) { nodeFactories.add(dynaBeanFactory); } nodeFactories.add(new ContainerPointerFactory()); createNodeFactoryArray(); } /** * Create the default node factory array. */ private static synchronized void createNodeFactoryArray() { if (nodeFactoryArray == null) { nodeFactoryArray = (NodePointerFactory[]) nodeFactories. toArray(new NodePointerFactory[nodeFactories.size()]); Arrays.sort(nodeFactoryArray, new Comparator() { public int compare(Object a, Object b) { int orderA = ((NodePointerFactory) a).getOrder(); int orderB = ((NodePointerFactory) b).getOrder(); return orderA - orderB; } }); } } /** * Call this with a custom NodePointerFactory to add support for * additional types of objects. Make sure the factory returns * a name that puts it in the right position on the list of factories. * @param factory NodePointerFactory to add */ public static void addNodePointerFactory(NodePointerFactory factory) { synchronized (nodeFactories) { nodeFactories.add(factory); nodeFactoryArray = null; } } /** * Get the registered NodePointerFactories. * @return NodePointerFactory[] */ public static NodePointerFactory[] getNodePointerFactories() { return nodeFactoryArray; } /** Namespace resolver */ protected NamespaceResolver namespaceResolver; private Pointer rootPointer; private Pointer contextPointer; /** * Create a new JXPathContextReferenceImpl. * @param parentContext parent context * @param contextBean Object */ protected JXPathContextReferenceImpl(JXPathContext parentContext, Object contextBean) { this(parentContext, contextBean, null); } /** * Create a new JXPathContextReferenceImpl. * @param parentContext parent context * @param contextBean Object * @param contextPointer context pointer */ public JXPathContextReferenceImpl(JXPathContext parentContext, Object contextBean, Pointer contextPointer) { super(parentContext, contextBean); synchronized (nodeFactories) { createNodeFactoryArray(); } if (contextPointer != null) { this.contextPointer = contextPointer; this.rootPointer = NodePointer.newNodePointer( new QName(null, "root"), contextPointer.getRootNode(), getLocale()); } else { this.contextPointer = NodePointer.newNodePointer( new QName(null, "root"), contextBean, getLocale()); this.rootPointer = this.contextPointer; } NamespaceResolver parentNR = null; if (parentContext instanceof JXPathContextReferenceImpl) { parentNR = ((JXPathContextReferenceImpl) parentContext).getNamespaceResolver(); } namespaceResolver = new NamespaceResolver(parentNR); namespaceResolver .setNamespaceContextPointer((NodePointer) this.contextPointer); } /** * Returns a static instance of TreeCompiler. * * Override this to return an alternate compiler. * @return Compiler */ protected Compiler getCompiler() { return COMPILER; } protected CompiledExpression compilePath(String xpath) { return new JXPathCompiledExpression(xpath, compileExpression(xpath)); } /** * Compile the given expression. * @param xpath to compile * @return Expression */ private Expression compileExpression(String xpath) { Expression expr; synchronized (compiled) { if (USE_SOFT_CACHE) { expr = null; SoftReference ref = (SoftReference) compiled.get(xpath); if (ref != null) { expr = (Expression) ref.get(); } } else { expr = (Expression) compiled.get(xpath); } } if (expr != null) { return expr; } expr = (Expression) Parser.parseExpression(xpath, getCompiler()); synchronized (compiled) { if (USE_SOFT_CACHE) { if (cleanupCount++ >= CLEANUP_THRESHOLD) { Iterator it = compiled.entrySet().iterator(); while (it.hasNext()) { Entry me = (Entry) it.next(); if (((SoftReference) me.getValue()).get() == null) { it.remove(); } } cleanupCount = 0; } compiled.put(xpath, new SoftReference(expr)); } else { compiled.put(xpath, expr); } } return expr; } /** * Traverses the xpath and returns the resulting object. Primitive * types are wrapped into objects. * @param xpath expression * @return Object found */ public Object getValue(String xpath) { Expression expression = compileExpression(xpath); // TODO: (work in progress) - trying to integrate with Xalan // Object ctxNode = getNativeContextNode(expression); // if (ctxNode != null) { // System.err.println("WILL USE XALAN: " + xpath); // CachedXPathAPI api = new CachedXPathAPI(); // try { // if (expression instanceof Path) { // Node node = api.selectSingleNode((Node)ctxNode, xpath); // System.err.println("NODE: " + node); // if (node == null) { // return null; // } // return new DOMNodePointer(node, null).getValue(); // } // else { // XObject object = api.eval((Node)ctxNode, xpath); // switch (object.getType()) { // case XObject.CLASS_STRING: return object.str(); // case XObject.CLASS_NUMBER: return new Double(object.num()); // case XObject.CLASS_BOOLEAN: return new Boolean(object.bool()); // default: // System.err.println("OTHER TYPE: " + object.getTypeString()); // } // } // } // catch (TransformerException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // return // } return getValue(xpath, expression); } // private Object getNativeContextNode(Expression expression) { // Object node = getNativeContextNode(getContextBean()); // if (node == null) { // return null; // } // // List vars = expression.getUsedVariables(); // if (vars != null) { // return null; // } // // return node; // } // private Object getNativeContextNode(Object bean) { // if (bean instanceof Number || bean instanceof String || bean instanceof Boolean) { // return bean; // } // if (bean instanceof Node) { // return (Node)bean; // } // // if (bean instanceof Container) { // bean = ((Container)bean).getValue(); // return getNativeContextNode(bean); // } // // return null; // } /** * Get the value indicated. * @param xpath String * @param expr Expression * @return Object */ public Object getValue(String xpath, Expression expr) { Object result = expr.computeValue(getEvalContext()); if (result == null) { if (expr instanceof Path && !isLenient()) { throw new JXPathNotFoundException("No value for xpath: " + xpath); } return null; } if (result instanceof EvalContext) { EvalContext ctx = (EvalContext) result; result = ctx.getSingleNodePointer(); if (!isLenient() && result == null) { throw new JXPathNotFoundException("No value for xpath: " + xpath); } } if (result instanceof NodePointer) { result = ((NodePointer) result).getValuePointer(); if (!isLenient() && !((NodePointer) result).isActual()) { // We need to differentiate between pointers representing // a non-existing property and ones representing a property // whose value is null. In the latter case, the pointer // is going to have isActual == false, but its parent, // which is a non-node pointer identifying the bean property, // will return isActual() == true. NodePointer parent = ((NodePointer) result).getImmediateParentPointer(); if (parent == null || !parent.isContainer() || !parent.isActual()) { throw new JXPathNotFoundException("No value for xpath: " + xpath); } } result = ((NodePointer) result).getValue(); } return result; } /** * Calls getValue(xpath), converts the result to the required type * and returns the result of the conversion. * @param xpath expression * @param requiredType Class * @return Object */ public Object getValue(String xpath, Class requiredType) { Expression expr = compileExpression(xpath); return getValue(xpath, expr, requiredType); } /** * Get the value indicated. * @param xpath expression * @param expr compiled Expression * @param requiredType Class * @return Object */ public Object getValue(String xpath, Expression expr, Class requiredType) { Object value = getValue(xpath, expr); if (value != null && requiredType != null) { if (!TypeUtils.canConvert(value, requiredType)) { throw new JXPathTypeConversionException( "Invalid expression type. '" + xpath + "' returns " + value.getClass().getName() + ". It cannot be converted to " + requiredType.getName()); } value = TypeUtils.convert(value, requiredType); } return value; } /** * Traverses the xpath and returns a Iterator of all results found * for the path. If the xpath matches no properties * in the graph, the Iterator will not be null. * @param xpath expression * @return Iterator */ public Iterator iterate(String xpath) { return iterate(xpath, compileExpression(xpath)); } /** * Traverses the xpath and returns a Iterator of all results found * for the path. If the xpath matches no properties * in the graph, the Iterator will not be null. * @param xpath expression * @param expr compiled Expression * @return Iterator */ public Iterator iterate(String xpath, Expression expr) { return expr.iterate(getEvalContext()); } public Pointer getPointer(String xpath) { return getPointer(xpath, compileExpression(xpath)); } /** * Get a pointer to the specified path/expression. * @param xpath String * @param expr compiled Expression * @return Pointer */ public Pointer getPointer(String xpath, Expression expr) { Object result = expr.computeValue(getEvalContext()); if (result instanceof EvalContext) { result = ((EvalContext) result).getSingleNodePointer(); } if (result instanceof Pointer) { if (!isLenient() && !((NodePointer) result).isActual()) { throw new JXPathNotFoundException("No pointer for xpath: " + xpath); } return (Pointer) result; } return NodePointer.newNodePointer(null, result, getLocale()); } public void setValue(String xpath, Object value) { setValue(xpath, compileExpression(xpath), value); } /** * Set the value of xpath to value. * @param xpath path * @param expr compiled Expression * @param value Object */ public void setValue(String xpath, Expression expr, Object value) { try { setValue(xpath, expr, value, false); } catch (Throwable ex) { throw new JXPathException( "Exception trying to set value with xpath " + xpath, ex); } } public Pointer createPath(String xpath) { return createPath(xpath, compileExpression(xpath)); } /** * Create the given path. * @param xpath String * @param expr compiled Expression * @return resulting Pointer */ public Pointer createPath(String xpath, Expression expr) { try { Object result = expr.computeValue(getEvalContext()); Pointer pointer = null; if (result instanceof Pointer) { pointer = (Pointer) result; } else if (result instanceof EvalContext) { EvalContext ctx = (EvalContext) result; pointer = ctx.getSingleNodePointer(); } else { checkSimplePath(expr); // This should never happen throw new JXPathException("Cannot create path:" + xpath); } return ((NodePointer) pointer).createPath(this); } catch (Throwable ex) { throw new JXPathException( "Exception trying to create xpath " + xpath, ex); } } public Pointer createPathAndSetValue(String xpath, Object value) { return createPathAndSetValue(xpath, compileExpression(xpath), value); } /** * Create the given path setting its value to value. * @param xpath String * @param expr compiled Expression * @param value Object * @return resulting Pointer */ public Pointer createPathAndSetValue(String xpath, Expression expr, Object value) { try { return setValue(xpath, expr, value, true); } catch (Throwable ex) { throw new JXPathException( "Exception trying to create xpath " + xpath, ex); } } /** * Set the specified value. * @param xpath path * @param expr compiled Expression * @param value destination value * @param create whether to create missing node(s) * @return Pointer created */ private Pointer setValue(String xpath, Expression expr, Object value, boolean create) { Object result = expr.computeValue(getEvalContext()); Pointer pointer = null; if (result instanceof Pointer) { pointer = (Pointer) result; } else if (result instanceof EvalContext) { EvalContext ctx = (EvalContext) result; pointer = ctx.getSingleNodePointer(); } else { if (create) { checkSimplePath(expr); } // This should never happen throw new JXPathException("Cannot set value for xpath: " + xpath); } if (create) { pointer = ((NodePointer) pointer).createPath(this, value); } else { pointer.setValue(value); } return pointer; } /** * Checks if the path follows the JXPath restrictions on the type * of path that can be passed to create... methods. * @param expr Expression to check */ private void checkSimplePath(Expression expr) { if (!(expr instanceof LocationPath) || !((LocationPath) expr).isSimplePath()) { throw new JXPathInvalidSyntaxException( "JXPath can only create a path if it uses exclusively " + "the child:: and attribute:: axes and has " + "no context-dependent predicates"); } } /** * Traverses the xpath and returns an Iterator of Pointers. * A Pointer provides easy access to a property. * If the xpath matches no properties * in the graph, the Iterator be empty, but not null. * @param xpath expression * @return Iterator */ public Iterator iteratePointers(String xpath) { return iteratePointers(xpath, compileExpression(xpath)); } /** * Traverses the xpath and returns an Iterator of Pointers. * A Pointer provides easy access to a property. * If the xpath matches no properties * in the graph, the Iterator be empty, but not null. * @param xpath expression * @param expr compiled Expression * @return Iterator */ public Iterator iteratePointers(String xpath, Expression expr) { return expr.iteratePointers(getEvalContext()); } public void removePath(String xpath) { removePath(xpath, compileExpression(xpath)); } /** * Remove the specified path. * @param xpath expression * @param expr compiled Expression */ public void removePath(String xpath, Expression expr) { try { NodePointer pointer = (NodePointer) getPointer(xpath, expr); if (pointer != null) { ((NodePointer) pointer).remove(); } } catch (Throwable ex) { throw new JXPathException( "Exception trying to remove xpath " + xpath, ex); } } public void removeAll(String xpath) { removeAll(xpath, compileExpression(xpath)); } /** * Remove all matching nodes. * @param xpath expression * @param expr compiled Expression */ public void removeAll(String xpath, Expression expr) { try { ArrayList list = new ArrayList(); Iterator it = expr.iteratePointers(getEvalContext()); while (it.hasNext()) { list.add(it.next()); } Collections.sort(list, ReverseComparator.INSTANCE); it = list.iterator(); if (it.hasNext()) { NodePointer pointer = (NodePointer) it.next(); pointer.remove(); while (it.hasNext()) { removePath(((NodePointer) it.next()).asPath()); } } } catch (Throwable ex) { throw new JXPathException( "Exception trying to remove all for xpath " + xpath, ex); } } public JXPathContext getRelativeContext(Pointer pointer) { Object contextBean = pointer.getNode(); if (contextBean == null) { throw new JXPathException( "Cannot create a relative context for a non-existent node: " + pointer); } return new JXPathContextReferenceImpl(this, contextBean, pointer); } public Pointer getContextPointer() { return contextPointer; } /** * Get absolute root pointer. * @return NodePointer */ private NodePointer getAbsoluteRootPointer() { return (NodePointer) rootPointer; } /** * Get the evaluation context. * @return EvalContext */ private EvalContext getEvalContext() { return new InitialContext(new RootContext(this, (NodePointer) getContextPointer())); } /** * Get the absolute root context. * @return EvalContext */ public EvalContext getAbsoluteRootContext() { return new InitialContext(new RootContext(this, getAbsoluteRootPointer())); } /** * Get a VariablePointer for the given variable name. * @param name variable name * @return NodePointer */ public NodePointer getVariablePointer(QName name) { return NodePointer.newNodePointer(name, VariablePointerFactory .contextWrapper(this), getLocale()); } /** * Get the named Function. * @param functionName name * @param parameters function args * @return Function */ public Function getFunction(QName functionName, Object[] parameters) { String namespace = functionName.getPrefix(); String name = functionName.getName(); JXPathContext funcCtx = this; Function func = null; Functions funcs; while (funcCtx != null) { funcs = funcCtx.getFunctions(); if (funcs != null) { func = funcs.getFunction(namespace, name, parameters); if (func != null) { return func; } } funcCtx = funcCtx.getParentContext(); } throw new JXPathFunctionNotFoundException( "Undefined function: " + functionName.toString()); } public void registerNamespace(String prefix, String namespaceURI) { if (namespaceResolver.isSealed()) { namespaceResolver = (NamespaceResolver) namespaceResolver.clone(); } namespaceResolver.registerNamespace(prefix, namespaceURI); } public String getNamespaceURI(String prefix) { return namespaceResolver.getNamespaceURI(prefix); } /** * {@inheritDoc} * @see org.apache.commons.jxpath.JXPathContext#getPrefix(java.lang.String) */ public String getPrefix(String namespaceURI) { return namespaceResolver.getPrefix(namespaceURI); } public void setNamespaceContextPointer(Pointer pointer) { if (namespaceResolver.isSealed()) { namespaceResolver = (NamespaceResolver) namespaceResolver.clone(); } namespaceResolver.setNamespaceContextPointer((NodePointer) pointer); } public Pointer getNamespaceContextPointer() { return namespaceResolver.getNamespaceContextPointer(); } /** * Get the namespace resolver. * @return NamespaceResolver */ public NamespaceResolver getNamespaceResolver() { namespaceResolver.seal(); return namespaceResolver; } /** * Checks if existenceCheckClass exists on the class path. If so, allocates * an instance of the specified class, otherwise returns null. * @param className to instantiate * @param existenceCheckClassName guard class * @return className instance */ public static Object allocateConditionally(String className, String existenceCheckClassName) { try { try { Class.forName(existenceCheckClassName); } catch (ClassNotFoundException ex) { return null; } Class cls = Class.forName(className); return cls.newInstance(); } catch (Exception ex) { throw new JXPathException("Cannot allocate " + className, ex); } } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/beans/BeanAttributeIterator.java100644 0 0 4675 11044113534 30651 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.beans; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; /** * An iterator of attributes of a JavaBean. Returns bean properties as * well as the "xml:lang" attribute. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class BeanAttributeIterator extends PropertyIterator { private NodePointer parent; private int position = 0; private boolean includeXmlLang; /** * Create a new BeanAttributeIterator. * @param parent parent pointer * @param name name of this bean */ public BeanAttributeIterator(PropertyOwnerPointer parent, QName name) { super( parent, (name.getPrefix() == null && (name.getName() == null || name.getName().equals("*"))) ? null : name.toString(), false, null); this.parent = parent; includeXmlLang = (name.getPrefix() != null && name.getPrefix().equals("xml")) && (name.getName().equals("lang") || name.getName().equals("*")); } public NodePointer getNodePointer() { return includeXmlLang && position == 1 ? new LangAttributePointer(parent) : super.getNodePointer(); } public int getPosition() { return position; } public boolean setPosition(int position) { this.position = position; if (includeXmlLang) { return position == 1 || super.setPosition(position - 1); } return super.setPosition(position); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/beans/BeanPointer.java100644 0 0 11656 11044113534 26631 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.beans; import java.util.Locale; import org.apache.commons.jxpath.JXPathBeanInfo; import org.apache.commons.jxpath.JXPathIntrospector; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; /** * A Pointer that points to a JavaBean or a collection. It is either * the first element of a path or a pointer for a property value. * Typically there is a {@link BeanPropertyPointer} between two BeanPointers * in the chain. * * @author Dmitri Plotnikov * @version $Revision: 670727 $ $Date: 2008-06-23 15:10:38 -0500 (Mon, 23 Jun 2008) $ */ public class BeanPointer extends PropertyOwnerPointer { private QName name; private Object bean; private JXPathBeanInfo beanInfo; private static final long serialVersionUID = -8227317938284982440L; /** * Create a new BeanPointer. * @param name is the name given to the first node * @param bean pointed * @param beanInfo JXPathBeanInfo * @param locale Locale */ public BeanPointer(QName name, Object bean, JXPathBeanInfo beanInfo, Locale locale) { super(null, locale); this.name = name; this.bean = bean; this.beanInfo = beanInfo; } /** * Create a new BeanPointer. * @param parent pointer * @param name is the name given to the first node * @param bean pointed * @param beanInfo JXPathBeanInfo */ public BeanPointer(NodePointer parent, QName name, Object bean, JXPathBeanInfo beanInfo) { super(parent); this.name = name; this.bean = bean; this.beanInfo = beanInfo; } public PropertyPointer getPropertyPointer() { return new BeanPropertyPointer(this, beanInfo); } public QName getName() { return name; } public Object getBaseValue() { return bean; } /** * {@inheritDoc} * @return false */ public boolean isCollection() { return false; } /** * {@inheritDoc} * @return 1 */ public int getLength() { return 1; } public boolean isLeaf() { Object value = getNode(); return value == null || JXPathIntrospector.getBeanInfo(value.getClass()).isAtomic(); } public int hashCode() { return name == null ? 0 : name.hashCode(); } public boolean equals(Object object) { if (object == this) { return true; } if (!(object instanceof BeanPointer)) { return false; } BeanPointer other = (BeanPointer) object; if (parent != other.parent && (parent == null || !parent.equals(other.parent))) { return false; } if ((name == null && other.name != null) || (name != null && !name.equals(other.name))) { return false; } int iThis = (index == WHOLE_COLLECTION ? 0 : index); int iOther = (other.index == WHOLE_COLLECTION ? 0 : other.index); if (iThis != iOther) { return false; } if (bean instanceof Number || bean instanceof String || bean instanceof Boolean) { return bean.equals(other.bean); } return bean == other.bean; } /** * {@inheritDoc} * If the pointer has a parent, then parent's path. * If the bean is null, "null()". * If the bean is a primitive value, the value itself. * Otherwise - an empty string. */ public String asPath() { if (parent != null) { return super.asPath(); } if (bean == null) { return "null()"; } if (bean instanceof Number) { String string = bean.toString(); if (string.endsWith(".0")) { string = string.substring(0, string.length() - 2); } return string; } if (bean instanceof Boolean) { return ((Boolean) bean).booleanValue() ? "true()" : "false()"; } if (bean instanceof String) { return "'" + bean + "'"; } return "/"; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/beans/BeanPointerFactory.java100644 0 0 4074 11044113534 30135 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.beans; import java.util.Locale; import org.apache.commons.jxpath.JXPathBeanInfo; import org.apache.commons.jxpath.JXPathIntrospector; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.NodePointerFactory; /** * Implements NodePointerFactory for JavaBeans. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class BeanPointerFactory implements NodePointerFactory { /** factory order constant */ public static final int BEAN_POINTER_FACTORY_ORDER = 900; public int getOrder() { return BEAN_POINTER_FACTORY_ORDER; } public NodePointer createNodePointer(QName name, Object bean, Locale locale) { JXPathBeanInfo bi = JXPathIntrospector.getBeanInfo(bean.getClass()); return new BeanPointer(name, bean, bi, locale); } public NodePointer createNodePointer(NodePointer parent, QName name, Object bean) { if (bean == null) { return new NullPointer(parent, name); } JXPathBeanInfo bi = JXPathIntrospector.getBeanInfo(bean.getClass()); return new BeanPointer(parent, name, bean, bi); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/beans/BeanPropertyPointer.java100644 0 0 22715 11044113534 30374 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.beans; import java.beans.IndexedPropertyDescriptor; import java.beans.PropertyDescriptor; import org.apache.commons.jxpath.JXPathBeanInfo; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathInvalidAccessException; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.util.ValueUtils; /** * Pointer pointing to a property of a JavaBean. * * @author Dmitri Plotnikov * @version $Revision: 670727 $ $Date: 2008-06-23 15:10:38 -0500 (Mon, 23 Jun 2008) $ */ public class BeanPropertyPointer extends PropertyPointer { private static final long serialVersionUID = -6008991447676468786L; private static final Object UNINITIALIZED = new Object(); private String propertyName; private JXPathBeanInfo beanInfo; private Object baseValue = UNINITIALIZED; private Object value = UNINITIALIZED; private transient String[] names; private transient PropertyDescriptor[] propertyDescriptors; private transient PropertyDescriptor propertyDescriptor; /** * Create a new BeanPropertyPointer. * @param parent parent pointer * @param beanInfo describes the target property/ies. */ public BeanPropertyPointer(NodePointer parent, JXPathBeanInfo beanInfo) { super(parent); this.beanInfo = beanInfo; } /** * This type of node is auxiliary. * @return true */ public boolean isContainer() { return true; } public int getPropertyCount() { if (beanInfo.isAtomic()) { return 0; } return getPropertyDescriptors().length; } /** * Get the names of all properties, sorted alphabetically * @return String[] */ public String[] getPropertyNames() { if (names == null) { PropertyDescriptor[] pds = getPropertyDescriptors(); names = new String[pds.length]; for (int i = 0; i < names.length; i++) { names[i] = pds[i].getName(); } } return names; } /** * Select a property by name. * @param propertyName String name */ public void setPropertyName(String propertyName) { setPropertyIndex(UNSPECIFIED_PROPERTY); this.propertyName = propertyName; } /** * Selects a property by its offset in the alphabetically sorted list. * @param index property index */ public void setPropertyIndex(int index) { if (propertyIndex != index) { super.setPropertyIndex(index); propertyName = null; propertyDescriptor = null; baseValue = UNINITIALIZED; value = UNINITIALIZED; } } /** * Get the value of the currently selected property. * @return Object value */ public Object getBaseValue() { if (baseValue == UNINITIALIZED) { PropertyDescriptor pd = getPropertyDescriptor(); if (pd == null) { return null; } baseValue = ValueUtils.getValue(getBean(), pd); } return baseValue; } public void setIndex(int index) { if (this.index == index) { return; } // When dealing with a scalar, index == 0 is equivalent to // WHOLE_COLLECTION, so do not change it. if (this.index != WHOLE_COLLECTION || index != 0 || isCollection()) { super.setIndex(index); value = UNINITIALIZED; } } /** * If index == WHOLE_COLLECTION, the value of the property, otherwise * the value of the index'th element of the collection represented by the * property. If the property is not a collection, index should be zero * and the value will be the property itself. * @return Object */ public Object getImmediateNode() { if (value == UNINITIALIZED) { if (index == WHOLE_COLLECTION) { value = ValueUtils.getValue(getBaseValue()); } else { PropertyDescriptor pd = getPropertyDescriptor(); if (pd == null) { value = null; } else { value = ValueUtils.getValue(getBean(), pd, index); } } } return value; } protected boolean isActualProperty() { return getPropertyDescriptor() != null; } public boolean isCollection() { PropertyDescriptor pd = getPropertyDescriptor(); if (pd == null) { return false; } if (pd instanceof IndexedPropertyDescriptor) { return true; } int hint = ValueUtils.getCollectionHint(pd.getPropertyType()); if (hint == -1) { return false; } if (hint == 1) { return true; } Object value = getBaseValue(); return value != null && ValueUtils.isCollection(value); } /** * If the property contains a collection, then the length of that * collection, otherwise - 1. * @return int length */ public int getLength() { PropertyDescriptor pd = getPropertyDescriptor(); if (pd == null) { return 1; } if (pd instanceof IndexedPropertyDescriptor) { return ValueUtils.getIndexedPropertyLength( getBean(), (IndexedPropertyDescriptor) pd); } int hint = ValueUtils.getCollectionHint(pd.getPropertyType()); if (hint == -1) { return 1; } return ValueUtils.getLength(getBaseValue()); } /** * If index == WHOLE_COLLECTION, change the value of the property, otherwise * change the value of the index'th element of the collection * represented by the property. * @param value value to set */ public void setValue(Object value) { PropertyDescriptor pd = getPropertyDescriptor(); if (pd == null) { throw new JXPathInvalidAccessException( "Cannot set property: " + asPath() + " - no such property"); } if (index == WHOLE_COLLECTION) { ValueUtils.setValue(getBean(), pd, value); } else { ValueUtils.setValue(getBean(), pd, index, value); } this.value = value; } public NodePointer createPath(JXPathContext context) { if (getImmediateNode() == null) { super.createPath(context); baseValue = UNINITIALIZED; value = UNINITIALIZED; } return this; } public void remove() { if (index == WHOLE_COLLECTION) { setValue(null); } else if (isCollection()) { Object o = getBaseValue(); Object collection = ValueUtils.remove(getBaseValue(), index); if (collection != o) { ValueUtils.setValue(getBean(), getPropertyDescriptor(), collection); } } else if (index == 0) { index = WHOLE_COLLECTION; setValue(null); } } /** * Get the name of the currently selected property. * @return String property name */ public String getPropertyName() { if (propertyName == null) { PropertyDescriptor pd = getPropertyDescriptor(); if (pd != null) { propertyName = pd.getName(); } } return propertyName != null ? propertyName : "*"; } /** * Finds the property descriptor corresponding to the current property * index. * @return PropertyDescriptor */ private PropertyDescriptor getPropertyDescriptor() { if (propertyDescriptor == null) { int inx = getPropertyIndex(); if (inx == UNSPECIFIED_PROPERTY) { propertyDescriptor = beanInfo.getPropertyDescriptor(propertyName); } else { PropertyDescriptor[] propertyDescriptors = getPropertyDescriptors(); if (inx >= 0 && inx < propertyDescriptors.length) { propertyDescriptor = propertyDescriptors[inx]; } else { propertyDescriptor = null; } } } return propertyDescriptor; } /** * Get all PropertyDescriptors. * @return PropertyDescriptor[] */ protected synchronized PropertyDescriptor[] getPropertyDescriptors() { if (propertyDescriptors == null) { propertyDescriptors = beanInfo.getPropertyDescriptors(); } return propertyDescriptors; } } ././@LongLink100644 0 0 156 11044114245 10251 Lustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/beans/CollectionAttributeNodeIterator.javacommons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/beans/CollectionAttributeNodeIter100644 0 0 3423 11044113534 31065 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.beans; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; /** * Combines attribute node iterators of all elements of a collection into one * aggregate attribute node iterator. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class CollectionAttributeNodeIterator extends CollectionNodeIterator { private QName name; /** * Create a new CollectionAttributeNodeIterator. * @param pointer collection pointer * @param name attribute name */ public CollectionAttributeNodeIterator( CollectionPointer pointer, QName name) { super(pointer, false, null); this.name = name; } protected NodeIterator getElementNodeIterator(NodePointer elementPointer) { return elementPointer.attributeIterator(name); } } ././@LongLink100644 0 0 152 11044114245 10245 Lustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/beans/CollectionChildNodeIterator.javacommons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/beans/CollectionChildNodeIterator100644 0 0 3643 11044113534 31037 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.beans; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; /** * Combines child node iterators of all elements of a collection into one * aggregate child node iterator. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class CollectionChildNodeIterator extends CollectionNodeIterator { private NodeTest test; /** * Create a new CollectionChildNodeIterator. * @param pointer CollectionPointer * @param test child test * @param reverse iteration order * @param startWith starting pointer */ public CollectionChildNodeIterator( CollectionPointer pointer, NodeTest test, boolean reverse, NodePointer startWith) { super(pointer, reverse, startWith); this.test = test; } protected NodeIterator getElementNodeIterator(NodePointer elementPointer) { return elementPointer.childIterator(test, false, null); } } ././@LongLink100644 0 0 145 11044114245 10247 Lustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/beans/CollectionNodeIterator.javacommons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/beans/CollectionNodeIterator.java100644 0 0 7614 11044113534 31015 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.beans; import java.util.ArrayList; import java.util.List; import org.apache.commons.jxpath.JXPathException; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; /** * Combines node iterators of all elements of a collection into one * aggregate node iterator. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public abstract class CollectionNodeIterator implements NodeIterator { private CollectionPointer pointer; private boolean reverse; private NodePointer startWith; private int position; private List collection; /** * Create a new CollectionNodeIterator. * @param pointer collection pointer * @param reverse iteration order * @param startWith starting pointer */ protected CollectionNodeIterator( CollectionPointer pointer, boolean reverse, NodePointer startWith) { this.pointer = pointer; this.reverse = reverse; this.startWith = startWith; } /** * Implemented by subclasses to produce child/attribute node iterators. * @param elementPointer owning pointer * @return NodeIterator */ protected abstract NodeIterator getElementNodeIterator(NodePointer elementPointer); public int getPosition() { return position; } public boolean setPosition(int position) { if (collection == null) { prepare(); } if (position < 1 || position > collection.size()) { return false; } this.position = position; return true; } public NodePointer getNodePointer() { if (position == 0) { return null; } return (NodePointer) collection.get(position - 1); } /** * Prepare... */ private void prepare() { collection = new ArrayList(); NodePointer ptr = (NodePointer) pointer.clone(); int length = ptr.getLength(); for (int i = 0; i < length; i++) { ptr.setIndex(i); NodePointer elementPointer = ptr.getValuePointer(); NodeIterator iter = getElementNodeIterator(elementPointer); for (int j = 1; iter.setPosition(j); j++) { NodePointer childPointer = iter.getNodePointer(); if (reverse) { collection.add(0, childPointer); } else { collection.add(childPointer); } } } if (startWith != null) { int index = collection.indexOf(startWith); if (index == -1) { throw new JXPathException( "Invalid starting pointer for iterator: " + startWith); } while (collection.size() > index) { if (!reverse) { collection.remove(collection.size() - 1); } else { collection.remove(0); } } } } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/beans/CollectionPointer.java100644 0 0 16321 11044113534 30051 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.beans; import java.util.Locale; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathIntrospector; import org.apache.commons.jxpath.ri.Compiler; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.compiler.NodeNameTest; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.compiler.NodeTypeTest; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.util.ValueUtils; /** * Transparent pointer to a collection (array or Collection). * * @author Dmitri Plotnikov * @version $Revision: 668329 $ $Date: 2008-06-16 16:59:48 -0500 (Mon, 16 Jun 2008) $ */ public class CollectionPointer extends NodePointer { private Object collection; private NodePointer valuePointer; private static final long serialVersionUID = 8620254915563256588L; /** * Create a new CollectionPointer. * @param collection value * @param locale Locale */ public CollectionPointer(Object collection, Locale locale) { super(null, locale); this.collection = collection; } /** * Create a new CollectionPointer. * @param parent parent NodePointer * @param collection value */ public CollectionPointer(NodePointer parent, Object collection) { super(parent); this.collection = collection; } public QName getName() { return null; } public Object getBaseValue() { return collection; } public boolean isCollection() { return true; } public int getLength() { return ValueUtils.getLength(getBaseValue()); } public boolean isLeaf() { Object value = getNode(); return value == null || JXPathIntrospector.getBeanInfo(value.getClass()).isAtomic(); } public boolean isContainer() { return index != WHOLE_COLLECTION; } public Object getImmediateNode() { return index == WHOLE_COLLECTION ? ValueUtils.getValue(collection) : ValueUtils.getValue(collection, index); } public void setValue(Object value) { if (index == WHOLE_COLLECTION) { parent.setValue(value); } else { ValueUtils.setValue(collection, index, value); } } public void setIndex(int index) { super.setIndex(index); valuePointer = null; } public NodePointer getValuePointer() { if (valuePointer == null) { if (index == WHOLE_COLLECTION) { valuePointer = this; } else { Object value = getImmediateNode(); valuePointer = NodePointer.newChildNodePointer(this, getName(), value); } } return valuePointer; } public NodePointer createPath(JXPathContext context) { if (ValueUtils.getLength(getBaseValue()) <= index) { collection = ValueUtils.expandCollection(getNode(), index + 1); } return this; } public NodePointer createPath(JXPathContext context, Object value) { NodePointer ptr = createPath(context); ptr.setValue(value); return ptr; } public NodePointer createChild( JXPathContext context, QName name, int index, Object value) { NodePointer ptr = (NodePointer) clone(); ptr.setIndex(index); return ptr.createPath(context, value); } public NodePointer createChild( JXPathContext context, QName name, int index) { NodePointer ptr = (NodePointer) clone(); ptr.setIndex(index); return ptr.createPath(context); } public int hashCode() { return System.identityHashCode(collection) + index; } public boolean equals(Object object) { if (object == this) { return true; } if (!(object instanceof CollectionPointer)) { return false; } CollectionPointer other = (CollectionPointer) object; return collection == other.collection && index == other.index; } public NodeIterator childIterator(NodeTest test, boolean reverse, NodePointer startWith) { if (index == WHOLE_COLLECTION) { return new CollectionChildNodeIterator( this, test, reverse, startWith); } return getValuePointer().childIterator(test, reverse, startWith); } public NodeIterator attributeIterator(QName name) { return index == WHOLE_COLLECTION ? new CollectionAttributeNodeIterator(this, name) : getValuePointer().attributeIterator(name); } public NodeIterator namespaceIterator() { return index == WHOLE_COLLECTION ? null : getValuePointer().namespaceIterator(); } public NodePointer namespacePointer(String namespace) { return index == WHOLE_COLLECTION ? null : getValuePointer().namespacePointer(namespace); } public boolean testNode(NodeTest test) { if (index == WHOLE_COLLECTION) { if (test == null) { return true; } if (test instanceof NodeNameTest) { return false; } return test instanceof NodeTypeTest && ((NodeTypeTest) test).getNodeType() == Compiler.NODE_TYPE_NODE; } return getValuePointer().testNode(test); } public int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2) { return pointer1.getIndex() - pointer2.getIndex(); } public String asPath() { StringBuffer buffer = new StringBuffer(); NodePointer parent = getImmediateParentPointer(); if (parent != null) { buffer.append(parent.asPath()); if (index != WHOLE_COLLECTION) { // Address the list[1][2] case if (parent.getIndex() != WHOLE_COLLECTION) { buffer.append("/."); } buffer.append("[").append(index + 1).append(']'); } } else { if (index != WHOLE_COLLECTION) { buffer.append("/.[").append(index + 1).append(']'); } else { buffer.append("/"); } } return buffer.toString(); } } ././@LongLink100644 0 0 147 11044114245 10251 Lustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/beans/CollectionPointerFactory.javacommons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/beans/CollectionPointerFactory.ja100644 0 0 3572 11044113534 31036 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.beans; import java.util.Locale; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.NodePointerFactory; import org.apache.commons.jxpath.util.ValueUtils; /** * Implements NodePointerFactory for stand-alone collections. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class CollectionPointerFactory implements NodePointerFactory { /** factory order constant */ public static final int COLLECTION_POINTER_FACTORY_ORDER = 10; public int getOrder() { return COLLECTION_POINTER_FACTORY_ORDER; } public NodePointer createNodePointer(QName name, Object bean, Locale locale) { return ValueUtils.isCollection(bean) ? new CollectionPointer(bean, locale) : null; } public NodePointer createNodePointer(NodePointer parent, QName name, Object bean) { return ValueUtils.isCollection(bean) ? new CollectionPointer(parent, bean) : null; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/beans/LangAttributePointer.java100644 0 0 6167 11044113534 30512 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.beans; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.model.NodePointer; /** * A Pointer that points to the "lang" attribute of a JavaBean. The value * of the attribute is based on the locale supplied to it in the constructor. * * @author Dmitri Plotnikov * @version $Revision: 652884 $ $Date: 2008-05-02 15:02:00 -0500 (Fri, 02 May 2008) $ */ public class LangAttributePointer extends NodePointer { private static final long serialVersionUID = -8665319197100034134L; /** * Create a new LangAttributePointer. * @param parent parent pointer. */ public LangAttributePointer(NodePointer parent) { super(parent); } public QName getName() { return new QName("xml", "lang"); } public String getNamespaceURI() { return null; } public boolean isCollection() { return false; } public int getLength() { return 1; } public Object getBaseValue() { return parent.getLocale().toString().replace('_', '-'); } public Object getImmediateNode() { return getBaseValue(); } public boolean isLeaf() { return true; } /** * {@inheritDoc} * * Throws UnsupportedOperationException. * @param value Object */ public void setValue(Object value) { throw new UnsupportedOperationException( "Cannot change locale using the 'lang' attribute"); } public String asPath() { StringBuffer buffer = new StringBuffer(); if (parent != null) { buffer.append(parent.asPath()); if (buffer.length() == 0 || buffer.charAt(buffer.length() - 1) != '/') { buffer.append('/'); } } buffer.append("@xml:lang"); return buffer.toString(); } public int hashCode() { return 0; } public boolean equals(Object object) { return object instanceof LangAttributePointer; } public boolean testNode(NodeTest test) { return false; } public int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2) { // Won't happen - lang attributes don't have children return 0; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/beans/NullElementPointer.java100644 0 0 10516 11044113534 30202 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.beans; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; /** * Used when there is a need to construct a Pointer for a collection element * that does not exist. For example, if the path is "foo[3]", but the * collection "foo" only has one element or is empty or is null, the * NullElementPointer can be used to capture this situation without putting a * regular NodePointer into an invalid state. Just create a NullElementPointer * with index 2 (= 3 - 1) and a "foo" pointer as the parent. * * @author Dmitri Plotnikov * @version $Revision: 652884 $ $Date: 2008-05-02 15:02:00 -0500 (Fri, 02 May 2008) $ */ public class NullElementPointer extends CollectionPointer { private static final long serialVersionUID = 8714236818791036721L; /** * Create a new NullElementPointer. * @param parent parent pointer * @param index int */ public NullElementPointer(NodePointer parent, int index) { super(parent, (Object) null); this.index = index; } public QName getName() { return null; } public Object getBaseValue() { return null; } public Object getImmediateNode() { return null; } public boolean isLeaf() { return true; } public boolean isCollection() { return false; } /** * Get the property pointer for this. * @return PropertyPointer */ public PropertyPointer getPropertyPointer() { return new NullPropertyPointer(this); } public NodePointer getValuePointer() { return new NullPointer(this, getName()); } public void setValue(Object value) { throw new UnsupportedOperationException( "Collection element does not exist: " + this); } public boolean isActual() { return false; } public boolean isContainer() { return true; } public NodePointer createPath(JXPathContext context) { return parent.createChild(context, null, index); } public NodePointer createPath(JXPathContext context, Object value) { return parent.createChild(context, null, index, value); } public int hashCode() { return getImmediateParentPointer().hashCode() + index; } public boolean equals(Object object) { if (object == this) { return true; } if (!(object instanceof NullElementPointer)) { return false; } NullElementPointer other = (NullElementPointer) object; return getImmediateParentPointer() == other.getImmediateParentPointer() && index == other.index; } public int getLength() { return 0; } public String asPath() { StringBuffer buffer = new StringBuffer(); NodePointer parent = getImmediateParentPointer(); if (parent != null) { buffer.append(parent.asPath()); } if (index != WHOLE_COLLECTION) { // Address the list[1][2] case if (parent != null && parent.getIndex() != WHOLE_COLLECTION) { buffer.append("/."); } else if (parent != null && parent.getImmediateParentPointer() != null && parent.getImmediateParentPointer().getIndex() != WHOLE_COLLECTION) { buffer.append("/."); } buffer.append("[").append(index + 1).append(']'); } return buffer.toString(); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/beans/NullPointer.java100644 0 0 7717 11044113534 26661 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.beans; import java.util.Locale; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; /** * Pointer whose value is null. * @author Dmitri Plotnikov * @version $Revision: 652915 $ $Date: 2008-05-02 16:12:57 -0500 (Fri, 02 May 2008) $ */ public class NullPointer extends PropertyOwnerPointer { private QName name; private String id; private static final long serialVersionUID = 2193425983220679887L; /** * Create a new NullPointer. * @param name node name * @param locale Locale */ public NullPointer(QName name, Locale locale) { super(null, locale); this.name = name; } /** * Used for the root node. * @param parent parent pointer * @param name node name */ public NullPointer(NodePointer parent, QName name) { super(parent); this.name = name; } /** * Create a new NullPointer. * @param locale Locale * @param id String */ public NullPointer(Locale locale, String id) { super(null, locale); this.id = id; } public QName getName() { return name; } public Object getBaseValue() { return null; } public boolean isCollection() { return false; } public boolean isLeaf() { return true; } public boolean isActual() { return false; } public PropertyPointer getPropertyPointer() { return new NullPropertyPointer(this); } public NodePointer createPath(JXPathContext context, Object value) { if (parent != null) { return parent.createPath(context, value).getValuePointer(); } throw new UnsupportedOperationException( "Cannot create the root object: " + asPath()); } public NodePointer createPath(JXPathContext context) { if (parent != null) { return parent.createPath(context).getValuePointer(); } throw new UnsupportedOperationException( "Cannot create the root object: " + asPath()); } public NodePointer createChild( JXPathContext context, QName name, int index) { return createPath(context).createChild(context, name, index); } public NodePointer createChild( JXPathContext context, QName name, int index, Object value) { return createPath(context).createChild(context, name, index, value); } public int hashCode() { return name == null ? 0 : name.hashCode(); } public boolean equals(Object object) { if (object == this) { return true; } if (!(object instanceof NullPointer)) { return false; } NullPointer other = (NullPointer) object; return name == other.name || name != null && name.equals(other.name); } public String asPath() { if (id != null) { return "id(" + id + ")"; } return parent == null ? "null()" : super.asPath(); } public int getLength() { return 0; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/beans/NullPropertyPointer.java100644 0 0 16666 11044113534 30451 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.beans; import org.apache.commons.jxpath.AbstractFactory; import org.apache.commons.jxpath.JXPathAbstractFactoryException; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathInvalidAccessException; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; /** * @author Dmitri Plotnikov * @version $Revision: 652884 $ $Date: 2008-05-02 15:02:00 -0500 (Fri, 02 May 2008) $ */ public class NullPropertyPointer extends PropertyPointer { private String propertyName = "*"; private boolean byNameAttribute = false; private static final long serialVersionUID = 5296593071854982754L; /** * Create a new NullPropertyPointer. * @param parent pointer */ public NullPropertyPointer(NodePointer parent) { super(parent); } public QName getName() { return new QName(propertyName); } public void setPropertyIndex(int index) { } public int getLength() { return 0; } public Object getBaseValue() { return null; } public Object getImmediateNode() { return null; } public boolean isLeaf() { return true; } public NodePointer getValuePointer() { return new NullPointer(this, new QName(getPropertyName())); } protected boolean isActualProperty() { return false; } public boolean isActual() { return false; } public boolean isContainer() { return true; } public void setValue(Object value) { if (parent == null || parent.isContainer()) { throw new JXPathInvalidAccessException( "Cannot set property " + asPath() + ", the target object is null"); } if (parent instanceof PropertyOwnerPointer && ((PropertyOwnerPointer) parent) .isDynamicPropertyDeclarationSupported()) { // If the parent property owner can create // a property automatically - let it do so PropertyPointer propertyPointer = ((PropertyOwnerPointer) parent).getPropertyPointer(); propertyPointer.setPropertyName(propertyName); propertyPointer.setValue(value); } else { throw new JXPathInvalidAccessException( "Cannot set property " + asPath() + ", path does not match a changeable location"); } } public NodePointer createPath(JXPathContext context) { NodePointer newParent = parent.createPath(context); if (isAttribute()) { return newParent.createAttribute(context, getName()); } if (parent instanceof NullPointer && parent.equals(newParent)) { throw createBadFactoryException(context.getFactory()); } // Consider these two use cases: // 1. The parent pointer of NullPropertyPointer is // a PropertyOwnerPointer other than NullPointer. When we call // createPath on it, it most likely returns itself. We then // take a PropertyPointer from it and get the PropertyPointer // to expand the collection for the corresponding property. // // 2. The parent pointer of NullPropertyPointer is a NullPointer. // When we call createPath, it may return a PropertyOwnerPointer // or it may return anything else, like a DOMNodePointer. // In the former case we need to do exactly what we did in use // case 1. In the latter case, we simply request that the // non-property pointer expand the collection by itself. if (newParent instanceof PropertyOwnerPointer) { PropertyOwnerPointer pop = (PropertyOwnerPointer) newParent; newParent = pop.getPropertyPointer(); } return newParent.createChild(context, getName(), getIndex()); } public NodePointer createPath(JXPathContext context, Object value) { NodePointer newParent = parent.createPath(context); if (isAttribute()) { NodePointer pointer = newParent.createAttribute(context, getName()); pointer.setValue(value); return pointer; } if (parent instanceof NullPointer && parent.equals(newParent)) { throw createBadFactoryException(context.getFactory()); } if (newParent instanceof PropertyOwnerPointer) { PropertyOwnerPointer pop = (PropertyOwnerPointer) newParent; newParent = pop.getPropertyPointer(); } return newParent.createChild(context, getName(), index, value); } public NodePointer createChild(JXPathContext context, QName name, int index) { return createPath(context).createChild(context, name, index); } public NodePointer createChild(JXPathContext context, QName name, int index, Object value) { return createPath(context).createChild(context, name, index, value); } public String getPropertyName() { return propertyName; } public void setPropertyName(String propertyName) { this.propertyName = propertyName; } /** * Set the name attribute. * @param attributeValue value to set */ public void setNameAttributeValue(String attributeValue) { this.propertyName = attributeValue; byNameAttribute = true; } public boolean isCollection() { return getIndex() != WHOLE_COLLECTION; } public int getPropertyCount() { return 0; } public String[] getPropertyNames() { return new String[0]; } public String asPath() { if (!byNameAttribute) { return super.asPath(); } StringBuffer buffer = new StringBuffer(); buffer.append(getImmediateParentPointer().asPath()); buffer.append("[@name='"); buffer.append(escape(getPropertyName())); buffer.append("']"); if (index != WHOLE_COLLECTION) { buffer.append('[').append(index + 1).append(']'); } return buffer.toString(); } /** * Create a "bad factory" JXPathAbstractFactoryException for the specified AbstractFactory. * @param factory AbstractFactory * @return JXPathAbstractFactoryException */ private JXPathAbstractFactoryException createBadFactoryException(AbstractFactory factory) { return new JXPathAbstractFactoryException("Factory " + factory + " reported success creating object for path: " + asPath() + " but object was null. Terminating to avoid stack recursion."); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/beans/package.html100644 0 0 1610 11044113534 26006 0ustar 0 0 Implementation of "model" APIs for JavaBeans, Dynamic Property Objects, collections and null. commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/beans/PropertyIterator.java100644 0 0 24363 11044113534 27760 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.beans; import org.apache.commons.jxpath.JXPathException; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; /** * Iterates property values of an object pointed at with a {@link PropertyOwnerPointer}. * Examples of such objects are JavaBeans and objects with Dynamic Properties. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class PropertyIterator implements NodeIterator { private boolean empty = false; private boolean reverse; private String name; private int startIndex = 0; private boolean targetReady = false; private int position = 0; private PropertyPointer propertyNodePointer; private int startPropertyIndex; private boolean includeStart = false; /** * Create a new PropertyIterator. * @param pointer owning pointer * @param name property name * @param reverse iteration order * @param startWith beginning pointer */ public PropertyIterator( PropertyOwnerPointer pointer, String name, boolean reverse, NodePointer startWith) { propertyNodePointer = (PropertyPointer) pointer.getPropertyPointer().clone(); this.name = name; this.reverse = reverse; this.includeStart = true; if (reverse) { this.startPropertyIndex = PropertyPointer.UNSPECIFIED_PROPERTY; this.startIndex = -1; } if (startWith != null) { while (startWith != null && startWith.getImmediateParentPointer() != pointer) { startWith = startWith.getImmediateParentPointer(); } if (startWith == null) { throw new JXPathException( "PropertyIerator startWith parameter is " + "not a child of the supplied parent"); } this.startPropertyIndex = ((PropertyPointer) startWith).getPropertyIndex(); this.startIndex = startWith.getIndex(); if (this.startIndex == NodePointer.WHOLE_COLLECTION) { this.startIndex = 0; } this.includeStart = false; if (reverse && startIndex == -1) { this.includeStart = true; } } } /** * Get the property pointer. * @return NodePointer */ protected NodePointer getPropertyPointer() { return propertyNodePointer; } /** * Reset property iteration. */ public void reset() { position = 0; targetReady = false; } public NodePointer getNodePointer() { if (position == 0) { if (name != null) { if (!targetReady) { prepareForIndividualProperty(name); } // If there is no such property - return null if (empty) { return null; } } else { if (!setPosition(1)) { return null; } reset(); } } try { return propertyNodePointer.getValuePointer(); } catch (Throwable ex) { // @todo: should this exception be reported in any way? NullPropertyPointer npp = new NullPropertyPointer( propertyNodePointer.getImmediateParentPointer()); npp.setPropertyName(propertyNodePointer.getPropertyName()); npp.setIndex(propertyNodePointer.getIndex()); return npp.getValuePointer(); } } public int getPosition() { return position; } public boolean setPosition(int position) { return name == null ? setPositionAllProperties(position) : setPositionIndividualProperty(position); } /** * Set position for an individual property. * @param position int position * @return whether this was a valid position */ private boolean setPositionIndividualProperty(int position) { this.position = position; if (position < 1) { return false; } if (!targetReady) { prepareForIndividualProperty(name); } if (empty) { return false; } int length = getLength(); int index; if (!reverse) { index = position + startIndex; if (!includeStart) { index++; } if (index > length) { return false; } } else { int end = startIndex; if (end == -1) { end = length - 1; } index = end - position + 2; if (!includeStart) { index--; } if (index < 1) { return false; } } propertyNodePointer.setIndex(index - 1); return true; } /** * Set position for all properties * @param position int position * @return whether this was a valid position */ private boolean setPositionAllProperties(int position) { this.position = position; if (position < 1) { return false; } int offset; int count = propertyNodePointer.getPropertyCount(); if (!reverse) { int index = 1; for (int i = startPropertyIndex; i < count; i++) { propertyNodePointer.setPropertyIndex(i); int length = getLength(); if (i == startPropertyIndex) { length -= startIndex; if (!includeStart) { length--; } offset = startIndex + position - index; if (!includeStart) { offset++; } } else { offset = position - index; } if (index <= position && position < index + length) { propertyNodePointer.setIndex(offset); return true; } index += length; } } else { int index = 1; int start = startPropertyIndex; if (start == PropertyPointer.UNSPECIFIED_PROPERTY) { start = count - 1; } for (int i = start; i >= 0; i--) { propertyNodePointer.setPropertyIndex(i); int length = getLength(); if (i == startPropertyIndex) { int end = startIndex; if (end == -1) { end = length - 1; } length = end + 1; offset = end - position + 1; if (!includeStart) { offset--; length--; } } else { offset = length - (position - index) - 1; } if (index <= position && position < index + length) { propertyNodePointer.setIndex(offset); return true; } index += length; } } return false; } /** * Prepare for an individual property. * @param name property name */ protected void prepareForIndividualProperty(String name) { targetReady = true; empty = true; String[] names = propertyNodePointer.getPropertyNames(); if (!reverse) { if (startPropertyIndex == PropertyPointer.UNSPECIFIED_PROPERTY) { startPropertyIndex = 0; } if (startIndex == NodePointer.WHOLE_COLLECTION) { startIndex = 0; } for (int i = startPropertyIndex; i < names.length; i++) { if (names[i].equals(name)) { propertyNodePointer.setPropertyIndex(i); if (i != startPropertyIndex) { startIndex = 0; includeStart = true; } empty = false; break; } } } else { if (startPropertyIndex == PropertyPointer.UNSPECIFIED_PROPERTY) { startPropertyIndex = names.length - 1; } if (startIndex == NodePointer.WHOLE_COLLECTION) { startIndex = -1; } for (int i = startPropertyIndex; i >= 0; i--) { if (names[i].equals(name)) { propertyNodePointer.setPropertyIndex(i); if (i != startPropertyIndex) { startIndex = -1; includeStart = true; } empty = false; break; } } } } /** * Computes length for the current pointer - ignores any exceptions. * @return length */ private int getLength() { int length; try { length = propertyNodePointer.getLength(); // TBD: cache length } catch (Throwable t) { // @todo: should this exception be reported in any way? length = 0; } return length; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/beans/PropertyOwnerPointer.java100644 0 0 14575 11044113534 30626 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.beans; import java.util.Locale; import org.apache.commons.jxpath.JXPathInvalidAccessException; import org.apache.commons.jxpath.ri.Compiler; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.compiler.NodeNameTest; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.compiler.NodeTypeTest; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.util.ValueUtils; /** * A pointer describing a node that has properties, each of which could be * a collection. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public abstract class PropertyOwnerPointer extends NodePointer { private static final Object UNINITIALIZED = new Object(); private Object value = UNINITIALIZED; public NodeIterator childIterator(NodeTest test, boolean reverse, NodePointer startWith) { if (test == null) { return createNodeIterator(null, reverse, startWith); } if (test instanceof NodeNameTest) { NodeNameTest nodeNameTest = (NodeNameTest) test; QName testName = nodeNameTest.getNodeName(); if (isValidProperty(testName)) { return createNodeIterator(nodeNameTest.isWildcard() ? null : testName.toString(), reverse, startWith); } return null; } return test instanceof NodeTypeTest && ((NodeTypeTest) test).getNodeType() == Compiler.NODE_TYPE_NODE ? createNodeIterator(null, reverse, startWith) : null; } /** * Create a NodeIterator. * @param property property name * @param reverse whether to iterate in reverse * @param startWith first pointer to return * @return NodeIterator */ public NodeIterator createNodeIterator(String property, boolean reverse, NodePointer startWith) { return new PropertyIterator(this, property, reverse, startWith); } public NodeIterator attributeIterator(QName name) { return new BeanAttributeIterator(this, name); } /** * Create a new PropertyOwnerPointer. * @param parent parent pointer * @param locale Locale */ protected PropertyOwnerPointer(NodePointer parent, Locale locale) { super(parent, locale); } /** * Create a new PropertyOwnerPointer. * @param parent pointer */ protected PropertyOwnerPointer(NodePointer parent) { super(parent); } public void setIndex(int index) { if (this.index != index) { super.setIndex(index); value = UNINITIALIZED; } } public Object getImmediateNode() { if (value == UNINITIALIZED) { value = index == WHOLE_COLLECTION ? ValueUtils.getValue(getBaseValue()) : ValueUtils.getValue(getBaseValue(), index); } return value; } public abstract QName getName(); /** * Learn whether name is a valid child name for this PropertyOwnerPointer. * @param name the QName to test * @return true if QName is a valid property name. * @since JXPath 1.3 */ public boolean isValidProperty(QName name) { return isDefaultNamespace(name.getPrefix()); } /** * Throws an exception if you try to change the root element, otherwise * forwards the call to the parent pointer. * @param value to set */ public void setValue(Object value) { this.value = value; if (parent != null) { if (parent.isContainer()) { parent.setValue(value); } else { if (index == WHOLE_COLLECTION) { throw new UnsupportedOperationException( "Cannot setValue of an object that is not " + "some other object's property"); } throw new JXPathInvalidAccessException( "The specified collection element does not exist: " + this); } } else { throw new UnsupportedOperationException( "Cannot replace the root object"); } } /** * If this is a root node pointer, throws an exception; otherwise * forwards the call to the parent node. */ public void remove() { this.value = null; if (parent != null) { parent.remove(); } else { throw new UnsupportedOperationException( "Cannot remove an object that is not " + "some other object's property or a collection element"); } } /** * Get a PropertyPointer for this PropertyOwnerPointer. * @return PropertyPointer */ public abstract PropertyPointer getPropertyPointer(); /** * Learn whether dynamic property declaration is supported. * @return true if the property owner can set a property "does not exist". * A good example is a Map. You can always assign a value to any * key even if it has never been "declared". */ public boolean isDynamicPropertyDeclarationSupported() { return false; } public int compareChildNodePointers(NodePointer pointer1, NodePointer pointer2) { int r = pointer1.getName().toString().compareTo(pointer2.getName().toString()); return r == 0 ? pointer1.getIndex() - pointer2.getIndex() : r; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/beans/PropertyPointer.java100644 0 0 16525 11044113534 27610 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.beans; import org.apache.commons.jxpath.AbstractFactory; import org.apache.commons.jxpath.JXPathAbstractFactoryException; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathIntrospector; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.util.ValueUtils; /** * A pointer allocated by a PropertyOwnerPointer to represent the value of * a property of the parent object. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public abstract class PropertyPointer extends NodePointer { public static final int UNSPECIFIED_PROPERTY = Integer.MIN_VALUE; /** property index */ protected int propertyIndex = UNSPECIFIED_PROPERTY; /** owning object */ protected Object bean; /** * Takes a javabean, a descriptor of a property of that object and * an offset within that property (starting with 0). * @param parent parent pointer */ public PropertyPointer(NodePointer parent) { super(parent); } /** * Get the property index. * @return int index */ public int getPropertyIndex() { return propertyIndex; } /** * Set the property index. * @param index property index */ public void setPropertyIndex(int index) { if (propertyIndex != index) { propertyIndex = index; setIndex(WHOLE_COLLECTION); } } /** * Get the parent bean. * @return Object */ public Object getBean() { if (bean == null) { bean = getImmediateParentPointer().getNode(); } return bean; } public QName getName() { return new QName(null, getPropertyName()); } /** * Get the property name. * @return String property name. */ public abstract String getPropertyName(); /** * Set the property name. * @param propertyName property name to set. */ public abstract void setPropertyName(String propertyName); /** * Count the number of properties represented. * @return int */ public abstract int getPropertyCount(); /** * Get the names of the included properties. * @return String[] */ public abstract String[] getPropertyNames(); /** * Learn whether this pointer references an actual property. * @return true if actual */ protected abstract boolean isActualProperty(); public boolean isActual() { if (!isActualProperty()) { return false; } return super.isActual(); } private static final Object UNINITIALIZED = new Object(); private Object value = UNINITIALIZED; public Object getImmediateNode() { if (value == UNINITIALIZED) { value = index == WHOLE_COLLECTION ? ValueUtils.getValue(getBaseValue()) : ValueUtils.getValue(getBaseValue(), index); } return value; } public boolean isCollection() { Object value = getBaseValue(); return value != null && ValueUtils.isCollection(value); } public boolean isLeaf() { Object value = getNode(); return value == null || JXPathIntrospector.getBeanInfo(value.getClass()).isAtomic(); } /** * If the property contains a collection, then the length of that * collection, otherwise - 1. * @return int length */ public int getLength() { return ValueUtils.getLength(getBaseValue()); } /** * Returns a NodePointer that can be used to access the currently * selected property value. * @return NodePointer */ public NodePointer getImmediateValuePointer() { return NodePointer.newChildNodePointer( (NodePointer) this.clone(), getName(), getImmediateNode()); } public NodePointer createPath(JXPathContext context) { if (getImmediateNode() == null) { AbstractFactory factory = getAbstractFactory(context); int inx = (index == WHOLE_COLLECTION ? 0 : index); boolean success = factory.createObject( context, this, getBean(), getPropertyName(), inx); if (!success) { throw new JXPathAbstractFactoryException("Factory " + factory + " could not create an object for path: " + asPath()); } } return this; } public NodePointer createPath(JXPathContext context, Object value) { // If neccessary, expand collection if (index != WHOLE_COLLECTION && index >= getLength()) { createPath(context); } setValue(value); return this; } public NodePointer createChild( JXPathContext context, QName name, int index, Object value) { PropertyPointer prop = (PropertyPointer) clone(); if (name != null) { prop.setPropertyName(name.toString()); } prop.setIndex(index); return prop.createPath(context, value); } public NodePointer createChild( JXPathContext context, QName name, int index) { PropertyPointer prop = (PropertyPointer) clone(); if (name != null) { prop.setPropertyName(name.toString()); } prop.setIndex(index); return prop.createPath(context); } public int hashCode() { return getImmediateParentPointer().hashCode() + propertyIndex + index; } public boolean equals(Object object) { if (object == this) { return true; } if (!(object instanceof PropertyPointer)) { return false; } PropertyPointer other = (PropertyPointer) object; if (parent != other.parent && (parent == null || !parent.equals(other.parent))) { return false; } if (getPropertyIndex() != other.getPropertyIndex() || !getPropertyName().equals(other.getPropertyName())) { return false; } int iThis = (index == WHOLE_COLLECTION ? 0 : index); int iOther = (other.index == WHOLE_COLLECTION ? 0 : other.index); return iThis == iOther; } public int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2) { return getValuePointer().compareChildNodePointers(pointer1, pointer2); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/container/ContainerPointer.java100644 0 0 11553 11044113531 30571 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.container; import java.util.Locale; import org.apache.commons.jxpath.Container; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.util.ValueUtils; /** * Transparent pointer to a Container. The {@link #getValue()} method * returns the contents of the container, rather than the container * itself. * * @author Dmitri Plotnikov * @version $Revision: 652884 $ $Date: 2008-05-02 15:02:00 -0500 (Fri, 02 May 2008) $ */ public class ContainerPointer extends NodePointer { private Container container; private NodePointer valuePointer; private static final long serialVersionUID = 6140752946621686118L; /** * Create a new ContainerPointer. * @param container Container object * @param locale Locale */ public ContainerPointer(Container container, Locale locale) { super(null, locale); this.container = container; } /** * Create a new ContainerPointer. * @param parent parent pointer * @param container Container object */ public ContainerPointer(NodePointer parent, Container container) { super(parent); this.container = container; } /** * This type of node is auxiliary. * @return true. */ public boolean isContainer() { return true; } public QName getName() { return null; } public Object getBaseValue() { return container; } public boolean isCollection() { Object value = getBaseValue(); return value != null && ValueUtils.isCollection(value); } public int getLength() { Object value = getBaseValue(); return value == null ? 1 : ValueUtils.getLength(value); } public boolean isLeaf() { return getValuePointer().isLeaf(); } public Object getImmediateNode() { Object value = getBaseValue(); if (index != WHOLE_COLLECTION) { return index >= 0 && index < getLength() ? ValueUtils.getValue(value, index) : null; } return ValueUtils.getValue(value); } public void setValue(Object value) { // TODO: what if this is a collection? container.setValue(value); } public NodePointer getImmediateValuePointer() { if (valuePointer == null) { Object value = getImmediateNode(); valuePointer = NodePointer.newChildNodePointer(this, getName(), value); } return valuePointer; } public int hashCode() { return System.identityHashCode(container) + index; } public boolean equals(Object object) { if (object == this) { return true; } if (!(object instanceof ContainerPointer)) { return false; } ContainerPointer other = (ContainerPointer) object; return container == other.container && index == other.index; } public NodeIterator childIterator( NodeTest test, boolean reverse, NodePointer startWith) { return getValuePointer().childIterator(test, reverse, startWith); } public NodeIterator attributeIterator(QName name) { return getValuePointer().attributeIterator(name); } public NodeIterator namespaceIterator() { return getValuePointer().namespaceIterator(); } public NodePointer namespacePointer(String namespace) { return getValuePointer().namespacePointer(namespace); } public boolean testNode(NodeTest nodeTest) { return getValuePointer().testNode(nodeTest); } public int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2) { return pointer1.getIndex() - pointer2.getIndex(); } public String getNamespaceURI(String prefix) { return getValuePointer().getNamespaceURI(prefix); } public String asPath() { return parent == null ? "/" : parent.asPath(); } } ././@LongLink100644 0 0 152 11044114245 10245 Lustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/container/ContainerPointerFactory.javacommons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/container/ContainerPointerFactory100644 0 0 3656 11044113531 31166 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.container; import java.util.Locale; import org.apache.commons.jxpath.Container; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.NodePointerFactory; /** * Implements NodePointerFactory for {@link Container} objects. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class ContainerPointerFactory implements NodePointerFactory { /** factory order for this factory */ public static final int CONTAINER_POINTER_FACTORY_ORDER = 200; public int getOrder() { return CONTAINER_POINTER_FACTORY_ORDER; } public NodePointer createNodePointer(QName name, Object bean, Locale locale) { return bean instanceof Container ? new ContainerPointer( (Container) bean, locale) : null; } public NodePointer createNodePointer(NodePointer parent, QName name, Object bean) { return bean instanceof Container ? new ContainerPointer(parent, (Container) bean) : null; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/container/package.html100644 0 0 1531 11044113531 26677 0ustar 0 0 Implementation of "model" APIs for Containers. commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributeIterator.java100644 0 0 12607 11044113531 30121 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dom; import java.util.ArrayList; import java.util.List; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; import org.w3c.dom.Attr; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; /** * An iterator of attributes of a DOM Node. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class DOMAttributeIterator implements NodeIterator { private NodePointer parent; private QName name; private List attributes; private int position = 0; /** * Create a new DOMAttributeIterator. * @param parent pointer * @param name to test */ public DOMAttributeIterator(NodePointer parent, QName name) { this.parent = parent; this.name = name; attributes = new ArrayList(); Node node = (Node) parent.getNode(); if (node.getNodeType() == Node.ELEMENT_NODE) { String lname = name.getName(); if (!lname.equals("*")) { Attr attr = getAttribute((Element) node, name); if (attr != null) { attributes.add(attr); } } else { NamedNodeMap map = node.getAttributes(); int count = map.getLength(); for (int i = 0; i < count; i++) { Attr attr = (Attr) map.item(i); if (testAttr(attr)) { attributes.add(attr); } } } } } /** * Test an attribute. * @param attr to test * @return whether test succeeded */ private boolean testAttr(Attr attr) { String nodePrefix = DOMNodePointer.getPrefix(attr); String nodeLocalName = DOMNodePointer.getLocalName(attr); if (nodePrefix != null && nodePrefix.equals("xmlns")) { return false; } if (nodePrefix == null && nodeLocalName.equals("xmlns")) { return false; } String testLocalName = name.getName(); if (testLocalName.equals("*") || testLocalName.equals(nodeLocalName)) { String testPrefix = name.getPrefix(); if (testPrefix == null || equalStrings(testPrefix, nodePrefix)) { return true; } if (nodePrefix == null) { return false; } return equalStrings(parent.getNamespaceURI(testPrefix), parent .getNamespaceURI(nodePrefix)); } return false; } /** * Test whether two strings are == or .equals() * @param s1 first string * @param s2 second string * @return boolean */ private static boolean equalStrings(String s1, String s2) { return s1 == s2 || s1 != null && s1.equals(s2); } /** * Get the named attribute. * @param element to search * @param name to match * @return Attr found */ private Attr getAttribute(Element element, QName name) { String testPrefix = name.getPrefix(); String testNS = null; if (testPrefix != null) { testNS = parent.getNamespaceResolver().getNamespaceURI(testPrefix); } if (testNS != null) { Attr attr = element.getAttributeNodeNS(testNS, name.getName()); if (attr != null) { return attr; } // This may mean that the parser does not support NS for // attributes, example - the version of Crimson bundled // with JDK 1.4.0 NamedNodeMap nnm = element.getAttributes(); for (int i = 0; i < nnm.getLength(); i++) { attr = (Attr) nnm.item(i); if (testAttr(attr)) { return attr; } } return null; } return element.getAttributeNode(name.getName()); } public NodePointer getNodePointer() { if (position == 0) { if (!setPosition(1)) { return null; } position = 0; } int index = position - 1; if (index < 0) { index = 0; } return new DOMAttributePointer(parent, (Attr) attributes.get(index)); } public int getPosition() { return position; } public boolean setPosition(int position) { this.position = position; return position >= 1 && position <= attributes.size(); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributePointer.java100644 0 0 10027 11044113531 27742 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dom; import org.apache.commons.jxpath.ri.Compiler; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.compiler.NodeTypeTest; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.util.TypeUtils; import org.w3c.dom.Attr; /** * A Pointer that points to a DOM node. Because the underlying DOM Attr is not Serializable, * neither is this pointer class truly so. * * @author Dmitri Plotnikov * @version $Revision: 670727 $ $Date: 2008-06-23 15:10:38 -0500 (Mon, 23 Jun 2008) $ */ public class DOMAttributePointer extends NodePointer { private static final long serialVersionUID = 1115085175427555951L; private Attr attr; /** * Create a new DOMAttributePointer. * @param parent pointer * @param attr pointed */ public DOMAttributePointer(NodePointer parent, Attr attr) { super(parent); this.attr = attr; } public QName getName() { return new QName( DOMNodePointer.getPrefix(attr), DOMNodePointer.getLocalName(attr)); } public String getNamespaceURI() { String prefix = DOMNodePointer.getPrefix(attr); return prefix == null ? null : parent.getNamespaceURI(prefix); } public Object getValue() { String value = attr.getValue(); if (value == null || (value.equals("") && !attr.getSpecified())) { return null; } return value; } public Object getBaseValue() { return attr; } public boolean isCollection() { return false; } public int getLength() { return 1; } public Object getImmediateNode() { return attr; } public boolean isActual() { return true; } public boolean isLeaf() { return true; } public boolean testNode(NodeTest nodeTest) { return nodeTest == null || ((nodeTest instanceof NodeTypeTest) && ((NodeTypeTest) nodeTest).getNodeType() == Compiler.NODE_TYPE_NODE); } /** * Sets the value of this attribute. * @param value to set */ public void setValue(Object value) { attr.setValue((String) TypeUtils.convert(value, String.class)); } public void remove() { attr.getOwnerElement().removeAttributeNode(attr); } public String asPath() { StringBuffer buffer = new StringBuffer(); if (parent != null) { buffer.append(parent.asPath()); if (buffer.length() == 0 || buffer.charAt(buffer.length() - 1) != '/') { buffer.append('/'); } } buffer.append('@'); buffer.append(getName()); return buffer.toString(); } public int hashCode() { return System.identityHashCode(attr); } public boolean equals(Object object) { return object == this || object instanceof DOMAttributePointer && attr == ((DOMAttributePointer) object).attr; } public int compareChildNodePointers(NodePointer pointer1, NodePointer pointer2) { // Won't happen - attributes don't have children return 0; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNamespaceIterator.java100644 0 0 7011 11044113531 30023 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dom; import java.util.ArrayList; import java.util.List; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; /** * An iterator of namespaces of a DOM Node. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class DOMNamespaceIterator implements NodeIterator { private NodePointer parent; private List attributes; private int position = 0; /** * Create a new DOMNamespaceIterator. * @param parent parent pointer */ public DOMNamespaceIterator(NodePointer parent) { this.parent = parent; attributes = new ArrayList(); collectNamespaces(attributes, (Node) parent.getNode()); } /** * Collect namespaces from attribute nodes. * @param attributes attribute list * @param node target node */ private void collectNamespaces(List attributes, Node node) { Node parent = node.getParentNode(); if (parent != null) { collectNamespaces(attributes, parent); } if (node.getNodeType() == Node.DOCUMENT_NODE) { node = ((Document) node).getDocumentElement(); } if (node.getNodeType() == Node.ELEMENT_NODE) { NamedNodeMap map = node.getAttributes(); int count = map.getLength(); for (int i = 0; i < count; i++) { Attr attr = (Attr) map.item(i); String prefix = DOMNodePointer.getPrefix(attr); String name = DOMNodePointer.getLocalName(attr); if ((prefix != null && prefix.equals("xmlns")) || (prefix == null && name.equals("xmlns"))) { attributes.add(attr); } } } } public NodePointer getNodePointer() { if (position == 0) { if (!setPosition(1)) { return null; } position = 0; } int index = position - 1; if (index < 0) { index = 0; } String prefix = ""; Attr attr = (Attr) attributes.get(index); String name = attr.getPrefix(); if (name != null && name.equals("xmlns")) { prefix = DOMNodePointer.getLocalName(attr); } return new NamespacePointer(parent, prefix, attr.getValue()); } public int getPosition() { return position; } public boolean setPosition(int position) { this.position = position; return position >= 1 && position <= attributes.size(); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodeIterator.java100644 0 0 11062 11044113531 27035 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dom; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; import org.w3c.dom.Node; /** * An iterator of children of a DOM Node. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class DOMNodeIterator implements NodeIterator { private NodePointer parent; private NodeTest nodeTest; private Node node; private Node child = null; private boolean reverse; private int position = 0; /** * Create a new DOMNodeIterator. * @param parent parent pointer * @param nodeTest test * @param reverse whether to iterate in reverse * @param startWith starting pointer */ public DOMNodeIterator( NodePointer parent, NodeTest nodeTest, boolean reverse, NodePointer startWith) { this.parent = parent; this.node = (Node) parent.getNode(); if (startWith != null) { this.child = (Node) startWith.getNode(); } this.nodeTest = nodeTest; this.reverse = reverse; } public NodePointer getNodePointer() { if (position == 0) { setPosition(1); } return child == null ? null : new DOMNodePointer(parent, child); } public int getPosition() { return position; } public boolean setPosition(int position) { while (this.position < position) { if (!next()) { return false; } } while (this.position > position) { if (!previous()) { return false; } } return true; } /** * Set the previous position. * @return whether valid */ private boolean previous() { position--; if (!reverse) { if (position == 0) { child = null; } else if (child == null) { child = node.getLastChild(); } else { child = child.getPreviousSibling(); } while (child != null && !testChild()) { child = child.getPreviousSibling(); } } else { child = child.getNextSibling(); while (child != null && !testChild()) { child = child.getNextSibling(); } } return child != null; } /** * Set the next position. * @return whether valid */ private boolean next() { position++; if (!reverse) { if (position == 1) { if (child == null) { child = node.getFirstChild(); } else { child = child.getNextSibling(); } } else { child = child.getNextSibling(); } while (child != null && !testChild()) { child = child.getNextSibling(); } } else { if (position == 1) { if (child == null) { child = node.getLastChild(); } else { child = child.getPreviousSibling(); } } else { child = child.getPreviousSibling(); } while (child != null && !testChild()) { child = child.getPreviousSibling(); } } return child != null; } /** * Test child. * @return result of the test */ private boolean testChild() { return DOMNodePointer.testNode(child, nodeTest); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java100644 0 0 63305 11044113531 26673 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dom; import java.util.HashMap; import java.util.Locale; import java.util.Map; import org.apache.commons.jxpath.JXPathAbstractFactoryException; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathException; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.Compiler; import org.apache.commons.jxpath.ri.NamespaceResolver; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.compiler.NodeNameTest; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.compiler.NodeTypeTest; import org.apache.commons.jxpath.ri.compiler.ProcessingInstructionTest; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.beans.NullPointer; import org.apache.commons.jxpath.util.TypeUtils; import org.w3c.dom.Attr; import org.w3c.dom.Comment; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.w3c.dom.ProcessingInstruction; /** * A Pointer that points to a DOM node. Because a DOM Node is not guaranteed Serializable, * a DOMNodePointer instance may likewise not be properly Serializable. * * @author Dmitri Plotnikov * @version $Revision: 668329 $ $Date: 2008-06-16 16:59:48 -0500 (Mon, 16 Jun 2008) $ */ public class DOMNodePointer extends NodePointer { private static final long serialVersionUID = -8751046933894857319L; private Node node; private Map namespaces; private String defaultNamespace; private String id; private NamespaceResolver localNamespaceResolver; /** XML namespace URI */ public static final String XML_NAMESPACE_URI = "http://www.w3.org/XML/1998/namespace"; /** XMLNS namespace URI */ public static final String XMLNS_NAMESPACE_URI = "http://www.w3.org/2000/xmlns/"; /** * Create a new DOMNodePointer. * @param node pointed at * @param locale Locale */ public DOMNodePointer(Node node, Locale locale) { super(null, locale); this.node = node; } /** * Create a new DOMNodePointer. * @param node pointed at * @param locale Locale * @param id string id */ public DOMNodePointer(Node node, Locale locale, String id) { super(null, locale); this.node = node; this.id = id; } /** * Create a new DOMNodePointer. * @param parent pointer * @param node pointed */ public DOMNodePointer(NodePointer parent, Node node) { super(parent); this.node = node; } public boolean testNode(NodeTest test) { return testNode(node, test); } /** * Test a Node. * @param node to test * @param test to execute * @return true if node passes test */ public static boolean testNode(Node node, NodeTest test) { if (test == null) { return true; } if (test instanceof NodeNameTest) { if (node.getNodeType() != Node.ELEMENT_NODE) { return false; } NodeNameTest nodeNameTest = (NodeNameTest) test; QName testName = nodeNameTest.getNodeName(); String namespaceURI = nodeNameTest.getNamespaceURI(); boolean wildcard = nodeNameTest.isWildcard(); String testPrefix = testName.getPrefix(); if (wildcard && testPrefix == null) { return true; } if (wildcard || testName.getName() .equals(DOMNodePointer.getLocalName(node))) { String nodeNS = DOMNodePointer.getNamespaceURI(node); return equalStrings(namespaceURI, nodeNS) || nodeNS == null && equalStrings(testPrefix, getPrefix(node)); } return false; } if (test instanceof NodeTypeTest) { int nodeType = node.getNodeType(); switch (((NodeTypeTest) test).getNodeType()) { case Compiler.NODE_TYPE_NODE : return true; case Compiler.NODE_TYPE_TEXT : return nodeType == Node.CDATA_SECTION_NODE || nodeType == Node.TEXT_NODE; case Compiler.NODE_TYPE_COMMENT : return nodeType == Node.COMMENT_NODE; case Compiler.NODE_TYPE_PI : return nodeType == Node.PROCESSING_INSTRUCTION_NODE; default: return false; } } if (test instanceof ProcessingInstructionTest && node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { String testPI = ((ProcessingInstructionTest) test).getTarget(); String nodePI = ((ProcessingInstruction) node).getTarget(); return testPI.equals(nodePI); } return false; } /** * Test string equality. * @param s1 String 1 * @param s2 String 2 * @return true if == or .equals() */ private static boolean equalStrings(String s1, String s2) { if (s1 == s2) { return true; } s1 = s1 == null ? "" : s1.trim(); s2 = s2 == null ? "" : s2.trim(); return s1.equals(s2); } public QName getName() { String ln = null; String ns = null; int type = node.getNodeType(); if (type == Node.ELEMENT_NODE) { ns = DOMNodePointer.getPrefix(node); ln = DOMNodePointer.getLocalName(node); } else if (type == Node.PROCESSING_INSTRUCTION_NODE) { ln = ((ProcessingInstruction) node).getTarget(); } return new QName(ns, ln); } public String getNamespaceURI() { return getNamespaceURI(node); } public NodeIterator childIterator(NodeTest test, boolean reverse, NodePointer startWith) { return new DOMNodeIterator(this, test, reverse, startWith); } public NodeIterator attributeIterator(QName name) { return new DOMAttributeIterator(this, name); } public NodePointer namespacePointer(String prefix) { return new NamespacePointer(this, prefix); } public NodeIterator namespaceIterator() { return new DOMNamespaceIterator(this); } public synchronized NamespaceResolver getNamespaceResolver() { if (localNamespaceResolver == null) { localNamespaceResolver = new NamespaceResolver(super.getNamespaceResolver()); localNamespaceResolver.setNamespaceContextPointer(this); } return localNamespaceResolver; } public String getNamespaceURI(String prefix) { if (prefix == null || prefix.equals("")) { return getDefaultNamespaceURI(); } if (prefix.equals("xml")) { return XML_NAMESPACE_URI; } if (prefix.equals("xmlns")) { return XMLNS_NAMESPACE_URI; } String namespace = null; if (namespaces == null) { namespaces = new HashMap(); } else { namespace = (String) namespaces.get(prefix); } if (namespace == null) { String qname = "xmlns:" + prefix; Node aNode = node; if (aNode instanceof Document) { aNode = ((Document) aNode).getDocumentElement(); } while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { namespace = attr.getValue(); break; } } aNode = aNode.getParentNode(); } if (namespace == null || namespace.equals("")) { namespace = NodePointer.UNKNOWN_NAMESPACE; } } namespaces.put(prefix, namespace); if (namespace == UNKNOWN_NAMESPACE) { return null; } // TBD: We are supposed to resolve relative URIs to absolute ones. return namespace; } public String getDefaultNamespaceURI() { if (defaultNamespace == null) { Node aNode = node; if (aNode instanceof Document) { aNode = ((Document) aNode).getDocumentElement(); } while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode("xmlns"); if (attr != null) { defaultNamespace = attr.getValue(); break; } } aNode = aNode.getParentNode(); } } if (defaultNamespace == null) { defaultNamespace = ""; } // TBD: We are supposed to resolve relative URIs to absolute ones. return defaultNamespace.equals("") ? null : defaultNamespace; } public Object getBaseValue() { return node; } public Object getImmediateNode() { return node; } public boolean isActual() { return true; } public boolean isCollection() { return false; } public int getLength() { return 1; } public boolean isLeaf() { return !node.hasChildNodes(); } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix lang. * If no node has this prefix, calls super.isLanguage(lang). * @param lang ns to test * @return boolean */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase(Locale.ENGLISH).startsWith(lang.toUpperCase(Locale.ENGLISH)); } /** * Find the nearest occurrence of the specified attribute * on the specified and enclosing elements. * @param n current node * @param attrName attribute name * @return attribute value */ protected static String findEnclosingAttribute(Node n, String attrName) { while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; String attr = e.getAttribute(attrName); if (attr != null && !attr.equals("")) { return attr; } } n = n.getParentNode(); } return null; } /** * Get the language attribute for this node. * @return String language name */ protected String getLanguage() { return findEnclosingAttribute(node, "xml:lang"); } /** * Sets contents of the node to the specified value. If the value is * a String, the contents of the node are replaced with this text. * If the value is an Element or Document, the children of the * node are replaced with the children of the passed node. * @param value to set */ public void setValue(Object value) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { node.setNodeValue(string); } else { node.getParentNode().removeChild(node); } } else { NodeList children = node.getChildNodes(); int count = children.getLength(); for (int i = count; --i >= 0;) { Node child = children.item(i); node.removeChild(child); } if (value instanceof Node) { Node valueNode = (Node) value; if (valueNode instanceof Element || valueNode instanceof Document) { children = valueNode.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); node.appendChild(child.cloneNode(true)); } } else { node.appendChild(valueNode.cloneNode(true)); } } else { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { Node textNode = node.getOwnerDocument().createTextNode(string); node.appendChild(textNode); } } } } public NodePointer createChild(JXPathContext context, QName name, int index) { if (index == WHOLE_COLLECTION) { index = 0; } boolean success = getAbstractFactory(context).createObject( context, this, node, name.toString(), index); if (success) { NodeTest nodeTest; String prefix = name.getPrefix(); String namespaceURI = prefix == null ? null : context .getNamespaceURI(prefix); nodeTest = new NodeNameTest(name, namespaceURI); NodeIterator it = childIterator(nodeTest, false, null); if (it != null && it.setPosition(index + 1)) { return it.getNodePointer(); } } throw new JXPathAbstractFactoryException( "Factory could not create a child node for path: " + asPath() + "/" + name + "[" + (index + 1) + "]"); } public NodePointer createChild(JXPathContext context, QName name, int index, Object value) { NodePointer ptr = createChild(context, name, index); ptr.setValue(value); return ptr; } public NodePointer createAttribute(JXPathContext context, QName name) { if (!(node instanceof Element)) { return super.createAttribute(context, name); } Element element = (Element) node; String prefix = name.getPrefix(); if (prefix != null) { String ns = null; NamespaceResolver nsr = getNamespaceResolver(); if (nsr != null) { ns = nsr.getNamespaceURI(prefix); } if (ns == null) { throw new JXPathException( "Unknown namespace prefix: " + prefix); } element.setAttributeNS(ns, name.toString(), ""); } else { if (!element.hasAttribute(name.getName())) { element.setAttribute(name.getName(), ""); } } NodeIterator it = attributeIterator(name); it.setPosition(1); return it.getNodePointer(); } public void remove() { Node parent = node.getParentNode(); if (parent == null) { throw new JXPathException("Cannot remove root DOM node"); } parent.removeChild(node); } public String asPath() { if (id != null) { return "id('" + escape(id) + "')"; } StringBuffer buffer = new StringBuffer(); if (parent != null) { buffer.append(parent.asPath()); } switch (node.getNodeType()) { case Node.ELEMENT_NODE : // If the parent pointer is not a DOMNodePointer, it is // the parent's responsibility to produce the node test part // of the path if (parent instanceof DOMNodePointer) { if (buffer.length() == 0 || buffer.charAt(buffer.length() - 1) != '/') { buffer.append('/'); } String ln = DOMNodePointer.getLocalName(node); String nsURI = getNamespaceURI(); if (nsURI == null) { buffer.append(ln); buffer.append('['); buffer.append(getRelativePositionByName()).append(']'); } else { String prefix = getNamespaceResolver().getPrefix(nsURI); if (prefix != null) { buffer.append(prefix); buffer.append(':'); buffer.append(ln); buffer.append('['); buffer.append(getRelativePositionByName()); buffer.append(']'); } else { buffer.append("node()"); buffer.append('['); buffer.append(getRelativePositionOfElement()); buffer.append(']'); } } } break; case Node.TEXT_NODE : case Node.CDATA_SECTION_NODE : buffer.append("/text()"); buffer.append('['); buffer.append(getRelativePositionOfTextNode()).append(']'); break; case Node.PROCESSING_INSTRUCTION_NODE : buffer.append("/processing-instruction(\'"); buffer.append(((ProcessingInstruction) node).getTarget()).append("')"); buffer.append('['); buffer.append(getRelativePositionOfPI()).append(']'); break; case Node.DOCUMENT_NODE : // That'll be empty break; default: break; } return buffer.toString(); } /** * Get relative position of this among like-named siblings. * @return 1..n */ private int getRelativePositionByName() { int count = 1; Node n = node.getPreviousSibling(); while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { String nm = n.getNodeName(); if (nm.equals(node.getNodeName())) { count++; } } n = n.getPreviousSibling(); } return count; } /** * Get relative position of this among all siblings. * @return 1..n */ private int getRelativePositionOfElement() { int count = 1; Node n = node.getPreviousSibling(); while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { count++; } n = n.getPreviousSibling(); } return count; } /** * Get the relative position of this among sibling text nodes. * @return 1..n */ private int getRelativePositionOfTextNode() { int count = 1; Node n = node.getPreviousSibling(); while (n != null) { if (n.getNodeType() == Node.TEXT_NODE || n.getNodeType() == Node.CDATA_SECTION_NODE) { count++; } n = n.getPreviousSibling(); } return count; } /** * Get the relative position of this among same-target processing instruction siblings. * @return 1..n */ private int getRelativePositionOfPI() { int count = 1; String target = ((ProcessingInstruction) node).getTarget(); Node n = node.getPreviousSibling(); while (n != null) { if (n.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE && ((ProcessingInstruction) n).getTarget().equals(target)) { count++; } n = n.getPreviousSibling(); } return count; } public int hashCode() { return node.hashCode(); } public boolean equals(Object object) { return object == this || object instanceof DOMNodePointer && node == ((DOMNodePointer) object).node; } /** * Get any prefix from the specified node. * @param node the node to check * @return String xml prefix */ public static String getPrefix(Node node) { String prefix = node.getPrefix(); if (prefix != null) { return prefix; } String name = node.getNodeName(); int index = name.lastIndexOf(':'); return index < 0 ? null : name.substring(0, index); } /** * Get the local name of the specified node. * @param node node to check * @return String local name */ public static String getLocalName(Node node) { String localName = node.getLocalName(); if (localName != null) { return localName; } String name = node.getNodeName(); int index = name.lastIndexOf(':'); return index < 0 ? name : name.substring(index + 1); } /** * Get the ns uri of the specified node. * @param node Node to check * @return String ns uri */ public static String getNamespaceURI(Node node) { if (node instanceof Document) { node = ((Document) node).getDocumentElement(); } Element element = (Element) node; String uri = element.getNamespaceURI(); if (uri != null) { return uri; } String prefix = getPrefix(node); String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { if (aNode.getNodeType() == Node.ELEMENT_NODE) { Attr attr = ((Element) aNode).getAttributeNode(qname); if (attr != null) { return attr.getValue(); } } aNode = aNode.getParentNode(); } return null; } public Object getValue() { if (node.getNodeType() == Node.COMMENT_NODE) { String text = ((Comment) node).getData(); return text == null ? "" : text.trim(); } return stringValue(node); } /** * Get the string value of the specified node. * @param node Node to check * @return String */ private String stringValue(Node node) { int nodeType = node.getNodeType(); if (nodeType == Node.COMMENT_NODE) { return ""; } boolean trim = !"preserve".equals(findEnclosingAttribute(node, "xml:space")); if (nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE) { String text = node.getNodeValue(); return text == null ? "" : trim ? text.trim() : text; } if (nodeType == Node.PROCESSING_INSTRUCTION_NODE) { String text = ((ProcessingInstruction) node).getData(); return text == null ? "" : trim ? text.trim() : text; } NodeList list = node.getChildNodes(); StringBuffer buf = new StringBuffer(); for (int i = 0; i < list.getLength(); i++) { Node child = list.item(i); buf.append(stringValue(child)); } return buf.toString(); } /** * Locates a node by ID. * @param context starting context * @param id to find * @return Pointer */ public Pointer getPointerByID(JXPathContext context, String id) { Document document = node.getNodeType() == Node.DOCUMENT_NODE ? (Document) node : node.getOwnerDocument(); Element element = document.getElementById(id); return element == null ? (Pointer) new NullPointer(getLocale(), id) : new DOMNodePointer(element, getLocale(), id); } public int compareChildNodePointers(NodePointer pointer1, NodePointer pointer2) { Node node1 = (Node) pointer1.getBaseValue(); Node node2 = (Node) pointer2.getBaseValue(); if (node1 == node2) { return 0; } int t1 = node1.getNodeType(); int t2 = node2.getNodeType(); if (t1 == Node.ATTRIBUTE_NODE && t2 != Node.ATTRIBUTE_NODE) { return -1; } if (t1 != Node.ATTRIBUTE_NODE && t2 == Node.ATTRIBUTE_NODE) { return 1; } if (t1 == Node.ATTRIBUTE_NODE && t2 == Node.ATTRIBUTE_NODE) { NamedNodeMap map = ((Node) getNode()).getAttributes(); int length = map.getLength(); for (int i = 0; i < length; i++) { Node n = map.item(i); if (n == node1) { return -1; } if (n == node2) { return 1; } } return 0; // Should not happen } Node current = node.getFirstChild(); while (current != null) { if (current == node1) { return -1; } if (current == node2) { return 1; } current = current.getNextSibling(); } return 0; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/dom/DOMPointerFactory.java100644 0 0 3523 11044113531 27371 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dom; import java.util.Locale; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.NodePointerFactory; import org.w3c.dom.Node; /** * Implements NodePointerFactory for DOM elements. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class DOMPointerFactory implements NodePointerFactory { /** factory order */ public static final int DOM_POINTER_FACTORY_ORDER = 100; public int getOrder() { return DOM_POINTER_FACTORY_ORDER; } public NodePointer createNodePointer( QName name, Object bean, Locale locale) { return bean instanceof Node ? new DOMNodePointer((Node) bean, locale) : null; } public NodePointer createNodePointer( NodePointer parent, QName name, Object bean) { return bean instanceof Node ? new DOMNodePointer(parent, (Node) bean) : null; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/dom/NamespacePointer.java100644 0 0 10030 11044113531 27325 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dom; import org.apache.commons.jxpath.ri.Compiler; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.compiler.NodeTypeTest; import org.apache.commons.jxpath.ri.model.NodePointer; /** * Represents a namespace node. * * @author Dmitri Plotnikov * @version $Revision: 652884 $ $Date: 2008-05-02 15:02:00 -0500 (Fri, 02 May 2008) $ */ public class NamespacePointer extends NodePointer { private String prefix; private String namespaceURI; private static final long serialVersionUID = -7622456151550131709L; /** * Create a new NamespacePointer. * @param parent parent pointer * @param prefix associated ns prefix. */ public NamespacePointer(NodePointer parent, String prefix) { super(parent); this.prefix = prefix; } /** * Create a new NamespacePointer. * @param parent parent pointer * @param prefix associated ns prefix. * @param namespaceURI associated ns URI. */ public NamespacePointer( NodePointer parent, String prefix, String namespaceURI) { super(parent); this.prefix = prefix; this.namespaceURI = namespaceURI; } public QName getName() { return new QName(prefix); } public Object getBaseValue() { return null; } public boolean isCollection() { return false; } public int getLength() { return 1; } public Object getImmediateNode() { return getNamespaceURI(); } public String getNamespaceURI() { if (namespaceURI == null) { namespaceURI = parent.getNamespaceURI(prefix); } return namespaceURI; } public boolean isLeaf() { return true; } /** * Throws UnsupportedOperationException. * @param value Object */ public void setValue(Object value) { throw new UnsupportedOperationException("Cannot modify DOM trees"); } public boolean testNode(NodeTest nodeTest) { return nodeTest == null || ((nodeTest instanceof NodeTypeTest) && ((NodeTypeTest) nodeTest).getNodeType() == Compiler.NODE_TYPE_NODE); } public String asPath() { StringBuffer buffer = new StringBuffer(); if (parent != null) { buffer.append(parent.asPath()); if (buffer.length() == 0 || buffer.charAt(buffer.length() - 1) != '/') { buffer.append('/'); } } buffer.append("namespace::"); buffer.append(prefix); return buffer.toString(); } public int hashCode() { return prefix.hashCode(); } public boolean equals(Object object) { if (object == this) { return true; } if (!(object instanceof NamespacePointer)) { return false; } NamespacePointer other = (NamespacePointer) object; return prefix.equals(other.prefix); } public int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2) { // Won't happen - namespaces don't have children return 0; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/dom/package.html100644 0 0 1526 11044113531 25500 0ustar 0 0 Implementation of "model" APIs for W3C DOM. commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/dynabeans/DynaBeanPointer.java100644 0 0 7336 11044113531 30276 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dynabeans; import java.util.Locale; import org.apache.commons.beanutils.DynaBean; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.beans.PropertyOwnerPointer; import org.apache.commons.jxpath.ri.model.beans.PropertyPointer; /** * A Pointer that points to a {@link DynaBean}. If the target DynaBean is Serializable, * so should this instance be. * * @author Dmitri Plotnikov * @version $Revision: 668329 $ $Date: 2008-06-16 16:59:48 -0500 (Mon, 16 Jun 2008) $ */ public class DynaBeanPointer extends PropertyOwnerPointer { private static final long serialVersionUID = -9135052498044877965L; private QName name; private DynaBean dynaBean; /** * Create a new DynaBeanPointer. * @param name is the name given to the first node * @param dynaBean pointed * @param locale Locale */ public DynaBeanPointer(QName name, DynaBean dynaBean, Locale locale) { super(null, locale); this.name = name; this.dynaBean = dynaBean; } /** * Create a new DynaBeanPointer. * @param parent pointer * @param name is the name given to the first node * @param dynaBean pointed */ public DynaBeanPointer(NodePointer parent, QName name, DynaBean dynaBean) { super(parent); this.name = name; this.dynaBean = dynaBean; } public PropertyPointer getPropertyPointer() { return new DynaBeanPropertyPointer(this, dynaBean); } public QName getName() { return name; } public Object getBaseValue() { return dynaBean; } public Object getImmediateNode() { return dynaBean; } public boolean isCollection() { return false; } public int getLength() { return 1; } public boolean isLeaf() { return false; } public int hashCode() { return name == null ? 0 : name.hashCode(); } public boolean equals(Object object) { if (object == this) { return true; } if (!(object instanceof DynaBeanPointer)) { return false; } DynaBeanPointer other = (DynaBeanPointer) object; if (!(equalObjects(parent, other.parent) && equalObjects(name, other.name))) { return false; } int iThis = (index == WHOLE_COLLECTION ? 0 : index); int iOther = (other.index == WHOLE_COLLECTION ? 0 : other.index); return iThis == iOther && dynaBean == other.dynaBean; } public String asPath() { return parent == null ? "/" : super.asPath(); } /** * Learn whether two objects are == || .equals(). * @param o1 first object * @param o2 second object * @return boolean */ private static boolean equalObjects(Object o1, Object o2) { return o1 == o2 || o1 != null && o1.equals(o2); } } ././@LongLink100644 0 0 151 11044114245 10244 Lustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/dynabeans/DynaBeanPointerFactory.javacommons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/dynabeans/DynaBeanPointerFactory.100644 0 0 3730 11044113531 30756 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dynabeans; import java.util.Locale; import org.apache.commons.beanutils.DynaBean; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.NodePointerFactory; /** * Implements NodePointerFactory for DynaBeans. * See * Apache Commons BeanUtils * * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class DynaBeanPointerFactory implements NodePointerFactory { /** factory order constant */ public static final int DYNA_BEAN_POINTER_FACTORY_ORDER = 700; public int getOrder() { return DYNA_BEAN_POINTER_FACTORY_ORDER; } public NodePointer createNodePointer(QName name, Object bean, Locale locale) { return bean instanceof DynaBean ? new DynaBeanPointer(name, (DynaBean) bean, locale) : null; } public NodePointer createNodePointer(NodePointer parent, QName name, Object bean) { return bean instanceof DynaBean ? new DynaBeanPointer(parent, name, (DynaBean) bean) : null; } } ././@LongLink100644 0 0 152 11044114245 10245 Lustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/dynabeans/DynaBeanPropertyPointer.javacommons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/dynabeans/DynaBeanPropertyPointer100644 0 0 22050 11044113531 31131 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dynabeans; import java.util.Arrays; import org.apache.commons.beanutils.DynaBean; import org.apache.commons.beanutils.DynaClass; import org.apache.commons.beanutils.DynaProperty; import org.apache.commons.jxpath.JXPathTypeConversionException; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.beans.PropertyPointer; import org.apache.commons.jxpath.util.TypeUtils; import org.apache.commons.jxpath.util.ValueUtils; /** * Pointer pointing to a property of a {@link DynaBean}. If the target DynaBean is * Serializable, so should this instance be. * * @author Dmitri Plotnikov * @version $Revision: 668329 $ $Date: 2008-06-16 16:59:48 -0500 (Mon, 16 Jun 2008) $ */ public class DynaBeanPropertyPointer extends PropertyPointer { private DynaBean dynaBean; private String name; private String[] names; private static final long serialVersionUID = 2094421509141267239L; /** * Create a new DynaBeanPropertyPointer. * @param parent pointer * @param dynaBean pointed */ public DynaBeanPropertyPointer(NodePointer parent, DynaBean dynaBean) { super(parent); this.dynaBean = dynaBean; } public Object getBaseValue() { return dynaBean.get(getPropertyName()); } /** * This type of node is auxiliary. * @return true */ public boolean isContainer() { return true; } public int getPropertyCount() { return getPropertyNames().length; } public String[] getPropertyNames() { /* @todo do something about the sorting - LIKE WHAT? - MJB */ if (names == null) { DynaClass dynaClass = dynaBean.getDynaClass(); DynaProperty[] properties = dynaClass.getDynaProperties(); int count = properties.length; boolean hasClass = dynaClass.getDynaProperty("class") != null; if (hasClass) { count--; // Exclude "class" from properties } names = new String[count]; for (int i = 0, j = 0; i < properties.length; i++) { String name = properties[i].getName(); if (!hasClass || !name.equals("class")) { names[j++] = name; } } Arrays.sort(names); } return names; } /** * Returns the name of the currently selected property or "*" * if none has been selected. * @return String */ public String getPropertyName() { if (name == null) { String[] names = getPropertyNames(); name = propertyIndex >= 0 && propertyIndex < names.length ? names[propertyIndex] : "*"; } return name; } /** * Select a property by name. * @param propertyName to select */ public void setPropertyName(String propertyName) { setPropertyIndex(UNSPECIFIED_PROPERTY); this.name = propertyName; } /** * Index of the currently selected property in the list of all * properties sorted alphabetically. * @return int */ public int getPropertyIndex() { if (propertyIndex == UNSPECIFIED_PROPERTY) { String[] names = getPropertyNames(); for (int i = 0; i < names.length; i++) { if (names[i].equals(name)) { propertyIndex = i; name = null; break; } } } return super.getPropertyIndex(); } /** * Index a property by its index in the list of all * properties sorted alphabetically. * @param index to set */ public void setPropertyIndex(int index) { if (propertyIndex != index) { super.setPropertyIndex(index); name = null; } } /** * If index == WHOLE_COLLECTION, the value of the property, otherwise * the value of the index'th element of the collection represented by the * property. If the property is not a collection, index should be zero * and the value will be the property itself. * @return Object */ public Object getImmediateNode() { String name = getPropertyName(); if (name.equals("*")) { return null; } Object value; if (index == WHOLE_COLLECTION) { value = ValueUtils.getValue(dynaBean.get(name)); } else if (isIndexedProperty()) { // DynaClass at this point is not based on whether // the property is indeed indexed, but rather on // whether it is an array or List. Therefore // the indexed set may fail. try { value = ValueUtils.getValue(dynaBean.get(name, index)); } catch (ArrayIndexOutOfBoundsException ex) { value = null; } catch (IllegalArgumentException ex) { value = dynaBean.get(name); value = ValueUtils.getValue(value, index); } } else { value = dynaBean.get(name); if (ValueUtils.isCollection(value)) { value = ValueUtils.getValue(value, index); } else if (index != 0) { value = null; } } return value; } /** * Returns true if the bean has the currently selected property. * @return boolean */ protected boolean isActualProperty() { DynaClass dynaClass = dynaBean.getDynaClass(); return dynaClass.getDynaProperty(getPropertyName()) != null; } /** * Learn whether the property referenced is an indexed property. * @return boolean */ protected boolean isIndexedProperty() { DynaClass dynaClass = dynaBean.getDynaClass(); DynaProperty property = dynaClass.getDynaProperty(name); return property.isIndexed(); } /** * If index == WHOLE_COLLECTION, change the value of the property, otherwise * change the value of the index'th element of the collection * represented by the property. * @param value to set */ public void setValue(Object value) { setValue(index, value); } public void remove() { if (index == WHOLE_COLLECTION) { dynaBean.set(getPropertyName(), null); } else if (isIndexedProperty()) { dynaBean.set(getPropertyName(), index, null); } else if (isCollection()) { Object collection = ValueUtils.remove(getBaseValue(), index); dynaBean.set(getPropertyName(), collection); } else if (index == 0) { dynaBean.set(getPropertyName(), null); } } /** * Set an indexed value. * @param index to change * @param value to set */ private void setValue(int index, Object value) { if (index == WHOLE_COLLECTION) { dynaBean.set(getPropertyName(), convert(value, false)); } else if (isIndexedProperty()) { dynaBean.set(getPropertyName(), index, convert(value, true)); } else { Object baseValue = dynaBean.get(getPropertyName()); ValueUtils.setValue(baseValue, index, value); } } /** * Convert a value to the appropriate property type. * @param value to convert * @param element whether this should be a collection element. * @return conversion result */ private Object convert(Object value, boolean element) { DynaClass dynaClass = (DynaClass) dynaBean.getDynaClass(); DynaProperty property = dynaClass.getDynaProperty(getPropertyName()); Class type = property.getType(); if (element) { if (type.isArray()) { type = type.getComponentType(); } else { return value; // No need to convert } } try { return TypeUtils.convert(value, type); } catch (Exception ex) { String string = value == null ? "null" : value.getClass().getName(); throw new JXPathTypeConversionException( "Cannot convert value of class " + string + " to type " + type, ex); } } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/dynabeans/package.html100644 0 0 1552 11044113531 26664 0ustar 0 0 Implementation of "model" APIs for Commons BeanUtils DynaBeans. ././@LongLink100644 0 0 151 11044114245 10244 Lustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/dynamic/DynamicAttributeIterator.javacommons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/dynamic/DynamicAttributeIterator.100644 0 0 3602 11044113532 31045 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dynamic; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.beans.BeanAttributeIterator; import org.apache.commons.jxpath.ri.model.beans.PropertyOwnerPointer; /** * DynamicAttributeIterator is different from a regular * BeanAttributeIterator in that given a property name it * will always find that property (albeit with a null value). * * @author Dmitri Plotnikov * @version $Id: DynamicAttributeIterator.java 652845 2008-05-02 17:46:46Z ebourg $ */ public class DynamicAttributeIterator extends BeanAttributeIterator { /** * Create a new DynamicAttributeIterator. * @param parent pointer * @param name to match properties */ public DynamicAttributeIterator(PropertyOwnerPointer parent, QName name) { super(parent, name); } protected void prepareForIndividualProperty(String name) { ((DynamicPropertyPointer) getPropertyPointer()).setPropertyName(name); super.prepareForIndividualProperty(name); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/dynamic/DynamicPointer.java100644 0 0 10275 11044113532 27676 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dynamic; import java.util.Locale; import org.apache.commons.jxpath.DynamicPropertyHandler; import org.apache.commons.jxpath.JXPathIntrospector; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.beans.PropertyIterator; import org.apache.commons.jxpath.ri.model.beans.PropertyOwnerPointer; import org.apache.commons.jxpath.ri.model.beans.PropertyPointer; /** * A Pointer that points to an object with Dynamic Properties. It is used for * the first element of a path; following elements will by of type * {@link PropertyPointer}. * * @author Dmitri Plotnikov * @version $Revision: 652884 $ $Date: 2008-05-02 15:02:00 -0500 (Fri, 02 May 2008) $ */ public class DynamicPointer extends PropertyOwnerPointer { private QName name; private Object bean; private DynamicPropertyHandler handler; private static final long serialVersionUID = -1842347025295904256L; /** * Create a new DynamicPointer. * @param name property name * @param bean owning bean * @param handler DynamicPropertyHandler * @param locale Locale */ public DynamicPointer(QName name, Object bean, DynamicPropertyHandler handler, Locale locale) { super(null, locale); this.name = name; this.bean = bean; this.handler = handler; } /** * Create a new DynamicPointer. * @param parent parent pointer * @param name property name * @param bean owning bean * @param handler DynamicPropertyHandler */ public DynamicPointer(NodePointer parent, QName name, Object bean, DynamicPropertyHandler handler) { super(parent); this.name = name; this.bean = bean; this.handler = handler; } public PropertyPointer getPropertyPointer() { return new DynamicPropertyPointer(this, handler); } public NodeIterator createNodeIterator( String property, boolean reverse, NodePointer startWith) { return new PropertyIterator(this, property, reverse, startWith); } public NodeIterator attributeIterator(QName name) { return new DynamicAttributeIterator(this, name); } public QName getName() { return name; } public boolean isDynamicPropertyDeclarationSupported() { return true; } /** * Returns the DP object iself. * @return Object */ public Object getBaseValue() { return bean; } public boolean isLeaf() { Object value = getNode(); return value == null || JXPathIntrospector.getBeanInfo(value.getClass()).isAtomic(); } public boolean isCollection() { return false; } /** * Returns 1. * @return int */ public int getLength() { return 1; } public String asPath() { return parent == null ? "/" : super.asPath(); } public int hashCode() { return System.identityHashCode(bean) + name.hashCode(); } public boolean equals(Object object) { if (object == this) { return true; } if (!(object instanceof DynamicPointer)) { return false; } DynamicPointer other = (DynamicPointer) object; return bean == other.bean && name.equals(other.name); } } ././@LongLink100644 0 0 146 11044114245 10250 Lustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/dynamic/DynamicPointerFactory.javacommons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/dynamic/DynamicPointerFactory.jav100644 0 0 5375 11044113532 31052 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dynamic; import java.util.Locale; import org.apache.commons.jxpath.DynamicPropertyHandler; import org.apache.commons.jxpath.JXPathBeanInfo; import org.apache.commons.jxpath.JXPathIntrospector; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.NodePointerFactory; import org.apache.commons.jxpath.ri.model.beans.NullPointer; import org.apache.commons.jxpath.util.ValueUtils; /** * Implements NodePointerFactory for Dynamic classes like Map. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class DynamicPointerFactory implements NodePointerFactory { /** * Factory order constant. */ public static final int DYNAMIC_POINTER_FACTORY_ORDER = 800; public int getOrder() { return DYNAMIC_POINTER_FACTORY_ORDER; } public NodePointer createNodePointer( QName name, Object bean, Locale locale) { JXPathBeanInfo bi = JXPathIntrospector.getBeanInfo(bean.getClass()); if (bi.isDynamic()) { DynamicPropertyHandler handler = ValueUtils.getDynamicPropertyHandler( bi.getDynamicPropertyHandlerClass()); return new DynamicPointer(name, bean, handler, locale); } return null; } public NodePointer createNodePointer( NodePointer parent, QName name, Object bean) { if (bean == null) { return new NullPointer(parent, name); } JXPathBeanInfo bi = JXPathIntrospector.getBeanInfo(bean.getClass()); if (bi.isDynamic()) { DynamicPropertyHandler handler = ValueUtils.getDynamicPropertyHandler( bi.getDynamicPropertyHandlerClass()); return new DynamicPointer(parent, name, bean, handler); } return null; } } ././@LongLink100644 0 0 150 11044114245 10243 Lustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/dynamic/DynamicPropertyIterator.javacommons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/dynamic/DynamicPropertyIterator.j100644 0 0 3367 11044113532 31110 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dynamic; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.beans.PropertyIterator; import org.apache.commons.jxpath.ri.model.beans.PropertyOwnerPointer; /** * @deprecated - no longer needed, as it is identical to PropertyIterator. * * @author Dmitri Plotnikov * @version $Id: DynamicPropertyIterator.java 604304 2007-12-14 21:31:19Z mbenson $ */ public class DynamicPropertyIterator extends PropertyIterator { /** * Create a new DynamicPropertyIterator * @param pointer PropertyOwnerPointer * @param name String * @param reverse iteration order * @param startWith beginning child */ public DynamicPropertyIterator( PropertyOwnerPointer pointer, String name, boolean reverse, NodePointer startWith) { super(pointer, name, reverse, startWith); } } ././@LongLink100644 0 0 147 11044114245 10251 Lustar 0 0 commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/dynamic/DynamicPropertyPointer.javacommons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/dynamic/DynamicPropertyPointer.ja100644 0 0 23175 11044113532 31117 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dynamic; import java.util.Arrays; import java.util.Map; import org.apache.commons.jxpath.AbstractFactory; import org.apache.commons.jxpath.DynamicPropertyHandler; import org.apache.commons.jxpath.JXPathAbstractFactoryException; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathInvalidAccessException; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.beans.PropertyPointer; import org.apache.commons.jxpath.util.ValueUtils; /** * Pointer pointing to a property of an object with dynamic properties. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class DynamicPropertyPointer extends PropertyPointer { private static final long serialVersionUID = -5720585681149150822L; private DynamicPropertyHandler handler; private String name; private String[] names; private String requiredPropertyName; /** * Create a new DynamicPropertyPointer. * @param parent pointer * @param handler DynamicPropertyHandler */ public DynamicPropertyPointer(NodePointer parent, DynamicPropertyHandler handler) { super(parent); this.handler = handler; } /** * This type of node is auxiliary. * @return true */ public boolean isContainer() { return true; } /** * Number of the DP object's properties. * @return int */ public int getPropertyCount() { return getPropertyNames().length; } /** * Names of all properties, sorted alphabetically. * @return String[] */ public String[] getPropertyNames() { if (names == null) { String[] allNames = handler.getPropertyNames(getBean()); names = new String[allNames.length]; for (int i = 0; i < names.length; i++) { names[i] = allNames[i]; } Arrays.sort(names); if (requiredPropertyName != null) { int inx = Arrays.binarySearch(names, requiredPropertyName); if (inx < 0) { allNames = names; names = new String[allNames.length + 1]; names[0] = requiredPropertyName; System.arraycopy(allNames, 0, names, 1, allNames.length); Arrays.sort(names); } } } return names; } /** * Returns the name of the currently selected property or "*" * if none has been selected. * @return String */ public String getPropertyName() { if (name == null) { String[] names = getPropertyNames(); name = propertyIndex >= 0 && propertyIndex < names.length ? names[propertyIndex] : "*"; } return name; } /** * Select a property by name. If the supplied name is * not one of the object's existing properties, it implicitly * adds this name to the object's property name list. It does not * set the property value though. In order to set the property * value, call setValue(). * @param propertyName to set */ public void setPropertyName(String propertyName) { setPropertyIndex(UNSPECIFIED_PROPERTY); this.name = propertyName; requiredPropertyName = propertyName; if (names != null && Arrays.binarySearch(names, propertyName) < 0) { names = null; } } /** * Index of the currently selected property in the list of all * properties sorted alphabetically. * @return int */ public int getPropertyIndex() { if (propertyIndex == UNSPECIFIED_PROPERTY) { String[] names = getPropertyNames(); for (int i = 0; i < names.length; i++) { if (names[i].equals(name)) { setPropertyIndex(i); break; } } } return super.getPropertyIndex(); } /** * Index a property by its index in the list of all * properties sorted alphabetically. * @param index to set */ public void setPropertyIndex(int index) { if (propertyIndex != index) { super.setPropertyIndex(index); name = null; } } /** * Returns the value of the property, not an element of the collection * represented by the property, if any. * @return Object */ public Object getBaseValue() { return handler.getProperty(getBean(), getPropertyName()); } /** * If index == WHOLE_COLLECTION, the value of the property, otherwise * the value of the index'th element of the collection represented by the * property. If the property is not a collection, index should be zero * and the value will be the property itself. * @return Object */ public Object getImmediateNode() { Object value; if (index == WHOLE_COLLECTION) { value = ValueUtils.getValue(handler.getProperty( getBean(), getPropertyName())); } else { value = ValueUtils.getValue(handler.getProperty( getBean(), getPropertyName()), index); } return value; } /** * A dynamic property is always considered actual - all keys are apparently * existing with possibly the value of null. * @return boolean */ protected boolean isActualProperty() { return true; } /** * If index == WHOLE_COLLECTION, change the value of the property, otherwise * change the value of the index'th element of the collection * represented by the property. * @param value to set */ public void setValue(Object value) { if (index == WHOLE_COLLECTION) { handler.setProperty(getBean(), getPropertyName(), value); } else { ValueUtils.setValue( handler.getProperty(getBean(), getPropertyName()), index, value); } } public NodePointer createPath(JXPathContext context) { // Ignore the name passed to us, use our own data Object collection = getBaseValue(); if (collection == null) { AbstractFactory factory = getAbstractFactory(context); boolean success = factory.createObject( context, this, getBean(), getPropertyName(), 0); if (!success) { throw new JXPathAbstractFactoryException( "Factory could not create an object for path: " + asPath()); } collection = getBaseValue(); } if (index != WHOLE_COLLECTION) { if (index < 0) { throw new JXPathInvalidAccessException("Index is less than 1: " + asPath()); } if (index >= getLength()) { collection = ValueUtils.expandCollection(collection, index + 1); handler.setProperty(getBean(), getPropertyName(), collection); } } return this; } public NodePointer createPath(JXPathContext context, Object value) { if (index == WHOLE_COLLECTION) { handler.setProperty(getBean(), getPropertyName(), value); } else { createPath(context); ValueUtils.setValue(getBaseValue(), index, value); } return this; } public void remove() { if (index == WHOLE_COLLECTION) { removeKey(); } else if (isCollection()) { Object collection = ValueUtils.remove(getBaseValue(), index); handler.setProperty(getBean(), getPropertyName(), collection); } else if (index == 0) { removeKey(); } } /** * Remove the current property. */ private void removeKey() { Object bean = getBean(); if (bean instanceof Map) { ((Map) bean).remove(getPropertyName()); } else { handler.setProperty(bean, getPropertyName(), null); } } public String asPath() { StringBuffer buffer = new StringBuffer(); buffer.append(getImmediateParentPointer().asPath()); if (buffer.length() == 0) { buffer.append("/."); } else if (buffer.charAt(buffer.length() - 1) == '/') { buffer.append('.'); } buffer.append("[@name='"); buffer.append(escape(getPropertyName())); buffer.append("']"); if (index != WHOLE_COLLECTION && isCollection()) { buffer.append('[').append(index + 1).append(']'); } return buffer.toString(); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/dynamic/package.html100644 0 0 1700 11044113532 26340 0ustar 0 0 Implementation of "model" APIs for dynamic property objects e.g. Maps or anything else for which a client can provide a DynamicPropertyHandler class. commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMAttributeIterator.java100644 0 0 7734 11044113535 30376 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.jdom; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; import org.jdom.Attribute; import org.jdom.Element; import org.jdom.Namespace; /** * An iterator of attributes of a DOM Node. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class JDOMAttributeIterator implements NodeIterator { private NodePointer parent; private List attributes; private int position = 0; /** * Create a new JDOMAttributeIterator. * @param parent pointer * @param name test */ public JDOMAttributeIterator(NodePointer parent, QName name) { this.parent = parent; if (parent.getNode() instanceof Element) { Element element = (Element) parent.getNode(); String prefix = name.getPrefix(); Namespace ns = null; if (prefix != null) { if (prefix.equals("xml")) { ns = Namespace.XML_NAMESPACE; } else { String uri = parent.getNamespaceResolver().getNamespaceURI(prefix); if (uri != null) { ns = Namespace.getNamespace(prefix, uri); } if (ns == null) { // TBD: no attributes attributes = Collections.EMPTY_LIST; return; } } } else { ns = Namespace.NO_NAMESPACE; } String lname = name.getName(); if (!lname.equals("*")) { attributes = new ArrayList(); Attribute attr = element.getAttribute(lname, ns); if (attr != null) { attributes.add(attr); } } else { attributes = new ArrayList(); List allAttributes = element.getAttributes(); for (int i = 0; i < allAttributes.size(); i++) { Attribute attr = (Attribute) allAttributes.get(i); if (ns == Namespace.NO_NAMESPACE || attr.getNamespace().equals(ns)) { attributes.add(attr); } } } } } public NodePointer getNodePointer() { if (position == 0) { if (!setPosition(1)) { return null; } position = 0; } int index = position - 1; if (index < 0) { index = 0; } return new JDOMAttributePointer( parent, (Attribute) attributes.get(index)); } public int getPosition() { return position; } public boolean setPosition(int position) { if (attributes == null) { return false; } this.position = position; return position >= 1 && position <= attributes.size(); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMAttributePointer.java100644 0 0 6612 11044113535 30217 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.jdom; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.util.TypeUtils; import org.jdom.Attribute; /** * A Pointer that points to a DOM node. * * @author Dmitri Plotnikov * @version $Revision: 652884 $ $Date: 2008-05-02 15:02:00 -0500 (Fri, 02 May 2008) $ */ public class JDOMAttributePointer extends NodePointer { private Attribute attr; private static final long serialVersionUID = 8896050354479644028L; /** * Create a JDOMAttributePointer. * @param parent NodePointer parent * @param attr JDOM Attribute */ public JDOMAttributePointer(NodePointer parent, Attribute attr) { super(parent); this.attr = attr; } public QName getName() { return new QName( JDOMNodePointer.getPrefix(attr), JDOMNodePointer.getLocalName(attr)); } public String getNamespaceURI() { String uri = attr.getNamespaceURI(); if (uri != null && uri.equals("")) { uri = null; } return uri; } public Object getValue() { return attr.getValue(); } public Object getBaseValue() { return attr; } public boolean isCollection() { return false; } public int getLength() { return 1; } public Object getImmediateNode() { return attr; } public boolean isActual() { return true; } public boolean isLeaf() { return true; } public void setValue(Object value) { attr.setValue((String) TypeUtils.convert(value, String.class)); } public void remove() { attr.getParent().removeAttribute(attr); } public String asPath() { StringBuffer buffer = new StringBuffer(); if (parent != null) { buffer.append(parent.asPath()); if (buffer.length() == 0 || buffer.charAt(buffer.length() - 1) != '/') { buffer.append('/'); } } buffer.append('@'); buffer.append(getName()); return buffer.toString(); } public int hashCode() { return System.identityHashCode(attr); } public boolean equals(Object object) { return object == this || object instanceof JDOMAttributePointer && ((JDOMAttributePointer) object).attr == attr; } public int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2) { // Won't happen - attributes don't have children return 0; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNamespaceIterator.java100644 0 0 6757 11044113535 30333 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.jdom; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; import org.jdom.Document; import org.jdom.Element; import org.jdom.Namespace; /** * An iterator of namespaces of a DOM Node. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class JDOMNamespaceIterator implements NodeIterator { private NodePointer parent; private List namespaces; private Set prefixes; private int position = 0; /** * Create a new JDOMNamespaceIterator. * @param parent the parent NodePointer. */ public JDOMNamespaceIterator(NodePointer parent) { this.parent = parent; Object node = parent.getNode(); if (node instanceof Document) { node = ((Document) node).getRootElement(); } if (node instanceof Element) { namespaces = new ArrayList(); prefixes = new HashSet(); collectNamespaces((Element) node); } } /** * Collect the namespaces from a JDOM Element. * @param element the source Element */ private void collectNamespaces(Element element) { Namespace ns = element.getNamespace(); if (ns != null && !prefixes.contains(ns.getPrefix())) { namespaces.add(ns); prefixes.add(ns.getPrefix()); } List others = element.getAdditionalNamespaces(); for (int i = 0; i < others.size(); i++) { ns = (Namespace) others.get(i); if (ns != null && !prefixes.contains(ns.getPrefix())) { namespaces.add(ns); prefixes.add(ns.getPrefix()); } } Object elementParent = element.getParent(); if (elementParent instanceof Element) { collectNamespaces((Element) elementParent); } } public NodePointer getNodePointer() { if (position == 0) { if (!setPosition(1)) { return null; } position = 0; } int index = position - 1; if (index < 0) { index = 0; } Namespace ns = (Namespace) namespaces.get(index); return new JDOMNamespacePointer(parent, ns.getPrefix(), ns.getURI()); } public int getPosition() { return position; } public boolean setPosition(int position) { if (namespaces == null) { return false; } this.position = position; return position >= 1 && position <= namespaces.size(); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNamespacePointer.java100644 0 0 7012 11044113535 30143 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.jdom; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; /** * Represents a namespace node. * * @author Dmitri Plotnikov * @version $Revision: 652884 $ $Date: 2008-05-02 15:02:00 -0500 (Fri, 02 May 2008) $ */ public class JDOMNamespacePointer extends NodePointer { private String prefix; private String namespaceURI; private static final long serialVersionUID = 7935311686545862379L; /** * Create a new JDOMNamespacePointer. * @param parent parent pointer * @param prefix ns prefix */ public JDOMNamespacePointer(NodePointer parent, String prefix) { super(parent); this.prefix = prefix; } /** * Create a new JDOMNamespacePointer. * @param parent parent pointer * @param prefix ns prefix * @param namespaceURI ns URI */ public JDOMNamespacePointer( NodePointer parent, String prefix, String namespaceURI) { super(parent); this.prefix = prefix; this.namespaceURI = namespaceURI; } public QName getName() { return new QName(prefix); } public Object getBaseValue() { return null; } public boolean isCollection() { return false; } public int getLength() { return 1; } public Object getImmediateNode() { return getNamespaceURI(); } public String getNamespaceURI() { if (namespaceURI == null) { namespaceURI = parent.getNamespaceURI(prefix); } return namespaceURI; } public boolean isLeaf() { return true; } /** * Throws UnsupportedOperationException. * @param value Object value to set */ public void setValue(Object value) { throw new UnsupportedOperationException("Cannot modify a namespace"); } public String asPath() { StringBuffer buffer = new StringBuffer(); if (parent != null) { buffer.append(parent.asPath()); if (buffer.length() == 0 || buffer.charAt(buffer.length() - 1) != '/') { buffer.append('/'); } } buffer.append("namespace::"); buffer.append(prefix); return buffer.toString(); } public int hashCode() { return prefix.hashCode(); } public boolean equals(Object object) { return object == this || object instanceof JDOMNamespacePointer && prefix.equals(((JDOMNamespacePointer) object).prefix); } public int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2) { // Won't happen - namespaces don't have children return 0; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNodeIterator.java100644 0 0 12223 11044113535 27325 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.jdom; import java.util.Collections; import java.util.List; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; import org.jdom.Document; import org.jdom.Element; /** * An iterator of children of a JDOM Node. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class JDOMNodeIterator implements NodeIterator { private NodePointer parent; private NodeTest nodeTest; private boolean reverse; private int position = 0; private int index = 0; private List children; private Object child; /** * Create a new JDOMNodeIterator. * @param parent pointer * @param nodeTest test * @param reverse whether to iterate in reverse * @param startWith starting pointer */ public JDOMNodeIterator( NodePointer parent, NodeTest nodeTest, boolean reverse, NodePointer startWith) { this.parent = parent; if (startWith != null) { this.child = startWith.getNode(); } // TBD: optimize me for different node tests Object node = parent.getNode(); if (node instanceof Document) { this.children = ((Document) node).getContent(); } else if (node instanceof Element) { this.children = ((Element) node).getContent(); } else { this.children = Collections.EMPTY_LIST; } this.nodeTest = nodeTest; this.reverse = reverse; } public NodePointer getNodePointer() { if (child == null) { if (!setPosition(1)) { return null; } position = 0; } return new JDOMNodePointer(parent, child); } public int getPosition() { return position; } public boolean setPosition(int position) { while (this.position < position) { if (!next()) { return false; } } while (this.position > position) { if (!previous()) { return false; } } return true; } /** * This is actually never invoked during the normal evaluation * of xpaths - an iterator is always going forward, never backwards. * So, this is implemented only for completeness and perhaps for * those who use these iterators outside of XPath evaluation. * @return boolean */ private boolean previous() { position--; if (!reverse) { while (--index >= 0) { child = children.get(index); if (testChild()) { return true; } } } else { for (; index < children.size(); index++) { child = children.get(index); if (testChild()) { return true; } } } return false; } /** * Iterate to next pointer. * @return whether valid */ private boolean next() { position++; if (!reverse) { if (position == 1) { index = 0; if (child != null) { index = children.indexOf(child) + 1; } } else { index++; } for (; index < children.size(); index++) { child = children.get(index); if (testChild()) { return true; } } return false; } else { if (position == 1) { index = children.size() - 1; if (child != null) { index = children.indexOf(child) - 1; } } else { index--; } for (; index >= 0; index--) { child = children.get(index); if (testChild()) { return true; } } return false; } } /** * Test a child node. * @return whether test passes. */ private boolean testChild() { return JDOMNodePointer.testNode(parent, child, nodeTest); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNodePointer.java100644 0 0 63720 11044113535 27164 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.jdom; import java.util.List; import java.util.Locale; import org.apache.commons.jxpath.JXPathAbstractFactoryException; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathException; import org.apache.commons.jxpath.ri.Compiler; import org.apache.commons.jxpath.ri.NamespaceResolver; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.compiler.NodeNameTest; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.compiler.NodeTypeTest; import org.apache.commons.jxpath.ri.compiler.ProcessingInstructionTest; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.util.TypeUtils; import org.jdom.Attribute; import org.jdom.CDATA; import org.jdom.Comment; import org.jdom.Document; import org.jdom.Element; import org.jdom.Namespace; import org.jdom.ProcessingInstruction; import org.jdom.Text; /** * A Pointer that points to a DOM node. * * @author Dmitri Plotnikov * @version $Revision: 668329 $ $Date: 2008-06-16 16:59:48 -0500 (Mon, 16 Jun 2008) $ */ public class JDOMNodePointer extends NodePointer { private static final long serialVersionUID = -6346532297491082651L; private Object node; private String id; private NamespaceResolver localNamespaceResolver; /** XML ns uri */ public static final String XML_NAMESPACE_URI = "http://www.w3.org/XML/1998/namespace"; /** XMLNS ns uri */ public static final String XMLNS_NAMESPACE_URI = "http://www.w3.org/2000/xmlns/"; /** * Create a new JDOMNodePointer. * @param node pointed * @param locale Locale */ public JDOMNodePointer(Object node, Locale locale) { super(null, locale); this.node = node; } /** * Create a new JDOMNodePointer. * @param node pointed * @param locale Locale * @param id String id */ public JDOMNodePointer(Object node, Locale locale, String id) { super(null, locale); this.node = node; this.id = id; } /** * Create a new JDOMNodePointer. * @param parent NodePointer * @param node pointed */ public JDOMNodePointer(NodePointer parent, Object node) { super(parent); this.node = node; } public NodeIterator childIterator( NodeTest test, boolean reverse, NodePointer startWith) { return new JDOMNodeIterator(this, test, reverse, startWith); } public NodeIterator attributeIterator(QName name) { return new JDOMAttributeIterator(this, name); } public NodeIterator namespaceIterator() { return new JDOMNamespaceIterator(this); } public NodePointer namespacePointer(String prefix) { return new JDOMNamespacePointer(this, prefix); } public String getNamespaceURI() { return getNamespaceURI(node); } /** * Get the ns uri of the specified node. * @param node Node to check * @return String */ private static String getNamespaceURI(Object node) { if (node instanceof Element) { Element element = (Element) node; String ns = element.getNamespaceURI(); if (ns != null && ns.equals("")) { ns = null; } return ns; } return null; } public synchronized NamespaceResolver getNamespaceResolver() { if (localNamespaceResolver == null) { localNamespaceResolver = new NamespaceResolver(super.getNamespaceResolver()); localNamespaceResolver.setNamespaceContextPointer(this); } return localNamespaceResolver; } public String getNamespaceURI(String prefix) { if (prefix.equals("xml")) { return Namespace.XML_NAMESPACE.getURI(); } Element element = null; if (node instanceof Document) { element = ((Document) node).getRootElement(); } if (node instanceof Element) { element = (Element) node; } if (element == null) { return null; } Namespace ns = element.getNamespace(prefix); return ns == null ? null : ns.getURI(); } public int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2) { Object node1 = pointer1.getBaseValue(); Object node2 = pointer2.getBaseValue(); if (node1 == node2) { return 0; } if ((node1 instanceof Attribute) && !(node2 instanceof Attribute)) { return -1; } if ( !(node1 instanceof Attribute) && (node2 instanceof Attribute)) { return 1; } if ( (node1 instanceof Attribute) && (node2 instanceof Attribute)) { List list = ((Element) getNode()).getAttributes(); int length = list.size(); for (int i = 0; i < length; i++) { Object n = list.get(i); if (n == node1) { return -1; } else if (n == node2) { return 1; } } return 0; // Should not happen } if (!(node instanceof Element)) { throw new RuntimeException( "JXPath internal error: " + "compareChildNodes called for " + node); } List children = ((Element) node).getContent(); int length = children.size(); for (int i = 0; i < length; i++) { Object n = children.get(i); if (n == node1) { return -1; } if (n == node2) { return 1; } } return 0; } public Object getBaseValue() { return node; } public boolean isCollection() { return false; } public int getLength() { return 1; } public boolean isLeaf() { if (node instanceof Element) { return ((Element) node).getContent().size() == 0; } if (node instanceof Document) { return ((Document) node).getContent().size() == 0; } return true; } public QName getName() { String ns = null; String ln = null; if (node instanceof Element) { ns = ((Element) node).getNamespacePrefix(); if (ns != null && ns.equals("")) { ns = null; } ln = ((Element) node).getName(); } else if (node instanceof ProcessingInstruction) { ln = ((ProcessingInstruction) node).getTarget(); } return new QName(ns, ln); } public Object getImmediateNode() { return node; } public Object getValue() { if (node instanceof Element) { StringBuffer buf = new StringBuffer(); for (NodeIterator children = childIterator(null, false, null); children.setPosition(children.getPosition() + 1);) { NodePointer ptr = children.getNodePointer(); if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) { buf.append(ptr.getValue()); } } return buf.toString(); } if (node instanceof Comment) { String text = ((Comment) node).getText(); if (text != null) { text = text.trim(); } return text; } String result = null; if (node instanceof Text) { result = ((Text) node).getText(); } if (node instanceof ProcessingInstruction) { result = ((ProcessingInstruction) node).getData(); } boolean trim = !"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE)); return result != null && trim ? result.trim() : result; } public void setValue(Object value) { if (node instanceof Text) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { ((Text) node).setText(string); } else { nodeParent(node).removeContent((Text) node); } } else { Element element = (Element) node; element.getContent().clear(); if (value instanceof Element) { Element valueElement = (Element) value; addContent(valueElement.getContent()); } else if (value instanceof Document) { Document valueDocument = (Document) value; addContent(valueDocument.getContent()); } else if (value instanceof Text || value instanceof CDATA) { String string = ((Text) value).getText(); element.addContent(new Text(string)); } else if (value instanceof ProcessingInstruction) { ProcessingInstruction pi = (ProcessingInstruction) ((ProcessingInstruction) value) .clone(); element.addContent(pi); } else if (value instanceof Comment) { Comment comment = (Comment) ((Comment) value).clone(); element.addContent(comment); } else { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { element.addContent(new Text(string)); } } } } /** * Add the specified content to this element. * @param content List */ private void addContent(List content) { Element element = (Element) node; int count = content.size(); for (int i = 0; i < count; i++) { Object child = content.get(i); if (child instanceof Element) { child = ((Element) child).clone(); element.addContent((Element) child); } else if (child instanceof Text) { child = ((Text) child).clone(); element.addContent((Text) child); } else if (node instanceof CDATA) { child = ((CDATA) child).clone(); element.addContent((CDATA) child); } else if (node instanceof ProcessingInstruction) { child = ((ProcessingInstruction) child).clone(); element.addContent((ProcessingInstruction) child); } else if (node instanceof Comment) { child = ((Comment) child).clone(); element.addContent((Comment) child); } } } public boolean testNode(NodeTest test) { return testNode(this, node, test); } /** * Execute test against node on behalf of pointer. * @param pointer Pointer * @param node to test * @param test to execute * @return true if node passes test */ public static boolean testNode( NodePointer pointer, Object node, NodeTest test) { if (test == null) { return true; } if (test instanceof NodeNameTest) { if (!(node instanceof Element)) { return false; } NodeNameTest nodeNameTest = (NodeNameTest) test; QName testName = nodeNameTest.getNodeName(); String namespaceURI = nodeNameTest.getNamespaceURI(); boolean wildcard = nodeNameTest.isWildcard(); String testPrefix = testName.getPrefix(); if (wildcard && testPrefix == null) { return true; } if (wildcard || testName.getName() .equals(JDOMNodePointer.getLocalName(node))) { String nodeNS = JDOMNodePointer.getNamespaceURI(node); return equalStrings(namespaceURI, nodeNS) || nodeNS == null && equalStrings(testPrefix, getPrefix(node)); } return false; } if (test instanceof NodeTypeTest) { switch (((NodeTypeTest) test).getNodeType()) { case Compiler.NODE_TYPE_NODE : return true; case Compiler.NODE_TYPE_TEXT : return (node instanceof Text) || (node instanceof CDATA); case Compiler.NODE_TYPE_COMMENT : return node instanceof Comment; case Compiler.NODE_TYPE_PI : return node instanceof ProcessingInstruction; default: return false; } } if (test instanceof ProcessingInstructionTest && node instanceof ProcessingInstruction) { String testPI = ((ProcessingInstructionTest) test).getTarget(); String nodePI = ((ProcessingInstruction) node).getTarget(); return testPI.equals(nodePI); } return false; } /** * Learn whether two strings are == or .equals() * @param s1 string 1 * @param s2 string 2 * @return true if equal */ private static boolean equalStrings(String s1, String s2) { if (s1 == s2) { return true; } s1 = s1 == null ? "" : s1.trim(); s2 = s2 == null ? "" : s2.trim(); return s1.equals(s2); } /** * Get the prefix from a given node. * @param node to check * @return String */ public static String getPrefix(Object node) { if (node instanceof Element) { String prefix = ((Element) node).getNamespacePrefix(); return (prefix == null || prefix.equals("")) ? null : prefix; } if (node instanceof Attribute) { String prefix = ((Attribute) node).getNamespacePrefix(); return (prefix == null || prefix.equals("")) ? null : prefix; } return null; } /** * Get the local name of the specified node. * @param node to check * @return String local name */ public static String getLocalName(Object node) { if (node instanceof Element) { return ((Element) node).getName(); } if (node instanceof Attribute) { return ((Attribute) node).getName(); } return null; } /** * Returns true if the xml:lang attribute for the current node * or its parent has the specified prefix lang. * If no node has this prefix, calls super.isLanguage(lang). * @param lang to compare * @return true if this element uses the specified language. */ public boolean isLanguage(String lang) { String current = getLanguage(); return current == null ? super.isLanguage(lang) : current.toUpperCase( Locale.ENGLISH).startsWith(lang.toUpperCase(Locale.ENGLISH)); } /** * Get the language of this element. * @return String language */ protected String getLanguage() { return findEnclosingAttribute(node, "lang", Namespace.XML_NAMESPACE); } /** * Find the nearest occurrence of the specified attribute * on the specified and enclosing elements. * @param n current node * @param attrName attribute name * @param ns Namespace * @return attribute value */ protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) { while (n != null) { if (n instanceof Element) { Element e = (Element) n; String attr = e.getAttributeValue(attrName, ns); if (attr != null && !attr.equals("")) { return attr; } } n = nodeParent(n); } return null; } /** * Get the parent of the specified node. * @param node to check * @return parent Element */ private static Element nodeParent(Object node) { if (node instanceof Element) { Object parent = ((Element) node).getParent(); return parent instanceof Element ? (Element) parent : null; } if (node instanceof Text) { return (Element) ((Text) node).getParent(); } if (node instanceof CDATA) { return (Element) ((CDATA) node).getParent(); } if (node instanceof ProcessingInstruction) { return (Element) ((ProcessingInstruction) node).getParent(); } if (node instanceof Comment) { return (Element) ((Comment) node).getParent(); } return null; } public NodePointer createChild( JXPathContext context, QName name, int index) { if (index == WHOLE_COLLECTION) { index = 0; } boolean success = getAbstractFactory(context).createObject( context, this, node, name.toString(), index); if (success) { NodeTest nodeTest; String prefix = name.getPrefix(); String namespaceURI = prefix == null ? null : context .getNamespaceURI(prefix); nodeTest = new NodeNameTest(name, namespaceURI); NodeIterator it = childIterator(nodeTest, false, null); if (it != null && it.setPosition(index + 1)) { return it.getNodePointer(); } } throw new JXPathAbstractFactoryException("Factory could not create " + "a child node for path: " + asPath() + "/" + name + "[" + (index + 1) + "]"); } public NodePointer createChild( JXPathContext context, QName name, int index, Object value) { NodePointer ptr = createChild(context, name, index); ptr.setValue(value); return ptr; } public NodePointer createAttribute(JXPathContext context, QName name) { if (!(node instanceof Element)) { return super.createAttribute(context, name); } Element element = (Element) node; String prefix = name.getPrefix(); if (prefix != null) { String namespaceUri = getNamespaceResolver().getNamespaceURI(prefix); if (namespaceUri == null) { throw new JXPathException( "Unknown namespace prefix: " + prefix); } Namespace ns = Namespace.getNamespace(prefix, namespaceUri); Attribute attr = element.getAttribute(name.getName(), ns); if (attr == null) { element.setAttribute(name.getName(), "", ns); } } else { Attribute attr = element.getAttribute(name.getName()); if (attr == null) { element.setAttribute(name.getName(), ""); } } NodeIterator it = attributeIterator(name); it.setPosition(1); return it.getNodePointer(); } public void remove() { Element parent = nodeParent(node); if (parent == null) { throw new JXPathException("Cannot remove root JDOM node"); } parent.getContent().remove(node); } public String asPath() { if (id != null) { return "id('" + escape(id) + "')"; } StringBuffer buffer = new StringBuffer(); if (parent != null) { buffer.append(parent.asPath()); } if (node instanceof Element) { // If the parent pointer is not a JDOMNodePointer, it is // the parent's responsibility to produce the node test part // of the path if (parent instanceof JDOMNodePointer) { if (buffer.length() == 0 || buffer.charAt(buffer.length() - 1) != '/') { buffer.append('/'); } String nsURI = getNamespaceURI(); String ln = JDOMNodePointer.getLocalName(node); if (nsURI == null) { buffer.append(ln); buffer.append('['); buffer.append(getRelativePositionByName()).append(']'); } else { String prefix = getNamespaceResolver().getPrefix(nsURI); if (prefix != null) { buffer.append(prefix); buffer.append(':'); buffer.append(ln); buffer.append('['); buffer.append(getRelativePositionByName()); buffer.append(']'); } else { buffer.append("node()"); buffer.append('['); buffer.append(getRelativePositionOfElement()); buffer.append(']'); } } } } else if (node instanceof Text || node instanceof CDATA) { buffer.append("/text()"); buffer.append('[').append(getRelativePositionOfTextNode()).append( ']'); } else if (node instanceof ProcessingInstruction) { buffer.append("/processing-instruction(\'").append(((ProcessingInstruction) node).getTarget()).append( "')"); buffer.append('[').append(getRelativePositionOfPI()).append( ']'); } return buffer.toString(); } /** * Get relative position of this among like-named siblings. * @return 1..n */ private int getRelativePositionByName() { if (node instanceof Element) { Object parent = ((Element) node).getParent(); if (!(parent instanceof Element)) { return 1; } List children = ((Element) parent).getContent(); int count = 0; String name = ((Element) node).getQualifiedName(); for (int i = 0; i < children.size(); i++) { Object child = children.get(i); if ((child instanceof Element) && ((Element) child).getQualifiedName().equals(name)) { count++; } if (child == node) { break; } } return count; } return 1; } /** * Get relative position of this among all siblings. * @return 1..n */ private int getRelativePositionOfElement() { Object parent = ((Element) node).getParent(); if (parent == null) { return 1; } List children; if (parent instanceof Element) { children = ((Element) parent).getContent(); } else { children = ((Document) parent).getContent(); } int count = 0; for (int i = 0; i < children.size(); i++) { Object child = children.get(i); if (child instanceof Element) { count++; } if (child == node) { break; } } return count; } /** * Get the relative position of this among sibling text nodes. * @return 1..n */ private int getRelativePositionOfTextNode() { Element parent; if (node instanceof Text) { parent = (Element) ((Text) node).getParent(); } else { parent = (Element) ((CDATA) node).getParent(); } if (parent == null) { return 1; } List children = parent.getContent(); int count = 0; for (int i = 0; i < children.size(); i++) { Object child = children.get(i); if (child instanceof Text || child instanceof CDATA) { count++; } if (child == node) { break; } } return count; } /** * Get the relative position of this among same-target processing instruction siblings. * @return 1..n */ private int getRelativePositionOfPI() { String target = ((ProcessingInstruction) node).getTarget(); Element parent = (Element) ((ProcessingInstruction) node).getParent(); if (parent == null) { return 1; } List children = parent.getContent(); int count = 0; for (int i = 0; i < children.size(); i++) { Object child = children.get(i); if (child instanceof ProcessingInstruction && (target == null || target.equals( ((ProcessingInstruction) child).getTarget()))) { count++; } if (child == node) { break; } } return count; } public int hashCode() { return node.hashCode(); } public boolean equals(Object object) { if (object == this) { return true; } if (!(object instanceof JDOMNodePointer)) { return false; } JDOMNodePointer other = (JDOMNodePointer) object; return node == other.node; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMPointerFactory.java100644 0 0 4176 11044113535 27666 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.jdom; import java.util.Locale; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.NodePointerFactory; import org.jdom.Document; import org.jdom.Element; /** * Implements NodePointerFactory for DOM elements. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class JDOMPointerFactory implements NodePointerFactory { /** factory order constant */ public static final int JDOM_POINTER_FACTORY_ORDER = 110; public int getOrder() { return JDOM_POINTER_FACTORY_ORDER; } public NodePointer createNodePointer( QName name, Object bean, Locale locale) { if (bean instanceof Document) { return new JDOMNodePointer(bean, locale); } if (bean instanceof Element) { return new JDOMNodePointer(bean, locale); } return null; } public NodePointer createNodePointer( NodePointer parent, QName name, Object bean) { if (bean instanceof Document) { return new JDOMNodePointer(parent, bean); } if (bean instanceof Element) { return new JDOMNodePointer(parent, bean); } return null; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/jdom/package.html100644 0 0 1541 11044113535 25653 0ustar 0 0 Implementation of "model" APIs for JDOM (see jdom.org). commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/NodeIterator.java100644 0 0 2752 11044113535 25710 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model; /** * Definition for an iterator for all kinds of Nodes. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public interface NodeIterator { /** * Get the current iterator position. * @return int position */ int getPosition(); /** * Set the new current position. * @param position the position to set * @return true if there is a node at position. */ boolean setPosition(int position); /** * Get the NodePointer at the current position. * @return NodePointer */ NodePointer getNodePointer(); } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java100644 0 0 67756 11044113535 25576 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model; import java.util.HashSet; import java.util.Locale; import org.apache.commons.jxpath.AbstractFactory; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathException; import org.apache.commons.jxpath.NodeSet; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.Compiler; import org.apache.commons.jxpath.ri.JXPathContextReferenceImpl; import org.apache.commons.jxpath.ri.NamespaceResolver; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.compiler.NodeNameTest; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.compiler.NodeTypeTest; import org.apache.commons.jxpath.ri.model.beans.NullPointer; /** * Common superclass for Pointers of all kinds. A NodePointer maps to * a deterministic XPath that represents the location of a node in an * object graph. This XPath uses only simple axes: child, namespace and * attribute and only simple, context-independent predicates. * * @author Dmitri Plotnikov * @version $Revision: 668329 $ $Date: 2008-06-16 16:59:48 -0500 (Mon, 16 Jun 2008) $ */ public abstract class NodePointer implements Pointer { /** Whole collection index. */ public static final int WHOLE_COLLECTION = Integer.MIN_VALUE; /** Constant to indicate unknown namespace */ public static final String UNKNOWN_NAMESPACE = "<>"; /** Index for this NodePointer */ protected int index = WHOLE_COLLECTION; private boolean attribute = false; private NamespaceResolver namespaceResolver; private transient Object rootNode; /** * Allocates an entirely new NodePointer by iterating through all installed * NodePointerFactories until it finds one that can create a pointer. * @param name QName * @param bean Object * @param locale Locale * @return NodePointer */ public static NodePointer newNodePointer( QName name, Object bean, Locale locale) { NodePointer pointer = null; if (bean == null) { pointer = new NullPointer(name, locale); return pointer; } NodePointerFactory[] factories = JXPathContextReferenceImpl.getNodePointerFactories(); for (int i = 0; i < factories.length; i++) { pointer = factories[i].createNodePointer(name, bean, locale); if (pointer != null) { return pointer; } } throw new JXPathException( "Could not allocate a NodePointer for object of " + bean.getClass()); } /** * Allocates an new child NodePointer by iterating through all installed * NodePointerFactories until it finds one that can create a pointer. * @param parent pointer * @param name QName * @param bean Object * @return NodePointer */ public static NodePointer newChildNodePointer( NodePointer parent, QName name, Object bean) { NodePointerFactory[] factories = JXPathContextReferenceImpl.getNodePointerFactories(); for (int i = 0; i < factories.length; i++) { NodePointer pointer = factories[i].createNodePointer(parent, name, bean); if (pointer != null) { return pointer; } } throw new JXPathException( "Could not allocate a NodePointer for object of " + bean.getClass()); } /** Parent pointer */ protected NodePointer parent; /** Locale */ protected Locale locale; /** * Create a new NodePointer. * @param parent Pointer */ protected NodePointer(NodePointer parent) { this.parent = parent; } /** * Create a new NodePointer. * @param parent Pointer * @param locale Locale */ protected NodePointer(NodePointer parent, Locale locale) { this.parent = parent; this.locale = locale; } /** * Get the NamespaceResolver associated with this NodePointer. * @return NamespaceResolver */ public NamespaceResolver getNamespaceResolver() { if (namespaceResolver == null && parent != null) { namespaceResolver = parent.getNamespaceResolver(); } return namespaceResolver; } /** * Set the NamespaceResolver for this NodePointer. * @param namespaceResolver NamespaceResolver */ public void setNamespaceResolver(NamespaceResolver namespaceResolver) { this.namespaceResolver = namespaceResolver; } /** * Get the parent pointer. * @return NodePointer */ public NodePointer getParent() { NodePointer pointer = parent; while (pointer != null && pointer.isContainer()) { pointer = pointer.getImmediateParentPointer(); } return pointer; } /** * Get the immediate parent pointer. * @return NodePointer */ public NodePointer getImmediateParentPointer() { return parent; } /** * Set to true if the pointer represents the "attribute::" axis. * @param attribute boolean */ public void setAttribute(boolean attribute) { this.attribute = attribute; } /** * Returns true if the pointer represents the "attribute::" axis. * @return boolean */ public boolean isAttribute() { return attribute; } /** * Returns true if this Pointer has no parent. * @return boolean */ public boolean isRoot() { return parent == null; } /** * If true, this node does not have children * @return boolean */ public abstract boolean isLeaf(); /** * Learn whether this pointer is considered to be a node. * @return boolean * @deprecated Please use !isContainer() */ public boolean isNode() { return !isContainer(); } /** * If true, this node is auxiliary and can only be used as an intermediate in * the chain of pointers. * @return boolean */ public boolean isContainer() { return false; } /** * If the pointer represents a collection, the index identifies * an element of that collection. The default value of index * is WHOLE_COLLECTION, which just means that the pointer * is not indexed at all. * Note: the index on NodePointer starts with 0, not 1. * @return int */ public int getIndex() { return index; } /** * Set the index of this NodePointer. * @param index int */ public void setIndex(int index) { this.index = index; } /** * Returns true if the value of the pointer is an array or * a Collection. * @return boolean */ public abstract boolean isCollection(); /** * If the pointer represents a collection (or collection element), * returns the length of the collection. * Otherwise returns 1 (even if the value is null). * @return int */ public abstract int getLength(); /** * By default, returns getNode(), can be overridden to * return a "canonical" value, like for instance a DOM element should * return its string value. * @return Object value */ public Object getValue() { NodePointer valuePointer = getValuePointer(); if (valuePointer != this) { return valuePointer.getValue(); } // Default behavior is to return the same as getNode() return getNode(); } /** * If this pointer manages a transparent container, like a variable, * this method returns the pointer to the contents. * Only an auxiliary (non-node) pointer can (and should) return a * value pointer other than itself. * Note that you probably don't want to override * getValuePointer() directly. Override the * getImmediateValuePointer() method instead. The * getValuePointer() method is calls * getImmediateValuePointer() and, if the result is not * this, invokes getValuePointer() recursively. * The idea here is to open all nested containers. Let's say we have a * container within a container within a container. The * getValuePointer() method should then open all those * containers and return the pointer to the ultimate contents. It does so * with the above recursion. * @return NodePointer */ public NodePointer getValuePointer() { NodePointer ivp = getImmediateValuePointer(); return ivp == this ? this : ivp.getValuePointer(); } /** * @see #getValuePointer() * * @return NodePointer is either this or a pointer * for the immediately contained value. */ public NodePointer getImmediateValuePointer() { return this; } /** * An actual pointer points to an existing part of an object graph, even * if it is null. A non-actual pointer represents a part that does not exist * at all. * For instance consider the pointer "/address/street". * If both address and street are not null, * the pointer is actual. * If address is not null, but street is null, * the pointer is still actual. * If address is null, the pointer is not actual. * (In JavaBeans) if address is not a property of the root bean, * a Pointer for this path cannot be obtained at all - actual or otherwise. * @return boolean */ public boolean isActual() { return index == WHOLE_COLLECTION || index >= 0 && index < getLength(); } /** * Returns the name of this node. Can be null. * @return QName */ public abstract QName getName(); /** * Returns the value represented by the pointer before indexing. * So, if the node represents an element of a collection, this * method returns the collection itself. * @return Object value */ public abstract Object getBaseValue(); /** * Returns the object the pointer points to; does not convert it * to a "canonical" type. * @return Object node value * @deprecated 1.1 Please use getNode() */ public Object getNodeValue() { return getNode(); } /** * Returns the object the pointer points to; does not convert it * to a "canonical" type. Opens containers, properties etc and returns * the ultimate contents. * @return Object node */ public Object getNode() { return getValuePointer().getImmediateNode(); } /** * Get the root node. * @return Object value of this pointer's root (top parent). */ public synchronized Object getRootNode() { if (rootNode == null) { rootNode = parent == null ? getImmediateNode() : parent.getRootNode(); } return rootNode; } /** * Returns the object the pointer points to; does not convert it * to a "canonical" type. * @return Object node */ public abstract Object getImmediateNode(); /** * Converts the value to the required type and changes the corresponding * object to that value. * @param value the value to set */ public abstract void setValue(Object value); /** * Compares two child NodePointers and returns a positive number, * zero or a positive number according to the order of the pointers. * @param pointer1 first pointer to be compared * @param pointer2 second pointer to be compared * @return int per Java comparison conventions */ public abstract int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2); /** * Checks if this Pointer matches the supplied NodeTest. * @param test the NodeTest to execute * @return true if a match */ public boolean testNode(NodeTest test) { if (test == null) { return true; } if (test instanceof NodeNameTest) { if (isContainer()) { return false; } NodeNameTest nodeNameTest = (NodeNameTest) test; QName testName = nodeNameTest.getNodeName(); QName nodeName = getName(); if (nodeName == null) { return false; } String testPrefix = testName.getPrefix(); String nodePrefix = nodeName.getPrefix(); if (!equalStrings(testPrefix, nodePrefix)) { String testNS = getNamespaceURI(testPrefix); String nodeNS = getNamespaceURI(nodePrefix); if (!equalStrings(testNS, nodeNS)) { return false; } } if (nodeNameTest.isWildcard()) { return true; } return testName.getName().equals(nodeName.getName()); } return test instanceof NodeTypeTest && ((NodeTypeTest) test).getNodeType() == Compiler.NODE_TYPE_NODE && isNode(); } /** * Compare two strings, either of which may be null, for equality. * @param s1 the first String to compare * @param s2 the second String to compare * @return true if both Strings are null, same or equal */ private static boolean equalStrings(String s1, String s2) { return s1 == s2 || s1 != null && s1.equals(s2); } /** * Called directly by JXPathContext. Must create path and * set value. * @param context the owning JXPathContext * @param value the new value to set * @return created NodePointer */ public NodePointer createPath(JXPathContext context, Object value) { setValue(value); return this; } /** * Remove the node of the object graph this pointer points to. */ public void remove() { // It is a no-op // System.err.println("REMOVING: " + asPath() + " " + getClass()); // printPointerChain(); } /** * Called by a child pointer when it needs to create a parent object. * Must create an object described by this pointer and return * a new pointer that properly describes the new object. * @param context the owning JXPathContext * @return created NodePointer */ public NodePointer createPath(JXPathContext context) { return this; } /** * Called by a child pointer if that child needs to assign the value * supplied in the createPath(context, value) call to a non-existent * node. This method may have to expand the collection in order to assign * the element. * @param context the owning JXPathCOntext * @param name the QName at which a child should be created * @param index child index. * @param value node value to set * @return created NodePointer */ public NodePointer createChild( JXPathContext context, QName name, int index, Object value) { throw new JXPathException("Cannot create an object for path " + asPath() + "/" + name + "[" + (index + 1) + "]" + ", operation is not allowed for this type of node"); } /** * Called by a child pointer when it needs to create a parent object for a * non-existent collection element. It may have to expand the collection, * then create an element object and return a new pointer describing the * newly created element. * @param context the owning JXPathCOntext * @param name the QName at which a child should be created * @param index child index. * @return created NodePointer */ public NodePointer createChild(JXPathContext context, QName name, int index) { throw new JXPathException("Cannot create an object for path " + asPath() + "/" + name + "[" + (index + 1) + "]" + ", operation is not allowed for this type of node"); } /** * Called to create a non-existing attribute * @param context the owning JXPathCOntext * @param name the QName at which an attribute should be created * @return created NodePointer */ public NodePointer createAttribute(JXPathContext context, QName name) { throw new JXPathException("Cannot create an attribute for path " + asPath() + "/@" + name + ", operation is not allowed for this type of node"); } /** * If the Pointer has a parent, returns the parent's locale; otherwise * returns the locale specified when this Pointer was created. * @return Locale for this NodePointer */ public Locale getLocale() { if (locale == null && parent != null) { locale = parent.getLocale(); } return locale; } /** * Check whether our locale matches the specified language. * @param lang String language to check * @return true if the selected locale name starts * with the specified prefix lang, case-insensitive. */ public boolean isLanguage(String lang) { Locale loc = getLocale(); String name = loc.toString().replace('_', '-'); return name.toUpperCase(Locale.ENGLISH).startsWith(lang.toUpperCase(Locale.ENGLISH)); } /** * Returns a NodeIterator that iterates over all children or all children * that match the given NodeTest, starting with the specified one. * @param test NodeTest to filter children * @param reverse specified iteration direction * @param startWith the NodePointer to start with * @return NodeIterator */ public NodeIterator childIterator( NodeTest test, boolean reverse, NodePointer startWith) { NodePointer valuePointer = getValuePointer(); return valuePointer == null || valuePointer == this ? null : valuePointer.childIterator(test, reverse, startWith); } /** * Returns a NodeIterator that iterates over all attributes of the current * node matching the supplied node name (could have a wildcard). * May return null if the object does not support the attributes. * @param qname the attribute name to test * @return NodeIterator */ public NodeIterator attributeIterator(QName qname) { NodePointer valuePointer = getValuePointer(); return valuePointer == null || valuePointer == this ? null : valuePointer.attributeIterator(qname); } /** * Returns a NodeIterator that iterates over all namespaces of the value * currently pointed at. * May return null if the object does not support the namespaces. * @return NodeIterator */ public NodeIterator namespaceIterator() { return null; } /** * Returns a NodePointer for the specified namespace. Will return null * if namespaces are not supported. * Will return UNKNOWN_NAMESPACE if there is no such namespace. * @param namespace incoming namespace * @return NodePointer for namespace */ public NodePointer namespacePointer(String namespace) { return null; } /** * Decodes a namespace prefix to the corresponding URI. * @param prefix prefix to decode * @return String uri */ public String getNamespaceURI(String prefix) { return null; } /** * Returns the namespace URI associated with this Pointer. * @return String uri */ public String getNamespaceURI() { return null; } /** * Returns true if the supplied prefix represents the * default namespace in the context of the current node. * @param prefix the prefix to check * @return true if prefix is default */ protected boolean isDefaultNamespace(String prefix) { if (prefix == null) { return true; } String namespace = getNamespaceURI(prefix); return namespace != null && namespace.equals(getDefaultNamespaceURI()); } /** * Get the default ns uri * @return String uri */ protected String getDefaultNamespaceURI() { return null; } /** * Locates a node by ID. * @param context JXPathContext owning context * @param id String id * @return Pointer found */ public Pointer getPointerByID(JXPathContext context, String id) { return context.getPointerByID(id); } /** * Locates a node by key and value. * @param context owning JXPathContext * @param key key to search for * @param value value to match * @return Pointer found */ public Pointer getPointerByKey( JXPathContext context, String key, String value) { return context.getPointerByKey(key, value); } /** * Find a NodeSet by key/value. * @param context owning JXPathContext * @param key key to search for * @param value value to match * @return NodeSet found */ public NodeSet getNodeSetByKey(JXPathContext context, String key, Object value) { return context.getNodeSetByKey(key, value); } /** * Returns an XPath that maps to this Pointer. * @return String xpath expression */ public String asPath() { // If the parent of this node is a container, it is responsible // for appended this node's part of the path. if (parent != null && parent.isContainer()) { return parent.asPath(); } StringBuffer buffer = new StringBuffer(); if (parent != null) { buffer.append(parent.asPath()); } if (buffer.length() == 0 || buffer.charAt(buffer.length() - 1) != '/') { buffer.append('/'); } if (attribute) { buffer.append('@'); } buffer.append(getName()); if (index != WHOLE_COLLECTION && isCollection()) { buffer.append('[').append(index + 1).append(']'); } return buffer.toString(); } /** * Clone this NodePointer. * @return cloned NodePointer */ public Object clone() { try { NodePointer ptr = (NodePointer) super.clone(); if (parent != null) { ptr.parent = (NodePointer) parent.clone(); } return ptr; } catch (CloneNotSupportedException ex) { // Of course it is supported ex.printStackTrace(); } return null; } public String toString() { return asPath(); } public int compareTo(Object object) { if (object == this) { return 0; } // Let it throw a ClassCastException NodePointer pointer = (NodePointer) object; if (parent == pointer.parent) { return parent == null ? 0 : parent.compareChildNodePointers(this, pointer); } // Task 1: find the common parent int depth1 = 0; NodePointer p1 = this; HashSet parents1 = new HashSet(); while (p1 != null) { depth1++; p1 = p1.parent; if (p1 != null) { parents1.add(p1); } } boolean commonParentFound = false; int depth2 = 0; NodePointer p2 = pointer; while (p2 != null) { depth2++; p2 = p2.parent; if (parents1.contains(p2)) { commonParentFound = true; } } //nodes from different graphs are equal, else continue comparison: return commonParentFound ? compareNodePointers(this, depth1, pointer, depth2) : 0; } /** * Compare node pointers. * @param p1 pointer 1 * @param depth1 depth 1 * @param p2 pointer 2 * @param depth2 depth 2 * @return comparison result: (< 0) -> (p1 lt p2); (0) -> (p1 eq p2); (> 0) -> (p1 gt p2) */ private int compareNodePointers( NodePointer p1, int depth1, NodePointer p2, int depth2) { if (depth1 < depth2) { int r = compareNodePointers(p1, depth1, p2.parent, depth2 - 1); return r == 0 ? -1 : r; } if (depth1 > depth2) { int r = compareNodePointers(p1.parent, depth1 - 1, p2, depth2); return r == 0 ? 1 : r; } //henceforth depth1 == depth2: if (p1 == p2 || p1 != null && p1.equals(p2)) { return 0; } if (depth1 == 1) { throw new JXPathException( "Cannot compare pointers that do not belong to the same tree: '" + p1 + "' and '" + p2 + "'"); } int r = compareNodePointers(p1.parent, depth1 - 1, p2.parent, depth2 - 1); return r == 0 ? p1.parent.compareChildNodePointers(p1, p2) : r; } /** * Print internal structure of a pointer for debugging */ public void printPointerChain() { printDeep(this, ""); } /** * Return a string escaping single and double quotes. * @param string string to treat * @return string with any necessary changes made. */ protected String escape(String string) { final char[] c = new char[] { '\'', '"' }; final String[] esc = new String[] { "'", """ }; StringBuffer sb = null; for (int i = 0; sb == null && i < c.length; i++) { if (string.indexOf(c[i]) >= 0) { sb = new StringBuffer(string); } } if (sb == null) { return string; } for (int i = 0; i < c.length; i++) { if (string.indexOf(c[i]) < 0) { continue; } int pos = 0; while (pos < sb.length()) { if (sb.charAt(pos) == c[i]) { sb.replace(pos, pos + 1, esc[i]); pos += esc[i].length(); } else { pos++; } } } return sb.toString(); } /** * Get the AbstractFactory associated with the specified JXPathContext. * @param context JXPathContext * @return AbstractFactory */ protected AbstractFactory getAbstractFactory(JXPathContext context) { AbstractFactory factory = context.getFactory(); if (factory == null) { throw new JXPathException( "Factory is not set on the JXPathContext - cannot create path: " + asPath()); } return factory; } /** * Print deep * @param pointer to print * @param indent indentation level */ private static void printDeep(NodePointer pointer, String indent) { if (indent.length() == 0) { System.err.println( "POINTER: " + pointer + "(" + pointer.getClass().getName() + ")"); } else { System.err.println( indent + " of " + pointer + "(" + pointer.getClass().getName() + ")"); } if (pointer.getImmediateParentPointer() != null) { printDeep(pointer.getImmediateParentPointer(), indent + " "); } } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/NodePointerFactory.java100644 0 0 4233 11044113535 27063 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model; import java.util.Locale; import org.apache.commons.jxpath.ri.QName; /** * Creates NodePointers for objects of a certain type. * NodePointerFactories are ordered according to the values returned * by the "getOrder" method and always queried in that order. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public interface NodePointerFactory { /** * The factory order number determines its position between other factories. * @return int order */ int getOrder(); /** * Create a NodePointer for the supplied object. The node will represent * the "root" object for a path. * * @param name String node name * @param object child object * @param locale Locale * @return null if this factory does not recognize objects of the supplied * type. */ NodePointer createNodePointer(QName name, Object object, Locale locale); /** * Create a NodePointer for the supplied child object. * * @param parent parent node * @param name String node name * @param object child object * @return null if this factory does not recognize objects of the supplied * type. */ NodePointer createNodePointer( NodePointer parent, QName name, Object object); } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/package.html100644 0 0 2017 11044113535 24721 0ustar 0 0 The "model" package defines APIs that are implemented for every object model to be supported by JXPath. The main part of this API is Pointers, which are a mechanism for identifying locations of objects within an object graph. commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/VariablePointer.java100644 0 0 25062 11044113535 26416 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model; import org.apache.commons.jxpath.AbstractFactory; import org.apache.commons.jxpath.JXPathAbstractFactoryException; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathException; import org.apache.commons.jxpath.JXPathIntrospector; import org.apache.commons.jxpath.JXPathInvalidAccessException; import org.apache.commons.jxpath.Variables; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.compiler.NodeTest; import org.apache.commons.jxpath.ri.model.beans.NullPointer; import org.apache.commons.jxpath.util.ValueUtils; /** * Pointer to a context variable. * * @author Dmitri Plotnikov * @version $Revision: 652884 $ $Date: 2008-05-02 15:02:00 -0500 (Fri, 02 May 2008) $ */ public class VariablePointer extends NodePointer { private Variables variables; private QName name; private NodePointer valuePointer; private boolean actual; private static final long serialVersionUID = -454731297397189293L; /** * Create a new VariablePointer. * @param variables Variables instance * @param name variable name */ public VariablePointer(Variables variables, QName name) { super(null); this.variables = variables; this.name = name; actual = true; } /** * Create a new (non-actual) VariablePointer. * @param name variable name */ public VariablePointer(QName name) { super(null); this.name = name; actual = false; } public boolean isContainer() { return true; } public QName getName() { return name; } public Object getBaseValue() { if (!actual) { throw new JXPathException("Undefined variable: " + name); } return variables.getVariable(name.toString()); } public boolean isLeaf() { Object value = getNode(); return value == null || JXPathIntrospector.getBeanInfo(value.getClass()).isAtomic(); } public boolean isCollection() { Object value = getBaseValue(); return value != null && ValueUtils.isCollection(value); } public Object getImmediateNode() { Object value = getBaseValue(); return index == WHOLE_COLLECTION ? ValueUtils.getValue(value) : ValueUtils.getValue(value, index); } public void setValue(Object value) { if (!actual) { throw new JXPathException("Cannot set undefined variable: " + name); } valuePointer = null; if (index != WHOLE_COLLECTION) { Object collection = getBaseValue(); ValueUtils.setValue(collection, index, value); } else { variables.declareVariable(name.toString(), value); } } public boolean isActual() { return actual; } public void setIndex(int index) { super.setIndex(index); valuePointer = null; } public NodePointer getImmediateValuePointer() { if (valuePointer == null) { Object value = null; if (actual) { value = getImmediateNode(); valuePointer = NodePointer.newChildNodePointer(this, null, value); } else { return new NullPointer(this, getName()) { public Object getImmediateNode() { throw new JXPathException( "Undefined variable: " + name); } }; } } return valuePointer; } public int getLength() { if (actual) { Object value = getBaseValue(); return value == null ? 1 : ValueUtils.getLength(value); } return 0; } public NodePointer createPath(JXPathContext context, Object value) { if (actual) { setValue(value); return this; } NodePointer ptr = createPath(context); ptr.setValue(value); return ptr; } public NodePointer createPath(JXPathContext context) { if (!actual) { AbstractFactory factory = getAbstractFactory(context); if (!factory.declareVariable(context, name.toString())) { throw new JXPathAbstractFactoryException( "Factory cannot define variable '" + name + "' for path: " + asPath()); } findVariables(context); // Assert: actual == true } return this; } public NodePointer createChild( JXPathContext context, QName name, int index) { Object collection = createCollection(context, index); if (!isActual() || (index != 0 && index != WHOLE_COLLECTION)) { AbstractFactory factory = getAbstractFactory(context); boolean success = factory.createObject( context, this, collection, getName().toString(), index); if (!success) { throw new JXPathAbstractFactoryException( "Factory could not create object path: " + asPath()); } NodePointer cln = (NodePointer) clone(); cln.setIndex(index); return cln; } return this; } public NodePointer createChild( JXPathContext context, QName name, int index, Object value) { Object collection = createCollection(context, index); ValueUtils.setValue(collection, index, value); NodePointer cl = (NodePointer) clone(); cl.setIndex(index); return cl; } /** * Create a collection. * @param context JXPathContext * @param index collection index * @return Object */ private Object createCollection(JXPathContext context, int index) { createPath(context); Object collection = getBaseValue(); if (collection == null) { throw new JXPathAbstractFactoryException( "Factory did not assign a collection to variable '" + name + "' for path: " + asPath()); } if (index == WHOLE_COLLECTION) { index = 0; } else if (index < 0) { throw new JXPathInvalidAccessException("Index is less than 1: " + asPath()); } if (index >= getLength()) { collection = ValueUtils.expandCollection(collection, index + 1); variables.declareVariable(name.toString(), collection); } return collection; } public void remove() { if (actual) { if (index == WHOLE_COLLECTION) { variables.undeclareVariable(name.toString()); } else { if (index < 0) { throw new JXPathInvalidAccessException( "Index is less than 1: " + asPath()); } Object collection = getBaseValue(); if (collection != null && index < getLength()) { collection = ValueUtils.remove(collection, index); variables.declareVariable(name.toString(), collection); } } } } /** * Assimilate the Variables instance associated with the specified context. * @param context JXPathContext to search */ protected void findVariables(JXPathContext context) { valuePointer = null; JXPathContext varCtx = context; while (varCtx != null) { variables = varCtx.getVariables(); if (variables.isDeclaredVariable(name.toString())) { actual = true; break; } varCtx = varCtx.getParentContext(); variables = null; } } public int hashCode() { return (actual ? System.identityHashCode(variables) : 0) + name.hashCode() + index; } public boolean equals(Object object) { if (object == this) { return true; } if (!(object instanceof VariablePointer)) { return false; } VariablePointer other = (VariablePointer) object; return variables == other.variables && name.equals(other.name) && index == other.index; } public String asPath() { StringBuffer buffer = new StringBuffer(); buffer.append('$'); buffer.append(name); if (!actual) { if (index != WHOLE_COLLECTION) { buffer.append('[').append(index + 1).append(']'); } } else if ( index != WHOLE_COLLECTION && (getNode() == null || isCollection())) { buffer.append('[').append(index + 1).append(']'); } return buffer.toString(); } public NodeIterator childIterator( NodeTest test, boolean reverse, NodePointer startWith) { return getValuePointer().childIterator(test, reverse, startWith); } public NodeIterator attributeIterator(QName name) { return getValuePointer().attributeIterator(name); } public NodeIterator namespaceIterator() { return getValuePointer().namespaceIterator(); } public NodePointer namespacePointer(String name) { return getValuePointer().namespacePointer(name); } public boolean testNode(NodeTest nodeTest) { return getValuePointer().testNode(nodeTest); } public int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2) { return pointer1.getIndex() - pointer2.getIndex(); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/model/VariablePointerFactory.java100644 0 0 6412 11044113535 27724 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model; import java.util.Locale; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.Variables; import org.apache.commons.jxpath.ri.QName; /** * NodePointerFactory to create {@link VariablePointer VariablePointers}. * @author Matt Benson * @since JXPath 1.3 * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class VariablePointerFactory implements NodePointerFactory { /** factory order constant */ public static final int VARIABLE_POINTER_FACTORY_ORDER = 890; /** * Node value wrapper to trigger a VariablePointerFactory. */ public static final class VariableContextWrapper { private final JXPathContext context; /** * Create a new VariableContextWrapper. * @param context to wrap */ private VariableContextWrapper(JXPathContext context) { this.context = context; } /** * Get the original (unwrapped) context. * * @return JXPathContext. */ public JXPathContext getContext() { return context; } } /** * VariableContextWrapper factory method. * @param context the JXPathContext to wrap. * @return VariableContextWrapper. */ public static VariableContextWrapper contextWrapper(JXPathContext context) { return new VariableContextWrapper(context); } public NodePointer createNodePointer(QName name, Object object, Locale locale) { if (object instanceof VariableContextWrapper) { JXPathContext varCtx = ((VariableContextWrapper) object).getContext(); while (varCtx != null) { Variables vars = varCtx.getVariables(); if (vars.isDeclaredVariable(name.toString())) { return new VariablePointer(vars, name); } varCtx = varCtx.getParentContext(); } // The variable is not declared, but we will create // a pointer anyway in case the user wants to set, rather // than get, the value of the variable. return new VariablePointer(name); } return null; } public NodePointer createNodePointer(NodePointer parent, QName name, Object object) { return createNodePointer(name, object, null); } public int getOrder() { return VARIABLE_POINTER_FACTORY_ORDER; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/NamespaceResolver.java100644 0 0 15303 11044113541 25640 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri; import java.io.Serializable; import java.util.HashMap; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; /** * Namespace resolver for {@link JXPathContextReferenceImpl}. * * @author Dmitri Plotnikov * @version $Revision: 668329 $ $Date: 2008-06-16 16:59:48 -0500 (Mon, 16 Jun 2008) $ */ public class NamespaceResolver implements Cloneable, Serializable { private static final long serialVersionUID = 1085590057838651311L; /** Parent NamespaceResolver */ protected final NamespaceResolver parent; /** namespace map */ protected HashMap namespaceMap = new HashMap(); /** reverse lookup map */ protected HashMap reverseMap = new HashMap(); /** pointer */ protected NodePointer pointer; private boolean sealed; /** * Find the namespace prefix for the specified namespace URI and NodePointer. * @param pointer location * @param namespaceURI to check * @return prefix if found * @since JXPath 1.3 */ protected static String getPrefix(NodePointer pointer, String namespaceURI) { NodePointer currentPointer = pointer; while (currentPointer != null) { NodeIterator ni = currentPointer.namespaceIterator(); for (int position = 1; ni != null && ni.setPosition(position); position++) { NodePointer nsPointer = ni.getNodePointer(); String uri = nsPointer.getNamespaceURI(); if (uri.equals(namespaceURI)) { String prefix = nsPointer.getName().getName(); if (!"".equals(prefix)) { return prefix; } } } currentPointer = pointer.getParent(); } return null; } /** * Create a new NamespaceResolver. */ public NamespaceResolver() { this(null); } /** * Create a new NamespaceResolver. * @param parent NamespaceResolver */ public NamespaceResolver(NamespaceResolver parent) { this.parent = parent; } /** * Registers a namespace prefix. * * @param prefix A namespace prefix * @param namespaceURI A URI for that prefix */ public synchronized void registerNamespace(String prefix, String namespaceURI) { if (isSealed()) { throw new IllegalStateException( "Cannot register namespaces on a sealed NamespaceResolver"); } namespaceMap.put(prefix, namespaceURI); reverseMap.put(namespaceURI, prefix); } /** * Register a namespace for the expression context. * @param pointer the Pointer to set. */ public void setNamespaceContextPointer(NodePointer pointer) { this.pointer = pointer; } /** * Get the namespace context pointer. * @return Pointer */ public Pointer getNamespaceContextPointer() { if (pointer == null && parent != null) { return parent.getNamespaceContextPointer(); } return pointer; } /** * Given a prefix, returns a registered namespace URI. If the requested * prefix was not defined explicitly using the registerNamespace method, * JXPathContext will then check the context node to see if the prefix is * defined there. See * {@link #setNamespaceContextPointer(NodePointer) setNamespaceContextPointer}. * * @param prefix The namespace prefix to look up * @return namespace URI or null if the prefix is undefined. */ public synchronized String getNamespaceURI(String prefix) { String uri = getExternallyRegisteredNamespaceURI(prefix); return uri == null && pointer != null ? pointer.getNamespaceURI(prefix) : uri; } /** * Given a prefix, returns an externally registered namespace URI. * * @param prefix The namespace prefix to look up * @return namespace URI or null if the prefix is undefined. * @since JXPath 1.3 */ protected synchronized String getExternallyRegisteredNamespaceURI( String prefix) { String uri = (String) namespaceMap.get(prefix); return uri == null && parent != null ? parent .getExternallyRegisteredNamespaceURI(prefix) : uri; } /** * Get the prefix associated with the specifed namespace URI. * @param namespaceURI the ns URI to check. * @return String prefix */ public synchronized String getPrefix(String namespaceURI) { String prefix = getExternallyRegisteredPrefix(namespaceURI); return prefix == null && pointer != null ? getPrefix(pointer, namespaceURI) : prefix; } /** * Get the nearest prefix found that matches an externally-registered namespace. * @param namespaceURI the ns URI to check. * @return String prefix if found. * @since JXPath 1.3 */ protected synchronized String getExternallyRegisteredPrefix(String namespaceURI) { String prefix = (String) reverseMap.get(namespaceURI); return prefix == null && parent != null ? parent .getExternallyRegisteredPrefix(namespaceURI) : prefix; } /** * Learn whether this NamespaceResolver has been sealed. * @return boolean */ public boolean isSealed() { return sealed; } /** * Seal this {@link NamespaceResolver}. */ public void seal() { sealed = true; if (parent != null) { parent.seal(); } } public Object clone() { try { NamespaceResolver result = (NamespaceResolver) super.clone(); result.sealed = false; return result; } catch (CloneNotSupportedException e) { // Of course, it's supported. e.printStackTrace(); return null; } } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/package.html100644 0 0 1735 11044113541 23624 0ustar 0 0 Reference implementation of JXPath. It comes with a JavaCC-based parser for XPath expressions, a parse tree and a fast interpreter, which applies XPaths to graphs of Java objects. commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/parser/jcc.bat100644 0 0 1737 11044113541 24070 0ustar 0 0 rem * Licensed to the Apache Software Foundation (ASF) under one or more rem * contributor license agreements. See the NOTICE file distributed with rem * this work for additional information regarding copyright ownership. rem * The ASF licenses this file to You under the Apache License, Version 2.0 rem * (the "License"); you may not use this file except in compliance with rem * the License. You may obtain a copy of the License at rem * rem * http://www.apache.org/licenses/LICENSE-2.0 rem * rem * Unless required by applicable law or agreed to in writing, software rem * distributed under the License is distributed on an "AS IS" BASIS, rem * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. rem * See the License for the specific language governing permissions and rem * limitations under the License. @echo off set JAVACC_HOME=c:\tools\javacc-3.0 call %JAVACC_HOME%\bin\javacc.bat XPath.jj call %JAVACC_HOME%\bin\jjdoc.bat XPath.jjcommons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/parser/package.html100644 0 0 1646 11044113541 25121 0ustar 0 0 JavaCC XPath grammar. All classes in this package were generated by JavaCC. The grammar definition is in the XPath.jj file. commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/parser/ParseException.java100644 0 0 14352 11044113541 26452 0ustar 0 0 /* Generated By:JavaCC: Do not edit this line. ParseException.java Version 3.0 */ package org.apache.commons.jxpath.ri.parser; /** * This exception is thrown when parse errors are encountered. * You can explicitly create objects of this exception type by * calling the method generateParseException in the generated * parser. * * You can modify this class to customize your error reporting * mechanisms so long as you retain the public fields. */ public class ParseException extends Exception { /** * This constructor is used by the method "generateParseException" * in the generated parser. Calling this constructor generates * a new object of this type with the fields "currentToken", * "expectedTokenSequences", and "tokenImage" set. The boolean * flag "specialConstructor" is also set to true to indicate that * this constructor was used to create this object. * This constructor calls its super class with the empty string * to force the "toString" method of parent class "Throwable" to * print the error message in the form: * ParseException: */ public ParseException(Token currentTokenVal, int[][] expectedTokenSequencesVal, String[] tokenImageVal ) { super(""); specialConstructor = true; currentToken = currentTokenVal; expectedTokenSequences = expectedTokenSequencesVal; tokenImage = tokenImageVal; } /** * The following constructors are for use by you for whatever * purpose you can think of. Constructing the exception in this * manner makes the exception behave in the normal way - i.e., as * documented in the class "Throwable". The fields "errorToken", * "expectedTokenSequences", and "tokenImage" do not contain * relevant information. The JavaCC generated code does not use * these constructors. */ public ParseException() { super(); specialConstructor = false; } public ParseException(String message) { super(message); specialConstructor = false; } /** * This variable determines which constructor was used to create * this object and thereby affects the semantics of the * "getMessage" method (see below). */ protected boolean specialConstructor; /** * This is the last token that has been consumed successfully. If * this object has been created due to a parse error, the token * followng this token will (therefore) be the first error token. */ public Token currentToken; /** * Each entry in this array is an array of integers. Each array * of integers represents a sequence of tokens (by their ordinal * values) that is expected at this point of the parse. */ public int[][] expectedTokenSequences; /** * This is a reference to the "tokenImage" array of the generated * parser within which the parse error occurred. This array is * defined in the generated ...Constants interface. */ public String[] tokenImage; /** * This method has the standard behavior when this object has been * created using the standard constructors. Otherwise, it uses * "currentToken" and "expectedTokenSequences" to generate a parse * error message and returns it. If this object has been created * due to a parse error, and you do not catch it (it gets thrown * from the parser), then this method is called during the printing * of the final stack trace, and hence the correct error message * gets displayed. */ public String getMessage() { if (!specialConstructor) { return super.getMessage(); } String expected = ""; int maxSize = 0; for (int i = 0; i < expectedTokenSequences.length; i++) { if (maxSize < expectedTokenSequences[i].length) { maxSize = expectedTokenSequences[i].length; } for (int j = 0; j < expectedTokenSequences[i].length; j++) { expected += tokenImage[expectedTokenSequences[i][j]] + " "; } if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) { expected += "..."; } expected += eol + " "; } String retval = "Encountered \""; Token tok = currentToken.next; for (int i = 0; i < maxSize; i++) { if (i != 0) retval += " "; if (tok.kind == 0) { retval += tokenImage[0]; break; } retval += add_escapes(tok.image); tok = tok.next; } retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; retval += "." + eol; if (expectedTokenSequences.length == 1) { retval += "Was expecting:" + eol + " "; } else { retval += "Was expecting one of:" + eol + " "; } retval += expected; return retval; } /** * The end of line string for this machine. */ protected String eol = System.getProperty("line.separator", "\n"); /** * Used to convert raw characters to their escaped version * when these raw version cannot be used as part of an ASCII * string literal. */ protected String add_escapes(String str) { StringBuffer retval = new StringBuffer(); char ch; for (int i = 0; i < str.length(); i++) { switch (str.charAt(i)) { case 0 : continue; case '\b': retval.append("\\b"); continue; case '\t': retval.append("\\t"); continue; case '\n': retval.append("\\n"); continue; case '\f': retval.append("\\f"); continue; case '\r': retval.append("\\r"); continue; case '\"': retval.append("\\\""); continue; case '\'': retval.append("\\\'"); continue; case '\\': retval.append("\\\\"); continue; default: if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { String s = "0000" + Integer.toString(ch, 16); retval.append("\\u" + s.substring(s.length() - 4, s.length())); } else { retval.append(ch); } continue; } } return retval.toString(); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/parser/SimpleCharStream.java100644 0 0 22712 11044113541 26723 0ustar 0 0 /* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 3.0 */ package org.apache.commons.jxpath.ri.parser; /** * An implementation of interface CharStream, where the stream is assumed to * contain only ASCII characters (without unicode processing). */ public class SimpleCharStream { public static final boolean staticFlag = false; int bufsize; int available; int tokenBegin; public int bufpos = -1; protected int bufline[]; protected int bufcolumn[]; protected int column = 0; protected int line = 1; protected boolean prevCharIsCR = false; protected boolean prevCharIsLF = false; protected java.io.Reader inputStream; protected char[] buffer; protected int maxNextCharInd = 0; protected int inBuf = 0; protected void ExpandBuff(boolean wrapAround) { char[] newbuffer = new char[bufsize + 2048]; int newbufline[] = new int[bufsize + 2048]; int newbufcolumn[] = new int[bufsize + 2048]; try { if (wrapAround) { System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos); buffer = newbuffer; System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos); bufline = newbufline; System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos); bufcolumn = newbufcolumn; maxNextCharInd = (bufpos += (bufsize - tokenBegin)); } else { System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); buffer = newbuffer; System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); bufline = newbufline; System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); bufcolumn = newbufcolumn; maxNextCharInd = (bufpos -= tokenBegin); } } catch (Throwable t) { throw new Error(t.getMessage()); } bufsize += 2048; available = bufsize; tokenBegin = 0; } protected void FillBuff() throws java.io.IOException { if (maxNextCharInd == available) { if (available == bufsize) { if (tokenBegin > 2048) { bufpos = maxNextCharInd = 0; available = tokenBegin; } else if (tokenBegin < 0) bufpos = maxNextCharInd = 0; else ExpandBuff(false); } else if (available > tokenBegin) available = bufsize; else if ((tokenBegin - available) < 2048) ExpandBuff(true); else available = tokenBegin; } int i; try { if ((i = inputStream.read(buffer, maxNextCharInd, available - maxNextCharInd)) == -1) { inputStream.close(); throw new java.io.IOException(); } else maxNextCharInd += i; return; } catch(java.io.IOException e) { --bufpos; backup(0); if (tokenBegin == -1) tokenBegin = bufpos; throw e; } } public char BeginToken() throws java.io.IOException { tokenBegin = -1; char c = readChar(); tokenBegin = bufpos; return c; } protected void UpdateLineColumn(char c) { column++; if (prevCharIsLF) { prevCharIsLF = false; line += (column = 1); } else if (prevCharIsCR) { prevCharIsCR = false; if (c == '\n') { prevCharIsLF = true; } else line += (column = 1); } switch (c) { case '\r' : prevCharIsCR = true; break; case '\n' : prevCharIsLF = true; break; case '\t' : column--; column += (8 - (column & 07)); break; default : break; } bufline[bufpos] = line; bufcolumn[bufpos] = column; } public char readChar() throws java.io.IOException { if (inBuf > 0) { --inBuf; if (++bufpos == bufsize) bufpos = 0; return buffer[bufpos]; } if (++bufpos >= maxNextCharInd) FillBuff(); char c = buffer[bufpos]; UpdateLineColumn(c); return (c); } /** * @deprecated * @see #getEndColumn */ public int getColumn() { return bufcolumn[bufpos]; } /** * @deprecated * @see #getEndLine */ public int getLine() { return bufline[bufpos]; } public int getEndColumn() { return bufcolumn[bufpos]; } public int getEndLine() { return bufline[bufpos]; } public int getBeginColumn() { return bufcolumn[tokenBegin]; } public int getBeginLine() { return bufline[tokenBegin]; } public void backup(int amount) { inBuf += amount; if ((bufpos -= amount) < 0) bufpos += bufsize; } public SimpleCharStream(java.io.Reader dstream, int startline, int startcolumn, int buffersize) { inputStream = dstream; line = startline; column = startcolumn - 1; available = bufsize = buffersize; buffer = new char[buffersize]; bufline = new int[buffersize]; bufcolumn = new int[buffersize]; } public SimpleCharStream(java.io.Reader dstream, int startline, int startcolumn) { this(dstream, startline, startcolumn, 4096); } public SimpleCharStream(java.io.Reader dstream) { this(dstream, 1, 1, 4096); } public void ReInit(java.io.Reader dstream, int startline, int startcolumn, int buffersize) { inputStream = dstream; line = startline; column = startcolumn - 1; if (buffer == null || buffersize != buffer.length) { available = bufsize = buffersize; buffer = new char[buffersize]; bufline = new int[buffersize]; bufcolumn = new int[buffersize]; } prevCharIsLF = prevCharIsCR = false; tokenBegin = inBuf = maxNextCharInd = 0; bufpos = -1; } public void ReInit(java.io.Reader dstream, int startline, int startcolumn) { ReInit(dstream, startline, startcolumn, 4096); } public void ReInit(java.io.Reader dstream) { ReInit(dstream, 1, 1, 4096); } public SimpleCharStream(java.io.InputStream dstream, int startline, int startcolumn, int buffersize) { this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096); } public SimpleCharStream(java.io.InputStream dstream, int startline, int startcolumn) { this(dstream, startline, startcolumn, 4096); } public SimpleCharStream(java.io.InputStream dstream) { this(dstream, 1, 1, 4096); } public void ReInit(java.io.InputStream dstream, int startline, int startcolumn, int buffersize) { ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096); } public void ReInit(java.io.InputStream dstream) { ReInit(dstream, 1, 1, 4096); } public void ReInit(java.io.InputStream dstream, int startline, int startcolumn) { ReInit(dstream, startline, startcolumn, 4096); } public String GetImage() { if (bufpos >= tokenBegin) return new String(buffer, tokenBegin, bufpos - tokenBegin + 1); else return new String(buffer, tokenBegin, bufsize - tokenBegin) + new String(buffer, 0, bufpos + 1); } public char[] GetSuffix(int len) { char[] ret = new char[len]; if ((bufpos + 1) >= len) System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); else { System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0, len - bufpos - 1); System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1); } return ret; } public void Done() { buffer = null; bufline = null; bufcolumn = null; } /** * Method to adjust line and column numbers for the start of a token.
*/ public void adjustBeginLineColumn(int newLine, int newCol) { int start = tokenBegin; int len; if (bufpos >= tokenBegin) { len = bufpos - tokenBegin + inBuf + 1; } else { len = bufsize - tokenBegin + bufpos + 1 + inBuf; } int i = 0, j = 0, k = 0; int nextColDiff = 0, columnDiff = 0; while (i < len && bufline[j = start % bufsize] == bufline[k = ++start % bufsize]) { bufline[j] = newLine; nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j]; bufcolumn[j] = newCol + columnDiff; columnDiff = nextColDiff; i++; } if (i < len) { bufline[j] = newLine++; bufcolumn[j] = newCol + columnDiff; while (i++ < len) { if (bufline[j = start % bufsize] != bufline[++start % bufsize]) bufline[j] = newLine++; else bufline[j] = newLine; } } line = bufline[j]; column = bufcolumn[j]; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/parser/Token.java100644 0 0 5172 11044113541 24561 0ustar 0 0 /* Generated By:JavaCC: Do not edit this line. Token.java Version 3.0 */ package org.apache.commons.jxpath.ri.parser; /** * Describes the input token stream. */ public class Token { /** * An integer that describes the kind of this token. This numbering * system is determined by JavaCCParser, and a table of these numbers is * stored in the file ...Constants.java. */ public int kind; /** * beginLine and beginColumn describe the position of the first character * of this token; endLine and endColumn describe the position of the * last character of this token. */ public int beginLine, beginColumn, endLine, endColumn; /** * The string image of the token. */ public String image; /** * A reference to the next regular (non-special) token from the input * stream. If this is the last token from the input stream, or if the * token manager has not read tokens beyond this one, this field is * set to null. This is true only if this token is also a regular * token. Otherwise, see below for a description of the contents of * this field. */ public Token next; /** * This field is used to access special tokens that occur prior to this * token, but after the immediately preceding regular (non-special) token. * If there are no such special tokens, this field is set to null. * When there are more than one such special token, this field refers * to the last of these special tokens, which in turn refers to the next * previous special token through its specialToken field, and so on * until the first special token (whose specialToken field is null). * The next fields of special tokens refer to other special tokens that * immediately follow it (without an intervening regular token). If there * is no such token, this field is null. */ public Token specialToken; /** * Returns the image. */ public String toString() { return image; } /** * Returns a new Token object, by default. However, if you want, you * can create and return subclass objects based on the value of ofKind. * Simply add the cases to the switch for all those special cases. * For example, if you have a subclass of Token called IDToken that * you want to create if ofKind is ID, simlpy add something like : * * case MyParserConstants.ID : return new IDToken(); * * to the following switch statement. Then you can cast matchedToken * variable to the appropriate type and use it in your lexical actions. */ public static final Token newToken(int ofKind) { switch(ofKind) { default : return new Token(); } } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/parser/TokenMgrError.java100644 0 0 10750 11044113541 26257 0ustar 0 0 /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 * * * !!!MODIFIED BY DMITRI PLOTNIKOV - DO NOT REGENERATE!!! */ package org.apache.commons.jxpath.ri.parser; public class TokenMgrError extends Error { /* * Ordinals for various reasons why an Error of this type can be thrown. */ /** * Lexical error occured. */ static final int LEXICAL_ERROR = 0; /** * An attempt wass made to create a second instance of a static token manager. */ static final int STATIC_LEXER_ERROR = 1; /** * Tried to change to an invalid lexical state. */ static final int INVALID_LEXICAL_STATE = 2; /** * Detected (and bailed out of) an infinite loop in the token manager. */ static final int LOOP_DETECTED = 3; /** * Indicates the reason why the exception is thrown. It will have * one of the above 4 values. */ int errorCode; /** * Replaces unprintable characters by their espaced (or unicode escaped) * equivalents in the given string */ public static final String addEscapes(String str) { StringBuffer retval = new StringBuffer(); char ch; for (int i = 0; i < str.length(); i++) { switch (str.charAt(i)) { case 0 : continue; case '\b': retval.append("\\b"); continue; case '\t': retval.append("\\t"); continue; case '\n': retval.append("\\n"); continue; case '\f': retval.append("\\f"); continue; case '\r': retval.append("\\r"); continue; case '\"': retval.append("\\\""); continue; case '\'': retval.append("\\\'"); continue; case '\\': retval.append("\\\\"); continue; default: if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { String s = "0000" + Integer.toString(ch, 16); retval.append("\\u" + s.substring(s.length() - 4, s.length())); } else { retval.append(ch); } continue; } } return retval.toString(); } /** * Returns a detailed message for the Error when it is thrown by the * token manager to indicate a lexical error. * Parameters : * EOFSeen : indicates if EOF caused the lexicl error * curLexState : lexical state in which this error occured * errorLine : line number when the error occured * errorColumn : column number when the error occured * errorAfter : prefix that was seen before this error occured * curchar : the offending character * Note: You can customize the lexical error message by modifying this method. */ protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { return("Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered: " + (EOFSeen ? " " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + "after : \"" + addEscapes(errorAfter) + "\""); } /** * You can also modify the body of this method to customize your error messages. * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not * of end-users concern, so you can return something like : * * "Internal Error : Please file a bug report .... " * * from this method for such cases in the release version of your parser. */ public String getMessage() { return super.getMessage(); } /* * Constructors of various flavors follow. */ public TokenMgrError() { } public TokenMgrError(String message, int reason) { super(message); errorCode = reason; } public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); // ADDED BY ME FROM THIS POINT TO THE EOF - DMITRI PLOTNIKOV position = errorColumn - 1; character = curChar; } private int position; private char character; public int getPosition(){ return position; } public char getCharacter(){ return character; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/parser/XPath.html100644 0 0 27213 11044113541 24570 0ustar 0 0 BNF for XPath.jj

BNF for XPath.jj

NON-TERMINALS

NCName ::= ( NCName_Without_CoreFunctions | <NODE> | <TEXT> | <COMMENT> | <PI> | <FUNCTION_LAST> | <FUNCTION_POSITION> | <FUNCTION_COUNT> | <FUNCTION_ID> | <FUNCTION_LOCAL_NAME> | <FUNCTION_NAMESPACE_URI> | <FUNCTION_NAME> | <FUNCTION_STRING> | <FUNCTION_CONCAT> | <FUNCTION_STARTS_WITH> | <FUNCTION_CONTAINS> | <FUNCTION_SUBSTRING_BEFORE> | <FUNCTION_SUBSTRING_AFTER> | <FUNCTION_SUBSTRING> | <FUNCTION_STRING_LENGTH> | <FUNCTION_NORMALIZE_SPACE> | <FUNCTION_TRANSLATE> | <FUNCTION_BOOLEAN> | <FUNCTION_NOT> | <FUNCTION_TRUE> | <FUNCTION_FALSE> | <FUNCTION_NULL> | <FUNCTION_LANG> | <FUNCTION_NUMBER> | <FUNCTION_SUM> | <FUNCTION_FLOOR> | <FUNCTION_CEILING> | <FUNCTION_ROUND> | <FUNCTION_KEY> | <FUNCTION_FORMAT_NUMBER> )
NCName_Without_CoreFunctions ::= ( <NCName> | <OR> | <AND> | <MOD> | <DIV> )
CoreFunctionName ::= ( <FUNCTION_LAST> | <FUNCTION_POSITION> | <FUNCTION_COUNT> | <FUNCTION_ID> | <FUNCTION_LOCAL_NAME> | <FUNCTION_NAMESPACE_URI> | <FUNCTION_NAME> | <FUNCTION_STRING> | <FUNCTION_CONCAT> | <FUNCTION_STARTS_WITH> | <FUNCTION_CONTAINS> | <FUNCTION_SUBSTRING_BEFORE> | <FUNCTION_SUBSTRING_AFTER> | <FUNCTION_SUBSTRING> | <FUNCTION_STRING_LENGTH> | <FUNCTION_NORMALIZE_SPACE> | <FUNCTION_TRANSLATE> | <FUNCTION_BOOLEAN> | <FUNCTION_NOT> | <FUNCTION_TRUE> | <FUNCTION_FALSE> | <FUNCTION_NULL> | <FUNCTION_LANG> | <FUNCTION_NUMBER> | <FUNCTION_SUM> | <FUNCTION_FLOOR> | <FUNCTION_CEILING> | <FUNCTION_ROUND> | <FUNCTION_KEY> | <FUNCTION_FORMAT_NUMBER> )
QName ::= NCName ( ":" NCName )?
QName_Without_CoreFunctions ::= ( NCName ":" NCName | NCName_Without_CoreFunctions )
parseExpression ::= Expression <EOF>
LocationPath ::= ( RelativeLocationPath | AbsoluteLocationPath )
AbsoluteLocationPath ::= ( ( LocationStep ( LocationStep )* ) | <SLASH> )
RelativeLocationPath ::= ( NodeTest ( LocationStep )* )
LocationStep ::= ( <SLASH> | <SLASHSLASH> ) NodeTest
NodeTest ::= ( ( AxisSpecifier ( NodeType "(" ")" | <PI> "(" <Literal> ")" | WildcardName ) | "." | ".." ) ( Predicate )* )
AxisSpecifier ::= ( AxisName | AbbreviatedAxisSpecifier )
AxisName ::= ( <AXIS_SELF> | <AXIS_CHILD> | <AXIS_PARENT> | <AXIS_ANCESTOR> | <AXIS_ATTRIBUTE> | <AXIS_NAMESPACE> | <AXIS_PRECEDING> | <AXIS_FOLLOWING> | <AXIS_DESCENDANT> | <AXIS_ANCESTOR_OR_SELF> | <AXIS_FOLLOWING_SIBLING> | <AXIS_PRECEDING_SIBLING> | <AXIS_DESCENDANT_OR_SELF> )
Predicate ::= "[" Expression "]"
AbbreviatedAxisSpecifier ::= ( "@" )?
Expression ::= OrExpr
PrimaryExpr ::= ( VariableReference | "(" Expression ")" | <Literal> | <Number> | CoreFunctionCall | FunctionCall )
FunctionCall ::= FunctionName ArgumentList
CoreFunctionCall ::= ( CoreFunctionName ) ArgumentList
ArgumentList ::= "(" ( Argument ( "," Argument )* )? ")"
Argument ::= Expression
UnionExpr ::= ( PathExpr ( <UNION> PathExpr )* )
PathExpr ::= ( FilterExpr | LocationPath )
FilterExpr ::= ( PrimaryExpr ( Predicate )* ( LocationStep )* )
OrExpr ::= ( AndExpr ( <OR> AndExpr )* )
AndExpr ::= ( EqualityExpr ( <AND> EqualityExpr )* )
EqualityExpr ::= ( RelationalExpr ( ( <EQ> RelationalExpr | <NEQ> RelationalExpr ) )* )
RelationalExpr ::= ( AdditiveExpr ( ( <LT> AdditiveExpr | <GT> AdditiveExpr | <LTE> AdditiveExpr | <GTE> AdditiveExpr ) )* )
AdditiveExpr ::= ( SubtractiveExpr ( ( <PLUS> SubtractiveExpr ) )* )
SubtractiveExpr ::= ( MultiplicativeExpr ( <MINUS> MultiplicativeExpr )* )
MultiplicativeExpr ::= ( UnaryExpr ( ( "*" UnaryExpr | <DIV> UnaryExpr | <MOD> UnaryExpr ) )* )
UnaryExpr ::= ( UnionExpr | <MINUS> UnaryExpr )
FunctionName ::= QName_Without_CoreFunctions
VariableReference ::= <VARIABLE> QName
WildcardName ::= ( ( "*" | NCName ) ( ":" ( "*" | NCName ) )? )
NodeType ::= ( <TEXT> | <NODE> | <COMMENT> | <PI> )
commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/parser/XPath.jj100644 0 0 104314 11044113541 24245 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* ---------------------------------------- JavaCC 1.1 Options -------------------------------------------*/ options { LOOKAHEAD = 1; // (default 1) CHOICE_AMBIGUITY_CHECK = 2; // (default 2) OTHER_AMBIGUITY_CHECK = 1; // (default 1) STATIC = false; // (default true) DEBUG_PARSER = false; // (default false) DEBUG_LOOKAHEAD = false; // (default false) DEBUG_TOKEN_MANAGER = false; // (default false) OPTIMIZE_TOKEN_MANAGER = true; // (default true) ERROR_REPORTING = true; // (default true) JAVA_UNICODE_ESCAPE = false; // (default false) UNICODE_INPUT = true; // (default false) IGNORE_CASE = false; // (default false) COMMON_TOKEN_ACTION = false; // (default false) USER_TOKEN_MANAGER = false; // (default false) USER_CHAR_STREAM = false; // (default false) BUILD_PARSER = true; // (default true) BUILD_TOKEN_MANAGER = true; // (default true) SANITY_CHECK = true; // (default true) FORCE_LA_CHECK = false; // (default false) CACHE_TOKENS = true; // (default false) } /*-------------------------------------------- Parser Class ---------------------------------------------*/ PARSER_BEGIN(XPathParser) package org.apache.commons.jxpath.ri.parser; import org.apache.commons.jxpath.ri.Compiler; import java.util.ArrayList; public class XPathParser { private Compiler compiler; public void setCompiler(Compiler compiler){ this.compiler = compiler; } private String unescape(String string){ int index = string.indexOf("'"); while (index != -1){ string = string.substring(0, index) + "\'" + string.substring(index + 6); index = string.indexOf("'"); } index = string.indexOf("""); while (index != -1){ string = string.substring(0, index) + "\"" + string.substring(index + 6); index = string.indexOf("""); } return string; } } PARSER_END(XPathParser) /*----------------------------*/ /* Skip Whitespace everywhere */ /*----------------------------*/ /* [39] ExprWhitespace ::= S */ SKIP : { " " | "\t" | "\n" | "\r" | "\f" } /*-----------------*/ /* Operator Tokens */ /*-----------------*/ TOKEN: { | | | | | | " > | =" > | } /*-----------------------------------------------*/ /* Unambigious Tokens (Number, Literal, Variable */ /*-----------------------------------------------*/ TOKEN: { /* [29] Literal ::= '"' [^"]* '"' | "'" [^']* "'" */ | /* [31] Digits ::= [0-9]+ */ <#Digit : ["0"-"9"] > | /* [30] Number ::= Digits ('.' Digits?)? | '.' Digits */ )+ ("." ( ()+ )? )? | "." ()+ > } /*-------------------------------*/ /* XML Names and Qualified Names */ /*-------------------------------*/ TOKEN: { <#Letter : | > | <#BaseChar : ( ["\u0041"-"\u005A"] | ["\u0061"-"\u007A"] | ["\u00C0"-"\u00D6"] | ["\u00D8"-"\u00F6"] | ["\u00F8"-"\u00FF"] | ["\u0100"-"\u0131"] | ["\u0134"-"\u013E"] | ["\u0141"-"\u0148"] | ["\u014A"-"\u017E"] | ["\u0180"-"\u01C3"] | ["\u01CD"-"\u01F0"] | ["\u01F4"-"\u01F5"] | ["\u01FA"-"\u0217"] | ["\u0250"-"\u02A8"] | ["\u02BB"-"\u02C1"] | "\u0386" | ["\u0388"-"\u038A"] | "\u038C" | ["\u038E"-"\u03A1"] | ["\u03A3"-"\u03CE"] | ["\u03D0"-"\u03D6"] | "\u03DA" | "\u03DC" | "\u03DE" | "\u03E0" | ["\u03E2"-"\u03F3"] | ["\u0401"-"\u040C"] | ["\u040E"-"\u044F"] | ["\u0451"-"\u045C"] | ["\u045E"-"\u0481"] | ["\u0490"-"\u04C4"] | ["\u04C7"-"\u04C8"] | ["\u04CB"-"\u04CC"] | ["\u04D0"-"\u04EB"] | ["\u04EE"-"\u04F5"] | ["\u04F8"-"\u04F9"] | ["\u0531"-"\u0556"] | "\u0559" | ["\u0561"-"\u0586"] | ["\u05D0"-"\u05EA"] | ["\u05F0"-"\u05F2"] | ["\u0621"-"\u063A"] | ["\u0641"-"\u064A"] | ["\u0671"-"\u06B7"] | ["\u06BA"-"\u06BE"] | ["\u06C0"-"\u06CE"] | ["\u06D0"-"\u06D3"] | "\u06D5" | ["\u06E5"-"\u06E6"] | ["\u0905"-"\u0939"] | "\u093D" | ["\u0958"-"\u0961"] | ["\u0985"-"\u098C"] | ["\u098F"-"\u0990"] | ["\u0993"-"\u09A8"] | ["\u09AA"-"\u09B0"] | "\u09B2" | ["\u09B6"-"\u09B9"] | ["\u09DC"-"\u09DD"] | ["\u09DF"-"\u09E1"] | ["\u09F0"-"\u09F1"] | ["\u0A05"-"\u0A0A"] | ["\u0A0F"-"\u0A10"] | ["\u0A13"-"\u0A28"] | ["\u0A2A"-"\u0A30"] | ["\u0A32"-"\u0A33"] | ["\u0A35"-"\u0A36"] | ["\u0A38"-"\u0A39"] | ["\u0A59"-"\u0A5C"] | "\u0A5E" | ["\u0A72"-"\u0A74"] | ["\u0A85"-"\u0A8B"] | "\u0A8D" | ["\u0A8F"-"\u0A91"] | ["\u0A93"-"\u0AA8"] | ["\u0AAA"-"\u0AB0"] | ["\u0AB2"-"\u0AB3"] | ["\u0AB5"-"\u0AB9"] | "\u0ABD" | "\u0AE0" | ["\u0B05"-"\u0B0C"] | ["\u0B0F"-"\u0B10"] | ["\u0B13"-"\u0B28"] | ["\u0B2A"-"\u0B30"] | ["\u0B32"-"\u0B33"] | ["\u0B36"-"\u0B39"] | "\u0B3D" | ["\u0B5C"-"\u0B5D"] | ["\u0B5F"-"\u0B61"] | ["\u0B85"-"\u0B8A"] | ["\u0B8E"-"\u0B90"] | ["\u0B92"-"\u0B95"] | ["\u0B99"-"\u0B9A"] | "\u0B9C" | ["\u0B9E"-"\u0B9F"] | ["\u0BA3"-"\u0BA4"] | ["\u0BA8"-"\u0BAA"] | ["\u0BAE"-"\u0BB5"] | ["\u0BB7"-"\u0BB9"] | ["\u0C05"-"\u0C0C"] | ["\u0C0E"-"\u0C10"] | ["\u0C12"-"\u0C28"] | ["\u0C2A"-"\u0C33"] | ["\u0C35"-"\u0C39"] | ["\u0C60"-"\u0C61"] | ["\u0C85"-"\u0C8C"] | ["\u0C8E"-"\u0C90"] | ["\u0C92"-"\u0CA8"] | ["\u0CAA"-"\u0CB3"] | ["\u0CB5"-"\u0CB9"] | "\u0CDE" | ["\u0CE0"-"\u0CE1"] | ["\u0D05"-"\u0D0C"] | ["\u0D0E"-"\u0D10"] | ["\u0D12"-"\u0D28"] | ["\u0D2A"-"\u0D39"] | ["\u0D60"-"\u0D61"] | ["\u0E01"-"\u0E2E"] | "\u0E30" | ["\u0E32"-"\u0E33"] | ["\u0E40"-"\u0E45"] | ["\u0E81"-"\u0E82"] | "\u0E84" | ["\u0E87"-"\u0E88"] | "\u0E8A" | "\u0E8D" | ["\u0E94"-"\u0E97"] | ["\u0E99"-"\u0E9F"] | ["\u0EA1"-"\u0EA3"] | "\u0EA5" | "\u0EA7" | ["\u0EAA"-"\u0EAB"] | ["\u0EAD"-"\u0EAE"] | "\u0EB0" | ["\u0EB2"-"\u0EB3"] | "\u0EBD" | ["\u0EC0"-"\u0EC4"] | ["\u0F40"-"\u0F47"] | ["\u0F49"-"\u0F69"] | ["\u10A0"-"\u10C5"] | ["\u10D0"-"\u10F6"] | "\u1100" | ["\u1102"-"\u1103"] | ["\u1105"-"\u1107"] | "\u1109" | ["\u110B"-"\u110C"] | ["\u110E"-"\u1112"] | "\u113C" | "\u113E" | "\u1140" | "\u114C" | "\u114E" | "\u1150" | ["\u1154"-"\u1155"] | "\u1159" | ["\u115F"-"\u1161"] | "\u1163" | "\u1165" | "\u1167" | "\u1169" | ["\u116D"-"\u116E"] | ["\u1172"-"\u1173"] | "\u1175" | "\u119E" | "\u11A8" | "\u11AB" | ["\u11AE"-"\u11AF"] | ["\u11B7"-"\u11B8"] | "\u11BA" | ["\u11BC"-"\u11C2"] | "\u11EB" | "\u11F0" | "\u11F9" | ["\u1E00"-"\u1E9B"] | ["\u1EA0"-"\u1EF9"] | ["\u1F00"-"\u1F15"] | ["\u1F18"-"\u1F1D"] | ["\u1F20"-"\u1F45"] | ["\u1F48"-"\u1F4D"] | ["\u1F50"-"\u1F57"] | "\u1F59" | "\u1F5B" | "\u1F5D" | ["\u1F5F"-"\u1F7D"] | ["\u1F80"-"\u1FB4"] | ["\u1FB6"-"\u1FBC"] | "\u1FBE" | ["\u1FC2"-"\u1FC4"] | ["\u1FC6"-"\u1FCC"] | ["\u1FD0"-"\u1FD3"] | ["\u1FD6"-"\u1FDB"] | ["\u1FE0"-"\u1FEC"] | ["\u1FF2"-"\u1FF4"] | ["\u1FF6"-"\u1FFC"] | "\u2126" | ["\u212A"-"\u212B"] | "\u212E" | ["\u2180"-"\u2182"] | ["\u3041"-"\u3094"] | ["\u30A1"-"\u30FA"] | ["\u3105"-"\u312C"] | ["\uAC00"-"\uD7A3"] ) > | <#Ideographic : (["\u4E00"-"\u9FA5"] | "\u3007" | ["\u3021"-"\u3029"]) > | <#CombiningChar : ( ["\u0300"-"\u0345"] | ["\u0360"-"\u0361"] | ["\u0483"-"\u0486"] | ["\u0591"-"\u05A1"] | ["\u05A3"-"\u05B9"] | ["\u05BB"-"\u05BD"] | "\u05BF" | ["\u05C1"-"\u05C2"] | "\u05C4" | ["\u064B"-"\u0652"] | "\u0670" | ["\u06D6"-"\u06DC"] | ["\u06DD"-"\u06DF"] | ["\u06E0"-"\u06E4"] | ["\u06E7"-"\u06E8"] | ["\u06EA"-"\u06ED"] | ["\u0901"-"\u0903"] | "\u093C" |["\u093E"-"\u094C"] | "\u094D" | ["\u0951"-"\u0954"] | ["\u0962"-"\u0963"] | ["\u0981"-"\u0983"] | "\u09BC" | "\u09BE" | "\u09BF" | ["\u09C0"-"\u09C4"] | ["\u09C7"-"\u09C8"] | ["\u09CB"-"\u09CD"] | "\u09D7" | ["\u09E2"-"\u09E3"] | "\u0A02" | "\u0A3C" | "\u0A3E" | "\u0A3F" | ["\u0A40"-"\u0A42"] | ["\u0A47"-"\u0A48"] | ["\u0A4B"-"\u0A4D"] | ["\u0A70"-"\u0A71"] | ["\u0A81"-"\u0A83"] | "\u0ABC" | ["\u0ABE"-"\u0AC5"] | ["\u0AC7"-"\u0AC9"] | ["\u0ACB"-"\u0ACD"] | ["\u0B01"-"\u0B03"] | "\u0B3C" | ["\u0B3E"-"\u0B43"] | ["\u0B47"-"\u0B48"] | ["\u0B4B"-"\u0B4D"] | ["\u0B56"-"\u0B57"] | ["\u0B82"-"\u0B83"] | ["\u0BBE"-"\u0BC2"] | ["\u0BC6"-"\u0BC8"] | ["\u0BCA"-"\u0BCD"] | "\u0BD7" | ["\u0C01"-"\u0C03"] | ["\u0C3E"-"\u0C44"] | ["\u0C46"-"\u0C48"] | ["\u0C4A"-"\u0C4D"] | ["\u0C55"-"\u0C56"] | ["\u0C82"-"\u0C83"] | ["\u0CBE"-"\u0CC4"] | ["\u0CC6"-"\u0CC8"] | ["\u0CCA"-"\u0CCD"] | ["\u0CD5"-"\u0CD6"] | ["\u0D02"-"\u0D03"] | ["\u0D3E"-"\u0D43"] | ["\u0D46"-"\u0D48"] | ["\u0D4A"-"\u0D4D"] | "\u0D57" | "\u0E31" | ["\u0E34"-"\u0E3A"] | ["\u0E47"-"\u0E4E"] | "\u0EB1" | ["\u0EB4"-"\u0EB9"] | ["\u0EBB"-"\u0EBC"] | ["\u0EC8"-"\u0ECD"] | ["\u0F18"-"\u0F19"] | "\u0F35" | "\u0F37" | "\u0F39" | "\u0F3E" | "\u0F3F" | ["\u0F71"-"\u0F84"] | ["\u0F86"-"\u0F8B"] | ["\u0F90"-"\u0F95"] | "\u0F97" | ["\u0F99"-"\u0FAD"] | ["\u0FB1"-"\u0FB7"] | "\u0FB9" | ["\u20D0"-"\u20DC"] | "\u20E1" | ["\u302A"-"\u302F"] | "\u3099" | "\u309A" ) > | <#UnicodeDigit : ["\u0030"-"\u0039"] | ["\u0660"-"\u0669"] | ["\u06F0"-"\u06F9"] | ["\u0966"-"\u096F"] | ["\u09E6"-"\u09EF"] | ["\u0A66"-"\u0A6F"] | ["\u0AE6"-"\u0AEF"] | ["\u0B66"-"\u0B6F"] | ["\u0BE7"-"\u0BEF"] | ["\u0C66"-"\u0C6F"] | ["\u0CE6"-"\u0CEF"] | ["\u0D66"-"\u0D6F"] | ["\u0E50"-"\u0E59"] | ["\u0ED0"-"\u0ED9"] | ["\u0F20"-"\u0F29"] > | <#Extender : "\u00B7" | "\u02D0" | "\u02D1" | "\u0387" | "\u0640" | "\u0E46" | "\u0EC6" | "\u3005" | ["\u3031"-"\u3035"] | ["\u309D"-"\u309E"] | ["\u30FC"-"\u30FE"] > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ["_"]) ( | | [".","-","_"] | | )* > } // Note: XPath does not have reserved words, so we have to include all these terminals String NCName() : {} { ( NCName_Without_CoreFunctions() | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ) { return token.image; } } String NCName_Without_CoreFunctions() : {} { ( | | | |
) { return token.image; } } int CoreFunctionName() : { int code; } { ( { code = Compiler.FUNCTION_LAST; } | { code = Compiler.FUNCTION_POSITION; } | { code = Compiler.FUNCTION_COUNT; } | { code = Compiler.FUNCTION_ID; } | { code = Compiler.FUNCTION_LOCAL_NAME; } | { code = Compiler.FUNCTION_NAMESPACE_URI; } | { code = Compiler.FUNCTION_NAME; } | { code = Compiler.FUNCTION_STRING; } | { code = Compiler.FUNCTION_CONCAT; } | { code = Compiler.FUNCTION_STARTS_WITH; } | { code = Compiler.FUNCTION_CONTAINS; } | { code = Compiler.FUNCTION_SUBSTRING_BEFORE; } | { code = Compiler.FUNCTION_SUBSTRING_AFTER; } | { code = Compiler.FUNCTION_SUBSTRING; } | { code = Compiler.FUNCTION_STRING_LENGTH; } | { code = Compiler.FUNCTION_NORMALIZE_SPACE; } | { code = Compiler.FUNCTION_TRANSLATE; } | { code = Compiler.FUNCTION_BOOLEAN; } | { code = Compiler.FUNCTION_NOT; } | { code = Compiler.FUNCTION_TRUE; } | { code = Compiler.FUNCTION_FALSE; } | { code = Compiler.FUNCTION_NULL; } | { code = Compiler.FUNCTION_LANG; } | { code = Compiler.FUNCTION_NUMBER; } | { code = Compiler.FUNCTION_SUM; } | { code = Compiler.FUNCTION_FLOOR; } | { code = Compiler.FUNCTION_CEILING; } | { code = Compiler.FUNCTION_ROUND; } | { code = Compiler.FUNCTION_KEY; } | { code = Compiler.FUNCTION_FORMAT_NUMBER; } ) { return code; } } Object QName() : {String nc1, nc2 = null;} { nc1 = NCName() ( ":" nc2 = NCName() )? { if (nc2 == null){ return compiler.qname(null, nc1); } else { return compiler.qname(nc1, nc2); } } } Object QName_Without_CoreFunctions() : { String nc1, nc2 = null; } { ( LOOKAHEAD(NCName() ":") nc1 = NCName() ":" nc2 = NCName() | nc1 = NCName_Without_CoreFunctions() ) { if (nc2 == null){ return compiler.qname(null, nc1); } else { return compiler.qname(nc1, nc2); } } } Object parseExpression() : { Object ex; } { ex = Expression() { return ex; } } /* ################################################################################### */ /* XSLT Patterns (http://www.w3.org/1999/08/WD-xslt-19990813) */ /* ################################################################################### */ /* [XSLT1] Pattern ::= LocationPathPattern | Pattern '|' LocationPathPattern */ //void Pattern() : //{} //{ // LocationPathPattern() ( LocationPathPattern() )* //} // // ///* [XSLT2] LocationPathPattern ::= // '/' RelativePathPattern? | IdKeyPattern (('/' | '//' RelativePathPattern)? | '//'? RelativePathPattern //*/ // //void LocationPathPattern() : //{} //{ // ( RelativePathPattern() )? // | ( // LOOKAHEAD(IdKeyPattern()) // IdKeyPattern() ( ( | ) RelativePathPattern() )? // | ( )? RelativePathPattern() // ) //} // // // ///* [XSLT3] IdKeyPattern ::= 'id' '(' Literal ')' | 'key' '(' Literal ',' Literal ')' */ // //void IdKeyPattern() : //{} //{ // "(" ")" // | "(" "," ")" //} // // ///* [XSLT4] RelativePathPattern ::= StepPattern | RelativePathPattern '/' StepPattern // | RelativePathPattern '//' StepPattern //*/ //void RelativePathPattern() : //{} //{ // StepPattern() ( ( | ) StepPattern() )* //} // // ///* [XSLT5] StepPattern ::= AbbreviatedAxisSpecifier NodeTest Predicate* */ //void StepPattern() : //{} //{ // AbbreviatedAxisSpecifier() NodeTest() (Predicate())* //} // See XPath Syntax (http://www.w3.org/TR/xpath ) //void XPath() : //{} //{ // LocationPath() // //} /* [1] LocationPath ::= RelativeLocationPath | AbsoluteLocationPath */ Object LocationPath() : {Object ex = null;} { ( ex = RelativeLocationPath() | ex = AbsoluteLocationPath() ) { return ex; } } /* [2] AbsoluteLocationPath ::= '/' RelativeLocationPath? | AbbreviatedAbsoluteLocationPath */ /* [10] AbbreviatedAbsoluteLocationPath ::= '//' RelativeLocationPath */ Object AbsoluteLocationPath() : { ArrayList steps = new ArrayList(); } { ( LOOKAHEAD(LocationStep(steps)) (LocationStep(steps) ( LocationStep(steps) )* ) | ) { return compiler.locationPath(true, steps.toArray()); } } /* [3] RelativeLocationPath ::= Step | RelativeLocationPath '/' Step | AbbreviatedRelativeLocationPath */ Object RelativeLocationPath() : { ArrayList steps = new ArrayList(); } { ( NodeTest(steps) ( LocationStep(steps) )* ) { return compiler.locationPath(false, steps.toArray()); } } /* [3] RelativeLocationPath ::= Step | RelativeLocationPath '/' Step | AbbreviatedRelativeLocationPath */ /* [11] AbbreviatedRelativeLocationPath ::= RelativeLocationPath '//' Step */ /*--------------------*/ /* 2.1 Location Steps */ /*--------------------*/ /* [4] Step ::= AxisSpecifier NodeTest Predicate* | AbbreviatedStep */ void LocationStep(ArrayList steps) : { Object t; Object s; } { ( | { // Abbreviated step: descendant-or-self::node() t = compiler.nodeTypeTest(Compiler.NODE_TYPE_NODE); steps.add(compiler.step(Compiler.AXIS_DESCENDANT_OR_SELF, t, null)); } ) NodeTest(steps) } /* [7] NodeTest ::= WildcardName | NodeType '(' ')' | 'processing-instruction' '(' Literal ')' */ void NodeTest(ArrayList steps) : { int axis; int type = -1; String instruction = null; Object name = null; Object s; Object p; ArrayList ps = new ArrayList(); } { ( ( axis = AxisSpecifier() ( LOOKAHEAD(NodeType() "(" ")") type = NodeType() "(" ")" | LOOKAHEAD() "(" { instruction = unescape(token.image.substring(1, token.image.length() - 1)); } ")" | name = WildcardName() ) | "." { axis = Compiler.AXIS_SELF; type = Compiler.NODE_TYPE_NODE; } | ".." { axis = Compiler.AXIS_PARENT; type = Compiler.NODE_TYPE_NODE; } ) ( p = Predicate() { ps.add(p); } )* ) { if (name != null){ s = compiler.nodeNameTest(name); } else if (instruction != null){ s = compiler.processingInstructionTest(instruction); } else { s = compiler.nodeTypeTest(type); } steps.add(compiler.step(axis, s, ps.toArray())); } } /* [5] AxisSpecifier ::= AxisName '::' | AbbreviatedAxisSpecifier */ int AxisSpecifier() : { int axis; } { ( axis = AxisName() | axis = AbbreviatedAxisSpecifier() ) { return axis; } } /*----------*/ /* 2.2 Axes */ /*----------*/ /* [6] AxisName ::= 'ancestor' | 'ancestor-or-self' | 'attribute' | 'child' | 'descendant' | 'descendant-or-self' | 'following' | 'following-sibling' | 'namespace' | 'parent' | 'preceding' | 'preceding-sibling' | 'self' */ int AxisName() : { int axis = 0; } { ( { axis = Compiler.AXIS_SELF; } | { axis = Compiler.AXIS_CHILD; } | { axis = Compiler.AXIS_PARENT; } | { axis = Compiler.AXIS_ANCESTOR; } | { axis = Compiler.AXIS_ATTRIBUTE; } | { axis = Compiler.AXIS_NAMESPACE; } | { axis = Compiler.AXIS_PRECEDING; } | { axis = Compiler.AXIS_FOLLOWING; } | { axis = Compiler.AXIS_DESCENDANT; } | { axis = Compiler.AXIS_ANCESTOR_OR_SELF; } | { axis = Compiler.AXIS_FOLLOWING_SIBLING; } | { axis = Compiler.AXIS_PRECEDING_SIBLING; } | { axis = Compiler.AXIS_DESCENDANT_OR_SELF; } ) { return axis; } } /*----------------*/ /* 2.3 Node Tests */ /*----------------*/ /*----------------*/ /* 2.4 Predicates */ /*----------------*/ /* [8] Predicate ::= '[' PredicateExpr ']' */ /* [9] PredicateExpr ::= Expr */ Object Predicate() : { Object ex; } { "[" ex = Expression() "]" { return ex; } } /* [12] AbbreviatedStep ::= '.' | '..' */ /* [13] AbbreviatedAxisSpecifier ::= '@'? */ int AbbreviatedAxisSpecifier() : { int axis = Compiler.AXIS_CHILD; } { ( "@" {axis = Compiler.AXIS_ATTRIBUTE; } )? { return axis; } } /*---------------*/ /* 3 Expressions */ /*---------------*/ /*------------*/ /* 3.1 Basics */ /*------------*/ /* The effect of the grammar is that the order of precedence is (lowest precedence first): or and =, != <=, <, >=, > and all operators are left associative. For example, 3 > 2 > 1 is equivalent to (3 > 2) > 1, which evaluates to false. */ /* [14] Expr ::= OrExpr */ Object Expression() : {Object ex;} { ex = OrExpr() { return ex; } } /* [15] PrimaryExpr ::= VariableReference | '(' Expr ')' | Literal | Number | FunctionCall */ Object PrimaryExpr() : { Object ex = null; } { ( ex = VariableReference() | "(" ex = Expression() ")" | { ex = compiler.literal(unescape(token.image.substring(1, token.image.length() - 1))); } | { ex = compiler.number(token.image); } | LOOKAHEAD(CoreFunctionName() "(") ex = CoreFunctionCall() | ex = FunctionCall() ) { return ex; } } /*--------------------*/ /* 3.2 Function Calls */ /*--------------------*/ /* [16] FunctionCall ::= FunctionName '(' ( Argument ( ',' Argument)*)? ')' */ Object FunctionCall() : { Object name; ArrayList args; } { name = FunctionName() args = ArgumentList() { if (args == null){ return compiler.function(name, null); } else { return compiler.function(name, args.toArray()); } } } Object CoreFunctionCall() : { int code = 0; ArrayList args; } { ( code = CoreFunctionName() ) args = ArgumentList() { if (args == null){ return compiler.function(code, null); } else { return compiler.function(code, args.toArray()); } } } ArrayList ArgumentList() : { ArrayList args = null; Object arg; } { "(" ( arg = Argument() { args = new ArrayList(); args.add(arg); } ( "," arg = Argument() { args.add(arg); } )* )? ")" { return args; } } /* [17] Argument ::= Expr */ Object Argument() : { Object ex; } { ex = Expression() { return ex; } } /*---------------*/ /* 3.3 Node-sets */ /*---------------*/ /* [18] UnionExpr ::= PathExpr | UnionExpr '|' PathExpr */ Object UnionExpr() : { Object ex, r; ArrayList list = null; } { ( ex = PathExpr() ( r = PathExpr() { if (list == null){ list = new ArrayList(); list.add(ex); } list.add(r); } )* ) { if (list != null){ ex = compiler.union(list.toArray()); } return ex; } } /* [19] PathExpr ::= LocationPath | FilterExpr | FilterExpr '/' RelativeLocationPath | FilterExpr '//' RelativeLocationPath */ Object PathExpr() : { Object ex = null; Object[] steps; } { ( // Reason for LOOKAHEAD: // foo:bar() - filter path // foo:bar - location path LOOKAHEAD(PrimaryExpr()) ex = FilterExpr() | ex = LocationPath() ) { return ex; } } /* [20] FilterExpr ::= PrimaryExpr | FilterExpr Predicate */ Object FilterExpr() : { Object ex, p; ArrayList ps = new ArrayList(); boolean path = false; ArrayList steps = new ArrayList(); } { ( ex = PrimaryExpr() ( p = Predicate() { path = true; ps.add(p); } )* ( LocationStep(steps) { path = true; } )* ) { if (path){ return compiler.expressionPath(ex, ps.toArray(), steps.toArray()); } else { return ex; } } } /*--------------*/ /* 3.4 Booleans */ /*--------------*/ /* [21] OrExpr ::= AndExpr | OrExpr 'or' AndExpr */ Object OrExpr() : { Object ex, r; ArrayList list = null; } { ( ex = AndExpr() ( r = AndExpr() { if (list == null){ list = new ArrayList(); list.add(ex); } list.add(r); } )* ) { if (list != null){ ex = compiler.or(list.toArray()); } return ex; } } /* [22] AndExpr ::= EqualityExpr | AndExpr 'and' EqualityExpr */ Object AndExpr() : { Object ex, r; ArrayList list = null; } { ( ex = EqualityExpr() ( r = EqualityExpr() { if (list == null){ list = new ArrayList(); list.add(ex); } list.add(r); } )* ) { if (list != null){ ex = compiler.and(list.toArray()); } return ex; } } /* [23] EqualityExpr ::= RelationalExpr | EqualityExpr '=' RelationalExpr | EqualityExpr '!=' RelationalExpr */ Object EqualityExpr() : {Object ex, r;} { ( ex = RelationalExpr() (( r = RelationalExpr() { ex = compiler.equal(ex, r); } | r = RelationalExpr() { ex = compiler.notEqual(ex, r); } ))* ) { return ex; } } /* [24] RelationalExpr ::= AdditiveExpr | RelationalExpr '<' AdditiveExpr | RelationalExpr '>' AdditiveExpr | RelationalExpr '<=' AdditiveExpr | RelationalExpr '>=' AdditiveExpr */ Object RelationalExpr() : {Object ex, r;} { ( ex = AdditiveExpr() (( r = AdditiveExpr() { ex = compiler.lessThan(ex, r); } | r = AdditiveExpr() { ex = compiler.greaterThan(ex, r); } | r = AdditiveExpr() { ex = compiler.lessThanOrEqual(ex, r); } | r = AdditiveExpr() { ex = compiler.greaterThanOrEqual(ex, r); } ))* ) { return ex; } } /*-------------*/ /* 3.5 Numbers */ /*-------------*/ /* [25] AdditiveExpr ::= MultiplicativeExpr | AdditiveExpr '+' MultiplicativeExpr | AdditiveExpr '-' MultiplicativeExpr */ Object AdditiveExpr() : { Object ex, r; ArrayList list = null; } { ( ex = SubtractiveExpr() (( r = SubtractiveExpr() { if (list == null){ list = new ArrayList(); list.add(ex); } list.add(r); } ))* ) { if (list != null){ ex = compiler.sum(list.toArray()); } return ex; } } Object SubtractiveExpr() : { Object ex, r = null; } { ( ex = MultiplicativeExpr() ( r = MultiplicativeExpr() { ex = compiler.minus(ex, r); } )* ) { return ex; } } /* [26] MultiplicativeExpr ::= UnaryExpr | MultiplicativeExpr MultiplyOperator UnaryExpr | MultiplicativeExpr 'div' UnaryExpr | MultiplicativeExpr 'mod' UnaryExpr */ Object MultiplicativeExpr() : { Object ex, r; } { ( ex = UnaryExpr() ( ( "*" r = UnaryExpr() { ex = compiler.multiply(ex, r); } |
r = UnaryExpr() { ex = compiler.divide(ex, r); } | r = UnaryExpr() { ex = compiler.mod(ex, r); } ) )* ) { return ex; } } /* [27] UnaryExpr ::= UnionExpr | '-' UnaryExpr */ Object UnaryExpr() : { Object ex; } { ( ex = UnionExpr() | ex = UnaryExpr() { ex = compiler.minus(ex);} ) { return ex; } } /*-------------*/ /* 3.6 Strings */ /*-------------*/ /*----------------------------------*/ /* 3.7 Expression Lexical Structure */ /*----------------------------------*/ /* The following special tokenization rules must be applied in the order specified to disambiguate the grammar: 1. If there is a preceding token and the preceding token is not one of @, ::, (, [, , or an Operator, then a * must be recognized as a MultiplyOperator and an NCName must be recognized as an OperatorName. 2. If the character following an NCName (possibly after intervening ExprWhitespace) is (, then the token must be recognized as a NodeType or a FunctionName. 3. If the two characters following an NCName (possibly after intervening ExprWhitespace) are ::, then the token must be recognized as an AxisName. 4. Otherwise, the token must not be recognized as a MultiplyOperator, an OperatorName, a NodeType, a FunctionName, or an AxisName. */ /* [28] ExprToken ::= '(' | ')' | '[' | ']' | '.' | '..' | '@' | ',' | '::' | WildcardName | NodeType | Operator | FunctionName | AxisName | Literal | Number | VariableReference */ /* [34] MultiplyOperator ::= '*' */ /* [35] FunctionName ::= QName - NodeType */ Object FunctionName() : { Object qname; } { qname = QName_Without_CoreFunctions() { return qname; } } /* [36] VariableReference ::= '$' QName */ Object VariableReference() : { Object ex; } { ex = QName() { return compiler.variableReference(ex); } } /* [37] WildcardName ::= '*' | NCName ':' '*' | QName */ Object WildcardName() : { Object qn; String nc1, nc2 = null; } { ( ("*" | NCName()) { nc1 = token.image; } (":" ("*" | NCName()) {nc2 = token.image;} )? ) { if (nc2 != null){ qn = compiler.qname(nc1, nc2); } else { qn = compiler.qname(null, nc1); } return qn; } } /* [38] NodeType ::= 'comment' | 'text' | 'processing-instruction' | 'node' */ int NodeType() : { int type; } { ( { type = Compiler.NODE_TYPE_TEXT; } | { type = Compiler.NODE_TYPE_NODE; } | { type = Compiler.NODE_TYPE_COMMENT; } | { type = Compiler.NODE_TYPE_PI; } ) { return type; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/parser/XPathParser.java100644 0 0 330300 11044113541 25734 0ustar 0 0 /* Generated By:JavaCC: Do not edit this line. XPathParser.java */ package org.apache.commons.jxpath.ri.parser; import org.apache.commons.jxpath.ri.Compiler; import java.util.ArrayList; public class XPathParser implements XPathParserConstants { private Compiler compiler; public void setCompiler(Compiler compiler){ this.compiler = compiler; } private String unescape(String string){ int index = string.indexOf("'"); while (index != -1){ string = string.substring(0, index) + "\'" + string.substring(index + 6); index = string.indexOf("'"); } index = string.indexOf("""); while (index != -1){ string = string.substring(0, index) + "\"" + string.substring(index + 6); index = string.indexOf("""); } return string; } // Note: XPath does not have reserved words, so we have to include all these terminals final public String NCName() throws ParseException { switch (jj_nt.kind) { case OR: case AND: case MOD: case DIV: case NCName: NCName_Without_CoreFunctions(); break; case NODE: jj_consume_token(NODE); break; case TEXT: jj_consume_token(TEXT); break; case COMMENT: jj_consume_token(COMMENT); break; case PI: jj_consume_token(PI); break; case FUNCTION_LAST: jj_consume_token(FUNCTION_LAST); break; case FUNCTION_POSITION: jj_consume_token(FUNCTION_POSITION); break; case FUNCTION_COUNT: jj_consume_token(FUNCTION_COUNT); break; case FUNCTION_ID: jj_consume_token(FUNCTION_ID); break; case FUNCTION_LOCAL_NAME: jj_consume_token(FUNCTION_LOCAL_NAME); break; case FUNCTION_NAMESPACE_URI: jj_consume_token(FUNCTION_NAMESPACE_URI); break; case FUNCTION_NAME: jj_consume_token(FUNCTION_NAME); break; case FUNCTION_STRING: jj_consume_token(FUNCTION_STRING); break; case FUNCTION_CONCAT: jj_consume_token(FUNCTION_CONCAT); break; case FUNCTION_STARTS_WITH: jj_consume_token(FUNCTION_STARTS_WITH); break; case FUNCTION_CONTAINS: jj_consume_token(FUNCTION_CONTAINS); break; case FUNCTION_SUBSTRING_BEFORE: jj_consume_token(FUNCTION_SUBSTRING_BEFORE); break; case FUNCTION_SUBSTRING_AFTER: jj_consume_token(FUNCTION_SUBSTRING_AFTER); break; case FUNCTION_SUBSTRING: jj_consume_token(FUNCTION_SUBSTRING); break; case FUNCTION_STRING_LENGTH: jj_consume_token(FUNCTION_STRING_LENGTH); break; case FUNCTION_NORMALIZE_SPACE: jj_consume_token(FUNCTION_NORMALIZE_SPACE); break; case FUNCTION_TRANSLATE: jj_consume_token(FUNCTION_TRANSLATE); break; case FUNCTION_BOOLEAN: jj_consume_token(FUNCTION_BOOLEAN); break; case FUNCTION_NOT: jj_consume_token(FUNCTION_NOT); break; case FUNCTION_TRUE: jj_consume_token(FUNCTION_TRUE); break; case FUNCTION_FALSE: jj_consume_token(FUNCTION_FALSE); break; case FUNCTION_NULL: jj_consume_token(FUNCTION_NULL); break; case FUNCTION_LANG: jj_consume_token(FUNCTION_LANG); break; case FUNCTION_NUMBER: jj_consume_token(FUNCTION_NUMBER); break; case FUNCTION_SUM: jj_consume_token(FUNCTION_SUM); break; case FUNCTION_FLOOR: jj_consume_token(FUNCTION_FLOOR); break; case FUNCTION_CEILING: jj_consume_token(FUNCTION_CEILING); break; case FUNCTION_ROUND: jj_consume_token(FUNCTION_ROUND); break; case FUNCTION_KEY: jj_consume_token(FUNCTION_KEY); break; case FUNCTION_FORMAT_NUMBER: jj_consume_token(FUNCTION_FORMAT_NUMBER); break; default: jj_la1[0] = jj_gen; jj_consume_token(-1); throw new ParseException(); } {if (true) return token.image;} throw new Error("Missing return statement in function"); } final public String NCName_Without_CoreFunctions() throws ParseException { switch (jj_nt.kind) { case NCName: jj_consume_token(NCName); break; case OR: jj_consume_token(OR); break; case AND: jj_consume_token(AND); break; case MOD: jj_consume_token(MOD); break; case DIV: jj_consume_token(DIV); break; default: jj_la1[1] = jj_gen; jj_consume_token(-1); throw new ParseException(); } {if (true) return token.image;} throw new Error("Missing return statement in function"); } final public int CoreFunctionName() throws ParseException { int code; switch (jj_nt.kind) { case FUNCTION_LAST: jj_consume_token(FUNCTION_LAST); code = Compiler.FUNCTION_LAST; break; case FUNCTION_POSITION: jj_consume_token(FUNCTION_POSITION); code = Compiler.FUNCTION_POSITION; break; case FUNCTION_COUNT: jj_consume_token(FUNCTION_COUNT); code = Compiler.FUNCTION_COUNT; break; case FUNCTION_ID: jj_consume_token(FUNCTION_ID); code = Compiler.FUNCTION_ID; break; case FUNCTION_LOCAL_NAME: jj_consume_token(FUNCTION_LOCAL_NAME); code = Compiler.FUNCTION_LOCAL_NAME; break; case FUNCTION_NAMESPACE_URI: jj_consume_token(FUNCTION_NAMESPACE_URI); code = Compiler.FUNCTION_NAMESPACE_URI; break; case FUNCTION_NAME: jj_consume_token(FUNCTION_NAME); code = Compiler.FUNCTION_NAME; break; case FUNCTION_STRING: jj_consume_token(FUNCTION_STRING); code = Compiler.FUNCTION_STRING; break; case FUNCTION_CONCAT: jj_consume_token(FUNCTION_CONCAT); code = Compiler.FUNCTION_CONCAT; break; case FUNCTION_STARTS_WITH: jj_consume_token(FUNCTION_STARTS_WITH); code = Compiler.FUNCTION_STARTS_WITH; break; case FUNCTION_CONTAINS: jj_consume_token(FUNCTION_CONTAINS); code = Compiler.FUNCTION_CONTAINS; break; case FUNCTION_SUBSTRING_BEFORE: jj_consume_token(FUNCTION_SUBSTRING_BEFORE); code = Compiler.FUNCTION_SUBSTRING_BEFORE; break; case FUNCTION_SUBSTRING_AFTER: jj_consume_token(FUNCTION_SUBSTRING_AFTER); code = Compiler.FUNCTION_SUBSTRING_AFTER; break; case FUNCTION_SUBSTRING: jj_consume_token(FUNCTION_SUBSTRING); code = Compiler.FUNCTION_SUBSTRING; break; case FUNCTION_STRING_LENGTH: jj_consume_token(FUNCTION_STRING_LENGTH); code = Compiler.FUNCTION_STRING_LENGTH; break; case FUNCTION_NORMALIZE_SPACE: jj_consume_token(FUNCTION_NORMALIZE_SPACE); code = Compiler.FUNCTION_NORMALIZE_SPACE; break; case FUNCTION_TRANSLATE: jj_consume_token(FUNCTION_TRANSLATE); code = Compiler.FUNCTION_TRANSLATE; break; case FUNCTION_BOOLEAN: jj_consume_token(FUNCTION_BOOLEAN); code = Compiler.FUNCTION_BOOLEAN; break; case FUNCTION_NOT: jj_consume_token(FUNCTION_NOT); code = Compiler.FUNCTION_NOT; break; case FUNCTION_TRUE: jj_consume_token(FUNCTION_TRUE); code = Compiler.FUNCTION_TRUE; break; case FUNCTION_FALSE: jj_consume_token(FUNCTION_FALSE); code = Compiler.FUNCTION_FALSE; break; case FUNCTION_NULL: jj_consume_token(FUNCTION_NULL); code = Compiler.FUNCTION_NULL; break; case FUNCTION_LANG: jj_consume_token(FUNCTION_LANG); code = Compiler.FUNCTION_LANG; break; case FUNCTION_NUMBER: jj_consume_token(FUNCTION_NUMBER); code = Compiler.FUNCTION_NUMBER; break; case FUNCTION_SUM: jj_consume_token(FUNCTION_SUM); code = Compiler.FUNCTION_SUM; break; case FUNCTION_FLOOR: jj_consume_token(FUNCTION_FLOOR); code = Compiler.FUNCTION_FLOOR; break; case FUNCTION_CEILING: jj_consume_token(FUNCTION_CEILING); code = Compiler.FUNCTION_CEILING; break; case FUNCTION_ROUND: jj_consume_token(FUNCTION_ROUND); code = Compiler.FUNCTION_ROUND; break; case FUNCTION_KEY: jj_consume_token(FUNCTION_KEY); code = Compiler.FUNCTION_KEY; break; case FUNCTION_FORMAT_NUMBER: jj_consume_token(FUNCTION_FORMAT_NUMBER); code = Compiler.FUNCTION_FORMAT_NUMBER; break; default: jj_la1[2] = jj_gen; jj_consume_token(-1); throw new ParseException(); } {if (true) return code;} throw new Error("Missing return statement in function"); } final public Object QName() throws ParseException { String nc1, nc2 = null; nc1 = NCName(); switch (jj_nt.kind) { case 79: jj_consume_token(79); nc2 = NCName(); break; default: jj_la1[3] = jj_gen; ; } if (nc2 == null){ {if (true) return compiler.qname(null, nc1);} } else { {if (true) return compiler.qname(nc1, nc2);} } throw new Error("Missing return statement in function"); } final public Object QName_Without_CoreFunctions() throws ParseException { String nc1, nc2 = null; if (jj_2_1(2147483647)) { nc1 = NCName(); jj_consume_token(79); nc2 = NCName(); } else { switch (jj_nt.kind) { case OR: case AND: case MOD: case DIV: case NCName: nc1 = NCName_Without_CoreFunctions(); break; default: jj_la1[4] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } if (nc2 == null){ {if (true) return compiler.qname(null, nc1);} } else { {if (true) return compiler.qname(nc1, nc2);} } throw new Error("Missing return statement in function"); } final public Object parseExpression() throws ParseException { Object ex; ex = Expression(); jj_consume_token(0); {if (true) return ex;} throw new Error("Missing return statement in function"); } /* ################################################################################### */ /* XSLT Patterns (http://www.w3.org/1999/08/WD-xslt-19990813) */ /* ################################################################################### */ /* [XSLT1] Pattern ::= LocationPathPattern | Pattern '|' LocationPathPattern */ //void Pattern() : //{} //{ // LocationPathPattern() ( LocationPathPattern() )* //} // // ///* [XSLT2] LocationPathPattern ::= // '/' RelativePathPattern? | IdKeyPattern (('/' | '//' RelativePathPattern)? | '//'? RelativePathPattern //*/ // //void LocationPathPattern() : //{} //{ // ( RelativePathPattern() )? // | ( // LOOKAHEAD(IdKeyPattern()) // IdKeyPattern() ( ( | ) RelativePathPattern() )? // | ( )? RelativePathPattern() // ) //} // // // ///* [XSLT3] IdKeyPattern ::= 'id' '(' Literal ')' | 'key' '(' Literal ',' Literal ')' */ // //void IdKeyPattern() : //{} //{ // "(" ")" // | "(" "," ")" //} // // ///* [XSLT4] RelativePathPattern ::= StepPattern | RelativePathPattern '/' StepPattern // | RelativePathPattern '//' StepPattern //*/ //void RelativePathPattern() : //{} //{ // StepPattern() ( ( | ) StepPattern() )* //} // // ///* [XSLT5] StepPattern ::= AbbreviatedAxisSpecifier NodeTest Predicate* */ //void StepPattern() : //{} //{ // AbbreviatedAxisSpecifier() NodeTest() (Predicate())* //} // See XPath Syntax (http://www.w3.org/TR/xpath ) //void XPath() : //{} //{ // LocationPath() // //} /* [1] LocationPath ::= RelativeLocationPath | AbsoluteLocationPath */ final public Object LocationPath() throws ParseException { Object ex = null; switch (jj_nt.kind) { case OR: case AND: case MOD: case DIV: case NODE: case TEXT: case COMMENT: case PI: case AXIS_SELF: case AXIS_CHILD: case AXIS_PARENT: case AXIS_ANCESTOR: case AXIS_ATTRIBUTE: case AXIS_NAMESPACE: case AXIS_PRECEDING: case AXIS_FOLLOWING: case AXIS_DESCENDANT: case AXIS_ANCESTOR_OR_SELF: case AXIS_FOLLOWING_SIBLING: case AXIS_PRECEDING_SIBLING: case AXIS_DESCENDANT_OR_SELF: case FUNCTION_LAST: case FUNCTION_POSITION: case FUNCTION_COUNT: case FUNCTION_ID: case FUNCTION_KEY: case FUNCTION_LOCAL_NAME: case FUNCTION_NAMESPACE_URI: case FUNCTION_NAME: case FUNCTION_STRING: case FUNCTION_CONCAT: case FUNCTION_STARTS_WITH: case FUNCTION_CONTAINS: case FUNCTION_SUBSTRING_BEFORE: case FUNCTION_SUBSTRING_AFTER: case FUNCTION_SUBSTRING: case FUNCTION_STRING_LENGTH: case FUNCTION_NORMALIZE_SPACE: case FUNCTION_TRANSLATE: case FUNCTION_BOOLEAN: case FUNCTION_NOT: case FUNCTION_TRUE: case FUNCTION_FALSE: case FUNCTION_NULL: case FUNCTION_LANG: case FUNCTION_NUMBER: case FUNCTION_SUM: case FUNCTION_FLOOR: case FUNCTION_CEILING: case FUNCTION_ROUND: case FUNCTION_FORMAT_NUMBER: case NCName: case 82: case 83: case 86: case 88: ex = RelativeLocationPath(); break; case SLASH: case SLASHSLASH: ex = AbsoluteLocationPath(); break; default: jj_la1[5] = jj_gen; jj_consume_token(-1); throw new ParseException(); } {if (true) return ex;} throw new Error("Missing return statement in function"); } /* [2] AbsoluteLocationPath ::= '/' RelativeLocationPath? | AbbreviatedAbsoluteLocationPath */ /* [10] AbbreviatedAbsoluteLocationPath ::= '//' RelativeLocationPath */ final public Object AbsoluteLocationPath() throws ParseException { ArrayList steps = new ArrayList(); if (jj_2_2(2147483647)) { LocationStep(steps); label_1: while (true) { switch (jj_nt.kind) { case SLASH: case SLASHSLASH: ; break; default: jj_la1[6] = jj_gen; break label_1; } LocationStep(steps); } } else { switch (jj_nt.kind) { case SLASH: jj_consume_token(SLASH); break; default: jj_la1[7] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } {if (true) return compiler.locationPath(true, steps.toArray());} throw new Error("Missing return statement in function"); } /* [3] RelativeLocationPath ::= Step | RelativeLocationPath '/' Step | AbbreviatedRelativeLocationPath */ final public Object RelativeLocationPath() throws ParseException { ArrayList steps = new ArrayList(); NodeTest(steps); label_2: while (true) { switch (jj_nt.kind) { case SLASH: case SLASHSLASH: ; break; default: jj_la1[8] = jj_gen; break label_2; } LocationStep(steps); } {if (true) return compiler.locationPath(false, steps.toArray());} throw new Error("Missing return statement in function"); } /* [3] RelativeLocationPath ::= Step | RelativeLocationPath '/' Step | AbbreviatedRelativeLocationPath */ /* [11] AbbreviatedRelativeLocationPath ::= RelativeLocationPath '//' Step */ /*--------------------*/ /* 2.1 Location Steps */ /*--------------------*/ /* [4] Step ::= AxisSpecifier NodeTest Predicate* | AbbreviatedStep */ final public void LocationStep(ArrayList steps) throws ParseException { Object t; Object s; switch (jj_nt.kind) { case SLASH: jj_consume_token(SLASH); break; case SLASHSLASH: jj_consume_token(SLASHSLASH); // Abbreviated step: descendant-or-self::node() t = compiler.nodeTypeTest(Compiler.NODE_TYPE_NODE); steps.add(compiler.step(Compiler.AXIS_DESCENDANT_OR_SELF, t, null)); break; default: jj_la1[9] = jj_gen; jj_consume_token(-1); throw new ParseException(); } NodeTest(steps); } /* [7] NodeTest ::= WildcardName | NodeType '(' ')' | 'processing-instruction' '(' Literal ')' */ final public void NodeTest(ArrayList steps) throws ParseException { int axis; int type = -1; String instruction = null; Object name = null; Object s; Object p; ArrayList ps = new ArrayList(); switch (jj_nt.kind) { case OR: case AND: case MOD: case DIV: case NODE: case TEXT: case COMMENT: case PI: case AXIS_SELF: case AXIS_CHILD: case AXIS_PARENT: case AXIS_ANCESTOR: case AXIS_ATTRIBUTE: case AXIS_NAMESPACE: case AXIS_PRECEDING: case AXIS_FOLLOWING: case AXIS_DESCENDANT: case AXIS_ANCESTOR_OR_SELF: case AXIS_FOLLOWING_SIBLING: case AXIS_PRECEDING_SIBLING: case AXIS_DESCENDANT_OR_SELF: case FUNCTION_LAST: case FUNCTION_POSITION: case FUNCTION_COUNT: case FUNCTION_ID: case FUNCTION_KEY: case FUNCTION_LOCAL_NAME: case FUNCTION_NAMESPACE_URI: case FUNCTION_NAME: case FUNCTION_STRING: case FUNCTION_CONCAT: case FUNCTION_STARTS_WITH: case FUNCTION_CONTAINS: case FUNCTION_SUBSTRING_BEFORE: case FUNCTION_SUBSTRING_AFTER: case FUNCTION_SUBSTRING: case FUNCTION_STRING_LENGTH: case FUNCTION_NORMALIZE_SPACE: case FUNCTION_TRANSLATE: case FUNCTION_BOOLEAN: case FUNCTION_NOT: case FUNCTION_TRUE: case FUNCTION_FALSE: case FUNCTION_NULL: case FUNCTION_LANG: case FUNCTION_NUMBER: case FUNCTION_SUM: case FUNCTION_FLOOR: case FUNCTION_CEILING: case FUNCTION_ROUND: case FUNCTION_FORMAT_NUMBER: case NCName: case 86: case 88: axis = AxisSpecifier(); if (jj_2_3(2147483647)) { type = NodeType(); jj_consume_token(80); jj_consume_token(81); } else if (jj_2_4(2147483647)) { jj_consume_token(PI); jj_consume_token(80); jj_consume_token(Literal); instruction = unescape(token.image.substring(1, token.image.length() - 1)); jj_consume_token(81); } else { switch (jj_nt.kind) { case OR: case AND: case MOD: case DIV: case NODE: case TEXT: case COMMENT: case PI: case FUNCTION_LAST: case FUNCTION_POSITION: case FUNCTION_COUNT: case FUNCTION_ID: case FUNCTION_KEY: case FUNCTION_LOCAL_NAME: case FUNCTION_NAMESPACE_URI: case FUNCTION_NAME: case FUNCTION_STRING: case FUNCTION_CONCAT: case FUNCTION_STARTS_WITH: case FUNCTION_CONTAINS: case FUNCTION_SUBSTRING_BEFORE: case FUNCTION_SUBSTRING_AFTER: case FUNCTION_SUBSTRING: case FUNCTION_STRING_LENGTH: case FUNCTION_NORMALIZE_SPACE: case FUNCTION_TRANSLATE: case FUNCTION_BOOLEAN: case FUNCTION_NOT: case FUNCTION_TRUE: case FUNCTION_FALSE: case FUNCTION_NULL: case FUNCTION_LANG: case FUNCTION_NUMBER: case FUNCTION_SUM: case FUNCTION_FLOOR: case FUNCTION_CEILING: case FUNCTION_ROUND: case FUNCTION_FORMAT_NUMBER: case NCName: case 88: name = WildcardName(); break; default: jj_la1[10] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } break; case 82: jj_consume_token(82); axis = Compiler.AXIS_SELF; type = Compiler.NODE_TYPE_NODE; break; case 83: jj_consume_token(83); axis = Compiler.AXIS_PARENT; type = Compiler.NODE_TYPE_NODE; break; default: jj_la1[11] = jj_gen; jj_consume_token(-1); throw new ParseException(); } label_3: while (true) { switch (jj_nt.kind) { case 84: ; break; default: jj_la1[12] = jj_gen; break label_3; } p = Predicate(); ps.add(p); } if (name != null){ s = compiler.nodeNameTest(name); } else if (instruction != null){ s = compiler.processingInstructionTest(instruction); } else { s = compiler.nodeTypeTest(type); } steps.add(compiler.step(axis, s, ps.toArray())); } /* [5] AxisSpecifier ::= AxisName '::' | AbbreviatedAxisSpecifier */ final public int AxisSpecifier() throws ParseException { int axis; switch (jj_nt.kind) { case AXIS_SELF: case AXIS_CHILD: case AXIS_PARENT: case AXIS_ANCESTOR: case AXIS_ATTRIBUTE: case AXIS_NAMESPACE: case AXIS_PRECEDING: case AXIS_FOLLOWING: case AXIS_DESCENDANT: case AXIS_ANCESTOR_OR_SELF: case AXIS_FOLLOWING_SIBLING: case AXIS_PRECEDING_SIBLING: case AXIS_DESCENDANT_OR_SELF: axis = AxisName(); break; default: jj_la1[13] = jj_gen; axis = AbbreviatedAxisSpecifier(); } {if (true) return axis;} throw new Error("Missing return statement in function"); } /*----------*/ /* 2.2 Axes */ /*----------*/ /* [6] AxisName ::= 'ancestor' | 'ancestor-or-self' | 'attribute' | 'child' | 'descendant' | 'descendant-or-self' | 'following' | 'following-sibling' | 'namespace' | 'parent' | 'preceding' | 'preceding-sibling' | 'self' */ final public int AxisName() throws ParseException { int axis = 0; switch (jj_nt.kind) { case AXIS_SELF: jj_consume_token(AXIS_SELF); axis = Compiler.AXIS_SELF; break; case AXIS_CHILD: jj_consume_token(AXIS_CHILD); axis = Compiler.AXIS_CHILD; break; case AXIS_PARENT: jj_consume_token(AXIS_PARENT); axis = Compiler.AXIS_PARENT; break; case AXIS_ANCESTOR: jj_consume_token(AXIS_ANCESTOR); axis = Compiler.AXIS_ANCESTOR; break; case AXIS_ATTRIBUTE: jj_consume_token(AXIS_ATTRIBUTE); axis = Compiler.AXIS_ATTRIBUTE; break; case AXIS_NAMESPACE: jj_consume_token(AXIS_NAMESPACE); axis = Compiler.AXIS_NAMESPACE; break; case AXIS_PRECEDING: jj_consume_token(AXIS_PRECEDING); axis = Compiler.AXIS_PRECEDING; break; case AXIS_FOLLOWING: jj_consume_token(AXIS_FOLLOWING); axis = Compiler.AXIS_FOLLOWING; break; case AXIS_DESCENDANT: jj_consume_token(AXIS_DESCENDANT); axis = Compiler.AXIS_DESCENDANT; break; case AXIS_ANCESTOR_OR_SELF: jj_consume_token(AXIS_ANCESTOR_OR_SELF); axis = Compiler.AXIS_ANCESTOR_OR_SELF; break; case AXIS_FOLLOWING_SIBLING: jj_consume_token(AXIS_FOLLOWING_SIBLING); axis = Compiler.AXIS_FOLLOWING_SIBLING; break; case AXIS_PRECEDING_SIBLING: jj_consume_token(AXIS_PRECEDING_SIBLING); axis = Compiler.AXIS_PRECEDING_SIBLING; break; case AXIS_DESCENDANT_OR_SELF: jj_consume_token(AXIS_DESCENDANT_OR_SELF); axis = Compiler.AXIS_DESCENDANT_OR_SELF; break; default: jj_la1[14] = jj_gen; jj_consume_token(-1); throw new ParseException(); } {if (true) return axis;} throw new Error("Missing return statement in function"); } /*----------------*/ /* 2.3 Node Tests */ /*----------------*/ /*----------------*/ /* 2.4 Predicates */ /*----------------*/ /* [8] Predicate ::= '[' PredicateExpr ']' */ /* [9] PredicateExpr ::= Expr */ final public Object Predicate() throws ParseException { Object ex; jj_consume_token(84); ex = Expression(); jj_consume_token(85); {if (true) return ex;} throw new Error("Missing return statement in function"); } /* [12] AbbreviatedStep ::= '.' | '..' */ /* [13] AbbreviatedAxisSpecifier ::= '@'? */ final public int AbbreviatedAxisSpecifier() throws ParseException { int axis = Compiler.AXIS_CHILD; switch (jj_nt.kind) { case 86: jj_consume_token(86); axis = Compiler.AXIS_ATTRIBUTE; break; default: jj_la1[15] = jj_gen; ; } {if (true) return axis;} throw new Error("Missing return statement in function"); } /*---------------*/ /* 3 Expressions */ /*---------------*/ /*------------*/ /* 3.1 Basics */ /*------------*/ /* The effect of the grammar is that the order of precedence is (lowest precedence first): or and =, != <=, <, >=, > and all operators are left associative. For example, 3 > 2 > 1 is equivalent to (3 > 2) > 1, which evaluates to false. */ /* [14] Expr ::= OrExpr */ final public Object Expression() throws ParseException { Object ex; ex = OrExpr(); {if (true) return ex;} throw new Error("Missing return statement in function"); } /* [15] PrimaryExpr ::= VariableReference | '(' Expr ')' | Literal | Number | FunctionCall */ final public Object PrimaryExpr() throws ParseException { Object ex = null; switch (jj_nt.kind) { case VARIABLE: ex = VariableReference(); break; case 80: jj_consume_token(80); ex = Expression(); jj_consume_token(81); break; case Literal: jj_consume_token(Literal); ex = compiler.literal(unescape(token.image.substring(1, token.image.length() - 1))); break; case Number: jj_consume_token(Number); ex = compiler.number(token.image); break; default: jj_la1[16] = jj_gen; if (jj_2_5(2147483647)) { ex = CoreFunctionCall(); } else { switch (jj_nt.kind) { case OR: case AND: case MOD: case DIV: case NODE: case TEXT: case COMMENT: case PI: case FUNCTION_LAST: case FUNCTION_POSITION: case FUNCTION_COUNT: case FUNCTION_ID: case FUNCTION_KEY: case FUNCTION_LOCAL_NAME: case FUNCTION_NAMESPACE_URI: case FUNCTION_NAME: case FUNCTION_STRING: case FUNCTION_CONCAT: case FUNCTION_STARTS_WITH: case FUNCTION_CONTAINS: case FUNCTION_SUBSTRING_BEFORE: case FUNCTION_SUBSTRING_AFTER: case FUNCTION_SUBSTRING: case FUNCTION_STRING_LENGTH: case FUNCTION_NORMALIZE_SPACE: case FUNCTION_TRANSLATE: case FUNCTION_BOOLEAN: case FUNCTION_NOT: case FUNCTION_TRUE: case FUNCTION_FALSE: case FUNCTION_NULL: case FUNCTION_LANG: case FUNCTION_NUMBER: case FUNCTION_SUM: case FUNCTION_FLOOR: case FUNCTION_CEILING: case FUNCTION_ROUND: case FUNCTION_FORMAT_NUMBER: case NCName: ex = FunctionCall(); break; default: jj_la1[17] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } } {if (true) return ex;} throw new Error("Missing return statement in function"); } /*--------------------*/ /* 3.2 Function Calls */ /*--------------------*/ /* [16] FunctionCall ::= FunctionName '(' ( Argument ( ',' Argument)*)? ')' */ final public Object FunctionCall() throws ParseException { Object name; ArrayList args; name = FunctionName(); args = ArgumentList(); if (args == null){ {if (true) return compiler.function(name, null);} } else { {if (true) return compiler.function(name, args.toArray());} } throw new Error("Missing return statement in function"); } final public Object CoreFunctionCall() throws ParseException { int code = 0; ArrayList args; code = CoreFunctionName(); args = ArgumentList(); if (args == null){ {if (true) return compiler.function(code, null);} } else { {if (true) return compiler.function(code, args.toArray());} } throw new Error("Missing return statement in function"); } final public ArrayList ArgumentList() throws ParseException { ArrayList args = null; Object arg; jj_consume_token(80); switch (jj_nt.kind) { case SLASH: case SLASHSLASH: case MINUS: case VARIABLE: case Literal: case Number: case OR: case AND: case MOD: case DIV: case NODE: case TEXT: case COMMENT: case PI: case AXIS_SELF: case AXIS_CHILD: case AXIS_PARENT: case AXIS_ANCESTOR: case AXIS_ATTRIBUTE: case AXIS_NAMESPACE: case AXIS_PRECEDING: case AXIS_FOLLOWING: case AXIS_DESCENDANT: case AXIS_ANCESTOR_OR_SELF: case AXIS_FOLLOWING_SIBLING: case AXIS_PRECEDING_SIBLING: case AXIS_DESCENDANT_OR_SELF: case FUNCTION_LAST: case FUNCTION_POSITION: case FUNCTION_COUNT: case FUNCTION_ID: case FUNCTION_KEY: case FUNCTION_LOCAL_NAME: case FUNCTION_NAMESPACE_URI: case FUNCTION_NAME: case FUNCTION_STRING: case FUNCTION_CONCAT: case FUNCTION_STARTS_WITH: case FUNCTION_CONTAINS: case FUNCTION_SUBSTRING_BEFORE: case FUNCTION_SUBSTRING_AFTER: case FUNCTION_SUBSTRING: case FUNCTION_STRING_LENGTH: case FUNCTION_NORMALIZE_SPACE: case FUNCTION_TRANSLATE: case FUNCTION_BOOLEAN: case FUNCTION_NOT: case FUNCTION_TRUE: case FUNCTION_FALSE: case FUNCTION_NULL: case FUNCTION_LANG: case FUNCTION_NUMBER: case FUNCTION_SUM: case FUNCTION_FLOOR: case FUNCTION_CEILING: case FUNCTION_ROUND: case FUNCTION_FORMAT_NUMBER: case NCName: case 80: case 82: case 83: case 86: case 88: arg = Argument(); args = new ArrayList(); args.add(arg); label_4: while (true) { switch (jj_nt.kind) { case 87: ; break; default: jj_la1[18] = jj_gen; break label_4; } jj_consume_token(87); arg = Argument(); args.add(arg); } break; default: jj_la1[19] = jj_gen; ; } jj_consume_token(81); {if (true) return args;} throw new Error("Missing return statement in function"); } /* [17] Argument ::= Expr */ final public Object Argument() throws ParseException { Object ex; ex = Expression(); {if (true) return ex;} throw new Error("Missing return statement in function"); } /*---------------*/ /* 3.3 Node-sets */ /*---------------*/ /* [18] UnionExpr ::= PathExpr | UnionExpr '|' PathExpr */ final public Object UnionExpr() throws ParseException { Object ex, r; ArrayList list = null; ex = PathExpr(); label_5: while (true) { switch (jj_nt.kind) { case UNION: ; break; default: jj_la1[20] = jj_gen; break label_5; } jj_consume_token(UNION); r = PathExpr(); if (list == null){ list = new ArrayList(); list.add(ex); } list.add(r); } if (list != null){ ex = compiler.union(list.toArray()); } {if (true) return ex;} throw new Error("Missing return statement in function"); } /* [19] PathExpr ::= LocationPath | FilterExpr | FilterExpr '/' RelativeLocationPath | FilterExpr '//' RelativeLocationPath */ final public Object PathExpr() throws ParseException { Object ex = null; Object[] steps; if (jj_2_6(2147483647)) { ex = FilterExpr(); } else { switch (jj_nt.kind) { case SLASH: case SLASHSLASH: case OR: case AND: case MOD: case DIV: case NODE: case TEXT: case COMMENT: case PI: case AXIS_SELF: case AXIS_CHILD: case AXIS_PARENT: case AXIS_ANCESTOR: case AXIS_ATTRIBUTE: case AXIS_NAMESPACE: case AXIS_PRECEDING: case AXIS_FOLLOWING: case AXIS_DESCENDANT: case AXIS_ANCESTOR_OR_SELF: case AXIS_FOLLOWING_SIBLING: case AXIS_PRECEDING_SIBLING: case AXIS_DESCENDANT_OR_SELF: case FUNCTION_LAST: case FUNCTION_POSITION: case FUNCTION_COUNT: case FUNCTION_ID: case FUNCTION_KEY: case FUNCTION_LOCAL_NAME: case FUNCTION_NAMESPACE_URI: case FUNCTION_NAME: case FUNCTION_STRING: case FUNCTION_CONCAT: case FUNCTION_STARTS_WITH: case FUNCTION_CONTAINS: case FUNCTION_SUBSTRING_BEFORE: case FUNCTION_SUBSTRING_AFTER: case FUNCTION_SUBSTRING: case FUNCTION_STRING_LENGTH: case FUNCTION_NORMALIZE_SPACE: case FUNCTION_TRANSLATE: case FUNCTION_BOOLEAN: case FUNCTION_NOT: case FUNCTION_TRUE: case FUNCTION_FALSE: case FUNCTION_NULL: case FUNCTION_LANG: case FUNCTION_NUMBER: case FUNCTION_SUM: case FUNCTION_FLOOR: case FUNCTION_CEILING: case FUNCTION_ROUND: case FUNCTION_FORMAT_NUMBER: case NCName: case 82: case 83: case 86: case 88: ex = LocationPath(); break; default: jj_la1[21] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } {if (true) return ex;} throw new Error("Missing return statement in function"); } /* [20] FilterExpr ::= PrimaryExpr | FilterExpr Predicate */ final public Object FilterExpr() throws ParseException { Object ex, p; ArrayList ps = new ArrayList(); boolean path = false; ArrayList steps = new ArrayList(); ex = PrimaryExpr(); label_6: while (true) { switch (jj_nt.kind) { case 84: ; break; default: jj_la1[22] = jj_gen; break label_6; } p = Predicate(); path = true; ps.add(p); } label_7: while (true) { switch (jj_nt.kind) { case SLASH: case SLASHSLASH: ; break; default: jj_la1[23] = jj_gen; break label_7; } LocationStep(steps); path = true; } if (path){ {if (true) return compiler.expressionPath(ex, ps.toArray(), steps.toArray());} } else { {if (true) return ex;} } throw new Error("Missing return statement in function"); } /*--------------*/ /* 3.4 Booleans */ /*--------------*/ /* [21] OrExpr ::= AndExpr | OrExpr 'or' AndExpr */ final public Object OrExpr() throws ParseException { Object ex, r; ArrayList list = null; ex = AndExpr(); label_8: while (true) { switch (jj_nt.kind) { case OR: ; break; default: jj_la1[24] = jj_gen; break label_8; } jj_consume_token(OR); r = AndExpr(); if (list == null){ list = new ArrayList(); list.add(ex); } list.add(r); } if (list != null){ ex = compiler.or(list.toArray()); } {if (true) return ex;} throw new Error("Missing return statement in function"); } /* [22] AndExpr ::= EqualityExpr | AndExpr 'and' EqualityExpr */ final public Object AndExpr() throws ParseException { Object ex, r; ArrayList list = null; ex = EqualityExpr(); label_9: while (true) { switch (jj_nt.kind) { case AND: ; break; default: jj_la1[25] = jj_gen; break label_9; } jj_consume_token(AND); r = EqualityExpr(); if (list == null){ list = new ArrayList(); list.add(ex); } list.add(r); } if (list != null){ ex = compiler.and(list.toArray()); } {if (true) return ex;} throw new Error("Missing return statement in function"); } /* [23] EqualityExpr ::= RelationalExpr | EqualityExpr '=' RelationalExpr | EqualityExpr '!=' RelationalExpr */ final public Object EqualityExpr() throws ParseException { Object ex, r; ex = RelationalExpr(); label_10: while (true) { switch (jj_nt.kind) { case EQ: case NEQ: ; break; default: jj_la1[26] = jj_gen; break label_10; } switch (jj_nt.kind) { case EQ: jj_consume_token(EQ); r = RelationalExpr(); ex = compiler.equal(ex, r); break; case NEQ: jj_consume_token(NEQ); r = RelationalExpr(); ex = compiler.notEqual(ex, r); break; default: jj_la1[27] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } {if (true) return ex;} throw new Error("Missing return statement in function"); } /* [24] RelationalExpr ::= AdditiveExpr | RelationalExpr '<' AdditiveExpr | RelationalExpr '>' AdditiveExpr | RelationalExpr '<=' AdditiveExpr | RelationalExpr '>=' AdditiveExpr */ final public Object RelationalExpr() throws ParseException { Object ex, r; ex = AdditiveExpr(); label_11: while (true) { switch (jj_nt.kind) { case LT: case LTE: case GT: case GTE: ; break; default: jj_la1[28] = jj_gen; break label_11; } switch (jj_nt.kind) { case LT: jj_consume_token(LT); r = AdditiveExpr(); ex = compiler.lessThan(ex, r); break; case GT: jj_consume_token(GT); r = AdditiveExpr(); ex = compiler.greaterThan(ex, r); break; case LTE: jj_consume_token(LTE); r = AdditiveExpr(); ex = compiler.lessThanOrEqual(ex, r); break; case GTE: jj_consume_token(GTE); r = AdditiveExpr(); ex = compiler.greaterThanOrEqual(ex, r); break; default: jj_la1[29] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } {if (true) return ex;} throw new Error("Missing return statement in function"); } /*-------------*/ /* 3.5 Numbers */ /*-------------*/ /* [25] AdditiveExpr ::= MultiplicativeExpr | AdditiveExpr '+' MultiplicativeExpr | AdditiveExpr '-' MultiplicativeExpr */ final public Object AdditiveExpr() throws ParseException { Object ex, r; ArrayList list = null; ex = SubtractiveExpr(); label_12: while (true) { switch (jj_nt.kind) { case PLUS: ; break; default: jj_la1[30] = jj_gen; break label_12; } jj_consume_token(PLUS); r = SubtractiveExpr(); if (list == null){ list = new ArrayList(); list.add(ex); } list.add(r); } if (list != null){ ex = compiler.sum(list.toArray()); } {if (true) return ex;} throw new Error("Missing return statement in function"); } final public Object SubtractiveExpr() throws ParseException { Object ex, r = null; ex = MultiplicativeExpr(); label_13: while (true) { switch (jj_nt.kind) { case MINUS: ; break; default: jj_la1[31] = jj_gen; break label_13; } jj_consume_token(MINUS); r = MultiplicativeExpr(); ex = compiler.minus(ex, r); } {if (true) return ex;} throw new Error("Missing return statement in function"); } /* [26] MultiplicativeExpr ::= UnaryExpr | MultiplicativeExpr MultiplyOperator UnaryExpr | MultiplicativeExpr 'div' UnaryExpr | MultiplicativeExpr 'mod' UnaryExpr */ final public Object MultiplicativeExpr() throws ParseException { Object ex, r; ex = UnaryExpr(); label_14: while (true) { switch (jj_nt.kind) { case MOD: case DIV: case 88: ; break; default: jj_la1[32] = jj_gen; break label_14; } switch (jj_nt.kind) { case 88: jj_consume_token(88); r = UnaryExpr(); ex = compiler.multiply(ex, r); break; case DIV: jj_consume_token(DIV); r = UnaryExpr(); ex = compiler.divide(ex, r); break; case MOD: jj_consume_token(MOD); r = UnaryExpr(); ex = compiler.mod(ex, r); break; default: jj_la1[33] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } {if (true) return ex;} throw new Error("Missing return statement in function"); } /* [27] UnaryExpr ::= UnionExpr | '-' UnaryExpr */ final public Object UnaryExpr() throws ParseException { Object ex; switch (jj_nt.kind) { case SLASH: case SLASHSLASH: case VARIABLE: case Literal: case Number: case OR: case AND: case MOD: case DIV: case NODE: case TEXT: case COMMENT: case PI: case AXIS_SELF: case AXIS_CHILD: case AXIS_PARENT: case AXIS_ANCESTOR: case AXIS_ATTRIBUTE: case AXIS_NAMESPACE: case AXIS_PRECEDING: case AXIS_FOLLOWING: case AXIS_DESCENDANT: case AXIS_ANCESTOR_OR_SELF: case AXIS_FOLLOWING_SIBLING: case AXIS_PRECEDING_SIBLING: case AXIS_DESCENDANT_OR_SELF: case FUNCTION_LAST: case FUNCTION_POSITION: case FUNCTION_COUNT: case FUNCTION_ID: case FUNCTION_KEY: case FUNCTION_LOCAL_NAME: case FUNCTION_NAMESPACE_URI: case FUNCTION_NAME: case FUNCTION_STRING: case FUNCTION_CONCAT: case FUNCTION_STARTS_WITH: case FUNCTION_CONTAINS: case FUNCTION_SUBSTRING_BEFORE: case FUNCTION_SUBSTRING_AFTER: case FUNCTION_SUBSTRING: case FUNCTION_STRING_LENGTH: case FUNCTION_NORMALIZE_SPACE: case FUNCTION_TRANSLATE: case FUNCTION_BOOLEAN: case FUNCTION_NOT: case FUNCTION_TRUE: case FUNCTION_FALSE: case FUNCTION_NULL: case FUNCTION_LANG: case FUNCTION_NUMBER: case FUNCTION_SUM: case FUNCTION_FLOOR: case FUNCTION_CEILING: case FUNCTION_ROUND: case FUNCTION_FORMAT_NUMBER: case NCName: case 80: case 82: case 83: case 86: case 88: ex = UnionExpr(); break; case MINUS: jj_consume_token(MINUS); ex = UnaryExpr(); ex = compiler.minus(ex); break; default: jj_la1[34] = jj_gen; jj_consume_token(-1); throw new ParseException(); } {if (true) return ex;} throw new Error("Missing return statement in function"); } /*-------------*/ /* 3.6 Strings */ /*-------------*/ /*----------------------------------*/ /* 3.7 Expression Lexical Structure */ /*----------------------------------*/ /* The following special tokenization rules must be applied in the order specified to disambiguate the grammar: 1. If there is a preceding token and the preceding token is not one of @, ::, (, [, , or an Operator, then a * must be recognized as a MultiplyOperator and an NCName must be recognized as an OperatorName. 2. If the character following an NCName (possibly after intervening ExprWhitespace) is (, then the token must be recognized as a NodeType or a FunctionName. 3. If the two characters following an NCName (possibly after intervening ExprWhitespace) are ::, then the token must be recognized as an AxisName. 4. Otherwise, the token must not be recognized as a MultiplyOperator, an OperatorName, a NodeType, a FunctionName, or an AxisName. */ /* [28] ExprToken ::= '(' | ')' | '[' | ']' | '.' | '..' | '@' | ',' | '::' | WildcardName | NodeType | Operator | FunctionName | AxisName | Literal | Number | VariableReference */ /* [34] MultiplyOperator ::= '*' */ /* [35] FunctionName ::= QName - NodeType */ final public Object FunctionName() throws ParseException { Object qname; qname = QName_Without_CoreFunctions(); {if (true) return qname;} throw new Error("Missing return statement in function"); } /* [36] VariableReference ::= '$' QName */ final public Object VariableReference() throws ParseException { Object ex; jj_consume_token(VARIABLE); ex = QName(); {if (true) return compiler.variableReference(ex);} throw new Error("Missing return statement in function"); } /* [37] WildcardName ::= '*' | NCName ':' '*' | QName */ final public Object WildcardName() throws ParseException { Object qn; String nc1, nc2 = null; switch (jj_nt.kind) { case 88: jj_consume_token(88); break; case OR: case AND: case MOD: case DIV: case NODE: case TEXT: case COMMENT: case PI: case FUNCTION_LAST: case FUNCTION_POSITION: case FUNCTION_COUNT: case FUNCTION_ID: case FUNCTION_KEY: case FUNCTION_LOCAL_NAME: case FUNCTION_NAMESPACE_URI: case FUNCTION_NAME: case FUNCTION_STRING: case FUNCTION_CONCAT: case FUNCTION_STARTS_WITH: case FUNCTION_CONTAINS: case FUNCTION_SUBSTRING_BEFORE: case FUNCTION_SUBSTRING_AFTER: case FUNCTION_SUBSTRING: case FUNCTION_STRING_LENGTH: case FUNCTION_NORMALIZE_SPACE: case FUNCTION_TRANSLATE: case FUNCTION_BOOLEAN: case FUNCTION_NOT: case FUNCTION_TRUE: case FUNCTION_FALSE: case FUNCTION_NULL: case FUNCTION_LANG: case FUNCTION_NUMBER: case FUNCTION_SUM: case FUNCTION_FLOOR: case FUNCTION_CEILING: case FUNCTION_ROUND: case FUNCTION_FORMAT_NUMBER: case NCName: NCName(); break; default: jj_la1[35] = jj_gen; jj_consume_token(-1); throw new ParseException(); } nc1 = token.image; switch (jj_nt.kind) { case 79: jj_consume_token(79); switch (jj_nt.kind) { case 88: jj_consume_token(88); break; case OR: case AND: case MOD: case DIV: case NODE: case TEXT: case COMMENT: case PI: case FUNCTION_LAST: case FUNCTION_POSITION: case FUNCTION_COUNT: case FUNCTION_ID: case FUNCTION_KEY: case FUNCTION_LOCAL_NAME: case FUNCTION_NAMESPACE_URI: case FUNCTION_NAME: case FUNCTION_STRING: case FUNCTION_CONCAT: case FUNCTION_STARTS_WITH: case FUNCTION_CONTAINS: case FUNCTION_SUBSTRING_BEFORE: case FUNCTION_SUBSTRING_AFTER: case FUNCTION_SUBSTRING: case FUNCTION_STRING_LENGTH: case FUNCTION_NORMALIZE_SPACE: case FUNCTION_TRANSLATE: case FUNCTION_BOOLEAN: case FUNCTION_NOT: case FUNCTION_TRUE: case FUNCTION_FALSE: case FUNCTION_NULL: case FUNCTION_LANG: case FUNCTION_NUMBER: case FUNCTION_SUM: case FUNCTION_FLOOR: case FUNCTION_CEILING: case FUNCTION_ROUND: case FUNCTION_FORMAT_NUMBER: case NCName: NCName(); break; default: jj_la1[36] = jj_gen; jj_consume_token(-1); throw new ParseException(); } nc2 = token.image; break; default: jj_la1[37] = jj_gen; ; } if (nc2 != null){ qn = compiler.qname(nc1, nc2); } else { qn = compiler.qname(null, nc1); } {if (true) return qn;} throw new Error("Missing return statement in function"); } /* [38] NodeType ::= 'comment' | 'text' | 'processing-instruction' | 'node' */ final public int NodeType() throws ParseException { int type; switch (jj_nt.kind) { case TEXT: jj_consume_token(TEXT); type = Compiler.NODE_TYPE_TEXT; break; case NODE: jj_consume_token(NODE); type = Compiler.NODE_TYPE_NODE; break; case COMMENT: jj_consume_token(COMMENT); type = Compiler.NODE_TYPE_COMMENT; break; case PI: jj_consume_token(PI); type = Compiler.NODE_TYPE_PI; break; default: jj_la1[38] = jj_gen; jj_consume_token(-1); throw new ParseException(); } {if (true) return type;} throw new Error("Missing return statement in function"); } final private boolean jj_2_1(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; boolean retval = !jj_3_1(); jj_save(0, xla); return retval; } final private boolean jj_2_2(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; boolean retval = !jj_3_2(); jj_save(1, xla); return retval; } final private boolean jj_2_3(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; boolean retval = !jj_3_3(); jj_save(2, xla); return retval; } final private boolean jj_2_4(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; boolean retval = !jj_3_4(); jj_save(3, xla); return retval; } final private boolean jj_2_5(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; boolean retval = !jj_3_5(); jj_save(4, xla); return retval; } final private boolean jj_2_6(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; boolean retval = !jj_3_6(); jj_save(5, xla); return retval; } final private boolean jj_3R_65() { if (jj_scan_token(FUNCTION_ID)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_104() { if (jj_3R_118()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_64() { if (jj_scan_token(FUNCTION_COUNT)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_63() { if (jj_scan_token(FUNCTION_POSITION)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_62() { if (jj_scan_token(FUNCTION_LAST)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_18() { Token xsp; xsp = jj_scanpos; if (jj_3R_62()) { jj_scanpos = xsp; if (jj_3R_63()) { jj_scanpos = xsp; if (jj_3R_64()) { jj_scanpos = xsp; if (jj_3R_65()) { jj_scanpos = xsp; if (jj_3R_66()) { jj_scanpos = xsp; if (jj_3R_67()) { jj_scanpos = xsp; if (jj_3R_68()) { jj_scanpos = xsp; if (jj_3R_69()) { jj_scanpos = xsp; if (jj_3R_70()) { jj_scanpos = xsp; if (jj_3R_71()) { jj_scanpos = xsp; if (jj_3R_72()) { jj_scanpos = xsp; if (jj_3R_73()) { jj_scanpos = xsp; if (jj_3R_74()) { jj_scanpos = xsp; if (jj_3R_75()) { jj_scanpos = xsp; if (jj_3R_76()) { jj_scanpos = xsp; if (jj_3R_77()) { jj_scanpos = xsp; if (jj_3R_78()) { jj_scanpos = xsp; if (jj_3R_79()) { jj_scanpos = xsp; if (jj_3R_80()) { jj_scanpos = xsp; if (jj_3R_81()) { jj_scanpos = xsp; if (jj_3R_82()) { jj_scanpos = xsp; if (jj_3R_83()) { jj_scanpos = xsp; if (jj_3R_84()) { jj_scanpos = xsp; if (jj_3R_85()) { jj_scanpos = xsp; if (jj_3R_86()) { jj_scanpos = xsp; if (jj_3R_87()) { jj_scanpos = xsp; if (jj_3R_88()) { jj_scanpos = xsp; if (jj_3R_89()) { jj_scanpos = xsp; if (jj_3R_90()) { jj_scanpos = xsp; if (jj_3R_91()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_111() { if (jj_scan_token(DIV)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_110() { if (jj_scan_token(MOD)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_109() { if (jj_scan_token(AND)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_108() { if (jj_scan_token(OR)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_107() { if (jj_scan_token(NCName)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_173() { if (jj_scan_token(MINUS)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_170()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_98() { Token xsp; xsp = jj_scanpos; if (jj_3R_107()) { jj_scanpos = xsp; if (jj_3R_108()) { jj_scanpos = xsp; if (jj_3R_109()) { jj_scanpos = xsp; if (jj_3R_110()) { jj_scanpos = xsp; if (jj_3R_111()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_171() { Token xsp; xsp = jj_scanpos; if (jj_3R_174()) { jj_scanpos = xsp; if (jj_3R_175()) { jj_scanpos = xsp; if (jj_3R_176()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_172() { if (jj_3R_177()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_153() { if (jj_scan_token(86)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_130() { Token xsp; xsp = jj_scanpos; if (jj_3R_153()) jj_scanpos = xsp; else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_54() { if (jj_scan_token(FUNCTION_FORMAT_NUMBER)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_170() { Token xsp; xsp = jj_scanpos; if (jj_3R_172()) { jj_scanpos = xsp; if (jj_3R_173()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_53() { if (jj_scan_token(FUNCTION_KEY)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_52() { if (jj_scan_token(FUNCTION_ROUND)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_51() { if (jj_scan_token(FUNCTION_CEILING)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_50() { if (jj_scan_token(FUNCTION_FLOOR)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_49() { if (jj_scan_token(FUNCTION_SUM)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_48() { if (jj_scan_token(FUNCTION_NUMBER)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_176() { if (jj_scan_token(MOD)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_170()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_47() { if (jj_scan_token(FUNCTION_LANG)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_175() { if (jj_scan_token(DIV)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_170()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_46() { if (jj_scan_token(FUNCTION_NULL)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_174() { if (jj_scan_token(88)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_170()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_45() { if (jj_scan_token(FUNCTION_FALSE)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_44() { if (jj_scan_token(FUNCTION_TRUE)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_43() { if (jj_scan_token(FUNCTION_NOT)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_42() { if (jj_scan_token(FUNCTION_BOOLEAN)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_41() { if (jj_scan_token(FUNCTION_TRANSLATE)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_116() { if (jj_scan_token(84)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_104()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(85)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_40() { if (jj_scan_token(FUNCTION_NORMALIZE_SPACE)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_39() { if (jj_scan_token(FUNCTION_STRING_LENGTH)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_38() { if (jj_scan_token(FUNCTION_SUBSTRING)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_37() { if (jj_scan_token(FUNCTION_SUBSTRING_AFTER)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_36() { if (jj_scan_token(FUNCTION_SUBSTRING_BEFORE)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_168() { if (jj_3R_170()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; while (true) { xsp = jj_scanpos; if (jj_3R_171()) { jj_scanpos = xsp; break; } if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } return false; } final private boolean jj_3R_35() { if (jj_scan_token(FUNCTION_CONTAINS)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_34() { if (jj_scan_token(FUNCTION_STARTS_WITH)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_33() { if (jj_scan_token(FUNCTION_CONCAT)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_32() { if (jj_scan_token(FUNCTION_STRING)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_31() { if (jj_scan_token(FUNCTION_NAME)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_30() { if (jj_scan_token(FUNCTION_NAMESPACE_URI)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_29() { if (jj_scan_token(FUNCTION_LOCAL_NAME)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_169() { if (jj_scan_token(MINUS)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_168()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_28() { if (jj_scan_token(FUNCTION_ID)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_27() { if (jj_scan_token(FUNCTION_COUNT)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_152() { if (jj_scan_token(AXIS_DESCENDANT_OR_SELF)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_26() { if (jj_scan_token(FUNCTION_POSITION)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_25() { if (jj_scan_token(FUNCTION_LAST)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_151() { if (jj_scan_token(AXIS_PRECEDING_SIBLING)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_24() { if (jj_scan_token(PI)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_150() { if (jj_scan_token(AXIS_FOLLOWING_SIBLING)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_23() { if (jj_scan_token(COMMENT)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_149() { if (jj_scan_token(AXIS_ANCESTOR_OR_SELF)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_163() { if (jj_scan_token(PLUS)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_162()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_22() { if (jj_scan_token(TEXT)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_148() { if (jj_scan_token(AXIS_DESCENDANT)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_21() { if (jj_scan_token(NODE)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_147() { if (jj_scan_token(AXIS_FOLLOWING)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_20() { if (jj_3R_98()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_146() { if (jj_scan_token(AXIS_PRECEDING)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_145() { if (jj_scan_token(AXIS_NAMESPACE)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_162() { if (jj_3R_168()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; while (true) { xsp = jj_scanpos; if (jj_3R_169()) { jj_scanpos = xsp; break; } if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } return false; } final private boolean jj_3R_144() { if (jj_scan_token(AXIS_ATTRIBUTE)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_143() { if (jj_scan_token(AXIS_ANCESTOR)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_142() { if (jj_scan_token(AXIS_PARENT)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_15() { Token xsp; xsp = jj_scanpos; if (jj_3R_20()) { jj_scanpos = xsp; if (jj_3R_21()) { jj_scanpos = xsp; if (jj_3R_22()) { jj_scanpos = xsp; if (jj_3R_23()) { jj_scanpos = xsp; if (jj_3R_24()) { jj_scanpos = xsp; if (jj_3R_25()) { jj_scanpos = xsp; if (jj_3R_26()) { jj_scanpos = xsp; if (jj_3R_27()) { jj_scanpos = xsp; if (jj_3R_28()) { jj_scanpos = xsp; if (jj_3R_29()) { jj_scanpos = xsp; if (jj_3R_30()) { jj_scanpos = xsp; if (jj_3R_31()) { jj_scanpos = xsp; if (jj_3R_32()) { jj_scanpos = xsp; if (jj_3R_33()) { jj_scanpos = xsp; if (jj_3R_34()) { jj_scanpos = xsp; if (jj_3R_35()) { jj_scanpos = xsp; if (jj_3R_36()) { jj_scanpos = xsp; if (jj_3R_37()) { jj_scanpos = xsp; if (jj_3R_38()) { jj_scanpos = xsp; if (jj_3R_39()) { jj_scanpos = xsp; if (jj_3R_40()) { jj_scanpos = xsp; if (jj_3R_41()) { jj_scanpos = xsp; if (jj_3R_42()) { jj_scanpos = xsp; if (jj_3R_43()) { jj_scanpos = xsp; if (jj_3R_44()) { jj_scanpos = xsp; if (jj_3R_45()) { jj_scanpos = xsp; if (jj_3R_46()) { jj_scanpos = xsp; if (jj_3R_47()) { jj_scanpos = xsp; if (jj_3R_48()) { jj_scanpos = xsp; if (jj_3R_49()) { jj_scanpos = xsp; if (jj_3R_50()) { jj_scanpos = xsp; if (jj_3R_51()) { jj_scanpos = xsp; if (jj_3R_52()) { jj_scanpos = xsp; if (jj_3R_53()) { jj_scanpos = xsp; if (jj_3R_54()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_141() { if (jj_scan_token(AXIS_CHILD)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_140() { if (jj_scan_token(AXIS_SELF)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_129() { Token xsp; xsp = jj_scanpos; if (jj_3R_140()) { jj_scanpos = xsp; if (jj_3R_141()) { jj_scanpos = xsp; if (jj_3R_142()) { jj_scanpos = xsp; if (jj_3R_143()) { jj_scanpos = xsp; if (jj_3R_144()) { jj_scanpos = xsp; if (jj_3R_145()) { jj_scanpos = xsp; if (jj_3R_146()) { jj_scanpos = xsp; if (jj_3R_147()) { jj_scanpos = xsp; if (jj_3R_148()) { jj_scanpos = xsp; if (jj_3R_149()) { jj_scanpos = xsp; if (jj_3R_150()) { jj_scanpos = xsp; if (jj_3R_151()) { jj_scanpos = xsp; if (jj_3R_152()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_159() { Token xsp; xsp = jj_scanpos; if (jj_3R_164()) { jj_scanpos = xsp; if (jj_3R_165()) { jj_scanpos = xsp; if (jj_3R_166()) { jj_scanpos = xsp; if (jj_3R_167()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_158() { if (jj_3R_162()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; while (true) { xsp = jj_scanpos; if (jj_3R_163()) { jj_scanpos = xsp; break; } if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } return false; } final private boolean jj_3R_122() { if (jj_3R_130()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_121() { if (jj_3R_129()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_167() { if (jj_scan_token(GTE)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_158()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_112() { Token xsp; xsp = jj_scanpos; if (jj_3R_121()) { jj_scanpos = xsp; if (jj_3R_122()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_166() { if (jj_scan_token(LTE)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_158()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_165() { if (jj_scan_token(GT)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_158()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_157() { Token xsp; xsp = jj_scanpos; if (jj_3R_160()) { jj_scanpos = xsp; if (jj_3R_161()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_164() { if (jj_scan_token(LT)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_158()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_156() { if (jj_3R_158()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; while (true) { xsp = jj_scanpos; if (jj_3R_159()) { jj_scanpos = xsp; break; } if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } return false; } final private boolean jj_3R_161() { if (jj_scan_token(NEQ)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_156()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_160() { if (jj_scan_token(EQ)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_156()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_102() { if (jj_3R_116()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3_4() { if (jj_scan_token(PI)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3_3() { if (jj_3R_17()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(80)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(81)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_101() { if (jj_scan_token(83)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_100() { if (jj_scan_token(82)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_115() { if (jj_3R_123()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_134() { if (jj_3R_156()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; while (true) { xsp = jj_scanpos; if (jj_3R_157()) { jj_scanpos = xsp; break; } if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } return false; } final private boolean jj_3R_114() { if (jj_scan_token(PI)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(80)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(Literal)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(81)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_113() { if (jj_3R_17()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(80)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(81)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_99() { if (jj_3R_112()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; xsp = jj_scanpos; if (jj_3R_113()) { jj_scanpos = xsp; if (jj_3R_114()) { jj_scanpos = xsp; if (jj_3R_115()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_135() { if (jj_scan_token(AND)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_134()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_57() { Token xsp; xsp = jj_scanpos; if (jj_3R_99()) { jj_scanpos = xsp; if (jj_3R_100()) { jj_scanpos = xsp; if (jj_3R_101()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; while (true) { xsp = jj_scanpos; if (jj_3R_102()) { jj_scanpos = xsp; break; } if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } return false; } final private boolean jj_3R_125() { if (jj_3R_134()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; while (true) { xsp = jj_scanpos; if (jj_3R_135()) { jj_scanpos = xsp; break; } if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } return false; } final private boolean jj_3R_193() { if (jj_3R_16()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_56() { if (jj_scan_token(SLASHSLASH)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_55() { if (jj_scan_token(SLASH)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_126() { if (jj_scan_token(OR)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_125()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_16() { Token xsp; xsp = jj_scanpos; if (jj_3R_55()) { jj_scanpos = xsp; if (jj_3R_56()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_57()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_190() { if (jj_3R_16()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_118() { if (jj_3R_125()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; while (true) { xsp = jj_scanpos; if (jj_3R_126()) { jj_scanpos = xsp; break; } if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } return false; } final private boolean jj_3R_188() { if (jj_3R_57()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; while (true) { xsp = jj_scanpos; if (jj_3R_190()) { jj_scanpos = xsp; break; } if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } return false; } final private boolean jj_3_2() { if (jj_3R_16()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_185() { if (jj_3R_16()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_192() { if (jj_scan_token(SLASH)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_191() { if (jj_3R_16()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; while (true) { xsp = jj_scanpos; if (jj_3R_193()) { jj_scanpos = xsp; break; } if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } return false; } final private boolean jj_3R_184() { if (jj_3R_116()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_189() { Token xsp; xsp = jj_scanpos; if (jj_3R_191()) { jj_scanpos = xsp; if (jj_3R_192()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_182() { if (jj_3R_19()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; while (true) { xsp = jj_scanpos; if (jj_3R_184()) { jj_scanpos = xsp; break; } if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } while (true) { xsp = jj_scanpos; if (jj_3R_185()) { jj_scanpos = xsp; break; } if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } return false; } final private boolean jj_3_6() { if (jj_3R_19()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_187() { if (jj_3R_189()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_186() { if (jj_3R_188()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_183() { Token xsp; xsp = jj_scanpos; if (jj_3R_186()) { jj_scanpos = xsp; if (jj_3R_187()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_181() { if (jj_3R_183()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_180() { if (jj_3R_182()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_178() { Token xsp; xsp = jj_scanpos; if (jj_3R_180()) { jj_scanpos = xsp; if (jj_3R_181()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_179() { if (jj_scan_token(UNION)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_178()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_177() { if (jj_3R_178()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; while (true) { xsp = jj_scanpos; if (jj_3R_179()) { jj_scanpos = xsp; break; } if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } return false; } final private boolean jj_3R_136() { if (jj_3R_104()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_137() { if (jj_scan_token(87)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_136()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_127() { if (jj_3R_136()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; while (true) { xsp = jj_scanpos; if (jj_3R_137()) { jj_scanpos = xsp; break; } if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } return false; } final private boolean jj_3R_119() { if (jj_scan_token(80)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; xsp = jj_scanpos; if (jj_3R_127()) jj_scanpos = xsp; else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(81)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_61() { if (jj_scan_token(PI)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_60() { if (jj_scan_token(COMMENT)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_59() { if (jj_scan_token(NODE)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_58() { if (jj_scan_token(TEXT)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3_1() { if (jj_3R_15()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(79)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_17() { Token xsp; xsp = jj_scanpos; if (jj_3R_58()) { jj_scanpos = xsp; if (jj_3R_59()) { jj_scanpos = xsp; if (jj_3R_60()) { jj_scanpos = xsp; if (jj_3R_61()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_155() { if (jj_3R_15()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_139() { if (jj_3R_98()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_138() { if (jj_3R_15()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(79)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_15()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_154() { if (jj_scan_token(88)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_132() { if (jj_3R_15()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_105() { if (jj_3R_18()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_119()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_124() { if (jj_scan_token(79)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_15()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_133() { if (jj_scan_token(79)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; xsp = jj_scanpos; if (jj_3R_154()) { jj_scanpos = xsp; if (jj_3R_155()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_128() { Token xsp; xsp = jj_scanpos; if (jj_3R_138()) { jj_scanpos = xsp; if (jj_3R_139()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_131() { if (jj_scan_token(88)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_123() { Token xsp; xsp = jj_scanpos; if (jj_3R_131()) { jj_scanpos = xsp; if (jj_3R_132()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; xsp = jj_scanpos; if (jj_3R_133()) jj_scanpos = xsp; else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_106() { if (jj_3R_120()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_119()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_117() { if (jj_3R_15()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; xsp = jj_scanpos; if (jj_3R_124()) jj_scanpos = xsp; else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3_5() { if (jj_3R_18()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(80)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_103() { if (jj_scan_token(VARIABLE)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_117()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_91() { if (jj_scan_token(FUNCTION_FORMAT_NUMBER)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_90() { if (jj_scan_token(FUNCTION_KEY)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_89() { if (jj_scan_token(FUNCTION_ROUND)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_88() { if (jj_scan_token(FUNCTION_CEILING)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_97() { if (jj_3R_106()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_87() { if (jj_scan_token(FUNCTION_FLOOR)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_96() { if (jj_3R_105()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_86() { if (jj_scan_token(FUNCTION_SUM)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_95() { if (jj_scan_token(Number)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_85() { if (jj_scan_token(FUNCTION_NUMBER)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_94() { if (jj_scan_token(Literal)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_84() { if (jj_scan_token(FUNCTION_LANG)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_93() { if (jj_scan_token(80)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_104()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(81)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_83() { if (jj_scan_token(FUNCTION_NULL)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_92() { if (jj_3R_103()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_82() { if (jj_scan_token(FUNCTION_FALSE)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_81() { if (jj_scan_token(FUNCTION_TRUE)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_120() { if (jj_3R_128()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_80() { if (jj_scan_token(FUNCTION_NOT)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_79() { if (jj_scan_token(FUNCTION_BOOLEAN)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_78() { if (jj_scan_token(FUNCTION_TRANSLATE)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_77() { if (jj_scan_token(FUNCTION_NORMALIZE_SPACE)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_19() { Token xsp; xsp = jj_scanpos; if (jj_3R_92()) { jj_scanpos = xsp; if (jj_3R_93()) { jj_scanpos = xsp; if (jj_3R_94()) { jj_scanpos = xsp; if (jj_3R_95()) { jj_scanpos = xsp; if (jj_3R_96()) { jj_scanpos = xsp; if (jj_3R_97()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_76() { if (jj_scan_token(FUNCTION_STRING_LENGTH)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_75() { if (jj_scan_token(FUNCTION_SUBSTRING)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_74() { if (jj_scan_token(FUNCTION_SUBSTRING_AFTER)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_73() { if (jj_scan_token(FUNCTION_SUBSTRING_BEFORE)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_72() { if (jj_scan_token(FUNCTION_CONTAINS)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_71() { if (jj_scan_token(FUNCTION_STARTS_WITH)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_70() { if (jj_scan_token(FUNCTION_CONCAT)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_69() { if (jj_scan_token(FUNCTION_STRING)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_68() { if (jj_scan_token(FUNCTION_NAME)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_67() { if (jj_scan_token(FUNCTION_NAMESPACE_URI)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_66() { if (jj_scan_token(FUNCTION_LOCAL_NAME)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } public XPathParserTokenManager token_source; SimpleCharStream jj_input_stream; public Token token, jj_nt; private Token jj_scanpos, jj_lastpos; private int jj_la; public boolean lookingAhead = false; private boolean jj_semLA; private int jj_gen; final private int[] jj_la1 = new int[39]; static private int[] jj_la1_0; static private int[] jj_la1_1; static private int[] jj_la1_2; static { jj_la1_0(); jj_la1_1(); jj_la1_2(); } private static void jj_la1_0() { jj_la1_0 = new int[] {0xf8000000,0x78000000,0x0,0x0,0x78000000,0xf80000c0,0xc0,0x40,0xc0,0xc0,0xf8000000,0xf8000000,0x0,0x0,0x0,0x0,0x160000,0xf8000000,0x0,0xf81604c0,0x100,0xf80000c0,0x0,0xc0,0x8000000,0x10000000,0x1800,0x1800,0x1e000,0x1e000,0x200,0x400,0x60000000,0x60000000,0xf81604c0,0xf8000000,0xf8000000,0x0,0x80000000,}; } private static void jj_la1_1() { jj_la1_1 = new int[] {0xffff0007,0x0,0xffff0000,0x0,0x0,0xffffffff,0x0,0x0,0x0,0x0,0xffff0007,0xffffffff,0x0,0xfff8,0xfff8,0x0,0x0,0xffff0007,0x0,0xffffffff,0x0,0xffffffff,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xffffffff,0xffff0007,0xffff0007,0x0,0x7,}; } private static void jj_la1_2() { jj_la1_2 = new int[] {0x7fff,0x4000,0x3fff,0x8000,0x4000,0x14c7fff,0x0,0x0,0x0,0x0,0x1007fff,0x14c7fff,0x100000,0x0,0x0,0x400000,0x10000,0x7fff,0x800000,0x14d7fff,0x0,0x14c7fff,0x100000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1000000,0x1000000,0x14d7fff,0x1007fff,0x1007fff,0x8000,0x0,}; } final private JJCalls[] jj_2_rtns = new JJCalls[6]; private boolean jj_rescan = false; private int jj_gc = 0; public XPathParser(java.io.InputStream stream) { jj_input_stream = new SimpleCharStream(stream, 1, 1); token_source = new XPathParserTokenManager(jj_input_stream); token = new Token(); token.next = jj_nt = token_source.getNextToken(); jj_gen = 0; for (int i = 0; i < 39; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } public void ReInit(java.io.InputStream stream) { jj_input_stream.ReInit(stream, 1, 1); token_source.ReInit(jj_input_stream); token = new Token(); token.next = jj_nt = token_source.getNextToken(); jj_gen = 0; for (int i = 0; i < 39; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } public XPathParser(java.io.Reader stream) { jj_input_stream = new SimpleCharStream(stream, 1, 1); token_source = new XPathParserTokenManager(jj_input_stream); token = new Token(); token.next = jj_nt = token_source.getNextToken(); jj_gen = 0; for (int i = 0; i < 39; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } public void ReInit(java.io.Reader stream) { jj_input_stream.ReInit(stream, 1, 1); token_source.ReInit(jj_input_stream); token = new Token(); token.next = jj_nt = token_source.getNextToken(); jj_gen = 0; for (int i = 0; i < 39; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } public XPathParser(XPathParserTokenManager tm) { token_source = tm; token = new Token(); token.next = jj_nt = token_source.getNextToken(); jj_gen = 0; for (int i = 0; i < 39; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } public void ReInit(XPathParserTokenManager tm) { token_source = tm; token = new Token(); token.next = jj_nt = token_source.getNextToken(); jj_gen = 0; for (int i = 0; i < 39; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } final private Token jj_consume_token(int kind) throws ParseException { Token oldToken = token; if ((token = jj_nt).next != null) jj_nt = jj_nt.next; else jj_nt = jj_nt.next = token_source.getNextToken(); if (token.kind == kind) { jj_gen++; if (++jj_gc > 100) { jj_gc = 0; for (int i = 0; i < jj_2_rtns.length; i++) { JJCalls c = jj_2_rtns[i]; while (c != null) { if (c.gen < jj_gen) c.first = null; c = c.next; } } } return token; } jj_nt = token; token = oldToken; jj_kind = kind; throw generateParseException(); } final private boolean jj_scan_token(int kind) { if (jj_scanpos == jj_lastpos) { jj_la--; if (jj_scanpos.next == null) { jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken(); } else { jj_lastpos = jj_scanpos = jj_scanpos.next; } } else { jj_scanpos = jj_scanpos.next; } if (jj_rescan) { int i = 0; Token tok = token; while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; } if (tok != null) jj_add_error_token(kind, i); } return (jj_scanpos.kind != kind); } final public Token getNextToken() { if ((token = jj_nt).next != null) jj_nt = jj_nt.next; else jj_nt = jj_nt.next = token_source.getNextToken(); jj_gen++; return token; } final public Token getToken(int index) { Token t = lookingAhead ? jj_scanpos : token; for (int i = 0; i < index; i++) { if (t.next != null) t = t.next; else t = t.next = token_source.getNextToken(); } return t; } private java.util.Vector jj_expentries = new java.util.Vector(); private int[] jj_expentry; private int jj_kind = -1; private int[] jj_lasttokens = new int[100]; private int jj_endpos; private void jj_add_error_token(int kind, int pos) { if (pos >= 100) return; if (pos == jj_endpos + 1) { jj_lasttokens[jj_endpos++] = kind; } else if (jj_endpos != 0) { jj_expentry = new int[jj_endpos]; for (int i = 0; i < jj_endpos; i++) { jj_expentry[i] = jj_lasttokens[i]; } boolean exists = false; for (java.util.Enumeration en = jj_expentries.elements(); en.hasMoreElements();) { int[] oldentry = (int[])(en.nextElement()); if (oldentry.length == jj_expentry.length) { exists = true; for (int i = 0; i < jj_expentry.length; i++) { if (oldentry[i] != jj_expentry[i]) { exists = false; break; } } if (exists) break; } } if (!exists) jj_expentries.addElement(jj_expentry); if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind; } } public ParseException generateParseException() { jj_expentries.removeAllElements(); boolean[] la1tokens = new boolean[89]; for (int i = 0; i < 89; i++) { la1tokens[i] = false; } if (jj_kind >= 0) { la1tokens[jj_kind] = true; jj_kind = -1; } for (int i = 0; i < 39; i++) { if (jj_la1[i] == jj_gen) { for (int j = 0; j < 32; j++) { if ((jj_la1_0[i] & (1< jj_gen) { jj_la = p.arg; jj_lastpos = jj_scanpos = p.first; switch (i) { case 0: jj_3_1(); break; case 1: jj_3_2(); break; case 2: jj_3_3(); break; case 3: jj_3_4(); break; case 4: jj_3_5(); break; case 5: jj_3_6(); break; } } p = p.next; } while (p != null); } jj_rescan = false; } final private void jj_save(int index, int xla) { JJCalls p = jj_2_rtns[index]; while (p.gen > jj_gen) { if (p.next == null) { p = p.next = new JJCalls(); break; } p = p.next; } p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla; } static final class JJCalls { int gen; Token first; int arg; JJCalls next; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/parser/XPathParserConstants.java100644 0 0 7070 11044113541 27576 0ustar 0 0 /* Generated By:JavaCC: Do not edit this line. XPathParserConstants.java */ package org.apache.commons.jxpath.ri.parser; public interface XPathParserConstants { int EOF = 0; int SLASH = 6; int SLASHSLASH = 7; int UNION = 8; int PLUS = 9; int MINUS = 10; int EQ = 11; int NEQ = 12; int LT = 13; int LTE = 14; int GT = 15; int GTE = 16; int VARIABLE = 17; int Literal = 18; int Digit = 19; int Number = 20; int Letter = 21; int BaseChar = 22; int Ideographic = 23; int CombiningChar = 24; int UnicodeDigit = 25; int Extender = 26; int OR = 27; int AND = 28; int MOD = 29; int DIV = 30; int NODE = 31; int TEXT = 32; int COMMENT = 33; int PI = 34; int AXIS_SELF = 35; int AXIS_CHILD = 36; int AXIS_PARENT = 37; int AXIS_ANCESTOR = 38; int AXIS_ATTRIBUTE = 39; int AXIS_NAMESPACE = 40; int AXIS_PRECEDING = 41; int AXIS_FOLLOWING = 42; int AXIS_DESCENDANT = 43; int AXIS_ANCESTOR_OR_SELF = 44; int AXIS_FOLLOWING_SIBLING = 45; int AXIS_PRECEDING_SIBLING = 46; int AXIS_DESCENDANT_OR_SELF = 47; int FUNCTION_LAST = 48; int FUNCTION_POSITION = 49; int FUNCTION_COUNT = 50; int FUNCTION_ID = 51; int FUNCTION_KEY = 52; int FUNCTION_LOCAL_NAME = 53; int FUNCTION_NAMESPACE_URI = 54; int FUNCTION_NAME = 55; int FUNCTION_STRING = 56; int FUNCTION_CONCAT = 57; int FUNCTION_STARTS_WITH = 58; int FUNCTION_CONTAINS = 59; int FUNCTION_SUBSTRING_BEFORE = 60; int FUNCTION_SUBSTRING_AFTER = 61; int FUNCTION_SUBSTRING = 62; int FUNCTION_STRING_LENGTH = 63; int FUNCTION_NORMALIZE_SPACE = 64; int FUNCTION_TRANSLATE = 65; int FUNCTION_BOOLEAN = 66; int FUNCTION_NOT = 67; int FUNCTION_TRUE = 68; int FUNCTION_FALSE = 69; int FUNCTION_NULL = 70; int FUNCTION_LANG = 71; int FUNCTION_NUMBER = 72; int FUNCTION_SUM = 73; int FUNCTION_FLOOR = 74; int FUNCTION_CEILING = 75; int FUNCTION_ROUND = 76; int FUNCTION_FORMAT_NUMBER = 77; int NCName = 78; int DEFAULT = 0; String[] tokenImage = { "", "\" \"", "\"\\t\"", "\"\\n\"", "\"\\r\"", "\"\\f\"", "\"/\"", "\"//\"", "\"|\"", "\"+\"", "\"-\"", "\"=\"", "\"!=\"", "\"<\"", "\"<=\"", "\">\"", "\">=\"", "\"$\"", "", "", "", "", "", "", "", "", "", "\"or\"", "\"and\"", "\"mod\"", "\"div\"", "\"node\"", "\"text\"", "\"comment\"", "\"processing-instruction\"", "\"self::\"", "\"child::\"", "\"parent::\"", "\"ancestor::\"", "\"attribute::\"", "\"namespace::\"", "\"preceding::\"", "\"following::\"", "\"descendant::\"", "\"ancestor-or-self::\"", "\"following-sibling::\"", "\"preceding-sibling::\"", "\"descendant-or-self::\"", "\"last\"", "\"position\"", "\"count\"", "\"id\"", "\"key\"", "\"local-name\"", "\"namespace-uri\"", "\"name\"", "\"string\"", "\"concat\"", "\"starts-with\"", "\"contains\"", "\"substring-before\"", "\"substring-after\"", "\"substring\"", "\"string-length\"", "\"normalize-space\"", "\"translate\"", "\"boolean\"", "\"not\"", "\"true\"", "\"false\"", "\"null\"", "\"lang\"", "\"number\"", "\"sum\"", "\"floor\"", "\"ceiling\"", "\"round\"", "\"format-number\"", "", "\":\"", "\"(\"", "\")\"", "\".\"", "\"..\"", "\"[\"", "\"]\"", "\"@\"", "\",\"", "\"*\"", }; } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/parser/XPathParserTokenManager.java100644 0 0 171675 11044113541 30252 0ustar 0 0 /* Generated By:JavaCC: Do not edit this line. XPathParserTokenManager.java */ package org.apache.commons.jxpath.ri.parser; import org.apache.commons.jxpath.ri.Compiler; import java.util.ArrayList; public class XPathParserTokenManager implements XPathParserConstants { public java.io.PrintStream debugStream = System.out; public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; } private final int jjStopStringLiteralDfa_0(int pos, long active0, long active1) { switch (pos) { case 0: if ((active1 & 0xc0000L) != 0L) return 10; if ((active0 & 0xfffffffff8000000L) != 0L || (active1 & 0x3fffL) != 0L) { jjmatchedKind = 78; return 12; } return -1; case 1: if ((active0 & 0x8000008000000L) != 0L) return 12; if ((active0 & 0xfff7fffff0000000L) != 0L || (active1 & 0x3fffL) != 0L) { jjmatchedKind = 78; jjmatchedPos = 1; return 12; } return -1; case 2: if ((active0 & 0x10000070000000L) != 0L || (active1 & 0x208L) != 0L) return 12; if ((active0 & 0xffe7ffff80000000L) != 0L || (active1 & 0x3df7L) != 0L) { jjmatchedKind = 78; jjmatchedPos = 2; return 12; } return -1; case 3: if ((active0 & 0xc1010180000000L) != 0L || (active1 & 0xd0L) != 0L) return 12; if ((active0 & 0xff26fefe00000000L) != 0L || (active1 & 0x3d27L) != 0L) { if (jjmatchedPos != 3) { jjmatchedKind = 78; jjmatchedPos = 3; } return 12; } return -1; case 4: if ((active0 & 0xff62fff600000000L) != 0L || (active1 & 0x2907L) != 0L) { jjmatchedKind = 78; jjmatchedPos = 4; return 12; } if ((active0 & 0x4000000000000L) != 0L || (active1 & 0x1420L) != 0L) return 12; if ((active0 & 0x800000000L) != 0L) { if (jjmatchedPos < 3) { jjmatchedKind = 78; jjmatchedPos = 3; } return -1; } return -1; case 5: if ((active0 & 0x8300000000000000L) != 0L || (active1 & 0x100L) != 0L) return 12; if ((active0 & 0x7c62ffe600000000L) != 0L || (active1 & 0x2807L) != 0L) { if (jjmatchedPos != 5) { jjmatchedKind = 78; jjmatchedPos = 5; } return 12; } if ((active0 & 0x1000000000L) != 0L) { if (jjmatchedPos < 4) { jjmatchedKind = 78; jjmatchedPos = 4; } return -1; } if ((active0 & 0x800000000L) != 0L) { if (jjmatchedPos < 3) { jjmatchedKind = 78; jjmatchedPos = 3; } return -1; } return -1; case 6: if ((active0 & 0x200000000L) != 0L || (active1 & 0x804L) != 0L) return 12; if ((active0 & 0x2000000000L) != 0L) { if (jjmatchedPos < 5) { jjmatchedKind = 78; jjmatchedPos = 5; } return -1; } if ((active0 & 0x1000000000L) != 0L) { if (jjmatchedPos < 4) { jjmatchedKind = 78; jjmatchedPos = 4; } return -1; } if ((active0 & 0xfc62ffc400000000L) != 0L || (active1 & 0x2003L) != 0L) { jjmatchedKind = 78; jjmatchedPos = 6; return 12; } return -1; case 7: if ((active0 & 0xf460ffc400000000L) != 0L || (active1 & 0x2003L) != 0L) { jjmatchedKind = 78; jjmatchedPos = 7; return 12; } if ((active0 & 0x802000000000000L) != 0L) return 12; if ((active0 & 0x2000000000L) != 0L) { if (jjmatchedPos < 5) { jjmatchedKind = 78; jjmatchedPos = 5; } return -1; } return -1; case 8: if ((active0 & 0x7000000000000000L) != 0L || (active1 & 0x2L) != 0L) return 12; if ((active0 & 0x4000000000L) != 0L) { if (jjmatchedPos < 7) { jjmatchedKind = 78; jjmatchedPos = 7; } return -1; } if ((active0 & 0x8460ff8400000000L) != 0L || (active1 & 0x2001L) != 0L) { if (jjmatchedPos != 8) { jjmatchedKind = 78; jjmatchedPos = 8; } return 12; } return -1; case 9: if ((active0 & 0x20000000000000L) != 0L) return 12; if ((active0 & 0x78000000000L) != 0L) { if (jjmatchedPos < 8) { jjmatchedKind = 78; jjmatchedPos = 8; } return -1; } if ((active0 & 0x4000000000L) != 0L) { if (jjmatchedPos < 7) { jjmatchedKind = 78; jjmatchedPos = 7; } return -1; } if ((active0 & 0xb440f80400000000L) != 0L || (active1 & 0x2001L) != 0L) { jjmatchedKind = 78; jjmatchedPos = 9; return 12; } return -1; case 10: if ((active0 & 0x400000000000000L) != 0L) return 12; if ((active0 & 0x80000000000L) != 0L) { if (jjmatchedPos < 9) { jjmatchedKind = 78; jjmatchedPos = 9; } return -1; } if ((active0 & 0x78000000000L) != 0L) { if (jjmatchedPos < 8) { jjmatchedKind = 78; jjmatchedPos = 8; } return -1; } if ((active0 & 0xb040f00400000000L) != 0L || (active1 & 0x2001L) != 0L) { jjmatchedKind = 78; jjmatchedPos = 10; return 12; } return -1; case 11: if ((active0 & 0xb040f00400000000L) != 0L || (active1 & 0x2001L) != 0L) { jjmatchedKind = 78; jjmatchedPos = 11; return 12; } if ((active0 & 0x80000000000L) != 0L) { if (jjmatchedPos < 9) { jjmatchedKind = 78; jjmatchedPos = 9; } return -1; } return -1; case 12: if ((active0 & 0x8040000000000000L) != 0L || (active1 & 0x2000L) != 0L) return 12; if ((active0 & 0x3000f00400000000L) != 0L || (active1 & 0x1L) != 0L) { jjmatchedKind = 78; jjmatchedPos = 12; return 12; } return -1; case 13: if ((active0 & 0x3000f00400000000L) != 0L || (active1 & 0x1L) != 0L) { jjmatchedKind = 78; jjmatchedPos = 13; return 12; } return -1; case 14: if ((active0 & 0x2000000000000000L) != 0L || (active1 & 0x1L) != 0L) return 12; if ((active0 & 0x1000f00400000000L) != 0L) { jjmatchedKind = 78; jjmatchedPos = 14; return 12; } return -1; case 15: if ((active0 & 0x1000000000000000L) != 0L) return 12; if ((active0 & 0xf00400000000L) != 0L) { jjmatchedKind = 78; jjmatchedPos = 15; return 12; } return -1; case 16: if ((active0 & 0xe00400000000L) != 0L) { jjmatchedKind = 78; jjmatchedPos = 16; return 12; } if ((active0 & 0x100000000000L) != 0L) { if (jjmatchedPos < 15) { jjmatchedKind = 78; jjmatchedPos = 15; } return -1; } return -1; case 17: if ((active0 & 0x600000000000L) != 0L) { if (jjmatchedPos < 16) { jjmatchedKind = 78; jjmatchedPos = 16; } return -1; } if ((active0 & 0x100000000000L) != 0L) { if (jjmatchedPos < 15) { jjmatchedKind = 78; jjmatchedPos = 15; } return -1; } if ((active0 & 0x800400000000L) != 0L) { jjmatchedKind = 78; jjmatchedPos = 17; return 12; } return -1; case 18: if ((active0 & 0x400000000L) != 0L) { jjmatchedKind = 78; jjmatchedPos = 18; return 12; } if ((active0 & 0x800000000000L) != 0L) { if (jjmatchedPos < 17) { jjmatchedKind = 78; jjmatchedPos = 17; } return -1; } if ((active0 & 0x600000000000L) != 0L) { if (jjmatchedPos < 16) { jjmatchedKind = 78; jjmatchedPos = 16; } return -1; } return -1; case 19: if ((active0 & 0x400000000L) != 0L) { jjmatchedKind = 78; jjmatchedPos = 19; return 12; } if ((active0 & 0x800000000000L) != 0L) { if (jjmatchedPos < 17) { jjmatchedKind = 78; jjmatchedPos = 17; } return -1; } return -1; case 20: if ((active0 & 0x400000000L) != 0L) { jjmatchedKind = 78; jjmatchedPos = 20; return 12; } return -1; default : return -1; } } private final int jjStartNfa_0(int pos, long active0, long active1) { return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0, active1), pos + 1); } private final int jjStopAtPos(int pos, int kind) { jjmatchedKind = kind; jjmatchedPos = pos; return pos + 1; } private final int jjStartNfaWithStates_0(int pos, int kind, int state) { jjmatchedKind = kind; jjmatchedPos = pos; try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { return pos + 1; } return jjMoveNfa_0(state, pos + 1); } private final int jjMoveStringLiteralDfa0_0() { switch(curChar) { case 33: return jjMoveStringLiteralDfa1_0(0x1000L, 0x0L); case 36: return jjStopAtPos(0, 17); case 40: return jjStopAtPos(0, 80); case 41: return jjStopAtPos(0, 81); case 42: return jjStopAtPos(0, 88); case 43: return jjStopAtPos(0, 9); case 44: return jjStopAtPos(0, 87); case 45: return jjStopAtPos(0, 10); case 46: jjmatchedKind = 82; return jjMoveStringLiteralDfa1_0(0x0L, 0x80000L); case 47: jjmatchedKind = 6; return jjMoveStringLiteralDfa1_0(0x80L, 0x0L); case 58: return jjStopAtPos(0, 79); case 60: jjmatchedKind = 13; return jjMoveStringLiteralDfa1_0(0x4000L, 0x0L); case 61: return jjStopAtPos(0, 11); case 62: jjmatchedKind = 15; return jjMoveStringLiteralDfa1_0(0x10000L, 0x0L); case 64: return jjStopAtPos(0, 86); case 91: return jjStopAtPos(0, 84); case 93: return jjStopAtPos(0, 85); case 97: return jjMoveStringLiteralDfa1_0(0x10c010000000L, 0x0L); case 98: return jjMoveStringLiteralDfa1_0(0x0L, 0x4L); case 99: return jjMoveStringLiteralDfa1_0(0xa04001200000000L, 0x800L); case 100: return jjMoveStringLiteralDfa1_0(0x880040000000L, 0x0L); case 102: return jjMoveStringLiteralDfa1_0(0x240000000000L, 0x2420L); case 105: return jjMoveStringLiteralDfa1_0(0x8000000000000L, 0x0L); case 107: return jjMoveStringLiteralDfa1_0(0x10000000000000L, 0x0L); case 108: return jjMoveStringLiteralDfa1_0(0x21000000000000L, 0x80L); case 109: return jjMoveStringLiteralDfa1_0(0x20000000L, 0x0L); case 110: return jjMoveStringLiteralDfa1_0(0xc0010080000000L, 0x149L); case 111: return jjMoveStringLiteralDfa1_0(0x8000000L, 0x0L); case 112: return jjMoveStringLiteralDfa1_0(0x2422400000000L, 0x0L); case 114: return jjMoveStringLiteralDfa1_0(0x0L, 0x1000L); case 115: return jjMoveStringLiteralDfa1_0(0xf500000800000000L, 0x200L); case 116: return jjMoveStringLiteralDfa1_0(0x100000000L, 0x12L); case 124: return jjStopAtPos(0, 8); default : return jjMoveNfa_0(0, 0); } } private final int jjMoveStringLiteralDfa1_0(long active0, long active1) { try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { jjStopStringLiteralDfa_0(0, active0, active1); return 1; } switch(curChar) { case 46: if ((active1 & 0x80000L) != 0L) return jjStopAtPos(1, 83); break; case 47: if ((active0 & 0x80L) != 0L) return jjStopAtPos(1, 7); break; case 61: if ((active0 & 0x1000L) != 0L) return jjStopAtPos(1, 12); else if ((active0 & 0x4000L) != 0L) return jjStopAtPos(1, 14); else if ((active0 & 0x10000L) != 0L) return jjStopAtPos(1, 16); break; case 97: return jjMoveStringLiteralDfa2_0(active0, 0xc1012000000000L, active1, 0xa0L); case 100: if ((active0 & 0x8000000000000L) != 0L) return jjStartNfaWithStates_0(1, 51, 12); break; case 101: return jjMoveStringLiteralDfa2_0(active0, 0x10880900000000L, active1, 0x800L); case 104: return jjMoveStringLiteralDfa2_0(active0, 0x1000000000L, active1, 0L); case 105: return jjMoveStringLiteralDfa2_0(active0, 0x40000000L, active1, 0L); case 108: return jjMoveStringLiteralDfa2_0(active0, 0L, active1, 0x400L); case 110: return jjMoveStringLiteralDfa2_0(active0, 0x104010000000L, active1, 0L); case 111: return jjMoveStringLiteralDfa2_0(active0, 0xa262402a0000000L, active1, 0x300dL); case 114: if ((active0 & 0x8000000L) != 0L) return jjStartNfaWithStates_0(1, 27, 12); return jjMoveStringLiteralDfa2_0(active0, 0x420400000000L, active1, 0x12L); case 116: return jjMoveStringLiteralDfa2_0(active0, 0x8500008000000000L, active1, 0L); case 117: return jjMoveStringLiteralDfa2_0(active0, 0x7000000000000000L, active1, 0x340L); default : break; } return jjStartNfa_0(0, active0, active1); } private final int jjMoveStringLiteralDfa2_0(long old0, long active0, long old1, long active1) { if (((active0 &= old0) | (active1 &= old1)) == 0L) return jjStartNfa_0(0, old0, old1); try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { jjStopStringLiteralDfa_0(1, active0, active1); return 2; } switch(curChar) { case 97: return jjMoveStringLiteralDfa3_0(active0, 0x400000000000000L, active1, 0x2L); case 98: return jjMoveStringLiteralDfa3_0(active0, 0x7000000000000000L, active1, 0L); case 99: return jjMoveStringLiteralDfa3_0(active0, 0x20104000000000L, active1, 0L); case 100: if ((active0 & 0x10000000L) != 0L) return jjStartNfaWithStates_0(2, 28, 12); else if ((active0 & 0x20000000L) != 0L) return jjStartNfaWithStates_0(2, 29, 12); return jjMoveStringLiteralDfa3_0(active0, 0x80000000L, active1, 0L); case 101: return jjMoveStringLiteralDfa3_0(active0, 0x420000000000L, active1, 0L); case 105: return jjMoveStringLiteralDfa3_0(active0, 0x1000000000L, active1, 0x800L); case 108: return jjMoveStringLiteralDfa3_0(active0, 0x240800000000L, active1, 0x60L); case 109: if ((active1 & 0x200L) != 0L) return jjStartNfaWithStates_0(2, 73, 12); return jjMoveStringLiteralDfa3_0(active0, 0xc0010200000000L, active1, 0x100L); case 110: return jjMoveStringLiteralDfa3_0(active0, 0xa00000000000000L, active1, 0x80L); case 111: return jjMoveStringLiteralDfa3_0(active0, 0x400000000L, active1, 0x404L); case 114: return jjMoveStringLiteralDfa3_0(active0, 0x8100002000000000L, active1, 0x2001L); case 115: return jjMoveStringLiteralDfa3_0(active0, 0x3880000000000L, active1, 0L); case 116: if ((active1 & 0x8L) != 0L) return jjStartNfaWithStates_0(2, 67, 12); return jjMoveStringLiteralDfa3_0(active0, 0x8000000000L, active1, 0L); case 117: return jjMoveStringLiteralDfa3_0(active0, 0x4000000000000L, active1, 0x1010L); case 118: if ((active0 & 0x40000000L) != 0L) return jjStartNfaWithStates_0(2, 30, 12); break; case 120: return jjMoveStringLiteralDfa3_0(active0, 0x100000000L, active1, 0L); case 121: if ((active0 & 0x10000000000000L) != 0L) return jjStartNfaWithStates_0(2, 52, 12); break; default : break; } return jjStartNfa_0(1, active0, active1); } private final int jjMoveStringLiteralDfa3_0(long old0, long active0, long old1, long active1) { if (((active0 &= old0) | (active1 &= old1)) == 0L) return jjStartNfa_0(1, old0, old1); try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { jjStopStringLiteralDfa_0(2, active0, active1); return 3; } switch(curChar) { case 97: return jjMoveStringLiteralDfa4_0(active0, 0x20000000000000L, active1, 0L); case 98: return jjMoveStringLiteralDfa4_0(active0, 0L, active1, 0x100L); case 99: return jjMoveStringLiteralDfa4_0(active0, 0x200ca0400000000L, active1, 0L); case 101: if ((active0 & 0x80000000L) != 0L) return jjStartNfaWithStates_0(3, 31, 12); else if ((active0 & 0x80000000000000L) != 0L) { jjmatchedKind = 55; jjmatchedPos = 3; } else if ((active1 & 0x10L) != 0L) return jjStartNfaWithStates_0(3, 68, 12); return jjMoveStringLiteralDfa4_0(active0, 0x40116000000000L, active1, 0L); case 102: return jjMoveStringLiteralDfa4_0(active0, 0x800000000L, active1, 0L); case 103: if ((active1 & 0x80L) != 0L) return jjStartNfaWithStates_0(3, 71, 12); break; case 105: return jjMoveStringLiteralDfa4_0(active0, 0x8102000000000000L, active1, 0L); case 108: if ((active1 & 0x40L) != 0L) return jjStartNfaWithStates_0(3, 70, 12); return jjMoveStringLiteralDfa4_0(active0, 0x241000000000L, active1, 0x804L); case 109: return jjMoveStringLiteralDfa4_0(active0, 0x200000000L, active1, 0x2001L); case 110: return jjMoveStringLiteralDfa4_0(active0, 0x4000000000000L, active1, 0x1002L); case 111: return jjMoveStringLiteralDfa4_0(active0, 0L, active1, 0x400L); case 114: return jjMoveStringLiteralDfa4_0(active0, 0x400008000000000L, active1, 0L); case 115: return jjMoveStringLiteralDfa4_0(active0, 0x7000000000000000L, active1, 0x20L); case 116: if ((active0 & 0x100000000L) != 0L) return jjStartNfaWithStates_0(3, 32, 12); else if ((active0 & 0x1000000000000L) != 0L) return jjStartNfaWithStates_0(3, 48, 12); return jjMoveStringLiteralDfa4_0(active0, 0x800000000000000L, active1, 0L); default : break; } return jjStartNfa_0(2, active0, active1); } private final int jjMoveStringLiteralDfa4_0(long old0, long active0, long old1, long active1) { if (((active0 &= old0) | (active1 &= old1)) == 0L) return jjStartNfa_0(2, old0, old1); try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { jjStopStringLiteralDfa_0(3, active0, active1); return 4; } switch(curChar) { case 58: return jjMoveStringLiteralDfa5_0(active0, 0x800000000L, active1, 0L); case 97: return jjMoveStringLiteralDfa5_0(active0, 0xa00000000000000L, active1, 0x2001L); case 100: if ((active1 & 0x1000L) != 0L) return jjStartNfaWithStates_0(4, 76, 12); return jjMoveStringLiteralDfa5_0(active0, 0x1000000000L, active1, 0L); case 101: if ((active1 & 0x20L) != 0L) return jjStartNfaWithStates_0(4, 69, 12); return jjMoveStringLiteralDfa5_0(active0, 0xca0600000000L, active1, 0x104L); case 105: return jjMoveStringLiteralDfa5_0(active0, 0x8000000000L, active1, 0x800L); case 108: return jjMoveStringLiteralDfa5_0(active0, 0x20000000000000L, active1, 0L); case 110: return jjMoveStringLiteralDfa5_0(active0, 0x8100002000000000L, active1, 0L); case 111: return jjMoveStringLiteralDfa5_0(active0, 0x240000000000L, active1, 0L); case 114: if ((active1 & 0x400L) != 0L) return jjStartNfaWithStates_0(4, 74, 12); break; case 115: return jjMoveStringLiteralDfa5_0(active0, 0x40114000000000L, active1, 0x2L); case 116: if ((active0 & 0x4000000000000L) != 0L) return jjStartNfaWithStates_0(4, 50, 12); return jjMoveStringLiteralDfa5_0(active0, 0x7402000000000000L, active1, 0L); default : break; } return jjStartNfa_0(3, active0, active1); } private final int jjMoveStringLiteralDfa5_0(long old0, long active0, long old1, long active1) { if (((active0 &= old0) | (active1 &= old1)) == 0L) return jjStartNfa_0(3, old0, old1); try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { jjStopStringLiteralDfa_0(4, active0, active1); return 5; } switch(curChar) { case 45: return jjMoveStringLiteralDfa6_0(active0, 0x20000000000000L, active1, 0L); case 58: if ((active0 & 0x800000000L) != 0L) return jjStopAtPos(5, 35); return jjMoveStringLiteralDfa6_0(active0, 0x1000000000L, active1, 0L); case 97: return jjMoveStringLiteralDfa6_0(active0, 0L, active1, 0x4L); case 98: return jjMoveStringLiteralDfa6_0(active0, 0x8000000000L, active1, 0L); case 100: return jjMoveStringLiteralDfa6_0(active0, 0x420000000000L, active1, 0L); case 103: if ((active0 & 0x100000000000000L) != 0L) { jjmatchedKind = 56; jjmatchedPos = 5; } return jjMoveStringLiteralDfa6_0(active0, 0x8000000000000000L, active1, 0L); case 105: return jjMoveStringLiteralDfa6_0(active0, 0x802000000000000L, active1, 0L); case 108: return jjMoveStringLiteralDfa6_0(active0, 0L, active1, 0x3L); case 110: return jjMoveStringLiteralDfa6_0(active0, 0x880200000000L, active1, 0x800L); case 112: return jjMoveStringLiteralDfa6_0(active0, 0x40010000000000L, active1, 0L); case 114: if ((active1 & 0x100L) != 0L) return jjStartNfaWithStates_0(5, 72, 12); return jjMoveStringLiteralDfa6_0(active0, 0x7000000000000000L, active1, 0L); case 115: return jjMoveStringLiteralDfa6_0(active0, 0x400000400000000L, active1, 0L); case 116: if ((active0 & 0x200000000000000L) != 0L) return jjStartNfaWithStates_0(5, 57, 12); return jjMoveStringLiteralDfa6_0(active0, 0x106000000000L, active1, 0x2000L); case 119: return jjMoveStringLiteralDfa6_0(active0, 0x240000000000L, active1, 0L); default : break; } return jjStartNfa_0(4, active0, active1); } private final int jjMoveStringLiteralDfa6_0(long old0, long active0, long old1, long active1) { if (((active0 &= old0) | (active1 &= old1)) == 0L) return jjStartNfa_0(4, old0, old1); try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { jjStopStringLiteralDfa_0(5, active0, active1); return 6; } switch(curChar) { case 45: return jjMoveStringLiteralDfa7_0(active0, 0x8400000000000000L, active1, 0x2000L); case 58: if ((active0 & 0x1000000000L) != 0L) return jjStopAtPos(6, 36); return jjMoveStringLiteralDfa7_0(active0, 0x2000000000L, active1, 0L); case 97: return jjMoveStringLiteralDfa7_0(active0, 0x40010000000000L, active1, 0x2L); case 100: return jjMoveStringLiteralDfa7_0(active0, 0x880000000000L, active1, 0L); case 103: if ((active1 & 0x800L) != 0L) return jjStartNfaWithStates_0(6, 75, 12); break; case 105: return jjMoveStringLiteralDfa7_0(active0, 0x7000660000000000L, active1, 0x1L); case 110: if ((active1 & 0x4L) != 0L) return jjStartNfaWithStates_0(6, 66, 12); return jjMoveStringLiteralDfa7_0(active0, 0x820000000000000L, active1, 0L); case 111: return jjMoveStringLiteralDfa7_0(active0, 0x2104000000000L, active1, 0L); case 115: return jjMoveStringLiteralDfa7_0(active0, 0x400000000L, active1, 0L); case 116: if ((active0 & 0x200000000L) != 0L) return jjStartNfaWithStates_0(6, 33, 12); break; case 117: return jjMoveStringLiteralDfa7_0(active0, 0x8000000000L, active1, 0L); default : break; } return jjStartNfa_0(5, active0, active1); } private final int jjMoveStringLiteralDfa7_0(long old0, long active0, long old1, long active1) { if (((active0 &= old0) | (active1 &= old1)) == 0L) return jjStartNfa_0(5, old0, old1); try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { jjStopStringLiteralDfa_0(6, active0, active1); return 7; } switch(curChar) { case 58: if ((active0 & 0x2000000000L) != 0L) return jjStopAtPos(7, 37); break; case 97: return jjMoveStringLiteralDfa8_0(active0, 0x20880000000000L, active1, 0L); case 99: return jjMoveStringLiteralDfa8_0(active0, 0x40010000000000L, active1, 0L); case 105: return jjMoveStringLiteralDfa8_0(active0, 0x400000000L, active1, 0L); case 108: return jjMoveStringLiteralDfa8_0(active0, 0x8000000000000000L, active1, 0L); case 110: if ((active0 & 0x2000000000000L) != 0L) return jjStartNfaWithStates_0(7, 49, 12); return jjMoveStringLiteralDfa8_0(active0, 0x7000660000000000L, active1, 0x2000L); case 114: return jjMoveStringLiteralDfa8_0(active0, 0x104000000000L, active1, 0L); case 115: if ((active0 & 0x800000000000000L) != 0L) return jjStartNfaWithStates_0(7, 59, 12); break; case 116: return jjMoveStringLiteralDfa8_0(active0, 0x8000000000L, active1, 0x2L); case 119: return jjMoveStringLiteralDfa8_0(active0, 0x400000000000000L, active1, 0L); case 122: return jjMoveStringLiteralDfa8_0(active0, 0L, active1, 0x1L); default : break; } return jjStartNfa_0(6, active0, active1); } private final int jjMoveStringLiteralDfa8_0(long old0, long active0, long old1, long active1) { if (((active0 &= old0) | (active1 &= old1)) == 0L) return jjStartNfa_0(6, old0, old1); try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { jjStopStringLiteralDfa_0(7, active0, active1); return 8; } switch(curChar) { case 45: return jjMoveStringLiteralDfa9_0(active0, 0x100000000000L, active1, 0L); case 58: return jjMoveStringLiteralDfa9_0(active0, 0x4000000000L, active1, 0L); case 101: if ((active1 & 0x2L) != 0L) return jjStartNfaWithStates_0(8, 65, 12); return jjMoveStringLiteralDfa9_0(active0, 0x8040018000000000L, active1, 0x1L); case 103: if ((active0 & 0x4000000000000000L) != 0L) { jjmatchedKind = 62; jjmatchedPos = 8; } return jjMoveStringLiteralDfa9_0(active0, 0x3000660000000000L, active1, 0L); case 105: return jjMoveStringLiteralDfa9_0(active0, 0x400000000000000L, active1, 0L); case 109: return jjMoveStringLiteralDfa9_0(active0, 0x20000000000000L, active1, 0L); case 110: return jjMoveStringLiteralDfa9_0(active0, 0x880400000000L, active1, 0L); case 117: return jjMoveStringLiteralDfa9_0(active0, 0L, active1, 0x2000L); default : break; } return jjStartNfa_0(7, active0, active1); } private final int jjMoveStringLiteralDfa9_0(long old0, long active0, long old1, long active1) { if (((active0 &= old0) | (active1 &= old1)) == 0L) return jjStartNfa_0(7, old0, old1); try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { jjStopStringLiteralDfa_0(8, active0, active1); return 9; } switch(curChar) { case 45: return jjMoveStringLiteralDfa10_0(active0, 0x3040600000000000L, active1, 0x1L); case 58: if ((active0 & 0x4000000000L) != 0L) return jjStopAtPos(9, 38); return jjMoveStringLiteralDfa10_0(active0, 0x78000000000L, active1, 0L); case 101: if ((active0 & 0x20000000000000L) != 0L) return jjStartNfaWithStates_0(9, 53, 12); break; case 103: return jjMoveStringLiteralDfa10_0(active0, 0x400000000L, active1, 0L); case 109: return jjMoveStringLiteralDfa10_0(active0, 0L, active1, 0x2000L); case 110: return jjMoveStringLiteralDfa10_0(active0, 0x8000000000000000L, active1, 0L); case 111: return jjMoveStringLiteralDfa10_0(active0, 0x100000000000L, active1, 0L); case 116: return jjMoveStringLiteralDfa10_0(active0, 0x400880000000000L, active1, 0L); default : break; } return jjStartNfa_0(8, active0, active1); } private final int jjMoveStringLiteralDfa10_0(long old0, long active0, long old1, long active1) { if (((active0 &= old0) | (active1 &= old1)) == 0L) return jjStartNfa_0(8, old0, old1); try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { jjStopStringLiteralDfa_0(9, active0, active1); return 10; } switch(curChar) { case 45: return jjMoveStringLiteralDfa11_0(active0, 0x800400000000L, active1, 0L); case 58: if ((active0 & 0x8000000000L) != 0L) return jjStopAtPos(10, 39); else if ((active0 & 0x10000000000L) != 0L) return jjStopAtPos(10, 40); else if ((active0 & 0x20000000000L) != 0L) return jjStopAtPos(10, 41); else if ((active0 & 0x40000000000L) != 0L) return jjStopAtPos(10, 42); return jjMoveStringLiteralDfa11_0(active0, 0x80000000000L, active1, 0L); case 97: return jjMoveStringLiteralDfa11_0(active0, 0x2000000000000000L, active1, 0L); case 98: return jjMoveStringLiteralDfa11_0(active0, 0x1000000000000000L, active1, 0x2000L); case 103: return jjMoveStringLiteralDfa11_0(active0, 0x8000000000000000L, active1, 0L); case 104: if ((active0 & 0x400000000000000L) != 0L) return jjStartNfaWithStates_0(10, 58, 12); break; case 114: return jjMoveStringLiteralDfa11_0(active0, 0x100000000000L, active1, 0L); case 115: return jjMoveStringLiteralDfa11_0(active0, 0x600000000000L, active1, 0x1L); case 117: return jjMoveStringLiteralDfa11_0(active0, 0x40000000000000L, active1, 0L); default : break; } return jjStartNfa_0(9, active0, active1); } private final int jjMoveStringLiteralDfa11_0(long old0, long active0, long old1, long active1) { if (((active0 &= old0) | (active1 &= old1)) == 0L) return jjStartNfa_0(9, old0, old1); try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { jjStopStringLiteralDfa_0(10, active0, active1); return 11; } switch(curChar) { case 45: return jjMoveStringLiteralDfa12_0(active0, 0x100000000000L, active1, 0L); case 58: if ((active0 & 0x80000000000L) != 0L) return jjStopAtPos(11, 43); break; case 101: return jjMoveStringLiteralDfa12_0(active0, 0x1000000000000000L, active1, 0x2000L); case 102: return jjMoveStringLiteralDfa12_0(active0, 0x2000000000000000L, active1, 0L); case 105: return jjMoveStringLiteralDfa12_0(active0, 0x600400000000L, active1, 0L); case 111: return jjMoveStringLiteralDfa12_0(active0, 0x800000000000L, active1, 0L); case 112: return jjMoveStringLiteralDfa12_0(active0, 0L, active1, 0x1L); case 114: return jjMoveStringLiteralDfa12_0(active0, 0x40000000000000L, active1, 0L); case 116: return jjMoveStringLiteralDfa12_0(active0, 0x8000000000000000L, active1, 0L); default : break; } return jjStartNfa_0(10, active0, active1); } private final int jjMoveStringLiteralDfa12_0(long old0, long active0, long old1, long active1) { if (((active0 &= old0) | (active1 &= old1)) == 0L) return jjStartNfa_0(10, old0, old1); try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { jjStopStringLiteralDfa_0(11, active0, active1); return 12; } switch(curChar) { case 97: return jjMoveStringLiteralDfa13_0(active0, 0L, active1, 0x1L); case 98: return jjMoveStringLiteralDfa13_0(active0, 0x600000000000L, active1, 0L); case 102: return jjMoveStringLiteralDfa13_0(active0, 0x1000000000000000L, active1, 0L); case 104: if ((active0 & 0x8000000000000000L) != 0L) return jjStartNfaWithStates_0(12, 63, 12); break; case 105: if ((active0 & 0x40000000000000L) != 0L) return jjStartNfaWithStates_0(12, 54, 12); break; case 110: return jjMoveStringLiteralDfa13_0(active0, 0x400000000L, active1, 0L); case 114: if ((active1 & 0x2000L) != 0L) return jjStartNfaWithStates_0(12, 77, 12); return jjMoveStringLiteralDfa13_0(active0, 0x800000000000L, active1, 0L); case 115: return jjMoveStringLiteralDfa13_0(active0, 0x100000000000L, active1, 0L); case 116: return jjMoveStringLiteralDfa13_0(active0, 0x2000000000000000L, active1, 0L); default : break; } return jjStartNfa_0(11, active0, active1); } private final int jjMoveStringLiteralDfa13_0(long old0, long active0, long old1, long active1) { if (((active0 &= old0) | (active1 &= old1)) == 0L) return jjStartNfa_0(11, old0, old1); try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { jjStopStringLiteralDfa_0(12, active0, active1); return 13; } switch(curChar) { case 45: return jjMoveStringLiteralDfa14_0(active0, 0x800000000000L, active1, 0L); case 99: return jjMoveStringLiteralDfa14_0(active0, 0L, active1, 0x1L); case 101: return jjMoveStringLiteralDfa14_0(active0, 0x2000100000000000L, active1, 0L); case 108: return jjMoveStringLiteralDfa14_0(active0, 0x600000000000L, active1, 0L); case 111: return jjMoveStringLiteralDfa14_0(active0, 0x1000000000000000L, active1, 0L); case 115: return jjMoveStringLiteralDfa14_0(active0, 0x400000000L, active1, 0L); default : break; } return jjStartNfa_0(12, active0, active1); } private final int jjMoveStringLiteralDfa14_0(long old0, long active0, long old1, long active1) { if (((active0 &= old0) | (active1 &= old1)) == 0L) return jjStartNfa_0(12, old0, old1); try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { jjStopStringLiteralDfa_0(13, active0, active1); return 14; } switch(curChar) { case 101: if ((active1 & 0x1L) != 0L) return jjStartNfaWithStates_0(14, 64, 12); break; case 105: return jjMoveStringLiteralDfa15_0(active0, 0x600000000000L, active1, 0L); case 108: return jjMoveStringLiteralDfa15_0(active0, 0x100000000000L, active1, 0L); case 114: if ((active0 & 0x2000000000000000L) != 0L) return jjStartNfaWithStates_0(14, 61, 12); return jjMoveStringLiteralDfa15_0(active0, 0x1000000000000000L, active1, 0L); case 115: return jjMoveStringLiteralDfa15_0(active0, 0x800000000000L, active1, 0L); case 116: return jjMoveStringLiteralDfa15_0(active0, 0x400000000L, active1, 0L); default : break; } return jjStartNfa_0(13, active0, active1); } private final int jjMoveStringLiteralDfa15_0(long old0, long active0, long old1, long active1) { if (((active0 &= old0) | (active1 &= old1)) == 0L) return jjStartNfa_0(13, old0, old1); try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { jjStopStringLiteralDfa_0(14, active0, 0L); return 15; } switch(curChar) { case 101: if ((active0 & 0x1000000000000000L) != 0L) return jjStartNfaWithStates_0(15, 60, 12); return jjMoveStringLiteralDfa16_0(active0, 0x800000000000L); case 102: return jjMoveStringLiteralDfa16_0(active0, 0x100000000000L); case 110: return jjMoveStringLiteralDfa16_0(active0, 0x600000000000L); case 114: return jjMoveStringLiteralDfa16_0(active0, 0x400000000L); default : break; } return jjStartNfa_0(14, active0, 0L); } private final int jjMoveStringLiteralDfa16_0(long old0, long active0) { if (((active0 &= old0)) == 0L) return jjStartNfa_0(14, old0, 0L); try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { jjStopStringLiteralDfa_0(15, active0, 0L); return 16; } switch(curChar) { case 58: return jjMoveStringLiteralDfa17_0(active0, 0x100000000000L); case 103: return jjMoveStringLiteralDfa17_0(active0, 0x600000000000L); case 108: return jjMoveStringLiteralDfa17_0(active0, 0x800000000000L); case 117: return jjMoveStringLiteralDfa17_0(active0, 0x400000000L); default : break; } return jjStartNfa_0(15, active0, 0L); } private final int jjMoveStringLiteralDfa17_0(long old0, long active0) { if (((active0 &= old0)) == 0L) return jjStartNfa_0(15, old0, 0L); try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { jjStopStringLiteralDfa_0(16, active0, 0L); return 17; } switch(curChar) { case 58: if ((active0 & 0x100000000000L) != 0L) return jjStopAtPos(17, 44); return jjMoveStringLiteralDfa18_0(active0, 0x600000000000L); case 99: return jjMoveStringLiteralDfa18_0(active0, 0x400000000L); case 102: return jjMoveStringLiteralDfa18_0(active0, 0x800000000000L); default : break; } return jjStartNfa_0(16, active0, 0L); } private final int jjMoveStringLiteralDfa18_0(long old0, long active0) { if (((active0 &= old0)) == 0L) return jjStartNfa_0(16, old0, 0L); try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { jjStopStringLiteralDfa_0(17, active0, 0L); return 18; } switch(curChar) { case 58: if ((active0 & 0x200000000000L) != 0L) return jjStopAtPos(18, 45); else if ((active0 & 0x400000000000L) != 0L) return jjStopAtPos(18, 46); return jjMoveStringLiteralDfa19_0(active0, 0x800000000000L); case 116: return jjMoveStringLiteralDfa19_0(active0, 0x400000000L); default : break; } return jjStartNfa_0(17, active0, 0L); } private final int jjMoveStringLiteralDfa19_0(long old0, long active0) { if (((active0 &= old0)) == 0L) return jjStartNfa_0(17, old0, 0L); try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { jjStopStringLiteralDfa_0(18, active0, 0L); return 19; } switch(curChar) { case 58: if ((active0 & 0x800000000000L) != 0L) return jjStopAtPos(19, 47); break; case 105: return jjMoveStringLiteralDfa20_0(active0, 0x400000000L); default : break; } return jjStartNfa_0(18, active0, 0L); } private final int jjMoveStringLiteralDfa20_0(long old0, long active0) { if (((active0 &= old0)) == 0L) return jjStartNfa_0(18, old0, 0L); try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { jjStopStringLiteralDfa_0(19, active0, 0L); return 20; } switch(curChar) { case 111: return jjMoveStringLiteralDfa21_0(active0, 0x400000000L); default : break; } return jjStartNfa_0(19, active0, 0L); } private final int jjMoveStringLiteralDfa21_0(long old0, long active0) { if (((active0 &= old0)) == 0L) return jjStartNfa_0(19, old0, 0L); try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { jjStopStringLiteralDfa_0(20, active0, 0L); return 21; } switch(curChar) { case 110: if ((active0 & 0x400000000L) != 0L) return jjStartNfaWithStates_0(21, 34, 12); break; default : break; } return jjStartNfa_0(20, active0, 0L); } private final void jjCheckNAdd(int state) { if (jjrounds[state] != jjround) { jjstateSet[jjnewStateCnt++] = state; jjrounds[state] = jjround; } } private final void jjAddStates(int start, int end) { do { jjstateSet[jjnewStateCnt++] = jjnextStates[start]; } while (start++ != end); } private final void jjCheckNAddTwoStates(int state1, int state2) { jjCheckNAdd(state1); jjCheckNAdd(state2); } private final void jjCheckNAddStates(int start, int end) { do { jjCheckNAdd(jjnextStates[start]); } while (start++ != end); } private final void jjCheckNAddStates(int start) { jjCheckNAdd(jjnextStates[start]); jjCheckNAdd(jjnextStates[start + 1]); } static final long[] jjbitVec0 = { 0xfffffffffffffffeL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL }; static final long[] jjbitVec2 = { 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL }; static final long[] jjbitVec3 = { 0x0L, 0xffffffffffffc000L, 0xfffff0007fffffffL, 0x7fffffL }; static final long[] jjbitVec4 = { 0x0L, 0x0L, 0x0L, 0xff7fffffff7fffffL }; static final long[] jjbitVec5 = { 0x7ff3ffffffffffffL, 0x7ffffffffffffdfeL, 0xffffffffffffffffL, 0xfc31ffffffffe00fL }; static final long[] jjbitVec6 = { 0xffffffL, 0xffffffffffff0000L, 0xf80001ffffffffffL, 0x3L }; static final long[] jjbitVec7 = { 0x0L, 0x0L, 0xfffffffbffffd740L, 0xffffd547f7fffL }; static final long[] jjbitVec8 = { 0xffffffffffffdffeL, 0xffffffffdffeffffL, 0xffffffffffff0003L, 0x33fcfffffff199fL }; static final long[] jjbitVec9 = { 0xfffe000000000000L, 0xfffffffe027fffffL, 0x7fL, 0x707ffffff0000L }; static final long[] jjbitVec10 = { 0x7fffffe00000000L, 0xfffe0000000007feL, 0x7cffffffffffffffL, 0x60002f7fffL }; static final long[] jjbitVec11 = { 0x23ffffffffffffe0L, 0x3ff000000L, 0x3c5fdfffff99fe0L, 0x30003b0000000L }; static final long[] jjbitVec12 = { 0x36dfdfffff987e0L, 0x1c00005e000000L, 0x23edfdfffffbafe0L, 0x100000000L }; static final long[] jjbitVec13 = { 0x23cdfdfffff99fe0L, 0x3b0000000L, 0x3bfc718d63dc7e0L, 0x0L }; static final long[] jjbitVec14 = { 0x3effdfffffddfe0L, 0x300000000L, 0x3effdfffffddfe0L, 0x340000000L }; static final long[] jjbitVec15 = { 0x3fffdfffffddfe0L, 0x300000000L, 0x0L, 0x0L }; static final long[] jjbitVec16 = { 0xd7ffffffffffeL, 0x3fL, 0x200d6caefef02596L, 0x1fL }; static final long[] jjbitVec17 = { 0x0L, 0x3fffffffeffL, 0x0L, 0x0L }; static final long[] jjbitVec18 = { 0x0L, 0x0L, 0xffffffff00000000L, 0x7fffffffff003fL }; static final long[] jjbitVec19 = { 0x500000000007daedL, 0x2c62ab82315001L, 0xf580c90040000000L, 0x201080000000007L }; static final long[] jjbitVec20 = { 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffff0fffffffL, 0x3ffffffffffffffL }; static final long[] jjbitVec21 = { 0xffffffff3f3fffffL, 0x3fffffffaaff3f3fL, 0x5fdfffffffffffffL, 0x1fdc1fff0fcf1fdcL }; static final long[] jjbitVec22 = { 0x4c4000000000L, 0x0L, 0x7L, 0x0L }; static final long[] jjbitVec23 = { 0x3fe00000080L, 0xfffffffffffffffeL, 0xfffffffe001fffffL, 0x7ffffffffffffffL }; static final long[] jjbitVec24 = { 0x1fffffffffe0L, 0x0L, 0x0L, 0x0L }; static final long[] jjbitVec25 = { 0xffffffffffffffffL, 0xffffffffffffffffL, 0x3fffffffffL, 0x0L }; static final long[] jjbitVec26 = { 0xffffffffffffffffL, 0xffffffffffffffffL, 0xfffffffffL, 0x0L }; static final long[] jjbitVec27 = { 0x0L, 0x0L, 0x80000000000000L, 0xff7fffffff7fffffL }; static final long[] jjbitVec28 = { 0xffffffL, 0xffffffffffff0000L, 0xf80001ffffffffffL, 0x30003L }; static final long[] jjbitVec29 = { 0xffffffffffffffffL, 0x30000003fL, 0xfffffffbffffd7c0L, 0xffffd547f7fffL }; static final long[] jjbitVec30 = { 0xffffffffffffdffeL, 0xffffffffdffeffffL, 0xffffffffffff007bL, 0x33fcfffffff199fL }; static final long[] jjbitVec31 = { 0xfffe000000000000L, 0xfffffffe027fffffL, 0xbbfffffbfffe007fL, 0x707ffffff0016L }; static final long[] jjbitVec32 = { 0x7fffffe00000000L, 0xffff03ff0007ffffL, 0x7cffffffffffffffL, 0x3ff3dffffef7fffL }; static final long[] jjbitVec33 = { 0xf3ffffffffffffeeL, 0xffcfff1e3fffL, 0xd3c5fdfffff99feeL, 0x3ffcfb080399fL }; static final long[] jjbitVec34 = { 0xd36dfdfffff987e4L, 0x1fffc05e003987L, 0xf3edfdfffffbafeeL, 0xffc100003bbfL }; static final long[] jjbitVec35 = { 0xf3cdfdfffff99feeL, 0xffc3b0c0398fL, 0xc3bfc718d63dc7ecL, 0xff8000803dc7L }; static final long[] jjbitVec36 = { 0xc3effdfffffddfeeL, 0xffc300603ddfL, 0xc3effdfffffddfecL, 0xffc340603ddfL }; static final long[] jjbitVec37 = { 0xc3fffdfffffddfecL, 0xffc300803dcfL, 0x0L, 0x0L }; static final long[] jjbitVec38 = { 0x7ff7ffffffffffeL, 0x3ff7fffL, 0x3bff6caefef02596L, 0x3ff3f5fL }; static final long[] jjbitVec39 = { 0xc2a003ff03000000L, 0xfffe03fffffffeffL, 0x2fe3ffffebf0fdfL, 0x0L }; static final long[] jjbitVec40 = { 0x0L, 0x0L, 0x0L, 0x21fff0000L }; static final long[] jjbitVec41 = { 0x3efffe000000a0L, 0xfffffffffffffffeL, 0xfffffffe661fffffL, 0x77ffffffffffffffL }; private final int jjMoveNfa_0(int startState, int curPos) { int[] nextStates; int startsAt = 0; jjnewStateCnt = 13; int i = 1; jjstateSet[0] = startState; int j, kind = 0x7fffffff; for (;;) { if (++jjround == 0x7fffffff) ReInitRounds(); if (curChar < 64) { long l = 1L << curChar; MatchLoop: do { switch(jjstateSet[--i]) { case 0: if ((0x3ff000000000000L & l) != 0L) { if (kind > 20) kind = 20; jjCheckNAddTwoStates(6, 7); } else if (curChar == 46) jjCheckNAdd(10); else if (curChar == 39) jjCheckNAddTwoStates(4, 5); else if (curChar == 34) jjCheckNAddTwoStates(1, 2); break; case 1: if ((0xfffffffbffffffffL & l) != 0L) jjCheckNAddTwoStates(1, 2); break; case 2: if (curChar == 34 && kind > 18) kind = 18; break; case 3: if (curChar == 39) jjCheckNAddTwoStates(4, 5); break; case 4: if ((0xffffff7fffffffffL & l) != 0L) jjCheckNAddTwoStates(4, 5); break; case 5: if (curChar == 39 && kind > 18) kind = 18; break; case 6: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 20) kind = 20; jjCheckNAddTwoStates(6, 7); break; case 7: if (curChar != 46) break; if (kind > 20) kind = 20; jjCheckNAdd(8); break; case 8: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 20) kind = 20; jjCheckNAdd(8); break; case 9: if (curChar == 46) jjCheckNAdd(10); break; case 10: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 20) kind = 20; jjCheckNAdd(10); break; case 12: if ((0x3ff600000000000L & l) == 0L) break; if (kind > 78) kind = 78; jjstateSet[jjnewStateCnt++] = 12; break; default : break; } } while(i != startsAt); } else if (curChar < 128) { long l = 1L << (curChar & 077); MatchLoop: do { switch(jjstateSet[--i]) { case 0: case 12: if ((0x7fffffe87fffffeL & l) == 0L) break; if (kind > 78) kind = 78; jjCheckNAdd(12); break; case 1: jjAddStates(0, 1); break; case 4: jjAddStates(2, 3); break; default : break; } } while(i != startsAt); } else { int hiByte = (int)(curChar >> 8); int i1 = hiByte >> 6; long l1 = 1L << (hiByte & 077); int i2 = (curChar & 0xff) >> 6; long l2 = 1L << (curChar & 077); MatchLoop: do { switch(jjstateSet[--i]) { case 0: if (!jjCanMove_1(hiByte, i1, i2, l1, l2)) break; if (kind > 78) kind = 78; jjCheckNAdd(12); break; case 1: if (jjCanMove_0(hiByte, i1, i2, l1, l2)) jjAddStates(0, 1); break; case 4: if (jjCanMove_0(hiByte, i1, i2, l1, l2)) jjAddStates(2, 3); break; case 12: if (!jjCanMove_2(hiByte, i1, i2, l1, l2)) break; if (kind > 78) kind = 78; jjCheckNAdd(12); break; default : break; } } while(i != startsAt); } if (kind != 0x7fffffff) { jjmatchedKind = kind; jjmatchedPos = curPos; kind = 0x7fffffff; } ++curPos; if ((i = jjnewStateCnt) == (startsAt = 13 - (jjnewStateCnt = startsAt))) return curPos; try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { return curPos; } } } static final int[] jjnextStates = { 1, 2, 4, 5, }; private static final boolean jjCanMove_0(int hiByte, int i1, int i2, long l1, long l2) { switch(hiByte) { case 0: return ((jjbitVec2[i2] & l2) != 0L); default : if ((jjbitVec0[i1] & l1) != 0L) return true; return false; } } private static final boolean jjCanMove_1(int hiByte, int i1, int i2, long l1, long l2) { switch(hiByte) { case 0: return ((jjbitVec4[i2] & l2) != 0L); case 1: return ((jjbitVec5[i2] & l2) != 0L); case 2: return ((jjbitVec6[i2] & l2) != 0L); case 3: return ((jjbitVec7[i2] & l2) != 0L); case 4: return ((jjbitVec8[i2] & l2) != 0L); case 5: return ((jjbitVec9[i2] & l2) != 0L); case 6: return ((jjbitVec10[i2] & l2) != 0L); case 9: return ((jjbitVec11[i2] & l2) != 0L); case 10: return ((jjbitVec12[i2] & l2) != 0L); case 11: return ((jjbitVec13[i2] & l2) != 0L); case 12: return ((jjbitVec14[i2] & l2) != 0L); case 13: return ((jjbitVec15[i2] & l2) != 0L); case 14: return ((jjbitVec16[i2] & l2) != 0L); case 15: return ((jjbitVec17[i2] & l2) != 0L); case 16: return ((jjbitVec18[i2] & l2) != 0L); case 17: return ((jjbitVec19[i2] & l2) != 0L); case 30: return ((jjbitVec20[i2] & l2) != 0L); case 31: return ((jjbitVec21[i2] & l2) != 0L); case 33: return ((jjbitVec22[i2] & l2) != 0L); case 48: return ((jjbitVec23[i2] & l2) != 0L); case 49: return ((jjbitVec24[i2] & l2) != 0L); case 159: return ((jjbitVec25[i2] & l2) != 0L); case 215: return ((jjbitVec26[i2] & l2) != 0L); default : if ((jjbitVec3[i1] & l1) != 0L) return true; return false; } } private static final boolean jjCanMove_2(int hiByte, int i1, int i2, long l1, long l2) { switch(hiByte) { case 0: return ((jjbitVec27[i2] & l2) != 0L); case 1: return ((jjbitVec5[i2] & l2) != 0L); case 2: return ((jjbitVec28[i2] & l2) != 0L); case 3: return ((jjbitVec29[i2] & l2) != 0L); case 4: return ((jjbitVec30[i2] & l2) != 0L); case 5: return ((jjbitVec31[i2] & l2) != 0L); case 6: return ((jjbitVec32[i2] & l2) != 0L); case 9: return ((jjbitVec33[i2] & l2) != 0L); case 10: return ((jjbitVec34[i2] & l2) != 0L); case 11: return ((jjbitVec35[i2] & l2) != 0L); case 12: return ((jjbitVec36[i2] & l2) != 0L); case 13: return ((jjbitVec37[i2] & l2) != 0L); case 14: return ((jjbitVec38[i2] & l2) != 0L); case 15: return ((jjbitVec39[i2] & l2) != 0L); case 16: return ((jjbitVec18[i2] & l2) != 0L); case 17: return ((jjbitVec19[i2] & l2) != 0L); case 30: return ((jjbitVec20[i2] & l2) != 0L); case 31: return ((jjbitVec21[i2] & l2) != 0L); case 32: return ((jjbitVec40[i2] & l2) != 0L); case 33: return ((jjbitVec22[i2] & l2) != 0L); case 48: return ((jjbitVec41[i2] & l2) != 0L); case 49: return ((jjbitVec24[i2] & l2) != 0L); case 159: return ((jjbitVec25[i2] & l2) != 0L); case 215: return ((jjbitVec26[i2] & l2) != 0L); default : if ((jjbitVec3[i1] & l1) != 0L) return true; return false; } } public static final String[] jjstrLiteralImages = { "", null, null, null, null, null, "\57", "\57\57", "\174", "\53", "\55", "\75", "\41\75", "\74", "\74\75", "\76", "\76\75", "\44", null, null, null, null, null, null, null, null, null, "\157\162", "\141\156\144", "\155\157\144", "\144\151\166", "\156\157\144\145", "\164\145\170\164", "\143\157\155\155\145\156\164", "\160\162\157\143\145\163\163\151\156\147\55\151\156\163\164\162\165\143\164\151\157\156", "\163\145\154\146\72\72", "\143\150\151\154\144\72\72", "\160\141\162\145\156\164\72\72", "\141\156\143\145\163\164\157\162\72\72", "\141\164\164\162\151\142\165\164\145\72\72", "\156\141\155\145\163\160\141\143\145\72\72", "\160\162\145\143\145\144\151\156\147\72\72", "\146\157\154\154\157\167\151\156\147\72\72", "\144\145\163\143\145\156\144\141\156\164\72\72", "\141\156\143\145\163\164\157\162\55\157\162\55\163\145\154\146\72\72", "\146\157\154\154\157\167\151\156\147\55\163\151\142\154\151\156\147\72\72", "\160\162\145\143\145\144\151\156\147\55\163\151\142\154\151\156\147\72\72", "\144\145\163\143\145\156\144\141\156\164\55\157\162\55\163\145\154\146\72\72", "\154\141\163\164", "\160\157\163\151\164\151\157\156", "\143\157\165\156\164", "\151\144", "\153\145\171", "\154\157\143\141\154\55\156\141\155\145", "\156\141\155\145\163\160\141\143\145\55\165\162\151", "\156\141\155\145", "\163\164\162\151\156\147", "\143\157\156\143\141\164", "\163\164\141\162\164\163\55\167\151\164\150", "\143\157\156\164\141\151\156\163", "\163\165\142\163\164\162\151\156\147\55\142\145\146\157\162\145", "\163\165\142\163\164\162\151\156\147\55\141\146\164\145\162", "\163\165\142\163\164\162\151\156\147", "\163\164\162\151\156\147\55\154\145\156\147\164\150", "\156\157\162\155\141\154\151\172\145\55\163\160\141\143\145", "\164\162\141\156\163\154\141\164\145", "\142\157\157\154\145\141\156", "\156\157\164", "\164\162\165\145", "\146\141\154\163\145", "\156\165\154\154", "\154\141\156\147", "\156\165\155\142\145\162", "\163\165\155", "\146\154\157\157\162", "\143\145\151\154\151\156\147", "\162\157\165\156\144", "\146\157\162\155\141\164\55\156\165\155\142\145\162", null, "\72", "\50", "\51", "\56", "\56\56", "\133", "\135", "\100", "\54", "\52", }; public static final String[] lexStateNames = { "DEFAULT", }; static final long[] jjtoToken = { 0xfffffffff817ffc1L, 0x1ffffffL, }; static final long[] jjtoSkip = { 0x3eL, 0x0L, }; protected SimpleCharStream input_stream; private final int[] jjrounds = new int[13]; private final int[] jjstateSet = new int[26]; protected char curChar; public XPathParserTokenManager(SimpleCharStream stream) { if (SimpleCharStream.staticFlag) throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer."); input_stream = stream; } public XPathParserTokenManager(SimpleCharStream stream, int lexState) { this(stream); SwitchTo(lexState); } public void ReInit(SimpleCharStream stream) { jjmatchedPos = jjnewStateCnt = 0; curLexState = defaultLexState; input_stream = stream; ReInitRounds(); } private final void ReInitRounds() { int i; jjround = 0x80000001; for (i = 13; i-- > 0;) jjrounds[i] = 0x80000000; } public void ReInit(SimpleCharStream stream, int lexState) { ReInit(stream); SwitchTo(lexState); } public void SwitchTo(int lexState) { if (lexState >= 1 || lexState < 0) throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE); else curLexState = lexState; } protected Token jjFillToken() { Token t = Token.newToken(jjmatchedKind); t.kind = jjmatchedKind; String im = jjstrLiteralImages[jjmatchedKind]; t.image = (im == null) ? input_stream.GetImage() : im; t.beginLine = input_stream.getBeginLine(); t.beginColumn = input_stream.getBeginColumn(); t.endLine = input_stream.getEndLine(); t.endColumn = input_stream.getEndColumn(); return t; } int curLexState = 0; int defaultLexState = 0; int jjnewStateCnt; int jjround; int jjmatchedPos; int jjmatchedKind; public Token getNextToken() { int kind; Token specialToken = null; Token matchedToken; int curPos = 0; EOFLoop : for (;;) { try { curChar = input_stream.BeginToken(); } catch(java.io.IOException e) { jjmatchedKind = 0; matchedToken = jjFillToken(); return matchedToken; } try { input_stream.backup(0); while (curChar <= 32 && (0x100003600L & (1L << curChar)) != 0L) curChar = input_stream.BeginToken(); } catch (java.io.IOException e1) { continue EOFLoop; } jjmatchedKind = 0x7fffffff; jjmatchedPos = 0; curPos = jjMoveStringLiteralDfa0_0(); if (jjmatchedKind != 0x7fffffff) { if (jjmatchedPos + 1 < curPos) input_stream.backup(curPos - jjmatchedPos - 1); if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) { matchedToken = jjFillToken(); return matchedToken; } else { continue EOFLoop; } } int error_line = input_stream.getEndLine(); int error_column = input_stream.getEndColumn(); String error_after = null; boolean EOFSeen = false; try { input_stream.readChar(); input_stream.backup(1); } catch (java.io.IOException e1) { EOFSeen = true; error_after = curPos <= 1 ? "" : input_stream.GetImage(); if (curChar == '\n' || curChar == '\r') { error_line++; error_column = 0; } else error_column++; } if (!EOFSeen) { input_stream.backup(1); error_after = curPos <= 1 ? "" : input_stream.GetImage(); } throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR); } } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/Parser.java100644 0 0 6747 11044113541 23452 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri; import java.io.StringReader; import org.apache.commons.jxpath.JXPathInvalidSyntaxException; import org.apache.commons.jxpath.ri.parser.ParseException; import org.apache.commons.jxpath.ri.parser.TokenMgrError; import org.apache.commons.jxpath.ri.parser.XPathParser; /** * XPath parser * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class Parser { private static XPathParser parser = new XPathParser(new StringReader("")); /** * Parses the XPath expression. Throws a JXPathException in case * of a syntax error. * @param expression to parse * @param compiler the compiler * @return parsed Object */ public static Object parseExpression( String expression, Compiler compiler) { synchronized (parser) { parser.setCompiler(compiler); Object expr = null; try { parser.ReInit(new StringReader(expression)); expr = parser.parseExpression(); } catch (TokenMgrError e) { throw new JXPathInvalidSyntaxException( "Invalid XPath: '" + addEscapes(expression) + "'. Invalid symbol '" + addEscapes(String.valueOf(e.getCharacter())) + "' " + describePosition(expression, e.getPosition())); } catch (ParseException e) { throw new JXPathInvalidSyntaxException( "Invalid XPath: '" + addEscapes(expression) + "'. Syntax error " + describePosition( expression, e.currentToken.beginColumn)); } return expr; } } /** * Describe a parse position. * @param expression to parse * @param position parse position * @return String */ private static String describePosition(String expression, int position) { if (position <= 0) { return "at the beginning of the expression"; } if (position >= expression.length()) { return "- expression incomplete"; } return "after: '" + addEscapes(expression.substring(0, position)) + "'"; } /** * Add escapes to the specified String. * @param string incoming String * @return String */ private static String addEscapes(String string) { // Piggy-back on the code generated by JavaCC return TokenMgrError.addEscapes(string); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/ri/QName.java100644 0 0 5071 11044113541 23204 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri; import java.io.Serializable; /** * A qualified name: a combination of an optional namespace prefix * and an local name. * * @author Dmitri Plotnikov * @version $Revision: 652925 $ $Date: 2008-05-02 17:05:41 -0500 (Fri, 02 May 2008) $ */ public class QName implements Serializable { private static final long serialVersionUID = 7616199282015091496L; private String prefix; private String name; private String qualifiedName; /** * Create a new QName. * @param qualifiedName value */ public QName(String qualifiedName) { this.qualifiedName = qualifiedName; int index = qualifiedName.indexOf(':'); prefix = index < 0 ? null : qualifiedName.substring(0, index); name = index < 0 ? qualifiedName : qualifiedName.substring(index + 1); } /** * Create a new QName. * @param prefix ns * @param localName String */ public QName(String prefix, String localName) { this.prefix = prefix; this.name = localName; this.qualifiedName = prefix == null ? localName : prefix + ':' + localName; } /** * Get the prefix of this QName. * @return String */ public String getPrefix() { return prefix; } /** * Get the local name. * @return String */ public String getName() { return name; } public String toString() { return qualifiedName; } public int hashCode() { return name.hashCode(); } public boolean equals(Object object) { if (this == object) { return true; } if (!(object instanceof QName)) { return false; } return qualifiedName.equals(((QName) object).qualifiedName); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/servlet/Constants.java100644 0 0 3532 11044113526 25234 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.servlet; /** * String constants for this package. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public final class Constants { /** * Variable name for {@link javax.servlet.ServletContext}. */ public static final String APPLICATION_SCOPE = "application"; /** * Variable name for {@link javax.servlet.http.HttpSession}. */ public static final String SESSION_SCOPE = "session"; /** * Variable name for {@link javax.servlet.ServletRequest}. */ public static final String REQUEST_SCOPE = "request"; /** * Variable name for {@link javax.servlet.jsp.PageContext}. */ public static final String PAGE_SCOPE = "page"; /** * Attribute name used in page context, requst, session, and servlet * context to store the corresponding {@link org.apache.commons.jxpath.JXPathContext}. */ public static final String JXPATH_CONTEXT = "org.apache.commons.jxpath.JXPATH_CONTEXT"; } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/servlet/HttpSessionAndServletContext.java100644 0 0 3455 11044113526 31104 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.servlet; import javax.servlet.ServletContext; import javax.servlet.http.HttpSession; /** * Just a structure to hold a ServletRequest and ServletContext together. * * @author Dmitri Plotnikov * @version $Revision: 604304 $ $Date: 2007-12-14 15:31:19 -0600 (Fri, 14 Dec 2007) $ */ public class HttpSessionAndServletContext { private HttpSession session; private ServletContext context; /** * Create a new HttpSessionAndServletContext. * @param session HttpSession * @param context ServletContext */ public HttpSessionAndServletContext(HttpSession session, ServletContext context) { this.session = session; this.context = context; } /** * Get the session. * @return HttpSession */ public HttpSession getSession() { return session; } /** * Get the ServletContext. * @return ServletContext */ public ServletContext getServletContext() { return context; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/servlet/HttpSessionHandler.java100644 0 0 5302 11044113526 27036 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.servlet; import java.util.Enumeration; import java.util.HashSet; import javax.servlet.http.HttpSession; import org.apache.commons.jxpath.JXPathException; /** * Implementation of the {@link org.apache.commons.jxpath.DynamicPropertyHandler} * interface that provides access to attributes of a @{link HttpSession}. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class HttpSessionHandler extends ServletContextHandler { protected void collectPropertyNames(HashSet set, Object bean) { HttpSessionAndServletContext handle = (HttpSessionAndServletContext) bean; super.collectPropertyNames(set, handle.getServletContext()); HttpSession session = handle.getSession(); if (session != null) { Enumeration e = session.getAttributeNames(); while (e.hasMoreElements()) { set.add(e.nextElement()); } } } public Object getProperty(Object bean, String property) { HttpSessionAndServletContext handle = (HttpSessionAndServletContext) bean; HttpSession session = handle.getSession(); if (session != null) { Object object = session.getAttribute(property); if (object != null) { return object; } } return super.getProperty(handle.getServletContext(), property); } public void setProperty(Object bean, String property, Object value) { HttpSessionAndServletContext handle = (HttpSessionAndServletContext) bean; HttpSession session = handle.getSession(); if (session != null) { session.setAttribute(property, value); } else { throw new JXPathException("Cannot set session attribute: " + "there is no session"); } } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/servlet/JXPathServletContexts.java100644 0 0 20627 11044113526 27537 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.servlet; import javax.servlet.ServletContext; import javax.servlet.ServletRequest; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import javax.servlet.jsp.PageContext; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathContextFactory; import org.apache.commons.jxpath.JXPathIntrospector; /** * Static methods that allocate and cache JXPathContexts bound to * {@link PageContext}, {@link ServletRequest}, {@link HttpSession} * and {@link ServletContext}. *

* The {@link JXPathContext} returned by {@link #getPageContext getPageContext()} * provides access to all scopes via the PageContext.findAttribute() * method. Thus, an expression like "foo" will first look for the attribute * named "foo" in the "page" context, then the "request" context, then * the "session" one and finally in the "application" context. *

* If you need to limit the attibute lookup to just one scope, you can use the * pre-definded variables "page", "request", "session" and "application". * For example, the expression "$session/foo" extracts the value of the * session attribute named "foo". *

* Following are some implementation details. There is a separate JXPathContext * for each of the four scopes. These contexts are chained according to the * nesting of the scopes. So, the parent of the "page" JXPathContext is a * "request" JXPathContext, whose parent is a "session" JXPathContext (that is * if there is a session), whose parent is an "application" context. *

* The XPath context node for each context is the corresponding object: * PageContext, ServletRequest, HttpSession or ServletContext. This feature can * be used by servlets. A servlet can use one of the methods declared by this * class and work with a specific JXPathContext for any scope. *

* Since JXPath chains lookups for variables and extension functions, variables * and extension function declared in the outer scopes are also available in * the inner scopes. *

* Each of the four context declares exactly one variable, the value of which * is the corresponding object: PageContext, etc. *

* The "session" variable will be undefined if there is no session for this * servlet. JXPath does not automatically create sessions. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public final class JXPathServletContexts { private static JXPathContextFactory factory; static { JXPathIntrospector.registerDynamicClass( PageScopeContext.class, PageScopeContextHandler.class); JXPathIntrospector.registerDynamicClass( PageContext.class, PageContextHandler.class); JXPathIntrospector.registerDynamicClass( ServletContext.class, ServletContextHandler.class); JXPathIntrospector.registerDynamicClass( ServletRequestAndContext.class, ServletRequestHandler.class); JXPathIntrospector.registerDynamicClass( HttpSessionAndServletContext.class, HttpSessionHandler.class); factory = JXPathContextFactory.newInstance(); } /** * Returns a JXPathContext bound to the "page" scope. Caches that context * within the PageContext itself. * @param pageContext as described * @return JXPathContext */ public static JXPathContext getPageContext(PageContext pageContext) { JXPathContext context = (JXPathContext) pageContext.getAttribute(Constants.JXPATH_CONTEXT); if (context == null) { JXPathContext parentContext = getRequestContext( pageContext.getRequest(), pageContext.getServletContext()); context = factory.newContext(parentContext, pageContext); context.setVariables( new KeywordVariables( Constants.PAGE_SCOPE, new PageScopeContext(pageContext))); pageContext.setAttribute(Constants.JXPATH_CONTEXT, context); } return context; } /** * Returns a JXPathContext bound to the "request" scope. Caches that context * within the request itself. * @param request as described * @param servletContext operative * @return JXPathContext */ public static JXPathContext getRequestContext(ServletRequest request, ServletContext servletContext) { JXPathContext context = (JXPathContext) request.getAttribute(Constants.JXPATH_CONTEXT); // If we are in an included JSP or Servlet, the request parameter // will represent the included URL, but the JXPathContext we have // just acquired will represent the outer request. if (context != null) { ServletRequestAndContext handle = (ServletRequestAndContext) context.getContextBean(); if (handle.getServletRequest() == request) { return context; } } JXPathContext parentContext = null; if (request instanceof HttpServletRequest) { HttpSession session = ((HttpServletRequest) request).getSession(false); if (session != null) { parentContext = getSessionContext(session, servletContext); } else { parentContext = getApplicationContext(servletContext); } } ServletRequestAndContext handle = new ServletRequestAndContext(request, servletContext); context = factory.newContext(parentContext, handle); context.setVariables( new KeywordVariables(Constants.REQUEST_SCOPE, handle)); request.setAttribute(Constants.JXPATH_CONTEXT, context); return context; } /** * Returns a JXPathContext bound to the "session" scope. Caches that context * within the session itself. * @param session as described * @param servletContext operative * @return JXPathContext */ public static JXPathContext getSessionContext(HttpSession session, ServletContext servletContext) { JXPathContext context = (JXPathContext) session.getAttribute(Constants.JXPATH_CONTEXT); if (context == null) { JXPathContext parentContext = getApplicationContext(servletContext); HttpSessionAndServletContext handle = new HttpSessionAndServletContext(session, servletContext); context = factory.newContext(parentContext, handle); context.setVariables( new KeywordVariables(Constants.SESSION_SCOPE, handle)); session.setAttribute(Constants.JXPATH_CONTEXT, context); } return context; } /** * Returns a JXPathContext bound to the "application" scope. Caches that * context within the servlet context itself. * @param servletContext operative * @return JXPathContext */ public static JXPathContext getApplicationContext( ServletContext servletContext) { JXPathContext context = (JXPathContext) servletContext.getAttribute( Constants.JXPATH_CONTEXT); if (context == null) { context = factory.newContext(null, servletContext); context.setVariables( new KeywordVariables( Constants.APPLICATION_SCOPE, servletContext)); servletContext.setAttribute(Constants.JXPATH_CONTEXT, context); } return context; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/servlet/KeywordVariables.java100644 0 0 4267 11044113526 26543 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.servlet; import org.apache.commons.jxpath.Variables; /** * Implementation of the Variables interface that provides access * to a single object using a reserved name (keyword). * * @author Dmitri Plotnikov * @version $Revision: 652925 $ $Date: 2008-05-02 17:05:41 -0500 (Fri, 02 May 2008) $ */ public class KeywordVariables implements Variables { private static final long serialVersionUID = 894145608741325442L; private String keyword; private Object object; /** * Create a new KeywordVariables. * @param keyword String * @param object value */ public KeywordVariables(String keyword, Object object) { if (keyword == null) { throw new IllegalArgumentException("keyword cannot be null"); } this.keyword = keyword; this.object = object; } public boolean isDeclaredVariable(String variable) { return variable.equals(keyword); } public Object getVariable(String variable) { return isDeclaredVariable(variable) ? object : null; } public void declareVariable(String variable, Object value) { throw new UnsupportedOperationException( "Cannot declare new keyword variables."); } public void undeclareVariable(String variable) { throw new UnsupportedOperationException( "Cannot undeclare keyword variables."); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/servlet/package.html100644 0 0 2001 11044113526 24664 0ustar 0 0 Implementations of JXPathContexts bound to various servlet scopes: PageContext, ServletRequest, HttpSession and ServletContext. Start with the {@link org.apache.commons.jxpath.servlet.JXPathServletContexts} class. commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/servlet/PageContextHandler.java100644 0 0 5512 11044113526 26777 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.servlet; import java.util.Enumeration; import java.util.HashSet; import javax.servlet.jsp.PageContext; import org.apache.commons.jxpath.DynamicPropertyHandler; /** * Implementation of the {@link DynamicPropertyHandler} interface that provides * access to attributes of a {@link PageContext} in all scopes. * * @author Dmitri Plotnikov * @version $Revision: 668329 $ $Date: 2008-06-16 16:59:48 -0500 (Mon, 16 Jun 2008) $ */ public class PageContextHandler implements DynamicPropertyHandler { public String[] getPropertyNames(Object pageContext) { HashSet list = new HashSet(); Enumeration e = ((PageContext) pageContext).getAttributeNamesInScope( PageContext.PAGE_SCOPE); while (e.hasMoreElements()) { list.add(e.nextElement()); } e = ((PageContext) pageContext).getAttributeNamesInScope( PageContext.REQUEST_SCOPE); while (e.hasMoreElements()) { list.add(e.nextElement()); } e = ((PageContext) pageContext).getAttributeNamesInScope( PageContext.SESSION_SCOPE); while (e.hasMoreElements()) { list.add(e.nextElement()); } e = ((PageContext) pageContext).getAttributeNamesInScope( PageContext.APPLICATION_SCOPE); while (e.hasMoreElements()) { list.add(e.nextElement()); } return (String[]) list.toArray(new String[list.size()]); } /** * Returns pageContext.findAttribute(property). * @param pageContext to search * @param property name * @return Object value */ public Object getProperty(Object pageContext, String property) { return ((PageContext) pageContext).findAttribute(property); } public void setProperty(Object pageContext, String property, Object value) { ((PageContext) pageContext).setAttribute( property, value, PageContext.PAGE_SCOPE); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/servlet/PageScopeContext.java100644 0 0 4434 11044113526 26475 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.servlet; import java.util.Enumeration; import javax.servlet.jsp.PageContext; /** * A lightweight wrapper for {@link PageContext} that restricts access * to attributes of the "page" scope. This object is needed so that * XPath "foo" would lookup the attribute "foo" in all scopes, while * "$page/foo" would only look in the "page" scope. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class PageScopeContext { private PageContext pageContext; /** * Create a new PageScopeContext. * @param pageContext base */ public PageScopeContext(PageContext pageContext) { this.pageContext = pageContext; } /** * Returns attributes of the pageContext declared in the "page" scope. * @return Enumeration of attribute names */ public Enumeration getAttributeNames() { return pageContext.getAttributeNamesInScope(PageContext.PAGE_SCOPE); } /** * Get the value of the specified attribute. * @param attribute name * @return Object */ public Object getAttribute(String attribute) { return pageContext.getAttribute(attribute, PageContext.PAGE_SCOPE); } /** * Set the specified attribute. * @param attribute to set * @param value to set */ public void setAttribute(String attribute, Object value) { pageContext.setAttribute(attribute, value, PageContext.PAGE_SCOPE); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/servlet/PageScopeContextHandler.java100644 0 0 3723 11044113526 27773 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.servlet; import java.util.ArrayList; import java.util.Enumeration; import org.apache.commons.jxpath.DynamicPropertyHandler; /** * Implementation of the {@link DynamicPropertyHandler} interface that provides * access to attributes of a {@link PageScopeContext}. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class PageScopeContextHandler implements DynamicPropertyHandler { private static final int DEFAULT_LIST_SIZE = 16; public String[] getPropertyNames(Object pageScope) { Enumeration e = ((PageScopeContext) pageScope).getAttributeNames(); ArrayList list = new ArrayList(DEFAULT_LIST_SIZE); while (e.hasMoreElements()) { list.add(e.nextElement()); } return (String[]) list.toArray(new String[list.size()]); } public Object getProperty(Object pageScope, String property) { return ((PageScopeContext) pageScope).getAttribute(property); } public void setProperty(Object pageScope, String property, Object value) { ((PageScopeContext) pageScope).setAttribute(property, value); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/servlet/ServletContextHandler.java100644 0 0 4341 11044113526 27546 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.servlet; import java.util.Enumeration; import java.util.HashSet; import javax.servlet.ServletContext; import org.apache.commons.jxpath.DynamicPropertyHandler; /** * Implementation of the {@link DynamicPropertyHandler} interface that provides * access to attributes of a {@link ServletContext}. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class ServletContextHandler implements DynamicPropertyHandler { private static final int DEFAULT_PROPERTY_COUNT = 16; public String[] getPropertyNames(Object context) { HashSet list = new HashSet(DEFAULT_PROPERTY_COUNT); collectPropertyNames(list, context); return (String[]) list.toArray(new String[list.size()]); } /** * Collect the property names from bean, storing in set. * @param set destination * @param bean to read */ protected void collectPropertyNames(HashSet set, Object bean) { Enumeration e = ((ServletContext) bean).getAttributeNames(); while (e.hasMoreElements()) { set.add(e.nextElement()); } } public Object getProperty(Object context, String property) { return ((ServletContext) context).getAttribute(property); } public void setProperty(Object context, String property, Object value) { ((ServletContext) context).setAttribute(property, value); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/servlet/ServletRequestAndContext.java100644 0 0 3672 11044113526 30252 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.servlet; import javax.servlet.ServletContext; import javax.servlet.ServletRequest; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; /** * Just a structure to hold a {@link ServletRequest} and {@link ServletContext} * together. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class ServletRequestAndContext extends HttpSessionAndServletContext { private ServletRequest request; /** * Create a new ServletRequestAndContext. * * @param request ServletRequest * @param context ServletContext */ public ServletRequestAndContext(ServletRequest request, ServletContext context) { super(null, context); this.request = request; } public HttpSession getSession() { return request instanceof HttpServletRequest ? ((HttpServletRequest) request).getSession(false) : null; } /** * Get the request. * * @return ServletRequest */ public ServletRequest getServletRequest() { return request; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/servlet/ServletRequestHandler.java100644 0 0 5263 11044113526 27556 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.servlet; import java.util.Enumeration; import java.util.HashSet; import javax.servlet.ServletRequest; /** * Implementation of the {@link org.apache.commons.jxpath.DynamicPropertyHandler} * interface that provides access to attributes and parameters * of a {@link ServletRequest}. * * @author Dmitri Plotnikov * @version $Revision: 652848 $ $Date: 2008-05-02 12:53:50 -0500 (Fri, 02 May 2008) $ */ public class ServletRequestHandler extends HttpSessionHandler { protected void collectPropertyNames(HashSet set, Object bean) { super.collectPropertyNames(set, bean); ServletRequestAndContext handle = (ServletRequestAndContext) bean; ServletRequest servletRequest = handle.getServletRequest(); Enumeration e = servletRequest.getAttributeNames(); while (e.hasMoreElements()) { set.add(e.nextElement()); } e = servletRequest.getParameterNames(); while (e.hasMoreElements()) { set.add(e.nextElement()); } } public Object getProperty(Object bean, String property) { ServletRequestAndContext handle = (ServletRequestAndContext) bean; ServletRequest servletRequest = handle.getServletRequest(); String[] strings = servletRequest.getParameterValues(property); if (strings != null) { if (strings.length == 0) { return null; } if (strings.length == 1) { return strings[0]; } return strings; } Object object = servletRequest.getAttribute(property); if (object != null) { return object; } return super.getProperty(bean, property); } public void setProperty(Object request, String property, Object value) { ((ServletRequestAndContext) request).getServletRequest().setAttribute(property, value); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/util/BasicTypeConverter.java100644 0 0 44762 11044113545 26357 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.util; import java.lang.reflect.Array; import java.lang.reflect.Modifier; import java.math.BigDecimal; import java.math.BigInteger; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.SortedSet; import org.apache.commons.beanutils.ConvertUtils; import org.apache.commons.beanutils.Converter; import org.apache.commons.jxpath.JXPathInvalidAccessException; import org.apache.commons.jxpath.JXPathTypeConversionException; import org.apache.commons.jxpath.NodeSet; import org.apache.commons.jxpath.Pointer; /** * The default implementation of TypeConverter. * * @author Dmitri Plotnikov * @version $Revision: 670727 $ $Date: 2008-06-23 15:10:38 -0500 (Mon, 23 Jun 2008) $ */ public class BasicTypeConverter implements TypeConverter { /** * Returns true if it can convert the supplied * object to the specified class. * @param object to check * @param toType prospective destination class * @return boolean */ public boolean canConvert(Object object, final Class toType) { if (object == null) { return true; } final Class useType = TypeUtils.wrapPrimitive(toType); Class fromType = object.getClass(); if (useType.isAssignableFrom(fromType)) { return true; } if (useType == String.class) { return true; } if (object instanceof Boolean && (Number.class.isAssignableFrom(useType) || "java.util.concurrent.atomic.AtomicBoolean" .equals(useType.getName()))) { return true; } if (object instanceof Number && (Number.class.isAssignableFrom(useType) || useType == Boolean.class)) { return true; } if (object instanceof String && (useType == Boolean.class || useType == Character.class || useType == Byte.class || useType == Short.class || useType == Integer.class || useType == Long.class || useType == Float.class || useType == Double.class)) { return true; } if (fromType.isArray()) { // Collection -> array if (useType.isArray()) { Class cType = useType.getComponentType(); int length = Array.getLength(object); for (int i = 0; i < length; i++) { Object value = Array.get(object, i); if (!canConvert(value, cType)) { return false; } } return true; } if (Collection.class.isAssignableFrom(useType)) { return canCreateCollection(useType); } if (Array.getLength(object) > 0) { Object value = Array.get(object, 0); return canConvert(value, useType); } return canConvert("", useType); } if (object instanceof Collection) { // Collection -> array if (useType.isArray()) { Class cType = useType.getComponentType(); Iterator it = ((Collection) object).iterator(); while (it.hasNext()) { Object value = it.next(); if (!canConvert(value, cType)) { return false; } } return true; } if (Collection.class.isAssignableFrom(useType)) { return canCreateCollection(useType); } if (((Collection) object).size() > 0) { Object value; if (object instanceof List) { value = ((List) object).get(0); } else { Iterator it = ((Collection) object).iterator(); value = it.next(); } return canConvert(value, useType); } return canConvert("", useType); } if (object instanceof NodeSet) { return canConvert(((NodeSet) object).getValues(), useType); } if (object instanceof Pointer) { return canConvert(((Pointer) object).getValue(), useType); } return ConvertUtils.lookup(useType) != null; } /** * Converts the supplied object to the specified * type. Throws a runtime exception if the conversion is * not possible. * @param object to convert * @param toType destination class * @return converted object */ public Object convert(Object object, final Class toType) { if (object == null) { return toType.isPrimitive() ? convertNullToPrimitive(toType) : null; } if (toType == Object.class) { if (object instanceof NodeSet) { return convert(((NodeSet) object).getValues(), toType); } if (object instanceof Pointer) { return convert(((Pointer) object).getValue(), toType); } return object; } final Class useType = TypeUtils.wrapPrimitive(toType); Class fromType = object.getClass(); if (useType.isAssignableFrom(fromType)) { return object; } if (fromType.isArray()) { int length = Array.getLength(object); if (useType.isArray()) { Class cType = useType.getComponentType(); Object array = Array.newInstance(cType, length); for (int i = 0; i < length; i++) { Object value = Array.get(object, i); Array.set(array, i, convert(value, cType)); } return array; } if (Collection.class.isAssignableFrom(useType)) { Collection collection = allocateCollection(useType); for (int i = 0; i < length; i++) { collection.add(Array.get(object, i)); } return unmodifiableCollection(collection); } if (length > 0) { Object value = Array.get(object, 0); return convert(value, useType); } return convert("", useType); } if (object instanceof Collection) { int length = ((Collection) object).size(); if (useType.isArray()) { Class cType = useType.getComponentType(); Object array = Array.newInstance(cType, length); Iterator it = ((Collection) object).iterator(); for (int i = 0; i < length; i++) { Object value = it.next(); Array.set(array, i, convert(value, cType)); } return array; } if (Collection.class.isAssignableFrom(useType)) { Collection collection = allocateCollection(useType); collection.addAll((Collection) object); return unmodifiableCollection(collection); } if (length > 0) { Object value; if (object instanceof List) { value = ((List) object).get(0); } else { Iterator it = ((Collection) object).iterator(); value = it.next(); } return convert(value, useType); } return convert("", useType); } if (object instanceof NodeSet) { return convert(((NodeSet) object).getValues(), useType); } if (object instanceof Pointer) { return convert(((Pointer) object).getValue(), useType); } if (useType == String.class) { return object.toString(); } if (object instanceof Boolean) { if (Number.class.isAssignableFrom(useType)) { return allocateNumber(useType, ((Boolean) object).booleanValue() ? 1 : 0); } if ("java.util.concurrent.atomic.AtomicBoolean".equals(useType.getName())) { try { return useType.getConstructor(new Class[] { boolean.class }) .newInstance(new Object[] { object }); } catch (Exception e) { throw new JXPathTypeConversionException(useType.getName(), e); } } } if (object instanceof Number) { double value = ((Number) object).doubleValue(); if (useType == Boolean.class) { return value == 0.0 ? Boolean.FALSE : Boolean.TRUE; } if (Number.class.isAssignableFrom(useType)) { return allocateNumber(useType, value); } } if (object instanceof String) { Object value = convertStringToPrimitive(object, useType); if (value != null) { return value; } } Converter converter = ConvertUtils.lookup(useType); if (converter != null) { return converter.convert(useType, object); } throw new JXPathTypeConversionException("Cannot convert " + object.getClass() + " to " + useType); } /** * Convert null to a primitive type. * @param toType destination class * @return a wrapper */ protected Object convertNullToPrimitive(Class toType) { if (toType == boolean.class) { return Boolean.FALSE; } if (toType == char.class) { return new Character('\0'); } if (toType == byte.class) { return new Byte((byte) 0); } if (toType == short.class) { return new Short((short) 0); } if (toType == int.class) { return new Integer(0); } if (toType == long.class) { return new Long(0L); } if (toType == float.class) { return new Float(0.0f); } if (toType == double.class) { return new Double(0.0); } return null; } /** * Convert a string to a primitive type. * @param object String * @param toType destination class * @return wrapper */ protected Object convertStringToPrimitive(Object object, Class toType) { toType = TypeUtils.wrapPrimitive(toType); if (toType == Boolean.class) { return Boolean.valueOf((String) object); } if (toType == Character.class) { return new Character(((String) object).charAt(0)); } if (toType == Byte.class) { return new Byte((String) object); } if (toType == Short.class) { return new Short((String) object); } if (toType == Integer.class) { return new Integer((String) object); } if (toType == Long.class) { return new Long((String) object); } if (toType == Float.class) { return new Float((String) object); } if (toType == Double.class) { return new Double((String) object); } return null; } /** * Allocate a number of a given type and value. * @param type destination class * @param value double * @return Number */ protected Number allocateNumber(Class type, double value) { type = TypeUtils.wrapPrimitive(type); if (type == Byte.class) { return new Byte((byte) value); } if (type == Short.class) { return new Short((short) value); } if (type == Integer.class) { return new Integer((int) value); } if (type == Long.class) { return new Long((long) value); } if (type == Float.class) { return new Float((float) value); } if (type == Double.class) { return new Double(value); } if (type == BigInteger.class) { return BigInteger.valueOf((long) value); } if (type == BigDecimal.class) { return new BigDecimal(value); } String classname = type.getName(); Class initialValueType = null; if ("java.util.concurrent.atomic.AtomicInteger".equals(classname)) { initialValueType = int.class; } if ("java.util.concurrent.atomic.AtomicLong".equals(classname)) { initialValueType = long.class; } if (initialValueType != null) { try { return (Number) type.getConstructor( new Class[] { initialValueType }) .newInstance( new Object[] { allocateNumber(initialValueType, value) }); } catch (Exception e) { throw new JXPathTypeConversionException(classname, e); } } return null; } /** * Learn whether this BasicTypeConverter can create a collection of the specified type. * @param type prospective destination class * @return boolean */ protected boolean canCreateCollection(Class type) { if (!type.isInterface() && ((type.getModifiers() & Modifier.ABSTRACT) == 0)) { try { type.getConstructor(new Class[0]); return true; } catch (Exception e) { return false; } } return type == List.class || type == Collection.class || type == Set.class; } /** * Create a collection of a given type. * @param type destination class * @return Collection */ protected Collection allocateCollection(Class type) { if (!type.isInterface() && ((type.getModifiers() & Modifier.ABSTRACT) == 0)) { try { return (Collection) type.newInstance(); } catch (Exception ex) { throw new JXPathInvalidAccessException( "Cannot create collection of type: " + type, ex); } } if (type == List.class || type == Collection.class) { return new ArrayList(); } if (type == Set.class) { return new HashSet(); } throw new JXPathInvalidAccessException( "Cannot create collection of type: " + type); } /** * Get an unmodifiable version of a collection. * @param collection to wrap * @return Collection */ protected Collection unmodifiableCollection(Collection collection) { if (collection instanceof List) { return Collections.unmodifiableList((List) collection); } if (collection instanceof SortedSet) { return Collections.unmodifiableSortedSet((SortedSet) collection); } if (collection instanceof Set) { return Collections.unmodifiableSet((Set) collection); } return Collections.unmodifiableCollection(collection); } /** * NodeSet implementation */ static final class ValueNodeSet implements NodeSet { private List values; private List pointers; /** * Create a new ValueNodeSet. * @param values to return */ public ValueNodeSet(List values) { this.values = values; } public List getValues() { return Collections.unmodifiableList(values); } public List getNodes() { return Collections.unmodifiableList(values); } public List getPointers() { if (pointers == null) { pointers = new ArrayList(); for (int i = 0; i < values.size(); i++) { pointers.add(new ValuePointer(values.get(i))); } pointers = Collections.unmodifiableList(pointers); } return pointers; } } /** * Value pointer */ static final class ValuePointer implements Pointer { private static final long serialVersionUID = -4817239482392206188L; private Object bean; /** * Create a new ValuePointer. * @param object value */ public ValuePointer(Object object) { this.bean = object; } public Object getValue() { return bean; } public Object getNode() { return bean; } public Object getRootNode() { return bean; } public void setValue(Object value) { throw new UnsupportedOperationException(); } public Object clone() { return this; } public int compareTo(Object object) { return 0; } public String asPath() { if (bean == null) { return "null()"; } if (bean instanceof Number) { String string = bean.toString(); if (string.endsWith(".0")) { string = string.substring(0, string.length() - 2); } return string; } if (bean instanceof Boolean) { return ((Boolean) bean).booleanValue() ? "true()" : "false()"; } if (bean instanceof String) { return "'" + bean + "'"; } return "{object of type " + bean.getClass().getName() + "}"; } } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/util/JXPath11CompatibleTypeConverter.java100644 0 0 3044 11044113545 30602 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.util; import org.apache.commons.jxpath.NodeSet; /** * TypeConverter implementation to circumvent automagic {@link NodeSet} * decoding. Suggested by JIRA issue JXPATH-10. * * @since JXPath 1.3 * @author Matt Benson * @version $Revision: 658784 $ $Date: 2008-05-21 12:44:55 -0500 (Wed, 21 May 2008) $ */ public class JXPath11CompatibleTypeConverter extends BasicTypeConverter { public boolean canConvert(Object object, Class toType) { return object instanceof NodeSet ? toType.isInstance(object) : super.canConvert(object, toType); } public Object convert(Object object, Class toType) { return object instanceof NodeSet && toType.isInstance(object) ? object : super.convert(object, toType); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/util/KeyManagerUtils.java100644 0 0 5537 11044113545 25625 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.util; import org.apache.commons.jxpath.BasicNodeSet; import org.apache.commons.jxpath.ExtendedKeyManager; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.KeyManager; import org.apache.commons.jxpath.NodeSet; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.InfoSetUtil; /** * Utility class. * * @author Matt Benson * @since JXPath 1.3 * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class KeyManagerUtils { /** * Adapt KeyManager to implement ExtendedKeyManager. */ private static class SingleNodeExtendedKeyManager implements ExtendedKeyManager { private KeyManager delegate; /** * Create a new SingleNodeExtendedKeyManager. * @param delegate KeyManager to wrap */ public SingleNodeExtendedKeyManager(KeyManager delegate) { this.delegate = delegate; } public NodeSet getNodeSetByKey(JXPathContext context, String key, Object value) { Pointer pointer = delegate.getPointerByKey(context, key, InfoSetUtil.stringValue(value)); BasicNodeSet result = new BasicNodeSet(); result.add(pointer); return result; } public Pointer getPointerByKey(JXPathContext context, String keyName, String keyValue) { return delegate.getPointerByKey(context, keyName, keyValue); } } /** * Get an ExtendedKeyManager from the specified KeyManager. * @param keyManager to adapt, if necessary * @return keyManager if it implements ExtendedKeyManager * or a basic single-result ExtendedKeyManager that delegates to * keyManager. */ public static ExtendedKeyManager getExtendedKeyManager(KeyManager keyManager) { return keyManager instanceof ExtendedKeyManager ? (ExtendedKeyManager) keyManager : new SingleNodeExtendedKeyManager(keyManager); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/util/MethodLookupUtils.java100644 0 0 23430 11044113545 26224 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.util; import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Arrays; import org.apache.commons.jxpath.ExpressionContext; import org.apache.commons.jxpath.JXPathException; /** * Method lookup utilities, which find static and non-static methods as well * as constructors based on a name and list of parameters. * * @author Dmitri Plotnikov * @version $Revision: 670727 $ $Date: 2008-06-23 15:10:38 -0500 (Mon, 23 Jun 2008) $ */ public class MethodLookupUtils { private static final int NO_MATCH = 0; private static final int APPROXIMATE_MATCH = 1; private static final int EXACT_MATCH = 2; /** * Look up a constructor. * @param targetClass the class constructed * @param parameters arguments * @return Constructor found if any. */ public static Constructor lookupConstructor( Class targetClass, Object[] parameters) { boolean tryExact = true; int count = parameters == null ? 0 : parameters.length; Class[] types = new Class[count]; for (int i = 0; i < count; i++) { Object param = parameters[i]; if (param != null) { types[i] = param.getClass(); } else { types[i] = null; tryExact = false; } } Constructor constructor = null; if (tryExact) { // First - without type conversion try { constructor = targetClass.getConstructor(types); if (constructor != null) { return constructor; } } catch (NoSuchMethodException ex) { //NOPMD // Ignore } } int currentMatch = 0; boolean ambiguous = false; // Then - with type conversion Constructor[] constructors = targetClass.getConstructors(); for (int i = 0; i < constructors.length; i++) { int match = matchParameterTypes( constructors[i].getParameterTypes(), parameters); if (match != NO_MATCH) { if (match > currentMatch) { constructor = constructors[i]; currentMatch = match; ambiguous = false; } else if (match == currentMatch) { ambiguous = true; } } } if (ambiguous) { throw new JXPathException( "Ambigous constructor " + Arrays.asList(parameters)); } return constructor; } /** * Look up a static method. * @param targetClass the owning class * @param name method name * @param parameters method parameters * @return Method found if any */ public static Method lookupStaticMethod( Class targetClass, String name, Object[] parameters) { boolean tryExact = true; int count = parameters == null ? 0 : parameters.length; Class[] types = new Class[count]; for (int i = 0; i < count; i++) { Object param = parameters[i]; if (param != null) { types[i] = param.getClass(); } else { types[i] = null; tryExact = false; } } Method method = null; if (tryExact) { // First - without type conversion try { method = targetClass.getMethod(name, types); if (method != null && Modifier.isStatic(method.getModifiers())) { return method; } } catch (NoSuchMethodException ex) { //NOPMD // Ignore } } int currentMatch = 0; boolean ambiguous = false; // Then - with type conversion Method[] methods = targetClass.getMethods(); for (int i = 0; i < methods.length; i++) { if (Modifier.isStatic(methods[i].getModifiers()) && methods[i].getName().equals(name)) { int match = matchParameterTypes( methods[i].getParameterTypes(), parameters); if (match != NO_MATCH) { if (match > currentMatch) { method = methods[i]; currentMatch = match; ambiguous = false; } else if (match == currentMatch) { ambiguous = true; } } } } if (ambiguous) { throw new JXPathException("Ambigous method call: " + name); } return method; } /** * Look up a method. * @param targetClass owning class * @param name method name * @param parameters method parameters * @return Method found if any */ public static Method lookupMethod( Class targetClass, String name, Object[] parameters) { if (parameters == null || parameters.length < 1 || parameters[0] == null) { return null; } if (matchType(targetClass, parameters[0]) == NO_MATCH) { return null; } targetClass = TypeUtils.convert(parameters[0], targetClass).getClass(); boolean tryExact = true; int count = parameters.length - 1; Class[] types = new Class[count]; Object[] arguments = new Object[count]; for (int i = 0; i < count; i++) { Object param = parameters[i + 1]; arguments[i] = param; if (param != null) { types[i] = param.getClass(); } else { types[i] = null; tryExact = false; } } Method method = null; if (tryExact) { // First - without type conversion try { method = targetClass.getMethod(name, types); if (method != null && !Modifier.isStatic(method.getModifiers())) { return method; } } catch (NoSuchMethodException ex) { //NOPMD // Ignore } } int currentMatch = 0; boolean ambiguous = false; // Then - with type conversion Method[] methods = targetClass.getMethods(); for (int i = 0; i < methods.length; i++) { if (!Modifier.isStatic(methods[i].getModifiers()) && methods[i].getName().equals(name)) { int match = matchParameterTypes( methods[i].getParameterTypes(), arguments); if (match != NO_MATCH) { if (match > currentMatch) { method = methods[i]; currentMatch = match; ambiguous = false; } else if (match == currentMatch) { ambiguous = true; } } } } if (ambiguous) { throw new JXPathException("Ambigous method call: " + name); } return method; } /** * Return a match code of objects to types. * @param types Class[] of expected types * @param parameters Object[] to attempt to match * @return int code */ private static int matchParameterTypes( Class[] types, Object[] parameters) { int pi = 0; if (types.length >= 1 && ExpressionContext.class.isAssignableFrom(types[0])) { pi++; } int length = parameters == null ? 0 : parameters.length; if (types.length != length + pi) { return NO_MATCH; } int totalMatch = EXACT_MATCH; for (int i = 0; i < length; i++) { int match = matchType(types[i + pi], parameters[i]); if (match == NO_MATCH) { return NO_MATCH; } if (match < totalMatch) { totalMatch = match; } } return totalMatch; } /** * Return a match code between an object and type. * @param expected class to test * @param object object to test * @return int code */ private static int matchType(Class expected, Object object) { if (object == null) { return APPROXIMATE_MATCH; } Class actual = object.getClass(); if (expected.equals(actual)) { return EXACT_MATCH; } if (expected.isAssignableFrom(actual)) { return EXACT_MATCH; } if (TypeUtils.canConvert(object, expected)) { return APPROXIMATE_MATCH; } return NO_MATCH; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/util/package.html100644 0 0 1560 11044113545 24167 0ustar 0 0 Utility classes to assist with JXPath implementation(s) and/or usage. commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/util/ReverseComparator.java100644 0 0 2774 11044113545 26224 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.util; import java.io.Serializable; import java.util.Comparator; /** * Reverse comparator. * * @author Dmitri Plotnikov * @version $Revision: 668329 $ $Date: 2008-06-16 16:59:48 -0500 (Mon, 16 Jun 2008) $ */ public final class ReverseComparator implements Comparator, Serializable { private static final long serialVersionUID = -2795475743948616649L; /** * Singleton reverse comparator instance. */ public static final Comparator INSTANCE = new ReverseComparator(); /** * Create a new ReverseComparator. */ private ReverseComparator() { } public int compare(Object o1, Object o2) { return ((Comparable) o2).compareTo(o1); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/util/TypeConverter.java100644 0 0 3402 11044113545 25357 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.util; /** * A type converter can be installed on {@link TypeUtils} to introduce * additional type conversions for JXPath. Most of * the time {@link BasicTypeConverter} should be used as the superclass. * * @see TypeUtils#setTypeConverter * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public interface TypeConverter { /** * Returns true if it can convert the supplied * object to the specified class. * @param object object to test * @param toType target class * @return boolean */ boolean canConvert(Object object, Class toType); /** * Converts the supplied object to the specified * type. Throws a runtime exception if the conversion is * not possible. * @param object object to convert * @param toType target class * @return resulting Object */ Object convert(Object object, Class toType); } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/util/TypeUtils.java100644 0 0 5753 11044113545 24523 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.util; import java.util.HashMap; /** * Global type conversion utilities. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class TypeUtils { private static TypeConverter typeConverter = new BasicTypeConverter(); private static final HashMap PRIMITIVE_TYPE_MAP = new HashMap() { { put(int.class, Integer.class); put(byte.class, Byte.class); put(short.class, Short.class); put(char.class, Character.class); put(long.class, Long.class); put(float.class, Float.class); put(double.class, Double.class); put(boolean.class, Boolean.class); } }; /** * Install an alternative type converter. * @param converter new TypeConverter */ public static synchronized void setTypeConverter(TypeConverter converter) { typeConverter = converter; } /** * Returns the current type converter. * @return TypeConverter */ public static TypeConverter getTypeConverter() { return typeConverter; } /** * Returns true if the global converter can convert the supplied * object to the specified type. * @param object object to test * @param toType target class * @return boolean */ public static boolean canConvert(Object object, Class toType) { return typeConverter.canConvert(object, toType); } /** * Converts the supplied object to the specified type. May * throw a RuntimeException. * @param object object to convert * @param toType target class * @return resulting Object */ public static Object convert(Object object, Class toType) { return typeConverter.convert(object, toType); } /** * Return the appropriate wrapper type for the specified class. * @param p Class for which to retrieve a wrapper class. * @return the wrapper if p is primitive, else p. * @since JXPath 1.3 */ public static Class wrapPrimitive(Class p) { return p.isPrimitive() ? (Class) PRIMITIVE_TYPE_MAP.get(p) : p; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/util/ValueUtils.java100644 0 0 53414 11044113545 24673 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.util; import java.beans.IndexedPropertyDescriptor; import java.beans.PropertyDescriptor; import java.lang.reflect.Array; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import org.apache.commons.jxpath.Container; import org.apache.commons.jxpath.DynamicPropertyHandler; import org.apache.commons.jxpath.JXPathException; /** * Collection and property access utilities. * * @author Dmitri Plotnikov * @version $Revision: 670728 $ $Date: 2008-06-23 15:12:44 -0500 (Mon, 23 Jun 2008) $ */ public class ValueUtils { private static Map dynamicPropertyHandlerMap = new HashMap(); private static final int UNKNOWN_LENGTH_MAX_COUNT = 16000; /** * Returns true if the object is an array or a Collection. * @param value to test * @return boolean */ public static boolean isCollection(Object value) { value = getValue(value); if (value == null) { return false; } if (value.getClass().isArray()) { return true; } if (value instanceof Collection) { return true; } return false; } /** * Returns 1 if the type is a collection, * -1 if it is definitely not * and 0 if it may be a collection in some cases. * @param clazz to test * @return int */ public static int getCollectionHint(Class clazz) { if (clazz.isArray()) { return 1; } if (Collection.class.isAssignableFrom(clazz)) { return 1; } if (clazz.isPrimitive()) { return -1; } if (clazz.isInterface()) { return 0; } if (Modifier.isFinal(clazz.getModifiers())) { return -1; } return 0; } /** * If there is a regular non-indexed read method for this property, * uses this method to obtain the collection and then returns its * length. * Otherwise, attempts to guess the length of the collection by * calling the indexed get method repeatedly. The method is supposed * to throw an exception if the index is out of bounds. * @param object collection * @param pd IndexedPropertyDescriptor * @return int */ public static int getIndexedPropertyLength(Object object, IndexedPropertyDescriptor pd) { if (pd.getReadMethod() != null) { return getLength(getValue(object, pd)); } Method readMethod = pd.getIndexedReadMethod(); if (readMethod == null) { throw new JXPathException( "No indexed read method for property " + pd.getName()); } for (int i = 0; i < UNKNOWN_LENGTH_MAX_COUNT; i++) { try { readMethod.invoke(object, new Object[] { new Integer(i)}); } catch (Throwable t) { return i; } } throw new JXPathException( "Cannot determine the length of the indexed property " + pd.getName()); } /** * Returns the length of the supplied collection. If the supplied object * is not a collection, returns 1. If collection is null, returns 0. * @param collection to check * @return int */ public static int getLength(Object collection) { if (collection == null) { return 0; } collection = getValue(collection); if (collection.getClass().isArray()) { return Array.getLength(collection); } if (collection instanceof Collection) { return ((Collection) collection).size(); } return 1; } /** * Returns an iterator for the supplied collection. If the argument * is null, returns an empty iterator. If the argument is not * a collection, returns an iterator that produces just that one object. * @param collection to iterate * @return Iterator */ public static Iterator iterate(Object collection) { if (collection == null) { return Collections.EMPTY_LIST.iterator(); } if (collection.getClass().isArray()) { int length = Array.getLength(collection); if (length == 0) { return Collections.EMPTY_LIST.iterator(); } ArrayList list = new ArrayList(); for (int i = 0; i < length; i++) { list.add(Array.get(collection, i)); } return list.iterator(); } if (collection instanceof Collection) { return ((Collection) collection).iterator(); } return Collections.singletonList(collection).iterator(); } /** * Grows the collection if necessary to the specified size. Returns * the new, expanded collection. * @param collection to expand * @param size desired size * @return collection or array */ public static Object expandCollection(Object collection, int size) { if (collection == null) { return null; } if (size < getLength(collection)) { throw new JXPathException("adjustment of " + collection + " to size " + size + " is not an expansion"); } if (collection.getClass().isArray()) { Object bigger = Array.newInstance( collection.getClass().getComponentType(), size); System.arraycopy( collection, 0, bigger, 0, Array.getLength(collection)); return bigger; } if (collection instanceof Collection) { while (((Collection) collection).size() < size) { ((Collection) collection).add(null); } return collection; } throw new JXPathException( "Cannot turn " + collection.getClass().getName() + " into a collection of size " + size); } /** * Remove the index'th element from the supplied collection. * @param collection to edit * @param index int * @return the resulting collection */ public static Object remove(Object collection, int index) { collection = getValue(collection); if (collection == null) { return null; } if (index >= getLength(collection)) { throw new JXPathException("No such element at index " + index); } if (collection.getClass().isArray()) { int length = Array.getLength(collection); Object smaller = Array.newInstance( collection.getClass().getComponentType(), length - 1); if (index > 0) { System.arraycopy(collection, 0, smaller, 0, index); } if (index < length - 1) { System.arraycopy( collection, index + 1, smaller, index, length - index - 1); } return smaller; } if (collection instanceof List) { int size = ((List) collection).size(); if (index < size) { ((List) collection).remove(index); } return collection; } if (collection instanceof Collection) { Iterator it = ((Collection) collection).iterator(); for (int i = 0; i < index; i++) { if (!it.hasNext()) { break; } it.next(); } if (it.hasNext()) { it.next(); it.remove(); } return collection; } throw new JXPathException( "Cannot remove " + collection.getClass().getName() + "[" + index + "]"); } /** * Returns the index'th element of the supplied collection. * @param collection to read * @param index int * @return collection[index] */ public static Object getValue(Object collection, int index) { collection = getValue(collection); Object value = collection; if (collection != null) { if (collection.getClass().isArray()) { if (index < 0 || index >= Array.getLength(collection)) { return null; } value = Array.get(collection, index); } else if (collection instanceof List) { if (index < 0 || index >= ((List) collection).size()) { return null; } value = ((List) collection).get(index); } else if (collection instanceof Collection) { int i = 0; Iterator it = ((Collection) collection).iterator(); for (; i < index; i++) { it.next(); } if (it.hasNext()) { value = it.next(); } else { value = null; } } } return value; } /** * Modifies the index'th element of the supplied collection. * Converts the value to the required type if necessary. * @param collection to edit * @param index to replace * @param value new value */ public static void setValue(Object collection, int index, Object value) { collection = getValue(collection); if (collection != null) { if (collection.getClass().isArray()) { Array.set( collection, index, convert(value, collection.getClass().getComponentType())); } else if (collection instanceof List) { ((List) collection).set(index, value); } else if (collection instanceof Collection) { throw new UnsupportedOperationException( "Cannot set value of an element of a " + collection.getClass().getName()); } } } /** * Returns the value of the bean's property represented by * the supplied property descriptor. * @param bean to read * @param propertyDescriptor indicating what to read * @return Object value */ public static Object getValue(Object bean, PropertyDescriptor propertyDescriptor) { Object value; try { Method method = getAccessibleMethod(propertyDescriptor.getReadMethod()); if (method == null) { throw new JXPathException("No read method"); } value = method.invoke(bean, new Object[0]); } catch (Exception ex) { throw new JXPathException( "Cannot access property: " + (bean == null ? "null" : bean.getClass().getName()) + "." + propertyDescriptor.getName(), ex); } return value; } /** * Modifies the value of the bean's property represented by * the supplied property descriptor. * @param bean to read * @param propertyDescriptor indicating what to read * @param value to set */ public static void setValue(Object bean, PropertyDescriptor propertyDescriptor, Object value) { try { Method method = getAccessibleMethod(propertyDescriptor.getWriteMethod()); if (method == null) { throw new JXPathException("No write method"); } value = convert(value, propertyDescriptor.getPropertyType()); method.invoke(bean, new Object[] { value }); } catch (Exception ex) { throw new JXPathException( "Cannot modify property: " + (bean == null ? "null" : bean.getClass().getName()) + "." + propertyDescriptor.getName(), ex); } } /** * Convert value to type. * @param value Object * @param type destination * @return conversion result */ private static Object convert(Object value, Class type) { try { return TypeUtils.convert(value, type); } catch (Exception ex) { throw new JXPathException( "Cannot convert value of class " + (value == null ? "null" : value.getClass().getName()) + " to type " + type, ex); } } /** * Returns the index'th element of the bean's property represented by * the supplied property descriptor. * @param bean to read * @param propertyDescriptor indicating what to read * @param index int * @return Object */ public static Object getValue(Object bean, PropertyDescriptor propertyDescriptor, int index) { if (propertyDescriptor instanceof IndexedPropertyDescriptor) { try { IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) propertyDescriptor; Method method = ipd.getIndexedReadMethod(); if (method != null) { return method.invoke( bean, new Object[] { new Integer(index)}); } } catch (InvocationTargetException ex) { Throwable t = ex.getTargetException(); if (t instanceof IndexOutOfBoundsException) { return null; } throw new JXPathException( "Cannot access property: " + propertyDescriptor.getName(), t); } catch (Throwable ex) { throw new JXPathException( "Cannot access property: " + propertyDescriptor.getName(), ex); } } // We will fall through if there is no indexed read return getValue(getValue(bean, propertyDescriptor), index); } /** * Modifies the index'th element of the bean's property represented by * the supplied property descriptor. Converts the value to the required * type if necessary. * @param bean to edit * @param propertyDescriptor indicating what to set * @param index int * @param value to set */ public static void setValue(Object bean, PropertyDescriptor propertyDescriptor, int index, Object value) { if (propertyDescriptor instanceof IndexedPropertyDescriptor) { try { IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) propertyDescriptor; Method method = ipd.getIndexedWriteMethod(); if (method != null) { method.invoke( bean, new Object[] { new Integer(index), convert(value, ipd.getIndexedPropertyType())}); return; } } catch (Exception ex) { throw new RuntimeException( "Cannot access property: " + propertyDescriptor.getName() + ", " + ex.getMessage()); } } // We will fall through if there is no indexed read Object collection = getValue(bean, propertyDescriptor); if (isCollection(collection)) { setValue(collection, index, value); } else if (index == 0) { setValue(bean, propertyDescriptor, value); } else { throw new RuntimeException( "Not a collection: " + propertyDescriptor.getName()); } } /** * If the parameter is a container, opens the container and * return the contents. The method is recursive. * @param object to read * @return Object */ public static Object getValue(Object object) { while (object instanceof Container) { object = ((Container) object).getValue(); } return object; } /** * Returns a shared instance of the dynamic property handler class * returned by getDynamicPropertyHandlerClass(). * @param clazz to handle * @return DynamicPropertyHandler */ public static DynamicPropertyHandler getDynamicPropertyHandler(Class clazz) { DynamicPropertyHandler handler = (DynamicPropertyHandler) dynamicPropertyHandlerMap.get(clazz); if (handler == null) { try { handler = (DynamicPropertyHandler) clazz.newInstance(); } catch (Exception ex) { throw new JXPathException( "Cannot allocate dynamic property handler of class " + clazz.getName(), ex); } dynamicPropertyHandlerMap.put(clazz, handler); } return handler; } // -------------------------------------------------------- Private Methods // // The rest of the code in this file was copied FROM // org.apache.commons.beanutils.PropertyUtil. We don't want to introduce // a dependency on BeanUtils yet - DP. // /** * Return an accessible method (that is, one that can be invoked via * reflection) that implements the specified Method. If no such method * can be found, return null. * * @param method The method that we wish to call * @return Method */ public static Method getAccessibleMethod(Method method) { // Make sure we have a method to check if (method == null) { return (null); } // If the requested method is not public we cannot call it if (!Modifier.isPublic(method.getModifiers())) { return (null); } // If the declaring class is public, we are done Class clazz = method.getDeclaringClass(); if (Modifier.isPublic(clazz.getModifiers())) { return (method); } String name = method.getName(); Class[] parameterTypes = method.getParameterTypes(); while (clazz != null) { // Check the implemented interfaces and subinterfaces Method aMethod = getAccessibleMethodFromInterfaceNest(clazz, name, parameterTypes); if (aMethod != null) { return aMethod; } clazz = clazz.getSuperclass(); if (clazz != null && Modifier.isPublic(clazz.getModifiers())) { try { return clazz.getDeclaredMethod(name, parameterTypes); } catch (NoSuchMethodException e) { //NOPMD //ignore } } } return null; } /** * Return an accessible method (that is, one that can be invoked via * reflection) that implements the specified method, by scanning through * all implemented interfaces and subinterfaces. If no such Method * can be found, return null. * * @param clazz Parent class for the interfaces to be checked * @param methodName Method name of the method we wish to call * @param parameterTypes The parameter type signatures * @return Method */ private static Method getAccessibleMethodFromInterfaceNest(Class clazz, String methodName, Class[] parameterTypes) { Method method = null; // Check the implemented interfaces of the parent class Class[] interfaces = clazz.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { // Is this interface public? if (!Modifier.isPublic(interfaces[i].getModifiers())) { continue; } // Does the method exist on this interface? try { method = interfaces[i].getDeclaredMethod(methodName, parameterTypes); } catch (NoSuchMethodException e) { //NOPMD //ignore } if (method != null) { break; } // Recursively check our parent interfaces method = getAccessibleMethodFromInterfaceNest( interfaces[i], methodName, parameterTypes); if (method != null) { break; } } // Return whatever we have found return (method); } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/Variables.java100644 0 0 4322 11044113545 23503 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; import java.io.Serializable; /** * Variables provide access to a global set of values accessible via XPath. * XPath can reference variables using the "$varname" syntax. * To use a custom implementation of this interface, pass it to * {@link JXPathContext#setVariables JXPathContext.setVariables()} * * @author Dmitri Plotnikov * @version $Revision: 652925 $ $Date: 2008-05-02 17:05:41 -0500 (Fri, 02 May 2008) $ */ public interface Variables extends Serializable { /** * Returns true if the specified variable is declared. * @param varName variable name * @return boolean */ boolean isDeclaredVariable(String varName); /** * Returns the value of the specified variable. * @param varName variable name * @return Object value * @throws IllegalArgumentException if there is no such variable. */ Object getVariable(String varName); /** * Defines a new variable with the specified value or modifies * the value of an existing variable. * May throw UnsupportedOperationException. * @param varName variable name * @param value to declare */ void declareVariable(String varName, Object value); /** * Removes an existing variable. May throw UnsupportedOperationException. * * @param varName is a variable name without the "$" sign */ void undeclareVariable(String varName); } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/xml/DocumentContainer.java100644 0 0 14601 11044113543 26033 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.xml; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.HashMap; import org.apache.commons.jxpath.Container; import org.apache.commons.jxpath.JXPathException; /** * An XML document container reads and parses XML only when it is * accessed. JXPath traverses Containers transparently - * you use the same paths to access objects in containers as you * do to access those objects directly. You can create * XMLDocumentContainers for various XML documents that may or * may not be accessed by XPaths. If they are, they will be automatically * read, parsed and traversed. If they are not - they won't be * read at all. * * @author Dmitri Plotnikov * @version $Revision: 668329 $ $Date: 2008-06-16 16:59:48 -0500 (Mon, 16 Jun 2008) $ */ public class DocumentContainer extends XMLParser2 implements Container { /** DOM constant */ public static final String MODEL_DOM = "DOM"; /** JDOM constant */ public static final String MODEL_JDOM = "JDOM"; private static final long serialVersionUID = -8713290334113427066L; private static HashMap parserClasses = new HashMap(); static { parserClasses.put(MODEL_DOM, "org.apache.commons.jxpath.xml.DOMParser"); parserClasses.put(MODEL_JDOM, "org.apache.commons.jxpath.xml.JDOMParser"); } private static HashMap parsers = new HashMap(); private Object document; private URL xmlURL; private String model; /** * Add an XML parser. Parsers for the models "DOM" and "JDOM" are * pre-registered. * @param model model name * @param parser parser */ public static void registerXMLParser(String model, XMLParser parser) { parsers.put(model, parser); } /** * Add a class of a custom XML parser. * Parsers for the models "DOM" and "JDOM" are pre-registered. * @param model model name * @param parserClassName parser classname */ public static void registerXMLParser(String model, String parserClassName) { parserClasses.put(model, parserClassName); } /** * Use this constructor if the desired model is DOM. * * @param xmlURL is a URL for an XML file. * Use getClass().getResource(resourceName) to load XML from a * resource file. */ public DocumentContainer(URL xmlURL) { this(xmlURL, MODEL_DOM); } /** * Construct a new DocumentContainer. * @param xmlURL is a URL for an XML file. Use getClass().getResource * (resourceName) to load XML from a resource file. * * @param model is one of the MODEL_* constants defined in this class. It * determines which parser should be used to load the XML. */ public DocumentContainer(URL xmlURL, String model) { this.xmlURL = xmlURL; if (xmlURL == null) { throw new JXPathException("XML URL is null"); } this.model = model; } /** * Reads XML, caches it internally and returns the Document. * @return Object */ public Object getValue() { if (document == null) { try { InputStream stream = null; try { if (xmlURL != null) { stream = xmlURL.openStream(); } document = parseXML(stream); } finally { if (stream != null) { stream.close(); } } } catch (IOException ex) { throw new JXPathException( "Cannot read XML from: " + xmlURL.toString(), ex); } } return document; } /** * Parses XML using the parser for the specified model. * @param stream InputStream * @return Object */ public Object parseXML(InputStream stream) { XMLParser parser = getParser(model); if (parser instanceof XMLParser2) { XMLParser2 parser2 = (XMLParser2) parser; parser2.setValidating(isValidating()); parser2.setNamespaceAware(isNamespaceAware()); parser2.setIgnoringElementContentWhitespace( isIgnoringElementContentWhitespace()); parser2.setExpandEntityReferences(isExpandEntityReferences()); parser2.setIgnoringComments(isIgnoringComments()); parser2.setCoalescing(isCoalescing()); } return parser.parseXML(stream); } /** * Throws an UnsupportedOperationException. * @param value value (not) to set */ public void setValue(Object value) { throw new UnsupportedOperationException(); } /** * Maps a model type to a parser. * @param model input model type * @return XMLParser */ private static XMLParser getParser(String model) { XMLParser parser = (XMLParser) parsers.get(model); if (parser == null) { String className = (String) parserClasses.get(model); if (className == null) { throw new JXPathException("Unsupported XML model: " + model); } try { Class clazz = Class.forName(className); parser = (XMLParser) clazz.newInstance(); } catch (Exception ex) { throw new JXPathException( "Cannot allocate XMLParser: " + className, ex); } parsers.put(model, parser); } return parser; } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/xml/DOMParser.java100644 0 0 3703 11044113543 24167 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.xml; import java.io.InputStream; import javax.xml.parsers.DocumentBuilderFactory; import org.apache.commons.jxpath.JXPathException; /** * An implementation of the XMLParser interface that produces a DOM Document. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class DOMParser extends XMLParser2 { public Object parseXML(InputStream stream) { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(isValidating()); factory.setNamespaceAware(isNamespaceAware()); factory.setIgnoringElementContentWhitespace( isIgnoringElementContentWhitespace()); factory.setExpandEntityReferences(isExpandEntityReferences()); factory.setIgnoringComments(isIgnoringComments()); factory.setCoalescing(isCoalescing()); return factory.newDocumentBuilder().parse(stream); } catch (Exception ex) { throw new JXPathException("DOM parser error", ex); } } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/xml/JDOMParser.java100644 0 0 3601 11044113543 24276 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.xml; import java.io.InputStream; import org.apache.commons.jxpath.JXPathException; import org.jdom.input.SAXBuilder; /** * An implementation of the XMLParser interface that produces a JDOM Document. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class JDOMParser extends XMLParser2 { public Object parseXML(InputStream stream) { if (!isNamespaceAware()) { throw new JXPathException("JDOM parser configuration error. JDOM " + "does not support the namespaceAware=false setting."); } try { SAXBuilder builder = new SAXBuilder(); builder.setExpandEntities(isExpandEntityReferences()); builder.setIgnoringElementContentWhitespace( isIgnoringElementContentWhitespace()); builder.setValidation(isValidating()); return builder.build(stream); } catch (Exception ex) { throw new JXPathException("JDOM parser error", ex); } } } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/xml/package.html100644 0 0 1520 11044113543 24004 0ustar 0 0 Support classes for working with XML. commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/xml/XMLParser.java100644 0 0 2546 11044113543 24214 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.xml; import java.io.InputStream; /** * Common interface for XML parsers. We are not using JAXP because * some of the parsers we want to support may not be JAXP compliant. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public interface XMLParser { /** * Reads the supplied XML file and returns the resulting model, * which is not necessarily DOM. * @param stream InputStream * @return Object */ Object parseXML(InputStream stream); } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/xml/XMLParser2.java100644 0 0 11415 11044113543 24311 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.xml; import java.io.InputStream; /** * The abstract superclass of XML parsers that produce DOM Documents. * The features have the same defaults as {@link javax.xml.parsers.DocumentBuilderFactory}. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public abstract class XMLParser2 implements XMLParser { private boolean validating = false; private boolean namespaceAware = true; private boolean whitespace = false; private boolean expandEntityRef = true; private boolean ignoreComments = false; private boolean coalescing = false; /** * Set whether the underlying parser should be validating. * @param validating flag * @see javax.xml.parsers.DocumentBuilderFactory#setValidating(boolean) */ public void setValidating(boolean validating) { this.validating = validating; } /** * Learn whether the underlying parser is validating. * @return boolean * @see javax.xml.parsers.DocumentBuilderFactory#isValidating() */ public boolean isValidating() { return validating; } /** * Learn whether the underlying parser is ns-aware. * @return boolean * @see javax.xml.parsers.DocumentBuilderFactory#isNamespaceAware() */ public boolean isNamespaceAware() { return namespaceAware; } /** * Set whether the underlying parser is ns-aware. * @param namespaceAware flag * @see javax.xml.parsers.DocumentBuilderFactory#setNamespaceAware(boolean) */ public void setNamespaceAware(boolean namespaceAware) { this.namespaceAware = namespaceAware; } /** * Set whether the underlying parser is ignoring whitespace. * @param whitespace flag * @see javax.xml.parsers.DocumentBuilderFactory#setIgnoringElementContentWhitespace(boolean) */ public void setIgnoringElementContentWhitespace(boolean whitespace) { this.whitespace = whitespace; } /** * Learn whether the underlying parser is ignoring whitespace. * @return boolean * @see javax.xml.parsers.DocumentBuilderFactory#isIgnoringElementContentWhitespace() */ public boolean isIgnoringElementContentWhitespace() { return whitespace; } /** * Learn whether the underlying parser expands entity references. * @return boolean * @see javax.xml.parsers.DocumentBuilderFactory#isExpandEntityReferences() */ public boolean isExpandEntityReferences() { return expandEntityRef; } /** * Set whether the underlying parser expands entity references. * @param expandEntityRef flag * @see javax.xml.parsers.DocumentBuilderFactory#setExpandEntityReferences(boolean) */ public void setExpandEntityReferences(boolean expandEntityRef) { this.expandEntityRef = expandEntityRef; } /** * Learn whether the underlying parser ignores comments. * @return boolean * @see javax.xml.parsers.DocumentBuilderFactory#isIgnoringComments() */ public boolean isIgnoringComments() { return ignoreComments; } /** * Set whether the underlying parser ignores comments. * @param ignoreComments flag * @see javax.xml.parsers.DocumentBuilderFactory#setIgnoringComments(boolean) */ public void setIgnoringComments(boolean ignoreComments) { this.ignoreComments = ignoreComments; } /** * Learn whether the underlying parser is coalescing. * @return boolean * @see javax.xml.parsers.DocumentBuilderFactory#isCoalescing() */ public boolean isCoalescing() { return coalescing; } /** * Set whether the underlying parser is coalescing. * @param coalescing flag * @see javax.xml.parsers.DocumentBuilderFactory#setCoalescing(boolean) */ public void setCoalescing(boolean coalescing) { this.coalescing = coalescing; } public abstract Object parseXML(InputStream stream); } commons-jxpath-1.3-src/src/java/org/apache/commons/jxpath/XMLDocumentContainer.java100644 0 0 7357 11044113545 25610 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; import java.net.URL; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMResult; import org.apache.commons.jxpath.xml.DocumentContainer; import org.w3c.dom.Document; /** * An XML document container reads and parses XML only when it is * accessed. JXPath traverses Containers transparently - * you use the same paths to access objects in containers as you * do to access those objects directly. You can create * XMLDocumentContainers for various XML documents that may or * may not be accessed by XPaths. If they are, they will be automatically * read, parsed and traversed. If they are not - they won't be * read at all. * * @deprecated 1.1 Please use {@link DocumentContainer} * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class XMLDocumentContainer implements Container { private DocumentContainer delegate; private Object document; private URL xmlURL; private Source source; /** * Create a new XMLDocumentContainer. * @param xmlURL a URL for an XML file. Use getClass().getResource(resourceName) * to load XML from a resource file. */ public XMLDocumentContainer(URL xmlURL) { this.xmlURL = xmlURL; delegate = new DocumentContainer(xmlURL); } /** * Create a new XMLDocumentContainer. * @param source XML source */ public XMLDocumentContainer(Source source) { this.source = source; if (source == null) { throw new RuntimeException("Source is null"); } } /** * Reads XML, caches it internally and returns the Document. * @return Object value */ public Object getValue() { if (document == null) { try { if (source != null) { DOMResult result = new DOMResult(); Transformer trans = TransformerFactory.newInstance().newTransformer(); trans.transform(source, result); document = (Document) result.getNode(); } else { document = delegate.getValue(); } } catch (Exception ex) { throw new JXPathException( "Cannot read XML from: " + (xmlURL != null ? xmlURL.toString() : (source != null ? source.getSystemId() : "<>")), ex); } } return document; } /** * Throws an UnsupportedOperationException * @param value to set */ public void setValue(Object value) { throw new UnsupportedOperationException(); } } commons-jxpath-1.3-src/src/site/resources/images/jakarta-logo.gif100644 0 0 17506 11044113546 22344 0ustar 0 0 GIF89a^dæÿÿÿÿ!!!111999BBBcccsss{{{ŒŒŒÞÞÞïï籠„Þ„„Îï÷JB„”Öÿï!çÎÆµZ9÷RÿB÷k1ÞBÎ{Rç„RÞk1ÎRÖœ{ï{9çµ”ÿsÿc÷­{¥B½{JÎkÞcœ”Œ÷çÖskc÷¥RÎÆ½¥Zν¥ÖÆ­­”kcZJïÖ¥­{Ö­Bïµ)ç΄¥„sZ÷Ö)έέµœÞ½çÖcÿç½½µ{{s„„{„„sBcÖŒµÿ9ÿ9­c)ÎB!Z9ŒkÿkÞœÿ”)Æs­”ÞcŒJkcŒµÿ”½ÎŒÞ{”ÖÿÖ掠”Œÿï{kÖ1½”{ÞµµŒÿµœc΄ï{½ç„ÿŒµZçJ”ï!„{9”9ÞRÿR¥Rk­1Î!{÷1ïÿ­Ö,^d@ÿ€‚ƒ„…†… ‡‹ŒŽ‘’“”•–—˜™š›œ— ‰C¤CBŸ„‰BDB33*BE *||s|xwu·x}&##-"¡84©ÐÑÒÓÔÕÖ×Пڡ‰´ B¤â¤DQIHJHLRQSRTT^V_Wa`cùakinþmoÎøs3çMƒÀö< ð@‚„ *˜à B„l3jÜȱ££o.T$`Á† C`$P €Í˜3bòyy'ÅŠvMÎÇÓˆ‘#H– I²d $MØM‰"Þ-[¶xÁ7MÌ|hÞø«#G«?:}îìÙC¡ì„9tæ™°!‰ÿL@Ð@× xóêÝ«é"n `HáŸ>xøÔáµXë4ùÆ\ÍwÆË—/` n¹â%ª•&9ŸðÝó§%GÔ!š´iN&준Žo³å/‘Å\É'ÆJdÉhÞâó O=„e0ÑÀs/òN½zµmÜuS nMLÈ@A|Ùâ†äÙs°OZ7wÚ¸yó>¾?5tüÍq“&~iŒ‘Æ=c€áÅ”‰Ûbàs™=‘}áÅTHÅ[L‘EWpaE^xA‡|õÁÿCH°PD˜`@!ƒ €ÐÂŽ¼×o&ÛŠdå´,PÀÃAæp†4X%2a@P¸°+H¯&\ DÓ©?áè ŠQ”œH V°B<® …ìQ¦3`øB¼`:7¨Á JÃÔ †­À§~86 ?P}h4°¿Üïˆ~ËÎ’D0‚˜`9ã©€øÚÞƒØg>oèÏcú#†0Œ õðB>®@Í„á2V®iá p,WDZ“Ÿ$! FH‚:–€Ž›À£&M€‡g´ ½Ë`Æ /èÁ|àƒÉ( Bv@$ZÒT©(’7åË)@ÿÊBÞr d@&( *)0@¤!ÁðC Ó‡<øá‹ù^Ú0=„kàî0:Ì¡¹Ãúc†60³Èä¥Vú¡Èèã7ò$Pƒå F6ÊÁzàEú Ú¸¤:y—IU Ü€g‘4©oÔ³õ´ç X¢yúóŸ˜2â:Z©}©JhùYAI©Ž 2„B÷PÆE4e -D¿–ö³Ná åæ$×0Œò$hiHº+“6g]„ FJš°MŽU8€ в‡É ’û¨£„ÖÑI¥êa£ ZLíwÑ»!”a-—I“RŠ-ÊeèÿZ\Jˆc5,«¤ÙªS—ªQF½lŽkÙ ªÔ?¼T,å Û`êVULu4ÚRÀ]IñÑ"kwxDR 1ØM(à§8,!t ‰ÀV¢°‡r,^0¶R:#K›­01X€³ÅVŒ8¹@d]Em±¡‚ÀT8X+wÁvµýlg ‚Ú&ඃ(-mm[ѱ·ÄUE«°Û¹ámÇr×Ú¢Ý?¸öj…pÁ‰ ÙËB"žPáªêÝòš×# `_U@‹F, O. fÐ ðZÀ$xAÂ#ÙiÀv+ðyLàIdR‰0 )Ø› @ÿ*Âÿ,‡]ª! kÈ¢~V׺6ñay†rÔw‚Ü@Gà-°ŠÏ;$n¸`ð:éN 0–8á)RШ—BÞ(P -\4o±‡îAäó¦;¬‰ÁE\PЂÜ€p†”÷¬7©àÏC˜Añ]„•(  ¬Ð”°%\pRvô2lŽÀ&,T˜Bg¾°…2_Æ@¼ñ œ‚iÅ4±2s¸eY*àõmà$øÁ ÌWb€ Å|ÎuFóçÂ!½,aCÞ 2àÃQi †>ÿ#0¡‚>Êj]”¡@O!LöTN™5¨Á™Å|C÷d(úÂy8¦ZpXNÄó[A{uMoOü“ ¸@YÜó¦ýøc üx èRX3r \ÀB<–²”'ìµ4GÈcQöÈ„$²)€ŒM¬°CzÚv>Ò †¤w&|¼‚ÌÔ…‰"à‘@ëMsG(‘%"  ÌS 0D|{ÀøÞ0MþÀ0@ÒÇè:³¾#›ÉB&HA´Z—G8‚µI'!6®¹ø¥áAB/FÃj( ši~„›F= gv4óšï™HKl0Z«g!|º›æPÅÿï!S—† dk¢!éW"5] \à´‡ÀÐ!,„P Y˜ âhu á >Ñ£:@3p~S’AðA7Ã)NØ8È”ÝuÝâP$É8 @0p€Ã0A[N  àðyÀCÐ}Åà!1u@Ì/åð7´!íXq¦_ºI@/1öÂpÆõébHú Ä…xÓ‘=x| ¸H:@@:P[9Àñ´{ (Oô´OJbÐ àPâ'@|Ä` éc³CÑ|àfÃv·t½@„§w°¸ÔaLïñsІ± AôÿKÁi`5à5"k9@{ìc‚b9…²€JèN‡ð ½wo¾ç€RèIRø{RxSR3“èV¨øW@–xPy8ÒøŠ“2Wcõÿâ+ã@5ÄøT¥ÂŒäàŒ*ÃŽ¤ ZtÅVŸ˜‡eRŘ+ÒxÔ1¥ +†àªÈUÜXWˆŠeáÆ0$°¹£¤hºkòä?3šI–y°À+±v`EinãS‘a ¦È g9š¦ˆjsã¢D˜(5æb,0Ep5¦eP¢¤Öfjgªd) sƒaÀ!Pgš¨¬ ½ç`8ù-BÐ[°9S[ pVp—q ÝV:‘qCãcÐ&íÖ°@# º×ªÒ‡F–™",`9NLpqM `ÿ«2/ñmnp('¬Vg¸ð¯cª àd«:­Ò:OIN:?Q|4±‘Ò³«QWa:hZdr.çK‡·0%p>pkÑJ¯hª Èó À*ÖEî¢ù:©1ë÷{ dH]”Ý£*ÇK«s°|Å |€-Ð P±+¢„,¶9,ð À¦TÐ7¦<¦¯yÔu_‡q5Áðm·«ú0ÛrMx½ð qѬ&àJ˧sP2@ð'D¯­?Koïee!1UŠ9DÐ ,QâïðeGq¢GB¡AײñÿAZÀqçgï—dð²iðЄnǤ‡a¶n‘(qö­&ª&V¦‡:·S…'ae PežÄó±2!dí =MpGMK>a]·G|Má5‘y˜=&:ý¡1¡EÁ!kbr¼dƒ«V¶baà€!-ºª«;Ø û£´Ð»m ‚b¤²)ä!I¸9U·(ѶGèÐh'' r™Á«*$F#·Kê·~dç:ÿ±s@x¬³&Ê笃ñ&Ð-6¯ãK¾ó„„¾×à·Ðòám‹ gpFâ Ôt=økÿu\׿EÑA²¡qÖÓqaÐBŒ\@yd výaLÂqÂ^z0z L¾‹zo 0âÓ:æFùAl”t-!\`[À:&S@èWz>Á¿’ÖŒQдÁ´F›–=’{Àn ©=ˆ°Ð‹C²SCä·1`¤S¬8ét`¾'6ÀÅ"æ° ½@YÔhÀƒÚ3:WyGFWÇJðTçÆ¦‡«qGüºrL¼Mc;a0ájšÑ«ãVLw@èŠ `› t¸CEÔÈ{ƒwŸdk+¦ÊwJ ïÁÉçê}Ó”i š:ÿpšÇqV€¼a B 4ÎY ÊWztdGO0²FÑ¿°A•æɆ+dBg`ºñ3ÔM‹I㔲ÌÌl47‡$4à>€& s&@|pØ—®Atÿ0Mm`M’1®ægM•§»ñVàEõ@HS0O G«ÌÎâ`G§P °ai v5q5µG{ÛI>`Ê,¾íäÌ¿g±‡ÃÀ½çÁ®×Ç‚æÌÿpagàÖß§EÖÔÇÄ«W€& ôF—$œGBuŒ¿êìpW ;1,Bß#90„áN´ç;°¹gÔG½-¶$. ÿ!àD(@ÅðÐ|ÆA8h}›ÜK¹¤ƒÈDƒÿö=þÐf€ _r°Ü^ÀÑ #Ö%Tp”gvë7›ýÇ,¢¾‰"*-Â"ŠDN6@Ø…ÍœÐHâ‚P|¨:Ë ¨ý@6¸&@èv‚Æxba}F†®ÆT@YÍÀ`\ÁÔ3>¬òç2$â· 4:fP#¯÷H’ä×7²Hýç":0ÜÄ]ÜÖáO›T…h.ÐÜpXlªP m! Ñ|è¶Å»€Þ'z xàoÐÃjLUûÑÍÔ¼kE)85„ts@N|}ÿ#öI±—6ã4Ð?>+ན)mˆOZø{'" ŽJ9˜}²@$øµ'Xd×}Â"ævCTò²bcqVíkpäÉýg À€¤wØ@ 0| ÐÀ À Àv  `d.vÀ¶s¤Hr;,àTH…KÂ…=Nçö3sCrçP˜çz¾ê«î{ýäOpHê=€Ÿ@â„¿%Dä¾þë\লiw_HĉpìúNÏð(rè8 ð Ð Õ0GÙi 岡Ø@ÿíÖÞ8ÌΊ ìœ°ÀrP©äŽ07űSðÎðȉ2Ðð­‰9HU’„ `5æ/ Yœ@ñŸ)TY¢!/^ @òÀH’éñ!9Ðòºñu§ó¾’,st˜Šð9)ŽÈŠ'E^Œ ˆÜÕ)Ô‰P¤ØYM?)»Õ‰¥5±º*ƒ0õ‹¢òùQ)©.VORIE¤5»˜Œ‚R¦HõD•ŠsŒÐ®,¡Âí*¨•’B¿ô?É^…p’ )·ˆËˆ6€_ÿ¢' /šð•iøíÂbˆOGŠ/^E9G‰PxÏZ¬ 2æ9 À9DrÒØ‰®÷|_“hùñ"9Ñ ÚxïäNB™"Žˆ26ƒ7Ð2ú‚€ú†°ú³èúYïCŸïÀO“7Ó¥·‰ß8ø9Ž¿?¸X“…4Ò?)ÏúË?I-¿üs½8éýÉTD¿0-*Ø‚e~¸85žVÕüPE L ûCRª ƒBB„ˆˆ‹ ‘’‚„†ˆŠ„••‹’”’„•„ ‘£˜B±²³.©ƒ§¡­º½¾¿ÀÁ½Ÿ¼–‹„ Âÿ¥ƒˆ¯ƒ«“„‡›ƒ¬„.Ôƒ*»Ø‘ÛŒäÑ¡Æ×ƒÙšÈ¾ÄòÞ•—ƒµ.ƭʃ̾îýy·®ž³ƒÒ«VÌ`#‘ -+@q™®s‹5C4c‘!!2æk÷GÚ±eÍ:Â)2]ÉP[ªô1䢑.|YÉß  XtÀ“C1ÿ (1À³E$0ðjÜÓŒøjÝlž¨£'¹EZ4cºÜ2‹6’@B3îÍpiÑZ¼.ÝPj±þÁvQ_¾;­éb‡ˆ¬à?gª[öS[ ™»va® C‹Mº´éÓ¨µ2Nͺµë×°cËžýu2ÿíÛ¯àæH°ÑŒwŠþÒ½{6ñâ´õ9¹óÒèŠImÀª¤ê £oÕþ|]÷ëv¯°äp¢¦‹7UÒ€\’‚v’Ÿ^Ÿ!ð0`@’‹fø‰Ò+•ü—H~ +ì hßñõ·€u“$pžSZâà|3,°@\Jr@  £€Ð,%y,wÜéçÉ.À€Ô‰3꣒((Ö˜CÁ˜ãX@Š•V‘BÊØÈHÖ7dŒP Cà”TÆØâ•ÛÑ 3n©Üe“Ò^$ïI¢‚ˆœé]#Ü'df8 P‹ IzÙ%"r@§{ùå¹'+bn€ŸÜPÔ}UÚHc€‡½•‰H~(^Œ þ‰å¥ÎY Øqcqê$¦ò€ê¢¨¤Òæi/mv’j|@a©•œ «6©ä9ë­¸æªë®¼öêë¯À’;klˆ›b#cú,{ÕE„¦Ø¦mB-¯ˆ@æ®'@@*ìª,¢Ù‚k$—‘| @¸ß@Ëh9æfb$dÞŠdpˆšˆî!†"ªh°“1Âî±l0©¥,#¬ ¿ú!±B|ðÄãØp(Úz’q- ¤‡kXæêVlòÉ(§¬òÊ,·ìòË0Ç,ó!;E•W† a©Õv[n1jàpÃw\C7[оWÜ‚b!$–¡y'r€X`³u×- Þ7Ð@6ºUxáÐÔíw]Ì ÝÏHàâ‹`w£s ìX³ y]8;àcÏPfxe–ù ·€†T6°€5’ù³›Aæ„w…snyh¢3Ú9æ‰pàšÿÀ€—n:€ÿ8¢¦Á]h†F÷é—b„ €º×®³›¡¥ˆØbxXÜÐöÚižèh…²&Xéܶ,¸ëN¨4Æ[ïÃû%!©Á¥Új‡"Ç»d‰çþÇð¢;÷"¾Ò\f4€sвþG¡“5g!•K7áÖçf\ö;\Åçæ€Ú~Ý¡ÐP@ÜÀ]wq(i÷‡FÈaÒMG÷~©ï÷÷Ï»÷>ó¸Oh\ʘA`ÉBÿÌ:>\Ô%R}!"fwÑ“~@õö·?¡Ú9rã €õ?¡Õo!”ÈèÀe€Ì€ x[ñTG,•­¯ïWݰÿ¾\Ɔøø÷=v®xãKšBP3Ü%o!YÖjöêå\€^†ç²plÄkáD‚º¹aK‡ÿxœ!n»p•Ë]EŒ!Ch¨¼'Љ)äâçVÅ!º°fës Eæ×3Õõk‰â’âBö7º)†‘!9{£æø²;Ê1!ë«¡ß–ˆ.2±w5œc»xH–}Ñ„ ya¸ö®¼5@’“œdü"2‘qîŒhäõvD0þƒ‡âê_'ÿ‘·éÝPh73%*J"‚‹´b¸¤§è‰eë‹$%)Y7èÝò!BCd1©¥H™™€á @ SWD> ñ¯ƒeÇÎGÊPÿRS•†Œã—¨MGFD‘´d$Ý2™¡¬vÍŒˆ)†D=SžÇÄc!ã©ÌK“øâèþçDH6€ØÛ\7ÑeÊÓÔ“ç„–Fø@¡§(A-¹ÄY´!Á@ÆgOo"$T»› º YëD;8O˜â ™ÜÄ'5÷¯‡<z;#–)£ØÉ6.—á:€Åúe Jó„–Ù)QâSp!5Šâ¬' ^ #ÄÄÆÃ»b+ÄÉ3’,“ /ÅÎ….Ù ÝXÈo-pNk™#ûWWE+Þ“‡üäy&¹!‚c•]x-ÇæJÊ¥ší?: e0‡YÌc&s™Í|f4#2 ;commons-jxpath-1.3-src/src/site/resources/images/logo-for-anakia.jpg100644 0 0 15554 11044113546 22753 0ustar 0 0 ÿØÿàJFIF––ÿÛC     ÿÛC  ÿÀpú"ÿÄ ÿÄ9!1"AQ2#BaR‘$bq‚CDS¡ÑðÿÄÿÄ.1!AQaq±Á¡Ñáð‘"24ÿÚ ?¿Ô¥)JV½Î9ž+§ÜW'É9¦; |&FU×|­ð± $ÌÄ(³äæ²c¼Á!FLØiZ×çΣñ _'À{ËÈÆÍN²#+²:°Ù ¬<¶ ²îŒ¥Iq†ˆ¥)X™ŠR”ˆ¥)HŠR”ˆ¥)HŠR”ˆ¥)HŠR”ˆ¥)HŠÂò¾[…àø+¬ç+¿‹µÝÕ›[ Af$Ÿ€ ¬ÕS¿Vá9VúQÄr_¬þ}wêÑn;b”Kr‘ÕCª†úÙÆ¾ S¦¨]`Ry}¤ú‹M5–ËuŒÉZfq¶y,\ësc{\[ÌŸ¶HÝC+ìA»U¯HŠ±Æ€*ªàYk ÍÄE‰ÝN{¥·JR±JR‘¥)^zñÉ]ËÔ¾=–fklÜC,’O*»~vDQüEzT#×®DËÏ8¶?ÙE¾!§‡›Ü™—´¯ÈÚØ?~ãø®§Ã?és›ñùÏ”’ý'òùaèõÄSÀ¶W— ÉU•Ë÷# ;”ëà©d0yA|vö* tZ{›n•ñ¸eŠX;Rr½ã]ê×0`?7ß[ùøÑ6_§Îαߊ—Vs¨*Ó PžH”ªuë3¬œ§‰åð¼W‹Iw„·h“#.N 9'pìHÃCµt¼–QàÝ1t¬C©Ý7ÇäòŽjЛ,™Ð^ùÐæZ²¶€ |V_KbP.;åu(÷†âLu ucÔÿ éFJ ]ßê3¹Fcú‹|kÆæÔ»÷IaÚÅX•_;íóÚ5Óë¯Z.0ñpžž-ÅïQóÉca†ánì¦bí¥}lý>´¢±xM\3Žô¶çˆälí/ò×Ж»Ì=º¼ÉrWAâfUB~•ñ½ùfߺª­{ö;YæË,rRÆçÛÇÒN‘v¹d€<Ô¹±ùåSú5“éÏ/°ÀEyir}£q™X·gk+ØÝÄQ ïä w)Ò^iÃ,]ú?Ï3†Þ9բċֵúIò{ìnw䂪'äø;-Ñé‚¡[1žÞ¿i®­^ –â¯8ìýç=¥yákÖP½:»KžAG)‹³íÌw˜äžÝ“Îû®#]®·¿5¡½Rã½0w×Ë-âw˜{f*¢æÒñnûI:%¢£çÇqü Ðß¼ ¦w¹uÔ“‡Êžñ-í+„ä8ÎGŒµÉá/a¾°»ŒIÑ6ÕÔýÇÿŸjÉü×8‚ ¼óJR±3¥)ë?¨!Ó^Iâ¼c'*åYGWýrÂBĪýaOÖÌ†Ž‚’Ú»š½äû°ÝPN›È½NõmÈ9L-Æ3su{ÈÌË,QÓÀU¼|í‘W sÝòv÷|š»WRQÀƒ|dùý¤ZkZî';gÊoŠÁ†ÔìUNê2įV\s ÌàøÕÉ]BÀ§·qÜ$N¾®âö{ó­¯?6›þ媱ûÕWéš¿$õÖN[ oidã 6¹$VDfVßoþÓ¸Ÿæ/Çq¥ÿïØ=yLê?È¢vŸNrcyeg'gÉ­÷Œ¶Xù5£ÇtŠ?&¤;ý«H×ûTRÉÙ¥)HŠR”ˆ¥)HŠ«³×)—ãöØ›[Œ=–*Óq—»’ø!šVŠh#Há,¥‘‰›åuݾÒ@:kOT{×n/+Èø¬–†Kë;|eÔÍm»1µUxÄ“;@S܃zvù'~:^-JÈuÇv™n‘ËW¦<^tF@¶†Ìr2þ¥I«ÓøBÆ¿ØTÒ{hìúeÅ"C¼zIí Œ½ÅÉs&ÏÇynþß…ïíOüocüµ6£9ñÚ}egå.{¤Õ=Mðé¹H³qcq™Œš ›hæ‰ÚEíýÍBH±Qä1¥H:ª ÑN¬ÉÒ¬åôóÅ5Î.þ˘aíî÷f7×Á,ºØðäù õjD!SðkÏnµË…êGXn¸65gˆ±²y 3~”îrd(hKÐ;ChþáÚÄ‚zz CVÔ¸Êî{§;[YW[á¶ò\è/’Û/ê'8"ãšgWa -„"U>Cvª©'È ¸´Õyr÷Ò•C°Õ_zk—º–¸ŽlÖ Úµ¾0ÊdW&0R@ÇD÷/ÎÀ=Êãí³bøÅ ºTb>Û®n¡™­<^^1݉СUk?§¬½9ð ŸàÎs Gs{“º¢Xû=¾ÖëZDÂXÓ TÊad˜*©—Dëοþ5赎^Ç¥ø+>OÇ–µ{È'WVv]Ì«¢ÞHí ¦>Xh’wº‘1öI5â÷¯ØÓPÅ®r{LP¡jP;%5ëoKž´ôý—ÜŽúwîwf.¬È/ÛÏ~Èÿ6õãÌ­ŽÅݤ~v|Ö‘ÔNK‡¸õWĦÉ\K†Ãâ±¥ÃfQ¬cIut;—Ýí Œ`:ì6†‰×Œ—)õÅpÓÇŒá6×Ó54žÜvÖ Â2Û=ÎÓÜH']ŠûÖ‰e´ÝbÔŠ À÷2J­ª¶±˜ãŸ°’Ý–:èY11ªiêÅsªÂž$wü†V•oíqVþêÈÞ1)àÉû¶à÷@Üâý?ëZaõ-kÓÞ#¾ÖÆcØI5ÊÿÕÚǸt{ÜTIüo¥œ3¦øy,8v?Û–Eâòv÷..mœý¼oµB¨$£f”ºh›‹-Ø6ó?hµ[X8xp½§!÷‘—§Œ6¦8ì9Wß[§IaÇ!îK#丿%‰éI÷V/Õ>;°?Æ9žV]€uŒ;†vw? ˆ ³¾”Ið ¨—”N'ŠÈr Ä>Â#,½ºîo°UÙ³FÉ/C¹?^p±rþ_˜|'ëB6 ¬ñÚÙ°îûeÙqÚv<ýÈøEÔª5.m¸ásÏñ61:tR2w—[r\O1ÁXç8ÕìyUô~å½Ä{†È#GDA ‚•¨§ÙLH±œk¥ñçó.–ÓM:v¼àÈòHý£aFËè½)ò{I©“|×k¶©,P¬q·Nñ*­‹(Îý|fV°Ü¶üb¸¦vý±í–[L}ÄæÅS¸ÜöÆÍí£²ÚíÖÍvóO‘|Ø­§ÊˆÙÇtå"it{C ½o^uU+©¿Ô‡âY.QžÈqŽ%aŽ#݂ΞIH#P¡Öa¦,¤m†ó¯"¶ÑI¹†&kºáRìO€šÏ£ìTÖÜg™gµv×÷°ÙÃ.3¸óý:ž=y$öülF2šö5ò|Õyé? êWà–QCÉñ˜Ë;Å[ËLmÆ;õ ÈmßjUŽÆ×ê×ö;´`x§Wå–пTm-.?ÛÀ[ʱŸúIQßþ¡j½Z­·³|ÁõûItÌÕR«À~Ÿym­ÂZY‚çµ;˜þô3+€ß_ÚòKNS"ÌÜåÝ»Åy;U—R}{Ü{!€ ’>Û9Þo˜¿á}ç/Èy]æfôã.…¶F{xm$…ä‡Û‰ÙU÷Ñ×vßçÀ®El¬°}á¶öjðÀظîå÷e,Ê=Égàf:ø©‚ðÐÄÈ×9Fx®PFÀ™½XÛ—»ˆhþêßPvªÀ¯8ýDz…—™OsÅøeÃEÇ"r—WQ¶óðÿÇó|ŸtúEË'ÒÞuº{ËÉpÖ¦yä»É C31$–$“ç{¯WiŠ–ÇëÒb­R]c"ôë$ªW^Öín”•®ÅE+ŠR”ˆ¥)HŠ¦Þ°9íç æVÑZÚAsgˆßb¼R+"Ï*÷¿y ‹¥_ ’[Ã-\š£Þ¿nƒå¸-¨m´V÷’×Àfˆoøö®Ã”6¥A¾’ y+§$wzɃ‹)¸O›ø2–âííÒêBJcŒ! 0yR4@ ‚S ‡²ÿÓP/K¿SmÓ®/N+x. náЦ¾†î díc¯¹?5?pÙTÚ–Þ€O$ÔvŒXüÊê9­Opš§¨~¢OÓ¾›_Mˆ‚{œæXÿ Æ-´Ê’¤ò«•GîbŸ!POhð6ËŸLœ_ÓÌN-qw6bÒ÷øÎZÒsÒÝwÇzMP4ÒÃOWŒYÅ×.¼dz…p‘KÄ8<‰Ã™&Žöò2XÎ,;G¸$VßòH'µ…Lù;†»‘”š©Ý´Êµ¡ÁÜû/y2*ê» ‡¹ó”ã•–áýG³çüjÒîlå­ó°ŒS[Il¤†i^3Éõæw0òÉ®í0àð¼ÄØÚÜ[MöóƯ±¸et#a ìXœ¯´äx‹Û<½¤w6·°û7ÃEÓÏ#[$v‘£P¿G9QáÜ›1Ò¾IyÛÁÜ1ÄÉ<ÁšâÌ$iÝãn¨Àèké:4süŠò5ôüzBãÙ‚y7¯æZ˸Äò‡`¨¬/"¼Ëàð—·Ü[܇1zµ° ºäåÜ€ÞÏö<Ö_r·€çΫ,Tì „ËÈÄó¿Œð\ï^:³Êòd¸’Æó"%ý„¬{òá-ÑúPvþ免ÿVÛ¾¬ãxkü?ˆc ÆÀI,SlîIßÔìK7Ï“¡àx­?¥78ÜŸVzßw„ WÊÛ/óP™;®=Ó¥$hȬAù ‚tI)Úa^êñ~Àµtu·9~ ”˦ÂA£©qîI<úï3¶·3Km³Šî[c¦¹>èÖÉŽãqA{žt+±È2¶x®uµo$€£ £Q¿pÐ*ÃûVwÚs Fñý«­Ç,ÎåFÉ5Ôá}G¸Îõ^ï‰q˜,opX\q—;™¡¼g+²°Ò†IoÝðËô”"¹ÊŒù#§9ÐfTÀ=yL¨ç¼ƒ¢ü1é!º¹ÖÑ¢GÜÒ{—1!E;$1<ùñæ´îG’Ÿª\Î릜QcÄð¾<±EÈîm'¸ÒØÂö®Ô«|~ÇéöoYüžÇÒûlo3fó9‡Ån~½ÄáÙô<>•ñç¹×ý3\'ƒØtË…ãð8´ŒIj÷“*n. rC¿>HðÀ}ªå"­2¹ß'N~];äL º‚£l ýyyõ•CÕoÁqŒÿ—Œã­ñQ\Yû¯F¹—$¹ã£ñ<<wör–×lVÖÚnïævýLÅ‹è:ó£ÚjÆVÔèõž|äŠWO­aÐŽžRø`ùe†6;(ò—";‹ù–ÞÒRòM!? Š ÙŽ´ª˜…ö Žñ«n?<¹œåÊfùeڸɼAJE½ˆb]Ÿn1¡à~â 'BcŠøÌßIñ\G æv±a‰”¥qO*7\«Ä÷¥)Tƒ×k ·+àLyYòÁ[uÐoçIGäý™£`6¤ÕߪUÕls«~¨#^;ndÅðaŽ\„ítaEç¾Ý¬¾UÏ{(ןåö®ÃÈ[¸ÎÊ ö÷kj¸R¼”ÿ†.2(,a–iã´… Y'rò8U ˜ü±ÖÉûšÅõ“œÉÂúOua†æë;ÉOðŒl‡ù¥åR€c¡àv‚K:ØÛgˆ<îu½š8Ù‹ª£X\@·¼{§vÆZ0cL“ºùØ;îN·às “§N Ø]¶^g÷¼Í·’"îyß .ôÿ‡AÒþœàø½°_~ÖÜ5ã2áþ©cäwáBµfñöísp·æ¸_În.ïcu°qû>Ô÷TÌÅØ±ÜÊB(Q°™x­U!j,êDøŸPol¯¹V0ßIfŽ‘vÏ$[ A;(A:íñçÆÍKuù\@'Œ©¬£²%80Ê®0Ã"Gø eÁCkcŽ…-¬í£X †5ÒÆŠ4À·ëYZXÁošÅœ)ï´F$ ÕãyëiRz …¶°æ]g’ »øªKQ¶(¨‘K?k!ßy«û{À µ=ãcò-ê­Yº[}êï+æÑf±|ŠÚÝíš$D3ï΂>¼ê·ãÎጥäDƒûªK‹,ãp=$út5×ÂFÄúÍèxz²nC”éͯáx«Ü®O’d"µu¶‰˜$(}Æ,ãéAܱ‚XÚX“ jy®/ûþÕ®«>S‡Æq6XŸ1 g•›§ý'¼á)ŠÈsÌËr^CÇÇcV@-ñP c„}ÛÇi—@Ðó¹4—·„HËc^âg!I$×g`Ìf]X²Æµ¸š+­k^•¯¬¾•ךrɹ&0¸¡xŠoa{c7t î)ï (+ãàùÕuzqÑü/LrPßIJe3(¥Eìê·¿ÛO„Øñ½–Ñ#z$U¿¾Ç¬ÖÅÙÕh÷ÜAä—º4ûÖöÕÞÕü²Ü¦‘¥¥_æç?k ´÷v¨»?LùVWü9ëI%÷äK‹ÛKWXæ*IžÒ$]ùPΤ¯Á ª¼xn<Öê=ÁU£ª¾˜9.ëg™µÂâ%kim&¶ï{µ’(bO ;BPÝÄ_Ú­þaÀ*G¤Õ¬GuN’3'Ô.{auoÄ:vö×¼ß"â0¬{—^æž_+|ì0Ò´·ÒþŽég¶Âãf{ˇv¸¾¾•@’îá¼´¯ö’B€ 'dÆ\Wƒaº~ׄ·ž[ë× yw)šâá·²]Ïäì ;ÕKXù&½·ˆ@©ì±BüºöëÞ~Ý‚oDbÜo¿ ýÞEÝxáÃfú{Ê1Ø›œ–KÉ,cºhœ­—¸YË&õ á|ëÇqÙÕH÷±½Ì„ý·[¥Ž3þ]¶>Õ8}“âµµ…ÑTô›°¬Ì:ÌPàxN[ƒ6\£i–³YÉÔ"EY 0ßÁÑ#cìHûšÔrœ6Ï ³ÁXÛcl£ßd°¬Q®ÎΕ@dî¦<]¸‚Ð%~XHÕxâ8ÆyO|#9Ç9ñK ¡pÏš“qöl'Å~¶xH-<ªö¬F€Ð¯30£´_iJDV¥È­ù>.k¼·–<ËȪ!0‚à5Ýê…£?vV­¡®ÂI;mqqµ:¯JxLòFD«1õ Ô=ÊÜá¬8¾7§vhZ Œô/+Æè@v‰‰+&÷ô…NŽŸÆÄ™ÂøN¦*…Pñ\}”üW:R'ÅP£Câ¾Ò”ˆ¥)HŠR”ˆ¥)HŸœG/ïPk‚Ù‡j€ýéHŸÒ~+^—îHÌGɭЏûkø¤NŽ.Ô[ÆÞ4I¬…|¡_iJR‘¥)JR‘¥)JR‘¥)JR‘¥)JR‘¥)JR‘¥)ÿÙcommons-jxpath-1.3-src/src/site/resources/images/logo-wbg.jpg100644 0 0 15554 11044113546 21522 0ustar 0 0 ÿØÿàJFIF––ÿÛC     ÿÛC  ÿÀpú"ÿÄ ÿÄ9!1"AQ2#BaR‘$bq‚CDS¡ÑðÿÄÿÄ.1!AQaq±Á¡Ñáð‘"24ÿÚ ?¿Ô¥)JV½Î9ž+§ÜW'É9¦; |&FU×|­ð± $ÌÄ(³äæ²c¼Á!FLØiZ×çΣñ _'À{ËÈÆÍN²#+²:°Ù ¬<¶ ²îŒ¥Iq†ˆ¥)X™ŠR”ˆ¥)HŠR”ˆ¥)HŠR”ˆ¥)HŠR”ˆ¥)HŠÂò¾[…àø+¬ç+¿‹µÝÕ›[ Af$Ÿ€ ¬ÕS¿Vá9VúQÄr_¬þ}wêÑn;b”Kr‘ÕCª†úÙÆ¾ S¦¨]`Ry}¤ú‹M5–ËuŒÉZfq¶y,\ësc{\[ÌŸ¶HÝC+ìA»U¯HŠ±Æ€*ªàYk ÍÄE‰ÝN{¥·JR±JR‘¥)^zñÉ]ËÔ¾=–fklÜC,’O*»~vDQüEzT#×®DËÏ8¶?ÙE¾!§‡›Ü™—´¯ÈÚØ?~ãø®§Ã?és›ñùÏ”’ý'òùaèõÄSÀ¶W— ÉU•Ë÷# ;”ëà©d0yA|vö* tZ{›n•ñ¸eŠX;Rr½ã]ê×0`?7ß[ùøÑ6_§Îαߊ—Vs¨*Ó PžH”ªuë3¬œ§‰åð¼W‹Iw„·h“#.N 9'pìHÃCµt¼–QàÝ1t¬C©Ý7ÇäòŽjЛ,™Ð^ùÐæZ²¶€ |V_KbP.;åu(÷†âLu ucÔÿ éFJ ]ßê3¹Fcú‹|kÆæÔ»÷IaÚÅX•_;íóÚ5Óë¯Z.0ñpžž-ÅïQóÉca†ánì¦bí¥}lý>´¢±xM\3Žô¶çˆälí/ò×Ж»Ì=º¼ÉrWAâfUB~•ñ½ùfߺª­{ö;YæË,rRÆçÛÇÒN‘v¹d€<Ô¹±ùåSú5“éÏ/°ÀEyir}£q™X·gk+ØÝÄQ ïä w)Ò^iÃ,]ú?Ï3†Þ9բċֵúIò{ìnw䂪'äø;-Ñé‚¡[1žÞ¿i®­^ –â¯8ìýç=¥yákÖP½:»KžAG)‹³íÌw˜äžÝ“Îû®#]®·¿5¡½Rã½0w×Ë-âw˜{f*¢æÒñnûI:%¢£çÇqü Ðß¼ ¦w¹uÔ“‡Êžñ-í+„ä8ÎGŒµÉá/a¾°»ŒIÑ6ÕÔýÇÿŸjÉü×8‚ ¼óJR±3¥)ë?¨!Ó^Iâ¼c'*åYGWýrÂBĪýaOÖÌ†Ž‚’Ú»š½äû°ÝPN›È½NõmÈ9L-Æ3su{ÈÌË,QÓÀU¼|í‘W sÝòv÷|š»WRQÀƒ|dùý¤ZkZî';gÊoŠÁ†ÔìUNê2įV\s ÌàøÕÉ]BÀ§·qÜ$N¾®âö{ó­¯?6›þ媱ûÕWéš¿$õÖN[ oidã 6¹$VDfVßoþÓ¸Ÿæ/Çq¥ÿïØ=yLê?È¢vŸNrcyeg'gÉ­÷Œ¶Xù5£ÇtŠ?&¤;ý«H×ûTRÉÙ¥)HŠR”ˆ¥)HŠ«³×)—ãöØ›[Œ=–*Óq—»’ø!šVŠh#Há,¥‘‰›åuݾÒ@:kOT{×n/+Èø¬–†Kë;|eÔÍm»1µUxÄ“;@S܃zvù'~:^-JÈuÇv™n‘ËW¦<^tF@¶†Ìr2þ¥I«ÓøBÆ¿ØTÒ{hìúeÅ"C¼zIí Œ½ÅÉs&ÏÇynþß…ïíOüocüµ6£9ñÚ}egå.{¤Õ=Mðé¹H³qcq™Œš ›hæ‰ÚEíýÍBH±Qä1¥H:ª ÑN¬ÉÒ¬åôóÅ5Î.þ˘aíî÷f7×Á,ºØðäù õjD!SðkÏnµË…êGXn¸65gˆ±²y 3~”îrd(hKÐ;ChþáÚÄ‚zz CVÔ¸Êî{§;[YW[á¶ò\è/’Û/ê'8"ãšgWa -„"U>Cvª©'È ¸´Õyr÷Ò•C°Õ_zk—º–¸ŽlÖ Úµ¾0ÊdW&0R@ÇD÷/ÎÀ=Êãí³bøÅ ºTb>Û®n¡™­<^^1݉СUk?§¬½9ð ŸàÎs Gs{“º¢Xû=¾ÖëZDÂXÓ TÊad˜*©—Dëοþ5赎^Ç¥ø+>OÇ–µ{È'WVv]Ì«¢ÞHí ¦>Xh’wº‘1öI5â÷¯ØÓPÅ®r{LP¡jP;%5ëoKž´ôý—ÜŽúwîwf.¬È/ÛÏ~Èÿ6õãÌ­ŽÅݤ~v|Ö‘ÔNK‡¸õWĦÉ\K†Ãâ±¥ÃfQ¬cIut;—Ýí Œ`:ì6†‰×Œ—)õÅpÓÇŒá6×Ó54žÜvÖ Â2Û=ÎÓÜH']ŠûÖ‰e´ÝbÔŠ À÷2J­ª¶±˜ãŸ°’Ý–:èY11ªiêÅsªÂž$wü†V•oíqVþêÈÞ1)àÉû¶à÷@Üâý?ëZaõ-kÓÞ#¾ÖÆcØI5ÊÿÕÚǸt{ÜTIüo¥œ3¦øy,8v?Û–Eâòv÷..mœý¼oµB¨$£f”ºh›‹-Ø6ó?hµ[X8xp½§!÷‘—§Œ6¦8ì9Wß[§IaÇ!îK#丿%‰éI÷V/Õ>;°?Æ9žV]€uŒ;†vw? ˆ ³¾”Ið ¨—”N'ŠÈr Ä>Â#,½ºîo°UÙ³FÉ/C¹?^p±rþ_˜|'ëB6 ¬ñÚÙ°îûeÙqÚv<ýÈøEÔª5.m¸ásÏñ61:tR2w—[r\O1ÁXç8ÕìyUô~å½Ä{†È#GDA ‚•¨§ÙLH±œk¥ñçó.–ÓM:v¼àÈòHý£aFËè½)ò{I©“|×k¶©,P¬q·Nñ*­‹(Îý|fV°Ü¶üb¸¦vý±í–[L}ÄæÅS¸ÜöÆÍí£²ÚíÖÍvóO‘|Ø­§ÊˆÙÇtå"it{C ½o^uU+©¿Ô‡âY.QžÈqŽ%aŽ#݂ΞIH#P¡Öa¦,¤m†ó¯"¶ÑI¹†&kºáRìO€šÏ£ìTÖÜg™gµv×÷°ÙÃ.3¸óý:ž=y$öülF2šö5ò|Õyé? êWà–QCÉñ˜Ë;Å[ËLmÆ;õ ÈmßjUŽÆ×ê×ö;´`x§Wå–пTm-.?ÛÀ[ʱŸúIQßþ¡j½Z­·³|ÁõûItÌÕR«À~Ÿym­ÂZY‚çµ;˜þô3+€ß_ÚòKNS"ÌÜåÝ»Åy;U—R}{Ü{!€ ’>Û9Þo˜¿á}ç/Èy]æfôã.…¶F{xm$…ä‡Û‰ÙU÷Ñ×vßçÀ®El¬°}á¶öjðÀظîå÷e,Ê=Égàf:ø©‚ðÐÄÈ×9Fx®PFÀ™½XÛ—»ˆhþêßPvªÀ¯8ýDz…—™OsÅøeÃEÇ"r—WQ¶óðÿÇó|ŸtúEË'ÒÞuº{ËÉpÖ¦yä»É C31$–$“ç{¯WiŠ–ÇëÒb­R]c"ôë$ªW^Öín”•®ÅE+ŠR”ˆ¥)HŠ¦Þ°9íç æVÑZÚAsgˆßb¼R+"Ï*÷¿y ‹¥_ ’[Ã-\š£Þ¿nƒå¸-¨m´V÷’×Àfˆoøö®Ã”6¥A¾’ y+§$wzɃ‹)¸O›ø2–âííÒêBJcŒ! 0yR4@ ‚S ‡²ÿÓP/K¿SmÓ®/N+x. náЦ¾†î díc¯¹?5?pÙTÚ–Þ€O$ÔvŒXüÊê9­Opš§¨~¢OÓ¾›_Mˆ‚{œæXÿ Æ-´Ê’¤ò«•GîbŸ!POhð6ËŸLœ_ÓÌN-qw6bÒ÷øÎZÒsÒÝwÇzMP4ÒÃOWŒYÅ×.¼dz…p‘KÄ8<‰Ã™&Žöò2XÎ,;G¸$VßòH'µ…Lù;†»‘”š©Ý´Êµ¡ÁÜû/y2*ê» ‡¹ó”ã•–áýG³çüjÒîlå­ó°ŒS[Il¤†i^3Éõæw0òÉ®í0àð¼ÄØÚÜ[MöóƯ±¸et#a ìXœ¯´äx‹Û<½¤w6·°û7ÃEÓÏ#[$v‘£P¿G9QáÜ›1Ò¾IyÛÁÜ1ÄÉ<ÁšâÌ$iÝãn¨Àèké:4süŠò5ôüzBãÙ‚y7¯æZ˸Äò‡`¨¬/"¼Ëàð—·Ü[܇1zµ° ºäåÜ€ÞÏö<Ö_r·€çΫ,Tì „ËÈÄó¿Œð\ï^:³Êòd¸’Æó"%ý„¬{òá-ÑúPvþ免ÿVÛ¾¬ãxkü?ˆc ÆÀI,SlîIßÔìK7Ï“¡àx­?¥78ÜŸVzßw„ WÊÛ/óP™;®=Ó¥$hȬAù ‚tI)Úa^êñ~Àµtu·9~ ”˦ÂA£©qîI<úï3¶·3Km³Šî[c¦¹>èÖÉŽãqA{žt+±È2¶x®uµo$€£ £Q¿pÐ*ÃûVwÚs Fñý«­Ç,ÎåFÉ5Ôá}G¸Îõ^ï‰q˜,opX\q—;™¡¼g+²°Ò†IoÝðËô”"¹ÊŒù#§9ÐfTÀ=yL¨ç¼ƒ¢ü1é!º¹ÖÑ¢GÜÒ{—1!E;$1<ùñæ´îG’Ÿª\Î릜QcÄð¾<±EÈîm'¸ÒØÂö®Ô«|~ÇéöoYüžÇÒûlo3fó9‡Ån~½ÄáÙô<>•ñç¹×ý3\'ƒØtË…ãð8´ŒIj÷“*n. rC¿>HðÀ}ªå"­2¹ß'N~];äL º‚£l ýyyõ•CÕoÁqŒÿ—Œã­ñQ\Yû¯F¹—$¹ã£ñ<<wör–×lVÖÚnïævýLÅ‹è:ó£ÚjÆVÔèõž|äŠWO­aÐŽžRø`ùe†6;(ò—";‹ù–ÞÒRòM!? Š ÙŽ´ª˜…ö Žñ«n?<¹œåÊfùeڸɼAJE½ˆb]Ÿn1¡à~â 'BcŠøÌßIñ\G æv±a‰”¥qO*7\«Ä÷¥)Tƒ×k ·+àLyYòÁ[uÐoçIGäý™£`6¤ÕߪUÕls«~¨#^;ndÅðaŽ\„ítaEç¾Ý¬¾UÏ{(ןåö®ÃÈ[¸ÎÊ ö÷kj¸R¼”ÿ†.2(,a–iã´… Y'rò8U ˜ü±ÖÉûšÅõ“œÉÂúOua†æë;ÉOðŒl‡ù¥åR€c¡àv‚K:ØÛgˆ<îu½š8Ù‹ª£X\@·¼{§vÆZ0cL“ºùØ;îN·às “§N Ø]¶^g÷¼Í·’"îyß .ôÿ‡AÒþœàø½°_~ÖÜ5ã2áþ©cäwáBµfñöísp·æ¸_În.ïcu°qû>Ô÷TÌÅØ±ÜÊB(Q°™x­U!j,êDøŸPol¯¹V0ßIfŽ‘vÏ$[ A;(A:íñçÆÍKuù\@'Œ©¬£²%80Ê®0Ã"Gø eÁCkcŽ…-¬í£X †5ÒÆŠ4À·ëYZXÁošÅœ)ï´F$ ÕãyëiRz …¶°æ]g’ »øªKQ¶(¨‘K?k!ßy«û{À µ=ãcò-ê­Yº[}êï+æÑf±|ŠÚÝíš$D3ï΂>¼ê·ãÎጥäDƒûªK‹,ãp=$út5×ÂFÄúÍèxz²nC”éͯáx«Ü®O’d"µu¶‰˜$(}Æ,ãéAܱ‚XÚX“ jy®/ûþÕ®«>S‡Æq6XŸ1 g•›§ý'¼á)ŠÈsÌËr^CÇÇcV@-ñP c„}ÛÇi—@Ðó¹4—·„HËc^âg!I$×g`Ìf]X²Æµ¸š+­k^•¯¬¾•ךrɹ&0¸¡xŠoa{c7t î)ï (+ãàùÕuzqÑü/LrPßIJe3(¥Eìê·¿ÛO„Øñ½–Ñ#z$U¿¾Ç¬ÖÅÙÕh÷ÜAä—º4ûÖöÕÞÕü²Ü¦‘¥¥_æç?k ´÷v¨»?LùVWü9ëI%÷äK‹ÛKWXæ*IžÒ$]ùPΤ¯Á ª¼xn<Öê=ÁU£ª¾˜9.ëg™µÂâ%kim&¶ï{µ’(bO ;BPÝÄ_Ú­þaÀ*G¤Õ¬GuN’3'Ô.{auoÄ:vö×¼ß"â0¬{—^æž_+|ì0Ò´·ÒþŽég¶Âãf{ˇv¸¾¾•@’îá¼´¯ö’B€ 'dÆ\Wƒaº~ׄ·ž[ë× yw)šâá·²]Ïäì ;ÕKXù&½·ˆ@©ì±BüºöëÞ~Ý‚oDbÜo¿ ýÞEÝxáÃfú{Ê1Ø›œ–KÉ,cºhœ­—¸YË&õ á|ëÇqÙÕH÷±½Ì„ý·[¥Ž3þ]¶>Õ8}“âµµ…ÑTô›°¬Ì:ÌPàxN[ƒ6\£i–³YÉÔ"EY 0ßÁÑ#cìHûšÔrœ6Ï ³ÁXÛcl£ßd°¬Q®ÎΕ@dî¦<]¸‚Ð%~XHÕxâ8ÆyO|#9Ç9ñK ¡pÏš“qöl'Å~¶xH-<ªö¬F€Ð¯30£´_iJDV¥È­ù>.k¼·–<ËȪ!0‚à5Ýê…£?vV­¡®ÂI;mqqµ:¯JxLòFD«1õ Ô=ÊÜá¬8¾7§vhZ Œô/+Æè@v‰‰+&÷ô…NŽŸÆÄ™ÂøN¦*…Pñ\}”üW:R'ÅP£Câ¾Ò”ˆ¥)HŠR”ˆ¥)HŸœG/ïPk‚Ù‡j€ýéHŸÒ~+^—îHÌGɭЏûkø¤NŽ.Ô[ÆÞ4I¬…|¡_iJR‘¥)JR‘¥)JR‘¥)JR‘¥)JR‘¥)JR‘¥)ÿÙcommons-jxpath-1.3-src/src/site/resources/images/logo.jpg100644 0 0 13137 11044113546 20740 0ustar 0 0 ÿØÿàJFIF––ÿÛC     ÿÛC  ÿÀqî"ÿÄ ÿÄ8!1"AQ2aq#Br$Rb‚‘¡4áðÿÄÿÄ(!1"AQÑ2a¡Áq‘áÿÚ ?å:R•ú!ðb”¥¥)@)JP R””¥¥)@)JP R””¥¥)@)JP PñRË¥¬}>Vª¿ÌM¹õ¸„Æ·8×ê:•Œ«>Ucr¶àðžqØ6FÒòGô«{ê ¬Ôl¶Š©JT)JPqS~è+Îh[Í×S%Ø·cO[˜m`ì AP+ÆAÜp1ܹÀ„›q-:Û‹@q(PQAì jïûœØ±ì³&ÊܸMÅ[ÎlNIl$“ëÅC1Ën5¯sóãĪ’¼šÆ}m%÷De­lŸ N$%E9à ãÓ'òkëKÍb¯líq¤fR³Ý±ÜØ´G»»ôÚä-Mµ+aðÔ pF9üàûó·ŠÛf:*¥lÚB]:u\0Che!rw! $œ~ç¾®±©’éÐ73DËwFÜUt½ÂJ‰}Râ^u#ÌÑHá=ˆHà‚FIÙJ©—¦s­*Ó!Ù6Ìt-çœPBBJ”¥€É>•4ÅøhÕOCm×î¸ÒÅ…¸²PÒT”‘ùÆz…I–¦£õ=Ý*wÖÿríÖˆh¥=vœ,Öu߯w£8‘´’yzˆæè]Ymqh›¦®ÍìÎT!8¤~ʃû:KÉæ×¥ž%*…•°êš} iÔ) IIî €Ô¦™w-Ò¾ }©*)JP R½ –^£¼Bµ[*[¡¶Áàr~ÀdŸÅçÒ¦î¶éM7 ´®ž³Úà%Wg\*Tòœ-Ä y÷÷*Zp9 {T¾«±>µ´\QâºâMô#NhÖc:莰âÐÛŠVT†ÂT­Ü•¬dóæ>õ è»CZ‡VY­rJƒ2å¶Û…8ÎÒyî@íÿÐ'Šß~%/Ï×È·)Gåí±”#ÓzÆõ+òAHÿˆªÓèŽ;É+ã‚!ÝW95‹º²æ«/l襤_¥)[ R”}5Û×mOb¹ôÚõs´ÉLûSv×’¯”X H '˜yU‚8Pã ⸅Ϡ×f]aÊÿ µ,GbljonÆ´Û›h”¨6"çÝØïÜ0}56e‘'Å¿“‡7Vm±L lÁÃ8Ÿ7Åóc>¸Î+ ¯Ç×o‘êÞ´wÄ{n›Ö:Û,þº~TbÃB>0ر줨gŸQ\[ü¥uV¯V•i‚«°–b„@ÜÕý¸ógÛšœ>º…j…ý5vS¦x…Èl 2NJ õP$‘îÚ·tý“KZî}P²D®Ï[›b4„¤)¬,€‡Hã¾P »íç=tö·ðy8ùb·Þü’7êòG4Éк.[Ž]æ(¿sšH6•ÇÒ¥$¢yî kÉøo¹\…þû"Ëð—lqõÂñR’ó©)J6“ØùˆÏnF}*t•v¸Hr}reÉp¸ó«<©Däš“ú¨%iË®©¸Bl:¸ÚrSà(e!h(('×°æ°Y93¶ððÆ×—ý–:'ª¬:G[&ãªLo•[l>.x¨§ r<¡iÈùªiê^`Ç6øý8¹·t¼ ÈmÈ¿*¥µ!µ$»ÈÔS‚“œý«“H8«aKmiSEIq*%'LT<•3¤Yý›á\‘Ù±5×KúĦ¢^£¶‰¨^ƹ¤0éÏ¢J½Oô…g>«Ãêõv×çh,öS¸AqâãoÝ)R²¤¨údpÍC½?è–¨× Ÿ—6›CƒwÎËN“ÇЩ|ƒÂN˜TÙ­º÷jж–lºvju=þ3iaÉKe*JpV¢œÿJxï’ÁÚm9ÝœõŽ¢Ôá{ý½‘Ë‹GylÈBÚyµ- IJ’ pA±Í\BóVåN™¨/%¾&}ÂJXm¸ëŠ$á#ܞ¦–þnpôTëÝâ∗8ñW%0{€JS»j—ž@#€@>¦§¶tdãåîCô«AÊú•ä×FÑŸ\©cá⫦¾Lò¶ƒV¦ê’£æR– ÑxÜI8 cÈ5f§o†%ÀEçP®BϦ#je{s†B‰ƒùðÿêŒË&Ô=Ä&£7®¢IŠÚ³ÖÊ"§‚¯©gó•mÿE{ë/P_]ÔWËÚZPÛó¤-õ¡¿¥%G8a^r½A(GØ ×'>ÎØÇÆR%.„ZSwê]§Æi.µ 9)AIÈ);ä,¤þEkK¿#TkËíÑ‚ I)h„íÊq÷ ·^ƒÀ»®n¢»ié‘â?ÚR¥? R ³»' ý.;úŒ‰dH\¹È}[ÝuekV1•’p+Föc+ÖÙg”ÈÂkÔoG_\ÓkÔˆ¶ó¡‘!Cú‰Oú•ûyÿN´AÕ½#µ[¤6”[å_×2cûöØm%*9Ï*%¾Ï¥F=\׬jk‹V}8”ÅÒ¶|³†¼¨pŽ ¤zçœgœB¥V­ë³žwUS>ÿDZÔýP/Jõ HŒ·3ÕšB0”% `;ø®KµÝw·?™úSpvÞḭ̈8¦\q;w•°H$Äçö®´Ûæ^®­ö˜îK›%a 2ØÊ”ýÉ=€59+T™ŸÒNâ“öeæ•“Yíj,ÎŽ1íón-K¿dª\xÄ-¨ÉÇ•~®z8šð·VÑ[F”»è®”¥hfPçÐk³:“qnÝÑ»›­6™;kC'v0âBø¶à¡œ ’;×8 NÉ®œøŽ‘"×ÓkM®?Œ¤;!¤Hq «am´q•ì “Ž3ƒŒ­é2”¹\/ÜäÜT«ÐÍC¨âî–§ìŸæ'.BÊ•ŽØ …(Ðsìb³Úºÿ³¥}·ØÙ*EóT~´²FÈCÙ±pr£šå'nføñ^YõZÈ׺¢UÞBËD£2UŸ ¤öN$“÷Q­AiÍ]¯©NMh×!:…¤n½Ö Ñ:Ú$™‹¶Ë-7zˆ@mDyÈÎÓÏ#ß·zÙú¥ÑIšiÙ×í9à?¦U‡›ËéJÙJ¹ÛƒÀØÉÁðMDÞÚ¯K›.w…óÒŸ“á !¿Ò½‰ öµéh£î¹&XlñR‡A-ˆ¹u*Þ¥É\eDiÉؤ‚² 9 …Î3ÈÆj0HÅI] ¸&ßÔû9vGË·!.°¬öp©³µ=½TíȪðS'ézøf±Õ'~c¨º¥IQ^.o£'ý«)ÇíŒVŸ°“[_P"J‰®uw¨Iþ$úÖTÞ­Ë* ÛÎÉàŽMk5ƒ³x­J+i¬$TóиXtÖ­Ö-DT©LG1-èB Ô·pR=ÔZ}êGÐ*jc­ôWN-V•¹y,•I”óClwTw/9É gŒßµtiJ9r:¾‘æÌJzAg~d×ÐÿQ¯('…[+åK㳪Î3éž8w•ðÿ}º©Sûª+qÇT¥¨œ’Iä“ïQt›å(¦Y&[é|~MÞÝ6åÕ¡[õj›"ç9¦ÞJ|¡-n’œ})J3ÛÛ=êPø¬º8åËOZþ]Ä2Ë.ÈñÊNÕ©D'bO©H@'ûÅDÝ.yQº…¥–•„sa#<)a$~ùÇïSÿ_:mu×:K.C[’iöeÉZ”a´©g²y[†åc×h“pÌíÌgô´Î~éÖƒ—¯µVøŠCQZé²ÈKL‚7;“Ø2}@ɇT.Ö;α”­' 4;DFу°„½³‚çòx¹5µõT[z¦ÃÍ !/I<_®Œ …õ󹬎~Ägäç*¨uƒå5IÒz6õW©øöü'¯£¹Ó„Û´è’¡pº8þÓž|GR~‘ÂsÎs÷®fZ|¦¤MW¬íÚ§šFѲWñ›*žiÅ+‚qŒóÀ@qµ_lè;<µ4¹1‰8]ùÛ;¢º‚Ïjèõ‘w‹¼6Zi/¥Ó!ä£gë,ì ýˆã×Ó‚*Ô}V³i˜Òìµ3iˆêJ¼-ÊxÈB—æJy8*äg€“ÍDŸ95_…Unœ¥ð' MºÞ÷ßìSªôSXm# ¬ÄÖØ–ÈöÌ–YrCͳµºóŠB’¥)DàrMR°[ZâJ’B’F>ÕSO;æÞŽâÙy¥¶âR¤¨‚ìAõ©7Iu/O™i=GÓQoo(m]ÏÂJžP˽…ŸB¼…Œçô7£›Øð:Y¥äj½mia˜î;<”?-À‚P†ÒwaG°Ý·hü×·×^§C×7$[-‘GÊÚ¤:–¦‡‰ñó€¬$yv’AäàÙ9½¯ºÜõâìú&tõ•Ôøm¤¶ë™R|§?ŽO¾8¨omsÛo£Lq·Î½¼—IôÓ:¯¨VKlÄx‘ ¥çÓ´(6’½ª‚Rº³ºÑªªúu~2‚¢B" ó%¼…‚Aedb+ké|vô§Lµž¶PÌÕ4m±2{oØ ¿RÓëý&¡VÓYë]/UºøëûÑ]^m5lk!´ÖжȧÑô§Š£m^¥lÖÌ“ÑcmeÛn2,×87$&T7ÐûEC - £"­Õ ¨k¢w³ÒÕZ–~±¾I¼^Kf\¡A´íJBRØãm«›i¶©Ä²zéôU•Œ“W€ò×ÂŒÕÚÚ*ž™ŒQšøZÍdøuô"©À¿3µT–þÕ°S`¨ûh}Ã#N^Ó7ÛmÞ*ã°d!à…v^Ó’“í‘Æ}3[Ž±ëŽ¯ÕÁlüà´A*Èb-’=7/;ý€}«DZ*‘U©k ¸Óä×f‘Y § ª¼3W[FRcLÖ¯¢ÚQWx«©F*­µººÙŽæ¾ø?jÈö§‚#›1ÒÖ ^ ÅUJ²ItÙðÕµÕÚ¤§4d#C5ð"¯xU÷ìøšrFßvÖìÈ鵓GÛ™y<‡%N}Àp©{R Ê@PÉ<ä+IÅ\ÛÍ6Ôq%4¼¥<ÖBF[By«µ¤­§±JR¬PPŒÒ”Í¢›E}¥¥)@)JP R”Â3_6 ª”'eª‚@¯´ Û¥(@¥)@)JP R”†” -šR•RÇÔ÷ªéJ”C¥*H¥()JJR€R” ¥()JJR€R” ¥()JÿÙcommons-jxpath-1.3-src/src/site/site.xml100644 0 0 5072 11044113546 15464 0ustar 0 0 Commons JXPath http://commons.apache.org/jxpath/images/logo-wbg.jpg http://commons.apache.org/jxpath/

commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/BasicNodeSetTest.java100644 0 0 12025 11044113525 25011 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; import java.util.Iterator; import java.util.List; import org.w3c.dom.Element; /** * Test BasicNodeSet * * @author Matt Benson * @version $Revision: 658784 $ $Date: 2007-12-10 15:15:27 -0600 (Mon, 10 Dec * 2007) $ */ public class BasicNodeSetTest extends JXPathTestCase { /** JXPathContext */ protected JXPathContext context; /** BasicNodeSet */ protected BasicNodeSet nodeSet; protected void setUp() throws Exception { super.setUp(); context = JXPathContext.newContext(new TestMixedModelBean()); nodeSet = new BasicNodeSet(); } /** * Add the pointers for the specified path to nodeSet. * * @param xpath */ protected void addPointers(String xpath) { for (Iterator iter = context.iteratePointers(xpath); iter.hasNext();) { nodeSet.add((Pointer) iter.next()); } nudge(); } /** * Remove the pointers for the specified path from nodeSet. * * @param xpath */ protected void removePointers(String xpath) { for (Iterator iter = context.iteratePointers(xpath); iter.hasNext();) { nodeSet.remove((Pointer) iter.next()); } nudge(); } /** * "Nudge" the nodeSet. */ protected void nudge() { nodeSet.getPointers(); nodeSet.getValues(); nodeSet.getNodes(); } /** * Test adding pointers. */ public void testAdd() { addPointers("/bean/integers"); assertEquals(nodeSet.getPointers().toString(), list("/bean/integers[1]", "/bean/integers[2]", "/bean/integers[3]", "/bean/integers[4]").toString()); assertEquals(list(new Integer(1), new Integer(2), new Integer(3), new Integer(4)), nodeSet.getValues()); assertEquals(list(new Integer(1), new Integer(2), new Integer(3), new Integer(4)), nodeSet.getNodes()); } /** * Test removing a pointer. */ public void testRemove() { addPointers("/bean/integers"); removePointers("/bean/integers[4]"); assertEquals(list("/bean/integers[1]", "/bean/integers[2]", "/bean/integers[3]") .toString(), nodeSet.getPointers().toString()); assertEquals(list(new Integer(1), new Integer(2), new Integer(3)), nodeSet.getValues()); assertEquals(list(new Integer(1), new Integer(2), new Integer(3)), nodeSet.getNodes()); } /** * Demonstrate when nodes != values: in XML models. */ public void testNodes() { addPointers("/document/vendor/contact"); assertEquals(list("/document/vendor[1]/contact[1]", "/document/vendor[1]/contact[2]", "/document/vendor[1]/contact[3]", "/document/vendor[1]/contact[4]").toString(), nodeSet.getPointers().toString()); assertEquals(list("John", "Jack", "Jim", "Jack Black"), nodeSet.getValues()); assertElementNames(list("contact", "contact", "contact", "contact"), nodeSet.getNodes()); assertElementValues(list("John", "Jack", "Jim", "Jack Black"), nodeSet.getNodes()); } /** * Do assertions on DOM element names. * @param names List of expected names * @param elements List of DOM elements */ protected void assertElementNames(List names, List elements) { assertEquals(names.size(), elements.size()); Iterator nameIter = names.iterator(); Iterator elementIter = elements.iterator(); while (elementIter.hasNext()) { assertEquals(nameIter.next(), ((Element) elementIter.next()).getTagName()); } } /** * Do assertions on DOM element values. * @param values List of expected values * @param elements List of DOM elements */ protected void assertElementValues(List values, List elements) { assertEquals(values.size(), elements.size()); Iterator valueIter = values.iterator(); Iterator elementIter = elements.iterator(); while (elementIter.hasNext()) { assertEquals(valueIter.next(), ((Element) elementIter.next()).getFirstChild().getNodeValue()); } } } commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ExternalNS.xml100644 0 0 1577 11044113525 23542 0ustar 0 0 MY VALUE commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/JXPathTestCase.java100644 0 0 24700 11044113525 24443 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Set; import junit.framework.TestCase; import org.apache.commons.jxpath.ri.model.NodePointer; /** * Abstract superclass for various JXPath tests. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public abstract class JXPathTestCase extends TestCase { /** * Construct a new instance of this test case. */ public JXPathTestCase() { Locale.setDefault(Locale.US); } protected void assertXPathValue(JXPathContext ctx, String xpath, Object expected) { ctx.setLenient(false); Object actual = ctx.getValue(xpath); assertEquals("Evaluating <" + xpath + ">", expected, actual); } protected void assertXPathValue(JXPathContext ctx, String xpath, Object expected, Class resultType) { ctx.setLenient(false); Object actual = ctx.getValue(xpath, resultType); assertEquals("Evaluating <" + xpath + ">", expected, actual); } protected void assertXPathValueLenient(JXPathContext ctx, String xpath, Object expected) { ctx.setLenient(true); Object actual = ctx.getValue(xpath); ctx.setLenient(false); assertEquals("Evaluating lenient <" + xpath + ">", expected, actual); } protected void assertXPathSetValue(JXPathContext ctx, String xpath, Object value) { assertXPathSetValue(ctx, xpath, value, value); } protected void assertXPathSetValue(JXPathContext ctx, String xpath, Object value, Object expected) { ctx.setValue(xpath, value); Object actual = ctx.getValue(xpath); assertEquals("Modifying <" + xpath + ">", expected, actual); } protected void assertXPathCreatePath(JXPathContext ctx, String xpath, Object expectedValue, String expectedPath) { Pointer pointer = ctx.createPath(xpath); assertEquals("Creating path <" + xpath + ">", expectedPath, pointer.asPath()); assertEquals("Creating path (pointer value) <" + xpath + ">", expectedValue, pointer.getValue()); assertEquals("Creating path (context value) <" + xpath + ">", expectedValue, ctx.getValue(pointer.asPath())); } protected void assertXPathCreatePathAndSetValue(JXPathContext ctx, String xpath, Object value, String expectedPath) { Pointer pointer = ctx.createPathAndSetValue(xpath, value); assertEquals("Creating path <" + xpath + ">", expectedPath, pointer.asPath()); assertEquals("Creating path (pointer value) <" + xpath + ">", value, pointer.getValue()); assertEquals("Creating path (context value) <" + xpath + ">", value, ctx.getValue(pointer.asPath())); } protected void assertXPathPointer(JXPathContext ctx, String xpath, String expected) { ctx.setLenient(false); Pointer pointer = ctx.getPointer(xpath); String actual = pointer.toString(); assertEquals("Evaluating pointer <" + xpath + ">", expected, actual); } protected void assertXPathPointerLenient(JXPathContext ctx, String xpath, String expected) { ctx.setLenient(true); Pointer pointer = ctx.getPointer(xpath); String actual = pointer.toString(); assertEquals("Evaluating pointer <" + xpath + ">", expected, actual); } protected void assertXPathValueAndPointer(JXPathContext ctx, String xpath, Object expectedValue, String expectedPointer) { assertXPathValue(ctx, xpath, expectedValue); assertXPathPointer(ctx, xpath, expectedPointer); } protected void assertXPathValueIterator(JXPathContext ctx, String xpath, Collection expected) { Collection actual; if (expected instanceof List) { actual = new ArrayList(); } else { actual = new HashSet(); } Iterator it = ctx.iterate(xpath); while (it.hasNext()) { actual.add(it.next()); } assertEquals("Evaluating value iterator <" + xpath + ">", expected, actual); } protected void assertXPathPointerIterator( JXPathContext ctx, String xpath, Collection expected) { Collection actual; if (expected instanceof List) { actual = new ArrayList(); } else { actual = new HashSet(); } Iterator it = ctx.iteratePointers(xpath); while (it.hasNext()) { Pointer pointer = (Pointer) it.next(); actual.add(pointer.toString()); } assertEquals( "Evaluating pointer iterator <" + xpath + ">", expected, actual); } protected void assertDocumentOrder( JXPathContext context, String path1, String path2, int expected) { NodePointer np1 = (NodePointer) context.getPointer(path1); NodePointer np2 = (NodePointer) context.getPointer(path2); int res = np1.compareTo(np2); if (res < 0) { res = -1; } else if (res > 0) { res = 1; } assertEquals( "Comparing paths '" + path1 + "' and '" + path2 + "'", expected, res); } protected void assertXPathValueType( JXPathContext ctx, String xpath, Class clazz) { ctx.setLenient(false); Object actual = ctx.getValue(xpath); assertTrue("Evaluating <" + xpath + "> = " + actual.getClass(), clazz.isAssignableFrom(actual.getClass())); } protected void assertXPathNodeType( JXPathContext ctx, String xpath, Class clazz) { ctx.setLenient(false); Pointer actual = ctx.getPointer(xpath); assertTrue("Evaluating <" + xpath + "> = " + actual.getNode().getClass(), clazz.isAssignableFrom(actual.getNode().getClass())); } protected static List list() { return Collections.EMPTY_LIST; } protected static List list(Object o1) { List list = new ArrayList(); list.add(o1); return list; } protected static List list(Object o1, Object o2) { List list = new ArrayList(); list.add(o1); list.add(o2); return list; } protected static List list(Object o1, Object o2, Object o3) { List list = new ArrayList(); list.add(o1); list.add(o2); list.add(o3); return list; } protected static Set set(Object o1, Object o2) { Set list = new HashSet(); list.add(o1); list.add(o2); return list; } protected static Set set(Object o1, Object o2, Object o3) { Set list = new HashSet(); list.add(o1); list.add(o2); list.add(o3); return list; } protected static List list(Object o1, Object o2, Object o3, Object o4) { List list = new ArrayList(); list.add(o1); list.add(o2); list.add(o3); list.add(o4); return list; } protected static Set set(Object o1, Object o2, Object o3, Object o4) { Set list = new HashSet(); list.add(o1); list.add(o2); list.add(o3); list.add(o4); return list; } protected static List list(Object o1, Object o2, Object o3, Object o4, Object o5) { List list = new ArrayList(); list.add(o1); list.add(o2); list.add(o3); list.add(o4); list.add(o5); return list; } protected static Set set(Object o1, Object o2, Object o3, Object o4, Object o5) { Set list = new HashSet(); list.add(o1); list.add(o2); list.add(o3); list.add(o4); list.add(o5); return list; } protected static List list(Object o1, Object o2, Object o3, Object o4, Object o5, Object o6) { List list = new ArrayList(); list.add(o1); list.add(o2); list.add(o3); list.add(o4); list.add(o5); list.add(o6); return list; } protected static Set set(Object o1, Object o2, Object o3, Object o4, Object o5, Object o6) { Set list = new HashSet(); list.add(o1); list.add(o2); list.add(o3); list.add(o4); list.add(o5); list.add(o6); return list; } protected static List list(Object o1, Object o2, Object o3, Object o4, Object o5, Object o6, Object o7) { List list = new ArrayList(); list.add(o1); list.add(o2); list.add(o3); list.add(o4); list.add(o5); list.add(o6); list.add(o7); return list; } protected static Set set(Object o1, Object o2, Object o3, Object o4, Object o5, Object o6, Object o7) { Set list = new HashSet(); list.add(o1); list.add(o2); list.add(o3); list.add(o4); list.add(o5); list.add(o6); list.add(o7); return list; } }commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/NestedTestBean.java100644 0 0 3751 11044113525 24504 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; /** * A general purpose JavaBean for JUnit tests for the "jxpath" component. * * @author Dmitri Plotnikov * @version $Revision: 480417 $ $Date: 2006-11-28 23:37:40 -0600 (Tue, 28 Nov 2006) $ */ public class NestedTestBean { private String name = "Name 0"; private int integer = 1; public NestedTestBean() { } public NestedTestBean(String name) { this.name = name; } public void setName(String name) { this.name = name; } /** * A read-only boolean property */ public boolean isBoolean() { return false; } /** * A read-only int property */ public int getInt() { return integer; } public void setInt(int value) { this.integer = value; } /** * A read-only String property */ public String getName() { return name; } private String[] strings = new String[] { "String 1", "String 2", "String 3" }; public String[] getStrings() { return strings; } public void setStrings(String[] array) { strings = array; } public String toString() { return "Nested: " + name; } }commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/axes/RecursiveAxesTest.java100644 0 0 3451 11044113517 26634 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathTestCase; /** * Test for the protection mechanism that stops infinite recursion * in descent down a recursive graph. */ public class RecursiveAxesTest extends JXPathTestCase { private RecursiveBean bean; private JXPathContext context; protected void setUp() throws Exception { bean = new RecursiveBean("zero"); RecursiveBean bean1 = new RecursiveBean("one"); RecursiveBean bean2 = new RecursiveBean("two"); RecursiveBean bean3 = new RecursiveBean("three"); bean.setFirst(bean1); bean1.setFirst(bean2); bean2.setFirst(bean1); bean2.setSecond(bean3); context = JXPathContext.newContext(null, bean); } public void testInfiniteDescent() { // Existing scalar property assertXPathPointer( context, "//.[name = 'three']", "/first/first/second"); } } commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/axes/RecursiveBean.java100644 0 0 3223 11044113517 25736 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; /** * This bean is used to test infinite recursion protection in * descendant search contexts. * * @author Dmitri Plotnikov * @version $Revision: 480417 $ $Date: 2006-11-28 23:37:40 -0600 (Tue, 28 Nov 2006) $ */ public class RecursiveBean { private String name; private RecursiveBean first; private RecursiveBean second; public RecursiveBean(String name) { this.name = name; } public String getName() { return name; } public RecursiveBean getFirst() { return first; } public void setFirst(RecursiveBean bean) { this.first = bean; } public RecursiveBean getSecond() { return second; } public void setSecond(RecursiveBean bean) { second = bean; } public String toString() { return name; } } commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/axes/SimplePathInterpreterTest.java100644 0 0 54025 11044113517 30361 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import java.util.HashMap; import junit.framework.TestCase; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.NestedTestBean; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.TestNull; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.ri.model.VariablePointer; import org.apache.commons.jxpath.ri.model.beans.BeanPointer; import org.apache.commons.jxpath.ri.model.beans.BeanPropertyPointer; import org.apache.commons.jxpath.ri.model.beans.CollectionPointer; import org.apache.commons.jxpath.ri.model.beans.NullElementPointer; import org.apache.commons.jxpath.ri.model.beans.NullPointer; import org.apache.commons.jxpath.ri.model.beans.NullPropertyPointer; import org.apache.commons.jxpath.ri.model.beans.TestBeanFactory; import org.apache.commons.jxpath.ri.model.dom.DOMNodePointer; import org.apache.commons.jxpath.ri.model.dynamic.DynamicPointer; import org.apache.commons.jxpath.ri.model.dynamic.DynamicPropertyPointer; public class SimplePathInterpreterTest extends TestCase { private TestBeanWithNode bean; private JXPathContext context; protected void setUp() throws Exception { bean = TestBeanWithNode.createTestBeanWithDOM(); HashMap submap = new HashMap(); submap.put("key", new NestedTestBean("Name 9")); submap.put("strings", bean.getNestedBean().getStrings()); bean.getList().add(new int[]{1, 2}); bean.getList().add(bean.getVendor()); bean.getMap().put("Key3", new Object[]{ new NestedTestBean("some"), new Integer(2), bean.getVendor(), submap } ); bean.getMap().put("Key4", bean.getVendor()); bean.getMap().put("Key5", submap); bean.getMap().put("Key6", new Object[0]); context = JXPathContext.newContext(null, bean); context.setLenient(true); context.setFactory(new TestBeanFactory()); } public void testDoStepNoPredicatesPropertyOwner() { // Existing scalar property assertValueAndPointer("/int", new Integer(1), "/int", "Bb", "BbB"); // self:: assertValueAndPointer("/./int", new Integer(1), "/int", "Bb", "BbB"); // Missing property assertNullPointer("/foo", "/foo", "Bn"); // existingProperty/existingScalarProperty assertValueAndPointer("/nestedBean/int", new Integer(1), "/nestedBean/int", "BbBb", "BbBbB"); // existingProperty/collectionProperty assertValueAndPointer("/nestedBean/strings", bean.getNestedBean().getStrings(), "/nestedBean/strings", "BbBb", "BbBbC"); // existingProperty/missingProperty assertNullPointer("/nestedBean/foo", "/nestedBean/foo", "BbBn"); // map/missingProperty assertNullPointer("/map/foo", "/map[@name='foo']", "BbDd"); // Existing property by search in collection assertValueAndPointer("/list/int", new Integer(1), "/list[3]/int", "BbBb", "BbBbB"); // Missing property by search in collection assertNullPointer("/list/foo", "/list[1]/foo", "BbBn"); // existingProperty/missingProperty/missingProperty assertNullPointer("/nestedBean/foo/bar", "/nestedBean/foo/bar", "BbBnNn"); // collection/existingProperty/missingProperty assertNullPointer("/list/int/bar", "/list[3]/int/bar", "BbBbBn"); // collectionProperty/missingProperty/missingProperty assertNullPointer("/list/foo/bar", "/list[1]/foo/bar", "BbBnNn"); // map/missingProperty/anotherStep assertNullPointer("/map/foo/bar", "/map[@name='foo']/bar", "BbDdNn"); // Existing dynamic property assertValueAndPointer("/map/Key1", "Value 1", "/map[@name='Key1']", "BbDd", "BbDdB"); // collectionProperty assertValueAndPointer("/integers", bean.getIntegers(), "/integers", "Bb", "BbC"); } public void testDoStepNoPredicatesStandard() { // Existing DOM node assertValueAndPointer("/vendor/location/address/city", "Fruit Market", "/vendor/location[2]/address[1]/city[1]", "BbMMMM"); // Missing DOM node assertNullPointer("/vendor/location/address/pity", "/vendor/location[1]/address[1]/pity", "BbMMMn"); // Missing DOM node inside a missing element assertNullPointer("/vendor/location/address/itty/bitty", "/vendor/location[1]/address[1]/itty/bitty", "BbMMMnNn"); // Missing DOM node by search for the best match assertNullPointer("/vendor/location/address/city/pretty", "/vendor/location[2]/address[1]/city[1]/pretty", "BbMMMMn"); } public void testDoStepPredicatesPropertyOwner() { // missingProperty[@name=foo] assertNullPointer("/foo[@name='foo']", "/foo[@name='foo']", "BnNn"); // missingProperty[index] assertNullPointer("/foo[3]", "/foo[3]", "Bn"); } public void testDoStepPredicatesStandard() { // Looking for an actual XML attribute called "name" // nodeProperty/name[@name=value] assertValueAndPointer("/vendor/contact[@name='jack']", "Jack", "/vendor/contact[2]", "BbMM"); // Indexing in XML assertValueAndPointer("/vendor/contact[2]", "Jack", "/vendor/contact[2]", "BbMM"); // Indexing in XML, no result assertNullPointer("/vendor/contact[5]", "/vendor/contact[5]", "BbMn"); // Combination of search by name and indexing in XML assertValueAndPointer("/vendor/contact[@name='jack'][2]", "Jack Black", "/vendor/contact[4]", "BbMM"); // Combination of search by name and indexing in XML assertValueAndPointer("/vendor/contact[@name='jack'][2]", "Jack Black", "/vendor/contact[4]", "BbMM"); } public void testDoPredicateName() { // existingProperty[@name=existingProperty] assertValueAndPointer("/nestedBean[@name='int']", new Integer(1), "/nestedBean/int", "BbBb", "BbBbB"); // /self::node()[@name=existingProperty] assertValueAndPointer("/.[@name='int']", new Integer(1), "/int", "Bb", "BbB"); // dynamicProperty[@name=existingProperty] assertValueAndPointer("/map[@name='Key1']", "Value 1", "/map[@name='Key1']", "BbDd", "BbDdB"); // existingProperty[@name=collectionProperty] assertValueAndPointer("/nestedBean[@name='strings']", bean.getNestedBean().getStrings(), "/nestedBean/strings", "BbBb", "BbBbC"); // existingProperty[@name=missingProperty] assertNullPointer("/nestedBean[@name='foo']", "/nestedBean[@name='foo']", "BbBn"); // map[@name=collectionProperty] assertValueAndPointer("/map[@name='Key3']", bean.getMap().get("Key3"), "/map[@name='Key3']", "BbDd", "BbDdC"); // map[@name=missingProperty] assertNullPointer("/map[@name='foo']", "/map[@name='foo']", "BbDd"); // collectionProperty[@name=...] (find node) assertValueAndPointer("/list[@name='fruitco']", context.getValue("/vendor"), "/list[5]", "BbCM"); // collectionProperty[@name=...] (find map entry) assertValueAndPointer("/map/Key3[@name='key']/name", "Name 9", "/map[@name='Key3'][4][@name='key']/name", "BbDdCDdBb", "BbDdCDdBbB"); // map/collectionProperty[@name...] assertValueAndPointer("map/Key3[@name='fruitco']", context.getValue("/vendor"), "/map[@name='Key3'][3]", "BbDdCM"); // Bean property -> DOM Node, name match assertValueAndPointer("/vendor[@name='fruitco']", context.getValue("/vendor"), "/vendor", "BbM"); // Bean property -> DOM Node, name mismatch assertNullPointer("/vendor[@name='foo']", "/vendor[@name='foo']", "BbMn"); assertNullPointer("/vendor[@name='foo'][3]", "/vendor[@name='foo'][3]", "BbMn"); // existingProperty(bean)[@name=missingProperty]/anotherStep assertNullPointer("/nestedBean[@name='foo']/bar", "/nestedBean[@name='foo']/bar", "BbBnNn"); // map[@name=missingProperty]/anotherStep assertNullPointer("/map[@name='foo']/bar", "/map[@name='foo']/bar", "BbDdNn"); // existingProperty(node)[@name=missingProperty]/anotherStep assertNullPointer("/vendor[@name='foo']/bar", "/vendor[@name='foo']/bar", "BbMnNn"); // existingProperty(node)[@name=missingProperty][index]/anotherStep assertNullPointer("/vendor[@name='foo'][3]/bar", "/vendor[@name='foo'][3]/bar", "BbMnNn"); // Existing dynamic property + existing property assertValueAndPointer("/map[@name='Key2'][@name='name']", "Name 6", "/map[@name='Key2']/name", "BbDdBb", "BbDdBbB"); // Existing dynamic property + existing property + index assertValueAndPointer("/map[@name='Key2'][@name='strings'][2]", "String 2", "/map[@name='Key2']/strings[2]", "BbDdBb", "BbDdBbB"); // bean/map/map/property assertValueAndPointer("map[@name='Key5'][@name='key']/name", "Name 9", "/map[@name='Key5'][@name='key']/name", "BbDdDdBb", "BbDdDdBbB"); assertNullPointer("map[@name='Key2'][@name='foo']", "/map[@name='Key2'][@name='foo']", "BbDdBn"); assertNullPointer("map[@name='Key2'][@name='foo'][@name='bar']", "/map[@name='Key2'][@name='foo'][@name='bar']", "BbDdBnNn"); // bean/map/node assertValueAndPointer("map[@name='Key4'][@name='fruitco']", context.getValue("/vendor"), "/map[@name='Key4']", "BbDdM"); } public void testDoPredicatesStandard() { // bean/map/collection/node assertValueAndPointer("map[@name='Key3'][@name='fruitco']", context.getValue("/vendor"), "/map[@name='Key3'][3]", "BbDdCM"); // bean/map/collection/missingNode assertNullPointer("map[@name='Key3'][@name='foo']", "/map[@name='Key3'][4][@name='foo']", "BbDdCDd"); // bean/map/node assertValueAndPointer("map[@name='Key4'][@name='fruitco']", context.getValue("/vendor"), "/map[@name='Key4']", "BbDdM"); // bean/map/emptyCollection[@name=foo] assertNullPointer("map[@name='Key6'][@name='fruitco']", "/map[@name='Key6'][@name='fruitco']", "BbDdCn"); // bean/node[@name=foo][index] assertValueAndPointer("/vendor/contact[@name='jack'][2]", "Jack Black", "/vendor/contact[4]", "BbMM"); // bean/node[@name=foo][missingIndex] assertNullPointer("/vendor/contact[@name='jack'][5]", "/vendor/contact[@name='jack'][5]", "BbMnNn"); // bean/node/.[@name=foo][index] assertValueAndPointer("/vendor/contact/.[@name='jack']", "Jack", "/vendor/contact[2]", "BbMM"); } public void testDoPredicateIndex() { // Existing dynamic property + existing property + index assertValueAndPointer("/map[@name='Key2'][@name='strings'][2]", "String 2", "/map[@name='Key2']/strings[2]", "BbDdBb", "BbDdBbB"); // existingProperty[@name=collectionProperty][index] assertValueAndPointer("/nestedBean[@name='strings'][2]", bean.getNestedBean().getStrings()[1], "/nestedBean/strings[2]", "BbBb", "BbBbB"); // existingProperty[@name=missingProperty][index] assertNullPointer("/nestedBean[@name='foo'][3]", "/nestedBean[@name='foo'][3]", "BbBn"); // existingProperty[@name=collectionProperty][missingIndex] assertNullPointer("/nestedBean[@name='strings'][5]", "/nestedBean/strings[5]", "BbBbE"); // map[@name=collectionProperty][index] assertValueAndPointer("/map[@name='Key3'][2]", new Integer(2), "/map[@name='Key3'][2]", "BbDd", "BbDdB"); // map[@name=collectionProperty][missingIndex] assertNullPointer("/map[@name='Key3'][5]", "/map[@name='Key3'][5]", "BbDdE"); // map[@name=collectionProperty][missingIndex]/property assertNullPointer("/map[@name='Key3'][5]/foo", "/map[@name='Key3'][5]/foo", "BbDdENn"); // map[@name=map][@name=collection][index] assertValueAndPointer("/map[@name='Key5'][@name='strings'][2]", "String 2", "/map[@name='Key5'][@name='strings'][2]", "BbDdDd", "BbDdDdB"); // map[@name=map][@name=collection][missingIndex] assertNullPointer("/map[@name='Key5'][@name='strings'][5]", "/map[@name='Key5'][@name='strings'][5]", "BbDdDdE"); // Existing dynamic property + indexing assertValueAndPointer("/map[@name='Key3'][2]", new Integer(2), "/map[@name='Key3'][2]", "BbDd", "BbDdB"); // Existing dynamic property + indexing assertValueAndPointer("/map[@name='Key3'][1]/name", "some", "/map[@name='Key3'][1]/name", "BbDdBb", "BbDdBbB"); // map[@name=missingProperty][index] assertNullPointer("/map[@name='foo'][3]", "/map[@name='foo'][3]", "BbDdE"); // collectionProperty[index] assertValueAndPointer("/integers[2]", new Integer(2), "/integers[2]", "Bb", "BbB"); // existingProperty/collectionProperty[index] assertValueAndPointer("/nestedBean/strings[2]", bean.getNestedBean().getStrings()[1], "/nestedBean/strings[2]", "BbBb", "BbBbB"); // existingProperty[index]/existingProperty assertValueAndPointer("/list[3]/int", new Integer(1), "/list[3]/int", "BbBb", "BbBbB"); // existingProperty[missingIndex] assertNullPointer("/list[6]", "/list[6]", "BbE"); // existingProperty/missingProperty[index] assertNullPointer("/nestedBean/foo[3]", "/nestedBean/foo[3]", "BbBn"); // map[@name=missingProperty][index] assertNullPointer("/map/foo[3]", "/map[@name='foo'][3]", "BbDdE"); // existingProperty/collectionProperty[missingIndex] assertNullPointer("/nestedBean/strings[5]", "/nestedBean/strings[5]", "BbBbE"); // map/collectionProperty[missingIndex]/property assertNullPointer("/map/Key3[5]/foo", "/map[@name='Key3'][5]/foo", "BbDdENn"); // map[@name=map]/collection[index] assertValueAndPointer("/map[@name='Key5']/strings[2]", "String 2", "/map[@name='Key5'][@name='strings'][2]", "BbDdDd", "BbDdDdB"); // map[@name=map]/collection[missingIndex] assertNullPointer("/map[@name='Key5']/strings[5]", "/map[@name='Key5'][@name='strings'][5]", "BbDdDdE"); // scalarPropertyAsCollection[index] assertValueAndPointer("/int[1]", new Integer(1), "/int", "Bb", "BbB"); // scalarPropertyAsCollection[index] assertValueAndPointer(".[1]/int", new Integer(1), "/int", "Bb", "BbB"); } public void testInterpretExpressionPath() { context.getVariables().declareVariable("array", new String[]{"Value1"}); context.getVariables().declareVariable("testnull", new TestNull()); assertNullPointer("$testnull/nothing[2]", "$testnull/nothing[2]", "VBbE"); } private void assertValueAndPointer( String path, Object expectedValue, String expectedPath, String expectedSignature) { assertValueAndPointer( path, expectedValue, expectedPath, expectedSignature, expectedSignature); } private void assertValueAndPointer( String path, Object expectedValue, String expectedPath, String expectedSignature, String expectedValueSignature) { Object value = context.getValue(path); assertEquals("Checking value: " + path, expectedValue, value); Pointer pointer = context.getPointer(path); assertEquals("Checking pointer: " + path, expectedPath, pointer.toString()); assertEquals("Checking signature: " + path, expectedSignature, pointerSignature(pointer)); Pointer vPointer = ((NodePointer) pointer).getValuePointer(); assertEquals("Checking value pointer signature: " + path, expectedValueSignature, pointerSignature(vPointer)); } private void assertNullPointer(String path, String expectedPath, String expectedSignature) { Pointer pointer = context.getPointer(path); assertNotNull("Null path exists: " + path, pointer); assertEquals("Null path as path: " + path, expectedPath, pointer.asPath()); assertEquals("Checking Signature: " + path, expectedSignature, pointerSignature(pointer)); Pointer vPointer = ((NodePointer) pointer).getValuePointer(); assertTrue("Null path is null: " + path, !((NodePointer) vPointer).isActual()); assertEquals("Checking value pointer signature: " + path, expectedSignature + "N", pointerSignature(vPointer)); } /** * Since we need to test the internal Signature of a pointer, * we will get a signature which will contain a single character * per pointer in the chain, representing that pointer's type. */ private String pointerSignature(Pointer pointer) { if (pointer == null) { return ""; } char type = '?'; if (pointer instanceof NullPointer) { type = 'N'; } else if (pointer instanceof NullPropertyPointer) { type = 'n'; } else if (pointer instanceof NullElementPointer) { type = 'E'; } else if (pointer instanceof VariablePointer) { type = 'V'; } else if (pointer instanceof CollectionPointer) { type = 'C'; } else if (pointer instanceof BeanPointer) { type = 'B'; } else if (pointer instanceof BeanPropertyPointer) { type = 'b'; } else if (pointer instanceof DynamicPointer) { type = 'D'; } else if (pointer instanceof DynamicPropertyPointer) { type = 'd'; } else if (pointer instanceof DOMNodePointer) { type = 'M'; } else { System.err.println("UNKNOWN TYPE: " + pointer.getClass()); } NodePointer parent = ((NodePointer) pointer).getImmediateParentPointer(); return pointerSignature(parent) + type; } } commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/axes/TestBeanWithNode.java100644 0 0 4032 11044113517 26347 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.axes; import org.apache.commons.jxpath.JXPathTestCase; import org.apache.commons.jxpath.TestBean; import org.apache.commons.jxpath.xml.DocumentContainer; import org.w3c.dom.Document; /** * Test bean for mixed model JUnit tests. * * @author Dmitri Plotnikov * @version $Revision: 480417 $ $Date: 2006-11-28 23:37:40 -0600 (Tue, 28 Nov 2006) $ */ public class TestBeanWithNode extends TestBean { private Object node; private Object object; public Object getVendor() { return node; } public Object[] getVendors() { return new Object[] { node }; } public void setVendor(Object node) { this.node = node; } public Object getObject() { return object; } public void setObject(Object object) { this.object = object; } public static TestBeanWithNode createTestBeanWithDOM() { DocumentContainer docCtr = new DocumentContainer( JXPathTestCase.class.getResource("Vendor.xml")); Document doc = (Document) docCtr.getValue(); TestBeanWithNode tbwdom = new TestBeanWithNode(); tbwdom.setVendor(doc.getDocumentElement()); tbwdom.setObject(docCtr); return tbwdom; } } commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/compiler/ContextDependencyTest.java100644 0 0 3730 11044113523 30336 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.JXPathTestCase; import org.apache.commons.jxpath.ri.Parser; /** * Tests the determination of whether an expression is context dependent. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class ContextDependencyTest extends JXPathTestCase { public void testContextDependency() { testContextDependency("1", false); testContextDependency("$x", false); testContextDependency("/foo", false); testContextDependency("foo", true); testContextDependency("/foo[3]", false); testContextDependency("/foo[$x]", false); testContextDependency("/foo[bar]", true); testContextDependency("3 + 5", false); testContextDependency("test:func(3, 5)", true); testContextDependency("test:func(3, foo)", true); } public void testContextDependency(String xpath, boolean expected) { Expression expr = (Expression) Parser.parseExpression(xpath, new TreeCompiler()); assertEquals("Context dependency <" + xpath + ">", expected, expr.isContextDependent()); } } commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/compiler/CoreFunctionTest.java100644 0 0 24014 11044113523 27327 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import java.text.DecimalFormatSymbols; import java.util.Arrays; import java.util.List; import org.apache.commons.jxpath.ExtendedKeyManager; import org.apache.commons.jxpath.IdentityManager; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathTestCase; import org.apache.commons.jxpath.KeyManager; import org.apache.commons.jxpath.NodeSet; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.TestMixedModelBean; import org.apache.commons.jxpath.Variables; import org.apache.commons.jxpath.ri.model.NodePointer; /** * Test basic functionality of JXPath - core functions. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class CoreFunctionTest extends JXPathTestCase { private JXPathContext context; public void setUp() { if (context == null) { context = JXPathContext.newContext(new TestMixedModelBean()); Variables vars = context.getVariables(); vars.declareVariable("nan", new Double(Double.NaN)); vars.declareVariable("bool_true", new Boolean("true")); vars.declareVariable("bool_false", new Boolean("false")); } } public void testCoreFunctions() { assertXPathValue(context, "string(2)", "2"); assertXPathValue(context, "string($nan)", "NaN"); assertXPathValue(context, "string(-$nan)", "NaN"); assertXPathValue(context, "string(-2 div 0)", "-Infinity"); assertXPathValue(context, "string(2 div 0)", "Infinity"); assertXPathValue(context, "concat('a', 'b', 'c')", "abc"); assertXPathValue(context, "starts-with('abc', 'ab')", Boolean.TRUE); assertXPathValue(context, "starts-with('xabc', 'ab')", Boolean.FALSE); assertXPathValue(context, "contains('xabc', 'ab')", Boolean.TRUE); assertXPathValue(context, "contains('xabc', 'ba')", Boolean.FALSE); assertXPathValue( context, "substring-before('1999/04/01', '/')", "1999"); assertXPathValue( context, "substring-after('1999/04/01', '/')", "04/01"); assertXPathValue(context, "substring('12345', 2, 3)", "234"); assertXPathValue(context, "substring('12345', 2)", "2345"); assertXPathValue(context, "substring('12345', 1.5, 2.6)", "234"); assertXPathValue(context, "substring('12345', 0, 3)", "12"); assertXPathValue(context, "substring('12345', 0 div 0, 3)", ""); assertXPathValue(context, "substring('12345', 1, 0 div 0)", ""); assertXPathValue(context, "substring('12345', -42, 1 div 0)", "12345"); assertXPathValue(context, "substring('12345', -1 div 0, 1 div 0)", ""); assertXPathValue(context, "substring('12345', 6, 6)", ""); assertXPathValue(context, "substring('12345', 7, 8)", ""); assertXPathValue(context, "substring('12345', 7)", ""); assertXPathValue(context, "string-length('12345')", new Double(5)); assertXPathValue(context, "normalize-space(' abc def ')", "abc def"); assertXPathValue(context, "normalize-space('abc def')", "abc def"); assertXPathValue(context, "normalize-space(' ')", ""); assertXPathValue(context, "translate('--aaa--', 'abc-', 'ABC')", "AAA"); assertXPathValue(context, "boolean(1)", Boolean.TRUE); assertXPathValue(context, "boolean(0)", Boolean.FALSE); assertXPathValue(context, "boolean('x')", Boolean.TRUE); assertXPathValue(context, "boolean('')", Boolean.FALSE); assertXPathValue(context, "boolean(/list)", Boolean.TRUE); assertXPathValue(context, "boolean(/list[position() < 1])", Boolean.FALSE); assertXPathValue(context, "true()", Boolean.TRUE); assertXPathValue(context, "false()", Boolean.FALSE); assertXPathValue(context, "not(false())", Boolean.TRUE); assertXPathValue(context, "not(true())", Boolean.FALSE); assertXPathValue(context, "null()", null); assertXPathValue(context, "number('1')", new Double(1)); assertXPathValue(context, "number($bool_true)", new Double(1)); assertXPathValue(context, "number($bool_false)", new Double(0)); assertXPathValue(context, "floor(1.5)", new Double(1)); assertXPathValue(context, "floor(-1.5)", new Double(-2)); assertXPathValue(context, "ceiling(1.5)", new Double(2)); assertXPathValue(context, "ceiling(-1.5)", new Double(-1)); assertXPathValue(context, "round(1.5)", new Double(2)); assertXPathValue(context, "round(-1.5)", new Double(-1)); assertXPathValue(context, "floor('NaN')", new Double(Double.NaN)); assertXPathValue(context, "floor(-2 div 0)", new Double(Double.NEGATIVE_INFINITY)); assertXPathValue(context, "floor(2 div 0)", new Double(Double.POSITIVE_INFINITY)); assertXPathValue(context, "ceiling('NaN')", new Double(Double.NaN)); assertXPathValue(context, "ceiling(-2 div 0)", new Double(Double.NEGATIVE_INFINITY)); assertXPathValue(context, "ceiling(2 div 0)", new Double(Double.POSITIVE_INFINITY)); assertXPathValue(context, "round('NaN')", new Double(Double.NaN)); assertXPathValue(context, "round(-2 div 0)", new Double(Double.NEGATIVE_INFINITY)); assertXPathValue(context, "round(2 div 0)", new Double(Double.POSITIVE_INFINITY)); } public void testIDFunction() { context.setIdentityManager(new IdentityManager() { public Pointer getPointerByID(JXPathContext context, String id) { NodePointer ptr = (NodePointer) context.getPointer("/document"); ptr = ptr.getValuePointer(); return ptr.getPointerByID(context, id); } }); assertXPathValueAndPointer( context, "id(101)//street", "Tangerine Drive", "id('101')/address[1]/street[1]"); assertXPathPointerLenient( context, "id(105)/address/street", "id(105)/address/street"); } public void testKeyFunction() { context.setKeyManager(new KeyManager() { public Pointer getPointerByKey( JXPathContext context, String key, String value) { return NodePointer.newNodePointer(null, "42", null); } }); assertXPathValue(context, "key('a', 'b')", "42"); } public void testExtendedKeyFunction() { context.setKeyManager(new ExtendedKeyManager() { public Pointer getPointerByKey(JXPathContext context, String key, String value) { return NodePointer.newNodePointer(null, "incorrect", null); } public NodeSet getNodeSetByKey(JXPathContext context, String keyName, Object keyValue) { return new NodeSet() { public List getNodes() { return Arrays.asList(new Object[] { "53", "64" }); } public List getPointers() { return Arrays.asList(new NodePointer[] { NodePointer.newNodePointer(null, "53", null), NodePointer.newNodePointer(null, "64", null) }); } public List getValues() { return Arrays.asList(new Object[] { "53", "64" }); } }; } }); assertXPathValue(context, "key('a', 'b')", "53"); assertXPathValue(context, "key('a', 'b')[1]", "53"); assertXPathValue(context, "key('a', 'b')[2]", "64"); assertXPathValueIterator(context, "key('a', 'b')", list("53", "64")); assertXPathValueIterator(context, "'x' | 'y'", list("x", "y")); assertXPathValueIterator(context, "key('a', 'x' | 'y')", list("53", "64", "53", "64")); assertXPathValueIterator(context, "key('a', /list[position() < 4])", list("53", "64", "53", "64", "53", "64")); context.getVariables().declareVariable("ints", new int[] { 0, 0 }); assertXPathValueIterator(context, "key('a', $ints)", list("53", "64", "53", "64")); } public void testFormatNumberFunction() { DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setDigit('D'); context.setDecimalFormatSymbols("test", symbols); assertXPathValue( context, "format-number(123456789, '#.000000000')", "123456789.000000000"); assertXPathValue( context, "format-number(123456789, '#.0')", "123456789.0"); assertXPathValue( context, "format-number(0.123456789, '##%')", "12%"); assertXPathValue( context, "format-number(123456789, '################')", "123456789"); assertXPathValue( context, "format-number(123456789, 'D.0', 'test')", "123456789.0"); assertXPathValue( context, "format-number(123456789, '$DDD,DDD,DDD.DD', 'test')", "$123,456,789"); } }commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/compiler/CoreOperationTest.java100644 0 0 17152 11044113523 27507 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathTestCase; import org.apache.commons.jxpath.Variables; /** * Test basic functionality of JXPath - infoset types, * operations. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class CoreOperationTest extends JXPathTestCase { private JXPathContext context; public void setUp() { if (context == null) { context = JXPathContext.newContext(null); Variables vars = context.getVariables(); vars.declareVariable("integer", new Integer(1)); vars.declareVariable("array", new double[] { 0.25, 0.5, 0.75 }); vars.declareVariable("nan", new Double(Double.NaN)); } } public void testInfoSetTypes() { // Numbers assertXPathValue(context, "1", new Double(1.0)); assertXPathPointer(context, "1", "1"); assertXPathValueIterator(context, "1", list(new Double(1.0))); assertXPathPointerIterator(context, "1", list("1")); assertXPathValue(context, "-1", new Double(-1.0)); assertXPathValue(context, "2 + 2", new Double(4.0)); assertXPathValue(context, "3 - 2", new Double(1.0)); assertXPathValue(context, "1 + 2 + 3 - 4 + 5", new Double(7.0)); assertXPathValue(context, "3 * 2", new Double(3.0 * 2.0)); assertXPathValue(context, "3 div 2", new Double(3.0 / 2.0)); assertXPathValue(context, "5 mod 2", new Double(1.0)); // This test produces a different result with Xalan? assertXPathValue(context, "5.9 mod 2.1", new Double(1.0)); assertXPathValue(context, "5 mod -2", new Double(1.0)); assertXPathValue(context, "-5 mod 2", new Double(-1.0)); assertXPathValue(context, "-5 mod -2", new Double(-1.0)); assertXPathValue(context, "1 < 2", Boolean.TRUE); assertXPathValue(context, "1 > 2", Boolean.FALSE); assertXPathValue(context, "1 <= 1", Boolean.TRUE); assertXPathValue(context, "1 >= 2", Boolean.FALSE); assertXPathValue(context, "3 > 2 > 1", Boolean.FALSE); assertXPathValue(context, "3 > 2 and 2 > 1", Boolean.TRUE); assertXPathValue(context, "3 > 2 and 2 < 1", Boolean.FALSE); assertXPathValue(context, "3 < 2 or 2 > 1", Boolean.TRUE); assertXPathValue(context, "3 < 2 or 2 < 1", Boolean.FALSE); assertXPathValue(context, "1 = 1", Boolean.TRUE); assertXPathValue(context, "1 = '1'", Boolean.TRUE); assertXPathValue(context, "1 > 2 = 2 > 3", Boolean.TRUE); assertXPathValue(context, "1 > 2 = 0", Boolean.TRUE); assertXPathValue(context, "1 = 2", Boolean.FALSE); assertXPathValue(context, "$integer", new Double(1), Double.class); assertXPathValue(context, "2 + 3", "5.0", String.class); assertXPathValue(context, "2 + 3", Boolean.TRUE, boolean.class); assertXPathValue(context, "'true'", Boolean.TRUE, Boolean.class); } public void testNodeSetOperations() { assertXPathValue(context, "$array > 0", Boolean.TRUE, Boolean.class); assertXPathValue(context, "$array >= 0", Boolean.TRUE, Boolean.class); assertXPathValue(context, "$array = 0", Boolean.FALSE, Boolean.class); assertXPathValue(context, "$array = 0.25", Boolean.TRUE, Boolean.class); assertXPathValue(context, "$array = 0.5", Boolean.TRUE, Boolean.class); assertXPathValue(context, "$array = 0.50000", Boolean.TRUE, Boolean.class); assertXPathValue(context, "$array = 0.75", Boolean.TRUE, Boolean.class); assertXPathValue(context, "$array < 1", Boolean.TRUE, Boolean.class); assertXPathValue(context, "$array <= 1", Boolean.TRUE, Boolean.class); assertXPathValue(context, "$array = 1", Boolean.FALSE, Boolean.class); assertXPathValue(context, "$array > 1", Boolean.FALSE, Boolean.class); assertXPathValue(context, "$array < 0", Boolean.FALSE, Boolean.class); } public void testEmptyNodeSetOperations() { assertXPathValue(context, "/idonotexist = 0", Boolean.FALSE, Boolean.class); assertXPathValue(context, "/idonotexist != 0", Boolean.FALSE, Boolean.class); assertXPathValue(context, "/idonotexist < 0", Boolean.FALSE, Boolean.class); assertXPathValue(context, "/idonotexist > 0", Boolean.FALSE, Boolean.class); assertXPathValue(context, "/idonotexist >= 0", Boolean.FALSE, Boolean.class); assertXPathValue(context, "/idonotexist <= 0", Boolean.FALSE, Boolean.class); assertXPathValue(context, "$array[position() < 1] = 0", Boolean.FALSE, Boolean.class); assertXPathValue(context, "$array[position() < 1] != 0", Boolean.FALSE, Boolean.class); assertXPathValue(context, "$array[position() < 1] < 0", Boolean.FALSE, Boolean.class); assertXPathValue(context, "$array[position() < 1] > 0", Boolean.FALSE, Boolean.class); assertXPathValue(context, "$array[position() < 1] >= 0", Boolean.FALSE, Boolean.class); assertXPathValue(context, "$array[position() < 1] <= 0", Boolean.FALSE, Boolean.class); } public void testNan() { assertXPathValue(context, "$nan > $nan", Boolean.FALSE, Boolean.class); assertXPathValue(context, "$nan < $nan", Boolean.FALSE, Boolean.class); assertXPathValue(context, "$nan >= $nan", Boolean.FALSE, Boolean.class); assertXPathValue(context, "$nan <= $nan", Boolean.FALSE, Boolean.class); assertXPathValue(context, "$nan >= $nan and $nan <= $nan", Boolean.FALSE, Boolean.class); assertXPathValue(context, "$nan = $nan", Boolean.FALSE, Boolean.class); assertXPathValue(context, "$nan != $nan", Boolean.FALSE, Boolean.class); assertXPathValue(context, "$nan > 0", Boolean.FALSE, Boolean.class); assertXPathValue(context, "$nan < 0", Boolean.FALSE, Boolean.class); assertXPathValue(context, "$nan >= 0", Boolean.FALSE, Boolean.class); assertXPathValue(context, "$nan <= 0", Boolean.FALSE, Boolean.class); assertXPathValue(context, "$nan >= 0 and $nan <= 0", Boolean.FALSE, Boolean.class); assertXPathValue(context, "$nan = 0", Boolean.FALSE, Boolean.class); assertXPathValue(context, "$nan != 0", Boolean.FALSE, Boolean.class); assertXPathValue(context, "$nan > 1", Boolean.FALSE, Boolean.class); assertXPathValue(context, "$nan < 1", Boolean.FALSE, Boolean.class); assertXPathValue(context, "$nan >= 1", Boolean.FALSE, Boolean.class); assertXPathValue(context, "$nan <= 1", Boolean.FALSE, Boolean.class); assertXPathValue(context, "$nan >= 1 and $nan <= 1", Boolean.FALSE, Boolean.class); assertXPathValue(context, "$nan = 1", Boolean.FALSE, Boolean.class); assertXPathValue(context, "$nan != 1", Boolean.FALSE, Boolean.class); } }commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/compiler/ExtensionFunctionTest.java100644 0 0 33460 11044113523 30420 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Locale; import org.apache.commons.jxpath.ClassFunctions; import org.apache.commons.jxpath.ExpressionContext; import org.apache.commons.jxpath.Function; import org.apache.commons.jxpath.FunctionLibrary; import org.apache.commons.jxpath.Functions; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathTestCase; import org.apache.commons.jxpath.NodeSet; import org.apache.commons.jxpath.PackageFunctions; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.TestBean; import org.apache.commons.jxpath.Variables; import org.apache.commons.jxpath.ri.model.NodePointer; import org.apache.commons.jxpath.util.JXPath11CompatibleTypeConverter; import org.apache.commons.jxpath.util.TypeConverter; import org.apache.commons.jxpath.util.TypeUtils; /** * Test extension functions. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class ExtensionFunctionTest extends JXPathTestCase { private Functions functions; private JXPathContext context; private TestBean testBean; private TypeConverter typeConverter; public void setUp() { if (context == null) { testBean = new TestBean(); context = JXPathContext.newContext(testBean); Variables vars = context.getVariables(); vars.declareVariable("test", new TestFunctions(4, "test")); FunctionLibrary lib = new FunctionLibrary(); lib.addFunctions(new ClassFunctions(TestFunctions.class, "test")); lib.addFunctions(new ClassFunctions(TestFunctions2.class, "test")); lib.addFunctions(new PackageFunctions("", "call")); lib.addFunctions( new PackageFunctions( "org.apache.commons.jxpath.ri.compiler.", "jxpathtest")); lib.addFunctions(new PackageFunctions("", null)); context.setFunctions(lib); context.getVariables().declareVariable("List.class", List.class); context.getVariables().declareVariable("NodeSet.class", NodeSet.class); } functions = new ClassFunctions(TestFunctions.class, "test"); typeConverter = TypeUtils.getTypeConverter(); } public void tearDown() { TypeUtils.setTypeConverter(typeConverter); } public void testConstructorLookup() { Object[] args = new Object[] { new Integer(1), "x" }; Function func = functions.getFunction("test", "new", args); assertEquals( "test:new(1, x)", func.invoke(new Context(null), args).toString(), "foo=1; bar=x"); } public void testConstructorLookupWithExpressionContext() { Object[] args = new Object[] { "baz" }; Function func = functions.getFunction("test", "new", args); assertEquals( "test:new('baz')", func.invoke(new Context(new Integer(1)), args).toString(), "foo=1; bar=baz"); } public void testStaticMethodLookup() { Object[] args = new Object[] { new Integer(1), "x" }; Function func = functions.getFunction("test", "build", args); assertEquals( "test:build(1, x)", func.invoke(new Context(null), args).toString(), "foo=1; bar=x"); } public void testStaticMethodLookupWithConversion() { Object[] args = new Object[] { "7", new Integer(1)}; Function func = functions.getFunction("test", "build", args); assertEquals( "test:build('7', 1)", func.invoke(new Context(null), args).toString(), "foo=7; bar=1"); } public void testMethodLookup() { Object[] args = new Object[] { new TestFunctions()}; Function func = functions.getFunction("test", "getFoo", args); assertEquals( "test:getFoo($test, 1, x)", func.invoke(new Context(null), args).toString(), "0"); } public void testStaticMethodLookupWithExpressionContext() { Object[] args = new Object[0]; Function func = functions.getFunction("test", "path", args); assertEquals( "test:path()", func.invoke(new Context(new Integer(1)), args), "1"); } public void testMethodLookupWithExpressionContext() { Object[] args = new Object[] { new TestFunctions()}; Function func = functions.getFunction("test", "instancePath", args); assertEquals( "test:instancePath()", func.invoke(new Context(new Integer(1)), args), "1"); } public void testMethodLookupWithExpressionContextAndArgument() { Object[] args = new Object[] { new TestFunctions(), "*" }; Function func = functions.getFunction("test", "pathWithSuffix", args); assertEquals( "test:pathWithSuffix('*')", func.invoke(new Context(new Integer(1)), args), "1*"); } public void testAllocation() { // Allocate new object using the default constructor assertXPathValue(context, "string(test:new())", "foo=0; bar=null"); // Allocate new object using PackageFunctions and class name assertXPathValue( context, "string(jxpathtest:TestFunctions.new())", "foo=0; bar=null"); // Allocate new object using a fully qualified class name assertXPathValue( context, "string(" + TestFunctions.class.getName() + ".new())", "foo=0; bar=null"); // Allocate new object using a custom constructor assertXPathValue( context, "string(test:new(3, 'baz'))", "foo=3; bar=baz"); // Allocate new object using a custom constructor - type conversion assertXPathValue(context, "string(test:new('3', 4))", "foo=3; bar=4.0"); context.getVariables().declareVariable("A", "baz"); assertXPathValue( context, "string(test:new(2, $A, false))", "foo=2; bar=baz"); } public void testMethodCall() { assertXPathValue(context, "length('foo')", new Integer(3)); // We are just calling a method - prefix is ignored assertXPathValue(context, "call:substring('foo', 1, 2)", "o"); // Invoke a function implemented as a regular method assertXPathValue(context, "string(test:getFoo($test))", "4"); // Note that the prefix is ignored anyway, we are just calling a method assertXPathValue(context, "string(call:getFoo($test))", "4"); // We don't really need to supply a prefix in this case assertXPathValue(context, "string(getFoo($test))", "4"); // Method with two arguments assertXPathValue( context, "string(test:setFooAndBar($test, 7, 'biz'))", "foo=7; bar=biz"); } public void testCollectionMethodCall() { List list = new ArrayList(); list.add("foo"); context.getVariables().declareVariable("myList", list); assertXPathValue( context, "size($myList)", new Integer(1)); assertXPathValue( context, "size(beans)", new Integer(2)); context.getValue("add($myList, 'hello')"); assertEquals("After adding an element", 2, list.size()); JXPathContext context = JXPathContext.newContext(new ArrayList()); assertEquals("Extension function on root collection", "0", String .valueOf(context.getValue("size(/)"))); } public void testStaticMethodCall() { assertXPathValue( context, "string(test:build(8, 'goober'))", "foo=8; bar=goober"); // Call a static method using PackageFunctions and class name assertXPathValue( context, "string(jxpathtest:TestFunctions.build(8, 'goober'))", "foo=8; bar=goober"); // Call a static method with a fully qualified class name assertXPathValue( context, "string(" + TestFunctions.class.getName() + ".build(8, 'goober'))", "foo=8; bar=goober"); // Two ClassFunctions are sharing the same prefix. // This is TestFunctions2 assertXPathValue(context, "string(test:increment(8))", "9"); // See that a NodeSet gets properly converted to a string assertXPathValue(context, "test:string(/beans/name)", "Name 1"); } public void testExpressionContext() { // Execute an extension function for each node while searching // The function uses ExpressionContext to get to the current // node. assertXPathValue( context, "//.[test:isMap()]/Key1", "Value 1"); // The function gets all // nodes in the context that match the pattern. assertXPathValue( context, "count(//.[test:count(strings) = 3])", new Double(7)); // The function receives a collection of strings // and checks their type for testing purposes assertXPathValue( context, "test:count(//strings)", new Integer(21)); // The function receives a collection of pointers // and checks their type for testing purposes assertXPathValue( context, "test:countPointers(//strings)", new Integer(21)); // The function uses ExpressionContext to get to the current // pointer and returns its path. assertXPathValue( context, "/beans[contains(test:path(), '[2]')]/name", "Name 2"); } public void testCollectionReturn() { assertXPathValueIterator( context, "test:collection()/name", list("foo", "bar")); assertXPathPointerIterator( context, "test:collection()/name", list("/.[1]/name", "/.[2]/name")); assertXPathValue( context, "test:collection()/name", "foo"); assertXPathValue( context, "test:collection()/@name", "foo"); List list = new ArrayList(); list.add("foo"); list.add("bar"); context.getVariables().declareVariable("list", list); Object values = context.getValue("test:items($list)"); assertTrue("Return type: ", values instanceof Collection); assertEquals( "Return values: ", list, new ArrayList((Collection) values)); } public void testNodeSetReturn() { assertXPathValueIterator( context, "test:nodeSet()/name", list("Name 1", "Name 2")); assertXPathValueIterator( context, "test:nodeSet()", list(testBean.getBeans()[0], testBean.getBeans()[1])); assertXPathPointerIterator( context, "test:nodeSet()/name", list("/beans[1]/name", "/beans[2]/name")); assertXPathValueAndPointer( context, "test:nodeSet()/name", "Name 1", "/beans[1]/name"); assertXPathValueAndPointer( context, "test:nodeSet()/@name", "Name 1", "/beans[1]/@name"); assertEquals(2, ((Number) context.getValue("count(test:nodeSet())")).intValue()); assertXPathValue(context, "test:nodeSet()", testBean.getBeans()[0]); } public void testEstablishNodeSetBaseline() { assertXPathValue( context, "test:isInstance(//strings, $List.class)", Boolean.TRUE); assertXPathValue( context, "test:isInstance(//strings, $NodeSet.class)", Boolean.FALSE); } public void testBCNodeSetHack() { TypeUtils.setTypeConverter(new JXPath11CompatibleTypeConverter()); assertXPathValue( context, "test:isInstance(//strings, $List.class)", Boolean.FALSE); assertXPathValue( context, "test:isInstance(//strings, $NodeSet.class)", Boolean.TRUE); } private static class Context implements ExpressionContext { private Object object; public Context(Object object) { this.object = object; } public Pointer getContextNodePointer() { return NodePointer .newNodePointer(null, object, Locale.getDefault()); } public List getContextNodeList() { return null; } public JXPathContext getJXPathContext() { return null; } public int getPosition() { return 0; } } }commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/compiler/TestFunctions.java100644 0 0 11016 11044113523 26677 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.Map; import org.apache.commons.jxpath.BasicNodeSet; import org.apache.commons.jxpath.ExpressionContext; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.NestedTestBean; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.NodeSet; /** * @author Dmitri Plotnikov * @version $Revision: 495033 $ $Date: 2007-01-10 17:15:33 -0600 (Wed, 10 Jan 2007) $ */ public class TestFunctions { private int foo; private String bar; public TestFunctions() { } public TestFunctions(int foo, String bar) { this.foo = foo; this.bar = bar; } public TestFunctions(ExpressionContext context, String bar) { this.foo = ((Number) context.getContextNodePointer().getValue()).intValue(); this.bar = bar; } public TestFunctions(int foo, Object object, boolean another) { this.foo = foo; bar = String.valueOf(object); } public int getFoo() { return foo; } public String getBar() { return bar; } public void doit() { } public TestFunctions setFooAndBar(int foo, String bar) { this.foo = foo; this.bar = bar; return this; } public static TestFunctions build(int foo, String bar) { return new TestFunctions(foo, bar); } public String toString() { return "foo=" + foo + "; bar=" + bar; } public static String path(ExpressionContext context) { return context.getContextNodePointer().asPath(); } public String instancePath(ExpressionContext context) { return context.getContextNodePointer().asPath(); } public String pathWithSuffix(ExpressionContext context, String suffix) { return context.getContextNodePointer().asPath() + suffix; } public String className( ExpressionContext context, ExpressionContext child) { return context.getContextNodePointer().asPath(); } /** * Returns true if the current node in the current context is a map */ public static boolean isMap(ExpressionContext context) { Pointer ptr = context.getContextNodePointer(); return ptr == null ? false : (ptr.getValue() instanceof Map); } /** * Returns the number of nodes in the context that is passed as * the first argument. */ public static int count(ExpressionContext context, Collection col) { for (Iterator iter = col.iterator(); iter.hasNext();) { Object element = iter.next(); if (!(element instanceof String)) { throw new RuntimeException("Invalid argument"); } }; return col.size(); } public static int countPointers(NodeSet nodeSet) { return nodeSet.getPointers().size(); } public static String string(String string) { return string; } public static Collection collection() { ArrayList list = new ArrayList(); list.add(new NestedTestBean("foo")); list.add(new NestedTestBean("bar")); return list; } public static NodeSet nodeSet(ExpressionContext context) { JXPathContext jxpathCtx = context.getJXPathContext(); BasicNodeSet set = new BasicNodeSet(); set.add(jxpathCtx.getPointer("/beans[1]")); set.add(jxpathCtx.getPointer("/beans[2]")); return set; } public static Collection items(Collection arg) { return arg; } public static Boolean isInstance(Object o, Class c) { return c.isInstance(o) ? Boolean.TRUE : Boolean.FALSE; } }commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/compiler/TestFunctions2.java100644 0 0 2062 11044113523 26742 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; /** * @author Dmitri Plotnikov * @version $Revision: 480417 $ $Date: 2006-11-28 23:37:40 -0600 (Tue, 28 Nov 2006) $ */ public class TestFunctions2 { public static int increment(int i) { return i + 1; } }commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/compiler/VariableFactory.java100644 0 0 5007 11044113523 27127 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.AbstractFactory; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.TestBean; /** * Test AbstractFactory. * * @author Dmitri Plotnikov * @version $Revision: 480417 $ $Date: 2006-11-28 23:37:40 -0600 (Tue, 28 Nov 2006) $ */ public class VariableFactory extends AbstractFactory { /** */ public boolean createObject( JXPathContext context, Pointer pointer, Object parent, String name, int index) { if (name.equals("testArray")) { ((TestBean[]) parent)[index] = new TestBean(); return true; } else if (name.equals("stringArray")) { ((String[]) parent)[index] = ""; return true; } else if (name.equals("array")) { ((String[]) parent)[index] = ""; return true; } return false; } /** * Create a new object and set it on the specified variable */ public boolean declareVariable(JXPathContext context, String name) { if (name.equals("test")) { context.getVariables().declareVariable(name, new TestBean()); return true; } else if (name.equals("testArray")) { context.getVariables().declareVariable(name, new TestBean[0]); return true; } else if (name.equals("stringArray")) { context.getVariables().declareVariable( name, new String[] { "Value1" }); return true; } context.getVariables().declareVariable(name, null); return true; } } commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/compiler/VariableTest.java100644 0 0 22171 11044113523 26460 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.compiler; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathTestCase; import org.apache.commons.jxpath.TestMixedModelBean; import org.apache.commons.jxpath.Variables; /** * Test basic functionality of JXPath - infoset types, * operations. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class VariableTest extends JXPathTestCase { private JXPathContext context; public void setUp() { if (context == null) { context = JXPathContext.newContext(new TestMixedModelBean()); context.setFactory(new VariableFactory()); Variables vars = context.getVariables(); vars.declareVariable("a", new Double(1)); vars.declareVariable("b", new Double(1)); vars.declareVariable("c", null); vars.declareVariable("d", new String[] { "a", "b" }); vars.declareVariable("integer", new Integer(1)); vars.declareVariable("nan", new Double(Double.NaN)); vars.declareVariable("x", null); } } public void testVariables() { // Variables assertXPathValueAndPointer(context, "$a", new Double(1), "$a"); } public void testVariablesInExpressions() { assertXPathValue(context, "$a = $b", Boolean.TRUE); assertXPathValue(context, "$a = $nan", Boolean.FALSE); assertXPathValue(context, "$a + 1", new Double(2)); assertXPathValue(context, "$c", null); assertXPathValue(context, "$d[2]", "b"); } public void testInvalidVariableName() { boolean exception = false; try { context.getValue("$none"); } catch (Exception ex) { exception = true; } assertTrue( "Evaluating '$none', expected exception - did not get it", exception); exception = false; try { context.setValue("$none", new Integer(1)); } catch (Exception ex) { exception = true; } assertTrue( "Setting '$none = 1', expected exception - did not get it", exception); } public void testNestedContext() { JXPathContext nestedContext = JXPathContext.newContext(context, null); assertXPathValue(nestedContext, "$a", new Double(1)); } public void testSetValue() { assertXPathSetValue(context, "$x", new Integer(1)); } public void testCreatePathDeclareVariable() { // Calls factory.declareVariable("string") assertXPathCreatePath(context, "$string", null, "$string"); } public void testCreatePathAndSetValueDeclareVariable() { // Calls factory.declareVariable("string") assertXPathCreatePathAndSetValue( context, "$string", "Value", "$string"); } public void testCreatePathDeclareVariableSetCollectionElement() { // Calls factory.declareVariable("stringArray"). // The factory needs to create a collection assertXPathCreatePath( context, "$stringArray[2]", "", "$stringArray[2]"); // See if the factory populated the first element as well assertEquals( "Created <" + "$stringArray[1]" + ">", "Value1", context.getValue("$stringArray[1]")); } public void testCreateAndSetValuePathDeclareVariableSetCollectionElement() { // Calls factory.declareVariable("stringArray"). // The factory needs to create a collection assertXPathCreatePathAndSetValue( context, "$stringArray[2]", "Value2", "$stringArray[2]"); // See if the factory populated the first element as well assertEquals( "Created <" + "$stringArray[1]" + ">", "Value1", context.getValue("$stringArray[1]")); } public void testCreatePathExpandCollection() { context.getVariables().declareVariable( "array", new String[] { "Value1" }); // Does not involve factory at all - just expands the collection assertXPathCreatePath(context, "$array[2]", "", "$array[2]"); // Make sure it is still the same array assertEquals( "Created <" + "$array[1]" + ">", "Value1", context.getValue("$array[1]")); } public void testCreatePathAndSetValueExpandCollection() { context.getVariables().declareVariable( "array", new String[] { "Value1" }); // Does not involve factory at all - just expands the collection assertXPathCreatePathAndSetValue( context, "$array[2]", "Value2", "$array[2]"); // Make sure it is still the same array assertEquals( "Created <" + "$array[1]" + ">", "Value1", context.getValue("$array[1]")); } public void testCreatePathDeclareVariableSetProperty() { // Calls factory.declareVariable("test"). // The factory should create a TestBean assertXPathCreatePath( context, "$test/boolean", Boolean.FALSE, "$test/boolean"); } public void testCreatePathAndSetValueDeclareVariableSetProperty() { // Calls factory.declareVariable("test"). // The factory should create a TestBean assertXPathCreatePathAndSetValue( context, "$test/boolean", Boolean.TRUE, "$test/boolean"); } public void testCreatePathDeclareVariableSetCollectionElementProperty() { // Calls factory.declareVariable("testArray"). // The factory should create a collection of TestBeans. // Then calls factory.createObject(..., collection, "testArray", 1). // That one should produce an instance of TestBean and // put it in the collection at index 1. assertXPathCreatePath( context, "$testArray[2]/boolean", Boolean.FALSE, "$testArray[2]/boolean"); } public void testCreatePathAndSetValueDeclVarSetCollectionElementProperty() { // Calls factory.declareVariable("testArray"). // The factory should create a collection of TestBeans. // Then calls factory.createObject(..., collection, "testArray", 1). // That one should produce an instance of TestBean and // put it in the collection at index 1. assertXPathCreatePathAndSetValue( context, "$testArray[2]/boolean", Boolean.TRUE, "$testArray[2]/boolean"); } public void testRemovePathUndeclareVariable() { // Undeclare variable context.getVariables().declareVariable("temp", "temp"); context.removePath("$temp"); assertTrue( "Undeclare variable", !context.getVariables().isDeclaredVariable("temp")); } public void testRemovePathArrayElement() { // Remove array element - reassigns the new array to the var context.getVariables().declareVariable( "temp", new String[] { "temp1", "temp2" }); context.removePath("$temp[1]"); assertEquals( "Remove array element", "temp2", context.getValue("$temp[1]")); } public void testRemovePathCollectionElement() { // Remove list element - does not create a new list context.getVariables().declareVariable("temp", list("temp1", "temp2")); context.removePath("$temp[1]"); assertEquals( "Remove collection element", "temp2", context.getValue("$temp[1]")); } public void testUnionOfVariableAndNode() throws Exception { assertXPathValue(context, "count($a | /document/vendor/location)", new Double(3)); assertXPathValue(context, "count($a | /list)", new Double(7)); //$o + list which contains six discrete values (one is duped, wrapped in a Container) } public void testIterateVariable() throws Exception { assertXPathValueIterator(context, "$d", list("a", "b")); assertXPathValue(context, "$d = 'a'", Boolean.TRUE); assertXPathValue(context, "$d = 'b'", Boolean.TRUE); } }commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/JXPathCompiledExpressionTest.java100644 0 0 30751 11044113525 30021 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathTestCase; import org.apache.commons.jxpath.ri.compiler.Constant; import org.apache.commons.jxpath.ri.compiler.CoreFunction; import org.apache.commons.jxpath.ri.compiler.CoreOperationAdd; import org.apache.commons.jxpath.ri.compiler.CoreOperationAnd; import org.apache.commons.jxpath.ri.compiler.CoreOperationDivide; import org.apache.commons.jxpath.ri.compiler.CoreOperationEqual; import org.apache.commons.jxpath.ri.compiler.CoreOperationGreaterThan; import org.apache.commons.jxpath.ri.compiler.CoreOperationGreaterThanOrEqual; import org.apache.commons.jxpath.ri.compiler.CoreOperationLessThan; import org.apache.commons.jxpath.ri.compiler.CoreOperationLessThanOrEqual; import org.apache.commons.jxpath.ri.compiler.CoreOperationMod; import org.apache.commons.jxpath.ri.compiler.CoreOperationMultiply; import org.apache.commons.jxpath.ri.compiler.CoreOperationNegate; import org.apache.commons.jxpath.ri.compiler.CoreOperationNotEqual; import org.apache.commons.jxpath.ri.compiler.CoreOperationOr; import org.apache.commons.jxpath.ri.compiler.CoreOperationSubtract; import org.apache.commons.jxpath.ri.compiler.CoreOperationUnion; import org.apache.commons.jxpath.ri.compiler.ExpressionPath; import org.apache.commons.jxpath.ri.compiler.ExtensionFunction; import org.apache.commons.jxpath.ri.compiler.LocationPath; import org.apache.commons.jxpath.ri.compiler.NameAttributeTest; import org.apache.commons.jxpath.ri.compiler.VariableReference; /** * Test compiler. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class JXPathCompiledExpressionTest extends JXPathTestCase { public void testConstant() { assertXPathExpression("1", Constant.class); assertXPathExpression("1.5", Constant.class); assertXPathExpression("'foo'", Constant.class); } public void testCoreFunction() { assertXPathExpression("last()", CoreFunction.class); assertXPathExpression("position()", CoreFunction.class); assertXPathExpression("count(book)", CoreFunction.class); assertXPathExpression("id(13)", CoreFunction.class); assertXPathExpression("local-name()", CoreFunction.class); assertXPathExpression("local-name(book)", CoreFunction.class); assertXPathExpression("namespace-uri()", CoreFunction.class); assertXPathExpression("namespace-uri(book)", CoreFunction.class); assertXPathExpression("name()", CoreFunction.class); assertXPathExpression("name(book)", CoreFunction.class); assertXPathExpression("string(3)", CoreFunction.class); assertXPathExpression("concat('a', 'b')", CoreFunction.class); assertXPathExpression("starts-with('a', 'b')", CoreFunction.class); assertXPathExpression("contains('a', 'b')", CoreFunction.class); assertXPathExpression("substring-before('a', 1)", CoreFunction.class); assertXPathExpression("substring-after('a', 2)", CoreFunction.class); assertXPathExpression("substring('a', 2)", CoreFunction.class); assertXPathExpression("substring('a', 2, 3)", CoreFunction.class); assertXPathExpression("string-length('a')", CoreFunction.class); assertXPathExpression("normalize-space('a')", CoreFunction.class); assertXPathExpression("translate('a', 'b', 'c')", CoreFunction.class); assertXPathExpression("boolean('true')", CoreFunction.class); assertXPathExpression("not(1)", CoreFunction.class); assertXPathExpression("true()", CoreFunction.class); assertXPathExpression("false()", CoreFunction.class); assertXPathExpression("lang('fr')", CoreFunction.class); assertXPathExpression("number('12')", CoreFunction.class); assertXPathExpression("sum(book/price)", CoreFunction.class); assertXPathExpression("floor(11.4)", CoreFunction.class); assertXPathExpression("ceiling(11.4)", CoreFunction.class); assertXPathExpression("round(11.4)", CoreFunction.class); assertXPathExpression("key('title', 'Hobbit')", CoreFunction.class); assertXPathExpression("format-number(12, '##')", CoreFunction.class); } public void testCoreOperationAnd() { assertXPathExpression("2 and 4", CoreOperationAnd.class); assertXPathExpression("2 > 1 and 4 < 5", CoreOperationAnd.class); } public void testCoreOperationOr() { assertXPathExpression("2 or 4", CoreOperationOr.class); assertXPathExpression("2 > 1 or 4 < 5", CoreOperationOr.class); assertXPathExpression("1 > 1 and 2 <= 2 or 3 = 4", CoreOperationOr.class); } public void testCoreOperationEqual() { assertXPathExpression("2 = 4", CoreOperationEqual.class); assertXPathExpression("2 + 1 = 3", CoreOperationEqual.class); } public void testCoreOperationNameAttributeTest() { assertXPathExpression("@name = 'bar'", NameAttributeTest.class); } public void testCoreOperationNotEqual() { assertXPathExpression("2 != 4", CoreOperationNotEqual.class); assertXPathExpression("2 + 1 != 3", CoreOperationNotEqual.class); } public void testCoreOperationLessThan() { assertXPathExpression("3<4", CoreOperationLessThan.class, "3 < 4"); assertXPathExpression("3<(2>=1)", CoreOperationLessThan.class, "3 < (2 >= 1)"); } public void testCoreOperationLessThanOrEqual() { assertXPathExpression("3<=4", CoreOperationLessThanOrEqual.class, "3 <= 4"); assertXPathExpression("3<=(2>=1)", CoreOperationLessThanOrEqual.class, "3 <= (2 >= 1)"); } public void testCoreOperationGreaterThan() { assertXPathExpression("3>4", CoreOperationGreaterThan.class, "3 > 4"); assertXPathExpression("3>(2>=1)", CoreOperationGreaterThan.class, "3 > (2 >= 1)"); assertXPathExpression("1 > (1 and 2 <= (2 or 3) = 4)", CoreOperationGreaterThan.class); } public void testCoreOperationGreaterThanOrEqual() { assertXPathExpression("3>=4", CoreOperationGreaterThanOrEqual.class, "3 >= 4"); assertXPathExpression("3>=(2>=1)", CoreOperationGreaterThanOrEqual.class, "3 >= (2 >= 1)"); } public void testCoreOperationDivide() { assertXPathExpression("2 div 4", CoreOperationDivide.class); assertXPathExpression("2|3 div -3", CoreOperationDivide.class, "2 | 3 div -3"); } public void testCoreOperationMod() { assertXPathExpression("2 mod 4", CoreOperationMod.class); assertXPathExpression("2|3 mod -3", CoreOperationMod.class, "2 | 3 mod -3"); } public void testCoreOperationMultiply() { assertXPathExpression("2*4", CoreOperationMultiply.class, "2 * 4"); assertXPathExpression("2*(3 + 1)", CoreOperationMultiply.class, "2 * (3 + 1)"); } public void testCoreOperationMinus() { assertXPathExpression("1 - 1", CoreOperationSubtract.class); assertXPathExpression("1 - 1 - 2", CoreOperationSubtract.class); assertXPathExpression("1 - (1 - 2)", CoreOperationSubtract.class); } public void testCoreOperationSum() { assertXPathExpression("3 + 1 + 4", CoreOperationAdd.class); assertXPathExpression("(3 + 1) + 4", CoreOperationAdd.class, "3 + 1 + 4"); assertXPathExpression("3 + (1 + 4)", CoreOperationAdd.class, "3 + 1 + 4"); assertXPathExpression("3 + -1", CoreOperationAdd.class, "3 + -1"); assertXPathExpression("2*-3 + -1", CoreOperationAdd.class, "2 * -3 + -1"); } public void testCoreOperationUnaryMinus() { assertXPathExpression("-3", CoreOperationNegate.class); assertXPathExpression("-(3 + 1)", CoreOperationNegate.class); } public void testCoreOperationUnion() { assertXPathExpression("3 | 1 | 4", CoreOperationUnion.class); } public void testExpressionPath() { assertXPathExpression("$x/foo/bar", ExpressionPath.class); assertXPathExpression("(2 + 2)/foo/bar", ExpressionPath.class); assertXPathExpression("$x[3][2 + 2]/foo/bar", ExpressionPath.class); } public void testExtensionFunction() { assertXPathExpression("my:function(3, other.function())", ExtensionFunction.class); } public void testLocationPathAxisSelf() { assertXPathExpression("self::foo:bar", LocationPath.class); assertXPathExpression(".", LocationPath.class); } public void testLocationPathAxisChild() { assertXPathExpression("child::foo:bar", LocationPath.class, "foo:bar"); assertXPathExpression("foo:bar", LocationPath.class); assertXPathExpression("/foo:bar", LocationPath.class); assertXPathExpression("/foo/bar", LocationPath.class); assertXPathExpression("*", LocationPath.class); assertXPathExpression("foo:*", LocationPath.class); } public void testLocationPathAxisParent() { assertXPathExpression("parent::foo:bar", LocationPath.class); assertXPathExpression("..", LocationPath.class); } public void testLocationPathAxisAttribute() { assertXPathExpression("attribute::foo:bar", LocationPath.class, "@foo:bar"); assertXPathExpression("@foo:bar", LocationPath.class); assertXPathExpression("../@foo:bar", LocationPath.class); assertXPathExpression("@*", LocationPath.class); assertXPathExpression("@*[last()]", LocationPath.class); } public void testLocationPathAxisDescendant() { assertXPathExpression("descendant::foo:bar", LocationPath.class); } public void testLocationPathAxisDescendantOrSelf() { assertXPathExpression("descendant-or-self::foo:bar", LocationPath.class); assertXPathExpression("//foo", LocationPath.class); assertXPathExpression("foo//bar", LocationPath.class); } public void testLocationPathAxisOther() { assertXPathExpression("ancestor::foo:bar", LocationPath.class); assertXPathExpression("ancestor-or-self::foo:bar", LocationPath.class); assertXPathExpression("namespace::foo:bar", LocationPath.class); assertXPathExpression("preceding::foo:bar", LocationPath.class); assertXPathExpression("preceding-sibling::foo:bar", LocationPath.class); assertXPathExpression("following::foo:bar", LocationPath.class); assertXPathExpression("following-sibling::foo:bar", LocationPath.class); } public void testLocationPathNodeTest() { assertXPathExpression("node()", LocationPath.class); assertXPathExpression("text()", LocationPath.class); assertXPathExpression("comment()", LocationPath.class); assertXPathExpression("processing-instruction()", LocationPath.class); assertXPathExpression("processing-instruction('test')", LocationPath.class); } public void testVariableReference() { assertXPathExpression("$x", VariableReference.class); assertXPathExpression("$x:y", VariableReference.class); } /** * Compiles the xpath into an Expression, checks the expression * class, converts the expression to string and checks that the string * matches the expected one. */ private void assertXPathExpression(String xpath, Class expectedClass, String expected) { JXPathCompiledExpression expression = (JXPathCompiledExpression) JXPathContext.compile(xpath); assertEquals("Expression class for " + xpath, expectedClass, expression.getExpression().getClass()); assertEquals("Expression toString() for " + xpath, expected, expression.getExpression().toString()); } private void assertXPathExpression(String xpath, Class expectedClass) { assertXPathExpression(xpath, expectedClass, xpath); } } commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/BeanModelTestCase.java100644 0 0 72722 11044113523 26652 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Locale; import org.apache.commons.jxpath.AbstractFactory; import org.apache.commons.jxpath.ClassFunctions; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathTestCase; import org.apache.commons.jxpath.NestedTestBean; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.compiler.NodeNameTest; import org.apache.commons.jxpath.ri.compiler.TestFunctions; import org.apache.commons.jxpath.ri.model.beans.PropertyOwnerPointer; import org.apache.commons.jxpath.ri.model.beans.PropertyPointer; import org.apache.commons.jxpath.ri.model.dynabeans.DynaBeanModelTest; /** * Abstract superclass for Bean access with JXPath. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public abstract class BeanModelTestCase extends JXPathTestCase { private JXPathContext context; public void setUp() { // if (context == null) { context = JXPathContext.newContext(createContextBean()); context.setLocale(Locale.US); context.setFactory(getAbstractFactory()); // } } protected abstract Object createContextBean(); protected abstract AbstractFactory getAbstractFactory(); /** * Test property iterators, the core of the graph traversal engine */ public void testIndividualIterators() { testIndividual(+1, 0, true, false, 0); testIndividual(-1, 0, true, false, 4); testIndividual(0, -1, true, true, 4); testIndividual(+1, -1, true, true, 4); testIndividual(-1, -1, true, true, 0); testIndividual(0, 1, true, false, 2); testIndividual(0, 1, true, true, 1); testIndividual(0, 0, false, false, 4); testIndividual(0, 0, false, true, 4); } private void testIndividual( int relativePropertyIndex, int offset, boolean useStartLocation, boolean reverse, int expected) { PropertyOwnerPointer root = (PropertyOwnerPointer) NodePointer.newNodePointer( new QName(null, "root"), createContextBean(), Locale.getDefault()); NodeIterator it; PropertyPointer start = null; if (useStartLocation) { start = root.getPropertyPointer(); start.setPropertyIndex( relativeProperty(start, relativePropertyIndex)); start.setIndex(offset); } it = root.childIterator( new NodeNameTest(new QName(null, "integers")), reverse, start); int size = 0; while (it.setPosition(it.getPosition() + 1)) { size++; } assertEquals( "ITERATIONS: Individual, relativePropertyIndex=" + relativePropertyIndex + ", offset=" + offset + ", useStartLocation=" + useStartLocation + ", reverse=" + reverse, expected, size); } /** * Test property iterators with multiple properties returned */ public void testMultipleIterators() { testMultiple(0, 0, true, false, 20); testMultiple(3, 0, true, false, 16); testMultiple(3, -1, true, true, 8); testMultiple(3, 0, true, true, 4); testMultiple(0, 0, false, false, 21); testMultiple(0, 0, false, true, 21); testMultiple(3, 1, true, false, 15); testMultiple(3, 3, true, false, 13); } private void testMultiple( int propertyIndex, int offset, boolean useStartLocation, boolean reverse, int expected) { PropertyOwnerPointer root = (PropertyOwnerPointer) NodePointer.newNodePointer( new QName(null, "root"), createContextBean(), Locale.getDefault()); NodeIterator it; PropertyPointer start = null; if (useStartLocation) { start = root.getPropertyPointer(); start.setPropertyIndex(propertyIndex); start.setIndex(offset); } it = root.childIterator(null, reverse, start); int size = 0; while (it.setPosition(it.getPosition() + 1)) { // System.err.println("LOC: " + it.getCurrentNodePointer()); size++; } assertEquals( "ITERATIONS: Multiple, propertyIndex=" + propertyIndex + ", offset=" + offset + ", useStartLocation=" + useStartLocation + ", reverse=" + reverse, expected, size); } private int relativeProperty(PropertyPointer holder, int offset) { String[] names = holder.getPropertyNames(); for (int i = 0; i < names.length; i++) { if (names[i].equals("integers")) { return i + offset; } } return -1; } public void testIteratePropertyArrayWithHasNext() { JXPathContext context = JXPathContext.newContext(createContextBean()); Iterator it = context.iteratePointers("/integers"); List actual = new ArrayList(); while (it.hasNext()) { actual.add(((Pointer) it.next()).asPath()); } assertEquals( "Iterating 'hasNext'/'next'<" + "/integers" + ">", list( "/integers[1]", "/integers[2]", "/integers[3]", "/integers[4]"), actual); } public void testIteratePropertyArrayWithoutHasNext() { JXPathContext context = JXPathContext.newContext(createContextBean()); Iterator it = context.iteratePointers("/integers"); List actual = new ArrayList(); for (int i = 0; i < 4; i++) { actual.add(it.next().toString()); } assertEquals( "Iterating 'next'<" + "/integers" + ">", list( "/integers[1]", "/integers[2]", "/integers[3]", "/integers[4]"), actual); } public void testIterateAndSet() { JXPathContext context = JXPathContext.newContext(createContextBean()); Iterator it = context.iteratePointers("beans/int"); int i = 5; while (it.hasNext()) { NodePointer pointer = (NodePointer) it.next(); pointer.setValue(new Integer(i++)); } it = context.iteratePointers("beans/int"); List actual = new ArrayList(); while (it.hasNext()) { actual.add(((Pointer) it.next()).getValue()); } assertEquals( "Iterating <" + "beans/int" + ">", list(new Integer(5), new Integer(6)), actual); } /** * Test contributed by Kate Dvortsova */ public void testIteratePointerSetValue() { JXPathContext context = JXPathContext.newContext(createContextBean()); assertXPathValue(context, "/beans[1]/name", "Name 1"); assertXPathValue(context, "/beans[2]/name", "Name 2"); // Test setting via context context.setValue("/beans[2]/name", "Name 2 set"); assertXPathValue(context, "/beans[2]/name", "Name 2 set"); // Restore original value context.setValue("/beans[2]/name", "Name 2"); assertXPathValue(context, "/beans[2]/name", "Name 2"); int iterCount = 0; Iterator iter = context.iteratePointers("/beans/name"); while (iter.hasNext()) { iterCount++; Pointer pointer = (Pointer) iter.next(); String s = (String) pointer.getValue(); s = s + "suffix"; pointer.setValue(s); assertEquals("pointer.getValue", s, pointer.getValue()); // fails right here, the value isn't getting set in the bean. assertEquals( "context.getValue", s, context.getValue(pointer.asPath())); } assertEquals("Iteration count", 2, iterCount); assertXPathValue(context, "/beans[1]/name", "Name 1suffix"); assertXPathValue(context, "/beans[2]/name", "Name 2suffix"); } public void testRoot() { assertXPathValueAndPointer(context, "/", context.getContextBean(), "/"); } public void testAxisAncestor() { // ancestor:: assertXPathValue(context, "int/ancestor::root = /", Boolean.TRUE); assertXPathValue( context, "count(beans/name/ancestor-or-self::node())", new Double(5)); assertXPathValue( context, "beans/name/ancestor-or-self::node()[3] = /", Boolean.TRUE); } public void testAxisChild() { assertXPathValue(context, "boolean", Boolean.FALSE); assertXPathPointer(context, "boolean", "/boolean"); assertXPathPointerIterator(context, "boolean", list("/boolean")); // Count elements in a child collection assertXPathValue(context, "count(set)", new Double(3)); // assertXPathValue(context,"boolean/class/name", "java.lang.Boolean"); // Child with namespace - should not find any assertXPathValueIterator(context, "foo:boolean", list()); // Count all children with a wildcard assertXPathValue(context, "count(*)", new Double(21)); // Same, constrained by node type = node() assertXPathValue(context, "count(child::node())", new Double(21)); } public void testAxisChildNestedBean() { // Nested bean assertXPathValue(context, "nestedBean/name", "Name 0"); assertXPathPointer(context, "nestedBean/name", "/nestedBean/name"); assertXPathPointerIterator( context, "nestedBean/name", list("/nestedBean/name")); } public void testAxisChildNestedCollection() { assertXPathValueIterator( context, "integers", list( new Integer(1), new Integer(2), new Integer(3), new Integer(4))); assertXPathPointer(context, "integers", "/integers"); assertXPathPointerIterator( context, "integers", list( "/integers[1]", "/integers[2]", "/integers[3]", "/integers[4]")); } public void testIndexPredicate() { assertXPathValue(context, "integers[2]", new Integer(2)); assertXPathPointer(context, "integers[2]", "/integers[2]"); assertXPathPointerIterator( context, "integers[2]", list("/integers[2]")); assertXPathValue(context, "beans[1]/name", "Name 1"); assertXPathPointer(context, "beans[1]/name", "/beans[1]/name"); assertXPathValueIterator( context, "beans[1]/strings", list("String 1", "String 2", "String 3")); assertXPathValueIterator( context, "beans/strings[2]", list("String 2", "String 2")); // Find the first match assertXPathValue(context, "beans/strings[2]", "String 2"); // Indexing in a set collected from a UnionContext assertXPathValue(context, "(beans/strings[2])[1]", "String 2"); } public void testAxisDescendant() { // descendant:: assertXPathValue(context, "count(descendant::node())", new Double(65)); // Should not find any descendants with name root assertXPathValue(context, "count(descendant::root)", new Double(0)); assertXPathValue(context, "count(descendant::name)", new Double(7)); } public void testAxisDescendantOrSelf() { // descendant-or-self:: assertXPathValueIterator( context, "descendant-or-self::name", set( "Name 1", "Name 2", "Name 3", "Name 6", "Name 0", "Name 5", "Name 4")); // Same - abbreviated syntax assertXPathValueIterator( context, "//name", set( "Name 1", "Name 2", "Name 3", "Name 6", "Name 0", "Name 5", "Name 4")); // See that it actually finds self assertXPathValue( context, "count(descendant-or-self::root)", new Double(1)); // Combine descendant-or-self:: and and self:: assertXPathValue(context, "count(nestedBean//.)", new Double(7)); // Combine descendant-or-self:: and and self::name assertXPathValue(context, "count(//self::beans)", new Double(2)); // Count all nodes in the tree assertXPathValue( context, "count(descendant-or-self::node())", new Double(66)); } public void testAxisFollowing() { // following:: assertXPathValue( context, "count(nestedBean/strings[2]/following::node())", new Double(21)); assertXPathValue( context, "count(nestedBean/strings[2]/following::strings)", new Double(7)); } public void testAxisFollowingSibling() { // following-sibling:: assertXPathValue( context, "count(/nestedBean/following-sibling::node())", new Double(8)); assertXPathValue( context, "count(/nestedBean/following-sibling::object)", new Double(1)); // Combine parent:: and following-sibling:: assertXPathValue( context, "count(/nestedBean/boolean/../following-sibling::node())", new Double(8)); assertXPathValue( context, "count(/nestedBean/boolean/../following-sibling::object)", new Double(1)); // Combine descendant:: and following-sibling:: assertXPathValue( context, "count(/descendant::boolean/following-sibling::node())", new Double(53)); assertXPathValue( context, "count(/descendant::boolean/following-sibling::name)", new Double(7)); } public void testAxisParent() { // parent:: assertXPathValue(context, "count(/beans/..)", new Double(1)); assertXPathValue(context, "count(//..)", new Double(9)); assertXPathValue(context, "count(//../..)", new Double(2)); assertXPathValueIterator( context, "//parent::beans/name", list("Name 1", "Name 2")); } public void testAxisPreceding() { // preceding:: assertXPathValue( context, "count(beans[2]/int/preceding::node())", new Double(8)); assertXPathValue( context, "count(beans[2]/int/preceding::boolean)", new Double(2)); } public void testAxisPrecedingSibling() { // preceding-sibling:: assertXPathValue( context, "count(/boolean/preceding-sibling::node())", new Double(2)); assertXPathValue( context, "count(/nestedBean/int/../preceding-sibling::node())", new Double(12)); assertXPathValue( context, "count(/descendant::int/preceding-sibling::node())", new Double(10)); } public void testAxisSelf() { // self:: assertXPathValue(context, "self::node() = /", Boolean.TRUE); assertXPathValue(context, "self::root = /", Boolean.TRUE); } public void testUnion() { // Union - note corrected document order assertXPathValueIterator( context, "integers | beans[1]/strings", list( "String 1", "String 2", "String 3", new Integer(1), new Integer(2), new Integer(3), new Integer(4))); assertXPathValue( context, "count((integers | beans[1]/strings)[contains(., '1')])", new Double(2)); assertXPathValue( context, "count((integers | beans[1]/strings)[name(.) = 'strings'])", new Double(3)); // Note that the following is different from "integer[2]" - // it is a filter expression assertXPathValue(context, "(integers)[2]", new Integer(2)); } public void testAxisAttribute() { // Attributes are just like children to beans assertXPathValue(context, "count(@*)", new Double(21.0)); // Unknown attribute assertXPathValueLenient(context, "@foo", null); } /** * Testing the pseudo-attribute "name" that java beans * objects appear to have. */ public void testAttributeName() { assertXPathValue(context, "nestedBean[@name = 'int']", new Integer(1)); assertXPathPointer( context, "nestedBean[@name = 'int']", "/nestedBean/int"); } public void testAttributeLang() { assertXPathValue(context, "@xml:lang", "en-US"); assertXPathValue(context, "count(@xml:*)", new Double(1)); assertXPathValue(context, "lang('en')", Boolean.TRUE); assertXPathValue(context, "lang('fr')", Boolean.FALSE); } public void testCoreFunctions() { assertXPathValue(context, "boolean(boolean)", Boolean.TRUE); assertXPathValue(context, "boolean(boolean = false())", Boolean.TRUE); assertXPathValue( context, "boolean(integers[position() < 3])", Boolean.TRUE); assertXPathValue( context, "boolean(integers[position() > 4])", Boolean.FALSE); assertXPathValue(context, "sum(integers)", new Double(10)); assertXPathValueAndPointer( context, "integers[last()]", new Integer(4), "/integers[4]"); assertXPathValueAndPointer( context, "//strings[last()]", "String 3", "/beans[1]/strings[3]"); } public void testBooleanPredicate() { // use child axis // bean[1]/int = 1 // bean[2]/int = 3 assertXPathValue(context, "beans[int > 2]/name", "Name 2"); assertXPathValueIterator( context, "beans[int > 2]/name", list("Name 2")); assertXPathValueIterator( context, "beans[int >= 1]/name", list("Name 1", "Name 2")); assertXPathValueIterator( context, "beans[int < 2]/name", list("Name 1")); assertXPathValueIterator( context, "beans[int <= 3]/name", list("Name 1", "Name 2")); assertXPathValueIterator( context, "beans[1]/strings[string-length() = 8]", list("String 1", "String 2", "String 3")); // use some fancy axis and the child axis in the predicate assertXPathValueIterator( context, "//self::node()[name = 'Name 0']/name", list("Name 0")); // use context-dependent function in the predicate assertXPathValue( context, "beans/strings[name(.)='strings'][2]", "String 2"); // use context-independent function in the predicate assertXPathValueIterator( context, "//self::node()[name(.) = concat('n', 'a', 'm', 'e')]", list( "Name 1", "Name 2", "Name 3", "Name 6", "Name 0", "Name 5", "Name 4")); assertXPathValueIterator( context, "integers[position()<3]", list(new Integer(1), new Integer(2))); context.getVariables().declareVariable( "temp", context.getValue("beans")); assertXPathValueIterator( context, "$temp[int < 2]/int", list(new Integer(1))); } public void testDocumentOrder() { assertDocumentOrder(context, "boolean", "int", -1); assertDocumentOrder(context, "integers[1]", "integers[2]", -1); assertDocumentOrder(context, "integers[1]", "integers[1]", 0); assertDocumentOrder(context, "nestedBean/int", "nestedBean", 1); assertDocumentOrder( context, "nestedBean/int", "nestedBean/strings", -1); assertDocumentOrder(context, "nestedBean/int", "object/int", -1); } public void testSetPropertyValue() { // Simple property assertXPathSetValue(context, "int", new Integer(2)); // Simple property with conversion from string assertXPathSetValue(context, "int", "3", new Integer(3)); // Simple property with conversion from array assertXPathSetValue(context, "int", new int[] { 4 }, new Integer(4)); // Attribute (which is the same as a child for beans assertXPathSetValue(context, "@int", new Integer(10)); } public void testSetCollectionElement() { // Collection element assertXPathSetValue(context, "integers[2]", new Integer(5)); // Collection element with conversion assertXPathSetValue( context, "integers[2]", new int[] { 6 }, new Integer(6)); } public void testSetContextDependentNode() { // Find node without using SimplePathInterpreter assertXPathSetValue( context, "integers[position() = 1]", new Integer(8)); // Find node without using SimplePathInterpreter and set its property assertXPathSetValue( context, "beans[name = 'Name 1']/int", new Integer(9)); } public void testSetNonPrimitiveValue() { // First, let's see if we can set a collection element to null assertXPathSetValue(context, "beans[2]", null); // Now, assign it a whole bean context.setValue("beans[2]", new NestedTestBean("Name 9")); assertEquals( "Modified <" + "beans[2]/name" + ">", "Name 9", context.getValue("beans[2]/name")); } public void testCreatePath() { context.setValue("nestedBean", null); // Calls factory.createObject(..., TestBean, "nestedBean") assertXPathCreatePath( context, "/nestedBean/int", new Integer(1), "/nestedBean/int"); boolean ex = false; try { assertXPathCreatePath( context, "/nestedBean/beans[last() + 1]", new Integer(1), "/nestedBean/beans[last() + 1]"); } catch (Exception e) { ex = true; } assertTrue("Exception thrown on invalid path for creation", ex); } public void testCreatePathAndSetValue() { context.setValue("nestedBean", null); // Calls factory.createObject(..., TestBean, "nestedBean") assertXPathCreatePathAndSetValue( context, "/nestedBean/int", new Integer(2), "/nestedBean/int"); } public void testCreatePathExpandNewCollection() { context.setValue("beans", null); // Calls factory.createObject(..., testBean, "beans", 2), // then factory.createObject(..., testBean, "beans", 2) assertXPathCreatePath( context, "/beans[2]/int", new Integer(1), "/beans[2]/int"); } public void testCreatePathAndSetValueExpandNewCollection() { context.setValue("beans", null); // Calls factory.createObject(..., testBean, "beans", 2), // then factory.createObject(..., testBean, "beans", 2) assertXPathCreatePathAndSetValue( context, "/beans[2]/int", new Integer(2), "/beans[2]/int"); } public void testCreatePathExpandExistingCollection() { // Calls factory.createObject(..., TestBean, "integers", 5) // to expand collection assertXPathCreatePathAndSetValue( context, "/integers[5]", new Integer(3), "/integers[5]"); } public void testCreatePathExpandExistingCollectionAndSetProperty() { // Another, but the collection already exists assertXPathCreatePath( context, "/beans[3]/int", new Integer(1), "/beans[3]/int"); } public void testCreatePathAndSetValueExpandExistingCollection() { // Another, but the collection already exists assertXPathCreatePathAndSetValue( context, "/beans[3]/int", new Integer(2), "/beans[3]/int"); } public void testCreatePathCreateBeanExpandCollection() { context.setValue("nestedBean", null); // Calls factory.createObject(..., TestBean, "nestedBean") // Calls factory.createObject(..., nestedBean, "strings", 2) assertXPathCreatePath( context, "/nestedBean/strings[2]", "String 2", "/nestedBean/strings[2]"); } public void testCreatePathAndSetValueCreateBeanExpandCollection() { context.setValue("nestedBean", null); // Calls factory.createObject(..., TestBean, "nestedBean") // Calls factory.createObject(..., nestedBean, "strings", 2) assertXPathCreatePathAndSetValue( context, "/nestedBean/strings[2]", "Test", "/nestedBean/strings[2]"); } public void testRemovePathPropertyValue() { // Remove property value context.removePath("nestedBean/int"); assertEquals( "Remove property value", new Integer(0), context.getValue("nestedBean/int")); } public void testRemovePathArrayElement() { // Assigns a new array to the property context.removePath("nestedBean/strings[1]"); assertEquals( "Remove array element", "String 2", context.getValue("nestedBean/strings[1]")); } public void testRemoveAllArrayElements() { context.removeAll("nestedBean/strings"); assertXPathValueIterator( context, "nestedBean/strings", list()); } public void testRemoveAllListElements() { context.removeAll("list"); assertXPathValueIterator( context, "list", this instanceof DynaBeanModelTest ? list(null, null, null) : list()); } public void testRemoveAllMapEntries() { context.removeAll("map/*"); assertXPathValue( context, "map", Collections.EMPTY_MAP); } public void testRemovePathBeanValue() { context.removePath("nestedBean"); assertEquals( "Remove collection element", null, context.getValue("nestedBean")); } public void testRelativeContextRelativePath() { JXPathContext relative = context.getRelativeContext(context.getPointer("nestedBean")); assertXPathValueAndPointer(relative, "int", new Integer(1), "/nestedBean/int"); } public void testRelativeContextAbsolutePath() { JXPathContext relative = context.getRelativeContext(context.getPointer("nestedBean")); assertXPathValueAndPointer(relative, "/integers[2]", new Integer(2), "/integers[2]"); } public void testRelativeContextParent() { JXPathContext relative = context.getRelativeContext(context.getPointer("nestedBean")); assertXPathValueAndPointer(relative, "../integers[2]", new Integer(2), "/integers[2]"); } public void testRelativeContextInheritance() { context.setFunctions(new ClassFunctions(TestFunctions.class, "test")); JXPathContext relative = context.getRelativeContext(context.getPointer("nestedBean")); assertXPathValue(relative, "test:countPointers(strings)", new Integer(3)); } }././@LongLink100644 0 0 152 11044114245 10245 Lustar 0 0 commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/beans/BadlyImplementedFactoryTest.javacommons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/beans/BadlyImplementedFactoryTest100644 0 0 4173 11044113517 31125 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.beans; import java.util.HashMap; import java.util.Map; import junit.framework.TestCase; import org.apache.commons.jxpath.AbstractFactory; import org.apache.commons.jxpath.JXPathAbstractFactoryException; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathException; import org.apache.commons.jxpath.Pointer; /** * Badly-implemented Factory test. From JIRA JXPATH-68. * * @author Matt Benson * @version $Revision: 658784 $ $Date: 2008-05-21 12:44:55 -0500 (Wed, 21 May 2008) $ */ public class BadlyImplementedFactoryTest extends TestCase { private JXPathContext context; public void setUp() { context = JXPathContext.newContext(new HashMap()); context.setFactory(new AbstractFactory() { public boolean createObject(JXPathContext context, Pointer pointer, Object parent, String name, int index) { ((Map) parent).put(name, null); return true; } }); } public void testBadFactoryImplementation() { try { context.createPath("foo/bar"); fail("should fail with JXPathException caused by JXPathAbstractFactoryException"); } catch (JXPathException e) { assertTrue(e.getCause() instanceof JXPathAbstractFactoryException); } } } commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/beans/BeanModelTest.java100644 0 0 3336 11044113517 27124 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.beans; import org.apache.commons.jxpath.AbstractFactory; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.TestBean; import org.apache.commons.jxpath.ri.model.BeanModelTestCase; /** * Tests JXPath with JavaBeans * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class BeanModelTest extends BeanModelTestCase { protected Object createContextBean() { return new TestBean(); } protected AbstractFactory getAbstractFactory() { return new TestBeanFactory(); } public void testIndexedProperty() { JXPathContext context = JXPathContext.newContext(null, new TestIndexedPropertyBean()); assertXPathValueAndPointer( context, "indexed[1]", new Integer(0), "/indexed[1]"); } }commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/beans/TestBeanFactory.java100644 0 0 4632 11044113517 27473 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.beans; import org.apache.commons.jxpath.AbstractFactory; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.NestedTestBean; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.TestBean; /** * Test AbstractFactory. * * @author Dmitri Plotnikov * @version $Revision: 480417 $ $Date: 2006-11-28 23:37:40 -0600 (Tue, 28 Nov 2006) $ */ public class TestBeanFactory extends AbstractFactory { /** * Return false if this factory cannot create the requested object. */ public boolean createObject( JXPathContext context, Pointer pointer, Object parent, String name, int index) { if (name.equals("nestedBean")) { ((TestBean) parent).setNestedBean(new NestedTestBean("newName")); return true; } else if (name.equals("beans")) { TestBean bean = (TestBean) parent; if (bean.getBeans() == null || index >= bean.getBeans().length) { bean.setBeans(new NestedTestBean[index + 1]); } bean.getBeans()[index] = new NestedTestBean("newName"); return true; } else if (name.equals("integers")) { // This will implicitly expand the collection ((TestBean) parent).setIntegers(index, 0); return true; } return false; } /** * Create a new object and set it on the specified variable */ public boolean declareVariable(JXPathContext context, String name) { return false; } } ././@LongLink100644 0 0 146 11044114245 10250 Lustar 0 0 commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/beans/TestIndexedPropertyBean.javacommons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/beans/TestIndexedPropertyBean.jav100644 0 0 2314 11044113517 31043 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.beans; /** * Test bean for JUnit tests of indexed property handling. * * @author Dmitri Plotnikov * @version $Revision: 480417 $ $Date: 2006-11-28 23:37:40 -0600 (Tue, 28 Nov 2006) $ */ public class TestIndexedPropertyBean { public int getIndexed(int i) { if (i >= 2) { throw new ArrayIndexOutOfBoundsException(i); } return i; } } ././@LongLink100644 0 0 145 11044114245 10247 Lustar 0 0 commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/container/ContainerModelTest.javacommons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/container/ContainerModelTest.java100644 0 0 12031 11044113517 31103 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.container; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.commons.jxpath.Container; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathTestCase; /** * Tests JXPath with containers as root or value of a variable, property, etc. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class ContainerModelTest extends JXPathTestCase { private class ArrayContainer implements Container { private String[] array = new String[]{"foo", "bar"}; public Object getValue() { return array; } public void setValue(Object value) { throw new UnsupportedOperationException(); } }; public class ListContainer implements Container { private List list; public ListContainer() { list = new ArrayList(); list.add("foo"); list.add("bar"); } public Object getValue() { return list; } public void setValue(Object value) { throw new UnsupportedOperationException(); } } public class Bean { private ListContainer container = new ListContainer(); public ListContainer getContainer() { return container; } } public void testContainerVariableWithCollection() { ArrayContainer container = new ArrayContainer(); String[] array = (String[]) container.getValue(); JXPathContext context = JXPathContext.newContext(null); context.getVariables().declareVariable("list", container); assertXPathValueAndPointer(context, "$list", array, "$list"); assertXPathValueAndPointer(context, "$list[1]", "foo", "$list[1]"); assertXPathValueAndPointer(context, "$list[2]", "bar", "$list[2]"); assertXPathSetValue(context, "$list[1]", "baz"); assertEquals("Checking setValue(index)", "baz", array[0]); } public void testContainerPropertyWithCollection() { Bean bean = new Bean(); List list = (List) bean.getContainer().getValue(); JXPathContext context = JXPathContext.newContext(bean); assertXPathValueAndPointer(context, "/container", list, "/container"); assertXPathValueAndPointer(context, "/container[1]", list.get(0), "/container[1]"); assertXPathValueAndPointer(context, "/container[2]", list.get(1), "/container[2]"); assertXPathSetValue(context, "/container[1]", "baz"); assertEquals("Checking setValue(index)", "baz", list.get(0)); } public void testContainerMapWithCollection() { ListContainer container = new ListContainer(); List list = (List) container.getValue(); Map map = new HashMap(); map.put("container", container); JXPathContext context = JXPathContext.newContext(map); assertXPathValueAndPointer(context, "/container", list, "/.[@name='container']"); assertXPathValueAndPointer(context, "/container[1]", list.get(0), "/.[@name='container'][1]"); assertXPathValueAndPointer(context, "/container[2]", list.get(1), "/.[@name='container'][2]"); assertXPathSetValue(context, "/container[1]", "baz"); assertEquals("Checking setValue(index)", "baz", list.get(0)); } public void testContainerRootWithCollection() { ArrayContainer container = new ArrayContainer(); String[] array = (String[]) container.getValue(); JXPathContext context = JXPathContext.newContext(container); context.getVariables().declareVariable("list", container); assertXPathValueAndPointer(context, "/", array, "/"); assertXPathValueAndPointer(context, "/.[1]", "foo", "/.[1]"); assertXPathValueAndPointer(context, "/.[2]", "bar", "/.[2]"); assertXPathSetValue(context, "/.[1]", "baz"); assertEquals("Checking setValue(index)", "baz", array[0]); } }commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/dom/DOMModelTest.java100644 0 0 10124 11044113517 26376 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dom; import org.apache.commons.jxpath.AbstractFactory; import org.apache.commons.jxpath.ri.model.XMLModelTestCase; import org.apache.commons.jxpath.xml.DocumentContainer; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; /** * Tests JXPath with DOM * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class DOMModelTest extends XMLModelTestCase { protected String getModel() { return DocumentContainer.MODEL_DOM; } protected AbstractFactory getAbstractFactory() { return new TestDOMFactory(); } public void testGetNode() { assertXPathNodeType(context, "/", Document.class); assertXPathNodeType(context, "/vendor/location", Element.class); assertXPathNodeType(context, "//location/@name", Attr.class); assertXPathNodeType(context, "//vendor", Element.class); } protected String getXMLSignature( Object node, boolean elements, boolean attributes, boolean text, boolean pi) { StringBuffer buffer = new StringBuffer(); appendXMLSignature(buffer, node, elements, attributes, text, pi); return buffer.toString(); } private void appendXMLSignature( StringBuffer buffer, Object object, boolean elements, boolean attributes, boolean text, boolean pi) { Node node = (Node) object; int type = node.getNodeType(); switch (type) { case Node.DOCUMENT_NODE : buffer.append(""); appendXMLSignature( buffer, node.getChildNodes(), elements, attributes, text, pi); buffer.append(""); appendXMLSignature( buffer, node.getChildNodes(), elements, attributes, text, pi); buffer.append(""); break; case Node.TEXT_NODE : case Node.CDATA_SECTION_NODE : if (text) { String string = node.getNodeValue(); string = string.replace('\n', '='); buffer.append(string); } break; } } private void appendXMLSignature( StringBuffer buffer, NodeList children, boolean elements, boolean attributes, boolean text, boolean pi) { for (int i = 0; i < children.getLength(); i++) { appendXMLSignature( buffer, children.item(i), elements, attributes, text, pi); } } }commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/dom/TestDOMFactory.java100644 0 0 5502 11044113517 26731 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dom; import org.apache.commons.jxpath.AbstractFactory; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.Pointer; import org.w3c.dom.Document; import org.w3c.dom.Node; /** * Test AbstractFactory. * * @author Dmitri Plotnikov * @version $Revision: 480417 $ $Date: 2006-11-28 23:37:40 -0600 (Tue, 28 Nov 2006) $ */ public class TestDOMFactory extends AbstractFactory { /** * Return false if this factory cannot create the requested object. */ public boolean createObject( JXPathContext context, Pointer pointer, Object parent, String name, int index) { if (name.equals("location") || name.equals("address") || name.equals("street")) { addDOMElement((Node) parent, index, name, null); return true; } if (name.startsWith("price:")) { String namespaceURI = context.getNamespaceURI("price"); addDOMElement((Node) parent, index, name, namespaceURI); return true; } return false; } private void addDOMElement(Node parent, int index, String tag, String namespaceURI) { Node child = parent.getFirstChild(); int count = 0; while (child != null) { if (child.getNodeName().equals(tag)) { count++; } child = child.getNextSibling(); } // Keep inserting new elements until we have index + 1 of them while (count <= index) { Document doc = parent.getOwnerDocument(); Node newElement; if (namespaceURI == null) { newElement = doc.createElement(tag); } else { newElement = doc.createElementNS(namespaceURI, tag); } parent.appendChild(newElement); count++; } } public boolean declareVariable(JXPathContext context, String name) { return false; } } commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/dynabeans/DynaBeanModelTest.java100644 0 0 2733 11044113523 30611 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dynabeans; import org.apache.commons.beanutils.WrapDynaBean; import org.apache.commons.jxpath.AbstractFactory; import org.apache.commons.jxpath.TestBean; import org.apache.commons.jxpath.ri.model.BeanModelTestCase; /** * Test for support of DynaBeans (see BeanUtils) * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class DynaBeanModelTest extends BeanModelTestCase { protected Object createContextBean() { return new WrapDynaBean(new TestBean()); } protected AbstractFactory getAbstractFactory() { return new TestDynaBeanFactory(); } } ././@LongLink100644 0 0 146 11044114245 10250 Lustar 0 0 commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/dynabeans/TestDynaBeanFactory.javacommons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/dynabeans/TestDynaBeanFactory.jav100644 0 0 4644 11044113523 31022 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dynabeans; import org.apache.commons.beanutils.DynaBean; import org.apache.commons.jxpath.AbstractFactory; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.NestedTestBean; import org.apache.commons.jxpath.Pointer; /** * Test AbstractFactory. * * @author Dmitri Plotnikov * @version $Revision: 480417 $ $Date: 2006-11-28 23:37:40 -0600 (Tue, 28 Nov 2006) $ */ public class TestDynaBeanFactory extends AbstractFactory { /** */ public boolean createObject( JXPathContext context, Pointer pointer, Object parent, String name, int index) { if (name.equals("nestedBean")) { ((DynaBean) parent).set( "nestedBean", new NestedTestBean("newName")); return true; } else if (name.equals("beans")) { DynaBean bean = (DynaBean) parent; Object beans[] = (Object[]) bean.get("beans"); if (beans == null || index >= beans.length) { beans = new NestedTestBean[index + 1]; bean.set("beans", beans); } beans[index] = new NestedTestBean("newName"); return true; } else if (name.equals("integers")) { DynaBean bean = (DynaBean) parent; bean.set("integers", index, new Integer(0)); return true; } return false; } /** */ public boolean declareVariable(JXPathContext context, String name) { context.getVariables().declareVariable(name, null); return true; } } ././@LongLink100644 0 0 153 11044114245 10246 Lustar 0 0 commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/dynamic/DynamicPropertiesModelTest.javacommons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/dynamic/DynamicPropertiesModelTes100644 0 0 25714 11044113517 31174 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dynamic; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathTestCase; import org.apache.commons.jxpath.TestBean; /** * TODO more iterator testing with maps * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class DynamicPropertiesModelTest extends JXPathTestCase { private JXPathContext context; public void setUp() { if (context == null) { context = JXPathContext.newContext(new TestBean()); context.setFactory(new TestDynamicPropertyFactory()); } } public void testAxisChild() { assertXPathValue(context, "map/Key1", "Value 1"); assertXPathPointer(context, "map/Key1", "/map[@name='Key1']"); assertXPathValue(context, "map/Key2/name", "Name 6"); assertXPathPointer(context, "map/Key2/name", "/map[@name='Key2']/name"); } public void testAxisDescendant() { assertXPathValue(context, "//Key1", "Value 1"); } /** * Testing the pseudo-attribute "name" that dynamic property * objects appear to have. */ public void testAttributeName() { assertXPathValue(context, "map[@name = 'Key1']", "Value 1"); assertXPathPointer( context, "map[@name = 'Key1']", "/map[@name='Key1']"); assertXPathPointerLenient( context, "map[@name = 'Key"'"'1']", "/map[@name='Key"'"'1']"); assertXPathValue(context, "/.[@name='map']/Key2/name", "Name 6"); assertXPathPointer( context, "/.[@name='map']/Key2/name", "/map[@name='Key2']/name"); // Bean in a map assertXPathValue(context, "/map[@name='Key2'][@name='name']", "Name 6"); assertXPathPointer( context, "/map[@name='Key2'][@name='name']", "/map[@name='Key2']/name"); // Map in a bean in a map assertXPathValue( context, "/.[@name='map'][@name='Key2'][@name='name']", "Name 6"); assertXPathPointer( context, "/.[@name='map'][@name='Key2'][@name='name']", "/map[@name='Key2']/name"); ((Map)context.getValue("map")).put("Key:3", "value3"); assertXPathValueAndPointer( context, "/map[@name='Key:3']", "value3", "/map[@name='Key:3']"); assertXPathValueAndPointer( context, "/map[@name='Key:4:5']", null, "/map[@name='Key:4:5']"); } public void testSetPrimitiveValue() { assertXPathSetValue(context, "map/Key1", new Integer(6)); } public void testSetCollection() { // See if we can assign a whole collection context.setValue( "map/Key1", new Integer[] { new Integer(7), new Integer(8)}); // And then an element in that collection assertXPathSetValue(context, "map/Key1[1]", new Integer(9)); } /** * The key does not exist, but the assignment should succeed anyway, * because you should always be able to store anything in a Map. */ public void testSetNewKey() { // Using a "simple" path assertXPathSetValue(context, "map/Key4", new Integer(7)); // Using a "non-simple" path assertXPathPointerLenient(context, "//map/Key5", "/map/Key5"); assertXPathSetValue(context, "//map/Key5", new Integer(8)); } public void testCreatePath() { TestBean bean = (TestBean) context.getContextBean(); bean.setMap(null); // Calls factory.createObject(..., testBean, "map"), then // sets the value assertXPathCreatePath( context, "/map[@name='TestKey1']", "", "/map[@name='TestKey1']"); } public void testCreatePathAndSetValue() { TestBean bean = (TestBean) context.getContextBean(); bean.setMap(null); // Calls factory.createObject(..., testBean, "map"), then // sets the value assertXPathCreatePathAndSetValue( context, "/map[@name='TestKey1']", "Test", "/map[@name='TestKey1']"); } public void testCreatePathCreateBean() { TestBean bean = (TestBean) context.getContextBean(); bean.setMap(null); // Calls factory.createObject(..., testBean, "map"), then // then factory.createObject(..., map, "TestKey2"), then // sets the value assertXPathCreatePath( context, "/map[@name='TestKey2']/int", new Integer(1), "/map[@name='TestKey2']/int"); } public void testCreatePathAndSetValueCreateBean() { TestBean bean = (TestBean) context.getContextBean(); bean.setMap(null); // Calls factory.createObject(..., testBean, "map"), then // then factory.createObject(..., map, "TestKey2"), then // sets the value assertXPathCreatePathAndSetValue( context, "/map[@name='TestKey2']/int", new Integer(4), "/map[@name='TestKey2']/int"); } public void testCreatePathCollectionElement() { TestBean bean = (TestBean) context.getContextBean(); bean.setMap(null); assertXPathCreatePath( context, "/map/TestKey3[2]", null, "/map[@name='TestKey3'][2]"); // Should be the same as the one before assertXPathCreatePath( context, "/map[@name='TestKey3'][3]", null, "/map[@name='TestKey3'][3]"); } public void testCreatePathAndSetValueCollectionElement() { TestBean bean = (TestBean) context.getContextBean(); bean.setMap(null); assertXPathCreatePathAndSetValue( context, "/map/TestKey3[2]", "Test1", "/map[@name='TestKey3'][2]"); // Should be the same as the one before assertXPathCreatePathAndSetValue( context, "/map[@name='TestKey3'][3]", "Test2", "/map[@name='TestKey3'][3]"); } public void testCreatePathNewCollectionElement() { TestBean bean = (TestBean) context.getContextBean(); bean.setMap(null); // Create an element of a dynamic map element, which is a collection assertXPathCreatePath( context, "/map/TestKey4[1]/int", new Integer(1), "/map[@name='TestKey4'][1]/int"); bean.getMap().remove("TestKey4"); // Should be the same as the one before assertXPathCreatePath( context, "/map/TestKey4[1]/int", new Integer(1), "/map[@name='TestKey4'][1]/int"); } public void testCreatePathAndSetValueNewCollectionElement() { TestBean bean = (TestBean) context.getContextBean(); bean.setMap(null); // Create an element of a dynamic map element, which is a collection assertXPathCreatePathAndSetValue( context, "/map/TestKey4[1]/int", new Integer(2), "/map[@name='TestKey4'][1]/int"); bean.getMap().remove("TestKey4"); // Should be the same as the one before assertXPathCreatePathAndSetValue( context, "/map/TestKey4[1]/int", new Integer(3), "/map[@name='TestKey4'][1]/int"); } public void testRemovePath() { TestBean bean = (TestBean) context.getContextBean(); bean.getMap().put("TestKey1", "test"); // Remove dynamic property context.removePath("map[@name = 'TestKey1']"); assertEquals( "Remove dynamic property value", null, context.getValue("map[@name = 'TestKey1']")); } public void testRemovePathArrayElement() { TestBean bean = (TestBean) context.getContextBean(); bean.getMap().put("TestKey2", new String[] { "temp1", "temp2" }); context.removePath("map[@name = 'TestKey2'][1]"); assertEquals( "Remove dynamic property collection element", "temp2", context.getValue("map[@name = 'TestKey2'][1]")); } public void testCollectionOfMaps() { TestBean bean = (TestBean) context.getContextBean(); List list = new ArrayList(); bean.getMap().put("stuff", list); Map m = new HashMap(); m.put("fruit", "apple"); list.add(m); m = new HashMap(); m.put("berry", "watermelon"); list.add(m); m = new HashMap(); m.put("fruit", "banana"); list.add(m); assertXPathValueIterator( context, "/map/stuff/fruit", list("apple", "banana")); assertXPathValueIterator( context, "/map/stuff[@name='fruit']", list("apple", "banana")); } public void testMapOfMaps() { TestBean bean = (TestBean) context.getContextBean(); Map fruit = new HashMap(); fruit.put("apple", "green"); fruit.put("orange", "red"); Map meat = new HashMap(); meat.put("pork", "pig"); meat.put("beef", "cow"); bean.getMap().put("fruit", fruit); bean.getMap().put("meat", meat); assertXPathPointer( context, "//beef", "/map[@name='meat'][@name='beef']"); assertXPathPointer( context, "map//apple", "/map[@name='fruit'][@name='apple']"); // Ambiguous search - will return nothing assertXPathPointerLenient(context, "map//banana", "null()"); // Unambiguous, even though the particular key is missing assertXPathPointerLenient( context, "//fruit/pear", "/map[@name='fruit']/pear"); } } ././@LongLink100644 0 0 153 11044114245 10246 Lustar 0 0 commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/dynamic/TestDynamicPropertyFactory.javacommons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/dynamic/TestDynamicPropertyFactor100644 0 0 5112 11044113517 31174 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.dynamic; import java.util.HashMap; import java.util.Map; import java.util.Vector; import org.apache.commons.jxpath.AbstractFactory; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.NestedTestBean; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.TestBean; /** * Test AbstractFactory. * * @author Dmitri Plotnikov * @version $Revision: 480417 $ $Date: 2006-11-28 23:37:40 -0600 (Tue, 28 Nov 2006) $ */ public class TestDynamicPropertyFactory extends AbstractFactory { /** * Create a new instance and put it in the collection on the parent object. * Return false if this factory cannot create the requested object. */ public boolean createObject( JXPathContext context, Pointer pointer, Object parent, String name, int index) { if (name.equals("map")) { ((TestBean) parent).setMap(new HashMap()); return true; } else if (name.equals("TestKey1")) { ((Map) parent).put(name, ""); return true; } else if (name.equals("TestKey2")) { ((Map) parent).put(name, new NestedTestBean("newName")); return true; } else if (name.equals("TestKey3")) { Vector v = new Vector(); for (int i = 0; i <= index; i++) { v.add(null); } ((Map) parent).put(name, v); return true; } else if (name.equals("TestKey4")) { ((Map) parent).put(name, new Object[] { new TestBean()}); return true; } return false; } public boolean declareVariable(JXPathContext context, String name) { return false; } } commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/EmbeddedColonMapKeysTest.java100644 0 0 3454 11044113523 30162 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model; import java.util.HashMap; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathTestCase; /** * JXPATH-104 test. * * @author Matt Benson * @version $Revision: 658784 $ $Date: 2008-05-21 12:44:55 -0500 (Wed, 21 May 2008) $ */ public class EmbeddedColonMapKeysTest extends JXPathTestCase { private JXPathContext context; protected void setUp() throws Exception { super.setUp(); HashMap m = new HashMap(); m.put("foo:key", "value"); context = JXPathContext.newContext(m); context.setLenient(true); } public void testSelectNodes() throws Exception { assertXPathValueIterator(context, "/.[@name='foo:key']", list("value")); assertXPathValueIterator(context, "/foo:key", list()); } public void testSelectSingleNode() throws Exception { assertXPathValue(context, "/.[@name='foo:key']", "value"); assertXPathValueLenient(context, "/foo:key", null); } } commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/EmptyCollectionTest.java100644 0 0 4765 11044113523 27324 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model; import java.util.Collections; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathTestCase; /** * Be sure empty lists/sets/arrays work. * @author mbenson * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class EmptyCollectionTest extends JXPathTestCase { public static class HasChild { private Object child; /** * Construct a new EmptyCollectionTest.HasChild instance. */ public HasChild(Object child) { this.child = child; } public Object getChild() { return child; } } public void testEmptyList() { assertXPathPointerIterator(JXPathContext.newContext(Collections.EMPTY_LIST), "/*", Collections.EMPTY_LIST); } public void testEmptyArray() { assertXPathPointerIterator(JXPathContext.newContext(new Object[0]), "/*", list()); } public void testEmptySet() { assertXPathPointerIterator(JXPathContext.newContext(Collections.EMPTY_SET), "/*", Collections.EMPTY_SET); } public void testEmptyChildList() { assertXPathPointerIterator(JXPathContext.newContext(new HasChild(Collections.EMPTY_LIST)), "/child/*", Collections.EMPTY_LIST); } public void testEmptyChildArray() { assertXPathPointerIterator(JXPathContext.newContext(new HasChild(new Object[0])), "/child/*", list()); } public void testEmptyChildSet() { assertXPathPointerIterator(JXPathContext.newContext(new HasChild(Collections.EMPTY_SET)), "/child/*", Collections.EMPTY_SET); } } commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/ExceptionPropertyTestBean.java100644 0 0 2561 11044113523 30473 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model; import org.apache.commons.jxpath.TestBean; /** * * @author Dmitri Plotnikov * @version $Id: ExceptionPropertyTestBean.java 480417 2006-11-29 05:37:40Z bayard $ */ public class ExceptionPropertyTestBean { public String getErrorString() { throw new RuntimeException("errorString"); } public String[] getErrorStringArray() { throw new RuntimeException("errorStringArray"); } public TestBean getErrorBean() { throw new RuntimeException("errorBean"); } } commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/ExternalXMLNamespaceTest.java100644 0 0 5375 11044113523 30170 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathTestCase; import org.apache.commons.jxpath.xml.DocumentContainer; /** * Test externally registered XML namespaces; JXPATH-97. * * @author Matt Benson * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class ExternalXMLNamespaceTest extends JXPathTestCase { protected JXPathContext context; protected DocumentContainer createDocumentContainer(String model) { DocumentContainer result = new DocumentContainer(JXPathTestCase.class .getResource("ExternalNS.xml"), model); // this setting only works for DOM, so no JDOM tests :| result.setNamespaceAware(false); return result; } protected JXPathContext createContext(String model) { JXPathContext context = JXPathContext .newContext(createDocumentContainer(model)); context.registerNamespace("A", "foo"); context.registerNamespace("B", "bar"); return context; } protected void doTest(String xpath, String model, String expected) { assertXPathValue(createContext(model), xpath, expected); } protected void doTestAttribute(String model) { doTest("/ElementA/@A:myAttr", model, "Mytype"); } protected void doTestElement(String model) { doTest("/ElementA/B:ElementB", model, "MY VALUE"); } protected void doTestCreateAndSetAttribute(String model) { assertXPathCreatePathAndSetValue(createContext(model), "/ElementA/@A:newAttr", "newValue", "/ElementA[1]/@A:newAttr"); } public void testAttributeDOM() { doTestAttribute(DocumentContainer.MODEL_DOM); } public void testElementDOM() { doTestElement(DocumentContainer.MODEL_DOM); } public void testCreateAndSetAttributeDOM() { doTestCreateAndSetAttribute(DocumentContainer.MODEL_DOM); } } commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/jdom/JDOMModelTest.java100644 0 0 7730 11044113517 26653 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.jdom; import java.util.List; import org.apache.commons.jxpath.AbstractFactory; import org.apache.commons.jxpath.ri.model.XMLModelTestCase; import org.apache.commons.jxpath.xml.DocumentContainer; import org.jdom.Attribute; import org.jdom.CDATA; import org.jdom.Document; import org.jdom.Element; import org.jdom.Text; /** * Tests JXPath with JDOM * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class JDOMModelTest extends XMLModelTestCase { protected String getModel() { return DocumentContainer.MODEL_JDOM; } public void testGetNode() { assertXPathNodeType(context, "/", Document.class); assertXPathNodeType(context, "/vendor/location", Element.class); assertXPathNodeType(context, "//location/@name", Attribute.class); assertXPathNodeType(context, "//vendor", Element.class); //bugzilla #38586 } public void testID() { // id() is not supported by JDOM } protected AbstractFactory getAbstractFactory() { return new TestJDOMFactory(); } protected String getXMLSignature( Object node, boolean elements, boolean attributes, boolean text, boolean pi) { StringBuffer buffer = new StringBuffer(); appendXMLSignature(buffer, node, elements, attributes, text, pi); return buffer.toString(); } private void appendXMLSignature( StringBuffer buffer, Object object, boolean elements, boolean attributes, boolean text, boolean pi) { if (object instanceof Document) { buffer.append(""); appendXMLSignature( buffer, ((Document) object).getContent(), elements, attributes, text, pi); buffer.append(""); appendXMLSignature( buffer, ((Element) object).getContent(), elements, attributes, text, pi); buffer.append(""); } else if (object instanceof Text || object instanceof CDATA) { if (text) { String string = ((Text) object).getText(); string = string.replace('\n', '='); buffer.append(string); } } } private void appendXMLSignature( StringBuffer buffer, List children, boolean elements, boolean attributes, boolean text, boolean pi) { for (int i = 0; i < children.size(); i++) { appendXMLSignature( buffer, children.get(i), elements, attributes, text, pi); } } }commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/jdom/TestJDOMFactory.java100644 0 0 6230 11044113517 27214 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model.jdom; import java.util.List; import org.apache.commons.jxpath.AbstractFactory; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.Pointer; import org.jdom.Element; /** * Test AbstractFactory. * * @author Dmitri Plotnikov * @version $Revision: 480417 $ $Date: 2006-11-28 23:37:40 -0600 (Tue, 28 Nov 2006) $ */ public class TestJDOMFactory extends AbstractFactory { /** * Create a new instance and put it in the collection on the parent object. * Return false if this factory cannot create the requested object. */ public boolean createObject( JXPathContext context, Pointer pointer, Object parent, String name, int index) { if (name.equals("location") || name.equals("address") || name.equals("street")) { addJDOMElement((Element) parent, index, name, null); return true; } if (name.startsWith("price:")) { String namespaceURI = context.getNamespaceURI("price"); addJDOMElement((Element) parent, index, name, namespaceURI); return true; } return false; } private void addJDOMElement(Element parent, int index, String tag, String namespaceURI) { List children = parent.getContent(); int count = 0; for (int i = 0; i < children.size(); i++) { Object child = children.get(i); if (child instanceof Element && ((Element) child).getQualifiedName().equals(tag)) { count++; } } // Keep inserting new elements until we have index + 1 of them while (count <= index) { // In a real factory we would need to do the right thing with // the namespace prefix. Element newElement; if (namespaceURI != null) { String prefix = tag.substring(0, tag.indexOf(':')); tag = tag.substring(tag.indexOf(':') + 1); newElement = new Element(tag, prefix, namespaceURI); } else { newElement = new Element(tag); } parent.addContent(newElement); count++; } } public boolean declareVariable(JXPathContext context, String name) { return false; } } commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/MixedModelTest.java100644 0 0 37670 11044113523 26262 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Vector; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathTestCase; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.TestBean; import org.apache.commons.jxpath.TestMixedModelBean; import org.apache.commons.jxpath.TestNull; import org.apache.commons.jxpath.Variables; /** * Tests JXPath with mixed model: beans, maps, DOM etc. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class MixedModelTest extends JXPathTestCase { private JXPathContext context; public void setUp() { TestMixedModelBean bean = new TestMixedModelBean(); context = JXPathContext.newContext(bean); context.setFactory(new TestMixedModelFactory()); context.setLocale(Locale.US); Variables vars = context.getVariables(); vars.declareVariable("string", bean.getString()); vars.declareVariable("bean", bean.getBean()); vars.declareVariable("map", bean.getMap()); vars.declareVariable("list", bean.getList()); vars.declareVariable("document", bean.getDocument()); vars.declareVariable("element", bean.getElement()); vars.declareVariable("container", bean.getContainer()); vars.declareVariable("testnull", new TestNull()); int[][] matrix = new int[1][]; matrix[0] = new int[1]; matrix[0][0] = 3; vars.declareVariable("matrix", matrix); } public void testVar() { context.getVariables().declareVariable("foo:bar", "baz"); assertXPathValueAndPointer(context, "$foo:bar", "baz", "$foo:bar"); } public void testVarPrimitive() { assertXPathValueAndPointer(context, "$string", "string", "$string"); } public void testVarBean() { assertXPathValueAndPointer( context, "$bean/int", new Integer(1), "$bean/int"); } public void testVarMap() { assertXPathValueAndPointer( context, "$map/string", "string", "$map[@name='string']"); } public void testVarList() { assertXPathValueAndPointer(context, "$list[1]", "string", "$list[1]"); } public void testVarDocument() { assertXPathValueAndPointer( context, "$document/vendor/location/address/city", "Fruit Market", "$document/vendor[1]/location[2]/address[1]/city[1]"); } public void testVarElement() { assertXPathValueAndPointer( context, "$element/location/address/city", "Fruit Market", "$element/location[2]/address[1]/city[1]"); } public void testVarContainer() { assertXPathValueAndPointer( context, "$container/vendor/location/address/city", "Fruit Market", "$container/vendor[1]/location[2]/address[1]/city[1]"); } // ---------------------------------------------------------------------- public void testBeanPrimitive() { assertXPathValueAndPointer(context, "string", "string", "/string"); } public void testBeanBean() { assertXPathValueAndPointer( context, "bean/int", new Integer(1), "/bean/int"); } public void testBeanMap() { assertXPathValueAndPointer( context, "map/string", "string", "/map[@name='string']"); } public void testBeanList() { assertXPathValueAndPointer(context, "list[1]", "string", "/list[1]"); } public void testBeanDocument() { assertXPathValueAndPointer( context, "document/vendor/location/address/city", "Fruit Market", "/document/vendor[1]/location[2]/address[1]/city[1]"); } public void testBeanElement() { assertXPathValueAndPointer( context, "element/location/address/city", "Fruit Market", "/element/location[2]/address[1]/city[1]"); } public void testBeanContainer() { assertXPathValueAndPointer( context, "container/vendor/location/address/city", "Fruit Market", "/container/vendor[1]/location[2]/address[1]/city[1]"); } // ---------------------------------------------------------------------- public void testMapPrimitive() { assertXPathValueAndPointer( context, "map/string", "string", "/map[@name='string']"); } public void testMapBean() { assertXPathValueAndPointer( context, "map/bean/int", new Integer(1), "/map[@name='bean']/int"); } public void testMapMap() { assertXPathValueAndPointer( context, "map/map/string", "string", "/map[@name='map'][@name='string']"); } public void testMapList() { assertXPathValueAndPointer( context, "map/list[1]", "string", "/map[@name='list'][1]"); } public void testMapDocument() { assertXPathValueAndPointer( context, "map/document/vendor/location/address/city", "Fruit Market", "/map[@name='document']" + "/vendor[1]/location[2]/address[1]/city[1]"); } public void testMapElement() { assertXPathValueAndPointer( context, "map/element/location/address/city", "Fruit Market", "/map[@name='element']/location[2]/address[1]/city[1]"); } public void testMapContainer() { assertXPathValueAndPointer( context, "map/container/vendor/location/address/city", "Fruit Market", "/map[@name='container']" + "/vendor[1]/location[2]/address[1]/city[1]"); } // ---------------------------------------------------------------------- public void testListPrimitive() { assertXPathValueAndPointer(context, "list[1]", "string", "/list[1]"); } public void testListBean() { assertXPathValueAndPointer( context, "list[2]/int", new Integer(1), "/list[2]/int"); } public void testListMap() { assertXPathValueAndPointer( context, "list[3]/string", "string", "/list[3][@name='string']"); } public void testListList() { /** @todo: what is this supposed to do? Should we stick to XPath, * in which case [1] is simply ignored, or Java, in which case * it is supposed to extract the first element from the list? */ // assertXPathValueAndPointer(context, // "list[4][1]", // "string2", // "/list[4][1]"); assertXPathValueAndPointer( context, "list[4]/.[1]", "string2", "/list[4]/.[1]"); } public void testListDocument() { assertXPathValueAndPointer( context, "list[5]/vendor/location/address/city", "Fruit Market", "/list[5]/vendor[1]/location[2]/address[1]/city[1]"); } public void testListElement() { assertXPathValueAndPointer( context, "list[6]/location/address/city", "Fruit Market", "/list[6]/location[2]/address[1]/city[1]"); } public void testListContainer() { assertXPathValueAndPointer( context, "list[7]/vendor/location/address/city", "Fruit Market", "/list[7]/vendor[1]/location[2]/address[1]/city[1]"); } public void testNull() { assertXPathPointerLenient(context, "$null", "$null"); assertXPathPointerLenient(context, "$null[3]", "$null[3]"); assertXPathPointerLenient( context, "$testnull/nothing", "$testnull/nothing"); assertXPathPointerLenient( context, "$testnull/nothing[2]", "$testnull/nothing[2]"); assertXPathPointerLenient(context, "beans[8]/int", "/beans[8]/int"); assertXPathValueIterator( context, "$testnull/nothing[1]", Collections.EMPTY_LIST); JXPathContext ctx = JXPathContext.newContext(new TestNull()); assertXPathValue(ctx, "nothing", null); assertXPathValue(ctx, "child/nothing", null); assertXPathValue(ctx, "array[2]", null); assertXPathValueLenient(ctx, "nothing/something", null); assertXPathValueLenient(ctx, "array[2]/something", null); } public void testRootAsCollection() { assertXPathValue(context, ".[1]/string", "string"); } public void testCreatePath() { context = JXPathContext.newContext(new TestBean()); context.setFactory(new TestMixedModelFactory()); TestBean bean = (TestBean) context.getContextBean(); bean.setMap(null); assertXPathCreatePath( context, "/map[@name='TestKey5']/nestedBean/int", new Integer(1), "/map[@name='TestKey5']/nestedBean/int"); bean.setMap(null); assertXPathCreatePath( context, "/map[@name='TestKey5']/beans[2]/int", new Integer(1), "/map[@name='TestKey5']/beans[2]/int"); } /** * Test JXPath.iterate() with map containing an array */ public void testIterateArray() { Map map = new HashMap(); map.put("foo", new String[] { "a", "b", "c" }); JXPathContext context = JXPathContext.newContext(map); assertXPathValueIterator(context, "foo", list("a", "b", "c")); } public void testIteratePointersArray() { Map map = new HashMap(); map.put("foo", new String[] { "a", "b", "c" }); JXPathContext context = JXPathContext.newContext(map); Iterator it = context.iteratePointers("foo"); List actual = new ArrayList(); while (it.hasNext()) { Pointer ptr = (Pointer) it.next(); actual.add(context.getValue(ptr.asPath())); } assertEquals( "Iterating pointers <" + "foo" + ">", list("a", "b", "c"), actual); } public void testIteratePointersArrayElementWithVariable() { Map map = new HashMap(); map.put("foo", new String[] { "a", "b", "c" }); JXPathContext context = JXPathContext.newContext(map); context.getVariables().declareVariable("x", new Integer(2)); Iterator it = context.iteratePointers("foo[$x]"); List actual = new ArrayList(); while (it.hasNext()) { Pointer ptr = (Pointer) it.next(); actual.add(context.getValue(ptr.asPath())); } assertEquals("Iterating pointers <" + "foo" + ">", list("b"), actual); } public void testIterateVector() { Map map = new HashMap(); Vector vec = new Vector(); vec.add(new HashMap()); vec.add(new HashMap()); map.put("vec", vec); JXPathContext context = JXPathContext.newContext(map); assertXPathPointerIterator( context, "/vec", list("/.[@name='vec'][1]", "/.[@name='vec'][2]")); } public void testErrorProperty() { context.getVariables().declareVariable( "e", new ExceptionPropertyTestBean()); boolean ex = false; try { assertXPathValue(context, "$e/errorString", null); } catch (Throwable t) { ex = true; } assertTrue("Legitimate exception accessing property", ex); assertXPathPointer(context, "$e/errorString", "$e/errorString"); assertXPathPointerLenient( context, "$e/errorStringArray[1]", "$e/errorStringArray[1]"); assertXPathPointerIterator( context, "$e/errorString", list("$e/errorString")); assertXPathPointerIterator( context, "$e//error", Collections.EMPTY_LIST); } public void testMatrix() { assertXPathValueAndPointer( context, "$matrix[1]/.[1]", new Integer(3), "$matrix[1]/.[1]"); context.setValue("$matrix[1]/.[1]", new Integer(2)); assertXPathValueAndPointer( context, "matrix[1]/.[1]", new Integer(3), "/matrix[1]/.[1]"); context.setValue("matrix[1]/.[1]", "2"); assertXPathValue(context, "matrix[1]/.[1]", new Integer(2)); context.getVariables().declareVariable( "wholebean", context.getContextBean()); assertXPathValueAndPointer( context, "$wholebean/matrix[1]/.[1]", new Integer(2), "$wholebean/matrix[1]/.[1]"); boolean ex = false; try { context.setValue("$wholebean/matrix[1]/.[2]", "4"); } catch (Exception e) { ex = true; } assertTrue("Exception setting value of non-existent element", ex); ex = false; try { context.setValue("$wholebean/matrix[2]/.[1]", "4"); } catch (Exception e) { ex = true; } assertTrue("Exception setting value of non-existent element", ex); } public void testCreatePathAndSetValueWithMatrix() { context.setValue("matrix", null); // Calls factory.createObject(..., TestMixedModelBean, "matrix") // Calls factory.createObject(..., nestedBean, "strings", 2) assertXPathCreatePathAndSetValue( context, "/matrix[1]/.[1]", new Integer(4), "/matrix[1]/.[1]"); } /** * Scott Heaberlin's test - collection of collections */ public void testCollectionPointer() { List list = new ArrayList(); Map map = new HashMap(); map.put("KeyOne", "SomeStringOne"); map.put("KeyTwo", "SomeStringTwo"); Map map2 = new HashMap(); map2.put("KeyA", "StringA"); map2.put("KeyB", "StringB"); map.put("KeyThree", map2); list.add(map); List list2 = new ArrayList(); list2.add("foo"); list2.add(map); list2.add(map); list.add(list2); context = JXPathContext.newContext(list); assertEquals("SomeStringOne", context.getValue(".[1]/KeyOne")); assertEquals("StringA", context.getValue(".[1]/KeyThree/KeyA")); assertEquals(new Integer(3), context.getValue("size(.[1]/KeyThree)")); assertEquals(new Double(6.0), context.getValue("count(.[1]/KeyThree/*)")); assertEquals(new Double(3.0), context.getValue("count(.[1]/KeyThree/KeyA)")); } }commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/TestMixedModelFactory.java100644 0 0 5652 11044113523 27565 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model; import java.util.HashMap; import java.util.Map; import org.apache.commons.jxpath.AbstractFactory; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.NestedTestBean; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.TestBean; import org.apache.commons.jxpath.TestMixedModelBean; /** * Test AbstractFactory. * * @author Dmitri Plotnikov * @version $Revision: 480417 $ $Date: 2006-11-28 23:37:40 -0600 (Tue, 28 Nov 2006) $ */ public class TestMixedModelFactory extends AbstractFactory { /** * Create a new instance and put it in the collection on the parent object. * Return false if this factory cannot create the requested object. */ public boolean createObject( JXPathContext context, Pointer pointer, Object parent, String name, int index) { if (name.equals("nestedBean")) { ((TestBean) parent).setNestedBean(new NestedTestBean("newName")); return true; } else if (name.equals("beans")) { TestBean bean = (TestBean) parent; if (bean.getBeans() == null || index >= bean.getBeans().length) { bean.setBeans(new NestedTestBean[index + 1]); } bean.getBeans()[index] = new NestedTestBean("newName"); return true; } else if (name.equals("map")) { ((TestBean) parent).setMap(new HashMap()); return true; } else if (name.equals("TestKey5")) { TestBean tb = new TestBean(); tb.setNestedBean(null); tb.setBeans(null); ((Map) parent).put(name, tb); return true; } else if (name.equals("matrix")) { int[][] matrix = new int[2][]; matrix[0] = new int[1]; // matrix[1] = new int[2]; ((TestMixedModelBean) parent).setMatrix(matrix); return true; } return false; } public boolean declareVariable(JXPathContext context, String name) { return false; } } commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/XMLModelTestCase.java100644 0 0 65334 11044113523 26446 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model; import org.apache.commons.jxpath.AbstractFactory; import org.apache.commons.jxpath.IdentityManager; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathException; import org.apache.commons.jxpath.JXPathTestCase; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.Variables; import org.apache.commons.jxpath.xml.DocumentContainer; /** * Abstract superclass for pure XPath 1.0. Subclasses * apply the same XPaths to contexts using different models: * DOM, JDOM etc. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public abstract class XMLModelTestCase extends JXPathTestCase { protected JXPathContext context; public void setUp() { if (context == null) { DocumentContainer docCtr = createDocumentContainer(); context = createContext(); Variables vars = context.getVariables(); vars.declareVariable("document", docCtr.getValue()); vars.declareVariable("container", docCtr); vars.declareVariable("element", context.getPointer("vendor/location/address/street").getNode()); } } protected abstract String getModel(); protected DocumentContainer createDocumentContainer() { return new DocumentContainer( JXPathTestCase.class.getResource("Vendor.xml"), getModel()); } protected abstract AbstractFactory getAbstractFactory(); protected JXPathContext createContext() { JXPathContext context = JXPathContext.newContext(createDocumentContainer()); context.setFactory(getAbstractFactory()); context.registerNamespace("product", "productNS"); return context; } /** * An XML signature is used to determine if we have the right result * after a modification of XML by JXPath. It is basically a piece * of simplified XML. */ protected abstract String getXMLSignature( Object node, boolean elements, boolean attributes, boolean text, boolean pi); protected void assertXMLSignature( JXPathContext context, String path, String signature, boolean elements, boolean attributes, boolean text, boolean pi) { Object node = context.getPointer(path).getNode(); String sig = getXMLSignature(node, elements, attributes, text, pi); assertEquals("XML Signature mismatch: ", signature, sig); } // ------------------------------------------------ Individual Test Methods public void testDocumentOrder() { assertDocumentOrder( context, "vendor/location", "vendor/location/address/street", -1); assertDocumentOrder( context, "vendor/location[@id = '100']", "vendor/location[@id = '101']", -1); assertDocumentOrder( context, "vendor//price:amount", "vendor/location", 1); } public void testSetValue() { assertXPathSetValue( context, "vendor/location[@id = '100']", "New Text"); assertXMLSignature( context, "vendor/location[@id = '100']", "New Text", false, false, true, false); assertXPathSetValue( context, "vendor/location[@id = '101']", "Replacement Text"); assertXMLSignature( context, "vendor/location[@id = '101']", "Replacement Text", false, false, true, false); } /** * Test JXPathContext.createPath() with various arguments */ public void testCreatePath() { // Create a DOM element assertXPathCreatePath( context, "/vendor[1]/location[3]", "", "/vendor[1]/location[3]"); // Create a DOM element with contents assertXPathCreatePath( context, "/vendor[1]/location[3]/address/street", "", "/vendor[1]/location[3]/address[1]/street[1]"); // Create a DOM attribute assertXPathCreatePath( context, "/vendor[1]/location[2]/@manager", "", "/vendor[1]/location[2]/@manager"); assertXPathCreatePath( context, "/vendor[1]/location[1]/@name", "local", "/vendor[1]/location[1]/@name"); assertXPathCreatePathAndSetValue( context, "/vendor[1]/location[4]/@manager", "", "/vendor[1]/location[4]/@manager"); context.registerNamespace("price", "priceNS"); // Create a DOM element assertXPathCreatePath( context, "/vendor[1]/price:foo/price:bar", "", "/vendor[1]/price:foo[1]/price:bar[1]"); } /** * Test JXPath.createPathAndSetValue() with various arguments */ public void testCreatePathAndSetValue() { // Create a XML element assertXPathCreatePathAndSetValue( context, "vendor/location[3]", "", "/vendor[1]/location[3]"); // Create a DOM element with contents assertXPathCreatePathAndSetValue( context, "vendor/location[3]/address/street", "Lemon Circle", "/vendor[1]/location[3]/address[1]/street[1]"); // Create an attribute assertXPathCreatePathAndSetValue( context, "vendor/location[2]/@manager", "John Doe", "/vendor[1]/location[2]/@manager"); assertXPathCreatePathAndSetValue( context, "vendor/location[1]/@manager", "John Doe", "/vendor[1]/location[1]/@manager"); assertXPathCreatePathAndSetValue( context, "/vendor[1]/location[4]/@manager", "James Dow", "/vendor[1]/location[4]/@manager"); assertXPathCreatePathAndSetValue( context, "vendor/product/product:name/attribute::price:language", "English", "/vendor[1]/product[1]/product:name[1]/@price:language"); context.registerNamespace("price", "priceNS"); // Create a DOM element assertXPathCreatePathAndSetValue( context, "/vendor[1]/price:foo/price:bar", "123.20", "/vendor[1]/price:foo[1]/price:bar[1]"); } /** * Test JXPathContext.removePath() with various arguments */ public void testRemovePath() { // Remove XML nodes context.removePath("vendor/location[@id = '101']//street/text()"); assertEquals( "Remove DOM text", "", context.getValue("vendor/location[@id = '101']//street")); context.removePath("vendor/location[@id = '101']//street"); assertEquals( "Remove DOM element", new Double(0), context.getValue("count(vendor/location[@id = '101']//street)")); context.removePath("vendor/location[@id = '100']/@name"); assertEquals( "Remove DOM attribute", new Double(0), context.getValue("count(vendor/location[@id = '100']/@name)")); } public void testID() { context.setIdentityManager(new IdentityManager() { public Pointer getPointerByID(JXPathContext context, String id) { NodePointer ptr = (NodePointer) context.getPointer("/"); ptr = ptr.getValuePointer(); // Unwrap the container return ptr.getPointerByID(context, id); } }); assertXPathValueAndPointer( context, "id(101)//street", "Tangerine Drive", "id('101')/address[1]/street[1]"); assertXPathPointerLenient( context, "id(105)/address/street", "id(105)/address/street"); } public void testAxisChild() { assertXPathValue( context, "vendor/location/address/street", "Orchard Road"); // child:: - first child does not match, need to search assertXPathValue( context, "vendor/location/address/city", "Fruit Market"); // local-name(qualified) assertXPathValue( context, "local-name(vendor/product/price:amount)", "amount"); // local-name(non-qualified) assertXPathValue(context, "local-name(vendor/location)", "location"); // name (qualified) assertXPathValue( context, "name(vendor/product/price:amount)", "value:amount"); // name (non-qualified) assertXPathValue( context, "name(vendor/location)", "location"); // namespace-uri (qualified) assertXPathValue( context, "namespace-uri(vendor/product/price:amount)", "priceNS"); // default namespace does not affect search assertXPathValue(context, "vendor/product/prix", "934.99"); assertXPathValue(context, "/vendor/contact[@name='jim']", "Jim"); boolean nsv = false; try { context.setLenient(false); context.getValue("/vendor/contact[@name='jane']"); } catch (JXPathException ex) { nsv = true; } assertTrue("No such value: /vendor/contact[@name='jim']", nsv); nsv = false; try { context.setLenient(false); context.getValue("/vendor/contact[@name='jane']/*"); } catch (JXPathException ex) { nsv = true; } assertTrue("No such value: /vendor/contact[@name='jane']/*", nsv); // child:: with a wildcard assertXPathValue( context, "count(vendor/product/price:*)", new Double(2)); // child:: with the default namespace assertXPathValue(context, "count(vendor/product/*)", new Double(4)); // child:: with a qualified name assertXPathValue(context, "vendor/product/price:amount", "45.95"); // null default namespace context.registerNamespace("x", "temp"); assertXPathValue(context, "vendor/x:pos//number", "109"); } public void testAxisChildIndexPredicate() { assertXPathValue( context, "vendor/location[2]/address/street", "Tangerine Drive"); } public void testAxisDescendant() { // descendant:: assertXPathValue(context, "//street", "Orchard Road"); // descendent:: with a namespace and wildcard assertXPathValue(context, "count(//price:*)", new Double(2)); assertXPathValueIterator(context, "vendor//saleEnds", list("never")); assertXPathValueIterator(context, "vendor//promotion", list("")); assertXPathValueIterator( context, "vendor//saleEnds[../@stores = 'all']", list("never")); assertXPathValueIterator( context, "vendor//promotion[../@stores = 'all']", list("")); } // public void testAxisDescendantDocumentOrder() { // Iterator iter = context.iteratePointers("//*"); // while (iter.hasNext()) { // System.err.println(iter.next()); // } // } public void testAxisParent() { // parent:: assertXPathPointer( context, "//street/..", "/vendor[1]/location[1]/address[1]"); // parent:: (note reverse document order) assertXPathPointerIterator( context, "//street/..", list( "/vendor[1]/location[2]/address[1]", "/vendor[1]/location[1]/address[1]")); // parent:: with a namespace and wildcard assertXPathValue( context, "vendor/product/price:sale/saleEnds/parent::price:*" + "/saleEnds", "never"); } public void testAxisFollowingSibling() { // following-sibling:: assertXPathValue( context, "vendor/location[.//employeeCount = 10]/" + "following-sibling::location//street", "Tangerine Drive"); // following-sibling:: produces the correct pointer assertXPathPointer( context, "vendor/location[.//employeeCount = 10]/" + "following-sibling::location//street", "/vendor[1]/location[2]/address[1]/street[1]"); } public void testAxisPrecedingSibling() { // preceding-sibling:: produces the correct pointer assertXPathPointer( context, "//location[2]/preceding-sibling::location//street", "/vendor[1]/location[1]/address[1]/street[1]"); } public void testAxisPreceding() { // preceding:: assertXPathPointer( context, "//location[2]/preceding-sibling::location//street", "/vendor[1]/location[1]/address[1]/street[1]"); assertXPathPointer(context, "//location[2]/preceding::*[1]", "/vendor[1]/location[1]/employeeCount[1]"); assertXPathPointer(context, "//location[2]/preceding::node()[3]", "/vendor[1]/location[1]/employeeCount[1]/text()[1]"); assertXPathPointer(context, "//location[2]/preceding::node()[4]", "/vendor[1]/location[1]/employeeCount[1]"); } public void testAxisAttribute() { // attribute:: assertXPathValue(context, "vendor/location/@id", "100"); // attribute:: produces the correct pointer assertXPathPointer( context, "vendor/location/@id", "/vendor[1]/location[1]/@id"); // iterate over attributes assertXPathValueIterator( context, "vendor/location/@id", list("100", "101")); // Using different prefixes for the same namespace assertXPathValue( context, "vendor/product/price:amount/@price:discount", "10%"); // namespace uri for an attribute assertXPathValue( context, "namespace-uri(vendor/product/price:amount/@price:discount)", "priceNS"); // local name of an attribute assertXPathValue( context, "local-name(vendor/product/price:amount/@price:discount)", "discount"); // name for an attribute assertXPathValue( context, "name(vendor/product/price:amount/@price:discount)", "price:discount"); // attribute:: with the default namespace assertXPathValue( context, "vendor/product/price:amount/@discount", "20%"); // namespace uri of an attribute with the default namespace assertXPathValue( context, "namespace-uri(vendor/product/price:amount/@discount)", ""); // local name of an attribute with the default namespace assertXPathValue( context, "local-name(vendor/product/price:amount/@discount)", "discount"); // name of an attribute with the default namespace assertXPathValue( context, "name(vendor/product/price:amount/@discount)", "discount"); // attribute:: with a namespace and wildcard assertXPathValueIterator( context, "vendor/product/price:amount/@price:*", list("10%")); // attribute:: with a wildcard assertXPathValueIterator( context, "vendor/location[1]/@*", set("100", "", "local")); // attribute:: with default namespace and wildcard assertXPathValueIterator( context, "vendor/product/price:amount/@*", //use a set because DOM returns attrs sorted by name, JDOM by occurrence order: set("10%", "20%")); // attribute::node() assertXPathValueIterator( context, "vendor/product/price:amount/attribute::node()", //use a set because DOM returns attrs sorted by name, JDOM by occurrence order: set("10%", "20%")); // attribute:: select non-ns'd attributes only assertXPathValueIterator( context, "vendor/product/price:amount/@*[namespace-uri() = '']", list("20%")); // Empty attribute assertXPathValue(context, "vendor/location/@manager", ""); // Missing attribute assertXPathValueLenient(context, "vendor/location/@missing", null); // Missing attribute with namespace assertXPathValueLenient(context, "vendor/location/@miss:missing", null); // Using attribute in a predicate assertXPathValue( context, "vendor/location[@id='101']//street", "Tangerine Drive"); assertXPathValueIterator( context, "/vendor/location[1]/@*[name()!= 'manager']", list("100", "local")); } public void testAxisNamespace() { // namespace:: assertXPathValueAndPointer( context, "vendor/product/prix/namespace::price", "priceNS", "/vendor[1]/product[1]/prix[1]/namespace::price"); // namespace::* assertXPathValue( context, "count(vendor/product/namespace::*)", new Double(3)); // name of namespace assertXPathValue( context, "name(vendor/product/prix/namespace::price)", "price"); // local name of namespace assertXPathValue( context, "local-name(vendor/product/prix/namespace::price)", "price"); } public void testAxisAncestor() { // ancestor:: assertXPathValue( context, "vendor/product/price:sale/saleEnds/" + "ancestor::price:sale/saleEnds", "never"); // ancestor:: with a wildcard assertXPathValue( context, "vendor/product/price:sale/saleEnds/ancestor::price:*" + "/saleEnds", "never"); } public void testAxisAncestorOrSelf() { // ancestor-or-self:: assertXPathValue( context, "vendor/product/price:sale/" + "ancestor-or-self::price:sale/saleEnds", "never"); } public void testAxisFollowing() { assertXPathValueIterator( context, "vendor/contact/following::location//street", list("Orchard Road", "Tangerine Drive")); // following:: with a namespace assertXPathValue( context, "//location/following::price:sale/saleEnds", "never"); assertXPathPointer(context, "//location[2]/following::node()[2]", "/vendor[1]/product[1]"); } public void testAxisSelf() { // self:: with a namespace assertXPathValue( context, "//price:sale/self::price:sale/saleEnds", "never"); // self:: with an unmatching name assertXPathValueLenient(context, "//price:sale/self::x/saleEnds", null); } public void testNodeTypeComment() { // comment() assertXPathValue( context, "//product/comment()", "We are not buying this product, ever"); } public void testNodeTypeText() { // text() //Note that this is questionable as the XPath spec tells us "." is short for self::node() and text() is by definition _not_ a node: assertXPathValue( context, "//product/text()[. != '']", "We love this product."); // text() pointer assertXPathPointer( context, "//product/text()", "/vendor[1]/product[1]/text()[1]"); } public void testNodeTypeProcessingInstruction() { // processing-instruction() without an argument assertXPathValue( context, "//product/processing-instruction()", "do not show anybody"); // processing-instruction() with an argument assertXPathValue( context, "//product/processing-instruction('report')", "average only"); // processing-instruction() pointer without an argument assertXPathPointer( context, "//product/processing-instruction('report')", "/vendor[1]/product[1]/processing-instruction('report')[1]"); // processing-instruction name assertXPathValue( context, "name(//product/processing-instruction()[1])", "security"); } public void testLang() { // xml:lang built-in attribute assertXPathValue(context, "//product/prix/@xml:lang", "fr"); // lang() used the built-in xml:lang attribute assertXPathValue(context, "//product/prix[lang('fr')]", "934.99"); // Default language assertXPathValue( context, "//product/price:sale[lang('en')]/saleEnds", "never"); } public void testDocument() { assertXPathValue( context, "$document/vendor/location[1]//street", "Orchard Road"); assertXPathPointer( context, "$document/vendor/location[1]//street", "$document/vendor[1]/location[1]/address[1]/street[1]"); assertXPathValue(context, "$document/vendor//street", "Orchard Road"); } public void testContainer() { assertXPathValue(context, "$container/vendor//street", "Orchard Road"); assertXPathValue(context, "$container//street", "Orchard Road"); assertXPathPointer( context, "$container//street", "$container/vendor[1]/location[1]/address[1]/street[1]"); // Conversion to number assertXPathValue( context, "number(vendor/location/employeeCount)", new Double(10)); } public void testElementInVariable() { assertXPathValue(context, "$element", "Orchard Road"); } public void testTypeConversions() { // Implicit conversion to number assertXPathValue( context, "vendor/location/employeeCount + 1", new Double(11)); // Implicit conversion to boolean assertXPathValue( context, "vendor/location/employeeCount and true()", Boolean.TRUE); } public void testBooleanFunction() { assertXPathValue( context, "boolean(vendor//saleEnds[../@stores = 'all'])", Boolean.TRUE); assertXPathValue( context, "boolean(vendor//promotion[../@stores = 'all'])", Boolean.TRUE); assertXPathValue( context, "boolean(vendor//promotion[../@stores = 'some'])", Boolean.FALSE); } public void testFunctionsLastAndPosition() { assertXPathPointer( context, "vendor//location[last()]", "/vendor[1]/location[2]"); } public void testNamespaceMapping() { context.registerNamespace("rate", "priceNS"); context.registerNamespace("goods", "productNS"); assertEquals("Context node namespace resolution", "priceNS", context.getNamespaceURI("price")); assertEquals("Registered namespace resolution", "priceNS", context.getNamespaceURI("rate")); // child:: with a namespace and wildcard assertXPathValue(context, "count(vendor/product/rate:*)", new Double(2)); assertXPathValue(context, "vendor[1]/product[1]/rate:amount[1]/@rate:discount", "10%"); assertXPathValue(context, "vendor[1]/product[1]/rate:amount[1]/@price:discount", "10%"); assertXPathValue(context, "vendor[1]/product[1]/price:amount[1]/@rate:discount", "10%"); assertXPathValue(context, "vendor[1]/product[1]/price:amount[1]/@price:discount", "10%"); // Preference for externally registered namespace prefix assertXPathValueAndPointer(context, "//product:name", "Box of oranges", "/vendor[1]/product[1]/goods:name[1]"); // Same, but with a child context JXPathContext childCtx = JXPathContext.newContext(context, context.getContextBean()); assertXPathValueAndPointer(childCtx, "//product:name", "Box of oranges", "/vendor[1]/product[1]/goods:name[1]"); // Same, but with a relative context JXPathContext relativeCtx = context.getRelativeContext(context.getPointer("/vendor")); assertXPathValueAndPointer(relativeCtx, "product/product:name", "Box of oranges", "/vendor[1]/product[1]/goods:name[1]"); } public void testUnion() { assertXPathValue(context, "/vendor[1]/contact[1] | /vendor[1]/contact[4]", "John"); assertXPathValue(context, "/vendor[1]/contact[4] | /vendor[1]/contact[1]", "John"); } public void testNodes() { Pointer pointer = context.getPointer("/vendor[1]/contact[1]"); assertFalse(pointer.getNode().equals(pointer.getValue())); } }commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/XMLPreserveSpaceTest.java100644 0 0 6046 11044113523 27334 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathTestCase; import org.apache.commons.jxpath.xml.DocumentContainer; /** * Test for text trimming from JXPATH-83. * * @author Matt Benson * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class XMLPreserveSpaceTest extends JXPathTestCase { protected JXPathContext context; protected DocumentContainer createDocumentContainer(String model) { return new DocumentContainer(JXPathTestCase.class .getResource("XmlPreserveSpace.xml"), model); } protected JXPathContext createContext(String model) { JXPathContext context = JXPathContext .newContext(createDocumentContainer(model)); return context; } protected void doTest(String id, String model, String expectedValue) { JXPathContext context = JXPathContext .newContext(createDocumentContainer(model)); assertEquals(context.getValue("test/text[@id='" + id + "']"), expectedValue); } public void testUnspecifiedDOM() { doTest("unspecified", DocumentContainer.MODEL_DOM, " foo "); } public void testDefaultDOM() { doTest("default", DocumentContainer.MODEL_DOM, "foo"); } public void testPreserveDOM() { doTest("preserve", DocumentContainer.MODEL_DOM, " foo "); } public void testNestedDOM() { doTest("nested", DocumentContainer.MODEL_DOM, " foo ;bar; baz "); } public void testNestedWithCommentsDOM() { doTest("nested-with-comments", DocumentContainer.MODEL_DOM, " foo ;bar; baz "); } public void testUnspecifiedJDOM() { doTest("unspecified", DocumentContainer.MODEL_JDOM, " foo "); } public void testDefaultJDOM() { doTest("default", DocumentContainer.MODEL_JDOM, "foo"); } public void testPreserveJDOM() { doTest("preserve", DocumentContainer.MODEL_JDOM, " foo "); } public void testNestedJDOM() { doTest("nested", DocumentContainer.MODEL_JDOM, " foo ;bar; baz "); } public void testNestedWithCommentsJDOM() { doTest("nested-with-comments", DocumentContainer.MODEL_JDOM, " foo ;bar; baz "); } }commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/model/XMLSpaceTest.java100644 0 0 6012 11044113523 25611 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri.model; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathTestCase; import org.apache.commons.jxpath.xml.DocumentContainer; /** * Test for text trimming from JXPATH-83. * * @author Matt Benson * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class XMLSpaceTest extends JXPathTestCase { protected JXPathContext context; protected DocumentContainer createDocumentContainer(String model) { return new DocumentContainer(JXPathTestCase.class .getResource("XmlSpace.xml"), model); } protected JXPathContext createContext(String model) { JXPathContext context = JXPathContext .newContext(createDocumentContainer(model)); return context; } protected void doTest(String id, String model, String expectedValue) { JXPathContext context = JXPathContext .newContext(createDocumentContainer(model)); assertEquals(context.getValue("test/text[@id='" + id + "']"), expectedValue); } public void testUnspecifiedDOM() { doTest("unspecified", DocumentContainer.MODEL_DOM, "foo"); } public void testDefaultDOM() { doTest("default", DocumentContainer.MODEL_DOM, "foo"); } public void testPreserveDOM() { doTest("preserve", DocumentContainer.MODEL_DOM, " foo "); } public void testNestedDOM() { doTest("nested", DocumentContainer.MODEL_DOM, "foo;bar; baz "); } public void testNestedWithCommentsDOM() { doTest("nested-with-comments", DocumentContainer.MODEL_DOM, "foo;bar; baz "); } public void testUnspecifiedJDOM() { doTest("unspecified", DocumentContainer.MODEL_JDOM, "foo"); } public void testDefaultJDOM() { doTest("default", DocumentContainer.MODEL_JDOM, "foo"); } public void testPreserveJDOM() { doTest("preserve", DocumentContainer.MODEL_JDOM, " foo "); } public void testNestedJDOM() { doTest("nested", DocumentContainer.MODEL_JDOM, "foo;bar; baz "); } public void testNestedWithCommentsJDOM() { doTest("nested-with-comments", DocumentContainer.MODEL_JDOM, "foo;bar; baz "); } }commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/ri/StressTest.java100644 0 0 5450 11044113525 24367 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.ri; import junit.framework.TestCase; import org.apache.commons.jxpath.JXPathContext; /** * Test thread safety. * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class StressTest extends TestCase { private static final int THREAD_COUNT = 50; private static final int THREAD_DURATION = 1000; private static JXPathContext context; private static int count; private static Throwable exception; public void testThreads() throws Throwable { context = JXPathContext.newContext(null, new Double(100)); Thread[] threadArray = new Thread[THREAD_COUNT]; for (int i = 0; i < THREAD_COUNT; i++) { threadArray[i] = new Thread(new StressRunnable()); } for (int i = 0; i < threadArray.length; i++) { threadArray[i].start(); } for (int i = 0; i < threadArray.length; i++) { try { threadArray[i].join(); } catch (InterruptedException e) { assertTrue("Interrupted", false); } } if (exception != null) { throw exception; } assertEquals("Test count", THREAD_COUNT * THREAD_DURATION, count); } private final class StressRunnable implements Runnable { public void run() { for (int j = 0; j < THREAD_DURATION && exception == null; j++) { try { double random = 1 + Math.random(); double sum = ((Double) context.getValue("/ + " + random)) .doubleValue(); assertEquals(100 + random, sum, 0.0001); synchronized (context) { count++; } } catch (Throwable t) { exception = t; } } } } } commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/servlet/JXPathServletContextTest.java100644 0 0 17605 11044113516 30253 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.servlet; import java.util.Iterator; import javax.servlet.ServletContext; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.Variables; import com.mockrunner.mock.web.MockHttpServletRequest; import com.mockrunner.mock.web.MockHttpSession; import com.mockrunner.mock.web.MockPageContext; import com.mockrunner.mock.web.MockServletConfig; import com.mockrunner.mock.web.MockServletContext; import junit.framework.TestCase; /** * @author Emmanuel Bourg * @version $Revision: 652848 $, $Date: 2008-05-02 12:53:50 -0500 (Fri, 02 May 2008) $ */ public class JXPathServletContextTest extends TestCase { private ServletContext getServletContext() { MockServletContext context = new MockServletContext(); context.setAttribute("app", "OK"); return context; } public void testServletContext() { ServletContext context = getServletContext(); JXPathContext appContext = JXPathServletContexts.getApplicationContext(context); assertSame("Cached context not property returned", appContext, JXPathServletContexts.getApplicationContext(context)); assertEquals("Application Context", "OK", appContext.getValue("app")); checkPointerIterator(appContext); // test setting a value in the context appContext.setValue("/foo", "bar"); assertEquals("Context property", "bar", appContext.getValue("/foo")); // test the variables Variables variables = appContext.getVariables(); assertNotNull("$application variable", variables.getVariable("application")); assertNull("$foo variable", variables.getVariable("$foo")); } public void testServletRequest() { ServletContext context = getServletContext(); MockHttpSession session = new MockHttpSession(); session.setupServletContext(context); session.setUpIsNew(true); Integer count = new Integer(10); session.setAttribute("count", count); MockHttpServletRequest request = new MockHttpServletRequest(); request.setSession(session); request.setAttribute("attr", "OK"); request.setupAddParameter("parm", "OK"); request.setupAddParameter("multiparam", new String[] { "value1", "value2" }); request.setupAddParameter("emptyparam", new String[0]); assertSame("Request session", session, request.getSession()); JXPathContext reqContext = JXPathServletContexts.getRequestContext(request, context); assertSame("Cached context not property returned", reqContext, JXPathServletContexts.getRequestContext(request, context)); JXPathContext sessionContext = JXPathServletContexts.getSessionContext(session, context); assertSame("Cached context not property returned", sessionContext, JXPathServletContexts.getSessionContext(session, context)); assertEquals("Request Context Attribute", "OK", reqContext.getValue("attr")); assertEquals("Request Context Parameter", "OK", reqContext.getValue("parm")); assertTrue("Request Context Parameter (Array)", reqContext.getValue("multiparam").getClass().isArray()); assertEquals("Request Context Parameter (Empty)", null, reqContext.getValue("emptyparam")); assertEquals("Session Context Parameter", count, sessionContext.getValue("count")); assertEquals("Application Context via Request Context", "OK", reqContext.getValue("app")); assertEquals("Session Context via Request Context", count, reqContext.getValue("count")); assertEquals("Application Context via Session Context", "OK", sessionContext.getValue("app")); checkPointerIterator(reqContext); checkPointerIterator(sessionContext); // test setting a value in the context reqContext.setValue("/foo1", "bar1"); assertEquals("Context property", "bar1", reqContext.getValue("/foo1")); sessionContext.setValue("/foo2", "bar2"); assertEquals("Context property", "bar2", sessionContext.getValue("/foo2")); } public void testServletRequestWithoutSession() { ServletContext context = getServletContext(); MockHttpServletRequest request = new MockHttpServletRequest(); JXPathContext reqContext = JXPathServletContexts.getRequestContext(request, context); assertEquals("Application Context via Request Context", "OK", reqContext.getValue("app")); } private void checkPointerIterator(JXPathContext context) { Iterator it = context.iteratePointers("/*"); assertTrue("Empty context", it.hasNext()); while (it.hasNext()) { Pointer pointer = (Pointer) it.next(); assertNotNull("null pointer", pointer); assertNotNull("null path", pointer.asPath()); } } public void testPageContext() { MockServletContext servletContext = new MockServletContext(); servletContext.setAttribute("app", "app"); MockServletConfig servletConfig = new MockServletConfig(); servletConfig.setServletContext(servletContext); MockHttpSession session = new MockHttpSession(); session.setupServletContext(servletContext); session.setAttribute("session", "session"); MockHttpServletRequest request = new MockHttpServletRequest(); request.setAttribute("request", "request"); request.setSession(session); MockPageContext pageContext = new MockPageContext(); pageContext.setServletConfig(servletConfig); pageContext.setServletRequest(request); pageContext.setAttribute("page", "page"); assertSame("Request session", session, request.getSession()); JXPathContext context = JXPathServletContexts.getPageContext(pageContext); context.setLenient(true); checkPointerIterator(context); assertEquals("Page Scope", "page", context.getValue("page")); assertEquals("Request Scope", "request", context.getValue("request")); assertEquals("Session Scope", "session", context.getValue("session")); assertEquals("Application Scope", "app", context.getValue("app")); assertEquals("Explicit Page Scope", "page", context.getValue("$page/page")); assertEquals("Explicit Request Scope", "request", context.getValue("$request/request")); assertEquals("Explicit Session Scope", "session", context.getValue("$session/session")); assertEquals("Explicit Application Scope", "app", context.getValue("$application/app")); // iterate through the elements of page context only (two elements expected, 'page' and the context) Iterator it = context.iteratePointers("$page/*"); assertTrue("element not found", it.hasNext()); it.next(); it.next(); assertFalse("too many elements", it.hasNext()); // test setting a value in the context context.setValue("/foo1", "bar1"); assertEquals("Context property", "bar1", context.getValue("/foo1")); context.setValue("$page/foo2", "bar2"); assertEquals("Context property", "bar2", context.getValue("$page/foo2")); } } commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/TestBean.java100644 0 0 10442 11044113525 23354 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import org.apache.commons.jxpath.util.ValueUtils; /** * General purpose test bean for JUnit tests for the "jxpath" component. * * @author Dmitri Plotnikov * @version $Revision: 502244 $ $Date: 2007-02-01 09:39:01 -0600 (Thu, 01 Feb 2007) $ */ public class TestBean { // ------------------------------------------------------------- Properties /** * An array of nested java beans. */ private NestedTestBean[] beans; { beans = new NestedTestBean[2]; beans[0] = new NestedTestBean("Name 1"); beans[1] = new NestedTestBean("Name 2"); beans[1].setInt(3); } public NestedTestBean[] getBeans() { return beans; } public void setBeans(NestedTestBean[] beans) { this.beans = beans; } /** * A boolean property. */ private boolean bool = false; public boolean isBoolean() { return bool; } public void setBoolean(boolean bool) { this.bool = bool; } private int integer = 1; /** * A read-only integer property */ public int getInt() { return integer; } public void setInt(int integer) { this.integer = integer; } /** * A read-only array of integers */ private int[] array = { 1, 2, 3, 4 }; public int[] getIntegers() { return array; } public int getIntegers(int index) { return array[index]; } public void setIntegers(int index, int value) { if (index >= array.length) { array = (int[]) ValueUtils.expandCollection(array, index + 1); } array[index] = value; } /** * A heterogeneous list: String, Integer, NestedTestBean */ private ArrayList list; public List getList() { if (list == null) { list = new ArrayList(); list.add("String 3"); list.add(new Integer(3)); list.add(new NestedTestBean("Name 3")); } return list; } /** * A Map */ private HashMap map; { map = new HashMap(); map.put("Key1", "Value 1"); map.put("Key2", new NestedTestBean("Name 6")); } public Map getMap() { return map; } public void setMap(Map map) { this.map = (HashMap) map; } /** * A nested read-only java bean */ private NestedTestBean nestedBean = new NestedTestBean("Name 0"); public NestedTestBean getNestedBean() { return nestedBean; } public void setNestedBean(NestedTestBean bean) { this.nestedBean = bean; } private NestedTestBean object = new NestedTestBean("Name 5"); /** * Returns a NestedTestBean: testing recognition of generic objects */ public Object getObject() { return object; } /** * Returns an array of ints: testing recognition of generic objects */ public Object getObjects() { return getIntegers(); } /** * A heterogeneous set: String, Integer, NestedTestBean */ private HashSet set; public Set getSet() { if (set == null) { set = new HashSet(); set.add("String 4"); set.add(new Integer(4)); set.add(new NestedTestBean("Name 4")); } return set; } public String toString() { return "ROOT"; } } commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/TestMixedModelBean.java100644 0 0 5707 11044113525 25314 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.commons.jxpath.xml.DocumentContainer; import org.w3c.dom.Document; import org.w3c.dom.Element; /** * Mixed model test bean: Java, collections, map, DOM, Container. * * @author Dmitri Plotnikov * @version $Revision: 480417 $ $Date: 2006-11-28 23:37:40 -0600 (Tue, 28 Nov 2006) $ */ public class TestMixedModelBean { private String string; private TestBean bean; private Container container; private Document document; private Element element; private Map map; private List list; private int[][] matrix; public TestMixedModelBean() { string = "string"; bean = new TestBean(); map = new HashMap(); list = new ArrayList(); container = new DocumentContainer(getClass().getResource("Vendor.xml")); document = (Document) container.getValue(); element = document.getDocumentElement(); map.put("string", string); map.put("bean", bean); map.put("map", map); map.put("list", list); map.put("document", document); map.put("element", element); map.put("container", container); list.add(string); list.add(bean); list.add(map); list.add(new ArrayList(Collections.singletonList("string2"))); list.add(document); list.add(element); list.add(container); matrix = new int[1][]; matrix[0] = new int[1]; matrix[0][0] = 3; } public String getString() { return string; } public TestBean getBean() { return bean; } public Map getMap() { return map; } public List getList() { return list; } public Document getDocument() { return document; } public Element getElement() { return element; } public Container getContainer() { return container; } public int[][] getMatrix() { return matrix; } public void setMatrix(int[][] matrix) { this.matrix = matrix; } } commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/TestNull.java100644 0 0 3016 11044113525 23400 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath; /** * General purpose test bean for JUnit tests for the "jxpath" component. * * @author Dmitri Plotnikov * @version $Revision: 480417 $ $Date: 2006-11-28 23:37:40 -0600 (Tue, 28 Nov 2006) $ */ public class TestNull { private Object nothing = null; public Object getNothing() { return nothing; } public void setNothing(Object something) { this.nothing = something; } /** */ private static String[] array = { "a", null, "b" }; public String[] getArray() { return array; } private TestNull child; public TestNull getChild() { if (child == null) { child = new TestNull(); } return child; } } commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/util/BasicTypeConverterTest.java100644 0 0 12200 11044113525 27231 0ustar 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.jxpath.util; import java.lang.reflect.Array; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Date; import java.util.List; import junit.framework.TestCase; import org.apache.commons.jxpath.NodeSet; import org.apache.commons.jxpath.Pointer; /** * Tests BasicTypeConverter * * @author Dmitri Plotnikov * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $ */ public class BasicTypeConverterTest extends TestCase { public void testPrimitiveToString() { assertConversion(new Integer(1), String.class, "1"); } public void testArrayToList() { assertConversion( new int[] { 1, 2 }, List.class, Arrays.asList(new Object[] { new Integer(1), new Integer(2)})); } public void testArrayToArray() { assertConversion( new int[] { 1, 2 }, String[].class, Arrays.asList(new String[] { "1", "2" })); } public void testListToArray() { assertConversion( Arrays.asList(new Integer[] { new Integer(1), new Integer(2)}), String[].class, Arrays.asList(new String[] { "1", "2" })); assertConversion( Arrays.asList(new String[] { "1", "2" }), int[].class, Arrays.asList(new Integer[] { new Integer(1), new Integer(2)})); } public void testInvalidConversion() { boolean exception = false; try { TypeUtils.convert("'foo'", Date.class); } catch (Throwable ex) { exception = true; } assertTrue("Type conversion exception", exception); } public void assertConversion(Object from, Class toType, Object expected) { boolean can = TypeUtils.canConvert(from, toType); assertTrue("Can convert: " + from.getClass() + " to " + toType, can); Object result = TypeUtils.convert(from, toType); if (result.getClass().isArray()) { ArrayList list = new ArrayList(); for (int j = 0; j < Array.getLength(result); j++) { list.add(Array.get(result, j)); } result = list; } assertEquals( "Convert: " + from.getClass() + " to " + toType, expected, result); } public void testSingletonCollectionToString() { assertConversion(Collections.singleton("Earth"), String.class, "Earth"); } public void testSingletonArrayToString() { assertConversion(new String[] { "Earth" }, String.class, "Earth"); } public void testPointerToString() { assertConversion(new Pointer() { public Object getValue() { return "value"; } public Object getNode() { return null; } public void setValue(Object value) { } public Object getRootNode() { return null; } public String asPath() { return null; } public Object clone() { return null; } public int compareTo(Object o) { return 0; } }, String.class, "value"); } public void testNodeSetToString() { assertConversion(new NodeSet() { public List getNodes() { return null; } public List getPointers() { return null; } public List getValues() { List list = new ArrayList(); list.add("hello"); list.add("goodbye"); return Collections.singletonList(list); } }, String.class, "hello"); } // succeeds in current version public void testNodeSetToInteger() { assertConversion(new NodeSet() { public List getNodes() { return null; } public List getPointers() { return null; } public List getValues() { return Collections.singletonList("9"); } }, Integer.class, new Integer(9)); } public void testBeanUtilsConverter() { assertConversion("12", BigDecimal.class, new BigDecimal(12)); } }commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/Vendor.xml100644 0 0 4223 11044113525 22743 0ustar 0 0 ]> John Jack Jim Jack Black
Orchard Road
10
Text before address.
Tangerine Drive Fruit Market
Text after address.
Box of oranges We love this product. 45.95 934.99 never 109
commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/XmlPreserveSpace.xml100644 0 0 3050 11044113525 24733 0ustar 0 0 ]> foo foo foo foo ; bar ; baz foo ; bar ; baz commons-jxpath-1.3-src/src/test/org/apache/commons/jxpath/XmlSpace.xml100644 0 0 2777 11044113525 23236 0ustar 0 0 ]> foo foo foo foo ; bar ; baz foo ; bar ; baz commons-jxpath-1.3-src/xdocs/building.xml100644 0 0 6176 11044113515 15704 0ustar 0 0 Building Commons Documentation Team

Commons JXPath uses Maven 1, Maven 2 (preferred), or Ant as a build system.

The following Maven 2 commands can be used to build Commons JXPath:

  • mvn clean - clean up
  • mvn test - compile and run the unit tests
  • mvn site - create Commons JXPath documentation
  • mvn package - build the jar
  • mvn install - build the jar and install in local maven repository
  • mvn site assembly:assembly - Create the source and binary distributions

The following Maven 1 commands can be used to build Commons JXPath:

  • maven clean - clean up
  • maven test - compile and run the unit tests
  • maven site - create Commons JXPath documentation
  • maven jar - build the jar
  • maven dist - Create the source and binary distributions

Note:

  • Dependencies are automatically downloaded if not specified explicitly in a build.properties file.

The following Ant commands can be used to build Commons JXPath:

  • ant clean - clean up
  • ant test - compile and run the unit tests
  • ant javadoc - create javadocs
  • ant jar - build the jar
  • ant dist - Create the source and binary distributions
commons-jxpath-1.3-src/xdocs/contributors.xml100644 0 0 3575 11044113515 16644 0ustar 0 0 Contributors Commons Documentation Team Dmitri Plotnikov $Id: contributors.xml 560804 2007-07-29 20:14:22Z bayard $

The original code of JXPath was developed by Dmitri Plotnikov of PLOTNIX, Inc and contributed to Jakarta.

After the original contribution, the following volunteers have contributed code, documentation, testing and support to JXPath.

  • Matt Benson
  • Craig R. McClanahan
  • Dmitri Plotnikov

Special thanks to James Strachan, whose help in bringing JXPath to Apache cannot be overestimated.

commons-jxpath-1.3-src/xdocs/cvs-usage.xml100644 0 0 3557 11044113515 16004 0ustar 0 0 Source repository Commons Documentation Team

Apache Commons JXPath is hosted on the Apache subversion repository.

The project URL is:
http://svn.apache.org/repos/asf/commons/proper/jxpath/trunk

The best way to view the repository is via the subversion viewer.

The alternative is to use the native subversion display.

For more information on subversion and creating patches see the Apache Contributors Guide.

commons-jxpath-1.3-src/xdocs/download_jxpath.xml100644 0 0 16474 11044113515 17316 0ustar 0 0 Download Commons JXPath Commons Documentation Team

We recommend you use a mirror to download our release builds, but you must verify the integrity of the downloaded files using signatures downloaded from our main distribution directories. Recent releases (48 hours) may not yet be available from the mirrors.

You are currently using [preferred]. If you encounter a problem with this mirror, please select another mirror. If all mirrors are failing, there are backup mirrors (at the end of the mirrors list) that should be available.

[if-any logo][end]

Other mirrors:

The KEYS link links to the code signing keys used to sign the product. The PGP link downloads the OpenPGP compatible signature from our main site. The MD5 link downloads the checksum from the main site.

For more information concerning Commons JXPath, see the Commons JXPath web site.

commons-jxpath-1.3-src/xdocs/images/jakarta-logo.gif100644 0 0 17506 11044113511 17707 0ustar 0 0 GIF89a^dæÿÿÿÿ!!!111999BBBcccsss{{{ŒŒŒÞÞÞïï籠„Þ„„Îï÷JB„”Öÿï!çÎÆµZ9÷RÿB÷k1ÞBÎ{Rç„RÞk1ÎRÖœ{ï{9çµ”ÿsÿc÷­{¥B½{JÎkÞcœ”Œ÷çÖskc÷¥RÎÆ½¥Zν¥ÖÆ­­”kcZJïÖ¥­{Ö­Bïµ)ç΄¥„sZ÷Ö)έέµœÞ½çÖcÿç½½µ{{s„„{„„sBcÖŒµÿ9ÿ9­c)ÎB!Z9ŒkÿkÞœÿ”)Æs­”ÞcŒJkcŒµÿ”½ÎŒÞ{”ÖÿÖ掠”Œÿï{kÖ1½”{ÞµµŒÿµœc΄ï{½ç„ÿŒµZçJ”ï!„{9”9ÞRÿR¥Rk­1Î!{÷1ïÿ­Ö,^d@ÿ€‚ƒ„…†… ‡‹ŒŽ‘’“”•–—˜™š›œ— ‰C¤CBŸ„‰BDB33*BE *||s|xwu·x}&##-"¡84©ÐÑÒÓÔÕÖ×Пڡ‰´ B¤â¤DQIHJHLRQSRTT^V_Wa`cùakinþmoÎøs3çMƒÀö< ð@‚„ *˜à B„l3jÜȱ££o.T$`Á† C`$P €Í˜3bòyy'ÅŠvMÎÇÓˆ‘#H– I²d $MØM‰"Þ-[¶xÁ7MÌ|hÞø«#G«?:}îìÙC¡ì„9tæ™°!‰ÿL@Ð@× xóêÝ«é"n `HáŸ>xøÔáµXë4ùÆ\ÍwÆË—/` n¹â%ª•&9ŸðÝó§%GÔ!š´iN&준Žo³å/‘Å\É'ÆJdÉhÞâó O=„e0ÑÀs/òN½zµmÜuS nMLÈ@A|Ùâ†äÙs°OZ7wÚ¸yó>¾?5tüÍq“&~iŒ‘Æ=c€áÅ”‰Ûbàs™=‘}áÅTHÅ[L‘EWpaE^xA‡|õÁÿCH°PD˜`@!ƒ €ÐÂŽ¼×o&ÛŠdå´,PÀÃAæp†4X%2a@P¸°+H¯&\ DÓ©?áè ŠQ”œH V°B<® …ìQ¦3`øB¼`:7¨Á JÃÔ †­À§~86 ?P}h4°¿Üïˆ~ËÎ’D0‚˜`9ã©€øÚÞƒØg>oèÏcú#†0Œ õðB>®@Í„á2V®iá p,WDZ“Ÿ$! FH‚:–€Ž›À£&M€‡g´ ½Ë`Æ /èÁ|àƒÉ( Bv@$ZÒT©(’7åË)@ÿÊBÞr d@&( *)0@¤!ÁðC Ó‡<øá‹ù^Ú0=„kàî0:Ì¡¹Ãúc†60³Èä¥Vú¡Èèã7ò$Pƒå F6ÊÁzàEú Ú¸¤:y—IU Ü€g‘4©oÔ³õ´ç X¢yúóŸ˜2â:Z©}©JhùYAI©Ž 2„B÷PÆE4e -D¿–ö³Ná åæ$×0Œò$hiHº+“6g]„ FJš°MŽU8€ в‡É ’û¨£„ÖÑI¥êa£ ZLíwÑ»!”a-—I“RŠ-ÊeèÿZ\Jˆc5,«¤ÙªS—ªQF½lŽkÙ ªÔ?¼T,å Û`êVULu4ÚRÀ]IñÑ"kwxDR 1ØM(à§8,!t ‰ÀV¢°‡r,^0¶R:#K›­01X€³ÅVŒ8¹@d]Em±¡‚ÀT8X+wÁvµýlg ‚Ú&ඃ(-mm[ѱ·ÄUE«°Û¹ámÇr×Ú¢Ý?¸öj…pÁ‰ ÙËB"žPáªêÝòš×# `_U@‹F, O. fÐ ðZÀ$xAÂ#ÙiÀv+ðyLàIdR‰0 )Ø› @ÿ*Âÿ,‡]ª! kÈ¢~V׺6ñay†rÔw‚Ü@Gà-°ŠÏ;$n¸`ð:éN 0–8á)RШ—BÞ(P -\4o±‡îAäó¦;¬‰ÁE\PЂÜ€p†”÷¬7©àÏC˜Añ]„•(  ¬Ð”°%\pRvô2lŽÀ&,T˜Bg¾°…2_Æ@¼ñ œ‚iÅ4±2s¸eY*àõmà$øÁ ÌWb€ Å|ÎuFóçÂ!½,aCÞ 2àÃQi †>ÿ#0¡‚>Êj]”¡@O!LöTN™5¨Á™Å|C÷d(úÂy8¦ZpXNÄó[A{uMoOü“ ¸@YÜó¦ýøc üx èRX3r \ÀB<–²”'ìµ4GÈcQöÈ„$²)€ŒM¬°CzÚv>Ò †¤w&|¼‚ÌÔ…‰"à‘@ëMsG(‘%"  ÌS 0D|{ÀøÞ0MþÀ0@ÒÇè:³¾#›ÉB&HA´Z—G8‚µI'!6®¹ø¥áAB/FÃj( ši~„›F= gv4óšï™HKl0Z«g!|º›æPÅÿï!S—† dk¢!éW"5] \à´‡ÀÐ!,„P Y˜ âhu á >Ñ£:@3p~S’AðA7Ã)NØ8È”ÝuÝâP$É8 @0p€Ã0A[N  àðyÀCÐ}Åà!1u@Ì/åð7´!íXq¦_ºI@/1öÂpÆõébHú Ä…xÓ‘=x| ¸H:@@:P[9Àñ´{ (Oô´OJbÐ àPâ'@|Ä` éc³CÑ|àfÃv·t½@„§w°¸ÔaLïñsІ± AôÿKÁi`5à5"k9@{ìc‚b9…²€JèN‡ð ½wo¾ç€RèIRø{RxSR3“èV¨øW@–xPy8ÒøŠ“2Wcõÿâ+ã@5ÄøT¥ÂŒäàŒ*ÃŽ¤ ZtÅVŸ˜‡eRŘ+ÒxÔ1¥ +†àªÈUÜXWˆŠeáÆ0$°¹£¤hºkòä?3šI–y°À+±v`EinãS‘a ¦È g9š¦ˆjsã¢D˜(5æb,0Ep5¦eP¢¤Öfjgªd) sƒaÀ!Pgš¨¬ ½ç`8ù-BÐ[°9S[ pVp—q ÝV:‘qCãcÐ&íÖ°@# º×ªÒ‡F–™",`9NLpqM `ÿ«2/ñmnp('¬Vg¸ð¯cª àd«:­Ò:OIN:?Q|4±‘Ò³«QWa:hZdr.çK‡·0%p>pkÑJ¯hª Èó À*ÖEî¢ù:©1ë÷{ dH]”Ý£*ÇK«s°|Å |€-Ð P±+¢„,¶9,ð À¦TÐ7¦<¦¯yÔu_‡q5Áðm·«ú0ÛrMx½ð qѬ&àJ˧sP2@ð'D¯­?Koïee!1UŠ9DÐ ,QâïðeGq¢GB¡AײñÿAZÀqçgï—dð²iðЄnǤ‡a¶n‘(qö­&ª&V¦‡:·S…'ae PežÄó±2!dí =MpGMK>a]·G|Má5‘y˜=&:ý¡1¡EÁ!kbr¼dƒ«V¶baà€!-ºª«;Ø û£´Ð»m ‚b¤²)ä!I¸9U·(ѶGèÐh'' r™Á«*$F#·Kê·~dç:ÿ±s@x¬³&Ê笃ñ&Ð-6¯ãK¾ó„„¾×à·Ðòám‹ gpFâ Ôt=økÿu\׿EÑA²¡qÖÓqaÐBŒ\@yd výaLÂqÂ^z0z L¾‹zo 0âÓ:æFùAl”t-!\`[À:&S@èWz>Á¿’ÖŒQдÁ´F›–=’{Àn ©=ˆ°Ð‹C²SCä·1`¤S¬8ét`¾'6ÀÅ"æ° ½@YÔhÀƒÚ3:WyGFWÇJðTçÆ¦‡«qGüºrL¼Mc;a0ájšÑ«ãVLw@èŠ `› t¸CEÔÈ{ƒwŸdk+¦ÊwJ ïÁÉçê}Ó”i š:ÿpšÇqV€¼a B 4ÎY ÊWztdGO0²FÑ¿°A•æɆ+dBg`ºñ3ÔM‹I㔲ÌÌl47‡$4à>€& s&@|pØ—®Atÿ0Mm`M’1®ægM•§»ñVàEõ@HS0O G«ÌÎâ`G§P °ai v5q5µG{ÛI>`Ê,¾íäÌ¿g±‡ÃÀ½çÁ®×Ç‚æÌÿpagàÖß§EÖÔÇÄ«W€& ôF—$œGBuŒ¿êìpW ;1,Bß#90„áN´ç;°¹gÔG½-¶$. ÿ!àD(@ÅðÐ|ÆA8h}›ÜK¹¤ƒÈDƒÿö=þÐf€ _r°Ü^ÀÑ #Ö%Tp”gvë7›ýÇ,¢¾‰"*-Â"ŠDN6@Ø…ÍœÐHâ‚P|¨:Ë ¨ý@6¸&@èv‚Æxba}F†®ÆT@YÍÀ`\ÁÔ3>¬òç2$â· 4:fP#¯÷H’ä×7²Hýç":0ÜÄ]ÜÖáO›T…h.ÐÜpXlªP m! Ñ|è¶Å»€Þ'z xàoÐÃjLUûÑÍÔ¼kE)85„ts@N|}ÿ#öI±—6ã4Ð?>+ན)mˆOZø{'" ŽJ9˜}²@$øµ'Xd×}Â"ævCTò²bcqVíkpäÉýg À€¤wØ@ 0| ÐÀ À Àv  `d.vÀ¶s¤Hr;,àTH…KÂ…=Nçö3sCrçP˜çz¾ê«î{ýäOpHê=€Ÿ@â„¿%Dä¾þë\লiw_HĉpìúNÏð(rè8 ð Ð Õ0GÙi 岡Ø@ÿíÖÞ8ÌΊ ìœ°ÀrP©äŽ07űSðÎðȉ2Ðð­‰9HU’„ `5æ/ Yœ@ñŸ)TY¢!/^ @òÀH’éñ!9Ðòºñu§ó¾’,st˜Šð9)ŽÈŠ'E^Œ ˆÜÕ)Ô‰P¤ØYM?)»Õ‰¥5±º*ƒ0õ‹¢òùQ)©.VORIE¤5»˜Œ‚R¦HõD•ŠsŒÐ®,¡Âí*¨•’B¿ô?É^…p’ )·ˆËˆ6€_ÿ¢' /šð•iøíÂbˆOGŠ/^E9G‰PxÏZ¬ 2æ9 À9DrÒØ‰®÷|_“hùñ"9Ñ ÚxïäNB™"Žˆ26ƒ7Ð2ú‚€ú†°ú³èúYïCŸïÀO“7Ó¥·‰ß8ø9Ž¿?¸X“…4Ò?)ÏúË?I-¿üs½8éýÉTD¿0-*Ø‚e~¸85žVÕüPE L ûCRª ƒBB„ˆˆ‹ ‘’‚„†ˆŠ„••‹’”’„•„ ‘£˜B±²³.©ƒ§¡­º½¾¿ÀÁ½Ÿ¼–‹„ Âÿ¥ƒˆ¯ƒ«“„‡›ƒ¬„.Ôƒ*»Ø‘ÛŒäÑ¡Æ×ƒÙšÈ¾ÄòÞ•—ƒµ.ƭʃ̾îýy·®ž³ƒÒ«VÌ`#‘ -+@q™®s‹5C4c‘!!2æk÷GÚ±eÍ:Â)2]ÉP[ªô1䢑.|YÉß  XtÀ“C1ÿ (1À³E$0ðjÜÓŒøjÝlž¨£'¹EZ4cºÜ2‹6’@B3îÍpiÑZ¼.ÝPj±þÁvQ_¾;­éb‡ˆ¬à?gª[öS[ ™»va® C‹Mº´éÓ¨µ2Nͺµë×°cËžýu2ÿíÛ¯àæH°ÑŒwŠþÒ½{6ñâ´õ9¹óÒèŠImÀª¤ê £oÕþ|]÷ëv¯°äp¢¦‹7UÒ€\’‚v’Ÿ^Ÿ!ð0`@’‹fø‰Ò+•ü—H~ +ì hßñõ·€u“$pžSZâà|3,°@\Jr@  £€Ð,%y,wÜéçÉ.À€Ô‰3꣒((Ö˜CÁ˜ãX@Š•V‘BÊØÈHÖ7dŒP Cà”TÆØâ•ÛÑ 3n©Üe“Ò^$ïI¢‚ˆœé]#Ü'df8 P‹ IzÙ%"r@§{ùå¹'+bn€ŸÜPÔ}UÚHc€‡½•‰H~(^Œ þ‰å¥ÎY Øqcqê$¦ò€ê¢¨¤Òæi/mv’j|@a©•œ «6©ä9ë­¸æªë®¼öêë¯À’;klˆ›b#cú,{ÕE„¦Ø¦mB-¯ˆ@æ®'@@*ìª,¢Ù‚k$—‘| @¸ß@Ëh9æfb$dÞŠdpˆšˆî!†"ªh°“1Âî±l0©¥,#¬ ¿ú!±B|ðÄãØp(Úz’q- ¤‡kXæêVlòÉ(§¬òÊ,·ìòË0Ç,ó!;E•W† a©Õv[n1jàpÃw\C7[оWÜ‚b!$–¡y'r€X`³u×- Þ7Ð@6ºUxáÐÔíw]Ì ÝÏHàâ‹`w£s ìX³ y]8;àcÏPfxe–ù ·€†T6°€5’ù³›Aæ„w…snyh¢3Ú9æ‰pàšÿÀ€—n:€ÿ8¢¦Á]h†F÷é—b„ €º×®³›¡¥ˆØbxXÜÐöÚižèh…²&Xéܶ,¸ëN¨4Æ[ïÃû%!©Á¥Új‡"Ç»d‰çþÇð¢;÷"¾Ò\f4€sвþG¡“5g!•K7áÖçf\ö;\Åçæ€Ú~Ý¡ÐP@ÜÀ]wq(i÷‡FÈaÒMG÷~©ï÷÷Ï»÷>ó¸Oh\ʘA`ÉBÿÌ:>\Ô%R}!"fwÑ“~@õö·?¡Ú9rã €õ?¡Õo!”ÈèÀe€Ì€ x[ñTG,•­¯ïWݰÿ¾\Ɔøø÷=v®xãKšBP3Ü%o!YÖjöêå\€^†ç²plÄkáD‚º¹aK‡ÿxœ!n»p•Ë]EŒ!Ch¨¼'Љ)äâçVÅ!º°fës Eæ×3Õõk‰â’âBö7º)†‘!9{£æø²;Ê1!ë«¡ß–ˆ.2±w5œc»xH–}Ñ„ ya¸ö®¼5@’“œdü"2‘qîŒhäõvD0þƒ‡âê_'ÿ‘·éÝPh73%*J"‚‹´b¸¤§è‰eë‹$%)Y7èÝò!BCd1©¥H™™€á @ SWD> ñ¯ƒeÇÎGÊPÿRS•†Œã—¨MGFD‘´d$Ý2™¡¬vÍŒˆ)†D=SžÇÄc!ã©ÌK“øâèþçDH6€ØÛ\7ÑeÊÓÔ“ç„–Fø@¡§(A-¹ÄY´!Á@ÆgOo"$T»› º YëD;8O˜â ™ÜÄ'5÷¯‡<z;#–)£ØÉ6.—á:€Åúe Jó„–Ù)QâSp!5Šâ¬' ^ #ÄÄÆÃ»b+ÄÉ3’,“ /ÅÎ….Ù ÝXÈo-pNk™#ûWWE+Þ“‡üäy&¹!‚c•]x-ÇæJÊ¥ší?: e0‡YÌc&s™Í|f4#2 ;commons-jxpath-1.3-src/xdocs/images/logo-for-anakia.jpg100644 0 0 15554 11044113511 20316 0ustar 0 0 ÿØÿàJFIF––ÿÛC     ÿÛC  ÿÀpú"ÿÄ ÿÄ9!1"AQ2#BaR‘$bq‚CDS¡ÑðÿÄÿÄ.1!AQaq±Á¡Ñáð‘"24ÿÚ ?¿Ô¥)JV½Î9ž+§ÜW'É9¦; |&FU×|­ð± $ÌÄ(³äæ²c¼Á!FLØiZ×çΣñ _'À{ËÈÆÍN²#+²:°Ù ¬<¶ ²îŒ¥Iq†ˆ¥)X™ŠR”ˆ¥)HŠR”ˆ¥)HŠR”ˆ¥)HŠR”ˆ¥)HŠÂò¾[…àø+¬ç+¿‹µÝÕ›[ Af$Ÿ€ ¬ÕS¿Vá9VúQÄr_¬þ}wêÑn;b”Kr‘ÕCª†úÙÆ¾ S¦¨]`Ry}¤ú‹M5–ËuŒÉZfq¶y,\ësc{\[ÌŸ¶HÝC+ìA»U¯HŠ±Æ€*ªàYk ÍÄE‰ÝN{¥·JR±JR‘¥)^zñÉ]ËÔ¾=–fklÜC,’O*»~vDQüEzT#×®DËÏ8¶?ÙE¾!§‡›Ü™—´¯ÈÚØ?~ãø®§Ã?és›ñùÏ”’ý'òùaèõÄSÀ¶W— ÉU•Ë÷# ;”ëà©d0yA|vö* tZ{›n•ñ¸eŠX;Rr½ã]ê×0`?7ß[ùøÑ6_§Îαߊ—Vs¨*Ó PžH”ªuë3¬œ§‰åð¼W‹Iw„·h“#.N 9'pìHÃCµt¼–QàÝ1t¬C©Ý7ÇäòŽjЛ,™Ð^ùÐæZ²¶€ |V_KbP.;åu(÷†âLu ucÔÿ éFJ ]ßê3¹Fcú‹|kÆæÔ»÷IaÚÅX•_;íóÚ5Óë¯Z.0ñpžž-ÅïQóÉca†ánì¦bí¥}lý>´¢±xM\3Žô¶çˆälí/ò×Ж»Ì=º¼ÉrWAâfUB~•ñ½ùfߺª­{ö;YæË,rRÆçÛÇÒN‘v¹d€<Ô¹±ùåSú5“éÏ/°ÀEyir}£q™X·gk+ØÝÄQ ïä w)Ò^iÃ,]ú?Ï3†Þ9բċֵúIò{ìnw䂪'äø;-Ñé‚¡[1žÞ¿i®­^ –â¯8ìýç=¥yákÖP½:»KžAG)‹³íÌw˜äžÝ“Îû®#]®·¿5¡½Rã½0w×Ë-âw˜{f*¢æÒñnûI:%¢£çÇqü Ðß¼ ¦w¹uÔ“‡Êžñ-í+„ä8ÎGŒµÉá/a¾°»ŒIÑ6ÕÔýÇÿŸjÉü×8‚ ¼óJR±3¥)ë?¨!Ó^Iâ¼c'*åYGWýrÂBĪýaOÖÌ†Ž‚’Ú»š½äû°ÝPN›È½NõmÈ9L-Æ3su{ÈÌË,QÓÀU¼|í‘W sÝòv÷|š»WRQÀƒ|dùý¤ZkZî';gÊoŠÁ†ÔìUNê2įV\s ÌàøÕÉ]BÀ§·qÜ$N¾®âö{ó­¯?6›þ媱ûÕWéš¿$õÖN[ oidã 6¹$VDfVßoþÓ¸Ÿæ/Çq¥ÿïØ=yLê?È¢vŸNrcyeg'gÉ­÷Œ¶Xù5£ÇtŠ?&¤;ý«H×ûTRÉÙ¥)HŠR”ˆ¥)HŠ«³×)—ãöØ›[Œ=–*Óq—»’ø!šVŠh#Há,¥‘‰›åuݾÒ@:kOT{×n/+Èø¬–†Kë;|eÔÍm»1µUxÄ“;@S܃zvù'~:^-JÈuÇv™n‘ËW¦<^tF@¶†Ìr2þ¥I«ÓøBÆ¿ØTÒ{hìúeÅ"C¼zIí Œ½ÅÉs&ÏÇynþß…ïíOüocüµ6£9ñÚ}egå.{¤Õ=Mðé¹H³qcq™Œš ›hæ‰ÚEíýÍBH±Qä1¥H:ª ÑN¬ÉÒ¬åôóÅ5Î.þ˘aíî÷f7×Á,ºØðäù õjD!SðkÏnµË…êGXn¸65gˆ±²y 3~”îrd(hKÐ;ChþáÚÄ‚zz CVÔ¸Êî{§;[YW[á¶ò\è/’Û/ê'8"ãšgWa -„"U>Cvª©'È ¸´Õyr÷Ò•C°Õ_zk—º–¸ŽlÖ Úµ¾0ÊdW&0R@ÇD÷/ÎÀ=Êãí³bøÅ ºTb>Û®n¡™­<^^1݉СUk?§¬½9ð ŸàÎs Gs{“º¢Xû=¾ÖëZDÂXÓ TÊad˜*©—Dëοþ5赎^Ç¥ø+>OÇ–µ{È'WVv]Ì«¢ÞHí ¦>Xh’wº‘1öI5â÷¯ØÓPÅ®r{LP¡jP;%5ëoKž´ôý—ÜŽúwîwf.¬È/ÛÏ~Èÿ6õãÌ­ŽÅݤ~v|Ö‘ÔNK‡¸õWĦÉ\K†Ãâ±¥ÃfQ¬cIut;—Ýí Œ`:ì6†‰×Œ—)õÅpÓÇŒá6×Ó54žÜvÖ Â2Û=ÎÓÜH']ŠûÖ‰e´ÝbÔŠ À÷2J­ª¶±˜ãŸ°’Ý–:èY11ªiêÅsªÂž$wü†V•oíqVþêÈÞ1)àÉû¶à÷@Üâý?ëZaõ-kÓÞ#¾ÖÆcØI5ÊÿÕÚǸt{ÜTIüo¥œ3¦øy,8v?Û–Eâòv÷..mœý¼oµB¨$£f”ºh›‹-Ø6ó?hµ[X8xp½§!÷‘—§Œ6¦8ì9Wß[§IaÇ!îK#丿%‰éI÷V/Õ>;°?Æ9žV]€uŒ;†vw? ˆ ³¾”Ið ¨—”N'ŠÈr Ä>Â#,½ºîo°UÙ³FÉ/C¹?^p±rþ_˜|'ëB6 ¬ñÚÙ°îûeÙqÚv<ýÈøEÔª5.m¸ásÏñ61:tR2w—[r\O1ÁXç8ÕìyUô~å½Ä{†È#GDA ‚•¨§ÙLH±œk¥ñçó.–ÓM:v¼àÈòHý£aFËè½)ò{I©“|×k¶©,P¬q·Nñ*­‹(Îý|fV°Ü¶üb¸¦vý±í–[L}ÄæÅS¸ÜöÆÍí£²ÚíÖÍvóO‘|Ø­§ÊˆÙÇtå"it{C ½o^uU+©¿Ô‡âY.QžÈqŽ%aŽ#݂ΞIH#P¡Öa¦,¤m†ó¯"¶ÑI¹†&kºáRìO€šÏ£ìTÖÜg™gµv×÷°ÙÃ.3¸óý:ž=y$öülF2šö5ò|Õyé? êWà–QCÉñ˜Ë;Å[ËLmÆ;õ ÈmßjUŽÆ×ê×ö;´`x§Wå–пTm-.?ÛÀ[ʱŸúIQßþ¡j½Z­·³|ÁõûItÌÕR«À~Ÿym­ÂZY‚çµ;˜þô3+€ß_ÚòKNS"ÌÜåÝ»Åy;U—R}{Ü{!€ ’>Û9Þo˜¿á}ç/Èy]æfôã.…¶F{xm$…ä‡Û‰ÙU÷Ñ×vßçÀ®El¬°}á¶öjðÀظîå÷e,Ê=Égàf:ø©‚ðÐÄÈ×9Fx®PFÀ™½XÛ—»ˆhþêßPvªÀ¯8ýDz…—™OsÅøeÃEÇ"r—WQ¶óðÿÇó|ŸtúEË'ÒÞuº{ËÉpÖ¦yä»É C31$–$“ç{¯WiŠ–ÇëÒb­R]c"ôë$ªW^Öín”•®ÅE+ŠR”ˆ¥)HŠ¦Þ°9íç æVÑZÚAsgˆßb¼R+"Ï*÷¿y ‹¥_ ’[Ã-\š£Þ¿nƒå¸-¨m´V÷’×Àfˆoøö®Ã”6¥A¾’ y+§$wzɃ‹)¸O›ø2–âííÒêBJcŒ! 0yR4@ ‚S ‡²ÿÓP/K¿SmÓ®/N+x. náЦ¾†î díc¯¹?5?pÙTÚ–Þ€O$ÔvŒXüÊê9­Opš§¨~¢OÓ¾›_Mˆ‚{œæXÿ Æ-´Ê’¤ò«•GîbŸ!POhð6ËŸLœ_ÓÌN-qw6bÒ÷øÎZÒsÒÝwÇzMP4ÒÃOWŒYÅ×.¼dz…p‘KÄ8<‰Ã™&Žöò2XÎ,;G¸$VßòH'µ…Lù;†»‘”š©Ý´Êµ¡ÁÜû/y2*ê» ‡¹ó”ã•–áýG³çüjÒîlå­ó°ŒS[Il¤†i^3Éõæw0òÉ®í0àð¼ÄØÚÜ[MöóƯ±¸et#a ìXœ¯´äx‹Û<½¤w6·°û7ÃEÓÏ#[$v‘£P¿G9QáÜ›1Ò¾IyÛÁÜ1ÄÉ<ÁšâÌ$iÝãn¨Àèké:4süŠò5ôüzBãÙ‚y7¯æZ˸Äò‡`¨¬/"¼Ëàð—·Ü[܇1zµ° ºäåÜ€ÞÏö<Ö_r·€çΫ,Tì „ËÈÄó¿Œð\ï^:³Êòd¸’Æó"%ý„¬{òá-ÑúPvþ免ÿVÛ¾¬ãxkü?ˆc ÆÀI,SlîIßÔìK7Ï“¡àx­?¥78ÜŸVzßw„ WÊÛ/óP™;®=Ó¥$hȬAù ‚tI)Úa^êñ~Àµtu·9~ ”˦ÂA£©qîI<úï3¶·3Km³Šî[c¦¹>èÖÉŽãqA{žt+±È2¶x®uµo$€£ £Q¿pÐ*ÃûVwÚs Fñý«­Ç,ÎåFÉ5Ôá}G¸Îõ^ï‰q˜,opX\q—;™¡¼g+²°Ò†IoÝðËô”"¹ÊŒù#§9ÐfTÀ=yL¨ç¼ƒ¢ü1é!º¹ÖÑ¢GÜÒ{—1!E;$1<ùñæ´îG’Ÿª\Î릜QcÄð¾<±EÈîm'¸ÒØÂö®Ô«|~ÇéöoYüžÇÒûlo3fó9‡Ån~½ÄáÙô<>•ñç¹×ý3\'ƒØtË…ãð8´ŒIj÷“*n. rC¿>HðÀ}ªå"­2¹ß'N~];äL º‚£l ýyyõ•CÕoÁqŒÿ—Œã­ñQ\Yû¯F¹—$¹ã£ñ<<wör–×lVÖÚnïævýLÅ‹è:ó£ÚjÆVÔèõž|äŠWO­aÐŽžRø`ùe†6;(ò—";‹ù–ÞÒRòM!? Š ÙŽ´ª˜…ö Žñ«n?<¹œåÊfùeڸɼAJE½ˆb]Ÿn1¡à~â 'BcŠøÌßIñ\G æv±a‰”¥qO*7\«Ä÷¥)Tƒ×k ·+àLyYòÁ[uÐoçIGäý™£`6¤ÕߪUÕls«~¨#^;ndÅðaŽ\„ítaEç¾Ý¬¾UÏ{(ןåö®ÃÈ[¸ÎÊ ö÷kj¸R¼”ÿ†.2(,a–iã´… Y'rò8U ˜ü±ÖÉûšÅõ“œÉÂúOua†æë;ÉOðŒl‡ù¥åR€c¡àv‚K:ØÛgˆ<îu½š8Ù‹ª£X\@·¼{§vÆZ0cL“ºùØ;îN·às “§N Ø]¶^g÷¼Í·’"îyß .ôÿ‡AÒþœàø½°_~ÖÜ5ã2áþ©cäwáBµfñöísp·æ¸_În.ïcu°qû>Ô÷TÌÅØ±ÜÊB(Q°™x­U!j,êDøŸPol¯¹V0ßIfŽ‘vÏ$[ A;(A:íñçÆÍKuù\@'Œ©¬£²%80Ê®0Ã"Gø eÁCkcŽ…-¬í£X †5ÒÆŠ4À·ëYZXÁošÅœ)ï´F$ ÕãyëiRz …¶°æ]g’ »øªKQ¶(¨‘K?k!ßy«û{À µ=ãcò-ê­Yº[}êï+æÑf±|ŠÚÝíš$D3ï΂>¼ê·ãÎጥäDƒûªK‹,ãp=$út5×ÂFÄúÍèxz²nC”éͯáx«Ü®O’d"µu¶‰˜$(}Æ,ãéAܱ‚XÚX“ jy®/ûþÕ®«>S‡Æq6XŸ1 g•›§ý'¼á)ŠÈsÌËr^CÇÇcV@-ñP c„}ÛÇi—@Ðó¹4—·„HËc^âg!I$×g`Ìf]X²Æµ¸š+­k^•¯¬¾•ךrɹ&0¸¡xŠoa{c7t î)ï (+ãàùÕuzqÑü/LrPßIJe3(¥Eìê·¿ÛO„Øñ½–Ñ#z$U¿¾Ç¬ÖÅÙÕh÷ÜAä—º4ûÖöÕÞÕü²Ü¦‘¥¥_æç?k ´÷v¨»?LùVWü9ëI%÷äK‹ÛKWXæ*IžÒ$]ùPΤ¯Á ª¼xn<Öê=ÁU£ª¾˜9.ëg™µÂâ%kim&¶ï{µ’(bO ;BPÝÄ_Ú­þaÀ*G¤Õ¬GuN’3'Ô.{auoÄ:vö×¼ß"â0¬{—^æž_+|ì0Ò´·ÒþŽég¶Âãf{ˇv¸¾¾•@’îá¼´¯ö’B€ 'dÆ\Wƒaº~ׄ·ž[ë× yw)šâá·²]Ïäì ;ÕKXù&½·ˆ@©ì±BüºöëÞ~Ý‚oDbÜo¿ ýÞEÝxáÃfú{Ê1Ø›œ–KÉ,cºhœ­—¸YË&õ á|ëÇqÙÕH÷±½Ì„ý·[¥Ž3þ]¶>Õ8}“âµµ…ÑTô›°¬Ì:ÌPàxN[ƒ6\£i–³YÉÔ"EY 0ßÁÑ#cìHûšÔrœ6Ï ³ÁXÛcl£ßd°¬Q®ÎΕ@dî¦<]¸‚Ð%~XHÕxâ8ÆyO|#9Ç9ñK ¡pÏš“qöl'Å~¶xH-<ªö¬F€Ð¯30£´_iJDV¥È­ù>.k¼·–<ËȪ!0‚à5Ýê…£?vV­¡®ÂI;mqqµ:¯JxLòFD«1õ Ô=ÊÜá¬8¾7§vhZ Œô/+Æè@v‰‰+&÷ô…NŽŸÆÄ™ÂøN¦*…Pñ\}”üW:R'ÅP£Câ¾Ò”ˆ¥)HŠR”ˆ¥)HŸœG/ïPk‚Ù‡j€ýéHŸÒ~+^—îHÌGɭЏûkø¤NŽ.Ô[ÆÞ4I¬…|¡_iJR‘¥)JR‘¥)JR‘¥)JR‘¥)JR‘¥)JR‘¥)ÿÙcommons-jxpath-1.3-src/xdocs/images/logo-wbg.jpg100644 0 0 15554 11044113511 17065 0ustar 0 0 ÿØÿàJFIF––ÿÛC     ÿÛC  ÿÀpú"ÿÄ ÿÄ9!1"AQ2#BaR‘$bq‚CDS¡ÑðÿÄÿÄ.1!AQaq±Á¡Ñáð‘"24ÿÚ ?¿Ô¥)JV½Î9ž+§ÜW'É9¦; |&FU×|­ð± $ÌÄ(³äæ²c¼Á!FLØiZ×çΣñ _'À{ËÈÆÍN²#+²:°Ù ¬<¶ ²îŒ¥Iq†ˆ¥)X™ŠR”ˆ¥)HŠR”ˆ¥)HŠR”ˆ¥)HŠR”ˆ¥)HŠÂò¾[…àø+¬ç+¿‹µÝÕ›[ Af$Ÿ€ ¬ÕS¿Vá9VúQÄr_¬þ}wêÑn;b”Kr‘ÕCª†úÙÆ¾ S¦¨]`Ry}¤ú‹M5–ËuŒÉZfq¶y,\ësc{\[ÌŸ¶HÝC+ìA»U¯HŠ±Æ€*ªàYk ÍÄE‰ÝN{¥·JR±JR‘¥)^zñÉ]ËÔ¾=–fklÜC,’O*»~vDQüEzT#×®DËÏ8¶?ÙE¾!§‡›Ü™—´¯ÈÚØ?~ãø®§Ã?és›ñùÏ”’ý'òùaèõÄSÀ¶W— ÉU•Ë÷# ;”ëà©d0yA|vö* tZ{›n•ñ¸eŠX;Rr½ã]ê×0`?7ß[ùøÑ6_§Îαߊ—Vs¨*Ó PžH”ªuë3¬œ§‰åð¼W‹Iw„·h“#.N 9'pìHÃCµt¼–QàÝ1t¬C©Ý7ÇäòŽjЛ,™Ð^ùÐæZ²¶€ |V_KbP.;åu(÷†âLu ucÔÿ éFJ ]ßê3¹Fcú‹|kÆæÔ»÷IaÚÅX•_;íóÚ5Óë¯Z.0ñpžž-ÅïQóÉca†ánì¦bí¥}lý>´¢±xM\3Žô¶çˆälí/ò×Ж»Ì=º¼ÉrWAâfUB~•ñ½ùfߺª­{ö;YæË,rRÆçÛÇÒN‘v¹d€<Ô¹±ùåSú5“éÏ/°ÀEyir}£q™X·gk+ØÝÄQ ïä w)Ò^iÃ,]ú?Ï3†Þ9բċֵúIò{ìnw䂪'äø;-Ñé‚¡[1žÞ¿i®­^ –â¯8ìýç=¥yákÖP½:»KžAG)‹³íÌw˜äžÝ“Îû®#]®·¿5¡½Rã½0w×Ë-âw˜{f*¢æÒñnûI:%¢£çÇqü Ðß¼ ¦w¹uÔ“‡Êžñ-í+„ä8ÎGŒµÉá/a¾°»ŒIÑ6ÕÔýÇÿŸjÉü×8‚ ¼óJR±3¥)ë?¨!Ó^Iâ¼c'*åYGWýrÂBĪýaOÖÌ†Ž‚’Ú»š½äû°ÝPN›È½NõmÈ9L-Æ3su{ÈÌË,QÓÀU¼|í‘W sÝòv÷|š»WRQÀƒ|dùý¤ZkZî';gÊoŠÁ†ÔìUNê2įV\s ÌàøÕÉ]BÀ§·qÜ$N¾®âö{ó­¯?6›þ媱ûÕWéš¿$õÖN[ oidã 6¹$VDfVßoþÓ¸Ÿæ/Çq¥ÿïØ=yLê?È¢vŸNrcyeg'gÉ­÷Œ¶Xù5£ÇtŠ?&¤;ý«H×ûTRÉÙ¥)HŠR”ˆ¥)HŠ«³×)—ãöØ›[Œ=–*Óq—»’ø!šVŠh#Há,¥‘‰›åuݾÒ@:kOT{×n/+Èø¬–†Kë;|eÔÍm»1µUxÄ“;@S܃zvù'~:^-JÈuÇv™n‘ËW¦<^tF@¶†Ìr2þ¥I«ÓøBÆ¿ØTÒ{hìúeÅ"C¼zIí Œ½ÅÉs&ÏÇynþß…ïíOüocüµ6£9ñÚ}egå.{¤Õ=Mðé¹H³qcq™Œš ›hæ‰ÚEíýÍBH±Qä1¥H:ª ÑN¬ÉÒ¬åôóÅ5Î.þ˘aíî÷f7×Á,ºØðäù õjD!SðkÏnµË…êGXn¸65gˆ±²y 3~”îrd(hKÐ;ChþáÚÄ‚zz CVÔ¸Êî{§;[YW[á¶ò\è/’Û/ê'8"ãšgWa -„"U>Cvª©'È ¸´Õyr÷Ò•C°Õ_zk—º–¸ŽlÖ Úµ¾0ÊdW&0R@ÇD÷/ÎÀ=Êãí³bøÅ ºTb>Û®n¡™­<^^1݉СUk?§¬½9ð ŸàÎs Gs{“º¢Xû=¾ÖëZDÂXÓ TÊad˜*©—Dëοþ5赎^Ç¥ø+>OÇ–µ{È'WVv]Ì«¢ÞHí ¦>Xh’wº‘1öI5â÷¯ØÓPÅ®r{LP¡jP;%5ëoKž´ôý—ÜŽúwîwf.¬È/ÛÏ~Èÿ6õãÌ­ŽÅݤ~v|Ö‘ÔNK‡¸õWĦÉ\K†Ãâ±¥ÃfQ¬cIut;—Ýí Œ`:ì6†‰×Œ—)õÅpÓÇŒá6×Ó54žÜvÖ Â2Û=ÎÓÜH']ŠûÖ‰e´ÝbÔŠ À÷2J­ª¶±˜ãŸ°’Ý–:èY11ªiêÅsªÂž$wü†V•oíqVþêÈÞ1)àÉû¶à÷@Üâý?ëZaõ-kÓÞ#¾ÖÆcØI5ÊÿÕÚǸt{ÜTIüo¥œ3¦øy,8v?Û–Eâòv÷..mœý¼oµB¨$£f”ºh›‹-Ø6ó?hµ[X8xp½§!÷‘—§Œ6¦8ì9Wß[§IaÇ!îK#丿%‰éI÷V/Õ>;°?Æ9žV]€uŒ;†vw? ˆ ³¾”Ið ¨—”N'ŠÈr Ä>Â#,½ºîo°UÙ³FÉ/C¹?^p±rþ_˜|'ëB6 ¬ñÚÙ°îûeÙqÚv<ýÈøEÔª5.m¸ásÏñ61:tR2w—[r\O1ÁXç8ÕìyUô~å½Ä{†È#GDA ‚•¨§ÙLH±œk¥ñçó.–ÓM:v¼àÈòHý£aFËè½)ò{I©“|×k¶©,P¬q·Nñ*­‹(Îý|fV°Ü¶üb¸¦vý±í–[L}ÄæÅS¸ÜöÆÍí£²ÚíÖÍvóO‘|Ø­§ÊˆÙÇtå"it{C ½o^uU+©¿Ô‡âY.QžÈqŽ%aŽ#݂ΞIH#P¡Öa¦,¤m†ó¯"¶ÑI¹†&kºáRìO€šÏ£ìTÖÜg™gµv×÷°ÙÃ.3¸óý:ž=y$öülF2šö5ò|Õyé? êWà–QCÉñ˜Ë;Å[ËLmÆ;õ ÈmßjUŽÆ×ê×ö;´`x§Wå–пTm-.?ÛÀ[ʱŸúIQßþ¡j½Z­·³|ÁõûItÌÕR«À~Ÿym­ÂZY‚çµ;˜þô3+€ß_ÚòKNS"ÌÜåÝ»Åy;U—R}{Ü{!€ ’>Û9Þo˜¿á}ç/Èy]æfôã.…¶F{xm$…ä‡Û‰ÙU÷Ñ×vßçÀ®El¬°}á¶öjðÀظîå÷e,Ê=Égàf:ø©‚ðÐÄÈ×9Fx®PFÀ™½XÛ—»ˆhþêßPvªÀ¯8ýDz…—™OsÅøeÃEÇ"r—WQ¶óðÿÇó|ŸtúEË'ÒÞuº{ËÉpÖ¦yä»É C31$–$“ç{¯WiŠ–ÇëÒb­R]c"ôë$ªW^Öín”•®ÅE+ŠR”ˆ¥)HŠ¦Þ°9íç æVÑZÚAsgˆßb¼R+"Ï*÷¿y ‹¥_ ’[Ã-\š£Þ¿nƒå¸-¨m´V÷’×Àfˆoøö®Ã”6¥A¾’ y+§$wzɃ‹)¸O›ø2–âííÒêBJcŒ! 0yR4@ ‚S ‡²ÿÓP/K¿SmÓ®/N+x. náЦ¾†î díc¯¹?5?pÙTÚ–Þ€O$ÔvŒXüÊê9­Opš§¨~¢OÓ¾›_Mˆ‚{œæXÿ Æ-´Ê’¤ò«•GîbŸ!POhð6ËŸLœ_ÓÌN-qw6bÒ÷øÎZÒsÒÝwÇzMP4ÒÃOWŒYÅ×.¼dz…p‘KÄ8<‰Ã™&Žöò2XÎ,;G¸$VßòH'µ…Lù;†»‘”š©Ý´Êµ¡ÁÜû/y2*ê» ‡¹ó”ã•–áýG³çüjÒîlå­ó°ŒS[Il¤†i^3Éõæw0òÉ®í0àð¼ÄØÚÜ[MöóƯ±¸et#a ìXœ¯´äx‹Û<½¤w6·°û7ÃEÓÏ#[$v‘£P¿G9QáÜ›1Ò¾IyÛÁÜ1ÄÉ<ÁšâÌ$iÝãn¨Àèké:4süŠò5ôüzBãÙ‚y7¯æZ˸Äò‡`¨¬/"¼Ëàð—·Ü[܇1zµ° ºäåÜ€ÞÏö<Ö_r·€çΫ,Tì „ËÈÄó¿Œð\ï^:³Êòd¸’Æó"%ý„¬{òá-ÑúPvþ免ÿVÛ¾¬ãxkü?ˆc ÆÀI,SlîIßÔìK7Ï“¡àx­?¥78ÜŸVzßw„ WÊÛ/óP™;®=Ó¥$hȬAù ‚tI)Úa^êñ~Àµtu·9~ ”˦ÂA£©qîI<úï3¶·3Km³Šî[c¦¹>èÖÉŽãqA{žt+±È2¶x®uµo$€£ £Q¿pÐ*ÃûVwÚs Fñý«­Ç,ÎåFÉ5Ôá}G¸Îõ^ï‰q˜,opX\q—;™¡¼g+²°Ò†IoÝðËô”"¹ÊŒù#§9ÐfTÀ=yL¨ç¼ƒ¢ü1é!º¹ÖÑ¢GÜÒ{—1!E;$1<ùñæ´îG’Ÿª\Î릜QcÄð¾<±EÈîm'¸ÒØÂö®Ô«|~ÇéöoYüžÇÒûlo3fó9‡Ån~½ÄáÙô<>•ñç¹×ý3\'ƒØtË…ãð8´ŒIj÷“*n. rC¿>HðÀ}ªå"­2¹ß'N~];äL º‚£l ýyyõ•CÕoÁqŒÿ—Œã­ñQ\Yû¯F¹—$¹ã£ñ<<wör–×lVÖÚnïævýLÅ‹è:ó£ÚjÆVÔèõž|äŠWO­aÐŽžRø`ùe†6;(ò—";‹ù–ÞÒRòM!? Š ÙŽ´ª˜…ö Žñ«n?<¹œåÊfùeڸɼAJE½ˆb]Ÿn1¡à~â 'BcŠøÌßIñ\G æv±a‰”¥qO*7\«Ä÷¥)Tƒ×k ·+àLyYòÁ[uÐoçIGäý™£`6¤ÕߪUÕls«~¨#^;ndÅðaŽ\„ítaEç¾Ý¬¾UÏ{(ןåö®ÃÈ[¸ÎÊ ö÷kj¸R¼”ÿ†.2(,a–iã´… Y'rò8U ˜ü±ÖÉûšÅõ“œÉÂúOua†æë;ÉOðŒl‡ù¥åR€c¡àv‚K:ØÛgˆ<îu½š8Ù‹ª£X\@·¼{§vÆZ0cL“ºùØ;îN·às “§N Ø]¶^g÷¼Í·’"îyß .ôÿ‡AÒþœàø½°_~ÖÜ5ã2áþ©cäwáBµfñöísp·æ¸_În.ïcu°qû>Ô÷TÌÅØ±ÜÊB(Q°™x­U!j,êDøŸPol¯¹V0ßIfŽ‘vÏ$[ A;(A:íñçÆÍKuù\@'Œ©¬£²%80Ê®0Ã"Gø eÁCkcŽ…-¬í£X †5ÒÆŠ4À·ëYZXÁošÅœ)ï´F$ ÕãyëiRz …¶°æ]g’ »øªKQ¶(¨‘K?k!ßy«û{À µ=ãcò-ê­Yº[}êï+æÑf±|ŠÚÝíš$D3ï΂>¼ê·ãÎጥäDƒûªK‹,ãp=$út5×ÂFÄúÍèxz²nC”éͯáx«Ü®O’d"µu¶‰˜$(}Æ,ãéAܱ‚XÚX“ jy®/ûþÕ®«>S‡Æq6XŸ1 g•›§ý'¼á)ŠÈsÌËr^CÇÇcV@-ñP c„}ÛÇi—@Ðó¹4—·„HËc^âg!I$×g`Ìf]X²Æµ¸š+­k^•¯¬¾•ךrɹ&0¸¡xŠoa{c7t î)ï (+ãàùÕuzqÑü/LrPßIJe3(¥Eìê·¿ÛO„Øñ½–Ñ#z$U¿¾Ç¬ÖÅÙÕh÷ÜAä—º4ûÖöÕÞÕü²Ü¦‘¥¥_æç?k ´÷v¨»?LùVWü9ëI%÷äK‹ÛKWXæ*IžÒ$]ùPΤ¯Á ª¼xn<Öê=ÁU£ª¾˜9.ëg™µÂâ%kim&¶ï{µ’(bO ;BPÝÄ_Ú­þaÀ*G¤Õ¬GuN’3'Ô.{auoÄ:vö×¼ß"â0¬{—^æž_+|ì0Ò´·ÒþŽég¶Âãf{ˇv¸¾¾•@’îá¼´¯ö’B€ 'dÆ\Wƒaº~ׄ·ž[ë× yw)šâá·²]Ïäì ;ÕKXù&½·ˆ@©ì±BüºöëÞ~Ý‚oDbÜo¿ ýÞEÝxáÃfú{Ê1Ø›œ–KÉ,cºhœ­—¸YË&õ á|ëÇqÙÕH÷±½Ì„ý·[¥Ž3þ]¶>Õ8}“âµµ…ÑTô›°¬Ì:ÌPàxN[ƒ6\£i–³YÉÔ"EY 0ßÁÑ#cìHûšÔrœ6Ï ³ÁXÛcl£ßd°¬Q®ÎΕ@dî¦<]¸‚Ð%~XHÕxâ8ÆyO|#9Ç9ñK ¡pÏš“qöl'Å~¶xH-<ªö¬F€Ð¯30£´_iJDV¥È­ù>.k¼·–<ËȪ!0‚à5Ýê…£?vV­¡®ÂI;mqqµ:¯JxLòFD«1õ Ô=ÊÜá¬8¾7§vhZ Œô/+Æè@v‰‰+&÷ô…NŽŸÆÄ™ÂøN¦*…Pñ\}”üW:R'ÅP£Câ¾Ò”ˆ¥)HŠR”ˆ¥)HŸœG/ïPk‚Ù‡j€ýéHŸÒ~+^—îHÌGɭЏûkø¤NŽ.Ô[ÆÞ4I¬…|¡_iJR‘¥)JR‘¥)JR‘¥)JR‘¥)JR‘¥)JR‘¥)ÿÙcommons-jxpath-1.3-src/xdocs/images/logo.jpg100644 0 0 13137 11044113511 16303 0ustar 0 0 ÿØÿàJFIF––ÿÛC     ÿÛC  ÿÀqî"ÿÄ ÿÄ8!1"AQ2aq#Br$Rb‚‘¡4áðÿÄÿÄ(!1"AQÑ2a¡Áq‘áÿÚ ?å:R•ú!ðb”¥¥)@)JP R””¥¥)@)JP R””¥¥)@)JP PñRË¥¬}>Vª¿ÌM¹õ¸„Æ·8×ê:•Œ«>Ucr¶àðžqØ6FÒòGô«{ê ¬Ôl¶Š©JT)JPqS~è+Îh[Í×S%Ø·cO[˜m`ì AP+ÆAÜp1ܹÀ„›q-:Û‹@q(PQAì jïûœØ±ì³&ÊܸMÅ[ÎlNIl$“ëÅC1Ën5¯sóãĪ’¼šÆ}m%÷De­lŸ N$%E9à ãÓ'òkëKÍb¯líq¤fR³Ý±ÜØ´G»»ôÚä-Mµ+aðÔ pF9üàûó·ŠÛf:*¥lÚB]:u\0Che!rw! $œ~ç¾®±©’éÐ73DËwFÜUt½ÂJ‰}Râ^u#ÌÑHá=ˆHà‚FIÙJ©—¦s­*Ó!Ù6Ìt-çœPBBJ”¥€É>•4ÅøhÕOCm×î¸ÒÅ…¸²PÒT”‘ùÆz…I–¦£õ=Ý*wÖÿríÖˆh¥=vœ,Öu߯w£8‘´’yzˆæè]Ymqh›¦®ÍìÎT!8¤~ʃû:KÉæ×¥ž%*…•°êš} iÔ) IIî €Ô¦™w-Ò¾ }©*)JP R½ –^£¼Bµ[*[¡¶Áàr~ÀdŸÅçÒ¦î¶éM7 ´®ž³Úà%Wg\*Tòœ-Ä y÷÷*Zp9 {T¾«±>µ´\QâºâMô#NhÖc:莰âÐÛŠVT†ÂT­Ü•¬dóæ>õ è»CZ‡VY­rJƒ2å¶Û…8ÎÒyî@íÿÐ'Šß~%/Ï×È·)Gåí±”#ÓzÆõ+òAHÿˆªÓèŽ;É+ã‚!ÝW95‹º²æ«/l襤_¥)[ R”}5Û×mOb¹ôÚõs´ÉLûSv×’¯”X H '˜yU‚8Pã ⸅Ϡ×f]aÊÿ µ,GbljonÆ´Û›h”¨6"çÝØïÜ0}56e‘'Å¿“‡7Vm±L lÁÃ8Ÿ7Åóc>¸Î+ ¯Ç×o‘êÞ´wÄ{n›Ö:Û,þº~TbÃB>0ر줨gŸQ\[ü¥uV¯V•i‚«°–b„@ÜÕý¸ógÛšœ>º…j…ý5vS¦x…Èl 2NJ õP$‘îÚ·tý“KZî}P²D®Ï[›b4„¤)¬,€‡Hã¾P »íç=tö·ðy8ùb·Þü’7êòG4Éк.[Ž]æ(¿sšH6•ÇÒ¥$¢yî kÉøo¹\…þû"Ëð—lqõÂñR’ó©)J6“ØùˆÏnF}*t•v¸Hr}reÉp¸ó«<©Däš“ú¨%iË®©¸Bl:¸ÚrSà(e!h(('×°æ°Y93¶ððÆ×—ý–:'ª¬:G[&ãªLo•[l>.x¨§ r<¡iÈùªiê^`Ç6øý8¹·t¼ ÈmÈ¿*¥µ!µ$»ÈÔS‚“œý«“H8«aKmiSEIq*%'LT<•3¤Yý›á\‘Ù±5×KúĦ¢^£¶‰¨^ƹ¤0éÏ¢J½Oô…g>«Ãêõv×çh,öS¸AqâãoÝ)R²¤¨údpÍC½?è–¨× Ÿ—6›CƒwÎËN“ÇЩ|ƒÂN˜TÙ­º÷jж–lºvju=þ3iaÉKe*JpV¢œÿJxï’ÁÚm9ÝœõŽ¢Ôá{ý½‘Ë‹GylÈBÚyµ- IJ’ pA±Í\BóVåN™¨/%¾&}ÂJXm¸ëŠ$á#ܞ¦–þnpôTëÝâ∗8ñW%0{€JS»j—ž@#€@>¦§¶tdãåîCô«AÊú•ä×FÑŸ\©cá⫦¾Lò¶ƒV¦ê’£æR– ÑxÜI8 cÈ5f§o†%ÀEçP®BϦ#je{s†B‰ƒùðÿêŒË&Ô=Ä&£7®¢IŠÚ³ÖÊ"§‚¯©gó•mÿE{ë/P_]ÔWËÚZPÛó¤-õ¡¿¥%G8a^r½A(GØ ×'>ÎØÇÆR%.„ZSwê]§Æi.µ 9)AIÈ);ä,¤þEkK¿#TkËíÑ‚ I)h„íÊq÷ ·^ƒÀ»®n¢»ié‘â?ÚR¥? R ³»' ý.;úŒ‰dH\¹È}[ÝuekV1•’p+Föc+ÖÙg”ÈÂkÔoG_\ÓkÔˆ¶ó¡‘!Cú‰Oú•ûyÿN´AÕ½#µ[¤6”[å_×2cûöØm%*9Ï*%¾Ï¥F=\׬jk‹V}8”ÅÒ¶|³†¼¨pŽ ¤zçœgœB¥V­ë³žwUS>ÿDZÔýP/Jõ HŒ·3ÕšB0”% `;ø®KµÝw·?™úSpvÞḭ̈8¦\q;w•°H$Äçö®´Ûæ^®­ö˜îK›%a 2ØÊ”ýÉ=€59+T™ŸÒNâ“öeæ•“Yíj,ÎŽ1íón-K¿dª\xÄ-¨ÉÇ•~®z8šð·VÑ[F”»è®”¥hfPçÐk³:“qnÝÑ»›­6™;kC'v0âBø¶à¡œ ’;×8 NÉ®œøŽ‘"×ÓkM®?Œ¤;!¤Hq «am´q•ì “Ž3ƒŒ­é2”¹\/ÜäÜT«ÐÍC¨âî–§ìŸæ'.BÊ•ŽØ …(Ðsìb³Úºÿ³¥}·ØÙ*EóT~´²FÈCÙ±pr£šå'nføñ^YõZÈ׺¢UÞBËD£2UŸ ¤öN$“÷Q­AiÍ]¯©NMh×!:…¤n½Ö Ñ:Ú$™‹¶Ë-7zˆ@mDyÈÎÓÏ#ß·zÙú¥ÑIšiÙ×í9à?¦U‡›ËéJÙJ¹ÛƒÀØÉÁðMDÞÚ¯K›.w…óÒŸ“á !¿Ò½‰ öµéh£î¹&XlñR‡A-ˆ¹u*Þ¥É\eDiÉؤ‚² 9 …Î3ÈÆj0HÅI] ¸&ßÔû9vGË·!.°¬öp©³µ=½TíȪðS'ézøf±Õ'~c¨º¥IQ^.o£'ý«)ÇíŒVŸ°“[_P"J‰®uw¨Iþ$úÖTÞ­Ë* ÛÎÉàŽMk5ƒ³x­J+i¬$TóиXtÖ­Ö-DT©LG1-èB Ô·pR=ÔZ}êGÐ*jc­ôWN-V•¹y,•I”óClwTw/9É gŒßµtiJ9r:¾‘æÌJzAg~d×ÐÿQ¯('…[+åK㳪Î3éž8w•ðÿ}º©Sûª+qÇT¥¨œ’Iä“ïQt›å(¦Y&[é|~MÞÝ6åÕ¡[õj›"ç9¦ÞJ|¡-n’œ})J3ÛÛ=êPø¬º8åËOZþ]Ä2Ë.ÈñÊNÕ©D'bO©H@'ûÅDÝ.yQº…¥–•„sa#<)a$~ùÇïSÿ_:mu×:K.C[’iöeÉZ”a´©g²y[†åc×h“pÌíÌgô´Î~éÖƒ—¯µVøŠCQZé²ÈKL‚7;“Ø2}@ɇT.Ö;α”­' 4;DFу°„½³‚çòx¹5µõT[z¦ÃÍ !/I<_®Œ …õ󹬎~Ägäç*¨uƒå5IÒz6õW©øöü'¯£¹Ó„Û´è’¡pº8þÓž|GR~‘ÂsÎs÷®fZ|¦¤MW¬íÚ§šFѲWñ›*žiÅ+‚qŒóÀ@qµ_lè;<µ4¹1‰8]ùÛ;¢º‚Ïjèõ‘w‹¼6Zi/¥Ó!ä£gë,ì ýˆã×Ó‚*Ô}V³i˜Òìµ3iˆêJ¼-ÊxÈB—æJy8*äg€“ÍDŸ95_…Unœ¥ð' MºÞ÷ßìSªôSXm# ¬ÄÖØ–ÈöÌ–YrCͳµºóŠB’¥)DàrMR°[ZâJ’B’F>ÕSO;æÞŽâÙy¥¶âR¤¨‚ìAõ©7Iu/O™i=GÓQoo(m]ÏÂJžP˽…ŸB¼…Œçô7£›Øð:Y¥äj½mia˜î;<”?-À‚P†ÒwaG°Ý·hü×·×^§C×7$[-‘GÊÚ¤:–¦‡‰ñó€¬$yv’AäàÙ9½¯ºÜõâìú&tõ•Ôøm¤¶ë™R|§?ŽO¾8¨omsÛo£Lq·Î½¼—IôÓ:¯¨VKlÄx‘ ¥çÓ´(6’½ª‚Rº³ºÑªªúu~2‚¢B" ó%¼…‚Aedb+ké|vô§Lµž¶PÌÕ4m±2{oØ ¿RÓëý&¡VÓYë]/UºøëûÑ]^m5lk!´ÖжȧÑô§Š£m^¥lÖÌ“ÑcmeÛn2,×87$&T7ÐûEC - £"­Õ ¨k¢w³ÒÕZ–~±¾I¼^Kf\¡A´íJBRØãm«›i¶©Ä²zéôU•Œ“W€ò×ÂŒÕÚÚ*ž™ŒQšøZÍdøuô"©À¿3µT–þÕ°S`¨ûh}Ã#N^Ó7ÛmÞ*ã°d!à…v^Ó’“í‘Æ}3[Ž±ëŽ¯ÕÁlüà´A*Èb-’=7/;ý€}«DZ*‘U©k ¸Óä×f‘Y § ª¼3W[FRcLÖ¯¢ÚQWx«©F*­µººÙŽæ¾ø?jÈö§‚#›1ÒÖ ^ ÅUJ²ItÙðÕµÕÚ¤§4d#C5ð"¯xU÷ìøšrFßvÖìÈ鵓GÛ™y<‡%N}Àp©{R Ê@PÉ<ä+IÅ\ÛÍ6Ôq%4¼¥<ÖBF[By«µ¤­§±JR¬PPŒÒ”Í¢›E}¥¥)@)JP R”Â3_6 ª”'eª‚@¯´ Û¥(@¥)@)JP R”†” -šR•RÇÔ÷ªéJ”C¥*H¥()JJR€R” ¥()JJR€R” ¥()JÿÙcommons-jxpath-1.3-src/xdocs/index.xml100644 0 0 7622 11044113515 15213 0ustar 0 0 JXPath Home Commons Documentation Team Dmitri Plotnikov $Id: index.xml 561417 2007-07-31 18:13:25Z niallp $

The org.apache.commons.jxpath package defines a simple interpreter of an expression language called XPath. JXPath applies XPath expressions to graphs of objects of all kinds: JavaBeans, Maps, Servlet contexts, DOM etc, including mixtures thereof.

Consider this example:

Address address = (Address)JXPathContext.newContext(vendor).
         getValue("locations[address/zipCode='90210']/address");

This XPath expression is equivalent to the following Java code:

Address address = null;
Collection locations = vendor.getLocations();
Iterator it = locations.iterator();
while (it.hasNext()){
    Location location = (Location)it.next();
    String zipCode = location.getAddress().getZipCode();
    if (zipCode.equals("90210")){
      address = location.getAddress();
      break;
    }
}

XPath was standardized by W3C and is used in both XSLT and XPointer.

If you want to find out more about XPath, a good place to start is an excellent XPath Tutorial by W3Schools

The official definition of XPath by W3C can be found at XML Path Language (XPath) Version 1.0

Primary applications of JXPath are in scripting: JSP and similar template/script based technologies. However, programmers who prefer XML-flavored APIs, should consider JXPath as an alternative to other expression languages as well. JXPath is a must-have tool for those who work with mixtures of Java objects and XML and need to frequently traverse through graphs of those.

JXPath documentation currently contains:

See the JXPath Downloads page for current/previous releases.

commons-jxpath-1.3-src/xdocs/issue-tracking.xml100644 0 0 13245 11044113515 17052 0ustar 0 0 Commons JXPath Issue tracking Commons Documentation Team

Commons JXPath uses ASF JIRA for tracking issues. See the Commons JXPath JIRA project page.

To use JIRA you may need to create an account (if you have previously created/updated Commons issues using Bugzilla an account will have been automatically created and you can use the Forgot Password page to get a new password).

If you would like to report a bug, or raise an enhancement request with Commons JXPath please do the following:

  1. Search existing open bugs. If you find your issue listed then please add a comment with your details.
  2. Search the mailing list archive(s). You may find your issue or idea has already been discussed.
  3. Decide if your issue is a bug or an enhancement.
  4. Submit either a bug report or enhancement request.

Please also remember these points:

  • the more information you provide, the better we can help you
  • test cases are vital, particularly for any proposed enhancements
  • the developers of Commons JXPath are all unpaid volunteers

For more information on subversion and creating patches see the Apache Contributors Guide.

You may also find these links useful:

commons-jxpath-1.3-src/xdocs/navigation.xml100644 0 0 5337 11044113515 16244 0ustar 0 0 JXPath Commons &commons; commons-jxpath-1.3-src/xdocs/release-notes-1.1.xml100644 0 0 13651 11044113515 17166 0ustar 0 0 JXPath Release Notes 1.1 Dmitri Plotnikov

Most changes in 1.1 are in the internal implementation and do not affect public APIs. However there are some new publicly visible features:

  • Full support for JDOM. Just like with DOM, if a JDOM node is the root node of a JXPathContext, the implementation strictly follows the XPath 1.0 standard. A JDOM node can also be a part of a mixed model, i.e. the value of a property, variable, container, collection element etc.
  • Pointer has an additional method: getNode(), which returns the raw value without converting it to a primitive value. This makes a difference when you are working with DOM/JDOM and want to obtain the Node itself, not the textual value of the Node.
  • Support for DynaBeans (see Jakarta Commons BeanUtils).
  • Refactored XML parsing by container to allow for alternate parsers. All you do now is specify which model you want the container to use - DOM (default) or JDOM. From that point the processing is transparent. See org.apache.commons.jxpath.xml.DocumentContainer.
  • The format-number XSLT function is now supported. In order to provide full conformance with the standard, we also needed to introduce the format customization mechanism known in XSLT as <xsl:decimal-format> (see W3Schools tutorial). The new methods of JXPathContext: setDecimalFormatSymbols() and getDecimalFormatSymbols() fulfill that requirement.
  • The attribute:: axis is now supported models other than DOM/JDOM. For beans and maps it is interpreted the same way as the "child::" axis.
  • In JXPath 1.0 you could only register DynamicPropertyHandlers for concrete classes, now you can also register them for interfaces.
  • The implementation of setValue() has changed for DOM/JDOM nodes. In JXPath 1.0 it would replace text in the element, but leave sub-elements alone. The new implementation is more consistent: it drops all subelements first. Also, if you pass a Node as the new value, it will insert the Node in the tree.
  • If you need to evaluate multiple paths relative to a certain node in the object graph, you can now create a relative JXPathContext. Obtain the pointer for the location that is supposed to define the relative context and then a relative context by calling context.getRelativeContext(pointer).
  • The JUnit tests for JXPath have been completely redisigned and significantly enhanced.

Great thanks to everybody who reported problems, helped to trace them, suggested changed or simply provided encouragement. Special thanks to

  • Trond Aasan
  • Bjorn Bength
  • Derek A. Bodin
  • BoD
  • Stephen Colebourne
  • Torsten Curdt
  • Pierre Delisle
  • Ruud Diterwich
  • Peter Donald
  • Kate Dvortsova
  • Eduardo Francos
  • dIon Gillard
  • Mike Hogan
  • Ivelin Ivanov
  • Per Kreipke
  • Kees Kuip
  • David Li
  • Ulrich Nicolas Lisse
  • Costin Manolache
  • Thorsten Mauch
  • Craig R. McClanahan
  • Markus Menner
  • Daniel Michalik
  • Steve Pannier
  • Ed Peters
  • Kenneth Petersen
  • Ovidiu Predescu
  • Erik Pugh
  • Robert Rasmussen
  • Vasco C. Rocha
  • Francois Swiegers
  • Joern Turner
  • Knut Wannheden
  • Andrew Wulf
  • Jason van Zyl
Thanks!

commons-jxpath-1.3-src/xdocs/release-notes-1.2.xml100644 0 0 11432 11044113515 17162 0ustar 0 0 JXPath Release Notes 1.2 Dmitri Plotnikov

Most changes in 1.2 are in the internal implementation and do not affect public APIs. However there are a couple of publicly visible features:

  • Namespace registration. Namespace URIs can now be associated with prefixes at the level of JXPathContext.
  • JXPathContext has two new convenience methods: selectNodes and selectSingleNode.
  • Type conversion is integrated with BeanUtils.

This release also includes countless bug fixes and implementation improvements.

Great thanks to everybody who reported problems, helped to trace them, suggested changed or simply provided encouragement. Special thanks to

  • Jim Alateras
  • Psi Aushilfe3
  • Richard Barnett
  • Martin John Bartlett
  • Christian Beer
  • Jochen Bedersdorfer
  • Heiko Bensch
  • Noel J. Bergman
  • Timothy H. Bessie
  • Luca Biolcati
  • John C Bledsoe
  • Doug Borland
  • Vladimir R. Bossicard
  • Lloyd Boucher
  • Don Brown
  • Louis Calisi
  • Jerome Candat
  • Nassim Chalfouh
  • Prasad Rao Challakonda
  • Adam Chesney
  • Prasad Chodavarapu
  • David Chung
  • Mark R. Diggory
  • Robert Burrell Donkin
  • Juergen Donnerstag
  • Yann Duponchel
  • Xavier Dury
  • Erik Earle
  • Nagesh Eranki
  • JP Fielding
  • Gary Gregory
  • Peter Franken
  • Eric D. Friedman
  • Matthew Hawthorne
  • Joerg Heinicke
  • Reidar Hoerning
  • Nick Hofstede
  • Jason Horman
  • Ted Husted
  • Ivelin Ivanov
  • Uwe Janner
  • Kees Jongenburger
  • Adrian Perez Jorge
  • Snehal Khanna
  • John C. Landers
  • Jeff Lansing
  • Jonathan Layes
  • David Leangen
  • Joerg Lensing
  • Pato Loco
  • Tony Lodge
  • Joachim Maes
  • Thomas Mathis
  • Brian McCallister
  • Markus Menner
  • Stephan Mikaty
  • Shahar Mosek
  • Russell Neufeld
  • Peter Neumcke
  • Christopher Oliver
  • Steve Pannier
  • Adrian Price
  • Venkatesh Prasad Ranganath
  • Simon Raess
  • Sudhir Rao
  • Stan Reinis
  • Jean-Baptiste Reure
  • Michael Nascimento Santos
  • Dmitry Sklyut
  • Phil Steitz
  • Nikolay Tsankov
  • Joerg Troester
  • Joern Turner
  • Rob Walker
  • Sylvain Wallez
  • Knut Wannheden
  • Chris White
  • Jeremy Wohl
  • Henri Yandell
  • Guanqun Zhang
  • Chuck (bigfishsmallpond)
Thanks!

commons-jxpath-1.3-src/xdocs/release-notes-1.3.xml100644 0 0 21416 11044113515 17166 0ustar 0 0 Release Notes - Commons JXPath - Version 1.3 Matt Benson

Bug

  • [JXPATH-2] - Using JXPath in multiple threads
  • [JXPATH-5] - asPath() returns a path to the last sibling
  • [JXPATH-10] - JXPath 1.1 code using custom functions failing when run in 1.2 onwards
  • [JXPATH-12] - Descendant or self axis does not work correctly at root node
  • [JXPATH-17] - JXPathContext.iteratePointers("//*") results are incorrect
  • [JXPATH-30] - Source instructions on web site are wrong
  • [JXPATH-37] - JXPathException cause
  • [JXPATH-38] - ClassFunctions throws NPE searching for a function in null ns
  • [JXPATH-40] - Problem in namespace handling
  • [JXPATH-46] - NullPointerException
  • [JXPATH-50] - does not properly handle NodeSet returned by extension function
  • [JXPATH-68] - StackOverflow error on a call to 'JXPathContext.createPath()'
  • [JXPATH-70] - Javadoc missing from distribution
  • [JXPATH-73] - ValueUtils should catch IndexOutOfBoundsException instead of ArrayIndexOutOfBoundsException (for XmlBeans support)
  • [JXPATH-76] - CompiledExpression not completely thread-safe
  • [JXPATH-79] - Error when accessing JXPathContext methods in Concurrent Scenario
  • [JXPATH-83] - JXpath automatically trims string values
  • [JXPATH-84] - reserved word enum is used
  • [JXPATH-85] - Restore binary compatibility with JXPath 1.2
  • [JXPATH-87] - xmlURL field not set in XMLDocumentContainer
  • [JXPATH-89] - Cannot compare pointers that do not belong to the same tree
  • [JXPATH-90] - Upper boundary check is missing from substring(<string>, <number>)
  • [JXPATH-93] - Binary operators behaviour involving node-sets is incorrect
  • [JXPATH-94] - equality test for multi-valued variables does not conform to spec
  • [JXPATH-95] - Comparing with NaN is incorrect
  • [JXPATH-97] - Incomplete handling of undefined namespaces
  • [JXPATH-98] - termination problem with empty list
  • [JXPATH-100] - Core union operation does not sort result nodes according to document order
  • [JXPATH-101] - Original context from VariableContextWrapper is not visible
  • [JXPATH-102] - Core rounding functions don't handle NaN or infinite values correctly
  • [JXPATH-104] - selectSingleNode() from a map should not select map values keyed by strings with embedded colons using namespaced element syntax
  • [JXPATH-105] - BasicNodeSet.getNodes() returns values instead of nodes ?
  • [JXPATH-106] - Typo in JXPathException.getMessage()
  • [JXPATH-107] - RCN: Nullcheck of NodePointer.parent of value previously dereferenced in PropertyOwnerPointer.setValue(Object)
  • [JXPATH-109] - Namespaced attribute not selected with wildcard
  • [JXPATH-111] - ClassCastException in PrecedingOrFollowingContext
  • [JXPATH-113] - NullPointerException in ChildContext
  • [JXPATH-114] - node() implementation in DOM and JDOM model
  • [JXPATH-115] - Issue with attribute::
  • [JXPATH-120] - ClassCastException in ServletRequestHandler.setProperty()
  • [JXPATH-123] - Regression: "fix" made to NamespaceResolver broke existing testcases

Improvement

  • [JXPATH-75] - The dependency for xerces in commons-jxpath-1.2.pom is too old
  • [JXPATH-88] - Add getPrefix(String namespaceURI) to JXPathContext
  • [JXPATH-91] - KeyManager should support nodeset selection
  • [JXPATH-108] - problems with NodeSet returned from custom function.
  • [JXPATH-124] - Make buildContextChain method of Path class protected

New Feature

  • [JXPATH-96] - Extract VariablePointerFactory interface

Thanks to everybody who reported problems, helped to trace them, suggested changes or simply provided encouragement. Special thanks to

  • Dmitri Plotnikov (foundation)
  • Niall Pemberton (release guidance)
  • Dennis Lundberg (M2 assistance)
  • Sergey Vladimirov (numerous bug reports)
  • Michele Vivoda (numerous bug reports)
  • Henri Yandell (proposing a new committer)
  • Elliotte Rusty Harold (XPath feature sanity check)

commons-jxpath-1.3-src/xdocs/style/project.css100644 0 0 102 11044113510 16637 0ustar 0 0 @import url("http://commons.apache.org/style/commons-maven.css"); commons-jxpath-1.3-src/xdocs/users-guide.xml100644 0 0 200021 11044113515 16364 0ustar 0 0 JXPath User's Guide Dmitri Plotnikov

JXPath provides APIs for traversal of graphs of JavaBeans, DOM and other types of objects using the XPath syntax.

If you are not familiar with the XPath syntax, start with XPath Tutorial by W3Schools.
Also see XML Path Language (XPath) Version 1.0 - that's the official standard.

XPath is the official expression language of XSLT. In XSLT, you mostly use XPath to access various elements of XML documents. You can do that with JXPath as well. In addition, you can read and write properties of JavaBeans, get and set elements of arrays, collections, maps, transparent containers, various context objects in Servlets etc. In other words, JXPath applies the concepts of XPath to alternate object models.

You can also have JXPath create new objects if needed.

The central class in the JXPath architecture is JXPathContext. Most of the APIs discussed in this document have to do with the JXPathContext class.

JXPath uses JavaBeans introspection to enumerate and access JavaBeans properties.

The interpretation of the XPath syntax in the context of Java object graphs is quite intuitive: the "child" axis of XPath is mapped to JavaBean properties. In fact, the "attribute:" axis is mapped exactly the same way, so the "child::" and "attribute:" axes can be used interchangeably with JavaBeans.

JXPath can be used to access properties of a JavaBean.

public class Employee { public String getFirstName(){ ... } } Employee emp = new Employee(); ... JXPathContext context = JXPathContext.newContext(emp); String fName = (String)context.getValue("firstName");

In this example, we are using JXPath to access a property of the emp bean. In this simple case the invocation of JXPath is equivalent to invocation of getFirstName() on the bean.

Note that using the XPath "@firstName" instead of "firstName" would produce the same result, because the "child::" and "attribute::" axes are equivalent.

The context.getValue(xpath) method throws an exception if the supplied xpath does not map to an existing property. This constraint can be relaxed by calling context.setLenient(true). In the lenient mode the method merely returns null if the path maps to nothing.

JXPath can traverse object graphs:

public class Employee { public Address getHomeAddress(){ ... } } public class Address { public String getStreetNumber(){ ... } } Employee emp = new Employee(); ... JXPathContext context = JXPathContext.newContext(emp); String sNumber = (String)context.getValue("homeAddress/streetNumber");

In this case XPath is used to access a property of a nested bean.

A property identified by the XPath does not have to be a "leaf" property. For instance, we can extract the whole Address object in above example:

Address addr = (Address)context.getValue("homeAddress");

JXPath can extract elements from arrays and collections.

public class Integers { public int[] getNumbers(){ ... } } Integers ints = new Integers(); ... JXPathContext context = JXPathContext.newContext(ints); Integer thirdInt = (Integer)context.getValue("numbers[3]");

A collection can be an arbitrary array or an instance of java.util.Collection. JXPath also supports indexed properties according to the JavaBeans specification.

Note: in XPath the first element of a collection has index 1, not 0.

JXPath can retrieve multiple objects from a graph. Note that the method called in this case is not getValue, but iterate.

public class Author { public Book[] getBooks(){ ... } } Author auth = new Author(); ... JXPathContext context = JXPathContext.newContext(auth); Iterator threeBooks = context.iterate("books[position() < 4]");

This returns an iterator over at most three books from the array of all books written by the author.

JXPath supports maps. To get a value use its key as the name in a child::name construct.

public class Employee { private Map addressMap = new HashMap(); { addressMap.put("home", new Address(...)); addressMap.put("office", new Address(...)); } public Map getAddresses(){ return addressMap; } ... } Employee emp = new Employee(); JXPathContext context = JXPathContext.newContext(emp); String homeZipCode = (String)context.getValue("addresses/home/zipCode");

Often you will need to use the alternative syntax for accessing Map elements:

String homeZipCode = (String)context. getValue("addresses[@name='home']/zipCode");

Unlike a child name in XPath, the value of the "name" attribute does not have to be a properly formed identifier. Also, in this case the key can be an expression, e.g. a variable.

The attribute "name" can be used not only with Maps, but with JavaBeans as well. The value of this attribute represents the name of a property.

Note: At this point JXPath only supports Maps that use strings for keys.

Note: JXPath supports the extended notion of Map: any object similar to Map, i.e. having some kind of API for accessing values by key, can be handled by JXPath provided that its class is registered with the JXPathIntrospector. The term JXPath uses for such objects is "objects with Dynamic Properties".

JXPath supports DynaBeans as well. DynaBeans are treated exactly the same way as JavaBeans.

JXPath supports access to DOM and JDOM Nodes. The DOM/JDOM node can be the context node of JXPathContext or it can be a value of a property, element of a collection, value of a variable etc. Let's say we have a path "$foo/bar/baz". It will find the desired node if, for instance, the value of the variable "foo" is a JavaBean, whose property "bar" contains a DOM/JDOM Node, which has a child element named "baz".

The intepretation of XPath over DOM/JDOM structures is implemented in accordance with the XPath specification.

JXPathContext has two similar sets of APIs: getValue(xpath)/iterate(xpath) and selectSingleNode(xpath)/selectNodes(xpath). With JavaBeans and similar Java object models, these sets of APIs are effectively equivalent. However, with DOM/JDOM there is a difference: selectSingleNode(xpath) and selectNodes(xpath) return Nodes, while getValue() and iterate(xpath) return textual contents of those nodes.

Consider the following XML document:

<?xml version="1.0" ?> <address> <street>Orchard Road</street> </address>

With the same XPath, getValue("/address/street"), will return the string "Orchard Road", while selectSingleNode("/address/street") - an object of type Element (DOM or JDOM, depending on the type of parser used). The returned Element is, of course, <street>Orchard Road</street>.

When using namespaces, it is important to remember that XPath matches qualified names (QNames) based on the namespace URI, not on the prefix. Therefore the XPath "//foo:bar" may not find a node named "foo:bar" if the prefix "foo" in the context of the node and in the execution context of the XPath are mapped to different URIs. Conversely, "//foo:bar" will find the node named "biz:bar", if "foo" in the execution context and "biz" in the node context are mapped to the same URI.

In order to use a namespace prefix with JXPath, that prefix should be known to JXPathContext. JXPathContext knows about namespace prefixes declared on the document element of the context node (the one passed to JXPathContext.newContext(node)), as well as the ones explicitly registered using the JXPathContext.registerNamespace(prefix, namespaceURI) method.

A Container is an object implementing an indirection mechanism transparent to JXPath.

For example, if property "foo" of the context node has a Container as its value, the XPath "foo" will produce the contents of that Container, not the container itself.

An example of a useful container is XMLDocumentContainer. When you create an XMLDocumentContainer, you give it a pointer to an XML file (a URL or a javax.xml.transform.Source). It will read and parse the XML file only when it is accessed. You can create XMLDocumentContainers for various XML documents that may or may not be accessed by XPaths. If they are, they will be automatically read, parsed and traversed. If they are not- they won't be read at all. Of course, once XMLDocumentContainer has read its XML file, it will cache the parse results for a future use.

Let's say we have the the following XML file, which is stored as a Java resource.

<?xml version="1.0" ?> <vendor> <location id="store101"> <address> <street>Orchard Road</street> </address> </location> <location id="store102"> <address> <street>Tangerine Drive</street> </address> </location> </vendor>

Here's the code that makes use of XMLDocumentContainer.

class Company { private Container locations = null; public Container getLocations(){ if (locations == null){ URL url = getClass().getResource("Vendor.xml"); locations = new XMLDocumentContainer(url); } return locations; } } ... context = JXPathContext.newContext(new Company()); ... String street = (String)context.getValue( "locations/vendor/location[@id = 'store102']//street");

Like was described before, this code will implicitly open and parse the XML file and find a value in it according to the XPath.

Functions id() and key() can be used with JXPath, however most of the time that requires custom coding.

The only situation where no custom coding is needed is when you want to use the id() function and you have a DOM Node as the context node of the JXPathContext. In this case, JXPath will use the standard behavior of DOM.

In order to evaluate the id() function, JXPath calls a delegate object that should be implemented and installed on the JXPathContext. The object should implement the IdentityManager interface.

Similarly, the key() function relies on a custom implementation of the KeyManager interface.

The interpretation of XPath over XML models like DOM and JDOM is governed by the XPath standard. There is no official standard for the interpretation of XPaths on other types of models: beans, maps etc. This part describes how JXPath performs such interpretation.

In DOM/JDOM the definition of a node's parent is clear: a Node always points to its parent. XML is a strict tree, so there always exactly one parent for every node except the root.

With other models the situation is more complex. An general object model can not be described as a tree. In many cases it is a complicated graph with many paths to the same node and even referential cycles where node A is node B's child, but also node B is node A's child. Even if the graph is a strict tree, a node of that tree may not have a pointer to its parent.

Because of all these issues, JXPath abandons the static notion of a parent/child relationship in favor of a dynamic one. When an XPath is evaluated, the engine performs a series of searches and computations in so called evaluation contexts. For example, when the "/foo/bar" path is evaluated, JXPath first looks for a node named "foo" in the root evaluation context. If such a node is found, the interpreter forms a new context for the discovered node and searches for a node named "bar" in that context.

This chain of contexts is used in JXPath to define the parent-child relationship. Parent is the base node of the previous evaluation context in the chain. A more appropriate name for the "parent::" axis would then be "step back".

Consider this example. The evaluated path is "foo//bar/../baz". In the process of evaluating of this path, the engine will walk the graph forming chains of context like "/foo/a/b/c/bar". Once a node with the name "bar" is found, the engine will "step back": in our case it will go back to the "/foo/a/b/c" context and then look for the node with the name "baz" in that context.

Exercise: think about how the path "//foo[../@name='bar']" would be interpreted.

Solution:

  1. Descend from the root of the graph looking for a node with the name "foo".
  2. Let's say the engine has found such a node in the context of a node called "biz". The "biz" node is the dynamic parent of the node "foo".
  3. Form a new context for the "foo" node.
  4. To evaluate the predicate "../@name='bar'", step back to the previous context, which is the context of the node "biz" to see if it has an attribute called "name". If so, compare the value of that attribute to "bar". If it is equal, include the current "foo" node in the result set.

The dynamic interpretation of the parent/child relationship affects most axes including "parent::", "ancestor::", "preceding::", "following::" etc.

The XPath standard defines the term "document order" as the order in which pieces of XML follow each other in the textual representation. This definition is not applicable directly to non-XML models.

Results of many types of xpaths depend on the document order, so we cannot leave it as "unpredictable" or "undefined" for such nodes as JavaBeans or Maps. In order to have a predictable order, JXPath sorts properties of beans and keys of maps alphabetically.

For JavaBeans and Maps the "attribute::" axis is interpreted the same as the "child::" axis.

The only distinctions are "xml:lang", "xml:space", and "name".

Attribute xml:lang refers to the name of the locale associated with the node. In XML the xml:lang attribute can be specifed for an element explicitly. In non-XML models, the locale is associated with the whole JXPathContext. Unless explicitly set it is the application's default locale.

Since version 1.3, the xml:space attribute can be used in an XML model to direct JXPath's interpretation of embedded whitespace among XML content and nested text. In previous versions this data was trimmed, and this has been preserved as the default behavior for reasons of backward compatibility. Specifying xml:space="preserve" will cause JXPath to preserve whitespace. Keep in mind that it is possible to specify default attribute values using DTD or XML schema, so that there exists a straightforward and standards-based way to enable whitespace preservation by default at the document or element level.

The name attribute is primarily used when working with Maps. Often elements of a Map can be retrieved using the "child::" axis. For example, if "foo" in "foo/bar" refers to a Map then the path extracts from the map the value for the key "bar". The syntax of XPath requires that a child name be a properly formed identifier. Now, what if the key we are looking for is "?%$", which is not an identifier. In this case we can use the "name" attribute like this: "foo[@name='?%$']". This path is not interpreted as "find a 'foo' that has the name '?%$'". It is interpreted as "find a 'foo' and get the value for the key '?%$'" from it. This interpretation is used for maps and beans only. In the case of XML, "name" is treated like any other attribute.

Exceptions thrown by accessor methods are treated differently depending on the evaluated xpath and the particular method used to do the evaluation.

The basic idea is that if JXPath is looking for something by iterating over all properties of a bean and during that iteration an accessor method for one of these properties throws an exception, JXPath ignores the exception and moves on to the next property. This could happen if the method is iterate() or if the path contains search axes like "descendant::", "ancestor::" etc.

In all other cases, an exception thrown by an accessor method is wrapped into a JXPathException and re-thrown.

JXPath can also be used to modify parts of object graphs: property values, values for keys in Maps. It can in some cases create intermediate nodes in object graphs.

JXPath can be used to modify property values.

public class Employee { public Address getAddress() { ... } public void setAddress(Address address) { ... } } Employee emp = new Employee(); Address addr = new Address(); ... JXPathContext context = JXPathContext.newContext(emp); context.setValue("address", addr); context.setValue("address/zipCode", "90190");

JXPath can be used to create new objects. First, create a subclass of AbstractFactory and install it on the JXPathContext. Then call jxPathContext.createPath(xpath). JXPathContext will invoke your AbstractFactory when it discovers that an intermediate node of the path is null. It will not override existing nodes.

public class AddressFactory extends AbstractFactory { public boolean createObject(JXPathContext context, Pointer pointer, Object parent, String name, int index){ if ((parent instanceof Employee) && name.equals("address"){ ((Employee)parent).setAddress(new Address()); return true; } return false; } } JXPathContext context = JXPathContext.newContext(emp); context.setFactory(new AddressFactory()); context.createPath("address");

You can also combine creating a path with setting the value of the leaf: the createPathAndSetValue(path, value) method is used for that.

context.createPathAndSetValue("address/zipCode", "90190");

Note that it only makes sense to use the automatic creation of nodes with very simple paths. In fact, JXPath will not attempt to create intermediate nodes for paths that don't follow these three rules:

  • The only axes used are "child::" and "attribute::", e.g. "foo/bar/@baz"
  • The only two types of predicates used are context-independent indexing and the "[@name = expr]" construct, e.g. "map[@name='key1'][4/2]".
  • If a variable is used, it is the root of the path, e.g. "$object/child".

JXPath supports the notion of variables. The XPath syntax for accessing variables is "$varName".

public class Author { public Book[] getBooks(){ ... } } Author auth = new Author(); ... JXPathContext context = JXPathContext.newContext(auth); context.getVariables().declareVariable("index", new Integer(2)); Book secondBook = (Book)context.getValue("books[$index]");

You can also set variables using JXPath:

context.setValue("$index", new Integer(3));

Note: generally speaking, you can only change the value of an existing variable this way, you cannot define a new variable. If you do want to be able to define a new variable dynamically, implement a defineVariable() method on your custom AbstractFactory and call createPathAndSetValue() rather than setValue(). The restrictions described in the "Creating Objects" section still apply.

When a variable contains a JavaBean or a collection, you can traverse the bean or collection as well:

... context.getVariables().declareVariable("book", myBook); String title = (String)context.getValue("$book/title); Book array[] = new Book[]{...}; context.getVariables().declareVariable("books", array); String title = (String)context.getValue("$books[2]/title);

By default, JXPathContext creates a HashMap of variables. However, you can substitute a custom implementation of the Variables interface to make JXPath work with an alternative source of variables. For example, you can define implementations of Variables that cover a servlet context, HTTP request or any similar structure.

See the org.apache.commons.jxpath.servlet package for an example of just that.

The org.apache.commons.jxpath.servlet package contains classes that make it easy to use XPath to access values in various sevlet contexts: "page" (for JSPs), "request", "session" and "application".

See static methods of the class JXPathServletContexts. They allocate various servlet-related JXPathContexts.

The JXPathContext returned by getPageContext(PageContext pageContext) provides access to all scopes via the PageContext.findAttribute() method. Thus, an expression like "foo" will first look for the attribute named "foo" in the "page" context, then the "request" context, then the "session" one and finally in the "application" context.

If you need to limit the attibute lookup to just one scope, you can use the pre-definded variables "page", "request", "session" and "application". For example, the expression "$session/foo" extracts the value of the session attribute named "foo".

The getRequestContext(ServletRequest request, ServletContext servletContext) method will give you a context that checks the request scope first, then (if there is a session) the session context, then the application context.

The getSessionContext(HttpSession session, ServletContext servletContext) method will give you a context that checks the session context, then the application context.

Finally, getApplicationContext(ServletContext servletContext) method will give you a context that checks the application context.

All these methods cache the JXPathContexts they create within the corresponding scopes. Subsequent calls use the JXPathContexts created earlier.

Often, rather than getting a node in the object graph, you need to find out where in the graph that node is. In such situations you will need to employ Pointers. A Pointer is an object that represents the specific location in the object graph. Effectively, it is a simple XPath leading from the context root to the selected node. That simple XPath can be used to repeatedly acquire the same node of the graph without performing a costly search. Let's say, you invoke the JXPath search process by calling the getPointer() method:

Pointer ptr = context.getPointer("//address[zipCode='90190']") System.out.println(ptr);

This code will find the address with zipCode = 90190 and return a Pointer describing that node's location. The printed line will look something like this: /vendor[2]/location[1]/address[3]. It provides an unambiguous description of the node's location in the object graph and a fast XPath leading directly to that node.

Here's another example:

Pointer ptr = context.getPointer("employees[$i]/addresses[$j]")

Let's say, at the time of execution the value of the variable i is 1 and j = 3. If we call ptr.asPath(), it returns a simple XPath: "/employees[1]/addresses[3]"; this path does not have a dependency on the variables, it will remain the same when the variables change.

If you need to perform an exhaustive search for all nodes in the graph matching a certain XPath, you can get JXPath to produce an iterator returning pointers for all of discovered locations:

Iterator homeAddresses = context.iteratePointers("//employee/address[@name='home']");

Each Pointer returned by the iterator will represent a home address object in the graph.

It is a good idea to use pointers whenever you need to access the same node of a graph repeatedly.

JXPath is optimized to interpret XPaths produced by Pointers much faster than many other types of XPaths.

If you need to evaluate multiple paths relative to a certain node in the object graph, you might want to create a relative JXPathContext.

First, obtain the pointer for the location that is supposed to be the root the relative context. Then obtain the relative context by calling context.getRelativeContext(pointer).

JXPathContext context = JXPathContext.newContext(bean); Pointer addressPtr = context.getPointer("/employees[1]/addresses[2]"); JXPathContext relativeContext = context.getRelativeContext(addressPtr); // Evaluate relative path String zipCode = (String)relativeContext.getValue("zipCode"); // Evaluate absolute path String name = (String)relativeContext.getValue("/employees[1]/name"); // Use the parent axis to locate the employee for the current address Double salary = (Double)relativeContext.getValue("../salary");

JXPath supports standard XPath functions right out of the box. It also supports "standard" extension functions, which are basically a bridge to Java, as well as entirely custom extension functions.

Using the standard extension functions, you can call methods on objects, static methods on classes and create objects using any constructors. All class names should be fully qualified.

Here's how you can create new objects:

Book book = (Book)context. getValue("com.myco.books.Book.new('John Updike')");

Here's how you can call static methods:

Book book = (Book)context. getValue("com.myco.books.Book.getBestBook('John Updike')");

Here's how you can call regular methods:

String firstName = (String)context. getValue("getAuthorsFirstName($book)");

As you can see, the target of the method is specified as the first parameter of the function.

Collections of custom extension functions can be implemented as Functions objects or as Java classes, whose methods become extension functions.

Let's say the following class implements various formatting operations:

public class Formats { public static String date(Date d, String pattern){ return new SimpleDateFormat(pattern).format(d); } ... }

We can register this class with a JXPathContext:

context.setFunctions(new ClassFunctions(Formats.class, "format")); ... context.getVariables().declareVariable("today", new Date()); String today = (String)context.getValue("format:date($today, 'MM/dd/yyyy')");

You can also register whole packages of Java classes using PackageFunctions.

Also, see FunctionLibrary, which is a class that allows you to register multiple sets of extension functions with the same JXPathContext.

A custom function can get access to the context in which it is being evaluated. ClassFunctions and PackageFunctions have special support for methods and constructors that have ExpressionContext as the first argument. When such an extension function is invoked, it is passed an object that implements the ExpressionContext interface. The function can then gain access to the "current" object in the currently evaluated context.

public class MyExtensionFunctions { public static boolean isDate(ExpressionContext context){ Pointer pointer = context.getContextNodePointer(); if (pointer == null){ return false; } return pointer.getValue() instanceof Date; } ... }

You can then register this extension function using ClassFunctions and call it like this:

"//.[myext:isDate()]"

This expression will find all nodes of the graph that are dates.

There are two ways a collection can be passed to an extension function: as a NodeSet or as a Collection proper. If the argument type is declared as NodeSet, JXPath will pass a NodeSet object, otherwise it will take values out of the node set and pass those to the function as a regular collection. NodeSet, in addition to providing access to the values, also provides access to pointers. Note that a collection is often passed to an extension function by value and cannot be modified.

public class MyExtensionFunctions { ... public static boolean contains(NodeSet nodeSet, Object value){ Iterator iter = nodeSet.getPointers().iterator(); while (iter.hasNext()) { Pointer item = (Pointer)iter.next(); if (item.getValue().equals(value)){ return true; } } return false; } // Alternative implementation public static boolean contains(List list, Object value){ Iterator iter = list.iterator(); while (iter.hasNext()) { Object item = iter.next(); if (item.getValue().equals(value)){ return true; } } return false; } }

You can call this function to find all people who have a certain phone number:

"/addressBook/contact[myext:contains(phoneNumbers, '555-5555']"

In JXPath version 1.1, a function argument declared as Object would be passed as a NodeSet. In version 1.2, this behavior was changed such that a declared argument type of Object triggers the conversion of the NodeSet to its list of values. The simplest way to avoid this conversion, thereby receiving the untouched NodeSet as the function argument, is to declare the argument as a NodeSet. For such times as this may prove impractical, however, a version 1.1-compatible TypeConverter implementation, (org.apache.commons.jxpath.util.JXPath11CompatibleTypeConverter), has been provided in version 1.3. To enable this:

TypeUtils.setTypeConverter(new JXPath11CompatibleTypeConverter());

A custom function can return a collection of arbitrary objects or a NodeSet. The simple implementation of NodeSet, BasicNodeSet, may come in handy.

JXPath automatically performs the following type convertions:

From type To type Operation
null primitive false, zero
any String Calls toString()
Boolean any Number True = 1, false = 0
any Number any other Number Truncates if needed
String any primitive type Parses the string
array array Creates a new array of the same size and converts every element
array Collection Creates a collection and adds to it all elements of the array. Note that it will only know how to create the collection if the type is a concrete class, List or Set
Collection array Creates a new array the same size as the collection, converts and copies every element of the collection into the array.
Collection Collection Creates a collection and copies the source collection into the new collection. Note that it will only know how to create the collection if the type is a concrete class, List or Set
non-empty array any Takes the first element of the array
and (recursively) converts it to the needed type
non-empty collection any Takes the first element of the array
and (recursively) converts it to the needed type
NodeSet any Extracts a list of values from the NodeSet and (recursively) converts the list to the needed type.

For DOM Documents JXPathContext supports internationalization XPath-style. A locale can be declared on an XML Element like this:

<book xml:lang="fr">Les Miserables</book>

You can then use the lang function in XPath to find nodes for a specific language:

"//book[lang('fr')]

The "lang" boolean function is supported for non-DOM objects as well. It tests the Locale set on the JXPathContext (or the default locale). See JXPathContext.setLocale().

You can also utilize the xml:lang attribute, whose value is the name of the locale, whether in a DOM document or outside.

If you need to use the same configuration (variables, functions, abstract factories, locale, leniency etc.) while interpreting XPaths with different beans, it makes sense to put the configuration in a separate context and specify that context as a parent context every time you allocate a new JXPathContext for a JavaBean. This way you don't need to waste time fully configuring every context.

JXPathContext sharedContext = JXPathContext.newContext(null); sharedContext.getVariables().declareVariable("title", "Java"); sharedContext.setFunctions(new MyExtensionFunctions()); sharedContext.setLocale(Locale.CANADA); sharedContext.setFactory(new MyFactory()); ... JXPathContext context = JXPathContext.newContext(sharedContext, auth); Iterator javaBooks = context.iterate("books[preprocessTitle(title) = $title]");

When JXPath is asked to evaluate an expression for the first time, it compiles it and caches its compiled representation. This mechanism reduces the overhead caused by compilation. However, in some cases JXPath's own caching may not be sufficient- JXPath caches have limited size and they are automatically cleared once in a while.

Here's how you can precompile an XPath expression:

CompiledExpression expr = context.compile(xpath); ... Object value = expr.getValue(context);

Use compiled expressions if you need to satisfy any of the following requirements:

  • There is a relatively small number of XPaths your application works with, and it needs to evaluate those XPaths multiple times.
  • Some XPaths need to be precompiled at initialization time for speed.
  • The syntax of some XPaths needs to be checked before they are used for the first time.

JXPath can be customized on several levels.

  • You can provide custom JXPathBeanInfo objects to customize lists of properties of JavaBeans available to JXPath.
  • You can easily add support for object types similar to Map. All you need to do is implement the DynamicPropertyHandler interface and register the implementation with JXPathIntrospector.
  • You can add support for types of object models JXPath does not support out of the box. An example of such model would be an alternative implementation of XML parse tree (e.g. DOM4J etc). You will need to implement two or three classes to allow JXPath to traverse properties of these custom objects.
  • The most dramatic customization of JXPath can be done at the level of JXPathContextFactory- you can transparently provide an alternative implementation of all top level APIs.

JXPath uses JavaBeans introspection to discover properties of JavaBeans. You can provide alternative property lists by supplying custom JXPathBeanInfo classes (see JXPathBeanInfo).

JXPath uses various implementations of the DynamicPropertyHandler interface to access properties of objects similar to Map.

The org.apache.commons.jxpath.servlet package has several examples of custom DynamicPropertyHandlers.

Architecturally, multiple model support is made possible by the notions of a NodePointer and NodeIterator, which are simple abstract classes that are extended in different ways to traverse graphs of objects of different kinds. The NodePointer/NodeIterator APIs are designed with models like JavaBeans in mind. They directly support indexed collections. As a result, XPaths like "foo[10]" can be executed as "getFoo(9)" or "getFoo()[9]", or "getFoo().get(9)", depending on the type of collection. This flexibility is disguised well enough by the APIs of the abstract classes, so we can still have a natural implementation of traversal of object models, such as DOM, that do not have the same notion of collection.

To add support for a new object model, build custom implementations of NodePointer and NodeIterator as well as NodePointerFactory. Then register the new factory with JXPathContextReferenceImpl.

See existing NodePointerFactories for examples of how that's done:

  • BeanPointerFactory works with JavaBeans
  • DynamicPointerFactory works with Dynamic beans like Map, HttpRequest and such
  • ContainerPointerFactory works with Container objects like XMLDocumentContainer
  • DOMPointerFactory works with DOM Nodes

The core JXPath class, JXPathContext, allows for alternative implementations. This is why instead of allocating JXPathContext directly, you should call a static newContext method. This method will utilize the JXPathContextFactory API to locate a suitable implementation of JXPath. JXPath comes bundled with a default implementation called Reference Implementation.

commons-jxpath-1.3-src/conf/findbugs-exclude-filter.xml100644 0 0 11314 11044113515 20435 0ustar 0 0

JXPath uses JavaBeans introspection to discover properties of JavaBeans. You can provide alternative property lists by supplying custom JXPathBeanInfo classes (see JXPathBeanInfo).

JXPath uses various implementations of the DynamicPropertyHandler interface to access properties of objects similar to Map.

The org.apache.commons.jxpath.servlet package has several examples of custom DynamicPropertyHandlers.

Architecturally, multiple model support is made possible by the notions of a NodePointer and NodeIterator, which are simple abstract classes that are extended in different ways to traverse graphs of objects of different kinds. The NodePointer/NodeIterator APIs are designed with models like JavaBeans in mind. They directly support indexed collections. As a result, XPaths like "foo[10]" can be executed as "getFoo(9)" or "getFoo()[9]", or "getFoo().get(9)", depending on the type of collection. This flexibility is disguised well enough by the APIs of the abstract classes, so we can still have a natural implementation of traversal of object models, such as DOM, that do not have the same notion of collection.

To add support for a new object model, build custom implementations of NodePointer and NodeIterator as well as NodePointerFactory. Then register the new factory with JXPathContextReferenceImpl.

See existing NodePointerFactories for examples of how that's done:

  • BeanPointerFactory works with J