KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.*;
30
31 import cowsultants.itracker.ejb.client.resources.*;
32 import cowsultants.itracker.ejb.client.util.*;
33 import cowsultants.itracker.web.util.*;
34
35 /**
36   * Formats a resolution for a display. If the project uses fixed resolutions,
37   * it prints the appropriate string for the current locale. Currently the tag
38   * only supports non-editable resolution fields.
39   */

40 public class FormatResolutionTag extends BodyTagSupport {
41     public static final String JavaDoc DISPLAY_TYPE_EDIT = "edit";
42     public static final String JavaDoc DISPLAY_TYPE_VIEW = "view";
43
44     private String JavaDoc text = null;
45     private String JavaDoc displayType;
46     private int projectOptions;
47
48     public int getProjectOptions() {
49         return projectOptions;
50     }
51
52     public void setProjectOptions(int value) {
53         projectOptions = value;
54     }
55
56     public String JavaDoc getDisplayType() {
57         return displayType;
58     }
59
60     public void setDisplayType(String JavaDoc value) {
61         displayType = value;
62     }
63
64     public int doStartTag() throws JspException {
65         text = null;
66         return EVAL_BODY_BUFFERED;
67     }
68
69     public int doAfterBody() throws JspException {
70         if(bodyContent != null) {
71             String JavaDoc value = bodyContent.getString().trim();
72             if(value.length() > 0) {
73                 text = value;
74             }
75         }
76         return SKIP_BODY;
77     }
78
79     public int doEndTag() throws JspException {
80         StringBuffer JavaDoc results = new StringBuffer JavaDoc();
81         if(text != null && ! text.trim().equals("")) {
82             Locale currLocale = null;
83
84             HttpSession session = pageContext.getSession();
85             if(session != null) {
86                 currLocale = (Locale) session.getAttribute(Constants.LOCALE_KEY);
87             }
88
89             try {
90                 // Test to see if the resolution is only a number. If it is, assume that
91
// it is actually a key from a fixed resolution
92
int resolutionNumber = Integer.parseInt(text.trim());
93                 projectOptions = ProjectUtilities.OPTION_PREDEFINED_RESOLUTIONS;
94             } catch(NumberFormatException JavaDoc nfe) {
95             }
96
97             if(ProjectUtilities.hasOption(ProjectUtilities.OPTION_PREDEFINED_RESOLUTIONS, projectOptions)) {
98                 try {
99                     text = IssueUtilities.checkResolutionName(text, currLocale);
100                 } catch(MissingResourceException mre) {
101                     // Key didn't exist so just stick the key in as a real number.
102
}
103             }
104             results.append(text);
105         }
106         ResponseUtils.write(pageContext, results.toString());
107         clearState();
108         return (EVAL_PAGE);
109     }
110
111     public void release() {
112         super.release();
113         clearState();
114     }
115
116     private void clearState() {
117         text = null;
118         displayType = DISPLAY_TYPE_VIEW;
119         projectOptions = 0;
120     }
121 }
122
Popular Tags