Merge branch 'release-0.0.8' master 0.0.8
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 27 Sep 2011 04:58:17 +0000 (06:58 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 27 Sep 2011 04:58:17 +0000 (06:58 +0200)
pom.xml
src/main/java/net/pterodactylus/wotns/freenet/SimpleFieldSetBuilder.java
src/main/java/net/pterodactylus/wotns/freenet/wot/IdentityManager.java
src/main/java/net/pterodactylus/wotns/freenet/wot/WebOfTrustConnector.java
src/main/java/net/pterodactylus/wotns/main/IdentityComparator.java
src/main/java/net/pterodactylus/wotns/main/IdentityTargets.java
src/main/java/net/pterodactylus/wotns/main/Resolver.java
src/main/java/net/pterodactylus/wotns/main/WoTNSPlugin.java
src/main/java/net/pterodactylus/wotns/template/IdentityAccessor.java
src/main/java/net/pterodactylus/wotns/ui/web/WebInterface.java
src/main/resources/i18n/WoTNS.en.properties

diff --git a/pom.xml b/pom.xml
index ed413f2..fce9839 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -2,12 +2,12 @@
        <modelVersion>4.0.0</modelVersion>
        <groupId>net.pterodactylus</groupId>
        <artifactId>WoTNS</artifactId>
-       <version>0.0.7</version>
+       <version>0.0.8</version>
        <dependencies>
                <dependency>
                        <groupId>net.pterodactylus</groupId>
                        <artifactId>utils</artifactId>
-                       <version>0.10.1-SNAPSHOT</version>
+                       <version>0.11</version>
                </dependency>
                <dependency>
                        <groupId>junit</groupId>
index 1472a82..d3675f6 100644 (file)
@@ -67,7 +67,7 @@ public class SimpleFieldSetBuilder {
         *            The simple field set to copy
         * @return This simple field set builder
         */
-       public SimpleFieldSetBuilder put(@SuppressWarnings("hiding") SimpleFieldSet simpleFieldSet) {
+       public SimpleFieldSetBuilder put(SimpleFieldSet simpleFieldSet) {
                this.simpleFieldSet.putAllOverwrite(simpleFieldSet);
                return this;
        }
index 1c30752..5a53106 100644 (file)
@@ -212,7 +212,6 @@ public class IdentityManager extends AbstractService {
        protected void serviceRun() {
                while (!shouldStop()) {
                        Map<OwnIdentity, Map<String, Identity>> currentIdentities = new HashMap<OwnIdentity, Map<String, Identity>>();
-                       @SuppressWarnings("hiding")
                        Map<String, OwnIdentity> currentOwnIdentities = new HashMap<String, OwnIdentity>();
 
                        Set<OwnIdentity> ownIdentities = null;
@@ -314,7 +313,6 @@ public class IdentityManager extends AbstractService {
         */
        private void checkTrustedIdentities(OwnIdentity ownIdentity, Map<String, Identity> trustedIdentities) {
 
-               @SuppressWarnings("hiding")
                Map<String, Identity> currentTrustedIdentities = new HashMap<String, Identity>();
                synchronized (syncObject) {
                        if (this.currentTrustedIdentities.containsKey(ownIdentity)) {
index f56f739..4274caf 100644 (file)
@@ -86,7 +86,6 @@ public class WebOfTrustConnector implements ConnectorListener {
         *             if the own identities can not be loaded
         */
        public Set<OwnIdentity> loadAllOwnIdentities() throws WebOfTrustException {
-               @SuppressWarnings("hiding")
                Reply reply = performRequest(SimpleFieldSetConstructor.create().put("Message", "GetOwnIdentities").get());
                SimpleFieldSet fields = reply.getFields();
                int ownIdentityCounter = -1;
@@ -134,7 +133,6 @@ public class WebOfTrustConnector implements ConnectorListener {
         *             if an error occured talking to the Web of Trust plugin
         */
        public Set<Identity> loadTrustedIdentities(OwnIdentity ownIdentity, String context) throws WebOfTrustException {
-               @SuppressWarnings("hiding")
                Reply reply = performRequest(SimpleFieldSetConstructor.create().put("Message", "GetIdentitiesByScore").put("TreeOwner", ownIdentity.getId()).put("Selection", "+").put("Context", (context == null) ? "" : context).get());
                SimpleFieldSet fields = reply.getFields();
                Set<Identity> identities = new HashSet<Identity>();
@@ -195,7 +193,6 @@ public class WebOfTrustConnector implements ConnectorListener {
         *             if an error occured talking to the Web of Trust plugin
         */
        public String getProperty(Identity identity, String name) throws PluginException {
-               @SuppressWarnings("hiding")
                Reply reply = performRequest(SimpleFieldSetConstructor.create().put("Message", "GetProperty").put("Identity", identity.getId()).put("Property", name).get());
                return reply.getFields().get("Property");
        }
@@ -409,7 +406,7 @@ public class WebOfTrustConnector implements ConnectorListener {
         * {@inheritDoc}
         */
        @Override
-       public void receivedReply(@SuppressWarnings("hiding") PluginConnector pluginConnector, SimpleFieldSet fields, Bucket data) {
+       public void receivedReply(PluginConnector pluginConnector, SimpleFieldSet fields, Bucket data) {
                String messageName = fields.get("Message");
                logger.log(Level.FINEST, "Received Reply from Plugin: " + messageName);
                synchronized (reply) {
index c903a23..3bc8665 100644 (file)
@@ -22,14 +22,24 @@ import java.util.Comparator;
 import net.pterodactylus.wotns.freenet.wot.Identity;
 
 /**
- * TODO
+ * Contains several comparators that can be used with {@link Identity}s. At the
+ * moment only a single {@link Comparator} is defined; it sorts identities
+ * case-insensitively by name.
  *
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
 public class IdentityComparator {
 
+       /** Comparator for sorting by name. */
+       @SuppressWarnings("synthetic-access")
        public static final Comparator<Identity> NAME = new IdentityNameComparator();
 
+       /**
+        * {@link Comparator} for {@link Identity}s that sorts case-insensitively by
+        * name.
+        *
+        * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+        */
        private static class IdentityNameComparator implements Comparator<Identity> {
 
                /**
index 2eacd08..a992091 100644 (file)
@@ -26,25 +26,49 @@ import java.util.Map.Entry;
 import net.pterodactylus.wotns.freenet.wot.Identity;
 
 /**
- * TODO
+ * Scans an {@link Identity}’s properties for WoTNS targets.
  *
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
 public class IdentityTargets implements Iterable<Entry<String, String>> {
 
+       /** The identity being scanned. */
        private final Identity identity;
 
+       /** The located targets. */
        private final Map<String, String> targets = new HashMap<String, String>();
 
+       /**
+        * Creates a new target scanner for the given identity.
+        *
+        * @param identity
+        *            The identity to scan for targets
+        */
        public IdentityTargets(Identity identity) {
                this.identity = identity;
        }
 
+       //
+       // ACCESSORS
+       //
+
+       /**
+        * Returns the targets of the identity.
+        *
+        * @return The targets defined in the identity
+        */
        public Map<String, String> getTargets() {
                scanForTargets();
                return Collections.unmodifiableMap(targets);
        }
 
+       /**
+        * Returns the target with the given name.
+        *
+        * @param name
+        *            The name of the target
+        * @return The target
+        */
        public String getTarget(String name) {
                scanForTargets();
                return targets.get(name);
@@ -54,8 +78,12 @@ public class IdentityTargets implements Iterable<Entry<String, String>> {
        // PRIVATE METHODS
        //
 
+       /**
+        * Re-scans the identity for targets.
+        */
        private void scanForTargets() {
                synchronized (targets) {
+                       targets.clear();
                        for (Entry<String, String> property : identity.getProperties().entrySet()) {
                                if (property.getKey().startsWith("tns.")) {
                                        targets.put(property.getKey().substring(4), property.getValue());
@@ -73,7 +101,10 @@ public class IdentityTargets implements Iterable<Entry<String, String>> {
         */
        @Override
        public Iterator<Entry<String, String>> iterator() {
-               return targets.entrySet().iterator();
+               synchronized (targets) {
+                       scanForTargets();
+                       return new HashMap<String, String>(targets).entrySet().iterator();
+               }
        }
 
 }
index 94a098e..66032d9 100644 (file)
@@ -35,26 +35,61 @@ import net.pterodactylus.wotns.freenet.wot.Trust;
 import freenet.keys.FreenetURI;
 
 /**
- * TODO
+ * Resolves short names as given by the user.
+ * <p>
+ * Short names generally have the syntax:
+ *
+ * <pre>
+ * identity [ ‘@’ start-of-key ] ‘/’ target [ ‘/’ file-path ]
+ * </pre>
+ * <p>
+ * Because resolving a short name is based on the <i>web</i> of trust, the ID of
+ * an own identity must be given in order to find the entry point into the web
+ * of trust. If no ID is specified, the ID of a random own identity is used. If
+ * no own identity exists, short names can not be resolved.
  *
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
 public class Resolver {
 
+       /** The logger. */
        private static final Logger logger = Logging.getLogger(Resolver.class);
 
+       /** The identity manager. */
        private final IdentityManager identityManager;
 
+       /** The ID of the own identity to use for resolving. */
        private String ownIdentityId;
 
+       /**
+        * Creates a new resolver.
+        *
+        * @param identityManager
+        *            The identity manager to use
+        */
        public Resolver(IdentityManager identityManager) {
                this.identityManager = identityManager;
        }
 
+       //
+       // ACCESSORS
+       //
+
+       /**
+        * Returns the ID of the own identity used for resolving short names.
+        *
+        * @return The ID of the own identity used for resolving
+        */
        public String getOwnIdentityId() {
                return ownIdentityId;
        }
 
+       /**
+        * Sets the ID of the own identity used for resolving short names.
+        *
+        * @param ownIdentityId
+        *            The ID of the own identity used for resolving
+        */
        public void setOwnIdentityId(String ownIdentityId) {
                this.ownIdentityId = ownIdentityId;
        }
@@ -63,6 +98,16 @@ public class Resolver {
        // ACTIONS
        //
 
+       /**
+        * Resolves a short name.
+        *
+        * @param shortUri
+        *            The short name to resolve
+        * @return The Freenet URI the short name resolves to, or {@code null} if
+        *         the short name can not be resolved
+        * @throws MalformedURLException
+        *             if the short name is malformed
+        */
        public FreenetURI resolveURI(String shortUri) throws MalformedURLException {
                int firstSlash = shortUri.indexOf('/');
                if (firstSlash == -1) {
@@ -82,6 +127,18 @@ public class Resolver {
        // PRIVATE METHODS
        //
 
+       /**
+        * Locates the identity specified by the given short name. If more than one
+        * identity matches the given pattern, the one with the highest trust is
+        * used. When calculating the trust, local and remote trust are treated
+        * equally, i.e. the higher value of either one is used.
+        *
+        * @param shortName
+        *            The short name to locate an identity for
+        * @return The located identity, or {@code null} if no identity can be
+        *         found, or if no own identity is found to use for locating an
+        *         identity
+        */
        private Identity locateIdentity(String shortName) {
                int atSign = shortName.indexOf('@');
                String identityName = shortName;
@@ -130,6 +187,12 @@ public class Resolver {
                return matchingIdentities.get(0);
        }
 
+       /**
+        * Returns a random own identity from the web of trust.
+        *
+        * @return A random own identity from the web of trust, or {@code null} if
+        *         the web of trust does not have any own identities
+        */
        private OwnIdentity getFirstOwnIdentity() {
                Set<OwnIdentity> ownIdentities = identityManager.getAllOwnIdentities();
                if (!ownIdentities.isEmpty()) {
index c495e71..abbdea5 100644 (file)
 
 package net.pterodactylus.wotns.main;
 
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+
 import net.pterodactylus.util.logging.Logging;
+import net.pterodactylus.util.logging.LoggingListener;
 import net.pterodactylus.util.version.Version;
 import net.pterodactylus.wotns.freenet.plugin.PluginConnector;
 import net.pterodactylus.wotns.freenet.wot.IdentityManager;
@@ -35,7 +39,7 @@ import freenet.pluginmanager.FredPluginVersioned;
 import freenet.pluginmanager.PluginRespirator;
 
 /**
- * TODO
+ * Main plugin class for Web of Trust Name Service.
  *
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
@@ -43,39 +47,84 @@ public class WoTNSPlugin implements FredPlugin, FredPluginL10n, FredPluginBaseL1
 
        static {
                Logging.setup("WoTNS");
-               Logging.setupConsoleLogging();
+               Logging.addLoggingListener(new LoggingListener() {
+
+                       @Override
+                       public void logged(LogRecord logRecord) {
+                               Class<?> loggerClass = Logging.getLoggerClass(logRecord.getLoggerName());
+                               int recordLevel = logRecord.getLevel().intValue();
+                               if (recordLevel < Level.FINE.intValue()) {
+                                       freenet.support.Logger.debug(loggerClass, String.format(logRecord.getMessage(), logRecord.getParameters()), logRecord.getThrown());
+                               } else if (recordLevel < Level.INFO.intValue()) {
+                                       freenet.support.Logger.minor(loggerClass, String.format(logRecord.getMessage(), logRecord.getParameters()), logRecord.getThrown());
+                               } else if (recordLevel < Level.WARNING.intValue()) {
+                                       freenet.support.Logger.normal(loggerClass, String.format(logRecord.getMessage(), logRecord.getParameters()), logRecord.getThrown());
+                               } else if (recordLevel < Level.SEVERE.intValue()) {
+                                       freenet.support.Logger.warning(loggerClass, String.format(logRecord.getMessage(), logRecord.getParameters()), logRecord.getThrown());
+                               } else {
+                                       freenet.support.Logger.error(loggerClass, String.format(logRecord.getMessage(), logRecord.getParameters()), logRecord.getThrown());
+                               }
+                       }
+               });
        }
 
-       private static final Version VERSION = new Version(0, 0, 7);
+       /** The current version of the plugin. */
+       private static final Version VERSION = new Version(0, 0, 8);
 
+       /** The plugin respirator. */
        private PluginRespirator pluginRespirator;
 
+       /** The l10n handler. */
        private PluginL10n l10n;
 
+       /** The web interface. */
        private WebInterface webInterface;
 
+       /** The resolver. */
        private Resolver resolver;
 
+       /** The web of trust connector. */
        private WebOfTrustConnector webOfTrustConnector;
 
+       /** The identity manager. */
        private IdentityManager identityManager;
 
        //
        // ACCESSORS
        //
 
+       /**
+        * Returns the high-level simple client for the node.
+        *
+        * @return The high-level simple client
+        */
        public HighLevelSimpleClient getHighLevelSimpleClient() {
                return pluginRespirator.getHLSimpleClient();
        }
 
+       /**
+        * Returns the toadlet container of the node.
+        *
+        * @return The toadlet container of the node
+        */
        public ToadletContainer getToadletContainer() {
                return pluginRespirator.getToadletContainer();
        }
 
+       /**
+        * Returns the identity manager.
+        *
+        * @return The identity manager
+        */
        public IdentityManager getIdentityManager() {
                return identityManager;
        }
 
+       /**
+        * Returns the resolver.
+        *
+        * @return The resolver
+        */
        public Resolver getResolver() {
                return resolver;
        }
index 7039ef7..77d35d5 100644 (file)
 
 package net.pterodactylus.wotns.template;
 
+import net.pterodactylus.util.template.Accessor;
 import net.pterodactylus.util.template.ReflectionAccessor;
 import net.pterodactylus.util.template.TemplateContext;
 import net.pterodactylus.wotns.freenet.wot.Identity;
 import net.pterodactylus.wotns.main.IdentityTargets;
 
 /**
- * TODO
+ * {@link Accessor} implementation that can expose {@link IdentityTargets} for
+ * an {@link Identity}.
  *
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
index 4d63640..02b410a 100644 (file)
@@ -114,11 +114,11 @@ public class WebInterface {
                pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage<FreenetRequest>("css/", "/static/css/", "text/css")));
 
                ToadletContainer toadletContainer = wotNSPlugin.getToadletContainer();
-               toadletContainer.getPageMaker().addNavigationCategory("/tns/index.html", "Navigation.Menu.Name", "Navigation.Menu.Tooltip", wotNSPlugin);
+               toadletContainer.getPageMaker().addNavigationCategory("/tns/index.html", "Navigation.Menu.WoTNS.Name", "Navigation.Menu.WoTNS.Tooltip", wotNSPlugin);
                for (PageToadlet toadlet : pageToadlets) {
                        String menuName = toadlet.getMenuName();
                        if (menuName != null) {
-                               toadletContainer.register(toadlet, "Navigation.Menu.Name", toadlet.path(), true, "Navigation.Menu.Item." + menuName + ".Name", "Navigation.Menu.Item." + menuName + ".Tooltip", false, toadlet);
+                               toadletContainer.register(toadlet, "Navigation.Menu.WoTNS.Name", toadlet.path(), true, "Navigation.Menu.WoTNS.Item." + menuName + ".Name", "Navigation.Menu.WoTNS.Item." + menuName + ".Tooltip", false, toadlet);
                        } else {
                                toadletContainer.register(toadlet, null, toadlet.path(), true, false);
                        }
@@ -133,7 +133,7 @@ public class WebInterface {
                for (PageToadlet pageToadlet : pageToadlets) {
                        toadletContainer.unregister(pageToadlet);
                }
-               toadletContainer.getPageMaker().removeNavigationCategory("Navigation.Menu.Name");
+               toadletContainer.getPageMaker().removeNavigationCategory("Navigation.Menu.WoTNS.Name");
        }
 
        /**
index b034e45..37eaae4 100644 (file)
@@ -1,4 +1,4 @@
-Navigation.Menu.Name=WoTNS
-Navigation.Menu.Tooltip=Configure the Web of Trust Name Service
-Navigation.Menu.Item.Index.Name=Configure
-Navigation.Menu.Item.Index.Tooltip=Configure the Web of Trust Name Service
+Navigation.Menu.WoTNS.Name=WoTNS
+Navigation.Menu.WoTNS.Tooltip=Configure the Web of Trust Name Service
+Navigation.Menu.WoTNS.Item.Index.Name=Configure
+Navigation.Menu.WoTNS.Item.Index.Tooltip=Configure the Web of Trust Name Service