Add method to return the first WoT identity.
[WoTNS.git] / src / main / java / net / pterodactylus / wotns / main / Resolver.java
index 0d94ce2..4e53528 100644 (file)
@@ -23,7 +23,10 @@ import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
 import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
+import net.pterodactylus.util.logging.Logging;
 import net.pterodactylus.util.object.Default;
 import net.pterodactylus.wotns.freenet.wot.Identity;
 import net.pterodactylus.wotns.freenet.wot.IdentityManager;
@@ -38,6 +41,8 @@ import freenet.keys.FreenetURI;
  */
 public class Resolver {
 
+       private static final Logger logger = Logging.getLogger(Resolver.class);
+
        private final IdentityManager identityManager;
 
        private String ownIdentityId;
@@ -85,7 +90,6 @@ public class Resolver {
                        identityName = shortName.substring(0, atSign);
                        keyStart = shortName.substring(atSign + 1);
                }
-               @SuppressWarnings("hiding")
                final OwnIdentity ownIdentity;
                if ((this.ownIdentityId != null) && (identityManager.getOwnIdentity(this.ownIdentityId) != null)) {
                        ownIdentity = identityManager.getOwnIdentity(this.ownIdentityId);
@@ -97,6 +101,7 @@ public class Resolver {
                                ownIdentity = null;
                        }
                } else {
+                       logger.log(Level.SEVERE, "Can not resolve “" + shortName + "” without a Web of Trust Identity!");
                        ownIdentity = null;
                }
                if (ownIdentity == null) {
@@ -128,4 +133,12 @@ public class Resolver {
                return matchingIdentities.get(0);
        }
 
+       private OwnIdentity getFirstOwnIdentity() {
+               Set<OwnIdentity> ownIdentities = identityManager.getAllOwnIdentities();
+               if (!ownIdentities.isEmpty()) {
+                       return ownIdentities.iterator().next();
+               }
+               return null;
+       }
+
 }