KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > webman > content > eventhandler > CEForwardHandler


1 package de.webman.content.eventhandler;
2
3 import java.sql.ResultSet JavaDoc;
4 import com.teamkonzept.db.TKDBManager;
5 import com.teamkonzept.db.TKQuery;
6 import com.teamkonzept.db.QueryConstants;
7 import com.teamkonzept.lib.TKException;
8 import com.teamkonzept.lib.TKVector;
9 import com.teamkonzept.web.TKEvent;
10 import com.teamkonzept.web.TKHTMLTemplate;
11 import com.teamkonzept.web.TKParams;
12 import com.teamkonzept.webman.WebManEvent;
13 import com.teamkonzept.webman.mainint.ContextConstants;
14 import com.teamkonzept.webman.mainint.DatabaseDefaults;
15 import com.teamkonzept.webman.mainint.FrameConstants;
16 import com.teamkonzept.webman.mainint.HTMLUtils;
17 import com.teamkonzept.webman.mainint.TKStandardIterator;
18 import com.teamkonzept.webman.mainint.TreeUtils;
19 import com.teamkonzept.webman.mainint.WebmanExceptionHandler;
20 import com.teamkonzept.webman.mainint.db.queries.TKDBContentTreeIsChild;
21 import com.teamkonzept.webman.mainint.db.queries.content.SelectContentTree;
22 import com.teamkonzept.webman.mainint.events.DefaultEventHandler;
23 import com.teamkonzept.webman.mainint.events.ParameterTypes;
24 import de.webman.content.Content;
25 import de.webman.content.workflow.ContentVersion;
26 import de.webman.content.workflow.VersionCache;
27
28 /**
29  * Forwards content tree related events.
30  *
31  * @author $Author: uli $
32  * @version $Revision: 1.1 $
33  */

34 public class CEForwardHandler
35     extends DefaultEventHandler
36     implements ParameterTypes,
37                FrameConstants,
38                DatabaseDefaults
39 {
40
41     /**
42      * The singleton instance.
43      */

44     private static final CEForwardHandler INSTANCE = new CEForwardHandler();
45
46     /**
47      * Avoids outside intstantiation.
48      */

49     private CEForwardHandler ()
50     {
51         // NOP
52
}
53
54     /**
55      * Returns the singleton instance.
56      *
57      * @return the singleton instance.
58      */

59     public static CEForwardHandler getInstance ()
60     {
61         return INSTANCE;
62     }
63
64     /**
65      * Handles the specified event.
66      *
67      * @param event the event to be handled.
68      * @throws TKException if any error occurred during event handling.
69      */

70     public void handleEvent (TKEvent event)
71         throws TKException
72     {
73         try
74         {
75             CEUtils.checkEvent(event);
76
77             String JavaDoc target = event.getParameter(PARAMETER, "TARGET_EVENT");
78             Integer JavaDoc id = new Integer JavaDoc(event.getParameter(PARAMETER, "CONTENT_NODE_ID"));
79
80             ContentContext context = getContentContext(id);
81             TKHTMLTemplate frame = event.getPrepHTMLTemplate("f_ce.tmpl");
82
83             prepareFrameSet(frame, target, context);
84
85             if (target.equals("CE_GROUP_LIST"))
86             {
87                 frame.set("NAVIGATION_CONTEXT", context.calculateNavContext());
88             }
89
90             if (target.equals("CE_EDIT"))
91             {
92                 // Ich verstehe nicht, warum zum korrekten Editieren eines
93
// Single Contents im Template die Id und der Typ des
94
// den Content beinhaltenden Verzeichnisses stehen muß, aber
95
// es funktioniert leider nur so ... [unl/2002-04-17]
96
context.conNodeId = new Integer JavaDoc(event.getParameter(PARAMETER, "CONTENT_NODE_PARENT"));
97                 context.conNodeType = DIRECTORY_NODE_INTEGER;
98
99                 frame.set("NAVIGATION_CONTEXT", context.calculateNavContext());
100             }
101
102             event.finishTemplate(frame);
103         }
104         catch (Throwable JavaDoc e)
105         {
106             // TO DO : Analyze Exception !
107
throw WebmanExceptionHandler.getException(e);
108         }
109     }
110
111     /**
112      * Checks wether this handler is capable to handle the specified event.
113      *
114      * @param event the event to be handled.
115      * @return <CODE>true</CODE> if this handler is capable to handle the
116      * specified event, otherwise <CODE>false</CODE>.
117      */

118     public boolean isHandler (TKEvent event)
119     {
120         return event.getName().equalsIgnoreCase("CE_FORWARD");
121     }
122
123     /**
124      * Prepares a frame set for the event to be forwarded.
125      *
126      * @param frame the frame set.
127      * @param event the event to be forwarded.
128      * @param context the content context.
129      * @throws Throwable if an error occurred during preparation.
130      */

131     private void prepareFrameSet (TKHTMLTemplate frame,
132                                   String JavaDoc event,
133                                   ContentContext context)
134         throws Throwable JavaDoc
135     {
136         HTMLUtils.fillFrameSet(frame, LEFT_FRAME_WIDTH_SMALL, "CE_SHOWLIST", event);
137
138         context.fillIntoTemplate(frame);
139
140         TKVector openNodes = new TKVector();
141         openNodes.put(0, "-1");
142         openNodes = TreeUtils.updateOpenNodes(openNodes,
143                                               context.conNodeId.toString(),
144                                               "-1",
145                                               context.conNodeId.toString(),
146                                               TKDBContentTreeIsChild.class);
147
148         frame.setListIterator(new TKStandardIterator(openNodes, frame.getListIterator(), "OPEN_NODES", "OPEN_NODES"));
149     }
150
151     /**
152      * Returns a context information holder for the specified content.
153      *
154      * @param id the content identifier.
155      * @return a context information holder for the specified content.
156      * @throws Throwable if an error occurred during retrieval.
157      */

158     private ContentContext getContentContext (Integer JavaDoc id)
159         throws Throwable JavaDoc
160     {
161         ContentContext context = new ContentContext(new TKParams());
162         context.conNodeId = id;
163
164         TKQuery query = TKDBManager.newQuery(SelectContentTree.class);
165         query.setQueryParams("ID", id);
166         query.execute();
167
168         ResultSet JavaDoc result = query.fetchResultSet();
169
170         if (result.next())
171         {
172             context.conNodeType = new Integer JavaDoc(result.getInt("CONTENT_NODE_TYPE"));
173             context.formId = new Integer JavaDoc(result.getInt("CONTENT_FORM"));
174             context.conNodeName = result.getString("CONTENT_NODE_NAME");
175             context.conNodeShortName = result.getString("CONTENT_NODE_SHORTNAME");
176         }
177
178         if (GROUP_INTEGER.equals(context.conNodeType))
179         {
180             context.groupConNodeId = context.conNodeId;
181             context.groupConNodeName = context.conNodeName;
182             context.groupConNodeShortName = context.conNodeShortName;
183         }
184
185         if (SINGLE_INTEGER.equals(context.conNodeType))
186         {
187             Content content = VersionCache.getContentInfo(id);
188
189             context.instanceId = content.getInstanceId();
190             context.versionId = content.getCurrentVersion().getId();
191         }
192
193         return context;
194     }
195
196 }
197
Popular Tags