You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by "Niu, Xuetao" <Xu...@fiserv.com> on 2010/01/26 19:38:33 UTC

Jackrabbit2.0 how to xpath-query frozen nodes?

Hello,

I would like to execute xpath query on versioned node, but
QueryManager/Query interfaces do not seem to support relative xpath
query, which is puzzling me. 

I tried to call the getPath() of a frozen node in order to get the
absolute path and then append my relative query, but the QueryManager
doesn't allow such xpath:

/jcr:system/jcr:versionStorage/fd/fe/06/fdfe0612-92ea-4e2f-94d7-cd81e5b5
91c3/jcr:rootVersion/jcr:frozenNode//tenant:_15/env:testEnv

The error trace below doesn't show what the problem might be with my
xpath. Is my xpath wrong syntactically? Or JCR/Jackrabbit doesn't allow
xpath-query on frozen node at all?

Any of your help would be really great!
	
Caused by: javax.jcr.query.InvalidQueryException: Parse error: data is
not a RelationQueryNode
	at
org.apache.jackrabbit.spi.commons.query.xpath.XPathQueryBuilder.visit(XP
athQueryBuilder.java:508)
	at
org.apache.jackrabbit.spi.commons.query.xpath.SimpleNode.jjtAccept(Simpl
eNode.java:81)
	at
org.apache.jackrabbit.spi.commons.query.xpath.SimpleNode.childrenAccept(
SimpleNode.java:90)
	at
org.apache.jackrabbit.spi.commons.query.xpath.XPathQueryBuilder.visit(XP
athQueryBuilder.java:559)
	at
org.apache.jackrabbit.spi.commons.query.xpath.SimpleNode.jjtAccept(Simpl
eNode.java:81)
	at
org.apache.jackrabbit.spi.commons.query.xpath.SimpleNode.childrenAccept(
SimpleNode.java:90)
	at
org.apache.jackrabbit.spi.commons.query.xpath.XPathQueryBuilder.visit(XP
athQueryBuilder.java:559)
	at
org.apache.jackrabbit.spi.commons.query.xpath.SimpleNode.jjtAccept(Simpl
eNode.java:81)
	at
org.apache.jackrabbit.spi.commons.query.xpath.SimpleNode.childrenAccept(
SimpleNode.java:90)
	at
org.apache.jackrabbit.spi.commons.query.xpath.XPathQueryBuilder.visit(XP
athQueryBuilder.java:559)
	at
org.apache.jackrabbit.spi.commons.query.xpath.SimpleNode.jjtAccept(Simpl
eNode.java:81)
	at
org.apache.jackrabbit.spi.commons.query.xpath.SimpleNode.childrenAccept(
SimpleNode.java:90)
	at
org.apache.jackrabbit.spi.commons.query.xpath.XPathQueryBuilder.visit(XP
athQueryBuilder.java:559)
	at
org.apache.jackrabbit.spi.commons.query.xpath.SimpleNode.jjtAccept(Simpl
eNode.java:81)
	at
org.apache.jackrabbit.spi.commons.query.xpath.SimpleNode.childrenAccept(
SimpleNode.java:90)
	at
org.apache.jackrabbit.spi.commons.query.xpath.XPathQueryBuilder.visit(XP
athQueryBuilder.java:559)
	at
org.apache.jackrabbit.spi.commons.query.xpath.SimpleNode.jjtAccept(Simpl
eNode.java:81)
	at
org.apache.jackrabbit.spi.commons.query.xpath.SimpleNode.childrenAccept(
SimpleNode.java:90)
	at
org.apache.jackrabbit.spi.commons.query.xpath.XPathQueryBuilder.visit(XP
athQueryBuilder.java:559)
	at
org.apache.jackrabbit.spi.commons.query.xpath.SimpleNode.jjtAccept(Simpl
eNode.java:81)
	at
org.apache.jackrabbit.spi.commons.query.xpath.SimpleNode.childrenAccept(
SimpleNode.java:90)
	at
org.apache.jackrabbit.spi.commons.query.xpath.XPathQueryBuilder.visit(XP
athQueryBuilder.java:559)
	at
org.apache.jackrabbit.spi.commons.query.xpath.SimpleNode.jjtAccept(Simpl
eNode.java:81)
	at
org.apache.jackrabbit.spi.commons.query.xpath.SimpleNode.childrenAccept(
SimpleNode.java:90)
	at
org.apache.jackrabbit.spi.commons.query.xpath.XPathQueryBuilder.createPa
thQueryNode(XPathQueryBuilder.java:762)
	at
org.apache.jackrabbit.spi.commons.query.xpath.XPathQueryBuilder.visit(XP
athQueryBuilder.java:373)
	at
org.apache.jackrabbit.spi.commons.query.xpath.SimpleNode.jjtAccept(Simpl
eNode.java:81)
	at
org.apache.jackrabbit.spi.commons.query.xpath.XPathQueryBuilder.<init>(X
PathQueryBuilder.java:298)
	at
org.apache.jackrabbit.spi.commons.query.xpath.XPathQueryBuilder.createQu
ery(XPathQueryBuilder.java:332)
	at
org.apache.jackrabbit.spi.commons.query.xpath.QueryBuilder.createQueryTr
ee(QueryBuilder.java:39)
	at
org.apache.jackrabbit.spi.commons.query.QueryParser.parse(QueryParser.ja
va:57)
	at
org.apache.jackrabbit.core.query.lucene.QueryImpl.<init>(QueryImpl.java:
95)
	at
org.apache.jackrabbit.core.query.lucene.SearchIndex.createExecutableQuer
y(SearchIndex.java:668)
	at
org.apache.jackrabbit.core.query.QueryImpl.init(QueryImpl.java:114)
	at
org.apache.jackrabbit.core.SearchManager.createQuery(SearchManager.java:
250)
	at
org.apache.jackrabbit.core.query.QueryManagerImpl$QueryFactoryImpl$2.cre
ateQuery(QueryManagerImpl.java:206)
	at
org.apache.jackrabbit.core.query.CompoundQueryFactory.createQuery(Compou
ndQueryFactory.java:67)
	at
org.apache.jackrabbit.core.query.QueryManagerImpl.createQuery(QueryManag
erImpl.java:98)
	... 24 more

Regards,

Xuetao

Re: Jackrabbit2.0 xpath functions

Posted by Alexander Klimetschek <ak...@day.com>.
On Fri, Jan 29, 2010 at 11:40, Niu, Xuetao <Xu...@fiserv.com> wrote:
> Hello,
>
> I am wondering what are the standard xpath functions supported by
> Jackrabbit2.0, and what are also supported by Jackrabbit2.0 but not
> standard xpath functions.
>
> Especially, how to select all nodes whose namespace is "abc:"? I tried
> to use "//abc:*" as xpath, but jackrabbit throws exception, I also tried
> to use "//*[starts-with(name(),'abc:')]" and
> "//*[fn:starts-with(name(),'abc:')]", both being complained by
> jackrabbit as invalid xpath.

Supported axes are only child (/), descendant-or-self (abbreviated
syntax: //) and attribute (@). See the JCR 1.0 spec [1], section
6.6.4.6 [2]. Please also note that JCR 2.0 (in Jackrabbit 2.0)
deprecated XPath support, but Jackrabbit will keep the XPath option.

[1] http://jcp.org/en/jsr/detail?id=170
[2] http://www.day.com/specs/jcr/1.0/6.6.4.6_Axes.html

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com

Jackrabbit2.0 xpath functions

Posted by "Niu, Xuetao" <Xu...@fiserv.com>.
Hello,

I am wondering what are the standard xpath functions supported by
Jackrabbit2.0, and what are also supported by Jackrabbit2.0 but not
standard xpath functions.

Especially, how to select all nodes whose namespace is "abc:"? I tried
to use "//abc:*" as xpath, but jackrabbit throws exception, I also tried
to use "//*[starts-with(name(),'abc:')]" and
"//*[fn:starts-with(name(),'abc:')]", both being complained by
jackrabbit as invalid xpath.

Any help would be appreciated!

Xuetao

Re: Jackrabbit2.0 how to xpath-query frozen nodes?

Posted by Sébastien Launay <se...@gmail.com>.
2010/1/27 Alexander Klimetschek <ak...@day.com>
>
> On Tue, Jan 26, 2010 at 19:38, Niu, Xuetao <Xu...@fiserv.com> wrote:
> > /jcr:system/jcr:versionStorage/fd/fe/06/fdfe0612-92ea-4e2f-94d7-cd81e5b5
> > 91c3/jcr:rootVersion/jcr:frozenNode//tenant:_15/env:testEnv

Using //*[@jcr:uuid = '<frozenNode.getIdentifier()>']//tenant:_15/env:testEnv
will be simpler to implement and more efficient with Jackrabbit [1].

[1] http://wiki.apache.org/jackrabbit/Performance

--
Sébastien Launay

Re: Jackrabbit2.0 how to xpath-query frozen nodes?

Posted by Alexander Klimetschek <ak...@day.com>.
On Tue, Jan 26, 2010 at 19:38, Niu, Xuetao <Xu...@fiserv.com> wrote:
> /jcr:system/jcr:versionStorage/fd/fe/06/fdfe0612-92ea-4e2f-94d7-cd81e5b5
> 91c3/jcr:rootVersion/jcr:frozenNode//tenant:_15/env:testEnv

The "06" node step is the problem, it must be escaped. Xpath/XML names
cannot start with numbers, hence they must be escaped. See this page
for more info: http://wiki.apache.org/jackrabbit/EncodingAndEscaping#Encoding_path_in_queries

> The error trace below doesn't show what the problem might be with my
> xpath. ...
> Caused by: javax.jcr.query.InvalidQueryException: Parse error: data is
> not a RelationQueryNode

Yes, the exception could be a little bit better to at least show the
place where it fails.

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com