/*
 * $Id$
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 *
 * $Log$
 * Revision 1.2  2006/05/24 13:40:42  marbobo
 * + getUnicodeCharForSwing() hinzugefügt
 *
 * Revision 1.1  2006/05/09 15:24:47  marbobo
 * + Initiale Version
 *
 */
package vkc.util;

import java.util.HashMap;

/**
 * Die Klasse konvertiert HTML-Entities (z.B. &amp;euro;) in entsprechende
 * Unicode-Äquivalente (&#8364; = \u20AC)
 * <p>
 * @author marbobo
 */
public final class VKCHtmlEntities2Unicode {
	private static final HashMap entities = new HashMap();
	private static final HashMap entitiesNotInSwing = new HashMap();
	
	static {
		//All known Html-Entities
		entities.put("&Acirc;", "\u00C2");
		entities.put("&acirc;", "\u00E2");
		entities.put("&acute;", "\u00B4");
		entities.put("&AElig;", "\u00C6");
		entities.put("&aelig;", "\u00E6");
		entities.put("&Agrave;", "\u00C0");
		entities.put("&agrave;", "\u00E0");
		entities.put("&alefsym;", "\u2135");
		entities.put("&Alpha;", "\u0391");
		entities.put("&alpha;", "\u03B1");
		entities.put("&amp;", "\u0026");
		entities.put("&and;", "\u2227");
		entities.put("&ang;", "\u2220");
		entities.put("&apos;", "\u0027");
		entities.put("&Aring;", "\u00C5");
		entities.put("&aring;", "\u00E5");
		entities.put("&asymp;", "\u2248");
		entities.put("&Atilde;", "\u00C3");
		entities.put("&atilde;", "\u00E3");
		entities.put("&Auml;", "\u00C4");
		entities.put("&auml;", "\u00E4");
		
		entities.put("&bdquo;", "\u201E");
		entities.put("&Beta;", "\u0392");
		entities.put("&beta;", "\u03B2");
		entities.put("&brvbar;", "\u00A6");
		entities.put("&bull;", "\u2022");
		
		entities.put("&cap;", "\u2229");
		entities.put("&Ccedil;", "\u00C7");
		entities.put("&ccedil;", "\u00E7");
		entities.put("&cedil;", "\u00B8");
		entities.put("&cent;", "\u00A2");
		entities.put("&Chi;", "\u03A7");
		entities.put("&chi;", "\u03C7");
		entities.put("&circ;", "\u02C6");
		entities.put("&clubs;", "\u2663");
		entities.put("&cong;", "\u2245");
		entities.put("&copy;", "\u00A9");
		entities.put("&crarr;", "\u21B5");
		entities.put("&cup;", "\u222A");
		entities.put("&curren;", "\u00A4");
		
		entities.put("&Dagger;", "\u2021");
		entities.put("&dagger;", "\u2020");
		entities.put("&dArr;", "\u21D3");
		entities.put("&darr;", "\u2193");
		entities.put("&deg;", "\u00B0");
		entities.put("&Delta;", "\u0394");
		entities.put("&delta;", "\u03B4");
		entities.put("&diams;", "\u2666");
		entities.put("&divide;", "\u00F7");
		
		entities.put("&Eacute;", "\u00C9");
		entities.put("&eacute;", "\u00E9");
		entities.put("&Ecirc;", "\u00CA");
		entities.put("&ecirc;", "\u00EA");
		entities.put("&Egrave;", "\u00C8");
		entities.put("&egrave;", "\u00E8");
		entities.put("&empty;", "\u2205");
		entities.put("&emsp;", "\u2003");
		entities.put("&ensp;", "\u2002");
		entities.put("&Epsilon;", "\u0395");
		entities.put("&epsilon;", "\u03B5");
		entities.put("&equiv;", "\u2261");
		entities.put("&Eta;", "\u0397");
		entities.put("&eta;", "\u03B7");
		entities.put("&ETH;", "\u00D0");
		entities.put("&eth;", "\u00F0");
		entities.put("&Euml;", "\u00CB");
		entities.put("&euml;", "\u00EB");
		entities.put("&euro;", "\u20AC");
		entities.put("&exist;", "\u2203");
		
		entities.put("&fnof;", "\u0192");
		entities.put("&forall;", "\u2200");
		entities.put("&frac12;", "\u00BD");
		entities.put("&frac14;", "\u00BC");
		entities.put("&frac34;", "\u00BE");
		entities.put("&frasl;", "\u2044");
		
		entities.put("&Gamma;", "\u0393");
		entities.put("&gamma;", "\u03B3");
		entities.put("&ge;", "\u2265");
		entities.put("&gt;", "\u003E");
		
		entities.put("&hArr;", "\u21D4");
		entities.put("&harr;", "\u2194");
		entities.put("&hearts;", "\u2665");
		entities.put("&hellip;", "\u2026");
		
		entities.put("&Iacute;", "\u00CD");
		entities.put("&iacute;", "\u00ED");
		entities.put("&Icirc;", "\u00CE");
		entities.put("&icirc;", "\u00EE");
		entities.put("&iexcl;", "\u00A1");
		entities.put("&Igrave;", "\u00CC");
		entities.put("&igrave;", "\u00EC");
		entities.put("&image;", "\u2111");
		entities.put("&infin;", "\u221E");
		entities.put("&int;", "\u222B");
		entities.put("&Iota;", "\u0399");
		entities.put("&iota;", "\u03B9");
		entities.put("&iquest;", "\u00BF");
		entities.put("&isin;", "\u2208");
		entities.put("&Iuml;", "\u00CF");
		entities.put("&iuml;", "\u00EF");
		
		entities.put("&Kappa;", "\u039A");
		entities.put("&kappa;", "\u03BA");
		
		entities.put("&Lambda;", "\u039B");
		entities.put("&lambda;", "\u03BB");
		entities.put("&lang;", "\u2329");
		entities.put("&laquo;", "\u00AB");
		entities.put("&lArr;", "\u21D0");
		entities.put("&larr;", "\u2190");
		entities.put("&lceil;", "\u2308");
		entities.put("&ldquo;", "\u201C");
		entities.put("&le;", "\u2264");
		entities.put("&lfloor;", "\u230A");
		entities.put("&lowast;", "\u2217");
		entities.put("&loz;", "\u25CA");
		entities.put("&lrm;", "\u200E");
		entities.put("&lsaquo;", "\u2039");
		entities.put("&lsquo;", "\u2018");
		entities.put("&lt;", "\u003C");
		
		entities.put("&macr;", "\u00AF");
		entities.put("&mdash;", "\u2014");
		entities.put("&micro;", "\u00B5");
		entities.put("&middot;", "\u00B7");
		entities.put("&minus;", "\u2212");
		entities.put("&Mu;", "\u039C");
		entities.put("&mu;", "\u03BC");
		
		entities.put("&nabla;", "\u2207");
		entities.put("&nbsp;", "\u00A0");
		entities.put("&ndash;", "\u2013");
		entities.put("&ne;", "\u2260");
		entities.put("&ni;", "\u220B");
		entities.put("&not;", "\u00AC");
		entities.put("&notin;", "\u2209");
		entities.put("&nsub;", "\u2284");
		entities.put("&Ntilde;", "\u00D1");
		entities.put("&ntilde;", "\u00F1");
		entities.put("&Nu;", "\u039D");
		entities.put("&nu;", "\u03BD");
		
		entities.put("&Oacute;", "\u00D3");
		entities.put("&oacute;", "\u00F3");
		entities.put("&Ocirc;", "\u00D4");
		entities.put("&ocirc;", "\u00F4");
		entities.put("&OElig;", "\u0152");
		entities.put("&oelig;", "\u0153");
		entities.put("&Ograve;", "\u00D2");
		entities.put("&ograve;", "\u00F2");
		entities.put("&oline;", "\u203E");
		entities.put("&Omega;", "\u03A9");
		entities.put("&omega;", "\u03C9");
		entities.put("&Omicron;", "\u039F");
		entities.put("&omicron;", "\u03BF");
		entities.put("&oplus;", "\u2295");
		entities.put("&or;", "\u2228");
		entities.put("&ordf;", "\u00AA");
		entities.put("&ordm;", "\u00BA");
		entities.put("&Oslash;", "\u00D8");
		entities.put("&oslash;", "\u00F8");
		entities.put("&Otilde;", "\u00D5");
		entities.put("&otilde;", "\u00F5");
		entities.put("&otimes;", "\u2297");
		entities.put("&Ouml;", "\u00D6");
		entities.put("&ouml;", "\u00F6");
		
		entities.put("&para;", "\u00B6");
		entities.put("&part;", "\u2202");
		entities.put("&permil;", "\u2030");
		entities.put("&perp;", "\u22A5");
		entities.put("&Phi;", "\u03A6");
		entities.put("&phi;", "\u03C6");
		entities.put("&Pi;", "\u03A0");
		entities.put("&pi;", "\u03C0");
		entities.put("&piv;", "\u03D6");
		entities.put("&plusmn;", "\u00B1");
		entities.put("&pound;", "\u00A3");
		entities.put("&Prime;", "\u2033");
		entities.put("&prime;", "\u2032");
		entities.put("&prod;", "\u220F");
		entities.put("&prop;", "\u221D");
		entities.put("&Psi;", "\u03A8");
		entities.put("&psi;", "\u03C8");
		
		entities.put("&quot;", new String(new char[]{'\u0022'}));
		
		entities.put("&radic;", "\u221A");
		entities.put("&rang;", "\u232A");
		entities.put("&raquo;", "\u00BB");
		entities.put("&rArr;", "\u21D2");
		entities.put("&rarr;", "\u2192");
		entities.put("&rceil;", "\u2309");
		entities.put("&rdquo;", "\u201D");
		entities.put("&real;", "\u211C");
		entities.put("&reg;", "\u00AE");
		entities.put("&rfloor;", "\u230B");
		entities.put("&Rho;", "\u03A1");
		entities.put("&rho;", "\u03C1");
		entities.put("&rlm;", "\u200F");
		entities.put("&rsaquo;", "\u203A");
		entities.put("&rsquo;", "\u2019");
		
		entities.put("&sbquo;", "\u201A");
		entities.put("&Scaron;", "\u0160");
		entities.put("&scaron;", "\u0161");
		entities.put("&sdot;", "\u22C5");
		entities.put("&sect;", "\u00A7");
		entities.put("&shy;", "\u00AD");
		entities.put("&Sigma;", "\u03A3");
		entities.put("&sigma;", "\u03C3");
		entities.put("&sigmaf;", "\u03C2");
		entities.put("&sim;", "\u223C");
		entities.put("&spades;", "\u2660");
		entities.put("&sub;", "\u2282");
		entities.put("&sube;", "\u2286");
		entities.put("&sum;", "\u2211");
		entities.put("&sup;", "\u2283");
		entities.put("&sup1;", "\u00B9");
		entities.put("&sup2;", "\u00B2");
		entities.put("&sup3;", "\u00B3");
		entities.put("&supe;", "\u2287");
		entities.put("&szlig;", "\u00DF");
		
		entities.put("&Tau;", "\u03A4");
		entities.put("&tau;", "\u03C4");
		entities.put("&there4;", "\u2234");
		entities.put("&Theta;", "\u0398");
		entities.put("&theta;", "\u03B8");
		entities.put("&thetasym;", "\u03D1");
		entities.put("&thinsp;", "\u2009");
		entities.put("&THORN;", "\u00DE");
		entities.put("&thorn;", "\u00FE");
		entities.put("&tilde;", "\u02DC");
		entities.put("&times;", "\u00D7");
		entities.put("&trade;", "\u2122");
		
		entities.put("&Uacute;", "\u00DA");
		entities.put("&uacute;", "\u00FA");
		entities.put("&uArr;", "\u21D1");
		entities.put("&uarr;", "\u2191");
		entities.put("&Ucirc;", "\u00DB");
		entities.put("&ucirc;", "\u00FB");
		entities.put("&Ugrave;", "\u00D9");
		entities.put("&ugrave;", "\u00F9");
		entities.put("&uml;", "\u00A8");
		entities.put("&upsih;", "\u03D2");
		entities.put("&Upsilon;", "\u03A5");
		entities.put("&upsilon;", "\u03C5");
		entities.put("&Uuml;", "\u00DC");
		entities.put("&uuml;", "\u00FC");
		
		entities.put("&weierp;", "\u2118");
		
		entities.put("&Xi;", "\u039E");
		entities.put("&xi;", "\u03BE");
		
		entities.put("&Yacute;", "\u00DD");
		entities.put("&yacute;", "\u00FD");
		entities.put("&yen;", "\u00A5");
		entities.put("&Yuml;", "\u0178");
		entities.put("&yuml;", "\u00FF");
		
		entities.put("&Zeta;", "\u0396");
		entities.put("&zeta;", "\u03B6");
		entities.put("&zwj;", "\u200D");
		entities.put("&zwnj;", "\u200C");
		
		//The flowing Html-Entities are not in Swing Html-Editor
		entitiesNotInSwing.put("&alefsym;", "\u2135");
		entitiesNotInSwing.put("&Alpha;", "\u0391");
		entitiesNotInSwing.put("&alpha;", "\u03B1");
		entitiesNotInSwing.put("&and;", "\u2227");
		entitiesNotInSwing.put("&ang;", "\u2220");
		entitiesNotInSwing.put("&apos;", "\u0027");
		entitiesNotInSwing.put("&asymp;", "\u2248");

		entitiesNotInSwing.put("&bdquo;", "\u201E");
		entitiesNotInSwing.put("&Beta;", "\u0392");
		entitiesNotInSwing.put("&beta;", "\u03B2");
		entitiesNotInSwing.put("&bull;", "\u2022");

		entitiesNotInSwing.put("&cap;", "\u2229");
		entitiesNotInSwing.put("&Chi;", "\u03A7");
		entitiesNotInSwing.put("&chi;", "\u03C7");
		entitiesNotInSwing.put("&circ;", "\u02C6");
		entitiesNotInSwing.put("&clubs;", "\u2663");
		entitiesNotInSwing.put("&cong;", "\u2245");
		entitiesNotInSwing.put("&crarr;", "\u21B5");
		entitiesNotInSwing.put("&cup;", "\u222A");

		entitiesNotInSwing.put("&Dagger;", "\u2021");
		entitiesNotInSwing.put("&dagger;", "\u2020");
		entitiesNotInSwing.put("&dArr;", "\u21D3");
		entitiesNotInSwing.put("&darr;", "\u2193");
		entitiesNotInSwing.put("&Delta;", "\u0394");
		entitiesNotInSwing.put("&delta;", "\u03B4");
		entitiesNotInSwing.put("&diams;", "\u2666");

		entitiesNotInSwing.put("&empty;", "\u2205");
		entitiesNotInSwing.put("&emsp;", "\u2003");
		entitiesNotInSwing.put("&ensp;", "\u2002");
		entitiesNotInSwing.put("&Epsilon;", "\u0395");
		entitiesNotInSwing.put("&epsilon;", "\u03B5");
		entitiesNotInSwing.put("&equiv;", "\u2261");
		entitiesNotInSwing.put("&Eta;", "\u0397");
		entitiesNotInSwing.put("&eta;", "\u03B7");
		entitiesNotInSwing.put("&euro;", "\u20AC");
		entitiesNotInSwing.put("&exist;", "\u2203");

		entitiesNotInSwing.put("&fnof;", "\u0192");
		entitiesNotInSwing.put("&forall;", "\u2200");
		entitiesNotInSwing.put("&frasl;", "\u2044");

		entitiesNotInSwing.put("&Gamma;", "\u0393");
		entitiesNotInSwing.put("&gamma;", "\u03B3");
		entitiesNotInSwing.put("&ge;", "\u2265");

		entitiesNotInSwing.put("&hArr;", "\u21D4");
		entitiesNotInSwing.put("&harr;", "\u2194");
		entitiesNotInSwing.put("&hearts;", "\u2665");
		entitiesNotInSwing.put("&hellip;", "\u2026");

		entitiesNotInSwing.put("&image;", "\u2111");
		entitiesNotInSwing.put("&infin;", "\u221E");
		entitiesNotInSwing.put("&int;", "\u222B");
		entitiesNotInSwing.put("&Iota;", "\u0399");
		entitiesNotInSwing.put("&iota;", "\u03B9");
		entitiesNotInSwing.put("&isin;", "\u2208");

		entitiesNotInSwing.put("&Kappa;", "\u039A");
		entitiesNotInSwing.put("&kappa;", "\u03BA");
		
		entitiesNotInSwing.put("&Lambda;", "\u039B");
		entitiesNotInSwing.put("&lambda;", "\u03BB");
		entitiesNotInSwing.put("&lang;", "\u2329");
		entitiesNotInSwing.put("&lArr;", "\u21D0");
		entitiesNotInSwing.put("&larr;", "\u2190");
		entitiesNotInSwing.put("&lceil;", "\u2308");
		entitiesNotInSwing.put("&ldquo;", "\u201C");
		entitiesNotInSwing.put("&le;", "\u2264");
		entitiesNotInSwing.put("&lfloor;", "\u230A");
		entitiesNotInSwing.put("&lowast;", "\u2217");
		entitiesNotInSwing.put("&loz;", "\u25CA");
		entitiesNotInSwing.put("&lrm;", "\u200E");
		entitiesNotInSwing.put("&lsaquo;", "\u2039");
		entitiesNotInSwing.put("&lsquo;", "\u2018");

		entitiesNotInSwing.put("&mdash;", "\u2014");
		entitiesNotInSwing.put("&minus;", "\u2212");
		entitiesNotInSwing.put("&Mu;", "\u039C");
		entitiesNotInSwing.put("&mu;", "\u03BC");
		
		entitiesNotInSwing.put("&nabla;", "\u2207");
		entitiesNotInSwing.put("&ndash;", "\u2013");
		entitiesNotInSwing.put("&ne;", "\u2260");
		entitiesNotInSwing.put("&ni;", "\u220B");
		entitiesNotInSwing.put("&notin;", "\u2209");
		entitiesNotInSwing.put("&nsub;", "\u2284");
		entitiesNotInSwing.put("&Nu;", "\u039D");
		entitiesNotInSwing.put("&nu;", "\u03BD");

		entitiesNotInSwing.put("&OElig;", "\u0152");
		entitiesNotInSwing.put("&oelig;", "\u0153");
		entitiesNotInSwing.put("&oline;", "\u203E");
		entitiesNotInSwing.put("&Omega;", "\u03A9");
		entitiesNotInSwing.put("&omega;", "\u03C9");
		entitiesNotInSwing.put("&Omicron;", "\u039F");
		entitiesNotInSwing.put("&omicron;", "\u03BF");
		entitiesNotInSwing.put("&oplus;", "\u2295");
		entitiesNotInSwing.put("&or;", "\u2228");
		entitiesNotInSwing.put("&otimes;", "\u2297");

		entitiesNotInSwing.put("&part;", "\u2202");
		entitiesNotInSwing.put("&permil;", "\u2030");
		entitiesNotInSwing.put("&perp;", "\u22A5");
		entitiesNotInSwing.put("&Phi;", "\u03A6");
		entitiesNotInSwing.put("&phi;", "\u03C6");
		entitiesNotInSwing.put("&Pi;", "\u03A0");
		entitiesNotInSwing.put("&pi;", "\u03C0");
		entitiesNotInSwing.put("&piv;", "\u03D6");
		entitiesNotInSwing.put("&Prime;", "\u2033");
		entitiesNotInSwing.put("&prime;", "\u2032");
		entitiesNotInSwing.put("&prod;", "\u220F");
		entitiesNotInSwing.put("&prop;", "\u221D");
		entitiesNotInSwing.put("&Psi;", "\u03A8");
		entitiesNotInSwing.put("&psi;", "\u03C8");

		entitiesNotInSwing.put("&radic;", "\u221A");
		entitiesNotInSwing.put("&rang;", "\u232A");
		entitiesNotInSwing.put("&rArr;", "\u21D2");
		entitiesNotInSwing.put("&rarr;", "\u2192");
		entitiesNotInSwing.put("&rceil;", "\u2309");
		entitiesNotInSwing.put("&rdquo;", "\u201D");
		entitiesNotInSwing.put("&real;", "\u211C");
		entitiesNotInSwing.put("&rArr;", "\u21D2");
		entitiesNotInSwing.put("&rarr;", "\u2192");
		entitiesNotInSwing.put("&rceil;", "\u2309");
		entitiesNotInSwing.put("&rdquo;", "\u201D");
		entitiesNotInSwing.put("&real;", "\u211C");
		entitiesNotInSwing.put("&rfloor;", "\u230B");
		entitiesNotInSwing.put("&Rho;", "\u03A1");
		entitiesNotInSwing.put("&rho;", "\u03C1");
		entitiesNotInSwing.put("&rlm;", "\u200F");
		entitiesNotInSwing.put("&rsaquo;", "\u203A");
		entitiesNotInSwing.put("&rsquo;", "\u2019");
		
		entitiesNotInSwing.put("&sbquo;", "\u201A");
		entitiesNotInSwing.put("&Scaron;", "\u0160");
		entitiesNotInSwing.put("&scaron;", "\u0161");
		entitiesNotInSwing.put("&sdot;", "\u22C5");
		entitiesNotInSwing.put("&Sigma;", "\u03A3");
		entitiesNotInSwing.put("&sigma;", "\u03C3");
		entitiesNotInSwing.put("&sigmaf;", "\u03C2");
		entitiesNotInSwing.put("&sim;", "\u223C");
		entitiesNotInSwing.put("&spades;", "\u2660");
		entitiesNotInSwing.put("&sub;", "\u2282");
		entitiesNotInSwing.put("&sube;", "\u2286");
		entitiesNotInSwing.put("&sum;", "\u2211");
		entitiesNotInSwing.put("&sup;", "\u2283");
		entitiesNotInSwing.put("&supe;", "\u2287");

		entitiesNotInSwing.put("&Tau;", "\u03A4");
		entitiesNotInSwing.put("&tau;", "\u03C4");
		entitiesNotInSwing.put("&there4;", "\u2234");
		entitiesNotInSwing.put("&Theta;", "\u0398");
		entitiesNotInSwing.put("&theta;", "\u03B8");
		entitiesNotInSwing.put("&thetasym;", "\u03D1");
		entitiesNotInSwing.put("&thinsp;", "\u2009");
		entitiesNotInSwing.put("&tilde;", "\u02DC");
		entitiesNotInSwing.put("&trade;", "\u2122");

		entitiesNotInSwing.put("&uArr;", "\u21D1");
		entitiesNotInSwing.put("&uarr;", "\u2191");
		entitiesNotInSwing.put("&upsih;", "\u03D2");
		entitiesNotInSwing.put("&Upsilon;", "\u03A5");
		entitiesNotInSwing.put("&upsilon;", "\u03C5");

		entitiesNotInSwing.put("&weierp;", "\u2118");
		
		entitiesNotInSwing.put("&Xi;", "\u039E");
		entitiesNotInSwing.put("&xi;", "\u03BE");

		entitiesNotInSwing.put("&Yuml;", "\u0178");

		entitiesNotInSwing.put("&Zeta;", "\u0396");
		entitiesNotInSwing.put("&zeta;", "\u03B6");
		entitiesNotInSwing.put("&zwj;", "\u200D");
		entitiesNotInSwing.put("&zwnj;", "\u200C");
	}
	
	public static final String getUnicodeChar(String entity) {
		return (String)entities.get(entity);
	}
	
	public static final String getUnicodeCharForSwing(String entity) {
		return (String)entitiesNotInSwing.get(entity);
	}
}