List of usage examples for org.jsoup.safety Whitelist basicWithImages
public static Whitelist basicWithImages()
From source file:edu.harvard.iq.dataverse.util.MarkupChecker.java
/** * Wrapper around Jsoup clean method with the basic White list * http://jsoup.org/cookbook/cleaning-html/whitelist-sanitizer * @param unsafe//from ww w .j ava 2s . c o m * @return */ public static String sanitizeBasicHTML(String unsafe) { if (unsafe == null) { return null; } // basic includes: a, b, blockquote, br, cite, code, dd, dl, dt, em, i, li, ol, p, pre, q, small, span, strike, strong, sub, sup, u, ul //Whitelist wl = Whitelist.basic().addTags("img", "h1", "h2", "h3", "kbd", "hr", "s", "del"); Whitelist wl = Whitelist.basicWithImages().addTags("h1", "h2", "h3", "kbd", "hr", "s", "del", "map", "area") .addAttributes("img", "usemap").addAttributes("map", "name") .addAttributes("area", "shape", "coords", "href", "title", "alt") .addEnforcedAttribute("a", "target", "_blank"); return Jsoup.clean(unsafe, wl); }
From source file:com.thruzero.common.core.infonode.InfoNodeElement.java
public String getSafeText() { String result = getText();//w ww . j av a 2s . c om if (StringUtils.isNotEmpty(result)) { result = Jsoup.clean(result, Whitelist.basicWithImages()); } return result; }
From source file:com.thruzero.common.core.infonode.InfoNodeElement.java
public String getSafeChildText(final String name) { String result = getChildText(name); if (StringUtils.isNotEmpty(result)) { result = Jsoup.clean(result, Whitelist.basicWithImages()); }/* ww w.java 2 s . c o m*/ return result; }
From source file:com.metadot.book.connectr.server.domain.StreamItem.java
/** * convert a feed entry to a StreamItem//from w ww.j a v a2 s . co m */ @SuppressWarnings("unchecked") private static StreamItem buildItem(String urlstring, SyndFeed sf, SyndEntry entry, Set<Long> ukeys) { StreamItem item = null; String title = "", url = "", description = "", feedDescription = "", feedTitle = "", author = "", imageUrl = ""; Date date = null; String descr = null; try { // gather all the information..... url = entry.getLink(); date = entry.getPublishedDate(); feedTitle = sf.getTitle(); feedDescription = sf.getDescription(); title = Jsoup.clean(entry.getTitle(), Whitelist.simpleText()); // for twitter, first remove the leading author string if (url.contains("twitter.com")) { int cindex = title.indexOf(":"); if (cindex > 0) { title = title.substring(cindex + 1); } } if (entry.getDescription() != null) { descr = entry.getDescription().getValue(); } if (descr == null) { if (entry.getContents().size() > 0) { SyndContent content = (SyndContent) entry.getContents().get(0); if (content.getType().equalsIgnoreCase("html")) { descr = content.getValue(); } } } if (descr != null) { // sanitize the content description = Jsoup.clean(descr, Whitelist.basicWithImages()); } List<SyndPerson> sauthors = entry.getAuthors(); List<String> auths = new ArrayList<String>(); for (SyndPerson auth : sauthors) { auths.add(auth.getName()); } author = StringUtils.join(auths, ", "); SyndImage eImg = sf.getImage(); if (eImg != null) { imageUrl = eImg.getUrl(); } else { // if twitter link... if (url.contains("twitter.com")) { // then see if a second link is available-- if so, it should be the link to the image List<SyndLink> links = entry.getLinks(); if (links.size() >= 2) { SyndLink imgl = links.get(1); imageUrl = imgl.getHref(); } } } item = new StreamItem(title, description, feedDescription, date, feedTitle, author, url, urlstring, imageUrl, ukeys); item.buildDescrSummary(); } catch (Exception e) { e.printStackTrace(); } return item; }