<commit_before>/*
 * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
 * 
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package net.java.sip.communicator.util;

import java.io.*;

import javax.swing.text.html.*;
import javax.swing.text.html.parser.*;

/**
 * A utility class that allows to extract the text content of an html page 
 * stripped from all formatting tags.
 * 
 * @author <NAME> <emcho at sip-communicator.org>
 * @author <NAME>
 */
public class Html2Text
{
    private static final Logger logger
        = Logger.getLogger(Html2Text.class);

    private static HTMLParserCallBack parser;

    /**
     * A utility method that allows to extract the text content of an html page 
     * stripped from all formatting tags. Method is synchronized to avoid 
     * concurrent access to the underlying html editor kit.
     * 
     * @param html the html string that we will extract the text from.
     * @return the text content of the <tt>html</tt> parameter.
     */
    public static synchronized String extractText(String html)
    {
        if (parser == null)
            parser = new HTMLParserCallBack();<commit_msg>Fix NPE, added null check in Html2Text.<commit_after>/*
 * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
 * 
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package net.java.sip.communicator.util;

import java.io.*;

import javax.swing.text.html.*;
import javax.swing.text.html.parser.*;

/**
 * A utility class that allows to extract the text content of an html page 
 * stripped from all formatting tags.
 * 
 * @author <NAME> <emcho at sip-communicator.org>
 * @author <NAME>
 */
public class Html2Text
{
    private static final Logger logger
        = Logger.getLogger(Html2Text.class);

    private static HTMLParserCallBack parser;

    /**
     * A utility method that allows to extract the text content of an html page 
     * stripped from all formatting tags. Method is synchronized to avoid 
     * concurrent access to the underlying html editor kit.
     * 
     * @param html the html string that we will extract the text from.
     * @return the text content of the <tt>html</tt> parameter.
     */
    public static synchronized String extractText(String html)
    {
        if(html == null)
            return null;

        if (parser == null)
            parser = new HTMLParserCallBack();
{'fraction_non_alphanumeric': 0.08431771894093687, 'fraction_numerical': 0.002036659877800407, 'mean_word_length': 2.910828025477707, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4257625', 'n_tokens_mistral': 686, 'n_tokens_neox': 656, 'n_words': 273}