1 package org.jahia.data.containers; 17 18 import java.util.ArrayList ; 19 import java.util.Collection ; 20 import java.util.Enumeration ; 21 import java.util.HashSet ; 22 import java.util.Hashtable ; 23 import java.util.Iterator ; 24 import java.util.Map ; 25 import java.util.Properties ; 26 import java.util.Set ; 27 import java.util.SortedSet ; 28 import java.util.Vector ; 29 30 import org.apache.log4j.Logger; 31 import org.jahia.data.JahiaData; 32 import org.jahia.data.fields.JahiaFieldDefinition; 33 import org.jahia.data.fields.JahiaFieldSubDefinition; 34 import org.jahia.data.fields.LoadFlags; 35 import org.jahia.exceptions.JahiaException; 36 import org.jahia.params.ParamBean; 37 import org.jahia.registries.JahiaContainerDefinitionsRegistry; 38 import org.jahia.registries.JahiaFieldDefinitionsRegistry; 39 import org.jahia.registries.ServicesRegistry; 40 import org.jahia.services.containers.ContainerFactory; 41 import org.jahia.services.containers.JahiaContainerUtilsDB; 42 import org.jahia.services.pages.ContentPage; 43 import org.jahia.services.version.EntryLoadRequest; 44 45 public class JahiaContainerSet implements Map { 46 47 55 public static final String SHARED_CONTAINER = "@@@SHARED_CONTAINER@@@"; 56 57 private static Logger logger = Logger.getLogger(JahiaContainerSet.class); 58 59 private JahiaData jData; 60 61 private JahiaContainerUtilsDB c_utils; 62 63 66 private Map containerLists; 67 68 71 private Set declaredContainers; 73 77 private Hashtable declaredFields; 78 79 82 private Hashtable declaredFieldDefProps; 83 84 90 private Set absoluteContainerListAccesses = new HashSet (); 91 92 95 private Hashtable cachedFieldsFromContainers; 96 97 100 private Hashtable cachedContainersFromContainerLists; 101 102 105 private Hashtable cachedContainerListsFromContainers; 106 107 115 public JahiaContainerSet(JahiaData jahiaData) { 116 this.jData = jahiaData; 117 this.containerLists = new Hashtable (); 118 this.declaredContainers = new HashSet (); 119 this.declaredFields = new Hashtable (); 120 this.declaredFieldDefProps = new Hashtable (); 121 this.cachedFieldsFromContainers = new Hashtable (); 122 this.cachedContainersFromContainerLists = new Hashtable (); 123 this.c_utils = JahiaContainerUtilsDB.getInstance(); 124 ParamBean params = jahiaData.params(); 125 126 try { 127 this.cachedFieldsFromContainers = c_utils 128 .db_load_all_fields_from_container_from_page(params.getPageID()); 129 if (params.settings().isPreloadHomepageFieldsActivated() 130 && params.getPageID() != params.getSite().getHomePageID()) { 131 this.cachedFieldsFromContainers.putAll(c_utils 132 .db_load_all_fields_from_container_from_page(params 133 .getSite().getHomePageID())); 134 } 135 } catch (Throwable t) { 136 this.cachedFieldsFromContainers = new Hashtable (); 137 logger.warn("cannot load all fields from container from page", t); 138 } 139 try { 140 this.cachedContainersFromContainerLists = c_utils 141 .db_load_all_containers_from_containerlist_from_page(params 142 .getPageID()); 143 if (params.settings().isPreloadHomepageFieldsActivated() 144 && params.getPageID() != params.getSite().getHomePageID()) { 145 this.cachedContainersFromContainerLists.putAll(c_utils 146 .db_load_all_containers_from_containerlist_from_page(params 147 .getSite().getHomePageID())); 148 } 149 } catch (Throwable t) { 150 this.cachedContainersFromContainerLists = new Hashtable (); 151 logger.warn( 152 "cannot load all containers from containerlist from page", t); 153 } 154 try { 155 this.cachedContainerListsFromContainers = c_utils 156 .db_load_all_containerlists_from_container_from_page(params 157 .getPageID()); 158 if (params.settings().isPreloadHomepageFieldsActivated() 159 && params.getPageID() != params.getSite().getHomePageID()) { 160 this.cachedContainerListsFromContainers.putAll(c_utils 161 .db_load_all_containerlists_from_container_from_page(params 162 .getSite().getHomePageID())); 163 } 164 } catch (Throwable t) { 165 this.cachedContainerListsFromContainers = new Hashtable (); 166 logger.warn( 167 "cannot load all containerlists from container from page", t); 168 } 169 170 } 172 181 public synchronized void addContainerList(JahiaContainerList aContainerList) 182 throws JahiaException { 183 containerLists.put(aContainerList.getDefinition().getName(), 184 aContainerList); 185 } 187 215 public void declareField(String fieldName, String fieldTitle, 216 int fieldType, String defaultValue) throws JahiaException { 217 declareField(JahiaContainerSet.SHARED_CONTAINER, fieldName, fieldTitle, fieldType, 218 defaultValue); 219 } 220 221 245 public void declareField(String containerName, String fieldName, 246 String fieldTitle, int fieldType, String defaultValue) 247 throws JahiaException { 248 252 boolean isDeclaredField = checkDeclaredField(containerName, fieldName); 255 boolean isJahiaDataDeclaredField = jData.fields().checkDeclared( 256 fieldName); 257 258 boolean isDeclaredContainer = checkDeclared(fieldName); 263 264 if ((!isDeclaredField) && (!isJahiaDataDeclaredField) 265 && (!fieldName.equals("")) && (!fieldTitle.equals("")) 266 && (!isDeclaredContainer)) { 267 268 JahiaFieldDefinition aDef = JahiaFieldDefinitionsRegistry 272 .getInstance().getDefinition(jData.params().getSiteID(), 273 fieldName); 274 int pageDefID = jData.params().getPage().getPageTemplateID(); 275 if (aDef != null) { 276 280 Properties props = aDef.getProperties(); 281 Properties declaredProps = (Properties ) this.declaredFieldDefProps 282 .get(fieldName); 283 284 boolean propsHasChanged = ((props == null && (declaredProps != null && declaredProps 285 .size() > 0)) 286 || ((props != null && props.size() > 0) && declaredProps == null) || (props != null 287 && declaredProps != null && !props 288 .equals(declaredProps))); 289 290 if (!((aDef.getTitle(pageDefID).equals(fieldTitle)) 291 && (aDef.getType(pageDefID) == fieldType) 292 && ((aDef.getDefaultValue(pageDefID) == null && defaultValue == null) || (aDef 293 .getDefaultValue(pageDefID) != null && (aDef 294 .getDefaultValue(pageDefID).equals(defaultValue)))) && !propsHasChanged)) { 295 if ((aDef.getType(pageDefID) != fieldType) 300 && (aDef.getType(pageDefID) != -1)) { 301 String errorMsg = "Cannot change field type because field data already exists : " 305 + fieldName; 306 logger.error(errorMsg + " -> BAILING OUT"); 307 throw new JahiaException(errorMsg, errorMsg, 308 JahiaException.TEMPLATE_ERROR, 309 JahiaException.CRITICAL_SEVERITY); 310 311 } else { 312 logger.debug("Setting data for pageDef " + pageDefID); 319 aDef.setType(fieldType, pageDefID); 320 aDef.setTitle(fieldTitle, pageDefID); 321 aDef.setDefaultValue(defaultValue, pageDefID); 322 aDef 323 .setProperties((Properties ) this.declaredFieldDefProps 324 .get(fieldName)); 325 JahiaFieldDefinitionsRegistry.getInstance() 326 .setDefinition(aDef); 327 } 328 } 329 } else { 330 Hashtable subDefs = new Hashtable (); 339 subDefs.put(new Integer (pageDefID), 340 new JahiaFieldSubDefinition(0, 0, pageDefID, fieldTitle, 341 fieldType, defaultValue)); 342 aDef = new JahiaFieldDefinition(0, jData.params().getPage() 343 .getJahiaID(), fieldName, subDefs); 344 345 aDef.setProperties((Properties ) this.declaredFieldDefProps 346 .get(fieldName)); 347 348 JahiaFieldDefinitionsRegistry.getInstance().setDefinition(aDef); 349 } 350 ArrayList fieldNames = (ArrayList ) declaredFields 351 .get(containerName); 352 if (fieldNames == null) { 353 fieldNames = new ArrayList (); 354 } 355 fieldNames.add(fieldName); 356 declaredFields.put(containerName, fieldNames); 357 358 } else { 359 String errorMsg = ""; 361 if ("".equals(fieldName)) { 362 errorMsg = " Field has null name : " + fieldTitle; 363 } 364 if ("".equals(fieldTitle)) { 365 errorMsg += " Field has null title : " + fieldName; 366 } 367 if (isDeclaredField) { 368 errorMsg += " Field already declared : " + fieldName; 369 } 370 if (isJahiaDataDeclaredField) { 371 errorMsg += " Field already declared in JahiaData field set : " 372 + fieldName; 373 } 374 if (isDeclaredContainer) { 375 errorMsg += " Field name already used by a container : " 376 + fieldName; 377 } 378 379 throw new JahiaException(errorMsg, errorMsg, 380 JahiaException.TEMPLATE_ERROR, JahiaException.CRITICAL_SEVERITY); 381 } 382 } 384 391 public void declareFieldDefProp(String fieldName, String propName, 392 String propValue) { 393 if (fieldName != null && propName != null && propValue != null) { 394 Properties props = (Properties ) this.declaredFieldDefProps 395 .get(fieldName); 396 if (props == null) { 397 props = new Properties (); 398 } 399 props.setProperty(propName, propValue); 400 this.declaredFieldDefProps.put(fieldName, props); 401 } 402 } 403 404 429 public void declareContainer(String containerName, String containerTitle, 430 Vector containerFields) throws JahiaException { 431 declareContainer(containerName, containerTitle, containerFields, -1, 432 -1, null, null); 433 } 435 469 public void declareContainer(String containerName, String containerTitle, 470 Vector containerFields, int windowSize, int windowOffset) 471 throws JahiaException { 472 declareContainer(containerName, containerTitle, containerFields, 473 windowSize, windowOffset, null, null); 474 } 475 476 516 public void declareContainer(String containerName, String containerTitle, 517 Vector containerFields, int windowSize, int windowOffset, 518 String validatorKey, String containerBeanName) 519 throws JahiaException { 520 521 525 if (checkDeclared(containerName) || containerName.length() == 0 529 || containerTitle.length() == 0 530 || jData.fields().checkDeclared(containerName) 531 || this.checkDeclaredField(containerName)) { 532 533 String errorMsg = "Container already declared or has a null name - title : " 535 + containerName; 536 logger.error(errorMsg + " -> BAILING OUT"); 537 throw new JahiaException(errorMsg, errorMsg, 538 JahiaException.TEMPLATE_ERROR, JahiaException.CRITICAL_SEVERITY); 539 } else { 540 for (int i = 0; i < containerFields.size(); i++) { 542 String theName = (String ) containerFields.elementAt(i); 543 if (theName.equals("_self")) { 544 containerFields.setElementAt(containerName, i); 545 } else if ((!checkDeclared(theName)) 546 && (!checkDeclaredField(theName))) { 547 548 String errorMsg = "Element not defined in container " 550 + containerName + " : " + theName; 551 logger.error(errorMsg + " -> BAILING OUT"); 552 throw new JahiaException(errorMsg, errorMsg, 553 JahiaException.TEMPLATE_ERROR, 554 JahiaException.CRITICAL_SEVERITY); 555 } 556 } 557 558 Properties ctnDefProperties = new Properties (); 560 if ((windowSize >= 1)) { 561 if (windowOffset < 0) { 562 windowOffset = 0; 563 } 564 ctnDefProperties.setProperty("windowSize", Integer 565 .toString(windowSize)); 566 ctnDefProperties.setProperty("windowOffset", Integer 567 .toString(windowOffset)); 568 569 } 570 if (validatorKey != null && validatorKey.length() > 0) { 572 ctnDefProperties.setProperty("validatorKey", validatorKey); 573 } 574 if (containerBeanName != null && containerBeanName.length() > 0) { 575 ctnDefProperties.setProperty("containerBeanName", 576 containerBeanName); 577 } 578 579 JahiaContainerDefinitionsRegistry ctnDefRegistry = JahiaContainerDefinitionsRegistry 580 .getInstance(); 581 582 JahiaContainerDefinition aDef = ctnDefRegistry.getDefinition(jData 585 .params().getSiteID(), containerName); 586 int pageDefID = jData.params().getPage().getPageTemplateID(); 588 if (aDef != null) { 589 592 boolean havePropertiesChanged = aDef 593 .propertiesChanged(ctnDefProperties); 594 595 if ((!aDef.getTitle(pageDefID).equals(containerTitle)) 598 || (aDef.structureChanged(containerFields, pageDefID)) 599 || (havePropertiesChanged)) { 600 601 logger.warn("container structure changed: " 602 + containerTitle); 603 synchronized (ctnDefRegistry) { 604 aDef.getProperties().putAll(ctnDefProperties); 605 aDef.setTitle(containerTitle, pageDefID); 608 aDef.composeStructure(containerFields, pageDefID); 609 ctnDefRegistry.setDefinition(aDef); 614 } 615 620 if (havePropertiesChanged) { 621 logger.debug("Reloading containerList " + containerName 622 + "..."); 623 declaredContainers.add(containerName); 626 627 containerLists.remove(containerName); 628 getContainerList(containerName); 629 630 declaredContainers.remove(containerName); 632 } 633 } 634 } else { 635 Hashtable subDefs = new Hashtable (); 644 JahiaContainerSubDefinition subDef = new JahiaContainerSubDefinition( 645 0, pageDefID, containerTitle, null); 646 subDefs.put(new Integer (pageDefID), subDef); 647 aDef = new JahiaContainerDefinition(0, jData.params().getPage() 648 .getJahiaID(), containerName, subDefs); 649 aDef.setProperties(ctnDefProperties); 650 651 synchronized (ctnDefRegistry) { 653 ctnDefRegistry.setDefinition(aDef); 654 aDef.composeStructure(containerFields, pageDefID); 655 ctnDefRegistry.setDefinition(aDef); 656 } 657 666 } 667 668 if (aDef.getID() != 0) { 671 declaredContainers.add(containerName); 673 int clistID = ServicesRegistry.getInstance() 675 .getJahiaContainersService().getContainerListID( 676 containerName, jData.params().getPage().getID()); 677 if (clistID == -1) { 678 JahiaContainerList fakeContainerList = new JahiaContainerList( 681 0, 0, jData.params().getPage().getID(), aDef.getID(), 0); 682 addContainerList(fakeContainerList); 687 } 688 } 689 } 690 } 691 692 701 public void declareContainerEditView(String containerName, 702 ContainerEditView editView) throws JahiaException { 703 704 logger.debug("for container [" + containerName + "]"); 705 709 710 if (!containerName.equals("")) { 712 JahiaContainerDefinition aDef = JahiaContainerDefinitionsRegistry 715 .getInstance().getDefinition(jData.params().getSiteID(), 716 containerName); 717 if (aDef != null) { 718 aDef.setContainerEditView(editView); 719 logger.debug("for container [" + containerName 720 + "] done successfully "); 721 } 722 } 723 } 724 725 727 757 public void updateContainerDefinition(String containerName, 758 String containerTitle, Vector containerFields) 759 throws JahiaException { 760 logger.debug("Updating definition for container name=" + containerName 761 + " title=" + containerTitle + " with " 762 + Integer.toString(containerFields.size()) + " fields"); 763 if ((!containerName.equals("")) && (!containerTitle.equals("")) && 765 (!jData.fields().checkDeclared(containerName)) 767 && (!this.checkDeclaredField(containerName))) { 768 for (int i = 0; i < containerFields.size(); i++) { 770 String theName = (String ) containerFields.elementAt(i); 771 if (theName.equals("_self")) { 772 containerFields.setElementAt(containerName, i); 773 } else if ((!checkDeclared(theName)) 774 && (!checkDeclaredField(containerName, theName))) { 775 String errorMsg = "Element not defined in container " 777 + containerName + " : " + theName; 778 logger.error(errorMsg + " -> BAILING OUT"); 779 throw new JahiaException(errorMsg, errorMsg, 780 JahiaException.TEMPLATE_ERROR, 781 JahiaException.CRITICAL_SEVERITY); 782 } 783 } 784 785 JahiaContainerDefinition aDef = JahiaContainerDefinitionsRegistry 787 .getInstance().getDefinition(jData.params().getSiteID(), 788 containerName); 789 int pageDefID = jData.params().getPage().getPageTemplateID(); 790 791 if (aDef != null) { 792 if (!aDef.structureChanged(containerFields, pageDefID)) { 793 logger.debug("No changes in definition of " 795 + containerTitle + ", updating cancelled"); 796 return; 797 } 798 aDef.composeStructure(containerFields, pageDefID); 800 JahiaContainerDefinitionsRegistry.getInstance().setDefinition( 801 aDef); 802 803 } else { 804 logger 807 .debug("Meeting with a new container definition for the very first time, let's create " 808 + containerTitle + "..."); 809 Hashtable subDefs = new Hashtable (); 810 JahiaContainerSubDefinition subDef = new JahiaContainerSubDefinition( 811 0, pageDefID, containerTitle, null); 812 subDefs.put(new Integer (pageDefID), subDef); 813 aDef = new JahiaContainerDefinition(0, jData.params().getPage() 814 .getJahiaID(), containerName, subDefs); 815 JahiaContainerDefinitionsRegistry.getInstance().setDefinition( 816 aDef); 817 aDef.composeStructure(containerFields, pageDefID); 818 } 819 declaredContainers.add(containerName); 822 if (getContainerList(containerName) == null) { 824 JahiaContainerList fakeContainerList = new JahiaContainerList( 826 0, 0, jData.params().getPage().getID(), aDef.getID(), 0); 827 addContainerList(fakeContainerList); 828 } 829 } else { 830 String errorMsg = "Container has a null name - title : " 833 + containerName; 834 logger.error(errorMsg + " -> BAILING OUT"); 835 throw new JahiaException(errorMsg, errorMsg, 836 JahiaException.TEMPLATE_ERROR, JahiaException.CRITICAL_SEVERITY); 837 } 838 } 840 851 public boolean checkDeclared(String containerName) { 852 return declaredContainers.contains(containerName); 853 854 } 856 867 public boolean checkDeclaredField(String containerName, String fieldName) { 868 869 ArrayList fields = (ArrayList ) declaredFields 870 .get(JahiaContainerSet.SHARED_CONTAINER); 871 if (fields != null && fields.contains(fieldName)) { 872 return true; 873 } 874 fields = (ArrayList ) declaredFields.get(containerName); 875 return (fields != null && fields.contains(fieldName)); 876 877 } 879 886 public boolean checkDeclaredField(String name) { 887 Iterator iterator = declaredFields.values().iterator(); 888 while (iterator.hasNext()) { 889 ArrayList fields = (ArrayList ) iterator.next(); 890 if (fields.contains(name)) { 891 return true; 892 } 893 } 894 return false; 895 } 896 897 907 public JahiaContainer getContainer(String containerName) 908 throws JahiaException { 909 return getContainer(containerName, 0); 910 } 912 927 public JahiaContainer getContainer(String containerName, int index) 928 throws JahiaException { 929 930 if (checkDeclared(containerName)) { 931 JahiaContainerList theContainerList = (JahiaContainerList) containerLists 932 .get(containerName); 933 if (theContainerList != null) { 934 JahiaContainer theContainer = theContainerList 935 .getContainer(index); 936 if (theContainer != null) { 937 return theContainer; 938 } else { 939 String errorMsg = "Container is null : " + containerName 940 + "[" + index + "] -> BAILING OUT"; 941 logger.error(errorMsg); 942 throw new JahiaException("Error while returning field " 943 + containerName, errorMsg, 944 JahiaException.TEMPLATE_ERROR, 945 JahiaException.CRITICAL_SEVERITY); 946 } 947 } else { 948 String errorMsg = "Container not declared : " + containerName; 949 logger.error(errorMsg + " -> BAILING OUT"); 950 throw new JahiaException(errorMsg, errorMsg, 951 JahiaException.TEMPLATE_ERROR, 952 JahiaException.CRITICAL_SEVERITY); 953 } 954 } else { 955 String errorMsg = "Container not declared : " + containerName; 956 logger.error(errorMsg + " -> BAILING OUT"); 957 throw new JahiaException(errorMsg, errorMsg, 958 JahiaException.TEMPLATE_ERROR, JahiaException.CRITICAL_SEVERITY); 959 } 960 } 962 977 public JahiaContainer getContainer(int ctnid) throws JahiaException { 978 979 Iterator theContainers = containerLists.values().iterator(); 980 while (theContainers.hasNext()) { 981 JahiaContainerList aList = (JahiaContainerList) theContainers 982 .next(); 983 Enumeration enumeration = aList.getContainers(); 984 while (enumeration.hasMoreElements()) { 985 JahiaContainer aContainer = (JahiaContainer) enumeration 986 .nextElement(); 987 if (aContainer.getID() == ctnid) { 988 return aContainer; 989 } 990 } 991 } 992 return null; 993 } 995 1008 public JahiaContainerList getContainerList(String containerName) 1009 throws JahiaException { 1010 1011 if (checkDeclared(containerName)) { 1012 JahiaContainerList theContainerList = (JahiaContainerList) containerLists 1013 .get(containerName); 1014 EntryLoadRequest usedLoadRequest = jData.params() 1015 .getEntryLoadRequest(); 1016 if (theContainerList == null) { 1017 int clistID = ServicesRegistry.getInstance() 1018 .getJahiaContainersService().getContainerListID( 1019 containerName, jData.params().getPage().getID()); 1020 if (clistID != -1) { 1021 EntryLoadRequest ctnLoadRequest = jData.params() 1023 .getEntryLoadRequest(); 1024 usedLoadRequest = ctnLoadRequest; 1025 if (ctnLoadRequest.isVersioned()) { 1026 theContainerList = ServicesRegistry.getInstance() 1028 .getJahiaContainersService().loadContainerListInfo( 1029 clistID, ctnLoadRequest); 1030 } 1031 if (ctnLoadRequest.isVersioned() 1032 && theContainerList == null) { 1033 theContainerList = ServicesRegistry.getInstance() 1036 .getJahiaContainersService().loadContainerListInfo( 1037 clistID); 1038 theContainerList.setIsContainersLoaded(true); 1040 } else { 1041 1043 EntryLoadRequest loadRequest = (EntryLoadRequest) ctnLoadRequest 1045 .clone(); 1046 if (loadRequest.isVersioned()) { 1047 if (this.jData.params().showRevisionDiff()) { 1048 loadRequest.setWithDeleted(false); 1052 1053 loadRequest.setWithMarkedForDeletion(false); 1054 } else { 1055 loadRequest.setWithDeleted(false); 1056 loadRequest.setWithMarkedForDeletion(false); 1057 } 1058 } 1059 usedLoadRequest = loadRequest; 1060 try { 1061 theContainerList = ContainerFactory.getInstance() 1062 .fullyLoadContainerList(clistID, LoadFlags.ALL, 1063 this.jData.params(), loadRequest, 1064 this.cachedFieldsFromContainers, 1065 this.cachedContainersFromContainerLists, 1066 this.cachedContainerListsFromContainers); 1067 } catch (Throwable t) { 1068 logger 1069 .error("error while loading containerlist", t); 1070 } 1071 } 1072 } 1073 } 1074 if (theContainerList != null) { 1077 if (!theContainerList.isContainersLoaded() 1078 && theContainerList.getID() != 0) { ContainerFactory.getInstance().fullyLoadContainerList( 1080 theContainerList, LoadFlags.ALL, this.jData.params(), 1081 usedLoadRequest, this.cachedFieldsFromContainers, 1082 this.cachedContainersFromContainerLists, 1083 this.cachedContainerListsFromContainers); 1084 } 1085 addContainerList(theContainerList); 1086 } 1087 return theContainerList; 1088 } else { 1089 String errorMsg = "Container not declared : " + containerName; 1090 logger.error(errorMsg + " -> BAILING OUT"); 1091 throw new JahiaException(errorMsg, errorMsg, 1092 JahiaException.TEMPLATE_ERROR, JahiaException.CRITICAL_SEVERITY); 1093 } 1094 } 1096 1106 public JahiaContainerList getContainerList(int listID) 1107 throws JahiaException { 1108 1109 Iterator containerListIter = containerLists.values().iterator(); 1110 while (containerListIter.hasNext()) { 1111 JahiaContainerList aList = (JahiaContainerList) containerListIter 1112 .next(); 1113 if (aList.getID() == listID) { 1114 if (!aList.isContainersLoaded()) { 1115 EntryLoadRequest loadRequest = (EntryLoadRequest) jData 1117 .params().getEntryLoadRequest().clone(); 1118 if (this.jData.params().showRevisionDiff()) { 1119 loadRequest.setWithDeleted(false); 1123 1124 loadRequest.setWithMarkedForDeletion(false); 1125 } else { 1126 loadRequest.setWithDeleted(false); 1127 loadRequest.setWithMarkedForDeletion(false); 1128 } 1129 ContainerFactory.getInstance().fullyLoadContainerList( 1130 aList, LoadFlags.ALL, this.jData.params(), loadRequest, 1131 this.cachedFieldsFromContainers, 1132 this.cachedContainersFromContainerLists, 1133 this.cachedContainerListsFromContainers); 1134 } 1135 return aList; 1136 } 1137 } 1138 return null; 1139 } 1141 1156 public JahiaContainerList getAbsoluteContainerList(String containerName, 1157 int pageID) throws JahiaException { 1158 1159 if (pageID <= 0) { 1161 logger.error("Called with invalid pageID of " + pageID 1162 + ", returning null container list."); 1163 throw new JahiaException( 1164 "Error while loading absolute container list", 1165 "Invalid pageID passed to an absolute container list call : pageID=" 1166 + pageID + ", containerName=" + containerName, 1167 JahiaException.DATA_ERROR, JahiaException.ERROR_SEVERITY); 1168 } 1169 1170 JahiaContainerDefinition containerDefinition = JahiaContainerDefinitionsRegistry 1175 .getInstance().getDefinition(jData.params().getSiteID(), 1176 containerName); 1177 if (containerDefinition != null) { 1178 JahiaContainerDefinition theDef = JahiaContainerDefinitionsRegistry 1179 .getInstance().getDefinition(jData.params().getSiteID(), 1180 containerName); 1181 SortedSet parentSubContainerDefinitions = ServicesRegistry 1182 .getInstance().getJahiaContainersService() 1183 .getContainerDefinitionParents(theDef.getID()); 1184 if (parentSubContainerDefinitions.size() != 0) { 1185 throw new JahiaException( 1186 "Error while loading absolute container list", 1187 "Cannot load a sub container list with this method ! " 1188 + pageID, JahiaException.DATA_ERROR, 1189 JahiaException.ERROR_SEVERITY); 1190 } 1191 } 1192 1193 int containerListID = ServicesRegistry.getInstance() 1194 .getJahiaContainersService().getContainerListID(containerName, 1195 pageID); 1196 if (containerListID != -1) { 1197 absoluteContainerListAccesses.add(new Integer (containerListID)); 1199 1200 JahiaContainerList theContainerList = null; 1201 1202 try { 1203 Hashtable currentCachedFieldsFromContainers = this.cachedFieldsFromContainers; 1204 Hashtable currentCachedContainersFromContainerLists = this.cachedContainersFromContainerLists; 1205 Hashtable currentCachedContainerListsFromContainers = this.cachedContainerListsFromContainers; 1206 1207 if (pageID != this.jData.params().getPageID() 1208 && (jData.params().settings().isPreloadHomepageFieldsActivated() 1209 && pageID != this.jData.params().getSite().getHomePageID())) { 1210 try { 1212 currentCachedContainersFromContainerLists = c_utils 1213 .db_load_all_containers_from_containerlist_from_page(pageID); 1214 } catch (Throwable t) { 1215 logger.warn( 1216 "cannot load all containers from containerlist for page: " 1217 + pageID, t); 1218 } 1219 try { 1220 currentCachedFieldsFromContainers = c_utils 1221 .db_load_all_fields_from_container_from_page(pageID); 1222 } catch (Throwable t) { 1223 logger.warn( 1224 "cannot load all fields from container for page: " 1225 + pageID, t); 1226 } 1227 try { 1228 currentCachedContainerListsFromContainers = c_utils 1229 .db_load_all_containerlists_from_container_from_page(pageID); 1230 } catch (Throwable t) { 1231 logger.warn( 1232 "cannot load all containerlists from container for page: " 1233 + pageID, t); 1234 } 1235 } 1236 EntryLoadRequest ctnLoadRequest = jData.params() 1237 .getEntryLoadRequest(); 1238 if (ctnLoadRequest.isVersioned()) { 1239 theContainerList = ServicesRegistry.getInstance() 1241 .getJahiaContainersService().loadContainerListInfo( 1242 containerListID, ctnLoadRequest); 1243 } 1244 if (ctnLoadRequest.isVersioned() && theContainerList == null) { 1245 theContainerList = ServicesRegistry.getInstance() 1248 .getJahiaContainersService().loadContainerListInfo( 1249 containerListID); 1250 theContainerList.setIsContainersLoaded(true); 1252 } else { 1253 1254 EntryLoadRequest loadRequest = (EntryLoadRequest) ctnLoadRequest 1256 .clone(); 1257 if (this.jData.params().showRevisionDiff()) { 1258 loadRequest.setWithDeleted(false); 1262 1263 loadRequest.setWithMarkedForDeletion(false); 1264 } else { 1265 loadRequest.setWithDeleted(false); 1266 loadRequest.setWithMarkedForDeletion(false); 1267 } 1268 1269 if (theContainerList == null) { 1270 theContainerList = ContainerFactory.getInstance() 1271 .fullyLoadContainerList(containerListID, 1272 LoadFlags.ALL, this.jData.params(), 1273 loadRequest, currentCachedFieldsFromContainers, 1274 currentCachedContainersFromContainerLists, 1275 currentCachedContainerListsFromContainers); 1276 } else if (!theContainerList.isContainersLoaded()) { 1277 ContainerFactory.getInstance().fullyLoadContainerList( 1278 theContainerList, LoadFlags.ALL, 1279 this.jData.params(), loadRequest, 1280 currentCachedFieldsFromContainers, 1281 currentCachedContainersFromContainerLists, 1282 currentCachedContainerListsFromContainers); 1283 } 1284 } 1285 } catch (Throwable t) { 1286 logger.error("error while loading container list", t); 1287 } 1288 1289 if (theContainerList == null) { 1290 theContainerList = this.getContainerList(containerName); 1291 theContainerList.setID(containerListID); 1292 } 1293 return theContainerList; 1294 } else { 1295 JahiaContainerDefinition theDef = JahiaContainerDefinitionsRegistry 1298 .getInstance().getDefinition(jData.params().getSiteID(), 1299 containerName); 1300 if (theDef != null) { 1301 ContentPage contentPage = ContentPage.getPage(pageID); 1302 int pageACLID = contentPage.getAclID(); 1303 1304 JahiaContainerList fakeContainerList = new JahiaContainerList( 1305 0, 0, pageID, theDef.getID(), 0); 1306 1307 ServicesRegistry.getInstance().getJahiaContainersService() 1308 .saveContainerListInfo(fakeContainerList, pageACLID); 1309 1310 return getAbsoluteContainerList(containerName,pageID); 1311 1312 } else { 1313 return null; 1314 } 1315 } 1316 } 1318 1333 public JahiaContainerList getRelativeContainerList(String containerName, 1334 int levelNb) throws JahiaException { 1335 logger.debug("into relative...................."); 1336 int pageID = ServicesRegistry.getInstance().getJahiaPageService() 1337 .findPageIDFromLevel(jData.params().getPage().getID(), levelNb, 1338 jData.params()); 1339 logger.debug(".........page id found : " + pageID); 1340 if (pageID != -1) { 1341 return getAbsoluteContainerList(containerName, pageID); 1342 } else { 1343 return null; 1344 } 1345 } 1347 1356 public Set getAbsoluteContainerListAccesses() { 1357 return absoluteContainerListAccesses; 1358 } 1359 1360 1363 1364 public boolean equals(Object o) { 1365 return containerLists.equals(o); 1366 } 1367 1368 public int hashCode() { 1369 return containerLists.hashCode(); 1370 } 1371 1372 public Set entrySet() { 1373 return containerLists.entrySet(); 1374 } 1375 1376 public Collection values() { 1377 return containerLists.values(); 1378 } 1379 1380 public Set keySet() { 1381 return containerLists.keySet(); 1382 } 1383 1384 public void clear() throws UnsupportedOperationException { 1385 throw new UnsupportedOperationException ( 1386 "Jahia container lists collection is read-only!"); 1387 } 1388 1389 public void putAll(Map t) throws UnsupportedOperationException { 1390 throw new UnsupportedOperationException ( 1391 "Jahia container lists collection is read-only!"); 1392 } 1393 1394 public Object remove(Object key) throws UnsupportedOperationException { 1395 throw new UnsupportedOperationException ( 1396 "Jahia container lists collection is read-only!"); 1397 } 1398 1399 public Object put(Object key, Object value) 1400 throws UnsupportedOperationException { 1401 throw new UnsupportedOperationException ( 1402 "Jahia container lists collection is read-only!"); 1403 } 1404 1405 public Object get(Object key) { 1406 return containerLists.get(key); 1407 } 1408 1409 public boolean containsValue(Object value) { 1410 return containerLists.containsValue(value); 1411 } 1412 1413 public boolean containsKey(Object key) { 1414 return containerLists.containsKey(key); 1415 } 1416 1417 public boolean isEmpty() { 1418 return containerLists.isEmpty(); 1419 } 1420 1421 public int size() { 1422 return containerLists.size(); 1423 } 1424 1425} | Popular Tags |