HttpSession session = request.getSession();
Map uploadResults = LayoutWorker.uploadImageAndParameters(request, "imageData");
//Debug.logVerbose("in createLayoutImage(java), uploadResults:" + uploadResults, "");
Map formInput = (Map)uploadResults.get("formInput");
Map context = new HashMap();
ByteWrapper byteWrap = (ByteWrapper)uploadResults.get("imageData");
if (byteWrap == null) {
String errMsg = UtilProperties.getMessage(LayoutEvents.err_resource, "layoutEvents.image_data_null", locale);
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}
//Debug.logVerbose("in createLayoutImage, byteWrap(0):" + byteWrap, module);
String imageFileName = (String)uploadResults.get("imageFileName");
//Debug.logVerbose("in createLayoutImage(java), context:" + context, "");
String imageFileNameExt = null;
if (UtilValidate.isNotEmpty(imageFileName)) {
int pos = imageFileName.lastIndexOf(".");
if (pos >= 0)
imageFileNameExt = imageFileName.substring(pos + 1);
}
String mimeTypeId = "image/" + imageFileNameExt;
List errorMessages = new ArrayList();
if (locale == null)
locale = Locale.getDefault();
context.put("locale", locale);
try {
SimpleMapProcessor.runSimpleMapProcessor(
"org/ofbiz/content/ContentManagementMapProcessors.xml", "contentIn",
formInput, context, errorMessages, locale);
SimpleMapProcessor.runSimpleMapProcessor(
"org/ofbiz/content/ContentManagementMapProcessors.xml", "dataResourceIn",
formInput, context, errorMessages, locale);
SimpleMapProcessor.runSimpleMapProcessor(
"org/ofbiz/content/ContentManagementMapProcessors.xml", "contentAssocIn",
formInput, context, errorMessages, locale);
} catch(MiniLangException e) {
request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
return "error";
}
context.put("dataResourceName", context.get("contentName"));
context.put("userLogin", session.getAttribute("userLogin"));
context.put("dataResourceTypeId", "IMAGE_OBJECT");
context.put("contentAssocTypeId", "SUB_CONTENT");
context.put("contentTypeId", "DOCUMENT");
context.put("contentIdTo", formInput.get("contentIdTo"));
context.put("textData", formInput.get("textData"));
String contentPurposeTypeId = (String)formInput.get("contentPurposeTypeId");
if (UtilValidate.isNotEmpty(contentPurposeTypeId)){
context.put("contentPurposeList", UtilMisc.toList(contentPurposeTypeId));
}
Map result = dispatcher.runSync("persistContentAndAssoc", context);
//Debug.logVerbose("in createLayoutImage, result:" + result, module);
String dataResourceId = (String)result.get("dataResourceId");
String activeContentId = (String)result.get("contentId");
if (UtilValidate.isNotEmpty(activeContentId)) {
Map context2 = new HashMap();
context2.put("activeContentId", activeContentId);
//context2.put("dataResourceId", dataResourceId);
context2.put("contentAssocTypeId", result.get("contentAssocTypeId"));
context2.put("fromDate", result.get("fromDate"));
request.setAttribute("contentId", result.get("contentId"));
request.setAttribute("drDataResourceId", dataResourceId);
request.setAttribute("currentEntityName", "SubContentDataResourceId");
context2.put("contentIdTo", formInput.get("contentIdTo"));
context2.put("mapKey", formInput.get("mapKey"));
//Debug.logVerbose("in createLayoutImage, context2:" + context2, module);
Map result2 = dispatcher.runSync("deactivateAssocs", context2);
}
GenericValue dataResource = delegator.findByPrimaryKey("DataResource",
UtilMisc.toMap("dataResourceId", dataResourceId));
//Debug.logVerbose("in createLayoutImage, dataResource:" + dataResource, module);
// Use objectInfo field to store the name of the file, since there is no
// place in ImageDataResource for it.
if (dataResource != null) {
dataResource.set("objectInfo", imageFileName);
dataResource.set("mimeTypeId", mimeTypeId);
dataResource.store();
}
// See if this needs to be a create or an update procedure
GenericValue imageDataResource = delegator.findByPrimaryKey("ImageDataResource",
UtilMisc.toMap("dataResourceId", dataResourceId));
//Debug.logVerbose("in createLayoutImage, imageDataResource(0):" + imageDataResource, module);
if (imageDataResource == null) {
imageDataResource = delegator.makeValue("ImageDataResource",
UtilMisc.toMap("dataResourceId", dataResourceId));
imageDataResource.set("imageData", byteWrap.getBytes());
imageDataResource.create();
} else {
imageDataResource.set("imageData", byteWrap.getBytes());
imageDataResource.store();
}
} catch (GenericEntityException e3) {
request.setAttribute("_ERROR_MESSAGE_", e3.getMessage());
return "error";