Search in sources :

Example 1 with MethodRef

use of com.google.template.soy.jbcsrc.restricted.MethodRef in project closure-templates by google.

the class BasicEscapeDirective method applyForJbcSrc.

@Override
public SoyExpression applyForJbcSrc(JbcSrcPluginContext context, SoyExpression value, List<SoyExpression> args) {
    MethodRef sanitizerMethod = javaSoyValueSanitizer;
    if (sanitizerMethod == null) {
        // lazily allocated
        sanitizerMethod = MethodRef.create(Sanitizers.class, name.substring(1), SoyValue.class).asNonNullable();
        javaSoyValueSanitizer = sanitizerMethod;
    }
    // about the content kind of the string.
    return SoyExpression.forString(sanitizerMethod.invoke(value.box()));
}
Also used : MethodRef(com.google.template.soy.jbcsrc.restricted.MethodRef)

Example 2 with MethodRef

use of com.google.template.soy.jbcsrc.restricted.MethodRef in project closure-templates by google.

the class BasicEscapeDirective method applyForJbcSrcStreaming.

/**
 * Default implementation for {@link Streamable}.
 *
 * <p>Subclasses can simply add {@code implements Streamable} if they have an implementation in
 * Sanitizers.<name>Streaming. If they don't, this method will throw while trying to find it.
 */
public final AppendableAndOptions applyForJbcSrcStreaming(JbcSrcPluginContext context, Expression delegateAppendable, List<SoyExpression> args) {
    MethodRef sanitizerMethod = javaStreamingSanitizer;
    if (sanitizerMethod == null) {
        // lazily allocated
        sanitizerMethod = MethodRef.create(Sanitizers.class, name.substring(1) + "Streaming", LoggingAdvisingAppendable.class).asNonNullable();
        javaStreamingSanitizer = sanitizerMethod;
    }
    Expression streamingSanitizersExpr = sanitizerMethod.invoke(delegateAppendable);
    if (isCloseable()) {
        return AppendableAndOptions.createCloseable(streamingSanitizersExpr);
    } else {
        return AppendableAndOptions.create(streamingSanitizersExpr);
    }
}
Also used : MethodRef(com.google.template.soy.jbcsrc.restricted.MethodRef) SoyExpression(com.google.template.soy.jbcsrc.restricted.SoyExpression) Expression(com.google.template.soy.jbcsrc.restricted.Expression)

Aggregations

MethodRef (com.google.template.soy.jbcsrc.restricted.MethodRef)2 Expression (com.google.template.soy.jbcsrc.restricted.Expression)1 SoyExpression (com.google.template.soy.jbcsrc.restricted.SoyExpression)1