KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > data > containers > JahiaContainerSet


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12
//
13
// JahiaContainerSet
14
// EV 01.01.2001 Happy New Year, Folks !
15
//
16
package org.jahia.data.containers;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.Collection JavaDoc;
20 import java.util.Enumeration JavaDoc;
21 import java.util.HashSet JavaDoc;
22 import java.util.Hashtable JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.Map JavaDoc;
25 import java.util.Properties JavaDoc;
26 import java.util.Set JavaDoc;
27 import java.util.SortedSet JavaDoc;
28 import java.util.Vector JavaDoc;
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 JavaDoc {
46
47     /**
48      * this container name is used for backward compatibility with the method
49      * declareField(String fieldName, String fieldTitle, int fieldType, String
50      * defaultValue) without giving any container list name Declaring such field
51      * names has the limitation that theses field names should be uniques for
52      * all container of the template
53      *
54      */

55     public static final String JavaDoc 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     /**
64      * @associates JahiaContainerList
65      */

66     private Map JavaDoc containerLists;
67
68     /**
69      * @associates String
70      */

71     private Set JavaDoc declaredContainers; // list of per-request declared containers
72

73     /**
74      * @associates String (key = container name/ value = ArrayList of field
75      * name)
76      */

77     private Hashtable JavaDoc declaredFields;
78
79     /**
80      * key = field name / value = Properties
81      */

82     private Hashtable JavaDoc declaredFieldDefProps;
83
84     /**
85      * This is used to store during a request all the container lists that have
86      * been accessed in absolute manner. This will be used to figure out if the
87      * absolute references have changed since the last time this template was
88      * processed.
89      */

90     private Set JavaDoc absoluteContainerListAccesses = new HashSet JavaDoc();
91
92     /**
93      * Optional cached containers fields
94      */

95     private Hashtable JavaDoc cachedFieldsFromContainers;
96
97     /**
98      * Optional cached containers in container list
99      */

100     private Hashtable JavaDoc cachedContainersFromContainerLists;
101
102     /**
103      * Optional cached containerlists in containers
104      */

105     private Hashtable JavaDoc cachedContainerListsFromContainers;
106
107     // -------------------------------------------------------------------------
108
/***************************************************************************
109      * constructor
110      *
111      * @param jData
112      * JahiaData
113      *
114      */

115     public JahiaContainerSet(JahiaData jahiaData) {
116         this.jData = jahiaData;
117         this.containerLists = new Hashtable JavaDoc();
118         this.declaredContainers = new HashSet JavaDoc();
119         this.declaredFields = new Hashtable JavaDoc();
120         this.declaredFieldDefProps = new Hashtable JavaDoc();
121         this.cachedFieldsFromContainers = new Hashtable JavaDoc();
122         this.cachedContainersFromContainerLists = new Hashtable JavaDoc();
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 JavaDoc t) {
136             this.cachedFieldsFromContainers = new Hashtable JavaDoc();
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 JavaDoc t) {
150             this.cachedContainersFromContainerLists = new Hashtable JavaDoc();
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 JavaDoc t) {
165             this.cachedContainerListsFromContainers = new Hashtable JavaDoc();
166             logger.warn(
167                 "cannot load all containerlists from container from page", t);
168         }
169
170     } // end constructor
171

172     // -------------------------------------------------------------------------
173
/***************************************************************************
174      * adds a container list to the set.
175      *
176      * @param aContainerList
177      * the JahiaContainerList to add
178      * @see org.jahia.data.containers.JahiaContainerList
179      *
180      */

181     public synchronized void addContainerList(JahiaContainerList aContainerList)
182             throws JahiaException {
183         containerLists.put(aContainerList.getDefinition().getName(),
184             aContainerList);
185     } // end addContainerList
186

187     // -------------------------------------------------------------------------
188
/***************************************************************************
189      * enables a jahia template programmer to declare a field in a container
190      * Deprecated: declaring field name without the container name retrict this
191      * field name to be unique for all containers of the template
192      *
193      * @param fieldName
194      * the field name
195      * @param fieldTitle
196      * the field title
197      * @param fieldType
198      * the field tpe
199      * @param defaultValue
200      * the default field value
201      *
202      * @exception raises
203      * a critical JahiaException if the container has been
204      * already declared
205      * @exception raises
206      * a critical JahiaException if one of the containerFields
207      * have not been declared
208      * @exception raises
209      * a critical JahiaException if one of the fields has the
210      * same name as the container
211      *
212      * @deprecated, use declareField (String containerName, String fieldName,
213      * String fieldTitle, int fieldType, String defaultValue)
214      */

215     public void declareField(String JavaDoc fieldName, String JavaDoc fieldTitle,
216             int fieldType, String JavaDoc defaultValue) throws JahiaException {
217         declareField(JahiaContainerSet.SHARED_CONTAINER, fieldName, fieldTitle, fieldType,
218             defaultValue);
219     }
220
221     // -------------------------------------------------------------------------
222
/***************************************************************************
223      * enables a jahia template programmer to declare a field in a container
224      *
225      * @param fieldName
226      * the field name
227      * @param fieldTitle
228      * the field title
229      * @param fieldType
230      * the field tpe
231      * @param defaultValue
232      * the default field value
233      *
234      * @exception raises
235      * a critical JahiaException if the container has been
236      * already declared
237      * @exception raises
238      * a critical JahiaException if one of the containerFields
239      * have not been declared
240      * @exception raises
241      * a critical JahiaException if one of the fields has the
242      * same name as the container
243      *
244      */

245     public void declareField(String JavaDoc containerName, String JavaDoc fieldName,
246             String JavaDoc fieldTitle, int fieldType, String JavaDoc defaultValue)
247             throws JahiaException {
248         /**
249          * @todo ensure that the data provided by the user has no special chars
250          * in it
251          */

252         // we check if a field with the same name was not already declared, of
253
// if the field has no empty name or title
254
boolean isDeclaredField = checkDeclaredField(containerName, fieldName);
255         boolean isJahiaDataDeclaredField = jData.fields().checkDeclared(
256             fieldName);
257
258         // NK : 03.09.2003
259
// FIXME, why is this test for since field names are handled differently
260
// with container names ????
261
// boolean isDeclaredContainer = false;
262
boolean isDeclaredContainer = checkDeclared(fieldName);
263
264         if ((!isDeclaredField) && (!isJahiaDataDeclaredField)
265                 && (!fieldName.equals("")) && (!fieldTitle.equals(""))
266                 && (!isDeclaredContainer)) {
267
268             // first, let's check to see if the declared field has already a
269
// field definition in the FieldsDefinitionsRegistry (which means also in the
270
// jahia_fields_def table)
271
JahiaFieldDefinition aDef = JahiaFieldDefinitionsRegistry
272                 .getInstance().getDefinition(jData.params().getSiteID(),
273                     fieldName);
274             int pageDefID = jData.params().getPage().getPageTemplateID();
275             if (aDef != null) {
276                 // okay, it seems the definition already exists.
277
// now has it the same data than in the database (title, type,
278
// defaultval) ?
279

280                 Properties JavaDoc props = aDef.getProperties();
281                 Properties JavaDoc declaredProps = (Properties JavaDoc) 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                     // well, data is not the same in the registry and in the declare() method !
296
// this means the user has changed the field declaration in the template...
297
// before doing anything else, we have to be sure that the user didn't change the
298
// field data type, because this could crash the whole application !
299
if ((aDef.getType(pageDefID) != fieldType)
300                             && (aDef.getType(pageDefID) != -1)) {
301                         // okay, this user think he's smart : he tried to change the data type of
302
// fields already existing...
303
// let's send him a Jahia error to learn him a little lesson
304
String JavaDoc 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                         // okay, no alert ahead, the type hasn't been modified
313
// let's synchronize the data between :
314
// - the template declaration (file)
315
// - the database declaration (database)
316
// - the registry declaration (memory)
317
// the synchronizeData method handles all this for us... pfew :)
318
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 JavaDoc) this.declaredFieldDefProps
324                                 .get(fieldName));
325                         JahiaFieldDefinitionsRegistry.getInstance()
326                             .setDefinition(aDef);
327                     }
328                 }
329             } else {
330                 // hell, the definition doesn't exist in the memory !
331
// this can mean two things :
332
// - either this is the first time Jahia encounters this template
333
// - or the database data was screwed
334
// in any case, we got to :
335
// - add it into the registry (memory)
336
// - add it into the database (database)
337
// - change the values in jData (memory)
338
Hashtable JavaDoc subDefs = new Hashtable JavaDoc();
339                 subDefs.put(new Integer JavaDoc(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 JavaDoc) this.declaredFieldDefProps
346                     .get(fieldName));
347
348                 JahiaFieldDefinitionsRegistry.getInstance().setDefinition(aDef);
349             }
350             ArrayList JavaDoc fieldNames = (ArrayList JavaDoc) declaredFields
351                 .get(containerName);
352             if (fieldNames == null) {
353                 fieldNames = new ArrayList JavaDoc();
354             }
355             fieldNames.add(fieldName);
356             declaredFields.put(containerName, fieldNames);
357
358         } else {
359             // the field is already declared, or has a null name/title : let the user have it... ;)
360
String JavaDoc 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     } // end declareField
383

384     /**
385      * Declare properties for a given field definition ( field name )
386      *
387      * @param fieldName
388      * @param propName
389      * @param propValue
390      */

391     public void declareFieldDefProp(String JavaDoc fieldName, String JavaDoc propName,
392             String JavaDoc propValue) {
393         if (fieldName != null && propName != null && propValue != null) {
394             Properties JavaDoc props = (Properties JavaDoc) this.declaredFieldDefProps
395                 .get(fieldName);
396             if (props == null) {
397                 props = new Properties JavaDoc();
398             }
399             props.setProperty(propName, propValue);
400             this.declaredFieldDefProps.put(fieldName, props);
401         }
402     }
403
404     // -------------------------------------------------------------------------
405
/***************************************************************************
406      * enables a jahia template programmer to declare a container
407      *
408      * @param containerName
409      * the container name
410      * @param containerTitle
411      * the container title
412      * @param containerFields
413      * the fields (or containers) in the container
414      *
415      * @exception raises
416      * a critical JahiaException if the container has been
417      * already declared
418      * @exception raises
419      * a critical JahiaException if one of the containerFields
420      * have not been declared
421      * @exception raises
422      * a critical JahiaException if one of the fields has the
423      * same name as the container
424      *
425      * In order to let a container include itself, the keyword "_self" in the
426      * containeFields must be used.
427      *
428      */

429     public void declareContainer(String JavaDoc containerName, String JavaDoc containerTitle,
430             Vector JavaDoc containerFields) throws JahiaException {
431         declareContainer(containerName, containerTitle, containerFields, -1,
432             -1, null, null);
433     } // end declareContainer
434

435     /**
436      * enables a jahia template programmer to declare a container, specifying
437      * scrollable window size and offset for container lists that will grow very
438      * large in size.
439      *
440      * @param containerName
441      * the container name
442      * @param containerTitle
443      * the container title
444      * @param containerFields
445      * the fields (or containers) in the container
446      * @param windowSize
447      * an integer specifying the size of the display window in number
448      * of containers. Valid values are >= 1, -1 to deactivate this
449      * feature
450      * @param windowOffset
451      * an integer specifying the offset in the list of containers, to
452      * be used only when windowSize >= 1. Valid values are >= 0, and
453      * -1 is used to deactivate this feature
454      *
455      * @exception raises
456      * a critical JahiaException if the container has been
457      * already declared
458      * @exception raises
459      * a critical JahiaException if one of the containerFields
460      * have not been declared
461      * @exception raises
462      * a critical JahiaException if one of the fields has the
463      * same name as the container
464      *
465      * In order to let a container include itself, the keyword "_self" in the
466      * containeFields must be used.
467      *
468      */

469     public void declareContainer(String JavaDoc containerName, String JavaDoc containerTitle,
470             Vector JavaDoc containerFields, int windowSize, int windowOffset)
471             throws JahiaException {
472         declareContainer(containerName, containerTitle, containerFields,
473             windowSize, windowOffset, null, null);
474     }
475
476     /**
477      * enables a jahia template programmer to declare a container, specifying
478      * scrollable window size and offset for container lists that will grow very
479      * large in size.
480      *
481      * @param containerName
482      * the container name
483      * @param containerTitle
484      * the container title
485      * @param containerFields
486      * the fields (or containers) in the container
487      * @param windowSize
488      * an integer specifying the size of the display window in number
489      * of containers. Valid values are >= 1, -1 to deactivate this
490      * feature
491      * @param windowOffset
492      * an integer specifying the offset in the list of containers, to
493      * be used only when windowSize >= 1. Valid values are >= 0, and
494      * -1 is used to deactivate this feature
495      * @param validatorKey
496      * the key specifying the validator rules set to be applied to
497      * this container
498      * @param containerBeanName
499      * the name of the bean class being wrapped around the container
500      * facade
501      *
502      * @exception raises
503      * a critical JahiaException if the container has been
504      * already declared
505      * @exception raises
506      * a critical JahiaException if one of the containerFields
507      * have not been declared
508      * @exception raises
509      * a critical JahiaException if one of the fields has the
510      * same name as the container
511      *
512      * In order to let a container include itself, the keyword "_self" in the
513      * containeFields must be used.
514      *
515      */

516     public void declareContainer(String JavaDoc containerName, String JavaDoc containerTitle,
517             Vector JavaDoc containerFields, int windowSize, int windowOffset,
518             String JavaDoc validatorKey, String JavaDoc containerBeanName)
519             throws JahiaException {
520
521         /**
522          * @todo ensure that the data provided by the user has no special chars
523          * in it
524          */

525         // check if a container has already been declared with the same name
526
// checks if container name and title are not empty
527
// checks if a field has not the same name
528
if (checkDeclared(containerName) || containerName.length() == 0
529                 || containerTitle.length() == 0
530                 || jData.fields().checkDeclared(containerName)
531                 || this.checkDeclaredField(containerName)) {
532
533             // the container is already declared, or has a null name/title : let the user have it... ;)
534
String JavaDoc 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             // first, let's check that all the fields in the containerFields exist
541
for (int i = 0; i < containerFields.size(); i++) {
542                 String JavaDoc theName = (String JavaDoc) containerFields.elementAt(i);
543                 if (theName.equals("_self")) {
544                     containerFields.setElementAt(containerName, i);
545                 } else if ((!checkDeclared(theName))
546                         && (!checkDeclaredField(theName))) {
547
548                     // one of the fields or containers in containerFields doesn't exist !!
549
String JavaDoc 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             // second, let's build the property set of the container definition
559
Properties JavaDoc ctnDefProperties = new Properties JavaDoc();
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             // added for Apache Validator Support
571
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             // third, let's check to see if the declared container has already a
583
// container definition in the ContainersDefinitionsRegistry
584
JahiaContainerDefinition aDef = ctnDefRegistry.getDefinition(jData
585                 .params().getSiteID(), containerName);
586             // get the page template ID no matter in which language it is.
587
int pageDefID = jData.params().getPage().getPageTemplateID();
588             if (aDef != null) {
589                 // okay, it seems the definition already exists.
590
// now has it the same data than in the database ?
591

592                 boolean havePropertiesChanged = aDef
593                     .propertiesChanged(ctnDefProperties);
594
595                 // checks if title changed
596
// checks if structure changed
597
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                         // well, data is not the same in the registry and in the declare() method !
606
// this means the user has changed the container declaration in the template...
607
aDef.setTitle(containerTitle, pageDefID);
608                         aDef.composeStructure(containerFields, pageDefID);
609                         // okay, let's synchronize the data between :
610
// - the template declaration (file)
611
// - the database declaration (database)
612
// - the registry declaration (memory)
613
ctnDefRegistry.setDefinition(aDef);
614                     }
615                     /**
616                      * @todo we should now reload the container list since a lot
617                      * of things have changed, including window
618                      * parameters.
619                      */

620                     if (havePropertiesChanged) {
621                         logger.debug("Reloading containerList " + containerName
622                                 + "...");
623                         // small hack: to avoid doing this everywhere and to
624
// be able to call checkDeclared in the next call...
625
declaredContainers.add(containerName);
626                         
627                         containerLists.remove(containerName);
628                         getContainerList(containerName);
629                         
630                         // hack: will be added below...
631
declaredContainers.remove(containerName);
632                     }
633                 }
634             } else {
635                 // hell, the definition doesn't exist in the memory !
636
// this can mean two things :
637
// - either this is the first time Jahia encounters this template
638
// - or the database data was screwed
639
// in any case, we got to :
640
// - add it into the registry (memory)
641
// - add it into the database (database)
642
// - change the values in jData (memory)
643
Hashtable JavaDoc subDefs = new Hashtable JavaDoc();
644                 JahiaContainerSubDefinition subDef = new JahiaContainerSubDefinition(
645                     0, pageDefID, containerTitle, null);
646                 subDefs.put(new Integer JavaDoc(pageDefID), subDef);
647                 aDef = new JahiaContainerDefinition(0, jData.params().getPage()
648                     .getJahiaID(), containerName, subDefs);
649                 aDef.setProperties(ctnDefProperties);
650
651                 // insert new properties.
652
synchronized (ctnDefRegistry) {
653                     ctnDefRegistry.setDefinition(aDef);
654                     aDef.composeStructure(containerFields, pageDefID);
655                     ctnDefRegistry.setDefinition(aDef);
656                 }
657                 /*
658                                  Hashtable subDefs = new Hashtable();
659                                  JahiaContainerSubDefinition subDef = new JahiaContainerSubDefinition( 0, pageDefID, containerTitle, null );
660                                  subDef.composeStructure( containerFields );
661                                  subDefs.put( new Integer(pageDefID), subDef );
662                      aDef = new JahiaContainerDefinition( 0, jData.params().getPage().getJahiaID(),
663                                                 containerName, subDefs );
664                      JahiaContainerDefinitionsRegistry.getInstance().setDefinition( aDef );
665                  */

666             }
667
668             // fourth, we declare that the container has been loaded, in order
669
// to avoid double definitions
670
if (aDef.getID() != 0) {
671                 // last check that the definition was really created
672
declaredContainers.add(containerName);
673                 // last, we create a new fake container list if the container list is empty
674
int clistID = ServicesRegistry.getInstance()
675                     .getJahiaContainersService().getContainerListID(
676                         containerName, jData.params().getPage().getID());
677                 if (clistID == -1) {
678                     // if (getContainerList(containerName) == null) {
679
// we create a fake container list, and save it into memory
680
JahiaContainerList fakeContainerList = new JahiaContainerList(
681                         0, 0, jData.params().getPage().getID(), aDef.getID(), 0);
682                     // we can't create a *real* container list in the database here
683
// since we might be in the case of a sub container list and
684
// these can only be instantiated when the parent container is
685
// created.
686
addContainerList(fakeContainerList);
687                 }
688             }
689         }
690     }
691
692     /**
693      * enables a jahia template programmer to declare an edit view definition to
694      * use for a given container list.
695      *
696      * @param containerName
697      * the container name
698      * @param ContainerEditView ,
699      * the view definition
700      */

701     public void declareContainerEditView(String JavaDoc containerName,
702             ContainerEditView editView) throws JahiaException {
703
704         logger.debug("for container [" + containerName + "]");
705         /**
706          * @todo ensure that the data provided by the user has no special chars
707          * in it
708          */

709
710         // check if a container has already been declared with the same name
711
if (!containerName.equals("")) {
712             // third, let's check to see if the declared container has already a
713
// container definition in the ContainersDefinitionsRegistry
714
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     // -------------------------------------------------------------------------
726
/** @todo fix this implementation. It is extremely costly in performance. */
727     /***************************************************************************
728      * enables a jahia template developer to update a container definition used
729      * in the Jahia custom tag :
730      * org.jahia.tags.jahia.containers.ContainerListTag
731      *
732      * When meeting in a template the custom tag "<containerList>", Jahia
733      * declares a new container with empty field list; but after reading the
734      * <field> or <containerList> tags enclosed in the <containerList> tag, the
735      * container definition must be updated in order to add these fields and/or
736      * containers.
737      *
738      * @param containerName
739      * the container name
740      * @param containerTitle
741      * the container title
742      * @param containerFields
743      * the fields (or containers) in the container
744      *
745      * @exception raises
746      * a critical JahiaException if one of the containerFields
747      * have not been declared
748      * @exception raises
749      * a critical JahiaException if one of the fields has the
750      * same name as the container
751      *
752      * In order to let a container include itself, the keyword "_self" in the
753      * containerFields must be used.
754      *
755      * @author Jerome Tamiotti
756      */

757     public void updateContainerDefinition(String JavaDoc containerName,
758             String JavaDoc containerTitle, Vector JavaDoc containerFields)
759             throws JahiaException {
760         logger.debug("Updating definition for container name=" + containerName
761                 + " title=" + containerTitle + " with "
762                 + Integer.toString(containerFields.size()) + " fields");
763         // checks if container name and title are not empty
764
if ((!containerName.equals("")) && (!containerTitle.equals("")) &&
765         // checks if a field has not the same name
766
(!jData.fields().checkDeclared(containerName))
767                 && (!this.checkDeclaredField(containerName))) {
768             // first, let's check that all the fields in the containerFields exist
769
for (int i = 0; i < containerFields.size(); i++) {
770                 String JavaDoc theName = (String JavaDoc) containerFields.elementAt(i);
771                 if (theName.equals("_self")) {
772                     containerFields.setElementAt(containerName, i);
773                 } else if ((!checkDeclared(theName))
774                         && (!checkDeclaredField(containerName, theName))) {
775                     // one of the fields or containers in containerFields doesn't exist !!
776
String JavaDoc 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             // Retrieves the container definition in the registry
786
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                     // structure has not changed, let's exit right now...
794
logger.debug("No changes in definition of "
795                             + containerTitle + ", updating cancelled");
796                     return;
797                 }
798                 // update structure
799
aDef.composeStructure(containerFields, pageDefID);
800                 JahiaContainerDefinitionsRegistry.getInstance().setDefinition(
801                     aDef);
802
803             } else {
804                 // hell, the definition doesn't exist in the memory !
805
// declare it !
806
logger
807                     .debug("Meeting with a new container definition for the very first time, let's create "
808                             + containerTitle + "...");
809                 Hashtable JavaDoc subDefs = new Hashtable JavaDoc();
810                 JahiaContainerSubDefinition subDef = new JahiaContainerSubDefinition(
811                     0, pageDefID, containerTitle, null);
812                 subDefs.put(new Integer JavaDoc(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             // third, we declare that the container has been loaded, in order to
820
// avoid double definitions
821
declaredContainers.add(containerName);
822             // last, we create a new fake container list if the container list is empty
823
if (getContainerList(containerName) == null) {
824                 // we create a fake container list, and save it into memory
825
JahiaContainerList fakeContainerList = new JahiaContainerList(
826                     0, 0, jData.params().getPage().getID(), aDef.getID(), 0);
827                 addContainerList(fakeContainerList);
828             }
829         } else {
830             // the container is already declared, or has a null name/title : let
831
// the user have it... ;)
832
String JavaDoc 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     } // end updateContainerDefinition
839

840     // -------------------------------------------------------------------------
841
/***************************************************************************
842      * checks if a container has already been declared Note : we don't need to
843      * call this before a container declaration, this is already done in the
844      * declareContainer implementation
845      *
846      * @param containerName
847      * the container name
848      * @return true if already declared, false if not
849      *
850      */

851     public boolean checkDeclared(String JavaDoc containerName) {
852         return declaredContainers.contains(containerName);
853
854     } // end checkDeclared
855

856     // -------------------------------------------------------------------------
857
/***************************************************************************
858      * checks if a container field has already been declared Note : we don't
859      * need to do this before a container declaration. This is already done for
860      * us in the declareContainer and declareField implementations.
861      *
862      * @param containerName
863      * the container name
864      * @return true if already declared, false if not
865      *
866      */

867     public boolean checkDeclaredField(String JavaDoc containerName, String JavaDoc fieldName) {
868
869         ArrayList JavaDoc fields = (ArrayList JavaDoc) declaredFields
870             .get(JahiaContainerSet.SHARED_CONTAINER);
871         if (fields != null && fields.contains(fieldName)) {
872             return true;
873         }
874         fields = (ArrayList JavaDoc) declaredFields.get(containerName);
875         return (fields != null && fields.contains(fieldName));
876
877     } // end checjDeclaredField
878

879     // -------------------------------------------------------------------------
880
/***************************************************************************
881      * checks if a field name already declared in any containers
882      *
883      * @param name
884      * @return
885      */

886     public boolean checkDeclaredField(String JavaDoc name) {
887         Iterator JavaDoc iterator = declaredFields.values().iterator();
888         while (iterator.hasNext()) {
889             ArrayList JavaDoc fields = (ArrayList JavaDoc) iterator.next();
890             if (fields.contains(name)) {
891                 return true;
892             }
893         }
894         return false;
895     }
896
897     // -------------------------------------------------------------------------
898
/***************************************************************************
899      * gets the first occurence of a container list
900      *
901      * @param containerName
902      * the container name
903      * @return a JahiaContainer object
904      * @see org.jahia.data.containers.JahiaContainer
905      *
906      */

907     public JahiaContainer getContainer(String JavaDoc containerName)
908             throws JahiaException {
909         return getContainer(containerName, 0);
910     } // end getContainer
911

912     // -------------------------------------------------------------------------
913
/***************************************************************************
914      * gets an occurence of a container list
915      *
916      * @param containerName
917      * the container name
918      * @param index
919      * the occurence
920      * @return a JahiaContainer object
921      * @see org.jahia.data.containers.JahiaContainer
922      *
923      * @exception raises
924      * a critical JahiaException if container not found
925      *
926      */

927     public JahiaContainer getContainer(String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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     } // end getContainer
961

962     // -------------------------------------------------------------------------
963
/***************************************************************************
964      * gets a container through its ID
965      *
966      * @param ctnid
967      * the container ID
968      * @return a JahiaContainer object (may be null)
969      * @see org.jahia.data.containers.JahiaContainer
970      *
971      * @exception raises
972      * a critical JahiaException if container not found
973      *
974      * !!! Warning : this method can return a null value !!!
975      *
976      */

977     public JahiaContainer getContainer(int ctnid) throws JahiaException {
978
979         Iterator JavaDoc theContainers = containerLists.values().iterator();
980         while (theContainers.hasNext()) {
981             JahiaContainerList aList = (JahiaContainerList) theContainers
982                 .next();
983             Enumeration JavaDoc 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     } // end getContainer
994

995     // -------------------------------------------------------------------------
996
/***************************************************************************
997      * gets a containerlist through its name
998      *
999      * @param containerName
1000     * the countainer list name
1001     * @return a JahiaContainerList object
1002     * @see org.jahia.data.containers.JahiaContainerList
1003     *
1004     * @exception raises
1005     * a critical JahiaException if container list not found
1006     *
1007     */

1008    public JahiaContainerList getContainerList(String JavaDoc 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                    // apply containers search and filtering.
1022
EntryLoadRequest ctnLoadRequest = jData.params()
1023                        .getEntryLoadRequest();
1024                    usedLoadRequest = ctnLoadRequest;
1025                    if (ctnLoadRequest.isVersioned()) {
1026                        // does the container exists at this archive date
1027
theContainerList = ServicesRegistry.getInstance()
1028                            .getJahiaContainersService().loadContainerListInfo(
1029                                clistID, ctnLoadRequest);
1030                    }
1031                    if (ctnLoadRequest.isVersioned()
1032                            && theContainerList == null) {
1033                        // return the active version of the container list but
1034
// without any containers !
1035
theContainerList = ServicesRegistry.getInstance()
1036                            .getJahiaContainersService().loadContainerListInfo(
1037                                clistID);
1038                        // to avoid reloading the container
1039
theContainerList.setIsContainersLoaded(true);
1040                    } else {
1041                        // apply containers search and filtering.
1042

1043                        // When requesting an archived loadRequest
1044
EntryLoadRequest loadRequest = (EntryLoadRequest) ctnLoadRequest
1045                            .clone();
1046                        if (loadRequest.isVersioned()) {
1047                            if (this.jData.params().showRevisionDiff()) {
1048                                // @todo :
1049
// not fully handle so we dont load deleted yet
1050
// loadRequest.setWithDeleted(true);
1051
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 JavaDoc t) {
1068                            logger
1069                                .error("error while loading containerlist", t);
1070                        }
1071                    }
1072                }
1073            }
1074            // 05.05.2002 NK : Why the container list wasn't added in the list
1075
// before ?
1076
if (theContainerList != null) {
1077                if (!theContainerList.isContainersLoaded()
1078                        && theContainerList.getID() != 0) { // not a fake
1079
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 JavaDoc 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    } // end getContainerList
1095

1096    // -------------------------------------------------------------------------
1097
/***************************************************************************
1098     * gets a containerlist through its ID
1099     *
1100     * @param ctnid
1101     * the countainer list ID
1102     * @return a JahiaContainerList object, may return null
1103     * @see org.jahia.data.containers.JahiaContainerList
1104     *
1105     */

1106    public JahiaContainerList getContainerList(int listID)
1107            throws JahiaException {
1108
1109        Iterator JavaDoc 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                    // When requesting an archived loadRequest
1116
EntryLoadRequest loadRequest = (EntryLoadRequest) jData
1117                        .params().getEntryLoadRequest().clone();
1118                    if (this.jData.params().showRevisionDiff()) {
1119                        // @todo :
1120
// not fully handle so we dont load deleted yet
1121
// loadRequest.setWithDeleted(true);
1122
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    } // end getContainerList
1140

1141    // -------------------------------------------------------------------------
1142
/***************************************************************************
1143     * gets a container list in another page (absolute page reference by its id)
1144     *
1145     * @param containerName
1146     * the container list name
1147     * @param pageID
1148     * the page ID
1149     * @return a JahiaContainerList object, or null if nothing found
1150     * @see org.jahia.data.containers.JahiaContainerList
1151     *
1152     * !!! Warning : this method can return a null value !!! !!! Warning 2 :
1153     * this method should *NEVER* be called with the name of a sub container
1154     * list !
1155     */

1156    public JahiaContainerList getAbsoluteContainerList(String JavaDoc containerName,
1157            int pageID) throws JahiaException {
1158
1159        // quick check for a valid pageID
1160
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        // now let's check if we are accessing a top level container list or
1171
// not using only the definitions (as the container lists might not
1172
// yet exist). If it's not a top level container list, throw an
1173
// exception !
1174
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 JavaDoc 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            // let's update cross reference list
1198
absoluteContainerListAccesses.add(new Integer JavaDoc(containerListID));
1199
1200            JahiaContainerList theContainerList = null;
1201
1202            try {
1203                Hashtable JavaDoc currentCachedFieldsFromContainers = this.cachedFieldsFromContainers;
1204                Hashtable JavaDoc currentCachedContainersFromContainerLists = this.cachedContainersFromContainerLists;
1205                Hashtable JavaDoc currentCachedContainerListsFromContainers = this.cachedContainerListsFromContainers;
1206
1207                if (pageID != this.jData.params().getPageID()
1208                        && (jData.params().settings().isPreloadHomepageFieldsActivated()
1209                                && pageID != this.jData.params().getSite().getHomePageID())) {
1210                    // build correct caches
1211
try {
1212                        currentCachedContainersFromContainerLists = c_utils
1213                            .db_load_all_containers_from_containerlist_from_page(pageID);
1214                    } catch (Throwable JavaDoc 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 JavaDoc 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 JavaDoc 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                    // does the container exists at this archive date
1240
theContainerList = ServicesRegistry.getInstance()
1241                        .getJahiaContainersService().loadContainerListInfo(
1242                            containerListID, ctnLoadRequest);
1243                }
1244                if (ctnLoadRequest.isVersioned() && theContainerList == null) {
1245                    // return the active version of the container list but
1246
// without any containers !
1247
theContainerList = ServicesRegistry.getInstance()
1248                        .getJahiaContainersService().loadContainerListInfo(
1249                            containerListID);
1250                    // to avoid reload of containers
1251
theContainerList.setIsContainersLoaded(true);
1252                } else {
1253
1254                    // When requesting an archived loadRequest
1255
EntryLoadRequest loadRequest = (EntryLoadRequest) ctnLoadRequest
1256                        .clone();
1257                    if (this.jData.params().showRevisionDiff()) {
1258                        // @todo :
1259
// not fully handle so we dont load deleted yet
1260
// loadRequest.setWithDeleted(true);
1261
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 JavaDoc t) {
1286                logger.error("error while loading container list", t);
1287            }
1288            /** what this code does for NK * */
1289            if (theContainerList == null) {
1290                theContainerList = this.getContainerList(containerName);
1291                theContainerList.setID(containerListID);
1292            }
1293            return theContainerList;
1294        } else {
1295            // not found : gets definition id, then creates fake container list
1296
// and saves it into memory
1297
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    } // end getAbsoluteContainerList
1317

1318    // -------------------------------------------------------------------------
1319
/***************************************************************************
1320     * gets a container list in another page (relative page reference by number
1321     * of levels to go up)
1322     *
1323     * @param containerName
1324     * the container list name
1325     * @param levelNb
1326     * the numbers of level to go up in the site structure; -1 = Home
1327     * Page
1328     * @return a JahiaContainerList object, or null if nothing found
1329     * @see org.jahia.data.containers.JahiaContainerList
1330     *
1331     * !!! Warning : this method can return a null value !!!
1332     */

1333    public JahiaContainerList getRelativeContainerList(String JavaDoc 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    } // end getRelativeContainerList
1346

1347    /**
1348     * Returns a map that contains the current mapping of container list -> page
1349     * that represent the container lists that have been accessed by pages using
1350     * the absolute addressing method.
1351     *
1352     * @return a Set containing Integer objects that represent the container
1353     * list IDs that have been accessed absolutely from the current
1354     * page.
1355     */

1356    public Set JavaDoc getAbsoluteContainerListAccesses() {
1357        return absoluteContainerListAccesses;
1358    }
1359
1360    /*
1361     * Map interface implementation methods
1362     */

1363
1364    public boolean equals(Object JavaDoc o) {
1365        return containerLists.equals(o);
1366    }
1367
1368    public int hashCode() {
1369        return containerLists.hashCode();
1370    }
1371
1372    public Set JavaDoc entrySet() {
1373        return containerLists.entrySet();
1374    }
1375
1376    public Collection JavaDoc values() {
1377        return containerLists.values();
1378    }
1379
1380    public Set JavaDoc keySet() {
1381        return containerLists.keySet();
1382    }
1383
1384    public void clear() throws UnsupportedOperationException JavaDoc {
1385        throw new UnsupportedOperationException JavaDoc(
1386            "Jahia container lists collection is read-only!");
1387    }
1388
1389    public void putAll(Map JavaDoc t) throws UnsupportedOperationException JavaDoc {
1390        throw new UnsupportedOperationException JavaDoc(
1391            "Jahia container lists collection is read-only!");
1392    }
1393
1394    public Object JavaDoc remove(Object JavaDoc key) throws UnsupportedOperationException JavaDoc {
1395        throw new UnsupportedOperationException JavaDoc(
1396            "Jahia container lists collection is read-only!");
1397    }
1398
1399    public Object JavaDoc put(Object JavaDoc key, Object JavaDoc value)
1400            throws UnsupportedOperationException JavaDoc {
1401        throw new UnsupportedOperationException JavaDoc(
1402            "Jahia container lists collection is read-only!");
1403    }
1404
1405    public Object JavaDoc get(Object JavaDoc key) {
1406        return containerLists.get(key);
1407    }
1408
1409    public boolean containsValue(Object JavaDoc value) {
1410        return containerLists.containsValue(value);
1411    }
1412
1413    public boolean containsKey(Object JavaDoc 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} // end JahiaContainerSet
1426
Popular Tags