当前位置: 首页>>代码示例>>Java>>正文


Java Whitelist类代码示例

本文整理汇总了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);
}
 
开发者ID:bluetata,项目名称:crawler-jsoup-maven,代码行数:20,代码来源:JsoupTest.java

示例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);
    }
}
 
开发者ID:hongliangpan,项目名称:manydesigns.cn,代码行数:23,代码来源:AbstractCrudAction.java

示例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);

}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:20,代码来源:XHTMLDocumentHandler.java

示例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;
}
 
开发者ID:ugouku,项目名称:shoucang,代码行数:18,代码来源:ReplyService.java

示例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);
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:25,代码来源:AuditLogger.java

示例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;
}
 
开发者ID:qinjr,项目名称:TeamNote,代码行数:19,代码来源:QualityUtilImpl.java

示例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;
}
 
开发者ID:xtianus,项目名称:yadaframework,代码行数:23,代码来源:YadaWebUtil.java

示例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");

}
 
开发者ID:SOBotics,项目名称:SOCVFinder,代码行数:18,代码来源:ChatRoom.java

示例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);
}
 
开发者ID:mdilaveroglu,项目名称:Quoter-Android,代码行数:27,代码来源:QODFragment.java

示例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();
}
 
开发者ID:lucene4ir,项目名称:lucene4ir,代码行数:21,代码来源:TRECAquaintDocumentIndexer.java

示例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;
	}
}
 
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:17,代码来源:JavadocCommentProvider.java

示例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);
    }
}
 
开发者ID:ManyDesigns,项目名称:Portofino,代码行数:24,代码来源:AbstractCrudAction.java

示例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);

    }
 
开发者ID:ccjeng,项目名称:News,代码行数:18,代码来源:LibertyTimes.java

示例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);

    }
 
开发者ID:ccjeng,项目名称:News,代码行数:18,代码来源:OrientalDaily.java

示例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);

    }
 
开发者ID:ccjeng,项目名称:News,代码行数:22,代码来源:HKAppleDaily.java


注:本文中的org.jsoup.safety.Whitelist类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。