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

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

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

Whitelist.simpleText介绍

[英]This whitelist allows only simple text formatting: b, em, i, strong, u. All other HTML (tags and attributes) will be removed.
[中]此白名单只允许使用简单的文本格式:[$0$]。所有其他HTML(标记和属性)都将被删除。

代码示例

代码示例来源: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: 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: 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 simpleHtml(String s) {
  String output = Jsoup.clean(s, "", Whitelist.simpleText(), outputSettings);
  // According to
    // http://jsoup.org/apidocs/org/jsoup/nodes/Entities.EscapeMode.html#xhtml
    // jsoup scape lt, gt, amp, apos, and quot for xhtml
    // So we want to restore them
    output = output.replace(LT, DECODED_LT);
    output = output.replace(GT, DECODED_GT);
    output = output.replace(AMP, DECODED_AMP);
    output = output.replace(APOS, DECODED_APOS);
    output = output.replace(QUOT, DECODED_QUOT);
    return output;
}

代码示例来源: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: 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 SIMPLE_TEXT:
  whitelist = Whitelist.simpleText();
  break;

相关文章