1 18 19 20 package org.apache.struts.taglib.tiles; 21 22 import javax.servlet.jsp.JspException ; 23 import javax.servlet.jsp.PageContext ; 24 import javax.servlet.jsp.tagext.TagSupport ; 25 26 import org.apache.struts.taglib.tiles.util.TagUtils; 27 import org.apache.struts.tiles.ComponentContext; 28 29 30 34 public class UseAttributeTag extends TagSupport { 35 36 37 39 40 43 private String classname = null; 44 45 46 49 private String scopeName = null; 50 51 54 private int scope = PageContext.PAGE_SCOPE; 55 56 57 58 61 private String attributeName = null; 62 63 68 protected boolean isErrorIgnored = false; 69 70 71 73 74 77 public void release() { 78 79 super.release(); 80 attributeName = null; 81 classname = null; 82 scope = PageContext.PAGE_SCOPE; 83 scopeName = null; 84 isErrorIgnored = false; 85 id = null; 88 } 89 90 93 public String getClassname() { 94 95 return (this.classname); 96 97 } 98 99 100 105 public void setClassname(String name) { 106 107 this.classname = name; 108 109 } 110 111 114 public void setName(String value){ 115 this.attributeName = value; 116 } 117 118 121 public String getName() 122 { 123 return attributeName; 124 } 125 126 131 public void setScope(String scope) { 132 this.scopeName = scope; 133 } 134 135 138 public String getScope() 139 { 140 return scopeName; 141 } 142 143 146 public void setIgnore(boolean ignore) 147 { 148 this.isErrorIgnored = ignore; 149 } 150 151 154 public boolean getIgnore() 155 { 156 return isErrorIgnored; 157 } 158 159 161 162 167 public int doStartTag() throws JspException 168 { 169 String localId=this.id; 171 if( localId==null ) 172 localId=attributeName; 173 174 ComponentContext compContext = (ComponentContext)pageContext.getAttribute( ComponentConstants.COMPONENT_CONTEXT, PageContext.REQUEST_SCOPE); 175 if( compContext == null ) 176 throw new JspException ( "Error - tag useAttribute : no tiles context found." ); 177 178 Object value = compContext.getAttribute(attributeName); 179 if( value == null ) 181 if(!isErrorIgnored) 182 throw new JspException ( "Error - tag useAttribute : attribute '"+ attributeName + "' not found in context. Check tag syntax" ); 183 else 184 return SKIP_BODY; 185 186 if( scopeName != null ) 187 { 188 scope = TagUtils.getScope( scopeName, PageContext.PAGE_SCOPE ); 189 if(scope!=ComponentConstants.COMPONENT_SCOPE) 190 pageContext.setAttribute(localId, value, scope); 191 } 192 else 193 pageContext.setAttribute(localId, value); 194 195 return SKIP_BODY; 197 } 198 199 200 201 202 207 public int doEndTag() throws JspException 208 { 209 return (EVAL_PAGE); 210 } 211 212 } 213 | Popular Tags |