Clover Coverage Report - itracker
Coverage timestamp: Tue May 1 2012 16:42:12 CEST
68   185   36   9.71
42   126   0.53   7
7     5.14  
1    
 
 
  HTMLUtilities       Line # 30 68 36 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.services.util;
20   
21    import org.apache.log4j.Logger;
22    import org.apache.oro.text.regex.MalformedPatternException;
23    import org.apache.oro.text.regex.Pattern;
24    import org.apache.oro.text.regex.PatternCompiler;
25    import org.apache.oro.text.regex.Perl5Compiler;
26    import org.apache.oro.text.regex.Perl5Matcher;
27    import org.apache.oro.text.regex.Perl5Substitution;
28    import org.apache.oro.text.regex.Util;
29   
 
30    public class HTMLUtilities {
31   
32    private static final Logger logger = Logger.getLogger(HTMLUtilities.class);
33    private static Perl5Matcher matcher = new Perl5Matcher();
34    private static PatternCompiler compiler = new Perl5Compiler();
35    private static Pattern pattern = null;
36   
 
37    toggle static {
38    try {
39    pattern = compiler.compile("<[\\w/].*?>", Perl5Compiler.CASE_INSENSITIVE_MASK);
40    } catch(MalformedPatternException mpe) {
41    logger.error("Invalid pattern in HTMLUtilities. " + mpe.getMessage());
42    }
43    }
44   
 
45  0 toggle public static String removeQuotes(String input) {
46  0 StringBuffer sb = new StringBuffer(input.length());
47  0 int len = input.length();
48  0 char c;
49   
50  0 for(int i = 0; i < len; i++) {
51  0 c = input.charAt(i);
52  0 if (c == '\'') {
53  0 sb.append("''");
54    } else {
55  0 sb.append(c);
56    }
57    }
58  0 return sb.toString();
59    }
60   
 
61  0 toggle public static String handleQuotes(String input) {
62  0 if(input == null || "".equals(input) || input.indexOf('"') == -1) {
63  0 return input;
64    }
65   
66  0 StringBuffer buf = new StringBuffer();
67   
68  0 char[] chars = input.toCharArray();
69  0 for(int i = 0; i < chars.length; i++) {
70  0 if(chars[i] == '"') {
71  0 buf.append("&quot;");
72    } else {
73  0 buf.append(chars[i]);
74    }
75    }
76   
77  0 return buf.toString();
78    }
79   
 
80  0 toggle public static String escapeNewlines(String input) {
81  0 if(input == null || "".equals(input) || input.indexOf('\n') == -1) {
82  0 return input;
83    }
84   
85  0 StringBuffer buf = new StringBuffer();
86  0 char[] chars = input.toCharArray();
87  0 for(int i = 0; i < chars.length; i++) {
88  0 if(chars[i] == '\r') {
89  0 continue;
90  0 } else if(chars[i] == '\n') {
91  0 buf.append("\\n");
92    } else {
93  0 buf.append(chars[i]);
94    }
95    }
96  0 return buf.toString();
97    }
98   
 
99  0 toggle public static String newlinesToBreaks(String input) {
100  0 if(input == null || "".equals(input) || input.indexOf('\n') == -1) {
101  0 return input;
102    }
103   
104  0 StringBuffer buf = new StringBuffer();
105  0 char[] chars = input.toCharArray();
106  0 for(int i = 0; i < chars.length; i++) {
107  0 if(chars[i] == '\r') {
108  0 continue;
109  0 } else if(chars[i] == '\n') {
110  0 buf.append("<br>");
111    } else {
112  0 buf.append(chars[i]);
113    }
114    }
115  0 return buf.toString();
116    }
117   
 
118  0 toggle public static String removeMarkup(String input) {
119  0 String output = (input == null ? "" : input);
120   
121  0 if(pattern != null && matcher != null && output != null && ! output.equals("")) {
122  0 output = Util.substitute(matcher, pattern, new Perl5Substitution(), output, Util.SUBSTITUTE_ALL);
123    } else {
124  0 logger.debug("Failed removing markup. Pattern = " + pattern + " Output = " + output);
125    }
126   
127  0 return output;
128    }
129   
 
130  0 toggle public static String escapeTags(String input) {
131  0 StringBuffer sb = new StringBuffer(input.length());
132  0 int len = input.length();
133  0 char c;
134   
135  0 for(int i = 0; i < len; i++) {
136  0 c = input.charAt(i);
137  0 if (c == '"') {
138  0 sb.append("&quot;");
139  0 } else if (c == '&') {
140  0 sb.append("&amp;");
141  0 } else if (c == '<') {
142  0 sb.append("&lt;");
143  0 } else if (c == '>') {
144  0 sb.append("&gt;");
145    } else {
146  0 int ci = 0xffff & c;
147  0 if (ci < 160 ) {
148    // nothing special only 7 Bit
149  0 sb.append(c);
150    } else {
151    // Not 7 Bit use the unicode system
152  0 sb.append("&#");
153  0 sb.append(new Integer(ci).toString());
154  0 sb.append(';');
155    }
156    }
157    }
158   
159  0 return sb.toString();
160    }
161   
162    /**
163    * format a itracker date format for scal datepicker
164    *
165    * @see http://scal.fieldguidetoprogrammers.com
166    *
167    * @param format
168    * @return
169    */
 
170  0 toggle public static final String getJSDateFormat(String format) {
171   
172   
173  0 String f = format.replace('m', 'n');
174   
175   
176  0 f = format.toLowerCase();
177   
178  0 return f;
179   
180   
181    }
182   
183    }
184   
185