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
This commit is contained in:
Mike Hatfield
2007-06-21 10:09:56 +00:00
parent 3a3842e874
commit 84b84ffad0
4 changed files with 115 additions and 31 deletions

View File

@@ -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)
* <p>
* 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)