Java HTML to String htmlToString(String aS_Text)

Here you can find the source of htmlToString(String aS_Text)

Description

html To String

License

Open Source License

Declaration

public static final String htmlToString(String aS_Text) 

Method Source Code

//package com.java2s;
/*/*from  w  w w  .j av  a2s  . co  m*/
NetForm Library
---------------
Copyright (C) 2001-2005 - Sampsa Sohlman, Teemu Sohlman
    
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
    
This library 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
Lesser General Public License for more details.
    
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
*/

public class Main {
    public static final String htmlToString(String aS_Text) {
        if (aS_Text == null) {
            return null;
        }

        StringBuffer l_StringBuffer = new StringBuffer();
        int li_length = aS_Text.length();
        for (int li_index = 0; li_index < li_length; li_index++) {
            char l_char = aS_Text.charAt(li_index);
            switch (l_char) {
            case '&':
                if (li_index + 3 < li_length && aS_Text.charAt(li_index + 1) == 'l'
                        && aS_Text.charAt(li_index + 2) == 't' && aS_Text.charAt(li_index + 3) == ';') {
                    l_StringBuffer.append('<');
                    li_index += 3;
                } else if (li_index + 3 < li_length && aS_Text.charAt(li_index + 1) == 'g'
                        && aS_Text.charAt(li_index + 2) == 't' && aS_Text.charAt(li_index + 3) == ';') {
                    l_StringBuffer.append('>');
                    li_index += 3;
                } else if (li_index + 4 < li_length && aS_Text.charAt(li_index + 1) == 'a'
                        && aS_Text.charAt(li_index + 2) == 'm' && aS_Text.charAt(li_index + 3) == 'p'
                        && aS_Text.charAt(li_index + 4) == ';') {
                    l_StringBuffer.append('&');
                    li_index += 4;
                } else if (li_index + 5 < li_length && aS_Text.charAt(li_index + 1) == 'q'
                        && aS_Text.charAt(li_index + 2) == 'u' && aS_Text.charAt(li_index + 3) == 'o'
                        && aS_Text.charAt(li_index + 4) == 't' && aS_Text.charAt(li_index + 5) == ';') {
                    l_StringBuffer.append('&');
                    li_index += 5;
                }
                break;
            default:
                l_StringBuffer.append(l_char);
            }
        }
        return l_StringBuffer.toString();
    }
}

Related

  1. html2Plain(String text)
  2. html2Text(String html)
  3. htmlToStr(String htmlStr, int max_count)
  4. htmlToString(String s)
  5. htmlToString(String string)
  6. htmlToText(String html)
  7. htmlToText(String html)