Class ScriptNode

java.lang.Object
org.alfresco.repo.jscript.ScriptNode
All Implemented Interfaces:
Serializable, Scopeable, NamespacePrefixResolverProvider
Direct Known Subclasses:
ActivitiScriptNode, CategoryNode, ScriptThumbnail

public class ScriptNode extends Object implements Scopeable, NamespacePrefixResolverProvider
Script Node class implementation, specific for use by ScriptService as part of the object model.

The class exposes Node properties, children and assocs as dynamically populated maps and lists. The various collection classes are mirrored as JavaScript properties. So can be accessed using standard JavaScript property syntax, such as node.children[0].properties.name.

Various helper methods are provided to access common and useful node variables such as the content url and type information.

Author:
Kevin Roast
See Also:
  • Field Details

    • scope

      protected org.mozilla.javascript.Scriptable scope
      Root scope for this object
    • converter

      protected ScriptNode.NodeValueConverter converter
      Node Value Converter
    • nodeRef

      protected NodeRef nodeRef
      Cached values
    • id

      protected String id
    • siteName

      protected String siteName
    • siteNameResolved

      protected boolean siteNameResolved
    • aspects

      protected Set<QName> aspects
      The aspects applied to this node
    • services

      protected ServiceRegistry services
    • imageResolver

      protected TemplateImageResolver imageResolver
    • parent

      protected ScriptNode parent
  • Constructor Details

    • ScriptNode

      public ScriptNode(NodeRef nodeRef, ServiceRegistry services)
      Constructor
      Parameters:
      nodeRef - The NodeRef this Node wrapper represents
      services - The ServiceRegistry the Node can use to access services
    • ScriptNode

      public ScriptNode(FileInfo nodeInfo, ServiceRegistry services, org.mozilla.javascript.Scriptable scope)
      Constructor
      Parameters:
      nodeInfo - The FileInfo this Node wrapper represents
      services - The ServiceRegistry the Node can use to access services
      scope - Root scope for this Node
    • ScriptNode

      public ScriptNode(NodeRef nodeRef, ServiceRegistry services, org.mozilla.javascript.Scriptable scope)
      Constructor
      Parameters:
      nodeRef - The NodeRef this Node wrapper represents
      services - The ServiceRegistry the Node can use to access services
      scope - Root scope for this Node
  • Method Details

    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • newInstance

      public ScriptNode newInstance(NodeRef nodeRef, ServiceRegistry services, org.mozilla.javascript.Scriptable scope)
      Factory method
    • newInstance

      public ScriptNode newInstance(FileInfo nodeInfo, ServiceRegistry services, org.mozilla.javascript.Scriptable scope)
    • setScope

      public void setScope(org.mozilla.javascript.Scriptable scope)
      Description copied from interface: Scopeable
      Set the Scriptable global scope
      Specified by:
      setScope in interface Scopeable
      Parameters:
      scope - relative global scope
      See Also:
    • getId

      public String getId()
      Returns:
      The GUID for the node
    • getStoreType

      public String getStoreType()
      Returns:
      the store type for the node
    • getStoreId

      public String getStoreId()
      Returns:
      the store id for the node
    • getNodeRef

      public NodeRef getNodeRef()
      Returns:
      Returns the NodeRef this Node object represents
    • getQNameType

      public QName getQNameType()
      Returns:
      Returns the QName type.
    • getType

      public String getType()
      Returns:
      Returns the type.
    • getTypeShort

      public String getTypeShort()
      Returns:
      Returns the type in short format.
    • getName

      public String getName()
      Returns:
      Helper to return the 'name' property for the node
    • setName

      public void setName(String name)
      Helper to set the 'name' property for the node.
      Parameters:
      name - Name to set
    • getChildren

      public org.mozilla.javascript.Scriptable getChildren()
      Returns:
      The children of this Node as JavaScript array of Node object wrappers
    • getHasChildren

      public boolean getHasChildren()
      Returns:
      true if the Node has children
    • childByNamePath

      public ScriptNode childByNamePath(String path)
      childByNamePath returns the Node at the specified 'cm:name' based Path walking the children of this Node. So a valid call might be: mynode.childByNamePath("/QA/Testing/Docs");
      Parameters:
      path - the relative path of the descendant node to find e.g. "/QA/Testing/Docs"
      Returns:
      The ScriptNode or null if the node is not found. null if the specified path is "".
      Throws:
      NullPointerException - if the provided path is null.
    • childrenByXPath

      public org.mozilla.javascript.Scriptable childrenByXPath(String xpath)
      Returns:
      Returns a JavaScript array of Nodes at the specified XPath starting at this Node. So a valid call might be mynode.childrenByXPath("*[@cm:name='Testing']/*");
    • childFileFolders

      public org.mozilla.javascript.Scriptable childFileFolders()
      Returns:
      Returns a JavaScript array of child file/folder nodes for this nodes. Automatically retrieves all sub-types of cm:content and cm:folder, also removes system folder types from the results. This is equivalent to @see FileFolderService.list()
    • childFileFolders

      public org.mozilla.javascript.Scriptable childFileFolders(boolean files, boolean folders)
      Parameters:
      files - Return files extending from cm:content
      folders - Return folders extending from cm:folder - ignoring sub-types of cm:systemfolder
      Returns:
      Returns a JavaScript array of child file/folder nodes for this nodes. Automatically retrieves all sub-types of cm:content and cm:folder, also removes system folder types from the results. This is equivalent to @see FileFolderService.listFiles() and @see FileFolderService.listFolders()
    • childFileFolders

      public org.mozilla.javascript.Scriptable childFileFolders(boolean files, boolean folders, Object ignoreTypes)
      Parameters:
      files - Return files extending from cm:content
      folders - Return folders extending from cm:folder - ignoring sub-types of cm:systemfolder
      ignoreTypes - Also optionally removes additional type qnames. The additional type can be specified in short or long qname string form as a single string or an Array e.g. "fm:forum".
      Returns:
      Returns a JavaScript array of child file/folder nodes for this nodes. Automatically retrieves all sub-types of cm:content and cm:folder, also removes system folder types from the results. This is equivalent to @see FileFolderService.listFiles() and @see FileFolderService.listFolders()
    • childFileFolders

      public ScriptPagingNodes childFileFolders(boolean files, boolean folders, Object ignoreTypes, int maxItems)
      Deprecated.
      API for review (subject to change prior to release)
      author janv
      Parameters:
      files - Return files extending from cm:content
      folders - Return folders extending from cm:folder - ignoring sub-types of cm:systemfolder
      ignoreTypes - Also optionally removes additional type qnames. The additional type can be specified in short or long qname string form as a single string or an Array e.g. "fm:forum".
      maxItems - Max number of items
      Returns:
      Returns ScriptPagingNodes which includes a JavaScript array of child file/folder nodes for this nodes. Automatically retrieves all sub-types of cm:content and cm:folder, also removes system folder types from the results. This is equivalent to @see FileFolderService.listFiles() and @see FileFolderService.listFolders()
      Since:
      4.0
    • childFileFolders

      public ScriptPagingNodes childFileFolders(boolean files, boolean folders, Object ignoreTypes, int skipOffset, int maxItems, int requestTotalCountMax, String sortProp, Boolean sortAsc, String queryExecutionId)
    • getAssocs

      public Map<String,Object> getAssocs()
      Return the target associations from this Node. As a Map of assoc type to a JavaScript array of Nodes. The Map returned implements the Scriptable interface to allow access to the assoc arrays via JavaScript associative array access. This means associations of this node can be access thus: node.assocs["translations"][0]
      Returns:
      target associations as a Map of assoc name to a JavaScript array of Nodes.
    • getAssociations

      public Map<String,Object> getAssociations()
    • getSourceAssocs

      public Map<String,Object> getSourceAssocs()
      Return the source associations to this Node. As a Map of assoc name to a JavaScript array of Nodes. The Map returned implements the Scriptable interface to allow access to the assoc arrays via JavaScript associative array access. This means source associations to this node can be access thus: node.sourceAssocs["translations"][0]
      Returns:
      source associations as a Map of assoc name to a JavaScript array of Nodes.
    • getSourceAssociations

      public Map<String,Object> getSourceAssociations()
    • getChildAssocs

      public Map<String,Object> getChildAssocs()
      Return the child associations from this Node. As a Map of assoc name to a JavaScript array of Nodes. The Map returned implements the Scriptable interface to allow access to the assoc arrays via JavaScript associative array access. This means associations of this node can be access thus: node.childAssocs["contains"][0]
      Returns:
      child associations as a Map of assoc name to a JavaScript array of Nodes.
    • getChildAssociations

      public Map<String,Object> getChildAssociations()
    • getChildAssocsByType

      public org.mozilla.javascript.Scriptable getChildAssocsByType(String type)
      Return an Array of the associations from this Node that match a specific object type. node.getChildAssocsByType("cm:folder")[0]
      Returns:
      Array of child associations from this Node that match a specific object type.
    • getParentAssocs

      public Map<String,Object> getParentAssocs()
      Return the parent associations to this Node. As a Map of assoc name to a JavaScript array of Nodes. The Map returned implements the Scriptable interface to allow access to the assoc arrays via JavaScript associative array access. This means associations of this node can be access thus: node.parentAssocs["contains"][0]
      Returns:
      parent associations as a Map of assoc name to a JavaScript array of Nodes.
    • getParentAssociations

      public Map<String,Object> getParentAssociations()
    • exists

      public boolean exists()
      Checks whether the ScriptNode exists in the repository.
      Returns:
      boolean
    • getProperties

      public Map<String,Object> getProperties()
      Return all the properties known about this node. The Map returned implements the Scriptable interface to allow access to the properties via JavaScript associative array access. This means properties of a node can be access thus: node.properties["name"]
      Returns:
      Map of properties for this Node.
    • getTypePropertyNames

      public org.mozilla.javascript.Scriptable getTypePropertyNames()
      Return all the property names defined for this node's type as an array of short QNames.
      Returns:
      Array of property names for this node's type.
    • getTypePropertyNames

      public org.mozilla.javascript.Scriptable getTypePropertyNames(boolean useShortQNames)
      Return all the property names defined for this node's type as an array.
      Parameters:
      useShortQNames - if true short-form qnames will be returned, else long-form.
      Returns:
      Array of property names for this node's type.
    • getPropertyNames

      public org.mozilla.javascript.Scriptable getPropertyNames(boolean useShortQNames)
      Return all the property names defined for this node as an array.
      Parameters:
      useShortQNames - if true short-form qnames will be returned, else long-form.
      Returns:
      Array of property names for this node type and optionally parent properties.
    • getIsContainer

      public boolean getIsContainer()
      Returns:
      true if this Node is a container (i.e. a folder)
    • getIsDocument

      public boolean getIsDocument()
      Returns:
      true if this Node is a Document (i.e. with content)
    • getIsLinkToContainer

      public boolean getIsLinkToContainer()
      Returns:
      true if this Node is a Link to a Container (i.e. a folderlink)
    • getIsLinkToDocument

      public boolean getIsLinkToDocument()
      Returns:
      true if this Node is a Link to a Document (i.e. a filelink)
    • getIsCategory

      public boolean getIsCategory()
      Returns:
      true if the Node is a Category
    • getAspectsSet

      public Set<QName> getAspectsSet()
      Returns:
      The list of aspects applied to this node
    • getAspects

      public org.mozilla.javascript.Scriptable getAspects()
      Returns:
      The array of aspects applied to this node as fully qualified qname strings
    • getAspectsShort

      public org.mozilla.javascript.Scriptable getAspectsShort()
      Returns:
      The array of aspects applied to this node as short prefix qname strings
    • hasAspect

      public boolean hasAspect(String aspect)
      Parameters:
      aspect - The aspect name to test for (fully qualified or short-name form)
      Returns:
      true if the node has the aspect false otherwise
    • isSubType

      public boolean isSubType(String type)
      Parameters:
      type - The qname type to test this object against (fully qualified or short-name form)
      Returns:
      true if this Node is a sub-type of the specified class (or itself of that class)
    • getQnamePath

      public String getQnamePath()
      Returns:
      QName path to this node. This can be used for Lucene PATH: style queries
    • getDisplayPath

      public String getDisplayPath()
      Returns:
      Display path to this node
    • getIcon16

      public String getIcon16()
      Returns:
      the small icon image for this node
    • getIcon32

      public String getIcon32()
      Returns:
      the large icon image for this node
    • getIsLocked

      public boolean getIsLocked()
      Returns:
      true if the node is currently locked
    • getParent

      public ScriptNode getParent()
      Returns:
      the primary parent node
    • getParents

      public org.mozilla.javascript.Scriptable getParents()
      Returns:
      all parent nodes
    • getPrimaryParentAssoc

      public ChildAssociationRef getPrimaryParentAssoc()
      Returns:
      the primary parent association so we can get at the association QName and the association type QName.
    • getContent

      public String getContent()
      Returns:
      the content String for this node from the default content property (@see ContentModel.PROP_CONTENT)
    • setContent

      public void setContent(String content)
      Set the content for this node
      Parameters:
      content - Content string to set
    • getUrl

      public String getUrl()
      Returns:
      For a content document, this method returns the URL to the content stream for the default content property (@see ContentModel.PROP_CONTENT)

      For a container node, this method return the URL to browse to the folder in the web-client

    • getDownloadUrl

      public String getDownloadUrl()
      Returns:
      For a content document, this method returns the download URL to the content for the default content property (@see ContentModel.PROP_CONTENT)

      For a container node, this method returns an empty string

    • jsGet_downloadUrl

      public String jsGet_downloadUrl()
    • getWebdavUrl

      public String getWebdavUrl()
      Returns:
      The WebDav cm:name based path to the content for the default content property (@see ContentModel.PROP_CONTENT)
    • getMimetype

      public String getMimetype()
      Returns:
      The mimetype encoding for content attached to the node from the default content property (@see ContentModel.PROP_CONTENT)
    • setMimetype

      public void setMimetype(String mimetype)
      Set the mimetype encoding for the content attached to the node from the default content property (@see ContentModel.PROP_CONTENT)
      Parameters:
      mimetype - Mimetype to set
    • getSize

      public long getSize()
      Returns:
      The size in bytes of the content attached to the node from the default content property (@see ContentModel.PROP_CONTENT)
    • hasPermission

      public boolean hasPermission(String permission)
      Return true if the user has the specified permission on the node.

      The default permissions are found in org.alfresco.service.cmr.security.PermissionService. Most commonly used are "Write", "Delete" and "AddChildren".

      Parameters:
      permission - as found in org.alfresco.service.cmr.security.PermissionService
      Returns:
      true if the user has the specified permission on the node.
    • getPermissions

      public org.mozilla.javascript.Scriptable getPermissions()
      Returns:
      Array of permissions applied to this Node, including inherited. Strings returned are of the format [ALLOWED|DENIED];[USERNAME|GROUPNAME];PERMISSION for example ALLOWED;kevinr;Consumer so can be easily tokenized on the ';' character.
    • getDirectPermissions

      public org.mozilla.javascript.Scriptable getDirectPermissions()
      Returns:
      Array of permissions applied directly to this Node (does not include inherited). Strings returned are of the format [ALLOWED|DENIED];[USERNAME|GROUPNAME];PERMISSION for example ALLOWED;kevinr;Consumer so can be easily tokenized on the ';' character.
    • getFullPermissions

      public org.mozilla.javascript.Scriptable getFullPermissions()
      Returns:
      Array of all permissions applied to this Node, including inherited. Strings returned are of the format [ALLOWED|DENIED];[USERNAME|GROUPNAME];PERMISSION;[INHERITED|DIRECT] for example: ALLOWED;kevinr;Consumer;DIRECT so can be easily tokenized on the ';' character.
    • getSortedACLs

      public static List<AccessPermission> getSortedACLs(Set<AccessPermission> acls)
      Returns:
      Sorted list of AccessPermission based on CMISConnector.AccessPermissionComparator and AccessStatus of the permission for an authority.
    • retrieveAllSetPermissions

      protected Object[] retrieveAllSetPermissions(boolean direct, boolean full)
      Helper to construct the response object for the various getPermissions() calls.
      Parameters:
      direct - True to only retrieve direct permissions, false to get inherited also
      full - True to retrieve full data string with [INHERITED|DIRECT] element This exists to maintain backward compatibility with existing permission APIs.
      Returns:
      Object[] of packed permission strings.
    • getSettablePermissions

      public org.mozilla.javascript.Scriptable getSettablePermissions()
      Returns:
      Array of settable permissions for this Node
    • inheritsPermissions

      public boolean inheritsPermissions()
      Returns:
      true if the node inherits permissions from the parent node, false otherwise
    • setInheritsPermissions

      public void setInheritsPermissions(boolean inherit)
      Set whether this node should inherit permissions from the parent node.
      Parameters:
      inherit - True to inherit parent permissions, false otherwise.
    • setInheritsPermissions

      public void setInheritsPermissions(boolean inherit, boolean asyncCall)
      Set whether this node should inherit permissions from the parent node. If the operation takes too long and asyncCall parameter set accordingly, fixed ACLs method will be asynchronously called.
      Parameters:
      inherit - True to inherit parent permissions, false otherwise.
      asyncCall - True if fixed ACLs should be asynchronously set when operation execution takes too long, false otherwise.
    • setPermission

      public void setPermission(String permission)
      Apply a permission for ALL users to the node.
      Parameters:
      permission - Permission to apply
      See Also:
    • setPermission

      public void setPermission(String permission, String authority)
      Apply a permission for the specified authority (e.g. username or group) to the node.
      Parameters:
      permission - Permission to apply @see org.alfresco.service.cmr.security.PermissionService
      authority - Authority (generally a username or group name) to apply the permission for
    • removePermission

      public void removePermission(String permission)
      Remove a permission for ALL user from the node.
      Parameters:
      permission - Permission to remove @see org.alfresco.service.cmr.security.PermissionService
    • removePermission

      public void removePermission(String permission, String authority)
      Remove a permission for the specified authority (e.g. username or group) from the node.
      Parameters:
      permission - Permission to remove @see org.alfresco.service.cmr.security.PermissionService
      authority - Authority (generally a username or group name) to apply the permission for
    • setOwner

      public void setOwner(String userId)
      Set the owner of the node
    • takeOwnership

      public void takeOwnership()
      Take ownership of the node.
    • getOwner

      public String getOwner()
      Get the owner of the node.
      Returns:
      String
    • save

      public void save()
      Persist the modified properties of this Node.
    • specializeType

      public boolean specializeType(String type)
      Re-sets the type of the node. Can be called in order specialise a node to a sub-type. This should be used with caution since calling it changes the type of the node and thus* implies a different set of aspects, properties and associations. It is the responsibility of the caller to ensure that the node is in a approriate state after changing the type.
      Parameters:
      type - Type to specialize the node
      Returns:
      true if successful, false otherwise
    • createFile

      public ScriptNode createFile(String name)
      Create a new File (cm:content) node as a child of this node.

      Once created the file should have content set using the content property. Beware: Any unsaved property changes will be lost when this is called. To preserve property changes call save() first.

      Parameters:
      name - Name of the file to create
      Returns:
      Newly created Node or null if failed to create.
    • createFile

      public ScriptNode createFile(String name, String type)
      Create a new File (cm:content) node as a child of this node.

      Once created the file should have content set using the content property. Beware: Any unsaved property changes will be lost when this is called. To preserve property changes call save() first.

      Parameters:
      name - Name of the file to create
      type - Type of the file to create (if null, defaults to ContentModel.TYPE_CONTENT)
      Returns:
      Newly created Node or null if failed to create.
    • createFolder

      public ScriptNode createFolder(String name)
      Create a new folder (cm:folder) node as a child of this node. Beware: Any unsaved property changes will be lost when this is called. To preserve property changes call save() first.
      Parameters:
      name - Name of the folder to create
      Returns:
      Newly created Node or null if failed to create.
    • createFolder

      public ScriptNode createFolder(String name, String type)
      Create a new folder (cm:folder) node as a child of this node. Beware: Any unsaved property changes will be lost when this is called. To preserve property changes call save() first.
      Parameters:
      name - Name of the folder to create
      type - Type of the folder to create (if null, defaults to ContentModel.TYPE_FOLDER)
      Returns:
      Newly created Node or null if failed to create.
    • createFolderPath

      public ScriptNode createFolderPath(String path)
      Create a path of folder (cm:folder) nodes as a child of this node.

      This method operates like a unix 'mkdir -p' no error if existing, make parent directories as needed.

      Beware: Any unsaved property changes will be lost when this is called. To preserve property changes call save() first.

      Parameters:
      path - Folder path to create - of the form "One/Two/Three". Leading and trailing slashes are not expected to be present in the supplied path.
      Returns:
      reference to the last child of the newly created folder node(s) or null if failed to create.
    • createNode

      public ScriptNode createNode(String name, String type)
      Create a new Node of the specified type as a child of this node.
      Parameters:
      name - Name of the node to create (can be null for a node without a 'cm:name' property)
      type - QName type (fully qualified or short form such as 'cm:content')
      Returns:
      Newly created Node or null if failed to create.
    • createNode

      public ScriptNode createNode(String name, String type, String assocType)
      Create a new Node of the specified type as a child of this node.
      Parameters:
      name - Name of the node to create (can be null for a node without a 'cm:name' property)
      type - QName type (fully qualified or short form such as 'cm:content')
      assocType - QName of the child association type (fully qualified or short form e.g. 'cm:contains')
      Returns:
      Newly created Node or null if failed to create.
    • createNode

      public ScriptNode createNode(String name, String type, Object properties)
      Create a new Node of the specified type as a child of this node.
      Parameters:
      name - Name of the node to create (can be null for a node without a 'cm:name' property)
      type - QName type (fully qualified or short form such as 'cm:content')
      properties - Associative array of the default properties for the node.
      Returns:
      Newly created Node or null if failed to create.
    • createNode

      public ScriptNode createNode(String name, String type, Object properties, String assocType)
      Create a new Node of the specified type as a child of this node. Beware: Any unsaved property changes will be lost when this is called. To preserve property changes call save() first.
      Parameters:
      name - Name of the node to create (can be null for a node without a 'cm:name' property)
      type - QName type (fully qualified or short form such as 'cm:content')
      properties - Associative array of the default properties for the node.
      assocType - QName of the child association type (fully qualified or short form e.g. 'cm:contains')
      Returns:
      Newly created Node or null if failed to create.
    • createNode

      public ScriptNode createNode(String name, String type, Object properties, String assocType, String assocName)
      Create a new Node of the specified type as a child of this node. Beware: Any unsaved property changes will be lost when this is called. To preserve property changes call save() first.
      Parameters:
      name - Name of the node to create (can be null for a node without a 'cm:name' property)
      type - QName type (fully qualified or short form such as 'cm:content')
      properties - Associative array of the default properties for the node.
      assocType - QName of the child association type (fully qualified or short form e.g. 'cm:contains')
      assocName - QName of the child association name (fully qualified or short form e.g. 'fm:discussion')
      Returns:
      Newly created Node or null if failed to create.
    • addNode

      public void addNode(ScriptNode node)
      Creates a new secondary association between the current node and the specified child node. The association is given the same name as the child node's primary association. Beware: Any unsaved property changes will be lost when this is called. To preserve property changes call save() first.
      Parameters:
      node - node to add as a child of this node
    • removeNode

      public void removeNode(ScriptNode node)
      Remove an existing child node of this node. Severs all parent-child relationships between two nodes.

      The child node will be cascade deleted if one of the associations was the primary association, i.e. the one with which the child node was created. Beware: Any unsaved property changes will be lost when this is called. To preserve property changes call save() first.

      Parameters:
      node - child node to remove
    • createAssociation

      public Association createAssociation(ScriptNode target, String assocType)
      Create an association between this node and the specified target node. Beware: Any unsaved property changes will be lost when this is called. To preserve property changes call save() first.
      Parameters:
      target - Destination node for the association
      assocType - Association type qname (short form or fully qualified)
    • removeAssociation

      public void removeAssociation(ScriptNode target, String assocType)
      Remove an association between this node and the specified target node. Beware: Any unsaved property changes will be lost when this is called. To preserve property changes call save() first.
      Parameters:
      target - Destination node on the end of the association
      assocType - Association type qname (short form or fully qualified)
    • remove

      public boolean remove()
      Remove this node. Any references to this Node or its NodeRef should be discarded! Beware: Any unsaved property changes will be lost when this is called. To preserve property changes call save() first.
    • remove

      public boolean remove(boolean newTransaction)
      Remove this node in a new transaction or not as specified. Any references to this Node or its NodeRef should be discarded! Beware: Any unsaved property changes will be lost when this is called. To preserve property changes call save() first.
    • copy

      public ScriptNode copy(ScriptNode destination)
      Copy this Node to a new parent destination. Note that children of the source Node are not copied.
      Parameters:
      destination - Node
      Returns:
      The newly copied Node instance or null if failed to copy.
    • copy

      public ScriptNode copy(ScriptNode destination, boolean deepCopy)
      Copy this Node and potentially all child nodes to a new parent destination.
      Parameters:
      destination - Node
      deepCopy - True for a deep copy, false otherwise.
      Returns:
      The newly copied Node instance or null if failed to copy.
    • revert

      public ScriptNode revert(String history, boolean majorVersion, String versionLabel)
      Revert this Node to the specified version. Note this is not a deep revert of associations. This node must have the cm:versionable aspect. It will be checked out if required but will be checked in after the call.
      Parameters:
      versionLabel - to revert from
      Returns:
      the original Node that was checked out if reverted, null otherwise (if the version does not exist).
    • revert

      public ScriptNode revert(String history, boolean majorVersion, String versionLabel, boolean deep)
      Revert this Node to the specified version and potentially all child nodes. This node must have the cm:versionable aspect. It will be checked out if required but will be checked in after the call. Beware: Any unsaved property changes will be lost when this is called. To preserve property changes call save() first.
      Parameters:
      history - Version history note
      majorVersion - True to save as a major version increment, false for minor version.
      versionLabel - to revert from
      deep - true for a deep revert, false otherwise.
      Returns:
      the original Node that was checked out if reverted, null otherwise (if the version does not exist).
    • move

      public boolean move(ScriptNode destination)
      Move this Node to a new parent destination. Beware: Any unsaved property changes will be lost when this is called. To preserve property changes call save() first.
      Parameters:
      destination - Node
      Returns:
      true on successful move, false on failure to move.
    • move

      public boolean move(ScriptNode source, ScriptNode destination)
      Move this Node from specified parent to a new parent destination. Beware: Any unsaved property changes will be lost when this is called. To preserve property changes call save() first.
      Parameters:
      source - Node
      destination - Node
      Returns:
      true on successful move, false on failure to move.
    • addAspect

      public boolean addAspect(String type)
      Add an aspect to the Node. As no properties are provided in this call, it can only be used to add aspects that do not require any mandatory properties. Beware: Any unsaved property changes will be lost when this is called. To preserve property changes call save() first.
      Parameters:
      type - Type name of the aspect to add
      Returns:
      true if the aspect was added successfully, false if an error occured.
    • addAspect

      public boolean addAspect(String type, Object props)
      Add an aspect to the Node. Beware: Any unsaved property changes will be lost when this is called. To preserve property changes call save() first.
      Parameters:
      type - Type name of the aspect to add
      props - ScriptableObject (generally an assocative array) providing the named properties for the aspect - any mandatory properties for the aspect must be provided!
      Returns:
      true if the aspect was added successfully, false if an error occured.
    • removeAspect

      public boolean removeAspect(String type)
      Remove aspect from the node. Beware: Any unsaved property changes will be lost when this is called. To preserve property changes call save() first.
      Parameters:
      type - the aspect type
      Returns:
      true if successful, false otherwise
    • ensureVersioningEnabled

      public void ensureVersioningEnabled(boolean autoVersion, boolean autoVersionProps)
      Ensures that this document has the cm:versionable aspect applied to it, and that it has the initial version in the version store. Calling this on a versioned node with a version store entry will have no effect. Calling this on a newly uploaded share node will have versioning enabled for it (Share currently does lazy versioning to improve performance of documents that are uploaded but never edited, and multi upload performance).
      Parameters:
      autoVersion - If the cm:versionable aspect is applied, should auto versioning be requested?
      autoVersionProps - If the cm:versionable aspect is applied, should auto versioning of properties be requested?
    • ensureVersioningEnabled

      public void ensureVersioningEnabled()
      Ensures that this document has the cm:versionable aspect applied to it, and that it has the initial version in the version store. Calling this on a versioned node with a version store entry will have no effect. Calling this on a newly uploaded share node will have versioning enabled for it (Share currently does lazy versioning to improve performance of documents that are uploaded but never edited, and multi upload performance).
    • createVersion

      public ScriptVersion createVersion(String history, boolean majorVersion)
      Create a version of this document. Note: this will add the cm:versionable aspect.
      Parameters:
      history - Version history note
      majorVersion - True to save as a major version increment, false for minor version.
      Returns:
      ScriptVersion object representing the newly added version node
    • getIsVersioned

      public boolean getIsVersioned()
      Determines if this node is versioned
      Returns:
      true => is versioned
    • getVersionHistory

      public org.mozilla.javascript.Scriptable getVersionHistory()
      Gets the version history
      Returns:
      version history
    • getVersion

      public ScriptVersion getVersion(String versionLabel)
      Gets the version of this node specified by version label
      Parameters:
      versionLabel - version label
      Returns:
      version of node, or null if node is not versioned, or label does not exist
    • checkout

      public ScriptNode checkout()
      Perform a check-out of this document into the current parent space.
      Returns:
      the working copy Node for the checked out document
    • checkoutForUpload

      public ScriptNode checkoutForUpload()
      Performs a check-out of this document for the purposes of an upload
      Returns:
      ScriptNode
    • checkout

      public ScriptNode checkout(ScriptNode destination)
      Perform a check-out of this document into the specified destination space.
      Parameters:
      destination - Destination for the checked out document working copy Node.
      Returns:
      the working copy Node for the checked out document
    • checkin

      public ScriptNode checkin()
      Check-in a working copy document. The current state of the working copy is copied to the original node, this will include any content updated in the working node. Note that this method can only be called on a working copy Node.
      Returns:
      the original Node that was checked out.
    • checkin

      public ScriptNode checkin(String history)
      Check-in a working copy document. The current state of the working copy is copied to the original node, this will include any content updated in the working node. Note that this method can only be called on a working copy Node.
      Parameters:
      history - Version history note
      Returns:
      the original Node that was checked out.
    • checkin

      public ScriptNode checkin(String history, boolean majorVersion)
      Check-in a working copy document. The current state of the working copy is copied to the original node, this will include any content updated in the working node. Note that this method can only be called on a working copy Node.
      Parameters:
      history - Version history note
      majorVersion - True to save as a major version increment, false for minor version.
      Returns:
      the original Node that was checked out.
    • unlock

      public void unlock()
      Removes the lock on a node.
    • getCheckedOut

      public ScriptNode getCheckedOut()
      Gets the check-out of a working copy document
      Returns:
      the original Node that was checked out or null if it's not a working copy
    • cancelCheckout

      public ScriptNode cancelCheckout()
      Cancel the check-out of a working copy document. The working copy will be deleted and any changes made to it are lost. Note that this method can only be called on a working copy Node. The reference to this working copy Node should be discarded.
      Returns:
      the original Node that was checked out.
    • transformDocument

      public ScriptNode transformDocument(String mimetype)
      Transform a document to a new document mimetype format. A copy of the document is made and the extension changed to match the new mimetype, then the transformation isapplied.
      Parameters:
      mimetype - Mimetype destination for the transformation
      Returns:
      Node representing the newly transformed document.
    • transformDocument

      public ScriptNode transformDocument(String mimetype, ScriptNode destination)
      Transform a document to a new document mimetype format. A copy of the document is made in the specified destination folder and the extension changed to match the new mimetype, then then transformation is applied.
      Parameters:
      mimetype - Mimetype destination for the transformation
      destination - Destination folder location
      Returns:
      Node representing the newly transformed document.
    • transformImage

      public ScriptNode transformImage(String mimetype)
      Transform an image to a new image format. A copy of the image document is made and the extension changed to match the new mimetype, then the transformation is applied.
      Parameters:
      mimetype - Mimetype destination for the transformation
      Returns:
      Node representing the newly transformed image.
    • transformImage

      public ScriptNode transformImage(String mimetype, String options)
      Transform an image to a new image format. A copy of the image document is made and the extension changed to match the new mimetype, then the transformation is applied.
      Parameters:
      mimetype - Mimetype destination for the transformation
      options - Image convert command options
      Returns:
      Node representing the newly transformed image.
    • transformImage

      public ScriptNode transformImage(String mimetype, ScriptNode destination)
      Transform an image to a new image mimetype format. A copy of the image document is made in the specified destination folder and the extension changed to match the newmimetype, then then transformation is applied.
      Parameters:
      mimetype - Mimetype destination for the transformation
      destination - Destination folder location
      Returns:
      Node representing the newly transformed image.
    • transformImage

      public ScriptNode transformImage(String mimetype, String options, ScriptNode destination)
      Transform an image to a new image mimetype format. A copy of the image document is made in the specified destination folder and the extension changed to match the new mimetype, then then transformation is applied.
      Parameters:
      mimetype - Mimetype destination for the transformation
      options - Image convert command options
      destination - Destination folder location
      Returns:
      Node representing the newly transformed image.
    • processTemplate

      public String processTemplate(ScriptNode template)
      Process a FreeMarker Template against the current node.
      Parameters:
      template - Node of the template to execute
      Returns:
      output of the template execution
    • processTemplate

      public String processTemplate(ScriptNode template, Object args)
      Process a FreeMarker Template against the current node.
      Parameters:
      template - Node of the template to execute
      args - Scriptable object (generally an associative array) containing the name/value pairs of arguments to be passed to the template
      Returns:
      output of the template execution
    • processTemplate

      public String processTemplate(String template)
      Process a FreeMarker Template against the current node.
      Parameters:
      template - The template to execute
      Returns:
      output of the template execution
    • processTemplate

      public String processTemplate(String template, Object args)
      Process a FreeMarker Template against the current node.
      Parameters:
      template - The template to execute
      args - Scriptable object (generally an associative array) containing the name/value pairs of arguments to be passed to the template
      Returns:
      output of the template execution
    • createThumbnail

      public ScriptThumbnail createThumbnail(String thumbnailName)
      Creates a thumbnail for the content property of the node. The thumbnail name correspionds to pre-set thumbnail details stored in the repository.
      Parameters:
      thumbnailName - the name of the thumbnail
      Returns:
      ScriptThumbnail the newly create thumbnail node
    • createThumbnail

      @Deprecated public ScriptThumbnail createThumbnail(String thumbnailName, boolean async)
      Deprecated.
      The async flag in the method signature will not be applicable as all of the future transformations will be asynchronous
      Creates a thumbnail for the content property of the node. The thumbnail name corresponds to pre-set thumbnail details stored in the repository. If the thumbnail is created asynchronously then the result will be null and creation of the thumbnail will occure at some point in the background.
      Parameters:
      thumbnailName - the name of the thumbnail
      async - indicates whether the thumbnail is create asynchronously or not
      Returns:
      ScriptThumbnail the newly create thumbnail node or null if async creation occures
    • createThumbnail

      @Deprecated public ScriptThumbnail createThumbnail(String thumbnailName, boolean async, boolean force)
      Deprecated.
      The async flag in the method signature will not be applicable as all of the future transformations will be asynchronous
      Creates a thumbnail for the content property of the node. The thumbnail name corresponds to pre-set thumbnail details stored in the repository. If the thumbnail is created asynchronously then the result will be null and creation of the thumbnail will occure at some point in the background. If foce param specified system.thumbnail.generate is ignoring. Could be used for preview creation
      Parameters:
      thumbnailName - the name of the thumbnail
      async - indicates whether the thumbnail is create asynchronously or not
      force - ignore system.thumbnail.generate=false
      Returns:
      ScriptThumbnail the newly create thumbnail node or null if async creation occures
    • getThumbnail

      public ScriptThumbnail getThumbnail(String thumbnailName)
      Get the given thumbnail for the content property
      Parameters:
      thumbnailName - the thumbnail name
      Returns:
      ScriptThumbnail the thumbnail
    • getThumbnails

      public ScriptThumbnail[] getThumbnails()
      Get the all the thumbnails for a given node's content property.
      Returns:
      Scriptable list of thumbnails, empty if none available
    • getThumbnailDefinitions

      public String[] getThumbnailDefinitions()
      Returns the names of the thumbnail defintions that can be applied to the content property of this node.

      Thumbanil defintions only appear in this list if they can produce a thumbnail for the content found in the content property. This will be determined by looking at the mimetype of the content and the destinatino mimetype of the thumbnail.

      Returns:
      String[] array of thumbnail names that are valid for the current content type
    • getThumbnailDefintions

      @Deprecated public String[] getThumbnailDefintions()
      Deprecated.
      This version of the method name spelling is retained (for now) for backwards compatibility
      See Also:
    • clearTags

      public void clearTags()
      Clear the node's tags
    • addTag

      public void addTag(String tag)
      Adds a tag to the node
      Parameters:
      tag - tag name
    • addTags

      public void addTags(String[] tags)
      Adds all the tags to the node
      Parameters:
      tags - array of tag names
    • removeTag

      public void removeTag(String tag)
      Removes a tag from the node
      Parameters:
      tag - tag name
    • removeTags

      public void removeTags(String[] tags)
      Removes all the tags from the node
      Parameters:
      tags - array of tag names
    • getTags

      public String[] getTags()
      Get all the tags applied to this node
      Returns:
      String[] array containing all the tag applied to this node
    • setTags

      public void setTags(String[] tags)
      Set the tags applied to this node. This overwirtes the list of tags currently applied to the node.
      Parameters:
      tags - array of tags
    • setIsTagScope

      public void setIsTagScope(boolean value)
      Sets whether this node is a tag scope or not
      Parameters:
      value - true if this node is a tag scope, false otherwise
    • getIsTagScope

      public boolean getIsTagScope()
      Gets whether this node is a tag scope
      Returns:
      boolean true if this node is a tag scope, false otherwise
    • getTagScope

      public TagScope getTagScope()
      Gets the 'nearest' tag scope to this node by travesing up the parent hierarchy untill one is found.

      If none is found, null is returned.

      Returns:
      TagScope the 'nearest' tag scope
    • childrenByTags

      public ScriptNode[] childrenByTags(String tag)
      Gets all (deep) children of this node that have the tag specified.
      Parameters:
      tag - tag name
      Returns:
      ScriptNode[] nodes that are deep children of the node with the tag
    • getActiveWorkflows

      public org.mozilla.javascript.Scriptable getActiveWorkflows()
      Get active workflow instances this node belongs to
      Returns:
      the active workflow instances this node belongs to
    • getSiteShortName

      public String getSiteShortName()
      Returns the short name of the site this node is located within. If the node is not located within a site null is returned.
      Returns:
      The short name of the site this node is located within, null if the node is not located within a site.
    • toString

      public String toString()
      Override Object.toString() to provide useful debug output
      Overrides:
      toString in class Object
    • toJSON

      public String toJSON(boolean useShortQNames)
      Returns the JSON representation of this node.
      Parameters:
      useShortQNames - if true short-form qnames will be returned, else long-form.
      Returns:
      The JSON representation of this node
    • toJSON

      public String toJSON()
      Returns the JSON representation of this node. Long-form QNames are used in the result.
      Returns:
      The JSON representation of this node
    • getShortQName

      protected String getShortQName(QName longQName)
      Given a long-form QName, this method uses the namespace service to create a short-form QName string.
      Parameters:
      longQName - QName
      Returns:
      the short form of the QName string, e.g. "cm:content"
    • createQName

      protected QName createQName(String s)
      Helper to create a QName from either a fully qualified or short-name QName string
      Parameters:
      s - Fully qualified or short-name QName string
      Returns:
      QName
    • reset

      public void reset()
      Reset the Node cached state
    • isScriptContent

      public boolean isScriptContent(Object o)
      Helper to return true if the supplied property value is a ScriptContentData object
      Parameters:
      o - Object to test
      Returns:
      true if instanceof ScriptContentData, false otherwise
    • getValueConverter

      protected ScriptNode.NodeValueConverter getValueConverter()
      Gets the node value converter
      Returns:
      the node value converter
    • createValueConverter

      protected ScriptNode.NodeValueConverter createValueConverter()
      Constructs the node value converter
      Returns:
      the node value converter
    • getNamespacePrefixResolver

      public NamespacePrefixResolver getNamespacePrefixResolver()
      NamespacePrefixResolverProvider getter implementation
      Specified by:
      getNamespacePrefixResolver in interface NamespacePrefixResolverProvider