From eb2ef658fdd82fca688d1e0c52942cedb3699e3e Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 29 Oct 2010 22:39:28 +0200 Subject: [PATCH] Add methods to load all trusted identities. --- .../sone/freenet/wot/WebOfTrustConnector.java | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java b/src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java index 100241e..f386b0e 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java @@ -117,6 +117,49 @@ public class WebOfTrustConnector implements ConnectorListener { return contexts; } + /** + * Loads all identities that the given identities trusts with a score of + * more than 0. + * + * @param ownIdentity + * The own identity + * @return All trusted identities + * @throws PluginException + * if an error occured talking to the Web of Trust plugin + */ + public Set loadTrustedIdentities(OwnIdentity ownIdentity) throws PluginException { + return loadTrustedIdentities(ownIdentity, null); + } + + /** + * Loads all identities that the given identities trusts with a score of + * more than 0 and the (optional) given context. + * + * @param ownIdentity + * The own identity + * @param context + * The context to filter, or {@code null} + * @return All trusted identities + * @throws PluginException + * if an error occured talking to the Web of Trust plugin + */ + public Set loadTrustedIdentities(OwnIdentity ownIdentity, String context) throws PluginException { + Reply reply = performRequest("Identities", SimpleFieldSetConstructor.create().put("Message", "GetIdentitiesByScore").put("TreeOwner", ownIdentity.getId()).put("Selection", "+").put("Context", (context == null) ? "" : context).get()); + SimpleFieldSet fields = reply.getFields(); + Set identities = new HashSet(); + int identityCounter = -1; + while (true) { + String id = fields.get("Identity" + ++identityCounter); + if (id == null) { + break; + } + String nickname = fields.get("Nickname" + identityCounter); + String requestUri = fields.get("RequestURI" + identityCounter); + identities.add(new Identity(this, id, nickname, requestUri)); + } + return identities; + } + // // PRIVATE ACTIONS // -- 2.7.4