/** * 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)); }
@CheckReturnValue public SafeStyle build() { StringBuilder sb = new StringBuilder(); if (!properties.isEmpty()) { // SafeStyle contract requires a trailing ';'. JOINER.appendTo(sb, properties).append(";"); } return SafeStyles.create(sb.toString()); }
/** 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 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())); }
/** * Deserializes a SafeStyleProto into a SafeStyle instance. * * <p>Protocol-message forms are intended to be opaque. The fields of the protocol message should * be considered encapsulated and are not intended for direct inspection or manipulation. Protocol * message forms of this type should be produced by {@link #toProto(SafeStyle)} or its equivalent * in other implementation languages. * * <p><b>Important:</b> It is unsafe to invoke this method on a protocol message that has been * received from an entity outside the application's trust domain. Data coming from the browser * is outside the application's trust domain. */ public static SafeStyle fromProto(SafeStyleProto proto) { return create(proto.getPrivateDoNotAccessOrElseSafeStyleWrappedValue()); }
/** 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 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())); }
+ "specify a \"name: value\" pair: " + style); return create(style);