1 7 package org.ejtools.servlet.http.jsp.tagext.tree; 8 9 import java.beans.beancontext.BeanContext ; 10 import java.util.Collection ; 11 import java.util.Iterator ; 12 import java.util.Vector ; 13 14 import javax.servlet.jsp.JspException ; 15 import javax.servlet.jsp.tagext.TagSupport ; 16 17 import org.apache.struts.util.RequestUtils; 18 19 20 29 public class BeanContextTreeTag extends TagSupport 30 { 31 32 protected String id = null; 33 34 protected boolean ignore = false; 35 36 protected String name = null; 37 38 protected String property = null; 39 40 protected String scope = null; 41 42 43 49 public int doStartTag() 50 throws JspException 51 { 52 BeanContext context = null; 54 55 if (property != null) 56 { 57 context = (BeanContext ) RequestUtils.lookup(pageContext, name, property, scope); 58 } 59 else 60 { 61 context = (BeanContext ) RequestUtils.lookup(pageContext, name, scope); 62 } 63 64 if (ignore) 65 { 66 if (context == null) 67 { 68 return (SKIP_BODY); 69 } 70 } 72 73 Collection collection = populate(context, ""); 75 pageContext.setAttribute(id, collection); 76 77 return (SKIP_BODY); 79 } 80 81 82 90 public String getId() 91 { 92 return (this.id); 93 } 94 95 96 104 public boolean getIgnore() 105 { 106 return (this.ignore); 107 } 108 109 110 118 public String getName() 119 { 120 return (this.name); 121 } 122 123 124 132 public String getProperty() 133 { 134 return (this.property); 135 } 136 137 138 146 public String getScope() 147 { 148 return (this.scope); 149 } 150 151 152 153 public void release() 154 { 155 super.release(); 156 ignore = false; 157 name = null; 158 property = null; 159 scope = null; 160 id = null; 161 } 162 163 164 169 public void setId(String id) 170 { 171 this.id = id; 172 } 173 174 175 180 public void setIgnore(boolean ignore) 181 { 182 this.ignore = ignore; 183 } 184 185 186 191 public void setName(String name) 192 { 193 this.name = name; 194 } 195 196 197 202 public void setProperty(String property) 203 { 204 this.property = property; 205 } 206 207 208 213 public void setScope(String scope) 214 { 215 this.scope = scope; 216 } 217 218 219 226 protected Collection populate(BeanContext context, String depth) 227 { 228 String newDepth = depth; 229 Collection result = new Vector (); 230 231 Iterator it = context.iterator(); 232 while (it.hasNext()) 233 { 234 BeanContext bc = (BeanContext ) it.next(); 235 IndentedObject o = new IndentedObject(); 236 o.setObject(bc); 237 o.setDepth(depth); 238 if (it.hasNext()) 239 { 240 newDepth = depth + "1"; 241 } 242 else 243 { 244 newDepth = depth + "0"; 245 o.setLast(true); 246 } 247 result.add(o); 248 249 Collection collection = populate(bc, newDepth); 250 result.addAll(collection); 251 } 252 return result; 253 } 254 } 255 | Popular Tags |