Nuxeo ECM Projects 5.4.3-SNAPSHOT

org.nuxeo.ecm.automation.core.util
Class DocumentHelper

java.lang.Object
  extended by org.nuxeo.ecm.automation.core.util.DocumentHelper

public class DocumentHelper
extends Object

Author:
Bogdan Stefanescu

Method Summary
static void addBlob(Property p, Blob blob)
          Given a document property, updates its value with the given blob.
static HashMap<String,Serializable> createBlobHolderMap(Blob blob)
           
static String[] readStringList(String value)
          Read an encoded string list as a comma separated list.
static Object readStringList(String value, SimpleType type)
          Read an encoded string list as a comma separated list.
static void removeProperty(DocumentModel doc, String xpath)
          Removes a property from a document given the xpath.
static DocumentModel saveDocument(CoreSession session, DocumentModel doc)
          Saves the document and clear context data to avoid incrementing version in next operations if not needed.
static void setProperties(CoreSession session, DocumentModel doc, Map<String,String> values)
          Sets the properties given as a map of xpath:value to the given document.
static void setProperty(CoreSession session, DocumentModel doc, String key, String value)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

saveDocument

public static DocumentModel saveDocument(CoreSession session,
                                         DocumentModel doc)
                                  throws ClientException
Saves the document and clear context data to avoid incrementing version in next operations if not needed.

Throws:
ClientException

removeProperty

public static void removeProperty(DocumentModel doc,
                                  String xpath)
                           throws ClientException
Removes a property from a document given the xpath. If the xpath points to a list property the list will be cleared. If the path points to a blob in a list the property is removed from the list. Otherwise the xpath should point to a non list property that will be removed.

Throws:
ClientException

addBlob

public static void addBlob(Property p,
                           Blob blob)
                    throws PropertyException
Given a document property, updates its value with the given blob. The property can be a blob list or a blob. If a blob list the blob is appended to the list, if a blob then it will be set as the property value. Both blob list formats are supported: the file list (blob holder list) and simple blob list.

Throws:
PropertyException

createBlobHolderMap

public static HashMap<String,Serializable> createBlobHolderMap(Blob blob)

setProperties

public static void setProperties(CoreSession session,
                                 DocumentModel doc,
                                 Map<String,String> values)
                          throws Exception
Sets the properties given as a map of xpath:value to the given document. There is one special property: ecm:acl that can be used to set the local acl. The format of this property value is: [string username]:[string permission]:[boolean grant], [string username]:[string permission]:[boolean grant], ... TODO list properties are not yet supported

Throws:
Exception

setProperty

public static void setProperty(CoreSession session,
                               DocumentModel doc,
                               String key,
                               String value)
                        throws Exception
Throws:
Exception

readStringList

public static Object readStringList(String value,
                                    SimpleType type)
Read an encoded string list as a comma separated list. To use comma inside list element values you need to escape them using '\'. If the given type is different from StringType.ID then array elements will be converted to the actual type.

Parameters:
value -
type -
Returns:

readStringList

public static String[] readStringList(String value)
Read an encoded string list as a comma separated list. To use comma inside list element values you need to escape them using '\'.

Parameters:
value -
Returns:

Nuxeo ECM Projects 5.4.3-SNAPSHOT

Copyright © 2011 Nuxeo SAS. All Rights Reserved.