/** 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); }
/** * Creates a SafeUrl by doing an unchecked conversion from the given {@code url}. Also called * from SafeUrlBuilder. */ static SafeUrl create(String url) { return new SafeUrl(url); } }
/** 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 String into a SafeUrl, for refactoring legacy code. Please read class documentation * before using. */ public static SafeUrl riskilyAssumeSafeUrl(String url) { return new SafeUrl(url); }
/** * Sets the {@code icon} attribute for this element. * * <p>The attribute {@code icon} with a {@code SafeUrl} value is allowed on these elements: * * <ul> * <li>{@code menuitem} * </ul> * * @throws IllegalArgumentException if the {@code icon} attribute with a {@code SafeUrl} value is * not allowed on this element */ public SafeHtmlBuilder setIcon(SafeUrl value) { if (!ICON_SAFE_URL_ELEMENT_WHITELIST.contains(elementName)) { throw new IllegalArgumentException( "Attribute \"icon\" with a SafeUrl value can only be used " + "by one of the following elements: " + ICON_SAFE_URL_ELEMENT_WHITELIST); } return setAttribute("icon", value.getSafeUrlString()); }
/** * Converts a String into a SafeUrl. */ public static SafeUrl safeUrlFromStringKnownToSatisfyTypeContract(String url) { return new SafeUrl(url); }
/** * Sets the {@code action} attribute for this element. * * <p>The attribute {@code action} with a {@code SafeUrl} value is allowed on these elements: * * <ul> * <li>{@code form} * </ul> * * @throws IllegalArgumentException if the {@code action} attribute with a {@code SafeUrl} value * is not allowed on this element */ public SafeHtmlBuilder setAction(SafeUrl value) { if (!ACTION_SAFE_URL_ELEMENT_WHITELIST.contains(elementName)) { throw new IllegalArgumentException( "Attribute \"action\" with a SafeUrl value can only be used " + "by one of the following elements: " + ACTION_SAFE_URL_ELEMENT_WHITELIST); } return setAttribute("action", value.getSafeUrlString()); }
/** * Sets the {@code poster} attribute for this element. * * <p>The attribute {@code poster} with a {@code SafeUrl} value is allowed on these elements: * * <ul> * <li>{@code video} * </ul> * * @throws IllegalArgumentException if the {@code poster} attribute with a {@code SafeUrl} value * is not allowed on this element */ public SafeHtmlBuilder setPoster(SafeUrl value) { if (!POSTER_SAFE_URL_ELEMENT_WHITELIST.contains(elementName)) { throw new IllegalArgumentException( "Attribute \"poster\" with a SafeUrl value can only be used " + "by one of the following elements: " + POSTER_SAFE_URL_ELEMENT_WHITELIST); } return setAttribute("poster", value.getSafeUrlString()); }
/** * Sets the {@code formaction} attribute for this element. * * <p>The attribute {@code formaction} with a {@code SafeUrl} value is allowed on these elements: * * <ul> * <li>{@code button} * <li>{@code input} * </ul> * * @throws IllegalArgumentException if the {@code formaction} attribute with a {@code SafeUrl} * value is not allowed on this element */ public SafeHtmlBuilder setFormaction(SafeUrl value) { if (!FORMACTION_SAFE_URL_ELEMENT_WHITELIST.contains(elementName)) { throw new IllegalArgumentException( "Attribute \"formaction\" with a SafeUrl value can only be used " + "by one of the following elements: " + FORMACTION_SAFE_URL_ELEMENT_WHITELIST); } return setAttribute("formaction", value.getSafeUrlString()); }
/** * Sets the {@code cite} attribute for this element. * * <p>The attribute {@code cite} with a {@code SafeUrl} value is allowed on these elements: * * <ul> * <li>{@code blockquote} * <li>{@code del} * <li>{@code ins} * <li>{@code q} * </ul> * * @throws IllegalArgumentException if the {@code cite} attribute with a {@code SafeUrl} value is * not allowed on this element */ public SafeHtmlBuilder setCite(SafeUrl value) { if (!CITE_SAFE_URL_ELEMENT_WHITELIST.contains(elementName)) { throw new IllegalArgumentException( "Attribute \"cite\" with a SafeUrl value can only be used " + "by one of the following elements: " + CITE_SAFE_URL_ELEMENT_WHITELIST); } return setAttribute("cite", value.getSafeUrlString()); }
/** * Sets the {@code src} attribute for this element. * * <p>The attribute {@code src} with a {@code SafeUrl} value is allowed on these elements: * * <ul> * <li>{@code audio} * <li>{@code img} * <li>{@code input} * <li>{@code source} * <li>{@code video} * </ul> * * @throws IllegalArgumentException if the {@code src} attribute with a {@code SafeUrl} value is * not allowed on this element */ public SafeHtmlBuilder setSrc(SafeUrl value) { if (!SRC_SAFE_URL_ELEMENT_WHITELIST.contains(elementName)) { throw new IllegalArgumentException( "Attribute \"src\" with a SafeUrl value can only be used " + "by one of the following elements: " + SRC_SAFE_URL_ELEMENT_WHITELIST); } return setAttribute("src", value.getSafeUrlString()); }
/** 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 SafeUrlProto} into a Soy {@link SanitizedContent} of kind URI. */ public static SanitizedContent fromSafeUrlProto(SafeUrlProto url) { return SanitizedContent.create(SafeUrls.fromProto(url).getSafeUrlString(), ContentKind.URI); }
return setAttribute("href", value.getSafeUrlString());
/** * Serializes a SafeUrl into its opaque protocol message representation. * * <p>Protocol message forms of this type are intended to be opaque. The fields of the returned * protocol message should be considered encapsulated and are not intended for direct inspection * or manipulation. Protocol messages can be converted back into a SafeUrl using * {@link #fromProto(SafeUrlProto)}. */ public static SafeUrlProto toProto(SafeUrl url) { return SafeUrlProto.newBuilder() .setPrivateDoNotAccessOrElseSafeUrlWrappedValue(url.getSafeUrlString()) .build(); }
/** * Appends a {@code url} value to the {@code background-image} property, if necessary inserting * a leading comma. The {@code url} value will be inserted inside a {@code url} function call. * * <p>The {@code url} is validated as safe, as determined by {@link SafeUrls#sanitize(String)}. * It also percent-encoded to prevent it from interefering with the structure of the surrounding * CSS. * * <p>TODO(mlourenco): The right thing to do would be to CSS-escape but percent-encoding is * easier for now because we don't have a CSS-escaper. As URLs in CSS are likely to point to * domains we control it seems extremely unlikely that this will break anything. * * @see "http://dev.w3.org/csswg/css-backgrounds/#background-image" */ public SafeStyleBuilder backgroundImageAppendUrl(String url) { url = SafeUrls.sanitize(url).getSafeUrlString(); try { url = ESCAPER_BACKGROUND_IMAGE.escape(url); } catch (IllegalArgumentException e) { // Happens if url contains invalid surrogate sequences. url = INNOCUOUS_PROPERTY_STRING; } String urlValue = "url(" + url + ")"; appendToProperty("background-image", urlValue); return this; }