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

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

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

Whitelist.basicWithImages介绍

[英]This whitelist allows the same text tags as #basic, and also allows img tags, with appropriate attributes, with src pointing to http or https.
[中]此白名单允许使用与#basic相同的文本标记,还允许使用img标记,带有适当的属性,src指向httphttps

代码示例

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

/**
 * Tests whether the input data is valid HTML using Jsoup.
 * @param data Potentially HTML data.
 * @return boolean indicating whether the input is valid HTML5.
 */
public static boolean isHTMLComponent(String data){
  return !data.isEmpty() && Jsoup.isValid(data, Whitelist.basicWithImages());
}

代码示例来源: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: info.magnolia/magnolia-module-rssaggregator

/**
 * Format and sanitize description input.
 *
 * @param origDescription original description as delivered by feed fetcher.
 * @param abbreviation gives the amount of characters used for abbreviation.
 * @return sanitized HTML output string.
 */
public static String formatDescription(String origDescription, Integer abbreviation) {
  // replace Java linebreaks with HTML
  //origDescription = StringUtils.replace(origDescription, "\n", "<br/>");
  // check if abbreviation is wanted
  if (abbreviation != null && abbreviation > 0) {
    origDescription = StringUtils.abbreviate(origDescription, abbreviation);
  }
  // Sanitize HTML input
  Whitelist whitelist = Whitelist.basicWithImages();
  whitelist.addTags("h1", "h2", "h3", "h4", "h5", "h6", "div");
  // table tags
  whitelist.addTags("table", "tbody", "td", "tfoot", "th", "thead", "tr");
  return Jsoup.clean(origDescription, whitelist);
}

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

/**
 * Wrapper around Jsoup clean method with the basic White list
 *   http://jsoup.org/cookbook/cleaning-html/whitelist-sanitizer
 * @param unsafe
 * @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);
  
}

代码示例来源:origin: jungilhan/awesome-blogs-android

Whitelist whitelist = Whitelist.basicWithImages()
               .addTags("div",
                   "h1", "h2", "h3", "h4", "h5", "h6",

代码示例来源: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 BASIC_WITH_IMAGES:
  whitelist = Whitelist.basicWithImages();
  break;
case NONE:

相关文章