From 00adeb7e4a42365d0b5feb4e38338285e91a2301 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 13 Oct 2010 14:54:37 +0200 Subject: [PATCH] Store the Sone ID instead of the Sone itself in the session. --- src/main/java/net/pterodactylus/sone/core/Core.java | 5 ++++- src/main/java/net/pterodactylus/sone/data/Sone.java | 13 +++++++++---- .../java/net/pterodactylus/sone/web/SoneTemplatePage.java | 10 ++++++++-- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 7333d68..13f1589 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -22,6 +22,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.UUID; import java.util.logging.Level; import java.util.logging.Logger; @@ -147,10 +148,11 @@ public class Core extends AbstractService { /* parse local Sones. */ logger.log(Level.INFO, "Loading %d Sones…", allSoneNames.size()); for (String soneName : allSoneNames) { + String id = configuration.getStringValue("Sone/Name." + soneName + "/ID").getValue(null); String insertUri = configuration.getStringValue("Sone/Name." + soneName + "/InsertURI").getValue(null); String requestUri = configuration.getStringValue("Sone/Name." + soneName + "/RequestURI").getValue(null); try { - localSones.add(new Sone(soneName, new FreenetURI(requestUri), new FreenetURI(insertUri))); + localSones.add(new Sone(UUID.fromString(id), soneName, new FreenetURI(requestUri), new FreenetURI(insertUri))); } catch (MalformedURLException mue1) { logger.log(Level.WARNING, "Could not create Sone from requestUri (“" + requestUri + "”) and insertUri (“" + insertUri + "”)!", mue1); } @@ -178,6 +180,7 @@ public class Core extends AbstractService { /* store all Sones. */ for (Sone sone : localSones) { + configuration.getStringValue("Sone/Name." + sone.getName() + "/ID").setValue(sone.getId()); configuration.getStringValue("Sone/Name." + sone.getName() + "/RequestURI").setValue(sone.getRequestUri().toString()); configuration.getStringValue("Sone/Name." + sone.getName() + "/InsertURI").setValue(sone.getInsertUri().toString()); } diff --git a/src/main/java/net/pterodactylus/sone/data/Sone.java b/src/main/java/net/pterodactylus/sone/data/Sone.java index ba5ef68..4a73470 100644 --- a/src/main/java/net/pterodactylus/sone/data/Sone.java +++ b/src/main/java/net/pterodactylus/sone/data/Sone.java @@ -33,7 +33,7 @@ import freenet.keys.FreenetURI; public class Sone { /** A GUID for this Sone. */ - private final UUID id = UUID.randomUUID(); + private final UUID id; /** The name of this Sone. */ private final String name; @@ -51,18 +51,22 @@ public class Sone { /** * Creates a new Sone. * + * @param id + * The ID of this Sone * @param name * The name of the Sone * @param requestUri * The request URI of the Sone */ - public Sone(String name, FreenetURI requestUri) { - this(name, requestUri, null); + public Sone(UUID id, String name, FreenetURI requestUri) { + this(id, name, requestUri, null); } /** * Creates a new Sone. * + * @param id + * The ID of this Sone * @param name * The name of the Sone * @param requestUri @@ -70,7 +74,8 @@ public class Sone { * @param insertUri * The insert URI of the Sone */ - public Sone(String name, FreenetURI requestUri, FreenetURI insertUri) { + public Sone(UUID id, String name, FreenetURI requestUri, FreenetURI insertUri) { + this.id = id; this.name = name; this.requestUri = requestUri; this.insertUri = insertUri; diff --git a/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java b/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java index d6f1eb7..4078585 100644 --- a/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java +++ b/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java @@ -110,7 +110,13 @@ public class SoneTemplatePage extends TemplatePage { if (session == null) { return null; } - return (Sone) session.getAttribute("Sone.CurrentSone"); + String soneId = (String) session.getAttribute("Sone.CurrentSone"); + for (Sone sone : webInterface.core().localSones()) { + if (sone.getId().equals(soneId)) { + return sone; + } + } + return null; } /** @@ -123,7 +129,7 @@ public class SoneTemplatePage extends TemplatePage { */ protected void setCurrentSone(ToadletContext toadletContext, Sone sone) { Session session = getCurrentSession(toadletContext); - session.setAttribute("Sone.CurrentSone", sone); + session.setAttribute("Sone.CurrentSone", sone.getId()); } // -- 2.7.4