jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jukka Zitting" <jukka.zitt...@gmail.com>
Subject Re: Problems with character in file name
Date Wed, 01 Nov 2006 22:07:17 GMT

On 11/1/06, thomas-mlists"@jossystem.se Thomas Frössman <"> wrote:
> Hello, I am a newbie with a question.


> My goal is to create a repository that mirrors a local filesystem, I
> have a problem with file names.
> The problem is "This file will fail because of the ' character.txt".
> The line that fails is
>         Node fileNode = folderNode.addNode(file.getName(), "nt:file");

The set of valid JCR item names is a superset of valid XML names, but
a single quote is not allowed. See section 4.6 of the JCR
specification for the exact rules.

There is a utility class in Jackrabbit called
org.apache.jackrabbit.util.Text, that contains a number of escaping
and encoding methods for use with JCR. In your case I would suggest
you to use the Text.escapeIllegalJcrChars() and
Text.unescapeIllegalJcrChars() methods to make sure that you only
store valid JCR names. The methods use URI encoding but only where
absolutely necessary to keep the resulting name valid. Thus in normal
use the amount of encoded characters in names should be very small.

With the Text class your code would be:

    Node fileNode = folderNode.addNode(
       Text.escapeIllegalJcrChars(file.getName()), "nt:file");

Then, when passing the name back to a client, you'd do:

   String name = Text.unescapeIllegalJcrChars(fileNode.getName());


Jukka Zitting
View raw message