/*
- * Sone - IdentityAccessor.java - Copyright © 2010 David Roden
+ * Sone - IdentityAccessor.java - Copyright © 2010–2012 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
package net.pterodactylus.sone.template;
-import java.util.Collections;
import java.util.Set;
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
* {@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<OwnIdentity> ownIdentities = null;
- try {
- ownIdentities = core.getWebOfTrustConnector().loadAllOwnIdentities();
- } catch (PluginException e) {
- ownIdentities = Collections.emptySet();
- }
+ ownIdentities = core.getIdentityManager().getAllOwnIdentities();
do {
boolean unique = true;
String abbreviatedWantedNickname = getAbbreviatedNickname(identity, ++minLength);
} while (!found && (minLength < 43));
return getAbbreviatedNickname(identity, minLength);
}
- return super.get(dataProvider, object, member);
+ return super.get(templateContext, object, member);
}
//
* 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) : "");
}