1 18 19 package org.apache.struts.taglib.tiles; 20 21 import java.util.ArrayList ; 22 import java.util.List ; 23 24 import javax.servlet.jsp.JspException ; 25 import javax.servlet.jsp.tagext.TagSupport ; 26 27 import org.apache.struts.tiles.AttributeDefinition; 28 import org.apache.struts.tiles.UntypedAttribute; 29 30 33 public class PutListTag 34 extends TagSupport 35 implements ComponentConstants, AddTagParent, PutListTagParent { 36 37 40 private String attributeName = null; 41 42 45 private List list = null; 46 47 50 private String role = null; 51 52 55 public PutListTag() { 56 super(); 57 } 58 59 62 public void release() { 63 super.release(); 64 attributeName = null; 65 role = null; 66 } 67 68 71 protected void releaseInternal() { 72 list = null; 73 } 74 75 78 public void setName(String name) { 79 this.attributeName = name; 80 } 81 82 85 public String getName() { 86 return attributeName; 87 } 88 89 93 public void setRole(String role) { 94 this.role = role; 95 } 96 97 100 public String getRole() { 101 return role; 102 } 103 104 107 public List getList() { 108 return list; 109 } 110 111 114 public void addElement(Object value) { 115 if (list == null) { 116 list = new ArrayList (); 117 } 118 119 list.add(value); 120 } 121 122 129 public void processNestedTag(PutListTag nestedTag) throws JspException { 130 Object attributeValue = nestedTag.getList(); 134 135 if (nestedTag.getRole() != null) { 136 AttributeDefinition def = new UntypedAttribute(attributeValue); 137 def.setRole(nestedTag.getRole()); 138 attributeValue = def; 139 } 140 141 addElement(attributeValue); 143 } 144 145 152 public void processNestedTag(AddTag nestedTag) throws JspException { 153 Object attributeValue = nestedTag.getRealValue(); 157 AttributeDefinition def; 158 159 if (nestedTag.getRole() != null) { 160 try { 161 def = ((AttributeDefinition) attributeValue); 162 } catch (ClassCastException ex) { 163 def = new UntypedAttribute(attributeValue); 164 } 165 def.setRole(nestedTag.getRole()); 166 attributeValue = def; 167 } 168 169 addElement(attributeValue); 171 } 172 173 176 public int doStartTag() throws JspException { 177 return EVAL_BODY_INCLUDE; 178 } 179 180 183 public int doEndTag() throws JspException { 184 PutListTagParent enclosingParent = findEnclosingParent(); 185 enclosingParent.processNestedTag(this); 186 releaseInternal(); 188 return EVAL_PAGE; 189 } 190 191 195 protected PutListTagParent findEnclosingParent() throws JspException { 196 try { 197 PutListTagParent parent = 198 (PutListTagParent) findAncestorWithClass(this, 199 PutListTagParent.class); 200 201 if (parent == null) { 202 throw new JspException ("Error - tag putList : enclosing tag doesn't accept 'putList' tag."); 203 } 204 205 return parent; 206 207 } catch (ClassCastException ex) { 208 throw new JspException ("Error - tag putList : enclosing tag doesn't accept 'putList' tag."); 209 } 210 } 211 212 } 213 | Popular Tags |