/*
- * jSite - FileOption.java - Copyright © 2006–2012 David Roden
+ * jSite - FileOption.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 the Free Software
package de.todesbaum.jsite.application;
+import static java.util.Optional.empty;
+
+import java.util.Optional;
+
/**
* Container for various file options.
*
/** 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;
private String customKey;
/** The changed name. */
- private String changedName;
+ private Optional<String> changedName = empty();
/** The default MIME type. */
private final String defaultMimeType;
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
}
/**
- * 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<String> getChangedName() {
return changedName;
}
* The new changed name for this file
*/
public void setChangedName(String changedName) {
- this.changedName = changedName;
+ this.changedName = ((changedName != null) && (changedName.length() > 0)) ? Optional.of(changedName) : Optional.<String>empty();
}
/**
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)) {