This project has retired. For details please refer to its Attic page.
Source code
001package org.apache.archiva.xml;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *  http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.util.HashMap;
023import java.util.Map;
024
025/**
026 * LatinEntities - simple utility class to handle latin entity conversion. 
027 *
028 *
029 */
030public class LatinEntities
031{
032    private static final Map<String, String> defaultEntityMap;
033
034    static
035    {
036        defaultEntityMap = new HashMap<>();
037
038        defaultEntityMap.put( "nbsp", "\u00a0" );
039        defaultEntityMap.put( "iexcl", "\u00a1" );
040        defaultEntityMap.put( "cent", "\u00a2" );
041        defaultEntityMap.put( "pound", "\u00a3" );
042        defaultEntityMap.put( "curren", "\u00a4" );
043        defaultEntityMap.put( "yen", "\u00a5" );
044        defaultEntityMap.put( "brvbar", "\u00a6" );
045        defaultEntityMap.put( "sect", "\u00a7" );
046        defaultEntityMap.put( "uml", "\u00a8" );
047        defaultEntityMap.put( "copy", "\u00a9" );
048        defaultEntityMap.put( "ordf", "\u00aa" );
049        defaultEntityMap.put( "laquo", "\u00ab" );
050        defaultEntityMap.put( "not", "\u00ac" );
051        defaultEntityMap.put( "shy", "\u00ad" );
052        defaultEntityMap.put( "reg", "\u00ae" );
053        defaultEntityMap.put( "macr", "\u00af" );
054        defaultEntityMap.put( "deg", "\u00b0" );
055        defaultEntityMap.put( "plusmn", "\u00b1" );
056        defaultEntityMap.put( "sup2", "\u00b2" );
057        defaultEntityMap.put( "sup3", "\u00b3" );
058        defaultEntityMap.put( "acute", "\u00b4" );
059        defaultEntityMap.put( "micro", "\u00b5" );
060        defaultEntityMap.put( "para", "\u00b6" );
061        defaultEntityMap.put( "middot", "\u00b7" );
062        defaultEntityMap.put( "cedil", "\u00b8" );
063        defaultEntityMap.put( "sup1", "\u00b9" );
064        defaultEntityMap.put( "ordm", "\u00ba" );
065        defaultEntityMap.put( "raquo", "\u00bb" );
066        defaultEntityMap.put( "frac14", "\u00bc" );
067        defaultEntityMap.put( "frac12", "\u00bd" );
068        defaultEntityMap.put( "frac34", "\u00be" );
069        defaultEntityMap.put( "iquest", "\u00bf" );
070        defaultEntityMap.put( "Agrave", "\u00c0" );
071        defaultEntityMap.put( "Aacute", "\u00c1" );
072        defaultEntityMap.put( "Acirc", "\u00c2" );
073        defaultEntityMap.put( "Atilde", "\u00c3" );
074        defaultEntityMap.put( "Auml", "\u00c4" );
075        defaultEntityMap.put( "Aring", "\u00c5" );
076        defaultEntityMap.put( "AElig", "\u00c6" );
077        defaultEntityMap.put( "Ccedil", "\u00c7" );
078        defaultEntityMap.put( "Egrave", "\u00c8" );
079        defaultEntityMap.put( "Eacute", "\u00c9" );
080        defaultEntityMap.put( "Ecirc", "\u00ca" );
081        defaultEntityMap.put( "Euml", "\u00cb" );
082        defaultEntityMap.put( "Igrave", "\u00cc" );
083        defaultEntityMap.put( "Iacute", "\u00cd" );
084        defaultEntityMap.put( "Icirc", "\u00ce" );
085        defaultEntityMap.put( "Iuml", "\u00cf" );
086        defaultEntityMap.put( "ETH", "\u00d0" );
087        defaultEntityMap.put( "Ntilde", "\u00d1" );
088        defaultEntityMap.put( "Ograve", "\u00d2" );
089        defaultEntityMap.put( "Oacute", "\u00d3" );
090        defaultEntityMap.put( "Ocirc", "\u00d4" );
091        defaultEntityMap.put( "Otilde", "\u00d5" );
092        defaultEntityMap.put( "Ouml", "\u00d6" );
093        defaultEntityMap.put( "times", "\u00d7" );
094        defaultEntityMap.put( "Oslash", "\u00d8" );
095        defaultEntityMap.put( "Ugrave", "\u00d9" );
096        defaultEntityMap.put( "Uacute", "\u00da" );
097        defaultEntityMap.put( "Ucirc", "\u00db" );
098        defaultEntityMap.put( "Uuml", "\u00dc" );
099        defaultEntityMap.put( "Yacute", "\u00dd" );
100        defaultEntityMap.put( "THORN", "\u00de" );
101        defaultEntityMap.put( "szlig", "\u00df" );
102        defaultEntityMap.put( "agrave", "\u00e0" );
103        defaultEntityMap.put( "aacute", "\u00e1" );
104        defaultEntityMap.put( "acirc", "\u00e2" );
105        defaultEntityMap.put( "atilde", "\u00e3" );
106        defaultEntityMap.put( "auml", "\u00e4" );
107        defaultEntityMap.put( "aring", "\u00e5" );
108        defaultEntityMap.put( "aelig", "\u00e6" );
109        defaultEntityMap.put( "ccedil", "\u00e7" );
110        defaultEntityMap.put( "egrave", "\u00e8" );
111        defaultEntityMap.put( "eacute", "\u00e9" );
112        defaultEntityMap.put( "ecirc", "\u00ea" );
113        defaultEntityMap.put( "euml", "\u00eb" );
114        defaultEntityMap.put( "igrave", "\u00ec" );
115        defaultEntityMap.put( "iacute", "\u00ed" );
116        defaultEntityMap.put( "icirc", "\u00ee" );
117        defaultEntityMap.put( "iuml", "\u00ef" );
118        defaultEntityMap.put( "eth", "\u00f0" );
119        defaultEntityMap.put( "ntilde", "\u00f1" );
120        defaultEntityMap.put( "ograve", "\u00f2" );
121        defaultEntityMap.put( "oacute", "\u00f3" );
122        defaultEntityMap.put( "ocirc", "\u00f4" );
123        defaultEntityMap.put( "otilde", "\u00f5" );
124        defaultEntityMap.put( "ouml", "\u00f6" );
125        defaultEntityMap.put( "divide", "\u00f7" );
126        defaultEntityMap.put( "oslash", "\u00f8" );
127        defaultEntityMap.put( "ugrave", "\u00f9" );
128        defaultEntityMap.put( "uacute", "\u00fa" );
129        defaultEntityMap.put( "ucirc", "\u00fb" );
130        defaultEntityMap.put( "uuml", "\u00fc" );
131        defaultEntityMap.put( "yacute", "\u00fd" );
132        defaultEntityMap.put( "thorn", "\u00fe" );
133        defaultEntityMap.put( "yuml", "\u00ff" );
134
135        // ----------------------------------------------------------------------
136        // Special entities
137        // ----------------------------------------------------------------------
138
139        defaultEntityMap.put( "OElig", "\u0152" );
140        defaultEntityMap.put( "oelig", "\u0153" );
141        defaultEntityMap.put( "Scaron", "\u0160" );
142        defaultEntityMap.put( "scaron", "\u0161" );
143        defaultEntityMap.put( "Yuml", "\u0178" );
144        defaultEntityMap.put( "circ", "\u02c6" );
145        defaultEntityMap.put( "tilde", "\u02dc" );
146        defaultEntityMap.put( "ensp", "\u2002" );
147        defaultEntityMap.put( "emsp", "\u2003" );
148        defaultEntityMap.put( "thinsp", "\u2009" );
149        defaultEntityMap.put( "zwnj", "\u200c" );
150        defaultEntityMap.put( "zwj", "\u200d" );
151        defaultEntityMap.put( "lrm", "\u200e" );
152        defaultEntityMap.put( "rlm", "\u200f" );
153        defaultEntityMap.put( "ndash", "\u2013" );
154        defaultEntityMap.put( "mdash", "\u2014" );
155        defaultEntityMap.put( "lsquo", "\u2018" );
156        defaultEntityMap.put( "rsquo", "\u2019" );
157        defaultEntityMap.put( "sbquo", "\u201a" );
158        defaultEntityMap.put( "ldquo", "\u201c" );
159        defaultEntityMap.put( "rdquo", "\u201d" );
160        defaultEntityMap.put( "bdquo", "\u201e" );
161        defaultEntityMap.put( "dagger", "\u2020" );
162        defaultEntityMap.put( "Dagger", "\u2021" );
163        defaultEntityMap.put( "permil", "\u2030" );
164        defaultEntityMap.put( "lsaquo", "\u2039" );
165        defaultEntityMap.put( "rsaquo", "\u203a" );
166        defaultEntityMap.put( "euro", "\u20ac" );
167
168        // ----------------------------------------------------------------------
169        // Symbol entities
170        // ----------------------------------------------------------------------
171
172        defaultEntityMap.put( "fnof", "\u0192" );
173        defaultEntityMap.put( "Alpha", "\u0391" );
174        defaultEntityMap.put( "Beta", "\u0392" );
175        defaultEntityMap.put( "Gamma", "\u0393" );
176        defaultEntityMap.put( "Delta", "\u0394" );
177        defaultEntityMap.put( "Epsilon", "\u0395" );
178        defaultEntityMap.put( "Zeta", "\u0396" );
179        defaultEntityMap.put( "Eta", "\u0397" );
180        defaultEntityMap.put( "Theta", "\u0398" );
181        defaultEntityMap.put( "Iota", "\u0399" );
182        defaultEntityMap.put( "Kappa", "\u039a" );
183        defaultEntityMap.put( "Lambda", "\u039b" );
184        defaultEntityMap.put( "Mu", "\u039c" );
185        defaultEntityMap.put( "Nu", "\u039d" );
186        defaultEntityMap.put( "Xi", "\u039e" );
187        defaultEntityMap.put( "Omicron", "\u039f" );
188        defaultEntityMap.put( "Pi", "\u03a0" );
189        defaultEntityMap.put( "Rho", "\u03a1" );
190        defaultEntityMap.put( "Sigma", "\u03a3" );
191        defaultEntityMap.put( "Tau", "\u03a4" );
192        defaultEntityMap.put( "Upsilon", "\u03a5" );
193        defaultEntityMap.put( "Phi", "\u03a6" );
194        defaultEntityMap.put( "Chi", "\u03a7" );
195        defaultEntityMap.put( "Psi", "\u03a8" );
196        defaultEntityMap.put( "Omega", "\u03a9" );
197        defaultEntityMap.put( "alpha", "\u03b1" );
198        defaultEntityMap.put( "beta", "\u03b2" );
199        defaultEntityMap.put( "gamma", "\u03b3" );
200        defaultEntityMap.put( "delta", "\u03b4" );
201        defaultEntityMap.put( "epsilon", "\u03b5" );
202        defaultEntityMap.put( "zeta", "\u03b6" );
203        defaultEntityMap.put( "eta", "\u03b7" );
204        defaultEntityMap.put( "theta", "\u03b8" );
205        defaultEntityMap.put( "iota", "\u03b9" );
206        defaultEntityMap.put( "kappa", "\u03ba" );
207        defaultEntityMap.put( "lambda", "\u03bb" );
208        defaultEntityMap.put( "mu", "\u03bc" );
209        defaultEntityMap.put( "nu", "\u03bd" );
210        defaultEntityMap.put( "xi", "\u03be" );
211        defaultEntityMap.put( "omicron", "\u03bf" );
212        defaultEntityMap.put( "pi", "\u03c0" );
213        defaultEntityMap.put( "rho", "\u03c1" );
214        defaultEntityMap.put( "sigmaf", "\u03c2" );
215        defaultEntityMap.put( "sigma", "\u03c3" );
216        defaultEntityMap.put( "tau", "\u03c4" );
217        defaultEntityMap.put( "upsilon", "\u03c5" );
218        defaultEntityMap.put( "phi", "\u03c6" );
219        defaultEntityMap.put( "chi", "\u03c7" );
220        defaultEntityMap.put( "psi", "\u03c8" );
221        defaultEntityMap.put( "omega", "\u03c9" );
222        defaultEntityMap.put( "thetasym", "\u03d1" );
223        defaultEntityMap.put( "upsih", "\u03d2" );
224        defaultEntityMap.put( "piv", "\u03d6" );
225        defaultEntityMap.put( "bull", "\u2022" );
226        defaultEntityMap.put( "hellip", "\u2026" );
227        defaultEntityMap.put( "prime", "\u2032" );
228        defaultEntityMap.put( "Prime", "\u2033" );
229        defaultEntityMap.put( "oline", "\u203e" );
230        defaultEntityMap.put( "frasl", "\u2044" );
231        defaultEntityMap.put( "weierp", "\u2118" );
232        defaultEntityMap.put( "image", "\u2111" );
233        defaultEntityMap.put( "real", "\u211c" );
234        defaultEntityMap.put( "trade", "\u2122" );
235        defaultEntityMap.put( "alefsym", "\u2135" );
236        defaultEntityMap.put( "larr", "\u2190" );
237        defaultEntityMap.put( "uarr", "\u2191" );
238        defaultEntityMap.put( "rarr", "\u2192" );
239        defaultEntityMap.put( "darr", "\u2193" );
240        defaultEntityMap.put( "harr", "\u2194" );
241        defaultEntityMap.put( "crarr", "\u21b5" );
242        defaultEntityMap.put( "lArr", "\u21d0" );
243        defaultEntityMap.put( "uArr", "\u21d1" );
244        defaultEntityMap.put( "rArr", "\u21d2" );
245        defaultEntityMap.put( "dArr", "\u21d3" );
246        defaultEntityMap.put( "hArr", "\u21d4" );
247        defaultEntityMap.put( "forall", "\u2200" );
248        defaultEntityMap.put( "part", "\u2202" );
249        defaultEntityMap.put( "exist", "\u2203" );
250        defaultEntityMap.put( "empty", "\u2205" );
251        defaultEntityMap.put( "nabla", "\u2207" );
252        defaultEntityMap.put( "isin", "\u2208" );
253        defaultEntityMap.put( "notin", "\u2209" );
254        defaultEntityMap.put( "ni", "\u220b" );
255        defaultEntityMap.put( "prod", "\u220f" );
256        defaultEntityMap.put( "sum", "\u2211" );
257        defaultEntityMap.put( "minus", "\u2212" );
258        defaultEntityMap.put( "lowast", "\u2217" );
259        defaultEntityMap.put( "radic", "\u221a" );
260        defaultEntityMap.put( "prop", "\u221d" );
261        defaultEntityMap.put( "infin", "\u221e" );
262        defaultEntityMap.put( "ang", "\u2220" );
263        defaultEntityMap.put( "and", "\u2227" );
264        defaultEntityMap.put( "or", "\u2228" );
265        defaultEntityMap.put( "cap", "\u2229" );
266        defaultEntityMap.put( "cup", "\u222a" );
267        defaultEntityMap.put( "int", "\u222b" );
268        defaultEntityMap.put( "there4", "\u2234" );
269        defaultEntityMap.put( "sim", "\u223c" );
270        defaultEntityMap.put( "cong", "\u2245" );
271        defaultEntityMap.put( "asymp", "\u2248" );
272        defaultEntityMap.put( "ne", "\u2260" );
273        defaultEntityMap.put( "equiv", "\u2261" );
274        defaultEntityMap.put( "le", "\u2264" );
275        defaultEntityMap.put( "ge", "\u2265" );
276        defaultEntityMap.put( "sub", "\u2282" );
277        defaultEntityMap.put( "sup", "\u2283" );
278        defaultEntityMap.put( "nsub", "\u2284" );
279        defaultEntityMap.put( "sube", "\u2286" );
280        defaultEntityMap.put( "supe", "\u2287" );
281        defaultEntityMap.put( "oplus", "\u2295" );
282        defaultEntityMap.put( "otimes", "\u2297" );
283        defaultEntityMap.put( "perp", "\u22a5" );
284        defaultEntityMap.put( "sdot", "\u22c5" );
285        defaultEntityMap.put( "lceil", "\u2308" );
286        defaultEntityMap.put( "rceil", "\u2309" );
287        defaultEntityMap.put( "lfloor", "\u230a" );
288        defaultEntityMap.put( "rfloor", "\u230b" );
289        defaultEntityMap.put( "lang", "\u2329" );
290        defaultEntityMap.put( "rang", "\u232a" );
291        defaultEntityMap.put( "loz", "\u25ca" );
292        defaultEntityMap.put( "spades", "\u2660" );
293        defaultEntityMap.put( "clubs", "\u2663" );
294        defaultEntityMap.put( "hearts", "\u2665" );
295        defaultEntityMap.put( "diams", "\u2666" );
296    }
297
298    public static String resolveEntity( String entity )
299    {
300        if ( entity == null )
301        {
302            // Invalid. null.
303            return entity;
304        }
305
306        if ( entity.trim().length() <= 0 )
307        {
308            // Invalid. empty.
309            return entity;
310        }
311
312        if ( !( entity.charAt( 0 ) == '&' ) && ( entity.charAt( entity.length() ) == ';' ) )
313        {
314            // Invalid, not an entity.
315            return entity;
316        }
317
318        String result = (String) defaultEntityMap.get( entity.substring( 1, entity.length() - 1 ) );
319        if ( result == null )
320        {
321            return entity;
322        }
323
324        return result;
325    }
326}