mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
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/HEAD/root@126383 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,3 +1,21 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2015 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.rest.framework.webscripts;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -23,6 +41,7 @@ import org.codehaus.jackson.JsonGenerationException;
|
||||
import org.codehaus.jackson.JsonGenerator;
|
||||
import org.codehaus.jackson.map.JsonMappingException;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.springframework.extensions.surf.util.URLEncoder;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
@@ -39,6 +58,7 @@ import org.springframework.http.HttpMethod;
|
||||
* 5) Renders the response
|
||||
*
|
||||
* @author Gethin James
|
||||
* @author janv
|
||||
*/
|
||||
// TODO for requests that pass in input streams e.g. binary content for workflow, this is going to need a way to re-read the input stream a la
|
||||
// code in RepositoryContainer due to retrying transaction logic
|
||||
@@ -52,6 +72,8 @@ public abstract class AbstractResourceWebScript extends ApiWebScript implements
|
||||
private ContentStreamer streamer;
|
||||
protected ResourceWebScriptHelper helper;
|
||||
|
||||
public final static String HDR_NAME_CONTENT_DISPOSITION = "Content-Disposition";
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void execute(final Api api, final WebScriptRequest req, final WebScriptResponse res) throws IOException
|
||||
@@ -72,6 +94,17 @@ public abstract class AbstractResourceWebScript extends ApiWebScript implements
|
||||
{
|
||||
respons.put("toSerialize", result);
|
||||
respons.put("contentInfo", contentInfo);
|
||||
|
||||
if (result instanceof NodeBinaryResource)
|
||||
{
|
||||
String attachFileName = ((NodeBinaryResource)result).getAttachFileName();
|
||||
if ((attachFileName != null) && (attachFileName.length() > 0))
|
||||
{
|
||||
String headerValue = "attachment; filename=\"" + attachFileName + "\"; filename*=UTF-8''" + URLEncoder.encode(attachFileName);
|
||||
res.setHeader(HDR_NAME_CONTENT_DISPOSITION, headerValue);
|
||||
}
|
||||
}
|
||||
|
||||
if (params.getStatus().getRedirect())
|
||||
{
|
||||
res.setStatus(params.getStatus().getCode());
|
||||
|
Reference in New Issue
Block a user