Index: jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/PredicatesTest.java
===================================================================
--- jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/PredicatesTest.java (revision 732102)
+++ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/PredicatesTest.java (working copy)
@@ -80,7 +80,8 @@
* @throws RepositoryException
*/
public void testEquality() throws RepositoryException {
- String stmt = "/" + jcrRoot + "/" + testPath+ "/*[@" + jcrPrimaryType + "='" + nodeTypeName + "']";
+ String stmt =
+ xpathRoot + "/*[@" + jcrPrimaryType + "='" + nodeTypeName + "']";
try {
qm.createQuery(stmt, Query.XPATH);
@@ -95,7 +96,9 @@
* @throws RepositoryException
*/
public void testCombinedOr() throws RepositoryException {
- String stmt = "/" + jcrRoot + "/" + testPath+ "/*[@" + jcrPrimaryType + "='" + nodeTypeName + "' or @" + jcrPrimaryType + "='" + ntBase + "']";
+ String stmt =
+ xpathRoot + "/*[@" + jcrPrimaryType + "='" + nodeTypeName
+ + "' or @" + jcrPrimaryType + "='" + ntBase + "']";
try {
qm.createQuery(stmt, Query.XPATH);
@@ -110,7 +113,8 @@
* @throws RepositoryException
*/
public void testOr() throws RepositoryException {
- String stmt = "/" + jcrRoot + "/" + testPath+ "/*[@" + jcrPrimaryType + " or @" + jcrMixinTypes + "]";
+ String stmt =
+ xpathRoot + "/*[@" + jcrPrimaryType + " or @" + jcrMixinTypes + "]";
try {
qm.createQuery(stmt, Query.XPATH);
@@ -125,7 +129,8 @@
* @throws RepositoryException
*/
public void testAnd() throws RepositoryException {
- String stmt = "/" + jcrRoot + "/" + testPath+ "/*[@" + jcrPrimaryType + " and @" + jcrMixinTypes + "]";
+ String stmt =
+ xpathRoot + "/*[@" + jcrPrimaryType + " and @" + jcrMixinTypes + "]";
try {
qm.createQuery(stmt, Query.XPATH);
@@ -140,7 +145,9 @@
* @throws RepositoryException
*/
public void testCombinedAnd() throws RepositoryException {
- String stmt = "/" + jcrRoot + "/" + testPath+ "/*[@" + jcrPrimaryType + "='" + nodeTypeName + "' and @" + jcrPrimaryType + "='" + ntBase + "']";
+ String stmt =
+ xpathRoot + "/*[@" + jcrPrimaryType + "='" + nodeTypeName
+ + "' and @" + jcrPrimaryType + "='" + ntBase + "']";
try {
qm.createQuery(stmt, Query.XPATH);
Index: jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/XPathQueryLevel2Test.java
===================================================================
--- jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/XPathQueryLevel2Test.java (revision 732102)
+++ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/XPathQueryLevel2Test.java (working copy)
@@ -19,7 +19,6 @@
import javax.jcr.query.Query;
import javax.jcr.query.QueryResult;
import javax.jcr.query.RowIterator;
-import javax.jcr.query.Row;
import javax.jcr.Value;
import javax.jcr.NodeIterator;
@@ -130,11 +129,9 @@
* and excluding with a word
*/
private Statement getFullTextStatement() {
- StringBuffer tmp = new StringBuffer("/");
- tmp.append(jcrRoot).append(testRoot);
- tmp.append("/*[").append(jcrContains);
- tmp.append("(., '\"quick brown\" -cat')]");
- return new Statement(tmp.toString(), Query.XPATH);
+ String xpath =
+ xpathRoot + "/*[" + jcrContains + "(., '\"quick brown\" -cat')]";
+ return new Statement(xpath, Query.XPATH);
}
/**
@@ -142,24 +139,20 @@
* property
*/
private Statement getMultiValueStatement() {
- StringBuffer tmp = new StringBuffer("/");
- tmp.append(jcrRoot).append(testRoot);
- tmp.append("/*[@").append(propertyName2).append(" = 'two'");
- tmp.append(" and @").append(propertyName1).append(" = 'existence']");
- return new Statement(tmp.toString(), Query.XPATH);
+ String xpath =
+ xpathRoot + "/*[@" + propertyName2 + " = 'two' and @"
+ + propertyName1 + " = 'existence']";
+ return new Statement(xpath, Query.XPATH);
}
/**
* @return Statement selecting nodes by its range in {@link #propertyName1}
*/
private Statement getRangeStatement() {
- StringBuffer tmp = new StringBuffer("/");
- tmp.append(jcrRoot).append(testRoot);
- tmp.append("/*[@");
- tmp.append(propertyName1);
- tmp.append(" <= 'b' and @");
- tmp.append(propertyName1);
- tmp.append(" > 'a']");
- return new Statement(tmp.toString(), Query.XPATH);
+ String xpath =
+ xpathRoot + "/*[@" + propertyName1 + " <= 'b' and @"
+ + propertyName1 + " > 'a']";
+ return new Statement(xpath, Query.XPATH);
}
+
}
\ No newline at end of file
Index: jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/QueryResultNodeIteratorTest.java
===================================================================
--- jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/QueryResultNodeIteratorTest.java (revision 732102)
+++ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/QueryResultNodeIteratorTest.java (working copy)
@@ -54,7 +54,7 @@
* if getSize() returns -1 (unavailable).
*/
public void testGetSize() throws RepositoryException, NotExecutableException {
- NodeIterator it = execute(testPath + "//*", Query.XPATH).getNodes();
+ NodeIterator it = execute(xpathRoot + "//*", Query.XPATH).getNodes();
long size = testRootNode.getNodes().getSize();
if (size != -1) {
long count = 0;
@@ -72,7 +72,7 @@
* Tests the method NodeIterator.getPosition().
*/
public void testGetPosition() throws RepositoryException {
- QueryResult rs = execute(testPath + "//*", Query.XPATH);
+ QueryResult rs = execute(xpathRoot + "//*", Query.XPATH);
// getPosition initially returns 0
NodeIterator it = rs.getNodes();
@@ -91,7 +91,7 @@
* NodeIterator.
*/
public void testGetPositionEmptyIterator() throws RepositoryException {
- QueryResult rs = execute(testPath + "/" + nodeName4, Query.XPATH);
+ QueryResult rs = execute(xpathRoot + "/" + nodeName4, Query.XPATH);
NodeIterator it = rs.getNodes();
assertFalse("NodeIterator must be empty.", it.hasNext());
@@ -105,7 +105,7 @@
* available.
*/
public void testNoSuchElementException() throws RepositoryException {
- NodeIterator it = execute(testPath + "//*", Query.XPATH).getNodes();
+ NodeIterator it = execute(xpathRoot + "//*", Query.XPATH).getNodes();
while (it.hasNext()) {
it.nextNode();
}
@@ -121,7 +121,7 @@
* Tests if {@link javax.jcr.NodeIterator#skip(long)} works correctly.
*/
public void testSkip() throws RepositoryException {
- String query = testPath + "//*";
+ String query = xpathRoot + "//*";
QueryResult rs = execute(query, Query.XPATH);
NodeIterator it = rs.getNodes();
Index: jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/AbstractQueryTest.java
===================================================================
--- jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/AbstractQueryTest.java (revision 732102)
+++ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/AbstractQueryTest.java (working copy)
@@ -18,6 +18,7 @@
import org.apache.jackrabbit.test.AbstractJCRTest;
import org.apache.jackrabbit.test.NotExecutableException;
+import org.apache.jackrabbit.util.ISO9075;
import javax.jcr.query.QueryResult;
import javax.jcr.query.RowIterator;
@@ -64,6 +65,14 @@
protected String jcrDeref;
/**
+ * The string /${jcrRoot}${testRoot} with all components of the test path
+ * properly escaped for XPath.
+ *
+ * @see JCR-714
+ */
+ protected String xpathRoot;
+
+ /**
* Set-up the configuration values used for the test. Per default retrieves
* a session, configures testRoot, and nodetype and checks if the query
* language for the current language is available.
@@ -75,6 +84,7 @@
jcrRoot = superuser.getNamespacePrefix(NS_JCR_URI) + ":root";
jcrContains = superuser.getNamespacePrefix(NS_JCR_URI) + ":contains";
jcrDeref = superuser.getNamespacePrefix(NS_JCR_URI) + ":deref";
+ xpathRoot = "/" + jcrRoot + "/" + ISO9075.encodePath(testPath);
}
/**
Index: jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/AbstractOrderByTest.java
===================================================================
--- jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/AbstractOrderByTest.java (revision 732102)
+++ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/AbstractOrderByTest.java (working copy)
@@ -110,7 +110,7 @@
String sql = "SELECT " + escapeIdentifierForSQL(propertyName1) + " FROM " + escapeIdentifierForSQL(testNodeType) + " WHERE " +
jcrPath + " LIKE '" + testRoot + "/%' ORDER BY " + escapeIdentifierForSQL(propertyName1);
- String xpath = "/" + jcrRoot + testRoot + "/*[@jcr:primaryType='" + testNodeType + "'] order by @" + propertyName1;
+ String xpath = xpathRoot + "/*[@jcr:primaryType='" + testNodeType + "'] order by @" + propertyName1;
Query q;
QueryResult result;
if (checkSQL) {
Index: jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/XPathDocOrderTest.java
===================================================================
--- jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/XPathDocOrderTest.java (revision 732102)
+++ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/XPathDocOrderTest.java (working copy)
@@ -53,14 +53,12 @@
* For configuration description see {@link XPathDocOrderTest}.
*/
public void testDocOrderPositionFunction() throws Exception {
- StringBuffer tmp = new StringBuffer("/");
- tmp.append(jcrRoot).append(testRoot).append("/*");
- tmp.append("[position()=2]");
+ String xpath = xpathRoot + "/*[position()=2]";
String resultPath = "";
for (NodeIterator nodes = testRootNode.getNodes(); nodes.hasNext() && nodes.getPosition() < 2;) {
resultPath = nodes.nextNode().getPath();
}
- docOrderTest(new Statement(tmp.toString(), Query.XPATH), resultPath);
+ docOrderTest(new Statement(xpath, Query.XPATH), resultPath);
}
/**
@@ -70,14 +68,12 @@
* For configuration description see {@link XPathDocOrderTest}.
*/
public void testDocOrderPositionIndex() throws Exception {
- StringBuffer tmp = new StringBuffer("/");
- tmp.append(jcrRoot).append(testRoot).append("/*");
- tmp.append("[2]");
+ String xpath = xpathRoot + "/*[2]";
String resultPath = "";
for (NodeIterator nodes = testRootNode.getNodes(); nodes.hasNext() && nodes.getPosition() < 2;) {
resultPath = nodes.nextNode().getPath();
}
- docOrderTest(new Statement(tmp.toString(), Query.XPATH), resultPath);
+ docOrderTest(new Statement(xpath, Query.XPATH), resultPath);
}
/**
@@ -86,14 +82,12 @@
* For configuration description see {@link XPathDocOrderTest}.
*/
public void testDocOrderLastFunction() throws Exception {
- StringBuffer tmp = new StringBuffer("/");
- tmp.append(jcrRoot).append(testRoot).append("/*");
- tmp.append("[position()=last()]");
+ String xpath = xpathRoot + "/*[position()=last()]";
String resultPath = "";
for (NodeIterator nodes = testRootNode.getNodes(); nodes.hasNext();) {
resultPath = nodes.nextNode().getPath();
}
- docOrderTest(new Statement(tmp.toString(), Query.XPATH), resultPath);
+ docOrderTest(new Statement(xpath, Query.XPATH), resultPath);
}
/**
@@ -102,11 +96,9 @@
* For configuration description see {@link XPathDocOrderTest}.
*/
public void testDocOrderFirstFunction() throws Exception {
- StringBuffer tmp = new StringBuffer("/");
- tmp.append(jcrRoot).append(testRoot).append("/*");
- tmp.append("[first()]");
+ String xpath = xpathRoot + "/*[first()]";
String resultPath = testRootNode.getNodes().nextNode().getPath();
- docOrderTest(new Statement(tmp.toString(), Query.XPATH), resultPath);
+ docOrderTest(new Statement(xpath, Query.XPATH), resultPath);
}
//-----------------------------< internal >---------------------------------
Index: jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/XPathOrderByTest.java
===================================================================
--- jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/XPathOrderByTest.java (revision 732102)
+++ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/XPathOrderByTest.java (working copy)
@@ -44,13 +44,8 @@
protected void setUp() throws Exception {
isReadOnly = true;
super.setUp();
- StringBuffer tmp = new StringBuffer("/");
- tmp.append(jcrRoot).append(testRoot);
- tmp.append("/*[@");
- tmp.append(propertyName1);
- tmp.append("] order by @");
- tmp.append(propertyName1);
- baseStatement = tmp.toString();
+ baseStatement =
+ xpathRoot + "/*[@" + propertyName1 + "] order by @" + propertyName1;
}
/**
Index: jackrabbit-jcr-tests/pom.xml
===================================================================
--- jackrabbit-jcr-tests/pom.xml (revision 732102)
+++ jackrabbit-jcr-tests/pom.xml (working copy)
@@ -63,6 +63,11 @@
concurrent
concurrent
+
+ org.apache.jackrabbit
+ jackrabbit-jcr-commons
+ 1.6-SNAPSHOT
+