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