src/it/finsiel/siged/util/HtmlParser.java
public static String substituteEmailAddress(String s, boolean ignoreLinks) {
        if (ignoreLinks) {
            // Do not take existing link tags into account
            return substituteEmailAddress(s);
        }

        logger.info("Source:\n" + s);

        // initialisation
        Matcher noLinkMatcher = EMAIL_PATTERN.matcher(s);
        Matcher withLinkMatcher = EMAIL_PATTERN_INC_LINK.matcher(s);
        int pos = 0; // current position in s
        int length = s.length();
        StringBuffer buf = new StringBuffer();

        while (pos < length) {
            if (noLinkMatcher.find(pos)) {
                // an email adress was found - check whether its already a link
                int s1 = noLinkMatcher.start();
                int e1 = noLinkMatcher.end();
                boolean insertLink;

                if (withLinkMatcher.find(pos)) {
                    // found an email address with links - is it the same?
                    int s2 = withLinkMatcher.start();
                    int e2 = withLinkMatcher.end();

                    if ((s2 < s1) && (e2 > e1)) {
                        // same email adress - just append and continue
                        buf.append(s.substring(pos, e2));
                        pos = e2;
                        insertLink = false; // already handled
                    } else {
                        // not the same
                        insertLink = true;
                    }
                } else {
                    // no match with link tags
                    insertLink = true;
                }

                // shall we insert a link?
                if (insertLink) {
                    String email = s.substring(s1, e1);
                    String link = "<a href=\"mailto:" + email + "\">" + email
                            + "</a>";
                    buf.append(s.substring(pos, s1));
                    buf.append(link);
                    pos = e1;
                }
            } else {
                // no more matches - append rest of string
                buf.append(s.substring(pos));
                pos = length;
            }
        }

        // return result
        String result = buf.toString();
        logger.info("Result:\n" + result);

        return result;
    }
/**
     * Transforms email-addresses into HTML just as
     * substituteEmailAddress(String), but tries to ignore email-addresses,
     * which are already links, if the ignore links flag is set. <br>
     * This extended functionality is necessary when parsing a text which is
     * already (partly) html. <br>
     * 
     * 
     * @param s
     *            input text
     * @param ignoreLinks
     *            if true link tags are ignored. This gives a wrong result if
     *            some e-mail adresses are already links (but uses reg. expr.
     *            directly, and is therefore faster)
     * @return text with email-adresses transformed to links
     */
Transforms email-addresses into HTML just as
substituteEmailAddress(String), but tries to ignore email-addresses,
which are already links, if the ignore links flag is set. 
This extended functionality is necessary when parsing a text which is
already (partly) html.

@param s
input text
@param ignoreLinks
if true link tags are ignored. This gives a wrong result if
some e-mail adresses are already links (but uses reg. expr.
directly, and is therefore faster)
@return text with email-adresses transformed to links
Transforms email - addresses into HTML just as substituteEmailAddress ( String ) but tries to ignore email - addresses which are already links if the ignore links flag is set . This extended functionality is necessary when parsing a text which is already ( partly ) html . @param s input text @param ignoreLinks if true link tags are ignored . This gives a wrong result if some e - mail adresses are already links ( but uses reg . expr . directly and is therefore faster ) @return text with email - adresses transformed to links
public static String substituteEmailAddress(String s, boolean ignoreLinks) {
        if (ignoreLinks) {
            return substituteEmailAddress(s);
        }
        logger.info("Source:\n" + s);
        Matcher noLinkMatcher = EMAIL_PATTERN.matcher(s);
        Matcher withLinkMatcher = EMAIL_PATTERN_INC_LINK.matcher(s);
        int pos = 0; 
        int length = s.length();
        StringBuffer buf = new StringBuffer();
        while (pos < length) {
            if (noLinkMatcher.find(pos)) {
                int s1 = noLinkMatcher.start();
                int e1 = noLinkMatcher.end();
                boolean insertLink;
                if (withLinkMatcher.find(pos)) {
                    int s2 = withLinkMatcher.start();
                    int e2 = withLinkMatcher.end();
                    if ((s2 < s1) && (e2 > e1)) {
                        buf.append(s.substring(pos, e2));
                        pos = e2;
                        insertLink = false; 
                    } else {
                        insertLink = true;
                    }
                } else {
                    insertLink = true;
                }
                if (insertLink) {
                    String email = s.substring(s1, e1);
                    String link = "<a href=\"mailto:" + email + "\">" + email
                            + "</a>";
                    buf.append(s.substring(pos, s1));
                    buf.append(link);
                    pos = e1;
                }
            } else {
                buf.append(s.substring(pos));
                pos = length;
            }
        }
        String result = buf.toString();
        logger.info("Result:\n" + result);
        return result;
    }
public static String substituteEmailAddress ( String s , boolean ignoreLinks ) { if ( ignoreLinks ) { return substituteEmailAddress ( s ) ; } logger . info ( "Source:\n" + s ) ; Matcher noLinkMatcher = EMAIL_PATTERN . matcher ( s ) ; Matcher withLinkMatcher = EMAIL_PATTERN_INC_LINK . matcher ( s ) ; int pos = 0 ; int length = s . length ( ) ; StringBuffer buf = new StringBuffer ( ) ; while ( pos < length ) { if ( noLinkMatcher . find ( pos ) ) { int s1 = noLinkMatcher . start ( ) ; int e1 = noLinkMatcher . end ( ) ; boolean insertLink ; if ( withLinkMatcher . find ( pos ) ) { int s2 = withLinkMatcher . start ( ) ; int e2 = withLinkMatcher . end ( ) ; if ( ( s2 < s1 ) && ( e2 > e1 ) ) { buf . append ( s . substring ( pos , e2 ) ) ; pos = e2 ; insertLink = false ; } else { insertLink = true ; } } else { insertLink = true ; } if ( insertLink ) { String email = s . substring ( s1 , e1 ) ; String link = "<a href=\"mailto:" + email + "\">" + email + "</a>" ; buf . append ( s . substring ( pos , s1 ) ) ; buf . append ( link ) ; pos = e1 ; } } else { buf . append ( s . substring ( pos ) ) ; pos = length ; } } String result = buf . toString ( ) ; logger . info ( "Result:\n" + result ) ; return result ; }
Transforms email-addresses into HTML just as
 substituteEmailAddress(String), but tries to ignore email-addresses,
 which are already links, if the ignore links flag is set.
Transforms email - addresses into HTML just as substituteEmailAddress ( String ) but tries to ignore email - addresses which are already links if the ignore links flag is set .
// Do not take existing link tags into account // initialisation // current position in s // an email adress was found - check whether its already a link // found an email address with links - is it the same? // same email adress - just append and continue // already handled // not the same // no match with link tags // shall we insert a link? // no more matches - append rest of string // return result