2 * DemosceneMusic - AdminBasePage.java - Copyright © 2012 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.demoscenemusic.page.admin;
20 import java.util.ArrayList;
21 import java.util.List;
22 import java.util.Map.Entry;
24 import net.pterodactylus.demoscenemusic.core.Core;
25 import net.pterodactylus.demoscenemusic.data.Base;
26 import net.pterodactylus.demoscenemusic.data.User;
27 import net.pterodactylus.demoscenemusic.page.BasePage;
28 import net.pterodactylus.demoscenemusic.page.ServletRequest;
29 import net.pterodactylus.util.template.Template;
30 import net.pterodactylus.util.template.TemplateContextFactory;
33 * Base page for all admin pages.
35 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
37 public class AdminBasePage extends BasePage {
40 * Creates a new admin page.
44 * @param templateContextFactory
45 * The template context factory
47 * The template to render
49 * The name of the page
51 public AdminBasePage(Core core, TemplateContextFactory templateContextFactory, Template template, String pageName) {
52 super(core, templateContextFactory, template, pageName);
60 * Processes properties from the given requests and adjusts the properties
61 * of the given object.
64 * The request to process
66 * The object whose properties to modify
68 protected void processProperties(ServletRequest request, Base object) {
69 /* check if properties were changed. */
70 List<String> propertiesToDelete = new ArrayList<String>();
71 for (Entry<String, String> property : object.getProperties()) {
72 if (request.getServletRequest().getParameter("delete." + property.getKey()) != null) {
73 propertiesToDelete.add(property.getKey());
76 String value = request.getServletRequest().getParameter("value." + property.getKey());
80 object.getProperties().set(property.getKey(), value);
83 /* check if properties are deleted. */
84 if (!propertiesToDelete.isEmpty()) {
85 for (String propertyToDelete : propertiesToDelete) {
86 object.getProperties().remove(propertyToDelete);
90 /* check for a new property. */
91 if ("true".equals(request.getServletRequest().getParameter("new-property"))) {
92 String property = request.getServletRequest().getParameter("property").trim();
93 String value = request.getServletRequest().getParameter("value").trim();
94 if ((property.length() > 0) && (value.length() > 0)) {
95 object.getProperties().set(property, value);
108 protected int getRequiredUserLevel() {
109 return User.LEVEL_GOD;