From 7f024734546973cd592e6cbf04604705477f15f6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 22 Jan 2013 11:27:11 +0100 Subject: [PATCH] Remove possibility to create Sones from sone provider interface. --- .../java/net/pterodactylus/sone/core/Core.java | 25 ++-------------------- .../net/pterodactylus/sone/core/SoneProvider.java | 9 ++------ .../net/pterodactylus/sone/data/impl/PostImpl.java | 4 ++-- .../pterodactylus/sone/data/impl/ReplyImpl.java | 2 +- .../sone/fcp/AbstractSoneCommand.java | 2 +- .../pterodactylus/sone/fcp/GetPostFeedCommand.java | 2 +- .../pterodactylus/sone/template/ParserFilter.java | 2 +- .../pterodactylus/sone/text/SoneTextParser.java | 2 +- .../net/pterodactylus/sone/web/CreatePostPage.java | 2 +- .../net/pterodactylus/sone/web/DistrustPage.java | 2 +- .../pterodactylus/sone/web/ImageBrowserPage.java | 2 +- .../pterodactylus/sone/web/MarkAsKnownPage.java | 2 +- .../net/pterodactylus/sone/web/SearchPage.java | 2 +- .../java/net/pterodactylus/sone/web/TrustPage.java | 2 +- .../net/pterodactylus/sone/web/UntrustPage.java | 2 +- .../net/pterodactylus/sone/web/ViewSonePage.java | 4 ++-- .../sone/web/ajax/CreatePostAjaxPage.java | 2 +- .../sone/web/ajax/DistrustAjaxPage.java | 2 +- .../sone/web/ajax/GetStatusAjaxPage.java | 2 +- .../sone/web/ajax/MarkAsKnownAjaxPage.java | 2 +- .../pterodactylus/sone/web/ajax/TrustAjaxPage.java | 2 +- .../sone/web/ajax/UntrustAjaxPage.java | 2 +- .../sone/text/SoneTextParserTest.java | 2 +- 23 files changed, 27 insertions(+), 53 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 862cc78..582a5fd 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -357,30 +357,9 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, * @return The Sone with the given ID, or {@code null} if there is no such * Sone */ - public Sone getSone(String id) { - return getSone(id, true); - } - - /** - * Returns the Sone with the given ID, regardless whether it’s local or - * remote. - * - * @param id - * The ID of the Sone to get - * @param create - * {@code true} to create a new Sone if none exists, - * {@code false} to return {@code null} if a Sone with the given - * ID does not exist - * @return The Sone with the given ID, or {@code null} if there is no such - * Sone - */ @Override - public Sone getSone(String id, boolean create) { + public Sone getSone(String id) { synchronized (sones) { - if (!sones.containsKey(id) && create) { - Sone sone = new Sone(id, false); - sones.put(id, sone); - } return sones.get(id); } } @@ -2359,7 +2338,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, /* some local identity still trusts this identity, don’t remove. */ return; } - Sone sone = getSone(identity.getId(), false); + Sone sone = getSone(identity.getId()); if (sone == null) { /* TODO - we don’t have the Sone anymore. should this happen? */ return; diff --git a/src/main/java/net/pterodactylus/sone/core/SoneProvider.java b/src/main/java/net/pterodactylus/sone/core/SoneProvider.java index 73edd0b..6b479df 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneProvider.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneProvider.java @@ -27,17 +27,12 @@ import net.pterodactylus.sone.data.Sone; public interface SoneProvider { /** - * Returns the Sone with the given ID, if it exists. If it does not exist - * and {@code create} is {@code false}, {@code null} is returned; otherwise, - * a new Sone with the given ID is created and returned. + * Returns the Sone with the given ID, if it exists. * * @param soneId * The ID of the Sone to return - * @param create - * {@code true} to create a new Sone if no Sone with the given ID - * exists, {@code false} to return {@code null} instead * @return The Sone with the given ID, or {@code null} */ - public Sone getSone(String soneId, boolean create); + public Sone getSone(String soneId); } diff --git a/src/main/java/net/pterodactylus/sone/data/impl/PostImpl.java b/src/main/java/net/pterodactylus/sone/data/impl/PostImpl.java index bb8a4df..d422cba 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/PostImpl.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/PostImpl.java @@ -94,7 +94,7 @@ public class PostImpl implements Post { */ @Override public Sone getSone() { - return soneProvider.getSone(soneId, false); + return soneProvider.getSone(soneId); } /** @@ -102,7 +102,7 @@ public class PostImpl implements Post { */ @Override public Sone getRecipient() { - return soneProvider.getSone(recipientId, false); + return soneProvider.getSone(recipientId); } /** diff --git a/src/main/java/net/pterodactylus/sone/data/impl/ReplyImpl.java b/src/main/java/net/pterodactylus/sone/data/impl/ReplyImpl.java index 5590c7e..5ede070 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/ReplyImpl.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/ReplyImpl.java @@ -83,7 +83,7 @@ public abstract class ReplyImpl> implements Reply { */ @Override public Sone getSone() { - return soneProvider.getSone(soneId, false); + return soneProvider.getSone(soneId); } /** diff --git a/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java b/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java index 80802ad..036e451 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java +++ b/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java @@ -162,7 +162,7 @@ public abstract class AbstractSoneCommand extends AbstractCommand { if (mandatory && (soneId == null)) { throw new FcpException("Could not load Sone ID from “" + parameterName + "”."); } - Sone sone = localOnly ? core.getLocalSone(soneId, false) : core.getSone(soneId, false); + Sone sone = localOnly ? core.getLocalSone(soneId, false) : core.getSone(soneId); if (mandatory && (sone == null)) { throw new FcpException("Could not load Sone from “" + soneId + "”."); } diff --git a/src/main/java/net/pterodactylus/sone/fcp/GetPostFeedCommand.java b/src/main/java/net/pterodactylus/sone/fcp/GetPostFeedCommand.java index 5f2fd14..f842ac4 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/GetPostFeedCommand.java +++ b/src/main/java/net/pterodactylus/sone/fcp/GetPostFeedCommand.java @@ -66,7 +66,7 @@ public class GetPostFeedCommand extends AbstractSoneCommand { if (!getCore().hasSone(friendSoneId)) { continue; } - allPosts.addAll(getCore().getSone(friendSoneId, false).getPosts()); + allPosts.addAll(getCore().getSone(friendSoneId).getPosts()); } allPosts.addAll(getCore().getDirectedPosts(sone)); allPosts = Collections2.filter(allPosts, Post.FUTURE_POSTS_FILTER); diff --git a/src/main/java/net/pterodactylus/sone/template/ParserFilter.java b/src/main/java/net/pterodactylus/sone/template/ParserFilter.java index d2f2619..8833a2d 100644 --- a/src/main/java/net/pterodactylus/sone/template/ParserFilter.java +++ b/src/main/java/net/pterodactylus/sone/template/ParserFilter.java @@ -94,7 +94,7 @@ public class ParserFilter implements Filter { int cutOffLength = Numbers.safeParseInteger(parameters.get("cut-off-length"), Numbers.safeParseInteger(templateContext.get(String.valueOf(parameters.get("cut-off-length"))), length)); Object sone = parameters.get("sone"); if (sone instanceof String) { - sone = core.getSone((String) sone, false); + sone = core.getSone((String) sone); } FreenetRequest request = (FreenetRequest) templateContext.get("request"); SoneTextParserContext context = new SoneTextParserContext(request, (Sone) sone); diff --git a/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java b/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java index a093e46..8e3c023 100644 --- a/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java +++ b/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java @@ -239,7 +239,7 @@ public class SoneTextParser implements Parser { if (linkType == LinkType.SONE) { if (line.length() >= (7 + 43)) { String soneId = line.substring(7, 50); - Sone sone = soneProvider.getSone(soneId, false); + Sone sone = soneProvider.getSone(soneId); if (sone == null) { /* * don’t use create=true above, we don’t want diff --git a/src/main/java/net/pterodactylus/sone/web/CreatePostPage.java b/src/main/java/net/pterodactylus/sone/web/CreatePostPage.java index 087a5ad..e77e55a 100644 --- a/src/main/java/net/pterodactylus/sone/web/CreatePostPage.java +++ b/src/main/java/net/pterodactylus/sone/web/CreatePostPage.java @@ -65,7 +65,7 @@ public class CreatePostPage extends SoneTemplatePage { if (sender == null) { sender = currentSone; } - Sone recipient = webInterface.getCore().getSone(recipientId, false); + Sone recipient = webInterface.getCore().getSone(recipientId); text = TextFilter.filter(request.getHttpRequest().getHeader("host"), text); webInterface.getCore().createPost(sender, recipient, System.currentTimeMillis(), text); throw new RedirectException(returnPage); diff --git a/src/main/java/net/pterodactylus/sone/web/DistrustPage.java b/src/main/java/net/pterodactylus/sone/web/DistrustPage.java index 60c174d..262d602 100644 --- a/src/main/java/net/pterodactylus/sone/web/DistrustPage.java +++ b/src/main/java/net/pterodactylus/sone/web/DistrustPage.java @@ -59,7 +59,7 @@ public class DistrustPage extends SoneTemplatePage { String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256); String identity = request.getHttpRequest().getPartAsStringFailsafe("sone", 44); Sone currentSone = getCurrentSone(request.getToadletContext()); - Sone sone = webInterface.getCore().getSone(identity, false); + Sone sone = webInterface.getCore().getSone(identity); if (sone != null) { webInterface.getCore().distrustSone(currentSone, sone); } diff --git a/src/main/java/net/pterodactylus/sone/web/ImageBrowserPage.java b/src/main/java/net/pterodactylus/sone/web/ImageBrowserPage.java index 4a9548e..d0a446f 100644 --- a/src/main/java/net/pterodactylus/sone/web/ImageBrowserPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ImageBrowserPage.java @@ -77,7 +77,7 @@ public class ImageBrowserPage extends SoneTemplatePage { } String soneId = request.getHttpRequest().getParam("sone", null); if (soneId != null) { - Sone sone = webInterface.getCore().getSone(soneId, false); + Sone sone = webInterface.getCore().getSone(soneId); templateContext.set("soneRequested", true); templateContext.set("sone", sone); return; diff --git a/src/main/java/net/pterodactylus/sone/web/MarkAsKnownPage.java b/src/main/java/net/pterodactylus/sone/web/MarkAsKnownPage.java index 0bf5285..a923386 100644 --- a/src/main/java/net/pterodactylus/sone/web/MarkAsKnownPage.java +++ b/src/main/java/net/pterodactylus/sone/web/MarkAsKnownPage.java @@ -77,7 +77,7 @@ public class MarkAsKnownPage extends SoneTemplatePage { } webInterface.getCore().markReplyKnown(reply); } else if (type.equals("sone")) { - Sone sone = webInterface.getCore().getSone(id, false); + Sone sone = webInterface.getCore().getSone(id); if (sone == null) { continue; } diff --git a/src/main/java/net/pterodactylus/sone/web/SearchPage.java b/src/main/java/net/pterodactylus/sone/web/SearchPage.java index 337918d..c037baf 100644 --- a/src/main/java/net/pterodactylus/sone/web/SearchPage.java +++ b/src/main/java/net/pterodactylus/sone/web/SearchPage.java @@ -309,7 +309,7 @@ public class SearchPage extends SoneTemplatePage { */ private String getSoneId(String phrase) { String soneId = phrase.startsWith("sone://") ? phrase.substring(7) : phrase; - return (webInterface.getCore().getSone(soneId, false) != null) ? soneId : null; + return (webInterface.getCore().getSone(soneId) != null) ? soneId : null; } /** diff --git a/src/main/java/net/pterodactylus/sone/web/TrustPage.java b/src/main/java/net/pterodactylus/sone/web/TrustPage.java index ef5463b..5d62399 100644 --- a/src/main/java/net/pterodactylus/sone/web/TrustPage.java +++ b/src/main/java/net/pterodactylus/sone/web/TrustPage.java @@ -59,7 +59,7 @@ public class TrustPage extends SoneTemplatePage { String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256); String identity = request.getHttpRequest().getPartAsStringFailsafe("sone", 44); Sone currentSone = getCurrentSone(request.getToadletContext()); - Sone sone = webInterface.getCore().getSone(identity, false); + Sone sone = webInterface.getCore().getSone(identity); if (sone != null) { webInterface.getCore().trustSone(currentSone, sone); } diff --git a/src/main/java/net/pterodactylus/sone/web/UntrustPage.java b/src/main/java/net/pterodactylus/sone/web/UntrustPage.java index e43740e..1ee4f8e 100644 --- a/src/main/java/net/pterodactylus/sone/web/UntrustPage.java +++ b/src/main/java/net/pterodactylus/sone/web/UntrustPage.java @@ -59,7 +59,7 @@ public class UntrustPage extends SoneTemplatePage { String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256); String identity = request.getHttpRequest().getPartAsStringFailsafe("sone", 44); Sone currentSone = getCurrentSone(request.getToadletContext()); - Sone sone = webInterface.getCore().getSone(identity, false); + Sone sone = webInterface.getCore().getSone(identity); if (sone != null) { webInterface.getCore().untrustSone(currentSone, sone); } diff --git a/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java b/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java index dec4fe2..ddc0231 100644 --- a/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java +++ b/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java @@ -65,7 +65,7 @@ public class ViewSonePage extends SoneTemplatePage { @Override protected String getPageTitle(FreenetRequest request) { String soneId = request.getHttpRequest().getParam("sone"); - Sone sone = webInterface.getCore().getSone(soneId, false); + Sone sone = webInterface.getCore().getSone(soneId); if ((sone != null) && (sone.getTime() > 0)) { String soneName = SoneAccessor.getNiceName(sone); return soneName + " - " + webInterface.getL10n().getString("Page.ViewSone.Title"); @@ -80,7 +80,7 @@ public class ViewSonePage extends SoneTemplatePage { protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); String soneId = request.getHttpRequest().getParam("sone"); - Sone sone = webInterface.getCore().getSone(soneId, false); + Sone sone = webInterface.getCore().getSone(soneId); templateContext.set("sone", sone); templateContext.set("soneId", soneId); if (sone == null) { diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.java index 4750794..32ebfc9 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.java @@ -51,7 +51,7 @@ public class CreatePostAjaxPage extends JsonPage { return createErrorJsonObject("auth-required"); } String recipientId = request.getHttpRequest().getParam("recipient"); - Sone recipient = webInterface.getCore().getSone(recipientId, false); + Sone recipient = webInterface.getCore().getSone(recipientId); String senderId = request.getHttpRequest().getParam("sender"); Sone sender = webInterface.getCore().getLocalSone(senderId, false); if (sender == null) { diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/DistrustAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/DistrustAjaxPage.java index 25de182..b86055d 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/DistrustAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/DistrustAjaxPage.java @@ -51,7 +51,7 @@ public class DistrustAjaxPage extends JsonPage { return createErrorJsonObject("auth-required"); } String soneId = request.getHttpRequest().getParam("sone"); - Sone sone = webInterface.getCore().getSone(soneId, false); + Sone sone = webInterface.getCore().getSone(soneId); if (sone == null) { return createErrorJsonObject("invalid-sone-id"); } diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java index 8657a6a..384261c 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java @@ -74,7 +74,7 @@ public class GetStatusAjaxPage extends JsonPage { String[] soneIds = loadSoneIds.split(","); for (String soneId : soneIds) { /* just add it, we skip null further down. */ - sones.add(webInterface.getCore().getSone(soneId, false)); + sones.add(webInterface.getCore().getSone(soneId)); } } JsonArray jsonSones = new JsonArray(); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.java index e9c582a..55ae553 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.java @@ -69,7 +69,7 @@ public class MarkAsKnownAjaxPage extends JsonPage { } core.markReplyKnown(reply); } else if (type.equals("sone")) { - Sone sone = core.getSone(id, false); + Sone sone = core.getSone(id); if (sone == null) { continue; } diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/TrustAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/TrustAjaxPage.java index 756cee7..9329c1b 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/TrustAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/TrustAjaxPage.java @@ -51,7 +51,7 @@ public class TrustAjaxPage extends JsonPage { return createErrorJsonObject("auth-required"); } String soneId = request.getHttpRequest().getParam("sone"); - Sone sone = webInterface.getCore().getSone(soneId, false); + Sone sone = webInterface.getCore().getSone(soneId); if (sone == null) { return createErrorJsonObject("invalid-sone-id"); } diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/UntrustAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/UntrustAjaxPage.java index 227b580..70e1448 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/UntrustAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/UntrustAjaxPage.java @@ -51,7 +51,7 @@ public class UntrustAjaxPage extends JsonPage { return createErrorJsonObject("auth-required"); } String soneId = request.getHttpRequest().getParam("sone"); - Sone sone = webInterface.getCore().getSone(soneId, false); + Sone sone = webInterface.getCore().getSone(soneId); if (sone == null) { return createErrorJsonObject("invalid-sone-id"); } diff --git a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java index cd05acb..53c52dd 100644 --- a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java +++ b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java @@ -181,7 +181,7 @@ public class SoneTextParserTest extends TestCase { * {@inheritDoc} */ @Override - public Sone getSone(final String soneId, boolean create) { + public Sone getSone(final String soneId) { return new Sone(soneId, false) { /** -- 2.7.4