Examples of ScriptEngine


Examples of com.openbravo.pos.scripting.ScriptEngine

        if (sresource == null) {
            MessageInf msg = new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.cannotprintticket"));
            msg.show(this);
        } else {
            try {
                ScriptEngine script = ScriptFactory.getScriptEngine(ScriptFactory.VELOCITY);
                script.put("payments", m_PaymentsToClose);
                m_TTP.printTicket(script.eval(sresource).toString());
            } catch (ScriptException e) {
                MessageInf msg = new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.cannotprintticket"), e);
                msg.show(this);
            } catch (TicketPrinterException e) {
                MessageInf msg = new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.cannotprintticket"), e);
View Full Code Here

Examples of com.scratchdisk.script.ScriptEngine

   * Loads and executes a set of JavaScript source files in the current scope.
   */
  public static void include(Context cx, Scriptable thisObj, Object[] args,
      Function funObj) throws Exception {
    File baseDir = getDirectory(thisObj);
    ScriptEngine engine = ScriptEngine.getEngineByName("JavaScript");
    for (int i = 0; i < args.length; i++) {
      File file = new File(baseDir, Context.toString(args[i]));
      executeScript(engine.compile(file), engine.getScope(thisObj));
    }
  }
View Full Code Here

Examples of javax.script.ScriptEngine

  protected final Logger logger = LoggerFactory.getLogger(getClass());

  @Override
  public boolean execute(ScriptEngineManager engineManager,
      TransitionElement transition, Map<String, Object> conditions) {
    ScriptEngine engine = engineManager.getEngineByName(ScriptEngineConstants.AVIATOR);
   
    //创建执行表达式
    String expression = buildExpression(transition, conditions);
   
    if(logger.isDebugEnabled())
      logger.debug("Transition Expressopn:{} Start", expression);
    Bindings variables= engine.createBindings();
    if(conditions != null) {
      for (Map.Entry<String, Object> m : conditions.entrySet()) {  
        variables.put(m.getKey(), m.getValue());
       
        if(logger.isDebugEnabled())
          logger.debug("    Transition Condition:{} = {}", m.getKey(), m.getValue());
      }
    }
    if(logger.isDebugEnabled())
      logger.debug("Transition Expressopn End");
   
    try {
      Object result = engine.eval(expression, variables);
      if(result instanceof Boolean && (Boolean)result) {
        return true;
      } else
        return false;
    } catch (Exception e) {
View Full Code Here

Examples of javax.script.ScriptEngine

  public ScriptInstance(String scriptlanguage) {
    languageId = scriptlanguage;
    logger.debug("the language id is " + scriptlanguage);

    ScriptEngineManager sm;
    ScriptEngine se;
    Bindings sb;
    try {
      sm = new ScriptEngineManager();
      se = sm.getEngineByName(getLanguageId());
      sb = se.getBindings(ScriptContext.ENGINE_SCOPE);
    }
    catch (Exception e) {
      throw new UnsupportedScriptLanguageException(e, "Scriptlanguage " + getLanguageId() + " is not supported.", scriptlanguage);
    }
    scriptengine = se;
View Full Code Here

Examples of javax.script.ScriptEngine

  private ConfigService configService;

  public void parseConfig(ConfigFile configFile) {
    ScriptEngineManager factory = new ScriptEngineManager();
    ScriptEngine engine = factory.getEngineByName("JavaScript");
    String content = configFile.getContent();
    engine.put("config", this);
    try {
      engine.eval(content);
    } catch (ScriptException e) {
      throw new IllegalStateException("There was an arror evaluating config script: " + configFile.getPath(), e);
    }

  }
View Full Code Here

Examples of javax.script.ScriptEngine

    private Dictionary<String, String> props;
    private ComponentContext ctx;
    private final JmxScriptBindingsProvider jmxScriptBindingsProvider = new JmxScriptBindingsProvider();

    private void assertExpression(String expression, String languageExtension, boolean expected) throws Exception {
        final ScriptEngine rhino = new ScriptEngineManager().getEngineByExtension("js");
        assertNotNull("With the rhino jar in our classpath, we should get a js script engine", rhino);
        final ScriptEngineManager manager = Mockito.mock(ScriptEngineManager.class);
        Mockito.when(manager.getEngineByExtension(Matchers.same("ecma"))).thenReturn(rhino);
        final Field f = hc.getClass().getDeclaredField("scriptEngineManager");
        f.setAccessible(true);
View Full Code Here

Examples of javax.script.ScriptEngine

    @Override
    public Result execute() {
        final FormattingResultLog resultLog = new FormattingResultLog();
        resultLog.debug("Checking expression [{}], language extension=[{}]",  expression, languageExtension);
        try {
            final ScriptEngine engine = scriptEngineManager.getEngineByExtension(languageExtension);
            if (engine == null) {
                resultLog.healthCheckError("No ScriptEngine available for extension {}", languageExtension);
            } else {
                // Set Bindings, with our ResultLog as a binding first, so that other bindings can use it
                final Bindings b = engine.createBindings();
                b.put(FormattingResultLog.class.getName(), resultLog);
                synchronized (bindingsValuesProviders) {
                    for(BindingsValuesProvider bvp : bindingsValuesProviders) {
                        log.debug("Adding Bindings provided by {}", bvp);
                        bvp.addBindings(b);
                    }
                }
                log.debug("All Bindings added: {}", b.keySet());

                final Object value = engine.eval(expression, b);
                if(value!=null && "true".equals(value.toString().toLowerCase())) {
                    resultLog.debug("Expression [{}] evaluates to true as expected", expression);
                } else {
                    resultLog.warn("Expression [{}] does not evaluate to true as expected, value=[{}]", expression, value);
                }
View Full Code Here

Examples of javax.script.ScriptEngine

public class RhinoJavaScriptEngineTest extends TestCase {

    public void testPreserveScopeBetweenEvals() throws ScriptException {
        MockRhinoJavaScriptEngineFactory factory = new MockRhinoJavaScriptEngineFactory();
        ScriptEngine engine = factory.getScriptEngine();
        Bindings context = new SimpleBindings();
        engine.eval("var f = 1", context);
        Object result = null;
        try {
            result = engine.eval("f += 1", context);
        } catch (ScriptException e) {
            TestCase.fail(e.getMessage());
        }
        assertTrue(result instanceof Double);
        assertEquals(2.0, result);
View Full Code Here

Examples of javax.script.ScriptEngine

        Resource resource = (Resource) adaptable;
        String path = resource.getPath();
        String ext = path.substring(path.lastIndexOf('.') + 1);

        ScriptEngine engine = scriptEngineManager.getEngineByExtension(ext);
        if (engine != null) {
            final Collection<BindingsValuesProvider> bindingsValuesProviders =
                    bindingsValuesProviderTracker.getBindingsValuesProviders(engine.getFactory(), BINDINGS_CONTEXT);
            // unchecked cast
            return (AdapterType) new DefaultSlingScript(this.bundleContext,
                    resource, engine, bindingsValuesProviders, this.serviceCache);
        }
View Full Code Here

Examples of javax.script.ScriptEngine

     *            name contains no dot, the entire name is considered the
     *            extension.
     */
    public String getMimeType(String name) {
        name = name.substring(name.lastIndexOf('.') + 1);
        ScriptEngine se = scriptEngineManager.getEngineByExtension(name);
        if (se != null) {
            List<?> mimeTypes = se.getFactory().getMimeTypes();
            if (mimeTypes != null && mimeTypes.size() > 0) {
                return String.valueOf(mimeTypes.get(0));
            }
        }

View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.