protected Scriptable loadConfig ( String configScript ) throws IOException { configScript = processConfig ( configScript ) ; Context cx = Context . enter ( ) ; Scriptable config ; try { sharedScope = cx . initStandardObjects ( null , true ) ; // set up options object IOptions options = aggregator . getOptions ( ) ; if ( options != null ) { optionsUpdated ( options , 1 ) ; } // set up init params object InitParams initParams = aggregator . getInitParams ( ) ; if ( initParams != null ) { Scriptable jsInitParams = cx . newObject ( sharedScope ) ; Collection < String > names = initParams . getNames ( ) ; for ( String name : names ) { Collection < String > values = initParams . getValues ( name ) ; Object value = Context . javaToJS ( values . toArray ( new String [ values . size ( ) ] ) , sharedScope ) ; ScriptableObject . putProperty ( jsInitParams , name , value ) ; } ScriptableObject . putProperty ( sharedScope , "initParams" , jsInitParams ) ; //$NON-NLS-1$ } // set up bundle manifest headers property if ( aggregator . getPlatformServices ( ) != null ) { if ( aggregator . getPlatformServices ( ) . getHeaders ( ) != null ) { Dictionary < String , String > headers = ( Dictionary < String , String > ) ( aggregator . getPlatformServices ( ) . getHeaders ( ) ) ; Scriptable jsHeaders = cx . newObject ( sharedScope ) ; Enumeration < String > keys = headers . keys ( ) ; while ( keys . hasMoreElements ( ) ) { String key = keys . nextElement ( ) ; Object value = Context . javaToJS ( headers . get ( key ) , sharedScope ) ; ScriptableObject . putProperty ( jsHeaders , key , value ) ; } ScriptableObject . putProperty ( sharedScope , "headers" , jsHeaders ) ; //$NON-NLS-1$ } } // set up console object Console console = newConsole ( ) ; Object jsConsole = Context . javaToJS ( console , sharedScope ) ; ScriptableObject . putProperty ( sharedScope , "console" , jsConsole ) ; //$NON-NLS-1$ GetPropertyFunction getPropertyFn = newGetPropertyFunction ( sharedScope , aggregator ) ; ScriptableObject . putProperty ( sharedScope , "getProperty" , getPropertyFn ) ; //$NON-NLS-1$ // Call the registered scope modifiers callConfigScopeModifiers ( sharedScope ) ; cx . evaluateString ( sharedScope , "var config = " + //$NON-NLS-1$ aggregator . substituteProps ( configScript , new IAggregator . SubstitutionTransformer ( ) { @ Override public String transform ( String name , String value ) { // escape forward slashes for javascript literals return value . replace ( "\\" , "\\\\" ) ; //$NON-NLS-1$ //$NON-NLS-2$ } } ) , getConfigUri ( ) . toString ( ) , 1 , null ) ; config = ( Scriptable ) sharedScope . get ( "config" , sharedScope ) ; //$NON-NLS-1$ if ( config == Scriptable . NOT_FOUND ) { throw new IllegalStateException ( "config is not defined." ) ; //$NON-NLS-1$ } } finally { Context . exit ( ) ; } return config ; }
Loads the config JavaScript and returns the parsed config in a Map