Search in sources :

Example 1 with TextBuilder

use of org.apache.jasper.compiler.ELParser.TextBuilder in project tomcat70 by apache.

the class TestELParser method doTestParser.

private void doTestParser(String input, String expectedResult, String expectedBuilderOutput) throws JasperException {
    ELException elException = null;
    String elResult = null;
    // Don't try and evaluate expressions that depend on variables or functions
    if (expectedResult != null) {
        try {
            ExpressionFactory factory = ExpressionFactory.newInstance();
            ELContext context = new ELContextImpl();
            ValueExpression ve = factory.createValueExpression(context, input, String.class);
            elResult = ve.getValue(context).toString();
            Assert.assertEquals(expectedResult, elResult);
        } catch (ELException ele) {
            elException = ele;
        }
    }
    Nodes nodes = null;
    try {
        nodes = ELParser.parse(input, false);
        Assert.assertNull(elException);
    } catch (IllegalArgumentException iae) {
        Assert.assertNotNull(elResult, elException);
        // Not strictly true but enables us to report both
        iae.initCause(elException);
        throw iae;
    }
    TextBuilder textBuilder = new TextBuilder(false);
    nodes.visit(textBuilder);
    Assert.assertEquals(expectedBuilderOutput, textBuilder.getText());
}
Also used : ELContext(javax.el.ELContext) TextBuilder(org.apache.jasper.compiler.ELParser.TextBuilder) ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) ELException(javax.el.ELException) Nodes(org.apache.jasper.compiler.ELNode.Nodes)

Example 2 with TextBuilder

use of org.apache.jasper.compiler.ELParser.TextBuilder in project tomcat by apache.

the class TestELParser method doTestParser.

private void doTestParser(String input, String expectedResult, String expectedBuilderOutput) throws JasperException {
    ELException elException = null;
    String elResult = null;
    // Don't try and evaluate expressions that depend on variables or functions
    if (expectedResult != null) {
        try {
            ELManager manager = new ELManager();
            ELContext context = manager.getELContext();
            ExpressionFactory factory = ELManager.getExpressionFactory();
            ValueExpression ve = factory.createValueExpression(context, input, String.class);
            elResult = ve.getValue(context).toString();
            Assert.assertEquals(expectedResult, elResult);
        } catch (ELException ele) {
            elException = ele;
        }
    }
    Nodes nodes = null;
    try {
        nodes = ELParser.parse(input, false);
        Assert.assertNull(elException);
    } catch (IllegalArgumentException iae) {
        Assert.assertNotNull(elResult, elException);
        // Not strictly true but enables us to report both
        iae.initCause(elException);
        throw iae;
    }
    TextBuilder textBuilder = new TextBuilder(false);
    nodes.visit(textBuilder);
    Assert.assertEquals(expectedBuilderOutput, textBuilder.getText());
}
Also used : ELContext(jakarta.el.ELContext) TextBuilder(org.apache.jasper.compiler.ELParser.TextBuilder) ExpressionFactory(jakarta.el.ExpressionFactory) ValueExpression(jakarta.el.ValueExpression) ELManager(jakarta.el.ELManager) ELException(jakarta.el.ELException) Nodes(org.apache.jasper.compiler.ELNode.Nodes)

Aggregations

Nodes (org.apache.jasper.compiler.ELNode.Nodes)2 TextBuilder (org.apache.jasper.compiler.ELParser.TextBuilder)2 ELContext (jakarta.el.ELContext)1 ELException (jakarta.el.ELException)1 ELManager (jakarta.el.ELManager)1 ExpressionFactory (jakarta.el.ExpressionFactory)1 ValueExpression (jakarta.el.ValueExpression)1 ELContext (javax.el.ELContext)1 ELException (javax.el.ELException)1 ExpressionFactory (javax.el.ExpressionFactory)1 ValueExpression (javax.el.ValueExpression)1 ELContextImpl (org.apache.jasper.el.ELContextImpl)1