KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > webman > config > eventhandler > COPropGroupEditHandler


1 package de.webman.config.eventhandler;
2
3 import java.util.*;
4 import java.sql.*;
5
6 import com.teamkonzept.web.*;
7 import com.teamkonzept.lib.*;
8 import com.teamkonzept.db.*;
9 import com.teamkonzept.webman.mainint.*;
10 import com.teamkonzept.webman.mainint.db.queries.TKDBPropGroupGetGroup;
11 import com.teamkonzept.webman.*;
12 import com.teamkonzept.webman.mainint.db.queries.TKDBPropGroupGetGroupProps;
13 import com.teamkonzept.webman.mainint.events.*;
14
15 /**
16    Erzeugt eine Seite basierend auf co_propgroupedit.tmpl, die alle Properties der aktuelle Gruppe
17    als Liste "CO_PROP_LIST" zur verfügung stellt.
18  * @author $Author: doehling $
19  * @version $Revision: 1.7 $
20 */

21 public class COPropGroupEditHandler extends DefaultEventHandler implements ParameterTypes, DatabaseDefaults, FrameConstants
22 {
23     /** */
24     private COPropGroupEditHandler() {}
25
26     /** */
27     private static COPropGroupEditHandler instance = new COPropGroupEditHandler();
28
29     public static COPropGroupEditHandler getInstance()
30     {
31         return instance;
32     }
33
34     public void handleEvent(TKEvent evt) throws TKException
35     {
36         try {
37             WebManEvent.checkEvent(evt.getRemoteUser(), evt.getName(), ContextConstants.CUSTOMIZE_PROPERTIES); // check if event is allowed
38
String JavaDoc propGroupId = evt.getParameter(PARAMETER, "PROPGROUP_ID");
39             propGroupId = (propGroupId != null ? propGroupId : "-1");
40             String JavaDoc propGroupName = evt.getParameter(PARAMETER, "PROPGROUP_NAME");
41             String JavaDoc listProps = evt.getParameter(PARAMETER, "LIST_PROPS");
42             listProps = (listProps != null ? listProps : "-1");
43
44             TKHTMLTemplate t = evt.getPrepHTMLTemplate( "co_propgroupedit.tmpl" );
45             t.set("PROPGROUP_ID", propGroupId);
46             t.set("LIST_PROPS", listProps);
47
48             if (propGroupName != null)
49             {
50                 t.set("PROPGROUP_NAME", propGroupName);
51             }
52
53             // find the properties of this group
54
TKQuery q = TKDBManager.newQuery(TKDBPropGroupGetGroupProps.class);
55             q.setQueryParams("PROPGROUP_ID", new Integer JavaDoc(propGroupId));
56             q.execute();
57             ResultSet rs = q.fetchResultSet();
58             TKVector myProps = new TKVector();
59             while (rs != null && rs.next()) {
60                 int pId = rs.getInt("PROP_ID");
61                 String JavaDoc pName = rs.getString("PROP_NAME");
62                 String JavaDoc pValue = rs.getString("PROP_VALUE");
63                 /* setzen den value auf "", falls es null war, sonst gibt es bei der ausgabe
64                    eine exception, umwandeln beim schreiben wirkungslos, da die db's (oracle,...)
65                    teilweise leere strings in null-strings umwandelt */

66                 if ( pValue == null )
67                 {
68                     pValue = "";
69                 }
70                 TKHashtable hash = new TKHashtable();
71                 hash.put("PROP_ID", new Integer JavaDoc(pId));
72                 hash.put("PROP_NAME", pName);
73                 hash.put("PROP_VALUE", pValue);
74                 myProps.addElement(hash);
75             }
76
77             /*
78             find all properties - wird nicht mehr gebraucht, da jede group ihre eigenene props besitzt
79
80             q = TKDBManager.newQuery(TKDBPropGroupGetAllProps.class);
81             q.execute();
82             rs = q.fetchResultSet();
83             TKVector allProps = new TKVector();
84             while (rs != null && rs.next()) {
85                 int pId = rs.getInt("PROP_ID");
86                 String pName = rs.getString("PROP_NAME");
87                 String pValue = rs.getString("PROP_VALUE");
88                 TKHashtable hash = new TKHashtable();
89                 hash.put("PROP_ID", new Integer(pId));
90                 hash.put("PROP_NAME", pName);
91                 hash.put("PROP_VALUE", pValue);
92                 allProps.addElement(hash);
93             }
94             // remove all elements that belongs to group...
95             Enumeration enum = myProps.elements();
96             while (enum.hasMoreElements())
97             {
98                 allProps.remove(enum.nextElement());
99             }
100
101             t.setListIterator(new TKStandardPluginIterator("CO_ALL_PROP_LIST", null, allProps, true, t.getListIterator()));
102             */

103
104             // bekanntgeben der liste und ob sie übehaupt elemente enthält
105
t.setListIterator(new TKStandardPluginIterator("CO_PROP_LIST", null, myProps, true, t.getListIterator()));
106             if (myProps.size() > 0) t.set("HAS_PROPS", "1"); else t.set("HAS_PROPS", "0");
107
108             WebManEvent.fillEventsIntoTemplate(evt.getRemoteUser(), t, CUSTOMIZE_PROPERTIES);
109             evt.finishTemplate( t );
110         } catch (Throwable JavaDoc e) {
111             throw WebmanExceptionHandler.getException(e);
112         }
113     }
114
115     public boolean isHandler(TKEvent evt)
116     {
117         return evt.getName().equalsIgnoreCase( "CO_PROPGROUP_EDIT" );
118     }
119
120 }
121
Popular Tags