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