Example usage for javax.script Bindings get

List of usage examples for javax.script Bindings get

Introduction

In this page you can find the example usage for javax.script Bindings get.

Prototype

public Object get(Object key);

Source Link

Document

Returns the value to which this map maps the specified key.

Usage

From source file:org.onesec.raven.ivr.queue.actions.RegisterOperatorActionNode.java

private ConversationScenarioState getConversationState(Bindings bindings) {
    return (ConversationScenarioState) bindings.get(IvrEndpointConversation.CONVERSATION_STATE_BINDING);
}

From source file:com.sixdimensions.wcm.cq.component.bindings.impl.ComponentBindingsValuesProvider.java

@SuppressWarnings("unchecked")
// Suppressing warnings since Commons Collections is gangster...
@Override/*from w w  w  .  jav  a2s.  c  o m*/
public void addBindings(Bindings bindings) {
    try {
        SlingHttpServletRequest request = (SlingHttpServletRequest) bindings.get("request");
        String resourceType = request.getResource().getResourceType();
        Collection<ComponentBindingsProvider> cis = cif.getComponentBindingsProviders(resourceType);
        if (cis != null && cis.size() > 0) {
            CQVariables variables = variablesService.getVariables(bindings);
            for (ComponentBindingsProvider ci : cis) {
                try {
                    log.debug("Invoking component bindings provider {}", ci);
                    ci.addBindings(variables, bindings);
                } catch (Exception e) {
                    log.error("Exception invoking component bindings provider " + ci, e);
                    recentExceptions.add(new ComponentBindingsExceptionData(ci, e));
                }
            }
        }
    } catch (Exception e) {
        log.error("Exception invoking component binding providers", e);
    }
}

From source file:org.zanata.util.CommonMarkRenderer.java

public String renderToHtmlUnsafe(String commonMark) {
    try {//w ww .  j a v  a2 s. co m
        Bindings bindings = threadBindings.get();
        JSObject mdRender = (JSObject) bindings.get("mdRender");
        return (String) mdRender.call(bindings, commonMark);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.onesec.raven.ivr.queue.actions.RegisterOperatorActionNode.java

@Override
public Collection<Node> getEffectiveChildrens() {
    if (getStatus() != Node.Status.STARTED)
        return null;
    Bindings bindings = new SimpleBindings();
    formExpressionBindings(bindings);/*  w w w. j a v  a  2s  .  co  m*/
    List<String> dtmfs = (List<String>) bindings.get(IvrEndpointConversation.DTMFS_BINDING);
    String operatorCode = StringUtils.join(dtmfs, "");
    String operatorNumber = (String) bindings.get(IvrEndpointConversation.NUMBER_BINDING);
    OperatorRegistratorNode auth = callsQueues.getOperatorRegistrator();
    OperatorDesc operator;
    if (operatorCode == null || operatorCode.isEmpty()
            || (operator = auth.register(operatorNumber, operatorCode)) == null) {
        if (isLogLevelEnabled(LogLevel.WARN))
            getLogger().warn("Invalid authentication code {} for operator number {}", operatorCode,
                    operatorNumber);
        return null;
    } else {
        if (isLogLevelEnabled(LogLevel.DEBUG))
            getLogger().debug("Operator successfully authenticated. {}; number - ({})", operator,
                    operatorNumber);
        getConversationState(bindings).setBinding(OPERATOR_BINDING, operator, BindingScope.CONVERSATION);
        return super.getEffectiveChildrens();
    }
}

From source file:org.onesec.raven.ivr.actions.CollectDtmfsActionNode.java

private ConversationScenarioState getConversationState(Bindings bindings) {
    return (ConversationScenarioState) bindings.get(CONVERSATION_STATE_BINDING);
}

From source file:org.onesec.raven.ivr.queue.actions.SayNumberInQueueActionTest.java

public void formWords() throws Exception {
    ConversationScenarioState state = createMock(ConversationScenarioState.class);
    Bindings bindings = createMock(Bindings.class);
    QueuedCallStatus callStatus = createMock(QueuedCallStatus.class);
    BindingSupport bindingSupport = createMock(BindingSupport.class);

    expect(state.getBindings()).andReturn(bindings);
    expect(bindings.get(QueueCallAction.QUEUED_CALL_STATUS_BINDING)).andReturn(callStatus);
    String key = SayNumberInQueueAction.LAST_SAYED_NUMBER + "_" + owner.getId();
    expect(bindings.get(key)).andReturn(10);
    expect(callStatus.isQueueing()).andReturn(Boolean.TRUE);
    expect(callStatus.getSerialNumber()).andReturn(10).anyTimes();

    replay(state, bindings, callStatus, bindingSupport);

    conv.setConversationScenarioState(state);
    SayNumberInQueueAction action = new SayNumberInQueueAction(owner, bindingSupport, numbers, 50, preamble,
            resourceManager);/*from   w  w  w  . j av a  2  s .c  o m*/
    assertNull(action.formWords(conv));

    verify(state, bindings, callStatus, bindingSupport);
}

From source file:org.onesec.raven.ivr.queue.actions.SayNumberInQueueActionTest.java

public void formWords2() throws Exception {
    ConversationScenarioState state = createMock(ConversationScenarioState.class);
    Bindings bindings = createMock(Bindings.class);
    QueuedCallStatus callStatus = createMock(QueuedCallStatus.class);
    BindingSupport bindingSupport = createMock(BindingSupport.class);

    expect(state.getBindings()).andReturn(bindings);
    expect(bindings.get(QueueCallAction.QUEUED_CALL_STATUS_BINDING)).andReturn(callStatus);
    String key = SayNumberInQueueAction.LAST_SAYED_NUMBER + "_" + owner.getId();
    expect(bindings.get(key)).andReturn(null);
    expect(bindings.put(key, 10)).andReturn(null);
    expect(callStatus.isQueueing()).andReturn(Boolean.TRUE);
    expect(callStatus.getSerialNumber()).andReturn(10).anyTimes();
    bindingSupport.putAll(bindings);/*from  ww w. ja  v  a2  s.c  om*/
    bindingSupport.reset();

    replay(state, bindings, callStatus, bindingSupport);

    conv.setConversationScenarioState(state);
    SayNumberInQueueAction action = new SayNumberInQueueAction(owner, bindingSupport, numbers, 50, preamble,
            resourceManager);
    List words = action.formWords(conv);
    assertNotNull(words);
    assertEquals(2, words.size());
    assertArrayEquals(new Object[] { preamble, "10" }, words.toArray());

    verify(state, bindings, callStatus, bindingSupport);
}

From source file:org.onesec.raven.ivr.queue.actions.SayNumberInQueueActionTest.java

@Test(timeout = 15000)
public void test() throws Exception {
    ConversationScenarioState state = createMock(ConversationScenarioState.class);
    Bindings bindings = createMock(Bindings.class);
    BindingSupport bindingSupport = createMock(BindingSupport.class);
    QueuedCallStatus callStatus = createMock(QueuedCallStatus.class);

    expect(state.getBindings()).andReturn(bindings);
    expect(bindings.get(QueueCallAction.QUEUED_CALL_STATUS_BINDING)).andReturn(callStatus);
    String key = SayNumberInQueueAction.LAST_SAYED_NUMBER + "_" + owner.getId();
    expect(bindings.get(key)).andReturn(null);
    expect(bindings.put(key, 10)).andReturn(null);
    expect(callStatus.isQueueing()).andReturn(Boolean.TRUE);
    expect(callStatus.getSerialNumber()).andReturn(10).anyTimes();
    bindingSupport.putAll(bindings);//from  www .j  a  va 2s . co  m
    expectLastCall().atLeastOnce();
    bindingSupport.reset();

    replay(state, bindings, callStatus, bindingSupport);

    conv.setConversationScenarioState(state);
    assertTrue(conv.start());
    SayNumberInQueueAction action = new SayNumberInQueueAction(owner, bindingSupport, numbers, 50, preamble,
            resourceManager);
    action.execute(conv);
    Thread.sleep(10000);

    verify(state, bindings, callStatus, bindingSupport);
}

From source file:org.nuxeo.usermapper.extension.NashornUserMapper.java

@Override
public Object wrapNuxeoPrincipal(NuxeoPrincipal principal, Object userObject,
        Map<String, Serializable> params) {
    if (StringUtils.isEmpty(wrapperSource)) {
        return null;
    }/*ww w.jav a  2 s  .  c o m*/
    Bindings bindings = new SimpleBindings();
    bindings.put("nuxeoPrincipal", principal);
    bindings.put("userObject", userObject);
    bindings.put("params", params);
    try {
        engine.eval(wrapperSource, bindings);
    } catch (ScriptException e) {
        log.error("Error while executing JavaScript mapper", e);
    }
    return bindings.get("userObject");
}

From source file:org.apache.sling.scripting.javascript.internal.RhinoJavaScriptEngine.java

private String getScriptName(ScriptContext scriptContext) {
    Bindings bindings = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
    String scriptName = (String) bindings.get(ScriptEngine.FILENAME);
    if (scriptName != null && !"".equals(scriptName)) {
        return scriptName;
    }//from   w  w w . j a v a 2 s.c om
    SlingScriptHelper sling = (SlingScriptHelper) bindings.get(SlingBindings.SLING);
    if (sling != null) {
        return sling.getScript().getScriptResource().getPath();
    }
    return NO_SCRIPT_NAME;
}