public class JcrResourceUtil extends Object
JcrResourceUtil
class provides helper methods used
throughout this bundle.Constructor and Description |
---|
JcrResourceUtil() |
Modifier and Type | Method and Description |
---|---|
static javax.jcr.Node |
createPath(javax.jcr.Node parentNode,
String relativePath,
String intermediateNodeType,
String nodeType,
boolean autoSave)
Creates or gets the
Node at the given Path. |
static javax.jcr.Node |
createPath(String path,
String intermediateNodeType,
String nodeType,
javax.jcr.Session session,
boolean autoSave)
Creates or gets the
Node at the given Path. |
static javax.jcr.Value |
createValue(Object value,
javax.jcr.Session session)
Creates a
JCR Value for the given object with
the given Session. |
static String |
getResourceSuperType(Resource resource)
Deprecated.
|
static String |
getResourceSuperType(ResourceResolver resourceResolver,
String resourceType)
Deprecated.
|
static javax.jcr.query.QueryResult |
query(javax.jcr.Session session,
String query,
String language)
Helper method to execute a JCR query.
|
static String |
resourceTypeToPath(String type)
Deprecated.
|
static void |
setProperty(javax.jcr.Node node,
String propertyName,
Object propertyValue)
Sets the value of the property.
|
static Object |
toJavaObject(javax.jcr.Property property)
Converts the value(s) of a JCR Property to a corresponding Java Object.
|
static Object |
toJavaObject(javax.jcr.Value value)
Converts a JCR Value to a corresponding Java Object
|
public static javax.jcr.query.QueryResult query(javax.jcr.Session session, String query, String language) throws javax.jcr.RepositoryException
session
- the sessionquery
- the querylanguage
- the languagejavax.jcr.RepositoryException
- if the QueryManager
cannot be retrievedpublic static Object toJavaObject(javax.jcr.Value value) throws javax.jcr.RepositoryException
value
- the JCR Value to convertjavax.jcr.RepositoryException
- if the value cannot be convertedpublic static Object toJavaObject(javax.jcr.Property property) throws javax.jcr.RepositoryException
property
- the property to be converted to the corresponding Java Objectjavax.jcr.RepositoryException
- if the conversion cannot take placepublic static javax.jcr.Value createValue(Object value, javax.jcr.Session session) throws javax.jcr.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 forjavax.jcr.RepositoryException
- in case of error, accessing the Repositorypublic static void setProperty(javax.jcr.Node node, String propertyName, Object propertyValue) throws javax.jcr.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.javax.jcr.RepositoryException
- if the property cannot be set@Deprecated public static String resourceTypeToPath(String type)
ResourceUtil.resourceTypeToPath(String)
Resource.getResourceType()
as a
relative path.type
- The resource type to be converted into a path@Deprecated public static String getResourceSuperType(ResourceResolver resourceResolver, String resourceType)
ResourceUtil.getResourceSuperType(ResourceResolver, String)
JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY
of the
Resource
addressed by the resourceType
to a
string. If no such child resource exists or if the resource does not
adapt to a string, this method returns null
.resourceResolver
- The ResourceResolver
used to
access the resource whose path (relative or absolute) is given
by the resourceType
parameter.resourceType
- The resource type whose super type is to be returned.
This type is turned into a path by calling the
resourceTypeToPath(String)
method before trying to
get the resource through the resourceResolver
.resourceType
or
null
if the resource type does not have a child
resource
JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY
adapting to a string.@Deprecated public static String getResourceSuperType(Resource resource)
ResourceUtil.findResourceSuperType(Resource)
JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY
if the
given resource
adapted to a string or the result of
calling the getResourceSuperType(ResourceResolver, String)
method on the resource type of the resource
.
This mechanism allows to specifically set the resource super type on a per-resource level overwriting any resource super type hierarchy pre-defined by the actual resource type of the resource.
resource
- The Resource
whose resource super type is
requested.null
if the algorithm
described above does not yield a resource super type.public static javax.jcr.Node createPath(String path, String intermediateNodeType, String nodeType, javax.jcr.Session session, boolean autoSave) throws javax.jcr.RepositoryException
Node
at the given Path.
In case it has to create the Node all non-existent intermediate path-elements
will be create with the given intermediate node type and the returned node
will be created with the given nodeTypepath
- to createintermediateNodeType
- to use for creation of intermediate nodes (or null)nodeType
- to use for creation of the final node (or null)session
- to useautoSave
- Should save be called when a new node is created?javax.jcr.RepositoryException
- in case of exception accessing the Repositorypublic static javax.jcr.Node createPath(javax.jcr.Node parentNode, String relativePath, String intermediateNodeType, String nodeType, boolean autoSave) throws javax.jcr.RepositoryException
Node
at the given Path.
In case it has to create the Node all non-existent intermediate path-elements
will be create with the given intermediate node type and the returned node
will be created with the given nodeTypeparentNode
- starting noderelativePath
- to createintermediateNodeType
- to use for creation of intermediate nodes (or null)nodeType
- to use for creation of the final node (or null)autoSave
- Should save be called when a new node is created?javax.jcr.RepositoryException
- in case of exception accessing the RepositoryCopyright © 2015 The Apache Software Foundation. All rights reserved.