當前位置: 首頁>>代碼示例>>Java>>正文


Java UnsafeSanitizedContentOrdainer.ordainAsSafe方法代碼示例

本文整理匯總了Java中com.google.template.soy.data.UnsafeSanitizedContentOrdainer.ordainAsSafe方法的典型用法代碼示例。如果您正苦於以下問題:Java UnsafeSanitizedContentOrdainer.ordainAsSafe方法的具體用法?Java UnsafeSanitizedContentOrdainer.ordainAsSafe怎麽用?Java UnsafeSanitizedContentOrdainer.ordainAsSafe使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.template.soy.data.UnsafeSanitizedContentOrdainer的用法示例。


在下文中一共展示了UnsafeSanitizedContentOrdainer.ordainAsSafe方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getTemplateData

import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //導入方法依賴的package包/類
static SoyMapData getTemplateData(String canonicalURL, String cdnPath, String faviconPath)
    throws URISyntaxException {
  String canonicalPath = computeCanonicalPath(canonicalURL);

  String staticPath = "";
  if (cdnPath != null) {
    staticPath = cdnPath;
  } else if (canonicalPath != null) {
    staticPath = canonicalPath;
  }

  // The resource path must be typed as safe for use in a script src.
  // TODO(wyatta): Upgrade this to use an appropriate safe URL type.
  SanitizedContent sanitizedStaticPath =
      UnsafeSanitizedContentOrdainer.ordainAsSafe(
          staticPath, SanitizedContent.ContentKind.TRUSTED_RESOURCE_URI);

  return new SoyMapData(
      "canonicalPath", canonicalPath,
      "staticResourcePath", sanitizedStaticPath,
      "faviconPath", faviconPath);
}
 
開發者ID:gerrit-review,項目名稱:gerrit,代碼行數:23,代碼來源:IndexServlet.java

示例2: strictContinuation

import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //導入方法依賴的package包/類
/**
 * Return a {@link SanitizedContent} valued continuation. Rendering logic is delegated to the
 * {@link WriteContinuation}, but it is assumed that the builder is the render target.
 */
static Continuation<SanitizedContent> strictContinuation(
    WriteContinuation delegate,
    final StringBuilder buffer,
    OutputAppendable appendable,
    final ContentKind kind) {
  if (delegate.result().isDone()) {
    return new ResultContinuation<>(
        UnsafeSanitizedContentOrdainer.ordainAsSafe(buffer.toString(), kind));
  }
  return new AbstractContinuation<SanitizedContent>(delegate, appendable) {
    @Override
    Continuation<SanitizedContent> nextContinuation(WriteContinuation next) {
      return strictContinuation(next, buffer, appendable, kind);
    }
  };
}
 
開發者ID:google,項目名稱:closure-templates,代碼行數:21,代碼來源:Continuations.java

示例3: render

import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //導入方法依賴的package包/類
@Override
public RenderResult render(LoggingAdvisingAppendable appendable, RenderContext context)
    throws IOException {
  RenderResult result = delegate.render(buffer, context);
  if (result.isDone()) {
    SoyValue resultData =
        kind == null
            ? StringData.forValue(buffer.toString())
            : UnsafeSanitizedContentOrdainer.ordainAsSafe(buffer.toString(), kind);
    for (SoyJavaPrintDirective directive : directives) {
      resultData = directive.applyForJava(resultData, ImmutableList.<SoyValue>of());
    }
    appendable.append(resultData.coerceToString());
  }
  return result;
}
 
開發者ID:google,項目名稱:closure-templates,代碼行數:17,代碼來源:JbcSrcRuntime.java

示例4: getResolvedValue

import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //導入方法依賴的package包/類
private SoyString getResolvedValue() {
  SoyString local = resolvedValue;
  if (local == null) {
    if (buffer != null) {
      String string = buffer.toString();
      // This drops logs, but that is sometimes necessary.  We should make sure this only happens
      // when it has to by making sure that renderAndResolve is used for all printing usecases
      if (contentKind != null) {
        local = UnsafeSanitizedContentOrdainer.ordainAsSafe(string, contentKind);
      } else {
        local = StringData.forValue(string);
      }
      resolvedValue = local;
    } else {
      throw new AssertionError("getResolvedValue() should only be called if the value isDone.");
    }
  }
  return local;
}
 
開發者ID:google,項目名稱:closure-templates,代碼行數:20,代碼來源:DetachableContentProvider.java

示例5: renderStrict

import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //導入方法依賴的package包/類
@Override
public SanitizedContent renderStrict() {
  StringBuilder sb = new StringBuilder();
  TemplateNode template =
      baseTofu.renderMain(
          sb,
          templateName,
          data,
          ijData,
          activeDelPackageNames,
          msgBundle,
          idRenamingMap,
          cssRenamingMap,
          debugSoyTemplateInfo);
  enforceContentKind(template);
  // Use the expected instead of actual content kind; that way, if an HTML template is rendered
  // as TEXT, we will return TEXT.
  return UnsafeSanitizedContentOrdainer.ordainAsSafe(sb.toString(), expectedContentKind);
}
 
開發者ID:google,項目名稱:closure-templates,代碼行數:20,代碼來源:BaseTofu.java

示例6: escapeHtml

import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //導入方法依賴的package包/類
public static SanitizedContent escapeHtml(SoyValue value) {
  if (value == null) {
    // jbcsrc uses null as null.
    value = NullData.INSTANCE;
  }
  Dir valueDir = null;
  if (value instanceof SanitizedContent) {
    SanitizedContent sanitizedContent = (SanitizedContent) value;
    if (sanitizedContent.getContentKind() == SanitizedContent.ContentKind.HTML) {
      return (SanitizedContent) value;
    }
    valueDir = sanitizedContent.getContentDirection();
  }
  return UnsafeSanitizedContentOrdainer.ordainAsSafe(
      EscapingConventions.EscapeHtml.INSTANCE.escape(value.coerceToString()),
      SanitizedContent.ContentKind.HTML,
      valueDir);
}
 
開發者ID:google,項目名稱:closure-templates,代碼行數:19,代碼來源:CoreDirectivesRuntime.java

示例7: changeNewlineToBr

import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //導入方法依賴的package包/類
public static SoyString changeNewlineToBr(SoyValue value) {
  String result = NEWLINE_PATTERN.matcher(coerceToString(value)).replaceAll("<br>");

  // Make sure to transmit the known direction, if any, to any downstream directive that may need
  // it, e.g. BidiSpanWrapDirective. Since a known direction is carried only by SanitizedContent,
  // and the transformation we make is only valid in HTML, we only transmit the direction when we
  // get HTML SanitizedContent.
  // TODO(user): Consider always returning HTML SanitizedContent.
  if (value instanceof SanitizedContent) {
    SanitizedContent sanitizedContent = (SanitizedContent) value;
    if (sanitizedContent.getContentKind() == ContentKind.HTML) {
      return UnsafeSanitizedContentOrdainer.ordainAsSafe(
          result, ContentKind.HTML, sanitizedContent.getContentDirection());
    }
  }
  return StringData.forValue(result);
}
 
開發者ID:google,項目名稱:closure-templates,代碼行數:18,代碼來源:BasicDirectivesRuntime.java

示例8: insertWordBreaks

import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //導入方法依賴的package包/類
public static SoyString insertWordBreaks(SoyValue value, int maxCharsBetweenWordBreaks) {
  String result =
      new InsertWordBreaks(maxCharsBetweenWordBreaks).processString(coerceToString(value));

  // Make sure to transmit the known direction, if any, to any downstream directive that may need
  // it, e.g. BidiSpanWrapDirective. Since a known direction is carried only by SanitizedContent,
  // and the transformation we make is only valid in HTML, we only transmit the direction when we
  // get HTML SanitizedContent.
  // TODO(user): Consider always returning HTML SanitizedContent.
  if (value instanceof SanitizedContent) {
    SanitizedContent sanitizedContent = (SanitizedContent) value;
    if (sanitizedContent.getContentKind() == ContentKind.HTML) {
      return UnsafeSanitizedContentOrdainer.ordainAsSafe(
          result, ContentKind.HTML, sanitizedContent.getContentDirection());
    }
  }

  return StringData.forValue(result);
}
 
開發者ID:google,項目名稱:closure-templates,代碼行數:20,代碼來源:BasicDirectivesRuntime.java

示例9: cleanHtml

import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //導入方法依賴的package包/類
/**
 * Normalizes the input HTML of a given directionality while preserving "safe" tags.
 *
 * @param optionalSafeTags to add to the basic whitelist of formatting safe tags
 * @return the normalized input, in the form of {@link SanitizedContent} of {@link
 *     ContentKind#HTML}
 */
public static SanitizedContent cleanHtml(
    String value, Dir contentDir, Collection<? extends OptionalSafeTag> optionalSafeTags) {
  return UnsafeSanitizedContentOrdainer.ordainAsSafe(
      stripHtmlTags(value, TagWhitelist.FORMATTING.withOptionalSafeTags(optionalSafeTags), true),
      ContentKind.HTML,
      contentDir);
}
 
開發者ID:google,項目名稱:closure-templates,代碼行數:15,代碼來源:Sanitizers.java

示例10: filterImageDataUri

import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //導入方法依賴的package包/類
/** Makes sure that the given input is a data URI corresponding to an image. */
public static SanitizedContent filterImageDataUri(String value) {
  if (EscapingConventions.FilterImageDataUri.INSTANCE.getValueFilter().matcher(value).find()) {
    // NOTE: No need to escape.
    return UnsafeSanitizedContentOrdainer.ordainAsSafe(value, ContentKind.URI);
  }
  logger.log(Level.WARNING, "|filterImageDataUri received bad value ''{0}''", value);
  return UnsafeSanitizedContentOrdainer.ordainAsSafe(
      EscapingConventions.FilterImageDataUri.INSTANCE.getInnocuousOutput(),
      SanitizedContent.ContentKind.URI);
}
 
開發者ID:google,項目名稱:closure-templates,代碼行數:12,代碼來源:Sanitizers.java

示例11: filterTelUri

import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //導入方法依賴的package包/類
/** Makes sure that the given input is a tel URI. */
public static SanitizedContent filterTelUri(String value) {
  if (EscapingConventions.FilterTelUri.INSTANCE.getValueFilter().matcher(value).find()) {
    // NOTE: No need to escape. Escaping for other contexts (e.g. HTML) happen after this.
    return UnsafeSanitizedContentOrdainer.ordainAsSafe(value, ContentKind.URI);
  }
  logger.log(Level.WARNING, "|filterTelUri received bad value ''{0}''", value);
  return UnsafeSanitizedContentOrdainer.ordainAsSafe(
      EscapingConventions.FilterTelUri.INSTANCE.getInnocuousOutput(),
      SanitizedContent.ContentKind.URI);
}
 
開發者ID:google,項目名稱:closure-templates,代碼行數:12,代碼來源:Sanitizers.java

示例12: computeForJava

import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //導入方法依賴的package包/類
@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);
}
 
開發者ID:google,項目名稱:closure-templates,代碼行數:9,代碼來源:BidiDirAttrFunction.java

示例13: jsIdentifier

import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //導入方法依賴的package包/類
/**
 * Validates that {@code identifier} matches a safe pattern for JS identifiers and ordains the
 * value as JS.
 *
 * <p>TODO: this appears to be redundant with some code in JsSrcUtils.
 */
public static SanitizedContent jsIdentifier(String identifier) {
  checkArgument(
      VALID_JS_IDENTIFIER_PATTERN.matcher(identifier).matches(),
      "JS identifier '%s' should match the pattern '%s'",
      identifier,
      VALID_JS_IDENTIFIER_PATTERN.pattern());
  checkArgument(
      !INVALID_JS_IDENTIFIERS.contains(identifier),
      "JS identifier '%s' should not be a reserved word or match a literal",
      identifier);
  return UnsafeSanitizedContentOrdainer.ordainAsSafe(identifier, ContentKind.JS);
}
 
開發者ID:google,項目名稱:closure-templates,代碼行數:19,代碼來源:JsIdentifierOrdainer.java

示例14: testApplyForTofu

import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //導入方法依賴的package包/類
@Test
public void testApplyForTofu() {
  EscapeHtmlDirective escapeHtmlDirective = new EscapeHtmlDirective();

  assertTofuOutput("", "", escapeHtmlDirective);
  assertTofuOutput("a&amp;b &gt; c", "a&b > c", escapeHtmlDirective);
  assertTofuOutput(
      "&lt;script&gt;alert(&#39;boo&#39;);&lt;/script&gt;",
      "<script>alert('boo');</script>",
      escapeHtmlDirective);
  SanitizedContent fooTagHtml =
      UnsafeSanitizedContentOrdainer.ordainAsSafe("<foo>", SanitizedContent.ContentKind.HTML);
  assertTofuOutput(
      fooTagHtml,
      // Sanitized HTML is not escaped.
      fooTagHtml,
      escapeHtmlDirective);
  assertTofuOutput(
      "&lt;foo&gt;",
      // But JS_STR_CHARS are.
      UnsafeSanitizedContentOrdainer.ordainAsSafe("<foo>", SanitizedContent.ContentKind.JS),
      escapeHtmlDirective);
  assertTofuOutput(
      "&lt;foo&gt;",
      // But CSS is.
      UnsafeSanitizedContentOrdainer.ordainAsSafe("<foo>", SanitizedContent.ContentKind.CSS),
      escapeHtmlDirective);
}
 
開發者ID:google,項目名稱:closure-templates,代碼行數:29,代碼來源:EscapeHtmlDirectiveTest.java

示例15: ordainJson

import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //導入方法依賴的package包/類
private static SanitizedContent ordainJson(String knownSafeJson) {
  return UnsafeSanitizedContentOrdainer.ordainAsSafe(knownSafeJson, ContentKind.JS);
}
 
開發者ID:google,項目名稱:closure-templates,代碼行數:4,代碼來源:GsonOrdainer.java


注:本文中的com.google.template.soy.data.UnsafeSanitizedContentOrdainer.ordainAsSafe方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。