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