5

I'm implementing an email web client. Sometimes some emails come with HTML content. For security reasons I don't want to render the HTML code as it comes from the original source, but escape or even change the value of some unsafe elements or properties. I was about to start working on a library to do this, but I thought that maybe there is already some work done on this.

Is there any Java library that already does this?

Some examples of functionality I'm looking for:

  • Changing property "src" in element "img" for a stakeholder image
  • Remove "stript" elements.
  • Remove "import" at-rule.

I don't mind if such library is open-source or proprietary, just want to know if there is something already done about it.

6

After some days I found Jsoup to do such thing, they even have a special method to do it: http://jsoup.org/cookbook/cleaning-html/whitelist-sanitizer.

However, this library loads all the content first (it uses a model similar to XML's DOM) So this is not a perfect solution.

I'm going to leave my answer here but I'm not going to "accept it" straight away in hope someone else comes up with a better solution (something similar to XML's SAX)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.