Allow storing and loading the priority from/to the configuration.
[jSite.git] / src / de / todesbaum / jsite / main / Configuration.java
index 236c8bb..3c65d97 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * jSite - Configuration.java - Copyright © 2006–2011 David Roden
+ * jSite - Configuration.java - Copyright © 2006–2012 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
@@ -39,6 +39,7 @@ 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.PriorityClass;
 import de.todesbaum.util.io.Closer;
 import de.todesbaum.util.io.StreamCopier;
 import de.todesbaum.util.xml.SimpleXML;
@@ -335,8 +336,22 @@ public class Configuration {
                                        } else {
                                                project.setIgnoreHiddenFiles(true);
                                        }
-                                       SimpleXML fileOptionsNode = projectNode.getNode("file-options");
+
+                                       /* load last insert hashes. */
                                        Map<String, FileOption> fileOptions = new HashMap<String, FileOption>();
+                                       SimpleXML lastInsertHashesNode = projectNode.getNode("last-insert-hashes");
+                                       if (lastInsertHashesNode != null) {
+                                               for (SimpleXML fileNode : lastInsertHashesNode.getNodes("file")) {
+                                                       String filename = fileNode.getNode("filename").getValue();
+                                                       String lastInsertHash = fileNode.getNode("last-insert-hash").getValue();
+                                                       int lastInsertEdition = Integer.valueOf(fileNode.getNode("last-insert-edition").getValue());
+                                                       FileOption fileOption = project.getFileOption(filename);
+                                                       fileOption.setLastInsertHash(lastInsertHash).setLastInsertEdition(lastInsertEdition);
+                                                       fileOptions.put(filename, fileOption);
+                                               }
+                                       }
+
+                                       SimpleXML fileOptionsNode = projectNode.getNode("file-options");
                                        if (fileOptionsNode != null) {
                                                SimpleXML[] fileOptionNodes = fileOptionsNode.getNodes("file-option");
                                                for (SimpleXML fileOptionNode : fileOptionNodes) {
@@ -351,11 +366,6 @@ public class Configuration {
                                                                fileOption.setChangedName(fileOptionNode.getNode("changed-name").getValue());
                                                        }
                                                        fileOption.setMimeType(fileOptionNode.getNode("mime-type").getValue(""));
-                                                       fileOption.setContainer(fileOptionNode.getNode("container").getValue());
-                                                       if (fileOptionNode.getNode("replace-edition") != null) {
-                                                               fileOption.setReplaceEdition(Boolean.parseBoolean(fileOptionNode.getNode("replace-edition").getValue()));
-                                                               fileOption.setEditionRange(Integer.parseInt(fileOptionNode.getNode("edition-range").getValue()));
-                                                       }
                                                        fileOptions.put(filename, fileOption);
                                                }
                                        }
@@ -388,6 +398,19 @@ public class Configuration {
                        projectNode.append("insert-uri", project.getInsertURI());
                        projectNode.append("request-uri", project.getRequestURI());
                        projectNode.append("ignore-hidden-files", String.valueOf(project.isIgnoreHiddenFiles()));
+
+                       /* store last insert hashes. */
+                       SimpleXML lastInsertHashesNode = projectNode.append("last-insert-hashes");
+                       for (Entry<String, FileOption> fileOption : project.getFileOptions().entrySet()) {
+                               if ((fileOption.getValue().getLastInsertHash() == null) || (fileOption.getValue().getLastInsertHash().length() == 0)) {
+                                       continue;
+                               }
+                               SimpleXML fileNode = lastInsertHashesNode.append("file");
+                               fileNode.append("filename", fileOption.getKey());
+                               fileNode.append("last-insert-hash", fileOption.getValue().getLastInsertHash());
+                               fileNode.append("last-insert-edition", String.valueOf(fileOption.getValue().getLastInsertEdition()));
+                       }
+
                        SimpleXML fileOptionsNode = projectNode.append("file-options");
                        Iterator<Entry<String, FileOption>> entries = project.getFileOptions().entrySet().iterator();
                        while (entries.hasNext()) {
@@ -401,9 +424,6 @@ public class Configuration {
                                        fileOptionNode.append("custom-key", fileOption.getCustomKey());
                                        fileOptionNode.append("changed-name", fileOption.getChangedName());
                                        fileOptionNode.append("mime-type", fileOption.getMimeType());
-                                       fileOptionNode.append("container", fileOption.getContainer());
-                                       fileOptionNode.append("replace-edition", String.valueOf(fileOption.getReplaceEdition()));
-                                       fileOptionNode.append("edition-range", String.valueOf(fileOption.getEditionRange()));
                                }
                        }
                }
@@ -551,4 +571,48 @@ public class Configuration {
                }
        }
 
+       /**
+        * Returns whether to use the “early encode“ flag for the insert.
+        *
+        * @return {@code true} to set the “early encode” flag for the insert,
+        *         {@code false} otherwise
+        */
+       public boolean useEarlyEncode() {
+               return getNodeBooleanValue(new String[] { "use-early-encode" }, false);
+       }
+
+       /**
+        * Sets whether to use the “early encode“ flag for the insert.
+        *
+        * @param useEarlyEncode
+        *            {@code true} to set the “early encode” flag for the insert,
+        *            {@code false} otherwise
+        * @return This configuration
+        */
+       public Configuration setUseEarlyEncode(boolean useEarlyEncode) {
+               rootNode.replace("use-early-encode", String.valueOf(useEarlyEncode));
+               return this;
+       }
+
+       /**
+        * Returns the insert priority.
+        *
+        * @return The insert priority
+        */
+       public PriorityClass getPriority() {
+               return PriorityClass.valueOf(getNodeValue(new String[] { "insert-priority" }, "interactive"));
+       }
+
+       /**
+        * Sets the insert priority.
+        *
+        * @param priority
+        *            The insert priority
+        * @return This configuration
+        */
+       public Configuration setPriority(PriorityClass priority) {
+               rootNode.replace("insert-priority", priority.toString());
+               return this;
+       }
+
 }