Clover Coverage Report - itracker
Coverage timestamp: Tue May 1 2012 16:42:12 CEST
35   120   18   3.5
14   78   0.51   10
10     1.8  
1    
 
 
  FormatDescriptionTag       Line # 36 35 18 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 javax.servlet.http.HttpServletRequest;
22    import javax.servlet.jsp.JspException;
23    import javax.servlet.jsp.tagext.BodyTagSupport;
24   
25    import org.apache.struts.taglib.TagUtils;
26    import org.itracker.core.resources.ITrackerResources;
27    import org.itracker.web.util.LoginUtilities;
28   
29   
30    /**
31    * Truncate a string if it's longer than truncateLength
32    *
33    * @author ranks@rosa.com
34    *
35    */
 
36    public class FormatDescriptionTag extends BodyTagSupport {
37    /**
38    *
39    */
40    private static final long serialVersionUID = 1L;
41   
42    private String text = null;
43   
44    private String truncateKey = "itracker.web.generic.truncated";
45    private String truncateText = null;
46    private int truncateLength = 40;
47   
 
48  0 toggle public String getTruncateKey() {
49  0 return truncateKey;
50    }
51   
 
52  0 toggle public void setTruncateKey(String value) {
53  0 truncateKey = value;
54    }
55   
 
56  0 toggle public int getTruncateLength() {
57  0 return truncateLength;
58    }
59   
 
60  0 toggle public void setTruncateLength(int value) {
61  0 truncateLength = value;
62    }
63   
 
64  0 toggle public int doStartTag() throws JspException {
65  0 text = null;
66  0 return EVAL_BODY_BUFFERED;
67    }
68   
 
69  0 toggle public int doAfterBody() throws JspException {
70  0 if(bodyContent != null) {
71  0 String value = bodyContent.getString().trim();
72  0 if(value.length() > 0) {
73  0 text = value;
74    }
75    }
76  0 return SKIP_BODY;
77    }
78   
 
79  0 toggle public String getTruncateText() {
80  0 if (null == truncateText) {
81  0 if (pageContext.getRequest() instanceof HttpServletRequest) {
82  0 truncateText = ITrackerResources.getString(truncateKey, LoginUtilities.getCurrentLocale((HttpServletRequest)this.pageContext.getRequest()));
83    } else {
84  0 truncateText = ITrackerResources.getString(truncateKey);
85    }
86  0 if (null != truncateText) {
87  0 truncateText = truncateText.trim();
88    } else {
89  0 truncateText = "";
90    }
91    }
92  0 return truncateText;
93    }
 
94  0 toggle public int doEndTag() throws JspException {
95  0 StringBuffer results = new StringBuffer();
96  0 if(text != null && text.trim().length() > truncateLength - getTruncateText().length()) {
97  0 results.append(text.trim().substring(0, truncateLength - getTruncateText().length()).trim());
98  0 results.append(getTruncateText());
99  0 } else if (null == text) {
100  0 results.append("");
101    } else {
102  0 results.append(text.trim());
103    }
104  0 TagUtils.getInstance().write(pageContext, results.toString());
105  0 clearState();
106  0 return (EVAL_PAGE);
107    }
108   
 
109  0 toggle public void release() {
110  0 super.release();
111  0 clearState();
112    }
113   
 
114  0 toggle private void clearState() {
115  0 truncateKey = "itracker.web.generic.truncated";
116  0 truncateLength = 40;
117  0 text = null;
118  0 truncateText = null;
119    }
120    }