You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Mario-Leander Reimer <le...@vva-networks.de> on 2009/03/02 16:29:30 UTC

Problem with ISO9075 encoded name in XPath Query?

Hi Jackrabbit users,

I have a problem with an XPath query in our system when the path contains spaces. Well, it does not really contain spaces. When we save the node, we encode the name and path with the ISO9075 class (org.apache.jackrabbit.util.ISO9075)

So the name "Test Company" will result in "Test_x0020_Company"

We then construct an XPath query, something like

/jcr:root/application/com/testcompany/Test_x0020_Company//element(*)[type='IMAGE']

it never returns any results. But if I have a path that has no ISO9075 encoded parts like

/jcr:root/application/com/testcompany/TestCompany//element(*)[type='IMAGE']

this query works and returns nodes.

Any ideas? What am I doing wrong?

Thanks,
Leander

VVA Networks GmbH

Mario-Leander Reimer
Dipl.-Inf. (FH)
Teamleitung Publishing Solutions
---------------------------------------------------------------------------
VVA Networks GmbH
: medien mit zukunft
Geisenhausenerstra?e 15-17
81379 M?nchen
Deutschland
---------------------------------------------------------------------------
Fon:    +49 89 2000375-610
Fax:    +49 89 2000375-699
Mobil:  +49 173 5883541
---------------------------------------------------------------------------
leander.reimer@vva-networks.de
www.vva-networks.de

-----------------------------------------------------------------------
HRB 33884 D?sseldorf
Gesch?ftsf?hrer Rolf Christian Kassel
-----------------------------------------------------------------------
Ein Unternehmen der VVA Kommunikation
http://www.vva.de
-----------------------------------------------------------------------
omnisuite(r) - integrate. automate. communicate.
http://www.omnisuite.de
-----------------------------------------------------------------------

Diese Nachricht (inklusive aller Anh?nge) ist vertraulich. Sie darf
ausschlie?lich durch den vorgesehenen Empf?nger und Adressaten gelesen,
kopiert oder genutzt werden. Sollten Sie diese Nachricht versehentlich
erhalten haben, bitten wir, den Absender (durch Antwort-E-Mail) hiervon
unverz?glich zu informieren und die Nachricht zu l?schen. Jede unerlaubte
Nutzung oder Weitergabe des Inhalts dieser Nachricht, sei es vollst?ndig
oder teilweise, ist unzul?ssig.

This message (including any attachments) is confidential and may be
privileged. It may be read, copied and used only by the intended recipient.
If you have received it in error please contact the sender (by return
E-Mail) immediately and delete this message. Any unauthorised use or
dissemination of this message in whole or in part is strictly prohibited.

AW: AW: Problem with ISO9075 encoded name in XPath Query?

Posted by Mario-Leander Reimer <le...@vva-networks.de>.
Hi,

> The node name can, I think.
Yes, you are right!

> This may be a bad idea, depending on the use case; for instance, when
> you allow WebDAV access to the store, people will only see the encoded
> names...
Hmm, good thought, currently we have no WebDAV needs, but perhaps later. And then I would have to write a special WebDAV treatment that decodes the names.

Perhaps I should think this over once more.

BR,
Leander


>
> BR, Julian





VVA Networks GmbH

Mario-Leander Reimer
Dipl.-Inf. (FH)
Teamleitung Publishing Solutions
---------------------------------------------------------------------------
VVA Networks GmbH
: medien mit zukunft
Geisenhausenerstra?e 15-17
81379 M?nchen
Deutschland
---------------------------------------------------------------------------
Fon:    +49 89 2000375-610
Fax:    +49 89 2000375-699
Mobil:  +49 173 5883541
---------------------------------------------------------------------------
leander.reimer@vva-networks.de
www.vva-networks.de

-----------------------------------------------------------------------
HRB 33884 D?sseldorf
Gesch?ftsf?hrer Rolf Christian Kassel
-----------------------------------------------------------------------
Ein Unternehmen der VVA Kommunikation
http://www.vva.de
-----------------------------------------------------------------------
omnisuite(r) - integrate. automate. communicate.
http://www.omnisuite.de
-----------------------------------------------------------------------

Diese Nachricht (inklusive aller Anh?nge) ist vertraulich. Sie darf
ausschlie?lich durch den vorgesehenen Empf?nger und Adressaten gelesen,
kopiert oder genutzt werden. Sollten Sie diese Nachricht versehentlich
erhalten haben, bitten wir, den Absender (durch Antwort-E-Mail) hiervon
unverz?glich zu informieren und die Nachricht zu l?schen. Jede unerlaubte
Nutzung oder Weitergabe des Inhalts dieser Nachricht, sei es vollst?ndig
oder teilweise, ist unzul?ssig.

This message (including any attachments) is confidential and may be
privileged. It may be read, copied and used only by the intended recipient.
If you have received it in error please contact the sender (by return
E-Mail) immediately and delete this message. Any unauthorised use or
dissemination of this message in whole or in part is strictly prohibited.

Re: AW: Problem with ISO9075 encoded name in XPath Query?

Posted by Julian Reschke <ju...@gmx.de>.
Mario-Leander Reimer wrote:
> Hi Dave,
> 
> I encode the name because and did not want to restrict the user in any way regarding allowed characters for the "name" of an entity (which I use as node name) I store in JCR.
> Otherwise I would have to manage 2 names, the "artificial" valid JCR node name and the "real name" for the entity the user initially entered, and keep both in-synch.
> Same for nt:files a user can upload: a filename can start with a letter, the node name can't. So either strip the invalid characters and lose the original filename, or encode it somehow.

The node name can, I think.

> So I figured it's best to always encode every name, not matter what. Well, now I additionally have to encode the XPath query.


This may be a bad idea, depending on the use case; for instance, when 
you allow WebDAV access to the store, people will only see the encoded 
names...

BR, Julian

AW: Problem with ISO9075 encoded name in XPath Query?

Posted by Mario-Leander Reimer <le...@vva-networks.de>.
Hi Dave,

I encode the name because and did not want to restrict the user in any way regarding allowed characters for the "name" of an entity (which I use as node name) I store in JCR.
Otherwise I would have to manage 2 names, the "artificial" valid JCR node name and the "real name" for the entity the user initially entered, and keep both in-synch.
Same for nt:files a user can upload: a filename can start with a letter, the node name can't. So either strip the invalid characters and lose the original filename, or encode it somehow.

So I figured it's best to always encode every name, not matter what. Well, now I additionally have to encode the XPath query.

Thanks again,
BR,
Leander


> -----Ursprüngliche Nachricht-----
> Von: Dave Brosius [mailto:dbrosius@mebigfatguy.com]
> Gesendet: Montag, 2. März 2009 17:09
> An: users@jackrabbit.apache.org
> Betreff: Re: Problem with ISO9075 encoded name in XPath Query?
>
> Don't encode the name when you save it.
> Only encode the name when using xpath.
>
>
> ----- Original Message -----
> From: "Mario-Leander Reimer" <le...@vva-networks.de>
> To: <us...@jackrabbit.apache.org>
> Sent: Monday, March 02, 2009 10:29 AM
> Subject: Problem with ISO9075 encoded name in XPath Query?
>
>
> Hi Jackrabbit users,
>
> I have a problem with an XPath query in our system when the path
> contains
> spaces. Well, it does not really contain spaces. When we save the node,
> we
> encode the name and path with the ISO9075 class
> (org.apache.jackrabbit.util.ISO9075)
>
> So the name "Test Company" will result in "Test_x0020_Company"
>
> We then construct an XPath query, something like
>
> /jcr:root/application/com/testcompany/Test_x0020_Company//element(*)[ty
> pe='IMAGE']
>
> it never returns any results. But if I have a path that has no ISO9075
> encoded parts like
>
> /jcr:root/application/com/testcompany/TestCompany//element(*)[type='IMA
> GE']
>
> this query works and returns nodes.
>
> Any ideas? What am I doing wrong?
>
> Thanks,
> Leander
>
> VVA Networks GmbH
>
> Mario-Leander Reimer
> Dipl.-Inf. (FH)
> Teamleitung Publishing Solutions
> -----------------------------------------------------------------------
> ----
> VVA Networks GmbH
> : medien mit zukunft
> Geisenhausenerstra?e 15-17
> 81379 M?nchen
> Deutschland
> -----------------------------------------------------------------------
> ----
> Fon:    +49 89 2000375-610
> Fax:    +49 89 2000375-699
> Mobil:  +49 173 5883541
> -----------------------------------------------------------------------
> ----
> leander.reimer@vva-networks.de
> www.vva-networks.de
>
> -----------------------------------------------------------------------
> HRB 33884 D?sseldorf
> Gesch?ftsf?hrer Rolf Christian Kassel
> -----------------------------------------------------------------------
> Ein Unternehmen der VVA Kommunikation
> http://www.vva.de
> -----------------------------------------------------------------------
> omnisuite(r) - integrate. automate. communicate.
> http://www.omnisuite.de
> -----------------------------------------------------------------------
>
> Diese Nachricht (inklusive aller Anh?nge) ist vertraulich. Sie darf
> ausschlie?lich durch den vorgesehenen Empf?nger und Adressaten gelesen,
> kopiert oder genutzt werden. Sollten Sie diese Nachricht versehentlich
> erhalten haben, bitten wir, den Absender (durch Antwort-E-Mail) hiervon
> unverz?glich zu informieren und die Nachricht zu l?schen. Jede
> unerlaubte
> Nutzung oder Weitergabe des Inhalts dieser Nachricht, sei es
> vollst?ndig
> oder teilweise, ist unzul?ssig.
>
> This message (including any attachments) is confidential and may be
> privileged. It may be read, copied and used only by the intended
> recipient.
> If you have received it in error please contact the sender (by return
> E-Mail) immediately and delete this message. Any unauthorised use or
> dissemination of this message in whole or in part is strictly
> prohibited.


VVA Networks GmbH

Mario-Leander Reimer
Dipl.-Inf. (FH)
Teamleitung Publishing Solutions
---------------------------------------------------------------------------
VVA Networks GmbH
: medien mit zukunft
Geisenhausenerstraße 15-17
81379 München
Deutschland
---------------------------------------------------------------------------
Fon:    +49 89 2000375-610
Fax:    +49 89 2000375-699
Mobil:  +49 173 5883541
---------------------------------------------------------------------------
leander.reimer@vva-networks.de
www.vva-networks.de

-----------------------------------------------------------------------
HRB 33884 Düsseldorf
Geschäftsführer Rolf Christian Kassel
-----------------------------------------------------------------------
Ein Unternehmen der VVA Kommunikation
http://www.vva.de
-----------------------------------------------------------------------
omnisuite® - integrate. automate. communicate.
http://www.omnisuite.de
-----------------------------------------------------------------------

Diese Nachricht (inklusive aller Anhänge) ist vertraulich. Sie darf
ausschließlich durch den vorgesehenen Empfänger und Adressaten gelesen,
kopiert oder genutzt werden. Sollten Sie diese Nachricht versehentlich
erhalten haben, bitten wir, den Absender (durch Antwort-E-Mail) hiervon
unverzüglich zu informieren und die Nachricht zu löschen. Jede unerlaubte
Nutzung oder Weitergabe des Inhalts dieser Nachricht, sei es vollständig
oder teilweise, ist unzulässig.

This message (including any attachments) is confidential and may be
privileged. It may be read, copied and used only by the intended recipient.
If you have received it in error please contact the sender (by return
E-Mail) immediately and delete this message. Any unauthorised use or
dissemination of this message in whole or in part is strictly prohibited.

Re: Problem with ISO9075 encoded name in XPath Query?

Posted by Dave Brosius <db...@mebigfatguy.com>.
Don't encode the name when you save it.
Only encode the name when using xpath.


----- Original Message ----- 
From: "Mario-Leander Reimer" <le...@vva-networks.de>
To: <us...@jackrabbit.apache.org>
Sent: Monday, March 02, 2009 10:29 AM
Subject: Problem with ISO9075 encoded name in XPath Query?


Hi Jackrabbit users,

I have a problem with an XPath query in our system when the path contains 
spaces. Well, it does not really contain spaces. When we save the node, we 
encode the name and path with the ISO9075 class 
(org.apache.jackrabbit.util.ISO9075)

So the name "Test Company" will result in "Test_x0020_Company"

We then construct an XPath query, something like

/jcr:root/application/com/testcompany/Test_x0020_Company//element(*)[type='IMAGE']

it never returns any results. But if I have a path that has no ISO9075 
encoded parts like

/jcr:root/application/com/testcompany/TestCompany//element(*)[type='IMAGE']

this query works and returns nodes.

Any ideas? What am I doing wrong?

Thanks,
Leander

VVA Networks GmbH

Mario-Leander Reimer
Dipl.-Inf. (FH)
Teamleitung Publishing Solutions
---------------------------------------------------------------------------
VVA Networks GmbH
: medien mit zukunft
Geisenhausenerstra?e 15-17
81379 M?nchen
Deutschland
---------------------------------------------------------------------------
Fon:    +49 89 2000375-610
Fax:    +49 89 2000375-699
Mobil:  +49 173 5883541
---------------------------------------------------------------------------
leander.reimer@vva-networks.de
www.vva-networks.de

-----------------------------------------------------------------------
HRB 33884 D?sseldorf
Gesch?ftsf?hrer Rolf Christian Kassel
-----------------------------------------------------------------------
Ein Unternehmen der VVA Kommunikation
http://www.vva.de
-----------------------------------------------------------------------
omnisuite(r) - integrate. automate. communicate.
http://www.omnisuite.de
-----------------------------------------------------------------------

Diese Nachricht (inklusive aller Anh?nge) ist vertraulich. Sie darf
ausschlie?lich durch den vorgesehenen Empf?nger und Adressaten gelesen,
kopiert oder genutzt werden. Sollten Sie diese Nachricht versehentlich
erhalten haben, bitten wir, den Absender (durch Antwort-E-Mail) hiervon
unverz?glich zu informieren und die Nachricht zu l?schen. Jede unerlaubte
Nutzung oder Weitergabe des Inhalts dieser Nachricht, sei es vollst?ndig
oder teilweise, ist unzul?ssig.

This message (including any attachments) is confidential and may be
privileged. It may be read, copied and used only by the intended recipient.
If you have received it in error please contact the sender (by return
E-Mail) immediately and delete this message. Any unauthorised use or
dissemination of this message in whole or in part is strictly prohibited. 


AW: Problem with ISO9075 encoded name in XPath Query?

Posted by Mario-Leander Reimer <le...@vva-networks.de>.
Hi Sébastien,

Thanks for your answer. After ISO9075 encoding the XPath query string as well, it now works.

I wasn't aware that I always have to encode the query whether it's already encoded or not. I thought when I initially encode the node names then I would always have valid paths to use in the queries straight away.

BR,
Leander


> -----Ursprüngliche Nachricht-----
> Von: Sébastien Launay [mailto:sebastien.launay@anyware-tech.com]
> Gesendet: Montag, 2. März 2009 17:04
> An: users@jackrabbit.apache.org
> Betreff: Re: Problem with ISO9075 encoded name in XPath Query?
>
> Hi Mario,
>
> ISO9075 musts be used when creating an XPath Query whether a segment
> has been encoded or not.
> Therefore, i think you need to double encode the segment with:
> Node name stored = "Test_x0020_Company"
> Node name for query = "Test_x005F_x0020_x005F_Company"
>
> =>
> /jcr:root/application/com/testcompany/Test_x005F_x0020_x005F_Company//e
> lement(*)[type='IMAGE']
>
> I do not think that this encoding is necessary for storing if it is
> just for avoiding spaces problems, as spaces are allowed in node name
> (but not at the beginning).
>
> Note that the same problem will occurs if you have a node name starting
> with a number, it must be encoded with ISO9075 in the query.
>
> Mario-Leander Reimer a écrit :
> > Hi Jackrabbit users,
> >
> > I have a problem with an XPath query in our system when the path
> contains spaces. Well, it does not really contain spaces. When we save
> the node, we encode the name and path with the ISO9075 class
> (org.apache.jackrabbit.util.ISO9075)
> >
> > So the name "Test Company" will result in "Test_x0020_Company"
> >
> > We then construct an XPath query, something like
> >
> >
> /jcr:root/application/com/testcompany/Test_x0020_Company//element(*)[ty
> pe='IMAGE']
> >
> > it never returns any results. But if I have a path that has no
> ISO9075 encoded parts like
> >
> >
> /jcr:root/application/com/testcompany/TestCompany//element(*)[type='IMA
> GE']
> >
> > this query works and returns nodes.
> >
> > Any ideas? What am I doing wrong?
> >
> > Thanks,
> > Leander
> >
> > VVA Networks GmbH
> >
> > Mario-Leander Reimer
> > Dipl.-Inf. (FH)
> > Teamleitung Publishing Solutions
> --
> Sébastien Launay

VVA Networks GmbH

Mario-Leander Reimer
Dipl.-Inf. (FH)
Teamleitung Publishing Solutions
---------------------------------------------------------------------------
VVA Networks GmbH
: medien mit zukunft
Geisenhausenerstraße 15-17
81379 München
Deutschland
---------------------------------------------------------------------------
Fon:    +49 89 2000375-610
Fax:    +49 89 2000375-699
Mobil:  +49 173 5883541
---------------------------------------------------------------------------
leander.reimer@vva-networks.de
www.vva-networks.de

-----------------------------------------------------------------------
HRB 33884 Düsseldorf
Geschäftsführer Rolf Christian Kassel
-----------------------------------------------------------------------
Ein Unternehmen der VVA Kommunikation
http://www.vva.de
-----------------------------------------------------------------------
omnisuite® - integrate. automate. communicate.
http://www.omnisuite.de
-----------------------------------------------------------------------

Diese Nachricht (inklusive aller Anhänge) ist vertraulich. Sie darf
ausschließlich durch den vorgesehenen Empfänger und Adressaten gelesen,
kopiert oder genutzt werden. Sollten Sie diese Nachricht versehentlich
erhalten haben, bitten wir, den Absender (durch Antwort-E-Mail) hiervon
unverzüglich zu informieren und die Nachricht zu löschen. Jede unerlaubte
Nutzung oder Weitergabe des Inhalts dieser Nachricht, sei es vollständig
oder teilweise, ist unzulässig.

This message (including any attachments) is confidential and may be
privileged. It may be read, copied and used only by the intended recipient.
If you have received it in error please contact the sender (by return
E-Mail) immediately and delete this message. Any unauthorised use or
dissemination of this message in whole or in part is strictly prohibited.

Re: Problem with ISO9075 encoded name in XPath Query?

Posted by Sébastien Launay <se...@anyware-tech.com>.
Hi Mario,

ISO9075 musts be used when creating an XPath Query whether a segment
has been encoded or not.
Therefore, i think you need to double encode the segment with:
Node name stored = "Test_x0020_Company"
Node name for query = "Test_x005F_x0020_x005F_Company"

=> /jcr:root/application/com/testcompany/Test_x005F_x0020_x005F_Company//element(*)[type='IMAGE']

I do not think that this encoding is necessary for storing if it is
just for avoiding spaces problems, as spaces are allowed in node name
(but not at the beginning).

Note that the same problem will occurs if you have a node name starting
with a number, it must be encoded with ISO9075 in the query.

Mario-Leander Reimer a écrit :
> Hi Jackrabbit users,
>
> I have a problem with an XPath query in our system when the path contains spaces. Well, it does not really contain spaces. When we save the node, we encode the name and path with the ISO9075 class (org.apache.jackrabbit.util.ISO9075)
>
> So the name "Test Company" will result in "Test_x0020_Company"
>
> We then construct an XPath query, something like
>
> /jcr:root/application/com/testcompany/Test_x0020_Company//element(*)[type='IMAGE']
>
> it never returns any results. But if I have a path that has no ISO9075 encoded parts like
>
> /jcr:root/application/com/testcompany/TestCompany//element(*)[type='IMAGE']
>
> this query works and returns nodes.
>
> Any ideas? What am I doing wrong?
>
> Thanks,
> Leander
>
> VVA Networks GmbH
>
> Mario-Leander Reimer
> Dipl.-Inf. (FH)
> Teamleitung Publishing Solutions
--
Sébastien Launay

Re: Problem with ISO9075 encoded name in XPath Query?

Posted by Alexander Klimetschek <ak...@day.com>.
2009/3/2 Mario-Leander Reimer <le...@vva-networks.de>:
> I have a problem with an XPath query in our system when the path contains spaces. Well, it does not really contain spaces. When we save the node, we encode the name and path with the ISO9075 class (org.apache.jackrabbit.util.ISO9075)

There are *two different* encodings that apply here:

a) Valid JCR node names: this is separately specified in the JCR spec
(section 6.2.5.2 [1]), and basically follows URI encoding; but it also
allows spaces, for example! For proper encoding/decoding (using the
%NN URI-style escaping) use the
org.apache.jackrabbit.util.Text.escapeIllegalJcrChars() and
unescapeIllegalJcrChars() methods.

b) XPath queries and XML document view: since XPath is tied to XML, it
requires valid XML names (section 6.6.6.1 [2]), same goes for the XML
document view export (section 6.4.3 [3] or footnote 5 in the spec).
This is the ISO 9075 encoding (copied from SQL-over-XML mapping) and
is different from a) (for example, leading digits are not allowed).
For this, you can use the ISO9075 class you mentioned. You will only
have to use it to encode the path elements of the XPath query.


[1] http://www.day.com/specs/jcr/1.0/6.2.5.2_Name.html
[2] http://www.day.com/specs/jcr/1.0/6.6.6.1_Named_Terminals.html
[3] http://www.day.com/specs/jcr/1.0/6.4.3_Escaping_of_Names.html

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com