KickJava   Java API By Example, From Geeks To Geeks.

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


1 package de.webman.content.eventhandler;
2
3 import com.teamkonzept.lib.*;
4 import com.teamkonzept.web.*;
5 import com.teamkonzept.field.*;
6 import com.teamkonzept.field.db.*;
7 import de.webman.content.workflow.*;
8 import org.apache.log4j.Category;
9 import java.util.*;
10
11 /**
12     haelt den aktuellen Zustand beim Browsen durch Templates
13  * @author $Author: sebastian $
14  * @version $Revision: 1.9 $
15 */

16 public class ContentContext
17 {
18     /** Logging Category */
19     private static Category cat = Category.getInstance(ContentContext.class);
20     
21     private final static String JavaDoc DIVIDER = "$";
22     
23     private TKParams params;
24     private String JavaDoc event;
25     
26     public String JavaDoc groupConNodeName;
27     public String JavaDoc groupConNodeShortName;
28     public String JavaDoc conNodeName;
29     public String JavaDoc conNodeShortName;
30     public String JavaDoc mode;
31     public String JavaDoc upbase;
32     public String JavaDoc filterMode;
33     public String JavaDoc instanceStatus;
34     public String JavaDoc sort_by;
35     /** searchstring */
36     public String JavaDoc searchString;
37     public String JavaDoc sortUpDown;
38     /** searchoption kennung */
39     public String JavaDoc searchKennung;
40     public String JavaDoc conlist_start;
41     public String JavaDoc conlist_count;
42     
43     private String JavaDoc navigationContext;
44     
45     public Integer JavaDoc groupConNodeId;
46     public Integer JavaDoc conNodeId;
47     public Integer JavaDoc conNodeType;
48     public Integer JavaDoc formId;
49     public Integer JavaDoc instanceId;
50     public Integer JavaDoc versionId;
51     public Integer JavaDoc fromStatusId;
52     public Integer JavaDoc toStatusId;
53     public Integer JavaDoc filterId;
54     
55     public boolean subtree;
56     
57     public TKHashtable fieldLookup;
58     public TKContentDBData cdata;
59     
60     public TKVector diagnostics;
61
62     public ContentContext (TKParams _params, String JavaDoc _event)
63     {
64         event = _event;
65         params = _params;
66         diagnostics = new TKVector();
67         
68         navigationContext = getParam ( "NAVIGATION_CONTEXT");
69         groupConNodeName = getParam ( "GROUP_CONTENT_NODE_NAME" );
70         groupConNodeShortName = getParam ( "GROUP_CONTENT_NODE_SHORTNAME" );
71         conNodeName = getParam ( "CONTENT_NODE_NAME" );
72         conNodeShortName = getParam ( "CONTENT_NODE_SHORTNAME" );
73         filterMode = getParam ( "FILTER_MODE" );
74         mode = getParam ( "MODE" );
75         upbase = getParam ( "UPBASE" );
76         instanceStatus = getParam ( "INSTANCE_STATUS" );
77
78         groupConNodeId = string2Int (getParam ( "GROUP_CONTENT_NODE_ID" ));
79         conNodeId = string2Int (getParam ( "CONTENT_NODE_ID" ));
80         conNodeType = string2Int (getParam ( "CONTENT_NODE_TYPE" ));
81         formId = string2Int (getParam ( "CONTENT_FORM" ));
82         instanceId = string2Int (getParam ( "INSTANCE_ID" ));
83         versionId = string2Int ( getParam ( "VERSION_ID" ));
84         fromStatusId = string2Int (getParam ( "FROM_STATUS_ID" ));
85         toStatusId = string2Int (getParam ( "TO_STATUS_ID" ));
86         filterId = string2Int (getParam ( "FILTER_ID" ));
87
88         sort_by = getParam ( "SORT_BY" );
89         searchString = getParam ( "SEARCHSTRING" );
90         sortUpDown = getParam ( "SORT_UP_DOWN" );
91         searchKennung = getParam ( "S_KENNUNG" );
92         conlist_start = getParam ( "CONLIST_START" );
93         conlist_count = getParam ( "CONLIST_COUNT" );
94         subtree = getParam("SUBTREE") != null;
95     }
96     
97     public ContentContext (TKParams params) {
98     
99         this (params,null);
100     }
101
102     public String JavaDoc getNavigationContext()
103     {
104         return navigationContext;
105     }
106     
107     public ContentContext(String JavaDoc navContext)
108     {
109         this.navigationContext = navContext;
110         String JavaDoc newString = navContext.replace(DIVIDER.charAt(0), '\n');
111         java.io.StringBufferInputStream JavaDoc stream = new java.io.StringBufferInputStream JavaDoc(newString);
112         Properties prop = new Properties();
113         try
114         {
115             prop.load(stream);
116         }
117         catch (Exception JavaDoc e)
118         {
119             cat.error("",e);
120             // kann nicht passieren
121
}
122         conNodeName = decode(prop.getProperty("CONTENT_NODE_NAME"));
123         conNodeShortName = decode(prop.getProperty("CONTENT_NODE_SHORTNAME"));
124         groupConNodeName = decode(prop.getProperty("GROUP_CONTENT_NODE_NAME"));
125         groupConNodeShortName = decode(prop.getProperty("GROUP_CONTENT_NODE_SHORTNAME"));
126
127         conNodeId = string2Int (decode(prop.getProperty("CONTENT_NODE_ID")));
128         conNodeType = string2Int (decode(prop.getProperty("CONTENT_NODE_TYPE")));
129         filterId = string2Int (decode(prop.getProperty("FILTER_ID")));
130         groupConNodeId = string2Int (decode(prop.getProperty("GROUP_CONTENT_NODE_ID")));
131         formId = string2Int (decode(prop.getProperty("CONTENT_FORM")));
132         
133         sort_by = decode(prop.getProperty( "SORT_BY" ));
134         searchString = decode(prop.getProperty("SEARCHSTRING" ));
135         sortUpDown = decode(prop.getProperty("SORT_UP_DOWN" ));
136         searchKennung = decode(prop.getProperty( "S_KENNUNG" ));
137         conlist_start = decode(prop.getProperty( "CONLIST_START" ));
138         conlist_count = decode(prop.getProperty( "CONLIST_COUNT" ));
139         subtree = decode(prop.getProperty( "SUBTREE" ))!= null;
140         
141         toStatusId = new Integer JavaDoc(-1);
142         instanceId = new Integer JavaDoc(-1);
143         versionId = new Integer JavaDoc(-1);
144     }
145     
146     /**
147         ermittelt den NavContext
148         Wertpaare werden nicht durch & sondern durch % getrennt
149     */

150     public String JavaDoc calculateNavContext()
151     {
152         navigationContext = "";
153         if (conNodeId.intValue() != -1)
154             navigationContext += "CONTENT_NODE_ID=" + encode(conNodeId) + DIVIDER;
155         if (conNodeType.intValue() != -1)
156             navigationContext += "CONTENT_NODE_TYPE=" + encode(conNodeType) + DIVIDER;
157         if (conNodeName != null)
158             navigationContext += "CONTENT_NODE_NAME=" + encode(conNodeName)+ DIVIDER;
159         if (conNodeShortName != null)
160             navigationContext += "CONTENT_NODE_SHORTNAME=" + encode(conNodeShortName) + DIVIDER;
161         if (groupConNodeId.intValue() != -1)
162             navigationContext += "GROUP_CONTENT_NODE_ID=" + encode(groupConNodeId) + DIVIDER;
163         if (groupConNodeName != null)
164             navigationContext += "GROUP_CONTENT_NODE_NAME=" + encode(groupConNodeName) + DIVIDER;
165         if (groupConNodeShortName != null)
166             navigationContext += "GROUP_CONTENT_NODE_SHORTNAME=" + encode(groupConNodeShortName) + DIVIDER;
167         if (formId.intValue() != -1)
168             navigationContext += "CONTENT_FORM=" + encode(formId) + DIVIDER;
169         if (filterId.intValue() != -1)
170             navigationContext += "FILTER_ID=" + encode(filterId) + DIVIDER;
171         if (subtree)
172             navigationContext += "SUBTREE=1" + DIVIDER;
173         if (searchString != null)
174             navigationContext += "SEARCHSTRING=" + encode(searchString) + DIVIDER;
175         if (sort_by != null)
176             navigationContext += "SORT_BY=" + encode(sort_by) + DIVIDER;
177         if (sortUpDown != null)
178             navigationContext += "SORT_UP_DOWN=" + encode(sortUpDown) + DIVIDER;
179         if (conlist_start != null)
180             navigationContext += "CONLIST_START=" + encode(conlist_start) + DIVIDER;
181         if (conlist_count != null)
182             navigationContext += "CONLIST_COUNT=" + encode(conlist_count) + DIVIDER;
183                 
184         if (searchKennung != null)
185             navigationContext += "S_KENNUNG=" + encode(searchKennung);
186         
187         return navigationContext;
188     }
189     
190     public static ContentContext reCalculateContext(String JavaDoc navContext)
191     {
192         return new ContentContext(navContext);
193     }
194     
195     public String JavaDoc empty2Null (String JavaDoc str) {
196
197         return str != null && str.length() == 0 ? null : str;
198     }
199
200     public Integer JavaDoc string2Int (String JavaDoc str) {
201     
202         return str == null || str.length() == 0 ? new Integer JavaDoc(-1) : new Integer JavaDoc(str);
203     }
204     
205     public String JavaDoc int2String (int val) {
206
207         return Integer.toString(val);
208     }
209
210     public String JavaDoc getParam (String JavaDoc name) {
211
212         return empty2Null(
213             params.hasMultiple ("PAR",name ) ? params.get ("PAR",name,0) : params.get ("PAR",name)
214         );
215     }
216
217     public void fillIntoTemplate (TemplateBasic t) throws Throwable JavaDoc
218     {
219         if (groupConNodeId.intValue() != -1) t.set("GROUP_CONTENT_NODE_ID",groupConNodeId);
220         if (conNodeId.intValue() != -1) t.set("CONTENT_NODE_ID",conNodeId);
221         if (conNodeType.intValue() != -1) t.set("CONTENT_NODE_TYPE",conNodeType);
222         if (formId.intValue() != -1) t.set("CONTENT_FORM", formId);
223         if (instanceId.intValue() != -1) t.set("INSTANCE_ID", instanceId);
224         if (versionId.intValue() != -1) t.set("VERSION_ID", versionId);
225         if (filterId.intValue() != -1) t.set("FILTER_ID", filterId);
226         if (navigationContext != null) t.set("NAVIGATION_CONTEXT", navigationContext);
227         if (groupConNodeName != null) t.set("GROUP_CONTENT_NODE_NAME",groupConNodeName);
228         if (groupConNodeShortName != null) t.set("GROUP_CONTENT_NODE_SHORTNAME",groupConNodeShortName);
229         if (conNodeName != null) t.set("CONTENT_NODE_NAME",conNodeName);
230         if (conNodeShortName != null) t.set("CONTENT_NODE_SHORTNAME",conNodeShortName);
231         if (mode != null) t.set("MODE",mode);
232         if (filterMode != null) t.set("FILTER_MODE",filterMode);
233         if (upbase != null) t.set("UPBASE",upbase);
234         if (instanceStatus != null) t.set("INSTANCE_STATUS",instanceStatus);
235         
236         if (toStatusId.intValue() >= 0)
237         {
238             // statische Daten der Versionsverwaltung abrufen
239
VersionStatics statics = VersionStatics.setup();
240             VersionStatus statusDesc = (VersionStatus) statics.getStatusPool().get(toStatusId);
241             if (statusDesc != null)
242             {
243                 t.set("TO_STATUS_ID",toStatusId);
244                 t.set("TO_STATUS",statusDesc.getName());
245             }
246         }
247         if (searchString != null) t.set("SEARCHSTRING",searchString);
248         if (searchKennung != null) t.set("S_KENNUNG",searchKennung);
249         else t.set("S_KENNUNG","");
250         if (sort_by != null) t.set("SORT_BY",sort_by);
251         if (sortUpDown != null) t.set("SORT_UP_DOWN",sortUpDown);
252         if (conlist_start != null) t.set("CONLIST_START",conlist_start);
253         if (conlist_count != null) t.set("CONLIST_COUNT",conlist_count);
254         if (subtree)
255             t.set("SUBTREE","1");
256     }
257     
258     public String JavaDoc toString ()
259     {
260     
261         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
262         
263         if (groupConNodeId != null) buf.append (" GROUP_CONTENT_NODE_ID="+groupConNodeId);
264         if (conNodeId != null) buf.append (" CONTENT_NODE_ID="+conNodeId);
265         if (conNodeType != null) buf.append (" CONTENT_NODE_TYPE="+conNodeType);
266         if (formId != null) buf.append (" CONTENT_FORM="+formId);
267         if (instanceId != null) buf.append (" INSTANCE_ID="+instanceId);
268         if (filterId != null) buf.append (" FILTER_ID="+filterId);
269         
270         if (groupConNodeName != null) buf.append (" GROUP_CONTENT_NODE_NAME="+groupConNodeName);
271         if (groupConNodeShortName != null) buf.append (" GROUP_CONTENT_NODE_SHORTNAME="+groupConNodeShortName);
272         if (conNodeName != null) buf.append (" CONTENT_NODE_NAME="+conNodeName);
273         if (conNodeShortName != null) buf.append (" CONTENT_NODE_SHORTNAME="+conNodeShortName);
274         if (upbase != null) buf.append (" UPBASE="+upbase);
275         if (instanceStatus != null) buf.append (" INSTANCE_STATUS="+instanceStatus);
276         if (navigationContext != null) buf.append( "NAVIGATION_CONTEXT=" + navigationContext);
277         return buf.toString();
278     }
279
280     /*
281     private void scanAttributes ()
282     {
283         String action = event == null ? null : params.get("ACTION",event);
284         String indexStr = event == null ? null : params.get("INDEX",event);
285         
286         TKHashtable subFieldLookup = (TKHashtable) fieldLookup.get("ATTRIBUTES");
287         TKHashtable attributes = new TKHashtable ();
288         boolean selectionMissing = false;
289         
290         Enumeration subFields = subFieldLookup != null ? subFieldLookup.keys() : null;
291         while ((subFields != null) && subFields.hasMoreElements())
292         {
293         
294             String sub = (String) subFields.nextElement();
295             if (sub == null) continue;
296             
297             if ((action != null) && (action.trim().equalsIgnoreCase("DELETE_ATTRIBUTE")) &&
298                 (indexStr != null) && (indexStr.trim().equals(sub.trim()))) continue;
299             
300             String attrFieldName = (String) subFieldLookup.get(sub);
301             if (attrFieldName == null) continue;
302
303             TKHashtable attrFieldLookup = (TKHashtable) fieldLookup.get(attrFieldName);
304             if (attrFieldLookup == null) continue;
305         
306             String sAttributeId = null;
307             String sAttributeNewId = null;
308             String value = null;
309
310             String fullPath = (String) attrFieldLookup.get("ATTRIBUTE_ID");
311             if (fullPath != null) sAttributeId = getParam(fullPath);
312
313             fullPath = (String) attrFieldLookup.get("NEW_ATTRIBUTE_ID");
314             if (fullPath != null) sAttributeNewId = getParam(fullPath);
315             
316             fullPath = (String) attrFieldLookup.get("ATTRIBUTE_VALUE");
317             if (fullPath != null) value = getParam(fullPath);
318             
319             Integer attributeId = string2Int (sAttributeId);
320             Integer attributeNewId = string2Int (sAttributeNewId);
321
322             if (attributeNewId.intValue() >= 0)
323             {
324                 TKContentAttributeOption option = TKContentAttributeOption.getOptionById (attributeNewId);
325                 if (attributes.get (new Integer (attributeNewId)) != null) {
326                     diagnostics.addElement ("Neues Attribut '"+option.name+"' doppelt");
327                     attributeId = attributeNewId;
328                 } else {
329                     attributeId = attributeNewId;
330                     attributes.put (new Integer (attributeNewId),option);
331                 }
332
333             } else if (attributeId >= 0)
334             {
335                 TKContentAttributeOption option = TKContentAttributeOption.getOptionById (attributeId);
336                 if (attributes.get (new Integer (attributeId)) != null) {
337                     diagnostics.addElement ("Attribut '"+option.name+"' doppelt");
338                 } else {
339                     attributes.put (new Integer (attributeId),option);
340                 }
341             }
342             
343             TKContentAttributeOption option = TKContentAttributeOption.getOptionById (attributeId);
344             String scannedValue = null;
345             
346             if (option == null) selectionMissing = true;
347             else
348             {
349                 try
350                 {
351                     scannedValue = TKContentAttributeTableData.scanValue (value,attributeId);
352                     value = scannedValue;
353                 
354                 } catch (Exception ex)
355                 {
356                     String msg = ex.getMessage();
357                     diagnostics.addElement ("Attribut '"+option.name+"' syntaktisch falsch"+(msg == null ? "" : ": "+msg));
358                 }
359             }
360             
361             cdata.content_attribute.addElement
362                 (new TKContentAttributeTableData (cdata.content_id,attributeId,value));
363         }
364         
365         if (action.trim().equalsIgnoreCase("NEW_ATTR"))
366         {
367             cdata.content_attribute.addElement
368                 (new TKContentAttributeTableData (cdata.content_id));
369             diagnostics.addElement ("Bitte Attribut auswählen");
370
371         } else if (selectionMissing) diagnostics.addElement ("Bitte Attribut auswählen");
372
373     }
374     */

375     public void scanFields ()
376     {
377         fieldLookup = new TKHashtable ();
378         if (cdata == null) cdata = new TKContentDBData ();
379
380         scanFields (fieldLookup,params.getClass ("PAR"));
381         // scanAttributes ();
382
}
383
384     public static void scanFields (TKHashtable fieldLookup, TKHashtable lookup)
385     {
386         if (lookup == null) return;
387         
388         Enumeration e = lookup.keys();
389         while ((e != null) && e.hasMoreElements())
390         {
391             String JavaDoc name = (String JavaDoc) e.nextElement();
392             if (name == null) continue;
393
394             StringTokenizer tokenizer = new StringTokenizer(name,".");
395             String JavaDoc path = "";
396             
397             while (tokenizer.hasMoreTokens())
398             {
399                 String JavaDoc fieldName = tokenizer.nextToken();
400                 if (fieldName == null) continue;
401
402                 if (path.length() > 0)
403                 {
404                     String JavaDoc fullPath = path+"."+fieldName;
405                     TKHashtable subFields = (TKHashtable) fieldLookup.get(path);
406
407                     if (subFields == null)
408                     {
409                         subFields = new TKHashtable();
410                         fieldLookup.put(path,subFields);
411                     }
412
413                     subFields.put(fieldName,fullPath);
414                     path = fullPath;
415
416                 } else path = fieldName;
417             }
418         }
419     }
420     
421     public static String JavaDoc encode(Object JavaDoc in)
422     {
423         return java.net.URLEncoder.encode(in.toString());
424     }
425     
426     
427     public static String JavaDoc decode(String JavaDoc in)
428     {
429         try
430         {
431             if (in == null)
432                 return null;
433             else
434                 return java.net.URLDecoder.decode(in);
435         }
436         catch (Exception JavaDoc e)
437         {
438             // Wozu das hier steht weiss ich nicht, der Siegfried Compiler zwingt mich dazu
439
return null;
440         }
441     }
442     
443 }
444
445
Popular Tags