org.jsoup.safety.Whitelist.none()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(341)

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

Whitelist.none介绍

[英]This whitelist allows only text nodes: all HTML will be stripped.
[中]此白名单仅允许文本节点:所有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

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: viritin/viritin

protected Whitelist getWhitelist() {
  return Whitelist.none();
}

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

protected Whitelist getWhitelist() {
  return Whitelist.none();
}

代码示例来源: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: com.atlassian.jira/jira-core

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

代码示例来源:origin: IQSS/dataverse

/**
 * Strip all HTMl tags
 * 
 * http://jsoup.org/apidocs/org/jsoup/safety/Whitelist.html#none%28%29
 * 
 * @param unsafe
 * @return 
 */
public static String stripAllTags(String unsafe){
  
  if (unsafe == null){
    return null;
  }        
  
  return Jsoup.clean(unsafe, Whitelist.none());
  
}

代码示例来源: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

/**
 * 自定义的白名单
 *
 * @return
 */
private static Whitelist custome() {
  return Whitelist.none().addTags("p", "strong", "pre", "code", "span", "blockquote", "br").addAttributes("span", "class");
}

代码示例来源:origin: org.appverse.web.framework.modules.backend.core.api/appverse-web-modules-backend-core-api

public String stripXSS( String value )
{
  if( value != null )
  {
    System.out.println("STRIP XSS -> ["+value+"]");
    // Use the ESAPI library to avoid encoded attacks.
    value = ESAPI.encoder().canonicalize( value );
    // Avoid null characters
    value = value.replaceAll("\0", "");
    // Clean out HTML
    value = Jsoup.clean(value, Whitelist.none());
    System.out.println("STRIPED XSS -> ["+value+"]");
  }
  return value;
}

代码示例来源:origin: org.sakaiproject.kernel/sakai-kernel-impl

@Override
public String stripHtmlFromText(String text, boolean smartSpacing, boolean stripEscapeSequences)
{
  if (StringUtils.isBlank(text)) return text;
  if (smartSpacing) {
    text = text.replaceAll("/br>", "/br> ").replaceAll("/p>", "/p> ").replaceAll("/tr>", "/tr> ");
  }
  if (stripEscapeSequences) {
    org.jsoup.nodes.Document document = org.jsoup.Jsoup.parse(text);
    org.jsoup.nodes.Element body = document.body();
    //remove any html tags, unescape any escape characters
    text = body.text();
    //&nbsp; are converted to char code 160, java doesn't treat it like whitespace, so replace it with ' '
    text = text.replace((char)160, ' ');
  } else {
    text = org.jsoup.Jsoup.clean(text, "", org.jsoup.safety.Whitelist.none(), new org.jsoup.nodes.Document.OutputSettings().prettyPrint(false).outline(false));
  }
  if (smartSpacing || stripEscapeSequences) {
    text = text.replaceAll("\\s+", " ");
  }
  return text.trim();
}

代码示例来源:origin: apache/chukwa

/**
   * Strips any potential XSS threats out of the value
   * @param value is a string
   * @return filtered string
   */
  public String filter( String value ) {
   if( value == null )
    return null;
      // Use the ESAPI library to avoid encoded attacks.
   value = ESAPI.encoder().canonicalize( value );
    // Avoid null characters
   value = value.replaceAll("\0", "");
    // Clean out HTML
   value = Jsoup.clean( value, Whitelist.none() );
    return value;
  }
}

代码示例来源:origin: org.appverse.web.framework.modules.backend.core.api/appverse-web-modules-backend-core-api

/**
   * Strips any potential XSS threats out of the value
   * @param value
   * @return
   */
  public static String stripXSS( String value )
  {
    if( value != null )
    {
      // Use the ESAPI library to avoid encoded attacks.
      value = ESAPI.encoder().canonicalize( value );

      // Avoid null characters
      value = value.replaceAll("\0", "");

      // Clean out HTML
      // This clean, removes all html tags. so instead of &lt;script&gt;, it simple removes the <script> tag.
      value = Jsoup.clean(value, Whitelist.none());
    }
    return value;
  }
}

代码示例来源:origin: org.apache.myfaces.tobago/tobago-core

@Override
public void setProperties(final Properties configuration) {
 checkLocked();
 unmodifiable = true;
 for (final String key : configuration.stringPropertyNames()) {
  if ("whitelist".equals(key)) {
   whitelistName = configuration.getProperty(key);
   if ("basic".equals(whitelistName)) {
    whitelist = Whitelist.basic();
   } else if ("basicWithImages".equals(whitelistName)) {
    whitelist = Whitelist.basicWithImages();
   } else if ("none".equals(whitelistName)) {
    whitelist = Whitelist.none();
   } else if ("relaxed".equals(whitelistName)) {
    whitelist = Whitelist.relaxed();
   } else if ("simpleText".equals(whitelistName)) {
    whitelist = Whitelist.simpleText();
   } else {
    throw new TobagoConfigurationException(
      "Unknown configuration value for 'whitelist' in tobago-config.xml found! value='" + whitelistName + "'");
   }
  } else {
   throw new TobagoConfigurationException(
     "Unknown configuration key in tobago-config.xml found! key='" + key + "'");
  }
 }
 if (LOG.isInfoEnabled()) {
  LOG.warn("Using whitelist '" + whitelistName + "' for sanitizing!");
 }
}

代码示例来源:origin: mkalus/segrada

@Override
  public String toPlain(String markupText) {
    // sane default
    if (markupText == null || markupText.equals("")) return "";

    // first clean to have valid html
    String cleaned = Jsoup.clean(markupText, Whitelist.basic());
    // then strip all html out
    cleaned = Jsoup.clean(cleaned, Whitelist.none());

    // unescape all entities
    cleaned = Parser.unescapeEntities(cleaned, false);

    // clean further
    return super.toPlain(cleaned);
  }
}

代码示例来源:origin: com.eduworks/ew.levr.base

wl = Whitelist.none();
else
  wl = Whitelist.basic();

代码示例来源:origin: br.com.anteros/Anteros-Bean-Validation

public void initialize(SafeHtml safeHtmlAnnotation) {
  switch ( safeHtmlAnnotation.whitelistType() ) {
    case BASIC:
      whitelist = Whitelist.basic();
      break;
    case BASIC_WITH_IMAGES:
      whitelist = Whitelist.basicWithImages();
      break;
    case NONE:
      whitelist = Whitelist.none();
      break;
    case RELAXED:
      whitelist = Whitelist.relaxed();
      break;
    case SIMPLE_TEXT:
      whitelist = Whitelist.simpleText();
      break;
  }
  whitelist.addTags( safeHtmlAnnotation.additionalTags() );
  for ( SafeHtml.Tag tag : safeHtmlAnnotation.additionalTagsWithAttributes() ) {
    whitelist.addAttributes( tag.name(), tag.attributes() );
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.hibernate-validator

@Override
public void initialize(SafeHtml safeHtmlAnnotation) {
  switch ( safeHtmlAnnotation.whitelistType() ) {
    case BASIC:
      whitelist = Whitelist.basic();
      break;
    case BASIC_WITH_IMAGES:
      whitelist = Whitelist.basicWithImages();
      break;
    case NONE:
      whitelist = Whitelist.none();
      break;
    case RELAXED:
      whitelist = Whitelist.relaxed();
      break;
    case SIMPLE_TEXT:
      whitelist = Whitelist.simpleText();
      break;
  }
  whitelist.addTags( safeHtmlAnnotation.additionalTags() );
  for ( SafeHtml.Tag tag : safeHtmlAnnotation.additionalTagsWithAttributes() ) {
    whitelist.addAttributes( tag.name(), tag.attributes() );
  }
}

代码示例来源:origin: org.hibernate.validator/hibernate-validator

break;
case NONE:
  whitelist = Whitelist.none();
  break;
case RELAXED:

相关文章