📄 Update year in copyright line
[jSite.git] / src / main / java / de / todesbaum / jsite / main / Configuration.java
index 12eb398..3d6546c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * jSite - Configuration.java - Copyright Â© 2006–2012 David Roden
+ * jSite - Configuration.java - Copyright Â© 2006–2019 David Roden
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -35,16 +35,16 @@ import java.util.Map.Entry;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import net.pterodactylus.util.io.Closer;
+import net.pterodactylus.util.io.StreamCopier;
 import net.pterodactylus.util.xml.SimpleXML;
 import net.pterodactylus.util.xml.XML;
 import de.todesbaum.jsite.application.FileOption;
 import de.todesbaum.jsite.application.Node;
 import de.todesbaum.jsite.application.Project;
 import de.todesbaum.jsite.main.ConfigurationLocator.ConfigurationLocation;
-import de.todesbaum.util.freenet.fcp2.ClientPutDir.ManifestPutter;
 import de.todesbaum.util.freenet.fcp2.PriorityClass;
-import de.todesbaum.util.io.Closer;
-import de.todesbaum.util.io.StreamCopier;
+import org.w3c.dom.Document;
 
 /**
  * The configuration.
@@ -129,7 +129,10 @@ public class Configuration {
                                        StreamCopier.copy(fileInputStream, fileByteOutputStream, configurationFile.length());
                                        fileByteOutputStream.close();
                                        byte[] fileBytes = fileByteOutputStream.toByteArray();
-                                       rootNode = SimpleXML.fromDocument(XML.transformToDocument(fileBytes));
+                                       Document document = XML.transformToDocument(fileBytes);
+                                       if (document != null) {
+                                               rootNode = SimpleXML.fromDocument(document);
+                                       }
                                        return;
                                } catch (FileNotFoundException e) {
                                        /* ignore. */
@@ -307,7 +310,7 @@ public class Configuration {
         *
         * @return A list of all projects
         */
-       public Project[] getProjects() {
+       public List<Project> getProjects() {
                List<Project> projects = new ArrayList<Project>();
                SimpleXML projectsNode = rootNode.getNode("project-list");
                if (projectsNode != null) {
@@ -337,6 +340,7 @@ public class Configuration {
                                        } else {
                                                project.setIgnoreHiddenFiles(true);
                                        }
+                                       project.setAlwaysForceInsert(Boolean.parseBoolean(projectNode.getValue("always-force-insert", "false")));
 
                                        /* load last insert hashes. */
                                        Map<String, FileOption> fileOptions = new HashMap<String, FileOption>();
@@ -380,7 +384,7 @@ public class Configuration {
                                }
                        }
                }
-               return projects.toArray(new Project[projects.size()]);
+               return projects;
        }
 
        /**
@@ -389,7 +393,7 @@ public class Configuration {
         * @param projects
         *            The list of all projects
         */
-       public void setProjects(Project[] projects) {
+       public void setProjects(List<Project> projects) {
                SimpleXML projectsNode = new SimpleXML("project-list");
                for (Project project : projects) {
                        SimpleXML projectNode = projectsNode.append("project");
@@ -403,6 +407,7 @@ public class Configuration {
                        projectNode.append("insert-uri", project.getInsertURI());
                        projectNode.append("request-uri", project.getRequestURI());
                        projectNode.append("ignore-hidden-files", String.valueOf(project.isIgnoreHiddenFiles()));
+                       projectNode.append("always-force-insert", String.valueOf(project.isAlwaysForceInsert()));
 
                        /* store last insert hashes. */
                        SimpleXML lastInsertHashesNode = projectNode.append("last-insert-hashes");
@@ -428,7 +433,7 @@ public class Configuration {
                                        fileOptionNode.append("insert", String.valueOf(fileOption.isInsert()));
                                        fileOptionNode.append("insert-redirect", String.valueOf(fileOption.isInsertRedirect()));
                                        fileOptionNode.append("custom-key", fileOption.getCustomKey());
-                                       fileOptionNode.append("changed-name", fileOption.getChangedName());
+                                       fileOptionNode.append("changed-name", fileOption.getChangedName().orElse(null));
                                        fileOptionNode.append("mime-type", fileOption.getMimeType());
                                }
                        }
@@ -621,25 +626,4 @@ public class Configuration {
                return this;
        }
 
-       /**
-        * Returns the manifest putter.
-        *
-        * @return The manifest putter
-        */
-       public ManifestPutter getManifestPutter() {
-               return ManifestPutter.valueOf(getNodeValue(new String[] { "manifest-putter" }, "simple").toUpperCase());
-       }
-
-       /**
-        * Sets the manifest putter.
-        *
-        * @param manifestPutter
-        *            The manifest putter
-        * @return This configuration
-        */
-       public Configuration setManifestPutter(ManifestPutter manifestPutter) {
-               rootNode.replace("manifest-putter", manifestPutter.name().toLowerCase());
-               return this;
-       }
-
 }