pandora
Class CommandCtrl

java.lang.Object
  |
  +--javax.servlet.GenericServlet
        |
        +--javax.servlet.http.HttpServlet
              |
              +--pandora.CommandCtrl
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class CommandCtrl
extends javax.servlet.http.HttpServlet

Controller servlet used in combination with CommandBean (model) and command.jsp (view).

Copyright (c) 2002-2003 Alexis Grandemange

This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public License
 as published by the Free Software Foundation; version 2.1 of the
 License.
 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU Lesser General Public License for more details.
 A copy of the GNU Lesser General Public License lesser.txt should be
 included in the distribution.

Version:
0, 0, 2
Author:
Alexis Grandemange
See Also:
Serialized Form

Field Summary
(package private)  java.lang.String addr
          Delivery information (office #, mail address, phone#...)
(package private)  javax.servlet.RequestDispatcher authDispatcher
          Dispatcher to authError.html
(package private)  CommandBean cb
          Model object
(package private)  CheckSandbox cs
          To exercise the sandbox
(package private)  javax.servlet.ServletContext ctx
          Unique to the Web application
(package private)  java.lang.String delivery
          URL of the delivery Web service
(package private)  javax.servlet.RequestDispatcher dispatcher
          Dispatcher to command.jsp
(package private)  PageBoxAPI inst
          PageBox API instance
(package private)  PageBoxLib.LogIF log
          Logging object
(package private)  java.lang.String payment
          URL of the payment Web service
private  long period
          Time between two publications
static Publish publish
          Thread that publishes updates on the central server
(package private)  java.lang.String user
          User information (ID, name, billable account...)
(package private)  java.lang.String workDir
          Directory where API.txt is defined
 
Fields inherited from class javax.servlet.http.HttpServlet
 
Fields inherited from class javax.servlet.GenericServlet
 
Constructor Summary
CommandCtrl()
           
 
Method Summary
private  java.lang.String add(java.lang.Integer id, int qty)
          Add a new row to a command.
private  boolean checkReferrer(javax.servlet.http.HttpServletRequest request)
          Checks that the user and addr are stored in the session or were in request.
private  java.lang.String commit()
          Write a command on the database.
private  CommandBean createCb()
          Retrieves the article list from the article table and creates a CommandBean instance.
private  java.lang.String delete(java.lang.Integer id)
          Delete a row from a command.
 void destroy()
          Called by the servlet container to indicate to a servlet that the servlet is being taken out of service.
 void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          GET request handling.
 void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          POST request handling.
 void init(javax.servlet.ServletConfig config)
          Invoked by Servlet container.
private  java.lang.String update(java.lang.Integer id, int qty)
          Change the number of items of a given article in a command.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dispatcher

javax.servlet.RequestDispatcher dispatcher
Dispatcher to command.jsp


authDispatcher

javax.servlet.RequestDispatcher authDispatcher
Dispatcher to authError.html


inst

PageBoxAPI inst
PageBox API instance


log

PageBoxLib.LogIF log
Logging object


cb

CommandBean cb
Model object


user

java.lang.String user
User information (ID, name, billable account...)


addr

java.lang.String addr
Delivery information (office #, mail address, phone#...)


payment

java.lang.String payment
URL of the payment Web service


delivery

java.lang.String delivery
URL of the delivery Web service


publish

public static Publish publish
Thread that publishes updates on the central server


workDir

java.lang.String workDir
Directory where API.txt is defined


ctx

javax.servlet.ServletContext ctx
Unique to the Web application


cs

CheckSandbox cs
To exercise the sandbox


period

private long period
Time between two publications

Constructor Detail

CommandCtrl

public CommandCtrl()
Method Detail

init

public void init(javax.servlet.ServletConfig config)
          throws javax.servlet.ServletException
Invoked by Servlet container.

Specified by:
init in interface javax.servlet.Servlet
Overrides:
init in class javax.servlet.GenericServlet
Parameters:
config - servlet configuration
javax.servlet.ServletException

destroy

public void destroy()
Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. Ends the publish thread and closes the connections.

Specified by:
destroy in interface javax.servlet.Servlet
Overrides:
destroy in class javax.servlet.GenericServlet

createCb

private CommandBean createCb()
Retrieves the article list from the article table and creates a CommandBean instance.

Returns:
created CommandBean

doGet

public void doGet(javax.servlet.http.HttpServletRequest request,
                  javax.servlet.http.HttpServletResponse response)
           throws javax.servlet.ServletException,
                  java.io.IOException
GET request handling.

Overrides:
doGet in class javax.servlet.http.HttpServlet
Parameters:
request - HttpServletRequest
response - HttpServletResponse
javax.servlet.ServletException
java.io.IOException

doPost

public void doPost(javax.servlet.http.HttpServletRequest request,
                   javax.servlet.http.HttpServletResponse response)
            throws javax.servlet.ServletException,
                   java.io.IOException
POST request handling.

Overrides:
doPost in class javax.servlet.http.HttpServlet
Parameters:
request - HttpServletRequest
response - HttpServletResponse
javax.servlet.ServletException
java.io.IOException

update

private java.lang.String update(java.lang.Integer id,
                                int qty)
Change the number of items of a given article in a command.

Parameters:
id - article ID
qty - number of items
Returns:
message

add

private java.lang.String add(java.lang.Integer id,
                             int qty)
Add a new row to a command.

Parameters:
id - article ID
qty - number of items
Returns:
message

commit

private java.lang.String commit()
Write a command on the database. Setup when the user comes from another application.

Returns:
message

delete

private java.lang.String delete(java.lang.Integer id)
Delete a row from a command.

Parameters:
id - article ID
Returns:
message

checkReferrer

private boolean checkReferrer(javax.servlet.http.HttpServletRequest request)
Checks that the user and addr are stored in the session or were in request.

Parameters:
request - HttpServletRequest true if the user is authenticated