jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joshua Levy <l...@csl.sri.com>
Subject Quote escaping in jcr:contains searchexp
Date Sun, 17 Sep 2006 21:22:00 GMT
Hi,
I'm trying to properly escape characters in an XPath
query using jcr:contains.  Based on Sec 6.6.5.2 of
the JCR spec it seemed like one should use single
quotes and backslash escape some characters (", ', -, \).

Queries like this work for me:
  //element(*, my:record)[jcr:contains(.,'blah\-blah')] order by jcr:score() descending
  //element(*, my:record)[jcr:contains(.,'blah\"blah')] order by jcr:score() descending
But
  //element(*, my:record)[jcr:contains(.,'blah\'blah')] order by jcr:score() descending
throws an exception (below).

Am I not doing the escaping correctly, or is it a bug?

Also, this brings up broader question:  Are there any
libraries people use to help formulate (JCR) XPath queries,
that assist with such syntax details?  It seems rather
error-prone to be constructing them by hand, particularly
with character escaping (more than one kind), etc.

Many thanks!

Joshua




javax.jcr.query.InvalidQueryException: Lexical error at line 1, column 110.  Encountered:
<EOF> after : "\')] order by jcr:score() descending return $v": Lexical error at line
1, column 110.  Encountered: <EOF> after : "\')] order by jcr:score() descending return
$v": Lexical error at line 1, column 110.  Encountered: <EOF> after : "\')] order by
jcr:score() descending return $v"
    at org.apache.jackrabbit.core.query.xpath.XPathQueryBuilder.<init>(XPathQueryBuilder.java:249)
    at org.apache.jackrabbit.core.query.xpath.XPathQueryBuilder.createQuery(XPathQueryBuilder.java:275)
    at org.apache.jackrabbit.core.query.xpath.QueryBuilder.createQueryTree(QueryBuilder.java:36)
    at org.apache.jackrabbit.core.query.QueryParser.parse(QueryParser.java:53)
    at org.apache.jackrabbit.core.query.lucene.QueryImpl.<init>(QueryImpl.java:125)
    at org.apache.jackrabbit.core.query.lucene.SearchIndex.createExecutableQuery(SearchIndex.java:322)
    at org.apache.jackrabbit.core.query.QueryImpl.init(QueryImpl.java:92)
    at org.apache.jackrabbit.core.SearchManager.createQuery(SearchManager.java:337)
    at org.apache.jackrabbit.core.query.QueryManagerImpl.createQuery(QueryManagerImpl.java:86)
...
Caused by: org.apache.jackrabbit.core.query.xpath.TokenMgrError: Lexical error at line 1,
column 110.  Encountered: <EOF> after : "\')] order by jcr:score() descending return
$v"
    at org.apache.jackrabbit.core.query.xpath.XPathTokenManager.getNextToken(XPathTokenManager.java:14546)
    at org.apache.jackrabbit.core.query.xpath.XPath.jj_ntk(XPath.java:9187)
    at org.apache.jackrabbit.core.query.xpath.XPath.PredicateList(XPath.java:5195)
    at org.apache.jackrabbit.core.query.xpath.XPath.FilterExpr(XPath.java:5184)
    at org.apache.jackrabbit.core.query.xpath.XPath.StepExpr(XPath.java:4627)
    at org.apache.jackrabbit.core.query.xpath.XPath.RelativePathExpr(XPath.java:4511)
    at org.apache.jackrabbit.core.query.xpath.XPath.PathExpr(XPath.java:4482)
    at org.apache.jackrabbit.core.query.xpath.XPath.ValueExpr(XPath.java:4125)
    at org.apache.jackrabbit.core.query.xpath.XPath.UnaryExpr(XPath.java:4032)
    at org.apache.jackrabbit.core.query.xpath.XPath.CastExpr(XPath.java:3935)
    at org.apache.jackrabbit.core.query.xpath.XPath.CastableExpr(XPath.java:3898)
    at org.apache.jackrabbit.core.query.xpath.XPath.TreatExpr(XPath.java:3861)
    at org.apache.jackrabbit.core.query.xpath.XPath.InstanceofExpr(XPath.java:3824)
    at org.apache.jackrabbit.core.query.xpath.XPath.IntersectExceptExpr(XPath.java:3748)
    at org.apache.jackrabbit.core.query.xpath.XPath.UnionExpr(XPath.java:3672)
    at org.apache.jackrabbit.core.query.xpath.XPath.MultiplicativeExpr(XPath.java:3586)
    at org.apache.jackrabbit.core.query.xpath.XPath.AdditiveExpr(XPath.java:3510)
    at org.apache.jackrabbit.core.query.xpath.XPath.RangeExpr(XPath.java:3451)
    at org.apache.jackrabbit.core.query.xpath.XPath.ComparisonExpr(XPath.java:3353)
    at org.apache.jackrabbit.core.query.xpath.XPath.AndExpr(XPath.java:3290)
    at org.apache.jackrabbit.core.query.xpath.XPath.OrExpr(XPath.java:3227)
    at org.apache.jackrabbit.core.query.xpath.XPath.ExprSingle(XPath.java:2214)
    at org.apache.jackrabbit.core.query.xpath.XPath.FunctionCall(XPath.java:5677)
    at org.apache.jackrabbit.core.query.xpath.XPath.PrimaryExpr(XPath.java:5275)
    at org.apache.jackrabbit.core.query.xpath.XPath.FilterExpr(XPath.java:5183)
    at org.apache.jackrabbit.core.query.xpath.XPath.StepExpr(XPath.java:4627)
    at org.apache.jackrabbit.core.query.xpath.XPath.RelativePathExpr(XPath.java:4511)
    at org.apache.jackrabbit.core.query.xpath.XPath.PathExpr(XPath.java:4482)
    at org.apache.jackrabbit.core.query.xpath.XPath.ValueExpr(XPath.java:4125)
    at org.apache.jackrabbit.core.query.xpath.XPath.UnaryExpr(XPath.java:4032)
    at org.apache.jackrabbit.core.query.xpath.XPath.CastExpr(XPath.java:3935)
    at org.apache.jackrabbit.core.query.xpath.XPath.CastableExpr(XPath.java:3898)
    at org.apache.jackrabbit.core.query.xpath.XPath.TreatExpr(XPath.java:3861)
    at org.apache.jackrabbit.core.query.xpath.XPath.InstanceofExpr(XPath.java:3824)
    at org.apache.jackrabbit.core.query.xpath.XPath.IntersectExceptExpr(XPath.java:3748)
    at org.apache.jackrabbit.core.query.xpath.XPath.UnionExpr(XPath.java:3672)
    at org.apache.jackrabbit.core.query.xpath.XPath.MultiplicativeExpr(XPath.java:3586)
    at org.apache.jackrabbit.core.query.xpath.XPath.AdditiveExpr(XPath.java:3510)
    at org.apache.jackrabbit.core.query.xpath.XPath.RangeExpr(XPath.java:3451)
    at org.apache.jackrabbit.core.query.xpath.XPath.ComparisonExpr(XPath.java:3353)
    at org.apache.jackrabbit.core.query.xpath.XPath.AndExpr(XPath.java:3290)
    at org.apache.jackrabbit.core.query.xpath.XPath.OrExpr(XPath.java:3227)
    at org.apache.jackrabbit.core.query.xpath.XPath.ExprSingle(XPath.java:2214)
    at org.apache.jackrabbit.core.query.xpath.XPath.Expr(XPath.java:2094)
    at org.apache.jackrabbit.core.query.xpath.XPath.Predicate(XPath.java:5233)
    at org.apache.jackrabbit.core.query.xpath.XPath.PredicateList(XPath.java:5203)
    at org.apache.jackrabbit.core.query.xpath.XPath.AxisStep(XPath.java:4707)
    at org.apache.jackrabbit.core.query.xpath.XPath.StepExpr(XPath.java:4597)
    at org.apache.jackrabbit.core.query.xpath.XPath.RelativePathExpr(XPath.java:4511)
    at org.apache.jackrabbit.core.query.xpath.XPath.PathExpr(XPath.java:4417)
    at org.apache.jackrabbit.core.query.xpath.XPath.ValueExpr(XPath.java:4125)
    at org.apache.jackrabbit.core.query.xpath.XPath.UnaryExpr(XPath.java:4032)
    at org.apache.jackrabbit.core.query.xpath.XPath.CastExpr(XPath.java:3935)
    at org.apache.jackrabbit.core.query.xpath.XPath.CastableExpr(XPath.java:3898)
    at org.apache.jackrabbit.core.query.xpath.XPath.TreatExpr(XPath.java:3861)
    at org.apache.jackrabbit.core.query.xpath.XPath.InstanceofExpr(XPath.java:3824)
    at org.apache.jackrabbit.core.query.xpath.XPath.IntersectExceptExpr(XPath.java:3748)
    at org.apache.jackrabbit.core.query.xpath.XPath.UnionExpr(XPath.java:3672)
    at org.apache.jackrabbit.core.query.xpath.XPath.MultiplicativeExpr(XPath.java:3586)
    at org.apache.jackrabbit.core.query.xpath.XPath.AdditiveExpr(XPath.java:3510)
    at org.apache.jackrabbit.core.query.xpath.XPath.RangeExpr(XPath.java:3451)
    at org.apache.jackrabbit.core.query.xpath.XPath.ComparisonExpr(XPath.java:3353)
    at org.apache.jackrabbit.core.query.xpath.XPath.AndExpr(XPath.java:3290)
    at org.apache.jackrabbit.core.query.xpath.XPath.OrExpr(XPath.java:3227)
    at org.apache.jackrabbit.core.query.xpath.XPath.ExprSingle(XPath.java:2214)
    at org.apache.jackrabbit.core.query.xpath.XPath.ForClause(XPath.java:2337)
    at org.apache.jackrabbit.core.query.xpath.XPath.FLWORExpr(XPath.java:2233)
    at org.apache.jackrabbit.core.query.xpath.XPath.ExprSingle(XPath.java:2133)
    at org.apache.jackrabbit.core.query.xpath.XPath.Expr(XPath.java:2094)
    at org.apache.jackrabbit.core.query.xpath.XPath.QueryBody(XPath.java:2066)
    at org.apache.jackrabbit.core.query.xpath.XPath.MainModule(XPath.java:512)
    at org.apache.jackrabbit.core.query.xpath.XPath.Module(XPath.java:387)
    at org.apache.jackrabbit.core.query.xpath.XPath.QueryList(XPath.java:151)
    at org.apache.jackrabbit.core.query.xpath.XPath.XPath2(XPath.java:118)
    at org.apache.jackrabbit.core.query.xpath.XPathQueryBuilder.<init>(XPathQueryBuilder.java:242)
    ... 27 more

Mime
View raw message