adapforms.web
Class WebSessionImpl

java.lang.Object
  extended by adapforms.web.WebSessionImpl
All Implemented Interfaces:
WebSession

public class WebSessionImpl
extends java.lang.Object
implements WebSession

Concrete implementation of WebSession.

Author:
Henrik Gammelmark, geemark@cs.au.dk

Constructor Summary
WebSessionImpl(FormInstanceImpl instance)
          Create a new session given a form instance.
 
Method Summary
 java.util.Date createdAt()
          When was this session created?
 java.util.List<Adaptation> endAdaptationCycle()
          Calls FormInstanceImpl.endAdaptationCycle(), and adds any web-specific adaptations.
 void executeScript(java.lang.String scriptFragment)
          Execute a fragment of JavaScript on the web client.
 java.util.Set<FormPath> getElementsRendered()
          Get the mutable set of FormPaths corresponding to elements rendered to the client already.
 GUID getGUID()
          The unique identifier of the web session.
 FormInstance getInstance()
          Obtain the instance belonging to the session.
 boolean getRenderTitle()
           
 void redirectClient(java.lang.String url)
          Force the user web browser page containing the form to redirect to the specified URL.
 void setRenderTitle(boolean render)
          Specify whether the title of the document should be rendered to the web client.
 void writeHeadersToClient(javax.servlet.ServletRequest req, javax.servlet.ServletResponse resp)
          Render the required XHTML headers to the web client.
 void writeToClient(javax.servlet.ServletRequest req, javax.servlet.ServletResponse resp)
          Render the instantiated form to the web client.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebSessionImpl

WebSessionImpl(FormInstanceImpl instance)
Create a new session given a form instance.

Method Detail

getGUID

public GUID getGUID()
Description copied from interface: WebSession
The unique identifier of the web session.

Specified by:
getGUID in interface WebSession

getInstance

public FormInstance getInstance()
Description copied from interface: WebSession
Obtain the instance belonging to the session.

Specified by:
getInstance in interface WebSession

writeToClient

public void writeToClient(javax.servlet.ServletRequest req,
                          javax.servlet.ServletResponse resp)
                   throws FormRuntimeException
Description copied from interface: WebSession
Render the instantiated form to the web client.

Notice: It is recommended that you call WebSession.writeHeadersToClient(ServletRequest, ServletResponse) manuelly inside the "head" tag of your document. If not, the call to this method will ourput the headers in the position of the form, which may work but is not valid XHTML.

Specified by:
writeToClient in interface WebSession
Parameters:
req - The HTTP servlet request. Used for reading context information.
resp - The HTTP servlet response. Used for outputting the rendered form.
Throws:
FormRuntimeException - If anything goes wrong during the process.

writeHeadersToClient

public void writeHeadersToClient(javax.servlet.ServletRequest req,
                                 javax.servlet.ServletResponse resp)
                          throws FormRuntimeException
Description copied from interface: WebSession
Render the required XHTML headers to the web client.
This provides a means of generating valid XHTML, as these headers should be placed inside the XHTML "head" tag.

Specified by:
writeHeadersToClient in interface WebSession
Parameters:
req - The HTTP servlet request. Used for reading context information.
resp - The HTTP servlet response. Used for outputting the rendered header
Throws:
FormRuntimeException - If anything goes wrong during the process.

redirectClient

public void redirectClient(java.lang.String url)
                    throws FormStateException
Description copied from interface: WebSession
Force the user web browser page containing the form to redirect to the specified URL. The web URL may be relative or absolute.

Specified by:
redirectClient in interface WebSession
Throws:
FormStateException

executeScript

public void executeScript(java.lang.String scriptFragment)
                   throws FormStateException
Description copied from interface: WebSession
Execute a fragment of JavaScript on the web client. This may be a function call to an already loaded JavaScript library, or a complete block of JavaScript.

Use with caution: No checks are performed on the parsed script; it is merely attempted executed as is.

Specified by:
executeScript in interface WebSession
Throws:
FormStateException

endAdaptationCycle

public java.util.List<Adaptation> endAdaptationCycle()
                                              throws FormStateException
Calls FormInstanceImpl.endAdaptationCycle(), and adds any web-specific adaptations.

Throws:
FormStateException

getElementsRendered

public java.util.Set<FormPath> getElementsRendered()
Get the mutable set of FormPaths corresponding to elements rendered to the client already.

This is used to e.g. keep track of which nested elements should be deleted, when a repeat entry is deleted.


setRenderTitle

public void setRenderTitle(boolean render)
Description copied from interface: WebSession
Specify whether the title of the document should be rendered to the web client.

Specified by:
setRenderTitle in interface WebSession

getRenderTitle

public boolean getRenderTitle()
Specified by:
getRenderTitle in interface WebSession
See Also:
WebSession.setRenderTitle(boolean)

createdAt

public java.util.Date createdAt()
Description copied from interface: WebSession
When was this session created?

Specified by:
createdAt in interface WebSession