本文整理匯總了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);
}
示例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();
}
示例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();
}
示例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());
}
示例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()));
}
示例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));
}
示例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);
}
示例8: apply
import com.google.common.html.types.SafeUrlProto; //導入依賴的package包/類
@Override
public SoyValueProvider apply(Object obj) {
return SanitizedContents.fromSafeUrlProto((SafeUrlProto) obj);
}
示例9: urlString
import com.google.common.html.types.SafeUrlProto; //導入依賴的package包/類
private static String urlString(SafeUrlProto url) {
return SafeUrls.fromProto(url).getSafeUrlString();
}
示例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));
}