Skip to content

Commit

Permalink
Improved blacklist XML/JSON API.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcnause committed May 19, 2014
1 parent 830057d commit 4723329
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 37 deletions.
14 changes: 2 additions & 12 deletions htroot/api/blacklists/get_list_p.java
Expand Up @@ -30,8 +30,6 @@ public class get_list_p {
private static final String BLACK_LISTS_SHARED = "BlackLists.Shared";

private static final int lastTypeIndex = BLACKLIST_TYPE_VALUES.length - 1;
private static final String EMPTY_STRING = "";
private static final String COMMA_STRING = ",";

public static serverObjects respond(@SuppressWarnings("unused") final RequestHeader header, final serverObjects post, @SuppressWarnings("unused") final serverSwitch env) {

Expand All @@ -55,11 +53,7 @@ public static serverObjects respond(@SuppressWarnings("unused") final RequestHea
prop.put(PREFIX_TYPES + j + POSTFIX_VALUE,
ListManager.listSetContains(type + TYPES_EXT, element));

if (j < lastTypeIndex) {
prop.put(PREFIX_TYPES + j + POSTFIX_COMMA, COMMA_STRING);
} else {
prop.put(PREFIX_TYPES + j + POSTFIX_COMMA, EMPTY_STRING);
}
prop.put(PREFIX_TYPES + j + POSTFIX_COMMA, j < lastTypeIndex);

j++;
}
Expand All @@ -77,11 +71,7 @@ public static serverObjects respond(@SuppressWarnings("unused") final RequestHea

prop.putXML(PREFIX_ITEMS + count + POSTFIX_ITEM, entry);

if (count < lastItemCount) {
prop.put(PREFIX_ITEMS + count + POSTFIX_COMMA, COMMA_STRING);
} else {
prop.put(PREFIX_ITEMS + count + POSTFIX_COMMA, EMPTY_STRING);
}
prop.put(PREFIX_ITEMS + count + POSTFIX_COMMA, count < lastItemCount);

count++;
}
Expand Down
12 changes: 8 additions & 4 deletions htroot/api/blacklists/get_list_p.json
@@ -1,9 +1,13 @@
{
"name": "#[name]#",
"shared": "#[shared]#",
"types": [#{types}#{"#[name]#": "#[value]#"}#[comma]# #{/types}#]
"name":"#[name]#",
"shared":#(shared)#false::true#(/shared)#,
"types": {
#{types}#
"#[name]#":#(value)#false::true#(/value)##(comma)#::,#(/comma)#
#{/types}#
},
"items":
[
#{items}#"#[item]#"#[comma]#
#{items}#"#[item]#"#(comma)#::,#(/comma)#
#{/items}#]
}
4 changes: 2 additions & 2 deletions htroot/api/blacklists/get_list_p.xml
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<list name="#[name]#" shared="#[shared]#" #{types}#
#[name]#="#[value]#"#{/types}#>
<list name="#[name]#" shared="#(shared)#false::true#(/shared)#" #{types}#
#[name]#="#(value)#false::true#(/value)#"#{/types}#>
<items>
#{items}#
<item>#[item]#</item>
Expand Down
16 changes: 3 additions & 13 deletions htroot/api/blacklists/get_metadata_p.java
Expand Up @@ -26,8 +26,6 @@ public class get_metadata_p {
private static final String BLACK_LISTS_SHARED = "BlackLists.Shared";

private static final int lastTypeIndex = BLACKLIST_TYPE_VALUES.length - 1;
private static final String EMPTY_STRING = "";
private static final String COMMA_STRING = ",";

public static serverObjects respond(@SuppressWarnings("unused") final RequestHeader header, @SuppressWarnings("unused") final serverObjects post, @SuppressWarnings("unused") final serverSwitch env) {

Expand All @@ -49,22 +47,14 @@ public static serverObjects respond(@SuppressWarnings("unused") final RequestHea
prop.put(PREFIX_LISTS + blacklistCount + INFIX_TYPES + j + POSTFIX_VALUE,
ListManager.listSetContains(type + TYPES_EXT, element));

if (j < lastTypeIndex) {
prop.put(PREFIX_LISTS + blacklistCount + INFIX_TYPES + j + POSTFIX_COMMA, COMMA_STRING);
} else {
prop.put(PREFIX_LISTS + blacklistCount + INFIX_TYPES + j + POSTFIX_COMMA, EMPTY_STRING);
}
prop.put(PREFIX_LISTS + blacklistCount + INFIX_TYPES + j + POSTFIX_COMMA, j < lastTypeIndex);

j++;
}
prop.put(PREFIX_LISTS + blacklistCount + POSTFIX_TYPES, BLACKLIST_TYPE_VALUES.length);

if (blacklistCount < lastBlacklistCount) {
prop.put(PREFIX_LISTS + blacklistCount + POSTFIX_COMMA, COMMA_STRING);
} else {
prop.put(PREFIX_LISTS + blacklistCount + POSTFIX_COMMA, EMPTY_STRING);
}

prop.put(PREFIX_LISTS + blacklistCount + POSTFIX_COMMA, blacklistCount < lastBlacklistCount);

blacklistCount++;
}
}
Expand Down
12 changes: 8 additions & 4 deletions htroot/api/blacklists/get_metadata_p.json
@@ -1,8 +1,12 @@
[
#{lists}#{
"name": "#[name]#",
"shared": "#[shared]#",
"types": [#{types}#{"#[name]#": "#[value]#"}#[comma]# #{/types}#]
}#[comma]#
"name":"#[name]#",
"shared":#(shared)#false::true#(/shared)#,
"types": {
#{types}#
"#[name]#":#(value)#false::true#(/value)##(comma)#::,#(/comma)#
#{/types}#
}
}#(comma)#::,#(/comma)#
#{/lists}#
]
4 changes: 2 additions & 2 deletions htroot/api/blacklists/get_metadata_p.xml
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding="UTF-8" standalone='yes'?>
<blacklists>
#{lists}#<list name="#[name]#" shared="#[shared]#" #{types}#
#[name]#="#[value]#"#{/types}# />
#{lists}#<list name="#[name]#" shared="#(shared)#false::true#(/shared)#" #{types}#
#[name]#="#(value)#false::true#(/value)#"#{/types}# />
#{/lists}#
</blacklists>

0 comments on commit 4723329

Please sign in to comment.