/*
* Copyright (C) 2010- Peer internet solutions
*
* This file is part of mixare.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>
*/
package org.mixare.lib;
import java.util.HashMap;
public class HtmlUnescape {
private static HashMap<String, String> htmlEntities;
static {
htmlEntities = new HashMap<String, String>();
htmlEntities.put("<", "<");
htmlEntities.put(">", ">");
htmlEntities.put("&", "&");
htmlEntities.put(""", "\"");
htmlEntities.put("à", "à");
htmlEntities.put("À", "À");
htmlEntities.put("â", "â");
htmlEntities.put("ä", "ä");
htmlEntities.put("Ä", "Ä");
htmlEntities.put("Â", "Â");
htmlEntities.put("å", "å");
htmlEntities.put("Å", "Å");
htmlEntities.put("æ", "æ");
htmlEntities.put("Æ", "Æ");
htmlEntities.put("ç", "ç");
htmlEntities.put("Ç", "Ç");
htmlEntities.put("é", "é");
htmlEntities.put("É", "É");
htmlEntities.put("è", "è");
htmlEntities.put("È", "È");
htmlEntities.put("ê", "ê");
htmlEntities.put("Ê", "Ê");
htmlEntities.put("ë", "ë");
htmlEntities.put("Ë", "Ë");
htmlEntities.put("ï", "ï");
htmlEntities.put("Ï", "Ï");
htmlEntities.put("ô", "ô");
htmlEntities.put("Ô", "Ô");
htmlEntities.put("ö", "ö");
htmlEntities.put("Ö", "Ö");
htmlEntities.put("ø", "ø");
htmlEntities.put("Ø", "Ø");
htmlEntities.put("ß", "ß");
htmlEntities.put("ù", "ù");
htmlEntities.put("Ù", "Ù");
htmlEntities.put("û", "û");
htmlEntities.put("Û", "Û");
htmlEntities.put("ü", "ü");
htmlEntities.put("Ü", "Ü");
htmlEntities.put(" ", " ");
htmlEntities.put("©", "\u00a9");
htmlEntities.put("®", "\u00ae");
htmlEntities.put("€", "\u20a0");
}
public static String unescapeHTML(String source, int start) {
int i, j;
i = source.indexOf("&", start);
if (i > -1) {
j = source.indexOf(";", i);
if (j > i) {
String entityToLookFor = source.substring(i, j + 1);
String value = (String) htmlEntities.get(entityToLookFor);
if (value != null) {
source = new StringBuffer().append(source.substring(0, i))
.append(value).append(source.substring(j + 1))
.toString();
return unescapeHTML(source, i + 1); // recursive call
}
}
}
return source;
}
}