org.liquidsite.app.admin
Class ContentEditFormHandler

java.lang.Object
  extended byorg.liquidsite.core.web.FormHandler
      extended byorg.liquidsite.app.admin.AdminFormHandler
          extended byorg.liquidsite.app.admin.ContentEditFormHandler

public class ContentEditFormHandler
extends org.liquidsite.app.admin.AdminFormHandler

The content edit request handler. This class handles the edit workflow for the content view.


Constructor Summary
ContentEditFormHandler()
          Creates a new content edit request handler.
 
Method Summary
protected  java.lang.String convertFileName(java.lang.String name)
          Converts a file name to a valid file name.
protected  void display(Request request, int step)
          Displays a form for the specified workflow step.
protected  void displayDone(Request request)
          Displays the workflow finished page.
protected  void displayError(Request request, java.lang.String message)
          Displays the workflow error page.
protected  void displayStep(Request request, int step)
          Displays a form for the specified workflow step.
 java.lang.String getFormPage()
          Returns the form page for the workflow.
static ContentEditFormHandler getInstance()
          Returns an instance of this class.
 java.lang.String getStartPage()
          Returns the default start page for the workflow.
protected  int handle(Request request, int step)
          Handles a validated form for the specified workflow step.
 void handleAddDocumentFiles(Request request, ContentDocument doc)
          Handles adding all session files to a document.
 void handleFileRemoval(Request request)
          Handles a file removal (in the document editing form).
 void handleFileUpload(Request request)
          Handles a file upload (in the document editing form).
protected  int handleStep(Request request, int step)
          Handles a validated form for the specified workflow step.
protected  void lock(Content content, User user, boolean acquire)
          Checks or acquires a content lock.
protected  void unlock(Content content, User user, boolean force)
          Removes a content lock.
protected  void validate(Request request, int step)
          Validates a form for the specified workflow step.
protected  void validateParent(Request request, java.lang.String field, java.lang.String error)
          Validates a content name with regard to its parent.
protected  void validateStep(Request request, int step)
          Validates a form for the specified workflow step.
protected  void workflowEntered(Request request)
          This method locks content objects when entering the workflow.
protected  void workflowError(Request request, FormHandlingException e)
          This method is called when an error was encountered during the processing.
protected  void workflowExited(Request request)
          This method removes any files attached to the user session.
 
Methods inherited from class org.liquidsite.core.web.FormHandler
process, processWithoutErrorHandling
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContentEditFormHandler

public ContentEditFormHandler()
Creates a new content edit request handler.

Method Detail

getInstance

public static ContentEditFormHandler getInstance()
Returns an instance of this class. If a prior instance has been created, it will be returned instead of creating a new one.

Returns:
an instance of a content edit form handler

displayStep

protected void displayStep(Request request,
                           int step)
                    throws ContentException,
                           ContentSecurityException
Displays a form for the specified workflow step. This method will NOT be called when returning to the start page.

Parameters:
request - the request object
step - the workflow step
Throws:
ContentException - if the database couldn't be accessed properly
ContentSecurityException - if the user didn't have the required permissions

validateStep

protected void validateStep(Request request,
                            int step)
                     throws ContentException,
                            ContentSecurityException,
                            FormValidationException
Validates a form for the specified workflow step. If the form validation fails in this step, the form page for the workflow step will be displayed again with an 'error' attribute containing the message in the validation exception.

Parameters:
request - the request object
step - the workflow step
Throws:
ContentException - if the database couldn't be accessed properly
ContentSecurityException - if the user didn't have the required permissions
FormValidationException - if the form request data validation failed

handleStep

protected int handleStep(Request request,
                         int step)
                  throws ContentException,
                         ContentSecurityException
Handles a validated form for the specified workflow step. This method returns the next workflow step, i.e. the step used when calling the display method. If the special zero (0) workflow step is returned, the workflow is assumed to have terminated. Note that this method also allows additional validation to occur. By returning the incoming workflow step number and setting the appropriate request attributes the same results as in the normal validate method can be achieved. For recoverable errors, this is the recommended course of action.

Parameters:
request - the request object
step - the workflow step
Returns:
the next workflow step, or zero (0) if the workflow has finished
Throws:
ContentException - if the database couldn't be accessed properly
ContentSecurityException - if the user didn't have the required permissions

handleFileUpload

public void handleFileUpload(Request request)
                      throws ContentException
Handles a file upload (in the document editing form). The file will be added to the request session.

Parameters:
request - the request object
Throws:
ContentException - if the file couldn't be added to the session correctly

handleFileRemoval

public void handleFileRemoval(Request request)
Handles a file removal (in the document editing form). The file will either be removed from the request session or deleted as a content object.

Parameters:
request - the request object

handleAddDocumentFiles

public void handleAddDocumentFiles(Request request,
                                   ContentDocument doc)
                            throws ContentException,
                                   ContentSecurityException
Handles adding all session files to a document.

Parameters:
request - the request object
doc - the document content object
Throws:
ContentException - if the database couldn't be accessed properly
ContentSecurityException - if the user didn't have the required permissions

workflowExited

protected void workflowExited(Request request)
                       throws FormHandlingException
This method removes any files attached to the user session. It also calls the superclass implementation to unlock any locked objects.

Parameters:
request - the request object
Throws:
FormHandlingException - if an error was encountered while processing the form

getStartPage

public java.lang.String getStartPage()
Returns the default start page for the workflow. This is where redirects go when the workflow is finished, unless a start page is specified in the form.

Returns:
the start page for the workflow

getFormPage

public java.lang.String getFormPage()
Returns the form page for the workflow. This is where all form request will be posted.

Returns:
the form page for the workflow

display

protected final void display(Request request,
                             int step)
                      throws FormHandlingException
Displays a form for the specified workflow step. The special workflow step zero (0) is used for indicating display of the originating page outside the form workflow. Normally that would cause a redirect.

Specified by:
display in class FormHandler
Parameters:
request - the request object
step - the workflow step, or zero (0)
Throws:
FormHandlingException - if an error was encountered while processing the form

displayDone

protected void displayDone(Request request)
Displays the workflow finished page. By default this method sends a redirect to the start page.

Parameters:
request - the request object

displayError

protected void displayError(Request request,
                            java.lang.String message)
Displays the workflow error page. By default this method displays the site view error page and then redirects to the start page.

Parameters:
request - the request object
message - the error message

validate

protected final void validate(Request request,
                              int step)
                       throws FormHandlingException,
                              FormValidationException
Validates a form for the specified workflow step. If the form validation fails in this step, the form page for the workflow step will be displayed again with an 'error' attribute containing the message in the validation exception.

Specified by:
validate in class FormHandler
Parameters:
request - the request object
step - the workflow step
Throws:
FormHandlingException - if an error was encountered while processing the form
FormValidationException - if the form request data validation failed

validateParent

protected void validateParent(Request request,
                              java.lang.String field,
                              java.lang.String error)
                       throws ContentException,
                              ContentSecurityException,
                              FormValidationException
Validates a content name with regard to its parent. That is, this method will check that no other content objects with the same parent have the same name.

Parameters:
request - the request object
field - the parent id field
error - the message to use on validation error
Throws:
ContentException - if the database couldn't be accessed properly
ContentSecurityException - if the user didn't have the required permissions
FormValidationException - if the form request data validation failed

handle

protected final int handle(Request request,
                           int step)
                    throws FormHandlingException
Handles a validated form for the specified workflow step. This method returns the next workflow step, i.e. the step used when calling the display method. If the special zero (0) workflow step is returned, the workflow is assumed to have terminated. Note that this method also allows additional validation to occur. By returning the incoming workflow step number and setting the appropriate request attributes the same results as in the normal validate method can be achieved. For recoverable errors, this is the recommended course of action.

Specified by:
handle in class FormHandler
Parameters:
request - the request object
step - the workflow step
Returns:
the next workflow step, or zero (0) if the workflow has finished
Throws:
FormHandlingException - if an error was encountered while processing the form

workflowEntered

protected void workflowEntered(Request request)
                        throws FormHandlingException
This method locks content objects when entering the workflow. Nothing will be done if the lock flag hasn't been set of if the request doesn't reference a content object.

Overrides:
workflowEntered in class FormHandler
Parameters:
request - the request object
Throws:
FormHandlingException - if an error was encountered while processing the form

workflowError

protected void workflowError(Request request,
                             FormHandlingException e)
This method is called when an error was encountered during the processing. This event can be used for logging errors and displaying a simple error page. By default this method does nothing.

Overrides:
workflowError in class FormHandler
Parameters:
request - the request object
e - the form handling exception

lock

protected void lock(Content content,
                    User user,
                    boolean acquire)
             throws ContentException,
                    ContentSecurityException
Checks or acquires a content lock. This method will verify that any existing lock is owned by the correct user. If the acquire flag is not set, an existing lock will be checked for. If such a lock does not belong to the specified user, an exception will be thrown.

Parameters:
content - the content object
user - the user acquiring the lock
acquire - the acquire lock flag
Throws:
ContentException - if the database couldn't be accessed properly
ContentSecurityException - if the user didn't own and couldn't acquire the lock

unlock

protected void unlock(Content content,
                      User user,
                      boolean force)
               throws ContentException,
                      ContentSecurityException
Removes a content lock. This method will quietly ignore a missing lock or a lock owner by another user. If the force flag is specified, any existing lock will be removed.

Parameters:
content - the content object
user - the user removing the lock
force - the force removal flag
Throws:
ContentException - if the database couldn't be accessed properly
ContentSecurityException - if the user didn't have permission to remove the lock

convertFileName

protected java.lang.String convertFileName(java.lang.String name)
Converts a file name to a valid file name. All space characters and non-ASCII letters will be converted to '_' or '-'.

Parameters:
name - the file name to convert
Returns:
the converted file name