JSoup Configuration Externalization - Gson

Simple library that allows you you externalize JSoup configuration in either JSON or JowliML (a very terse grammar)

Лицензия

Лицензия

MIT
Категории

Категории

jsoup Прикладные библиотеки Configuration Библиотеки уровня приложения config Gson Данные JSON
Группа

Группа

io.shick.jsoup
Идентификатор

Идентификатор

jsoup-configuration-gson
Последняя версия

Последняя версия

1.0.3
Дата

Дата

Тип

Тип

jar
Описание

Описание

JSoup Configuration Externalization - Gson
Simple library that allows you you externalize JSoup configuration in either JSON or JowliML (a very terse grammar)

Скачать jsoup-configuration-gson

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/io.shick.jsoup/jsoup-configuration-gson/ -->
<dependency>
    <groupId>io.shick.jsoup</groupId>
    <artifactId>jsoup-configuration-gson</artifactId>
    <version>1.0.3</version>
</dependency>
// https://jarcasting.com/artifacts/io.shick.jsoup/jsoup-configuration-gson/
implementation 'io.shick.jsoup:jsoup-configuration-gson:1.0.3'
// https://jarcasting.com/artifacts/io.shick.jsoup/jsoup-configuration-gson/
implementation ("io.shick.jsoup:jsoup-configuration-gson:1.0.3")
'io.shick.jsoup:jsoup-configuration-gson:jar:1.0.3'
<dependency org="io.shick.jsoup" name="jsoup-configuration-gson" rev="1.0.3">
  <artifact name="jsoup-configuration-gson" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.shick.jsoup', module='jsoup-configuration-gson', version='1.0.3')
)
libraryDependencies += "io.shick.jsoup" % "jsoup-configuration-gson" % "1.0.3"
[io.shick.jsoup/jsoup-configuration-gson "1.0.3"]

Зависимости

compile (2)

Идентификатор библиотеки Тип Версия
io.shick.jsoup : jsoup-configuration-core jar 1.0.3
com.google.code.gson : gson jar 2.3.1

test (2)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.12
org.mockito : mockito-core jar 1.10.19

Модули Проекта

Данный проект не имеет модулей.

jsoup-configuration

Maven Status Build Status Coverage Status Dependency Status License

This library was born from the need to externalize JSoup's HTML Whitelist. Deploying code for constant tweaks to the Whitelist's configuration was cumbersome. This library allows me to update the configuration outside the code (in JSON or JowliML).

Usage

Pick your flavor, using JSON or JowliML and include the appropriate dependency.

In pom.xml, add the following:

<dependency>
    <groupId>io.shick.jsoup</groupId>
    <artifactId>jsoup-configuration-gson</artifactId>
    <version>1.0.1</version>
</dependency>

Then in your Java code

// you can simply instantiate the parser
final Whitelist whitelist = new GsonParser().parse(json).whitelist();

// or you can get a parser by 'type', (either gson or jowli)
final Whitelist whitelist = WhitelistConfigurationParserFactory.newParser("gson").parse(json).whitelist();

// or you can append to an existing whitelist
final Whitelist whitelist = new GsonParser().parse(json).apply(Whitelist.basic());

// you can construct a new config and serialize it out too!
WhitelistConfiguration wlc = new BasicWhitelistConfiguration().enforceAttribute("a","rel","nofollow");

final String jowli = new JowliMLFormatter().format(wlc).toString();   //jowliml
final String json = new GsonFormatter().format(wlc).toString();       //json

Formats

JSON

{
  "base" : "basic", /* basic, basicwithimages, relaxed, none, or null */
  "tags" : ["a","b"],
  "attributes" : {
    "blockquote": ["cite"]
    },
  "enforcedAttributes": {
    "a" : {
      "rel" : "nofollow"
      }
    },
  "protocols" : {
    "a" : { 
      "href":["ftp", "http", "https", "mailto"]
      }
    }
}

JowliML

The point of JowliML is to provide a very terse representation of the whitelist rules. What you see below is the same as the above JSON but in a much more compact, externalized configuration friendly format.

(all on one line)
b:b;    /* note this can be b=basic, i=basicwithimages, n=none, r=relaxed */
t:a,b;
a:blockquote[cite],a[href,rel];
e:a[rel:nofollow];
p:a[href:[ftp,http,https,mailto]]

All directives are optional and additive. In the case of 'b', the last one wins. What? Basically...

t:a,b

is equivalent to :

t:a;t:b

LICENSE

MIT

Версии библиотеки

Версия
1.0.3
1.0.2
1.0.1