| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
package com.atlassian.core.util; |
| 12 |
|
|
| 13 |
|
import java.util.ArrayList; |
| 14 |
|
import java.util.List; |
| 15 |
|
|
|
|
|
| 81% |
Uncovered Elements: 29 (153) |
Complexity: 33 |
Complexity Density: 0.35 |
|
| 16 |
|
public class HTMLUtils |
| 17 |
|
{ |
| 18 |
|
private int currentIndex; |
| 19 |
|
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 5 |
Complexity Density: 0.45 |
|
| 20 |
0
|
public static String stripTags(String html)... |
| 21 |
|
{ |
| 22 |
0
|
StringBuffer detagged = new StringBuffer(); |
| 23 |
0
|
boolean intag = false; |
| 24 |
0
|
for (int count = 0; count < html.length(); count++) |
| 25 |
|
{ |
| 26 |
0
|
char current = html.charAt(count); |
| 27 |
|
|
| 28 |
0
|
if (current == '>') |
| 29 |
0
|
intag = false; |
| 30 |
0
|
else if (current == '<') |
| 31 |
0
|
intag = true; |
| 32 |
0
|
else if (!intag) |
| 33 |
0
|
detagged.append(current); |
| 34 |
|
} |
| 35 |
0
|
return detagged.toString(); |
| 36 |
|
} |
| 37 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 38 |
3
|
public static String stripOuterHtmlTags(String html)... |
| 39 |
|
{ |
| 40 |
3
|
ArrayList tags = new ArrayList(); |
| 41 |
3
|
tags.add(new String[]{"html", "true", "0"}); |
| 42 |
3
|
tags.add(new String[]{"head", "false", "0"}); |
| 43 |
3
|
tags.add(new String[]{"body", "true", "0"}); |
| 44 |
3
|
String result = stripOuterTags(html, tags, 0); |
| 45 |
|
|
| 46 |
3
|
return result.trim(); |
| 47 |
|
} |
| 48 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 49 |
0
|
private static String stripOuterTags(String html, String tag, boolean inclusive)... |
| 50 |
|
{ |
| 51 |
0
|
ArrayList tags = new ArrayList(); |
| 52 |
0
|
tags.add(new String[]{tag, new Boolean(inclusive).toString(), "0"}); |
| 53 |
0
|
return stripOuterTags(html, tags, 0); |
| 54 |
|
} |
| 55 |
|
|
|
|
|
| 96.4% |
Uncovered Elements: 3 (83) |
Complexity: 16 |
Complexity Density: 0.3 |
|
| 56 |
4
|
private static String stripOuterTags(String html, List tagIncs, int listValue)... |
| 57 |
|
{ |
| 58 |
4
|
String[] tagInc = (String[]) tagIncs.get(listValue); |
| 59 |
4
|
String tag = tagInc[0]; |
| 60 |
4
|
boolean inclusive = new Boolean(tagInc[1]).booleanValue(); |
| 61 |
4
|
int initialCount = new Integer(tagInc[2]).intValue(); |
| 62 |
|
|
| 63 |
4
|
String[] previousInc = null; |
| 64 |
4
|
if (listValue != 0) |
| 65 |
1
|
previousInc = (String[]) tagIncs.get(listValue - 1); |
| 66 |
|
|
| 67 |
4
|
String[] nextInc = null; |
| 68 |
4
|
if (listValue < tagIncs.size() - 1) |
| 69 |
4
|
nextInc = (String[]) tagIncs.get(listValue + 1); |
| 70 |
|
|
| 71 |
4
|
StringBuffer detagged = new StringBuffer(); |
| 72 |
4
|
boolean tagValue = false; |
| 73 |
8252
|
for (int count = initialCount; count < html.length(); count++) |
| 74 |
|
{ |
| 75 |
8250
|
char current = html.charAt(count); |
| 76 |
|
|
| 77 |
8250
|
if (tagValue) |
| 78 |
|
{ |
| 79 |
624
|
if (current == '<') |
| 80 |
|
{ |
| 81 |
9
|
int newCounter = foundTag(html, count, tag, false); |
| 82 |
9
|
if (newCounter != -1) |
| 83 |
|
{ |
| 84 |
3
|
tagValue = false; |
| 85 |
3
|
count = newCounter; |
| 86 |
3
|
if (previousInc != null) |
| 87 |
|
{ |
| 88 |
2
|
previousInc[2] = new Integer(newCounter).toString(); |
| 89 |
2
|
tagIncs.add(listValue - 1, previousInc); |
| 90 |
2
|
tagIncs.remove(listValue); |
| 91 |
|
} |
| 92 |
3
|
if (inclusive) |
| 93 |
|
{ |
| 94 |
2
|
return detagged.toString(); |
| 95 |
|
} |
| 96 |
|
else |
| 97 |
|
{ |
| 98 |
1
|
listValue++; |
| 99 |
1
|
tagInc = (String[]) tagIncs.get(listValue); |
| 100 |
1
|
tag = tagInc[0]; |
| 101 |
1
|
inclusive = new Boolean(tagInc[1]).booleanValue(); |
| 102 |
1
|
if (listValue < tagIncs.size() - 1) |
| 103 |
0
|
nextInc = (String[]) tagIncs.get(listValue + 1); |
| 104 |
|
else |
| 105 |
1
|
nextInc = null; |
| 106 |
|
} |
| 107 |
|
} |
| 108 |
|
else |
| 109 |
|
{ |
| 110 |
6
|
if (inclusive) |
| 111 |
5
|
detagged.append(current); |
| 112 |
|
} |
| 113 |
|
} |
| 114 |
|
else |
| 115 |
|
{ |
| 116 |
615
|
if (inclusive) |
| 117 |
611
|
detagged.append(current); |
| 118 |
|
} |
| 119 |
|
} |
| 120 |
|
else |
| 121 |
|
{ |
| 122 |
7626
|
if (current == '<') |
| 123 |
|
{ |
| 124 |
206
|
int newCounter = foundTag(html, count, tag, true); |
| 125 |
206
|
if (newCounter != -1) |
| 126 |
|
{ |
| 127 |
3
|
tagValue = true; |
| 128 |
3
|
count = newCounter; |
| 129 |
|
|
| 130 |
3
|
if (nextInc != null) |
| 131 |
|
{ |
| 132 |
2
|
if (inclusive) |
| 133 |
|
{ |
| 134 |
1
|
nextInc[2] = new Integer(count).toString(); |
| 135 |
1
|
tagIncs.remove(listValue + 1); |
| 136 |
1
|
tagIncs.add(listValue + 1, nextInc); |
| 137 |
1
|
detagged.append(stripOuterTags(html, tagIncs, listValue + 1)); |
| 138 |
1
|
String[] tempTagIncs = (String[]) tagIncs.get(listValue); |
| 139 |
1
|
count = new Integer(tempTagIncs[2]).intValue(); |
| 140 |
|
} |
| 141 |
|
} |
| 142 |
|
} |
| 143 |
|
else |
| 144 |
|
{ |
| 145 |
203
|
detagged.append(current); |
| 146 |
|
} |
| 147 |
|
} |
| 148 |
|
else |
| 149 |
|
{ |
| 150 |
7420
|
detagged.append(current); |
| 151 |
|
} |
| 152 |
|
} |
| 153 |
|
} |
| 154 |
2
|
return detagged.toString(); |
| 155 |
|
} |
| 156 |
|
|
|
|
|
| 94.6% |
Uncovered Elements: 2 (37) |
Complexity: 10 |
Complexity Density: 0.48 |
|
| 157 |
215
|
private static int foundTag(String html, int count, String tag, boolean opening)... |
| 158 |
|
{ |
| 159 |
215
|
String tagToFind = tag; |
| 160 |
215
|
if (!opening) |
| 161 |
9
|
tagToFind = "/" + tagToFind; |
| 162 |
215
|
int htmlCounter = count; |
| 163 |
215
|
int htmlFound = 0; |
| 164 |
215
|
boolean inQuotes = false; |
| 165 |
5686
|
for (htmlCounter = count; htmlCounter < html.length(); htmlCounter++) |
| 166 |
|
{ |
| 167 |
5686
|
char current2 = html.charAt(htmlCounter); |
| 168 |
5686
|
if (current2 == '\"') |
| 169 |
|
{ |
| 170 |
292
|
inQuotes = !inQuotes; |
| 171 |
292
|
htmlFound = 0; |
| 172 |
|
} |
| 173 |
5394
|
else if (!inQuotes) |
| 174 |
|
{ |
| 175 |
1754
|
if (current2 == '>') |
| 176 |
215
|
break; |
| 177 |
1539
|
else if (htmlFound != tagToFind.length()) |
| 178 |
|
{ |
| 179 |
1539
|
if (tagToFind.toLowerCase().charAt(htmlFound) == current2 || tagToFind.toUpperCase().charAt(htmlFound) == current2) |
| 180 |
56
|
htmlFound++; |
| 181 |
|
else |
| 182 |
1483
|
htmlFound = 0; |
| 183 |
|
} |
| 184 |
|
} |
| 185 |
|
} |
| 186 |
215
|
if (htmlFound == tagToFind.length()) |
| 187 |
|
{ |
| 188 |
6
|
return htmlCounter + 1; |
| 189 |
|
} |
| 190 |
|
else |
| 191 |
|
{ |
| 192 |
209
|
return -1; |
| 193 |
|
} |
| 194 |
|
} |
| 195 |
|
} |