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
  • Field Details

  • Constructor Details

    • ScriptUtils

      public ScriptUtils()
  • Method Details

    • setServiceRegistry

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

      public void setNodeService(NodeService nodeService)
      Parameters:
      nodeService - the NodeService to set
    • displayPath

      public 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 String pad(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(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(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(String booleanString)
      Gets a boolean value from a string
      Parameters:
      booleanString - boolean string
      Returns:
      boolean the boolean value
      See Also:
    • moduleInstalled

      public boolean moduleInstalled(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 String toISO8601(long timeInMillis)
      Format timeInMillis to ISO 8601 formatted string
      Parameters:
      timeInMillis - long
      Returns:
      String
    • toISO8601

      public String toISO8601(Date date)
      Format date to ISO 8601 formatted string
      Parameters:
      date - Date
      Returns:
      String
    • fromISO8601

      public Date fromISO8601(String isoDateString)
      Parse date from ISO formatted string
      Parameters:
      isoDateString - String
      Returns:
      Date
    • shortQName

      public String shortQName(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 String longQName(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, String queryExecutionId)
      Builds a paging object, from the supplied Max Items, Skip Count and Query Execution ID
    • createPaging

      public ScriptPagingDetails createPaging(Map<String,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(String localeStr)
      Sets current Locale from string
    • getLocale

      public String getLocale()
      Returns current thread's locale