KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > webman > documenttype > eventhandler > DTEditPresCompHandler


1 package de.webman.documenttype.eventhandler;
2
3 import java.sql.ResultSet JavaDoc;
4 import com.teamkonzept.web.*;
5 import com.teamkonzept.webman.*;
6 import com.teamkonzept.webman.db.TKWebmanDBManager;
7 import com.teamkonzept.webman.mainint.*;
8 import com.teamkonzept.webman.mainint.db.*;
9 import com.teamkonzept.webman.mainint.db.queries.*;
10 import com.teamkonzept.webman.mainint.db.queries.presentation.*;
11 import com.teamkonzept.webman.mainint.events.*;
12 import com.teamkonzept.lib.*;
13 import com.teamkonzept.field.*;
14 import com.teamkonzept.field.db.*;
15 import com.teamkonzept.db.*;
16 import de.webman.form.Form;
17
18 /**
19  * Prepares an existing documenttype component for editing.
20  *
21  * @author $Author: uli $
22  * @version $Revision: 1.7 $
23  */

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

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

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

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

60     public void handleEvent (TKEvent event)
61         throws TKException
62     {
63         try
64         {
65             WebManEvent.checkEvent(event.getRemoteUser(), event.getName(), ContextConstants.PRESENTATIONS);
66
67             String JavaDoc type = event.getParameter(PARAMETER, "COMPONENT_TYPE");
68
69             if (type == null || type.length() == 0)
70             {
71                 TKQuery query = TKDBManager.newQuery(SelectPresentationComponent.class);
72                 query.setQueryParams("PRESENTATION_ID", new Integer JavaDoc(event.getParameter(PARAMETER, "PRESENTATION_ID")));
73                 query.setQueryParams("PRESENTATION_COMPONENT_IDX", new Integer JavaDoc(event.getParameter(PARAMETER, "COMPONENT_ID")));
74                 query.execute();
75
76                 ResultSet JavaDoc result = query.fetchResultSet();
77
78                 if (result.next())
79                 {
80                     type = result.getString("COMPONENT_TYPE");
81
82                     event.getParams().put(PARAMETER, "COMPONENT_TYPE", type);
83                     event.getParams().put(PARAMETER, "INTEGRATION_TYPE", result.getString("INTEGRATION_TYPE"));
84                     event.getParams().put(PARAMETER, "INTEGRATION_NAME", result.getString("INTEGRATION_NAME"));
85                     event.getParams().put(PARAMETER, "INTEGRATION_SHORTNAME", result.getString("INTEGRATION_SHORTNAME"));
86                     event.getParams().put(PARAMETER, "FORM_ID", result.getString("FORM_ID"));
87                 }
88             }
89
90             TKHTMLTemplate t = event.getPrepHTMLTemplate("pr_editComp.tmpl");
91             t.set(event.getParams().getClass(PARAMETER));
92
93             if (CONTENT.equals(type) || STRUCTURE.equals(type))
94             {
95                 t.set("FORM_NAME", (new Form(new Integer JavaDoc(event.getParameter(PARAMETER, "FORM_ID")))).getDescription());
96             }
97
98             if (REFERENCE_TYPED.equals(type))
99             {
100                 TKDBTemplate.prepareListTemplate(DTUtils.prepareSubPresSelection(event), t, "PR_SUBPRES_SELECTION");
101             }
102
103             WebManEvent.fillEventsIntoTemplate(event.getRemoteUser(), t, PRESENTATIONS);
104             event.finishTemplate(t);
105         }
106         catch (Throwable JavaDoc e)
107         {
108             // TO DO : Analyze Exception !
109
throw WebmanExceptionHandler.getException(e);
110         }
111     }
112
113     /**
114      * Checks wether this handler is capable to handle the specified event.
115      *
116      * @param event the event to be handled.
117      * @return <CODE>true</CODE> if this handler is capable to handle the
118      * specified event, otherwise <CODE>false</CODE>.
119      */

120     public boolean isHandler (TKEvent event)
121     {
122         return event.getName().equalsIgnoreCase("PR_EDIT_PRES_COMP");
123     }
124
125 }
126
Popular Tags