String inputMimeType = null;
if (dataResource != null) {
inputMimeType = dataResource.getString("mimeTypeId");
}
byte [] inputByteArray = null;
PdfReader reader = null;
if (inputMimeType != null && inputMimeType.equals("application/pdf")) {
ByteBuffer byteBuffer = DataResourceWorker.getContentAsByteBuffer(delegator, thisDataResourceId, https, webSiteId, locale, rootDir);
inputByteArray = byteBuffer.array();
reader = new PdfReader(inputByteArray);
} else if (inputMimeType != null && inputMimeType.equals("text/html")) {
ByteBuffer byteBuffer = DataResourceWorker.getContentAsByteBuffer(delegator, thisDataResourceId, https, webSiteId, locale, rootDir);
inputByteArray = byteBuffer.array();
String s = new String(inputByteArray);
Debug.logInfo("text/html string:" + s, module);
continue;
} else if (inputMimeType != null && inputMimeType.equals("application/vnd.ofbiz.survey.response")) {
String surveyResponseId = dataResource.getString("relatedDetailId");
String surveyId = null;
String acroFormContentId = null;
GenericValue surveyResponse = null;
if (UtilValidate.isNotEmpty(surveyResponseId)) {
surveyResponse = delegator.findByPrimaryKey("SurveyResponse", UtilMisc.toMap("surveyResponseId", surveyResponseId));
if (surveyResponse != null) {
surveyId = surveyResponse.getString("surveyId");
}
}
if (UtilValidate.isNotEmpty(surveyId)) {
GenericValue survey = delegator.findByPrimaryKey("Survey", UtilMisc.toMap("surveyId", surveyId));
if (survey != null) {
acroFormContentId = survey.getString("acroFormContentId");
if (UtilValidate.isNotEmpty(acroFormContentId)) {
// TODO: is something supposed to be done here?
}
}
}
if (surveyResponse != null) {
if (UtilValidate.isEmpty(acroFormContentId)) {
// Create AcroForm PDF
Map survey2PdfResults = dispatcher.runSync("buildPdfFromSurveyResponse", UtilMisc.toMap("surveyResponseId", surveyId));
if (ServiceUtil.isError(survey2PdfResults)) {
return ServiceUtil.returnError("Error building PDF from SurveyResponse: ", null, null, survey2PdfResults);
}
ByteBuffer outByteBuffer = (ByteBuffer) survey2PdfResults.get("outByteBuffer");
inputByteArray = outByteBuffer.array();
reader = new PdfReader(inputByteArray);
} else {
// Fill in acroForm
Map survey2AcroFieldResults = dispatcher.runSync("setAcroFieldsFromSurveyResponse", UtilMisc.toMap("surveyResponseId", surveyResponseId));
if (ServiceUtil.isError(survey2AcroFieldResults)) {
return ServiceUtil.returnError("Error setting AcroFields from SurveyResponse: ", null, null, survey2AcroFieldResults);
}
ByteBuffer outByteBuffer = (ByteBuffer) survey2AcroFieldResults.get("outByteBuffer");
inputByteArray = outByteBuffer.array();
reader = new PdfReader(inputByteArray);
}
}
} else {
ByteBuffer inByteBuffer = DataResourceWorker.getContentAsByteBuffer(delegator, thisDataResourceId, https, webSiteId, locale, rootDir);
Map convertInMap = UtilMisc.toMap("userLogin", userLogin, "inByteBuffer", inByteBuffer, "inputMimeType", inputMimeType, "outputMimeType", "application/pdf");
if (UtilValidate.isNotEmpty(oooHost)) convertInMap.put("oooHost", oooHost);
if (UtilValidate.isNotEmpty(oooPort)) convertInMap.put("oooPort", oooPort);
Map convertResult = dispatcher.runSync("convertDocumentByteBuffer", convertInMap);
if (ServiceUtil.isError(convertResult)) {
return ServiceUtil.returnError("Error in Open", null, null, convertResult);
}
ByteBuffer outByteBuffer = (ByteBuffer) convertResult.get("outByteBuffer");
inputByteArray = outByteBuffer.array();
reader = new PdfReader(inputByteArray);
}
if (reader != null) {
int n = reader.getNumberOfPages();
for (int i=0; i < n; i++) {
PdfImportedPage pg = writer.getImportedPage(reader, i + 1);
//cb.addTemplate(pg, left, height * pgCnt);
writer.addPage(pg);
pgCnt++;