KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > webman > content > eventhandler > CEContentAttributesHandler


1 package de.webman.content.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 de.webman.content.db.queries.*;
14 import com.teamkonzept.db.*;
15 import com.teamkonzept.publishing.markups.*;
16 import de.webman.content.workflow.*;
17
18 import java.sql.*;
19 import java.io.*;
20
21 /**
22 * Auflisten aller Attribute eines Contents:
23 *
24  * @author $Author: sebastian $
25  * @version $Revision: 1.10 $
26 */

27 public class CEContentAttributesHandler extends DefaultEventHandler implements ParameterTypes, FrameConstants, DatabaseDefaults
28 {
29     private CEContentAttributesHandler()
30     {}
31     
32     private static CEContentAttributesHandler instance = new CEContentAttributesHandler();
33     
34     public static CEContentAttributesHandler getInstance()
35     {
36         return instance;
37     }
38     
39     private static String JavaDoc getAttributeValue(TKEvent evt, int pos)
40     {
41         String JavaDoc help = "ATTRIBUTES." + Integer.toString(pos);
42         if (Integer.parseInt(evt.getParameter(PARAMETER, help + ".TYPE")) == 3)
43         {
44             String JavaDoc back;
45             
46             back = evt.getParameter(PARAMETER, help + ".DAY");
47             back = back + '.' + evt.getParameter(PARAMETER, help + ".MONTH");
48             back = back + '.' + evt.getParameter(PARAMETER, help + ".YEAR");
49             back = back + ' ' + evt.getParameter(PARAMETER, help + ".HOUR");
50             back = back + ':' + evt.getParameter(PARAMETER, help + ".MINUTE");
51             back = back + ":00";
52             
53             return back;
54         }
55         else
56             return evt.getParameter(PARAMETER, help + ".ATTRIBUTE_VALUE");
57     }
58     
59     public void handleEvent(TKEvent evt) throws TKException
60     {
61         try
62         {
63             
64             CEUtils.checkEvent(evt);
65             
66             TKHTMLTemplate t = evt.getPrepHTMLTemplate( "ce_conAttrList.tmpl" );
67
68             ContentContext ceContext = new ContentContext (evt.getParams(), evt.toString());
69
70             if (ceContext.instanceId == null) throw new Exception JavaDoc ("doCEContentAttributes: No Content Instance");
71             
72             String JavaDoc event = evt.getName();
73             String JavaDoc action = event == null ? null : evt.getParameter(ACTION,event);
74             
75             TKContentDBData cdata = new TKContentDBData( ceContext.instanceId.intValue(), ceContext.versionId.intValue() );
76             TKContentDBInterface.Get (cdata);
77             
78             if (action == null || action.length() == 0 || action.equalsIgnoreCase ("GET"))
79             {
80                 t.setListIterator (new TKContentIterator (t,cdata,t.getListIterator()));
81                 ceContext.fillIntoTemplate (t);
82
83                 evt.finishTemplate(t);
84                 return;
85             }
86             
87             if (action.equalsIgnoreCase("SAVE") || action.equalsIgnoreCase("NEW_ATTR") || action.equalsIgnoreCase("DELETE_ATTRIBUTE") || action.equalsIgnoreCase("SAVE_AND_CLOSE"))
88             {
89                 // packe neue Contentattribute in cdata
90
int i = 0;
91                 while (cdata.content_attribute != null && cdata.content_attribute.size() > i)
92                 {
93                 
94                     TKContentAttributeTableData table = (TKContentAttributeTableData)cdata.content_attribute.elementAt(i);
95                     int r;
96                     for (r = 0;r < cdata.content_attribute.size();r++)
97                     {
98                         if (Integer.parseInt(evt.getParameter(PARAMETER, "ATTRIBUTES." + Integer.toString(r) + ".VALUE_ID")) == table.value_id)
99                             break;
100                     }
101
102                     
103                     String JavaDoc value = getAttributeValue(evt, r);
104                     
105                     if (!(table.value.equals(value)))
106                     {
107                         table.value = value;
108                 
109                         TKQuery q = TKDBManager.newQuery(TKDBContentAttributeUpdate.class);
110                         table.insertIntoQuery(q);
111                         q.execute();
112                     }
113                     i++;
114                 }
115             }
116             
117             if (action.equalsIgnoreCase("DELETE_ATTRIBUTE"))
118             {
119                 TKQuery q = TKDBManager.newQuery(TKDBContentAttributeDelete.class);
120                 q.setQueryParams("VALUE_ID", new Integer JavaDoc(Integer.parseInt(evt.getParameter("VALUE_ID", evt.getName()))));
121                 q.execute();
122                 
123                 for (int i = 0;i < cdata.content_attribute.size();i++)
124                 {
125                     if (((TKContentAttributeTableData)cdata.content_attribute.elementAt(i)).value_id == Integer.parseInt(evt.getParameter("VALUE_ID",evt.getName())))
126                     {
127                         cdata.content_attribute.remove(i);
128                         break;
129                     }
130                 }
131                 
132                 t.setListIterator (new TKContentIterator (t,cdata,t.getListIterator()));
133                 ceContext.fillIntoTemplate (t);
134
135                 evt.finishTemplate(t);
136                 return;
137                 
138             }
139             if (action.equalsIgnoreCase("NEW_ATTR"))
140             {
141                 String JavaDoc new_attr_id = evt.getParameter(PARAMETER, "NEW_ATTRIBUTE_ID");
142                 System.out.println("new_attr_id : " + new_attr_id);
143                 if (new_attr_id != null && new_attr_id.length() != 0 && Integer.parseInt(new_attr_id) != -1)
144                 {
145                     // erzeuge neues attributtable
146
TKContentAttributeTableData table = new TKContentAttributeTableData(cdata.content_id,Integer.parseInt(new_attr_id),"");
147                     
148                     TKQuery q = TKDBManager.newQuery(TKDBContentAttributePut.class);
149                     table.insertIntoQuery(q);
150                     q.execute();
151                     if (cdata.content_attribute == null)
152                         cdata.content_attribute = new TKVector();
153                     ResultSet rs = q.fetchResultSet();
154                     rs.next();
155                     cdata.content_attribute.add(new TKContentAttributeTableData(rs) );
156                         
157                     t.setListIterator (new TKContentIterator (t,cdata,t.getListIterator()));
158                     ceContext.fillIntoTemplate (t);
159
160                     evt.finishTemplate(t);
161                     return;
162                     
163                 }
164                 else
165                 {
166                     throw new TKUserException("Please chose an attribute-type first.",UserCodes.CHOSE_CONTENT_ATTRIBUTE, ErrorCodes.USER_SEVERITY, true, null);
167                 }
168             }
169             if (action.equalsIgnoreCase("SAVE_AND_CLOSE") || action.equalsIgnoreCase("CLOSE"))
170             {
171                 CEBrowseHandler.getInstance().handleEvent(evt);
172                 return;
173             }
174             
175             t.setListIterator (new TKContentIterator (t,cdata,t.getListIterator()));
176             ceContext.fillIntoTemplate (t);
177
178             evt.finishTemplate(t);
179         }
180         catch (Throwable JavaDoc e)
181         {
182             // TO DO : Analyze Exception !
183
throw WebmanExceptionHandler.getException(e);
184         }
185     }
186     
187     public boolean isHandler(TKEvent evt)
188     {
189         return evt.getName().equalsIgnoreCase("CE_CONTENT_ATTRIBUTES");
190     }
191 }
192
Popular Tags