1 package org.ofbiz.content.layout; 2 3 import java.sql.Timestamp ; 4 import java.util.ArrayList ; 5 import java.util.Collection ; 6 import java.util.HashMap ; 7 import java.util.Iterator ; 8 import java.util.List ; 9 import java.util.Locale ; 10 import java.util.Map ; 11 import javax.servlet.http.HttpServletRequest ; 12 import javax.servlet.http.HttpServletResponse ; 13 import javax.servlet.http.HttpSession ; 14 15 import org.ofbiz.base.util.Debug; 16 import org.ofbiz.base.util.UtilDateTime; 17 import org.ofbiz.base.util.UtilHttp; 18 import org.ofbiz.base.util.UtilMisc; 19 import org.ofbiz.base.util.UtilProperties; 20 import org.ofbiz.base.util.UtilValidate; 21 import org.ofbiz.content.ContentManagementWorker; 22 import org.ofbiz.entity.GenericDelegator; 23 import org.ofbiz.entity.GenericEntityException; 24 import org.ofbiz.entity.GenericPK; 25 import org.ofbiz.entity.GenericValue; 26 import org.ofbiz.entity.util.ByteWrapper; 27 import org.ofbiz.minilang.MiniLangException; 28 import org.ofbiz.minilang.SimpleMapProcessor; 29 import org.ofbiz.service.GenericServiceException; 30 import org.ofbiz.service.LocalDispatcher; 31 import org.ofbiz.service.ModelService; 32 33 42 public class LayoutEvents { 43 44 public static final String module = LayoutEvents.class.getName(); 45 public static final String err_resource = "ContentErrorUiLabel"; 46 47 public static String createLayoutImage(HttpServletRequest request, HttpServletResponse response) { 48 Locale locale = UtilHttp.getLocale(request); 49 50 try { 51 GenericDelegator delegator = (GenericDelegator)request.getAttribute("delegator"); 52 LocalDispatcher dispatcher = (LocalDispatcher)request.getAttribute("dispatcher"); 53 HttpSession session = request.getSession(); 54 Map uploadResults = LayoutWorker.uploadImageAndParameters(request, "imageData"); 55 Map formInput = (Map )uploadResults.get("formInput"); 57 Map context = new HashMap (); 58 ByteWrapper byteWrap = (ByteWrapper)uploadResults.get("imageData"); 59 if (byteWrap == null) { 60 String errMsg = UtilProperties.getMessage(LayoutEvents.err_resource, "layoutEvents.image_data_null", locale); 61 request.setAttribute("_ERROR_MESSAGE_", errMsg); 62 return "error"; 63 } 64 String imageFileName = (String )uploadResults.get("imageFileName"); 66 String imageFileNameExt = null; 68 if (UtilValidate.isNotEmpty(imageFileName)) { 69 int pos = imageFileName.lastIndexOf("."); 70 if (pos >= 0) 71 imageFileNameExt = imageFileName.substring(pos + 1); 72 } 73 String mimeTypeId = "image/" + imageFileNameExt; 74 List errorMessages = new ArrayList (); 75 if (locale == null) 76 locale = Locale.getDefault(); 77 context.put("locale", locale); 78 79 try { 80 SimpleMapProcessor.runSimpleMapProcessor( 81 "org/ofbiz/content/ContentManagementMapProcessors.xml", "contentIn", 82 formInput, context, errorMessages, locale); 83 SimpleMapProcessor.runSimpleMapProcessor( 84 "org/ofbiz/content/ContentManagementMapProcessors.xml", "dataResourceIn", 85 formInput, context, errorMessages, locale); 86 SimpleMapProcessor.runSimpleMapProcessor( 87 "org/ofbiz/content/ContentManagementMapProcessors.xml", "contentAssocIn", 88 formInput, context, errorMessages, locale); 89 } catch(MiniLangException e) { 90 request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); 91 return "error"; 92 } 93 94 context.put("dataResourceName", context.get("contentName")); 95 context.put("userLogin", session.getAttribute("userLogin")); 96 context.put("dataResourceTypeId", "IMAGE_OBJECT"); 97 context.put("contentAssocTypeId", "SUB_CONTENT"); 98 context.put("contentTypeId", "DOCUMENT"); 99 context.put("contentIdTo", formInput.get("contentIdTo")); 100 context.put("textData", formInput.get("textData")); 101 String contentPurposeTypeId = (String )formInput.get("contentPurposeTypeId"); 102 if (UtilValidate.isNotEmpty(contentPurposeTypeId)){ 103 context.put("contentPurposeList", UtilMisc.toList(contentPurposeTypeId)); 104 } 105 106 Map result = dispatcher.runSync("persistContentAndAssoc", context); 107 109 String dataResourceId = (String )result.get("dataResourceId"); 110 String activeContentId = (String )result.get("contentId"); 111 if (UtilValidate.isNotEmpty(activeContentId)) { 112 Map context2 = new HashMap (); 113 context2.put("activeContentId", activeContentId); 114 context2.put("contentAssocTypeId", result.get("contentAssocTypeId")); 116 context2.put("fromDate", result.get("fromDate")); 117 118 request.setAttribute("contentId", result.get("contentId")); 119 request.setAttribute("drDataResourceId", dataResourceId); 120 request.setAttribute("currentEntityName", "SubContentDataResourceId"); 121 122 context2.put("contentIdTo", formInput.get("contentIdTo")); 123 context2.put("mapKey", formInput.get("mapKey")); 124 125 Map result2 = dispatcher.runSync("deactivateAssocs", context2); 127 } 128 129 GenericValue dataResource = delegator.findByPrimaryKey("DataResource", 130 UtilMisc.toMap("dataResourceId", dataResourceId)); 131 if (dataResource != null) { 135 dataResource.set("objectInfo", imageFileName); 136 dataResource.set("mimeTypeId", mimeTypeId); 137 dataResource.store(); 138 } 139 140 GenericValue imageDataResource = delegator.findByPrimaryKey("ImageDataResource", 142 UtilMisc.toMap("dataResourceId", dataResourceId)); 143 if (imageDataResource == null) { 145 imageDataResource = delegator.makeValue("ImageDataResource", 146 UtilMisc.toMap("dataResourceId", dataResourceId)); 147 imageDataResource.set("imageData", byteWrap.getBytes()); 148 imageDataResource.create(); 149 } else { 150 imageDataResource.set("imageData", byteWrap.getBytes()); 151 imageDataResource.store(); 152 } 153 } catch (GenericEntityException e3) { 154 request.setAttribute("_ERROR_MESSAGE_", e3.getMessage()); 155 return "error"; 156 } catch( GenericServiceException e) { 157 request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); 158 return "error"; 159 } 160 return "success"; 161 } 162 163 public static String updateLayoutImage(HttpServletRequest request, HttpServletResponse response) { 164 Locale locale = UtilHttp.getLocale(request); 165 try { 166 GenericDelegator delegator = (GenericDelegator)request.getAttribute("delegator"); 167 LocalDispatcher dispatcher = (LocalDispatcher)request.getAttribute("dispatcher"); 168 HttpSession session = request.getSession(); 169 Map uploadResults = LayoutWorker.uploadImageAndParameters(request, "imageData"); 170 Map context = (Map )uploadResults.get("formInput"); 171 ByteWrapper byteWrap = (ByteWrapper)uploadResults.get("imageData"); 172 if (byteWrap == null) { 173 String errMsg = UtilProperties.getMessage(LayoutEvents.err_resource, "layoutEvents.image_data_null", locale); 174 request.setAttribute("_ERROR_MESSAGE_", errMsg); 175 return "error"; 176 } 177 String imageFileName = (String )uploadResults.get("imageFileName"); 178 Debug.logVerbose("in createLayoutImage(java), context:" + context, ""); 179 context.put("userLogin", session.getAttribute("userLogin")); 180 context.put("dataResourceTypeId", "IMAGE_OBJECT"); 181 context.put("contentAssocTypeId", "SUB_CONTENT"); 182 context.put("contentTypeId", "DOCUMENT"); 183 context.put("mimeType", context.get("drMimeType")); 184 context.put("drMimeType", null); 185 context.put("objectInfo", context.get("drobjectInfo")); 186 context.put("drObjectInfo", null); 187 context.put("drDataResourceTypeId", null); 188 189 String dataResourceId = (String )context.get("drDataResourceId"); 190 Debug.logVerbose("in createLayoutImage(java), dataResourceId:" + dataResourceId, ""); 191 192 GenericValue dataResource = delegator.findByPrimaryKey("DataResource", 193 UtilMisc.toMap("dataResourceId", dataResourceId)); 194 Debug.logVerbose("in createLayoutImage(java), dataResource:" + dataResource, ""); 195 Debug.logVerbose("in createLayoutImage(java), imageFileName:" + imageFileName, ""); 198 if (dataResource != null) { 199 dataResource.setNonPKFields(context); 201 dataResource.store(); 202 } 203 204 GenericValue imageDataResource = delegator.findByPrimaryKey("ImageDataResource", 206 UtilMisc.toMap("dataResourceId", dataResourceId)); 207 if (imageDataResource == null) { 208 imageDataResource = delegator.makeValue("ImageDataResource", 209 UtilMisc.toMap("dataResourceId", dataResourceId)); 210 imageDataResource.set("imageData", byteWrap.getBytes()); 211 imageDataResource.create(); 212 } else { 213 imageDataResource.set("imageData", byteWrap.getBytes()); 214 imageDataResource.store(); 215 } 216 } catch (GenericEntityException e3) { 217 request.setAttribute("_ERROR_MESSAGE_", e3.getMessage()); 218 return "error"; 219 } 220 return "success"; 221 } 222 223 public static String replaceSubContent(HttpServletRequest request, HttpServletResponse response) { 224 225 GenericDelegator delegator = (GenericDelegator)request.getAttribute("delegator"); 226 LocalDispatcher dispatcher = (LocalDispatcher)request.getAttribute("dispatcher"); 227 HttpSession session = request.getSession(); 228 Locale locale = UtilHttp.getLocale(request); 229 Map context = new HashMap (); 230 Map paramMap = UtilHttp.getParameterMap(request); 231 Debug.logVerbose("in replaceSubContent, paramMap:" + paramMap, module); 232 String dataResourceId = (String )paramMap.get("dataResourceId"); 233 if (UtilValidate.isEmpty(dataResourceId)) { 234 String errMsg = UtilProperties.getMessage(LayoutEvents.err_resource, "layoutEvents.data_ressource_id_null", locale); 235 request.setAttribute("_ERROR_MESSAGE_", errMsg); 236 return "error"; 237 } 238 String contentIdTo = (String )paramMap.get("contentIdTo"); 239 if (UtilValidate.isEmpty(contentIdTo)) { 240 String errMsg = UtilProperties.getMessage(LayoutEvents.err_resource, "layoutEvents.content_id_to_null", locale); 241 request.setAttribute("_ERROR_MESSAGE_", errMsg); 242 return "error"; 243 } 244 String mapKey = (String )paramMap.get("mapKey"); 245 246 context.put("dataResourceId", dataResourceId); 247 String contentId = (String )paramMap.get("contentId"); 248 context.put("userLogin", session.getAttribute("userLogin")); 249 250 269 if (UtilValidate.isNotEmpty(contentId)) { 270 context.put("contentId", contentId); 271 context.put("contentIdTo", contentIdTo); 272 context.put("mapKey", mapKey); 273 context.put("contentAssocTypeId", "SUB_CONTENT"); 274 275 try { 276 Map result = dispatcher.runSync("persistContentAndAssoc", context); 277 request.setAttribute("contentId", contentIdTo); 279 Map context2 = new HashMap (); 280 context2.put("activeContentId", contentId); 281 context2.put("contentAssocTypeId", "SUB_CONTENT"); 283 context2.put("fromDate", result.get("fromDate")); 284 285 request.setAttribute("drDataResourceId", null); 286 request.setAttribute("currentEntityName", "ContentDataResourceView"); 287 288 context2.put("contentIdTo", contentIdTo); 289 context2.put("mapKey", mapKey); 290 291 Map result2 = dispatcher.runSync("deactivateAssocs", context2); 293 } catch( GenericServiceException e) { 294 request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); 295 return "error"; 296 } 297 } 298 299 return "success"; 300 } 301 302 public static String cloneLayout(HttpServletRequest request, HttpServletResponse response) { 303 304 GenericDelegator delegator = (GenericDelegator)request.getAttribute("delegator"); 305 LocalDispatcher dispatcher = (LocalDispatcher)request.getAttribute("dispatcher"); 306 HttpSession session = request.getSession(); 307 Locale locale = UtilHttp.getLocale(request); 308 Map paramMap = UtilHttp.getParameterMap(request); 309 String contentId = (String )paramMap.get("contentId"); 310 Debug.logVerbose("in cloneLayout, contentId:" + contentId, ""); 311 if (UtilValidate.isEmpty(contentId)) { 312 String errMsg = UtilProperties.getMessage(LayoutEvents.err_resource, "layoutEvents.content_id_empty", locale); 313 request.setAttribute("_ERROR_MESSAGE_", errMsg); 314 return "error"; 315 } 316 String contentIdTo = (String )paramMap.get("contentIdTo"); 317 Debug.logVerbose("in cloneLayout, contentIdTo:" + contentIdTo, ""); 318 GenericValue content = null; 319 GenericValue newContent = null; 320 GenericValue userLogin = (GenericValue)request.getSession().getAttribute("userLogin"); 321 String userLoginId = (String ) userLogin.get("userLoginId"); 322 List entityList = null; 323 String newId = null; 324 String newDataResourceId = null; 325 try { 326 content = delegator.findByPrimaryKey("Content", 327 UtilMisc.toMap("contentId", contentId)); 328 Debug.logVerbose("in cloneLayout, content:" + content, ""); 329 if (content == null) { 330 String errMsg = UtilProperties.getMessage(LayoutEvents.err_resource, "layoutEvents.content_empty", locale); 331 request.setAttribute("_ERROR_MESSAGE_", errMsg); 332 return "error"; 333 } 334 newContent = delegator.makeValue("Content", content); 335 Debug.logVerbose("in cloneLayout, newContent:" + newContent, ""); 336 String oldName = (String )content.get("contentName"); 337 newId = delegator.getNextSeqId("Content").toString(); 338 newContent.set("contentId", newId); 339 String dataResourceId = (String )content.get("dataResourceId"); 340 GenericValue dataResource = delegator.findByPrimaryKey("DataResource", 341 UtilMisc.toMap("dataResourceId", dataResourceId)); 342 if (dataResource != null) { 343 GenericValue newDataResource = delegator.makeValue("DataResource", dataResource); 344 Debug.logVerbose("in cloneLayout, newDataResource:" + newDataResource, ""); 345 String dataResourceName = "Copy:" + (String )dataResource.get("dataResourceName"); 346 newDataResource.set("dataResourceName", dataResourceName); 347 newDataResourceId = delegator.getNextSeqId("DataResource").toString(); 348 newDataResource.set("dataResourceId", newDataResourceId); 349 newDataResource.set("createdDate", UtilDateTime.nowTimestamp()); 350 newDataResource.set("lastModifiedDate", UtilDateTime.nowTimestamp()); 351 newDataResource.set("createdByUserLogin", userLoginId); 352 newDataResource.set("lastModifiedByUserLogin", userLoginId); 353 newDataResource.create(); 354 } 355 newContent.set("contentName", "Copy - " + oldName); 356 newContent.set("createdDate", UtilDateTime.nowTimestamp()); 357 newContent.set("lastModifiedDate", UtilDateTime.nowTimestamp()); 358 newContent.set("createdByUserLogin", userLoginId); 359 newContent.set("lastModifiedByUserLogin", userLoginId); 360 newContent.create(); 361 Debug.logVerbose("in cloneLayout, newContent:" + newContent, ""); 362 363 GenericValue newContentAssoc = delegator.makeValue("ContentAssoc", null); 364 newContentAssoc.set("contentId", newId); 365 newContentAssoc.set("contentIdTo", "TEMPLATE_MASTER"); 366 newContentAssoc.set("contentAssocTypeId", "SUB_CONTENT"); 367 newContentAssoc.set("fromDate", UtilDateTime.nowTimestamp()); 368 newContentAssoc.create(); 369 Debug.logVerbose("in cloneLayout, newContentAssoc:" + newContentAssoc, ""); 370 } catch(GenericEntityException e) { 371 request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); 372 return "error"; 373 } 374 Map serviceIn = new HashMap (); 375 Map results = null; 376 serviceIn.put("fromDate", UtilDateTime.nowTimestamp()); 377 serviceIn.put("contentId", contentId); 378 serviceIn.put("userLogin", session.getAttribute("userLogin")); 379 serviceIn.put("direction", "From"); 380 serviceIn.put("thruDate", null); 381 serviceIn.put("assocTypes", UtilMisc.toList("SUB_CONTENT")); 382 try { 383 results = dispatcher.runSync("getAssocAndContentAndDataResource", serviceIn); 384 entityList = (List )results.get("entityList"); 385 if (entityList == null || entityList.size() == 0) { 386 String errMsg = UtilProperties.getMessage(LayoutEvents.err_resource, "layoutEvents.no_subcontent", locale); 387 request.setAttribute("_ERROR_MESSAGE_", errMsg); 388 } 389 } catch(GenericServiceException e) { 390 request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); 391 return "error"; 392 } 393 394 serviceIn = new HashMap (); 395 serviceIn.put("userLogin", session.getAttribute("userLogin")); 396 397 Map beenThere = new HashMap (); 399 for (int i=0; i<entityList.size(); i++) { 400 GenericValue view = (GenericValue)entityList.get(i); 401 List errorMessages = new ArrayList (); 402 if (locale == null) 403 locale = Locale.getDefault(); 404 try { 405 SimpleMapProcessor.runSimpleMapProcessor( 406 "org/ofbiz/content/ContentManagementMapProcessors.xml", "contentAssocIn", 407 view, serviceIn, errorMessages, locale); 408 } catch(IllegalArgumentException e) { 409 request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); 410 return "error"; 411 } catch(MiniLangException e) { 412 request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); 413 return "error"; 414 } 415 String contentIdFrom = (String )view.get("contentId"); 416 String mapKey = (String )view.get("caMapKey"); 417 Timestamp fromDate = (Timestamp )view.get("caFromDate"); 418 Timestamp thruDate = (Timestamp )view.get("caThruDate"); 419 Debug.logVerbose("in cloneLayout, contentIdFrom:" + contentIdFrom 420 + " fromDate:" + fromDate 421 + " thruDate:" + thruDate 422 + " mapKey:" + mapKey 423 , ""); 424 if (beenThere.get(contentIdFrom) == null) { 425 serviceIn.put("contentIdFrom", contentIdFrom); 426 serviceIn.put("contentIdTo", newId); 427 serviceIn.put("fromDate", UtilDateTime.nowTimestamp()); 428 serviceIn.put("thruDate", null); 429 try { 430 results = dispatcher.runSync("persistContentAndAssoc", serviceIn); 431 } catch(GenericServiceException e) { 432 request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); 433 return "error"; 434 } 435 beenThere.put(contentIdFrom, view); 436 } 437 438 } 439 440 GenericValue view = delegator.makeValue("ContentDataResourceView", null); 441 view.set("contentId", newId); 442 view.set("drDataResourceId", newDataResourceId); 443 Debug.logVerbose("in cloneLayout, view:" + view, ""); 444 ContentManagementWorker.setCurrentEntityMap(request, view); 445 request.setAttribute("contentId", view.get("contentId")); 446 request.setAttribute("drDataResourceId", view.get("drDataResourceId")); 447 return "success"; 448 } 449 450 public static String createLayoutSubContent(HttpServletRequest request, HttpServletResponse response) { 451 452 453 try { 454 LocalDispatcher dispatcher = (LocalDispatcher)request.getAttribute("dispatcher"); 455 HttpSession session = request.getSession(); 456 Map paramMap = UtilHttp.getParameterMap(request); 457 String contentIdTo = (String )paramMap.get("contentIdTo"); 458 String mapKey = (String )paramMap.get("mapKey"); 459 if (Debug.verboseOn()) { 460 Debug.logVerbose("in createSubContent, contentIdTo:" + contentIdTo, module); 461 Debug.logVerbose("in createSubContent, mapKey:" + mapKey, module); 462 } 463 Map context = new HashMap (); 464 List errorMessages = null; 465 Locale loc = (Locale )request.getSession().getServletContext().getAttribute("locale"); 466 if (loc == null) 467 loc = Locale.getDefault(); 468 GenericValue userLogin = (GenericValue)session.getAttribute("userLogin"); 469 context.put("userLogin", userLogin); 470 471 String rootDir = request.getSession().getServletContext().getRealPath("/"); 472 context.put("rootDir", rootDir); 473 try { 474 SimpleMapProcessor.runSimpleMapProcessor( 475 "org/ofbiz/content/ContentManagementMapProcessors.xml", "contentIn", 476 paramMap, context, errorMessages, loc); 477 SimpleMapProcessor.runSimpleMapProcessor( 478 "org/ofbiz/content/ContentManagementMapProcessors.xml", "dataResourceIn", 479 paramMap, context, errorMessages, loc); 480 SimpleMapProcessor.runSimpleMapProcessor( 481 "org/ofbiz/content/ContentManagementMapProcessors.xml", "contentAssocIn", 482 paramMap, context, errorMessages, loc); 483 } catch(MiniLangException e) { 484 request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); 485 return "error"; 486 } 487 488 context.put("dataResourceName", context.get("contentName")); 489 String contentPurposeTypeId = (String )paramMap.get("contentPurposeTypeId"); 490 if (UtilValidate.isNotEmpty(contentPurposeTypeId)) 491 context.put("contentPurposeList", UtilMisc.toList(contentPurposeTypeId)); 492 context.put("contentIdTo", paramMap.get("contentIdTo")); 493 context.put("mapKey", paramMap.get("mapKey")); 494 context.put("textData", paramMap.get("textData")); 495 context.put("contentAssocTypeId", "SUB_CONTENT"); 496 if (Debug.verboseOn()) Debug.logVerbose("in createSubContent, context:" + context, module); 497 Map result = dispatcher.runSync("persistContentAndAssoc", context); 498 boolean isError = ModelService.RESPOND_ERROR.equals(result.get(ModelService.RESPONSE_MESSAGE)); 499 if (isError) { 500 request.setAttribute("_ERROR_MESSAGE_", result.get(ModelService.ERROR_MESSAGE)); 501 return "error"; 502 } 503 504 if (Debug.verboseOn()) Debug.logVerbose("in createLayoutFile, result:" + result, module); 505 String contentId = (String )result.get("contentId"); 506 String dataResourceId = (String )result.get("dataResourceId"); 507 request.setAttribute("contentId", contentId); 508 request.setAttribute("drDataResourceId", dataResourceId); 509 request.setAttribute("currentEntityName", "SubContentDataResourceId"); 510 Map context2 = new HashMap (); 511 context2.put("activeContentId", contentId); 512 context2.put("contentAssocTypeId", "SUB_CONTENT"); 514 context2.put("fromDate", result.get("fromDate")); 515 context2.put("contentIdTo", contentIdTo); 516 context2.put("mapKey", mapKey); 517 518 Map result2 = dispatcher.runSync("deactivateAssocs", context2); 520 } catch( GenericServiceException e) { 521 request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); 522 return "error"; 523 } 524 return "success"; 525 } 526 527 528 public static String updateLayoutSubContent(HttpServletRequest request, HttpServletResponse response) { 529 530 531 try { 532 LocalDispatcher dispatcher = (LocalDispatcher)request.getAttribute("dispatcher"); 533 HttpSession session = request.getSession(); 534 Map paramMap = UtilHttp.getParameterMap(request); 535 String contentIdTo = (String )paramMap.get("contentIdTo"); 536 String mapKey = (String )paramMap.get("mapKey"); 537 Map context = new HashMap (); 538 List errorMessages = null; 539 Locale loc = (Locale )request.getSession().getServletContext().getAttribute("locale"); 540 if (loc == null) 541 loc = Locale.getDefault(); 542 context.put("locale", loc); 543 GenericValue userLogin = (GenericValue)session.getAttribute("userLogin"); 544 context.put("userLogin", userLogin); 545 546 String rootDir = request.getSession().getServletContext().getRealPath("/"); 547 context.put("rootDir", rootDir); 548 try { 549 SimpleMapProcessor.runSimpleMapProcessor( 550 "org/ofbiz/content/ContentManagementMapProcessors.xml", "contentIn", 551 paramMap, context, errorMessages, loc); 552 SimpleMapProcessor.runSimpleMapProcessor( 553 "org/ofbiz/content/ContentManagementMapProcessors.xml", "dataResourceIn", 554 paramMap, context, errorMessages, loc); 555 SimpleMapProcessor.runSimpleMapProcessor( 556 "org/ofbiz/content/ContentManagementMapProcessors.xml", "contentAssocIn", 557 paramMap, context, errorMessages, loc); 558 } catch(MiniLangException e) { 559 request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); 560 return "error"; 561 } 562 563 564 context.put("dataResourceName", context.get("contentName")); 565 String contentPurposeTypeId = (String )paramMap.get("contentPurposeTypeId"); 566 if (UtilValidate.isNotEmpty(contentPurposeTypeId)) 567 context.put("contentPurposeList", UtilMisc.toList(contentPurposeTypeId)); 568 context.put("contentIdTo", paramMap.get("contentIdTo")); 569 context.put("textData", paramMap.get("textData")); 570 context.put("contentAssocTypeId", null); 571 Map result = dispatcher.runSync("persistContentAndAssoc", context); 572 boolean isError = ModelService.RESPOND_ERROR.equals(result.get(ModelService.RESPONSE_MESSAGE)); 573 if (isError) { 574 request.setAttribute("_ERROR_MESSAGE_", result.get(ModelService.ERROR_MESSAGE)); 575 return "error"; 576 } 577 String contentId = (String )result.get("contentId"); 578 String dataResourceId = (String )result.get("dataResourceId"); 579 request.setAttribute("contentId", contentId); 580 request.setAttribute("drDataResourceId", dataResourceId); 581 request.setAttribute("currentEntityName", "SubContentDataResourceId"); 582 594 } catch( GenericServiceException e) { 595 request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); 596 return "error"; 597 } 598 return "success"; 599 } 600 601 public static String copyToClip(HttpServletRequest request, HttpServletResponse response) { 602 GenericDelegator delegator = (GenericDelegator)request.getAttribute("delegator"); 603 Map paramMap = UtilHttp.getParameterMap(request); 604 String entityName = (String )paramMap.get("entityName"); 605 Locale locale = UtilHttp.getLocale(request); 606 607 if (UtilValidate.isEmpty(entityName) ) { 608 String errMsg = UtilProperties.getMessage(LayoutEvents.err_resource, "layoutEvents.entityname_empty", locale); 609 request.setAttribute("_ERROR_MESSAGE_", errMsg); 610 return "error"; 611 } 612 GenericValue v = delegator.makeValue(entityName, null); 613 GenericPK passedPK = v.getPrimaryKey(); 614 Collection keyColl = passedPK.getAllKeys(); 615 Iterator keyIt = keyColl.iterator(); 616 while (keyIt.hasNext()) { 617 String attrName = (String )keyIt.next(); 618 String attrVal = (String )request.getAttribute(attrName); 619 if (attrVal == null) { 620 attrVal = (String )paramMap.get(attrName); 621 } 622 Debug.logVerbose("in copyToClip, attrName:" + attrName,""); 623 Debug.logVerbose("in copyToClip, attrVal:" + attrVal,""); 624 if (UtilValidate.isNotEmpty(attrVal)) { 625 passedPK.put(attrName,attrVal); 626 } else { 627 String errMsg = UtilProperties.getMessage(LayoutEvents.err_resource, "layoutEvents.empty", locale); 628 request.setAttribute("_ERROR_MESSAGE_", attrName + " " + errMsg); 629 return "error"; 630 } 631 } 632 ContentManagementWorker.mruAdd(request, passedPK); 633 634 return "success"; 635 } 636 } 637 | Popular Tags |