src/it/finsiel/siged/util/HtmlParser.java
public static String stripHtmlTags(String s) {
        // initial check of input:
        if (s == null) {
            return null;
        }
        s = removeComments(s);
        // remove header
        s = HEADER_REMOVAL_PATTERN.matcher(s).replaceAll("");

        // remove extra whitespace
        s = WHITE_SPACE_REMOVAL_PATTERN.matcher(s).replaceAll(" ");

        // replace br, p and heading tags with newlines
        s = BREAK_TO_NL_PATTERN.matcher(s).replaceAll("\n");
        s = P_TO_DOUBLE_NL_PATTERN.matcher(s).replaceAll("\n\n");
        s = DIV_TO_DOUBLE_NL_PATTERN.matcher(s).replaceAll("\n\n");
        s = H_TO_DOUBLE_NL_PATTERN.matcher(s).replaceAll("\n\n");

        // strip remaining tags
        s = STRIP_TAGS_PATTERN.matcher(s).replaceAll("");

        // tag stripping can leave some double spaces at line beginnings
        s = TRIM_SPACE_PATTERN.matcher(s).replaceAll("\n").trim();

        return s;
    }
/**
     * Strips html tags and removes extra spaces which occurs due to e.g.
     * indentation of the html and the head section, which does not contain any
     * textual information. <br>
     * The conversion rutine does the following: <br>
     * 1. Removes the header from the html file, i.e. everything from the html
     * tag until and including the starting body tag. <br>
     * 2. Replaces multiple consecutive whitespace characters with a single
     * space (since extra whitespace should be ignored in html). <br>
     * 3. Replaces ending br tags with a single newline character <br>
     * 4. Replaces ending p, div and heading tags with two newlines characters;
     * resulting in a single empty line btw. paragraphs. <br>
     * 5. Strips remaining html tags. <br>
     * <br>
     * NB: The tag stripping is done using a very simple regular expression,
     * which removes everything between &lt and &gt. Therefore too much text
     * could in some (hopefully rare!?) cases be removed.
     * 
     * @param s
     *            Input string
     * @return Input stripped for html tags
     */
Strips html tags and removes extra spaces which occurs due to e.g.
indentation of the html and the head section, which does not contain any
textual information. 
The conversion rutine does the following: 
1. Removes the header from the html file, i.e. everything from the html
tag until and including the starting body tag. 
2. Replaces multiple consecutive whitespace characters with a single
space (since extra whitespace should be ignored in html). 
3. Replaces ending br tags with a single newline character 
4. Replaces ending p, div and heading tags with two newlines characters;
resulting in a single empty line btw. paragraphs. 
5. Strips remaining html tags. 

NB: The tag stripping is done using a very simple regular expression,
which removes everything between < and &gt. Therefore too much text
could in some (hopefully rare!?) cases be removed.

@param s
Input string
@return Input stripped for html tags
Strips html tags and removes extra spaces which occurs due to e . g . indentation of the html and the head section which does not contain any textual information . The conversion rutine does the following : 1 . Removes the header from the html file i . e . everything from the html tag until and including the starting body tag . 2 . Replaces multiple consecutive whitespace characters with a single space ( since extra whitespace should be ignored in html ) . 3 . Replaces ending br tags with a single newline character 4 . Replaces ending p div and heading tags with two newlines characters ; resulting in a single empty line btw . paragraphs . 5 . Strips remaining html tags . NB : The tag stripping is done using a very simple regular expression which removes everything between < and &gt . Therefore too much text could in some ( hopefully rare!? ) cases be removed . @param s Input string @return Input stripped for html tags
public static String stripHtmlTags(String s) {
        if (s == null) {
            return null;
        }
        s = removeComments(s);
        s = HEADER_REMOVAL_PATTERN.matcher(s).replaceAll("");
        s = WHITE_SPACE_REMOVAL_PATTERN.matcher(s).replaceAll(" ");
        s = BREAK_TO_NL_PATTERN.matcher(s).replaceAll("\n");
        s = P_TO_DOUBLE_NL_PATTERN.matcher(s).replaceAll("\n\n");
        s = DIV_TO_DOUBLE_NL_PATTERN.matcher(s).replaceAll("\n\n");
        s = H_TO_DOUBLE_NL_PATTERN.matcher(s).replaceAll("\n\n");
        s = STRIP_TAGS_PATTERN.matcher(s).replaceAll("");
        s = TRIM_SPACE_PATTERN.matcher(s).replaceAll("\n").trim();
        return s;
    }
public static String stripHtmlTags ( String s ) { if ( s == null ) { return null ; } s = removeComments ( s ) ; s = HEADER_REMOVAL_PATTERN . matcher ( s ) . replaceAll ( "" ) ; s = WHITE_SPACE_REMOVAL_PATTERN . matcher ( s ) . replaceAll ( " " ) ; s = BREAK_TO_NL_PATTERN . matcher ( s ) . replaceAll ( "\n" ) ; s = P_TO_DOUBLE_NL_PATTERN . matcher ( s ) . replaceAll ( "\n\n" ) ; s = DIV_TO_DOUBLE_NL_PATTERN . matcher ( s ) . replaceAll ( "\n\n" ) ; s = H_TO_DOUBLE_NL_PATTERN . matcher ( s ) . replaceAll ( "\n\n" ) ; s = STRIP_TAGS_PATTERN . matcher ( s ) . replaceAll ( "" ) ; s = TRIM_SPACE_PATTERN . matcher ( s ) . replaceAll ( "\n" ) . trim ( ) ; return s ; }
Strips html tags and removes extra spaces which occurs due to e.g.
Strips html tags and removes extra spaces which occurs due to e . g .
// initial check of input: // remove header // remove extra whitespace // replace br, p and heading tags with newlines // strip remaining tags // tag stripping can leave some double spaces at line beginnings