org.alfresco.web.bean.repository
Class Repository

java.lang.Object
  extended by org.alfresco.web.bean.repository.Repository

public final class Repository
extends java.lang.Object

Helper class for accessing repository objects, convert values, escape values and service utilities.


Field Summary
static java.lang.String ERROR_EXISTS
           
static java.lang.String ERROR_GENERIC
           
static java.lang.String ERROR_NODEREF
          I18N error messages
static java.lang.String ERROR_NOHOME
           
static java.lang.String ERROR_QUERY
           
static java.lang.String ERROR_SEARCH
           
 
Method Summary
static java.lang.String escapeQName(org.alfresco.service.namespace.QName qName)
          Escape a QName value so it can be used in lucene search strings
static boolean extractMetadata(javax.faces.context.FacesContext context, org.alfresco.service.cmr.repository.ContentReader reader, java.util.Map destination)
          Extracts the metadata of a "raw" piece of content into a map.
static org.alfresco.service.cmr.repository.NodeRef getCompanyRoot(javax.faces.context.FacesContext context)
          Returns a company root node reference object.
static org.alfresco.service.cmr.repository.NodeRef getCompanyRoot(org.alfresco.service.cmr.repository.NodeService nodeService, org.alfresco.service.cmr.search.SearchService searchService, org.alfresco.service.namespace.NamespaceService namespaceService, org.alfresco.service.cmr.repository.StoreRef storeRef, java.lang.String rootPath)
          Returns a company root node reference object.
static org.alfresco.repo.configuration.ConfigurableService getConfigurableService(javax.faces.context.FacesContext context)
          Return the Configurable Service
static java.lang.String getDisplayPath(org.alfresco.service.cmr.repository.Path path)
          Return the human readable form of the specified node Path.
static java.lang.String getDisplayPath(org.alfresco.service.cmr.repository.Path path, boolean showLeaf)
          Return the human readable form of the specified node Path.
static boolean getIsGuest(javax.faces.context.FacesContext context)
           
static org.alfresco.repo.content.metadata.MetadataExtracterRegistry getMetadataExtracterRegistry(javax.faces.context.FacesContext context)
          Return the Metadata Extracter Registry
static java.lang.String getMimeTypeForFile(javax.faces.context.FacesContext context, java.lang.String filename, java.io.File file)
          Return the mimetype for the specified file, based on both the file name and the file's contents.
static java.lang.String getMimeTypeForFileName(javax.faces.context.FacesContext context, java.lang.String filename)
          Return the mimetype for the specified file name.
static java.lang.String getNameForCategoryNode(org.alfresco.service.cmr.repository.NodeService nodeService, org.alfresco.service.cmr.repository.NodeRef ref)
          Helper to get the display name path for a category node.
static java.lang.String getNameForNode(org.alfresco.service.cmr.repository.NodeService nodeService, org.alfresco.service.cmr.repository.NodeRef ref)
          Helper to get the display name for a Node.
static java.lang.String getNamePath(org.alfresco.service.cmr.repository.NodeService nodeService, org.alfresco.service.cmr.repository.Path path, org.alfresco.service.cmr.repository.NodeRef rootNode, java.lang.String separator, java.lang.String prefix)
          Resolve a Path by converting each element into its display NAME attribute
static java.lang.String getNamePathEx(javax.faces.context.FacesContext context, org.alfresco.service.cmr.repository.Path path, org.alfresco.service.cmr.repository.NodeRef rootNode, java.lang.String separator, java.lang.String prefix)
          Resolve a Path by converting each element into its display NAME attribute.
static org.alfresco.repo.transaction.RetryingTransactionHelper getRetryingTransactionHelper(javax.faces.context.FacesContext context)
          Returns the transaction helper that executes a unit of work.
static org.alfresco.service.ServiceRegistry getServiceRegistry(javax.faces.context.FacesContext context)
          Return the Repository Service Registry
static org.alfresco.service.ServiceRegistry getServiceRegistry(javax.servlet.ServletContext context)
          Return the Repository Service Registry
static org.alfresco.service.cmr.repository.StoreRef getStoreRef()
          Returns a store reference object
static org.alfresco.service.cmr.repository.StoreRef getStoreRef(javax.servlet.ServletContext context)
          Returns a store reference object.
static java.util.List getUsers(javax.faces.context.FacesContext context, org.alfresco.service.cmr.repository.NodeService nodeService, org.alfresco.service.cmr.security.PersonService personService)
          Query a list of Person type nodes from the repo It is currently assumed that all Person nodes exist below the Repository root node
static java.util.List getUsers(javax.faces.context.FacesContext context, org.alfresco.service.cmr.repository.NodeService nodeService, org.alfresco.service.cmr.search.SearchService searchService)
          Deprecated. Use Repository.getUsers(FacesContext, NodeService, PersonService) instead
static javax.transaction.UserTransaction getUserTransaction(javax.faces.context.FacesContext context)
          Deprecated.  
static javax.transaction.UserTransaction getUserTransaction(javax.faces.context.FacesContext context, boolean readonly)
          Return a UserTransaction instance
static java.lang.String guessEncoding(javax.faces.context.FacesContext context, java.io.InputStream is, java.lang.String mimetype)
          Extract the characterset from the stream
static java.lang.Boolean isNodeLocked(Node node, org.alfresco.service.cmr.lock.LockService lockService)
          Return whether a Node is currently locked
static java.lang.Boolean isNodeOwnerLocked(Node node, org.alfresco.service.cmr.lock.LockService lockService)
          Return whether a Node is currently locked by the current user
static org.alfresco.service.namespace.QName resolveToQName(java.lang.String str)
          Creates a QName representation for the given String.
static java.lang.String resolveToQNameString(java.lang.String str)
          Creates a string representation of a QName for the given string.
static java.lang.String safePropertyToString(java.io.Serializable value)
          Convert a property of unknown type to a String value.
static void setupBreadcrumbLocation(javax.faces.context.FacesContext context, NavigationBean navBean, java.util.List location, org.alfresco.service.cmr.repository.NodeRef node)
          Sets up the breadcrumb location representation for the given node in the given list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERROR_NODEREF

public static final java.lang.String ERROR_NODEREF
I18N error messages

See Also:
Constant Field Values

ERROR_GENERIC

public static final java.lang.String ERROR_GENERIC
See Also:
Constant Field Values

ERROR_NOHOME

public static final java.lang.String ERROR_NOHOME
See Also:
Constant Field Values

ERROR_SEARCH

public static final java.lang.String ERROR_SEARCH
See Also:
Constant Field Values

ERROR_QUERY

public static final java.lang.String ERROR_QUERY
See Also:
Constant Field Values

ERROR_EXISTS

public static final java.lang.String ERROR_EXISTS
See Also:
Constant Field Values
Method Detail

getStoreRef

public static org.alfresco.service.cmr.repository.StoreRef getStoreRef()
Returns a store reference object

Returns:
A StoreRef object

getStoreRef

public static org.alfresco.service.cmr.repository.StoreRef getStoreRef(javax.servlet.ServletContext context)
Returns a store reference object. This method is used to setup the cached value by the ContextListener initialisation methods

Returns:
The StoreRef object

getCompanyRoot

public static org.alfresco.service.cmr.repository.NodeRef getCompanyRoot(javax.faces.context.FacesContext context)
Returns a company root node reference object.

Returns:
The NodeRef object

getCompanyRoot

public static org.alfresco.service.cmr.repository.NodeRef getCompanyRoot(org.alfresco.service.cmr.repository.NodeService nodeService,
                                                                         org.alfresco.service.cmr.search.SearchService searchService,
                                                                         org.alfresco.service.namespace.NamespaceService namespaceService,
                                                                         org.alfresco.service.cmr.repository.StoreRef storeRef,
                                                                         java.lang.String rootPath)
Returns a company root node reference object.

Returns:
The NodeRef object

getNameForNode

public static java.lang.String getNameForNode(org.alfresco.service.cmr.repository.NodeService nodeService,
                                              org.alfresco.service.cmr.repository.NodeRef ref)
Helper to get the display name for a Node. The method will attempt to use the "name" attribute, if not found it will revert to using the QName.getLocalName() retrieved from the primary parent relationship.

Parameters:
ref - NodeRef
Returns:
display name string for the specified Node.

getNameForCategoryNode

public static java.lang.String getNameForCategoryNode(org.alfresco.service.cmr.repository.NodeService nodeService,
                                                      org.alfresco.service.cmr.repository.NodeRef ref)
Helper to get the display name path for a category node.

Parameters:
nodeService -
ref - the category node ref
Returns:
display name string for the specified category node.

escapeQName

public static java.lang.String escapeQName(org.alfresco.service.namespace.QName qName)
Escape a QName value so it can be used in lucene search strings

Parameters:
qName - QName to escape
Returns:
escaped value

isNodeLocked

public static java.lang.Boolean isNodeLocked(Node node,
                                             org.alfresco.service.cmr.lock.LockService lockService)
Return whether a Node is currently locked

Parameters:
node - The Node wrapper to test against
lockService - The LockService to use
Returns:
whether a Node is currently locked

isNodeOwnerLocked

public static java.lang.Boolean isNodeOwnerLocked(Node node,
                                                  org.alfresco.service.cmr.lock.LockService lockService)
Return whether a Node is currently locked by the current user

Parameters:
node - The Node wrapper to test against
lockService - The LockService to use
Returns:
whether a Node is currently locked by the current user

getDisplayPath

public static java.lang.String getDisplayPath(org.alfresco.service.cmr.repository.Path path)
Return the human readable form of the specified node Path. Fast version of the method that simply converts QName localname components to Strings.

Parameters:
path - Path to extract readable form from, excluding the final element
Returns:
human readable form of the Path excluding the final element

getDisplayPath

public static java.lang.String getDisplayPath(org.alfresco.service.cmr.repository.Path path,
                                              boolean showLeaf)
Return the human readable form of the specified node Path. Fast version of the method that simply converts QName localname components to Strings.

Parameters:
path - Path to extract readable form from
showLeaf - Whether to process the final leaf element of the path
Returns:
human readable form of the Path excluding the final element

getNamePath

public static java.lang.String getNamePath(org.alfresco.service.cmr.repository.NodeService nodeService,
                                           org.alfresco.service.cmr.repository.Path path,
                                           org.alfresco.service.cmr.repository.NodeRef rootNode,
                                           java.lang.String separator,
                                           java.lang.String prefix)
Resolve a Path by converting each element into its display NAME attribute

Parameters:
path - Path to convert
separator - Separator to user between path elements
prefix - To prepend to the path
Returns:
Path converted using NAME attribute on each element

setupBreadcrumbLocation

public static void setupBreadcrumbLocation(javax.faces.context.FacesContext context,
                                           NavigationBean navBean,
                                           java.util.List location,
                                           org.alfresco.service.cmr.repository.NodeRef node)
Sets up the breadcrumb location representation for the given node in the given list.

Parameters:
context - FacesContext
navBean - NavigationBean instance
location - The location list to setup
node - The Node being navigated to

getNamePathEx

public static java.lang.String getNamePathEx(javax.faces.context.FacesContext context,
                                             org.alfresco.service.cmr.repository.Path path,
                                             org.alfresco.service.cmr.repository.NodeRef rootNode,
                                             java.lang.String separator,
                                             java.lang.String prefix)
Resolve a Path by converting each element into its display NAME attribute. Note: This method resolves path regardless access permissions. Fixes the UI part of the ETWOONE-214 and ETWOONE-238 issues

Parameters:
path - Path to convert
separator - Separator to user between path elements
prefix - To prepend to the path
Returns:
Path converted using NAME attribute on each element

getMimeTypeForFileName

public static java.lang.String getMimeTypeForFileName(javax.faces.context.FacesContext context,
                                                      java.lang.String filename)
Return the mimetype for the specified file name.

The file extension will be extracted from the filename and used to lookup the mimetype.

Parameters:
context - FacesContext
filename - Non-null filename to process
Returns:
mimetype for the specified filename - falls back to 'application/octet-stream' if not found.

getMimeTypeForFile

public static java.lang.String getMimeTypeForFile(javax.faces.context.FacesContext context,
                                                  java.lang.String filename,
                                                  java.io.File file)
Return the mimetype for the specified file, based on both the file name and the file's contents.

The file extension will be extracted from the filename and used along with the file contents to identify the mimetype.

Parameters:
context - FacesContext
filename - Non-null filename to process
file - The File object (used to read the contents)
Returns:
mimetype for the specified filename - falls back to 'application/octet-stream' if not found.

getUserTransaction

public static javax.transaction.UserTransaction getUserTransaction(javax.faces.context.FacesContext context)
Deprecated. 

Return a UserTransaction instance

Parameters:
context - FacesContext
Returns:
UserTransaction
See Also:
Repository.getRetryingTransactionHelper(FacesContext)

getRetryingTransactionHelper

public static org.alfresco.repo.transaction.RetryingTransactionHelper getRetryingTransactionHelper(javax.faces.context.FacesContext context)
Returns the transaction helper that executes a unit of work.

Parameters:
context - FacesContext
Returns:
Returns the transaction helper

getUserTransaction

public static javax.transaction.UserTransaction getUserTransaction(javax.faces.context.FacesContext context,
                                                                   boolean readonly)
Return a UserTransaction instance

Parameters:
context - FacesContext
readonly - Transaction readonly state
Returns:
UserTransaction

getServiceRegistry

public static org.alfresco.service.ServiceRegistry getServiceRegistry(javax.faces.context.FacesContext context)
Return the Repository Service Registry

Parameters:
context - Faces Context
Returns:
the Service Registry

getServiceRegistry

public static org.alfresco.service.ServiceRegistry getServiceRegistry(javax.servlet.ServletContext context)
Return the Repository Service Registry

Parameters:
context - Servlet Context
Returns:
the Service Registry

getConfigurableService

public static org.alfresco.repo.configuration.ConfigurableService getConfigurableService(javax.faces.context.FacesContext context)
Return the Configurable Service

Returns:
the configurable service

getMetadataExtracterRegistry

public static org.alfresco.repo.content.metadata.MetadataExtracterRegistry getMetadataExtracterRegistry(javax.faces.context.FacesContext context)
Return the Metadata Extracter Registry

Parameters:
context - Faces Context
Returns:
the MetadataExtracterRegistry

extractMetadata

public static boolean extractMetadata(javax.faces.context.FacesContext context,
                                      org.alfresco.service.cmr.repository.ContentReader reader,
                                      java.util.Map destination)
Extracts the metadata of a "raw" piece of content into a map.

Parameters:
context - Faces Context
reader - Content reader for the source content to extract from
destination - Map of metadata to set metadata values into
Returns:
True if an extracter was found

guessEncoding

public static java.lang.String guessEncoding(javax.faces.context.FacesContext context,
                                             java.io.InputStream is,
                                             java.lang.String mimetype)
Extract the characterset from the stream

Parameters:
context - the Faces Context
is - the stream of characters or data
mimetype - the stream's mimetype, or null if unknown
Returns:
Returns the guessed characterset and never null

getUsers

public static java.util.List getUsers(javax.faces.context.FacesContext context,
                                      org.alfresco.service.cmr.repository.NodeService nodeService,
                                      org.alfresco.service.cmr.search.SearchService searchService)
Deprecated. Use Repository.getUsers(FacesContext, NodeService, PersonService) instead

Query a list of Person type nodes from the repo It is currently assumed that all Person nodes exist below the Repository root node

Parameters:
context - Faces Context
nodeService - The node service
searchService - The search service, which is ignored
Returns:
List of Person node objects

getUsers

public static java.util.List getUsers(javax.faces.context.FacesContext context,
                                      org.alfresco.service.cmr.repository.NodeService nodeService,
                                      org.alfresco.service.cmr.security.PersonService personService)
Query a list of Person type nodes from the repo It is currently assumed that all Person nodes exist below the Repository root node

Parameters:
context - Faces Context
nodeService - The node service
searchService - used to perform the search
Returns:
List of Person node objects

getIsGuest

public static boolean getIsGuest(javax.faces.context.FacesContext context)
Returns:
true if we are currently the special Guest user

safePropertyToString

public static java.lang.String safePropertyToString(java.io.Serializable value)
Convert a property of unknown type to a String value. A native String value will be returned directly, else toString() will be executed, null is returned as null.

Parameters:
value - Property value
Returns:
value to String or null

resolveToQName

public static org.alfresco.service.namespace.QName resolveToQName(java.lang.String str)
Creates a QName representation for the given String. If the String has no namespace the Alfresco namespace is added. If the String has a prefix an attempt to resolve the prefix to the full URI will be made.

Parameters:
str - The string to convert
Returns:
A QName representation of the given string

resolveToQNameString

public static java.lang.String resolveToQNameString(java.lang.String str)
Creates a string representation of a QName for the given string. If the given string already has a namespace, either a URL or a prefix, nothing the given string is returned. If it does not have a namespace the Alfresco namespace is added.

Parameters:
str - The string to convert
Returns:
A QName String representation of the given string


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.