Class StaticResourceBuilderDefault<R extends RequestContext<?>,W extends WebsocketContext<?>>

java.lang.Object
org.spincast.plugins.routing.StaticResourceBuilderDefault<R,W>
All Implemented Interfaces:
StaticResourceBuilder<R>

public class StaticResourceBuilderDefault<R extends RequestContext<?>,W extends WebsocketContext<?>> extends Object implements StaticResourceBuilder<R>
  • Field Details

    • logger

      protected static final org.slf4j.Logger logger
  • Constructor Details

  • Method Details

    • isDir

      protected boolean isDir()
    • isSpicastOrPluginAddedResource

      protected boolean isSpicastOrPluginAddedResource()
    • getRouter

      protected Router<R,W> getRouter()
    • getStaticResourceFactory

      protected StaticResourceFactory<R> getStaticResourceFactory()
    • getStaticResourceCorsConfigFactory

      protected StaticResourceCorsConfigFactory getStaticResourceCorsConfigFactory()
    • getStaticResourceCacheConfigFactory

      protected StaticResourceCacheConfigFactory getStaticResourceCacheConfigFactory()
    • getSpincastConfig

      protected SpincastConfig getSpincastConfig()
    • getSpincastUtils

      protected SpincastUtils getSpincastUtils()
    • getSpincastRouterConfig

      protected SpincastRouterConfig getSpincastRouterConfig()
    • getUrl

      public String getUrl()
    • getPath

      public String getPath()
    • isHotlinkingProtected

      public boolean isHotlinkingProtected()
    • getHotlinkingManager

      public HotlinkingManager getHotlinkingManager()
    • isClasspath

      public boolean isClasspath()
    • getGenerator

      public Handler<R> getGenerator()
    • getCorsConfig

      public StaticResourceCorsConfig getCorsConfig()
    • getCacheConfig

      public StaticResourceCacheConfig getCacheConfig()
    • isIgnoreQueryString

      public boolean isIgnoreQueryString()
    • spicastOrPluginAddedResource

      public StaticResourceBuilder<R> spicastOrPluginAddedResource()
      Description copied from interface: StaticResourceBuilder
      This should only by called by *plugins*.

      When this method is called, the resulting route for the resource won't be remove by default when the Router.removeAllRoutes() method is used. The Router.removeAllRoutes(boolean) with true will have to be called to actually remove it.

      This is useful during development, when an hotreload mecanism is used to reload the Router without restarting the application, when the application routes changed. By default only the routes for which the #isSpicastCoreRouteOrPluginRoute() method has been called would then be reloaded.

      Specified by:
      spicastOrPluginAddedResource in interface StaticResourceBuilder<R extends RequestContext<?>>
    • url

      public StaticResourceBuilder<R> url(String url)
      Description copied from interface: StaticResourceBuilder
      The URL pointing to the resource.
      Specified by:
      url in interface StaticResourceBuilder<R extends RequestContext<?>>
    • classpath

      public StaticResourceBuilder<R> classpath(String path)
      Description copied from interface: StaticResourceBuilder
      The path to the resource, on the classpath.
      Specified by:
      classpath in interface StaticResourceBuilder<R extends RequestContext<?>>
    • pathAbsolute

      public StaticResourceBuilder<R> pathAbsolute(String absolutePath)
      Description copied from interface: StaticResourceBuilder
      The absolute path to the resource, on the file system.
      Specified by:
      pathAbsolute in interface StaticResourceBuilder<R extends RequestContext<?>>
      Parameters:
      absolutePath - the absolute path to the resource. If this is a file and not a directory, remember that it will be served as a static resource, so its extension is important for the correct Content-Type to be sent!
    • pathRelative

      public StaticResourceBuilder<R> pathRelative(String relativePath)
      Description copied from interface: StaticResourceBuilder
      The path to the resource, on the file system, relative to the temp Spincast directory, as returned by SpincastConfig::getSpincastTempDir()
      Specified by:
      pathRelative in interface StaticResourceBuilder<R extends RequestContext<?>>
      Parameters:
      relativePath - the relative path to the resource. If this is a file and not a directory, remember that it will be served as a static resource, so its extension is important for the correct Content-Type to be sent!
    • cors

      public StaticResourceBuilder<R> cors()
      Description copied from interface: StaticResourceBuilder
      Enables Cross-Origin Resource Sharing (Cors)
      Specified by:
      cors in interface StaticResourceBuilder<R extends RequestContext<?>>
      See Also:
      • SpincastFilters#cors(R context)
    • cors

      public StaticResourceBuilder<R> cors(Set<String> allowedOrigins)
      Description copied from interface: StaticResourceBuilder
      Enables Cross-Origin Resource Sharing (Cors)
      Specified by:
      cors in interface StaticResourceBuilder<R extends RequestContext<?>>
      See Also:
      • SpincastFilters#cors(R context, Set<String> allowedOrigins)
    • cors

      public StaticResourceBuilder<R> cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead)
      Description copied from interface: StaticResourceBuilder
      Enables Cross-Origin Resource Sharing (Cors)
      Specified by:
      cors in interface StaticResourceBuilder<R extends RequestContext<?>>
      See Also:
      • SpincastFilters#cors(R context, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead)
    • cors

      public StaticResourceBuilder<R> cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent)
      Description copied from interface: StaticResourceBuilder
      Enables Cross-Origin Resource Sharing (Cors)
      Specified by:
      cors in interface StaticResourceBuilder<R extends RequestContext<?>>
      See Also:
      • SpincastFilters#cors(R context, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent)
    • cors

      public StaticResourceBuilder<R> cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies)
      Description copied from interface: StaticResourceBuilder
      Enables Cross-Origin Resource Sharing (Cors)
      Specified by:
      cors in interface StaticResourceBuilder<R extends RequestContext<?>>
      See Also:
      • SpincastFilters#cors(R context, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies)
    • cors

      public StaticResourceBuilder<R> cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies, int maxAgeInSeconds)
      Description copied from interface: StaticResourceBuilder
      Enables Cross-Origin Resource Sharing (Cors)
      Specified by:
      cors in interface StaticResourceBuilder<R extends RequestContext<?>>
      See Also:
      • SpincastFilters#cors(R context, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies, int maxAgeInSeconds )
    • getCorsDefaultMaxAgeInSeconds

      protected int getCorsDefaultMaxAgeInSeconds()
      If <= 0, the "Access-Control-Max-Age" header won't be sent.
    • getCorsDefaultAllowedOrigins

      protected Set<String> getCorsDefaultAllowedOrigins()
      The origins allowed, by default.
    • getCorsDefaultExtraHeadersAllowedToBeRead

      protected Set<String> getCorsDefaultExtraHeadersAllowedToBeRead()
      The extra headers allowed to be read, by default,
    • getCorsDefaultExtraHeadersAllowedToBeSent

      protected Set<String> getCorsDefaultExtraHeadersAllowedToBeSent()
      The extra headers allowed to be sent, by default,
    • getCorsDefaultIsCookiesAllowed

      protected boolean getCorsDefaultIsCookiesAllowed()
      Are cookies allowed by default?
    • isCachePrivateDefault

      protected boolean isCachePrivateDefault()
      Is the cache private by default?
    • getCacheCdnSecondsDefault

      protected Integer getCacheCdnSecondsDefault()
    • cache

      public StaticResourceBuilder<R> cache(int seconds)
      Description copied from interface: StaticResourceBuilder
      Adds public cache headers.
      Specified by:
      cache in interface StaticResourceBuilder<R extends RequestContext<?>>
      Parameters:
      seconds - The number of seconds the resource associated with this route should be cached.
    • cache

      public StaticResourceBuilder<R> cache(int seconds, boolean isCachePrivate)
      Description copied from interface: StaticResourceBuilder
      Adds cache headers.
      Specified by:
      cache in interface StaticResourceBuilder<R extends RequestContext<?>>
      Parameters:
      seconds - The number of seconds the resource associated with this route should be cached.
      isCachePrivate - should the cache be private? (help)
    • cache

      public StaticResourceBuilder<R> cache(int seconds, boolean isCachePrivate, Integer cdnSeconds)
      Description copied from interface: StaticResourceBuilder
      Adds cache headers.
      Specified by:
      cache in interface StaticResourceBuilder<R extends RequestContext<?>>
      Parameters:
      seconds - The number of seconds the resource associated with this route should be cached.
      isCachePrivate - should the cache be private? (help)
      cdnSeconds - The number of seconds the resource associated with this route should be cached by a CDN/proxy. If null, it won't be used.
    • handle

      public void handle()
      Description copied from interface: StaticResourceBuilder
      Saves the static resource route to the router.

      If the creation of the resource was not started using an Router object, an exception will be thrown.

      Specified by:
      handle in interface StaticResourceBuilder<R extends RequestContext<?>>
    • handle

      public void handle(Handler<R> generator)
      Description copied from interface: StaticResourceBuilder
      Saves the static resource route. Note that the generated resource won't be cached if there is a queryString on the request : it will always be generated.

      If the creation of the resource was not started using an Router object, an exception will be thrown.

      Specified by:
      handle in interface StaticResourceBuilder<R extends RequestContext<?>>
      Parameters:
      generator - If the resource is not found, the specified generator will be used to generate it and the result will be saved.
    • handle

      public void handle(Handler<R> generator, boolean ignoreQueryString)
      Description copied from interface: StaticResourceBuilder
      Saves the static resource route.

      If the creation of the resource was not started using an Router object, an exception will be thrown.

      Specified by:
      handle in interface StaticResourceBuilder<R extends RequestContext<?>>
      Parameters:
      generator - If the resource is not found, the specified generator will be used to generate it and the result will be saved.
      ignoreQueryString - If true, only one instance of the resource will be generated and cached. If false (the default), the resource will always be generated if there is a queryString.
    • create

      public StaticResource<R> create()
      Description copied from interface: StaticResourceBuilder
      Creates and returns the static resource without adding it to the router. NOTE : use handle(...) instead to save the static resource to the router at the end of the build process!
      Specified by:
      create in interface StaticResourceBuilder<R extends RequestContext<?>>
    • getDefaultCacheConfig

      protected StaticResourceCacheConfig getDefaultCacheConfig()
      The default cache configurations to use if it is not specified. It can still be null and, in that case, no cache header will be used.
    • hotlinkingProtected

      public StaticResourceBuilder<R> hotlinkingProtected()
      Description copied from interface: StaticResourceBuilder
      When a static resource is flagged as being *hotlinking protected*, the server will validate the origin and referer of the request. If those don't matche the host of the application, a protection will be apply, the one provided by the default .
      Specified by:
      hotlinkingProtected in interface StaticResourceBuilder<R extends RequestContext<?>>
    • hotlinkingProtected

      public StaticResourceBuilder<R> hotlinkingProtected(HotlinkingManager hotlinkingManager)
      Description copied from interface: StaticResourceBuilder
      When a static resource is flagged as being *hotlinking protected*, the server will validate the origin and referer of the request. If those don't matche the host of the application, a protection will be apply, the one provided by the specified hotlinkingManager.
      Specified by:
      hotlinkingProtected in interface StaticResourceBuilder<R extends RequestContext<?>>