tags:

views:

49

answers:

1

Hi, is there an easy way to dell htmldocument (inside a JTextPane) to not load images from the web? i cant think of anything smarter then to simply remove the tags or similar. and cant seem to find any "build in" functionality for it.

+1  A: 

this is the best i came up with:

String removeImageTags(String content)
{
    Pattern imageRegexp = Pattern.compile("<img.*?src=['\"]{1}([^\"']*)['\"]{1}.*?>");
    Matcher m = imageRegexp.matcher(content);
    if (m.find())
    {
        content = m.replaceFirst(m.group(1));
    }
    else
    {
        return content;
    }
    return removeImageTags(content);
}
Mikael Sundberg