@Test public void simpleBehaviourTest2() { String h = "Hello <b>there</b>!"; String cleanHtml = Jsoup.clean(h, Whitelist.simpleText()); assertEquals("Hello <b>there</b>!", TextUtil.stripNewlines(cleanHtml)); }
@Test public void simpleBehaviourTest() { String h = "<div><p class=foo><a href='http://evil.com'>Hello <b id=bar>there</b>!</a></div>"; String cleanHtml = Jsoup.clean(h, Whitelist.simpleText()); assertEquals("Hello <b>there</b>!", TextUtil.stripNewlines(cleanHtml)); }
@Test public void testClensing() { String pageTitle = StringEscapeUtils.unescapeHtml4(Jsoup.clean("Jeppistä jee", Whitelist.simpleText())); assertTrue("Jeppistä jee".equals(pageTitle)); }
@Dynamic("editor") public static Result promote() { models.User u = Mupi.getLocalUser(session()); MultipartFormData body = request().body().asMultipartFormData(); FilePart picture = body.getFile("picture"); String picturePath = BLANK_EVT; DynamicForm bindedForm = form().bindFromRequest(); Long i = getInterest(bindedForm.get("interest")); Long l = getLocation(bindedForm.get("location")); models.Interest iObj = null; models.Location lObj = null; if (i != null) iObj = models.Interest.find.byId(i); if (l != null) lObj = models.Location.find.byId(l); final Form<models.Promotion> filledForm = form(models.Promotion.class).bindFromRequest(); final models.Profile p = Mupi.getLocalUser(session()).profile; try { if (picture != null) { String fileName = picture.getFilename(); File file = picture.getFile(); int index = (fileName.toLowerCase()).lastIndexOf('.'); String extension = "png"; if (index > 0 && index < fileName.length() - 1) { extension = fileName.substring(index + 1).toLowerCase(); } String hashTime = getMD5(System.currentTimeMillis()); String hashCommunity = getMD5(iObj.toString() + lObj.toString()); File destinationFile = new File( MupiParams.EVENT_ROOT + MupiParams.PIC_ROOT + "//" + hashCommunity + "//" + hashTime + fileName); FileUtils.copyFile(file, destinationFile); picturePath = "/" + hashCommunity + "/" + hashTime + fileName; File medium = new File( MupiParams.EVENT_ROOT + MupiParams.PIC_MEDIUM + "//" + hashCommunity + "//" + hashTime + fileName); medium.mkdirs(); BufferedImage bi = ImageHandler.createSmallInterest(destinationFile); bi = ImageHandler.createMediumPromotion(destinationFile); ImageIO.write(bi, extension, medium); } else { picturePath = BLANK_EVT; } String safeDesc = Jsoup.clean(filledForm.get().getDescription(), Whitelist.simpleText()); Promotion pr = models.Promotion.create( p, lObj, iObj, filledForm.get().getTitle(), filledForm.get().getAddress(), filledForm.get().getDate(), filledForm.get().getTime(), safeDesc, filledForm.get().getLink(), picturePath, PubType.EVENT, new Integer(0), new Integer(0), new Double(0.0)); flash(Mupi.FLASH_MESSAGE_KEY, Messages.get("mupi.promotion.created")); List<UserEmail> l_ue = models.Profile.emailsFromPublication(pr.getPublication()); for (UserEmail ue : l_ue) { if (u.getEmail().equalsIgnoreCase(ue.getEmail())) System.out.println("Commenter: " + ue.getEmail()); else System.out.println(ue.getEmail()); } return redirect(routes.Feed.feed()); } catch (Exception e) { flash( Mupi.FLASH_ERROR_KEY, "Erro ao divulgar evento, por favor contate-nos para que possamos resolver este problema."); // System.out.println(e.getMessage()); e.printStackTrace(); return redirect(routes.Feed.feed()); } }
/** * 比较宽松的过滤,但是会过滤掉object,script, span,div等标签,适用于富文本编辑器内容或其他html内容 * * @param html * @return */ public static String simpleText(String html) { return Jsoup.clean(html, Whitelist.simpleText()); }