Use JDK’s Optional instead of Guava’s
[jSite.git] / src / main / java / de / todesbaum / jsite / main / Configuration.java
index 0cc7750..41eafdb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * jSite - Configuration.java - Copyright © 2006–2012 David Roden
+ * jSite - Configuration.java - Copyright © 2006–2014 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
@@ -43,8 +43,8 @@ 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 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) {
@@ -381,7 +384,7 @@ public class Configuration {
                                }
                        }
                }
-               return projects.toArray(new Project[projects.size()]);
+               return projects;
        }
 
        /**
@@ -390,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");
@@ -430,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());
                                }
                        }
@@ -623,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;
-       }
-
 }