/** * Creates a {@link SafeStyleProto} wrapping the given {@code string}. No validation is performed. * * <p>If possible please use the production API in * {@link com.google.common.html.types.SafeStyles} * instead. */ public static SafeStyleProto newSafeStyleProtoForTest(String string) { return SafeStyles.toProto(newSafeStyleForTest(string)); }
/** * Converts a Soy {@link SanitizedContent} of kind CSS into a {@link SafeStyleProto}. * * @throws IllegalStateException if this SanitizedContent's content kind is not {@link * ContentKind#CSS}. */ public SafeStyleProto toSafeStyleProto() { Preconditions.checkState( getContentKind() == ContentKind.CSS, "toSafeStyleProto() only valid for SanitizedContent of kind CSS, is: %s", getContentKind()); // Sanity check: Try to prevent accidental misuse when this is a full stylesheet rather than a // declaration list. // The error may trigger incorrectly if the content contains curly brackets inside comments or // quoted strings. // // This is a best-effort attempt to preserve SafeStyle's semantical guarantees. Preconditions.checkState( !getContent().contains("{"), "Calling toSafeStyleProto() with content that doesn't look like CSS declarations. " + "Consider using toSafeStyleSheetProto()."); return SafeStyles.toProto( UncheckedConversions.safeStyleFromStringKnownToSatisfyTypeContract(getContent())); }
/** * Converts a Soy {@link SanitizedContent} of kind CSS into a {@link SafeStyleProto}. * * @throws IllegalStateException if this SanitizedContent's content kind is not {@link * ContentKind#CSS}. */ public SafeStyleProto toSafeStyleProto() { Preconditions.checkState( getContentKind() == ContentKind.CSS, "toSafeStyleProto() only valid for SanitizedContent of kind CSS, is: %s", getContentKind()); // Sanity check: Try to prevent accidental misuse when this is a full stylesheet rather than a // declaration list. // The error may trigger incorrectly if the content contains curly brackets inside comments or // quoted strings. // // This is a best-effort attempt to preserve SafeStyle's semantical guarantees. Preconditions.checkState( !getContent().contains("{"), "Calling toSafeStyleProto() with content that doesn't look like CSS declarations. " + "Consider using toSafeStyleSheetProto()."); return SafeStyles.toProto( UncheckedConversions.safeStyleFromStringKnownToSatisfyTypeContract(getContent())); }