1 package de.webman.generator; 2 3 import com.teamkonzept.db.*; 4 import com.teamkonzept.lib.*; 5 import com.teamkonzept.webman.db.*; 6 import de.webman.generator.db.queries.*; 7 8 import java.sql.*; 9 import java.util.*; 10 import org.apache.log4j.Category; 11 12 18 public class SiteNodeStatics 19 { 20 21 24 GeneratorContext context; 25 26 27 private TKHashtable nodeHash; 28 29 30 private SiteNode root; 31 32 33 private static Category cat = Category.getInstance(SiteNodeStatics.class.getName()); 34 35 private boolean reducedBuild; 38 private boolean indexBuild; 39 40 private int subtreeId; 42 private String subtreePath; 43 private String includeSubtreePath; 44 private SiteNode subtreeNode; 45 46 public SiteNodeStatics (GeneratorContext context) { 47 48 this.context = context != null ? context : GeneratorContext.setup (); 49 50 this.nodeHash = null; 51 this.root = null; 52 this.reducedBuild = false; 53 this.indexBuild = false; 54 55 this.subtreeId = -1; 56 this.subtreePath = null; 57 this.includeSubtreePath = null; 58 this.subtreeNode = null; 59 } 60 61 public boolean isReducedBuild() 62 { 63 return reducedBuild; 64 } 65 66 public boolean isIndexBuild() 67 { 68 return indexBuild; 69 } 70 71 public void setReducedBuild(boolean isReduced) 72 { 73 reducedBuild = isReduced; 74 } 75 76 public void setIndexBuild(boolean isIndex) 77 { 78 indexBuild = isIndex; 79 } 80 81 public String getIncludeSubtreePath() 82 { 83 return includeSubtreePath; 84 } 85 86 public void setIncludeSubtreePath(String subPath) 87 { 88 includeSubtreePath = subPath; 89 } 90 91 public String getSubtreePath() 92 { 93 return subtreePath; 94 } 95 96 public void setSubtreePath(String path) 97 { 98 subtreePath = path; 99 } 100 101 public SiteNode getSubtreeNode() 102 { 103 return subtreeNode; 104 } 105 106 public void setSubtreeNode(SiteNode node) 107 { 108 subtreeNode = node; 109 } 110 111 public int getSubtreeId() 112 { 113 return subtreeId; 114 } 115 116 public void setSubtreeId(int id) 117 { 118 subtreeId = id; 119 } 120 121 126 public boolean subTreeUnmatched () { 127 128 return ((subtreePath != null) || (subtreeId >= 0)) && (subtreeNode == null); 129 } 130 131 135 public SiteNode buildSiteTree() 136 { 137 SiteNode root; 138 cat.info("start build Site-Structure"); 139 140 context.contentNodes.getContents(); 142 cat.debug("got Contents"); 143 144 context.integrations.initSelection(); 145 146 context.referenceTypes.getTypes(); 148 149 try 152 { 153 TKQuery q = TKWebmanDBManager.newQuery(GenSiteTree.class); 154 q.execute(); 155 ResultSet rs = q.fetchResultSet(); 156 if( !rs.next() ) return null; 157 158 nodeHash = new TKHashtable(); 159 160 root = new SiteNode( context, rs, null ); 161 SiteNode last = root; 162 nodeHash.put( new Integer ( root.getId() ), root ); 163 while( rs.next() ) { 164 last = new SiteNode( context, rs, last ); 165 166 if ((subtreeNode != null) && (last.getParent().getId() == subtreeNode.getParent().getId()) && 168 (last.getId() != subtreeNode.getId())) break; 169 170 if (!subTreeUnmatched ()) 171 nodeHash.put( new Integer ( last.getId() ), last ); 172 } 173 if (subTreeUnmatched ()) return null; 174 175 SiteNode node = subtreeNode; 178 while (node != null) { 179 180 SiteNode parent = node.getParent(); 181 if (parent == null) break; 182 183 parent.getChilds().removeAllElements(); 184 parent.getChilds().addElement(node); 185 nodeHash.put( new Integer ( parent.getId() ), parent ); 186 187 node = parent; 188 } 189 190 root.readDocuments(); 192 cat.debug("got documents"); 193 194 if (indexBuild) 195 { 196 root.getContentIntegrations(); 198 cat.debug("got integrations"); 199 root.doContentSelections(); 200 cat.debug("did selections"); 201 return root; 202 } 203 root.readReferences(); 205 cat.debug("got refs"); 206 207 root.readStructureContents(); 209 cat.debug("got structure contents"); 210 211 root.getContentIntegrations(); 213 214 cat.debug("got integrations"); 215 216 root.assignInheritableDocuments(); 218 219 cat.debug("got inheritance"); 220 cat.debug("Reduced Build : " + reducedBuild); 221 if (reducedBuild) return root; 222 223 root.expandReferences(); 225 cat.debug("refs expanded"); 226 227 root.findReferenceContentDocuments(); 229 cat.debug("got referenced contents"); 230 231 root.doContentSelections(); 233 cat.debug("Site-Structure finished"); 234 } 235 catch( SQLException e ) 236 { 237 throw new TKSQLError( e.getMessage(), e ); 238 } 239 finally 240 { 241 try 242 { 243 if (TKDBManager.getDBVendor() == QueryConstants.ORACLE) 244 TKDBManager.closeConnection(); 245 } 246 catch (Exception e) 247 { 248 cat.error("Oracle spezial", e); 249 } 250 } 251 return root; 252 } 253 254 267 public void completeSiteTree(SiteNode root) 268 { 269 try { 270 if (!indexBuild) return; 271 272 root.readReferences(); 273 root.readStructureContents(); 274 root.assignInheritableDocuments(); 275 276 if (reducedBuild) return; 277 278 root.expandReferences(); 279 root.findReferenceContentDocuments(); 280 root.doContentSelections(); 281 } 282 catch( SQLException e ) 283 { 284 throw new TKSQLError( e.getMessage(), e ); 285 } 286 287 } 288 289 public SiteNode getRoot() 290 { 291 return root; 292 } 293 294 public void setRoot(SiteNode node) 295 { 296 root = node; 297 } 298 299 public Enumeration getAllNodes() 300 { 301 return nodeHash.keys(); 302 } 303 304 public SiteNode getNode( int nodeId ) 305 { 306 return (SiteNode) nodeHash.get( new Integer ( nodeId ) ); 307 } 308 } 309
| Popular Tags
|