KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
10 import com.teamkonzept.webman.mainint.*;
11 import com.teamkonzept.webman.mainint.db.queries.*;
12 import com.teamkonzept.webman.mainint.events.*;
13 import de.webman.config.eventhandler.COPropUpdateHandler;
14
15 /**
16    creates a new property group or updates an existing group with the given name PROPGROUP_NEW_NAME.
17    after that, it displays a frameset with the list of property groups on the left
18    and an empty page to the right.
19    
20    if the given name is NULL, there are no changes and displays a frameset with the list of
21    property groups on the left and an error page to the right.
22  * @author $Author: doehling $
23  * @version $Revision: 1.10 $
24 */

25 public class COPropGroupUpdateHandler extends DefaultEventHandler implements ParameterTypes, DatabaseDefaults, FrameConstants
26 {
27     /** */
28     private COPropGroupUpdateHandler() {}
29
30     private static COPropGroupUpdateHandler instance = new COPropGroupUpdateHandler();
31
32     public static COPropGroupUpdateHandler getInstance()
33     {
34         return instance;
35     }
36
37     public void handleEvent(TKEvent evt) throws TKException
38     {
39         try
40         {
41             WebManEvent.checkEvent(evt.getRemoteUser(), evt.getName(), ContextConstants.CUSTOMIZE_PROPERTIES); // check if event is allowed
42
String JavaDoc propGroupId = evt.getParameter(PARAMETER, "PROPGROUP_ID");
43             String JavaDoc propGroupName = evt.getParameter(PARAMETER, "PROPGROUP_NAME");
44             String JavaDoc propGroupNewName = evt.getParameter(PARAMETER, "PROPGROUP_NEW_NAME");
45             boolean newGroup = false;
46             boolean noDuplicateExists = true;
47             boolean nameGiven = true;
48             TKQuery q = TKDBManager.newQuery(TKDBPropGroupGetAll.class);
49
50             // check, ob es sich um eine neuanzulegende gruppe handelt
51
propGroupId = (propGroupId != null ? propGroupId : "-1");
52             if ( propGroupId.equals("-1") )
53             {
54                 newGroup = true;
55             }
56             
57             // check, ob ueberhaupt ein name eingegeben wurde
58
if ( propGroupNewName == null || propGroupNewName.equals("") )
59             {
60                 nameGiven = false;
61             }
62             
63             // nein - ueberpruefung, ob eine gleichnamige gruppe bereits existiert
64
if ( nameGiven )
65             {
66                 // find all groups - q schon oben definiert
67
q.execute();
68                 ResultSet rs = q.fetchResultSet();
69
70                 // check, ob eine andere gleichnamige gruppe bereits existiert
71
while (rs != null && rs.next())
72                 {
73                     if ( propGroupNewName.equals(rs.getString("PROPGROUP_NAME"))
74                          && ! propGroupId.equals(rs.getString("PROPGROUP_ID")) )
75                     {
76                         noDuplicateExists = false;
77                         break;
78                     }
79                 }
80             }
81
82             // 2x nein - gruppe wird angelegt/gešndert
83
if ( noDuplicateExists && nameGiven )
84             {
85                 // neue gruppe wird angelegt
86
if ( newGroup )
87                 {
88                     q = TKDBManager.newQuery(TKDBPropGroupNew.class);
89                     q.setQueryParams( "PROPGROUP_NAME", propGroupNewName );
90                     q.execute();
91                 }
92
93                 // bestehende gruppe wird gešndert
94
else
95                 {
96                     q = TKDBManager.newQuery(TKDBPropGroupUpdate.class);
97                     q.setQueryParams( "PROPGROUP_ID", new Integer JavaDoc(propGroupId) );
98                     q.setQueryParams( "PROPGROUP_NAME", propGroupNewName );
99                     q.execute();
100
101                     // Notify listeners registered with group name.
102
ConfigurationManager.getInstance().notifyListeners(propGroupName);
103                 }
104
105                 // Notify listeners registered with *new* group name.
106
ConfigurationManager.getInstance().notifyListeners(propGroupNewName);
107             }
108
109             // finish
110
TKHTMLTemplate t = evt.getPrepHTMLTemplate( "f_co_propgroup.tmpl" );
111
112             // alles ok
113
if ( noDuplicateExists && nameGiven )
114             {
115                 HTMLUtils.fillFrameSet( t, LEFT_FRAME_WIDTH, "CO_PROPGROUP_LIST", "EMPTY" );
116             }
117             // ups, etwas war nicht in ordnung
118
else
119             {
120                 HTMLUtils.fillFrameSet( t, LEFT_FRAME_WIDTH, "CO_PROPGROUP_LIST", "CO_ERROR" );
121                 
122                 // EDIT=1 : bestehende gruppe wurde editiert
123
if ( ! newGroup )
124                 {
125                     t.set("EDIT", "1");
126                 }
127                 
128                 // NONAME=1 : es wurde keine neuer name angegeben
129
if ( ! nameGiven )
130                 {
131                     t.set("NONAME", "1");
132                 }
133             }
134             
135
136             WebManEvent.fillEventsIntoTemplate(evt.getRemoteUser(), t, CUSTOMIZE_PROPERTIES);
137             evt.finishTemplate( t );
138         } catch (Throwable JavaDoc e) {
139             throw WebmanExceptionHandler.getException(e);
140         }
141     }
142
143     public boolean isHandler(TKEvent evt)
144     {
145         return evt.getName().equalsIgnoreCase( "CO_PROPGROUP_UPDATE" );
146     }
147
148 }
149
Popular Tags