jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Neale" <michael.ne...@gmail.com>
Subject Re: Quote escaping in jcr:contains searchexp
Date Mon, 18 Sep 2006 07:46:19 GMT
I would be keen to hear about this.

Is there or should there be a utility class to escape things correctly for
XPath? Kind of like URLEncoder but for xpath?

On 9/17/06, Joshua Levy <levy@csl.sri.com> wrote:
>
> 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)
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message