Class Widget

java.lang.Object
org.apache.juneau.rest.widget.Widget
All Implemented Interfaces:
HtmlWidget
Direct Known Subclasses:
MenuItemWidget, PoweredByApache, PoweredByJuneau

public abstract class Widget extends Object implements HtmlWidget
Defines an interface for resolvers of "$W{...}" string variables.

Widgets must provide one of the following public constructors:

  • public Widget();
  • public Widget(ContextProperties);

Widgets can be defined as inner classes of REST resource classes.

See Also:
  • Constructor Details

  • Method Details

    • getName

      public String getName()
      The widget key.

      (i.e. The variable name inside the "$W{...}" variable).

      The returned value must not be null.

      If not overridden, the default value is the class simple name.

      Specified by:
      getName in interface HtmlWidget
      Returns:
      The widget key.
    • getHtml

      public String getHtml(VarResolverSession session)
      Description copied from interface: HtmlWidget
      Resolves the HTML content for this widget.

      A returned value of null will cause nothing to be added to the page.

      Specified by:
      getHtml in interface HtmlWidget
      Parameters:
      session - The current serializer session.
      Returns:
      The HTML content of this widget.
    • getScript

      Description copied from interface: HtmlWidget
      Resolves any Javascript that should be added to the <head>/<script> element.

      A returned value of null will cause nothing to be added to the page.

      Specified by:
      getScript in interface HtmlWidget
      Parameters:
      session - The current serializer session.
      Returns:
      The Javascript needed by this widget.
    • getStyle

      Description copied from interface: HtmlWidget
      Resolves any CSS styles that should be added to the <head>/<style> element.

      A returned value of null will cause nothing to be added to the page.

      Specified by:
      getStyle in interface HtmlWidget
      Parameters:
      session - The current serializer session.
      Returns:
      The CSS styles needed by this widget.
    • getHtml

      public String getHtml(RestRequest req, RestResponse res)
      Resolves the HTML content for this widget.

      A returned value of null will cause nothing to be added to the page.

      Parameters:
      req - The HTTP request object.
      res - The current HTTP response.
      Returns:
      The HTML content of this widget.
    • getScript

      Resolves any Javascript that should be added to the <head>/<script> element.

      A returned value of null will cause nothing to be added to the page.

      Parameters:
      req - The HTTP request object.
      res - The current HTTP response.
      Returns:
      The Javascript needed by this widget.
    • getStyle

      Resolves any CSS styles that should be added to the <head>/<style> element.

      A returned value of null will cause nothing to be added to the page.

      Parameters:
      req - The HTTP request object.
      res - The current HTTP response.
      Returns:
      The CSS styles needed by this widget.
    • getFileFinder

      Returns the file finder to use for finding files on the file system.
      Parameters:
      req - The HTTP request object.
      Returns:
      The file finder to used for finding files on the file system.
    • loadScript

      protected String loadScript(RestRequest req, String name)
      Loads the specified javascript file and strips any Javascript comments from the file.

      Comments are assumed to be Java-style block comments: "/*".

      Parameters:
      req - The HTTP request object.
      name - Name of the desired resource.
      Returns:
      The resource converted to a string, or null if the resource could not be found.
    • loadScriptWithVars

      protected String loadScriptWithVars(RestRequest req, RestResponse res, String name) throws IOException
      Same as loadScript(RestRequest,String) but replaces request-time SVL variables.
      See Also:
      Parameters:
      req - The current HTTP request.
      res - The current HTTP response.
      name - Name of the desired resource.
      Returns:
      The resource converted to a string, or null if the resource could not be found.
      Throws:
      IOException - Thrown by underlying stream.
    • loadStyle

      protected String loadStyle(RestRequest req, String name)
      Loads the specified CSS file and strips CSS comments from the file.

      Comments are assumed to be Java-style block comments: "/*".

      Parameters:
      req - The HTTP request object.
      name - Name of the desired resource.
      Returns:
      The resource converted to a string, or null if the resource could not be found.
    • loadStyleWithVars

      protected String loadStyleWithVars(RestRequest req, RestResponse res, String name) throws IOException
      Same as loadStyle(RestRequest,String) but replaces request-time SVL variables.
      See Also:
      Parameters:
      req - The current HTTP request.
      res - The current HTTP response.
      name - Name of the desired resource.
      Returns:
      The resource converted to a string, or null if the resource could not be found.
      Throws:
      IOException - Thrown by underlying stream.
    • loadHtml

      protected String loadHtml(RestRequest req, String name)
      Loads the specified HTML file and strips HTML comments from the file.

      Comment are assumed to be "<!-- -->" code blocks.

      Parameters:
      req - The HTTP request object.
      name - Name of the desired resource.
      Returns:
      The resource converted to a string, or null if the resource could not be found.
    • loadHtmlWithVars

      protected String loadHtmlWithVars(RestRequest req, RestResponse res, String name) throws IOException
      Same as loadHtml(RestRequest,String) but replaces request-time SVL variables.
      See Also:
      Parameters:
      req - The current HTTP request.
      res - The current HTTP response.
      name - Name of the desired resource.
      Returns:
      The resource converted to a string, or null if the resource could not be found.
      Throws:
      IOException - Thrown by underlying stream.