本文整理汇总了Java中org.jsoup.safety.Whitelist类的典型用法代码示例。如果您正苦于以下问题:Java Whitelist类的具体用法?Java Whitelist怎么用?Java Whitelist使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Whitelist类属于org.jsoup.safety包,在下文中一共展示了Whitelist类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.jsoup.safety.Whitelist; //导入依赖的package包/类
public static void main(String[] args) {
String d = "<span><div>test</div></span>";
Document doc = Jsoup.parse(d);
Element div = doc.select("div").first(); // <div></div>
div.html("<p>lorem ipsum</p>"); // <div><p>lorem ipsum</p></div>
div.prepend("<p>First</p>");
div.append("<p>Last</p>");
// now: <div><p>First</p><p>lorem ipsum</p><p>Last</p></div>
div.appendElement(d);
Element span = doc.select("span").first(); // <span>One</span>
span.wrap("<li><a href='http://example.com/'></a></li>");
// now: <li><a href="http://example.com"><span>One</span></a></li>
System.out.println(doc.html());
String s = Jsoup.clean(doc.html(), "", Whitelist.relaxed(), new OutputSettings().prettyPrint(false));
System.out.println(s);
}
示例2: writeFormToObject
import org.jsoup.safety.Whitelist; //导入依赖的package包/类
/**
* Writes the contents of the create or edit form into the persistent object.
* Assumes that the form has already been validated.
* Also processes rich-text (HTML) fields by cleaning the submitted HTML according
* to the {@link #getWhitelist() whitelist}.
*/
protected void writeFormToObject() {
form.writeToObject(object);
for(TextField textField : getEditableRichTextFields()) {
PropertyAccessor propertyAccessor = textField.getPropertyAccessor();
String stringValue = textField.getStringValue();
String cleanText;
try {
Whitelist whitelist = getWhitelist();
cleanText = Jsoup.clean(stringValue, whitelist);
} catch (Throwable t) {
logger.error("Could not clean HTML, falling back to escaped text", t);
cleanText = StringEscapeUtils.escapeHtml(stringValue);
}
propertyAccessor.set(object, cleanText);
}
}
示例3: main
import org.jsoup.safety.Whitelist; //导入依赖的package包/类
public static void main(String[] args) {
String baseUri = "http://www.baidu.com";
String html = "<a href=\"http://www.baidu.com/gaoji/preferences.html\"name=\"tj_setting\">搜索设置</a>";
String doc = Jsoup.clean(html, baseUri, Whitelist.none());
System.out.println(doc);
System.out.println("*******");
doc = Jsoup.clean(html, baseUri, Whitelist.simpleText());
System.out.println(doc);
System.out.println("*******");
doc = Jsoup.clean(html, baseUri, Whitelist.basic());
System.out.println(doc);
System.out.println("*******");
doc = Jsoup.clean(html, baseUri, Whitelist.basicWithImages());
System.out.println(doc);
System.out.println("*******");
doc = Jsoup.clean(html, baseUri, Whitelist.relaxed());
System.out.println(doc);
}
示例4: createReply
import org.jsoup.safety.Whitelist; //导入依赖的package包/类
public Reply createReply(ReplyDTO replyDTO, User user) {
replyDTO.setUserId(user.getId());
Reply reply = replyDTO.toReply();
String content = Jsoup.clean(reply.getContent(), Whitelist.basicWithImages());
content = updateAtUser(content);
reply.setContent(content);
reply.setStatus(ReplyStatus.ACTIVE);
Reply result = replyRepository.save(reply);
reply.setUser(user);
afterCreatingReply(reply);
return result;
}
示例5: trimValue
import org.jsoup.safety.Whitelist; //导入依赖的package包/类
private String trimValue(String dataFormat, String input) {
String cleaned = null;
if ("html".equals(dataFormat)) {
Document document = Jsoup.parse(input);
if (document != null) {
document.outputSettings(new Document.OutputSettings().prettyPrint(false));
document.select("br").append("\\n");
String s = org.jsoup.parser.Parser.unescapeEntities(Jsoup.clean(document.html().replaceAll("\\\\n", " "), "", Whitelist.none(), new Document.OutputSettings().prettyPrint(false)), false);
if (s != null) {
cleaned = s.trim().replaceAll("\r", "").replaceAll("\n","");
}
}
} else {
cleaned = input.trim();
if (this.eolPattern == null) {
this.eolPattern = Pattern.compile("[\r|\n]");
}
Matcher m = this.eolPattern.matcher(cleaned);
if (m.find()) {
cleaned = cleaned.subSequence(0, m.start()).toString();
}
}
return cleaned != null ? (cleaned.length() > 100 ? cleaned.substring(0, 100) : cleaned) : (input.length() > 100 ? input.substring(0, 100) : input);
}
示例6: checkTextContent
import org.jsoup.safety.Whitelist; //导入依赖的package包/类
public int checkTextContent(int userId, String content) throws IOException {
HashSet<String> sensitiveWords = new HashSet<String>();
InputStream fis = new FileInputStream(source);
InputStreamReader isr = new InputStreamReader(fis, Charset.forName("UTF-8"));
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null)
sensitiveWords.add(line.substring(0, line.length() - 1));
Result result = ToAnalysis.parse(Jsoup.clean(content, Whitelist.none()));
List<Term> termList = result.getTerms();
for (Term term : termList) {
if (sensitiveWords.contains(term.getName()))
return 0;
}
return 1;
}
示例7: cleanContent
import org.jsoup.safety.Whitelist; //导入依赖的package包/类
/**
* Cleans the html content leaving only the following tags: b, em, i, strong, u, br, cite, em, i, p, strong, img, li, ul, ol, sup, sub, s
* @param content html content
* @param extraTags any other tags that you may want to keep, e. g. "a"
* @return
*/
public String cleanContent(String content, String ... extraTags) {
Whitelist allowedTags = Whitelist.simpleText(); // This whitelist allows only simple text formatting: b, em, i, strong, u. All other HTML (tags and attributes) will be removed.
allowedTags.addTags("br", "cite", "em", "i", "p", "strong", "img", "li", "ul", "ol", "sup", "sub", "s");
allowedTags.addTags(extraTags);
allowedTags.addAttributes("p", "style"); // Serve per l'allineamento a destra e sinistra
allowedTags.addAttributes("img", "src", "style", "class");
if (Arrays.asList(extraTags).contains("a")) {
allowedTags.addAttributes("a", "href", "target");
}
Document dirty = Jsoup.parseBodyFragment(content, "");
Cleaner cleaner = new Cleaner(allowedTags);
Document clean = cleaner.clean(dirty);
clean.outputSettings().escapeMode(EscapeMode.xhtml); // Non fa l'escape dei caratteri utf-8
String safe = clean.body().html();
return safe;
}
示例8: getUnkownCommandResponse
import org.jsoup.safety.Whitelist; //导入依赖的package包/类
public String getUnkownCommandResponse(String message,String userName) {
if (chatSession==null){
return "Sorry I did not recognize your command and the AI functions are disabled";
}
MagicStrings.default_Customer_id = userName;
String msg = chatSession.multisentenceRespond(message);
if (msg == null || (msg.toLowerCase().contains("google") || msg.contains("<search>"))) {
return "Sorry, I do not know";
}
if (msg.length() > 250 && !msg.contains("\n")) {
msg = "Well\n" + Jsoup.clean(msg, Whitelist.basic());
}
return msg.replaceAll("<br/>", "\n");
}
示例9: parseQodResponse
import org.jsoup.safety.Whitelist; //导入依赖的package包/类
private void parseQodResponse(JSONObject response) throws JSONException {
JSONObject parse = response.getJSONObject("parse");
JSONObject text = parse.getJSONObject("text");
String content = text.getString("*");
Document doc = Jsoup.parse(content);
Elements table = doc.select("table[style=\"text-align:center; width:100%\"]");
Elements rows = table.select("tr");
Elements qodTd = rows.get(0).select("td");
Elements author = rows.get(1).select("td");
Whitelist whitelist = Whitelist.none();
String newQuote = Html.fromHtml(Jsoup.clean(qodTd.toString(), whitelist)).toString();
String newAuthor = Html.fromHtml(Jsoup.clean(author.toString(), whitelist).replace("~", "")).toString();
Quote qod = sharedPrefStorage.getQod();
if (!qod.getQuoteText().equals(newQuote) || !qod.getQuoteAuthor().equals(newAuthor)) {
Snackbar.make(binding.coordinatorLayout, getString(R.string.str_Refreshing), Snackbar.LENGTH_SHORT).show();
}
sharedPrefStorage.setQodText(newQuote);
sharedPrefStorage.setQodAuthor(newAuthor);
setQuoteOfTheDayTextAndAuthor(qod);
}
示例10: TRECAquaintDocumentIndexer
import org.jsoup.safety.Whitelist; //导入依赖的package包/类
public TRECAquaintDocumentIndexer(String indexPath, String tokenFilterFile, boolean positional){
super(indexPath, tokenFilterFile, positional);
try {
whiteList = Whitelist.relaxed();
whiteList.addTags("docno");
whiteList.addTags("doc");
whiteList.addTags("headline");
whiteList.addTags("text");
whiteList.addTags("date_time");
whiteList.addTags("slug");
} catch (Exception e){
System.out.println(" caught a " + e.getClass() +
"\n with message: " + e.getMessage());
}
doc = new Document();
initFields();
initAQUAINTDoc();
}
示例11: getJavadocCommentAsText
import org.jsoup.safety.Whitelist; //导入依赖的package包/类
private String getJavadocCommentAsText(IMember member) {
try (Reader reader = JavadocContentAccess.getHTMLContentReader(member, true, true)) {
if (reader == null) {
return null;
}
String javadocAsHtml = CharStreams.toString(reader);
String javadocAsString = Jsoup.clean(javadocAsHtml, "", Whitelist.none(), new OutputSettings().prettyPrint(false));
// trim lines
try (BufferedReader bufferedReader = new BufferedReader(new StringReader(javadocAsString))) {
return bufferedReader.lines().map(line->line.trim()).collect(Collectors.joining("\n"));
}
} catch (JavaModelException | IOException e) {
return null;
}
}
示例12: writeFormToObject
import org.jsoup.safety.Whitelist; //导入依赖的package包/类
/**
* Writes the contents of the create or edit form into the persistent object.
* Assumes that the form has already been validated.
* Also processes rich-text (HTML) fields by cleaning the submitted HTML according
* to the {@link #getWhitelist() whitelist}.
*/
protected void writeFormToObject() {
form.writeToObject(object);
for(TextField textField : FormUtil.collectEditableRichTextFields(form)) {
//TODO in bulk edit mode, the field should be skipped altogether if the checkbox is not checked.
PropertyAccessor propertyAccessor = textField.getPropertyAccessor();
String stringValue = (String) propertyAccessor.get(object);
String cleanText;
try {
Whitelist whitelist = getWhitelist();
cleanText = Jsoup.clean(stringValue, whitelist);
} catch (Throwable t) {
logger.error("Could not clean HTML, falling back to escaped text", t);
cleanText = StringEscapeUtils.escapeHtml(stringValue);
}
propertyAccessor.set(object, cleanText);
}
}
示例13: cleaner
import org.jsoup.safety.Whitelist; //导入依赖的package包/类
protected String cleaner(String rs) {
rs = rs.replace(" 廣告","");
rs = rs.replace("data-original=","src=");
//rs = rs.replace("<span>","<p>");
//rs = rs.replace("</span>","</p>");
rs = rs.replace("相關新聞", "<!--");
Whitelist wlist = new Whitelist();
wlist.addTags("p", "span");
wlist.addTags("table","tbody","tr","td");
wlist.addTags("img").addAttributes("img", "src");
return Jsoup.clean(rs, wlist);
}
示例14: cleaner
import org.jsoup.safety.Whitelist; //导入依赖的package包/类
protected String cleaner(String rs) {
rs = rs.replace("src=\"/cnt", "src=\"http://orientaldaily.on.cc/cnt");
rs = rs.replace("<h3>","<p><b>");
rs = rs.replace("</h3>","</b></p>");
rs = rs.replace("<!--AD-->","<!--");
rs = rs.replace("<div id=\"articleNav\">","<!--");
Whitelist wlist = new Whitelist();
wlist.addTags("p","b");
//wlist.addTags("table","tbody","tr","td");
wlist.addTags("img").addAttributes("img", "src");
return Jsoup.clean(rs, wlist);
}
示例15: cleaner
import org.jsoup.safety.Whitelist; //导入依赖的package包/类
protected String cleaner(String rs) {
/*
rs = rs.replace("<h2>","<p>");
rs = rs.replace("</h2>","</p>");
rs = rs.replace("#video_player{width:100%; height:100%;}","");
rs = rs.replace("<h1>","<!--");
rs = rs.replace("</h1>","-->");
*/
rs = rs.replace("https://staticlayout.appledaily.hk/web_images/layout/art_end.gif","");
Whitelist wlist = new Whitelist();
wlist.addTags("p");
wlist.addTags("table","tbody","tr","td");
wlist.addTags("img").addAttributes("img", "src");
return Jsoup.clean(rs, wlist);
}