@Override public SoyData compute(List<SoyData> args) { SoyData arg0 = args.get(0); SoyData arg1 = args.get(1); Preconditions.checkArgument(arg0 instanceof StringData, String.format( "First argument to strContains() function is not StringData: %s", arg0.stringValue())); Preconditions.checkArgument(arg1 instanceof StringData, String.format( "Second argument to strContains() function is not StringData: %s", arg1.stringValue())); String strArg0 = arg0.stringValue(); String strArg1 = arg1.stringValue(); return toSoyData(strArg0.contains(strArg1)); }
/** * Precondition: The specified index contains a string. Gets the string at the given index. * * @param index The index. * @return The string at the given index, or null of the index is undefined. */ public String getString(int index) { return get(index).stringValue(); }
/** * Precondition: The specified index contains a string. Gets the string at the given index. * * @param index The index. * @return The string at the given index, or null of the index is undefined. */ public String getString(int index) { return get(index).stringValue(); }
/** * Precondition: The specified index contains a string. * Gets the string at the given index. * @param index The index. * @return The string at the given index, or null of the index is undefined. */ public String getString(int index) { return get(index).stringValue(); }
/** * Precondition: The specified key string is the path to a string. * Gets the string at the specified key string. * @param keyStr One or more map keys and/or list indices (separated by '.' if multiple parts). * Indicates the path to the location within this data tree. * @return The string at the specified key string. * @throws IllegalArgumentException If no data is stored at the specified key. */ public String getString(String keyStr) { SoyData valueData = get(keyStr); if (valueData == null) { throw new IllegalArgumentException("Missing key: " + keyStr); } return valueData.stringValue(); }
/** * Precondition: The specified key string is the path to a string. Gets the string at the * specified key string. * * @param keyStr One or more map keys and/or list indices (separated by '.' if multiple parts). * Indicates the path to the location within this data tree. * @return The string at the specified key string. * @throws IllegalArgumentException If no data is stored at the specified key. */ public String getString(String keyStr) { SoyData valueData = get(keyStr); if (valueData == null) { throw new IllegalArgumentException("Missing key: " + keyStr); } return valueData.stringValue(); }
/** * Precondition: The specified key string is the path to a string. Gets the string at the * specified key string. * * @param keyStr One or more map keys and/or list indices (separated by '.' if multiple parts). * Indicates the path to the location within this data tree. * @return The string at the specified key string. * @throws IllegalArgumentException If no data is stored at the specified key. */ public String getString(String keyStr) { SoyData valueData = get(keyStr); if (valueData == null) { throw new IllegalArgumentException("Missing key: " + keyStr); } return valueData.stringValue(); }
@Override public SoyData compute(List<SoyData> args) { String text = args.get(0).stringValue(); //noinspection SimplifiableConditionalExpression boolean isHtml = (args.size() == 2) ? args.get(1).booleanValue() : false /* default */; return toSoyData(BidiUtils.estimateDirection(text, isHtml).ord); }
@Override public SoyData apply(SoyData value, List<SoyData> args) { Locale locale = I18nUtils.parseLocale(localeStringProvider.get()); NumberFormat instance; String formatType = args.isEmpty() ? "decimal" : args.get(0).stringValue(); if (formatType.equals("decimal")) { instance = NumberFormat.getInstance(locale); } else if (formatType.equals("percent")) { instance = NumberFormat.getPercentInstance(locale); } else if (formatType.equals("currency")) { instance = NumberFormat.getCurrencyInstance(locale); } else if (formatType.equals("scientific")) { instance = NumberFormat.getScientificInstance(locale); } else { throw new IllegalArgumentException( String.format("Unrecognized Number Format Type: {0}", formatType)); } return toSoyData(StringEscapeUtils.escapeHtml4(instance.format(Float.parseFloat(value.stringValue())))); }
@Override public SoyData compute(List<SoyData> args) { String text = args.get(0).stringValue(); @SuppressWarnings("SimplifiableConditionalExpression") // make IntelliJ happy boolean isHtml = (args.size() == 2) ? args.get(1).booleanValue() : false /* default */; int bidiGlobalDir = bidiGlobalDirProvider.get().getStaticValue(); return UnsafeSanitizedContentOrdainer.ordainAsSafe( SoyBidiUtils.getBidiFormatter(bidiGlobalDir).dirAttr(text, isHtml), SanitizedContent.ContentKind.ATTRIBUTES); }
@Override public SoyData compute(List<SoyData> args) { String text = args.get(0).stringValue(); //noinspection SimplifiableConditionalExpression boolean isHtml = (args.size() == 2) ? args.get(1).booleanValue() : false /* default */; int bidiGlobalDir = bidiGlobalDirProvider.get().getStaticValue(); return toSoyData(SoyBidiUtils.getBidiFormatter(bidiGlobalDir).markAfter(text, isHtml)); }
@Override public SoyData computeForJava(List<SoyValue> args) { ArrayList<SoyValue> escapedArgs = new ArrayList<>(); SoyValue i18nKey = args.get(0); escapedArgs.add(i18nKey); for (SoyValue arg : args.subList(1, args.size())) { SoyValue escapedArg = arg instanceof NumberData ? arg : StringData.forValue(Sanitizers.escapeHtml(arg)); escapedArgs.add(escapedArg); } String html = getTextFunction.computeForJava(escapedArgs).stringValue(); // If the i18n key was resolved. Escape it just to be sure if (html.equals(i18nKey.stringValue())) { html = Sanitizers.escapeHtml(html); } return UnsafeSanitizedContentOrdainer.ordainAsSafe(html, SanitizedContent.ContentKind.HTML); } }
throw new IllegalArgumentException( "Could not parse first parameter of '|truncate' as integer (value was \"" + args.get(0).stringValue() + "\").");
@Override protected void visitLetContentNode(LetContentNode node) { SoyData renderedBlock = renderBlock(node); // If the let node has a content kind attribute, it will have been autoescaped in the // corresponding context by the strict contextual autoescaper. Hence, the result of evaluating // the let block is wrapped in SanitizedContent of the specified kind. // TODO: Consider adding mutable state to nodes that allows the contextual escaper to tag // nodes it has processed, and assert presence of this tag here. if (node.getContentKind() != null) { renderedBlock = UnsafeSanitizedContentOrdainer.ordainAsSafe( renderedBlock.stringValue(), node.getContentKind()); } env.peek().put(node.getVarName(), renderedBlock); }
return data.stringValue(); return data == NullData.INSTANCE ? null : data.stringValue();
@Override protected SoyData visitMapLiteralNode(MapLiteralNode node) { Map<String, SoyData> map = Maps.newHashMap(); for (int i = 0, n = node.numChildren(); i < n; i += 2) { SoyData key = visit(node.getChild(i)); if (! (key instanceof StringData)) { throw new RenderException( "Maps must have string keys (key \"" + node.getChild(i).toSourceString() + "\"" + " in map " + node.toSourceString() + " does not evaluate to a string)."); } SoyData value = visit(node.getChild(i + 1)); map.put(key.stringValue(), value); } return new SoyMapData(map); }
@Override protected void visitMsgSelectNode(MsgSelectNode node) { ExprRootNode<?> selectExpr = node.getExpr(); String selectValue; try { selectValue = master.evalForUseByAssistants(selectExpr).stringValue(); } catch (SoyDataException e) { throw new RenderException( String.format("Select expression \"%s\" doesn't evaluate to string.", selectExpr.toSourceString())); } // Check each case. for (CaseOrDefaultNode child : node.getChildren()) { if (child instanceof MsgSelectDefaultNode) { // This means it didn't match any other case. visitChildren(child); } else { if (((MsgSelectCaseNode) child).getCaseValue().equals(selectValue)) { visitChildren(child); return; } } } }
ExprRootNode<?> selectExpr = repSelectNode.getExpr(); try { correctSelectValue = master.evalForUseByAssistants(selectExpr).stringValue(); } catch (SoyDataException e) { throw new RenderException(
} else { try { variant = eval(variantExpr).stringValue(); } catch (SoyDataException e) { throw new RenderException(String.format(
renderedBlock.stringValue(), childCpcn.getContentKind());