Class ScriptUtils

  • All Implemented Interfaces:
    org.alfresco.processor.ProcessorExtension, Scopeable

    public class ScriptUtils
    extends BaseScopableProcessorExtension
    Place for general and miscellaneous utility functions not already found in generic JavaScript.
    Author:
    Kevin Roast
    • Constructor Summary

      Constructors 
      Constructor Description
      ScriptUtils()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      ScriptPagingDetails createPaging​(int maxItems, int skipCount)
      Builds a paging object, from the supplied Max Items and Skip Count
      ScriptPagingDetails createPaging​(int maxItems, int skipCount, java.lang.String queryExecutionId)
      Builds a paging object, from the supplied Max Items, Skip Count and Query Execution ID
      ScriptPagingDetails createPaging​(java.util.Map<java.lang.String,​java.lang.String> args)
      Builds a paging object, from the supplied Args object.
      void disableRules()
      Disable rule execution for this thread
      java.lang.String displayPath​(ScriptNode node)
      Function to return the cm:name display path for a node with minimum performance overhead.
      void enableRules()
      Enable rule execution for this thread
      java.util.Date fromISO8601​(java.lang.String isoDateString)
      Parse date from ISO formatted string
      java.lang.String getLocale()
      Returns current thread's locale
      ScriptNode getNodeFromString​(java.lang.String nodeRefString)
      Gets a JS node object from a string noderef
      java.lang.String longQName​(java.lang.String s)
      Given a short-form QName string, this method returns the fully qualified QName string.
      boolean moduleInstalled​(java.lang.String moduleName)
      Function to check if a module is installed
      java.lang.String pad​(java.lang.String s, int len)
      Function to pad a string with zero '0' characters to the required length
      ScriptNode resolveNodeReference​(java.lang.String reference)
      Use the Node Locator Service to find the a node reference from a number of possible locator types.
      void setLocale​(java.lang.String localeStr)
      Sets current Locale from string
      void setNodeService​(org.alfresco.service.cmr.repository.NodeService nodeService)  
      void setServiceRegistry​(ServiceRegistry services)
      Sets the service registry
      java.lang.String shortQName​(java.lang.String s)
      Given a long-form QName string, this method uses the namespace service to create a short-form QName string.
      boolean toBoolean​(java.lang.String booleanString)
      Gets a boolean value from a string
      java.lang.String toISO8601​(long timeInMillis)
      Format timeInMillis to ISO 8601 formatted string
      java.lang.String toISO8601​(java.util.Date date)
      Format date to ISO 8601 formatted string
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ScriptUtils

        public ScriptUtils()
    • Method Detail

      • setServiceRegistry

        public void setServiceRegistry​(ServiceRegistry services)
        Sets the service registry
        Parameters:
        services - the service registry
      • setNodeService

        public void setNodeService​(org.alfresco.service.cmr.repository.NodeService nodeService)
        Parameters:
        nodeService - the NodeService to set
      • displayPath

        public java.lang.String displayPath​(ScriptNode node)
        Function to return the cm:name display path for a node with minimum performance overhead.
        Parameters:
        node - ScriptNode
        Returns:
        cm:name based human readable display path for the give node.
      • pad

        public java.lang.String pad​(java.lang.String s,
                                    int len)
        Function to pad a string with zero '0' characters to the required length
        Parameters:
        s - String to pad with leading zero '0' characters
        len - Length to pad to
        Returns:
        padded string or the original if already at >=len characters
      • getNodeFromString

        public ScriptNode getNodeFromString​(java.lang.String nodeRefString)
        Gets a JS node object from a string noderef
        Parameters:
        nodeRefString - string reference to a node
        Returns:
        a JS node object
      • resolveNodeReference

        public ScriptNode resolveNodeReference​(java.lang.String reference)
        Use the Node Locator Service to find the a node reference from a number of possible locator types. This method is responsible for determining the locator type and then calling the Service as the Service does not know how to guess which locator to use.

        This service supports 'virtual' nodes including the following:

        alfresco://company/home The Company Home root node
        alfresco://user/home The User Home node under Company Home
        alfresco://company/shared The Shared node under Company Home
        alfresco://sites/home The Sites home node under Company Home
        workspace://.../... Any standard NodeRef
        /app:company_home/cm:... XPath QName style node reference

        Parameters:
        reference - The node reference - See above for list of possible node references supported.
        Returns:
        ScriptNode representing the node or null if not found
      • toBoolean

        public boolean toBoolean​(java.lang.String booleanString)
        Gets a boolean value from a string
        Parameters:
        booleanString - boolean string
        Returns:
        boolean the boolean value
        See Also:
        Boolean.parseBoolean(String)
      • moduleInstalled

        public boolean moduleInstalled​(java.lang.String moduleName)
        Function to check if a module is installed
        Parameters:
        moduleName - module name (e.g. "org.alfresco.module.foo")
        Returns:
        boolean true if the module is currently installed
      • toISO8601

        public java.lang.String toISO8601​(long timeInMillis)
        Format timeInMillis to ISO 8601 formatted string
        Parameters:
        timeInMillis - long
        Returns:
        String
      • toISO8601

        public java.lang.String toISO8601​(java.util.Date date)
        Format date to ISO 8601 formatted string
        Parameters:
        date - Date
        Returns:
        String
      • fromISO8601

        public java.util.Date fromISO8601​(java.lang.String isoDateString)
        Parse date from ISO formatted string
        Parameters:
        isoDateString - String
        Returns:
        Date
      • shortQName

        public java.lang.String shortQName​(java.lang.String s)
        Given a long-form QName string, this method uses the namespace service to create a short-form QName string.
        Parameters:
        s - Fully qualified QName string
        Returns:
        the short form of the QName string, e.g. "cm:content"
      • longQName

        public java.lang.String longQName​(java.lang.String s)
        Given a short-form QName string, this method returns the fully qualified QName string.
        Parameters:
        s - Short form QName string, e.g. "cm:content"
        Returns:
        Fully qualified QName string
      • createPaging

        public ScriptPagingDetails createPaging​(int maxItems,
                                                int skipCount)
        Builds a paging object, from the supplied Max Items and Skip Count
      • createPaging

        public ScriptPagingDetails createPaging​(int maxItems,
                                                int skipCount,
                                                java.lang.String queryExecutionId)
        Builds a paging object, from the supplied Max Items, Skip Count and Query Execution ID
      • createPaging

        public ScriptPagingDetails createPaging​(java.util.Map<java.lang.String,​java.lang.String> args)
        Builds a paging object, from the supplied Args object. Requires that the parameters have their standard names, i.e. "maxItems" and "skipCount"
        Parameters:
        args - Mandatory hash of paging arguments

        Possible arguments include:

        maxItems - max count of items to return, default -1 (all)
        skipCount - number of items to skip, default -1 (none)
        queryId
        queryExecutionId

      • disableRules

        public void disableRules()
        Disable rule execution for this thread
      • enableRules

        public void enableRules()
        Enable rule execution for this thread
      • setLocale

        public void setLocale​(java.lang.String localeStr)
        Sets current Locale from string
      • getLocale

        public java.lang.String getLocale()
        Returns current thread's locale