1 23 24 package org.dbforms.taglib; 25 26 import org.dbforms.util.MessageResources; 27 28 import java.util.Locale ; 29 import java.util.StringTokenizer ; 30 31 import javax.servlet.http.HttpServletRequest ; 32 import javax.servlet.jsp.JspException ; 33 34 35 36 39 public class MessageTag extends TagSupportWithScriptHandler 40 implements javax.servlet.jsp.tagext.TryCatchFinally { 41 private String key = null; 42 private String param = null; 43 44 49 public void setKey(String newKey) { 50 key = newKey; 51 } 52 53 54 59 public String getKey() { 60 return key; 61 } 62 63 64 69 public void setParam(String newParam) { 70 param = newParam; 71 } 72 73 74 79 public String getParam() { 80 return param; 81 } 82 83 84 91 public void doCatch(Throwable t) throws Throwable { 92 throw t; 93 } 94 95 96 103 public int doEndTag() throws JspException { 104 if (getKey() != null) { 105 Locale locale = MessageResources.getLocale((HttpServletRequest ) pageContext 106 .getRequest()); 107 String message; 108 109 if ((param == null) || (param.length() == 0)) { 110 message = MessageResources.getMessage(getKey(), locale); 111 } else { 112 message = MessageResources.getMessage(getKey(), locale, 113 splitString(param, ",")); 114 } 115 116 try { 117 if (message != null) { 118 pageContext.getOut() 119 .write(message); 120 } else { 121 pageContext.getOut() 122 .write(getKey()); 123 124 if (param != null) { 125 pageContext.getOut() 126 .write(" "); 127 pageContext.getOut() 128 .write(param); 129 } 130 } 131 } catch (java.io.IOException ioe) { 132 throw new JspException ("IO Error: " + ioe.getMessage()); 133 } 134 } 135 136 return EVAL_PAGE; 137 } 138 139 140 143 public void doFinally() { 144 key = null; 145 param = null; 146 } 147 148 149 156 public int doStartTag() throws javax.servlet.jsp.JspException { 157 return SKIP_BODY; 158 } 159 160 161 private String [] splitString(String str, 162 String delimeter) { 163 StringTokenizer st = new StringTokenizer (str, delimeter); 164 int i = 0; 165 String [] result = new String [st.countTokens()]; 166 167 while (st.hasMoreTokens()) { 168 result[i] = st.nextToken(); 169 i++; 170 } 171 172 return result; 173 } 174 } 175 | Popular Tags |