1 package com.teamkonzept.webman.field; 2 3 import com.teamkonzept.webman.mainint.*; 4 import de.webman.content.eventhandler.CEUtils; 6 import de.webman.content.workflow.*; 7 import de.webman.content.*; 8 import com.teamkonzept.lib.*; 9 import com.teamkonzept.publishing.markups.*; 10 import com.teamkonzept.web.*; 11 import com.teamkonzept.field.db.queries.*; 12 import com.teamkonzept.field.db.*; 13 import com.teamkonzept.db.*; 14 import com.teamkonzept.field.*; 15 import de.webman.generator.*; 16 import de.webman.util.log4j.WebmanCategory; 17 import com.teamkonzept.webman.mainint.db.queries.*; 18 import com.teamkonzept.webman.mainint.DatabaseDefaults; 19 import java.sql.*; 20 import java.util.*; 21 import com.teamkonzept.international.LanguageManager; 22 import org.w3c.dom.*; 23 import org.apache.log4j.Category; 24 25 31 public class TKContentSiteReferenceField 32 extends TKAtomField 33 { 34 35 38 public static final String CLASS_ID = "SITE_CONTENT_REF"; 39 40 43 public static final String FORM_KEY = "FORM"; 44 public static final String PRESENTATION_KEY = "PRESENTATION"; 45 public static final String NAME_ONLY_KEY = "NAME_ONLY"; 46 public static final String CONTENT_NODE = "CONTENT_NODE"; 47 48 49 public static final String YES_VALUE = "YES"; 50 public static final String NO_VALUE = "NO"; 51 52 55 public static final int WIDTH_ONE = 16; 56 57 60 public static final int WIDTH_TWO = 80; 61 62 65 public static final int WIDTH_THREE = 50; 66 67 70 public static final int WIDTH_FOUR = 254; 71 72 75 private static WebmanCategory cat = (WebmanCategory)WebmanCategory.getInstance(TKContentSiteReferenceField.class); 76 77 78 protected int formularId; 79 80 81 protected int presentationId; 82 83 84 protected int instanceId; 85 86 87 protected boolean deliverOnlyNames = true; 88 89 92 public TKContentSiteReferenceField () 93 { 94 super(); 95 } 96 97 public TKContentSiteReferenceField( 98 String name, 99 int formId, 100 int presId, 101 String showName 102 ) 103 { 104 initField( CLASS_ID, name, formId, presId, showName ); 105 } 106 107 public final void initField( 108 String type, 109 String name, 110 int formId, 111 int presID, 112 String showName 113 ) 114 { 115 initAtomField( type, name, showName ); 116 this.formularId = formId; 117 this.presentationId = presID; 118 } 119 120 123 public TKFieldGroup getDefGroup(TKFieldSwitch allSwitch, TKFieldSwitchList allSwitchList) 124 { 125 TKVector multipleOptions = new TKVector(2); 126 multipleOptions.addElement( new TKOptionFieldEntry( LanguageManager.getText(LanguageManager.GENERAL, "YES"), YES_VALUE ) ); 127 multipleOptions.addElement( new TKOptionFieldEntry( LanguageManager.getText(LanguageManager.GENERAL, "NO"), NO_VALUE ) ); 128 129 TKBaseField [] inputArray = { 130 new TKInputField( NAME_KEY, WIDTH_ONE, WIDTH_TWO, LanguageManager.getText(LANGUAGE_CONTEXT, "CONTENT_SITE_REF_NAME"), TKInputField.CHECK_STRING), 131 new TKInputField( SHOW_NAME_KEY, WIDTH_THREE, WIDTH_FOUR, LanguageManager.getText(LANGUAGE_CONTEXT, "CONTENT_SITE_REF_SHOWNAME"), TKInputField.CHECK_STRING), 132 new TKFormTypeSelectorField( FORM_KEY, LanguageManager.getText(LANGUAGE_CONTEXT, "CONTENT_REF_FORM"), TKFormTypeSelectorField.CONTENT_FORM_TYPE), 133 new TKDocumentTypeSelectorField( PRESENTATION_KEY, LanguageManager.getText(LANGUAGE_CONTEXT, "CONTENT_REF_PRES") ), 134 new TKCheckField( NAME_ONLY_KEY, LanguageManager.getText(LANGUAGE_CONTEXT, "CONTENT_REF_NAME_ONLY"), multipleOptions, false ) 135 }; 136 TKFieldGroup inputGroup = 137 new TKFieldGroup( CLASS_ID, new TKVector( inputArray ), LanguageManager.getText(LANGUAGE_CONTEXT, CLASS_ID) ); 138 139 return inputGroup; 140 } 141 142 145 public void init( String classId, Object initData ) 146 throws 147 TKUnregisteredClassException, 148 ClassNotFoundException , 149 InstantiationException , 150 IllegalAccessException 151 { 152 super.init( classId, initData ); 153 TKHashtable data = (TKHashtable) initData; 154 formularId = Integer.parseInt( (String ) data.get(FORM_KEY) ); 155 presentationId = Integer.parseInt( (String ) data.get(PRESENTATION_KEY) ); 156 deliverOnlyNames = ((String )data.get(NAME_ONLY_KEY)).equals( YES_VALUE ); 157 } 158 159 164 public Object toData () 165 { 166 TKHashtable result = (TKHashtable) super.toData(); 167 result.put( FORM_KEY, String.valueOf( formularId ) ); 168 result.put( PRESENTATION_KEY, String.valueOf( presentationId ) ); 169 result.put( NAME_ONLY_KEY, ( deliverOnlyNames ? YES_VALUE : NO_VALUE ) ); 170 return result; 171 } 172 173 180 public void fillIntoTemplate (TKHTMLTemplate template, 181 Object value, 182 String prefix) 183 { 184 try 185 { 186 super.fillIntoTemplate(template, value, prefix); 187 188 VersionStatics statics = VersionStatics.setup(); 190 TKHashtable statusPool = VersionStatus.selectSingles(statics, false); 191 TKHashtable filter = VersionSelection.initContentFilter(statusPool); 192 TKVector filteredInstances = new TKVector(); 193 194 TKQuery query = TKDBManager.newQuery(TKDBContentTreeGetFormType2.class); 196 query.setQueryParams("CONTENT_NODE_TYPE", DatabaseDefaults.SINGLE_INTEGER); 197 query.setQueryParams("CONTENT_FORM", new Integer (this.formularId)); 198 query.execute(); 199 200 ResultSet result = query.fetchResultSet(); 201 202 while (result.next()) 203 { 204 Content content = VersionCache.getContentInfo(new Integer (result.getInt("CONTENT_NODE_ID"))); 206 207 if (content != null && content.filterTransitions(filter, "SRC")) 208 { 209 TKHashtable entry = new TKHashtable(); 210 entry.put("INSTANCE_ID", content.getInstanceId()); 211 entry.put("CONTENT_NODE_NAME", content.getName()); 212 213 filteredInstances.addElement(entry); 214 } 215 } 216 217 template.setListIterator(new TKStandardPluginIterator(prefix + getName(), 219 null, 220 filteredInstances, 221 false, 222 template.getListIterator())); 223 } 224 catch (Exception e) 225 { 226 cat.error(e); 227 } 228 } 229 230 231 public void fillIntoPresentation( TKHTMLTemplate t, Object data, String scope ) 232 { 233 String scopedName = scope+"."+getName(); 234 Vector daten = getInformations(data); 235 if (daten != null) 236 { 237 t.set(scopedName + ".REF", daten.elementAt(0)); 238 t.set(scopedName + ".CONTENT_NAME", daten.elementAt(1)); 239 t.set(scopedName + ".DOC", daten.elementAt(2)); 240 t.set(scopedName + ".REF_NODE_PATH", daten.elementAt(4)); 241 if (!deliverOnlyNames) { 242 GeneratorContext context = GeneratorContext.setup (); 243 try { 244 context.push(); 245 246 SiteContent sc = (SiteContent)daten.elementAt(3); 247 if (!ReferenceCycleDetector.isCycle(new Integer (sc.getInstanceId()))) { 248 sc.fillNameIntoTemplate(t, scopedName); 249 sc.fillIntoTemplate(t, scopedName); 250 } 251 } 252 finally { 253 context.pop(); 254 } 255 } 256 } 257 } 258 259 269 private Vector getInformations(Object data) 270 { 271 if (data == null || data.equals("")) 272 return null; 273 Integer instanceID = new Integer ((String )data); 274 if (instanceID.intValue() == 0) 276 return null; 277 GeneratorContext context = GeneratorContext.setup (); 279 context.contentCalls.setup(); 280 281 SiteContent sc = null; 282 sc = (SiteContent) context.siteContents.getContent(instanceID.intValue()); 283 if (sc == null) 284 { 285 cat.error("Content of site reference " + getName() + " is not referenced in the Site-structure - content site reference not generated!"); 286 return null; } 288 Vector back = new Vector(); 289 290 291 TKVector list = context.contentCalls.getCalls(instanceID); 292 if (list == null) 293 { 294 cat.error("No Contents of site reference " + getName() + 295 " are released - site reference not generated!", WebmanCategory.ALL); 296 return null; } 298 ContentCall match = null; 299 300 for (int i = 0; i < list.size(); i++) 302 { 303 ContentCall dummy = (ContentCall)list.elementAt(i); 304 if (dummy.getDocument().getPresentationId() == presentationId && !dummy.isPerReference()) 305 { 306 match = dummy; 307 break; 308 } 309 } 310 311 if (match != null) 312 { 313 String path = match.getDocument().path(); 314 SiteNode node = match.getDocument().getAnchor(); 315 316 TKVector genNodes = node.getGenNodes(); 317 if (GeneratorContext.isPreviewMode()) 318 match.getDocument().complete(); 319 String docName = match.getDocument().getShortName(); 320 String contentName = sc.getShortName(); 321 path = node.getPath(); 322 String fullLink; 323 GenNode destNode = null; 324 330 if (GeneratorContext.isPreviewMode()) { 331 destNode = node.makeGenNode(sc); 332 } 333 else { 334 if (match.isPrimaryContent()) { 335 for (int i = 0; i < genNodes.size(); i++) { 336 destNode = (GenNode)genNodes.elementAt(i); 337 if (destNode.getPrimaryContent().getInstanceId() == instanceID.intValue()) { 338 break; 339 } 340 destNode = null; 341 } 342 } 343 else { 344 destNode = (GenNode)genNodes.elementAt(0); 345 } 346 } 347 if (GeneratorContext.isPreviewMode()) { 348 TKEvent evt = TKEvent.getEventForThread(); 349 String ownUrl = evt.getHttpInterface().getOwnURL(); 350 fullLink = ownUrl+"?TK_EV[CE_PREVIEW]=1"+ 352 "&TK_PAR[SNODE]="+node.getId()+ 353 "&TK_PAR[PID]="+instanceID+ 354 "&TK_PAR[DOCNAME]="+ docName + 355 "&TK_PAR[CHECKER]=1"; 356 back.addElement(fullLink); 357 back.addElement(contentName); 358 back.addElement(docName); back.addElement(sc); 360 back.addElement(""); return back; 362 } 363 364 if (destNode == null) 365 return null; 366 367 fullLink = destNode.getPath() + docName; 369 back.addElement(fullLink); 370 back.addElement(contentName); 371 back.addElement(docName); 372 back.addElement(sc); 373 back.addElement(destNode.getPath()); 374 return back; 375 } 376 cat.error("Did not found matching document type for " + getName() + " - site reference not generated!"); 377 378 return null; 379 } 380 383 public int insertDataIntoDB( TKContentDBData db, Object data, int contentId, int leftNr ) 384 { 385 return super.insertDataIntoDB(db, data, contentId, leftNr); 386 } 387 388 protected void fillDataIntoNode(Document doc, Element node, Object data) throws DOMException 389 { 390 Vector daten = getInformations(data); 391 if (daten != null) { 392 node.setAttribute("REF", (String )daten.elementAt(0)); 393 node.setAttribute("CONTENT_NAME", (String )daten.elementAt(1)); 394 node.setAttribute("DOC", (String )daten.elementAt(2)); 395 396 if (!deliverOnlyNames) { 397 Element me = doc.createElement("content"); 398 node.appendChild(me); 399 400 GeneratorContext context = GeneratorContext.setup (); 401 try { 402 context.push(); 403 SiteContent sc = (SiteContent)daten.elementAt(3); 404 if (!ReferenceCycleDetector.isCycle(new Integer (sc.getInstanceId()))) { 405 sc.fillBasicDOM(doc, me); 406 } 407 } 408 finally { 409 context.pop(); 410 } 411 } 412 node.setAttribute("REF_NODE_PATH", (String )daten.elementAt(4)); 413 } 414 } 415 416 public void initFromDB( String classId, TKFormDBData db, TKVector otherFields ) 417 throws 418 TKUnregisteredClassException, 419 ClassNotFoundException , 420 InstantiationException , 421 IllegalAccessException 422 { 423 super.initFromDB( classId, db, otherFields ); 424 formularId = Integer.parseInt( getFieldAttribute( db, FORM_KEY, 0 ) ); 425 presentationId = Integer.parseInt( getFieldAttribute( db, PRESENTATION_KEY, 0 ) ); 426 if (hasFieldAttribute(db, NAME_ONLY_KEY, 0)) 427 deliverOnlyNames= Boolean.valueOf(getFieldAttribute( db, NAME_ONLY_KEY, 0)).booleanValue(); 428 } 429 430 public int realInsertIntoDB( TKFormDBData db, int formId ) 431 { 432 if( super.realInsertIntoDB( db, formId ) == -1 ) return -1; 433 insertNewFieldAttribute( db, formId, FORM_KEY, 0, String.valueOf( formularId ) ); 434 insertNewFieldAttribute( db, formId, PRESENTATION_KEY, 0, String.valueOf( presentationId ) ); 435 insertNewFieldAttribute( db, formId, NAME_ONLY_KEY, 0, String.valueOf( deliverOnlyNames ) ); 436 437 return fieldId; 438 } 439 440 449 public boolean equals (Object object) 450 { 451 if (! super.equals(object)) 452 { 453 return false; 454 } 455 456 TKContentSiteReferenceField field = (TKContentSiteReferenceField) object; 457 458 return (this.formularId == field.formularId) && 459 (this.presentationId == field.presentationId) && 460 (this.instanceId == field.instanceId) && 461 (this.deliverOnlyNames == field.deliverOnlyNames); 462 } 463 464 469 public int hashCode () 470 { 471 return super.hashCode(); 473 } 474 475 } 476 | Popular Tags |