From 84b84ffad0c2cba6b4c22a6e40ec6a960ba22f37 Mon Sep 17 00:00:00 2001 From: Mike Hatfield Date: Thu, 21 Jun 2007 10:09:56 +0000 Subject: [PATCH] Made downloadUrl available across all public APIs for nodes git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6047 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../org/alfresco/repo/jscript/ScriptNode.java | 70 +++++++++++++++++++ .../repo/template/BaseContentNode.java | 30 ++++++++ .../repo/template/TemplateContent.java | 15 ++++ .../alfresco/repo/template/TemplateNode.java | 31 -------- 4 files changed, 115 insertions(+), 31 deletions(-) diff --git a/source/java/org/alfresco/repo/jscript/ScriptNode.java b/source/java/org/alfresco/repo/jscript/ScriptNode.java index 6b69864e95..89e0deefa1 100644 --- a/source/java/org/alfresco/repo/jscript/ScriptNode.java +++ b/source/java/org/alfresco/repo/jscript/ScriptNode.java @@ -58,6 +58,7 @@ import org.alfresco.service.cmr.repository.InvalidNodeRefException; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.StoreRef; +import org.alfresco.service.cmr.repository.TemplateException; import org.alfresco.service.cmr.repository.TemplateImageResolver; import org.alfresco.service.cmr.search.QueryParameterDefinition; import org.alfresco.service.cmr.security.AccessPermission; @@ -97,7 +98,9 @@ public class ScriptNode implements Serializable, Scopeable private final static String NAMESPACE_BEGIN = "" + QName.NAMESPACE_BEGIN; private final static String CONTENT_DEFAULT_URL = "/d/d/{0}/{1}/{2}/{3}"; + private final static String CONTENT_DOWNLOAD_URL = "/d/a/{0}/{1}/{2}/{3}"; private final static String CONTENT_PROP_URL = "/d/d/{0}/{1}/{2}/{3}?property={4}"; + private final static String CONTENT_DOWNLOAD_PROP_URL = "/d/a/{0}/{1}/{2}/{3}?property={4}"; private final static String FOLDER_BROWSE_URL = "/n/browse/{0}/{1}/{2}"; /** Root scope for this object */ @@ -826,6 +829,40 @@ public class ScriptNode implements Serializable, Scopeable return getUrl(); } + /** + * @return 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 + */ + public String getDownloadUrl() + { + if (getIsDocument() == true) + { + try + { + return MessageFormat.format(CONTENT_DOWNLOAD_URL, new Object[] { + nodeRef.getStoreRef().getProtocol(), + nodeRef.getStoreRef().getIdentifier(), + nodeRef.getId(), + StringUtils.replace(URLEncoder.encode(getName(), "UTF-8"), "+", "%20") }); + } + catch (UnsupportedEncodingException err) + { + throw new AlfrescoRuntimeException("Failed to encode content download URL for node: " + nodeRef, err); + } + } + else + { + return ""; + } + } + + public String jsGet_downloadUrl() + { + return getDownloadUrl(); + } + /** * @return The mimetype encoding for content attached to the node from the default content property * (@see ContentModel.PROP_CONTENT) @@ -2135,6 +2172,39 @@ public class ScriptNode implements Serializable, Scopeable return getUrl(); } + /** + * @return download URL to the content for a document item only + */ + public String getDownloadUrl() + { + if (getIsDocument() == true) + { + try + { + return MessageFormat.format(CONTENT_DOWNLOAD_PROP_URL, new Object[] { + nodeRef.getStoreRef().getProtocol(), + nodeRef.getStoreRef().getIdentifier(), + nodeRef.getId(), + StringUtils.replace(URLEncoder.encode(getName(), "UTF-8"), "+", "%20"), + StringUtils.replace(URLEncoder.encode(property.toString(), "UTF-8"), "+", "%20") }); + } + catch (UnsupportedEncodingException err) + { + throw new AlfrescoRuntimeException("Failed to encode content download URL for node: " + nodeRef, err); + } + } + else + { + return ""; + } + } + + public String jsGet_downloadUrl() + { + return getDownloadUrl(); + } + + public long getSize() { return contentData.getSize(); diff --git a/source/java/org/alfresco/repo/template/BaseContentNode.java b/source/java/org/alfresco/repo/template/BaseContentNode.java index 6d78f059bd..91ba982f6e 100644 --- a/source/java/org/alfresco/repo/template/BaseContentNode.java +++ b/source/java/org/alfresco/repo/template/BaseContentNode.java @@ -56,6 +56,7 @@ import org.springframework.util.StringUtils; public abstract class BaseContentNode implements TemplateContent { protected final static String CONTENT_DEFAULT_URL = "/d/d/{0}/{1}/{2}/{3}"; + protected final static String CONTENT_DOWNLOAD_URL = "/d/a/{0}/{1}/{2}/{3}"; protected final static String CONTENT_PROP_URL = "/d/d/{0}/{1}/{2}/{3}?property={4}"; protected final static String FOLDER_BROWSE_URL = "/n/browse/{0}/{1}/{2}"; @@ -353,6 +354,35 @@ public abstract class BaseContentNode implements TemplateContent } } + /** + * @return 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 + */ + public String getDownloadUrl() + { + if (getIsDocument() == true) + { + try + { + return MessageFormat.format(CONTENT_DOWNLOAD_URL, new Object[] { + getNodeRef().getStoreRef().getProtocol(), + getNodeRef().getStoreRef().getIdentifier(), + getNodeRef().getId(), + StringUtils.replace(URLEncoder.encode(getName(), "UTF-8"), "+", "%20") }); + } + catch (UnsupportedEncodingException err) + { + throw new TemplateException("Failed to encode content download URL for node: " + getNodeRef(), err); + } + } + else + { + return ""; + } + } + /** * @return The mimetype encoding for content attached to the node from the default content property * (@see ContentModel.PROP_CONTENT) diff --git a/source/java/org/alfresco/repo/template/TemplateContent.java b/source/java/org/alfresco/repo/template/TemplateContent.java index 780a4f5faa..d2c72f4a9a 100644 --- a/source/java/org/alfresco/repo/template/TemplateContent.java +++ b/source/java/org/alfresco/repo/template/TemplateContent.java @@ -24,6 +24,13 @@ */ package org.alfresco.repo.template; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.text.MessageFormat; + +import org.alfresco.service.cmr.repository.TemplateException; +import org.springframework.util.StringUtils; + /** * Contract for Template API objects that support content on the 'cm:content' default property. @@ -46,6 +53,14 @@ public interface TemplateContent extends TemplateProperties */ public String getUrl(); + /** + * @return 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 + */ + public String getDownloadUrl(); + /** * @return The mimetype encoding for content attached to the node from the default content property * (@see ContentModel.PROP_CONTENT) diff --git a/source/java/org/alfresco/repo/template/TemplateNode.java b/source/java/org/alfresco/repo/template/TemplateNode.java index ba3e15a701..70641bdc88 100644 --- a/source/java/org/alfresco/repo/template/TemplateNode.java +++ b/source/java/org/alfresco/repo/template/TemplateNode.java @@ -83,8 +83,6 @@ public class TemplateNode extends BasePermissionsNode /** The child associations from this node */ private Map> childAssocs = null; - private final static String CONTENT_DOWNLOAD_URL = "/d/a/{0}/{1}/{2}/{3}"; - /** Cached values */ protected NodeRef nodeRef; private String name; @@ -457,35 +455,6 @@ public class TemplateNode extends BasePermissionsNode return this.imageResolver; } - /** - * @return 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 - */ - public String getDownloadUrl() - { - if (getIsDocument() == true) - { - try - { - return MessageFormat.format(CONTENT_DOWNLOAD_URL, new Object[] { - nodeRef.getStoreRef().getProtocol(), - nodeRef.getStoreRef().getIdentifier(), - nodeRef.getId(), - StringUtils.replace(URLEncoder.encode(getName(), "UTF-8"), "+", "%20") } ); - } - catch (UnsupportedEncodingException err) - { - throw new TemplateException("Failed to encode content URL for node: " + nodeRef, err); - } - } - else - { - return ""; - } - } - // ------------------------------------------------------------------------------ // Inner classes