if (Debug.verboseOn()) Debug.logVerbose("SCVH(0b)- dataResourceId:" + dataResourceId, module);
}
} else {
GenericValue contentRevisionItem = delegator.findByPrimaryKeyCache("ContentRevisionItem", UtilMisc.toMap("contentId", rootContentId, "itemContentId", contentId, "contentRevisionSeqId", contentRevisionSeqId));
if (contentRevisionItem == null) {
throw new ViewHandlerException("ContentRevisionItem record not found for contentId=" + rootContentId
+ ", contentRevisionSeqId=" + contentRevisionSeqId + ", itemContentId=" + contentId);
}
dataResourceId = contentRevisionItem.getString("newDataResourceId");
if (Debug.verboseOn()) Debug.logVerbose("SCVH(1)- contentRevisionItem:" + contentRevisionItem, module);
if (Debug.verboseOn()) Debug.logVerbose("SCVH(2)-contentId=" + rootContentId + ", contentRevisionSeqId=" + contentRevisionSeqId + ", itemContentId=" + contentId, module);
if (Debug.verboseOn()) Debug.logVerbose("SCVH(3)- dataResourceId:" + dataResourceId, module);
}
}
GenericValue dataResource = delegator.findByPrimaryKeyCache("DataResource", UtilMisc.toMap("dataResourceId", dataResourceId));
// DEJ20080717: why are we rendering the DataResource directly instead of rendering the content?
ByteBuffer byteBuffer = DataResourceWorker.getContentAsByteBuffer(delegator, dataResourceId, https, webSiteId, locale, rootDir);
ByteArrayInputStream bais = new ByteArrayInputStream(byteBuffer.array());
// hack for IE and mime types
//String userAgent = request.getHeader("User-Agent");
//if (userAgent.indexOf("MSIE") > -1) {
// Debug.log("Found MSIE changing mime type from - " + mimeTypeId, module);
// mimeTypeId = "application/octet-stream";
//}
// setup chararcter encoding and content type
String charset = dataResource.getString("characterSetId");
mimeTypeId = dataResource.getString("mimeTypeId");
if (UtilValidate.isEmpty(charset)) {
charset = servletContext.getInitParameter("charset");
}
if (UtilValidate.isEmpty(charset)) {
charset = "UTF-8";
}
// setup content type
String contentType2 = UtilValidate.isNotEmpty(mimeTypeId) ? mimeTypeId + "; charset=" +charset : contentType;
String fileName = null;
if (!UtilValidate.isEmpty(dataResource.getString("dataResourceName"))) {
fileName = dataResource.getString("dataResourceName").replace(" ", "_"); // spaces in filenames can be a problem
}
UtilHttp.streamContentToBrowser(response, bais, byteBuffer.limit(), contentType2, fileName);
} catch (GenericEntityException e) {
throw new ViewHandlerException(e.getMessage());
} catch (IOException e) {
throw new ViewHandlerException(e.getMessage());
} catch (GeneralException e) {
throw new ViewHandlerException(e.getMessage());
}
}