Examples of SimpleBindings


Examples of javax.script.SimpleBindings

            protected ScriptEngine createScriptEngine() {
                return engine;
            }
        };

        EasyMock.expect(engine.createBindings()).andReturn(new SimpleBindings());
        engine.setContext((ScriptContext) EasyMock.anyObject());
        EasyMock.expect(engine.eval((Reader) EasyMock.anyObject())).andThrow(new ScriptException("test exception"));
        EasyMock.replay(engine);

        scriptedView.setEngineName("test-engine");
View Full Code Here

Examples of javax.script.SimpleBindings

  /**
   * Creates a bindings.
   */
  public Bindings createBindings() {
    return new SimpleBindings();
  }
View Full Code Here

Examples of javax.script.SimpleBindings

    public Object eval(String javascriptCode, Map<String, Object> data,
            final StringWriter sw) throws ScriptException {
        final PrintWriter pw = new PrintWriter(sw, true);
        ScriptContext ctx = new SimpleScriptContext();

        final Bindings b = new SimpleBindings();
        b.put("out", pw);
        if (data != null) {
            for (Map.Entry<String, Object> e : data.entrySet()) {
                b.put(e.getKey(), e.getValue());
            }
        }

        ctx.setBindings(b, ScriptContext.ENGINE_SCOPE);
        ctx.setWriter(sw);
View Full Code Here

Examples of javax.script.SimpleBindings

    }

    private Bindings verifySlingBindings(String scriptName,
            SlingBindings slingBindings) throws IOException {

      Bindings bindings = new SimpleBindings();

        final SlingHttpServletRequest request = slingBindings.getRequest();

        // check sling object
        Object slingObject = slingBindings.get(SLING);
        if (slingObject == null) {

            if ( request != null ) {
                slingObject = new ScriptHelper(this.bundleContext, this, request, slingBindings.getResponse());
            } else {
                slingObject = new ScriptHelper(this.bundleContext, this);
            }
        } else if (!(slingObject instanceof SlingScriptHelper) ) {
            throw fail(scriptName, SLING, "Wrong type");
        }
        final SlingScriptHelper sling = (SlingScriptHelper)slingObject;
        bindings.put(SLING, sling);

        if (request != null) {
            //throw fail(scriptName, REQUEST, "Missing or wrong type");

          SlingHttpServletResponse response = slingBindings.getResponse();
            if (response == null) {
                throw fail(scriptName, RESPONSE, "Missing or wrong type");
            }

            Object resourceObject = slingBindings.get(RESOURCE);
            if (resourceObject != null && !(resourceObject instanceof Resource)) {
                throw fail(scriptName, RESOURCE, "Wrong type");
            }

            Object writerObject = slingBindings.get(OUT);
            if (writerObject != null && !(writerObject instanceof PrintWriter)) {
                throw fail(scriptName, OUT, "Wrong type");
            }

            // if there is a provided sling script helper, check arguments
            if (slingBindings.get(SLING) != null) {

                if (sling.getRequest() != request) {
                    throw fail(scriptName, REQUEST,
                        "Not the same as request field of SlingScriptHelper");
                }

                if (sling.getResponse() != response) {
                    throw fail(scriptName, RESPONSE,
                        "Not the same as response field of SlingScriptHelper");
                }

                if (resourceObject != null
                    && sling.getRequest().getResource() != resourceObject) {
                    throw fail(scriptName, RESOURCE,
                        "Not the same as resource of the SlingScriptHelper request");
                }

                if (writerObject != null
                    && sling.getResponse().getWriter() != writerObject) {
                    throw fail(scriptName, OUT,
                        "Not the same as writer of the SlingScriptHelper response");
                }
            }

            // set base variables when executing inside a request
            bindings.put(REQUEST, sling.getRequest());
            bindings.put(READER, sling.getRequest().getReader());
            bindings.put(RESPONSE, sling.getResponse());
            bindings.put(RESOURCE, sling.getRequest().getResource());
            bindings.put(OUT, sling.getResponse().getWriter());
           
            // set the current node if the resource is node based
            Node node = sling.getRequest().getResource().adaptTo(Node.class);
            if (node != null) {
                bindings.put(NODE, node);
            }
        }

        Object logObject = slingBindings.get(LOG);
        if (logObject == null) {
            logObject = LoggerFactory.getLogger(getLoggerName());
        } else if (!(logObject instanceof Logger)) {
            throw fail(scriptName, LOG, "Wrong type");
        }
        bindings.put(LOG, logObject);

        // copy non-base variables
        for (Map.Entry<String, Object> entry : slingBindings.entrySet()) {
            if (!bindings.containsKey(entry.getKey())) {
                bindings.put(entry.getKey(), entry.getValue());
            }
        }

        return bindings;
    }
View Full Code Here

Examples of javax.script.SimpleBindings

  }

  private Bindings createGlobalBindings() {
    Map<String, Object> map =
      Collections.synchronizedMap(new HashMap<String, Object>());
    return new SimpleBindings(map);
  }
View Full Code Here

Examples of javax.script.SimpleBindings

        filter(requestUri, SCRIPT.scriptSource, null);

    if(it.hasNext()) {
      NonLiteral scriptResource = (NonLiteral) it.next().getObject();
      try {
        Bindings bindings = new SimpleBindings();
        bindings.put("uriInfo", uriInfo);
        bindings.put("request", request);
        bindings.put("httpHeaders", httpHeaders);
        return scriptExecution.execute(scriptResource, bindings);
      } catch (ScriptException ex) {
        logger.warn("Exception while executing script {}",
            ((UriRef) scriptResource).getUnicodeString());
        throw new WebApplicationException(
View Full Code Here

Examples of javax.script.SimpleBindings

            throw new ScriptException(e);
        }
    }

    public Bindings createBindings() {
        return new SimpleBindings();
    }
View Full Code Here

Examples of javax.script.SimpleBindings

    public void testEval_bindings() throws Exception {
        logger1.info("eval with bindings");
        System.setProperty("org.jruby.embed.localvariable.behavior", "transient");
        JRubyEngineFactory factory = new JRubyEngineFactory();
        JRubyEngine engine = (JRubyEngine) factory.getScriptEngine();
        Bindings bindings = new SimpleBindings();
        bindings.put("message", "Helloooo Woooorld!");
        engine.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
        String script = "\"I heard, \"#{message}\"\"";
        JRubyCompiledScript instance = (JRubyCompiledScript) engine.compile(script);
        Object expResult = "I heard, Helloooo Woooorld!";
        Object result = instance.eval(bindings);
        // Bug? a local variable isn't shared.
        //assertEquals(expResult, result);

        bindings.put("@message", "Saaaay Heeeey.");
        engine.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
        script = "\"I heard, #{@message}\"";
        instance = (JRubyCompiledScript) engine.compile(script);
        expResult = "I heard, Saaaay Heeeey.";
        result = instance.eval(bindings);
        assertEquals(expResult, result);

        bindings.put("$message", "Hiya, hiya, hiya");
        engine.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
        script = "\"I heard, #{$message}\"";
        instance = (JRubyCompiledScript) engine.compile(script);
        expResult = "I heard, Hiya, hiya, hiya";
        result = instance.eval(bindings);
View Full Code Here

Examples of org.apache.lucene.expressions.SimpleBindings

    try {
      expression = JavascriptCompiler.compile(weightExpression);
    } catch (ParseException e) {
      throw new RuntimeException();
    }
    SimpleBindings bindings = new SimpleBindings();
    for (SortField sortField: sortFields) {
      bindings.add(sortField);
    }
    weightsValueSource = expression.getValueSource(bindings);
   
  }
View Full Code Here

Examples of org.apache.lucene.expressions.SimpleBindings

    TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);

    // Aggregate categories by an expression that combines the document's score
    // and its popularity field
    Expression expr = JavascriptCompiler.compile("_score * sqrt(popularity)");
    SimpleBindings bindings = new SimpleBindings();
    bindings.add(new SortField("_score", SortField.Type.SCORE)); // the score of the document
    bindings.add(new SortField("popularity", SortField.Type.LONG)); // the value of the 'popularity' field

    FacetSearchParams fsp = new FacetSearchParams(
        new SumValueSourceFacetRequest(new CategoryPath("A"), 10, expr.getValueSource(bindings), true));

    // Aggregates the facet values
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.