List of usage examples for com.google.common.html.types UncheckedConversions safeStyleSheetFromStringKnownToSatisfyTypeContract
public static SafeStyleSheet safeStyleSheetFromStringKnownToSatisfyTypeContract(String stylesheet)
From source file:com.google.template.soy.data.SanitizedContent.java
/** * Converts a Soy {@link SanitizedContent} of kind CSS into a {@link SafeStyleSheet}. * * <p>To ensure correct behavior and usage, the SanitizedContent object should fulfill the * contract of SafeStyleSheet - the CSS content should represent the top-level content of a style * element within HTML.// w w w. j ava 2 s .c o m * * @throws IllegalStateException if this SanitizedContent's content kind is not * {@link ContentKind#CSS}. */ public SafeStyleSheet toSafeStyleSheet() { Preconditions.checkState(getContentKind() == ContentKind.CSS, "toSafeStyleSheet() only valid for SanitizedContent of kind CSS, is: %s", getContentKind()); // Sanity check: Try to prevent accidental misuse when this is not really a stylesheet but // instead just a declaration list (i.e. a SafeStyle). This does fail to accept a stylesheet // that is only a comment or only @imports; if you have a legitimate reason for this, it would // be fine to make this more sophisticated, but in practice it's unlikely and keeping this check // simple helps ensure it is fast. Note that this isn't a true security boundary, but a // best-effort attempt to preserve SafeStyleSheet's semantical guarantees. Preconditions.checkState(getContent().isEmpty() || getContent().indexOf('{') > 0, "Calling toSafeStyleSheet() with content that doesn't look like a stylesheet"); return UncheckedConversions.safeStyleSheetFromStringKnownToSatisfyTypeContract(getContent()); }