String contentId = request.getParameter("contentId");
String rootContentId = request.getParameter("rootContentId");
String dataResourceId = request.getParameter("dataResourceId");
String contentRevisionSeqId = request.getParameter("contentRevisionSeqId");
String mimeTypeId = request.getParameter("mimeTypeId");
ByteWrapper byteWrapper = null;
Locale locale = UtilHttp.getLocale(request);
String rootDir = null;
String webSiteId = null;
String https = null;
if (UtilValidate.isEmpty(rootDir)) {
rootDir = servletContext.getRealPath("/");
}
if (UtilValidate.isEmpty(webSiteId)) {
webSiteId = (String) servletContext.getAttribute("webSiteId");
}
if (UtilValidate.isEmpty(https)) {
https = (String) servletContext.getAttribute("https");
}
try {
Debug.logInfo("SCVH(0a)- dataResourceId:" + dataResourceId, module);
GenericDelegator delegator = (GenericDelegator)request.getAttribute("delegator");
if (UtilValidate.isEmpty(dataResourceId)) {
if (UtilValidate.isEmpty(contentRevisionSeqId)) {
GenericValue content = delegator.findByPrimaryKeyCache("Content", UtilMisc.toMap("contentId", contentId));
dataResourceId = content.getString("dataResourceId");
Debug.logInfo("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);
}
Debug.logInfo("SCVH(1)- contentRevisionItem:" + contentRevisionItem, module);
Debug.logInfo("SCVH(2)-contentId=" + rootContentId
+ ", contentRevisionSeqId=" + contentRevisionSeqId + ", itemContentId=" + contentId, module);
dataResourceId = contentRevisionItem.getString("newDataResourceId");
Debug.logInfo("SCVH(3)- dataResourceId:" + dataResourceId, module);
}
}
GenericValue dataResource = delegator.findByPrimaryKeyCache("DataResource", UtilMisc.toMap("dataResourceId", dataResourceId));
byteWrapper = DataResourceWorker.getContentAsByteWrapper(delegator, dataResourceId, https, webSiteId, locale, rootDir);
ByteArrayInputStream bais = new ByteArrayInputStream(byteWrapper.getBytes());
// 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 = "ISO-8859-1";
}
// setup content type
String contentType2 = UtilValidate.isNotEmpty(mimeTypeId) ? mimeTypeId + "; charset=" +charset : contentType;
UtilHttp.streamContentToBrowser(response, bais, byteWrapper.getLength(), contentType2);
} catch(GenericEntityException e) {
throw new ViewHandlerException(e.getMessage());
} catch(IOException e) {
throw new ViewHandlerException(e.getMessage());
} catch(GeneralException e) {