Here you can find the source of htmlDecode(String s)
public static String htmlDecode(String s)
//package com.java2s; /******************************************************************************* * Copyright (c) 2010 BSI Business Systems Integration AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors://from w ww. jav a 2 s . c o m * BSI Business Systems Integration AG - initial API and implementation ******************************************************************************/ public class Main { /** * @return decoded text, ready to be printed as text * <xmp>replaces &, ", ', <, > and all whitespace</xmp> */ public static String htmlDecode(String s) { if (s == null || s.length() == 0) { return s; } s = s.replace(" ", " "); s = s.replace(""", "\""); s = s.replace("'", "'"); s = s.replace("'", "'"); s = s.replace("<", "<"); s = s.replace(">", ">"); s = s.replace("&", "&"); // whitespace patterns String zeroOrMoreWhitespaces = "\\s*?"; String oneOrMoreWhitespaces = "\\s+?"; // replace <br/> by \n s = s.replaceAll( "<" + zeroOrMoreWhitespaces + "br" + zeroOrMoreWhitespaces + "/" + zeroOrMoreWhitespaces + ">", "\n"); // replace HTML-tabs by \t s = s.replaceAll("<" + zeroOrMoreWhitespaces + "span" + oneOrMoreWhitespaces + "style" + zeroOrMoreWhitespaces + "=" + zeroOrMoreWhitespaces + "\"white-space:pre\"" + zeroOrMoreWhitespaces + ">	<" + zeroOrMoreWhitespaces + "/" + zeroOrMoreWhitespaces + "span" + zeroOrMoreWhitespaces + ">", "\t"); return s; } public static int length(String s) { if (s == null) { return 0; } else { return s.length(); } } /** * replace plain text without using regex */ public static String replace(String s, String sOld, String sNew) { sNew = (sNew == null ? "" : sNew); if (s == null || sOld == null) { return s; } return s.replace(sOld, sNew); } }