Guest User

Untitled

a guest
Apr 26th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. ```scala
  2. lass CustomStrategy extends BaseStrategy with LazyLogging {
  3.  
  4.  
  5. override def format(value: String, strategyParam: String): String = {
  6. val manager = new ScriptEngineManager()
  7. val engine = manager.getEngineByName(CustomStrategy.ENGINE_NAME)
  8. try {
  9. engine.put(CustomStrategy.JS_FUNCTION_PARAM, value)
  10. engine.eval(strategyParam)
  11. } catch {
  12. case e: ScriptException =>
  13. logger.warn("Script execute failure", e)
  14. }
  15. value
  16. }
  17. }
  18.  
  19.  
  20. object CustomStrategy {
  21. val JS_FUNCTION_PARAM = "value"
  22. val ENGINE_NAME = "javascript"
  23. }
  24.  
  25. ```
Add Comment
Please, Sign In to add comment