- Timestamp:
- Jun 18, 2012, 8:44:29 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Network/CoolWeb/WebServer/UWebApp.pas
r357 r375 7 7 uses 8 8 Classes, SysUtils, CustApp, SpecializedList, UWebPage, UHTTPSessionFile, 9 UHTTPServer, Forms ;9 UHTTPServer, Forms, FileUtil; 10 10 11 11 type … … 17 17 end; 18 18 19 { T RegistredPageList }19 { TPageList } 20 20 21 TRegistredPageList = class(TListObject) 21 TPageList = class(TListObject) 22 RootDir: string; 22 23 function FindByName(Name: string): TRegistredPage; 24 procedure RegisterPage(PageClass: TWebPageClass; out Reference; Path: string); 25 function ProducePage(HandlerData: THTTPHandlerData): Boolean; 23 26 end; 24 27 … … 27 30 TWebApp = class(TComponent) 28 31 private 29 FOn BeforePageProduce: TOnProduceEvent;32 FOnPageProduce: TOnProduceEvent; 30 33 FOnInitialize: TNotifyEvent; 31 34 FServerType: THTTPServerType; … … 34 37 procedure SetServerType(AValue: THTTPServerType); 35 38 public 36 Pages: TRegistredPageList;37 39 HTTPServer: THTTPServer; 38 40 HTTPSessionStorageFile: THTTPSessionStorageFile; 39 41 LogException: Boolean; 40 42 procedure ShowException(E: Exception); 41 procedure RegisterPage(PageClass: TWebPageClass; out Reference; Path: string);42 43 constructor Create(AOwner: TComponent); override; 43 44 destructor Destroy; override; 44 45 procedure Run; 45 46 published 46 property On BeforePageProduce: TOnProduceEvent read FOnBeforePageProduce write FOnBeforePageProduce;47 property OnPageProduce: TOnProduceEvent read FOnPageProduce write FOnPageProduce; 47 48 property OnInitialize: TNotifyEvent read FOnInitialize write FOnInitialize; 48 49 property ServerType: THTTPServerType read FServerType write SetServerType; … … 57 58 UHTTPServerCGI, UHTTPServerTCP, UHTTPServerTurboPower; 58 59 59 resourcestring60 SPageNotFound = 'Page not found';61 62 60 63 61 procedure Register; … … 67 65 68 66 69 { T RegistredPageList }67 { TPageList } 70 68 71 function T RegistredPageList.FindByName(Name: string): TRegistredPage;69 function TPageList.FindByName(Name: string): TRegistredPage; 72 70 var 73 71 I: Integer; … … 108 106 end; 109 107 110 procedure T WebApp.RegisterPage(PageClass: TWebPageClass; out Reference;108 procedure TPageList.RegisterPage(PageClass: TWebPageClass; out Reference; 111 109 Path: string); 112 110 var … … 114 112 Instance: TWebPage; 115 113 begin 116 NewPage := TRegistredPage( Pages.AddNew(TRegistredPage.Create));114 NewPage := TRegistredPage(AddNew(TRegistredPage.Create)); 117 115 // NewPage.Page := PageClass.Create(Self); 118 116 NewPage.Page := PageClass.Create(nil); … … 121 119 end; 122 120 123 procedure TWebApp.HTTPServerRequest(HandlerData: THTTPHandlerData);121 function TPageList.ProducePage(HandlerData: THTTPHandlerData): Boolean; 124 122 var 125 123 Page: TRegistredPage; … … 127 125 begin 128 126 with HandlerData do begin 129 //Request.QueryParts.Count := 2;130 //Request.QueryParts[0] := 'uzivatel';131 //Request.QueryParts[1] := 'prihlaseni';132 if Assigned(FOnBeforePageProduce) then133 FOnBeforePageProduce(HandlerData);134 135 127 if Request.QueryParts.Count > 0 then PageName := Request.QueryParts[0] 136 128 else PageName := ''; 137 Page := Pages.FindByName(PageName);129 Page := FindByName(PageName); 138 130 if Assigned(Page) then begin 139 131 Page.Page.OnProduce(HandlerData); 140 end else Response.Content.WriteString(SPageNotFound); 132 Result := True; 133 end else Result := False; 141 134 end; 135 end; 136 137 procedure TWebApp.HTTPServerRequest(HandlerData: THTTPHandlerData); 138 begin 139 if Assigned(FOnPageProduce) then 140 FOnPageProduce(HandlerData); 142 141 end; 143 142 … … 179 178 begin 180 179 inherited Create(AOwner); 181 Pages := TRegistredPageList.Create;182 180 HTTPServer := THTTPServerCGI.Create(nil); 183 181 HTTPServer.OnRequest := HTTPServerRequest; … … 186 184 destructor TWebApp.Destroy; 187 185 begin 188 Pages.Free;189 186 HTTPServer.Free; 190 187 inherited Destroy;
Note:
See TracChangeset
for help on using the changeset viewer.