package net.pterodactylus.demoscenemusic.page.admin;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map.Entry;
+
import net.pterodactylus.demoscenemusic.core.Core;
+import net.pterodactylus.demoscenemusic.data.Base;
import net.pterodactylus.demoscenemusic.data.User;
import net.pterodactylus.demoscenemusic.page.BasePage;
+import net.pterodactylus.demoscenemusic.page.ServletRequest;
import net.pterodactylus.util.template.Template;
import net.pterodactylus.util.template.TemplateContextFactory;
}
//
+ // PROTECTED METHODS
+ //
+
+ /**
+ * Processes properties from the given requests and adjusts the properties
+ * of the given object.
+ *
+ * @param request
+ * The request to process
+ * @param object
+ * The object whose properties to modify
+ */
+ protected void processProperties(ServletRequest request, Base object) {
+ /* check if properties were changed. */
+ List<String> propertiesToDelete = new ArrayList<String>();
+ for (Entry<String, String> property : object.getProperties()) {
+ if (request.getServletRequest().getParameter("delete." + property.getKey()) != null) {
+ propertiesToDelete.add(property.getKey());
+ continue;
+ }
+ String value = request.getServletRequest().getParameter("value." + property.getKey()).trim();
+ object.getProperties().set(property.getKey(), value);
+ }
+
+ /* check if properties are deleted. */
+ if (!propertiesToDelete.isEmpty()) {
+ for (String propertyToDelete : propertiesToDelete) {
+ object.getProperties().remove(propertyToDelete);
+ }
+ }
+
+ /* check for a new property. */
+ if ("true".equals(request.getServletRequest().getParameter("new-property"))) {
+ String property = request.getServletRequest().getParameter("property").trim();
+ String value = request.getServletRequest().getParameter("value").trim();
+ if ((property.length() > 0) && (value.length() > 0)) {
+ object.getProperties().set(property, value);
+ }
+ }
+ }
+
+ //
// BASEPAGE METHODS
//