mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged HEAD (5.2) to 5.2.N (5.2.1)
126383 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2) 120445 jvonka: RA-631, RA-641: REST fwk - fix GET node binary resource (set content-disposition/attachment header) - by default, set attachment header when downloading content - unless "attachment=false" *and* content type is in nonAttachContentTypes white list (eg. pdf, images) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126729 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -109,6 +109,10 @@ import java.util.Set;
|
||||
|
||||
/**
|
||||
* Centralises access to file/folder/node services and maps between representations.
|
||||
*
|
||||
* Note:
|
||||
* This class was originally used for returning some basic node info when listing Favourites.
|
||||
* It has now been re-purposed and extended to implement the new File Folder (RESTful) API.
|
||||
*
|
||||
* @author steveglover
|
||||
* @author janv
|
||||
@@ -147,6 +151,12 @@ public class NodesImpl implements Nodes
|
||||
private Set<String> defaultIgnoreTypes;
|
||||
private Set<QName> ignoreTypeQNames;
|
||||
|
||||
private Set<String> nonAttachContentTypes = Collections.EMPTY_SET; // pre-configured whitelist, eg. images & pdf
|
||||
|
||||
public void setNonAttachContentTypes(Set<String> nonAttachWhiteList) {
|
||||
this.nonAttachContentTypes = nonAttachWhiteList;
|
||||
}
|
||||
|
||||
public void init()
|
||||
{
|
||||
this.namespaceService = sr.getNamespaceService();
|
||||
@@ -1161,14 +1171,36 @@ public class NodesImpl implements Nodes
|
||||
throw new InvalidArgumentException("NodeId of content is expected: "+nodeRef);
|
||||
}
|
||||
|
||||
ContentData cd = (ContentData)nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
|
||||
Map<QName, Serializable> nodeProps = nodeService.getProperties(nodeRef);
|
||||
ContentData cd = (ContentData)nodeProps.get(ContentModel.PROP_CONTENT);
|
||||
String name = (String)nodeProps.get(ContentModel.PROP_NAME);
|
||||
|
||||
org.alfresco.rest.framework.resource.content.ContentInfo ci = null;
|
||||
if (cd != null) {
|
||||
ci = new org.alfresco.rest.framework.resource.content.ContentInfoImpl(cd.getMimetype(), cd.getEncoding(), cd.getSize(), cd.getLocale());
|
||||
}
|
||||
|
||||
// TODO attachment header - update (or extend ?) REST fwk
|
||||
return new NodeBinaryResource(nodeRef, ContentModel.PROP_CONTENT, ci);
|
||||
// By default set attachment header (with filename) unless attachment=false *and* content type is pre-configured as non-attach
|
||||
boolean attach = true;
|
||||
String attachment = parameters.getParameter("attachment");
|
||||
if (attachment != null)
|
||||
{
|
||||
Boolean a = new Boolean(attachment);
|
||||
if ((a != null) && (a == false))
|
||||
{
|
||||
if (nonAttachContentTypes.contains(cd.getMimetype()))
|
||||
{
|
||||
attach = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.warn("Ignored attachment=false for "+fileNodeId+" since "+cd.getMimetype()+" is not in the whitelist for non-attach content types");
|
||||
}
|
||||
}
|
||||
}
|
||||
String attachFileName = (attach ? name : null);
|
||||
|
||||
return new NodeBinaryResource(nodeRef, ContentModel.PROP_CONTENT, ci, attachFileName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user