How do I get a list of all the valid tags of a given Jsoup Whitelist
?
I can't find such a function in the docs at Jsoup whitelist docs . I use ColdFusion, but a java solution or hint would be fine. I guess I could translate it.
You can check here that, what you are asking for is the tagNames
set. The class doesn't provide any getter.
What you can do is:
Whitelist
class and add a 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.
<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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.