Merge branch 'master' into next
[Sone.git] / src / main / java / net / pterodactylus / sone / web / page / PageToadletFactory.java
1 /*
2  * Sone - PageToadletFactory.java - Copyright © 2010–2015 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.web.page;
19
20 import net.pterodactylus.util.web.Page;
21 import freenet.client.HighLevelSimpleClient;
22
23 /**
24  * Factory that creates {@link PageToadlet}s using a given
25  * {@link HighLevelSimpleClient}.
26  *
27  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
28  */
29 public class PageToadletFactory {
30
31         /** The client to use when creating the toadlets. */
32         private final HighLevelSimpleClient highLevelSimpleClient;
33
34         /** The prefix for all pages’ paths. */
35         private final String pathPrefix;
36
37         /**
38          * Creates a new {@link PageToadlet} factory.
39          *
40          * @param highLevelSimpleClient
41          *            The client to use when creating the toadlets
42          * @param pathPrefix
43          *            The path that is prepended to all pages’ paths
44          */
45         public PageToadletFactory(HighLevelSimpleClient highLevelSimpleClient, String pathPrefix) {
46                 this.highLevelSimpleClient = highLevelSimpleClient;
47                 this.pathPrefix = pathPrefix;
48         }
49
50         /**
51          * Creates a {@link PageToadlet} that wraps the given page and does not
52          * appear in the node’s menu.
53          *
54          * @param page
55          *            The page to wrap
56          * @return The toadlet wrapped around the page
57          */
58         public PageToadlet createPageToadlet(Page<FreenetRequest> page) {
59                 return createPageToadlet(page, null);
60         }
61
62         /**
63          * Creates a {@link PageToadlet} that wraps the given page and appears in
64          * the node’s menu under the given name.
65          *
66          * @param page
67          *            The page to wrap
68          * @param menuName
69          *            The name of the menu item
70          * @return The toadlet wrapped around the page
71          */
72         public PageToadlet createPageToadlet(Page<FreenetRequest> page, String menuName) {
73                 return new PageToadlet(highLevelSimpleClient, menuName, page, pathPrefix);
74         }
75
76 }