From 180428fbb7c7c1b78034e5046cdf3b74f3c497e4 Mon Sep 17 00:00:00 2001 From: r-ca Date: Sat, 13 Jan 2024 15:07:11 +0900 Subject: [PATCH 1/4] =?UTF-8?q?=E5=AE=9F=E8=A3=85=20WIP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../one/nem/lacerta/model/PublicPath.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 model/src/main/java/one/nem/lacerta/model/PublicPath.java diff --git a/model/src/main/java/one/nem/lacerta/model/PublicPath.java b/model/src/main/java/one/nem/lacerta/model/PublicPath.java new file mode 100644 index 00000000..8ca9e9ff --- /dev/null +++ b/model/src/main/java/one/nem/lacerta/model/PublicPath.java @@ -0,0 +1,23 @@ +package one.nem.lacerta.model; + +public class PublicPath { + /* + * ユーザーが扱うパス(内部パスの代替) + */ + + String[] path; + + public PublicPath() { + this.path = new String[0]; + } + + public PublicPath load(String[] path) { + this.path = path; + return this; + } + + public PublicPath load(String path) { + this.path = path.split("/"); + return this; + } +} From 04651f3b8edc43b7c88cfb603e55fbe5444403a5 Mon Sep 17 00:00:00 2001 From: r-ca Date: Sat, 13 Jan 2024 15:12:03 +0900 Subject: [PATCH 2/4] =?UTF-8?q?=E5=AE=9F=E8=A3=85=20WIP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../one/nem/lacerta/model/PublicPath.java | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/model/src/main/java/one/nem/lacerta/model/PublicPath.java b/model/src/main/java/one/nem/lacerta/model/PublicPath.java index 8ca9e9ff..3181d00e 100644 --- a/model/src/main/java/one/nem/lacerta/model/PublicPath.java +++ b/model/src/main/java/one/nem/lacerta/model/PublicPath.java @@ -1,23 +1,47 @@ package one.nem.lacerta.model; +import java.util.ArrayList; +import java.util.List; + public class PublicPath { /* * ユーザーが扱うパス(内部パスの代替) */ - String[] path; + List path = new ArrayList(); public PublicPath() { - this.path = new String[0]; } - public PublicPath load(String[] path) { + public PublicPath(List path) { this.path = path; + } + + private void add(String path) { + this.path.add(path); + } + + public PublicPath resolve(String path) { + if (path.equals("..")) { + this.path.remove(this.path.size() - 1); + } else { + add(path); + } return this; } - public PublicPath load(String path) { - this.path = path.split("/"); + public PublicPath resolve(List path) { + for (String p : path) { + resolve(p); + } return this; } + + public List getPath() { + return path; + } + + public String getStringPath() { + return String.join("/", path); + } } From 171c8b380c4989110b784fa30fe355250cda5686 Mon Sep 17 00:00:00 2001 From: r-ca Date: Sat, 13 Jan 2024 15:13:56 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=E5=8A=B9=E7=8E=87=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/src/main/java/one/nem/lacerta/model/PublicPath.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/model/src/main/java/one/nem/lacerta/model/PublicPath.java b/model/src/main/java/one/nem/lacerta/model/PublicPath.java index 3181d00e..0da4ce3f 100644 --- a/model/src/main/java/one/nem/lacerta/model/PublicPath.java +++ b/model/src/main/java/one/nem/lacerta/model/PublicPath.java @@ -21,18 +21,22 @@ public class PublicPath { this.path.add(path); } - public PublicPath resolve(String path) { + private void resolveInternal(String path) { if (path.equals("..")) { this.path.remove(this.path.size() - 1); } else { add(path); } + } + + public PublicPath resolve(String path) { + resolveInternal(path); return this; } public PublicPath resolve(List path) { for (String p : path) { - resolve(p); + resolveInternal(p); } return this; } From 002c78d09ba11f9c7623576dd080f74e5d6fb2eb Mon Sep 17 00:00:00 2001 From: r-ca Date: Sat, 13 Jan 2024 15:17:48 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/one/nem/lacerta/model/PublicPath.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/model/src/main/java/one/nem/lacerta/model/PublicPath.java b/model/src/main/java/one/nem/lacerta/model/PublicPath.java index 0da4ce3f..980a3a9d 100644 --- a/model/src/main/java/one/nem/lacerta/model/PublicPath.java +++ b/model/src/main/java/one/nem/lacerta/model/PublicPath.java @@ -6,6 +6,11 @@ import java.util.List; public class PublicPath { /* * ユーザーが扱うパス(内部パスの代替) + * (時間がないのでInjectされることは考慮しない) + * + * TODO-rca: + * - こわれたパスを検知する + * - バリデーション */ List path = new ArrayList(); @@ -41,6 +46,18 @@ public class PublicPath { return this; } + public PublicPath resolve(PublicPath path) { + for (String p : path.getPath()) { + resolveInternal(p); + } + return this; + } + + public PublicPath parent() { + this.path.remove(this.path.size() - 1); + return this; + } + public List getPath() { return path; }