org.alfresco.repo.jscript
Class ScriptUtils

java.lang.Object
  extended by org.alfresco.repo.processor.BaseProcessorExtension
      extended by org.alfresco.repo.jscript.BaseScopableProcessorExtension
          extended by org.alfresco.repo.jscript.ScriptUtils
All Implemented Interfaces:
org.alfresco.processor.ProcessorExtension, Scopeable

public final class ScriptUtils
extends BaseScopableProcessorExtension

Place for general and miscellaneous utility functions not already found in generic JavaScript.


Constructor Summary
ScriptUtils()
           
 
Method Summary
 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 args)
          Builds a paging object, from the supplied Args object.
 void disableRules()
          Disable rule execution for this thread
 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
 void setLocale(java.lang.String language)
          Sets current Locale from string
 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(java.util.Date date)
          Format date to ISO 8601 formatted string
 java.lang.String toISO8601(long timeInMillis)
          Format timeInMillis to ISO 8601 formatted string
 java.lang.String toLocalizedString(java.lang.String messageId, java.lang.Object[] params)
          Get a localized message string, parameterized using standard MessageFormatter.
 
Methods inherited from class org.alfresco.repo.jscript.BaseScopableProcessorExtension
getScope, setScope
 
Methods inherited from class org.alfresco.repo.processor.BaseProcessorExtension
getExtensionName, register, setExtensionName, setProcessor
 
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

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

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 -
Returns:

toISO8601

public java.lang.String toISO8601(java.util.Date date)
Format date to ISO 8601 formatted string

Parameters:
date -
Returns:

fromISO8601

public java.util.Date fromISO8601(java.lang.String isoDateString)
Parse date from ISO formatted string

Parameters:
isoDateString -
Returns:

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 args)
Builds a paging object, from the supplied Args object. Requires that the parameters have their standard names, i.e. "maxItems" and "skipCount"


toLocalizedString

public java.lang.String toLocalizedString(java.lang.String messageId,
                                          java.lang.Object[] params)
Get a localized message string, parameterized using standard MessageFormatter.

Parameters:
messageKey - message key
params - format parameters
Returns:
the localized string, null if not found

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 language)
Sets current Locale from string


getLocale

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



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