public final class NodeNameCodec extends Object
Implements the encode and decode routines based on ISO 9075-14:2003 for
node names.It encodes and decode the minimal set to garanty the node names
are jcr valid.
If a character c
is not valid in the node name it is encoded
in the form: '_x' + hexValueOf(c) + '_' (UTF-16). It only
If a node name string is encoded twice or decoded twice it should return the
same string. If a node name string doesn't contain invalid characters the
encode functions should return the string itself. If a string doesn't contain
any encoded chars it should return the string itself. Eg:
Qualified name: a qualified name is a combination of a namespace URI and a local part. Instances of this class are used to internally represent the names of JCR content items and other objects within a content repository.
The prefixed JCR name format of a qualified name is specified by section 4.6 of the the JCR 1.0 specification (JSR 170) as follows:
name ::= simplename | prefixedname simplename ::= onecharsimplename | twocharsimplename | threeormorecharname prefixedname ::= prefix ':' localname localname ::= onecharlocalname | twocharlocalname | threeormorecharname onecharsimplename ::= (* Any Unicode character except: '.', '/', ':', '[', ']', '*', ''', '"', '|' or any whitespace character *) twocharsimplename ::= '.' onecharsimplename | onecharsimplename '.' | onecharsimplename onecharsimplename onecharlocalname ::= nonspace twocharlocalname ::= nonspace nonspace threeormorecharname ::= nonspace string nonspace prefix ::= (* Any valid non-empty XML NCName *) string ::= char | string char char ::= nonspace | ' ' nonspace ::= (* Any Unicode character except: '/', ':', '[', ']', '*', ''', '"', '|' or any whitespace character *)
Constructor and Description |
---|
NodeNameCodec() |
Modifier and Type | Method and Description |
---|---|
static String |
decode(String name)
Decode the name string with the ISO9075 coding standard.
|
static String |
encode(char c)
Encode the char to a valid JCR string.
|
static String |
encode(String name)
Encode the name to a valid JCR name.
|
static String |
encode(String name,
boolean forceSimpleName)
Encode the name to a valid JCR name.
|
public static final String encode(String name)
Encode the name to a valid JCR name. If the name is prefixed with a namespace, the prefix is not encoded but returned as-is.
Calling encode multiple times on the same string will return the same result as encoding the string once.
An IllegalArgumentException is thrown when the name is empty or null.
name
- the name to encodepublic static final String encode(char c)
Encode the char to a valid JCR string.
Calling encode multiple times on the same string will return the same result as encoding the string once.
c
- the char to encodepublic static final String encode(String name, boolean forceSimpleName)
Encode the name to a valid JCR name. If the name is prefixed with a namespace, the prefix is not encoded but returned as-is. The force simple name option, forces the codec to encode the name as simple name by encoding colons.
Calling encode multiple times on the same string will return the same result as encoding the string once.
An IllegalArgumentException is thrown when the name is empty or null.
name
- the name to encodeforceSimpleName
- force the name to be interpreted as a simple (non prefixed) nameCopyright © 2007–2019 Hippo B.V. (http://www.onehippo.com). All rights reserved.