1 18 19 20 package org.apache.struts.taglib.tiles; 21 22 import java.util.Iterator ; 23 24 import javax.servlet.jsp.JspException ; 25 import javax.servlet.jsp.PageContext ; 26 import javax.servlet.jsp.tagext.TagSupport ; 27 28 import org.apache.struts.taglib.tiles.util.TagUtils; 29 import org.apache.struts.tiles.ComponentContext; 30 31 32 37 38 public class ImportAttributeTag extends TagSupport { 39 40 43 private String name = null; 44 45 46 49 private String scopeName = null; 50 51 54 private int scope = PageContext.PAGE_SCOPE; 55 60 protected boolean isErrorIgnored = false; 61 62 63 66 public void release() { 67 68 super.release(); 69 name = null; 70 scopeName = null; 71 scope = PageContext.PAGE_SCOPE; 72 isErrorIgnored = false; 73 } 74 75 79 public String getName() 80 { 81 return (this.name); 82 } 83 84 85 89 public void setName(String name) 90 { 91 this.name = name; 92 } 93 94 98 public void setScope(String scope) 99 { 100 this.scopeName = scope; 101 } 102 103 107 public String getScope() 108 { 109 return scopeName; 110 } 111 112 117 public void setIgnore(boolean ignore) 118 { 119 this.isErrorIgnored = ignore; 120 } 121 122 127 public boolean getIgnore() 128 { 129 return isErrorIgnored; 130 } 131 132 134 135 140 public int doStartTag() throws JspException 141 { 142 ComponentContext compContext = (ComponentContext)pageContext.getAttribute(ComponentConstants.COMPONENT_CONTEXT, PageContext.REQUEST_SCOPE); 144 if( compContext == null ) 145 throw new JspException ( "Error - tag importAttribute : no tiles context found." ); 146 147 scope = TagUtils.getScope( scopeName, PageContext.PAGE_SCOPE ); 149 150 if( name != null ) 152 { 153 Object value = compContext.getAttribute(name); 154 if( value == null ) 156 if(!isErrorIgnored) 157 throw new JspException ( "Error - tag importAttribute : property '"+ name + "' not found in context. Check tag syntax" ); 158 else 159 return SKIP_BODY; 160 161 pageContext.setAttribute(name, value, scope); 162 } 163 else 164 { Iterator names = compContext.getAttributeNames(); 166 while(names.hasNext()) 167 { 168 String name = (String )names.next(); 169 if(name == null ) { 170 if(!isErrorIgnored) 171 throw new JspException ( "Error - tag importAttribute : encountered an attribute with key 'null'" ); 172 else 173 return SKIP_BODY; 174 } 175 176 Object value = compContext.getAttribute(name); 177 if( value == null ) { 179 if(!isErrorIgnored) 180 throw new JspException ( "Error - tag importAttribute : property '"+ name + "' has a value of 'null'" ); 181 else 182 return SKIP_BODY; 183 } 184 pageContext.setAttribute(name, value, scope); 185 } } 188 return SKIP_BODY; 190 } 191 192 197 public int doEndTag() throws JspException 198 { 199 return (EVAL_PAGE); 200 } 201 202 } 203 | Popular Tags |