1 23 24 package org.dbforms.taglib; 25 26 import org.dbforms.util.ICustomFormat; 27 28 import java.util.HashMap ; 29 30 import javax.servlet.http.HttpSession ; 31 import javax.servlet.jsp.JspException ; 32 33 import org.dbforms.util.ReflectionUtil; 34 35 41 public class SetCustomFormatterTag extends TagSupportWithScriptHandler 42 implements javax.servlet.jsp.tagext.TryCatchFinally { 43 44 static final String sessionKey = "dbforms.org.tag.CustomFormatterTag"; 45 46 Object arg = null; 47 String className = null; 48 String name = null; 49 50 55 public void setArg(Object obj) { 56 this.arg = obj; 57 } 58 59 60 65 public void setClassName(String className) { 66 this.className = className; 67 } 68 69 70 76 public void setName(String name) { 77 this.name = name; 78 } 79 80 81 84 public void doCatch(Throwable t) throws Throwable { 85 throw t; 86 } 87 88 89 94 public int doEndTag() throws JspException { 95 if ((name != null) && (name.length() > 0)) { 96 HttpSession session = pageContext.getSession(); 97 HashMap hm = (HashMap ) session.getAttribute(sessionKey); 98 if (hm == null) { 99 hm = new HashMap (); 100 session.setAttribute(sessionKey, hm); 101 } 102 try { 103 ICustomFormat cf = (ICustomFormat) hm.get(name); 104 if (cf == null) { 105 cf = (ICustomFormat) ReflectionUtil.newInstance(className); 106 cf.setArg(arg.toString()); 107 hm.put(name, cf); 108 } 109 } catch (Exception e) { 110 throw new JspException (e.getLocalizedMessage()); 111 } 112 } 113 return EVAL_PAGE; 114 } 115 116 117 120 public void doFinally() { 121 this.arg = null; 122 this.className = null; 123 this.name = null; 124 super.doFinally(); 125 } 126 127 128 135 public int doStartTag() throws javax.servlet.jsp.JspException { 136 return SKIP_BODY; 137 } 138 } 139 | Popular Tags |