Skip to content

Commit d49c04e

Browse files
committed
Refactor format
1 parent 9e781eb commit d49c04e

36 files changed

+44
-110
lines changed

src/main/java/com/networknt/schema/format/AbstractRFC3986Format.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import com.networknt.schema.ExecutionContext;
88

99
/**
10-
* {@link AbstractFormat} for RFC 3986.
10+
* {@link Format} for RFC 3986 Uniform Resource Identifier (URI): Generic Syntax.
1111
*/
1212
public abstract class AbstractRFC3986Format implements Format {
1313
private static final Pattern VALID = Pattern.compile("([A-Za-z0-9+-\\.]*:)?//|[A-Za-z0-9+-\\.]+:");

src/main/java/com/networknt/schema/format/Format.java

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import com.networknt.schema.NodePath;
2626
import com.networknt.schema.SchemaContext;
2727
import com.networknt.schema.TypeFactory;
28-
import com.networknt.schema.MessageSourceError.Builder;
2928
import com.networknt.schema.keyword.FormatValidator;
3029

3130
/**
@@ -47,31 +46,17 @@ public interface Format {
4746
* See jsv-messages.properties.
4847
* <p>
4948
* The following are the arguments.<br>
50-
* {0} The instance location<br>
51-
* {1} The format name<br>
52-
* {2} The error message description<br>
53-
* {3} The input value
49+
* {0} The format name<br>
50+
* {1} The input value
51+
* <p>
52+
* Note that the default localized messages do not use the input value.
5453
*
5554
* @return the message key
5655
*/
5756
default String getMessageKey() {
5857
return "format";
5958
}
6059

61-
/**
62-
* Gets the error message description.
63-
* <p>
64-
* Deprecated. Override getMessageKey() and set the localized message in the
65-
* resource bundle or message source.
66-
*
67-
* @return the error message description.
68-
*/
69-
@Deprecated
70-
default String getErrorMessageDescription() {
71-
return "";
72-
}
73-
74-
7560
/**
7661
* Determines if the value matches the format.
7762
* <p>
@@ -154,7 +139,7 @@ default void validate(ExecutionContext executionContext, SchemaContext schemaCon
154139
if (!matches(executionContext, schemaContext, node, rootNode, instanceLocation, assertionsEnabled,
155140
formatValidator)) {
156141
executionContext.addError(message.get()
157-
.arguments(this.getName(), this.getErrorMessageDescription(), node.asText()).build());
142+
.arguments(this.getName(), node.asText()).build());
158143
}
159144
}
160145
}

src/main/java/com/networknt/schema/format/PatternFormat.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public class PatternFormat implements Format {
2727
private final String name;
2828
private final Pattern pattern;
2929
private final String messageKey;
30-
private final String errorMessageDescription;
3130

3231
/**
3332
* Constructor.
@@ -36,19 +35,9 @@ public class PatternFormat implements Format {
3635
*
3736
* @param name the name
3837
* @param regex the regex
39-
* @param errorMessageDescription the error message description
4038
*/
41-
@Deprecated
42-
public PatternFormat(String name, String regex, String errorMessageDescription) {
39+
private PatternFormat(String name, String regex, String messageKey) {
4340
this.name = name;
44-
this.errorMessageDescription = errorMessageDescription != null ? errorMessageDescription : regex;
45-
this.messageKey = "format";
46-
this.pattern = Pattern.compile(regex);
47-
}
48-
49-
private PatternFormat(String name, String regex, String errorMessageDescription, String messageKey) {
50-
this.name = name;
51-
this.errorMessageDescription = errorMessageDescription != null ? errorMessageDescription : regex;
5241
this.messageKey = messageKey;
5342
this.pattern = Pattern.compile(regex);
5443
}
@@ -62,7 +51,7 @@ private PatternFormat(String name, String regex, String errorMessageDescription,
6251
* @return the pattern format
6352
*/
6453
public static PatternFormat of(String name, String regex, String messageKey) {
65-
return new PatternFormat(name, regex, null, messageKey != null ? messageKey : "format");
54+
return new PatternFormat(name, regex, messageKey != null ? messageKey : "format");
6655
}
6756

6857
@Override
@@ -79,9 +68,4 @@ public String getName() {
7968
public String getMessageKey() {
8069
return this.messageKey;
8170
}
82-
83-
@Override
84-
public String getErrorMessageDescription() {
85-
return this.errorMessageDescription;
86-
}
8771
}

src/main/resources/jsv-messages.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ enum = does not have a value in the enumeration {0}
1414
exclusiveMaximum = must have an exclusive maximum value of {0}
1515
exclusiveMinimum = must have an exclusive minimum value of {0}
1616
false = schema for ''{0}'' is false
17-
format = does not match the {0} pattern {1}
17+
format = does not match the {0} pattern
1818
format.date = does not match the {0} pattern must be a valid RFC 3339 full-date
1919
format.date-time = does not match the {0} pattern must be a valid RFC 3339 date-time
2020
format.duration = does not match the {0} pattern must be a valid ISO 8601 duration

src/main/resources/jsv-messages_ar.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ enum = \u0644\u0627 \u064A\u062D\u062A\u0648\u064A \u0639\u0644\u0649 \u0642\u06
1414
exclusiveMaximum = \u064A\u062C\u0628 \u0623\u0646 \u064A\u0643\u0648\u0646 \u0644\u0647 \u0642\u064A\u0645\u0629 \u0642\u0635\u0648\u0649 \u062D\u0635\u0631\u064A\u0629 \u062A\u0628\u0644\u063A {0}
1515
exclusiveMinimum = \u064A\u062C\u0628 \u0623\u0646 \u064A\u062D\u062A\u0648\u064A \u0639\u0644\u0649 \u0642\u064A\u0645\u0629 \u062F\u0646\u064A\u0627 \u062D\u0635\u0631\u064A\u0629 \u062A\u0628\u0644\u063A {0}
1616
false = \u0645\u062E\u0637\u0637 ''{0}'' \u063A\u064A\u0631 \u0635\u062D\u064A\u062D
17-
format = \u0644\u0627 \u064A\u0637\u0627\u0628\u0642 \u0627\u0644\u0646\u0645\u0637 {0} {1}
17+
format = \u0644\u0627 \u064A\u0637\u0627\u0628\u0642 \u0627\u0644\u0646\u0645\u0637 {0}
1818
format.date = \u0644\u0627 \u064A\u062A\u0637\u0627\u0628\u0642 \u0645\u0639 \u0627\u0644\u0646\u0645\u0637 {0} \u0648\u064A\u062C\u0628 \u0623\u0646 \u064A\u0643\u0648\u0646 \u062A\u0627\u0631\u064A\u062E\u064B\u0627 \u0643\u0627\u0645\u0644\u0627\u064B \u0635\u0627\u0644\u062D\u064B\u0627 \u0644\u0640 RFC 3339
1919
format.date-time = \u0644\u0627 \u064A\u062A\u0637\u0627\u0628\u0642 \u0645\u0639 \u0627\u0644\u0646\u0645\u0637 {0} \u0648\u064A\u062C\u0628 \u0623\u0646 \u064A\u0643\u0648\u0646 \u062A\u0627\u0631\u064A\u062E\u064B\u0627 \u0648\u0648\u0642\u062A\u064B\u0627 \u0635\u0627\u0644\u062D\u064B\u0627 \u0641\u064A RFC 3339
2020
format.duration = \u0644\u0627 \u064A\u062A\u0637\u0627\u0628\u0642 \u0645\u0639 \u0627\u0644\u0646\u0645\u0637 {0} \u0648\u064A\u062C\u0628 \u0623\u0646 \u062A\u0643\u0648\u0646 \u0645\u062F\u0629 ISO 8601 \u0635\u0627\u0644\u062D\u0629

src/main/resources/jsv-messages_cs.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ enum = nem
1414
exclusiveMaximum = musí mít exkluzivní maximální hodnotu {0}
1515
exclusiveMinimum = musí mít exkluzivní minimální hodnotu {0}
1616
false = schéma pro ''{0}'' je nepravdivé
17-
format = neodpovídá vzoru {0} {1}
17+
format = neodpovídá vzoru {0}
1818
format.date = neodpovídá vzoru {0} musí být platné plné datum RFC 3339
1919
format.date-time = neodpovídá vzoru {0} musí být platné datum a \u010Das RFC 3339
2020
format.duration = neodpovídá vzoru {0}, musí mít platnou dobu trvání ISO 8601

src/main/resources/jsv-messages_da.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ enum = har ikke en v
1414
exclusiveMaximum = skal have en eksklusiv maksimumværdi på {0}
1515
exclusiveMinimum = skal have en eksklusiv minimumsværdi på {0}
1616
false = skemaet for ''{0}'' er falsk
17-
format = matcher ikke {0}-mønsteret {1}
17+
format = matcher ikke {0}-mønsteret
1818
format.date = matcher ikke {0}-mønsteret skal være en gyldig RFC 3339 fuld-dato
1919
format.date-time = matcher ikke {0}-mønsteret skal være en gyldig RFC 3339 dato-tid
2020
format.duration = matcher ikke {0}-mønsteret skal være en gyldig ISO 8601-varighed

src/main/resources/jsv-messages_de.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ enum = hat keinen Wert in der Aufz
1414
exclusiveMaximum = muss einen exklusiven Maximalwert von {0} haben
1515
exclusiveMinimum = muss einen exklusiven Mindestwert von {0} haben
1616
false = Schema für ''{0}'' ist falsch
17-
format = entspricht nicht dem Muster {0} {1}
17+
format = entspricht nicht dem Muster {0}
1818
format.date = stimmt nicht mit dem {0}-Muster überein, muss ein gültiges RFC 3339-Volldatum sein
1919
format.date-time = entspricht nicht dem {0}-Muster. Es muss sich um ein gültiges RFC 3339-Datum/Uhrzeit-Format handeln
2020
format.duration = stimmt nicht mit dem {0}-Muster überein, muss eine gültige ISO 8601-Dauer sein

src/main/resources/jsv-messages_es.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ enum = no tiene un valor en la enumeraci\u00f3n {0}
1414
exclusiveMaximum = debe tener un valor m\u00e1ximo exclusivo de {0}
1515
exclusiveMinimum = debe tener un valor m\u00ednimo exclusivo de {0}
1616
false = el esquema para ''{0}'' es falso
17-
format = no coincide con el patr\u00f3n {0} {1}
17+
format = no coincide con el patr\u00f3n {0}
1818
format.date = no coincide con el patr\u00f3n {0}; debe ser un RFC 3339 con fecha completa v\u00e1lido
1919
format.date-time = no coincide con el patr\u00f3n {0}; debe ser un RFC 3339 con fecha y hora v\u00e1lido
2020
format.duration = no coincide con el patr\u00f3n {0}; debe ser un ISO 8601 de duraci\u00f3n v\u00e1lido

src/main/resources/jsv-messages_fa.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ enum = \u0645\u0642\u062F\u0627\u0631\u06CC \u062F\u0631 \u0634\u0645\u0627\u063
1414
exclusiveMaximum = \u0628\u0627\u06CC\u062F \u062D\u062F\u0627\u06A9\u062B\u0631 \u0645\u0642\u062F\u0627\u0631 \u0627\u0646\u062D\u0635\u0627\u0631\u06CC {0} \u062F\u0627\u0634\u062A\u0647 \u0628\u0627\u0634\u062F
1515
exclusiveMinimum = \u0628\u0627\u06CC\u062F \u062D\u062F\u0627\u0642\u0644 \u0645\u0642\u062F\u0627\u0631 \u0627\u0646\u062D\u0635\u0627\u0631\u06CC {0} \u062F\u0627\u0634\u062A\u0647 \u0628\u0627\u0634\u062F
1616
false = \u0637\u0631\u062D\u0648\u0627\u0631\u0647 ''{0}'' \u0646\u0627\u062F\u0631\u0633\u062A \u0627\u0633\u062A
17-
format = \u0628\u0627 \u0627\u0644\u06AF\u0648\u06CC {0} {1} \u0645\u0637\u0627\u0628\u0642\u062A \u0646\u062F\u0627\u0631\u062F
17+
format = \u0628\u0627 \u0627\u0644\u06AF\u0648\u06CC {0} \u0645\u0637\u0627\u0628\u0642\u062A \u0646\u062F\u0627\u0631\u062F
1818
format.date = \u0628\u0627 \u0627\u0644\u06AF\u0648\u06CC {0} \u0645\u0637\u0627\u0628\u0642\u062A \u0646\u062F\u0627\u0631\u062F \u0628\u0627\u06CC\u062F \u062A\u0627\u0631\u06CC\u062E \u06A9\u0627\u0645\u0644 RFC 3339 \u0645\u0639\u062A\u0628\u0631 \u0628\u0627\u0634\u062F
1919
format.date-time = \u0628\u0627 \u0627\u0644\u06AF\u0648\u06CC {0} \u0645\u0637\u0627\u0628\u0642\u062A \u0646\u062F\u0627\u0631\u062F \u0628\u0627\u06CC\u062F \u062A\u0627\u0631\u06CC\u062E \u0648 \u0632\u0645\u0627\u0646 RFC 3339 \u0645\u0639\u062A\u0628\u0631 \u0628\u0627\u0634\u062F
2020
format.duration = \u0628\u0627 \u0627\u0644\u06AF\u0648\u06CC {0} \u0645\u0637\u0627\u0628\u0642\u062A \u0646\u062F\u0627\u0631\u062F \u0628\u0627\u06CC\u062F \u0645\u062F\u062A \u0632\u0645\u0627\u0646 ISO 8601 \u0645\u0639\u062A\u0628\u0631 \u0628\u0627\u0634\u062F

0 commit comments

Comments
 (0)