Class FrontendDependencyUrlResolver

java.lang.Object
com.vaadin.flow.server.FrontendDependencyUrlResolver
All Implemented Interfaces:
Serializable

public final class FrontendDependencyUrlResolver extends Object implements Serializable
Resolves the value() of frontend dependency annotations to a canonical form that BootstrapHandler.BootstrapUriResolver can expand at render time.

The same rules are used whether the annotation is on an AppShellConfigurator or on an ordinary Component.

Used for StyleSheet values, and for the JavaScript values that are loaded at runtime instead of being bundled. Callers should note that a rejected value (see the rules below) yields null rather than an exception, and that the dependency is then skipped.

For internal framework use only.

Since:
25.1.19
See Also:
  • Method Details

    • resolveToContextRoot

      public static String resolveToContextRoot(String rawValue)
      Normalizes a frontend-dependency URL value to a form that the bootstrap URI resolver can expand.

      Rules, in order:

      1. null or blank values return null.
      2. Values containing path traversals (..) are rejected with a warning and null is returned.
      3. http://, https://, //, context:// and base:// prefixes, and URLs with any other scheme (a value containing ://), are returned unchanged.
      4. A leading ./ is stripped.
      5. If the value (after the previous step) starts with /, it is returned unchanged.
      6. Otherwise, context:// is prepended so the value resolves against the servlet context root.
      Parameters:
      rawValue - the raw annotation value
      Returns:
      the normalized value, or null if rejected
    • isRuntimeDependencyUrl

      public static boolean isRuntimeDependencyUrl(String value)
      Tells whether the given value is a runtime-loaded URL ? i.e. should be served by the servlet container at runtime rather than passed to the frontend bundler.

      Returns true for values starting with any of: http://, https://, //, context://, base://, or /, and for URLs with any other scheme (a value containing ://), which the bundler skips as well (see UrlUtil.isExternal(java.lang.String)). Returns false for null, blank, or any other value (e.g. bare relative paths and bundler import specifiers).

      Parameters:
      value - the raw annotation value
      Returns:
      true if the value is a runtime URL
      Since:
      25.4
    • isRuntimeJavaScript

      public static boolean isRuntimeJavaScript(JavaScript javaScript)
      Tells whether the given JavaScript annotation is loaded at runtime as a script element rather than bundled.

      That is the case for JavaScript.Type.MODULE values and for runtime URLs (see isRuntimeDependencyUrl(String)).

      Parameters:
      javaScript - the annotation to check, not null
      Returns:
      true if the value is loaded at runtime
      Since:
      25.4
    • resolveRuntimeJavaScript

      public static String resolveRuntimeJavaScript(String value)
      Normalizes the value of a JavaScript annotation that is loaded at runtime (see isRuntimeJavaScript(JavaScript)) so that the bootstrap URI resolver can expand it.

      Values with a protocol (external URLs but also context:// and base://) are returned unchanged. All other values, such as absolute paths or bare relative JavaScript.Type.MODULE values, go through resolveToContextRoot(String).

      Parameters:
      value - the raw annotation value
      Returns:
      the normalized value, or null if the value was rejected
      Since:
      25.4