From 936b1e72a332c6bfdd02370a2ea51adf2d8c9248 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 18 Jan 2013 22:56:42 +0100 Subject: [PATCH] Add helper for Sone URIs. --- .../java/net/pterodactylus/sone/core/Core.java | 2 +- .../java/net/pterodactylus/sone/core/SoneUri.java | 55 ++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/pterodactylus/sone/core/SoneUri.java diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 5a26b55..5e98c47 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -871,7 +871,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, synchronized (sones) { final Sone sone = getRemoteSone(identity.getId(), true).setIdentity(identity); boolean newSone = sone.getRequestUri() == null; - sone.setRequestUri(getSoneUri(identity.getRequestUri())); + sone.setRequestUri(SoneUri.create(identity.getRequestUri())); sone.setLatestEdition(Numbers.safeParseLong(identity.getProperty("Sone.LatestEdition"), (long) 0)); if (newSone) { synchronized (knownSones) { diff --git a/src/main/java/net/pterodactylus/sone/core/SoneUri.java b/src/main/java/net/pterodactylus/sone/core/SoneUri.java new file mode 100644 index 0000000..6c5bf16 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/core/SoneUri.java @@ -0,0 +1,55 @@ +/* + * Sone - SoneUri.java - Copyright © 2013 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.core; + +import java.net.MalformedURLException; +import java.util.logging.Level; +import java.util.logging.Logger; + +import net.pterodactylus.util.logging.Logging; +import freenet.keys.FreenetURI; + +/** + * Helper class that creates {@link FreenetURI}s for Sone to insert to and + * request from. + * + * @author David ‘Bombe’ Roden + */ +public class SoneUri { + + /** The logger. */ + private static final Logger logger = Logging.getLogger(SoneUri.class); + + /** + * Generate a Sone URI from the given URI. + * + * @param uri + * The URI to derive the Sone URI from + * @return The derived URI + */ + public static FreenetURI create(String uri) { + try { + return new FreenetURI(uri).setDocName("Sone").setMetaString(new String[0]); + } catch (MalformedURLException mue1) { + /* this should never happen. */ + logger.log(Level.WARNING, String.format("Could not create Sone URI from URI: %s", uri), mue1); + return null; + } + } + +} -- 2.7.4