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