Clover Coverage Report - itracker
Coverage timestamp: Tue May 1 2012 16:42:12 CEST
56   200   29   2.95
16   137   0.52   19
19     1.53  
1    
 
 
  FormatHistoryEntryTag       Line # 49 56 29 0% 0.0
 
No Tests
 
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.net.MalformedURLException;
22    import java.util.Locale;
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.oro.text.regex.MalformedPatternException;
29    import org.apache.oro.text.regex.Pattern;
30    import org.apache.oro.text.regex.PatternCompiler;
31    import org.apache.oro.text.regex.Perl5Compiler;
32    import org.apache.oro.text.regex.Perl5Matcher;
33    import org.apache.oro.text.regex.Perl5Substitution;
34    import org.apache.oro.text.regex.Util;
35    import org.apache.struts.taglib.TagUtils;
36    import org.itracker.core.resources.ITrackerResources;
37    import org.itracker.services.util.HTMLUtilities;
38    import org.itracker.services.util.ProjectUtilities;
39    import org.itracker.web.util.Constants;
40   
41   
42    /**
43    * Formats an ITracker Issue History entry. Will rewrite the entry to include
44    * links to other issues automatically based on the strings provided in the
45    * resource bundles under the itracker.web.issuenames key. This key can contain
46    * a pipe seperated list of names to look for and then matches in the pattern
47    * ([names])(\d+).
48    */
 
49    public class FormatHistoryEntryTag extends BodyTagSupport {
50    /**
51    *
52    */
53    private static final long serialVersionUID = 1L;
54    private static Perl5Matcher matcher = new Perl5Matcher();
55    private static PatternCompiler compiler = new Perl5Compiler();
56   
57    private String text = null;
58    private String issueNamesKey = "itracker.web.issuenames";
59    private String forward ="viewissue";
60    private String paramName = "id";
61    private String paramValue = "$2";
62    private String textPattern = "$1 $2";
63    private String styleClass = "history";
64    private int projectOptions = 0;
65   
 
66  0 toggle public String getForward() {
67  0 return forward;
68    }
69   
 
70  0 toggle public void setForward(String value) {
71  0 forward = value;
72    }
73   
 
74  0 toggle public String getParamName() {
75  0 return paramName;
76    }
77   
 
78  0 toggle public void setParamName(String value) {
79  0 paramName = value;
80    }
81   
 
82  0 toggle public Object getParamValue() {
83  0 return paramValue;
84    }
85   
 
86  0 toggle public void setParamValue(Object value) {
87  0 paramValue = (value != null ? value.toString() : null);
88    }
89   
 
90  0 toggle public String getIssueNamesKey() {
91  0 return issueNamesKey;
92    }
93   
 
94  0 toggle public void setIssueNamesKey(String value) {
95  0 issueNamesKey = value;
96    }
97   
 
98  0 toggle public String getTextPattern() {
99  0 return textPattern;
100    }
101   
 
102  0 toggle public void setTextPattern(String value) {
103  0 textPattern = value;
104    }
105   
 
106  0 toggle public String getStyleClass() {
107  0 return styleClass;
108    }
109   
 
110  0 toggle public void setStyleClass(String value) {
111  0 styleClass = value;
112    }
113   
 
114  0 toggle public int getProjectOptions() {
115  0 return projectOptions;
116    }
117   
 
118  0 toggle public void setProjectOptions(int value) {
119  0 projectOptions = value;
120    }
121   
 
122  0 toggle public int doStartTag() throws JspException {
123  0 text = null;
124  0 return EVAL_BODY_BUFFERED;
125    }
126   
 
127  0 toggle public int doAfterBody() throws JspException {
128  0 if(bodyContent != null) {
129  0 String value = bodyContent.getString().trim();
130  0 if(value.length() > 0) {
131  0 text = value;
132    }
133    }
134  0 return SKIP_BODY;
135    }
136   
 
137  0 toggle public int doEndTag() throws JspException {
138  0 if(text != null) {
139  0 Locale locale = null;
140   
141  0 HttpSession session = pageContext.getSession();
142  0 if(session != null) {
143  0 locale = (Locale) session.getAttribute(Constants.LOCALE_KEY);
144    }
145   
146  0 if(ProjectUtilities.hasOption(ProjectUtilities.OPTION_SURPRESS_HISTORY_HTML, projectOptions)) {
147  0 text = HTMLUtilities.removeMarkup(text);
148  0 } else if(ProjectUtilities.hasOption(ProjectUtilities.OPTION_LITERAL_HISTORY_HTML, projectOptions)) {
149  0 text = HTMLUtilities.escapeTags(text);
150    } else {
151  0 text = HTMLUtilities.newlinesToBreaks(text);
152    }
153   
154  0 try {
155  0 Pattern pattern = compiler.compile("(" + ITrackerResources.getString(issueNamesKey, locale) + ")\\s(\\d+)", Perl5Compiler.CASE_INSENSITIVE_MASK);
156   
157  0 StringBuffer buf = new StringBuffer("<a href=\"");
158  0 try {
159    //buf.append(RequestUtils.computeURL(pageContext, forward, null, null, null, null, null, false));
160  0 buf.append(TagUtils.getInstance().computeURL(pageContext, forward, null, null, null, null, null, null, false));
161    } catch(MalformedURLException murle) {
162  0 buf.append(forward);
163    }
164  0 buf.append("?" + paramName + "=" + paramValue + "\" ");
165  0 buf.append("class=\"" + styleClass + "\">");
166  0 buf.append(textPattern);
167  0 buf.append("</a>");
168   
169  0 text = Util.substitute(matcher, pattern, new Perl5Substitution(buf.toString()), text, Util.SUBSTITUTE_ALL);
170    } catch(MalformedPatternException mpe) {
171    }
172   
173  0 if(ProjectUtilities.hasOption(ProjectUtilities.OPTION_SURPRESS_HISTORY_HTML, projectOptions) ||
174    ProjectUtilities.hasOption(ProjectUtilities.OPTION_LITERAL_HISTORY_HTML, projectOptions)) {
175  0 text = "<pre>" + text + "</pre>";
176    }
177   
178    // ResponseUtils.write(pageContext, text);
179  0 TagUtils.getInstance().write(pageContext, text);
180    }
181   
182  0 clearState();
183  0 return (EVAL_PAGE);
184    }
185   
 
186  0 toggle public void release() {
187  0 super.release();
188  0 clearState();
189    }
190   
 
191  0 toggle private void clearState() {
192  0 text = null;
193  0 issueNamesKey = "itracker.web.issuenames";
194  0 forward ="viewissue";
195  0 paramName = "id";
196  0 paramValue = "$2";
197  0 textPattern = "$1 $2";
198  0 styleClass = "history";
199    }
200    }