public static Resource from ( String resource ) { if ( StringUtils . isNullOrBlank ( resource ) ) { return new StringResource ( ) ; } Matcher matcher = protocolPattern . matcher ( resource ) ; if ( matcher . find ( ) ) { String schema = matcher . group ( "PROTOCOL" ) ; String options = matcher . group ( "OPTIONS" ) ; String path = matcher . group ( "PATH" ) ; if ( StringUtils . isNullOrBlank ( options ) ) { options = "" ; } else { options = options . replaceFirst ( "\\[" , "" ) . replaceFirst ( "\\]$" , "" ) ; } ResourceProvider provider = resourceProviders . get ( schema . toLowerCase ( ) ) ; if ( provider == null ) { try { return new URIResource ( new URI ( resource ) ) ; } catch ( URISyntaxException e ) { throw new IllegalStateException ( schema + " is an unknown protocol." ) ; } } if ( provider . requiresProtocol ( ) ) { path = schema + ":" + path ; } return provider . createResource ( path , Val . of ( options ) . asMap ( String . class , String . class ) ) ; } return new FileResource ( resource ) ; }
Constructs a resource from a string representation . Defaults to a file based resource if no schema is present .