/** * Creates a {@link TrustedResourceUrlProto} wrapping the given {@code string}. No validation is * performed. * * <p>If possible please use the production API in * {@link com.google.common.html.types.TrustedResourceUrls} * instead. */ public static TrustedResourceUrlProto newTrustedResourceUrlProtoForTest(String string) { return TrustedResourceUrls.toProto(newTrustedResourceUrlForTest(string)); } }
/** * Returns the TrustedResourceUrl built so far. */ @CheckReturnValue public TrustedResourceUrl build() { return TrustedResourceUrls.create(url.toString()); } }
/** * Converts a {@link TrustedResourceUrlProto} into a Soy {@link SanitizedContent} of kind * TRUSTED_RESOURCE_URI. */ public static SanitizedContent fromTrustedResourceUrlProto(TrustedResourceUrlProto url) { return SanitizedContent.create( TrustedResourceUrls.fromProto(url).getTrustedResourceUrlString(), ContentKind.TRUSTED_RESOURCE_URI); }
/** * Converts a {@link TrustedResourceUrlProto} into a Soy {@link SanitizedContent} of kind * TRUSTED_RESOURCE_URI. */ public static SanitizedContent fromTrustedResourceUrlProto(TrustedResourceUrlProto url) { return SanitizedContent.create( TrustedResourceUrls.fromProto(url).getTrustedResourceUrlString(), ContentKind.TRUSTED_RESOURCE_URI); }
/** * 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())); }
/** * Creates a TrustedResourceUrl from the given compile-time constant string {@code url}. * * <p>No runtime validation or sanitization is performed on {@code url}; being under application * control, it is simply assumed to comply with the TrustedResourceUrl contract. */ public static TrustedResourceUrl fromConstant(@CompileTimeConstant final String url) { return create(url); }
/** * 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())); }
/** * Deserializes a TrustedResourceUrlProto into a TrustedResourceUrl 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(TrustedResourceUrl)} 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 TrustedResourceUrl fromProto(TrustedResourceUrlProto proto) { return create(proto.getPrivateDoNotAccessOrElseTrustedResourceUrlWrappedValue()); }
/** * Creates a {@link TrustedResourceUrl} from the value of an environment variable. In a server * setting, environment variables are part of the application's deployment configuration and are * hence considered application-controlled. If the variable is not defined returns null. * * * <p>No runtime validation or sanitization is performed on the value of the environment variable; * being under application control, it is simply assumed to comply with the TrustedResourceUrl * contract. * * @throws SecurityException if a security manager exists and its checkPermission method doesn't * allow access to the environment variable name */ @GwtIncompatible("System.getEnv") @Nullable public static TrustedResourceUrl fromEnvironmentVariable( @CompileTimeConstant final String variableName) { String var = System.getenv(variableName); if (var == null) { return null; } return create(var); }