/** * Private helper to convert a string result. * * @param s The string to convert. */ private SoyValue convertResult(String s) { return StringData.forValue(s); }
@Override public String stringValue() { return getValue(); }
/** * Gets a StringData instance for the given value. * * @param value The desired value. * @return A StringData instance with the given value. */ public static StringData forValue(String value) { return (value.length() == 0) ? EMPTY_STRING : new StringData(value); }
@Override public SoyData computeForJava(List<SoyValue> args) { SoyValue data = args.get(0); if (!(data instanceof StringData)) { throw SoySyntaxException.createWithoutMetaInfo("Argument to getText() is not a literal string"); } List<SoyValue> params = args.subList(1, args.size()); StringData stringData = (StringData) data; String text = i18nResolver.getText(stringData.getValue(), transformSoyDataListToSerializableArray(params)); return StringData.forValue(text); }
@Override public int hashCode() { // Keep this in sync with UnsanitizedString#hashCode so that StringData and UnsanitizedString // can be used interchangeably. return stringValue().hashCode(); } }
@Override public String coerceToString() { return toString(); }
private SoyValue renderRenderUnitNode(final RenderUnitNode renderUnitNode) { RenderableThunk thunk = new RenderableThunk() { @Override protected void doRender(Appendable appendable) throws IOException { renderBlock(renderUnitNode, appendable); } }; SanitizedContentKind contentKind = renderUnitNode.getContentKind(); if (contentKind != null) { return LazySanitizedContents.forThunk(thunk, ContentKind.valueOf(contentKind.name())); } else { return StringData.forThunk(thunk); } }
@Override public SoyData computeForTofu(List<SoyData> args) { SoyData data = args.get(0); if (!(data instanceof StringData)) { throw new SoySyntaxException("Argument to getText() is not a literal string"); } List<SoyData> params = args.subList(1, args.size()); StringData stringData = (StringData) data; String text = i18nResolver.getText(stringData.getValue(), transformSoyDataListToSerializableArray(params)); return StringData.forValue(text); }
@Override public boolean equals(@Nullable Object other) { // TODO(user): js uses reference equality, this uses content comparison if (other instanceof StringData) { // So that StringData and UnsanitizedString can be used interchangeably. Keep this in sync // with StringData#equals. return ((StringData) other).stringValue().equals(this.getContent()); } return other instanceof UnsanitizedString && this.getContentDirection() == ((SanitizedContent) other).getContentDirection() && this.getContent().equals(((UnsanitizedString) other).getContent()); }
@Override public String coerceToString() { return toString(); }
@Override public SoyValue apply(String input) { return StringData.forValue(input); } });
@Override public String toString() { return getValue(); }
/** * Gets a StringData instance for the given value. * @param value The desired value. * @return A StringData instance with the given value. */ public static StringData forValue(String value) { return (value.length() == 0) ? EMPTY_STRING : new StringData(value); }
@Override public SoyValue apply(String key) { return StringData.forValue(key); } });
@Override public String stringValue() { return getValue(); }
@Override public SoyValue apply(String key) { return StringData.forValue(key); } });
@Override public String toString() { return getValue(); }
@Override public SoyValue apply(String key) { return StringData.forValue(key); } });
/** * {@inheritDoc} * * <p>The empty string is falsy. */ @Override public boolean coerceToBoolean() { return getValue().length() > 0; }
/** * For any resource string/variable which has |blessStringAsTrustedResuorceUrlForLegacy directive * return the input value as is after converting it into SoyValue. */ public static SoyValue blessStringAsTrustedResourceUrlForLegacy(String value) { return StringData.forValue(value); }