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