Class CssFile
CssFile extends HttpFile to serve CSS content through HTTP requests. Subclasses implement
the createStyleSheet() method to define the CSS rules programmatically.
CssFile supports two modes of operation:
- Dynamic mode - CSS is regenerated on each request (default constructor)
- Cached mode - CSS is generated once and cached by name (named constructor)
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidClears all cached stylesheets.protected voidCreates or retrieves the CSS stylesheet content.protected abstract CssStyleSheetCreates the CSS stylesheet for this file.protected booleanInitializes the HTTP response for CSS content.protected voidAppends the stylesheet content to the output buffer.Methods inherited from class com.oorian.HttpFile
addResponseHeader, create, getCacheControl, getDocumentUrl, getFullUrl, getHost, getHttpRequest, getOriginalParameters, getParameter, getParameterAsFloat, getParameterAsInt, getParameterAsLong, getParameterAsShort, getParameters, getParametersAFloat, getParametersAsInt, getParametersAsLong, getParametersAsShort, getParameterValues, getPath, getServletPath, getSessionId, getUrl, getUrlParameters, getWebResponse, hasParameter, hasUrlParams, isWritten, onCreated, onWriteComplete, setCacheControl, setCharacterEncoding, setContentType, setResponseHeader, setUrlParameters, toString, toString, write
-
Constructor Details
-
CssFile
public CssFile()Constructs a dynamic CSS file that regenerates on each request.CSS generated in dynamic mode is not cached and will be recreated for every request. Use this constructor when the CSS content depends on request-specific data.
-
CssFile
Constructs a cacheable CSS file with the specified name.CSS generated with a name is cached globally. Subsequent requests for the same name will return the cached stylesheet without regenerating it.
- Parameters:
name- The unique name used to cache and retrieve this stylesheet.
-
-
Method Details
-
initializeFile
protected boolean initializeFile()Initializes the HTTP response for CSS content.Sets the content type to "text/css" and applies cache headers. Cached-mode files receive long-lived cache headers with an ETag, while dynamic-mode files receive
no-cacheheaders. A custom cache control policy set viaHttpFile.setCacheControl(com.oorian.security.CacheControl)takes precedence over the defaults.- Overrides:
initializeFilein classHttpFile- Returns:
- Always returns true to continue processing.
-
createFile
protected void createFile()Creates or retrieves the CSS stylesheet content.For cached stylesheets, checks the cache first and returns the cached version if available. For dynamic stylesheets, always creates a new stylesheet instance.
- Specified by:
createFilein classHttpFile
-
clearCache
public static void clearCache()Clears all cached stylesheets.This method should be called during application shutdown to free memory.
-
createStyleSheet
Creates the CSS stylesheet for this file.Subclasses must implement this method to define the CSS rules that will be included in the generated CSS file.
- Returns:
- A CssStyleSheet containing the CSS rules for this file.
-
toString
Appends the stylesheet content to the output buffer.
-