1 18 19 20 package org.apache.struts.taglib.tiles; 21 22 import java.io.IOException ; 23 24 import javax.servlet.http.HttpServletRequest ; 25 import javax.servlet.jsp.JspException ; 26 import javax.servlet.jsp.PageContext ; 27 import javax.servlet.jsp.tagext.TagSupport ; 28 29 import org.apache.struts.tiles.ComponentContext; 30 31 36 public class GetAttributeTag extends TagSupport implements ComponentConstants { 37 38 private String attribute = null; 39 40 private String role = null; 41 45 private boolean isErrorIgnored = false; 46 47 50 public GetAttributeTag() { 51 super(); 52 } 53 54 57 public void release() { 58 59 super.release(); 60 attribute = null; 61 role = null; 62 isErrorIgnored = false; 63 } 64 65 69 public void setAttribute(String attribute){ 70 this.attribute = attribute; 71 } 72 73 77 public String getAttribute() 78 { 79 return attribute; 80 } 81 82 87 public void setName(String value) 88 { 89 this.attribute = value; 90 } 91 92 97 public String getName() 98 { 99 return attribute; 100 } 101 102 107 public void setIgnore(boolean ignore) 108 { 109 this.isErrorIgnored = ignore; 110 } 111 112 117 public boolean getIgnore() 118 { 119 return isErrorIgnored; 120 } 121 122 126 public void setRole(String role) { 127 this.role = role; 128 } 129 130 134 public String getRole() 135 { 136 return role; 137 } 138 139 143 public int doEndTag() throws JspException { 144 145 if(role != null && !((HttpServletRequest )pageContext.getRequest()).isUserInRole(role) ) 147 { 148 return EVAL_PAGE; 149 } 151 ComponentContext compContext = (ComponentContext)pageContext.getAttribute( ComponentConstants.COMPONENT_CONTEXT, PageContext.REQUEST_SCOPE); 153 154 if( compContext == null ) 155 throw new JspException ( "Error - tag.getAsString : component context is not defined. Check tag syntax" ); 156 157 Object value = compContext.getAttribute(attribute); 158 if( value == null) 159 { if(isErrorIgnored == false ) 161 throw new JspException ( "Error - tag.getAsString : attribute '"+ attribute + "' not found in context. Check tag syntax" ); 162 else 163 return EVAL_PAGE; 164 } 166 167 try 168 { 169 pageContext.getOut().print( value ); 170 } 171 catch( IOException ex ) 172 { 173 ex.printStackTrace(); 174 throw new JspException ( "Error - tag.getProperty : IOException "); 175 } 176 177 return EVAL_PAGE; 178 } 179 } 180 | Popular Tags |