View Javadoc

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 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    * Formats a resolution for a display.  If the project uses fixed resolutions,
36    * it prints the appropriate string for the current locale.  Currently the tag
37    * only supports non-editable resolution fields.
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                     // Key didn't exist so just stick the key in as a real number.
103                 }
104             }
105             results.append(text);
106         }
107        // ResponseUtils.write(pageContext, results.toString());
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 }