From ae8391ccb82eb7412b3e74af4ef30f4944f4db58 Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Sat, 23 Jul 2022 10:40:47 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20Pa?= =?UTF-8?q?rser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- haiti-bom/pom.xml | 4 +- haiti-context/pom.xml | 2 +- haiti-core/pom.xml | 2 +- haiti-exception/pom.xml | 2 +- haiti-filter/pom.xml | 2 +- haiti-utils/pom.xml | 2 +- .../dev/struchkov/haiti/utils/Parser.java | 38 ++++++++++++++++++ .../haiti/utils/domain/CompositeUrl.java | 39 +++++++++++++++++++ haiti-utils/src/main/java/module-info.java | 1 + pom.xml | 4 +- 10 files changed, 87 insertions(+), 9 deletions(-) create mode 100644 haiti-utils/src/main/java/dev/struchkov/haiti/utils/Parser.java create mode 100644 haiti-utils/src/main/java/dev/struchkov/haiti/utils/domain/CompositeUrl.java diff --git a/haiti-bom/pom.xml b/haiti-bom/pom.xml index da7c7eb..a7f01c7 100644 --- a/haiti-bom/pom.xml +++ b/haiti-bom/pom.xml @@ -6,7 +6,7 @@ dev.struchkov.haiti haiti-bom - 1.0.3 + 1.1.0 pom Haiti BOM @@ -30,7 +30,7 @@ UTF-8 UTF-8 - 1.0.3 + 1.1.0 ${haiti.ver} ${haiti.ver} diff --git a/haiti-context/pom.xml b/haiti-context/pom.xml index 09b08bf..245aea8 100644 --- a/haiti-context/pom.xml +++ b/haiti-context/pom.xml @@ -6,7 +6,7 @@ dev.struchkov.haiti haiti - 1.0.3 + 1.1.0 haiti-context diff --git a/haiti-core/pom.xml b/haiti-core/pom.xml index 1e2256a..d4ab3c6 100644 --- a/haiti-core/pom.xml +++ b/haiti-core/pom.xml @@ -6,7 +6,7 @@ dev.struchkov.haiti haiti - 1.0.3 + 1.1.0 haiti-core diff --git a/haiti-exception/pom.xml b/haiti-exception/pom.xml index 82aba79..f14d901 100644 --- a/haiti-exception/pom.xml +++ b/haiti-exception/pom.xml @@ -6,7 +6,7 @@ dev.struchkov.haiti haiti - 1.0.3 + 1.1.0 haiti-exception diff --git a/haiti-filter/pom.xml b/haiti-filter/pom.xml index 312922d..78ce92e 100644 --- a/haiti-filter/pom.xml +++ b/haiti-filter/pom.xml @@ -6,7 +6,7 @@ dev.struchkov.haiti haiti - 1.0.3 + 1.1.0 haiti-filter diff --git a/haiti-utils/pom.xml b/haiti-utils/pom.xml index 19b671c..4d707c0 100644 --- a/haiti-utils/pom.xml +++ b/haiti-utils/pom.xml @@ -6,7 +6,7 @@ dev.struchkov.haiti haiti - 1.0.3 + 1.1.0 Haiti Utils diff --git a/haiti-utils/src/main/java/dev/struchkov/haiti/utils/Parser.java b/haiti-utils/src/main/java/dev/struchkov/haiti/utils/Parser.java new file mode 100644 index 0000000..09922f2 --- /dev/null +++ b/haiti-utils/src/main/java/dev/struchkov/haiti/utils/Parser.java @@ -0,0 +1,38 @@ +package dev.struchkov.haiti.utils; + +import dev.struchkov.haiti.utils.domain.CompositeUrl; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static dev.struchkov.haiti.utils.Checker.checkNull; +import static dev.struchkov.haiti.utils.Exceptions.utilityClass; + +public final class Parser { + + private static Pattern URL_PARSE; + + private Parser() { + utilityClass(); + } + + public static CompositeUrl url(String url) { + final Matcher matcher = getUrlParse().matcher(url); + + matcher.find(); + + final String protocol = matcher.group(1); + final String domain = matcher.group(2); + final String port = matcher.group(3); + final String path = matcher.group(4); + return CompositeUrl.of(protocol, domain, port, path); + } + + private static Pattern getUrlParse() { + if (checkNull(URL_PARSE)) { + URL_PARSE = Pattern.compile("(https?://)([^:^/]*)(:\\d*)?(.*)?"); + } + return URL_PARSE; + } + +} diff --git a/haiti-utils/src/main/java/dev/struchkov/haiti/utils/domain/CompositeUrl.java b/haiti-utils/src/main/java/dev/struchkov/haiti/utils/domain/CompositeUrl.java new file mode 100644 index 0000000..7b4040b --- /dev/null +++ b/haiti-utils/src/main/java/dev/struchkov/haiti/utils/domain/CompositeUrl.java @@ -0,0 +1,39 @@ +package dev.struchkov.haiti.utils.domain; + +import java.util.Optional; + +public class CompositeUrl { + + private final String protocol; + private final String domain; + private final String port; + private final String path; + + private CompositeUrl(String protocol, String domain, String port, String path) { + this.protocol = protocol; + this.domain = domain; + this.port = port; + this.path = path; + } + + public static CompositeUrl of(String protocol, String domain, String port, String path) { + return new CompositeUrl(protocol, domain, port, path); + } + + public Optional getProtocol() { + return Optional.ofNullable(protocol); + } + + public Optional getDomain() { + return Optional.ofNullable(domain); + } + + public Optional getPort() { + return Optional.ofNullable(port); + } + + public Optional getPath() { + return Optional.ofNullable(path); + } + +} diff --git a/haiti-utils/src/main/java/module-info.java b/haiti-utils/src/main/java/module-info.java index e123653..9df1e59 100644 --- a/haiti-utils/src/main/java/module-info.java +++ b/haiti-utils/src/main/java/module-info.java @@ -1,5 +1,6 @@ module haiti.utils { exports dev.struchkov.haiti.utils; + exports dev.struchkov.haiti.utils.domain; requires haiti.exception; } \ No newline at end of file diff --git a/pom.xml b/pom.xml index 8cb7177..73138a1 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ dev.struchkov.haiti haiti - 1.0.3 + 1.1.0 pom Haiti Framework @@ -39,7 +39,7 @@ UTF-8 UTF-8 - 1.0.3 + 1.1.0 ${haiti.ver} ${haiti.ver}