public class ConnectJcrUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static char[] |
INVALID_NAME_CHARACTERS
Add '?' to the list of forbidden characters.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
addMultiPropertyValue(Node node,
java.lang.String propName,
java.lang.String value)
Adds a string value on a multivalued property.
|
static java.lang.String |
addRefToMultiValuedProp(Node node,
java.lang.String propName,
Node nodeToReference)
Adds a reference to a JCR Node to the multi valued REFERENCE property of a
Node.
|
static java.lang.String |
addStringToMultiValuedProp(Node node,
java.lang.String propName,
java.lang.String value)
Adds a String to the multi valued STRING property of a Node.
|
static boolean |
canEdit(Node entity) |
static java.lang.String |
checkAndLocalizeNamespaces(java.lang.String name) |
static boolean |
checkCOStatusBeforeUpdate(Node node)
Simplify the save strategy keeping the check-in status unchanged.
|
static void |
checkPoint(Session session,
java.util.List<java.lang.String> pathes,
boolean updateLastModified)
Wraps a best effort to versionMananger.checkedPoint(path) a list of path.
|
static java.lang.String |
cleanNodeName(java.lang.String name) |
static java.lang.String |
concatIfNotEmpty(java.lang.String str1,
java.lang.String str2,
java.lang.String separator)
Concatenates 2 strings with given separator if they are not empty
|
static java.lang.String |
get(Node node,
java.lang.String propertyName)
Concisely gets the String value of a property.
|
static java.lang.String |
getAbsPath(java.lang.String parPath,
java.lang.String nodeName)
Shortcut to manage case where parentPath is "/" (parent is root)
|
static java.lang.Boolean |
getBooleanValue(Node node,
java.lang.String propertyName)
Concisely gets the value of a boolean property or null if this node doesn't
have this property
|
static Node |
getByPropertyValue(Session session,
java.lang.String parentPath,
java.lang.String nodeType,
java.lang.String propName,
java.lang.String propValue) |
static NodeIterator |
getByPropertyValue(Session session,
java.lang.String parentPath,
java.lang.String nodeType,
java.lang.String propName,
java.lang.String propValue,
boolean acceptMultipleResult) |
static java.lang.String |
getDateFormattedAsString(Node node,
java.lang.String propertyName,
java.lang.String dateFormatPattern)
Concisely gets the value of a date property formatted as String or an empty
String this node doesn't have this property
|
static java.util.Calendar |
getDateValue(Node node,
java.lang.String propRelPath)
Concisely gets the value of a date property or null if this node doesn't have
this property
|
static java.lang.Double |
getDoubleValue(Node node,
java.lang.String propRelPath)
Concisely gets the value of a double property or null if this node doesn't
have this property
|
static Constraint |
getFreeTextConstraint(Session session,
QueryObjectModelFactory factory,
Selector source,
java.lang.String filter)
Widely used pattern in various UI Parts
|
static java.lang.String |
getIdentifier(Node node)
Centralises exception management to call
Node.getIdentifier() |
static java.lang.String |
getLocalJcrItemName(java.lang.String name)
Replace the generic namespace with the local "jcr:" value.
|
static java.lang.Long |
getLongValue(Node node,
java.lang.String propRelPath)
Concisely gets the value of a long property or null if this node doesn't have
this property
|
static java.util.List<java.lang.String> |
getMultiAsList(Node node,
java.lang.String propertyName)
Concisely gets a list with the values of a multi-valued String property.
|
static java.lang.String |
getMultiAsString(Node node,
java.lang.String propertyName,
java.lang.String separator)
Concisely gets a string that concatenates values of a multi-valued String
property.
|
static java.lang.String |
getName(Node node)
Centralises exception management to call
Item.getName() |
static Node |
getNode(Row row,
java.lang.String selectorName)
Call
Row.getNode() catching RepositoryException |
static Node |
getNode(Session session,
java.lang.String absPath)
Call
Session#getNode() catching RepositoryException |
static Node |
getNode(Session session,
java.lang.String absParentPath,
java.lang.String... childRelPath)
If session.absParentPath exists and is visible, build a relative path with
the passed relative subpath and returns the node at corresponding relative
path if it exists
Call
Session#getNode() catching RepositoryException |
static Node |
getNodeByIdentifier(Node sessionNode,
java.lang.String identifier)
Centralizes exception management to call
Session.getNodeByIdentifier(String) . |
static Node |
getNodeByIdentifier(Session session,
java.lang.String identifier)
Centralizes exception management to call
Session.getNodeByIdentifier(String) |
static Node |
getNodeFromElement(java.lang.Object element,
java.lang.String selectorName)
Helper for label provider: returns the Node if element is a Node or retrieves
the Node if the object is a row.
|
static NodeIterator |
getNodesOfType(Session session,
java.lang.String parentPath,
java.lang.String nodeType)
Shortcut to get a node iterator on all nodes of a given type under a given
subpath.
|
static Node |
getParent(Node child)
Centralizes exception management to call
Item.getParent() |
static Node |
getParentVersionableNode(Node node)
Simply retrieves the first versionable node in the current node ancestor tree
(might be the ndoe itself) or null if none of them is versionable
|
static java.lang.String |
getPath(Node node)
Centralises exception management to call
Item.getPath() |
static java.lang.String |
getPrimaryNodeType(Node node)
Simply retrieves primary node type name
|
static java.lang.String |
getPropertyTypeAsString(Property prop)
Retrieves the human readable label of a property
|
static Node |
getReference(Node node,
java.lang.String propName)
Concisely gets a referenced node or null if the given node doesn't have this
property or if the property is of the wrong type
|
static Repository |
getRepository(Node node)
Centralises exception management to call
Node#getSession()#getRepository() |
static Session |
getSession(Node node)
Centralises exception management to call
Item.getSession() |
static Node |
getVersionableAncestor(Node node)
Returns the versionable node in the parent path, this if it is versionable or
null if none is versionnable including root node.
|
static boolean |
isNodeCheckedOut(Node node)
Wraps the versionMananger.isCheckedOut(path) method to adapt it to the
current check in / check out policy.
|
static boolean |
isNodeCheckedOutByMe(Node node)
For the time being, same as isNodeCheckedOut(Node node).
|
static boolean |
isNodeType(Node node,
java.lang.String nodeTypeName)
Calls
Node#isNodetype(String) without exceptions |
static boolean |
isVersionable(Node node)
Simply check if a node is versionable
|
static boolean |
itemExists(Session session,
java.lang.String absPath)
Simply calls
Session.itemExists(String) with no try/catch |
static java.lang.String |
lastRelPathElement(java.lang.String relPath)
The last element of a relative path.
|
static Constraint |
localAnd(QueryObjectModelFactory factory,
Constraint defaultC,
Constraint newC)
Returns and(constraintA, constraintB) if constraintA != null, or constraintB
otherwise (that cannot be null)
|
static Session |
login(Repository repository)
Call
Repository.login() without exceptions (useful in super
constructors). |
static Node[] |
nodeIteratorToArray(NodeIterator nit)
Browses a
NodeIterator to build the corresponding Node array. |
static boolean |
nodeStillExists(Node node)
Works around missing method to test if a node has been removed from existing
session
|
static void |
orderReferenceBefore(Node node,
java.lang.String propName,
Node sourceNode,
Node targetNode)
Insert a reference to a given node in a multi value reference property just
before the reference that is passed as target parameter.
|
static java.lang.String |
parentRelPath(java.lang.String relPath)
Simply retrieves the parent rel path of the provided relative path
|
static java.lang.String[] |
parseAndClean(java.lang.String string,
java.lang.String regExp,
boolean clean)
Parses and trims a String of values
|
static void |
removeMultiPropertyValue(Node node,
java.lang.String propName,
java.lang.String stringToRemove)
Removes a given String from a multi value property of a node.
|
static void |
removeRefFromMultiValuedProp(Node node,
java.lang.String propName,
java.lang.String identifier)
Remove a Reference from a multi valued property
|
static void |
removeStringFromMultiValuedProp(Node node,
java.lang.String propName,
java.lang.String value)
Remove a String from a multi valued property
|
static java.lang.String |
replaceInvalidChars(java.lang.String name)
Replaces characters which are invalid in a JCR name by '_'.
|
static java.lang.String |
replaceInvalidChars(java.lang.String name,
char replacement)
Replaces characters which are invalid in a JCR name.
|
static Row[] |
rowIteratorToArray(RowIterator rit)
Browses a
RowIterator to build the corresponding row array. |
static Row[] |
rowIteratorToDistinctArray(RowIterator rit,
java.lang.String distinctSelectorName)
Browses a
RowIterator to build the corresponding row array. |
static java.util.List<Node> |
rowIteratorToNodeList(RowIterator rowIterator,
java.lang.String selectorName)
Convert a
RowIterator to a list of Node given a selector
name. |
static boolean |
saveAndPublish(Node node,
boolean publish)
Make a version snapshot of the current state of the given versionable node.
|
static boolean |
saveIfNecessary(Node node)
Shortcut to save the underlying session if it has pending changes without
exception
|
static boolean |
setJcrProperty(Node node,
java.lang.String propName,
int propertyType,
java.lang.Object value)
Centralises management of updating property value.
|
static void |
setMultipleReferences(Node node,
java.lang.String propertyName,
java.util.List<Node> nodes)
Sets a property of type REFERENCE that is multiple.
|
static void |
setMultiValueStringPropFromString(Node node,
java.lang.String propName,
java.lang.String values,
java.lang.String separator)
Add a string value on a multivalued property.
|
static void |
updateLastModified(Node node,
java.lang.String userId)
If this node is has the
NodeType.MIX_LAST_MODIFIED mixin, it updates
the Property.JCR_LAST_MODIFIED property with the current time and the
Property.JCR_LAST_MODIFIED_BY property with the passed user id. |
static boolean |
valueExists(Node node,
java.lang.String propName,
java.lang.String value)
Simply checks a multi valued STRING property of a Node and returns true if
the given property has already such a value.
|
public static final char[] INVALID_NAME_CHARACTERS
public static java.lang.String getLocalJcrItemName(java.lang.String name)
name
- the property name which prefix has to be cleanedpublic static java.lang.String checkAndLocalizeNamespaces(java.lang.String name)
public static java.lang.String cleanNodeName(java.lang.String name)
public static java.lang.String replaceInvalidChars(java.lang.String name)
JcrUtils.INVALID_NAME_CHARACTERS
public static java.lang.String replaceInvalidChars(java.lang.String name, char replacement)
JcrUtils.INVALID_NAME_CHARACTERS
public static java.lang.String parentRelPath(java.lang.String relPath)
public static java.lang.String lastRelPathElement(java.lang.String relPath)
public static boolean canEdit(Node entity)
public static Node getNodeFromElement(java.lang.Object element, java.lang.String selectorName)
Row.getNode()
catching
RepositoryException
public static Node getVersionableAncestor(Node node)
public static boolean nodeStillExists(Node node)
node
- public static boolean isNodeCheckedOut(Node node)
public static NodeIterator getNodesOfType(Session session, java.lang.String parentPath, java.lang.String nodeType)
public static Node getByPropertyValue(Session session, java.lang.String parentPath, java.lang.String nodeType, java.lang.String propName, java.lang.String propValue)
public static NodeIterator getByPropertyValue(Session session, java.lang.String parentPath, java.lang.String nodeType, java.lang.String propName, java.lang.String propValue, boolean acceptMultipleResult)
public static java.lang.String getPropertyTypeAsString(Property prop)
public static void updateLastModified(Node node, java.lang.String userId)
NodeType.MIX_LAST_MODIFIED
mixin, it updates
the Property.JCR_LAST_MODIFIED
property with the current time and the
Property.JCR_LAST_MODIFIED_BY
property with the passed user id. In
Jackrabbit 2.x,
these properties are
not automatically updated, hence the need for manual update. The session
is not saved.public static boolean isNodeCheckedOutByMe(Node node)
public static boolean saveAndPublish(Node node, boolean publish)
public static boolean saveIfNecessary(Node node)
public static void checkPoint(Session session, java.util.List<java.lang.String> pathes, boolean updateLastModified)
public static boolean checkCOStatusBeforeUpdate(Node node)
checkCOStatusAfterUpdate
public static Node getParentVersionableNode(Node node) throws RepositoryException
RepositoryException
public static Session login(Repository repository)
Repository.login()
without exceptions (useful in super
constructors).public static Session getSession(Node node)
Item.getSession()
public static Repository getRepository(Node node)
Node#getSession()#getRepository()
public static java.lang.String getIdentifier(Node node)
Node.getIdentifier()
public static java.lang.String getName(Node node)
Item.getName()
public static java.lang.String getPath(Node node)
Item.getPath()
public static java.lang.String getAbsPath(java.lang.String parPath, java.lang.String nodeName)
public static boolean itemExists(Session session, java.lang.String absPath)
Session.itemExists(String)
with no try/catchpublic static Node getNodeByIdentifier(Session session, java.lang.String identifier)
Session.getNodeByIdentifier(String)
public static Node getParent(Node child)
Item.getParent()
public static Node getNodeByIdentifier(Node sessionNode, java.lang.String identifier)
Session.getNodeByIdentifier(String)
. The session is retrieved using
the passed nodepublic static Node getNode(Session session, java.lang.String absPath)
Session#getNode()
catching RepositoryException
public static Node getNode(Session session, java.lang.String absParentPath, java.lang.String... childRelPath)
Session#getNode()
catching RepositoryException
public static Node getNode(Row row, java.lang.String selectorName)
Row.getNode()
catching RepositoryException
public static boolean isNodeType(Node node, java.lang.String nodeTypeName)
Node#isNodetype(String)
without exceptionspublic static java.lang.String getPrimaryNodeType(Node node)
public static boolean isVersionable(Node node)
public static java.lang.String get(Node node, java.lang.String propertyName)
public static java.lang.Long getLongValue(Node node, java.lang.String propRelPath)
public static java.lang.Double getDoubleValue(Node node, java.lang.String propRelPath)
public static java.util.Calendar getDateValue(Node node, java.lang.String propRelPath)
public static java.lang.Boolean getBooleanValue(Node node, java.lang.String propertyName)
public static java.lang.String getDateFormattedAsString(Node node, java.lang.String propertyName, java.lang.String dateFormatPattern)
public static Node getReference(Node node, java.lang.String propName)
public static boolean setJcrProperty(Node node, java.lang.String propName, int propertyType, java.lang.Object value)
public static void removeMultiPropertyValue(Node node, java.lang.String propName, java.lang.String stringToRemove)
public static java.lang.String addMultiPropertyValue(Node node, java.lang.String propName, java.lang.String value)
public static void setMultiValueStringPropFromString(Node node, java.lang.String propName, java.lang.String values, java.lang.String separator)
public static java.lang.String getMultiAsString(Node node, java.lang.String propertyName, java.lang.String separator)
public static java.util.List<java.lang.String> getMultiAsList(Node node, java.lang.String propertyName)
public static void setMultipleReferences(Node node, java.lang.String propertyName, java.util.List<Node> nodes) throws RepositoryException
RepositoryException
public static void removeRefFromMultiValuedProp(Node node, java.lang.String propName, java.lang.String identifier)
public static java.lang.String addRefToMultiValuedProp(Node node, java.lang.String propName, Node nodeToReference)
public static void orderReferenceBefore(Node node, java.lang.String propName, Node sourceNode, Node targetNode)
public static boolean valueExists(Node node, java.lang.String propName, java.lang.String value)
public static java.lang.String addStringToMultiValuedProp(Node node, java.lang.String propName, java.lang.String value)
public static void removeStringFromMultiValuedProp(Node node, java.lang.String propName, java.lang.String value)
public static Node[] nodeIteratorToArray(NodeIterator nit)
NodeIterator
to build the corresponding Node array.public static Row[] rowIteratorToArray(RowIterator rit)
RowIterator
to build the corresponding row array.public static Row[] rowIteratorToDistinctArray(RowIterator rit, java.lang.String distinctSelectorName) throws RepositoryException
RowIterator
to build the corresponding row array. Performs
a kind of "select distinct" based on the JcrUID of the nodes designed by the
selector nameRepositoryException
public static java.util.List<Node> rowIteratorToNodeList(RowIterator rowIterator, java.lang.String selectorName) throws RepositoryException
RowIterator
to a list of Node
given a selector
name. It relies on the <code>Row.getNode(String
selectorName)</code> method.RepositoryException
public static java.lang.String[] parseAndClean(java.lang.String string, java.lang.String regExp, boolean clean)
public static java.lang.String concatIfNotEmpty(java.lang.String str1, java.lang.String str2, java.lang.String separator)
public static Constraint localAnd(QueryObjectModelFactory factory, Constraint defaultC, Constraint newC) throws RepositoryException
RepositoryException
public static Constraint getFreeTextConstraint(Session session, QueryObjectModelFactory factory, Selector source, java.lang.String filter) throws RepositoryException
RepositoryException
Copyright © 2007–2020. All rights reserved.