1 15 21 package org.jahia.engines.updatecontainer; 22 23 import java.util.ArrayList ; 24 import java.util.Collections ; 25 import java.util.Enumeration ; 26 import java.util.HashMap ; 27 import java.util.HashSet ; 28 import java.util.Hashtable ; 29 import java.util.Iterator ; 30 import java.util.Locale ; 31 import java.util.Properties ; 32 import java.util.Set ; 33 import java.util.Vector ; 34 35 import javax.servlet.http.HttpSession ; 36 37 import org.jahia.bin.Jahia; 38 import org.jahia.content.ContentContainerKey; 39 import org.jahia.content.ContentContainerListsXRefManager; 40 import org.jahia.data.JahiaData; 41 import org.jahia.data.containers.ContainerEditView; 42 import org.jahia.data.containers.ContainerEditViewFieldGroup; 43 import org.jahia.data.containers.JahiaContainer; 44 import org.jahia.data.containers.JahiaContainerList; 45 import org.jahia.data.containers.JahiaContentContainerFacade; 46 import org.jahia.data.events.JahiaEvent; 47 import org.jahia.data.fields.JahiaContentFieldFacade; 48 import org.jahia.data.fields.JahiaField; 49 import org.jahia.data.fields.LoadFlags; 50 import org.jahia.engines.EngineToolBox; 51 import org.jahia.engines.JahiaEngine; 52 import org.jahia.engines.addcontainer.AddContainer_Engine; 53 import org.jahia.engines.categories.ManageCategories; 54 import org.jahia.engines.lock.LockEngine; 55 import org.jahia.engines.rights.ManageRights; 56 import org.jahia.engines.validation.EngineValidationHelper; 57 import org.jahia.engines.validation.ValidationError; 58 import org.jahia.engines.validation.ValidationErrorSorter; 59 import org.jahia.exceptions.JahiaException; 60 import org.jahia.exceptions.JahiaForbiddenAccessException; 61 import org.jahia.exceptions.JahiaSessionExpirationException; 62 import org.jahia.exceptions.JahiaUpdateLockException; 63 import org.jahia.params.ParamBean; 64 import org.jahia.registries.ServicesRegistry; 65 import org.jahia.services.audit.LoggingEventListener; 66 import org.jahia.services.cache.CacheFactory; 67 import org.jahia.services.cache.HtmlCache; 68 import org.jahia.services.containers.ContentContainer; 69 import org.jahia.services.fields.ContentField; 70 import org.jahia.services.lock.LockKey; 71 import org.jahia.services.lock.LockService; 72 import org.jahia.services.usermanager.JahiaUser; 73 import org.jahia.services.version.EntryLoadRequest; 74 import org.jahia.utils.LanguageCodeConverters; 75 76 83 public class UpdateContainer_Engine implements JahiaEngine { 84 85 86 private static final org.apache.log4j.Logger logger = 87 org.apache.log4j.Logger.getLogger (UpdateContainer_Engine.class); 88 89 90 private static UpdateContainer_Engine instance = null; 91 92 private static final String TEMPLATE_JSP = "update_container"; 93 94 public static final String ENGINE_NAME = "updatecontainer"; 95 private EngineToolBox toolBox; 96 97 100 private UpdateContainer_Engine () { 101 logger.debug ("***** Starting " + UpdateContainer_Engine.class.getName () + " engine *****"); 102 toolBox = EngineToolBox.getInstance (); 103 } 104 105 110 public static UpdateContainer_Engine getInstance () { 111 if (instance == null) { 112 instance = new UpdateContainer_Engine (); 113 } 114 return instance; 115 } 116 117 120 public boolean authoriseRender (ParamBean jParams) { 121 return toolBox.authoriseRender (jParams); 122 } 124 127 public String renderLink (ParamBean jParams, Object theObj) 128 throws JahiaException { 129 ContentContainer contentContainer = (ContentContainer) theObj; 130 String params = "?mode=display&cid=" + contentContainer.getID (); 131 String useOriginPage = jParams.getParameter("use_container_origin_page"); 132 if (useOriginPage != null && (new Boolean (useOriginPage)).booleanValue()){ 133 Properties extraParams = new Properties (); 134 extraParams.put(ParamBean.PAGE_ID_PARAMETER, Integer.toString(contentContainer.getPageID())); 135 return jParams.composeEngineUrl (ENGINE_NAME, extraParams, params); 136 }else{ 137 return jParams.composeEngineUrl (ENGINE_NAME, params); 138 } 139 } 141 144 public boolean needsJahiaData (ParamBean jParams) { 145 return false; 146 } 148 154 public void handleActions (ParamBean jParams, JahiaData jData) 155 throws JahiaException, 156 JahiaUpdateLockException, 157 JahiaForbiddenAccessException { 158 HashMap engineMap = initEngineMap (jParams); 160 161 engineMap.put("org.jahia.engines.fieldEdit.flagStayOnSameField",Boolean.FALSE); 163 164 String theScreen = (String ) engineMap.get ("screen"); 166 167 JahiaContainer theContainer = (JahiaContainer) engineMap.get ( 169 "theContainer"); 170 JahiaUser theUser = jParams.getUser (); 171 172 if (theContainer.checkAdminAccess (theUser)) { 175 engineMap.put ("adminAccess", Boolean.TRUE); 176 engineMap.put ("enableRightView", Boolean.TRUE); 177 engineMap.put ("writeAccess", Boolean.TRUE); 178 179 } else if (theContainer.checkWriteAccess (theUser)) { 180 engineMap.put ("writeAccess", Boolean.TRUE); 181 } 182 183 if (engineMap.get ("writeAccess") != null) { 184 LockService lockRegistry = ServicesRegistry.getInstance (). 186 getLockService (); 187 if (jParams.settings ().areLocksActivated ()) { 188 LockKey lockKey = LockKey.composeLockKey (LockKey. 189 UPDATE_CONTAINER_TYPE, 190 theContainer.getID (), theContainer.getPageID ()); 191 if (lockRegistry.acquire (lockKey, jParams.getUser (), 192 jParams.getSessionID (), 193 jParams.getSession (). 194 getMaxInactiveInterval ())) { 195 flushPageCacheThatDisplayContainer (jParams, theContainer); 197 198 JahiaEvent theEvent = new JahiaEvent (this, jParams, 200 theContainer); 201 ServicesRegistry.getInstance ().getJahiaEventService () 202 .fireUpdateContainerEngineAfterInit (theEvent); 203 205 if (!theScreen.equals ("cancel")) { 206 processLastScreen (jParams, engineMap); 207 } 208 processCurrentScreen (jParams, engineMap); 209 } else { 211 LockEngine.getInstance ().redirect (jParams, engineMap,lockKey); 214 return; } 216 } 217 } else { 219 throw new JahiaForbiddenAccessException (); 220 } 221 222 toolBox.displayScreen (jParams, engineMap); 224 225 } 226 227 228 233 public final String getName () { 234 return ENGINE_NAME; 235 } 236 237 242 public void processLastScreen (ParamBean jParams, HashMap engineMap) 243 throws JahiaException, JahiaUpdateLockException, 244 JahiaForbiddenAccessException { 245 247 String lastScreen = jParams.getRequest ().getParameter ("lastscreen"); 250 if (lastScreen == null) { 251 lastScreen = EMPTY_STRING; 253 } 254 int mode = JahiaEngine.UPDATE_MODE; 256 257 String lastFieldIDStr = jParams.getRequest ().getParameter ("lastfid"); 258 259 JahiaContentContainerFacade jahiaContentContainerFacade 260 = (JahiaContentContainerFacade) engineMap.get ( 261 "UpdateContainer_Engine.JahiaContentContainerFacade"); 262 263 if (lastScreen.equals ("edit")) { 264 265 int lastFieldID = -1; 266 try { 267 lastFieldID = Integer.parseInt (lastFieldIDStr); 268 } catch (NumberFormatException nfe) { 269 return; 270 } 271 272 Boolean flagStayOnSameField = (Boolean ) 273 engineMap.get("org.jahia.engines.fieldEdit.flagStayOnSameField"); 274 275 AddContainer_Engine.processLastFields (lastFieldID, jParams, 276 engineMap, mode, lastScreen, 277 this.toolBox, 278 (flagStayOnSameField != null && flagStayOnSameField.booleanValue()) ); 279 280 } else if (lastScreen.equals ("versioning")) { 281 288 } else if (lastScreen.equals ("rightsMgmt")) { 289 if (engineMap.get ("adminAccess") != null) { 290 ManageRights.getInstance ().handleActions (jParams, mode, 291 engineMap, jahiaContentContainerFacade.getAclID ()); 292 } else { 293 throw new JahiaForbiddenAccessException (); 294 } 295 } else if (lastScreen.equals ("categories")) { 296 JahiaContainer theContainer = (JahiaContainer) engineMap.get ( 297 "theContainer"); 298 ManageCategories.getInstance ().handleActions (jParams, mode, 299 engineMap, 300 new ContentContainerKey (jahiaContentContainerFacade.getContainerID ()), 301 theContainer.getDefinition (), false); 302 } 303 } 305 310 public EngineValidationHelper processCurrentScreen (ParamBean jParams, HashMap engineMap) 311 throws JahiaException, 312 JahiaUpdateLockException, 313 JahiaForbiddenAccessException { 314 316 JahiaContentContainerFacade jahiaContentContainerFacade 317 = (JahiaContentContainerFacade) engineMap.get ( 318 "UpdateContainer_Engine.JahiaContentContainerFacade"); 319 320 EntryLoadRequest entryLoadRequest 321 = (EntryLoadRequest) engineMap.get ("entryLoadRequest"); 322 323 HashSet updatedLanguageEntries = (HashSet ) engineMap.get ( 324 "updatedLanguageEntries"); 325 HashSet updatedFields = (HashSet ) engineMap.get ("updated.fields"); 326 327 JahiaField theField = null; 328 JahiaContainer theContainer = jahiaContentContainerFacade.getContainer ( 329 entryLoadRequest, true); 330 engineMap.put ("theContainer", theContainer); 331 332 String theScreen = (String ) engineMap.get ("screen"); 335 336 int mode = JahiaEngine.LOAD_MODE; 338 339 Boolean flagStayOnSameField = (Boolean ) 340 engineMap.get("org.jahia.engines.fieldEdit.flagStayOnSameField"); 341 342 String fieldIDStr; 343 if (flagStayOnSameField != null && flagStayOnSameField.booleanValue()) { 344 fieldIDStr = jParams.getRequest ().getParameter ("lastfid"); 345 } else { 346 fieldIDStr = jParams.getRequest ().getParameter ("fid"); 347 } 348 int fieldID = -1; 349 350 try { 351 fieldID = Integer.parseInt (fieldIDStr); 352 } catch (NumberFormatException nfe) { 353 try { 354 fieldID = (((Integer ) engineMap.get ("field_id"))).intValue (); 355 } catch (Throwable t) { 356 fieldID = -1; 357 } 358 } 359 360 ContainerEditView editView = (ContainerEditView) engineMap.get ( 361 "ctnEditView"); 362 ContainerEditViewFieldGroup fieldGroup = null; 363 364 if (fieldID == -1) { 365 String fieldName = (String ) editView.getFields ().get (0); 367 theField = theContainer.getField (fieldName); 368 if (theField != null) { 369 fieldID = theField.getID (); 370 } 371 } else { 372 theField = theContainer.getField (fieldID); 373 } 374 if (theField != null) { 375 fieldGroup = editView.getFieldGroupByFieldName (theField. 376 getDefinition ().getName ()); 377 } 378 if (fieldGroup == null) { 379 Vector views = new Vector (editView.getViews ().values ()); 380 if (views.size () > 0) { 381 fieldGroup = (ContainerEditViewFieldGroup) views.get (0); 382 theField = theContainer.getField ((String ) fieldGroup. 383 getFieldNames ().get (0)); 384 fieldID = theField.getID (); 385 } else { 386 theField = null; 388 fieldID = 0; 389 } 390 } 391 392 engineMap.put ("field_id", new Integer (fieldID)); 393 394 LockKey lockKey = LockKey.composeLockKey (LockKey.UPDATE_CONTAINER_TYPE, 396 theContainer.getID (), 397 theContainer.getPageID ()); 398 LockService lockRegistry = ServicesRegistry.getInstance (). 399 getLockService (); 400 402 if (theScreen.equals ("edit")) { 403 AddContainer_Engine.processCurrentFields (fieldID, jParams, 404 engineMap, mode, theScreen, this.toolBox); 405 406 } else if (theScreen.equals ("versioning")) { 407 413 } else if (theScreen.equals ("logs")) { 414 toolBox.loadLogData (jParams, LoggingEventListener.CONTAINER_TYPE, 415 engineMap); 416 } else if (theScreen.equals ("rightsMgmt")) { 417 if (engineMap.get ("adminAccess") != null) { 418 ManageRights.getInstance ().handleActions (jParams, mode, 419 engineMap, theContainer.getAclID ()); 420 } else { 421 throw new JahiaForbiddenAccessException (); 422 } 423 } else if (theScreen.equals ("categories")) { 424 ManageCategories.getInstance ().handleActions (jParams, mode, 425 engineMap, 426 new ContentContainerKey (jahiaContentContainerFacade.getContainerID ()), 427 theContainer.getDefinition (), false); 428 } else if (theScreen.equals ("save") || theScreen.equals ("apply")) { 429 430 if (jParams.settings ().areLocksActivated () && 433 lockRegistry.isStealedInContext (lockKey, jParams.getUser (), 434 jParams.getSessionID ())) { 435 engineMap.put ("screen", 436 jParams.getRequest ().getParameter ("lastscreen")); 437 engineMap.put ("jspSource", "apply"); 438 return null; 439 } 440 442 logger.debug( 443 "processCurrentScreen > we are in validate Mode"); 444 mode = JahiaEngine.VALIDATE_MODE; 447 448 final EngineValidationHelper evh = 449 AddContainer_Engine.validate( 450 UpdateContainer_Engine.ENGINE_NAME, 451 jahiaContentContainerFacade, 452 jParams, 453 engineMap); 454 455 engineMap.put(JahiaEngine.ENGINE_VALIDATION_HELPER, evh); 456 final JahiaEvent validationEvent = new JahiaEvent (this, jParams, theContainer); 457 ServicesRegistry.getInstance ().getJahiaEventService () 458 .fireContainerValidation(validationEvent); 459 460 if (evh != null && evh.hasErrors()) { 461 462 final ContainerEditViewFieldGroup currentFieldGroup = 463 AddContainer_Engine.getFieldGroup( 464 fieldID, 465 theContainer, 466 (ContainerEditView)engineMap.get( 467 "ctnEditView")); 468 469 Collections.sort( 470 evh.getErrors(), 471 new ValidationErrorSorter(currentFieldGroup)); 472 473 final ValidationError ve = 474 (ValidationError)evh.getErrors().get(0); 475 final JahiaField field = (JahiaField)ve.getSource(); 476 477 AddContainer_Engine.processCurrentFields( 478 field.getID(), 479 jParams, 480 engineMap, 481 JahiaEngine.LOAD_MODE, 482 "edit", 483 this.toolBox); 484 485 engineMap.put( 487 JahiaEngine.ENGINE_VALIDATION_HELPER, 488 evh); 489 engineMap.put("screen", "edit"); 490 engineMap.put("jspSource", TEMPLATE_JSP); 491 return evh; 492 } 493 engineMap.remove(JahiaEngine.ENGINE_VALIDATION_HELPER); 494 495 mode = JahiaEngine.SAVE_MODE; 496 497 JahiaEvent theEvent = new JahiaEvent (this, jParams, theContainer); 499 ServicesRegistry.getInstance ().getJahiaEventService () 500 .fireUpdateContainerEngineBeforeSave (theEvent); 501 503 505 EntryLoadRequest loadVersion = EntryLoadRequest.CURRENT; 506 if (ServicesRegistry.getInstance ().getJahiaVersionService (). 507 isStagingEnabled (theContainer.getJahiaID ())) 508 loadVersion = EntryLoadRequest.STAGED; 509 510 JahiaContainerList theList = ServicesRegistry.getInstance (). 511 getJahiaContainersService (). 512 loadContainerListInfo (theContainer. 513 getListID (), loadVersion); 514 ServicesRegistry.getInstance ().getJahiaContainersService (). 518 saveContainerInfo (theContainer, theList.getParentEntryID (), 0, 519 jParams); 520 521 Enumeration enumeration = jahiaContentContainerFacade.getFields (); 522 while (enumeration.hasMoreElements ()) { 523 JahiaContentFieldFacade contentFieldFacade = ( 524 JahiaContentFieldFacade) enumeration.nextElement (); 525 Enumeration fields = contentFieldFacade.getFields (); 526 EntryLoadRequest processingEntryLoadRequest = null; 527 while (fields.hasMoreElements ()) { 528 JahiaField field = (JahiaField) fields.nextElement (); 529 if (field.hasChanged () && 530 (field.getLanguageCode ().equals (ContentField. 531 SHARED_LANGUAGE) 532 || 533 updatedLanguageEntries.contains (field.getLanguageCode ())) 534 || updatedFields.contains (new Integer (field.getID ()))) { 535 boolean processField = true; 537 processingEntryLoadRequest = 538 new EntryLoadRequest (field.getWorkflowState (), 539 field.getVersionID (), 540 new ArrayList ()); 541 processingEntryLoadRequest.getLocales () 542 .add (LanguageCodeConverters.languageCodeToLocale ( 543 field.getLanguageCode ())); 544 if (field.getWorkflowState () == 545 EntryLoadRequest.ACTIVE_WORKFLOW_STATE) { 546 ArrayList entryLocales = new ArrayList (); 547 entryLocales.add (LanguageCodeConverters 548 .languageCodeToLocale (field. 549 getLanguageCode ())); 550 EntryLoadRequest stagingLoadRequest = 551 new EntryLoadRequest (EntryLoadRequest. 552 STAGING_WORKFLOW_STATE, 553 0, entryLocales); 554 555 processField = (contentFieldFacade.getField ( 556 stagingLoadRequest, false) == null); 557 if (processField) { 558 processingEntryLoadRequest = stagingLoadRequest; 559 } 560 } 561 if (processField) { 562 engineMap.put ("theField", field); 563 jParams.setSubstituteEntryLoadRequest ( 564 processingEntryLoadRequest); 565 toolBox.processFieldTypes (jParams, mode, engineMap); 566 jParams.resetSubstituteEntryLoadRequest (); 567 } 568 } 569 } 570 } 571 572 if (engineMap.get ("adminAccess") != null) { 574 engineMap.put ("logObjectType", 575 Integer.toString (LoggingEventListener. 576 CONTAINER_TYPE)); 577 engineMap.put ("logObject", theContainer); 578 ManageRights.getInstance ().handleActions (jParams, mode, 580 engineMap, theContainer.getAclID ()); 581 } 582 583 ManageCategories.getInstance ().handleActions (jParams, mode, 585 engineMap, 586 new ContentContainerKey (jahiaContentContainerFacade. 587 getContainerID ()), 588 theContainer.getDefinition (), false); 589 590 flushPageCacheThatDisplayContainer (jParams, theContainer); 591 592 theEvent = new JahiaEvent (this, jParams, theContainer); 594 ServicesRegistry.getInstance ().getJahiaEventService (). 595 fireUpdateContainer (theEvent); 596 jParams.getSession ().setAttribute ("UpdateContainer", "false"); 598 if (theScreen.equals ("apply")) { 599 engineMap.put ("prevScreenIsApply", new Boolean (true)); 600 String lastScreen = jParams.getRequest ().getParameter ( 601 "lastscreen"); 602 engineMap.put ("screen", lastScreen); 603 } 604 else { 606 if (jParams.settings ().areLocksActivated ()) { 607 lockRegistry.release (lockKey, jParams.getUser (), 608 jParams.getSessionID ()); 609 } 610 } 611 logger.debug ("Changes applied and saved !"); 613 } else if (theScreen.equals ("cancel")) { 614 if (jParams.settings ().areLocksActivated ()) { 616 lockRegistry.release (lockKey, jParams.getUser (), 617 jParams.getSessionID ()); 618 flushPageCacheThatDisplayContainer (jParams, theContainer); 619 } 620 jParams.getSession ().setAttribute ("UpdateContainer", "false"); 623 624 } 625 return null; 626 } 628 private void flushPageCacheThatDisplayContainer (ParamBean jParams, 629 JahiaContainer theContainer) 630 throws JahiaException { 631 632 EntryLoadRequest loadVersion = EntryLoadRequest.CURRENT; 633 if (ServicesRegistry.getInstance ().getJahiaVersionService (). 634 isStagingEnabled (theContainer.getJahiaID ())) 635 loadVersion = EntryLoadRequest.STAGED; 636 637 JahiaContainerList theList = ServicesRegistry.getInstance (). 638 getJahiaContainersService (). 639 loadContainerListInfo (theContainer. 640 getListID (), loadVersion); 641 Set containerPageRefs = ContentContainerListsXRefManager. 645 getInstance (). 646 getAbsoluteContainerListPageIDs (theList. 647 getID ()); 648 649 HtmlCache htmlCache = CacheFactory.getHtmlCache (); 651 if (htmlCache == null) 652 logger.warn ("Could not get the HTML cache instance!!"); 653 654 if (containerPageRefs != null) { 655 Iterator pageRefIDs = containerPageRefs.iterator (); 656 while (pageRefIDs.hasNext ()) { 657 Integer curPageID = (Integer ) pageRefIDs.next (); 658 if (htmlCache != null) 659 htmlCache.invalidatePageEntries (curPageID.toString (),jParams.getEntryLoadRequest().getWorkflowState()); 660 } 661 } else { 662 logger.debug ("Why is cross ref list empty ?"); 663 } 664 if (htmlCache != null) 667 htmlCache.invalidatePageEntries (Integer.toString (jParams.getPageID ()), 668 jParams.getEntryLoadRequest().getWorkflowState()); 669 } 670 671 678 private HashMap initEngineMap (ParamBean jParams) 679 throws JahiaException, 680 JahiaSessionExpirationException { 681 HashMap engineMap = new HashMap (); 682 683 logger.debug ("Start initEngineMap"); 684 685 jParams.getSession ().setAttribute ("UpdateContainer", "true"); 687 688 JahiaContainer theContainer = null; 689 String theScreen = jParams.getRequest ().getParameter ("screen"); 690 String ctnidStr = jParams.getRequest ().getParameter ("cid"); 691 int ctnid = 0; 692 693 try { 694 ctnid = Integer.parseInt (ctnidStr); 695 } catch (NumberFormatException nfe) { 696 String errorMsg = "Error in parameters : cid (" + ctnidStr + 697 ") cannot be converted in int"; 698 throw new JahiaException ("Error in parameters", errorMsg, 699 JahiaException.DATA_ERROR, 700 JahiaException.CRITICAL_SEVERITY); 701 } 702 703 HttpSession theSession = jParams.getSession (); 706 engineMap = (HashMap ) theSession.getAttribute ("jahia_session_engineMap"); 707 Integer selectedFieldID = null; 708 boolean prevScreenIsApply = false; 709 710 if (engineMap != null && theScreen != null) { 711 Boolean prevScreenIsApplyBool = (Boolean ) engineMap.get ( 712 "prevScreenIsApply"); 713 prevScreenIsApply = (prevScreenIsApplyBool != null && 714 prevScreenIsApplyBool.booleanValue ()); 715 selectedFieldID = (Integer ) engineMap.get ("field_id"); 716 } 717 718 String languageCode = jParams.getRequest ().getParameter ("engine_lang"); 720 if (prevScreenIsApply) { 721 languageCode = (String ) engineMap.get ("languageCode"); 722 } 723 if (languageCode == null) { 724 Locale navLocale = (Locale ) theSession.getAttribute (ParamBean. 725 SESSION_LOCALE); 726 languageCode = navLocale.toString (); 727 } 728 if (languageCode == null) { 729 languageCode = jParams.settings ().getDefaultLanguageCode (); 730 } 731 String prevLanguageCode = jParams.getRequest ().getParameter ( 732 "prev_engine_lang"); 733 if (prevLanguageCode == null) { 734 prevLanguageCode = languageCode; 735 } 736 737 ArrayList locales = new ArrayList (); 738 locales.add (LanguageCodeConverters.languageCodeToLocale (languageCode)); 739 EntryLoadRequest entryLoadRequest = 740 new EntryLoadRequest (EntryLoadRequest.STAGING_WORKFLOW_STATE, 741 0, 742 locales); 743 744 ArrayList prevLocales = new ArrayList (); 745 prevLocales.add (LanguageCodeConverters.languageCodeToLocale ( 746 prevLanguageCode)); 747 EntryLoadRequest prevEntryLoadRequest = 748 new EntryLoadRequest (EntryLoadRequest.STAGING_WORKFLOW_STATE, 749 0, 750 prevLocales); 751 752 JahiaContentContainerFacade jahiaContentContainerFacade = null; 753 754 if (theScreen != null) { 755 756 logger.debug ("The Screen is not null, load it from session"); 757 758 engineMap = (HashMap ) theSession.getAttribute ( 760 "jahia_session_engineMap"); 761 762 if (engineMap == null) { 770 throw new JahiaSessionExpirationException (); 771 } 772 773 jahiaContentContainerFacade = (JahiaContentContainerFacade) 774 engineMap.get ( 775 "UpdateContainer_Engine.JahiaContentContainerFacade"); 776 777 if (prevScreenIsApply && theScreen.equals ("edit")) { 778 ArrayList localeList = jParams.getSite (). 780 getLanguageSettingsAsLocales (false); 781 782 jahiaContentContainerFacade 783 = new JahiaContentContainerFacade (ctnid, 784 LoadFlags.ALL, 785 jParams, 786 localeList, 787 true); 788 789 engineMap.put ( 790 "UpdateContainer_Engine.JahiaContentContainerFacade", 791 jahiaContentContainerFacade); 792 793 engineMap.remove ("updatedLanguageEntries"); 795 engineMap.remove ("updatedLanguageEntries"); 796 engineMap.remove ("updated.fields"); 797 engineMap.remove ("prevScreenIsApply"); 798 799 org.jahia.engines.shared.Page_Field.resetPageBeanSession ( 800 jParams); 801 802 } 803 804 } else { 805 806 logger.debug ("the Screen is null load from storage"); 807 808 engineMap = new HashMap (); 810 811 818 819 org.jahia.engines.shared.Page_Field.resetPageBeanSession (jParams); 821 822 ArrayList localeList = jParams.getSite (). 824 getLanguageSettingsAsLocales (false); 825 826 jahiaContentContainerFacade 827 = new JahiaContentContainerFacade (ctnid, 828 LoadFlags.ALL, 829 jParams, 830 localeList, 831 true); 832 833 engineMap.put ("UpdateContainer_Engine.JahiaContentContainerFacade", 834 jahiaContentContainerFacade); 835 836 if (theScreen == null || theScreen.equals (EMPTY_STRING)) { 837 theScreen = "edit"; 838 } 839 840 if (selectedFieldID != null) { 842 engineMap.put ("field_id", selectedFieldID); 843 } 844 845 Enumeration enumeration = jahiaContentContainerFacade.getContainers (); 848 while (enumeration.hasMoreElements ()) { 849 theContainer = (JahiaContainer) enumeration.nextElement (); 850 if (theContainer.getWorkflowState () > 851 EntryLoadRequest.ACTIVE_WORKFLOW_STATE) { 852 break; 853 } 854 } 855 HashMap ctnListFieldAcls = AddContainer_Engine. 856 getCtnListFieldAclMap (theContainer, 857 jParams); 858 engineMap.put ("ctnListFieldAcls", ctnListFieldAcls); 859 Set visibleFields = AddContainer_Engine.getCtnListVisibleFields ( 860 theContainer, jParams.getUser (), ctnListFieldAcls); 861 862 ContainerEditView editView = AddContainer_Engine. 864 customizeContainerEditView ( 865 theContainer, jParams, visibleFields); 866 if (editView == null) { 867 editView = AddContainer_Engine.buildContainerEditView ( 869 theContainer, jParams, visibleFields); 870 } 871 engineMap.put ("ctnEditView", editView); 872 } 873 874 engineMap.put ("entryLoadRequest", entryLoadRequest); 875 876 engineMap.put ("prevEntryLoadRequest", prevEntryLoadRequest); 877 878 engineMap.put ("languageCode", languageCode); 879 engineMap.put ("prevLanguageCode", prevLanguageCode); 880 881 HashSet updatedLanguageEntries = (HashSet ) engineMap.get ( 883 "updatedLanguageEntries"); 884 if (updatedLanguageEntries == null) { 885 updatedLanguageEntries = new HashSet (); 886 } 887 if (!updatedLanguageEntries.contains (languageCode)) { 888 updatedLanguageEntries.add (languageCode); 889 } 890 engineMap.put ("updatedLanguageEntries", updatedLanguageEntries); 891 892 HashSet updatedFields = (HashSet ) engineMap.get ("updated.fields"); 894 if (updatedFields == null) { 895 updatedFields = new HashSet (); 896 } 897 engineMap.put ("updated.fields", updatedFields); 898 899 theContainer = jahiaContentContainerFacade.getContainer ( 900 entryLoadRequest, true); 901 engineMap.put ("theContainer", theContainer); 902 903 engineMap.put (RENDER_TYPE_PARAM, new Integer (JahiaEngine.RENDERTYPE_FORWARD)); 904 engineMap.put (ENGINE_NAME_PARAM, ENGINE_NAME); 905 engineMap.put (ENGINE_URL_PARAM, 906 jParams.composeEngineUrl (ENGINE_NAME, 907 "?cid=" + theContainer.getID ())); 908 theSession.setAttribute ("jahia_session_engineMap", engineMap); 909 910 engineMap.put ("screen", theScreen); 912 913 if (theScreen.equals ("save")) { 914 engineMap.put ("jspSource", "close"); 915 916 } else if (theScreen.equals ("apply")) { 917 engineMap.put ("jspSource", "apply"); 918 919 } else if (theScreen.equals ("cancel")) { 920 engineMap.put ("jspSource", "close"); 921 922 } else { 923 engineMap.put ("jspSource", TEMPLATE_JSP); 924 } 925 926 engineMap.put ("enableCategories", new Boolean (true)); 927 928 engineMap.put ("fieldForms", new Hashtable ()); 930 jParams.getRequest ().setAttribute ("engineTitle", "Update Container"); 931 jParams.getRequest ().setAttribute ("org.jahia.engines.EngineHashMap", 932 engineMap); 933 934 return engineMap; 935 } 936 937 } 938 | Popular Tags |