Update year in copyright lines
[Sone.git] / src / main / java / net / pterodactylus / sone / web / page / PageToadletFactory.java
1 /*
2  * Sone - PageToadletFactory.java - Copyright © 2010–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.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 public class PageToadletFactory {
28
29         /** The client to use when creating the toadlets. */
30         private final HighLevelSimpleClient highLevelSimpleClient;
31
32         /** The prefix for all pages’ paths. */
33         private final String pathPrefix;
34
35         /**
36          * Creates a new {@link PageToadlet} factory.
37          *
38          * @param highLevelSimpleClient
39          *            The client to use when creating the toadlets
40          * @param pathPrefix
41          *            The path that is prepended to all pages’ paths
42          */
43         public PageToadletFactory(HighLevelSimpleClient highLevelSimpleClient, String pathPrefix) {
44                 this.highLevelSimpleClient = highLevelSimpleClient;
45                 this.pathPrefix = pathPrefix;
46         }
47
48         /**
49          * Creates a {@link PageToadlet} that wraps the given page and does not
50          * appear in the node’s menu.
51          *
52          * @param page
53          *            The page to wrap
54          * @return The toadlet wrapped around the page
55          */
56         public PageToadlet createPageToadlet(Page<FreenetRequest> page) {
57                 return createPageToadlet(page, null);
58         }
59
60         /**
61          * Creates a {@link PageToadlet} that wraps the given page and appears in
62          * the node’s menu under the given name.
63          *
64          * @param page
65          *            The page to wrap
66          * @param menuName
67          *            The name of the menu item
68          * @return The toadlet wrapped around the page
69          */
70         public PageToadlet createPageToadlet(Page<FreenetRequest> page, String menuName) {
71                 return new PageToadlet(highLevelSimpleClient, menuName, page, pathPrefix);
72         }
73
74 }