Class JspContext

java.lang.Object
net.sf.basedb.util.extensions.ClientContext
net.sf.basedb.clients.web.extensions.JspContext

public class JspContext extends ClientContext
Context object for the web application. Instances of this class are always used for passing client context information to web extensions. This means that it is always safe to cast the client context to this class in the ActionFactory.prepareContext(InvokationContext) and ActionFactory.getActions(InvokationContext) methods and other methods that has a context parameter.
@Override
public boolean prepareContext(InvokationContext context) 
{
        JspContext jspContext = (JspContext)context.getClientContext();
        jspContext.addStylesheet("/base/include/styles/mystylesheet.css");
        // Do other things
        return true;
}

This context exposes the underlying JSP PageContext, which can be used to get information about the current request among other things. Render factories usually needs access to the response output stream, getOut(), so that renderers can write the generated HTML to the response.

Version:
2.7
Author:
nicklas
Last modified
$Date:2008-03-20 12:15:25 +0100 (Thu, 20 Mar 2008) $
  • Field Details

    • ATTRIBUTE_KEY

      public static final String ATTRIBUTE_KEY
      The key that is used when storing a JspContext object in a request/page/session/etc. attribute.
      Since:
      2.17
      See Also:
    • EXTENSION_KEY

      public static final String EXTENSION_KEY
      The key that is used when storing an Extension object in a request/page/session/etc. attribute.
      Since:
      3.3
      See Also:
    • pageContext

      private final PageContext pageContext
    • guiContext

      private final GuiContext guiContext
    • itemContext

      private final ItemContext itemContext
    • needResourcesPerExtension

      private boolean needResourcesPerExtension
    • scripts

      private Map<String,Set<String>> scripts
    • stylesheets

      private Map<String,Set<String>> stylesheets
  • Constructor Details

  • Method Details

    • setNeedResourcesPerExtension

      public void setNeedResourcesPerExtension(boolean nrpe)
      Set a flag indicating that resources (eg. scripts and stylesheets) should be tracked per extension. If this is set, it is possible to use getScripts(String) and getStylesheets(String) to get the resources that was added by the given extension.
      Since:
      3.19.3
    • getPageContext

      public PageContext getPageContext()
      Get the JSP Page context object for the current request.
    • getOut

      public JspWriter getOut()
      Get a writer object that can be used to return generated text to the response that is sent back to the browser.

      Note! The writer is only intended to be used by render objects when rendering the extensions. Using the writer from the ActionFactory.prepareContext(InvokationContext) or RendererFactory.prepareContext(InvokationContext) method may produce unpredictable results.

      Returns:
      A JspWriter object
    • getGuiContext

      public GuiContext getGuiContext()
      Get the current GuiContext.
      Returns:
      A GuiContext object or null if it is not applicable to the extension point
      Since:
      2.12
    • getCurrentContext

      public ItemContext getCurrentContext()
      Get the current item context.
    • getRoot

      public String getRoot()
      Get the URL to the web application root as a string. The URL only includes the path information, not the server name or protocol.
    • getHome

      public String getHome(Extension<?> extension)
      Get the URL to the home directory for a given extension. The URL only includes the path information, not the server name or protocol.
      Parameters:
      extension - The extension
    • addScript

      public void addScript(String absolutePath)
      Add an absolute reference to a script that should be included on the generated page with a <script> tag. The path must be an absolute path.

      Note 1! This method must be called from the ActionFactory.prepareContext(InvokationContext) or RendererFactory.prepareContext(InvokationContext) methods. Changes to the context after that will not be reflected in the output.

      Note 2! Not all extension points supports custom scripts. Check the documentation for the extension point you are extending.

      Parameters:
      absolutePath - The absolute path
    • addScripts

      public void addScripts(Collection<String> scriptsToAdd)
      Add several scripts in one go. If the collection is null or empty nothing is done.
      Since:
      3.19.4
    • getSet

      private Set<String> getSet(Map<String,Set<String>> map, String key)
      Get the Set that is stored under the given key. If no Set exists it is created and stored in the map.
    • addStylesheet

      public void addStylesheet(String absolutePath)
      Add an absolute reference to a CSS stylesheet that should be included on the generated page with a <link> tag. The path must be the absolute path.

      Note 1! This method must be called from the ActionFactory.prepareContext(InvokationContext) or RendererFactory.prepareContext(InvokationContext) methods. Changes to the context after that will not be reflected in the output.

      Note 2! Not all extension points supports custom stylesheets. Check the documentation for the extension point you are extending.

      Parameters:
      absolutePath - The absolute path
    • addStylesheets

      public void addStylesheets(Collection<String> stylesheetsToAdd)
      Add several stylesheets in one go. If the collection is null or empty nothing is done.
      Since:
      3.19.4
    • getScripts

      public Collection<String> getScripts()
      Get all scripts that has been added to this context.
      Returns:
      A collection of scripts
    • getScripts

      public Collection<String> getScripts(String xtId)
      Get all scripts that has been added to this context by the given extension
      Returns:
      A collection of scripts
      Since:
      3.19.3
    • getStylesheets

      public Collection<String> getStylesheets()
      Get all stylesheets that has been added to this context.
      Returns:
      A collection of stylesheets
    • getStylesheets

      public Collection<String> getStylesheets(String xtId)
      Get all stylesheets that has been added to this context by the given extension.
      Returns:
      A collection of stylesheets
      Since:
      3.19.3