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 16 public class ContentContext 17 { 18 19 private static Category cat = Category.getInstance(ContentContext.class); 20 21 private final static String DIVIDER = "$"; 22 23 private TKParams params; 24 private String event; 25 26 public String groupConNodeName; 27 public String groupConNodeShortName; 28 public String conNodeName; 29 public String conNodeShortName; 30 public String mode; 31 public String upbase; 32 public String filterMode; 33 public String instanceStatus; 34 public String sort_by; 35 36 public String searchString; 37 public String sortUpDown; 38 39 public String searchKennung; 40 public String conlist_start; 41 public String conlist_count; 42 43 private String navigationContext; 44 45 public Integer groupConNodeId; 46 public Integer conNodeId; 47 public Integer conNodeType; 48 public Integer formId; 49 public Integer instanceId; 50 public Integer versionId; 51 public Integer fromStatusId; 52 public Integer toStatusId; 53 public Integer 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 _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 getNavigationContext() 103 { 104 return navigationContext; 105 } 106 107 public ContentContext(String navContext) 108 { 109 this.navigationContext = navContext; 110 String newString = navContext.replace(DIVIDER.charAt(0), '\n'); 111 java.io.StringBufferInputStream stream = new java.io.StringBufferInputStream (newString); 112 Properties prop = new Properties(); 113 try 114 { 115 prop.load(stream); 116 } 117 catch (Exception e) 118 { 119 cat.error("",e); 120 } 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 (-1); 142 instanceId = new Integer (-1); 143 versionId = new Integer (-1); 144 } 145 146 150 public String 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 navContext) 191 { 192 return new ContentContext(navContext); 193 } 194 195 public String empty2Null (String str) { 196 197 return str != null && str.length() == 0 ? null : str; 198 } 199 200 public Integer string2Int (String str) { 201 202 return str == null || str.length() == 0 ? new Integer (-1) : new Integer (str); 203 } 204 205 public String int2String (int val) { 206 207 return Integer.toString(val); 208 } 209 210 public String getParam (String 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 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 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 toString () 259 { 260 261 StringBuffer buf = new StringBuffer (); 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 375 public void scanFields () 376 { 377 fieldLookup = new TKHashtable (); 378 if (cdata == null) cdata = new TKContentDBData (); 379 380 scanFields (fieldLookup,params.getClass ("PAR")); 381 } 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 name = (String ) e.nextElement(); 392 if (name == null) continue; 393 394 StringTokenizer tokenizer = new StringTokenizer(name,"."); 395 String path = ""; 396 397 while (tokenizer.hasMoreTokens()) 398 { 399 String fieldName = tokenizer.nextToken(); 400 if (fieldName == null) continue; 401 402 if (path.length() > 0) 403 { 404 String 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 encode(Object in) 422 { 423 return java.net.URLEncoder.encode(in.toString()); 424 } 425 426 427 public static String decode(String 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 e) 437 { 438 return null; 440 } 441 } 442 443 } 444 445 | Popular Tags |