2 * Sone - PageToadletFactory.java - Copyright © 2010–2015 David Roden
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.
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.
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/>.
18 package net.pterodactylus.sone.web.page;
20 import net.pterodactylus.util.web.Page;
21 import freenet.client.HighLevelSimpleClient;
24 * Factory that creates {@link PageToadlet}s using a given
25 * {@link HighLevelSimpleClient}.
27 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
29 public class PageToadletFactory {
31 /** The client to use when creating the toadlets. */
32 private final HighLevelSimpleClient highLevelSimpleClient;
34 /** The prefix for all pages’ paths. */
35 private final String pathPrefix;
38 * Creates a new {@link PageToadlet} factory.
40 * @param highLevelSimpleClient
41 * The client to use when creating the toadlets
43 * The path that is prepended to all pages’ paths
45 public PageToadletFactory(HighLevelSimpleClient highLevelSimpleClient, String pathPrefix) {
46 this.highLevelSimpleClient = highLevelSimpleClient;
47 this.pathPrefix = pathPrefix;
51 * Creates a {@link PageToadlet} that wraps the given page and does not
52 * appear in the node’s menu.
56 * @return The toadlet wrapped around the page
58 public PageToadlet createPageToadlet(Page<FreenetRequest> page) {
59 return createPageToadlet(page, null);
63 * Creates a {@link PageToadlet} that wraps the given page and appears in
64 * the node’s menu under the given name.
69 * The name of the menu item
70 * @return The toadlet wrapped around the page
72 public PageToadlet createPageToadlet(Page<FreenetRequest> page, String menuName) {
73 return new PageToadlet(highLevelSimpleClient, menuName, page, pathPrefix);