Class FileVar


public class FileVar extends DefaultingVar
File resource variable resolver

The format for this var is "$F{path[,defaultValue]}".

Contents of files are retrieved from the request using RestRequest.getStaticFiles().

Localized resources (based on the locale of the HTTP request) are supported. For example, if looking for the resource "MyResource.txt" for the Japanese locale, we will look for files in the following order:

  1. "MyResource_ja_JP.txt"
  2. "MyResource_ja.txt"
  3. "MyResource.txt"

Example:

@HtmlDocConfig( aside="$F{resources/MyAsideMessage.html, Oops not found!}" )

Files of type HTML, XHTML, XML, JSON, Javascript, and CSS will be stripped of comments. This allows you to place license headers in files without them being serialized to the output.

This variable resolver requires that a RestRequest bean be available in the session bean store.

See Also:
  • Field Details

  • Constructor Details

    • FileVar

      public FileVar()
      Constructor.
  • Method Details

    • resolve

      public String resolve(VarResolverSession session, String key) throws Exception
      Description copied from class: Var
      The interface that needs to be implemented for subclasses of SimpleVar.
      Specified by:
      resolve in class Var
      Parameters:
      session - The session object used for a single instance of a var resolution.
      key - The inside argument of the variable.
      Returns:
      The resolved value.
      Throws:
      Exception - Any exception can be thrown.
    • canResolve

      public boolean canResolve(VarResolverSession session)
      Description copied from class: Var
      Returns true if this variable can be resolved in the specified session.

      For example, some variable cannot resolve unless specific context or session objects are available.

      Overrides:
      canResolve in class Var
      Parameters:
      session - The current session.
      Returns:
      true if this variable can be resolved in the specified session.