public class JcrUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static char[] |
INVALID_NAME_CHARACTERS
Not complete yet.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
accessControlListSummary(AccessControlList acl)
Returns a human-readable summary of this access control list.
|
static void |
addListener(Session session,
EventListener listener,
int eventTypes,
java.lang.String basePath,
java.lang.String nodeType)
Convenient method to add a listener.
|
static void |
addPrivilege(Session session,
java.lang.String path,
java.lang.String principal,
java.lang.String privilege)
Convenience method for adding a single privilege to a principal (user or
role), typically jcr:all
|
static java.lang.Boolean |
addPrivileges(Session session,
java.lang.String path,
java.security.Principal principal,
java.util.List<Privilege> privs)
Add privileges on a path to a
Principal . |
static java.lang.Boolean |
allPropertiesEquals(Node reference,
Node observed,
java.lang.Boolean onlyCommonProperties)
Check whether all first-level properties (except jcr:* properties) are equal.
|
static java.lang.Boolean |
check(Node node,
java.lang.String propertyName)
Concisely get the boolean value of a property
|
static java.lang.String |
checksumFile(Node fileNode,
java.lang.String algorithm)
Deprecated.
use separate digest utilities
|
static void |
clearAccessControList(Session session,
java.lang.String path,
java.lang.String username)
Clear authorizations for a user at this path
|
static void |
closeQuietly(Binary binary)
Cleanly disposes a
Binary even if it is null. |
static void |
copy(Node fromNode,
Node toNode)
Copies recursively the content of a node to another one.
|
static Node |
copyBytesAsFile(Node folderNode,
java.lang.String fileName,
byte[] bytes)
Copy bytes as an nt:file
|
static Node |
copyFile(Node folderNode,
java.io.File file)
Copy a file as an nt:file, assuming an nt:folder hierarchy.
|
static java.lang.Long |
copyFiles(Node fromNode,
Node toNode,
java.lang.Boolean recursive,
JcrMonitor monitor,
boolean onlyAdd)
Copy only nt:folder and nt:file, without their additional types and
properties.
|
static Node |
copyStreamAsFile(Node folderNode,
java.lang.String fileName,
java.io.InputStream in)
Copy a stream as an nt:file, assuming an nt:folder hierarchy.
|
static java.lang.Long |
countFiles(Node node)
Iteratively count all file nodes in subtree, inefficient but can be useful
when query are poorly supported, such as in remoting.
|
static java.lang.String |
dateAsPath(java.util.Calendar cal)
The provided data as a path ('/' at the end, not the beginning)
|
static java.lang.String |
dateAsPath(java.util.Calendar cal,
java.lang.Boolean addHour)
The provided data as a path ('/' at the end, not the beginning)
|
static void |
debug(Node node)
Recursively outputs the contents of the given node.
|
static void |
debug(Node node,
org.apache.commons.logging.Log log)
Recursively outputs the contents of the given node.
|
static java.util.Map<java.lang.String,PropertyDiff> |
diffProperties(Node reference,
Node observed) |
static java.util.Map<java.lang.String,PropertyDiff> |
diffProperties(Node reference,
Node observed,
java.util.List<java.lang.String> properties)
Compare only a restricted list of properties of two nodes.
|
static void |
discardQuietly(Session session)
Discards the current changes in a session by calling
Session.refresh(boolean) with false , only logging
potential errors when doing so. |
static void |
discardUnderlyingSessionQuietly(Node node)
Discards the current changes in the session attached to this node.
|
static java.lang.String |
firstCharsToPath(java.lang.String str,
java.lang.Integer nbrOfChars)
Creates depth from a string (typically a username) by adding levels based on
its first characters: "aBcD",2 becomes a/aB
|
static java.lang.String |
get(Node node,
java.lang.String propertyName)
Concisely get the string value of a property or null if this node doesn't
have this property
|
static AccessControlList |
getAccessControlList(AccessControlManager acm,
java.lang.String path)
Gets the first available access control list for this path, throws exception
if not found
|
static byte[] |
getBinaryAsBytes(Property property)
Retrieve a
Binary as a byte array |
static byte[] |
getBytes(Node node,
java.lang.String propertyName)
Concisely get the bytes array value of a property
|
static java.io.InputStream |
getFileAsStream(Node fileNode)
Read an an nt:file as an
InputStream . |
static java.lang.String |
getNameQuietly(Node node)
Call
Item.getName() without exceptions (useful in super
constructors). |
static long |
getNodeApproxSize(Node node)
Estimate the sub tree size from current node.
|
static Node |
getOrAdd(Node parent,
java.lang.String childName)
Routine that get the child with this name, adding id it does not already
exist
|
static Node |
getOrAdd(Node parent,
java.lang.String childName,
java.lang.String childPrimaryNodeType)
Routine that get the child with this name, adding id it does not already
exist
|
static java.lang.String |
getPath(Node node)
Concisely get the path of the given node.
|
static java.lang.String |
getPropertyDefinitionAsString(Property prop)
Returns a String representing the short version (see
Node type
Notation attributes grammar) of the main business attributes of this
property definition
|
static java.lang.String |
getStringPropertyQuietly(Node node,
java.lang.String propertyName)
Call
Node.getProperty(String) without exceptions (useful in super
constructors). |
static java.lang.String |
hostAsPath(java.lang.String host)
Creates a path from a FQDN, inverting the order of the component:
www.argeo.org becomes org.argeo.www
|
static java.lang.String |
lastPathElement(java.lang.String path)
The last element of a path.
|
static void |
logEffectiveAccessPolicies(Node node)
Logs the effective access control policies
|
static void |
logEffectiveAccessPolicies(Session session,
java.lang.String path)
Logs the effective access control policies
|
static Session |
loginOrCreateWorkspace(Repository repository,
java.lang.String workspaceName)
Login to a workspace with implicit credentials, creates the workspace with
these credentials if it does not already exist.
|
static Session |
loginOrCreateWorkspace(Repository repository,
java.lang.String workspaceName,
Credentials credentials)
Login to a workspace with implicit credentials, creates the workspace with
these credentials if it does not already exist.
|
static void |
logoutQuietly(Session session)
Logs out the session, not throwing any exception, even if it is null.
|
static Node |
mkdirs(Node parentNode,
java.lang.String relativePath)
Create sub nodes relative to a parent node
|
static Node |
mkdirs(Node parentNode,
java.lang.String relativePath,
java.lang.String nodeType)
Create sub nodes relative to a parent node
|
static Node |
mkdirs(Node parentNode,
java.lang.String relativePath,
java.lang.String nodeType,
java.lang.String intermediaryNodeType)
Create sub nodes relative to a parent node
|
static Node |
mkdirs(Session session,
java.lang.String path)
Creates the nodes making path, if they don't exist.
|
static Node |
mkdirs(Session session,
java.lang.String path,
java.lang.String type) |
static Node |
mkdirs(Session session,
java.lang.String path,
java.lang.String type,
java.lang.String intermediaryNodeType,
java.lang.Boolean versioning)
Creates the nodes making path, if they don't exist.
|
static Node |
mkdirsSafe(Session session,
java.lang.String path) |
static Node |
mkdirsSafe(Session session,
java.lang.String path,
java.lang.String type)
Synchronized and save is performed, to avoid race conditions in initializers
leading to duplicate nodes.
|
static Node |
mkfolders(Session session,
java.lang.String path)
Creates the nodes making the path as
NodeType.NT_FOLDER |
static java.util.List<Node> |
nodeIteratorToList(NodeIterator nodeIterator)
Convert a
NodeIterator to a list of Node |
static java.lang.String |
nodeNameFromPath(java.lang.String path)
Retrieves the node name from the provided path
|
static java.lang.String |
normalize(java.lang.String name)
Normalizes a name so that it can be stored in contexts not supporting names
with ':' (typically databases).
|
static java.lang.String |
normalizePath(java.lang.String path)
Make sure that: starts with '/', do not end with '/', do not have '//'
|
static java.lang.String |
parentPath(java.lang.String path)
Retrieves the parent path of the provided path
|
static java.util.Calendar |
parseCalendar(java.text.DateFormat dateFormat,
java.lang.String value)
Converts in one call a string into a gregorian calendar.
|
static Node |
querySingleNode(Query query)
Queries one single node.
|
static void |
registerNamespaceSafely(NamespaceRegistry nr,
java.lang.String prefix,
java.lang.String uri)
Safe and repository implementation independent registration of a namespace.
|
static void |
registerNamespaceSafely(Session session,
java.lang.String prefix,
java.lang.String uri)
Safe and repository implementation independent registration of a namespace.
|
static void |
removeListenerQuietly(Session session,
EventListener listener)
Removes a listener without throwing exception
|
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 void |
setBinaryAsBytes(Node node,
java.lang.String property,
byte[] bytes)
Writes a
Binary from a byte array |
static void |
setBinaryAsBytes(Property prop,
byte[] bytes)
Writes a
Binary from a byte array |
static java.util.List<java.lang.String> |
tokenize(java.lang.String path)
Convert a path to the list of its tokens
|
static void |
unregisterQuietly(Node node,
EventListener eventListener)
Quietly unregisters an
EventListener from the udnerlying workspace of
this node. |
static void |
unregisterQuietly(Workspace workspace,
EventListener eventListener)
Quietly unregisters an
EventListener from this workspace |
static void |
updateLastModified(Node node)
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 underlying session
user id. |
static void |
updateLastModifiedAndParents(Node node,
java.lang.String untilPath)
Update lastModified recursively until this parent.
|
static java.lang.String |
urlAsPath(java.lang.String url)
Creates a deep path based on a URL:
http://subdomain.example.com/to/content?args becomes
com/example/subdomain/to/content
|
static java.lang.String |
urlFromAddressProperties(Node node)
Build URL based on the
NodeType.NT_ADDRESS properties. |
static void |
urlToAddressProperties(Node node,
java.lang.String url)
Set the
NodeType.NT_ADDRESS properties based on this URL. |
static java.lang.String |
uuidAsPath(java.lang.String uuid)
Creates a path from a UUID (e.g.
|
public static final char[] INVALID_NAME_CHARACTERS
public static Node querySingleNode(Query query)
ArgeoJcrException
- if more than one node was foundpublic static java.lang.String nodeNameFromPath(java.lang.String path)
public static java.lang.String parentPath(java.lang.String path)
public static java.lang.String dateAsPath(java.util.Calendar cal)
public static java.lang.String urlAsPath(java.lang.String url)
public static void urlToAddressProperties(Node node, java.lang.String url)
NodeType.NT_ADDRESS
properties based on this URL.public static java.lang.String urlFromAddressProperties(Node node)
NodeType.NT_ADDRESS
properties.public static java.lang.String normalizePath(java.lang.String path)
public static java.lang.String hostAsPath(java.lang.String host)
public static java.lang.String uuidAsPath(java.lang.String uuid)
public static java.lang.String dateAsPath(java.util.Calendar cal, java.lang.Boolean addHour)
cal
- the dateaddHour
- whether to add hour as wellpublic static java.util.Calendar parseCalendar(java.text.DateFormat dateFormat, java.lang.String value)
public static java.lang.String lastPathElement(java.lang.String path)
public static java.lang.String getNameQuietly(Node node)
Item.getName()
without exceptions (useful in super
constructors).public static java.lang.String getStringPropertyQuietly(Node node, java.lang.String propertyName)
Node.getProperty(String)
without exceptions (useful in super
constructors).public static Node getOrAdd(Node parent, java.lang.String childName, java.lang.String childPrimaryNodeType) throws RepositoryException
RepositoryException
public static Node getOrAdd(Node parent, java.lang.String childName) throws RepositoryException
RepositoryException
public static java.util.List<Node> nodeIteratorToList(NodeIterator nodeIterator)
NodeIterator
to a list of Node
public static java.lang.String get(Node node, java.lang.String propertyName)
public static java.lang.String getPath(Node node)
public static java.lang.Boolean check(Node node, java.lang.String propertyName)
public static byte[] getBytes(Node node, java.lang.String propertyName)
public static Node mkdirs(Node parentNode, java.lang.String relativePath)
public static Node mkdirs(Node parentNode, java.lang.String relativePath, java.lang.String nodeType)
nodeType
- the type of the leaf nodepublic static Node mkdirs(Node parentNode, java.lang.String relativePath, java.lang.String nodeType, java.lang.String intermediaryNodeType)
nodeType
- the type of the leaf nodepublic static Node mkdirsSafe(Session session, java.lang.String path, java.lang.String type)
public static Node mkdirs(Session session, java.lang.String path)
public static Node mkdirs(Session session, java.lang.String path, java.lang.String type)
type
- the type of the leaf nodepublic static Node mkdirs(Session session, java.lang.String path, java.lang.String type, java.lang.String intermediaryNodeType, java.lang.Boolean versioning)
public static java.util.List<java.lang.String> tokenize(java.lang.String path)
public static void registerNamespaceSafely(Session session, java.lang.String prefix, java.lang.String uri)
public static void registerNamespaceSafely(NamespaceRegistry nr, java.lang.String prefix, java.lang.String uri)
public static void debug(Node node)
public static void debug(Node node, org.apache.commons.logging.Log log)
public static void logEffectiveAccessPolicies(Node node)
public static void logEffectiveAccessPolicies(Session session, java.lang.String path)
public static java.lang.String accessControlListSummary(AccessControlList acl)
public static void copy(Node fromNode, Node toNode)
NodeType.MIX_CREATED
and
NodeType.MIX_LAST_MODIFIED
, but update the
Property.JCR_LAST_MODIFIED
and Property.JCR_LAST_MODIFIED_BY
properties if the target node has the NodeType.MIX_LAST_MODIFIED
mixin.public static java.lang.Boolean allPropertiesEquals(Node reference, Node observed, java.lang.Boolean onlyCommonProperties)
public static java.util.Map<java.lang.String,PropertyDiff> diffProperties(Node reference, Node observed)
public static java.util.Map<java.lang.String,PropertyDiff> diffProperties(Node reference, Node observed, java.util.List<java.lang.String> properties)
public static java.lang.String normalize(java.lang.String name)
public static java.lang.String replaceInvalidChars(java.lang.String name)
INVALID_NAME_CHARACTERS
public static java.lang.String replaceInvalidChars(java.lang.String name, char replacement)
INVALID_NAME_CHARACTERS
public static void closeQuietly(Binary binary)
Binary
even if it is null.public static byte[] getBinaryAsBytes(Property property)
Binary
as a byte arraypublic static void setBinaryAsBytes(Node node, java.lang.String property, byte[] bytes)
Binary
from a byte arraypublic static void setBinaryAsBytes(Property prop, byte[] bytes)
Binary
from a byte arraypublic static java.lang.String firstCharsToPath(java.lang.String str, java.lang.Integer nbrOfChars)
public static void discardUnderlyingSessionQuietly(Node node)
discardQuietly(Session)
public static void discardQuietly(Session session)
Session.refresh(boolean)
with false
, only logging
potential errors when doing so. To be used typically in a catch block.public static Session loginOrCreateWorkspace(Repository repository, java.lang.String workspaceName) throws RepositoryException
RepositoryException
public static Session loginOrCreateWorkspace(Repository repository, java.lang.String workspaceName, Credentials credentials) throws RepositoryException
RepositoryException
public static void logoutQuietly(Session session)
Jcr.logout(Session)
should rather be used.public static void addListener(Session session, EventListener listener, int eventTypes, java.lang.String basePath, java.lang.String nodeType)
public static void removeListenerQuietly(Session session, EventListener listener)
public static void unregisterQuietly(Node node, EventListener eventListener)
EventListener
from the udnerlying workspace of
this node.public static void unregisterQuietly(Workspace workspace, EventListener eventListener)
EventListener
from this workspacepublic static void updateLastModified(Node node)
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 underlying session
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 void updateLastModifiedAndParents(Node node, java.lang.String untilPath)
node
- the nodeuntilPath
- the base path, null is equivalent to "/"public static java.lang.String getPropertyDefinitionAsString(Property prop)
prop
- public static long getNodeApproxSize(Node node)
Property.getLength()
method. Note : it is not the exact size used on
the disk by the current part of the JCR Tree.public static void addPrivilege(Session session, java.lang.String path, java.lang.String principal, java.lang.String privilege) throws RepositoryException
RepositoryException
public static java.lang.Boolean addPrivileges(Session session, java.lang.String path, java.security.Principal principal, java.util.List<Privilege> privs) throws RepositoryException
Principal
. The path must already exist.
Session is saved. Synchronized to prevent concurrent modifications of the
same node.RepositoryException
public static AccessControlList getAccessControlList(AccessControlManager acm, java.lang.String path) throws RepositoryException
RepositoryException
public static void clearAccessControList(Session session, java.lang.String path, java.lang.String username) throws RepositoryException
RepositoryException
public static Node mkfolders(Session session, java.lang.String path)
NodeType.NT_FOLDER
public static java.lang.Long copyFiles(Node fromNode, Node toNode, java.lang.Boolean recursive, JcrMonitor monitor, boolean onlyAdd)
recursive
- if true copies folders as well, otherwise only first level
filespublic static java.lang.Long countFiles(Node node)
public static Node copyFile(Node folderNode, java.io.File file)
public static Node copyBytesAsFile(Node folderNode, java.lang.String fileName, byte[] bytes)
public static Node copyStreamAsFile(Node folderNode, java.lang.String fileName, java.io.InputStream in)
public static java.io.InputStream getFileAsStream(Node fileNode) throws RepositoryException
InputStream
.RepositoryException
@Deprecated public static java.lang.String checksumFile(Node fileNode, java.lang.String algorithm)
Copyright © 2007–2020. All rights reserved.