org.sandev.tools.HTTP
Class XHTMLFormEditor

java.lang.Object
  extended byorg.sandev.tools.HTTP.XHTMLFormEditor

public class XHTMLFormEditor
extends java.lang.Object

Provides a simple XHTML UI for editing a single form serialized to a file. This can be used to edit things like configurations and other structures which are stored for use by the application. This class is a helper class for servlets set up to handle specific editing tasks.

This class is configured with the file containing the form instance information, a CharSerializer to read the file contents with, a UIFormAdaptor to handle rendering, a UIFormManager to handle user actions on the form, and a UIFormOwner to handle high level functions (find, save, help).

The UIFormOwner may choose to implement formHelp by simply setting the UIFormContext output text to "help: " plus the name of the class to be displayed. For example:

which will trigger a popup window with the docs for the message class.

The XHTMLFormEditor does not perform any authorization processing. Access can be restricted at the file level for the instance file specified.


Field Summary
protected  java.lang.String displayTitle
          The title of the page to be displayed.
protected  java.lang.String errorID
          A label used to identify error output.
protected  org.sandev.basics.util.UIFormAdaptor formAdaptor
          The form adaptor we are using for output.
protected  org.sandev.basics.util.UIFormManager formManager
          A manager to handle basic form context actions.
protected  org.sandev.basics.util.UIFormOwner formOwner
          The owner of the form.
protected  java.io.File instanceFile
          The file containing the instance information we are editing.
protected  java.lang.String messageClassName
          The short class name of the message we are editing.
protected  org.sandev.basics.nodecommon.CharSerializer serializer
          A serializer for reconstituting the message information from the input file.
 
Constructor Summary
XHTMLFormEditor()
          Default ctor does nothing.
 
Method Summary
protected  void convertAndDisplay(java.lang.String formHTML, javax.servlet.http.HttpServletResponse res, java.lang.String helpfile)
          Take the output that was returned by UIFormAdaptor and convert it, then display.
 void doRequest(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Like handleRequest but without error trapping.
 java.lang.String getDisplayTitle()
          accessor for displayTitle
 java.lang.String getErrorID()
          accessor for errorID
 org.sandev.basics.util.UIFormAdaptor getFormAdaptor()
          accessor for formAdaptor
 org.sandev.basics.util.UIFormManager getFormManager()
          accessor for formManager
 org.sandev.basics.util.UIFormOwner getFormOwner()
          accessor for formOwner
protected  java.lang.String getHelpFile(org.sandev.basics.util.UIFormContext uifc)
          Return the name of the helpfile to display.
 java.io.File getInstanceFile()
          accessor for instanceFile
 java.lang.String getMessageClassName()
          accessor for messageClassName
 org.sandev.basics.nodecommon.CharSerializer getSerializer()
          accessor for serializer
 void handleRequest(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
           
protected  void initialize(org.sandev.basics.util.UIFormContext uifc)
          Initialize the UIFormContext as we are starting from scratch.
protected  java.lang.String insertPopUp(java.lang.String formHTML, java.lang.String helpfile)
          Given some XHTML, modify it to create a pop up containing the given helpfile text.
protected  void loadForm(org.sandev.basics.util.UIFormContext uifc)
          Load the message we are editing from the file specified.
 void setDisplayTitle(java.lang.String val)
          mutator for displayTitle
 void setErrorID(java.lang.String name)
          mutator for errorID
 void setFormAdaptor(org.sandev.basics.util.UIFormAdaptor uifa)
          mutator for formAdaptor
 void setFormManager(org.sandev.basics.util.UIFormManager uifm)
          mutator for formManager
 void setFormOwner(org.sandev.basics.util.UIFormOwner uifo)
          mutator for formOwner
 void setInstanceFile(java.io.File f)
          mutator for instanceFile
 void setMessageClassName(java.lang.String val)
          mutator for messageClassName
 void setSerializer(org.sandev.basics.nodecommon.CharSerializer cs)
          mutator for serializer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

errorID

protected java.lang.String errorID
A label used to identify error output. This is typically set to the name of the calling servlet so the source can be identified from the log file message.


displayTitle

protected java.lang.String displayTitle
The title of the page to be displayed.


messageClassName

protected java.lang.String messageClassName
The short class name of the message we are editing. For example "Configuration". This is used when there is no pre-existing file, and for initializing the UIFormContext.


instanceFile

protected java.io.File instanceFile
The file containing the instance information we are editing.


serializer

protected org.sandev.basics.nodecommon.CharSerializer serializer
A serializer for reconstituting the message information from the input file.


formManager

protected org.sandev.basics.util.UIFormManager formManager
A manager to handle basic form context actions.


formOwner

protected org.sandev.basics.util.UIFormOwner formOwner
The owner of the form. Responsible for high level operations unique to the editing context.


formAdaptor

protected org.sandev.basics.util.UIFormAdaptor formAdaptor
The form adaptor we are using for output. This class must be initialized and ready for use.

Constructor Detail

XHTMLFormEditor

public XHTMLFormEditor()
Default ctor does nothing.

Method Detail

getErrorID

public java.lang.String getErrorID()
accessor for errorID


setErrorID

public void setErrorID(java.lang.String name)
mutator for errorID


getDisplayTitle

public java.lang.String getDisplayTitle()
accessor for displayTitle


setDisplayTitle

public void setDisplayTitle(java.lang.String val)
mutator for displayTitle


getMessageClassName

public java.lang.String getMessageClassName()
accessor for messageClassName


setMessageClassName

public void setMessageClassName(java.lang.String val)
mutator for messageClassName


getInstanceFile

public java.io.File getInstanceFile()
accessor for instanceFile


setInstanceFile

public void setInstanceFile(java.io.File f)
mutator for instanceFile


getSerializer

public org.sandev.basics.nodecommon.CharSerializer getSerializer()
accessor for serializer


setSerializer

public void setSerializer(org.sandev.basics.nodecommon.CharSerializer cs)
mutator for serializer


getFormManager

public org.sandev.basics.util.UIFormManager getFormManager()
accessor for formManager


setFormManager

public void setFormManager(org.sandev.basics.util.UIFormManager uifm)
mutator for formManager


getFormOwner

public org.sandev.basics.util.UIFormOwner getFormOwner()
accessor for formOwner


setFormOwner

public void setFormOwner(org.sandev.basics.util.UIFormOwner uifo)
mutator for formOwner


getFormAdaptor

public org.sandev.basics.util.UIFormAdaptor getFormAdaptor()
accessor for formAdaptor


setFormAdaptor

public void setFormAdaptor(org.sandev.basics.util.UIFormAdaptor uifa)
mutator for formAdaptor


handleRequest

public void handleRequest(javax.servlet.http.HttpServletRequest req,
                          javax.servlet.http.HttpServletResponse res)

doRequest

public void doRequest(javax.servlet.http.HttpServletRequest req,
                      javax.servlet.http.HttpServletResponse res)
               throws java.lang.Exception
Like handleRequest but without error trapping. This method throws a general exception which can be: Call this method directly if you want to do your own error handling.

Throws:
java.lang.Exception

initialize

protected void initialize(org.sandev.basics.util.UIFormContext uifc)
                   throws org.sandev.basics.util.UIFormAdaptorException
Initialize the UIFormContext as we are starting from scratch. The default mode is LISTING.

Throws:
org.sandev.basics.util.UIFormAdaptorException

loadForm

protected void loadForm(org.sandev.basics.util.UIFormContext uifc)
                 throws org.sandev.basics.util.UIFormAdaptorException
Load the message we are editing from the file specified. If the the file is not found, then initialize a new instance of the message by name. The message is assumed to be a SandStructMessage.

Throws:
org.sandev.basics.util.UIFormAdaptorException

getHelpFile

protected java.lang.String getHelpFile(org.sandev.basics.util.UIFormContext uifc)
Return the name of the helpfile to display. This returns the name of the doc file for the class mentioned in the output text. So if the output text is Then this method returns the file name for the MessageClass docs.


convertAndDisplay

protected void convertAndDisplay(java.lang.String formHTML,
                                 javax.servlet.http.HttpServletResponse res,
                                 java.lang.String helpfile)
                          throws java.io.IOException
Take the output that was returned by UIFormAdaptor and convert it, then display.

Throws:
java.io.IOException

insertPopUp

protected java.lang.String insertPopUp(java.lang.String formHTML,
                                       java.lang.String helpfile)
Given some XHTML, modify it to create a pop up containing the given helpfile text. The result may not be XHTML compatible, and we are assuming that it's ok to overwrite the body tag.