/** * Checks if the given attribute is defined, this means, neither <code>null</code> nor <code> * ScriptingEngine.getUndefinedValue()</code>. * * @param model the data model to use * @param name Name of the attribute. * @return <code>true</code> if the attribute is defined. */ protected boolean isAttributeDefined(DataModel model, final String name) { final Object value = attributes.get(name); if (value == null) { return false; } return model.getUndefinedValue() != value; }
/** {@inheritDoc} */ @Override public void evalAttributes(final VoiceXmlInterpreterContext context) throws SemanticError { final DataModel model = context.getDataModel(); final Collection<String> evalAttributes = getEvalAttributes(); if (evalAttributes == null) { return; } // Actually evalute the attributes for (String name : evalAttributes) { final Object expr = attributes.get(name); if (expr != null) { final String exprstring = expr.toString(); final String unescapedExprstring = StringEscapeUtils.unescapeXml(exprstring); Object value = model.evaluateExpression(unescapedExprstring, Object.class); attributes.put(name, value); } } }
/** * Test method for {@link * VarStrategy#execute(org.jvoicexml.interpreter.VoiceXmlInterpreterContext, * org.jvoicexml.interpreter.VoiceXmlInterpreter, * org.jvoicexml.interpreter.FormInterpretationAlgorithm, org.jvoicexml.interpreter.FormItem, * org.jvoicexml.xml.VoiceXmlNode)} . * * @exception Exception Test failed. * @exception JVoiceXMLEvent test failed */ @Test public void testExecuteExpr() throws Exception, JVoiceXMLEvent { final String name = "test"; final String val = "this is a test"; final Block block = createBlock(); final Value value = block.appendChild(Value.class); value.setExpr(name); final DataModel model = getDataModel(); Mockito.when(model.evaluateExpression(name, Object.class)).thenReturn(val); final ValueStrategy strategy = new ValueStrategy(); executeTagStrategy(value, strategy); final SsmlDocument ssml = new SsmlDocument(); final Speak speak = ssml.getSpeak(); speak.addText("this is a test"); final SpeakableText speakable = new SpeakableSsmlText(ssml); final ImplementationPlatform platform = getContext().getImplementationPlatform(); Mockito.verify(platform).queuePrompt(speakable); }