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