@Override Object protoFromSoy(SoyValue field) { return field.booleanValue(); } };
@Override Object protoFromSoy(SoyValue field) { return field.booleanValue(); } };
@Override public SoyValue computeForJava(List<SoyValue> args) { SoyValue value = args.get(0); return IntegerData.forValue( BidiFunctionsRuntime.bidiTextDir(value, args.size() == 2 && args.get(1).booleanValue())); }
@Override public SoyValue computeForJava(List<SoyValue> args) { SoyValue value = args.get(0); return UnsafeSanitizedContentOrdainer.ordainAsSafe( BidiFunctionsRuntime.bidiDirAttr( bidiGlobalDirProvider.get(), value, (args.size() == 2 && args.get(1).booleanValue())), ContentKind.ATTRIBUTES); }
@Override public SoyValue computeForJava(List<SoyValue> args) { SoyValue value = args.get(0); boolean isHtml = args.size() == 2 && args.get(1).booleanValue(); String markAfterKnownDir = BidiFunctionsRuntime.bidiMarkAfter(bidiGlobalDirProvider.get(), value, isHtml); return StringData.forValue(markAfterKnownDir); }
@Override boolean isLast(LoopVar loopVar) { return localVariableTable[loopVar.isLastIteratorIndex()].resolve().booleanValue(); }
@Override boolean isLast(LoopVar loopVar) { return localVariableTable[loopVar.isLastIteratorIndex()].resolve().booleanValue(); }
@Override public SoyValue applyForJava(SoyValue value, List<SoyValue> args) { int maxLen; try { maxLen = args.get(0).integerValue(); } catch (SoyDataException sde) { throw new IllegalArgumentException( "Could not parse first parameter of '|truncate' as integer (value was \"" + args.get(0).stringValue() + "\")."); } String str = value.coerceToString(); boolean doAddEllipsis; if (args.size() == 2) { try { doAddEllipsis = args.get(1).booleanValue(); } catch (SoyDataException sde) { throw new IllegalArgumentException( "Could not parse second parameter of '|truncate' as boolean."); } } else { doAddEllipsis = true; // default to true } return StringData.forValue(BasicDirectivesRuntime.truncate(str, maxLen, doAddEllipsis)); }
@Override boolean isLast(LoopVar loopVar) { return doGetProvider(loopVar.name() + "__isLast").resolve().booleanValue(); }
@Override public SoyValue applyForJava(SoyValue value, List<SoyValue> args) { int maxLen; try { maxLen = args.get(0).integerValue(); } catch (SoyDataException sde) { throw new IllegalArgumentException( "Could not parse first parameter of '|truncate' as integer (value was \"" + args.get(0).stringValue() + "\")."); } String str = value.coerceToString(); boolean doAddEllipsis; if (args.size() == 2) { try { doAddEllipsis = args.get(1).booleanValue(); } catch (SoyDataException sde) { throw new IllegalArgumentException( "Could not parse second parameter of '|truncate' as boolean."); } } else { doAddEllipsis = true; // default to true } return StringData.forValue(BasicDirectivesRuntime.truncate(str, maxLen, doAddEllipsis)); }
@Override boolean isLast(LoopVar loopVar) { return doGetProvider(loopVar.name() + "__isLast").resolve().booleanValue(); }
@Override protected void visitVeLogNode(VeLogNode node) { ExprRootNode logonlyExpression = node.getLogonlyExpression(); if (logonlyExpression != null) { if (eval(logonlyExpression, node).booleanValue()) { throw RenderException.createWithSource( "Cannot set logonly=\"true\" unless there is a logger configured, but tofu doesn't " + "support loggers", node); } } visitChildren(node); }
@Override protected void visitVeLogNode(VeLogNode node) { ExprRootNode logonlyExpression = node.getLogonlyExpression(); if (logonlyExpression != null) { if (eval(logonlyExpression, node).booleanValue()) { throw RenderException.createWithSource( "Cannot set logonly=\"true\" unless there is a logger configured, but tofu doesn't " + "support loggers", node); } } visitChildren(node); }
params[i] = value; } else if (type == boolean.class) { params[i] = value.booleanValue(); } else if (type == int.class) { params[i] = value.integerValue();
/** * Converts the input to a JavaScript expression. The resulting expression can be a boolean, * number, string literal, or {@code null}. */ public static String escapeJsValue(SoyValue value) { // We surround values with spaces so that they can't be interpolated into identifiers // by accident. We could use parentheses but those might be interpreted as a function call. if (NullData.INSTANCE == value || value == null) { // The JS counterpart of this code in soyutils.js emits " null " for both null and the special // JS value undefined. return " null "; } else if (value instanceof NumberData) { // This will emit references to NaN and Infinity. Client code should not redefine those // to store sensitive data. return " " + value.numberValue() + " "; } else if (value instanceof BooleanData) { return " " + value.booleanValue() + " "; } else if (isSanitizedContentOfKind(value, SanitizedContent.ContentKind.JS)) { String jsCode = value.coerceToString(); // This value may not be embeddable if it contains the substring "</script". // TODO(msamuel): Fixup. We need to be careful because mucking with '<' can // break code like // while (i</foo/.exec(str).length) // and mucking with / can break // return untrustedHTML.replace(/</g, '<'); return jsCode; } else { return escapeJsValue(value.coerceToString()); } }
/** * Converts the input to a JavaScript expression. The resulting expression can be a boolean, * number, string literal, or {@code null}. */ public static String escapeJsValue(SoyValue value) { // We surround values with spaces so that they can't be interpolated into identifiers // by accident. We could use parentheses but those might be interpreted as a function call. if (NullData.INSTANCE == value || value == null) { // The JS counterpart of this code in soyutils.js emits " null " for both null and the special // JS value undefined. return " null "; } else if (value instanceof NumberData) { // This will emit references to NaN and Infinity. Client code should not redefine those // to store sensitive data. return " " + value.numberValue() + " "; } else if (value instanceof BooleanData) { return " " + value.booleanValue() + " "; } else if (isSanitizedContentOfKind(value, SanitizedContent.ContentKind.JS)) { String jsCode = value.coerceToString(); // This value may not be embeddable if it contains the substring "</script". // TODO(msamuel): Fixup. We need to be careful because mucking with '<' can // break code like // while (i</foo/.exec(str).length) // and mucking with / can break // return untrustedHTML.replace(/</g, '<'); return jsCode; } else { return escapeJsValue(value.coerceToString()); } }