KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.*;
22 import java.util.*;
23 import java.text.*;
24 import javax.servlet.*;
25 import javax.servlet.http.*;
26 import javax.servlet.jsp.*;
27 import javax.servlet.jsp.tagext.*;
28
29 import org.apache.struts.Globals;
30 import org.apache.struts.action.*;
31 import org.apache.struts.util.*;
32
33 import cowsultants.itracker.ejb.client.models.*;
34 import cowsultants.itracker.ejb.client.resources.*;
35 import cowsultants.itracker.web.util.*;
36
37 public class FormatIssueOwnerTag extends TagSupport {
38     private String JavaDoc emptyKey = "itracker.web.generic.unassigned";
39     private String JavaDoc format;
40     private IssueModel issue;
41
42     public String JavaDoc getFormat() {
43         return format;
44     }
45
46     public void setFormat(String JavaDoc value) {
47         format = value;
48     }
49
50     public IssueModel getIssue() {
51         return issue;
52     }
53
54     public void setIssue(IssueModel value) {
55         issue = value;
56     }
57
58     public String JavaDoc getEmptyKey() {
59         return emptyKey;
60     }
61
62     public void setEmptyKey(String JavaDoc value) {
63         emptyKey = value;
64     }
65
66     public int doStartTag() throws JspException {
67         return SKIP_BODY;
68     }
69
70     public int doEndTag() throws JspException {
71         String JavaDoc value = "";
72         Locale currLocale = null;
73
74         HttpSession session = pageContext.getSession();
75         if(session != null) {
76             currLocale = (Locale) session.getAttribute(Constants.LOCALE_KEY);
77         }
78
79         if(issue == null || issue.getOwnerId() == null || issue.getOwnerId().intValue() < 0) {
80             value = ITrackerResources.getString(emptyKey, currLocale);
81         } else {
82             try {
83                 if("short".equalsIgnoreCase(format)) {
84                     value = (issue.getOwnerFirstName().length() > 0 ? issue.getOwnerFirstName().substring(0,1).toUpperCase() + "." : "") +
85                             " " + issue.getOwnerLastName();
86                 } else {
87                     value = issue.getOwnerFirstName() + " " + issue.getOwnerLastName();
88                 }
89             } catch(Exception JavaDoc e) {
90                 value = ITrackerResources.getString(emptyKey, currLocale);
91             }
92         }
93         ResponseUtils.write(pageContext, value);
94         clearState();
95         return EVAL_PAGE;
96     }
97
98     public void release() {
99         super.release();
100         clearState();
101     }
102
103     private void clearState() {
104         emptyKey = "itracker.web.generic.unassigned";
105         format = null;
106         issue = null;
107     }
108 }
109
Popular Tags