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


Java SafeUrlProto類代碼示例

本文整理匯總了Java中com.google.common.html.types.SafeUrlProto的典型用法代碼示例。如果您正苦於以下問題:Java SafeUrlProto類的具體用法?Java SafeUrlProto怎麽用?Java SafeUrlProto使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SafeUrlProto類屬於com.google.common.html.types包,在下文中一共展示了SafeUrlProto類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testCommonSafeUrlTypeConversions

import com.google.common.html.types.SafeUrlProto; //導入依賴的package包/類
@Test
public void testCommonSafeUrlTypeConversions() {
  final String testUrl = "http://blahblah";
  final SanitizedContent sanitizedConstantUri = SanitizedContents.constantUri(testUrl);
  final SafeUrl safeUrl = SafeUrls.fromConstant(testUrl);

  final SanitizedContent sanitizedUrl = SanitizedContents.fromSafeUrl(safeUrl);
  assertThat(sanitizedUrl.getContentKind()).isEqualTo(ContentKind.URI);
  assertThat(sanitizedUrl.getContent()).isEqualTo(testUrl);
  assertThat(sanitizedUrl).isEqualTo(sanitizedConstantUri);

  // Proto conversions.
  final SafeUrlProto safeUrlProto = SafeUrls.toProto(safeUrl);
  final SanitizedContent sanitizedUrlProto = SanitizedContents.fromSafeUrlProto(safeUrlProto);
  assertThat(sanitizedUrlProto.getContent()).isEqualTo(testUrl);
  assertThat(sanitizedUrlProto).isEqualTo(sanitizedConstantUri);
}
 
開發者ID:google,項目名稱:closure-templates,代碼行數:18,代碼來源:SanitizedContentsTest.java

示例2: renderScripts

import com.google.common.html.types.SafeUrlProto; //導入依賴的package包/類
private SoyValue renderScripts(List<SafeUrlProto> urls) {
  String template = "{namespace dossier.soy.dynamic}{template .scripts kind=\"html\"}";
  for (SafeUrlProto proto : urls) {
    String url = SafeUrls.fromProto(proto).getSafeUrlString();
    template += "<script src=\"" + url + "\" defer></script>";
  }
  template += "{/template}";

  return filesetBuilderProvider
      .get()
      .add(template, "<dynamic>")
      .build()
      .compileToTofu()
      .newRenderer("dossier.soy.dynamic.scripts")
      .setContentKind(SanitizedContent.ContentKind.HTML)
      .renderStrict();
}
 
開發者ID:jleyba,項目名稱:js-dossier,代碼行數:18,代碼來源:Renderer.java

示例3: makeSafeUrlProto

import com.google.common.html.types.SafeUrlProto; //導入依賴的package包/類
public static SafeUrlProto makeSafeUrlProto(String href) {
  // CAVEAT: href is not known to satisfy the type contract.
  // If href is "javascript:doEvil()" we could be in trouble.
  return SafeUrlProto.newBuilder()
      // The hint is in the name.
      .setPrivateDoNotAccessOrElseSafeUrlWrappedValue(href)
      .build();
}
 
開發者ID:google,項目名稱:safe-html-types,代碼行數:9,代碼來源:Example.java

示例4: makeLink

import com.google.common.html.types.SafeUrlProto; //導入依賴的package包/類
public static SafeHtmlProto makeLink(String href) {
  SafeUrlProto safeHref = Unapproved.makeSafeUrlProto(href);

  // Use the builder to make the link.
  return SafeHtmls.toProto(
      new SafeHtmlBuilder("a")
      .setHref(SafeUrls.fromProto(safeHref))
      .build());
}
 
開發者ID:google,項目名稱:safe-html-types,代碼行數:10,代碼來源:Example.java

示例5: toSafeUrlProto

import com.google.common.html.types.SafeUrlProto; //導入依賴的package包/類
/**
 * Converts a Soy {@link SanitizedContent} of kind URI into a {@link SafeUrlProto}.
 *
 * @throws IllegalStateException if this SanitizedContent's content kind is not {@link
 *     ContentKind#URI}.
 */
public SafeUrlProto toSafeUrlProto() {
  Preconditions.checkState(
      getContentKind() == ContentKind.URI,
      "toSafeUrlProto() only valid for SanitizedContent of kind URI, is: %s",
      getContentKind());
  return SafeUrls.toProto(
      UncheckedConversions.safeUrlFromStringKnownToSatisfyTypeContract(getContent()));
}
 
開發者ID:google,項目名稱:closure-templates,代碼行數:15,代碼來源:SanitizedContent.java

示例6: testNewSafeUrlProtoForTest

import com.google.common.html.types.SafeUrlProto; //導入依賴的package包/類
public void testNewSafeUrlProtoForTest() {
  String url = "https://www.google.com";
  SafeUrlProto proto = HtmlConversions.newSafeUrlProtoForTest(url);
  assertEquals(SafeUrls.sanitize(url), SafeUrls.fromProto(proto));
}
 
開發者ID:google,項目名稱:safe-html-types,代碼行數:6,代碼來源:HtmlConversionsTest.java

示例7: fromSafeUrlProto

import com.google.common.html.types.SafeUrlProto; //導入依賴的package包/類
/** Converts a {@link SafeUrlProto} into a Soy {@link SanitizedContent} of kind URI. */
public static SanitizedContent fromSafeUrlProto(SafeUrlProto url) {
  return SanitizedContent.create(
      SafeUrls.fromProto(url).getSafeUrlString(), ContentKind.URI, Dir.LTR);
}
 
開發者ID:google,項目名稱:closure-templates,代碼行數:6,代碼來源:SanitizedContents.java

示例8: apply

import com.google.common.html.types.SafeUrlProto; //導入依賴的package包/類
@Override
public SoyValueProvider apply(Object obj) {
  return SanitizedContents.fromSafeUrlProto((SafeUrlProto) obj);
}
 
開發者ID:google,項目名稱:closure-templates,代碼行數:5,代碼來源:SafeStringTypes.java

示例9: urlString

import com.google.common.html.types.SafeUrlProto; //導入依賴的package包/類
private static String urlString(SafeUrlProto url) {
  return SafeUrls.fromProto(url).getSafeUrlString();
}
 
開發者ID:jleyba,項目名稱:js-dossier,代碼行數:4,代碼來源:TypeInspector.java

示例10: newSafeUrlProtoForTest

import com.google.common.html.types.SafeUrlProto; //導入依賴的package包/類
/**
 * Creates a {@link SafeUrlProto} wrapping the given {@code string}. No validation is performed.
 *
 * <p>If possible please use the production API in
 * {@link com.google.common.html.types.SafeUrls}
 * instead.
 */
public static SafeUrlProto newSafeUrlProtoForTest(String string) {
  return SafeUrls.toProto(newSafeUrlForTest(string));
}
 
開發者ID:google,項目名稱:safe-html-types,代碼行數:11,代碼來源:HtmlConversions.java


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