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.model.util.IssueUtilities;
23 import org.itracker.model.util.ProjectUtilities;
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.BodyTagSupport;
29 import java.util.Locale;
30 import java.util.MissingResourceException;
31
32
33
34
35
36
37
38 public class FormatResolutionTag extends BodyTagSupport {
39
40
41
42 private static final long serialVersionUID = 1L;
43 public static final String DISPLAY_TYPE_EDIT = "edit";
44 public static final String DISPLAY_TYPE_VIEW = "view";
45
46 private String text = null;
47 private String displayType;
48 private int projectOptions;
49
50 public int getProjectOptions() {
51 return projectOptions;
52 }
53
54 public void setProjectOptions(int value) {
55 projectOptions = value;
56 }
57
58 public String getDisplayType() {
59 return displayType;
60 }
61
62 public void setDisplayType(String value) {
63 displayType = value;
64 }
65
66 public int doStartTag() throws JspException {
67 text = null;
68 return EVAL_BODY_BUFFERED;
69 }
70
71 public int doAfterBody() throws JspException {
72 if (bodyContent != null) {
73 String value = bodyContent.getString().trim();
74 if (value.length() > 0) {
75 text = value;
76 }
77 }
78 return SKIP_BODY;
79 }
80
81 public int doEndTag() throws JspException {
82 StringBuffer results = new StringBuffer();
83 if (text != null && !text.trim().equals("")) {
84 Locale locale = null;
85
86 HttpSession session = pageContext.getSession();
87 if (session != null) {
88 locale = (Locale) session.getAttribute(Constants.LOCALE_KEY);
89 }
90
91 try {
92
93 projectOptions = ProjectUtilities.OPTION_PREDEFINED_RESOLUTIONS;
94 } catch (NumberFormatException nfe) {
95 }
96
97 if (ProjectUtilities.hasOption(ProjectUtilities.OPTION_PREDEFINED_RESOLUTIONS, projectOptions)) {
98 try {
99 text = IssueUtilities.checkResolutionName(text, locale);
100 } catch (MissingResourceException mre) {
101
102 }
103 }
104 results.append(text);
105 }
106
107 TagUtils.getInstance().write(pageContext, results.toString());
108 clearState();
109 return (EVAL_PAGE);
110 }
111
112 public void release() {
113 super.release();
114 clearState();
115 }
116
117 private void clearState() {
118 text = null;
119 displayType = DISPLAY_TYPE_VIEW;
120 projectOptions = 0;
121 }
122 }