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

@@ -24,6 +24,7 @@
*/ */
package org.alfresco.repo.web.scripts; package org.alfresco.repo.web.scripts;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@@ -361,10 +362,36 @@ public class Repository implements ApplicationContextAware, ApplicationListener,
{ {
if (referenceType.equals("node")) if (referenceType.equals("node"))
{ {
NodeRef urlRef = new NodeRef(storeRef, reference[2]); // find the node the rest of the path is relative to
if (nodeService.exists(urlRef)) NodeRef relRef = new NodeRef(storeRef, reference[2]);
if (nodeService.exists(relRef))
{ {
nodeRef = urlRef; // are there any relative path elements to process?
if (reference.length == 3 || reference.length == 4)
{
// just the NodeRef can be specified
nodeRef = relRef;
}
else
{
// process optional path elements
List<String> paths = new ArrayList<String>(reference.length - 3);
for (int i=3; i<reference.length; i++)
{
paths.add(reference[i]);
}
try
{
NodeRef parentRef = nodeService.getPrimaryParent(relRef).getParentRef();
FileInfo fileInfo = fileFolderService.resolveNamePath(parentRef, paths);
nodeRef = fileInfo.getNodeRef();
}
catch (FileNotFoundException e)
{
// NOTE: return null node ref
}
}
} }
} }
@@ -388,7 +415,7 @@ public class Repository implements ApplicationContextAware, ApplicationListener,
else else
{ {
// TODO: Allow a root path to be specified - for now, hard-code to Company Home // TODO: Allow a root path to be specified - for now, hard-code to Company Home
// NodeRef rootNodeRef = nodeService.getRootNode(storeRef); //NodeRef rootNodeRef = nodeService.getRootNode(storeRef);
NodeRef rootNodeRef = getCompanyHome(); NodeRef rootNodeRef = getCompanyHome();
if (reference.length == 3) if (reference.length == 3)
{ {

View File

@@ -26,6 +26,7 @@ package org.alfresco.repo.web.scripts.bean;
import java.io.IOException; import java.io.IOException;
import java.net.SocketException; import java.net.SocketException;
import java.text.MessageFormat;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; 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.cmr.security.PermissionService;
import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.util.URLEncoder;
import org.alfresco.web.scripts.AbstractWebScript; import org.alfresco.web.scripts.AbstractWebScript;
import org.alfresco.web.scripts.Cache; import org.alfresco.web.scripts.Cache;
import org.alfresco.web.scripts.WebScriptException; import org.alfresco.web.scripts.WebScriptException;
@@ -68,6 +70,8 @@ public class ContentGet extends AbstractWebScript
// Logger // Logger
private static final Log logger = LogFactory.getLog(ContentGet.class); private static final Log logger = LogFactory.getLog(ContentGet.class);
private static final String NODE_URL = "/api/node/content/{0}/{1}/{2}/{3}";
// Component dependencies // Component dependencies
private Repository repository; private Repository repository;
private NamespaceService namespaceService; 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) } );
}
} }