org.jsoup.Jsoup.clean()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(670)

本文整理了Java中org.jsoup.Jsoup.clean()方法的一些代码示例,展示了Jsoup.clean()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jsoup.clean()方法的具体详情如下:
包路径:org.jsoup.Jsoup
类名称:Jsoup
方法名:clean

Jsoup.clean介绍

[英]Get safe HTML from untrusted input HTML, by parsing input HTML and filtering it through a white-list of permitted tags and attributes.
[中]通过解析输入HTML并通过允许的标记和属性的白名单进行过滤,从不受信任的输入HTML中获取安全的HTML。

代码示例

代码示例来源:origin: org.jsoup/jsoup

/**
 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 HTML (body fragment)
 @param whitelist white-list of permitted HTML elements
 @return safe HTML (body fragment)
 @see Cleaner#clean(Document)
 */
public static String clean(String bodyHtml, Whitelist whitelist) {
  return clean(bodyHtml, "", whitelist);
}

代码示例来源:origin: wuyouzhuguli/FEBS-Shiro

public static String clean(String content) {
  return Jsoup.clean(content, "", whitelist, outputSettings);
}

代码示例来源:origin: JpressProjects/jpress

public static String clean(String html) {
  if (StrUtils.isNotBlank(html))
    return Jsoup.clean(html, whitelist);
  return html;
}

代码示例来源:origin: k9mail/k-9

public static String extractText(String html) {
    return Jsoup.clean(html, Whitelist.none());
  }
}

代码示例来源:origin: RipMeApp/ripme

public String getDescription(String page) {
  try {
    // Fetch the image page
    Response resp = Http.url(page)
        .referrer(this.url)
        .response();
    cookies.putAll(resp.cookies());
    // Try to find the description
    Elements els = resp.parse().select("td[class=alt1][width=\"70%\"]");
    if (els.isEmpty()) {
      LOGGER.debug("No description at " + page);
      throw new IOException("No description found");
    }
    LOGGER.debug("Description found!");
    Document documentz = resp.parse();
    Element ele = documentz.select("td[class=alt1][width=\"70%\"]").get(0); // This is where the description is.
    // Would break completely if FurAffinity changed site layout.
    documentz.outputSettings(new Document.OutputSettings().prettyPrint(false));
    ele.select("br").append("\\n");
    ele.select("p").prepend("\\n\\n");
    LOGGER.debug("Returning description at " + page);
    String tempPage = Jsoup.clean(ele.html().replaceAll("\\\\n", System.getProperty("line.separator")), "", Whitelist.none(), new Document.OutputSettings().prettyPrint(false));
    return documentz.select("meta[property=og:title]").attr("content") + "\n" + tempPage; // Overridden saveText takes first line and makes it the file name.
  } catch (IOException ioe) {
    LOGGER.info("Failed to get description " + page + " : '" + ioe.getMessage() + "'");
    return null;
  }
}
@Override

代码示例来源:origin: tomoya92/pybbs

content = Jsoup.clean(content, Whitelist.relaxed().addTags("code", "pre").addAttributes("code", "class"));
Document parse = Jsoup.parse(content);
Elements tableElements = parse.select("table");

代码示例来源:origin: ron190/jsql-injection

Jsoup.clean(
  "<html>"+ StringUtil.detectUtf8(networkData.getSource()).replaceAll("#{5,}", "#*") + "</html>"
    .replaceAll("<img.*>", "")

代码示例来源:origin: tomoya92/pybbs

public Topic insertTopic(String title, String content, String tags, User user, HttpSession session) {
 Topic topic = new Topic();
 topic.setTitle(Jsoup.clean(title, Whitelist.simpleText()));
 topic.setContent(content);
 topic.setInTime(new Date());
 topic.setUserId(user.getId());
 topicMapper.insert(topic);
 // 增加用户积分
 user.setScore(user.getScore() + Integer.parseInt(systemConfigService.selectAllConfig().get("create_topic_score").toString()));
 userService.update(user);
 if (session != null) session.setAttribute("_user", user);
 // 保存标签
 List<Tag> tagList = tagService.insertTag(Jsoup.clean(tags, Whitelist.none()));
 // 处理标签与话题的关联
 topicTagService.insertTopicTag(topic.getId(), tagList);
 // 索引话题
 indexTopic(String.valueOf(topic.getId()), topic.getTitle(), topic.getContent());
 return topic;
}

代码示例来源:origin: tomoya92/pybbs

public Topic updateTopic(Topic topic, String title, String content, String tags) {
 topic.setTitle(Jsoup.clean(title, Whitelist.simpleText()));
 topic.setContent(content);
 topic.setModifyTime(new Date());
 topicMapper.updateById(topic);
 // 旧标签每个topicCount都-1
 tagService.reduceTopicCount(topic.getId());
 // 保存标签
 List<Tag> tagList = tagService.insertTag(Jsoup.clean(tags, Whitelist.none()));
 // 处理标签与话题的关联
 topicTagService.insertTopicTag(topic.getId(), tagList);
 // 索引话题
 indexTopic(String.valueOf(topic.getId()), topic.getTitle(), topic.getContent());
 // 缓存到redis里
 redisService.setString(Constants.REDIS_TOPIC_KEY + topic.getId(), JsonUtil.objectToJson(topic));
 return topic;
}

代码示例来源:origin: ron190/jsql-injection

htmlSource = Jsoup.clean(
  Jsoup.connect(this.url).get().html()
    .replaceAll("<img.*>", "")

代码示例来源:origin: opplus/springboot-admin

public static String clear(String html) {
  if (StringUtils.isNotBlank(html))
    return Jsoup.clean(html, whitelist);
  return html;
}

代码示例来源:origin: org.jetbrains.intellij.plugins/intellij-plugin-structure

@XmlElement(name = "change-notes")
 public void setChangeNotes(String changeNotes) {
  if(changeNotes == null){
   this.changeNotes = null;
  } else{
   this.changeNotes = Jsoup.clean(changeNotes.trim(), WHITELIST);
  }
 }
}

代码示例来源:origin: com.atlassian.jira/jira-core

@Nonnull
private String stripAllHtml(@Nonnull final String html)
{
  return Jsoup.clean(html, Whitelist.none());
}

代码示例来源:origin: zhangyd-c/OneBlog

public static String subKeywordsStr(String keywords) {
    String keys = StringUtils.isNotEmpty(keywords) && !"null".equals(keywords) ? keywords.trim().replaceAll(" +|,", ",").replaceAll(",,", ",") : null;
    return StringUtils.isEmpty(keys) ? null : Jsoup.clean(keys, Whitelist.simpleText());
  }
}

代码示例来源:origin: ORCID/ORCID-Source

public static String stripHtml(String s) {
  String output = Jsoup.clean(s, "", Whitelist.none(), outputSettings);
  output = output.replace(GT, DECODED_GT);
    output = output.replace(AMP, DECODED_AMP);            
    return output;
}

代码示例来源:origin: zhangyd-c/OneBlog

public static String subDescStr(String description, String content) {
  String desc = StringUtils.isNotEmpty(description) ? description.replaceAll("\r\n| ", "") : content.length() > 100 ? content.substring(0, 100) : content;
  return StringUtils.isEmpty(desc) ? null : Jsoup.clean(desc.trim(), Whitelist.simpleText());
}

代码示例来源:origin: com.atlassian.jira.plugins/jira-workflow-sharing-plugin

public String asMarkdown()
{
  return Jsoup.clean(markdown, Whitelist.relaxed());
}

代码示例来源:origin: com.atlassian.jira.plugins/jira-workflow-sharing-plugin

public String asHtml()
{
  return Jsoup.clean(pegDown.markdownToHtml(markdown),Whitelist.relaxed());
}

代码示例来源:origin: viritin/viritin

@Override
public void beforeClientResponse(boolean initial) {
  setContentMode(ContentMode.HTML);
  super.setValue(Jsoup.clean(richText, getWhitelist()));
  super.beforeClientResponse(initial);
}

代码示例来源:origin: com.vaadin/vaadin-rich-text-editor-flow

String sanitize(String html) {
  return org.jsoup.Jsoup.clean(html,
          org.jsoup.safety.Whitelist.basic()
          .addTags("img", "h1", "h2", "h3", "s")
          .addAttributes("img", "align", "alt", "height", "src", "title", "width")
          .addAttributes(":all", "style")
          .addProtocols("img", "src", "data"));
}

相关文章