Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

abstract_application.hh

00001 /*
00002 *  Name:      abstract_application.hh
00003 *  Author:    Angel Jimenez Jimenez
00004 *             Rafael Jesus Alcantara Perez
00005 *  Summary:   CGI base application
00006 *  Date:      $Date: 2003/10/06 12:45:11 $
00007 *  Revision:  $Revision: 1.1 $
00008 *
00009 *  Copyright (C) 1994-2003  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00010 *
00011 *  This program is free software; you can redistribute it and/or modify
00012 *  it under the terms of the GNU General Public License as published by
00013 *  the Free Software Foundation; either version 2 of the License, or
00014 *  (at your option) any later version.
00015 *
00016 *  This program is distributed in the hope that it will be useful,
00017 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 *  GNU General Public License for more details.
00020 *
00021 *  You should have received a copy of the GNU General Public License
00022 *  along with this program; if not, write to the Free Software
00023 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00024 *  MA 02111-1307, USA.
00025 */
00026 
00027 #ifndef _MPCL_NET_CGI_ABSTRACT_APPLICATION__
00028 #define _MPCL_NET_CGI_ABSTRACT_APPLICATION__
00029 
00030 #include <iostream>
00031 #include "../../abstract_application.hh"
00032 #include "../../memory/smart_pointer.hh"
00033 #include "../../text/html/base_page.hh"
00034 #include "../../text/html/form.hh"
00035 #include "../../text/string.hh"
00036 #include "../../util/collection/map.hh"
00037 #include "config_processor.hh"
00038 #include "cookie.hh"
00039 #include "session.hh"
00040 
00041 
00043 namespace mpcl
00044 {
00045 
00047   namespace net
00048   {
00049 
00051     namespace cgi
00052     {
00053 
00054       using text::html::QKTBasePage;
00055       using text::html::QTBasePage;
00056       using text::html::TForm;
00057 
00079       class TAbstractApplication : public mpcl::TAbstractApplication
00080       {
00081 
00082         private:
00083 
00085           bool gIsRedirected;
00086 
00088           TForm*   ptSourceForm;
00089 
00091           QTBasePage   qtSourcePage;
00092 
00094           QTBasePage   qtTargetPage;
00095 
00097           TString   yTargetUrl;
00098 
00099 
00100         protected:
00101 
00103           std::basic_ostream<char>*   ptTargetOstream;
00104 
00106           TConfigProcessor   tConfigProcessor;
00107 
00109           TSession<TCookie>   tSession;
00110 
00111 
00112         private:
00113 
00114           //
00115           //  C O N S T R U C T O R S
00116           //
00117 
00119           void buildSourcePage (void);
00120 
00121 
00122         public:
00123 
00124           //
00125           //  C O N S T R U C T O R S
00126           //
00127 
00135           TAbstractApplication ( const char*  pkcNAME          ,
00136                                  const char*  pkcRELEASE       ,
00137                                  int          iPARAMETER_COUNT ,
00138                                  const char** ppkcPARAMETERS   )  :
00139             mpcl::TAbstractApplication (pkcNAME, pkcRELEASE)      ,
00140             gIsRedirected      (false)                            ,
00141             ptSourceForm       (NULL)                             ,
00142             qtSourcePage       ()                                 ,
00143             qtTargetPage       ()                                 ,
00144             yTargetUrl         ()                                 ,
00145             ptTargetOstream    (&std::cout)                       ,
00146             tConfigProcessor   (iPARAMETER_COUNT, ppkcPARAMETERS) ,
00147             tSession           ()
00148           {
00149             TString                           yHttpCookieValue;
00150             std::basic_istringstream<char>*   ptIstrstream;
00151 
00152             //
00153             //  Loads cookies from HTTP environment variable.
00154             //
00155             yHttpCookieValue = tConfigProcessor.environmentValue ("HTTP_COOKIE");
00156             ptIstrstream     = new std::basic_istringstream<char> (yHttpCookieValue.c_str());
00157             *ptIstrstream >> tSession;
00158             delete ptIstrstream;
00159           }
00160 
00168           virtual QTBasePage buildPage (const TString& rkyPAGE_IDENTIFIER) = 0;
00169 
00177           void initialize (void) = 0;
00178 
00184           virtual void processRequest (void) = 0;
00185 
00190           void redirect (const TString& rkyTARGET_URL)
00191           {
00192             gIsRedirected = true;
00193             yTargetUrl    = rkyTARGET_URL;
00194           }
00195 
00200           void setOutput (std::basic_ostream<char>& rtTARGET_OSTREAM)
00201           {
00202             ptTargetOstream = &rtTARGET_OSTREAM;
00203           }
00204 
00209           void setResponse (const QTBasePage& rkqtTARGET_PAGE)
00210           {
00211             gIsRedirected = false;
00212             qtTargetPage  = rkqtTARGET_PAGE;
00213           }
00214 
00221           int start (void)
00222           {
00223             buildSourcePage();
00224             processRequest();
00225             writeResponse();
00226             return 0;
00227           }
00228 
00229 
00230         private:
00231 
00232           //
00233           //  S E L E C T O R S
00234           //
00235 
00241           void writeResponse (void) const;
00242 
00243 
00244         protected:
00245 
00250           bool hasSourcePage (void) const
00251           {
00252             return !qtSourcePage.isNull();
00253           }
00254 
00255 
00256         public:
00257 
00258           //
00259           //  S E L E C T O R S
00260           //
00261 
00267           QKTBasePage getSourcePage (void) const
00268           {
00269             return QKTBasePage (qtSourcePage);
00270           }
00271 
00277           const TForm& getSourceForm (void) const
00278           {
00279             if ( !ptSourceForm )
00280             {
00281               throw TConstraintException ("form is null", __FILE__, __LINE__);
00282             }
00283             return *ptSourceForm;
00284           }
00285 
00292           QTBasePage getResponsePage (void) const
00293           {
00294             return qtTargetPage;
00295           }
00296 
00302           TString fullName (void) const
00303           {
00304             return tConfigProcessor.environmentValue ("SCRIPT_NAME");
00305           }
00306 
00307           TString programFileName (void) const
00308           {
00309             return tConfigProcessor.programFileName();
00310           }
00311 
00312       };  // class TAbstractApplication
00313 
00314     }  // namespace cgi
00315 
00316   }  // namespace net
00317 
00318 }  // namespace mpcl
00319 
00320 
00321 #endif  // not _MPCL_NET_CGI_ABSTRACT_APPLICATION__

Generated on Mon Oct 13 02:35:22 2003 for MPCL by doxygen1.2.18