
public.javadoc.org.spincast.plugins.routing.StaticResourceBuilderDefault.html Maven / Gradle / Ivy
Show all versions of spincast-website Show documentation
StaticResourceBuilderDefault (org.spincast:spincast-framework 2.1.1 API)
Package org.spincast.plugins.routing
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 Summary
Fields
-
Constructor Summary
Constructors
Constructor
Description
StaticResourceBuilderDefault(boolean isDir,
StaticResourceFactory<R> staticResourceFactory,
StaticResourceCorsConfigFactory staticResourceCorsConfigFactory,
StaticResourceCacheConfigFactory staticResourceCacheConfigFactory,
SpincastConfig spincastConfig,
SpincastUtils spincastUtils,
SpincastRouterConfig spincastRouterConfig)
StaticResourceBuilderDefault(Router<R,W> router,
boolean isDir,
StaticResourceFactory<R> staticResourceFactory,
StaticResourceCorsConfigFactory staticResourceCorsConfigFactory,
StaticResourceCacheConfigFactory staticResourceCacheConfigFactory,
SpincastConfig spincastConfig,
SpincastUtils spincastUtils,
SpincastRouterConfig spincastRouterConfig)
-
Method Summary
Modifier and Type
Method
Description
cache(int seconds)
Adds public cache headers.
cache(int seconds,
boolean isCachePrivate)
Adds cache headers.
Adds cache headers.
The path to the resource, on the classpath.
cors()
Enables Cross-Origin Resource Sharing (Cors)
Enables Cross-Origin Resource Sharing (Cors)
Enables Cross-Origin Resource Sharing (Cors)
cors(Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead,
Set<String> extraHeadersAllowedToBeSent)
Enables Cross-Origin Resource Sharing (Cors)
cors(Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead,
Set<String> extraHeadersAllowedToBeSent,
boolean allowCookies)
Enables Cross-Origin Resource Sharing (Cors)
cors(Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead,
Set<String> extraHeadersAllowedToBeSent,
boolean allowCookies,
int maxAgeInSeconds)
Enables Cross-Origin Resource Sharing (Cors)
create()
Creates and returns the static resource without adding it to
the router.
protected Integer
The origins allowed, by default.
The extra headers allowed to be read, by default,
The extra headers allowed to be sent, by default,
protected boolean
Are cookies allowed by default?
protected int
If <= 0, the "Access-Control-Max-Age" header
won't be sent.
protected StaticResourceCacheConfig
The default cache configurations to use if it is
not specified.
getPath()
protected SpincastConfig
protected SpincastRouterConfig
protected SpincastUtils
protected StaticResourceCacheConfigFactory
protected StaticResourceCorsConfigFactory
protected StaticResourceFactory<R>
getUrl()
void
handle()
Saves the static resource route to the router.
void
Saves the static resource route.
void
Saves the static resource route.
When a static resource is flagged as being
*hotlinking protected*, the server will
validate the origin
and referer
of the request.
hotlinkingProtected(HotlinkingManager hotlinkingManager)
When a static resource is flagged as being
*hotlinking protected*, the server will
validate the origin
and referer
of the request.
protected boolean
Is the cache private by default?
boolean
protected boolean
isDir()
boolean
boolean
protected boolean
pathAbsolute(String absolutePath)
The absolute path to the resource, on the file system.
pathRelative(String relativePath)
The path to the resource, on the file system, relative to the
temp Spincast directory, as returned by
SpincastConfig::getSpincastTempDir()
This should only by called by *plugins*.
The URL pointing to the resource.
-
Field Details
-
logger
protected static final org.slf4j.Logger logger
-
Constructor Details
-
StaticResourceBuilderDefault
public StaticResourceBuilderDefault(boolean isDir,
StaticResourceFactory<R> staticResourceFactory,
StaticResourceCorsConfigFactory staticResourceCorsConfigFactory,
StaticResourceCacheConfigFactory staticResourceCacheConfigFactory,
SpincastConfig spincastConfig,
SpincastUtils spincastUtils,
SpincastRouterConfig spincastRouterConfig)
-
StaticResourceBuilderDefault
public StaticResourceBuilderDefault(Router<R,W> router,
boolean isDir,
StaticResourceFactory<R> staticResourceFactory,
StaticResourceCorsConfigFactory staticResourceCorsConfigFactory,
StaticResourceCacheConfigFactory staticResourceCacheConfigFactory,
SpincastConfig spincastConfig,
SpincastUtils spincastUtils,
SpincastRouterConfig spincastRouterConfig)
-
Method Details
-
isDir
protected boolean isDir()
-
isSpicastOrPluginAddedResource
protected boolean isSpicastOrPluginAddedResource()
-
getRouter
-
getStaticResourceFactory
-
getStaticResourceCorsConfigFactory
-
getStaticResourceCacheConfigFactory
-
getSpincastConfig
-
getSpincastUtils
-
getSpincastRouterConfig
-
getUrl
-
getPath
-
isHotlinkingProtected
public boolean isHotlinkingProtected()
-
getHotlinkingManager
-
isClasspath
public boolean isClasspath()
-
getGenerator
-
getCorsConfig
-
getCacheConfig
-
isIgnoreQueryString
public boolean isIgnoreQueryString()
-
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
Description copied from interface: StaticResourceBuilder
The URL pointing to the resource.
- Specified by:
url
in interface StaticResourceBuilder<R extends RequestContext<?>>
-
classpath
Description copied from interface: StaticResourceBuilder
The path to the resource, on the classpath.
- Specified by:
classpath
in interface StaticResourceBuilder<R extends RequestContext<?>>
-
pathAbsolute
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
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
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
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
The origins allowed, by default.
-
getCorsDefaultExtraHeadersAllowedToBeRead
The extra headers allowed to be read, by default,
-
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
-
cache
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
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
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
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
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
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
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
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
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<?>>