mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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:
@@ -24,6 +24,7 @@
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -361,10 +362,36 @@ public class Repository implements ApplicationContextAware, ApplicationListener,
|
||||
{
|
||||
if (referenceType.equals("node"))
|
||||
{
|
||||
NodeRef urlRef = new NodeRef(storeRef, reference[2]);
|
||||
if (nodeService.exists(urlRef))
|
||||
// find the node the rest of the path is relative to
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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) } );
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user