Package org.alfresco.repo.jscript
Class ScriptUtils
- java.lang.Object
-
- org.alfresco.repo.processor.BaseProcessorExtension
-
- org.alfresco.repo.jscript.BaseScopableProcessorExtension
-
- org.alfresco.repo.jscript.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 Summary
Fields Modifier and Type Field Description protected ServiceRegistryservicesServices
-
Constructor Summary
Constructors Constructor Description ScriptUtils()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ScriptPagingDetailscreatePaging(int maxItems, int skipCount)Builds a paging object, from the supplied Max Items and Skip CountScriptPagingDetailscreatePaging(int maxItems, int skipCount, java.lang.String queryExecutionId)Builds a paging object, from the supplied Max Items, Skip Count and Query Execution IDScriptPagingDetailscreatePaging(java.util.Map<java.lang.String,java.lang.String> args)Builds a paging object, from the supplied Args object.voiddisableRules()Disable rule execution for this threadjava.lang.StringdisplayPath(ScriptNode node)Function to return the cm:name display path for a node with minimum performance overhead.voidenableRules()Enable rule execution for this threadjava.util.DatefromISO8601(java.lang.String isoDateString)Parse date from ISO formatted stringjava.lang.StringgetLocale()Returns current thread's localeScriptNodegetNodeFromString(java.lang.String nodeRefString)Gets a JS node object from a string noderefjava.lang.StringlongQName(java.lang.String s)Given a short-form QName string, this method returns the fully qualified QName string.booleanmoduleInstalled(java.lang.String moduleName)Function to check if a module is installedjava.lang.Stringpad(java.lang.String s, int len)Function to pad a string with zero '0' characters to the required lengthScriptNoderesolveNodeReference(java.lang.String reference)Use the Node Locator Service to find the a node reference from a number of possible locator types.voidsetLocale(java.lang.String localeStr)Sets current Locale from stringvoidsetNodeService(org.alfresco.service.cmr.repository.NodeService nodeService)voidsetServiceRegistry(ServiceRegistry services)Sets the service registryjava.lang.StringshortQName(java.lang.String s)Given a long-form QName string, this method uses the namespace service to create a short-form QName string.booleantoBoolean(java.lang.String booleanString)Gets a boolean value from a stringjava.lang.StringtoISO8601(long timeInMillis)Format timeInMillis to ISO 8601 formatted stringjava.lang.StringtoISO8601(java.util.Date date)Format date to ISO 8601 formatted string-
Methods inherited from class org.alfresco.repo.jscript.BaseScopableProcessorExtension
getScope, setScope
-
Methods inherited from class org.alfresco.repo.processor.BaseProcessorExtension
getExtensionName, register, setExtensionName, setProcessor
-
-
-
-
Field Detail
-
services
protected ServiceRegistry services
Services
-
-
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' characterslen- 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 argumentsPossible 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
-
-