2.17.2: 2011-06-17

net.sf.basedb.clients.web.extensions
Class JspContext

java.lang.Object
  extended by net.sf.basedb.util.extensions.ClientContext
      extended by 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 Summary
static String ATTRIBUTE_KEY
          The key that is used when storing a JspContext object in a request/page/session/etc. attribute.
private  ExtensionsDirectory directory
           
private  GuiContext guiContext
           
private  PageContext pageContext
           
private  Set<String> scripts
           
private  Set<String> stylesheets
           
 
Constructor Summary
JspContext(ExtensionsDirectory directory, SessionControl sc, DbControl dc, PageContext pageContext, GuiContext guiContext, Object item)
           
 
Method Summary
 void addScript(String absolutePath)
          Add an absolute reference to a script that should be included on the generated page with a <script> tag.
 void addStylesheet(String absolutePath)
          Add an absolute reference to a CSS stylesheet that should be included on the generated page with a <link> tag.
 GuiContext getGuiContext()
          Get the current GuiContext.
 String getHome(Extension extension)
          Get the URL to the home directory for a given extension.
 JspWriter getOut()
          Get a writer object that can be used to return generated text to the response that is sent back to the browser.
 PageContext getPageContext()
          Get the JSP Page context object for the current request.
 String getRoot()
          Get the URL to the web application root as a string.
 Collection<String> getScripts()
          Get all scripts that has been added to this context.
 Collection<String> getStylesheets()
          Get all stylesheets that has been added to this context.
 
Methods inherited from class net.sf.basedb.util.extensions.ClientContext
getAttribute, getCurrentItem, getDbControl, getSessionControl, setAttribute, setCurrentItem
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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:
Constant Field Values

directory

private final ExtensionsDirectory directory

pageContext

private final PageContext pageContext

guiContext

private final GuiContext guiContext

scripts

private Set<String> scripts

stylesheets

private Set<String> stylesheets
Constructor Detail

JspContext

JspContext(ExtensionsDirectory directory,
           SessionControl sc,
           DbControl dc,
           PageContext pageContext,
           GuiContext guiContext,
           Object item)
Method Detail

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

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

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

getScripts

public Collection<String> getScripts()
Get all scripts that has been added to this context.

Returns:
A collection of scripts

getStylesheets

public Collection<String> getStylesheets()
Get all stylesheets that has been added to this context.

Returns:
A collection of stylesheets

2.17.2: 2011-06-17