Example usage for org.apache.commons.lang3 StringEscapeUtils unescapeXml

List of usage examples for org.apache.commons.lang3 StringEscapeUtils unescapeXml

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringEscapeUtils unescapeXml.

Prototype

public static final String unescapeXml(final String input) 

Source Link

Document

Unescapes a string containing XML entity escapes to a string containing the actual Unicode characters corresponding to the escapes.

Supports only the five basic XML entities (gt, lt, quot, amp, apos).

Usage

From source file:org.jvoicexml.interpreter.event.AbstractEventStrategy.java

/**
 * {@inheritDoc}/*from w w  w. j  av a  2 s  . c o  m*/
 */
@Override
public final boolean isActive() throws SemanticError {
    if (!(node instanceof AbstractCatchElement)) {
        return true;
    }
    final AbstractCatchElement catchElement = (AbstractCatchElement) node;
    final String cond = catchElement.getCond();
    if (cond == null) {
        return true;
    }
    final DataModel model = context.getDataModel();
    final String unescapedCond = StringEscapeUtils.unescapeXml(cond);
    return model.evaluateExpression(unescapedCond, Boolean.class);
}

From source file:org.jvoicexml.interpreter.formitem.AbstractFormItem.java

/**
 * {@inheritDoc}/*ww  w  .  j  a  va 2 s .  c o  m*/
 */
@Override
public final Object evaluateExpression(final DataModel model) throws SemanticError {
    final String expr = node.getAttribute("expr");
    final String unescapedExpr = StringEscapeUtils.unescapeXml(expr);
    return model.evaluateExpression(unescapedExpr, Object.class);
}

From source file:org.jvoicexml.interpreter.formitem.AbstractFormItem.java

/**
 * {@inheritDoc}// ww w.j  av a  2 s.co  m
 */
@Override
public boolean evaluateCondition() throws SemanticError {
    final String condAttribute = node.getAttribute("cond");
    if (condAttribute == null) {
        return true;
    }
    final String unescapedCond = StringEscapeUtils.unescapeXml(condAttribute);
    final DataModel model = context.getDataModel();
    return model.evaluateExpression(unescapedCond, Boolean.class);
}

From source file:org.jvoicexml.interpreter.formitem.TransferFormItem.java

/**
 * Retrieves the destination of this transfer by evaluating the
 * <code>dest</code> and the <code>destexpr</code> attributes.
 * /*from www.  ja v a  2 s . co  m*/
 * @return destination of this transfer.
 * @throws SemanticError
 *             Error evaluating the <code>destexpr</code> attribute.
 * @throws BadFetchError
 *             No destination specified.
 * @since 0.7 TODO evaluate the telephone URI after RFC2806
 */
public String getDest() throws SemanticError, BadFetchError {
    final Transfer transfer = getTransfer();
    if (transfer == null) {
        return null;
    }
    String dest = transfer.getDest();
    if (dest != null) {
        return dest;
    }
    dest = transfer.getDestexpr();
    if (dest == null) {
        throw new BadFetchError("Either one of \"dest\" or \"destexpr\"" + " must be specified!");
    }
    final String unescapedDestexpr = StringEscapeUtils.unescapeXml(dest);
    final VoiceXmlInterpreterContext context = getContext();
    final DataModel model = context.getDataModel();
    return model.evaluateExpression(unescapedDestexpr, String.class);
}

From source file:org.jvoicexml.interpreter.grammar.GrammarLoader.java

/**
 * Retrieves the URI from the grammar node by either returning the src
 * attribute or by evaluating the srcexpr attribute.
 * /*  www . j  a va  2  s . co  m*/
 * @param grammar
 *            the current grammar node
 * @param context
 *            the VoiceXML interpreter context
 * @return grammar URI, <code>null</code> if there is no value defined
 * @throws URISyntaxException
 *             error creating an URI from the attribute
 * @throws SemanticError
 *             error evaluating the srcexpr attribute
 * @throws BadFetchError
 *             both, src and srcexpr were specified
 * @since 0.7.4
 */
private URI getExternalUriSrc(final Grammar grammar, final VoiceXmlInterpreterContext context)
        throws URISyntaxException, SemanticError, BadFetchError {
    final URI src = grammar.getSrcUri();
    if (src != null) {
        return src;
    }
    final String srcexpr = grammar.getSrcexpr();
    if (srcexpr == null) {
        LOGGER.warn("unable to resolve the external URI: " + "neither a src nor a srcexpr found");
        return null;
    }
    final String unescapedSrcexpr = StringEscapeUtils.unescapeXml(srcexpr);
    final DataModel model = context.getDataModel();
    final String value = model.evaluateExpression(unescapedSrcexpr, String.class);
    if ((value == null) || (value == model.getUndefinedValue())) {
        LOGGER.warn("srcexpr does not describe a valid uri");
        return null;
    }
    return new URI(value);
}

From source file:org.jvoicexml.interpreter.ParamParser.java

/**
 * Retrieve all parameters defined in the current tag.
 * //from  w  w  w. java2 s .com
 * @return Mapping of parameter names to their values.
 * @throws SemanticError
 *             Error evaluating an expression of a
 *             <code>&lt;param&gt;</code> tag.
 * @throws BadFetchError
 *             A param tag features neither a value nor an expr attribute.
 */
public Map<String, Object> getParameters() throws SemanticError, BadFetchError {
    final Collection<Param> paramtags = node.getChildNodes(Param.class);

    final Map<String, Object> parameters = new java.util.HashMap<String, Object>();

    for (Param param : paramtags) {
        final String name = param.getName();
        Object value = param.getValue();
        if (value == null) {
            final String expr = param.getExpr();
            if (expr == null) {
                throw new BadFetchError(
                        "Exactly one of \"value\" or " + "\"expr\" must be specified in a param tag!");
            }
            final String unescapedExpr = StringEscapeUtils.unescapeXml(expr);
            value = model.evaluateExpression(unescapedExpr, Object.class);
        } else {
            final ParamValueType valueType = param.getValuetype();
            if (valueType == ParamValueType.REF) {
                final URI uri;
                try {
                    uri = new URI(value.toString());
                } catch (URISyntaxException e) {
                    throw new BadFetchError("'" + value + "' is not a valid URI");
                }
                final String type = param.getType();
                final DocumentDescriptor descriptor = new DocumentDescriptor(uri);
                value = server.getObject(sessionId, descriptor, type);
            }
        }
        parameters.put(name, value);
    }

    return parameters;
}

From source file:org.jvoicexml.interpreter.ParamParser.java

/**
 * Retrieve all parameters defined in the current tag.
 * /*from ww  w  . j a  va2 s . c om*/
 * @return collection of all parameters.
 * @throws SemanticError
 *             Error evaluating an expression of a
 *             <code>&lt;param&gt;</code> tag.
 * @throws BadFetchError
 *             A <code>&lt;param&gt;</code> tag features neither a value nor
 *             an <code>expr</code> attribute.
 */
public Collection<Object> getParameterValues() throws SemanticError, BadFetchError {
    final Collection<Param> paramtags = node.getChildNodes(Param.class);

    final Collection<Object> parameters = new java.util.ArrayList<Object>();

    for (Param param : paramtags) {
        Object value = param.getValue();
        if (value == null) {
            final String expr = param.getExpr();
            if (expr == null) {
                throw new BadFetchError(
                        "Exactly one of \"value\" or " + "\"expr\" must be specified in a param tag!");
            }
            final String unescapedExpr = StringEscapeUtils.unescapeXml(expr);
            value = model.evaluateExpression(unescapedExpr, Object.class);
        } else {
            final ParamValueType valueType = param.getValuetype();
            if (valueType == ParamValueType.REF) {
                final URI uri;
                try {
                    uri = new URI(value.toString());
                } catch (URISyntaxException e) {
                    throw new BadFetchError("'" + value + "' is not a valid URI");
                }
                final String type = param.getType();
                final DocumentDescriptor descriptor = new DocumentDescriptor(uri);
                value = server.getObject(sessionId, descriptor, type);
            }
        }
        parameters.add(value);
    }

    return parameters;
}

From source file:org.jvoicexml.interpreter.PromptChooser.java

/**
 * Remove from this list all prompts whose cond evaluates to false after
 * conversion to boolean./*from w  ww . j a v  a  2s. c o m*/
 *
 * @param prompts Collection of prompts to be filtered.
 * @return list of filtered prompts.
 *
 * @exception SemanticError
 *            Error evaluating the condition.
 */
private Collection<Prompt> filterCond(final Collection<Prompt> prompts) throws SemanticError {
    final Collection<Prompt> filteredPrompts = new java.util.ArrayList<Prompt>();
    final DataModel model = context.getDataModel();
    for (Prompt prompt : prompts) {
        final String cond = prompt.getCond();
        final String unescapedCond = StringEscapeUtils.unescapeXml(cond);
        final boolean result = model.evaluateExpression(unescapedCond, Boolean.class);
        if (result) {
            filteredPrompts.add(prompt);
        }
    }

    return filteredPrompts;
}

From source file:org.jvoicexml.interpreter.SubdialogExecutorThread.java

/**
 * Creates the value for the returned result.
 * /* ww  w. j a va  2 s  . c om*/
 * @param event
 *            caught event.
 * @return return result.
 * @throws SemanticError
 *             if a variable could not be evaluated
 */
private Object getReturnObject(final ReturnEvent event) throws SemanticError {
    final StringBuilder str = new StringBuilder();
    str.append("var out = new Object();");
    final Map<String, Object> variables = event.getVariables();
    for (String name : variables.keySet()) {
        str.append("out.");
        str.append(name);
        str.append(" = ");
        final Object value = variables.get(name);
        if (value instanceof String) {
            str.append("\"");
            str.append(value);
            str.append("\"");
        } else {
            str.append(value);
        }
        str.append(";");
    }
    final DataModel model = context.getDataModel();
    final String expr = str.toString();
    final String unescapedExpr = StringEscapeUtils.unescapeXml(expr);
    model.evaluateExpression(unescapedExpr, Object.class);
    return model.readVariable("out", Object.class);
}

From source file:org.jvoicexml.profile.vxml21.tagstrategy.AbstractSsmlParsingStrategy.java

/**
 * {@inheritDoc}/*from w ww .j av  a2 s.  c o m*/
 */
@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);
        }
    }
}