1 16 package com.blandware.atleap.webapp.taglib.core.logic; 17 18 import com.blandware.atleap.webapp.util.core.GlobalProperties; 19 import org.apache.commons.logging.Log; 20 import org.apache.commons.logging.LogFactory; 21 import org.apache.struts.taglib.TagUtils; 22 23 import javax.servlet.jsp.JspException ; 24 import javax.servlet.jsp.PageContext ; 25 import javax.servlet.jsp.tagext.SimpleTagSupport ; 26 27 68 public class GlobalPropertyTag extends SimpleTagSupport { 69 70 protected transient final Log log = LogFactory.getLog(GlobalPropertyTag.class); 71 72 75 protected String name; 76 77 80 protected Object defaultValue; 81 82 86 protected String type; 87 88 91 protected String var; 92 93 96 protected String scope; 97 98 108 public String getName() { 109 return name; 110 } 111 112 118 public void setName(String name) { 119 this.name = name; 120 } 121 122 132 public Object getDefaultValue() { 133 return defaultValue; 134 } 135 136 141 public void setDefaultValue(Object defaultValue) { 142 this.defaultValue = defaultValue; 143 } 144 145 155 public String getType() { 156 return type; 157 } 158 159 165 public void setType(String type) { 166 this.type = type; 167 } 168 169 179 public String getVar() { 180 return var; 181 } 182 183 189 public void setVar(String var) { 190 this.var = var; 191 } 192 193 203 public String getScope() { 204 return scope; 205 } 206 207 213 public void setScope(String scope) { 214 this.scope = scope; 215 } 216 217 222 public void doTag() throws JspException { 223 224 PageContext pageContext = (PageContext ) getJspContext(); 225 226 if ( !"string".equalsIgnoreCase(type) && !"integer".equalsIgnoreCase(type) ) { 227 type = "string"; 228 } 229 230 GlobalProperties globalProperties = GlobalProperties.getInstance(pageContext.getServletContext()); 231 232 Object property = null; 233 234 if ( type.equalsIgnoreCase("string") ) { 235 property = globalProperties.getString(name, defaultValue != null ? defaultValue.toString() : null); 236 } else { 237 String s = defaultValue != null ? defaultValue.toString() : null; 238 Integer value = null; 239 if ( s != null && s.length() > 0 ) { 240 try { 241 value = Integer.valueOf(s); 242 } catch ( NumberFormatException e ) { 243 throw new JspException ("Value '" + s + "' cannot be converted to java.lang.Integer"); 244 } 245 } 246 property = globalProperties.getInteger(name, value); 247 } 248 249 int varScope = PageContext.PAGE_SCOPE; 250 if ( scope != null ) { 251 varScope = TagUtils.getInstance().getScope(scope); 252 } 253 pageContext.setAttribute(var, property, varScope); 254 } 255 256 } 257 | Popular Tags |