01: package de.webman.form.eventhandler;
02:
03: import com.teamkonzept.web.*;
04: import com.teamkonzept.webman.*;
05: import com.teamkonzept.webman.db.TKWebmanDBManager;
06: import com.teamkonzept.webman.mainint.*;
07: import com.teamkonzept.webman.mainint.db.*;
08: import com.teamkonzept.webman.mainint.db.queries.*;
09: 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 com.teamkonzept.international.LanguageManager;
16:
17: /**
18: * Modifes either a new or an existing form.
19: *
20: * @author $Author: uli $
21: * @version $Revision: 1.7 $
22: */
23: public class CTModifyHandler extends DefaultEventHandler implements
24: ParameterTypes, FrameConstants, DatabaseDefaults {
25:
26: /**
27: * The singleton instance.
28: */
29: private static final CTModifyHandler INSTANCE = new CTModifyHandler();
30:
31: /**
32: * Avoids outside instantiation.
33: */
34: private CTModifyHandler() {
35: // NOP
36: }
37:
38: /**
39: * Returns the singleton instance.
40: *
41: * @return the singleton instance.
42: */
43: public static CTModifyHandler getInstance() {
44: return INSTANCE;
45: }
46:
47: /**
48: * Handles the specified event.
49: *
50: * @param event the event to be handled.
51: * @throws TKException if any error occurred during event handling.
52: */
53: public void handleEvent(TKEvent event) throws TKException {
54: try {
55: // Check event.
56: WebManEvent.checkEvent(event.getRemoteUser(), event
57: .getName(), CONTENT_TREE);
58:
59: // Get form prototype from submitted form data.
60: TKBaseField field = CTUtils.getStructure(Integer
61: .parseInt(event
62: .getParameter(PARAMETER, "FORM_TYPE")));
63: Object realData = field.compileData("", event.getParams()
64: .getClass(PARAMETER), new TKHashtable());
65: String action = event.getParameter(ACTION, "MODIFY");
66: String target = event.getParameter(TARGET, "MODIFY");
67:
68: // Finish event.
69: TKHTMLTemplate t = event
70: .getPrepHTMLTemplate("ct_fields.tmpl");
71: field.fillIntoTemplate(t, realData, "");
72: t
73: .set("DESTINATION", field.modify(action, target,
74: realData));
75: CTUtils.keepCTContext(event, t);
76: WebManEvent.fillEventsIntoTemplate(event.getRemoteUser(),
77: t, CONTENT_TREE);
78: event.finishTemplate(t);
79: } catch (Throwable e) {
80: // TO DO : Analyze Exception !
81: throw WebmanExceptionHandler.getException(e);
82: }
83: }
84:
85: /**
86: * Checks wether this handler is capable to handle the specified event.
87: *
88: * @param event the event to be handled.
89: * @return <CODE>true</CODE> if this handler is capable to handle the
90: * specified event, otherwise <CODE>false</CODE>.
91: */
92: public boolean isHandler(TKEvent event) {
93: return event.getName().equalsIgnoreCase("CT_MODIFY");
94: }
95:
96: }
|