public class JcrUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String[] |
HYPHEN_LABEL_CHAR_MAPPING
the list of replacement string for non-valid jcr characters.
|
static java.lang.String |
NON_VALID_CHARS
Non-valid name characters.
|
static java.lang.String[] |
STANDARD_LABEL_CHAR_MAPPING
the list of replacement string for non-valid jcr characters.
|
Constructor and Description |
---|
JcrUtil() |
Modifier and Type | Method and Description |
---|---|
static Item |
copy(Item src,
Node dstParent,
java.lang.String name)
Copy the
src item into the dstParent node. |
static Node |
copy(Node src,
Node dstParent,
java.lang.String name)
Copy the
src node into the dstParent node. |
static Node |
copy(Node src,
Node dstParent,
java.lang.String name,
boolean bestEffort)
Copy the
src node into the dstParent node. |
static Property |
copy(Property src,
Node dstParent,
java.lang.String name)
Copy the
src property into the dstParent
node. |
static int |
copyResource(Session session,
java.lang.String path,
java.io.Writer out)
Copies the contents of the resource to the given writer.
|
static Node |
createPath(Node baseNode,
java.lang.String path,
boolean createUniqueLeaf,
java.lang.String intermediateNodeType,
java.lang.String nodeType,
Session session,
boolean autoSave)
Creates or gets the
Node at the given path
relative to the baseNode. |
static Node |
createPath(java.lang.String absolutePath,
boolean createUniqueLeaf,
java.lang.String intermediateNodeType,
java.lang.String nodeType,
Session session,
boolean autoSave)
Creates or gets the
Node at the given Path. |
static Node |
createPath(java.lang.String absolutePath,
java.lang.String nodeType,
Session session)
Creates or gets the
Node at the given Path. |
static Node |
createPath(java.lang.String absolutePath,
java.lang.String intermediateNodeType,
java.lang.String nodeType,
Session session,
boolean autoSave)
Creates or gets the
Node at the given Path. |
static Node |
createUniqueNode(Node parent,
java.lang.String nodeNameHint,
java.lang.String nodeType,
Session session)
Creates or gets the
Node at the given Path. |
static Node |
createUniquePath(java.lang.String pathHint,
java.lang.String nodeType,
Session session)
Creates a
Node at the given Path. |
static java.lang.String |
createValidChildName(Node node,
java.lang.String name)
Create a valid name for a child of the
node . |
static java.lang.String |
createValidName(java.lang.String title)
Create a valid label out of an arbitrary string.
|
static java.lang.String |
createValidName(java.lang.String title,
java.lang.String[] labelCharMapping)
Create a valid label out of an arbitrary string with a custom character
mapping.
|
static java.lang.String |
createValidName(java.lang.String title,
java.lang.String[] labelCharMapping,
java.lang.String defaultReplacementCharacter)
Create a valid label out of an arbitrary string with a custom character
mapping.
|
static Value |
createValue(java.lang.Object value,
Session session)
Creates a
JCR Value for the given object with
the given Session. |
static java.lang.String |
escapeIllegalJcrChars(java.lang.String name)
Escapes all illegal JCR name characters of a string.
|
static boolean |
isValidName(java.lang.String name)
Checks if the name is not empty and contains only valid chars.
|
static boolean |
setChildNodeOrder(Node parent,
java.lang.String nameList)
Restores the odering of the nodes according to the given comma seperated
name list.
|
static boolean |
setChildNodeOrder(Node parent,
java.lang.String[] names)
Restores the odering of the nodes according to the given
name list.
|
static void |
setProperty(Node node,
java.lang.String propertyName,
java.lang.Object propertyValue)
Sets the value of the property.
|
static java.lang.String |
unescapeIllegalJcrChars(java.lang.String name)
Unescapes previously escaped jcr chars.
|
public static final java.lang.String[] STANDARD_LABEL_CHAR_MAPPING
public static final java.lang.String[] HYPHEN_LABEL_CHAR_MAPPING
public static final java.lang.String NON_VALID_CHARS
public static java.lang.String escapeIllegalJcrChars(java.lang.String name)
unescapeIllegalJcrChars(String)
for decoding.
QName EBNF:
simplename ::= onecharsimplename | twocharsimplename | threeormorecharname onecharsimplename ::= (* Any Unicode character except: '.', '/', ':', '[', ']', '*', ''', '"', '|' or any whitespace character *) twocharsimplename ::= '.' onecharsimplename | onecharsimplename '.' | onecharsimplename onecharsimplename threeormorecharname ::= nonspace string nonspace string ::= char | string char char ::= nonspace | ' ' nonspace ::= (* Any Unicode character except: '/', ':', '[', ']', '*', ''', '"', '|' or any whitespace character *)
name
- the name to escapepublic static java.lang.String unescapeIllegalJcrChars(java.lang.String name)
Please note, that this does not exactly the same as the url related
Text.unescape(String)
, since it handles the byte-encoding
differently.
name
- the name to unescapepublic static Node createPath(java.lang.String absolutePath, java.lang.String nodeType, Session session) throws RepositoryException
Node
at the given Path.
In case it has to create the Node all non-existent intermediate path-elements
will be created with the given NodeType.
Changes made are not saved by this method, so session.save()
has to be called to persist them.
absolutePath
- absolute path to createnodeType
- to use for creation of nodessession
- to useRepositoryException
- in case of exception accessing the Repositorypublic static Node createPath(java.lang.String absolutePath, java.lang.String intermediateNodeType, java.lang.String nodeType, Session session, boolean autoSave) throws RepositoryException
Node
at the given Path.
In case it has to create the Node all non-existent intermediate path-elements
will be created with the given intermediate node type and the returned node
will be created with the given nodeType.absolutePath
- absolute path to createintermediateNodeType
- to use for creation of intermediate nodesnodeType
- to use for creation of the final nodesession
- to useautoSave
- Should save be called when a new node is created?RepositoryException
- in case of exception accessing the Repositorypublic static Node createUniquePath(java.lang.String pathHint, java.lang.String nodeType, Session session) throws RepositoryException
Node
at the given Path. In case it has
to create the Node all non-existent intermediate path-elements will be
created with the given intermediate node type and the returned node will
be created with the given nodeType.
If the path points to an existing node, the leaf node name will be
regarded as a name hint and a unique node name will be created by
appending a number to the given name (eg. /some/path/foobar2
).
Please note that the uniqueness check is not an atomic JCR operation,
so it is possible that you get a RepositoryException
(path
already exists) if another concurrent session created the same node in
the meantime.
Changes made are not saved by this method, so session.save()
has to be called to persist them.
pathHint
- path to createnodeType
- to use for creation of nodessession
- to useRepositoryException
- in case of exception accessing the Repositorypublic static Node createPath(java.lang.String absolutePath, boolean createUniqueLeaf, java.lang.String intermediateNodeType, java.lang.String nodeType, Session session, boolean autoSave) throws RepositoryException
Node
at the given Path. In
case it has to create the Node all non-existent intermediate
path-elements will be created with the given intermediate node type and
the returned node will be created with the given nodeType.
If the parameter createUniqueLeaf
is set, it will not get
an existing node but rather try to create a unique node by appending a
number to the last path element (leaf node). Please note that the
uniqueness check is not an atomic JCR operation, so it is possible
that you get a RepositoryException
(path already exists) if
another concurrent session created the same node in the meantime.
absolutePath
- absolute path to createcreateUniqueLeaf
- whether the leaf of the path should be regarded as a name hint
and a unique node name should be created by appending a number
to the given name (eg. /some/path/foobar2
)intermediateNodeType
- to use for creation of intermediate nodesnodeType
- to use for creation of the final nodesession
- to useautoSave
- Should save be called when a new node is created?RepositoryException
- in case of exception accessing the Repositorypublic static Node createUniqueNode(Node parent, java.lang.String nodeNameHint, java.lang.String nodeType, Session session) throws RepositoryException
Node
at the given Path. In
case it has to create the Node all non-existent intermediate
path-elements will be created with the given intermediate node type and
the returned node will be created with the given nodeType.
If the node name points to an existing node, the node name will be
regarded as a name hint and a unique node name will be created by
appending a number to the given name (eg. /some/path/foobar2
).
Please note that the uniqueness check is not an atomic JCR operation,
so it is possible that you get a RepositoryException
(path
already exists) if another concurrent session created the same node in
the meantime.
Changes made are not saved by this method, so session.save()
has to be called to persist them.
parent
- existing parent node for the new nodenodeNameHint
- name hint for the new nodenodeType
- to use for creation of the nodesession
- to useRepositoryException
- in case of exception accessing the Repositorypublic static Node createPath(Node baseNode, java.lang.String path, boolean createUniqueLeaf, java.lang.String intermediateNodeType, java.lang.String nodeType, Session session, boolean autoSave) throws RepositoryException
Node
at the given path
relative to the baseNode. In case it has to create the Node all
non-existent intermediate path-elements will be created with the given
intermediate node type and the returned node will be created with the
given nodeType.
If the parameter createUniqueLeaf
is set, it will not get
an existing node but rather try to create a unique node by appending a
number to the last path element (leaf node). Please note that the
uniqueness check is not an atomic JCR operation, so it is possible
that you get a RepositoryException
(path already exists) if
another concurrent session created the same node in the meantime.
baseNode
- existing node that should be the base for the relative pathpath
- relative path to createcreateUniqueLeaf
- whether the leaf of the path should be regarded as a name hint
and a unique node name should be created by appending a number
to the given name (eg. /some/path/foobar2
)intermediateNodeType
- to use for creation of intermediate nodesnodeType
- to use for creation of the final nodesession
- to useautoSave
- Should save be called when a new node is created?RepositoryException
- in case of exception accessing the Repositorypublic static java.lang.String createValidName(java.lang.String title)
createValidName(String, String[])
using
STANDARD_LABEL_CHAR_MAPPING
.title
- title to convert into a namepublic static java.lang.String createValidName(java.lang.String title, java.lang.String[] labelCharMapping)
title
- title to convert into a namelabelCharMapping
- a mapping of chars (index of the array) to strings that should
be used as replacement for the characterspublic static java.lang.String createValidName(java.lang.String title, java.lang.String[] labelCharMapping, java.lang.String defaultReplacementCharacter)
title
- title to convert into a namelabelCharMapping
- a mapping of chars (index of the array) to strings that should
be used as replacement for the charactersdefaultReplacementCharacter
- the default character to use for characters not mapped in the labelCharMapping parameterpublic static java.lang.String createValidChildName(Node node, java.lang.String name) throws RepositoryException
node
. Generates a valid name and test if child
already exists. If name is already existing, iterate until a unique one is foundnode
- parent nodename
- the name to checkRepositoryException
- in case of error, accessing the Repositorypublic static boolean isValidName(java.lang.String name)
name
- the name to checktrue
if the name is validpublic static Value createValue(java.lang.Object value, Session session) throws RepositoryException
JCR Value
for the given object with
the given Session.
Selects the the PropertyType
according
the instance of the object's Classvalue
- objectsession
- to create value forRepositoryException
- in case of error, accessing the Repositorypublic static void setProperty(Node node, java.lang.String propertyName, java.lang.Object propertyValue) throws RepositoryException
PropertyType
according
to the instance of the object's class.node
- The node where the property will be set on.propertyName
- The name of the property.propertyValue
- The value for the property.RepositoryException
- if a repository error occurspublic static Item copy(Item src, Node dstParent, java.lang.String name) throws RepositoryException
src
item into the dstParent
node.
The name of the newly created item is set to name
.src
- The item to copy to the new locationdstParent
- The node into which the src
node is to be
copiedname
- The name of the newly created item. If this is
null
the new item gets the same name as the
src
item.RepositoryException
- May be thrown in case of any problem copying
the content.copy(Node, Node, String)
,
copy(Property , Node, String)
public static Node copy(Node src, Node dstParent, java.lang.String name) throws RepositoryException
src
node into the dstParent
node.
The name of the newly created node is set to name
.
This method does a recursive (deep) copy of the subtree rooted at the source node to the destination. Any protected child nodes and and properties are not copied.
src
- The node to copy to the new locationdstParent
- The node into which the src
node is to be
copiedname
- The name of the newly created node. If this is
null
the new node gets the same name as the
src
node.RepositoryException
- May be thrown in case of any problem copying
the content.public static Node copy(Node src, Node dstParent, java.lang.String name, boolean bestEffort) throws RepositoryException
src
node into the dstParent
node.
The name of the newly created node is set to name
.
This method does a recursive (deep) copy of the subtree rooted at the
source node to the destination. Any protected child nodes and and
properties are not copied. The bestEffort
argument specifies
whether or not copying is aborted when adding a mixin, creating a property
or creating a child node fails with a RepositoryException
.
src
- The node to copy to the new locationdstParent
- The node into which the src
node is to be
copiedname
- The name of the newly created node. If this is
null
the new node gets the same name as the
src
node.bestEffort
- true
for best effort copying: skip mixins,
properties and child nodes which cannot be added.RepositoryException
- May be thrown in case of any problem copying
the content.public static Property copy(Property src, Node dstParent, java.lang.String name) throws RepositoryException
src
property into the dstParent
node. The name of the newly created property is set to name
.
If the source property is protected, this method does nothing.
src
- The property to copy to the new locationdstParent
- The node into which the src
property is
to be copiedname
- The name of the newly created property. If this is
null
the new property gets the same name as the
src
property.null
if nothing was copiedRepositoryException
- May be thrown in case of any problem copying
the content.public static boolean setChildNodeOrder(Node parent, java.lang.String nameList) throws RepositoryException
parent
- the parent nodenameList
- the list of namestrue
if the nodes were reorderedRepositoryException
- if an error occurrs.public static boolean setChildNodeOrder(Node parent, java.lang.String[] names) throws RepositoryException
parent
- the parent nodenames
- the list of namestrue
if the nodes were reorderedRepositoryException
- if an error occurrs.public static int copyResource(Session session, java.lang.String path, java.io.Writer out) throws java.io.IOException, RepositoryException
path
needs to have a binary property at the relative
path "jcr:content/jcr:data". the string is encoded using the optional
"jcr:content/jcr:encoding" property.session
- sessionpath
- file node pathout
- the writerjava.io.IOException
- if an I/O error occursRepositoryException
- if a repository error occursCopyright © 2010 - 2020 Adobe. All Rights Reserved