本文整理了Java中org.jsoup.safety.Whitelist.basic()
方法的一些代码示例,展示了Whitelist.basic()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Whitelist.basic()
方法的具体详情如下:
包路径:org.jsoup.safety.Whitelist
类名称:Whitelist
方法名:basic
[英]This whitelist allows a fuller range of text nodes: a, b, blockquote, br, cite, code, dd, dl, dt, em, i, li, ol, p, pre, q, small, span, strike, strong, sub, sup, u, ul
, and appropriate attributes.
Links (a
elements) can point to http, https, ftp, mailto
, and have an enforced rel=nofollow
attribute.
Does not allow images.
[中]此白名单允许更全面的文本节点:a, b, blockquote, br, cite, code, dd, dl, dt, em, i, li, ol, p, pre, q, small, span, strike, strong, sub, sup, u, ul
和适当的属性。
链接(a
元素)可以指向http, https, ftp, mailto
,并具有强制的rel=nofollow
属性。
不允许使用图像。
代码示例来源:origin: org.jsoup/jsoup
/**
This whitelist allows the same text tags as {@link #basic}, and also allows <code>img</code> tags, with appropriate
attributes, with <code>src</code> pointing to <code>http</code> or <code>https</code>.
@return whitelist
*/
public static Whitelist basicWithImages() {
return basic()
.addTags("img")
.addAttributes("img", "align", "alt", "height", "src", "title", "width")
.addProtocols("img", "src", "http", "https")
;
}
代码示例来源: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: ManyDesigns/Portofino
/**
* Returns the JSoup whitelist used to clean user-provided HTML in rich-text fields.
* @return the default implementation returns the "basic" whitelist ({@link Whitelist#basic()}).
*/
protected Whitelist getWhitelist() {
return Whitelist.basic();
}
代码示例来源: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: com.manydesigns/portofino-crud
/**
* Returns the JSoup whitelist used to clean user-provided HTML in rich-text fields.
* @return the default implementation returns the "basic" whitelist ({@link Whitelist#basic()}).
*/
protected Whitelist getWhitelist() {
return Whitelist.basic();
}
代码示例来源:origin: org.hibernate.validator/hibernate-validator
switch ( safeHtmlAnnotation.whitelistType() ) {
case BASIC:
whitelist = Whitelist.basic();
break;
case BASIC_WITH_IMAGES:
代码示例来源:origin: org.apache.marmotta/ldpath-functions-html
@Override
protected String doFilter(String in) {
return Jsoup.clean(in, Whitelist.basic());
}
代码示例来源:origin: apache/marmotta
@Override
protected String doFilter(String in) {
return Jsoup.clean(in, Whitelist.basic());
}
代码示例来源:origin: javalite/activeweb
/**
* Cleans HTML from harmful tags, making XSS impossible.
* <p>For example, input like this:</p>
*
* <pre>
* <html><script> alert('hello');</script><div>this is a clean part</div></html>
* </pre>
*
* Will produce output like this:
*
* <pre>
* this is a clean part
* </pre>
*
* @param unsafeContent unsafe content. Something that an end user typed into a text area, or input that may include
* a script tag or other garbage.
* @return sanitized version of input
*/
protected String sanitize(String unsafeContent){
return Jsoup.clean(unsafeContent, Whitelist.basic());
}
代码示例来源: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.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"));
}
代码示例来源:origin: com.eduworks/ew.levr.base
wl = Whitelist.none();
else
wl = Whitelist.basic();
代码示例来源:origin: 94fzb/zrlog
if (createCommentRequest.getLogId() != null && createCommentRequest.getComment() != null) {
if (isAllowComment(Integer.valueOf(createCommentRequest.getLogId()))) {
String comment = Jsoup.clean(createCommentRequest.getComment(), Whitelist.basic());
if (comment.length() > 0 && !ParseUtil.isGarbageComment(comment)) {
new Comment().set("userHome", createCommentRequest.getUserHome())
内容来源于网络,如有侵权,请联系作者删除!