1 package de.webman.duplication.eventhandler; 2 3 import com.teamkonzept.web.*; 4 import com.teamkonzept.webman.*; 5 import com.teamkonzept.webman.db.TKWebmanDBManager; 6 import com.teamkonzept.webman.mainint.*; 7 import com.teamkonzept.webman.mainint.db.*; 8 9 10 import com.teamkonzept.webman.mainint.db.queries.*; 11 import com.teamkonzept.webman.mainint.events.*; 12 import com.teamkonzept.lib.*; 13 import com.teamkonzept.db.*; 14 15 import java.sql.*; 16 import java.io.*; 17 import java.util.*; 18 19 import com.teamkonzept.webman.mainint.*; 20 21 22 public class DUOpenSiteTreeIterator implements TKListIterator { 23 24 TKListIterator oldIterator; 25 String listName; 26 TKDBResult dbResult; 27 int lastLeft = -1; 28 int lastRight = -1; 29 int destId = -1; 30 Stack parents; 31 int level; 32 int levels = 0; 33 int maxlevels; 34 35 public DUOpenSiteTreeIterator( TKDBResult dbResult, TKListIterator oldIterator, String listName, int maxlevels ) 36 { 37 this.oldIterator = oldIterator; 38 this.listName = listName; 39 this.dbResult = dbResult; 40 this.parents = new Stack(); 41 this.level = 0; 42 this.maxlevels = maxlevels; 43 } 44 45 public DUOpenSiteTreeIterator( TKDBResult dbResult, TKListIterator oldIterator, String listName, int destId, int maxlevels ) 46 { 47 this.oldIterator = oldIterator; 48 this.listName = listName; 49 this.dbResult = dbResult; 50 this.destId = destId; 51 this.parents = new Stack(); 52 this.level = 0; 53 this.maxlevels = maxlevels; 54 } 55 56 public boolean apply( TKTemplate template, int i, String currListName ) 57 { 58 if( currListName.equalsIgnoreCase( listName ) ) { 59 if( i >= dbResult.size() ) { 60 if( !parents.empty() ) parents.pop(); 61 level = 0; 62 lastLeft = -1; 63 lastRight = -1; 64 return false; 65 } 66 TKDBResultRow resultRow = (TKDBResultRow)(dbResult.get( i )); 67 if( !TKDBTemplate.prepareTemplate( resultRow,template ) ) return false; 68 try { 69 int myId = Integer.parseInt( (String ) resultRow.getColumn( "SITE_NODE_ID" ) ); 70 if( destId != -1 && myId == destId ) { 71 template.set( "IS_DESTINATION", Boolean.TRUE ); 72 } 73 int thisLeft = Integer.parseInt( (String ) resultRow.getColumn( "LEFT_NR" ) ); 74 int thisRight = Integer.parseInt( (String ) resultRow.getColumn( "RIGHT_NR" ) ); 75 String tmp = (String ) resultRow.getColumn( "SITE_NODE_PARENT" ); 76 int thisParent = ( tmp == null || tmp.equals("") )?myId:Integer.parseInt( tmp ); 77 78 String nodeId = (String ) resultRow.getColumn( "NODE_ID" ); 79 int thisPar = ( nodeId.equals("") )?myId+1:Integer.parseInt( nodeId ); 80 if( nodeId.equals("") ) { 81 template.set( "IS_LEAF", Boolean.TRUE ); 82 } 83 else if( thisPar == myId ) { 84 template.set( "IS_CLOSED", Boolean.TRUE ); 85 } 86 else { 87 template.set( "IS_OPEN", Boolean.TRUE ); 88 } 89 90 if( i == 0 ) template.set( "IS_ROOT", Boolean.TRUE ); 91 if( thisLeft > lastLeft && thisRight < lastRight ) { 92 parents.push( new Integer ( thisParent ) ); 93 level++; 94 } 95 else if( !parents.empty() ) { 96 if( !(parents.peek().equals( new Integer (thisParent))) ) { 101 while( !parents.empty() ) { 102 if( parents.pop().equals( new Integer ( thisParent )) ) { 103 parents.push( new Integer ( thisParent ) ); 104 break; 105 } 106 level--; 107 } 108 } 109 } 110 levels = level; 111 template.set( "LEVEL", new Integer ( level ) ); 112 template.set( "CURR_COLSPAN", new Integer ( maxlevels-level+1 ) ); 113 lastLeft = thisLeft; 114 lastRight = thisRight; 115 } 116 catch ( Throwable th ) { 117 throw new Error ( th.getMessage() ); 118 } 119 return true; 120 } 121 else if( currListName.equalsIgnoreCase( "ST_LEVELS" ) ) { 122 return (--levels >= 0); 123 } 124 else if( oldIterator != null ) { 125 return oldIterator.apply( template, i, currListName ); 126 } 127 else { 128 return false; 129 } 130 } 131 } 132 | Popular Tags |