/** * Creates a SanitizedContent object of kind TEXT of a given direction (null if unknown). * * <p>This is useful when stubbing out a function that needs to create a SanitizedContent object. */ public static SanitizedContent unsanitizedText(String text, @Nullable Dir dir) { return SanitizedContent.create(text, ContentKind.TEXT, dir); }
/** Wraps an assumed-safe constant string. */ @SuppressWarnings("ReferenceEquality") // need to use a reference check to ensure it is a constant private static SanitizedContent fromConstant( String constant, ContentKind kind, @Nullable Dir dir) { // Extra runtime check in case the compile-time check doesn't work. Preconditions.checkArgument( constant.intern() == constant, "The provided argument does not look like a compile-time constant."); return SanitizedContent.create(constant, kind, dir); }
/** Wraps an assumed-safe constant string. */ private static SanitizedContent fromConstant( String constant, ContentKind kind, @Nullable Dir dir) { // Extra runtime check in case the compile-time check doesn't work. Preconditions.checkArgument( constant.intern().equals(constant), "The provided argument does not look like a compile-time constant."); return SanitizedContent.create(constant, kind, dir); }
/** Creates an empty string constant. */ public static SanitizedContent emptyString(ContentKind kind) { if (kind == ContentKind.TEXT) { return UnsanitizedString.create("", Dir.NEUTRAL); } return SanitizedContent.create("", kind, Dir.NEUTRAL); // Empty string is neutral. }
/** * Converts a {@link TrustedResourceUrl} into a Soy {@link SanitizedContent} of kind * TRUSTED_RESOURCE_URI. */ public static SanitizedContent fromTrustedResourceUrl(TrustedResourceUrl url) { return SanitizedContent.create( url.getTrustedResourceUrlString(), ContentKind.TRUSTED_RESOURCE_URI); }
/** Converts a {@link SafeScript} into a Soy {@link SanitizedContent} of kind JS. */ public static SanitizedContent fromSafeScript(SafeScript script) { return SanitizedContent.create(script.getSafeScriptString(), ContentKind.JS); }
/** * Converts a {@link TrustedResourceUrl} into a Soy {@link SanitizedContent} of kind * TRUSTED_RESOURCE_URI. */ public static SanitizedContent fromTrustedResourceUrl(TrustedResourceUrl url) { return SanitizedContent.create( url.getTrustedResourceUrlString(), ContentKind.TRUSTED_RESOURCE_URI); }
/** Converts a {@link SafeUrl} into a Soy {@link SanitizedContent} of kind URI. */ public static SanitizedContent fromSafeUrl(SafeUrl url) { return SanitizedContent.create(url.getSafeUrlString(), ContentKind.URI); }
/** Converts a {@link SafeHtml} into a Soy {@link SanitizedContent} of kind HTML. */ public static SanitizedContent fromSafeHtml(SafeHtml html) { return SanitizedContent.create(html.getSafeHtmlString(), ContentKind.HTML); }
/** Converts a {@link SafeStyleSheet} into a Soy {@link SanitizedContent} of kind CSS. */ public static SanitizedContent fromSafeStyleSheet(SafeStyleSheet styleSheet) { return SanitizedContent.create(styleSheet.getSafeStyleSheetString(), ContentKind.CSS); }
/** Converts a {@link SafeScriptProto} into a Soy {@link SanitizedContent} of kind JS. */ public static SanitizedContent fromSafeScriptProto(SafeScriptProto script) { return SanitizedContent.create( SafeScripts.fromProto(script).getSafeScriptString(), ContentKind.JS); }
/** Converts a {@link SafeScriptProto} into a Soy {@link SanitizedContent} of kind JS. */ public static SanitizedContent fromSafeScriptProto(SafeScriptProto script) { return SanitizedContent.create( SafeScripts.fromProto(script).getSafeScriptString(), ContentKind.JS); }
/** Converts a {@link SafeStyleProto} into a Soy {@link SanitizedContent} of kind CSS. */ public static SanitizedContent fromSafeStyleProto(SafeStyleProto style) { return SanitizedContent.create( SafeStyles.fromProto(style).getSafeStyleString(), ContentKind.CSS); }
/** Converts a {@link SafeStyleSheetProto} into a Soy {@link SanitizedContent} of kind CSS. */ public static SanitizedContent fromSafeStyleSheetProto(SafeStyleSheetProto styleSheet) { return SanitizedContent.create( SafeStyleSheets.fromProto(styleSheet).getSafeStyleSheetString(), ContentKind.CSS); }
/** * Converts a {@link TrustedResourceUrlProto} into a Soy {@link SanitizedContent} of kind * TRUSTED_RESOURCE_URI. */ public static SanitizedContent fromTrustedResourceUrlProto(TrustedResourceUrlProto url) { return SanitizedContent.create( TrustedResourceUrls.fromProto(url).getTrustedResourceUrlString(), ContentKind.TRUSTED_RESOURCE_URI); }
/** 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); }
/** Converts a {@link SafeStyleSheetProto} into a Soy {@link SanitizedContent} of kind CSS. */ public static SanitizedContent fromSafeStyleSheetProto(SafeStyleSheetProto styleSheet) { return SanitizedContent.create( SafeStyleSheets.fromProto(styleSheet).getSafeStyleSheetString(), ContentKind.CSS); }
/** 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); }
/** * Converts a {@link TrustedResourceUrlProto} into a Soy {@link SanitizedContent} of kind * TRUSTED_RESOURCE_URI. */ public static SanitizedContent fromTrustedResourceUrlProto(TrustedResourceUrlProto url) { return SanitizedContent.create( TrustedResourceUrls.fromProto(url).getTrustedResourceUrlString(), ContentKind.TRUSTED_RESOURCE_URI); }
/** Converts a {@link SafeStyleProto} into a Soy {@link SanitizedContent} of kind CSS. */ public static SanitizedContent fromSafeStyleProto(SafeStyleProto style) { return SanitizedContent.create( SafeStyles.fromProto(style).getSafeStyleString(), ContentKind.CSS); }