@ Override public Schema fetch ( URI targetUri , URI srcOrigUri , URI srcId ) { Schema res = null ; URI schemaUri = convertUri ( resolveUri ( targetUri , srcOrigUri , srcId ) ) ; if ( ! schemaUri . isAbsolute ( ) ) throw new RuntimeException ( "Json Schema Fetcher works only with absolute URIs" ) ; try { String fragment = schemaUri . getFragment ( ) ; JsonObject schemaJson = JsonElement . readFrom ( new InputStreamReader ( schemaUri . toURL ( ) . openStream ( ) ) ) . asJsonObject ( ) ; if ( fragment != null && ! fragment . trim ( ) . isEmpty ( ) ) { String [ ] pointers = fragment . split ( "/" ) ; for ( String pointer : pointers ) { if ( pointer != null && ! pointer . trim ( ) . isEmpty ( ) ) { schemaJson = schemaJson . getJsonObject ( pointer ) ; } } } String version = schemaJson . optString ( "$schema" , "" ) ; if ( version . equals ( Schema . VER_4 ) ) { res = new SchemaV4 ( ) . setSchemaFetcher ( this ) . setOrigSrc ( schemaUri ) . wrap ( schemaJson ) ; } else { res = new SchemaV4 ( ) . setSchemaFetcher ( this ) . setOrigSrc ( schemaUri ) . wrap ( schemaJson ) ; } } catch ( IOException e ) { e . printStackTrace ( ) ; } catch ( JsonException e ) { e . printStackTrace ( ) ; } return res ; }
accepts only absolute URI or converted absolute URI