mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
First cut of export REST API for RM. Takes a list of arbitary NodeRef's, creates an ACP file of the nodes and streams it back to the client as an attachment.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@15668 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -357,24 +357,54 @@ public class StreamContent extends AbstractWebScript
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Streams content back to client from a given resource path
|
* Streams content back to client from a given resource path.
|
||||||
*
|
*
|
||||||
* @param req
|
* @param req The request
|
||||||
* @param res
|
* @param res The response
|
||||||
* @param resourcePath
|
* @param resourcePath The resource path the content is required for
|
||||||
* @param attach
|
* @param attach Indicates whether the content should be streamed as an attachment or not
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
protected void streamContent(WebScriptRequest req, WebScriptResponse res, String resourcePath, boolean attach)
|
protected void streamContent(WebScriptRequest req, WebScriptResponse res, String resourcePath, boolean attach)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
|
// get extension of resource
|
||||||
String ext = "";
|
String ext = "";
|
||||||
String mimetype = MimetypeMap.MIMETYPE_BINARY;
|
|
||||||
int extIndex = resourcePath.lastIndexOf('.');
|
int extIndex = resourcePath.lastIndexOf('.');
|
||||||
if (extIndex != -1)
|
if (extIndex != -1)
|
||||||
{
|
{
|
||||||
ext = resourcePath.substring(extIndex + 1);
|
ext = resourcePath.substring(extIndex);
|
||||||
String mt = mimetypeService.getMimetypesByExtension().get(ext);
|
}
|
||||||
|
|
||||||
|
// create temporary file
|
||||||
|
File file = TempFileProvider.createTempFile("streamContent-", ext);
|
||||||
|
InputStream is = this.getClass().getClassLoader().getResourceAsStream(resourcePath);
|
||||||
|
OutputStream os = new FileOutputStream(file);
|
||||||
|
FileCopyUtils.copy(is, os);
|
||||||
|
|
||||||
|
// stream the contents of the file
|
||||||
|
streamContent(req, res, file, attach);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Streams content back to client from a given resource path.
|
||||||
|
*
|
||||||
|
* @param req The request
|
||||||
|
* @param res The response
|
||||||
|
* @param resourcePath The resource path the content is required for
|
||||||
|
* @param attach Indicates whether the content should be streamed as an attachment or not
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
protected void streamContent(WebScriptRequest req, WebScriptResponse res, File file, boolean attach)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
// determine mimetype from file extension
|
||||||
|
String filePath = file.getAbsolutePath();
|
||||||
|
String mimetype = MimetypeMap.MIMETYPE_BINARY;
|
||||||
|
int extIndex = filePath.lastIndexOf('.');
|
||||||
|
if (extIndex != -1)
|
||||||
|
{
|
||||||
|
String mt = mimetypeService.getMimetypesByExtension().get(filePath.substring(extIndex + 1));
|
||||||
if (mt != null)
|
if (mt != null)
|
||||||
{
|
{
|
||||||
mimetype = mt;
|
mimetype = mt;
|
||||||
@@ -387,13 +417,9 @@ public class StreamContent extends AbstractWebScript
|
|||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
calendar.set(1975, 3, 26);
|
calendar.set(1975, 3, 26);
|
||||||
this.resouceFileModifiedDate = calendar.getTime();
|
this.resouceFileModifiedDate = calendar.getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
File file = TempFileProvider.createTempFile("streamContent-", ext);
|
|
||||||
InputStream is = this.getClass().getClassLoader().getResourceAsStream(resourcePath);
|
|
||||||
OutputStream os = new FileOutputStream(file);
|
|
||||||
FileCopyUtils.copy(is, os);
|
|
||||||
|
|
||||||
|
// setup file reader and stream
|
||||||
FileContentReader reader = new FileContentReader(file);
|
FileContentReader reader = new FileContentReader(file);
|
||||||
reader.setMimetype(mimetype);
|
reader.setMimetype(mimetype);
|
||||||
reader.setEncoding("UTF-8");
|
reader.setEncoding("UTF-8");
|
||||||
|
Reference in New Issue
Block a user