1 18 19 package cowsultants.itracker.web.taglib; 20 21 import java.util.*; 22 23 import javax.servlet.jsp.JspException ; 24 import javax.servlet.jsp.tagext.TagSupport ; 25 26 import org.apache.struts.util.*; 27 28 import cowsultants.itracker.ejb.client.resources.*; 29 import cowsultants.itracker.ejb.client.util.*; 30 import cowsultants.itracker.web.util.*; 31 32 public class FormatMessageTag extends TagSupport { 33 private String key = null; 34 private String arg0 = null; 35 private String arg1 = null; 36 private String arg2 = null; 37 private String locale = null; 38 private String localeKey = Constants.LOCALE_KEY; 39 40 protected static final Locale defaultLocale = ITrackerResources.getLocale(); 41 42 public String getArg0() { 43 return arg0; 44 } 45 46 public void setArg0(String value) { 47 arg0 = value; 48 } 49 50 public String getArg1() { 51 return arg1; 52 } 53 54 public void setArg1(String value) { 55 arg1 = value; 56 } 57 58 public String getArg2() { 59 return arg2; 60 } 61 62 public void setArg2(String value) { 63 arg2 = value; 64 } 65 66 public String getKey() { 67 return key; 68 } 69 70 public void setKey(String value) { 71 key = value; 72 } 73 74 public String getLocaleKey() { 75 return localeKey; 76 } 77 78 public void setLocaleKey(String value) { 79 localeKey = value; 80 } 81 82 public String getLocale() { 83 return locale; 84 } 85 86 public void setLocale(String value) { 87 locale = value; 88 } 89 90 public int doStartTag() throws JspException { 91 return SKIP_BODY; 92 } 93 94 public int doEndTag() throws JspException { 95 try { 96 String message = null; 97 Locale messageLocale = defaultLocale; 98 99 try { 100 messageLocale = (Locale) (pageContext.getSession().getAttribute(getLocaleKey())); 101 } catch(Exception e) { 102 } 103 104 if(locale != null) { 105 messageLocale = ITrackerResources.getLocale(locale); 106 } 107 108 if(getArg0() == null) { 109 message = ITrackerResources.getString(key, messageLocale); 110 } else if(getArg2() != null) { 111 Object args[] = { getArg0(), getArg1(), getArg2() }; 112 message = ITrackerResources.getString(key, messageLocale, args); 113 } else if(getArg1() != null) { 114 Object args[] = { getArg0(), getArg1() }; 115 message = ITrackerResources.getString(key, messageLocale, args); 116 } else { 117 Object args[] = { getArg0() }; 118 message = ITrackerResources.getString(key, messageLocale, args); 119 } 120 121 ResponseUtils.write(pageContext, message); 122 } catch(Exception e) { 123 Logger.logDebug("Error displaying localized text.", e); 124 } 125 126 clearState(); 127 return EVAL_PAGE; 128 } 129 130 131 public void release() { 132 super.release(); 133 localeKey = Constants.LOCALE_KEY; 134 } 135 136 private void clearState() { 137 arg0 = null; 138 arg1 = null; 139 arg2 = null; 140 key = null; 141 locale = null; 142 } 143 } 144 | Popular Tags |