Search in sources :

Example 1 with Cleaner

use of com.jsoup.safety.Cleaner in project User-Behavior-in-Facebook by abozanona.

the class Jsoup method clean.

/**
 *     Get safe HTML from untrusted input HTML, by parsing input HTML and filtering it through a white-list of permitted
 *     tags and attributes.
 *
 *     @param bodyHtml  input untrusted HMTL
 *     @param baseUri   URL to resolve relative URLs against
 *     @param whitelist white-list of permitted HTML elements
 *     @return safe HTML
 *
 *     @see Cleaner#clean(Document)
 */
public static String clean(String bodyHtml, String baseUri, Whitelist whitelist) {
    Document dirty = parseBodyFragment(bodyHtml, baseUri);
    Cleaner cleaner = new Cleaner(whitelist);
    Document clean = cleaner.clean(dirty);
    return clean.body().html();
}
Also used : Document(com.jsoup.nodes.Document) Cleaner(com.jsoup.safety.Cleaner)

Example 2 with Cleaner

use of com.jsoup.safety.Cleaner in project User-Behavior-in-Facebook by abozanona.

the class Jsoup method isValid.

/**
 *     Test if the input HTML has only tags and attributes allowed by the Whitelist. Useful for form validation. The input HTML should
 *     still be run through the cleaner to set up enforced attributes, and to tidy the output.
 *     @param bodyHtml HTML to test
 *     @param whitelist whitelist to test against
 *     @return true if no tags or attributes were removed; false otherwise
 *     @see #clean(String, com.jsoup.safety.Whitelist)
 */
public static boolean isValid(String bodyHtml, Whitelist whitelist) {
    Document dirty = parseBodyFragment(bodyHtml, "");
    Cleaner cleaner = new Cleaner(whitelist);
    return cleaner.isValid(dirty);
}
Also used : Document(com.jsoup.nodes.Document) Cleaner(com.jsoup.safety.Cleaner)

Aggregations

Document (com.jsoup.nodes.Document)2 Cleaner (com.jsoup.safety.Cleaner)2