X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=inline;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftemplate%2FIdentityAccessor.java;h=ed139deb4801f00b60b2ee946da414e5ef119e03;hb=9b102d5ff09775e3867ad8709f22baf0ad608d30;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..ed139de 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â2019 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,23 +17,23 @@
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
* {@link Identity}.
- *
- * @author David âBombeâ Roden
*/
+@Singleton
public class IdentityAccessor extends ReflectionAccessor {
/** The core. */
@@ -45,6 +45,7 @@ public class IdentityAccessor extends ReflectionAccessor {
* @param core
* The core
*/
+ @Inject
public IdentityAccessor(Core core) {
this.core = core;
}
@@ -53,17 +54,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 +77,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 +95,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) : "");
}