KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > webman > form > eventhandler > CTDuplicateHandler


1 package de.webman.form.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.form.Form;
16
17 /**
18  * Prepares the duplication of an existing form.
19  *
20  * @author $Author: uli $
21  * @version $Revision: 1.8 $
22  */

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

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

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

48     public static CTDuplicateHandler 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 hanlding.
58      */

59     public void handleEvent (TKEvent event)
60         throws TKException
61     {
62         try
63         {
64             // Check event.
65
WebManEvent.checkEvent(event.getRemoteUser(), event.getName(), ContextConstants.CONTENT_TREE);
66
67             // Get form.
68
Form form = new Form(Integer.valueOf(event.getParameter(PARAMETER, "FORM_ID")));
69
70             // Get template.
71
TKHTMLTemplate t = event.getPrepHTMLTemplate("ct_dupForm.tmpl");
72
73             // Propagate parameters.
74
t.set("FORM_ID", form.getIdentifier());
75             t.set("FORM_NAME", form.getDescription());
76
77             if (form.isFormFragment())
78             {
79                 String JavaDoc name = event.getParameter(PARAMETER, "NEW_FORM_NAME");
80                 t.set("NEW_FORM_NAME", (name != null && name.length() > 0) ? name : form.getName());
81             }
82
83             String JavaDoc description = event.getParameter(PARAMETER, "NEW_FORM_DESCRIPTION");
84             t.set("NEW_FORM_DESCRIPTION", (description != null && description.length() > 0) ? description : form.getDescription());
85
86             if (event.getParameter(PARAMETER, "ERROR") != null)
87             {
88                 t.set("ERROR", event.getParameter(PARAMETER, "ERROR"));
89             }
90
91             // Finish event.
92
WebManEvent.fillEventsIntoTemplate(event.getRemoteUser(), t, CONTENT_TREE);
93             event.finishTemplate(t);
94         }
95         catch (Throwable JavaDoc e)
96         {
97             // TO DO : Analyze Exception !
98
throw WebmanExceptionHandler.getException(e);
99         }
100     }
101
102     /**
103      * Checks wether this handler is capable to handle the specified event.
104      *
105      * @param event the event to be handled.
106      * @return <CODE>true</CODE> if this handler is capable to handle the
107      * specified event, otherwise <CODE>false</CODE>.
108      */

109     public boolean isHandler (TKEvent event)
110     {
111         return event.getName().equalsIgnoreCase("CT_DUPLICATE");
112     }
113
114 }
115
Popular Tags