KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > containers > JahiaContainersLogic


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 /***
14  * JahiaContainersLogic
15  * @author Eric Vassalli
16  *
17  * Holds all the methods to build a container logical tree structure
18  *
19  * @todo we MUST get rid of this code, it's slow, it's ugly, it's outdated !
20  *
21  */

22
23 //
24
// logic_build_container_tree( int pageID, ParamBean jParams )
25
//
26

27
28 package org.jahia.services.containers;
29
30 import org.jahia.data.containers.JahiaContainer;
31 import org.jahia.data.containers.JahiaContainerList;
32 import org.jahia.exceptions.JahiaException;
33
34 import java.util.Enumeration JavaDoc;
35 import java.util.Vector JavaDoc;
36
37
38 public class JahiaContainersLogic {
39
40     private static org.apache.log4j.Logger logger =
41             org.apache.log4j.Logger.getLogger (JahiaContainersLogic.class);
42
43
44     /**
45      * constructor
46      */

47     public JahiaContainersLogic () {
48     }
49
50
51     /**
52      * sorts the container tree
53      *
54      * @param theTree the actual tree, unsorted
55      *
56      * @see org.jahia.data.containers.JahiaContainerList
57      */

58     public void logic_sort_container_tree (Vector JavaDoc theTree)
59             throws JahiaException {
60         // build dependencies between container lists
61
for (int i = 0; i < theTree.size (); i++) {
62             JahiaContainerList theList = (JahiaContainerList) theTree.elementAt (i);
63             if (theList.getParentEntryID () != 0) {
64                 if (logic_add_container_list_to_container (theList, theList.getParentEntryID (),
65                         theTree)) {
66                     theTree.removeElementAt (i);
67                     i--;
68                 }
69             }
70         }
71     }
72
73
74     /**
75      * adds a container list to a container in the tree
76      *
77      * @param theContainerList the container list to add
78      * @param thectnid the container id to add the container list to
79      * @param theTree the Tree Vector
80      *
81      * @return true if succeeded, false if failed
82      */

83     private boolean logic_add_container_list_to_container (
84             JahiaContainerList theContainerList,
85             int thectnid,
86             Vector JavaDoc theTree)
87             throws JahiaException {
88         JahiaContainer theContainer = logic_find_container_in_list (thectnid,
89                 theTree.elements ());
90         if (theContainer != null) {
91             if (theContainerList == null) {
92                 logger.error ("Hey, the container list is null !!");
93             }
94             theContainer.addContainerList (theContainerList);
95             return true;
96         } else {
97             String JavaDoc errorMsg = "Error in container structure : container " + thectnid + " is referrenced";
98             errorMsg += " by list " + theContainerList.getID () + ", but does not exist.";
99             logger.error (errorMsg);
100             return false;
101         }
102     }
103
104
105     /**
106      * finds a container object by its id in the tree structure
107      *
108      * @param thectnid the container id
109      */

110     private JahiaContainer logic_find_container_in_list (int thectnid,
111                                                          Enumeration JavaDoc containerLists) {
112         while (containerLists.hasMoreElements ()) {
113             JahiaContainerList theContainerList = (JahiaContainerList) containerLists.nextElement ();
114             Enumeration JavaDoc containers = theContainerList.getContainers ();
115             while (containers.hasMoreElements ()) {
116                 JahiaContainer theContainer = (JahiaContainer) containers.nextElement ();
117                 if (theContainer.getID () != thectnid) {
118                     Enumeration JavaDoc listInContainer = theContainer.getContainerLists ();
119                     while (listInContainer.hasMoreElements ()) {
120                         JahiaContainer tmpContainer = logic_find_container_in_list (thectnid,
121                                 listInContainer);
122                         if (tmpContainer != null) {
123                             return tmpContainer;
124                         }
125                     }
126                 } else {
127                     return theContainer;
128                 }
129             }
130         }
131         return null;
132     }
133
134 }
135
Popular Tags