KickJava   Java API By Example, From Geeks To Geeks.

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


1 package de.webman.documenttype.eventhandler;
2
3 import java.sql.ResultSet JavaDoc;
4 import com.teamkonzept.db.TKDBManager;
5 import com.teamkonzept.db.TKQuery;
6 import com.teamkonzept.lib.TKException;
7 import com.teamkonzept.web.TKEvent;
8 import com.teamkonzept.web.TKHTMLTemplate;
9 import com.teamkonzept.webman.WebManEvent;
10 import com.teamkonzept.webman.mainint.ContextConstants;
11 import com.teamkonzept.webman.mainint.DatabaseDefaults;
12 import com.teamkonzept.webman.mainint.FrameConstants;
13 import com.teamkonzept.webman.mainint.HTMLUtils;
14 import com.teamkonzept.webman.mainint.WebmanExceptionHandler;
15 import com.teamkonzept.webman.mainint.db.queries.presentation.SelectPresentation;
16 import com.teamkonzept.webman.mainint.events.DefaultEventHandler;
17 import com.teamkonzept.webman.mainint.events.ParameterTypes;
18
19 /**
20  * Forwards document type related events.
21  *
22  * @author $Author: uli $
23  * @version $Revision: 1.1 $
24  */

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

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

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

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

61     public void handleEvent (TKEvent event)
62         throws TKException
63     {
64         try
65         {
66             WebManEvent.checkEvent(event.getRemoteUser(), event.getName(), ContextConstants.PRESENTATIONS);
67
68             String JavaDoc target = event.getParameter(PARAMETER, "TARGET_EVENT");
69             Integer JavaDoc id = new Integer JavaDoc(event.getParameter(PARAMETER, "PRESENTATION_ID"));
70
71             TKHTMLTemplate frame = event.getPrepHTMLTemplate("f_pr.tmpl");
72
73             if (target.equals("PR_EDIT"))
74             {
75                 prepareFrameSet(frame, target, id);
76             }
77
78             if (target.equals("PR_EDIT_PRES_COMP"))
79             {
80                 prepareFrameSet(frame, target, id);
81                 frame.set("COMPONENT_ID", event.getParameter(PARAMETER, "COMPONENT_ID"));
82             }
83
84             WebManEvent.fillEventsIntoTemplate(event.getRemoteUser(), frame, PRESENTATIONS);
85             event.finishTemplate(frame);
86         }
87         catch (Throwable JavaDoc e)
88         {
89             // TO DO : Analyze Exception !
90
throw WebmanExceptionHandler.getException(e);
91         }
92     }
93
94     /**
95      * Checks wether this handler is capable to handle the specified event.
96      *
97      * @param event the event to be handled.
98      * @return <CODE>true</CODE> if this handler is capable to handle the
99      * specified event, otherwise <CODE>false</CODE>.
100      */

101     public boolean isHandler (TKEvent event)
102     {
103         return event.getName().equalsIgnoreCase("PR_FORWARD");
104     }
105
106     /**
107      * Prepares a frame set for the event to be forwarded.
108      *
109      * @param frame the frame set.
110      * @param event the event to be forwarded.
111      * @param id the document type identifier.
112      * @throws Throwable if an error occurred during preparation.
113      */

114     private void prepareFrameSet (TKHTMLTemplate frame,
115                                   String JavaDoc event,
116                                   Integer JavaDoc id)
117         throws Throwable JavaDoc
118     {
119         HTMLUtils.fillFrameSet(frame, LEFT_FRAME_WIDTH_SMALL, "PR_SHOWLIST", event);
120
121         frame.set("PRESENTATION_ID", id);
122
123         TKQuery query = TKDBManager.newQuery(SelectPresentation.class);
124         query.setQueryParams("PRESENTATION_ID", id);
125         query.execute();
126
127         ResultSet JavaDoc result = query.fetchResultSet();
128
129         if (result.next())
130         {
131             frame.set("PRESENTATION_NAME", result.getString("PRESENTATION_NAME"));
132             frame.set("PRESENTATION_SHORTNAME", result.getString("PRESENTATION_SHORTNAME"));
133             frame.set("TEMPLATE_ID", new Integer JavaDoc(result.getInt("TEMPLATE_ID")));
134         }
135     }
136
137 }
138
Popular Tags