use of com.pogeyan.cmis.api.messages.PostFileResponse in project copper-cms by PogeyanOSS.
the class ObjectActor method getContent.
private PostFileResponse getContent(QueryGetRequest request) throws CmisObjectNotFoundException, CmisInvalidArgumentException, CmisRuntimeException {
String permission = request.getUserObject().getPermission();
if (!Helpers.checkingUserPremission(permission, "get")) {
throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
}
String objectId = request.getObjectId();
String streamId = request.getParameter(QueryGetRequest.PARAM_STREAM_ID);
boolean download = false;
String downloadParam = request.getParameter(QueryGetRequest.PARAM_DOWNLOAD);
if (downloadParam != null && downloadParam.length() > 0) {
String downloadParamLower = downloadParam.trim().toLowerCase(Locale.ENGLISH);
if ("attachment".equals(downloadParamLower)) {
download = true;
} else if ("inline".equals(downloadParamLower)) {
download = false;
} else {
throw new CmisInvalidArgumentException("Invalid download parameter value!");
}
}
BigInteger offset = request.getOffset();
BigInteger length = request.getLength();
ContentStream content = CmisObjectService.Impl.getContentStream(request.getRepositoryId(), objectId, streamId, offset, length);
PostFileResponse fileResponse = new PostFileResponse();
fileResponse.setDownload(download);
fileResponse.setOffset(offset);
fileResponse.setContent(content);
if (Helpers.isPerfMode()) {
MetricsInputs.get().getCounter("Count_Downloads_" + request.getObjectId()).inc();
}
return fileResponse;
/*
* if (content == null || content.getStream() == null) { throw new
* CmisRuntimeException("Content stream is null!"); }
*
* String contentType = content.getMimeType(); if (contentType == null) {
* contentType = QueryGetRequest.MEDIATYPE_OCTETSTREAM; }
*
* String contentFilename = content.getFileName(); if (contentFilename == null)
* { contentFilename = "content"; }
*
* // send content InputStream in = content.getStream(); OutputStream out =
* null; try { out = new FileOutputStream(content.getFileName());
* IOUtils.copy(in, out, QueryGetRequest.BUFFER_SIZE); out.flush(); } catch
* (Exception e) { LOG.error("writeContent exception: {}, {}", e.getMessage(),
* ExceptionUtils.getStackTrace(e)); throw new
* IllegalArgumentException("Could not write content: " + e.getMessage(), e); }
* finally { IOUtils.closeQuietly(out); IOUtils.closeQuietly(in); } return null;
*/
}
Aggregations