373077fb943b1128e6122e0d7b54431e80a82a53
[Sone.git] / src / main / java / net / pterodactylus / sone / core / SoneUri.java
1 /*
2  * Sone - SoneUri.java - Copyright © 2013–2019 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 static java.util.logging.Logger.getLogger;
21
22 import java.net.MalformedURLException;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25
26 import freenet.keys.FreenetURI;
27
28 /**
29  * Helper class that creates {@link FreenetURI}s for Sone to insert to and
30  * request from.
31  */
32 public class SoneUri {
33
34         /** The logger. */
35         private static final Logger logger = getLogger(SoneUri.class.getName());
36
37         /**
38          * Generate a Sone URI from the given URI.
39          *
40          * @param uri
41          *            The URI to derive the Sone URI from
42          * @return The derived URI
43          */
44         public static FreenetURI create(String uri) {
45                 try {
46                         return new FreenetURI(uri).setDocName("Sone").setMetaString(new String[0]);
47                 } catch (MalformedURLException mue1) {
48                         /* this should never happen. */
49                         logger.log(Level.WARNING, String.format("Could not create Sone URI from URI: %s", uri), mue1);
50                         return null;
51                 }
52         }
53
54 }