Class CssFile

java.lang.Object
com.oorian.HttpFile
com.oorian.css.CssFile

public abstract class CssFile extends HttpFile
Abstract base class for generating CSS files dynamically at runtime.

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 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

      public CssFile(String name)
      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-cache headers. A custom cache control policy set via HttpFile.setCacheControl(com.oorian.security.CacheControl) takes precedence over the defaults.

      Overrides:
      initializeFile in class HttpFile
      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:
      createFile in class HttpFile
    • clearCache

      public static void clearCache()
      Clears all cached stylesheets.

      This method should be called during application shutdown to free memory.

    • createStyleSheet

      protected abstract CssStyleSheet 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

      protected void toString(StringBuilder sb)
      Appends the stylesheet content to the output buffer.
      Specified by:
      toString in class HttpFile
      Parameters:
      sb - The StringBuilder to append CSS content to.