当前位置: 首页>>代码示例>>Java>>正文


Java StringData.forValue方法代码示例

本文整理汇总了Java中com.google.template.soy.data.restricted.StringData.forValue方法的典型用法代码示例。如果您正苦于以下问题:Java StringData.forValue方法的具体用法?Java StringData.forValue怎么用?Java StringData.forValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.template.soy.data.restricted.StringData的用法示例。


在下文中一共展示了StringData.forValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: convertPrimitiveExprToData

import com.google.template.soy.data.restricted.StringData; //导入方法依赖的package包/类
/**
 * Converts a primitive expression node into a primitive data object.
 *
 * @param primitiveNode The primitive expression node to convert.
 * @return The resulting primitive data object.
 */
public static PrimitiveData convertPrimitiveExprToData(PrimitiveNode primitiveNode) {

  if (primitiveNode instanceof StringNode) {
    return StringData.forValue(((StringNode) primitiveNode).getValue());
  } else if (primitiveNode instanceof BooleanNode) {
    return BooleanData.forValue(((BooleanNode) primitiveNode).getValue());
  } else if (primitiveNode instanceof IntegerNode) {
    return IntegerData.forValue(((IntegerNode) primitiveNode).getValue());
  } else if (primitiveNode instanceof FloatNode) {
    return FloatData.forValue(((FloatNode) primitiveNode).getValue());
  } else if (primitiveNode instanceof NullNode) {
    return NullData.INSTANCE;
  } else {
    throw new IllegalArgumentException();
  }
}
 
开发者ID:google,项目名称:closure-templates,代码行数:23,代码来源:InternalValueUtils.java

示例2: applyForJava

import com.google.template.soy.data.restricted.StringData; //导入方法依赖的package包/类
@Override
public SoyValue applyForJava(SoyValue value, List<SoyValue> args) {
  ULocale uLocale = I18nUtils.parseULocale(localeStringProvider.get());
  String formatType = args.isEmpty() ? DEFAULT_FORMAT : args.get(0).stringValue();
  String numbersKeyword = "local";
  if (args.size() > 1) {
    // A keyword for ULocale was passed (like 'native', for instance, to use native characters).
    numbersKeyword = args.get(1).stringValue();
  }

  // Minimum and maximum fraction digits. If only one value was specified, use as both min and max
  // (i.e. significant digits after the decimal point).
  Integer minFractionDigits =
      args.size() > 2 ? Integer.valueOf((int) args.get(2).numberValue()) : null;
  Integer maxFractionDigits =
      args.size() > 3 ? Integer.valueOf((int) args.get(3).numberValue()) : minFractionDigits;

  double number = value.numberValue();
  return StringData.forValue(
      I18NDirectivesRuntime.formatNum(
          uLocale, number, formatType, numbersKeyword, minFractionDigits, maxFractionDigits));
}
 
开发者ID:google,项目名称:closure-templates,代码行数:23,代码来源:FormatNumDirective.java

示例3: filterNoAutoescape

import com.google.template.soy.data.restricted.StringData; //导入方法依赖的package包/类
/**
 * Filters noAutoescape input from explicitly tainted content.
 *
 * <p>SanitizedContent.ContentKind.TEXT is used to explicitly mark input that is never meant to be
 * used unescaped. Specifically, {let} and {param} blocks of kind "text" are explicitly forbidden
 * from being noAutoescaped to avoid XSS regressions during application transition.
 */
public static SoyValue filterNoAutoescape(SoyValue value) {
  value = normalizeNull(value);
  // TODO: Consider also checking for things that are never valid, like null characters.
  if (isSanitizedContentOfKind(value, SanitizedContent.ContentKind.TEXT)) {
    logger.log(
        Level.WARNING,
        "|noAutoescape received value explicitly tagged as ContentKind.TEXT: ''{0}''",
        value);
    return StringData.forValue(EscapingConventions.INNOCUOUS_OUTPUT);
  }
  return value;
}
 
开发者ID:google,项目名称:closure-templates,代码行数:20,代码来源:Sanitizers.java

示例4: plus

import com.google.template.soy.data.restricted.StringData; //导入方法依赖的package包/类
/** Performs the {@code +} operator on the two values. */
public static SoyValue plus(SoyValue operand0, SoyValue operand1) {
  if (operand0 instanceof IntegerData && operand1 instanceof IntegerData) {
    return IntegerData.forValue(operand0.longValue() + operand1.longValue());
  } else if (operand0 instanceof NumberData && operand1 instanceof NumberData) {
    return FloatData.forValue(operand0.numberValue() + operand1.numberValue());
  } else {
    // String concatenation is the fallback for other types (like in JS). Use the implemented
    // coerceToString() for the type.
    return StringData.forValue(operand0.coerceToString() + operand1.coerceToString());
  }
}
 
开发者ID:google,项目名称:closure-templates,代码行数:13,代码来源:SharedRuntime.java

示例5: computeForJava

import com.google.template.soy.data.restricted.StringData; //导入方法依赖的package包/类
@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);
}
 
开发者ID:google,项目名称:closure-templates,代码行数:9,代码来源:BidiMarkAfterFunction.java

示例6: testComputeForJava_endIndex

import com.google.template.soy.data.restricted.StringData; //导入方法依赖的package包/类
@Test
public void testComputeForJava_endIndex() {
  StrSubFunction strSub = new StrSubFunction();
  SoyValue arg0 = StringData.forValue("foobarfoo");
  SoyValue arg1 = IntegerData.forValue(2);
  SoyValue arg2 = IntegerData.forValue(7);
  assertEquals(
      StringData.forValue("obarf"), strSub.computeForJava(ImmutableList.of(arg0, arg1, arg2)));
}
 
开发者ID:google,项目名称:closure-templates,代码行数:10,代码来源:StrSubFunctionTest.java

示例7: testComputeForJava_doesNotContainString

import com.google.template.soy.data.restricted.StringData; //导入方法依赖的package包/类
@Test
public void testComputeForJava_doesNotContainString() {
  StrContainsFunction strContains = new StrContainsFunction();
  SoyValue arg0 = StringData.forValue("foobarfoo");
  SoyValue arg1 = StringData.forValue("baz");
  assertEquals(BooleanData.FALSE, strContains.computeForJava(ImmutableList.of(arg0, arg1)));
}
 
开发者ID:google,项目名称:closure-templates,代码行数:8,代码来源:StrContainsFunctionTest.java

示例8: testMapMethods

import com.google.template.soy.data.restricted.StringData; //导入方法依赖的package包/类
@Test
public void testMapMethods() {
  StringData boo = StringData.forValue("boo");
  Map<String, SoyValueProvider> providerMap = Maps.newHashMap();
  DictImpl dict = DictImpl.forProviderMap(providerMap);
  assertEquals(0, dict.size());
  assertEquals(0, Iterables.size(dict.keys()));
  assertFalse(dict.containsKey(boo));
  assertNull(dict.get(boo));
  assertNull(dict.getProvider(boo));
  providerMap.put("boo", IntegerData.forValue(111));
  assertEquals(1, dict.size());
  assertEquals(1, Iterables.size(dict.keys()));
  assertEquals("boo", Iterables.getOnlyElement(dict.keys()).stringValue());
  providerMap.put("foo", IntegerData.forValue(222));
  providerMap.put("goo", IntegerData.forValue(333));
  assertEquals(3, dict.size());
  assertEquals(3, Iterables.size(dict.keys()));
  assertTrue(dict.containsKey(boo));
  assertEquals(111, dict.get(boo).integerValue());
  assertEquals(111, dict.getProvider(boo).resolve().integerValue());
  providerMap.remove("foo");
  assertEquals(2, dict.size());
  providerMap.remove("boo");
  providerMap.remove("goo");
  assertEquals(0, dict.size());
  assertEquals(0, Iterables.size(dict.keys()));
  assertFalse(dict.containsKey(boo));
  assertNull(dict.get(boo));
  assertNull(dict.getProvider(boo));
}
 
开发者ID:google,项目名称:closure-templates,代码行数:32,代码来源:DictImplTest.java

示例9: testComputeForJava

import com.google.template.soy.data.restricted.StringData; //导入方法依赖的package包/类
@Test
public void testComputeForJava() {
  BidiTextDirFunction bidiTextDirFunction = new BidiTextDirFunction();

  SoyValue text = StringData.EMPTY_STRING;
  assertThat(bidiTextDirFunction.computeForJava(ImmutableList.of(text)))
      .isEqualTo(IntegerData.ZERO);
  text = StringData.forValue("a");
  assertThat(bidiTextDirFunction.computeForJava(ImmutableList.of(text)))
      .isEqualTo(IntegerData.ONE);
  text = StringData.forValue("\u05E0");
  assertThat(bidiTextDirFunction.computeForJava(ImmutableList.of(text)))
      .isEqualTo(IntegerData.MINUS_ONE);

  text = SanitizedContents.unsanitizedText("a");
  assertThat(bidiTextDirFunction.computeForJava(ImmutableList.of(text)))
      .isEqualTo(IntegerData.ONE);
  text = SanitizedContents.unsanitizedText("a", Dir.LTR);
  assertThat(bidiTextDirFunction.computeForJava(ImmutableList.of(text)))
      .isEqualTo(IntegerData.ONE);
  text = SanitizedContents.unsanitizedText("a", Dir.RTL);
  assertThat(bidiTextDirFunction.computeForJava(ImmutableList.of(text)))
      .isEqualTo(IntegerData.MINUS_ONE);
  text = SanitizedContents.unsanitizedText("a", Dir.NEUTRAL);
  assertThat(bidiTextDirFunction.computeForJava(ImmutableList.of(text)))
      .isEqualTo(IntegerData.ZERO);
}
 
开发者ID:google,项目名称:closure-templates,代码行数:28,代码来源:BidiTextDirFunctionTest.java

示例10: testComputeForJava_doesNotContainString

import com.google.template.soy.data.restricted.StringData; //导入方法依赖的package包/类
@Test
public void testComputeForJava_doesNotContainString() {
  StrIndexOfFunction strIndexOf = new StrIndexOfFunction();
  SoyValue arg0 = StringData.forValue("foobarfoo");
  SoyValue arg1 = StringData.forValue("baz");
  assertEquals(IntegerData.forValue(-1), strIndexOf.computeForJava(ImmutableList.of(arg0, arg1)));
}
 
开发者ID:google,项目名称:closure-templates,代码行数:8,代码来源:StrIndexOfFunctionTest.java

示例11: testComputeForJava_containsString

import com.google.template.soy.data.restricted.StringData; //导入方法依赖的package包/类
@Test
public void testComputeForJava_containsString() {
  StrIndexOfFunction strIndexOf = new StrIndexOfFunction();
  SoyValue arg0 = StringData.forValue("foobarfoo");
  SoyValue arg1 = StringData.forValue("bar");
  assertEquals(IntegerData.forValue(3), strIndexOf.computeForJava(ImmutableList.of(arg0, arg1)));
}
 
开发者ID:google,项目名称:closure-templates,代码行数:8,代码来源:StrIndexOfFunctionTest.java

示例12: testComputeForJava_containsString

import com.google.template.soy.data.restricted.StringData; //导入方法依赖的package包/类
@Test
public void testComputeForJava_containsString() {
  StrLenFunction strLen = new StrLenFunction();
  SoyValue arg0 = StringData.forValue("foobarfoo");
  assertEquals(IntegerData.forValue(9), strLen.computeForJava(ImmutableList.of(arg0)));
}
 
开发者ID:google,项目名称:closure-templates,代码行数:7,代码来源:StrLenFunctionTest.java

示例13: computeForJava

import com.google.template.soy.data.restricted.StringData; //导入方法依赖的package包/类
@Override
public SoyValue computeForJava(List<SoyValue> args) {
  return StringData.forValue(BidiFunctionsRuntime.bidiStartEdge(bidiGlobalDirProvider.get()));
}
 
开发者ID:google,项目名称:closure-templates,代码行数:5,代码来源:BidiStartEdgeFunction.java

示例14: applyForJava

import com.google.template.soy.data.restricted.StringData; //导入方法依赖的package包/类
@Override
public SoyValue applyForJava(SoyValue value, List<SoyValue> args) {
  return StringData.forValue(
      BidiDirectivesRuntime.bidiSpanWrap(bidiGlobalDirProvider.get(), value));
}
 
开发者ID:google,项目名称:closure-templates,代码行数:6,代码来源:BidiSpanWrapDirective.java

示例15: applyForJava

import com.google.template.soy.data.restricted.StringData; //导入方法依赖的package包/类
@Override
public SoyValue applyForJava(SoyValue value, List<SoyValue> args) {
  return (value instanceof StringData) ? value : StringData.forValue(value.coerceToString());
}
 
开发者ID:google,项目名称:closure-templates,代码行数:5,代码来源:IdDirective.java


注:本文中的com.google.template.soy.data.restricted.StringData.forValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。