com.silverpeas.jcrutil
Class BasicDaoFactory

java.lang.Object
  extended by com.silverpeas.jcrutil.BasicDaoFactory
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware

public class BasicDaoFactory
extends Object
implements org.springframework.context.ApplicationContextAware

Author:
Emmanuel Hugonnet

Field Summary
static String JRC_REPOSITORY
           
 
Method Summary
static void addCalendarProperty(javax.jcr.Node node, String propertyName, Calendar value)
          Defines the Calendar value of a JCR Node's property.
static void addDateProperty(javax.jcr.Node node, String propertyName, Date value)
          Defines the Calendar value of a JCR Node's property.
static void addStringProperty(javax.jcr.Node node, String propertyName, String value)
          Defines the value of a JCR Node's property.
static String computeUniqueName(String prefix, String tableName)
          Compute a unique node name if a node with the same name already exists under the same parent node.
protected  org.springframework.context.ApplicationContext getApplicationContext()
           
static javax.jcr.Session getAuthentifiedSession(String login, String password)
          Create a system JCR session
static Object getBean(String name)
           
static Calendar getCalendarProperty(javax.jcr.Node node, String propertyName)
          Return the property value as Calendar for a JCR Node.
static String getComponentId(javax.jcr.Node node)
          Compute the componentId corresponding to the specified node by checking the name of the first Ancestor.
static byte[] getContent(javax.jcr.Node fileNode)
           
static void getContent(javax.jcr.Node fileNode, OutputStream out)
           
static Date getDateProperty(javax.jcr.Node node, String propertyName)
          Return the property value as java.util.Date for a JCR Node.
static BasicDaoFactory getInstance()
           
static int getIntProperty(javax.jcr.Node node, String propertyName)
          Return the property value as an int for a JCR Node.
static long getLongProperty(javax.jcr.Node node, String propertyName)
          Return the property value as an long for a JCR Node.
static long getSize(javax.jcr.Node contentNode)
           
static String getStringProperty(javax.jcr.Node node, String propertyName)
          Return the property value as String for a JCR Node.
static javax.jcr.Session getSystemSession()
          Create a system JCR session
static void logout(javax.jcr.Session session)
          Logout of the JCR session
static javax.jcr.Value[] removeReference(javax.jcr.Value[] values, String uuid)
          Remove a reference from an array of javax.jcr.Value.
 void setApplicationContext(org.springframework.context.ApplicationContext context)
           
static void setContent(javax.jcr.Node fileNode, byte[] content, String mimeType)
           
static void setContent(javax.jcr.Node fileNode, File file, String mimeType)
           
static void setContent(javax.jcr.Node fileNode, InputStream content, String mimeType)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JRC_REPOSITORY

public static final String JRC_REPOSITORY
See Also:
Constant Field Values
Method Detail

getApplicationContext

protected org.springframework.context.ApplicationContext getApplicationContext()

setApplicationContext

public void setApplicationContext(org.springframework.context.ApplicationContext context)
                           throws org.springframework.beans.BeansException
Specified by:
setApplicationContext in interface org.springframework.context.ApplicationContextAware
Throws:
org.springframework.beans.BeansException

getInstance

public static BasicDaoFactory getInstance()

getBean

public static Object getBean(String name)

getSystemSession

public static javax.jcr.Session getSystemSession()
                                          throws javax.jcr.LoginException,
                                                 javax.jcr.RepositoryException
Create a system JCR session

Returns:
a jcrSession with System rights.
Throws:
javax.jcr.LoginException
javax.jcr.RepositoryException

getAuthentifiedSession

public static javax.jcr.Session getAuthentifiedSession(String login,
                                                       String password)
                                                throws javax.jcr.LoginException,
                                                       javax.jcr.RepositoryException
Create a system JCR session

Parameters:
login - the user's login.
password - the user's password.
Returns:
a jcrSession with user's rights.
Throws:
javax.jcr.LoginException
javax.jcr.RepositoryException

logout

public static void logout(javax.jcr.Session session)
Logout of the JCR session

Parameters:
session - the session to be closed.

getComponentId

public static String getComponentId(javax.jcr.Node node)
                             throws javax.jcr.ItemNotFoundException,
                                    javax.jcr.AccessDeniedException,
                                    javax.jcr.RepositoryException
Compute the componentId corresponding to the specified node by checking the name of the first Ancestor.

Parameters:
node - the node whose componentId is required.
Returns:
the componentId of the specified node.
Throws:
javax.jcr.ItemNotFoundException
javax.jcr.AccessDeniedException
javax.jcr.RepositoryException

addStringProperty

public static void addStringProperty(javax.jcr.Node node,
                                     String propertyName,
                                     String value)
                              throws javax.jcr.version.VersionException,
                                     javax.jcr.lock.LockException,
                                     javax.jcr.nodetype.ConstraintViolationException,
                                     javax.jcr.RepositoryException
Defines the value of a JCR Node's property. If the specified value is null then the corresponding property is removed from the Node.

Parameters:
node - the node whose property is being set.
propertyName - the name of the property being set.
value - the value being set. If it is null then the property is removed.
Throws:
javax.jcr.version.VersionException
javax.jcr.lock.LockException
javax.jcr.nodetype.ConstraintViolationException
javax.jcr.RepositoryException

addDateProperty

public static void addDateProperty(javax.jcr.Node node,
                                   String propertyName,
                                   Date value)
                            throws javax.jcr.version.VersionException,
                                   javax.jcr.lock.LockException,
                                   javax.jcr.nodetype.ConstraintViolationException,
                                   javax.jcr.RepositoryException
Defines the Calendar value of a JCR Node's property. If the specified value is null then the corresponding property is removed from the Node.

Parameters:
node - the node whose property is being set.
propertyName - the name of the property being set.
value - the value being set. If it is null then the property is removed.
Throws:
javax.jcr.version.VersionException
javax.jcr.lock.LockException
javax.jcr.nodetype.ConstraintViolationException
javax.jcr.RepositoryException

addCalendarProperty

public static void addCalendarProperty(javax.jcr.Node node,
                                       String propertyName,
                                       Calendar value)
                                throws javax.jcr.version.VersionException,
                                       javax.jcr.lock.LockException,
                                       javax.jcr.nodetype.ConstraintViolationException,
                                       javax.jcr.RepositoryException
Defines the Calendar value of a JCR Node's property. If the specified value is null then the corresponding property is removed from the Node.

Parameters:
node - the node whose property is being set.
propertyName - the name of the property being set.
value - the value being set. If it is null then the property is removed.
Throws:
javax.jcr.version.VersionException
javax.jcr.lock.LockException
javax.jcr.nodetype.ConstraintViolationException
javax.jcr.RepositoryException

getStringProperty

public static String getStringProperty(javax.jcr.Node node,
                                       String propertyName)
                                throws javax.jcr.ValueFormatException,
                                       javax.jcr.RepositoryException
Return the property value as String for a JCR Node. If the property doesn't exist return null.

Parameters:
node - the node whose property is required.
propertyName - the name of the property required.
Returns:
the String value of the property - null if the property doesn't exist.
Throws:
javax.jcr.RepositoryException
javax.jcr.ValueFormatException

getCalendarProperty

public static Calendar getCalendarProperty(javax.jcr.Node node,
                                           String propertyName)
                                    throws javax.jcr.ValueFormatException,
                                           javax.jcr.RepositoryException
Return the property value as Calendar for a JCR Node. If the property doesn't exist return null.

Parameters:
node - the node whose property is required.
propertyName - the name of the property required.
Returns:
the Calendar value of the property - null if the property doesn't exist.
Throws:
javax.jcr.RepositoryException
javax.jcr.ValueFormatException

getDateProperty

public static Date getDateProperty(javax.jcr.Node node,
                                   String propertyName)
                            throws javax.jcr.ValueFormatException,
                                   javax.jcr.RepositoryException
Return the property value as java.util.Date for a JCR Node. If the property doesn't exist return null.

Parameters:
node - the node whose property is required.
propertyName - the name of the property required.
Returns:
the java.util.Date value of the property - null if the property doesn't exist.
Throws:
javax.jcr.RepositoryException
javax.jcr.ValueFormatException

getIntProperty

public static int getIntProperty(javax.jcr.Node node,
                                 String propertyName)
                          throws javax.jcr.ValueFormatException,
                                 javax.jcr.RepositoryException
Return the property value as an int for a JCR Node. If the property doesn't exist return 0.

Parameters:
node - the node whose property is required.
propertyName - the name of the property required.
Returns:
the int value of the property - 0 if the property doesn't exist.
Throws:
javax.jcr.RepositoryException
javax.jcr.ValueFormatException

getLongProperty

public static long getLongProperty(javax.jcr.Node node,
                                   String propertyName)
                            throws javax.jcr.ValueFormatException,
                                   javax.jcr.RepositoryException
Return the property value as an long for a JCR Node. If the property doesn't exist return 0.

Parameters:
node - the node whose property is required.
propertyName - the name of the property required.
Returns:
the long value of the property - 0 if the property doesn't exist.
Throws:
javax.jcr.RepositoryException
javax.jcr.ValueFormatException

removeReference

public static javax.jcr.Value[] removeReference(javax.jcr.Value[] values,
                                                String uuid)
                                         throws javax.jcr.ValueFormatException,
                                                IllegalStateException,
                                                javax.jcr.RepositoryException
Remove a reference from an array of javax.jcr.Value. If the reference is not found no change is done to the array.

Parameters:
values - the array of references
uuid - the reference to be removed
Returns:
the updated arry of references.
Throws:
javax.jcr.ValueFormatException
IllegalStateException
javax.jcr.RepositoryException

computeUniqueName

public static String computeUniqueName(String prefix,
                                       String tableName)
                                throws UtilException
Compute a unique node name if a node with the same name already exists under the same parent node.

Parameters:
prefix -
tableName - the name of the column used to stored the id.
Returns:
the name of the node.
Throws:
UtilException

setContent

public static void setContent(javax.jcr.Node fileNode,
                              InputStream content,
                              String mimeType)
                       throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

setContent

public static void setContent(javax.jcr.Node fileNode,
                              File file,
                              String mimeType)
                       throws javax.jcr.RepositoryException,
                              IOException
Throws:
javax.jcr.RepositoryException
IOException

setContent

public static void setContent(javax.jcr.Node fileNode,
                              byte[] content,
                              String mimeType)
                       throws javax.jcr.RepositoryException,
                              IOException
Throws:
javax.jcr.RepositoryException
IOException

getContent

public static byte[] getContent(javax.jcr.Node fileNode)
                         throws javax.jcr.RepositoryException,
                                IOException
Throws:
javax.jcr.RepositoryException
IOException

getContent

public static void getContent(javax.jcr.Node fileNode,
                              OutputStream out)
                       throws javax.jcr.RepositoryException,
                              IOException
Throws:
javax.jcr.RepositoryException
IOException

getSize

public static long getSize(javax.jcr.Node contentNode)
                    throws javax.jcr.ValueFormatException,
                           javax.jcr.PathNotFoundException,
                           javax.jcr.RepositoryException
Throws:
javax.jcr.ValueFormatException
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException


Copyright © 2016 Silverpeas. All Rights Reserved.