1 18 19 package org.apache.struts.taglib.tiles; 20 21 import javax.servlet.jsp.JspException ; 22 23 import org.apache.struts.taglib.tiles.util.TagUtils; 24 import org.apache.struts.tiles.AttributeDefinition; 25 import org.apache.struts.tiles.ComponentDefinition; 26 import org.apache.struts.tiles.UntypedAttribute; 27 28 35 public class DefinitionTag 36 extends DefinitionTagSupport 37 implements PutTagParent, PutListTagParent { 38 39 40 43 private String id = null; 44 45 48 private String scope = null; 49 50 53 private String extendsDefinition = null; 54 55 56 59 private ComponentDefinition definition = null; 60 61 65 public void release() { 66 super.release(); 67 id = null; 68 page = null; 69 scope = null; 70 role = null; 71 extendsDefinition = null; 72 } 73 74 77 protected void releaseInternal() { 78 definition = null; 79 } 80 81 86 public void putAttribute(String name, Object content) { 87 definition.putAttribute(name, content); 88 } 89 90 97 public void processNestedTag(PutTag nestedTag) throws JspException { 98 Object attributeValue = nestedTag.getRealValue(); 102 AttributeDefinition def; 103 104 if (nestedTag.getRole() != null) { 105 try { 106 def = ((AttributeDefinition) attributeValue); 107 } catch (ClassCastException ex) { 108 def = new UntypedAttribute(attributeValue); 109 } 110 def.setRole(nestedTag.getRole()); 111 attributeValue = def; 112 } 113 114 putAttribute(nestedTag.getName(), attributeValue); 116 } 117 118 125 public void processNestedTag(PutListTag nestedTag) throws JspException { 126 Object attributeValue = nestedTag.getList(); 130 131 if (nestedTag.getRole() != null) { 132 AttributeDefinition def = new UntypedAttribute(attributeValue); 133 def.setRole(nestedTag.getRole()); 134 attributeValue = def; 135 } 136 137 if (nestedTag.getName() == null) { 139 throw new JspException ("Error - PutList : attribute name is not defined. It is mandatory as the list is added to a 'definition'."); 140 } 141 142 putAttribute(nestedTag.getName(), attributeValue); 144 } 145 146 150 public String getId() { 151 return id; 152 } 153 154 158 public void setId(String id) { 159 this.id = id; 160 } 161 162 166 public String getScope() { 167 return scope; 168 } 169 170 174 public void setScope(String aScope) { 175 scope = aScope; 176 } 177 178 182 public void setExtends(String definitionName) { 183 this.extendsDefinition = definitionName; 184 } 185 186 190 public String getExtends() { 191 return extendsDefinition; 192 } 193 194 198 public int doStartTag() throws JspException { 199 if (extendsDefinition != null && !extendsDefinition.equals("")) { 201 ComponentDefinition parentDef = 202 TagUtils.getComponentDefinition(extendsDefinition, pageContext); 203 204 definition = new ComponentDefinition(parentDef); 205 206 } else { 207 definition = new ComponentDefinition(); 208 } 209 210 if (page != null) { 212 definition.setTemplate(page); 213 } 214 215 if (role != null) { 216 definition.setRole(role); 217 } 218 219 return EVAL_BODY_INCLUDE; 220 } 221 222 226 public int doEndTag() throws JspException { 227 TagUtils.setAttribute(pageContext, id, definition, scope); 228 229 releaseInternal(); 230 return EVAL_PAGE; 231 } 232 233 } 234 | Popular Tags |