Merge commit 'fcabe38e9b3abacc0d580bf0513600858aee2eca' into less-critical
[Sone.git] / src / main / java / net / pterodactylus / sone / core / SoneUri.java
1 /*
2  * Sone - SoneUri.java - Copyright © 2013 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.sone.core;
19
20 import java.net.MalformedURLException;
21 import java.util.logging.Level;
22 import java.util.logging.Logger;
23
24 import net.pterodactylus.util.logging.Logging;
25 import freenet.keys.FreenetURI;
26
27 /**
28  * Helper class that creates {@link FreenetURI}s for Sone to insert to and
29  * request from.
30  *
31  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
32  */
33 public class SoneUri {
34
35         /** The logger. */
36         private static final Logger logger = Logging.getLogger(SoneUri.class);
37
38         /**
39          * Generate a Sone URI from the given URI.
40          *
41          * @param uri
42          *            The URI to derive the Sone URI from
43          * @return The derived URI
44          */
45         public static FreenetURI create(String uri) {
46                 try {
47                         return new FreenetURI(uri).setDocName("Sone").setMetaString(new String[0]);
48                 } catch (MalformedURLException mue1) {
49                         /* this should never happen. */
50                         logger.log(Level.WARNING, String.format("Could not create Sone URI from URI: %s", uri), mue1);
51                         return null;
52                 }
53         }
54
55 }