Package javax.script

Examples of javax.script.Bindings


    }
    if (scriptContext == null) {
      throw new IllegalArgumentException(
          "Method argument scriptContext must not be null.");
    }
        Bindings bindings = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
        SlingScriptHelper helper = (SlingScriptHelper) bindings.get(SlingBindings.SLING);
        if (helper == null) {
            throw new ScriptException("SlingScriptHelper missing from bindings");
        }

        String scriptName = helper.getScript().getScriptResource().getPath();

        final ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
       
        try {
          Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
         
          // initialize the Velocity context
          final VelocityContext c = new VelocityContext();
          for (Object entryObj : bindings.entrySet()) {
              Map.Entry<?, ?> entry = (Map.Entry<?, ?>) entryObj;
              c.put((String) entry.getKey(), entry.getValue());
          }
 
          // let Velocity evaluate the script, and send the output to the browser
View Full Code Here


    }

    /** Output the HTML representation, with reference to the actual client-side script */
    public Object eval(Reader script, ScriptContext context) throws ScriptException {

        final Bindings props = context.getBindings(ScriptContext.ENGINE_SCOPE);
        final SlingScriptHelper helper = (SlingScriptHelper) props.get(SlingBindings.SLING);
        final InputStream scriptStream = helper.getScript().getScriptResource().adaptTo(InputStream.class);
       
        try {
            htmlGenerator.generateHtml(helper.getRequest(),
                    helper.getScript().getScriptResource().getPath(), scriptStream,
View Full Code Here

    }
  }

  public Object eval(Reader script, ScriptContext scriptContext)
      throws ScriptException {
    Bindings bindings = scriptContext
        .getBindings(ScriptContext.ENGINE_SCOPE);

    SlingScriptHelper helper = (SlingScriptHelper) bindings
        .get(SlingBindings.SLING);
    if (helper == null) {
      throw new ScriptException("SlingScriptHelper missing from bindings");
    }

    // ensure GET request
    if (helper.getRequest() != null && !"GET".equals(helper.getRequest().getMethod())) {
      throw new ScriptException(
          "Python scripting only supports GET requests");
    }

    final ClassLoader oldClassLoader = Thread.currentThread()
        .getContextClassLoader();
    try {
      Thread.currentThread().setContextClassLoader(
          getClass().getClassLoader());
      StringBuffer scriptString = new StringBuffer();
      BufferedReader bufferedScript = new BufferedReader(script);
      String nextLine = bufferedScript.readLine();
      String newLine = System.getProperty("line.separator");
      while (nextLine != null) {
        scriptString.append(nextLine);
        scriptString.append(newLine);
        nextLine = bufferedScript.readLine();
      }

      // set writer
      interp.setOut(scriptContext.getWriter());
      interp.setErr(scriptContext.getErrorWriter());
     
      // set all bindings
      for (Object entryObj : bindings.entrySet()) {
        Map.Entry<?, ?> entry = (Map.Entry<?, ?>) entryObj;
        interp.set((String) entry.getKey(), entry.getValue());
      }

      // execute Python code
View Full Code Here

        /**
         * @see javax.script.ScriptEngine#eval(java.io.Reader, javax.script.ScriptContext)
         */
        public Object eval(Reader script, ScriptContext context)
        throws ScriptException {
            final Bindings props = context.getBindings(ScriptContext.ENGINE_SCOPE);
            final SlingScriptHelper scriptHelper = (SlingScriptHelper) props.get(SLING);
            if (scriptHelper != null) {
                ((JavaScriptEngineFactory)this.getFactory()).callServlet(props, scriptHelper, context);
            }
            return null;
        }
View Full Code Here

            throw new ScriptException("Unable to compile GSP script: " + e.getMessage());
        } catch (ClassNotFoundException e) {
            throw new ScriptException("Unable to compile GSP script: " + e.getMessage());
        }

        Bindings bindings = ctx.getBindings(ScriptContext.ENGINE_SCOPE);

        Writable result = template.make(bindings);

        try {
            result.writeTo(ctx.getWriter());
View Full Code Here

  protected XProcScriptEngine(ScriptEngineFactory factory) {
    super(factory);
  }

  public Object eval(Reader reader, ScriptContext scriptContext) throws ScriptException {
    Bindings bindings = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
    SlingScriptHelper helper = (SlingScriptHelper) bindings.get(SlingBindings.SLING);
    if (helper == null) {
      throw new ScriptException("SlingScriptHelper missing from bindings");
    }
   
    String scriptName = helper.getScript().getScriptResource().getPath();
View Full Code Here

        configuration = new Configuration();
    }

    public Object eval(Reader reader, ScriptContext scriptContext)
            throws ScriptException {
        Bindings bindings = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
        SlingScriptHelper helper = (SlingScriptHelper) bindings.get(SlingBindings.SLING);
        if (helper == null) {
            throw new ScriptException("SlingScriptHelper missing from bindings");
        }

        // ensure GET request
        if (!"GET".equals(helper.getRequest().getMethod())) {
            throw new ScriptException(
                "FreeMarker templates only support GET requests");
        }

        String scriptName = helper.getScript().getScriptResource().getPath();

        try {
            Template tmpl = new Template(scriptName, reader, configuration);
            bindings.put("currentNode", new NodeModel((Node) bindings.get("currentNode")));
            tmpl.process(bindings, scriptContext.getWriter());
        } catch (Throwable t) {
            log.error("Failure running Freemarker script.", t);
            throw new ScriptException("Failure running FreeMarker script "
                + scriptName);
View Full Code Here

  @Override
  public Object evaluate(ScriptSource script, Map<String, Object> arguments) {
    ScriptEngine engine = discoverEngine(script, arguments);

    Bindings bindings = (!CollectionUtils.isEmpty(arguments) ? new SimpleBindings(arguments) : null);

    try {
      return (bindings == null ? engine.eval(script.getScriptAsString()) : engine.eval(
          script.getScriptAsString(), bindings));
    } catch (IOException ex) {
View Full Code Here

        this.thymeleafScriptEngineFactory = thymeleafScriptEngineFactory;
    }

    @Override
    public Object eval(final Reader reader, final ScriptContext scriptContext) throws ScriptException {
        final Bindings bindings = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
        final SlingScriptHelper helper = (SlingScriptHelper) bindings.get(SlingBindings.SLING);

        if (helper == null) {
            throw new ScriptException("SlingScriptHelper missing from bindings");
        }
View Full Code Here

    public void test() throws Exception {
        QueryBuilderBindingsValuesProvider provider = new QueryBuilderBindingsValuesProvider();
        QueryBuilder qb = mock(QueryBuilder.class);
        PrivateAccessor.setField(provider, "queryBuilder", qb);

        Bindings bindings = mock(Bindings.class);
        provider.addBindings(bindings);
        verify(bindings).put("queryBuilder", qb);
    }
View Full Code Here

TOP

Related Classes of javax.script.Bindings

Copyright © 2018 www.massapicom. 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.