X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftemplate%2FSoneAccessor.java;h=ead6066962ebd2a27c17a10dd7442b3ef9f4e719;hb=5e30dc1ca805f1a2d87b6c752da68a57275cb159;hp=d0a287f34d8b249e662816b4c57ce32fa655df5a;hpb=916b45a47c8dce3c6837c12d4facb6eb572bb987;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java b/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java
index d0a287f..ead6066 100644
--- a/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java
+++ b/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java
@@ -17,11 +17,20 @@
package net.pterodactylus.sone.template;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import net.pterodactylus.sone.core.Core;
+import net.pterodactylus.sone.core.Core.SoneStatus;
import net.pterodactylus.sone.data.Profile;
import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.freenet.wot.Trust;
+import net.pterodactylus.sone.web.WebInterface;
+import net.pterodactylus.sone.web.ajax.GetTimesAjaxPage;
+import net.pterodactylus.util.logging.Logging;
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} for {@link Sone}s that adds a couple of properties to Sones.
@@ -32,7 +41,7 @@ import net.pterodactylus.util.template.ReflectionAccessor;
*
friend
* Will return {@code true} if the sone in question is a friend of the
* currently logged in Sone (as determined by accessing the âcurrentSoneâ
- * variable of the given {@link DataProvider}).
+ * variable of the given {@link TemplateContext}).
* current
* Will return {@code true} if the sone in question is the currently logged
* in Sone.
@@ -42,27 +51,69 @@ import net.pterodactylus.util.template.ReflectionAccessor;
*/
public class SoneAccessor extends ReflectionAccessor {
+ /** The logger. */
+ private static final Logger logger = Logging.getLogger(SoneAccessor.class);
+
+ /** The core. */
+ private final Core core;
+
+ /**
+ * Creates a new Sone accessor.
+ *
+ * @param core
+ * The Sone core
+ */
+ public SoneAccessor(Core core) {
+ this.core = core;
+ }
+
/**
* {@inheritDoc}
*/
@Override
- public Object get(DataProvider dataProvider, Object object, String member) {
+ public Object get(TemplateContext templateContext, Object object, String member) {
Sone sone = (Sone) object;
if (member.equals("niceName")) {
return getNiceName(sone);
+ } else if (member.equals("local")) {
+ return core.isLocalSone(sone);
} else if (member.equals("friend")) {
- Sone currentSone = (Sone) dataProvider.getData("currentSone");
- return currentSone.hasFriend(sone) ? true : null;
+ Sone currentSone = (Sone) templateContext.get("currentSone");
+ return (currentSone != null) && currentSone.hasFriend(sone.getId());
} else if (member.equals("current")) {
- Sone currentSone = (Sone) dataProvider.getData("currentSone");
- return currentSone.equals(sone);
- } else if (member.equals("blocked")) {
- Sone currentSone = (Sone) dataProvider.getData("currentSone");
- return currentSone.isSoneBlocked(sone.getId());
+ Sone currentSone = (Sone) templateContext.get("currentSone");
+ return (currentSone != null) && currentSone.equals(sone);
} else if (member.equals("modified")) {
- return sone.getModificationCounter() > 0;
+ return core.isModifiedSone(sone);
+ } else if (member.equals("status")) {
+ return core.getSoneStatus(sone);
+ } else if (member.equals("unknown")) {
+ return core.getSoneStatus(sone) == SoneStatus.unknown;
+ } else if (member.equals("idle")) {
+ return core.getSoneStatus(sone) == SoneStatus.idle;
+ } else if (member.equals("inserting")) {
+ return core.getSoneStatus(sone) == SoneStatus.inserting;
+ } else if (member.equals("downloading")) {
+ return core.getSoneStatus(sone) == SoneStatus.downloading;
+ } else if (member.equals("new")) {
+ return core.isNewSone(sone.getId());
+ } else if (member.equals("locked")) {
+ return core.isLocked(sone);
+ } else if (member.equals("lastUpdatedText")) {
+ return GetTimesAjaxPage.getTime((WebInterface) templateContext.get("webInterface"), sone.getTime());
+ } else if (member.equals("trust")) {
+ Sone currentSone = (Sone) templateContext.get("currentSone");
+ if (currentSone == null) {
+ return null;
+ }
+ Trust trust = core.getTrust(currentSone, sone);
+ logger.log(Level.FINEST, "Trust for %s by %s: %s", new Object[] { sone, currentSone, trust });
+ if (trust == null) {
+ return new Trust(null, null, null);
+ }
+ return trust;
}
- return super.get(dataProvider, object, member);
+ return super.get(templateContext, object, member);
}
//
@@ -83,7 +134,7 @@ public class SoneAccessor extends ReflectionAccessor {
String lastName = profile.getLastName();
if (firstName == null) {
if (lastName == null) {
- return sone.getName();
+ return String.valueOf(sone.getName());
}
return lastName;
}