private void eval ( CssFormatter formatter ) { if ( type != UNKNOWN ) { return ; } try { ScriptEngineManager factory = new ScriptEngineManager ( getClass ( ) . getClassLoader ( ) ) ; ScriptEngine engine = factory . getEngineByName ( "JavaScript" ) ; engine . setContext ( new JavaScriptContext ( formatter , this ) ) ; String script = toString ( ) ; script = SelectorUtils . replacePlaceHolder ( formatter , script , this ) ; script = script . substring ( 1 , script . length ( ) - 1 ) ; result = engine . eval ( script ) ; if ( result instanceof Number ) { type = NUMBER ; } else if ( result instanceof Boolean ) { type = BOOLEAN ; } else if ( result instanceof Collection ) { type = LIST ; } else if ( result instanceof Map ) { result = ( ( Map ) result ) . values ( ) ; type = LIST ; } else { type = STRING ; } } catch ( Exception ex ) { throw createException ( ex ) ; } }
Execute the JavaScript