17
17
package com .networknt .schema ;
18
18
19
19
import java .io .UnsupportedEncodingException ;
20
- import java .net .MalformedURLException ;
21
- import java .net .URL ;
20
+ import java .net .URI ;
22
21
import java .net .URLDecoder ;
23
22
import java .util .Collections ;
24
23
import java .util .HashMap ;
30
29
import java .util .regex .Pattern ;
31
30
32
31
import com .fasterxml .jackson .databind .JsonNode ;
33
- import com .networknt .schema .url .URLFactory ;
34
32
35
33
/**
36
34
* This is the core of json constraint implementation. It parses json constraint
@@ -43,59 +41,56 @@ public class JsonSchema extends BaseJsonValidator {
43
41
private final ValidationContext validationContext ;
44
42
45
43
/**
46
- * This is the current url of this schema. This url could refer to the url of this schema's file
47
- * or it could potentially be a url that has been altered by an id. An 'id' is able to completely overwrite
48
- * the current url or add onto it. This is necessary so that '$ref's are able to be relative to a
49
- * combination of the current schema file's url and 'id' urls visible to this schema.
44
+ * This is the current uri of this schema. This uri could refer to the uri of this schema's file
45
+ * or it could potentially be a uri that has been altered by an id. An 'id' is able to completely overwrite
46
+ * the current uri or add onto it. This is necessary so that '$ref's are able to be relative to a
47
+ * combination of the current schema file's uri and 'id' uris visible to this schema.
50
48
*
51
- * This can be null. If it is null, then the creation of relative urls will fail. However, an absolute
52
- * 'id' would still be able to specify an absolute url .
49
+ * This can be null. If it is null, then the creation of relative uris will fail. However, an absolute
50
+ * 'id' would still be able to specify an absolute uri .
53
51
*/
54
- private final URL currentUrl ;
52
+ private final URI currentUri ;
55
53
56
54
private JsonValidator requiredValidator = null ;
57
55
58
- public JsonSchema (ValidationContext validationContext , URL baseUrl , JsonNode schemaNode ) {
59
- this (validationContext , "#" , baseUrl , schemaNode , null );
56
+ public JsonSchema (ValidationContext validationContext , URI baseUri , JsonNode schemaNode ) {
57
+ this (validationContext , "#" , baseUri , schemaNode , null );
60
58
}
61
59
62
- public JsonSchema (ValidationContext validationContext , String schemaPath , URL currentUrl , JsonNode schemaNode ,
60
+ public JsonSchema (ValidationContext validationContext , String schemaPath , URI currentUri , JsonNode schemaNode ,
63
61
JsonSchema parent ) {
64
- this (validationContext , schemaPath , currentUrl , schemaNode , parent , false );
62
+ this (validationContext , schemaPath , currentUri , schemaNode , parent , false );
65
63
}
66
64
67
- public JsonSchema (ValidationContext validationContext , URL baseUrl , JsonNode schemaNode , boolean suppressSubSchemaRetrieval ) {
68
- this (validationContext , "#" , baseUrl , schemaNode , null , suppressSubSchemaRetrieval );
65
+ public JsonSchema (ValidationContext validationContext , URI baseUri , JsonNode schemaNode , boolean suppressSubSchemaRetrieval ) {
66
+ this (validationContext , "#" , baseUri , schemaNode , null , suppressSubSchemaRetrieval );
69
67
}
70
68
71
- private JsonSchema (ValidationContext validationContext , String schemaPath , URL currentUrl , JsonNode schemaNode ,
69
+ private JsonSchema (ValidationContext validationContext , String schemaPath , URI currentUri , JsonNode schemaNode ,
72
70
JsonSchema parent , boolean suppressSubSchemaRetrieval ) {
73
71
super (schemaPath , schemaNode , parent , null , suppressSubSchemaRetrieval );
74
72
this .validationContext = validationContext ;
75
73
this .config = validationContext .getConfig ();
76
- this .currentUrl = this .combineCurrentUrlWithIds ( currentUrl , schemaNode );
74
+ this .currentUri = this .combineCurrentUriWithIds ( currentUri , schemaNode );
77
75
this .validators = Collections .unmodifiableMap (this .read (schemaNode ));
78
76
}
79
77
80
- private URL combineCurrentUrlWithIds ( URL currentUrl , JsonNode schemaNode ) {
78
+ private URI combineCurrentUriWithIds ( URI currentUri , JsonNode schemaNode ) {
81
79
final JsonNode idNode = schemaNode .get ("id" );
82
80
if (idNode == null ) {
83
- return currentUrl ;
81
+ return currentUri ;
84
82
} else {
85
- try
86
- {
87
- return URLFactory .toURL (currentUrl , idNode .asText ());
88
- }
89
- catch (MalformedURLException e )
90
- {
91
- throw new IllegalArgumentException (String .format ("Invalid 'id' in schema: %s" , schemaNode ), e );
83
+ try {
84
+ return this .validationContext .getJsonSchemaFactory ().getURIFactory ().create (currentUri , idNode .asText ());
85
+ } catch (IllegalArgumentException e ) {
86
+ throw new JsonSchemaException (ValidationMessage .of (ValidatorTypeCode .ID .getValue (), ValidatorTypeCode .ID , idNode .asText (), currentUri .toString ()));
92
87
}
93
88
}
94
89
}
95
90
96
- public URL getCurrentUrl ()
91
+ public URI getCurrentUri ()
97
92
{
98
- return this .currentUrl ;
93
+ return this .currentUri ;
99
94
}
100
95
101
96
/**
0 commit comments