[java-metadata-aggregator] 01/02: WIP: URL checking
Ian Young
ian at iay.org.uk
Wed Dec 20 18:07:34 UTC 2023
This is an automated email from the git hooks/post-receive script.
iay pushed a commit to branch dev/MDA-299
in repository java-metadata-aggregator.
View the commit online:
http://git.shibboleth.net/view/?p=java-metadata-aggregator.git;a=commit;h=0b8292b55cf9df88db3091f2fd5c82ed0876de4c
commit 0b8292b55cf9df88db3091f2fd5c82ed0876de4c
Author: Ian Young <ian at iay.org.uk>
AuthorDate: Mon Nov 27 16:38:52 2023 +0000
WIP: URL checking
---
.../validate/string/AsURLStringValidator.java | 55 ++++++++++++++++++++++
.../validate/string/AsURLStringValidatorTest.java | 17 +++++++
2 files changed, 72 insertions(+)
diff --git a/mda-framework/src/main/java/net/shibboleth/metadata/validate/string/AsURLStringValidator.java b/mda-framework/src/main/java/net/shibboleth/metadata/validate/string/AsURLStringValidator.java
new file mode 100644
index 0000000..14d1a31
--- /dev/null
+++ b/mda-framework/src/main/java/net/shibboleth/metadata/validate/string/AsURLStringValidator.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.metadata.validate.string;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.annotation.Nonnull;
+
+import net.shibboleth.metadata.validate.BaseAsValidator;
+import net.shibboleth.metadata.validate.Validator;
+
+/**
+ * A <code>Validator</code> that checks {@link String} values as URLs by converting the
+ * value to an {@link URL} and applying a sequence of validators to that value.
+ *
+ * <p>
+ * This validator fails (and returns {@link net.shibboleth.metadata.validate.Validator.Action#DONE}) if the
+ * value can not be converted to a {@link URL}.
+ * </p>
+ *
+ * <p>
+ * Otherwise, the validator applies the sequence of validators to the {@link URL} and returns
+ * the value of that sequence.
+ * </p>
+ *
+ * @since 0.10.0
+ */
+public class AsURLStringValidator extends BaseAsValidator<String, URL>
+ implements Validator<String> {
+
+ @Override
+ protected @Nonnull URL convert(@Nonnull final String value) throws IllegalArgumentException {
+ try {
+ final var result = new URL(value);
+ assert result != null;
+ return result;
+ } catch (final MalformedURLException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+}
diff --git a/mda-framework/src/test/java/net/shibboleth/metadata/validate/string/AsURLStringValidatorTest.java b/mda-framework/src/test/java/net/shibboleth/metadata/validate/string/AsURLStringValidatorTest.java
new file mode 100644
index 0000000..7f37329
--- /dev/null
+++ b/mda-framework/src/test/java/net/shibboleth/metadata/validate/string/AsURLStringValidatorTest.java
@@ -0,0 +1,17 @@
+package net.shibboleth.metadata.validate.string;
+
+import java.net.URL;
+
+import org.testng.annotations.Test;
+
+public class AsURLStringValidatorTest {
+
+ //@Test
+ public void f() throws Exception {
+ var v = new URL("http://wibble wobble");
+ System.out.println(v);
+ var v2 = new URL("data:asdadasd");
+ System.out.println(v2);
+ }
+
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list