org.apache.sling.jcr.resource
Class JcrResourceUtil

java.lang.Object
  extended by org.apache.sling.jcr.resource.JcrResourceUtil

public class JcrResourceUtil
extends java.lang.Object

The JcrResourceUtil class provides helper methods used throughout this bundle.


Constructor Summary
JcrResourceUtil()
           
 
Method Summary
static javax.jcr.Node createPath(javax.jcr.Node parentNode, java.lang.String relativePath, java.lang.String intermediateNodeType, java.lang.String nodeType, boolean autoSave)
          Creates or gets the Node at the given Path.
static javax.jcr.Node createPath(java.lang.String path, java.lang.String intermediateNodeType, java.lang.String nodeType, javax.jcr.Session session, boolean autoSave)
          Creates or gets the Node at the given Path.
static javax.jcr.Value createValue(java.lang.Object value, javax.jcr.Session session)
          Creates a JCR Value for the given object with the given Session.
static java.lang.String getResourceSuperType(Resource resource)
          Returns the resource super type of the given resource.
static java.lang.String getResourceSuperType(ResourceResolver resourceResolver, java.lang.String resourceType)
          Returns the super type of the given resource type.
static javax.jcr.query.QueryResult query(javax.jcr.Session session, java.lang.String query, java.lang.String language)
          Helper method to execute a JCR query
static java.lang.String resourceTypeToPath(java.lang.String type)
          Helper method, which returns the given resource type as returned from the Resource.getResourceType() as a relative path.
static void setProperty(javax.jcr.Node node, java.lang.String propertyName, java.lang.Object propertyValue)
          Sets the value of the property.
static java.lang.Object toJavaObject(javax.jcr.Property property)
          Converts the value(s) of a JCR Property to a corresponding Java Object.
static java.lang.Object toJavaObject(javax.jcr.Value value)
          Converts a JCR Value to a corresponding Java Object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JcrResourceUtil

public JcrResourceUtil()
Method Detail

query

public static javax.jcr.query.QueryResult query(javax.jcr.Session session,
                                                java.lang.String query,
                                                java.lang.String language)
                                         throws javax.jcr.RepositoryException
Helper method to execute a JCR query

Throws:
javax.jcr.RepositoryException

toJavaObject

public static java.lang.Object toJavaObject(javax.jcr.Value value)
                                     throws javax.jcr.RepositoryException
Converts a JCR Value to a corresponding Java Object

Throws:
javax.jcr.RepositoryException

toJavaObject

public static java.lang.Object toJavaObject(javax.jcr.Property property)
                                     throws javax.jcr.RepositoryException
Converts the value(s) of a JCR Property to a corresponding Java Object. If the property has multiple values the result is an array of Java Objects representing the converted values of the property.

Throws:
javax.jcr.RepositoryException

createValue

public static javax.jcr.Value createValue(java.lang.Object value,
                                          javax.jcr.Session session)
                                   throws javax.jcr.RepositoryException
Creates a JCR Value for the given object with the given Session. Selects the the PropertyType according the instance of the object's Class

Parameters:
value - object
session - to create value for
Returns:
the value or null if not convertible to a valid PropertyType
Throws:
javax.jcr.RepositoryException - in case of error, accessing the Repository

setProperty

public static void setProperty(javax.jcr.Node node,
                               java.lang.String propertyName,
                               java.lang.Object propertyValue)
                        throws javax.jcr.RepositoryException
Sets the value of the property. Selects the PropertyType according to the instance of the object's class.

Parameters:
node - The node where the property will be set on.
propertyName - The name of the property.
propertyValue - The value for the property.
Throws:
javax.jcr.RepositoryException

resourceTypeToPath

public static java.lang.String resourceTypeToPath(java.lang.String type)
Helper method, which returns the given resource type as returned from the Resource.getResourceType() as a relative path.

Parameters:
type - The resource type to be converted into a path
Returns:
The resource type as a path.

getResourceSuperType

public static java.lang.String getResourceSuperType(ResourceResolver resourceResolver,
                                                    java.lang.String resourceType)
Returns the super type of the given resource type. This is the result of adapting the child resource 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.

Parameters:
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.
Returns:
the super type of the resourceType or null if the resource type does not have a child resource JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY adapting to a string.

getResourceSuperType

public static java.lang.String getResourceSuperType(Resource resource)
Returns the resource super type of the given resource. This is either the child 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.

Parameters:
resource - The Resource whose resource super type is requested.
Returns:
The resource super type or null if the algorithm described above does not yield a resource super type.

createPath

public static javax.jcr.Node createPath(java.lang.String path,
                                        java.lang.String intermediateNodeType,
                                        java.lang.String nodeType,
                                        javax.jcr.Session session,
                                        boolean autoSave)
                                 throws javax.jcr.RepositoryException
Creates or gets the 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 nodeType

Parameters:
path - to create
intermediateNodeType - to use for creation of intermediate nodes (or null)
nodeType - to use for creation of the final node (or null)
session - to use
autoSave - Should save be called when a new node is created?
Returns:
the Node at path
Throws:
javax.jcr.RepositoryException - in case of exception accessing the Repository

createPath

public static javax.jcr.Node createPath(javax.jcr.Node parentNode,
                                        java.lang.String relativePath,
                                        java.lang.String intermediateNodeType,
                                        java.lang.String nodeType,
                                        boolean autoSave)
                                 throws javax.jcr.RepositoryException
Creates or gets the 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 nodeType

Parameters:
parentNode - starting node
relativePath - to create
intermediateNodeType - 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?
Returns:
the Node at path
Throws:
javax.jcr.RepositoryException - in case of exception accessing the Repository


Copyright © 2007-2009. All Rights Reserved.