Class NodeNameCodec

java.lang.Object
org.hippoecm.repository.api.NodeNameCodec

public final class NodeNameCodec extends Object

Helper class for encoding and decoding node names

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:

  • decode(encode(x)) = x
  • encode(decode(x)) = x
  • encode(encode(x)) = encode(x)
  • decode(decode(x)) = decode(x)
  • encode(valid_chars) = valid_chars

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 Details

    • NodeNameCodec

      public NodeNameCodec()
  • Method Details

    • encode

      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.

      Parameters:
      name - the name to encode
      Returns:
      the encoded name
    • encode

      public 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.

      Parameters:
      c - the char to encode
      Returns:
      the encoded char as string
    • encode

      public 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.

      Parameters:
      name - the name to encode
      forceSimpleName - force the name to be interpreted as a simple (non prefixed) name
      Returns:
      the encoded name
    • decode

      public static final String decode(String name)
      Decode the name string with the ISO9075 coding standard.

      Calling decode multiple times on the same string will return the same result as decoding the string once.

      Parameters:
      name - the name to decode
      Returns:
      the decoded name