Search in sources :

Example 1 with Fragment

use of org.apache.sling.scripting.sightly.impl.compiler.frontend.Fragment in project sling by apache.

the class MarkupHandler method requireContext.

private Interpolation requireContext(Interpolation interpolation) {
    Interpolation result = new Interpolation();
    for (Fragment fragment : interpolation.getFragments()) {
        Fragment addedFragment;
        if (fragment.isString()) {
            addedFragment = fragment;
        } else {
            if (fragment.getExpression().containsOption(Syntax.CONTEXT_OPTION)) {
                addedFragment = fragment;
            } else {
                String currentTag = currentElementTag();
                String warningMessage = String.format("Element %s requires that all expressions have an explicit context specified. " + "The expression will be replaced with an empty string.", currentTag);
                stream.warn(new PushStream.StreamMessage(warningMessage, fragment.getExpression().getRawText()));
                addedFragment = new Fragment.Expr(new Expression(StringConstant.EMPTY));
            }
        }
        result.addFragment(addedFragment);
    }
    return result;
}
Also used : Interpolation(org.apache.sling.scripting.sightly.impl.compiler.frontend.Interpolation) Expression(org.apache.sling.scripting.sightly.compiler.expression.Expression) PushStream(org.apache.sling.scripting.sightly.impl.compiler.PushStream) Fragment(org.apache.sling.scripting.sightly.impl.compiler.frontend.Fragment)

Example 2 with Fragment

use of org.apache.sling.scripting.sightly.impl.compiler.frontend.Fragment in project sling by apache.

the class MarkupHandler method attributeChecked.

private Interpolation attributeChecked(String attributeName, Interpolation interpolation) {
    if (!MarkupUtils.isSensitiveAttribute(attributeName)) {
        return interpolation;
    }
    Interpolation newInterpolation = new Interpolation();
    for (Fragment fragment : interpolation.getFragments()) {
        Fragment addedFragment = fragment;
        if (fragment.isExpression()) {
            Expression expression = fragment.getExpression();
            if (!expression.containsOption(Syntax.CONTEXT_OPTION)) {
                String warningMessage = String.format("Expressions within the value of attribute %s need to have an explicit context " + "option. The expression will be replaced with an empty string.", attributeName);
                stream.warn(new PushStream.StreamMessage(warningMessage, expression.getRawText()));
                addedFragment = new Fragment.Text("");
            }
        }
        newInterpolation.addFragment(addedFragment);
    }
    return newInterpolation;
}
Also used : Interpolation(org.apache.sling.scripting.sightly.impl.compiler.frontend.Interpolation) Expression(org.apache.sling.scripting.sightly.compiler.expression.Expression) PushStream(org.apache.sling.scripting.sightly.impl.compiler.PushStream) Fragment(org.apache.sling.scripting.sightly.impl.compiler.frontend.Fragment)

Aggregations

Expression (org.apache.sling.scripting.sightly.compiler.expression.Expression)2 PushStream (org.apache.sling.scripting.sightly.impl.compiler.PushStream)2 Fragment (org.apache.sling.scripting.sightly.impl.compiler.frontend.Fragment)2 Interpolation (org.apache.sling.scripting.sightly.impl.compiler.frontend.Interpolation)2