X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Ftodesbaum%2Fjsite%2Fapplication%2FFileOption.java;h=66efc090020e098e8c12d4c5e972fd7375b51f28;hb=766fdc1d45345d067065e2ff268b707608ad276f;hp=c8824de1b90861caeac9a71ec8ee8e02e3309984;hpb=38bdc433e50669e8244a63b5af59e597f88f1d29;p=jSite.git diff --git a/src/main/java/de/todesbaum/jsite/application/FileOption.java b/src/main/java/de/todesbaum/jsite/application/FileOption.java index c8824de..66efc09 100644 --- a/src/main/java/de/todesbaum/jsite/application/FileOption.java +++ b/src/main/java/de/todesbaum/jsite/application/FileOption.java @@ -1,5 +1,5 @@ /* - * jSite - FileOption.java - Copyright © 2006–2012 David Roden + * jSite - FileOption.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 @@ -18,6 +18,11 @@ package de.todesbaum.jsite.application; +import static com.google.common.base.Optional.absent; +import static com.google.common.base.Optional.of; + +import com.google.common.base.Optional; + /** * Container for various file options. * @@ -34,9 +39,6 @@ public class FileOption { /** The default for the custom key. */ private static final String DEFAULT_CUSTOM_KEY = "CHK@"; - /** The default changed name. */ - private static final String DEFAULT_CHANGED_NAME = null; - /** The insert state. */ private boolean insert; @@ -62,7 +64,7 @@ public class FileOption { private String customKey; /** The changed name. */ - private String changedName; + private Optional changedName = absent(); /** The default MIME type. */ private final String defaultMimeType; @@ -80,11 +82,24 @@ public class FileOption { insert = DEFAULT_INSERT; insertRedirect = DEFAULT_INSERT_REDIRECT; customKey = DEFAULT_CUSTOM_KEY; - changedName = DEFAULT_CHANGED_NAME; this.defaultMimeType = defaultMimeType; mimeType = defaultMimeType; } + public FileOption(FileOption other) { + this.insert = other.insert; + this.forceInsert = other.forceInsert; + this.insertRedirect = other.insertRedirect; + this.lastInsertHash = other.lastInsertHash; + this.lastInsertEdition = other.lastInsertEdition; + this.lastInsertFilename = other.lastInsertFilename; + this.currentHash = other.currentHash; + this.customKey = other.customKey; + this.changedName = other.changedName; + this.defaultMimeType = other.defaultMimeType; + this.mimeType = other.mimeType; + } + /** * Returns the custom key. The custom key is only used when * {@link #isInsert()} and {@link #isInsertRedirect()} both return {@code @@ -278,24 +293,13 @@ public class FileOption { } /** - * Returns whether this file has a changed name. Use - * {@link #getChangedName()} is this method returns {@code true}. - * - * @return {@code true} if this file has a changed name, {@code false} - * otherwise - */ - public boolean hasChangedName() { - return (changedName != null) && (changedName.length() > 0); - } - - /** * Returns the changed name for this file. This method will return {@code * null} or an empty {@link String} if this file should not be renamed. * * @return The changed name, or {@code null} if this file should not be * renamed */ - public String getChangedName() { + public Optional getChangedName() { return changedName; } @@ -307,7 +311,7 @@ public class FileOption { * The new changed name for this file */ public void setChangedName(String changedName) { - this.changedName = changedName; + this.changedName = ((changedName != null) && (changedName.length() > 0)) ? of(changedName) : Optional.absent(); } /** @@ -349,7 +353,7 @@ public class FileOption { if (!customKey.equals(DEFAULT_CUSTOM_KEY)) { return true; } - if (((changedName != null) && !changedName.equals(DEFAULT_CHANGED_NAME)) || ((DEFAULT_CHANGED_NAME != null) && !DEFAULT_CHANGED_NAME.equals(changedName))) { + if (changedName.isPresent()) { return true; } if (!defaultMimeType.equals(mimeType)) {