Search in sources :

Example 6 with RuntimeCall

use of org.apache.sling.scripting.sightly.compiler.expression.nodes.RuntimeCall in project sling by apache.

the class ExpressionWrapperTest method testJoinOptionsRemoval.

@Test
public void testJoinOptionsRemoval() {
    Interpolation interpolation = new Interpolation();
    Map<String, ExpressionNode> options = new HashMap<>();
    options.put(JoinFilter.JOIN_OPTION, new StringConstant(";"));
    List<ExpressionNode> array = new ArrayList<>();
    array.add(new NumericConstant(0));
    array.add(new NumericConstant(1));
    interpolation.addExpression(new Expression(new ArrayLiteral(array), options));
    ExpressionWrapper wrapper = new ExpressionWrapper(filters);
    Expression result = wrapper.transform(interpolation, MarkupContext.TEXT, ExpressionContext.TEXT);
    List<ExpressionNode> xssArguments = runOptionsAndXSSAssertions(result, 0);
    RuntimeCall join = (RuntimeCall) xssArguments.get(0);
    assertEquals(RuntimeFunction.JOIN, join.getFunctionName());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RuntimeCall(org.apache.sling.scripting.sightly.compiler.expression.nodes.RuntimeCall) ArrayLiteral(org.apache.sling.scripting.sightly.compiler.expression.nodes.ArrayLiteral) Interpolation(org.apache.sling.scripting.sightly.impl.compiler.frontend.Interpolation) Expression(org.apache.sling.scripting.sightly.compiler.expression.Expression) ExpressionNode(org.apache.sling.scripting.sightly.compiler.expression.ExpressionNode) NumericConstant(org.apache.sling.scripting.sightly.compiler.expression.nodes.NumericConstant) StringConstant(org.apache.sling.scripting.sightly.compiler.expression.nodes.StringConstant) ExpressionWrapper(org.apache.sling.scripting.sightly.impl.compiler.frontend.ExpressionWrapper) Test(org.junit.Test)

Example 7 with RuntimeCall

use of org.apache.sling.scripting.sightly.compiler.expression.nodes.RuntimeCall in project sling by apache.

the class IncludePlugin method invoke.

@Override
public PluginInvoke invoke(final Expression expression, final PluginCallInfo callInfo, final CompilerContext compilerContext) {
    return new DefaultPluginInvoke() {

        @Override
        public void beforeChildren(PushStream stream) {
            String includedContentVar = compilerContext.generateVariable("includedResult");
            String pathVar = compilerContext.generateVariable("includePath");
            stream.write(new VariableBinding.Start(pathVar, expression.getRoot()));
            stream.write(new VariableBinding.Start(includedContentVar, new RuntimeCall(RuntimeFunction.INCLUDE, new Identifier(pathVar), new MapLiteral(expression.getOptions()))));
            stream.write(new OutputVariable(includedContentVar));
            //end includedContentVar
            stream.write(VariableBinding.END);
            //end pathVar
            stream.write(VariableBinding.END);
            Patterns.beginStreamIgnore(stream);
        }

        @Override
        public void afterChildren(PushStream stream) {
            Patterns.endStreamIgnore(stream);
        }
    };
}
Also used : MapLiteral(org.apache.sling.scripting.sightly.compiler.expression.nodes.MapLiteral) Identifier(org.apache.sling.scripting.sightly.compiler.expression.nodes.Identifier) PushStream(org.apache.sling.scripting.sightly.impl.compiler.PushStream) RuntimeCall(org.apache.sling.scripting.sightly.compiler.expression.nodes.RuntimeCall) VariableBinding(org.apache.sling.scripting.sightly.compiler.commands.VariableBinding) OutputVariable(org.apache.sling.scripting.sightly.compiler.commands.OutputVariable)

Example 8 with RuntimeCall

use of org.apache.sling.scripting.sightly.compiler.expression.nodes.RuntimeCall in project sling by apache.

the class ExpressionWrapperTest method testFormatOptionsRemoval.

@Test
public void testFormatOptionsRemoval() {
    Interpolation interpolation = new Interpolation();
    Map<String, ExpressionNode> options = new HashMap<>();
    List<ExpressionNode> formatArray = new ArrayList<>();
    formatArray.add(new StringConstant("John"));
    formatArray.add(new StringConstant("Doe"));
    options.put(FormatFilter.FORMAT_OPTION, new ArrayLiteral(formatArray));
    interpolation.addExpression(new Expression(new StringConstant("Hello {0} {1}"), options));
    ExpressionWrapper wrapper = new ExpressionWrapper(filters);
    Expression result = wrapper.transform(interpolation, MarkupContext.TEXT, ExpressionContext.TEXT);
    List<ExpressionNode> xssArguments = runOptionsAndXSSAssertions(result, 0);
    RuntimeCall format = (RuntimeCall) xssArguments.get(0);
    assertEquals(RuntimeFunction.FORMAT, format.getFunctionName());
}
Also used : Interpolation(org.apache.sling.scripting.sightly.impl.compiler.frontend.Interpolation) HashMap(java.util.HashMap) Expression(org.apache.sling.scripting.sightly.compiler.expression.Expression) ExpressionNode(org.apache.sling.scripting.sightly.compiler.expression.ExpressionNode) ArrayList(java.util.ArrayList) RuntimeCall(org.apache.sling.scripting.sightly.compiler.expression.nodes.RuntimeCall) StringConstant(org.apache.sling.scripting.sightly.compiler.expression.nodes.StringConstant) ArrayLiteral(org.apache.sling.scripting.sightly.compiler.expression.nodes.ArrayLiteral) ExpressionWrapper(org.apache.sling.scripting.sightly.impl.compiler.frontend.ExpressionWrapper) Test(org.junit.Test)

Example 9 with RuntimeCall

use of org.apache.sling.scripting.sightly.compiler.expression.nodes.RuntimeCall in project sling by apache.

the class ExpressionWrapperTest method runOptionsAndXSSAssertions.

private List<ExpressionNode> runOptionsAndXSSAssertions(Expression result, int expectedOptions) {
    assertEquals("Options map size for expression after processing is different from expected.", expectedOptions, result.getOptions().size());
    RuntimeCall xss = (RuntimeCall) result.getRoot();
    assertEquals("Expected XSS escaping applied to expression.", RuntimeFunction.XSS, xss.getFunctionName());
    return xss.getArguments();
}
Also used : RuntimeCall(org.apache.sling.scripting.sightly.compiler.expression.nodes.RuntimeCall)

Example 10 with RuntimeCall

use of org.apache.sling.scripting.sightly.compiler.expression.nodes.RuntimeCall in project sling by apache.

the class ExpressionReducer method evaluate.

@Override
public EvalResult evaluate(RuntimeCall runtimeCall) {
    List<ExpressionNode> nodes = new ArrayList<>();
    for (ExpressionNode node : runtimeCall.getArguments()) {
        EvalResult result = eval(node);
        nodes.add(result.getNode());
    }
    return EvalResult.nonConstant(new RuntimeCall(runtimeCall.getFunctionName(), nodes));
}
Also used : ExpressionNode(org.apache.sling.scripting.sightly.compiler.expression.ExpressionNode) ArrayList(java.util.ArrayList) RuntimeCall(org.apache.sling.scripting.sightly.compiler.expression.nodes.RuntimeCall)

Aggregations

RuntimeCall (org.apache.sling.scripting.sightly.compiler.expression.nodes.RuntimeCall)11 ExpressionNode (org.apache.sling.scripting.sightly.compiler.expression.ExpressionNode)7 HashMap (java.util.HashMap)5 Expression (org.apache.sling.scripting.sightly.compiler.expression.Expression)5 MapLiteral (org.apache.sling.scripting.sightly.compiler.expression.nodes.MapLiteral)5 StringConstant (org.apache.sling.scripting.sightly.compiler.expression.nodes.StringConstant)5 ArrayList (java.util.ArrayList)4 VariableBinding (org.apache.sling.scripting.sightly.compiler.commands.VariableBinding)4 ExpressionWrapper (org.apache.sling.scripting.sightly.impl.compiler.frontend.ExpressionWrapper)4 Interpolation (org.apache.sling.scripting.sightly.impl.compiler.frontend.Interpolation)4 Test (org.junit.Test)4 OutputVariable (org.apache.sling.scripting.sightly.compiler.commands.OutputVariable)3 ArrayLiteral (org.apache.sling.scripting.sightly.compiler.expression.nodes.ArrayLiteral)3 PushStream (org.apache.sling.scripting.sightly.impl.compiler.PushStream)3 Identifier (org.apache.sling.scripting.sightly.compiler.expression.nodes.Identifier)2 NumericConstant (org.apache.sling.scripting.sightly.compiler.expression.nodes.NumericConstant)2 Map (java.util.Map)1 Conditional (org.apache.sling.scripting.sightly.compiler.commands.Conditional)1 MarkupContext (org.apache.sling.scripting.sightly.compiler.expression.MarkupContext)1 BinaryOperation (org.apache.sling.scripting.sightly.compiler.expression.nodes.BinaryOperation)1