Deep copy all file options when cloning project
[jSite.git] / src / main / java / de / todesbaum / jsite / application / Project.java
index fa0b774..d9146a1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * jSite - Project.java - Copyright © 2006–2012 David Roden
+ * jSite - Project.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 the Free Software
@@ -24,7 +24,7 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.Map.Entry;
 
-import de.todesbaum.util.mime.DefaultMIMETypes;
+import net.pterodactylus.util.io.MimeTypes;
 
 /**
  * Container for project information.
@@ -60,6 +60,9 @@ public class Project implements Comparable<Project> {
        /** The edition to insert to. */
        protected int edition;
 
+       /** Whether to always force inserts. */
+       private boolean alwaysForceInserts;
+
        /** Whether to ignore hidden directory. */
        private boolean ignoreHiddenFiles;
 
@@ -89,8 +92,11 @@ public class Project implements Comparable<Project> {
                localPath = project.localPath;
                indexFile = project.indexFile;
                lastInsertionTime = project.lastInsertionTime;
+               alwaysForceInserts = project.alwaysForceInserts;
                ignoreHiddenFiles = project.ignoreHiddenFiles;
-               fileOptions = new HashMap<String, FileOption>(project.fileOptions);
+               for (Entry<String, FileOption> fileOption : fileOptions.entrySet()) {
+                       fileOptions.put(fileOption.getKey(), new FileOption(fileOption.getValue()));
+               }
        }
 
        /**
@@ -252,6 +258,29 @@ public class Project implements Comparable<Project> {
        }
 
        /**
+        * Returns whether files for this project should always be inserted, even
+        * when unchanged.
+        *
+        * @return {@code true} to always force inserts on this project,
+        *         {@code false} otherwise
+        */
+       public boolean isAlwaysForceInsert() {
+               return alwaysForceInserts;
+       }
+
+       /**
+        * Sets whether files for this project should always be inserted, even when
+        * unchanged.
+        *
+        * @param alwaysForceInsert
+        *            {@code true} to always force inserts on this project,
+        *            {@code false} otherwise
+        */
+       public void setAlwaysForceInsert(boolean alwaysForceInsert) {
+               this.alwaysForceInserts = alwaysForceInsert;
+       }
+
+       /**
         * Returns whether hidden files are ignored, i.e. not inserted.
         *
         * @return {@code true} if hidden files are not inserted, {@code false}
@@ -289,7 +318,7 @@ public class Project implements Comparable<Project> {
         *            The URI to shorten
         * @return The shortened URI
         */
-       private String shortenURI(String uri) {
+       private static String shortenURI(String uri) {
                String shortUri = uri;
                if (shortUri.startsWith("freenet:")) {
                        shortUri = shortUri.substring("freenet:".length());
@@ -337,7 +366,7 @@ public class Project implements Comparable<Project> {
        public FileOption getFileOption(String filename) {
                FileOption fileOption = fileOptions.get(filename);
                if (fileOption == null) {
-                       fileOption = new FileOption(DefaultMIMETypes.guessMIMEType(filename));
+                       fileOption = new FileOption(MimeTypes.getMimeType(filename.substring(filename.lastIndexOf('.') + 1)));
                        fileOptions.put(filename, fileOption);
                }
                return fileOption;
@@ -386,6 +415,7 @@ public class Project implements Comparable<Project> {
         * <p>
         * Projects are compared by their name only.
         */
+       @Override
        public int compareTo(Project project) {
                return name.compareToIgnoreCase(project.name);
        }
@@ -432,7 +462,7 @@ public class Project implements Comparable<Project> {
                        if ((fileOption.getCurrentHash() != null) && (fileOption.getCurrentHash().length() > 0) && (!fileOption.getCurrentHash().equals(fileOption.getLastInsertHash()) || fileOption.isForceInsert())) {
                                fileOption.setLastInsertEdition(edition);
                                fileOption.setLastInsertHash(fileOption.getCurrentHash());
-                               fileOption.setLastInsertFilename(fileOption.hasChangedName() ? fileOption.getChangedName() : fileOptionEntry.getKey());
+                               fileOption.setLastInsertFilename(fileOption.getChangedName().or(fileOptionEntry.getKey()));
                        }
                        fileOption.setForceInsert(false);
                }