1 18 19 package cowsultants.itracker.web.taglib; 20 21 import java.io.*; 22 import java.net.*; 23 import java.util.*; 24 import java.text.*; 25 import javax.servlet.*; 26 import javax.servlet.http.*; 27 import javax.servlet.jsp.*; 28 import javax.servlet.jsp.tagext.*; 29 30 import org.apache.oro.text.regex.*; 31 import org.apache.struts.util.*; 32 33 import cowsultants.itracker.ejb.client.resources.*; 34 import cowsultants.itracker.ejb.client.util.*; 35 import cowsultants.itracker.web.util.*; 36 37 44 public class FormatHistoryEntryTag extends BodyTagSupport { 45 private static Perl5Matcher matcher = new Perl5Matcher(); 46 private static PatternCompiler compiler = new Perl5Compiler(); 47 48 private String text = null; 49 private String issueNamesKey = "itracker.web.issuenames"; 50 private String forward ="viewissue"; 51 private String paramName = "id"; 52 private String paramValue = "$2"; 53 private String textPattern = "$1 $2"; 54 private String styleClass = "history"; 55 private int projectOptions = 0; 56 57 public String getForward() { 58 return forward; 59 } 60 61 public void setForward(String value) { 62 forward = value; 63 } 64 65 public String getParamName() { 66 return paramName; 67 } 68 69 public void setParamName(String value) { 70 paramName = value; 71 } 72 73 public Object getParamValue() { 74 return paramValue; 75 } 76 77 public void setParamValue(Object value) { 78 paramValue = (value != null ? value.toString() : null); 79 } 80 81 public String getIssueNamesKey() { 82 return issueNamesKey; 83 } 84 85 public void setIssueNamesKey(String value) { 86 issueNamesKey = value; 87 } 88 89 public String getTextPattern() { 90 return textPattern; 91 } 92 93 public void setTextPattern(String value) { 94 textPattern = value; 95 } 96 97 public String getStyleClass() { 98 return styleClass; 99 } 100 101 public void setStyleClass(String value) { 102 styleClass = value; 103 } 104 105 public int getProjectOptions() { 106 return projectOptions; 107 } 108 109 public void setProjectOptions(int value) { 110 projectOptions = value; 111 } 112 113 public int doStartTag() throws JspException { 114 text = null; 115 return EVAL_BODY_BUFFERED; 116 } 117 118 public int doAfterBody() throws JspException { 119 if(bodyContent != null) { 120 String value = bodyContent.getString().trim(); 121 if(value.length() > 0) { 122 text = value; 123 } 124 } 125 return SKIP_BODY; 126 } 127 128 public int doEndTag() throws JspException { 129 if(text != null) { 130 Locale currLocale = null; 131 132 HttpSession session = pageContext.getSession(); 133 if(session != null) { 134 currLocale = (Locale) session.getAttribute(Constants.LOCALE_KEY); 135 } 136 137 if(ProjectUtilities.hasOption(ProjectUtilities.OPTION_SURPRESS_HISTORY_HTML, projectOptions)) { 138 text = HTMLUtilities.removeMarkup(text); 139 } else if(ProjectUtilities.hasOption(ProjectUtilities.OPTION_LITERAL_HISTORY_HTML, projectOptions)) { 140 text = HTMLUtilities.escapeTags(text); 141 } else { 142 text = HTMLUtilities.newlinesToBreaks(text); 143 } 144 145 try { 146 Pattern pattern = compiler.compile("(" + ITrackerResources.getString(issueNamesKey, currLocale) + ")\\s(\\d+)", Perl5Compiler.CASE_INSENSITIVE_MASK); 147 148 StringBuffer buf = new StringBuffer ("<a HREF=\""); 149 try { 150 buf.append(RequestUtils.computeURL(pageContext, forward, null, null, null, null, null, false)); 151 } catch(MalformedURLException murle) { 152 buf.append(forward); 153 } 154 buf.append("?" + paramName + "=" + paramValue + "\" "); 155 buf.append("class=\"" + styleClass + "\">"); 156 buf.append(textPattern); 157 buf.append("</a>"); 158 159 text = Util.substitute(matcher, pattern, new Perl5Substitution(buf.toString()), text, Util.SUBSTITUTE_ALL); 160 } catch(MalformedPatternException mpe) { 161 } 162 163 if(ProjectUtilities.hasOption(ProjectUtilities.OPTION_SURPRESS_HISTORY_HTML, projectOptions) || 164 ProjectUtilities.hasOption(ProjectUtilities.OPTION_LITERAL_HISTORY_HTML, projectOptions)) { 165 text = "<pre>" + text + "</pre>"; 166 } 167 168 ResponseUtils.write(pageContext, text); 169 } 170 171 clearState(); 172 return (EVAL_PAGE); 173 } 174 175 public void release() { 176 super.release(); 177 clearState(); 178 } 179 180 private void clearState() { 181 text = null; 182 issueNamesKey = "itracker.web.issuenames"; 183 forward ="viewissue"; 184 paramName = "id"; 185 paramValue = "$2"; 186 textPattern = "$1 $2"; 187 styleClass = "history"; 188 } 189 } 190 | Popular Tags |