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)
126489 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2) 122631 jkaabimofrad: RA-676: Added node's renditions REST API. - Download renditioned content + test git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126833 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2016 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.resource.content;
|
||||
|
||||
/**
|
||||
* An abstract binary resource.
|
||||
*
|
||||
* @author Jamal Kaabi-Mofrad
|
||||
*/
|
||||
public class AbstractBinaryResource implements BinaryResource
|
||||
{
|
||||
final String attachFileName;
|
||||
|
||||
public AbstractBinaryResource(String attachFileName)
|
||||
{
|
||||
this.attachFileName = attachFileName;
|
||||
}
|
||||
|
||||
public String getAttachFileName()
|
||||
{
|
||||
return attachFileName;
|
||||
}
|
||||
}
|
@@ -30,16 +30,21 @@ import java.io.File;
|
||||
|
||||
/**
|
||||
* A binary resource based on a File.
|
||||
*
|
||||
*
|
||||
* @author Gethin James
|
||||
*/
|
||||
public class FileBinaryResource implements BinaryResource
|
||||
public class FileBinaryResource extends AbstractBinaryResource
|
||||
{
|
||||
final File file;
|
||||
|
||||
public FileBinaryResource(File file)
|
||||
{
|
||||
super();
|
||||
this(file, null);
|
||||
}
|
||||
|
||||
public FileBinaryResource(File file, String attachFileName)
|
||||
{
|
||||
super(attachFileName);
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
|
@@ -30,25 +30,22 @@ import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* A binary resource based on a Node reference.
|
||||
*
|
||||
*
|
||||
* @author Gethin James
|
||||
*/
|
||||
public class NodeBinaryResource implements BinaryResource
|
||||
public class NodeBinaryResource extends AbstractBinaryResource
|
||||
{
|
||||
|
||||
final NodeRef nodeRef;
|
||||
final QName propertyQName;
|
||||
final ContentInfo contentInfo;
|
||||
final String attachFileName;
|
||||
|
||||
|
||||
public NodeBinaryResource(NodeRef nodeRef, QName propertyQName, ContentInfo contentInfo, String attachFileName)
|
||||
{
|
||||
super();
|
||||
|
||||
super(attachFileName);
|
||||
this.nodeRef = nodeRef;
|
||||
this.propertyQName = propertyQName;
|
||||
this.contentInfo = contentInfo;
|
||||
this.attachFileName = attachFileName;
|
||||
}
|
||||
|
||||
public NodeRef getNodeRef()
|
||||
@@ -65,9 +62,4 @@ public class NodeBinaryResource implements BinaryResource
|
||||
{
|
||||
return this.contentInfo;
|
||||
}
|
||||
|
||||
public String getAttachFileName()
|
||||
{
|
||||
return this.attachFileName;
|
||||
}
|
||||
}
|
||||
}
|
@@ -47,6 +47,7 @@ import org.alfresco.rest.framework.resource.content.ContentInfo;
|
||||
import org.alfresco.rest.framework.resource.content.FileBinaryResource;
|
||||
import org.alfresco.rest.framework.resource.content.NodeBinaryResource;
|
||||
import org.alfresco.rest.framework.resource.parameters.Params;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.codehaus.jackson.JsonGenerationException;
|
||||
@@ -90,11 +91,11 @@ public abstract class AbstractResourceWebScript extends ApiWebScript implements
|
||||
@Override
|
||||
public void execute(final Api api, final WebScriptRequest req, final WebScriptResponse res) throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
final Map<String, Object> respons = new HashMap<String, Object>();
|
||||
final Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
|
||||
final ResourceWithMetadata resource = locator.locateResource(api,templateVars, httpMethod);
|
||||
final ResourceWithMetadata resource = locator.locateResource(api,templateVars, httpMethod);
|
||||
final Params params = paramsExtractor.extractParams(resource.getMetaData(),req);
|
||||
final boolean isReadOnly = HttpMethod.GET==httpMethod;
|
||||
|
||||
@@ -132,19 +133,19 @@ public abstract class AbstractResourceWebScript extends ApiWebScript implements
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (ApiException apiException)
|
||||
{
|
||||
renderErrorResponse(resolveException(apiException), res);
|
||||
}
|
||||
catch (WebScriptException webException)
|
||||
{
|
||||
renderErrorResponse(resolveException(webException), res);
|
||||
}
|
||||
catch (RuntimeException runtimeException)
|
||||
{
|
||||
renderErrorResponse(resolveException(runtimeException), res);
|
||||
}
|
||||
}
|
||||
catch (ApiException apiException)
|
||||
{
|
||||
renderErrorResponse(resolveException(apiException), res);
|
||||
}
|
||||
catch (WebScriptException webException)
|
||||
{
|
||||
renderErrorResponse(resolveException(webException), res);
|
||||
}
|
||||
catch (RuntimeException runtimeException)
|
||||
{
|
||||
renderErrorResponse(resolveException(runtimeException), res);
|
||||
}
|
||||
}
|
||||
|
||||
public Object execute(final ResourceWithMetadata resource, final Params params, final WebScriptResponse res, boolean isReadOnly)
|
||||
@@ -176,6 +177,8 @@ public abstract class AbstractResourceWebScript extends ApiWebScript implements
|
||||
if (resource instanceof FileBinaryResource)
|
||||
{
|
||||
FileBinaryResource fileResource = (FileBinaryResource) resource;
|
||||
// if requested, set attachment
|
||||
setAttachment(res, fileResource.getAttachFileName());
|
||||
streamer.streamContent(req, res, fileResource.getFile(), null, false, null, null);
|
||||
}
|
||||
else if (resource instanceof NodeBinaryResource)
|
||||
@@ -183,16 +186,21 @@ public abstract class AbstractResourceWebScript extends ApiWebScript implements
|
||||
NodeBinaryResource nodeResource = (NodeBinaryResource) resource;
|
||||
ContentInfo contentInfo = nodeResource.getContentInfo();
|
||||
setContentInfoOnResponse(res,contentInfo);
|
||||
String attachFileName = nodeResource.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 requested, set attachment
|
||||
setAttachment(res, nodeResource.getAttachFileName());
|
||||
streamer.streamContent(req, res, nodeResource.getNodeRef(), nodeResource.getPropertyQName(), false, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
private void setAttachment(final WebScriptResponse res, final String attachFileName)
|
||||
{
|
||||
if (StringUtils.isNotEmpty(attachFileName))
|
||||
{
|
||||
String headerValue = "attachment; filename=\"" + attachFileName + "\"; filename*=UTF-8''" + URLEncoder.encode(attachFileName);
|
||||
res.setHeader(HDR_NAME_CONTENT_DISPOSITION, headerValue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The response status must be set before the response is written by Jackson (which will by default close and commit the response).
|
||||
* In a r/w txn, web script buffered responses ensure that it doesn't really matter but for r/o txns this is important.
|
||||
|
Reference in New Issue
Block a user