X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftemplate%2FIdentityAccessor.java;h=7766af30979725207bfffe089c7f4faa1cc41b9d;hb=d127c36ae1d62d93c718117506966ced68854d87;hp=4ea956d99dcdc7024ac5f62334cf97771acad3b3;hpb=9ceea683ab66b047fc4ded3ee6f92b33ceea3968;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/template/IdentityAccessor.java b/src/main/java/net/pterodactylus/sone/template/IdentityAccessor.java
index 4ea956d..7766af3 100644
--- a/src/main/java/net/pterodactylus/sone/template/IdentityAccessor.java
+++ b/src/main/java/net/pterodactylus/sone/template/IdentityAccessor.java
@@ -1,5 +1,5 @@
/*
- * Sone - IdentityAccessor.java - Copyright © 2010 David Roden
+ * Sone - IdentityAccessor.java - Copyright © 2010â2016 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -17,16 +17,17 @@
package net.pterodactylus.sone.template;
-import java.util.Collections;
import java.util.Set;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.freenet.wot.Identity;
import net.pterodactylus.sone.freenet.wot.OwnIdentity;
-import net.pterodactylus.sone.freenet.wot.PluginException;
import net.pterodactylus.util.template.Accessor;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.ReflectionAccessor;
+import net.pterodactylus.util.template.TemplateContext;
/**
* {@link Accessor} implementation that adds a âuniqueNicknameâ member to an
@@ -34,6 +35,7 @@ import net.pterodactylus.util.template.ReflectionAccessor;
*
* @author David âBombeâ Roden
*/
+@Singleton
public class IdentityAccessor extends ReflectionAccessor {
/** The core. */
@@ -45,6 +47,7 @@ public class IdentityAccessor extends ReflectionAccessor {
* @param core
* The core
*/
+ @Inject
public IdentityAccessor(Core core) {
this.core = core;
}
@@ -53,17 +56,12 @@ public class IdentityAccessor extends ReflectionAccessor {
* {@inheritDoc}
*/
@Override
- public Object get(DataProvider dataProvider, Object object, String member) {
+ public Object get(TemplateContext templateContext, Object object, String member) {
Identity identity = (Identity) object;
if ("uniqueNickname".equals(member)) {
int minLength = -1;
- boolean found = false;
- Set ownIdentities = null;
- try {
- ownIdentities = core.getWebOfTrustConnector().loadAllOwnIdentities();
- } catch (PluginException e) {
- ownIdentities = Collections.emptySet();
- }
+ boolean found;
+ Set ownIdentities = core.getIdentityManager().getAllOwnIdentities();
do {
boolean unique = true;
String abbreviatedWantedNickname = getAbbreviatedNickname(identity, ++minLength);
@@ -81,7 +79,7 @@ public class IdentityAccessor extends ReflectionAccessor {
} while (!found && (minLength < 43));
return getAbbreviatedNickname(identity, minLength);
}
- return super.get(dataProvider, object, member);
+ return super.get(templateContext, object, member);
}
//
@@ -99,7 +97,7 @@ public class IdentityAccessor extends ReflectionAccessor {
* append to the nickname
* @return The nickname with optional ID appendage
*/
- private String getAbbreviatedNickname(Identity identity, int length) {
+ private static String getAbbreviatedNickname(Identity identity, int length) {
return identity.getNickname() + ((length > 0) ? "@" + identity.getId().substring(0, length) : "");
}