mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-07-26 10:03:17 +00:00
mount name now included in servlet path
This commit is contained in:
@@ -14,8 +14,6 @@ import java.nio.file.FileSystem;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.Normalizer;
|
||||
import java.text.Normalizer.Form;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
@@ -63,11 +61,6 @@ public class Vault {
|
||||
this.vaultSettings = vaultSettings;
|
||||
this.server = server;
|
||||
this.closer = closer;
|
||||
try {
|
||||
setMountName(name().getValue());
|
||||
} catch (IllegalArgumentException e) {
|
||||
// mount name needs to be set by the user explicitly later
|
||||
}
|
||||
}
|
||||
|
||||
// ******************************************************************************
|
||||
@@ -102,7 +95,7 @@ public class Vault {
|
||||
if (!server.isRunning()) {
|
||||
server.start();
|
||||
}
|
||||
server.startWebDavServlet(fs.getPath("/"), vaultSettings.getId());
|
||||
server.startWebDavServlet(fs.getPath("/"), vaultSettings.getId() + "/" + vaultSettings.getMountName());
|
||||
} catch (IOException e) {
|
||||
LOG.error("Unable to provide frontend", e);
|
||||
} finally {
|
||||
@@ -215,32 +208,6 @@ public class Vault {
|
||||
return 0l;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to form a similar string using the regular latin alphabet.
|
||||
*
|
||||
* @param string
|
||||
* @return a string composed of a-z, A-Z, 0-9, and _.
|
||||
*/
|
||||
public static String normalize(String string) {
|
||||
String normalized = Normalizer.normalize(string, Form.NFD);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < normalized.length(); i++) {
|
||||
char c = normalized.charAt(i);
|
||||
if (Character.isWhitespace(c)) {
|
||||
if (builder.length() == 0 || builder.charAt(builder.length() - 1) != '_') {
|
||||
builder.append('_');
|
||||
}
|
||||
} else if (c < 127 && Character.isLetterOrDigit(c)) {
|
||||
builder.append(c);
|
||||
} else if (c < 127) {
|
||||
if (builder.length() == 0 || builder.charAt(builder.length() - 1) != '_') {
|
||||
builder.append('_');
|
||||
}
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public String getMountName() {
|
||||
return vaultSettings.getMountName();
|
||||
}
|
||||
@@ -252,11 +219,10 @@ public class Vault {
|
||||
* @throws IllegalArgumentException if the name is empty after normalization
|
||||
*/
|
||||
public void setMountName(String mountName) throws IllegalArgumentException {
|
||||
String normalized = normalize(mountName);
|
||||
if (StringUtils.isEmpty(normalized)) {
|
||||
if (StringUtils.isBlank(mountName)) {
|
||||
throw new IllegalArgumentException("mount name is empty");
|
||||
} else {
|
||||
vaultSettings.setMountName(normalized);
|
||||
vaultSettings.setMountName(mountName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ import java.util.Base64;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.google.gson.annotations.JsonAdapter;
|
||||
|
||||
import javafx.beans.property.Property;
|
||||
@@ -46,6 +48,28 @@ public class VaultSettings {
|
||||
return uuidBuffer.array();
|
||||
}
|
||||
|
||||
/*
|
||||
* visible for testing
|
||||
*/
|
||||
static String normalizeMountName(String mountName) {
|
||||
String normalizedMountName = StringUtils.stripAccents(mountName);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (char c : normalizedMountName.toCharArray()) {
|
||||
if (Character.isWhitespace(c)) {
|
||||
if (builder.length() == 0 || builder.charAt(builder.length() - 1) != '_') {
|
||||
builder.append('_');
|
||||
}
|
||||
} else if (c < 127 && Character.isLetterOrDigit(c)) {
|
||||
builder.append(c);
|
||||
} else {
|
||||
if (builder.length() == 0 || builder.charAt(builder.length() - 1) != '_') {
|
||||
builder.append('_');
|
||||
}
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/* Getter/Setter */
|
||||
|
||||
public String getId() {
|
||||
@@ -62,6 +86,9 @@ public class VaultSettings {
|
||||
|
||||
public void setPath(Path path) {
|
||||
this.path.setValue(path);
|
||||
if (StringUtils.isBlank(getMountName())) {
|
||||
setMountName(path.getFileName().toString());
|
||||
}
|
||||
}
|
||||
|
||||
public Property<String> mountNameProperty() {
|
||||
@@ -73,7 +100,7 @@ public class VaultSettings {
|
||||
}
|
||||
|
||||
public void setMountName(String mountName) {
|
||||
this.mountName.setValue(mountName);
|
||||
this.mountName.setValue(normalizeMountName(mountName));
|
||||
}
|
||||
|
||||
public Property<String> winDriveLetterProperty() {
|
||||
|
||||
@@ -55,8 +55,8 @@ class VaultSettingsJsonAdapter extends TypeAdapter<VaultSettings> {
|
||||
in.endObject();
|
||||
|
||||
VaultSettings settings = (id == null) ? VaultSettings.withRandomId() : new VaultSettings(id);
|
||||
settings.setPath(Paths.get(path));
|
||||
settings.setMountName(mountName);
|
||||
settings.setPath(Paths.get(path));
|
||||
settings.setWinDriveLetter(winDriveLetter);
|
||||
return settings;
|
||||
}
|
||||
|
||||
+7
-7
@@ -6,21 +6,21 @@
|
||||
* Contributors:
|
||||
* Sebastian Stenzel - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.cryptomator.ui.model;
|
||||
package org.cryptomator.ui.settings;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class VaultTest {
|
||||
public class VaultSettingsTest {
|
||||
|
||||
@Test
|
||||
public void testNormalize() throws Exception {
|
||||
assertEquals("_", Vault.normalize(" "));
|
||||
assertEquals("a", Vault.normalize("ä"));
|
||||
assertEquals("C", Vault.normalize("Ĉ"));
|
||||
assertEquals("_", Vault.normalize(":"));
|
||||
assertEquals("", Vault.normalize("汉语"));
|
||||
assertEquals("_", VaultSettings.normalizeMountName(" "));
|
||||
assertEquals("a", VaultSettings.normalizeMountName("ä"));
|
||||
assertEquals("C", VaultSettings.normalizeMountName("Ĉ"));
|
||||
assertEquals("_", VaultSettings.normalizeMountName(":"));
|
||||
assertEquals("_", VaultSettings.normalizeMountName("汉语"));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user