com.instantbank.lettertemplate.editor.web
Class TemplateEditorServlet

java.lang.Object
  |
  +--javax.servlet.GenericServlet
        |
        +--javax.servlet.http.HttpServlet
              |
              +--com.instantbank.lettertemplate.editor.web.TemplateEditorServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class TemplateEditorServlet
extends javax.servlet.http.HttpServlet

Servlet acting as a controller in order to ask ejb services for letter's template editor. Each method in this servlet has a corresponding one --having the same name, but different parameters-- in the TemplateEditorProxy class and in the LetterTemplate interface. Actual parameters in the TemplateEditorProxy methods are sent to this servlet --in the request-- and must be explicitly extracted by the corresponding methods in the servlet in order to be used as parameters for the services specified in the LetterTemplate interface.

Author:
InstantBank (Rodrigo Lopez, Consuelo Franky)
See Also:
Serialized Form

Field Summary
private  Debug debug
          The ubiquitous debug object.
private  java.util.Hashtable hashFields
          A hash table with company fields information
private  LetterTemplate letejb
          The ejb that provides the services for this servlet.
private  LetterTemplateHome lethome
          The home for the ejb that provides the services requested by this servlet.
 
Fields inherited from class javax.servlet.http.HttpServlet
HEADER_IFMODSINCE, HEADER_LASTMOD, LSTRING_FILE, lStrings, METHOD_DELETE, METHOD_GET, METHOD_HEAD, METHOD_OPTIONS, METHOD_POST, METHOD_PUT, METHOD_TRACE
 
Fields inherited from class javax.servlet.GenericServlet
config
 
Constructor Summary
TemplateEditorServlet()
           
 
Method Summary
private  java.lang.String brokenVarNames(java.util.Set brokenVars)
          Calculates a text containing a comma separated list of the names of variables in a Set.
private  void controlTimeout(java.io.ObjectOutputStream out, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Control time out in editor usecase: if timeout, inactivates the session and returns true if not timeout, reset timeout counter in lettertemplate and in Instantbank ear's and returns false.
 void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Acts as a dispatcher for the services encoded as LetterOp constants.
private  void exit(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, java.lang.String url)
          Exit from editor usecase for 2 possible reasons: user request or timeout
private  java.util.Set fixDateOffset(javax.servlet.http.HttpServletRequest req, LetterComponent comp)
          Brings to zero the inconsistent date offsets in a letter component.
private  java.util.Set fixDateOffset(javax.servlet.http.HttpServletRequest req, Template template)
          Brings to zero the inconsistent date offsets in a letter Template.
 void init()
          Description of the Method
private  void loadCategories(java.lang.String companyId, java.io.ObjectOutputStream out)
          Loads all [code, description] of the categories in the current company, from the web context or from the database.
private  void loadCodesStamps(java.io.ObjectInputStream in, java.io.ObjectOutputStream out)
          Loads code and stamp of template and components.
private  void loadComponent(javax.servlet.http.HttpServletRequest req, java.io.ObjectInputStream in, java.io.ObjectOutputStream out)
          Loads a letters component of the current company, corresponding to a code.
private  void loadComponentCode(java.io.ObjectInputStream in, java.io.ObjectOutputStream out)
          Loads the < code,stamp> of a component from the database.
private  void loadComponentsDescription(java.io.ObjectInputStream in, java.io.ObjectOutputStream out)
          Asks for code and description of the components, for a given component type and print type.
private  void loadImageRepository(java.io.ObjectInputStream in, java.io.ObjectOutputStream out)
          Asks the service of loading an image --of the current company-- after its name.
private  void loadImagesNamesRepository(java.lang.String companyId, java.io.ObjectInputStream in, java.io.ObjectOutputStream out)
          Loads the names of the images from the web context or from the data base.
private  void loadTemplate(javax.servlet.http.HttpServletRequest req, java.io.ObjectInputStream in, java.io.ObjectOutputStream out)
          Loads a letters template of the current company, corresponding to a code.
private  void loadTemplateCodes(java.io.ObjectInputStream in, java.io.ObjectOutputStream out)
          Asks for the service of loading < code, stamp> for a template and its components, after its code.
private  void loadTemplatesDescription(java.io.ObjectInputStream in, java.io.ObjectOutputStream out)
          Asks for code and description of the templates, for a given category and print type.
private  void loadVariableFormats(java.io.ObjectOutputStream out)
          Asks to the LetterTemplate ejb for the service of loading variable formats.
private  void loadVariables(java.io.ObjectOutputStream out)
          Asks to the LetterTemplate ejb for the service of loading loan variables.
private  void storeComponent(java.lang.String companyId, java.io.ObjectInputStream in, java.io.ObjectOutputStream out)
          Asks for the service of storing a letter component without changing its links with any template.
private  void storeComponentAs(java.lang.String companyId, java.io.ObjectInputStream in, java.io.ObjectOutputStream out)
          Asks for the service of storing a letter component bound to a template.
private  void storeTemplate(java.lang.String companyId, java.io.ObjectInputStream in, java.io.ObjectOutputStream out)
          Asks for the service of storing a template.
 
Methods inherited from class javax.servlet.http.HttpServlet
, doDelete, doGet, doHead, doOptions, doPut, doTrace, getAllDeclaredMethods, getLastModified, maybeSetLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

lethome

private LetterTemplateHome lethome
The home for the ejb that provides the services requested by this servlet.

letejb

private LetterTemplate letejb
The ejb that provides the services for this servlet.

hashFields

private java.util.Hashtable hashFields
A hash table with company fields information

debug

private Debug debug
The ubiquitous debug object.
Constructor Detail

TemplateEditorServlet

public TemplateEditorServlet()
Method Detail

init

public void init()
          throws javax.servlet.ServletException
Description of the Method
Overrides:
init in class javax.servlet.GenericServlet
Throws:
javax.servlet.ServletException -  

doPost

public void doPost(javax.servlet.http.HttpServletRequest req,
                   javax.servlet.http.HttpServletResponse resp)
            throws javax.servlet.ServletException,
                   java.io.IOException
Acts as a dispatcher for the services encoded as LetterOp constants.
Overrides:
doPost in class javax.servlet.http.HttpServlet
Parameters:
req -  
resp -  
Throws:
javax.servlet.ServletException -  
java.io.IOException -  

loadCategories

private void loadCategories(java.lang.String companyId,
                            java.io.ObjectOutputStream out)
                     throws javax.servlet.ServletException,
                            java.io.IOException
Loads all [code, description] of the categories in the current company, from the web context or from the database.
Parameters:
companyId -  
out -  
Throws:
javax.servlet.ServletException -  
java.io.IOException -  

loadCodesStamps

private void loadCodesStamps(java.io.ObjectInputStream in,
                             java.io.ObjectOutputStream out)
                      throws javax.servlet.ServletException,
                             java.io.IOException
Loads code and stamp of template and components. It sends back --to the proxy-- a CodeDescription array where:

loadTemplate

private void loadTemplate(javax.servlet.http.HttpServletRequest req,
                          java.io.ObjectInputStream in,
                          java.io.ObjectOutputStream out)
                   throws javax.servlet.ServletException,
                          java.io.IOException
Loads a letters template of the current company, corresponding to a code. The object send back to the proxy is a pair containing the full template structure extracted from the data base and a message containing the names of the variables with inconsistent date offsets. Those offsets are forced to zero.
Parameters:
req - The standard request object
in - Communication channel from the servlet proxy
out - Communication channel to the servlet proxy
Throws:
javax.servlet.ServletException -  
java.io.IOException -  

loadTemplatesDescription

private void loadTemplatesDescription(java.io.ObjectInputStream in,
                                      java.io.ObjectOutputStream out)
                               throws javax.servlet.ServletException,
                                      java.io.IOException
Asks for code and description of the templates, for a given category and print type. Sends back --to the proxy-- an array of < code,name> pairs of templates sorted by name.
Parameters:
in -  
out -  
Throws:
javax.servlet.ServletException -  
java.io.IOException -  

loadTemplateCodes

private void loadTemplateCodes(java.io.ObjectInputStream in,
                               java.io.ObjectOutputStream out)
                        throws javax.servlet.ServletException,
                               java.io.IOException
Asks for the service of loading < code, stamp> for a template and its components, after its code. Sends back --to the proxy-- a < code, stamp> array of the template in the THBC order.
Parameters:
in -  
out -  
Throws:
javax.servlet.ServletException -  
java.io.IOException -  

storeTemplate

private void storeTemplate(java.lang.String companyId,
                           java.io.ObjectInputStream in,
                           java.io.ObjectOutputStream out)
                    throws javax.servlet.ServletException,
                           java.io.IOException
Asks for the service of storing a template. Sends back --to the proxy-- an array of < code, stamp> of the stored elements in the THBC order.
Parameters:
companyId -  
in -  
out -  
Throws:
javax.servlet.ServletException -  
java.io.IOException -  

loadComponent

private void loadComponent(javax.servlet.http.HttpServletRequest req,
                           java.io.ObjectInputStream in,
                           java.io.ObjectOutputStream out)
                    throws javax.servlet.ServletException,
                           java.io.IOException
Loads a letters component of the current company, corresponding to a code. The object send back to the proxy is a pair containing the full component structure extracted from the data base and a message containing the names of the variables with inconsistent date offsets. Those offsets are forced to zero.
Parameters:
req - The standard request object
in - Communication channel from the servlet proxy.
out - Communication channel to the servlet proxy.
Throws:
javax.servlet.ServletException -  
java.io.IOException -  

loadComponentsDescription

private void loadComponentsDescription(java.io.ObjectInputStream in,
                                       java.io.ObjectOutputStream out)
                                throws javax.servlet.ServletException,
                                       java.io.IOException
Asks for code and description of the components, for a given component type and print type. Sens back --to the proxy-- An array of < code,name> pairs of components, sorted by name. If there are no components, "null" is sent back.
Parameters:
in -  
out -  
Throws:
javax.servlet.ServletException -  
java.io.IOException -  

loadComponentCode

private void loadComponentCode(java.io.ObjectInputStream in,
                               java.io.ObjectOutputStream out)
                        throws javax.servlet.ServletException,
                               java.io.IOException
Loads the < code,stamp> of a component from the database. Sends back --to the proxy-- The < code, stamp> of the component. If the component doesn't exists the returned value is < LetterTemplateGlobals.UNDEF, LetterTemplateGlobals.STR_UNDEF> .
Parameters:
in -  
out -  
Throws:
javax.servlet.ServletException -  
java.io.IOException -  

storeComponent

private void storeComponent(java.lang.String companyId,
                            java.io.ObjectInputStream in,
                            java.io.ObjectOutputStream out)
                     throws javax.servlet.ServletException,
                            java.io.IOException
Asks for the service of storing a letter component without changing its links with any template. An old version of the component must exist before asking the service. Sends back --to the proxy-- the < code, stamp> of the saved component.
Parameters:
companyId -  
in -  
out -  
Throws:
javax.servlet.ServletException -  
java.io.IOException -  

storeComponentAs

private void storeComponentAs(java.lang.String companyId,
                              java.io.ObjectInputStream in,
                              java.io.ObjectOutputStream out)
                       throws javax.servlet.ServletException,
                              java.io.IOException
Asks for the service of storing a letter component bound to a template. Following its type (header, body, closing) it also replaces the corresponding component of the template. Sends back --to the sender-- the < code,stamp> of the saved component.
Parameters:
companyId -  
in -  
out -  
Throws:
javax.servlet.ServletException -  
java.io.IOException -  

loadImageRepository

private void loadImageRepository(java.io.ObjectInputStream in,
                                 java.io.ObjectOutputStream out)
                          throws javax.servlet.ServletException,
                                 java.io.IOException
Asks the service of loading an image --of the current company-- after its name. Sends back --to the proxy-- an array containing the raw bytes of the image. See LetterTemplate.loadImageRepository(String)
Parameters:
in -  
out -  
Throws:
javax.servlet.ServletException -  
java.io.IOException -  

loadImagesNamesRepository

private void loadImagesNamesRepository(java.lang.String companyId,
                                       java.io.ObjectInputStream in,
                                       java.io.ObjectOutputStream out)
                                throws javax.servlet.ServletException,
                                       java.io.IOException
Loads the names of the images from the web context or from the data base. Sends back --to the proxy-- an array of images names. If there are no images, "null" is sent back.
Parameters:
companyId -  
in -  
out -  
Throws:
javax.servlet.ServletException -  
java.io.IOException -  

loadVariables

private void loadVariables(java.io.ObjectOutputStream out)
                    throws javax.servlet.ServletException,
                           java.io.IOException
Asks to the LetterTemplate ejb for the service of loading loan variables. It sends --to the proxy-- an ArrayList of ArrayLists containing the information about all loan variables. If there is no variables, null is sent back to the proxy. The internal ArrayList contains [code, name, type] of a variable.
Parameters:
out -  
Throws:
javax.servlet.ServletException -  
java.io.IOException -  

loadVariableFormats

private void loadVariableFormats(java.io.ObjectOutputStream out)
                          throws javax.servlet.ServletException,
                                 java.io.IOException
Asks to the LetterTemplate ejb for the service of loading variable formats. It sends --to the proxy-- an array of [code,description] containing the information of all variable formats. If there is no variable formats, null is sent back to the proxy.
Parameters:
out -  
Throws:
javax.servlet.ServletException -  
java.io.IOException -  

exit

private void exit(javax.servlet.http.HttpServletRequest req,
                  javax.servlet.http.HttpServletResponse resp,
                  java.lang.String url)
           throws javax.servlet.ServletException,
                  java.io.IOException
Exit from editor usecase for 2 possible reasons: user request or timeout
Parameters:
req - The standard request parameter
resp - The standard response parameter
url - Exit target
Throws:
javax.servlet.ServletException -  
java.io.IOException -  

fixDateOffset

private java.util.Set fixDateOffset(javax.servlet.http.HttpServletRequest req,
                                    LetterComponent comp)
                             throws java.lang.Exception
Brings to zero the inconsistent date offsets in a letter component.
Parameters:
comp - The component to be fixed.
req - Description of the Parameter
Returns:
A set containing the codes of the fixed variables.
Side effects:
Sets the hashFields attribute.
Throws:
java.lang.Exception - Description of the Exception

fixDateOffset

private java.util.Set fixDateOffset(javax.servlet.http.HttpServletRequest req,
                                    Template template)
                             throws java.lang.Exception
Brings to zero the inconsistent date offsets in a letter Template.
Parameters:
template - The template to be fixed.
req - Description of the Parameter
Returns:
A set containing the codes of the fixed variables.
Side effects:
based on fixDateOffset(HttpServletRequest,LetterComponent).
Throws:
java.lang.Exception - Description of the Exception

brokenVarNames

private java.lang.String brokenVarNames(java.util.Set brokenVars)
Calculates a text containing a comma separated list of the names of variables in a Set.
Parameters:
brokenVars - a Set of var codes.
Returns:
The specified String, or null if the set is void.

controlTimeout

private void controlTimeout(java.io.ObjectOutputStream out,
                            javax.servlet.http.HttpServletRequest request,
                            javax.servlet.http.HttpServletResponse response)
                     throws java.io.IOException,
                            javax.servlet.ServletException
Control time out in editor usecase: if timeout, inactivates the session and returns true if not timeout, reset timeout counter in lettertemplate and in Instantbank ear's and returns false. editor applet should invoke this method always before any other TemplateEditorServlet invokation and also in reaction to any user event. Example of invokation in editor applet: ----------------------------------------------------------------------- Integer opCode = new Integer(LetterOp.CONTROLTIMEOUT); Serializable objs[] = {opCode}; in = TemplateEditorSender.postObjects(servlet, objs); boolean existsTimeout = ((Boolean)in.readObject()).booleanValue(); in.close(); if (existsTimeout){ String homeurl = shortenUrl(getCodeBase().toExternalForm(),2); homeurl += "lettertemplate/control_web/TimeOutPage.jsp"; getAppletContext().showDocument (new URL(homeurl)); } ------------------------------------------------------------------------
Parameters:
out - answer stream to editor applet
request - of web session
response -  
Throws:
java.io.IOException -  
javax.servlet.ServletException -