KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cowsultants > itracker > web > taglib > FormatMessageTag


1 /*
2  * This software was designed and created by Jason Carroll.
3  * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4  * The author can be reached at jcarroll@cowsultants.com
5  * ITracker website: http://www.cowsultants.com
6  * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it only under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  */

18
19 package cowsultants.itracker.web.taglib;
20
21 import java.util.*;
22
23 import javax.servlet.jsp.JspException JavaDoc;
24 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
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 JavaDoc {
33     private String JavaDoc key = null;
34     private String JavaDoc arg0 = null;
35     private String JavaDoc arg1 = null;
36     private String JavaDoc arg2 = null;
37     private String JavaDoc locale = null;
38     private String JavaDoc localeKey = Constants.LOCALE_KEY;
39
40     protected static final Locale defaultLocale = ITrackerResources.getLocale();
41
42     public String JavaDoc getArg0() {
43           return arg0;
44     }
45
46     public void setArg0(String JavaDoc value) {
47           arg0 = value;
48     }
49
50     public String JavaDoc getArg1() {
51           return arg1;
52     }
53
54     public void setArg1(String JavaDoc value) {
55           arg1 = value;
56     }
57
58     public String JavaDoc getArg2() {
59           return arg2;
60     }
61
62     public void setArg2(String JavaDoc value) {
63           arg2 = value;
64     }
65
66     public String JavaDoc getKey() {
67           return key;
68     }
69
70     public void setKey(String JavaDoc value) {
71           key = value;
72     }
73
74     public String JavaDoc getLocaleKey() {
75         return localeKey;
76     }
77
78     public void setLocaleKey(String JavaDoc value) {
79         localeKey = value;
80     }
81
82     public String JavaDoc getLocale() {
83         return locale;
84     }
85
86     public void setLocale(String JavaDoc value) {
87         locale = value;
88     }
89
90     public int doStartTag() throws JspException JavaDoc {
91         return SKIP_BODY;
92     }
93
94     public int doEndTag() throws JspException JavaDoc {
95         try {
96             String JavaDoc message = null;
97             Locale messageLocale = defaultLocale;
98
99             try {
100                 messageLocale = (Locale) (pageContext.getSession().getAttribute(getLocaleKey()));
101             } catch(Exception JavaDoc 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 JavaDoc args[] = { getArg0(), getArg1(), getArg2() };
112                 message = ITrackerResources.getString(key, messageLocale, args);
113             } else if(getArg1() != null) {
114                 Object JavaDoc args[] = { getArg0(), getArg1() };
115                 message = ITrackerResources.getString(key, messageLocale, args);
116             } else {
117                 Object JavaDoc args[] = { getArg0() };
118                 message = ITrackerResources.getString(key, messageLocale, args);
119             }
120
121             ResponseUtils.write(pageContext, message);
122         } catch(Exception JavaDoc 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