Java HTML Escape escapeHTML(String text)

Here you can find the source of escapeHTML(String text)

Description

escape HTML

License

Open Source License

Declaration

public static String escapeHTML(String text) 

Method Source Code


//package com.java2s;
/*/*from   ww  w. j  a v a  2  s.c o m*/
 *  This file is part of MONGKIE. Visit <http://www.mongkie.org/> for details.
 *  Copyright (C) 2012 Korean Bioinformation Center(KOBIC)
 * 
 *  MONGKIE is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  MONGKE 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 Affero General Public License for more details.
 * 
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.HashMap;
import java.util.Map;

public class Main {
    private static final Map<Character, String> HTML2ESCAPE_MAP = new HashMap<Character, String>();

    public static String escapeHTML(String text) {
        StringBuilder escaped = new StringBuilder();
        int n = text.length();
        for (int i = 0; i < n; i++) {
            char c = text.charAt(i);
            escaped.append(HTML2ESCAPE_MAP.containsKey(c) ? HTML2ESCAPE_MAP.get(c) : c);
        }
        return escaped.toString();
    }
}

Related

  1. escapeHTML(String aText)
  2. escapeHtml(String s)
  3. escapeHTML(String s)
  4. escapeHTML(String s)
  5. escapeHtml(String s)
  6. escapeHTML(String text)
  7. escapeHTMLLine(String line)
  8. escapeHTMLSpecialChars(String aText)
  9. escapeHTMLTagCopy(String text)