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:
Ancuta Morarasu
2016-05-11 11:43:54 +00:00
parent b5a0388b74
commit f053fca565
10 changed files with 362 additions and 40 deletions

View File

@@ -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.