org.ibisph.mvc.controller
Class PublishXML

java.lang.Object
  extended by org.ibisph.mvc.controller.PublishXML
All Implemented Interfaces:
org.springframework.web.servlet.mvc.Controller
Direct Known Subclasses:
PublishIndicator, PublishIndicatorView, PublishOrgUnits

public class PublishXML
extends java.lang.Object
implements org.springframework.web.servlet.mvc.Controller

Base Publish XML Controller which can be directly used or extended. This controller has the base XML path as a property and the core class that gets the streamed XML from the admin system and puts into an XML Document. Controllers extending this controller need to focus on saving the document to the appropriate path and filename and returning.

Author:
Garth Braithwaite, STG

Field Summary
protected  java.lang.String destinationXMLPath
           
protected  Document documentDAO
           
protected  FileBackupFactory fileBackupFactory
           
protected  java.lang.String successReturnValue
           
 
Constructor Summary
PublishXML()
           
 
Method Summary
protected  java.lang.String getBaseFilename(javax.servlet.http.HttpServletRequest request)
          Helper method used to get the base filename (partial path and filename).
 java.lang.String getDestinationXMLPath()
          Sets the base path of where to save the XML content to.
 Document getDocumentDAO()
          DAO object that is used to save the XML content with.
protected  org.dom4j.Document getXMLDocument(javax.servlet.http.HttpServletRequest request)
          Helper method used to get the XML content sent from the requester.
 org.springframework.web.servlet.ModelAndView handleRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Controller method called by the Spring MVC framework to handle the publishing.
protected  java.lang.String postSaveXMLProcessing(java.lang.String baseFilename, org.dom4j.Document document)
          Handle any special post publish processing like deleting associated artifacts.
protected  void sendError(javax.servlet.http.HttpServletResponse response, java.lang.Exception e, java.lang.String actionsReturnMessage)
          Helper to localize error sent to requester.
protected  void sendSuccess(javax.servlet.http.HttpServletResponse response, java.lang.String actionsReturnMessage)
          Helper to localize success message sent to requester.
 void setDestinationXMLPath(java.lang.String xmlPath)
          Sets the base path of where to save the XML content to.
 void setDocumentDAO(Document documentDAO)
          Sets the DAO object that will be used to save the XML content with.
 void setFileBackupFactory(FileBackupFactory fileBackupFactory)
          Optional file backup factory that provides a file backup used to backup the current XML file.
 void setSuccessReturnValue(java.lang.String successReturnValue)
          Sets the string value that is returned to the requester.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

destinationXMLPath

protected java.lang.String destinationXMLPath

documentDAO

protected Document documentDAO

fileBackupFactory

protected FileBackupFactory fileBackupFactory

successReturnValue

protected java.lang.String successReturnValue
Constructor Detail

PublishXML

public PublishXML()
Method Detail

setDestinationXMLPath

public void setDestinationXMLPath(java.lang.String xmlPath)
Sets the base path of where to save the XML content to.

Parameters:
xmlPath - Complete file path with or without trailing slash.

setDocumentDAO

public void setDocumentDAO(Document documentDAO)
Sets the DAO object that will be used to save the XML content with. This simply keeps with the pluggable Spring framework.

Parameters:
documentDAO - Standard Document DAO used to save the XML document to disk.

setFileBackupFactory

public void setFileBackupFactory(FileBackupFactory fileBackupFactory)
Optional file backup factory that provides a file backup used to backup the current XML file.

Parameters:
fileBackupFactory - Provides a pluggable file backup used to backup the current XML file before the new content is published.

setSuccessReturnValue

public void setSuccessReturnValue(java.lang.String successReturnValue)
Sets the string value that is returned to the requester.

Parameters:
successReturnValue - Value that is returned to the requester if the XML is valid and if the XML document was successfully saved to the specified filename/path.

getDestinationXMLPath

public java.lang.String getDestinationXMLPath()
Sets the base path of where to save the XML content to.

Returns:
Path Complete file path with or without trailing slash.

getDocumentDAO

public Document getDocumentDAO()
DAO object that is used to save the XML content with.

Returns:
Standard Document DAO used to save the XML document to disk.

handleRequest

public org.springframework.web.servlet.ModelAndView handleRequest(javax.servlet.http.HttpServletRequest request,
                                                                  javax.servlet.http.HttpServletResponse response)
                                                           throws java.lang.Exception
Controller method called by the Spring MVC framework to handle the publishing. This method handles getting the XML document by calling the standard getXMLDocument method, builds the appropriate XML filename to save to, calls the optional file backup, and if successfully able to parse and save returns the success string. Otherwise the backup file is restored and a null is returned to the user.

Specified by:
handleRequest in interface org.springframework.web.servlet.mvc.Controller
Parameters:
request - HTTP Servlet Request passed from the servlet.
response - HTTP Servlet Response passed from the servlet.
Returns:
null - Handles its own error and success view responses.
Throws:
java.lang.Exception

getBaseFilename

protected java.lang.String getBaseFilename(javax.servlet.http.HttpServletRequest request)
                                    throws java.lang.Exception
Helper method used to get the base filename (partial path and filename).

Parameters:
request - Access to the standard HTTP request used to retrieve the path info.
Returns:
base filename (partial path and filename) of the request.
Throws:
java.lang.Exception

getXMLDocument

protected org.dom4j.Document getXMLDocument(javax.servlet.http.HttpServletRequest request)
                                     throws java.lang.Exception
Helper method used to get the XML content sent from the requester.

Parameters:
request - Access to the standard HTTP request used to retrieve the path info.
Returns:
Complete, valid, parsed XML document, null if not successful.
Throws:
java.lang.Exception

postSaveXMLProcessing

protected java.lang.String postSaveXMLProcessing(java.lang.String baseFilename,
                                                 org.dom4j.Document document)
                                          throws java.lang.Exception
Handle any special post publish processing like deleting associated artifacts.

Parameters:
baseFilename - Filename of the file just published without any path info.
document - XML document just published.
Returns:
String that describes what this operation did. If a problem happens then throw the appropriate exception. This message is typically to be returned to the user so they know the status of the operation(s).
Throws:
java.lang.Exception - General exception for any sub classed implementors.

sendError

protected void sendError(javax.servlet.http.HttpServletResponse response,
                         java.lang.Exception e,
                         java.lang.String actionsReturnMessage)
                  throws java.lang.Exception
Helper to localize error sent to requester. This is also needed so that special errors can be implemented for sub classes.

Parameters:
response - Response object used for the request.
e - Optional exception associated with the error.
actionsReturnMessage - Optional error message to send back to requester.
Throws:
java.lang.Exception

sendSuccess

protected void sendSuccess(javax.servlet.http.HttpServletResponse response,
                           java.lang.String actionsReturnMessage)
                    throws java.lang.Exception
Helper to localize success message sent to requester. This is also needed so that special messages can be implemented for sub classes.

Parameters:
response - Response object used for the request.
actionsReturnMessage - Optional message to send back to requester.
Throws:
java.lang.Exception