| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 117 (117) |
Complexity: 36 |
Complexity Density: 0.53 |
|
| 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 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 37 |
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
| 45 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 6 |
Complexity Density: 0.67 |
|
| 61 |
0
|
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("""); |
| 72 |
|
} else { |
| 73 |
0
|
buf.append(chars[i]); |
| 74 |
|
} |
| 75 |
|
} |
| 76 |
|
|
| 77 |
0
|
return buf.toString(); |
| 78 |
|
} |
| 79 |
|
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 7 |
Complexity Density: 0.64 |
|
| 80 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 7 |
Complexity Density: 0.64 |
|
| 99 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 5 |
Complexity Density: 1 |
|
| 118 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 32 (32) |
Complexity: 7 |
Complexity Density: 0.35 |
|
| 130 |
0
|
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("""); |
| 139 |
0
|
} else if (c == '&') { |
| 140 |
0
|
sb.append("&"); |
| 141 |
0
|
} else if (c == '<') { |
| 142 |
0
|
sb.append("<"); |
| 143 |
0
|
} else if (c == '>') { |
| 144 |
0
|
sb.append(">"); |
| 145 |
|
} else { |
| 146 |
0
|
int ci = 0xffff & c; |
| 147 |
0
|
if (ci < 160 ) { |
| 148 |
|
|
| 149 |
0
|
sb.append(c); |
| 150 |
|
} else { |
| 151 |
|
|
| 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 |
|
|
| 164 |
|
|
| 165 |
|
@see |
| 166 |
|
|
| 167 |
|
@param |
| 168 |
|
@return |
| 169 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 170 |
0
|
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 |
|
|