[英]How to get list of valid tags of Jsoup whitelist?
How do I get a list of all the valid tags of a given Jsoup Whitelist
? 如何获得给定Jsoup
Whitelist
名单的所有有效标签的列表?
I can't find such a function in the docs at Jsoup whitelist docs . 我在Jsoup白名单docs的docs中找不到这样的功能。 I use ColdFusion, but a java solution or hint would be fine.
我使用ColdFusion,但是可以使用Java解决方案或提示。 I guess I could translate it.
我想我可以翻译。
You can check here that, what you are asking for is the tagNames
set. 您可以在此处检查,要求的是设置的
tagNames
。 The class doesn't provide any getter. 该类不提供任何获取方法。
What you can do is: 您可以做的是:
Whitelist
class and add a getter. Whitelist
类并添加一个getter。 You can even make a pull request after that. If you want to go the reflection route, you can do something like below which grabs access to the tagNames
set, converts it to an array of org.jsoup.safety.Whitelist$TagName
objects (which contain the tag names) and then appends the toString()
values of those objects to another array. 如果您想进行反思,可以执行以下操作,以获取对
tagNames
集合的访问,将其转换为org.jsoup.safety.Whitelist$TagName
对象(包含标签名称)的数组,然后附加将这些对象的toString()
值添加到另一个数组。
<cfscript>
whitelist = createObject("java", "org.jsoup.safety.Whitelist");
collection = [];
tags = whitelist.getClass().getDeclaredField("tagNames");
tags.setAccessible(true);
// this portion uses the relaxed whitelist as an example
for (tag in tags.get(whitelist.relaxed()).toArray()) {
arrayAppend(collection, tag.toString());
}
writeDump(collection);
</cfscript>
If you need the attributes and/or protocols fields, it's a similar approach but there is more to iterate through since they are maps. 如果您需要属性和/或协议字段,这是一种类似的方法,但是由于它们是映射,因此还有很多要遍历的地方。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.