1 107 package com.ivata.groupware.web.tag; 108 109 import java.io.IOException ; 110 111 import javax.servlet.http.HttpServletRequest ; 112 import javax.servlet.http.HttpSession ; 113 import javax.servlet.jsp.JspException ; 114 import javax.servlet.jsp.JspWriter ; 115 import javax.servlet.jsp.tagext.TagSupport ; 116 117 import org.apache.struts.taglib.TagUtils; 118 import org.picocontainer.PicoContainer; 119 120 import com.ivata.groupware.admin.security.server.SecuritySession; 121 import com.ivata.groupware.admin.security.user.UserDO; 122 import com.ivata.groupware.admin.setting.Settings; 123 import com.ivata.groupware.container.PicoContainerFactory; 124 import com.ivata.mask.util.SystemException; 125 126 127 173 public class GetSettingTag extends TagSupport { 174 180 private String id = null; 181 186 private String scope = "page"; 187 190 private String setting = null; 191 195 private String type = null; 196 197 222 public int doStartTag() throws JspException { 223 HttpSession session = pageContext.getSession(); 225 SecuritySession securitySession = (SecuritySession) 226 session.getAttribute("securitySession"); 227 PicoContainer container; 228 UserDO user; 229 if (securitySession == null) { 232 try { 233 container = PicoContainerFactory.getInstance().getGlobalContainer(); 234 } catch (SystemException e) { 235 throw new JspException (e); 236 } 237 user = null; 238 } else { 239 container = securitySession.getContainer(); 240 user = securitySession.getUser(); 241 } 242 Settings settings = (Settings) container.getComponentInstance( 243 Settings.class); 244 245 Object value; 246 try { 247 value = settings.getSetting(securitySession, setting, 248 user); 249 } catch(SystemException eRemote) { 250 throw new JspException (eRemote); 251 } 252 253 if (type != null) { 255 Class typeClass; 256 try { 257 typeClass = Class.forName(type); 258 } catch (ClassNotFoundException e) { 259 throw new JspException (e); 260 } 261 if ((value != null) 262 && (!typeClass.isAssignableFrom(value.getClass()))) { 263 throw new JspException ("ERROR: setting '" 264 + setting 265 + "' is type '" 266 + value.getClass().getName() 267 + "', expected '" 268 + type 269 + "'"); 270 } 271 } 272 273 274 if(value != null) { 276 if (id == null) { 277 try { 278 JspWriter out = pageContext.getOut(); 279 out.print(value); 280 } catch(IOException eIo) { 281 throw new JspException (eIo); 282 } 283 } else { 284 HttpServletRequest request = (HttpServletRequest ) 286 pageContext.getRequest(); 287 int pageScope = TagUtils.getInstance().getScope(scope); 288 pageContext.setAttribute(id, value, pageScope); 289 } 290 } 291 return SKIP_BODY; 293 } 294 302 public final String getId() { 303 return id; 304 } 305 306 313 public final String getScope() { 314 return scope; 315 } 316 317 325 public final String getSetting() { 326 return setting; 327 } 328 334 public final String getType() { 335 return type; 336 } 337 338 346 public final void setId(final String string) { 347 id = string; 348 } 349 350 357 public final void setScope(final String string) { 358 scope = string; 359 } 360 361 369 public final void setSetting(final String setting) { 370 this.setting = setting; 371 } 372 373 379 public final void setType(final String string) { 380 type = string; 381 } 382 383 } 384 | Popular Tags |