Java HTML to Text html2text(String htmlStr)

Here you can find the source of html2text(String htmlStr)

Description

Converts html content to text.

License

Open Source License

Parameter

Parameter Description
htmlStr a parameter

Return

converted string

Declaration

public static String html2text(String htmlStr) 

Method Source Code

//package com.java2s;
/**/*  w ww.j a  v  a  2s . c  o m*/
 * Copyright 2014 Comcast Cable Communications Management, LLC
 *
 * This file is part of CATS.
 *
 * CATS 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.
 *
 * CATS 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 CATS.  If not, see <http://www.gnu.org/licenses/>.
 */

import org.jsoup.Jsoup;

public class Main {
    /**
     * Converts html content to text.
     * 
     * @param htmlStr
     * @return converted string
     */
    public static String html2text(String htmlStr) {
        if ((null == htmlStr) || (htmlStr.isEmpty())) {
            throw new IllegalArgumentException("The input html string was null or empty");
        }
        return Jsoup.parse(htmlStr).text();
    }
}

Related

  1. html2text(final String html)
  2. html2text(String html)
  3. text(Element e)
  4. text(Element element)
  5. textOf(final Element el)
  6. toElement(String html)