Merged V2.1-A to HEAD

7983: NodeRef + child path relative URLs support for WebScript download content API

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@8839 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2008-04-18 14:43:20 +00:00
parent c0de370461
commit 3f8d6dacab
2 changed files with 54 additions and 5 deletions

View File

@@ -26,6 +26,7 @@ package org.alfresco.repo.web.scripts.bean;
import java.io.IOException;
import java.net.SocketException;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Date;
@@ -45,6 +46,7 @@ import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.URLEncoder;
import org.alfresco.web.scripts.AbstractWebScript;
import org.alfresco.web.scripts.Cache;
import org.alfresco.web.scripts.WebScriptException;
@@ -68,6 +70,8 @@ public class ContentGet extends AbstractWebScript
// Logger
private static final Log logger = LogFactory.getLog(ContentGet.class);
private static final String NODE_URL = "/api/node/content/{0}/{1}/{2}/{3}";
// Component dependencies
private Repository repository;
private NamespaceService namespaceService;
@@ -258,4 +262,22 @@ public class ContentGet extends AbstractWebScript
}
}
/**
* Helper to generate a URL to a content node for downloading content from the server.
* The content is supplied directly in the reponse. This generally means a browser will
* attempt to open the content directly if possible, else it will prompt to save the file.
*
* @param ref NodeRef of the content node to generate URL for (cannot be null)
* @param name File name end element to return on the url (used by the browser on Save)
*
* @return URL to download the content from the specified node
*/
public final static String generateNodeURL(NodeRef ref, String name)
{
return MessageFormat.format(NODE_URL, new Object[] {
ref.getStoreRef().getProtocol(),
ref.getStoreRef().getIdentifier(),
ref.getId(),
URLEncoder.encode(name) } );
}
}