private LinkedMapWritable getMimetypesMap ( ) throws IOException { if ( mimetypeMap != null ) return mimetypeMap ; String mtmap = conf . get ( ConfigConstants . CONF_MIMETYPES ) ; if ( mtmap != null ) { mimetypeMap = DefaultStringifier . load ( conf , ConfigConstants . CONF_MIMETYPES , LinkedMapWritable . class ) ; return mimetypeMap ; } String [ ] hosts = conf . getStrings ( OUTPUT_HOST ) ; Session session = null ; ResultSequence result = null ; for ( int i = 0 ; i < hosts . length ; i ++ ) { try { String host = hosts [ i ] ; ContentSource cs = InternalUtilities . getOutputContentSource ( conf , host ) ; session = cs . newSession ( ) ; AdhocQuery query = session . newAdhocQuery ( MIMETYPES_QUERY ) ; RequestOptions options = new RequestOptions ( ) ; options . setDefaultXQueryVersion ( "1.0-ml" ) ; query . setOptions ( options ) ; result = session . submitRequest ( query ) ; if ( ! result . hasNext ( ) ) throw new IOException ( "Server-side transform requires MarkLogic 7 or later" ) ; mimetypeMap = new LinkedMapWritable ( ) ; while ( result . hasNext ( ) ) { String suffs = result . next ( ) . asString ( ) ; Text format = new Text ( result . next ( ) . asString ( ) ) ; // some extensions are in a space separated string for ( String s : suffs . split ( " " ) ) { Text suff = new Text ( s ) ; mimetypeMap . put ( suff , format ) ; } } return mimetypeMap ; } catch ( Exception e ) { if ( e . getCause ( ) instanceof ServerConnectionException ) { LOG . warn ( "Unable to connect to " + hosts [ i ] + " to query destination information" ) ; continue ; } LOG . error ( e . getMessage ( ) , e ) ; throw new IOException ( e ) ; } finally { if ( result != null ) { result . close ( ) ; } if ( session != null ) { session . close ( ) ; } } } return null ; }
initialize mimetype map if not initialized return the map