public ResourceFormatParser getParserForMIMEType ( final String mimeType ) throws UnsupportedFormatException { //clean up encoding final String cleanMime ; if ( null != mimeType && mimeType . indexOf ( ";" ) > 0 ) { cleanMime = mimeType . substring ( 0 , mimeType . indexOf ( ";" ) ) ; } else { cleanMime = mimeType ; } if ( ! validMimeType ( cleanMime ) ) { throw new IllegalArgumentException ( "Invalid MIME type: " + mimeType ) ; } for ( final ResourceFormatParser resourceFormatParser : listParsers ( ) ) { if ( null != resourceFormatParser . getMIMETypes ( ) ) { if ( resourceFormatParser . getMIMETypes ( ) . contains ( cleanMime ) ) { return resourceFormatParser ; } else { for ( final String s : resourceFormatParser . getMIMETypes ( ) ) { if ( validMimeType ( s ) && s . startsWith ( "*/" ) ) { String t1 = s . substring ( 2 ) ; String t2 = cleanMime . substring ( cleanMime . indexOf ( "/" ) + 1 ) ; if ( t1 . equals ( t2 ) ) { return resourceFormatParser ; } } } } } } throw new UnsupportedFormatException ( "No provider available to parse MIME type: " + mimeType ) ; }
Return a parser for a mime type .