1 package de.webman.generator; 2 3 import com.teamkonzept.lib.*; 4 import com.teamkonzept.webman.*; 5 6 import java.util.*; 7 import java.sql.*; 8 import org.apache.log4j.Category; 9 10 15 public class SiteReference 16 { 17 18 21 GeneratorContext context; 22 23 private static Category cat = Category.getInstance(SiteReference.class.getName()); 24 25 public final static int COMPONENT_TYPE_FREE = 1; 26 public final static int COMPONENT_TYPE_TYPED = 2; 27 28 public final static int INTEGRATION_TYPE_GROUP = 2; 29 public final static int INTEGRATION_TYPE_SINGLE = 3; 30 31 public final static int REF_TYPE_ABSOLUTE = 1; 32 public final static int REF_TYPE_RELATIVE = 2; 33 34 35 public SiteDocument src; 36 37 38 private String integrationShortName; 39 40 private int componentType; 41 42 private int integrationType; 43 44 private int referenceType; 45 46 private int presentationIdx; 47 51 private SiteNode destNode; 52 53 private String destShortName; 54 55 private String selectionType; 56 57 private String selectionData; 58 59 63 private int relDist; 64 65 69 private SiteDocument[] dest; 70 71 75 private String destContentSource; 76 77 78 85 public SiteReference( GeneratorContext context, ResultSet rs, SiteDocument doc ) 86 throws SQLException 87 { 88 this.context = context != null ? context : GeneratorContext.setup (); 89 90 src = doc; 91 dest = null; 92 93 integrationShortName = rs.getString( "INTEGRATION_SHORTNAME" ); 94 componentType = rs.getInt( "COMPONENT_TYPE" ); 95 integrationType = rs.getInt( "INTEGRATION_TYPE" ); 96 referenceType = rs.getInt( "REFERENCE_TYPE" ); 97 presentationIdx = rs.getInt( "PRESENTATION_COMPONENT_IDX" ); 98 destNode = this.context.siteNodes.getNode( rs.getInt( "DEST_SITE_NODE_ID" ) ); 99 destShortName = rs.getString( "DEST_SITE_NODE_DOC_SHORTNAME" ); 100 selectionType = rs.getString( "SELECTION_TYPE" ); 101 selectionData = rs.getString( "SELECTION_DATA" ); 102 103 if( referenceType == REF_TYPE_RELATIVE ) { 104 relDist = src.getAnchor().findDistance( destNode ); 105 } 106 } 107 108 117 public SiteReference( GeneratorContext context, SiteReference srcRef, SiteDocument doc ) 118 { 119 this.context = context != null ? context : GeneratorContext.setup (); 120 121 this.src = doc; 122 dest = null; 123 124 integrationShortName = srcRef.integrationShortName; 125 componentType = srcRef.componentType; 126 integrationType = srcRef.integrationType; 127 referenceType = srcRef.referenceType; 128 presentationIdx = srcRef.presentationIdx; 129 relDist = srcRef.relDist; 130 if( referenceType == REF_TYPE_RELATIVE ) { 131 destNode = doc.getAnchor(); 132 for( int i=relDist; i-- > 0; ) { 133 destNode = destNode.getParent(); 134 } 135 } 136 else { 137 destNode = srcRef.destNode; 138 } 139 destShortName = srcRef.destShortName; 140 141 selectionType = srcRef.selectionType; 142 selectionData = srcRef.selectionData; 143 } 144 145 public String path() 146 { 147 return src.path()+"."+integrationShortName; 148 } 149 150 public String getPath() 151 { 152 return src.getPath() + "/" + integrationShortName; 153 } 154 155 156 public String ctToString(int componentType) { 157 158 if (componentType == COMPONENT_TYPE_FREE) return "FREE"; 159 if (componentType == COMPONENT_TYPE_TYPED) return "TYPED"; 160 161 return "UNKNOWN"; 162 } 163 164 public String toString() 165 { 166 167 String result = 168 "<reference '"+path()+"'>"+ 169 " componentType = "+ctToString(componentType)+ 170 " integrationType = "+(integrationType==INTEGRATION_TYPE_GROUP?"GROUP":"SINGLE")+ 171 " referenceType = "+(referenceType==REF_TYPE_ABSOLUTE?"ABSOLUTE":"RELATIVE")+ 172 " presentationIdx = "+presentationIdx+ 173 " destNode = "+destNode.path()+ 174 " destShortName = "+destShortName+ 175 " selectionType = "+selectionType+ 176 ""; 177 178 if( dest != null ) { 179 result += " referenced Docs:"; 180 for( int i=0; i<dest.length; i++ ) { 181 result += " "+dest[i].path(); 182 } 183 } 184 return result+" </reference '"+path()+"'> "; 185 } 186 187 195 public void expand() 196 { 197 if( dest != null ) 198 { 199 return; 200 } 201 202 SiteNode[] destNodes = { destNode }; 204 if( selectionType != null ) 205 { 206 cat.debug( "["+context.siteReferences.getLevel()+"]"+"expand selection reference "+selectionType+" results: " ); 207 TKVector tmp = TKWMReferenceSelectorReg.getNodes( selectionType, selectionData, destNode.getId() ); 208 destNodes = new SiteNode[ tmp.size() ]; 209 for( int i=0; i<destNodes.length; i++ ) 210 { 211 destNodes[i] = context.siteNodes.getNode( ((Integer )tmp.get(i)).intValue() ); 212 if (destNodes[i] != null) 213 cat.debug( "["+context.siteReferences.getLevel()+"]"+" "+destNodes[i].getPath()+"."+destShortName+"," ); 214 } 215 } 216 else { 217 cat.debug( "["+context.siteReferences.getLevel()+"]"+"expand regular reference to "+destNode.getPath()+"."+destShortName ); 218 } 219 220 Vector temp = new Vector(); 222 223 for( int i=0; i < destNodes.length; i++ ) 225 { 226 SiteDocument doc = destNodes[i].getDocument( destShortName ); 227 if (doc != null) 228 temp.addElement(doc); 229 else 230 { 231 cat.warn( 232 "unmatched reference to document '"+destShortName 233 +"' of node '"+destNodes[i].path() 234 +"' in document '"+src.path()+"'" 235 ); 236 } 237 } 238 239 dest = new SiteDocument[ temp.size() ]; 241 temp.copyInto(dest); 242 for( int i=0; i < dest.length; i++ ) { 245 try { 246 if (dest[i] != null) 247 dest[i].expandReferences(); 248 } 249 catch( Throwable t ) { 250 cat.warn("could not expand subreferences of referenced document "+dest[i].path(), t ); 251 } 252 } 253 254 } 255 256 281 public boolean findMatchingContentSource() 282 { 283 destContentSource = null; 284 285 if( componentType == COMPONENT_TYPE_FREE ) 287 { 288 destContentSource = destShortName; 289 return true; 290 } 291 292 if( (integrationType == INTEGRATION_TYPE_GROUP) && (dest == null) || (dest.length == 0) ) 294 { 295 return false; 296 } 297 298 SiteDocument destDoc = dest[0]; 301 for (int count = 1; destDoc == null && count < dest.length; count++) 302 destDoc = dest[count]; 303 304 if( context.referenceTypes.isValidType( 306 src.getPresentationId(), 307 presentationIdx, 308 destDoc.getPresentationId () 309 ) ) 310 { 311 destContentSource = destShortName; 312 return true; 313 } 314 315 SiteNode destNode = destDoc.getAnchor(); 317 TKHashtable visitedDocs = new TKHashtable(); TKVector visitDocs = new TKVector(); visitedDocs.put( destDoc, "!" ); 320 visitDocs.addElement( destDoc ); while( visitDocs.size() > 0 ) 322 { 323 destDoc = (SiteDocument) visitDocs.firstElement(); 324 visitDocs.removeElementAt(0); 325 cat.debug("checking references in document"+destDoc.path() ); 326 327 Enumeration e = destDoc.getReferences().elements(); 329 while( e.hasMoreElements() ) 330 { 331 SiteReference theRef = (SiteReference) e.nextElement(); 332 if( theRef == null ) { 333 throw new Error ("got null reference in document "+destDoc.path() ); 334 } 335 336 if( theRef.dest == null ) { 337 throw new Error ("got null reference-destinations in reference "+theRef.integrationShortName+" of document "+destDoc.path() ); 338 } 339 340 if( theRef.dest.length == 0 ) { 341 cat.warn("got zero reference-destinations in reference "+theRef.integrationShortName+" of document "+destDoc.path() ); 342 continue; 343 } 344 345 SiteDocument refDoc = theRef.dest[0]; 347 if( refDoc.getAnchor() == destNode ) 349 { 350 if( context.referenceTypes.isValidType( 352 src.getPresentationId(), 353 presentationIdx, 354 refDoc.getPresentationId() 355 ) ) 356 { 357 destContentSource = refDoc.getShortName(); 358 return true; 359 } 360 if( ! visitedDocs.containsKey( refDoc ) ) 362 { 363 visitDocs.addElement( refDoc ); 364 visitedDocs.put( refDoc, "!" ); 365 } 366 } 367 } 368 } 369 throw new Error ( "no matching document for ref " + 370 integrationShortName + " of document " + 371 src.getShortName() + " in node " + destNode.getShortName() ); 372 } 373 374 378 public void addGenReference( TKHashtable result ) 379 { 380 result.put( integrationShortName, this ); 381 } 382 383 public String getIntegrationShortName() 384 { 385 return integrationShortName; 386 } 387 388 public SiteNode getDestinationNode() 389 { 390 return destNode; 391 } 392 393 public SiteDocument[] getDestinationDocuments() 394 { 395 return dest; 396 } 397 398 public String getDestinationShortName() 399 { 400 return destShortName; 401 } 402 403 public int getComponentType() 404 { 405 return componentType; 406 } 407 408 public String getSelectionType() 409 { 410 return selectionType; 411 } 412 413 public String getSelectionData() 414 { 415 return selectionData; 416 } 417 418 public int getIntegrationType() 419 { 420 return integrationType; 421 } 422 423 public String getDestinationContentSource() 424 { 425 return destContentSource; 427 } 428 } 429
| Popular Tags
|