1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.itracker.web.taglib;
20
21 import java.util.Locale;
22
23 import javax.servlet.http.HttpSession;
24 import javax.servlet.jsp.JspException;
25 import javax.servlet.jsp.tagext.TagSupport;
26
27 import org.apache.struts.taglib.TagUtils;
28 import org.itracker.core.resources.ITrackerResources;
29 import org.itracker.model.Issue;
30 import org.itracker.web.util.Constants;
31
32
33 public class FormatIssueOwnerTag extends TagSupport {
34
35
36
37 private static final long serialVersionUID = 1L;
38 private String emptyKey = "itracker.web.generic.unassigned";
39 private String format;
40 private Issue issue;
41
42 public String getFormat() {
43 return format;
44 }
45
46 public void setFormat(String value) {
47 format = value;
48 }
49
50 public Issue getIssue() {
51 return issue;
52 }
53
54 public void setIssue(Issue value) {
55 issue = value;
56 }
57
58 public String getEmptyKey() {
59 return emptyKey;
60 }
61
62 public void setEmptyKey(String 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 value = "";
72 Locale locale = null;
73
74 HttpSession session = pageContext.getSession();
75 if(session != null) {
76 locale = (Locale) session.getAttribute(Constants.LOCALE_KEY);
77 }
78
79 if(issue == null || issue.getOwner() == null) {
80 value = ITrackerResources.getString(emptyKey, locale);
81 } else {
82 try {
83 if("short".equalsIgnoreCase(format)) {
84 value = (issue.getOwner().getFirstName().length() > 0 ? issue.getOwner().getFirstName().substring(0,1).toUpperCase() + "." : "") +
85 " " + issue.getOwner().getLastName();
86 } else {
87 value = issue.getOwner().getFirstName() + " " + issue.getOwner().getLastName();
88 }
89 } catch(Exception e) {
90 value = ITrackerResources.getString(emptyKey, locale);
91 }
92 }
93
94
95 TagUtils.getInstance().write(pageContext, value);
96 clearState();
97 return EVAL_PAGE;
98 }
99
100 public void release() {
101 super.release();
102 clearState();
103 }
104
105 private void clearState() {
106 emptyKey = "itracker.web.generic.unassigned";
107 format = null;
108 issue = null;
109 }
110 }