|
| 1 | +--- |
| 2 | +title: jsoup-configuration 1.0.2 Released |
| 3 | +layout: post |
| 4 | +category : releases |
| 5 | +release-date: 2016-11-12 |
| 6 | +search: "yes" |
| 7 | +noindex: false |
| 8 | +tags: |
| 9 | +- jsoup |
| 10 | +- release |
| 11 | +keywords: "jsoup, release, jsoup-configuration" |
| 12 | +--- |
| 13 | + |
| 14 | + |
| 15 | +[JSoup Configuration v 1.0.2 Released](http://trevershick.github.io/jsoup-configuration/) |
| 16 | + |
| 17 | +This library was born from the need to externalize JSoup's HTML Whitelist. Deploying code |
| 18 | +for constant tweaks to the Whitelist's configuration was cumbersome. This library allows |
| 19 | +me to update the configuration outside the code (in JSON or JowliML). |
| 20 | + |
| 21 | +### Usage |
| 22 | + |
| 23 | +Pick your flavor, using JSON or JowliML and include the appropriate dependency. |
| 24 | + |
| 25 | +In pom.xml, add the following: |
| 26 | + |
| 27 | +```xml |
| 28 | +<dependency> |
| 29 | + <groupId>io.shick.jsoup</groupId> |
| 30 | + <artifactId>jsoup-configuration-gson</artifactId> |
| 31 | + <version>1.0.1</version> |
| 32 | +</dependency> |
| 33 | +``` |
| 34 | + |
| 35 | +Then in your Java code |
| 36 | + |
| 37 | +```java |
| 38 | + |
| 39 | +// you can simply instantiate the parser |
| 40 | +final Whitelist whitelist = new GsonParser().parse(json).whitelist(); |
| 41 | + |
| 42 | +// or you can get a parser by 'type', (either gson or jowli) |
| 43 | +final Whitelist whitelist = WhitelistConfigurationParserFactory.newParser("gson").parse(json).whitelist(); |
| 44 | + |
| 45 | +// or you can append to an existing whitelist |
| 46 | +final Whitelist whitelist = new GsonParser().parse(json).apply(Whitelist.basic()); |
| 47 | + |
| 48 | +// you can construct a new config and serialize it out too! |
| 49 | +WhitelistConfiguration wlc = new BasicWhitelistConfiguration().enforceAttribute("a","rel","nofollow"); |
| 50 | + |
| 51 | +final String jowli = new JowliMLFormatter().format(wlc).toString(); //jowliml |
| 52 | +final String json = new GsonFormatter().format(wlc).toString(); //json |
| 53 | + |
| 54 | + |
| 55 | +``` |
| 56 | + |
| 57 | +Formats |
| 58 | +---- |
| 59 | + |
| 60 | +JSON |
| 61 | + |
| 62 | +``` |
| 63 | +{ |
| 64 | + "tags" : ["a","b"], |
| 65 | + "attributes" : { |
| 66 | + "blockquote": ["cite"] |
| 67 | + }, |
| 68 | + "enforcedAttributes": { |
| 69 | + "a" : { |
| 70 | + "rel" : "nofollow" |
| 71 | + } |
| 72 | + }, |
| 73 | + "protocols" : { |
| 74 | + "a" : { |
| 75 | + "href":["ftp", "http", "https", "mailto"] |
| 76 | + } |
| 77 | + } |
| 78 | +} |
| 79 | +``` |
| 80 | + |
| 81 | +**JowliML** |
| 82 | + |
| 83 | +The point of JowliML is to provide a very terse representation of the whitelist rules. |
| 84 | +What you see below is the same as the above JSON but in a much more compact, |
| 85 | +externalized configuration friendly format. |
| 86 | + |
| 87 | + |
| 88 | +``` |
| 89 | +(all on one line) |
| 90 | +t:a,b; |
| 91 | +a:blockquote[cite],a[href,rel]; |
| 92 | +e:a[rel:nofollow]; |
| 93 | +p:a[href:[ftp,http,https,mailto]] |
| 94 | +``` |
0 commit comments