/** * Returns the string value. * * <p>In contexts where a string value is required, SanitizedContent is permitted. */ @Override public String stringValue() { return getContent(); }
/** * Converts a Soy {@link SanitizedContent} of kind HTML into a {@link SafeHtml}. * * @throws IllegalStateException if this SanitizedContent's content kind is not {@link * ContentKind#HTML}. */ public SafeHtml toSafeHtml() { Preconditions.checkState( getContentKind() == ContentKind.HTML, "toSafeHtml() only valid for SanitizedContent of kind HTML, is: %s", getContentKind()); return UncheckedConversions.safeHtmlFromStringKnownToSatisfyTypeContract(getContent()); }
@Override public void close() throws IOException { if (!isInHtml()) { StringBuilder buffer = (StringBuilder) activeAppendable; if (buffer.length() > 0) { SanitizedContent content = cleanHtml(buffer.toString(), getSanitizedContentDirectionality(), optionalSafeTags); delegate .setSanitizedContentKind(content.getContentKind()) .setSanitizedContentDirectionality(content.getContentDirection()) .append(content.getContent()); buffer.setLength(0); } } } }
/** * Converts a Soy {@link SanitizedContent} of kind HTML into a {@link SafeHtml}. * * @throws IllegalStateException if this SanitizedContent's content kind is not {@link * ContentKind#HTML}. */ public SafeHtml toSafeHtml() { Preconditions.checkState( getContentKind() == ContentKind.HTML, "toSafeHtml() only valid for SanitizedContent of kind HTML, is: %s", getContentKind()); return UncheckedConversions.safeHtmlFromStringKnownToSatisfyTypeContract(getContent()); }
/** * Returns the string value. * * <p>In contexts where a string value is required, SanitizedContent is permitted. */ @Override public String stringValue() { return getContent(); }
/** * 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())); }
@Override public String toString() { return getContent(); }
/** * Converts a Soy {@link SanitizedContent} of kind JS into a {@link SafeScriptProto}. * * @throws IllegalStateException if this SanitizedContent's content kind is not {@link * ContentKind#JS}. */ public SafeScriptProto toSafeScriptProto() { Preconditions.checkState( getContentKind() == ContentKind.JS, "toSafeScriptProto() only valid for SanitizedContent of kind JS, is: %s", getContentKind()); return SafeScripts.toProto( UncheckedConversions.safeScriptFromStringKnownToSatisfyTypeContract(getContent())); }
@Override public String toString() { return getContent(); }
/** * Converts a Soy {@link SanitizedContent} of kind HTML into a {@link SafeHtmlProto}. * * @throws IllegalStateException if this SanitizedContent's content kind is not {@link * ContentKind#HTML}. */ public SafeHtmlProto toSafeHtmlProto() { Preconditions.checkState( getContentKind() == ContentKind.HTML, "toSafeHtmlProto() only valid for SanitizedContent of kind HTML, is: %s", getContentKind()); return SafeHtmls.toProto( UncheckedConversions.safeHtmlFromStringKnownToSatisfyTypeContract(getContent())); }
@Override public boolean equals(@Nullable Object other) { // TODO(user): js uses reference equality, this uses content comparison return other instanceof SanitizedContent && this.contentKind == ((SanitizedContent) other).contentKind && this.contentDir == ((SanitizedContent) other).contentDir && this.getContent().equals(((SanitizedContent) other).getContent()); }
/** * 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())); }
@Override public boolean equals(@Nullable Object other) { // TODO(user): js uses reference equality, this uses content comparison return other instanceof SanitizedContent && this.contentKind == ((SanitizedContent) other).contentKind && this.contentDir == ((SanitizedContent) other).contentDir && this.getContent().equals(((SanitizedContent) other).getContent()); }
/** * Converts a Soy {@link SanitizedContent} of kind JS into a {@link SafeScriptProto}. * * @throws IllegalStateException if this SanitizedContent's content kind is not {@link * ContentKind#JS}. */ public SafeScriptProto toSafeScriptProto() { Preconditions.checkState( getContentKind() == ContentKind.JS, "toSafeScriptProto() only valid for SanitizedContent of kind JS, is: %s", getContentKind()); return SafeScripts.toProto( UncheckedConversions.safeScriptFromStringKnownToSatisfyTypeContract(getContent())); }
@Override public boolean coerceToBoolean() { return getContent().length() > 0; // Consistent with StringData }
/** * Converts a Soy {@link SanitizedContent} of kind HTML into a {@link SafeHtmlProto}. * * @throws IllegalStateException if this SanitizedContent's content kind is not {@link * ContentKind#HTML}. */ public SafeHtmlProto toSafeHtmlProto() { Preconditions.checkState( getContentKind() == ContentKind.HTML, "toSafeHtmlProto() only valid for SanitizedContent of kind HTML, is: %s", getContentKind()); return SafeHtmls.toProto( UncheckedConversions.safeHtmlFromStringKnownToSatisfyTypeContract(getContent())); }
@Override public boolean coerceToBoolean() { return getContent().length() > 0; // Consistent with StringData }
/** * Converts a Soy {@link SanitizedContent} of kind TRUSTED_RESOURCE_URI into a {@link * TrustedResourceUrlProto}. * * @throws IllegalStateException if this SanitizedContent's content kind is not {@link * ContentKind#TRUSTED_RESOURCE_URI}. */ public TrustedResourceUrlProto toTrustedResourceUrlProto() { Preconditions.checkState( getContentKind() == ContentKind.TRUSTED_RESOURCE_URI, "toTrustedResourceUrlProto() only valid for SanitizedContent of kind TRUSTED_RESOURCE_URI, " + "is: %s", getContentKind()); return TrustedResourceUrls.toProto( UncheckedConversions.trustedResourceUrlFromStringKnownToSatisfyTypeContract(getContent())); }
@Override public int hashCode() { return getContent().hashCode() + 31 * contentKind.hashCode(); }
@Override public int hashCode() { return getContent().hashCode() + 31 * contentKind.hashCode(); }