KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > webman > sitetree > eventhandler > STNodeListMultHandler


1 package de.webman.sitetree.eventhandler;
2
3 import com.teamkonzept.web.*;
4 import com.teamkonzept.webman.*;
5 import com.teamkonzept.webman.db.TKWebmanDBManager;
6 import com.teamkonzept.webman.mainint.*;
7 import com.teamkonzept.webman.mainint.db.*;
8 import com.teamkonzept.webman.mainint.db.queries.*;
9 import com.teamkonzept.webman.mainint.events.*;
10 import com.teamkonzept.lib.*;
11 import com.teamkonzept.field.*;
12 import com.teamkonzept.field.db.*;
13 import com.teamkonzept.db.*;
14 import com.teamkonzept.publishing.markups.*;
15 import de.webman.acl.*;
16
17 /**
18  * Lists the site structure.
19  *
20  * @author $Author: uli $
21  * @version $Revision: 1.7 $
22  */

23 public class STNodeListMultHandler
24     extends DefaultEventHandler
25     implements ParameterTypes,
26                FrameConstants,
27                DatabaseDefaults
28 {
29
30     /**
31      * The singleton instance.
32      */

33     private static final STNodeListMultHandler INSTANCE = new STNodeListMultHandler();
34
35     /**
36      * Avoids outside intstantiation.
37      */

38     private STNodeListMultHandler()
39     {
40         // NOP
41
}
42
43     /**
44      * Returns the singleton instance.
45      *
46      * @return the singleton instance.
47      */

48     public static STNodeListMultHandler getInstance ()
49     {
50         return INSTANCE;
51     }
52
53     /**
54      * Handles the specified event.
55      *
56      * @param event the event to be handled.
57      * @throws TKException if any error occurred during event handling.
58      */

59     public void handleEvent (TKEvent event)
60         throws TKException
61     {
62         try
63         {
64             WebManEvent.checkEvent(event.getRemoteUser(), event.getName(), ContextConstants.SITE_TREE);
65             TKHTMLTemplate left = event.getPrepHTMLTemplate("st_nodeList.tmpl");
66             String JavaDoc destination = event.getNotNullParameter(PARAMETER, "DESTINATION");
67
68             TKVector openNodes = new TKVector();
69
70             if (event.getParams().hasMultiple(PARAMETER, "OPEN_NODES"))
71             {
72                 openNodes = event.getParams().getVector(PARAMETER, "OPEN_NODES");
73             }
74             else
75             {
76                 openNodes.put(0, event.getParameter(PARAMETER, "OPEN_NODES"));
77             }
78
79             if (!destination.equals("") && !openNodes.contains(destination))
80             {
81                 openNodes.addElement(destination);
82             }
83
84             TKQuery q = null;
85             TKDBResult tree = null;
86             TKDBResult branch = null;
87             int size = openNodes.size();
88
89             for (int i = 0; i<size ; i++)
90             {
91                 String JavaDoc id = (String JavaDoc) openNodes.get(i);
92
93                 if (id != null)
94                 {
95                     q = TKDBManager.newQuery(TKDBSiteTreeGetOpen.class);
96
97                     if (id.equals("-1"))
98                     {
99                         q.setQueryParams("NODE_ID", TKNull.NULL);
100                     }
101                     else
102                     {
103                         q.setQueryParams("NODE_ID", new Integer JavaDoc(id));
104                     }
105
106                     q.execute();
107                     branch = new TKDBResult(q.fetchResultSet());
108                     tree = tree == null
109                                 ? branch
110                                 : TreeUtils.mergeIntoTree(tree, branch, "SITE_NODE_ID");
111                 }
112             }
113
114             int maxDepth = TreeUtils.getMaxDepth(tree, "SITE");
115             TKOpenSiteTreeIterator iterator = null;
116
117             if (destination.length() == 0)
118             {
119                 left.set("IS_TOP", "1");
120                 iterator = new TKOpenSiteTreeIterator(tree, left.getListIterator(), "ST_NODE_LIST", maxDepth);
121             }
122             else
123             {
124                 iterator = new TKOpenSiteTreeIterator(tree, left.getListIterator(), "ST_NODE_LIST", Integer.parseInt(destination), maxDepth);
125             }
126
127             left.setListIterator(iterator);
128             left.setListIterator(new TKStandardIterator(openNodes, left.getListIterator(), "OPEN_NODES", "OPEN_NODES"));
129
130             left.set("MAXDEPTH_PLUS_ONE", Integer.toString(maxDepth + 1));
131             left.set("MAXDEPTH_PLUS_TWO", Integer.toString(maxDepth + 2));
132             left.set("RTARGET", RIGHT_TARGET);
133             left.set("LTARGET", LEFT_TARGET);
134
135             if (LoginFactory.getInstance()
136                             .getLogin(event.getRemoteUser())
137                             .isAllowed(EventFactory.getInstance()
138                                                    .getEvent("DU_START")
139                                                    .getID(),
140                                        ContextConstants.DUPLICATION_TOOL))
141             {
142                 left.set("DU_START", "1");
143             }
144
145             if (LoginFactory.getInstance()
146                             .getLogin(event.getRemoteUser())
147                             .isAllowed(EventFactory.getInstance()
148                                                    .getEvent("GR_GENERATE")
149                                                    .getID(),
150                                        ContextConstants.GENERATOR))
151             {
152                 left.set("GR_GENERATE", "1");
153             }
154
155             WebManEvent.fillEventsIntoTemplate(event.getRemoteUser(), left, SITE_TREE);
156             event.finishTemplate(left);
157         }
158         catch (Throwable JavaDoc e)
159         {
160             // TO DO : Analyze Exception !
161
throw WebmanExceptionHandler.getException(e);
162         }
163     }
164
165     /**
166      * Checks wether this handler is capable to handle the specified event.
167      *
168      * @param event the event to be handled.
169      * @return <CODE>true</CODE> if this handler is capable to handle the
170      * specified event, otherwise <CODE>false</CODE>.
171      */

172     public boolean isHandler (TKEvent event)
173     {
174         return event.getName().equalsIgnoreCase("ST_SHOWLIST");
175     }
176
177 }
178
Popular Tags