1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rendering.wikimodel.util; |
21 |
|
|
22 |
|
import java.util.HashMap; |
23 |
|
import java.util.Map; |
24 |
|
|
25 |
|
|
26 |
|
@version |
27 |
|
@since |
28 |
|
|
|
|
| 73.1% |
Uncovered Elements: 25 (93) |
Complexity: 14 |
Complexity Density: 0.19 |
|
29 |
|
public class WikiEntityUtil |
30 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.33 |
|
31 |
|
private static class Entity |
32 |
|
{ |
33 |
|
public final int fHtmlCode; |
34 |
|
|
35 |
|
public final String fHtmlSymbol; |
36 |
|
|
37 |
|
public final String fWikiSymbol; |
38 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
39 |
57 |
public Entity(String wikiSymbol, String htmlSymbol, int htmlCode)... |
40 |
|
{ |
41 |
57 |
fWikiSymbol = wikiSymbol; |
42 |
57 |
fHtmlSymbol = htmlSymbol; |
43 |
57 |
fHtmlCode = htmlCode; |
44 |
|
} |
45 |
|
} |
46 |
|
|
47 |
|
private static Map<String, Entity> fHtmlToWiki = new HashMap<String, Entity>(); |
48 |
|
|
49 |
|
private static Entity[] fIdToWiki = new Entity[65535]; |
50 |
|
|
51 |
|
private static Map<String, Entity> fWikiToHtml = new HashMap<String, Entity>(); |
52 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (57) |
Complexity: 1 |
Complexity Density: 0.02 |
|
53 |
1 |
static {... |
54 |
1 |
add("<", "lt", 8249); |
55 |
1 |
add(">", "gt", 8250); |
56 |
1 |
add("&", "amp", 38); |
57 |
|
|
58 |
1 |
add("\'", "rsquo", 8217); |
59 |
1 |
add("(tm)", "trade", 8482); |
60 |
1 |
add("(TM)", "trade", 8482); |
61 |
1 |
add("(No)", "8470", 8470); |
62 |
1 |
add(" -- ", "ndash", 8211); |
63 |
1 |
add("---", "mdash", 8212); |
64 |
1 |
add(" --- ", "mdash", 8212); |
65 |
1 |
add("...", "hellip", 8230); |
66 |
1 |
add("(*)", "bull", 8226); |
67 |
1 |
add("(R)", "reg", 174); |
68 |
1 |
add("(r)", "reg", 174); |
69 |
1 |
add("(o)", "deg", 176); |
70 |
1 |
add("(C)", "copy", 169); |
71 |
1 |
add("(p)", "para", 182); |
72 |
1 |
add("(P)", "para", 182); |
73 |
1 |
add("(s)", "sect", 167); |
74 |
1 |
add("()", "nbsp", 160); |
75 |
1 |
add("<<", "laquo", 171); |
76 |
1 |
add(">>", "raquo", 187); |
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
1 |
add("(c)", "cent", 162); |
82 |
1 |
add("(E)", "euro", 8364); |
83 |
1 |
add("(O)", "curren", 164); |
84 |
1 |
add("(L)", "pound", 163); |
85 |
1 |
add("(Y)", "yen", 165); |
86 |
1 |
add("(f)", "fnof", 402); |
87 |
|
|
88 |
|
|
89 |
1 |
add("+/-", "plusmn", 177); |
90 |
1 |
add("(S)", "sum", 8721); |
91 |
1 |
add("(/)", "divide", 247); |
92 |
1 |
add("(x)", "times", 215); |
93 |
1 |
add("(8)", "infin", 8734); |
94 |
1 |
add("(~)", "sim", 8764); |
95 |
1 |
add("!=", "ne", 8800); |
96 |
|
|
97 |
1 |
add("->", "rarr", 8594); |
98 |
1 |
add("-->", "rarr", 8594); |
99 |
1 |
add("--->", "rarr", 8594); |
100 |
|
|
101 |
1 |
add("<-", "larr", 8592); |
102 |
1 |
add("<--", "larr", 8592); |
103 |
1 |
add("<---", "larr", 8592); |
104 |
|
|
105 |
1 |
add("<->", "harr", 8596); |
106 |
1 |
add("<-->", "harr", 8596); |
107 |
1 |
add("<--->", "harr", 8596); |
108 |
|
|
109 |
1 |
add("=>", "rArr", 8658); |
110 |
1 |
add("==>", "rArr", 8658); |
111 |
1 |
add("===>", "rArr", 8658); |
112 |
|
|
113 |
1 |
add("<=", "lArr", 8658); |
114 |
1 |
add("<==", "lArr", 8658); |
115 |
1 |
add("<===", "lArr", 8658); |
116 |
|
|
117 |
1 |
add("<=>", "hArr", 8660); |
118 |
1 |
add("<==>", "hArr", 8660); |
119 |
1 |
add("<===>", "hArr", 8660); |
120 |
|
|
121 |
1 |
add("<=", "le", 8804); |
122 |
1 |
add(">=", "ge", 8805); |
123 |
1 |
add("!=", "ne", 8800); |
124 |
1 |
add("~=", "asymp", 8776); |
125 |
|
} |
126 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
127 |
57 |
private static void add(String wikiEnity, String htmlEntity, int id)... |
128 |
|
{ |
129 |
57 |
Entity entity = new Entity(wikiEnity, htmlEntity, id); |
130 |
57 |
fWikiToHtml.put(wikiEnity, entity); |
131 |
57 |
fHtmlToWiki.put(htmlEntity, entity); |
132 |
57 |
fIdToWiki[id] = entity; |
133 |
|
} |
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
@param |
139 |
|
|
140 |
|
@return |
141 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
142 |
0 |
public static int getHtmlCodeByHtmlEntity(String htmlEntity)... |
143 |
|
{ |
144 |
0 |
Entity entity = fHtmlToWiki.get(htmlEntity); |
145 |
0 |
return entity != null ? entity.fHtmlCode : 0; |
146 |
|
} |
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
@param |
152 |
|
|
153 |
|
@return |
154 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
155 |
0 |
public static int getHtmlCodeByWikiSymbol(String wikiEntity)... |
156 |
|
{ |
157 |
0 |
Entity entity = fWikiToHtml.get(wikiEntity); |
158 |
0 |
return entity != null ? entity.fHtmlCode : 0; |
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
|
@param |
163 |
|
|
164 |
|
@return |
165 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
166 |
0 |
public static String getHtmlSymbol(char ch)... |
167 |
|
{ |
168 |
0 |
Entity entity = fIdToWiki[ch]; |
169 |
0 |
return entity != null ? entity.fWikiSymbol : null; |
170 |
|
} |
171 |
|
|
172 |
|
|
173 |
|
@param |
174 |
|
|
175 |
|
@return |
176 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
177 |
599 |
public static String getHtmlSymbol(String wikiEntity)... |
178 |
|
{ |
179 |
599 |
Entity entity = fWikiToHtml.get(wikiEntity); |
180 |
599 |
return entity != null ? entity.fHtmlSymbol : null; |
181 |
|
} |
182 |
|
|
183 |
|
|
184 |
|
@param |
185 |
|
|
186 |
|
@return |
187 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
188 |
0 |
public static String getWikiSymbol(char ch)... |
189 |
|
{ |
190 |
0 |
Entity entity = fIdToWiki[ch]; |
191 |
0 |
return entity != null ? entity.fWikiSymbol : null; |
192 |
|
} |
193 |
|
|
194 |
|
|
195 |
|
@param |
196 |
|
|
197 |
|
@return |
198 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
199 |
0 |
public static String getWikiSymbol(String htmlEntity)... |
200 |
|
{ |
201 |
0 |
Entity entity = fHtmlToWiki.get(htmlEntity); |
202 |
0 |
return entity != null ? entity.fHtmlSymbol : null; |
203 |
|
} |
204 |
|
} |