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