Changeset 375


Ignore:
Timestamp:
Jun 18, 2012, 8:44:29 PM (12 years ago)
Author:
chronos
Message:
  • Modified: TWebApp will not maintaing page list and produce response by itself. OnPageProduce handler have to be used.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Network/CoolWeb/WebServer/UWebApp.pas

    r357 r375  
    77uses
    88  Classes, SysUtils, CustApp, SpecializedList, UWebPage, UHTTPSessionFile,
    9   UHTTPServer, Forms;
     9  UHTTPServer, Forms, FileUtil;
    1010
    1111type
     
    1717  end;
    1818
    19   { TRegistredPageList }
     19  { TPageList }
    2020
    21   TRegistredPageList = class(TListObject)
     21  TPageList = class(TListObject)
     22    RootDir: string;
    2223    function FindByName(Name: string): TRegistredPage;
     24    procedure RegisterPage(PageClass: TWebPageClass; out Reference; Path: string);
     25    function ProducePage(HandlerData: THTTPHandlerData): Boolean;
    2326  end;
    2427
     
    2730  TWebApp = class(TComponent)
    2831  private
    29     FOnBeforePageProduce: TOnProduceEvent;
     32    FOnPageProduce: TOnProduceEvent;
    3033    FOnInitialize: TNotifyEvent;
    3134    FServerType: THTTPServerType;
     
    3437    procedure SetServerType(AValue: THTTPServerType);
    3538  public
    36     Pages: TRegistredPageList;
    3739    HTTPServer: THTTPServer;
    3840    HTTPSessionStorageFile: THTTPSessionStorageFile;
    3941    LogException: Boolean;
    4042    procedure ShowException(E: Exception);
    41     procedure RegisterPage(PageClass: TWebPageClass; out Reference; Path: string);
    4243    constructor Create(AOwner: TComponent); override;
    4344    destructor Destroy; override;
    4445    procedure Run;
    4546  published
    46     property OnBeforePageProduce: TOnProduceEvent read FOnBeforePageProduce write FOnBeforePageProduce;
     47    property OnPageProduce: TOnProduceEvent read FOnPageProduce write FOnPageProduce;
    4748    property OnInitialize: TNotifyEvent read FOnInitialize write FOnInitialize;
    4849    property ServerType: THTTPServerType read FServerType write SetServerType;
     
    5758  UHTTPServerCGI, UHTTPServerTCP, UHTTPServerTurboPower;
    5859
    59 resourcestring
    60   SPageNotFound = 'Page not found';
    61 
    6260
    6361procedure Register;
     
    6765
    6866
    69 { TRegistredPageList }
     67{ TPageList }
    7068
    71 function TRegistredPageList.FindByName(Name: string): TRegistredPage;
     69function TPageList.FindByName(Name: string): TRegistredPage;
    7270var
    7371  I: Integer;
     
    108106end;
    109107
    110 procedure TWebApp.RegisterPage(PageClass: TWebPageClass; out Reference;
     108procedure TPageList.RegisterPage(PageClass: TWebPageClass; out Reference;
    111109  Path: string);
    112110var
     
    114112  Instance: TWebPage;
    115113begin
    116   NewPage := TRegistredPage(Pages.AddNew(TRegistredPage.Create));
     114  NewPage := TRegistredPage(AddNew(TRegistredPage.Create));
    117115//  NewPage.Page := PageClass.Create(Self);
    118116  NewPage.Page := PageClass.Create(nil);
     
    121119end;
    122120
    123 procedure TWebApp.HTTPServerRequest(HandlerData: THTTPHandlerData);
     121function TPageList.ProducePage(HandlerData: THTTPHandlerData): Boolean;
    124122var
    125123  Page: TRegistredPage;
     
    127125begin
    128126  with HandlerData do begin
    129     //Request.QueryParts.Count := 2;
    130     //Request.QueryParts[0] := 'uzivatel';
    131     //Request.QueryParts[1] := 'prihlaseni';
    132     if Assigned(FOnBeforePageProduce) then
    133       FOnBeforePageProduce(HandlerData);
    134 
    135127    if Request.QueryParts.Count > 0 then PageName := Request.QueryParts[0]
    136128      else PageName := '';
    137     Page := Pages.FindByName(PageName);
     129    Page := FindByName(PageName);
    138130    if Assigned(Page) then begin
    139131      Page.Page.OnProduce(HandlerData);
    140     end else Response.Content.WriteString(SPageNotFound);
     132      Result := True;
     133    end else Result := False;
    141134  end;
     135end;
     136
     137procedure TWebApp.HTTPServerRequest(HandlerData: THTTPHandlerData);
     138begin
     139  if Assigned(FOnPageProduce) then
     140    FOnPageProduce(HandlerData);
    142141end;
    143142
     
    179178begin
    180179  inherited Create(AOwner);
    181   Pages := TRegistredPageList.Create;
    182180  HTTPServer := THTTPServerCGI.Create(nil);
    183181  HTTPServer.OnRequest := HTTPServerRequest;
     
    186184destructor TWebApp.Destroy;
    187185begin
    188   Pages.Free;
    189186  HTTPServer.Free;
    190187  inherited Destroy;
Note: See TracChangeset for help on using the changeset viewer.