1 18 19 package org.apache.struts.taglib.tiles; 20 21 import javax.servlet.jsp.JspException ; 22 import javax.servlet.jsp.PageContext ; 23 import javax.servlet.jsp.tagext.TagSupport ; 24 25 import org.apache.struts.taglib.tiles.util.TagUtils; 26 import org.apache.struts.tiles.ComponentContext; 27 28 29 33 public final class AttributeToScopeTag extends TagSupport { 34 35 36 38 39 42 private String scopeName = null; 43 44 47 private int scope = PageContext.PAGE_SCOPE; 48 49 50 51 54 private String property = null; 55 56 57 59 60 61 64 public String getProperty() 65 { 66 return (this.property); 67 } 68 69 70 75 public void setProperty(String property) 76 { 77 this.property = property; 78 } 79 80 85 public void setScope(String scope) 86 { 87 this.scopeName = scope; 88 } 89 90 92 93 98 public int doStartTag() throws JspException 99 { 100 if( id==null ) 101 id=property; 102 103 ComponentContext compContext = (ComponentContext)pageContext.getAttribute( ComponentConstants.COMPONENT_CONTEXT, PageContext.REQUEST_SCOPE); 104 105 if( compContext == null ) 106 throw new JspException ( "Error - tag.useProperty : component context is not defined. Check tag syntax" ); 107 108 Object value = compContext.getAttribute(property); 109 if( value == null ) 110 throw new JspException ( "Error - tag.useProperty : property '"+ property + "' not found in context. Check tag syntax" ); 111 112 if( scopeName != null ) 113 { 114 scope = TagUtils.getScope( scopeName, PageContext.PAGE_SCOPE ); 115 pageContext.setAttribute(id, value, scope); 116 } 117 else 118 pageContext.setAttribute(id, value); 119 120 return SKIP_BODY; 122 } 123 124 125 126 127 132 public int doEndTag() throws JspException 133 { 134 return (EVAL_PAGE); 135 } 136 137 140 public void release() { 141 142 super.release(); 143 property = null; 144 scopeName = null; 145 scope = PageContext.PAGE_SCOPE; 146 } 147 148 } 149 | Popular Tags |