From cbd452fd7da16bb488125c1f69977208dfa2b86b Mon Sep 17 00:00:00 2001 From: Gavin Cornwell Date: Wed, 25 Aug 2010 13:37:43 +0000 Subject: [PATCH] ALF-3102 & FORM-36: Allow the starting point to be defined for the association control also required to implement ALF-4070: F20 Selectable resources are limited to the current site (if appropriate) The association control now accepts a 'startLocation' parameter, this can be set to any of the following: {companyhome} {userhome} {siteshome} {doclib} {self} {parent} A NodeRef An XPath The NodeRef and XPath options can also be used for the category form control to start the category picker in a particular category. The XPath option is already used by the replication job UI and an example of {doclib} is in the FDK. Example config would be as follows:
.... {doclib} /app:company_home/app:dictionary/app:transfers/app:transfer_groups/cm:default
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@21992 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../org/alfresco/repo/jscript/ScriptNode.java | 102 +++++++++++++----- .../repo/template/BaseContentNode.java | 42 ++++++++ 2 files changed, 119 insertions(+), 25 deletions(-) diff --git a/source/java/org/alfresco/repo/jscript/ScriptNode.java b/source/java/org/alfresco/repo/jscript/ScriptNode.java index 81fcbf142b..9940dbd69d 100644 --- a/source/java/org/alfresco/repo/jscript/ScriptNode.java +++ b/source/java/org/alfresco/repo/jscript/ScriptNode.java @@ -51,7 +51,6 @@ import org.alfresco.repo.thumbnail.ThumbnailDefinition; import org.alfresco.repo.thumbnail.ThumbnailRegistry; import org.alfresco.repo.thumbnail.script.ScriptThumbnail; import org.alfresco.repo.transaction.AlfrescoTransactionSupport; -import org.alfresco.repo.transaction.TransactionUtil; import org.alfresco.repo.version.VersionModel; import org.alfresco.repo.workflow.jscript.JscriptWorkflowInstance; import org.alfresco.scripts.ScriptException; @@ -70,6 +69,7 @@ import org.alfresco.service.cmr.repository.ContentService; import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.repository.Path; import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.repository.TemplateImageResolver; import org.alfresco.service.cmr.search.QueryParameterDefinition; @@ -136,6 +136,8 @@ public class ScriptNode implements Serializable, Scopeable, NamespacePrefixResol private String name; private QName type; protected String id; + protected String siteName; + protected boolean siteNameResolved = false; /** The aspects applied to this node */ protected Set aspects = null; @@ -2670,31 +2672,79 @@ public class ScriptNode implements Serializable, Scopeable, NamespacePrefixResol // ------------------------------------------------------------------------------ // Workflow methods - /** - * Get active workflow instances this node belongs to - * - * @return the active workflow instances this node belongs to - */ - public Scriptable getActiveWorkflows() - { - if (this.activeWorkflows == null) - { - WorkflowService workflowService = this.services.getWorkflowService(); - - List workflowInstances = workflowService.getWorkflowsForContent(this.nodeRef, true); - Object[] jsWorkflowInstances = new Object[workflowInstances.size()]; - int index = 0; - for (WorkflowInstance workflowInstance : workflowInstances) - { - jsWorkflowInstances[index++] = new JscriptWorkflowInstance(workflowInstance, this.services, this.scope); - } - this.activeWorkflows = Context.getCurrentContext().newArray(this.scope, jsWorkflowInstances); - } - - return this.activeWorkflows; - } - + /** + * Get active workflow instances this node belongs to + * + * @return the active workflow instances this node belongs to + */ + public Scriptable getActiveWorkflows() + { + if (this.activeWorkflows == null) + { + WorkflowService workflowService = this.services.getWorkflowService(); + + List workflowInstances = workflowService.getWorkflowsForContent(this.nodeRef, true); + Object[] jsWorkflowInstances = new Object[workflowInstances.size()]; + int index = 0; + for (WorkflowInstance workflowInstance : workflowInstances) + { + jsWorkflowInstances[index++] = new JscriptWorkflowInstance(workflowInstance, this.services, this.scope); + } + this.activeWorkflows = Context.getCurrentContext().newArray(this.scope, jsWorkflowInstances); + } + return this.activeWorkflows; + } + + // ------------------------------------------------------------------------------ + // Site methods + + /** + * Returns the short name of the site this node is located within. If the + * node is not located within a site null is returned. + * + * @return The short name of the site this node is located within, null + * if the node is not located within a site. + */ + public String getSiteShortName() + { + if (!this.siteNameResolved) + { + this.siteNameResolved = true; + + Path path = this.services.getNodeService().getPath(getNodeRef()); + + if (logger.isDebugEnabled()) + logger.debug("Determing if node is within a site using path: " + path); + + for (int i = 0; i < path.size(); i++) + { + if ("st:sites".equals(path.get(i).getPrefixedString(this.services.getNamespaceService()))) + { + // we now know the node is in a site, find the next element in the array (if there is one) + if ((i+1) < path.size()) + { + // get the site name + Path.Element siteName = path.get(i+1); + + // remove the "cm:" prefix and add to result object + this.siteName = siteName.getPrefixedString(this.services.getNamespaceService()).substring(3); + } + + break; + } + } + } + + if (logger.isDebugEnabled()) + { + logger.debug(this.siteName != null ? + "Node is in the site named \"" + this.siteName + "\"" : "Node is not in a site"); + } + + return this.siteName; + } + // ------------------------------------------------------------------------------ // Helper methods @@ -2863,6 +2913,8 @@ public class ScriptNode implements Serializable, Scopeable, NamespacePrefixResol this.parent = null; this.primaryParentAssoc = null; this.activeWorkflows = null; + this.siteName = null; + this.siteNameResolved = false; } /** diff --git a/source/java/org/alfresco/repo/template/BaseContentNode.java b/source/java/org/alfresco/repo/template/BaseContentNode.java index aa341bcee5..6e5db992b3 100644 --- a/source/java/org/alfresco/repo/template/BaseContentNode.java +++ b/source/java/org/alfresco/repo/template/BaseContentNode.java @@ -37,6 +37,7 @@ import org.alfresco.service.cmr.repository.ContentReader; import org.alfresco.service.cmr.repository.ContentService; import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.FileTypeImageSize; +import org.alfresco.service.cmr.repository.Path; import org.alfresco.service.cmr.repository.TemplateImageResolver; import org.alfresco.service.namespace.QName; import org.springframework.extensions.surf.util.URLEncoder; @@ -70,6 +71,8 @@ public abstract class BaseContentNode implements TemplateContent private Boolean isContainer = null; private Boolean isLinkToDocument = null; private Boolean isLinkToContainer = null; + private String siteName; + private boolean siteNameResolved = false; /** * @return true if this Node is a container (i.e. a folder) @@ -493,6 +496,45 @@ public abstract class BaseContentNode implements TemplateContent return (o instanceof TemplateNodeRef); } + // ------------------------------------------------------------------------------ + // Site methods + + /** + * Returns the short name of the site this node is located within. If the + * node is not located within a site null is returned. + * + * @return The short name of the site this node is located within, null + * if the node is not located within a site. + */ + public String getSiteShortName() + { + if (!this.siteNameResolved) + { + this.siteNameResolved = true; + + Path path = this.services.getNodeService().getPath(getNodeRef()); + + for (int i = 0; i < path.size(); i++) + { + if ("st:sites".equals(path.get(i).getPrefixedString(this.services.getNamespaceService()))) + { + // we now know the node is in a site, find the next element in the array (if there is one) + if ((i+1) < path.size()) + { + // get the site name + Path.Element siteName = path.get(i+1); + + // remove the "cm:" prefix and add to result object + this.siteName = siteName.getPrefixedString(this.services.getNamespaceService()).substring(3); + } + + break; + } + } + } + + return this.siteName; + } // ------------------------------------------------------------------------------ // Inner classes