started cgilaz package

git-svn-id: trunk@4706 -
This commit is contained in:
mattias 2003-10-09 11:31:48 +00:00
parent eb04d73610
commit 48f29ad4c9
4 changed files with 203 additions and 0 deletions

2
.gitattributes vendored
View File

@ -1,5 +1,7 @@
* text=auto !eol
/COPYING.modifiedLGPL -text svneol=unset#application/octet-stream
components/cgi/cgilaz.lpk svneol=native#text/pascal
components/cgi/cgimodules.pas svneol=native#text/pascal
components/codetools/allcodetoolunits.pp svneol=native#text/pascal
components/codetools/avl_tree.pas svneol=native#text/pascal
components/codetools/basiccodetools.pas svneol=native#text/pascal

6
components/cgi/README Normal file
View File

@ -0,0 +1,6 @@
cgi
With the cgimodules.pas unit you can easily create cgi applications with
datamodules and edit them in the IDE.

37
components/cgi/cgilaz.lpk Normal file
View File

@ -0,0 +1,37 @@
<?xml version="1.0"?>
<CONFIG>
<Package Version="2">
<Name Value="cgiLaz"/>
<Author Value="Mattias Gaertner"/>
<CompilerOptions>
<SearchPaths>
<UnitOutputDirectory Value="lib/"/>
</SearchPaths>
<Other>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
<Description Value="cgi applications with data modules"/>
<License Value="LGPL"/>
<Version Minor="1" Release="1"/>
<Files Count="1">
<Item1>
<Filename Value="cgimodules.pas"/>
<UnitName Value="cgiModules"/>
</Item1>
</Files>
<Type Value="RunAndDesignTime"/>
<RequiredPkgs Count="1">
<Item1>
<PackageName Value="LCL"/>
</Item1>
</RequiredPkgs>
<UsageOptions>
<UnitPath Value="$(PkgOutDir)/"/>
</UsageOptions>
<PublishOptions>
<Version Value="2"/>
<IgnoreBinaries Value="False"/>
</PublishOptions>
</Package>
</CONFIG>

View File

@ -0,0 +1,158 @@
{ Copyright (C) 2003 Michael Van Canneyt
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program 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 Library General Public License
for more details.
You should have received a copy of the GNU Library General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
}
unit cgiModules;
{$mode objfpc}
{$H+}
interface
uses
Classes, SysUtils, cgiApp, LResources;
Type
TCGIDatamodule = Class(TDataModule)
private
FOnCGIRequest: TNotifyEvent;
function GetContentType: String;
procedure SetContentType(const AValue: String);
Protected
function GetResponse: TStream;
Public
procedure HandleRequest; virtual;
procedure EmitContentType; virtual;
procedure AddResponse(const Msg : String); virtual;
procedure AddResponseLn(const Msg : String); virtual;
procedure AddResponse(const Fmt : String; Args : Array of const); virtual;
procedure AddResponseLn(const Fmt : String; Args : Array of const); virtual;
Published
property OnCGIRequest : TNotifyEvent Read FOnCGIRequest Write FOnCGIRequest;
property Response : TStream Read GetResponse;
property ContentType : String Read GetContentType Write SetContentType;
end;
TCGIDataModuleClass = Class of TCGIDatamodule;
TModuledCGIApplication = Class(TCGIApplication)
FMainModule : TCGIDatamodule;
public
Procedure CreateForm(Var AForm : TCGIDatamodule; AClass : TCGIDataModuleClass);
Procedure DoRun; Override;
Property MainModule : TCGIDatamodule Read FMainModule;
end;
ECGIAppException = Class(Exception);
Var
Application : TModuledCGIApplication;
function InitResourceComponent(Instance: TComponent;
RootAncestor: TClass):Boolean;
implementation
ResourceString
SErrNoMainModule = 'No CGI datamodule to handle CGI request.';
SErrNoRequestHandler = '%s: No CGI request handler set.';
function InitResourceComponent(Instance: TComponent;
RootAncestor: TClass): Boolean;
begin
Result:=InitLazResourceComponent(Instance,RootAncestor);
end;
{ TModuledCGIApplication }
procedure TModuledCGIApplication.CreateForm(Var AForm: TCGIDatamodule;
AClass: TCGIDataModuleClass);
begin
AForm:=AClass.CreateNew(Self,0);
If FMainModule=Nil then
FMainModule:=AForm;
end;
procedure TModuledCGIApplication.DoRun;
begin
if (FMainModule=Nil) then
Raise ECGIAppException.Create(SErrNoMainModule);
Try
FMainModule.HandleRequest;
Finally
Terminate;
end;
end;
{ TCGIDatamodule }
function TCGIDatamodule.GetContentType: String;
begin
Result:=Application.ContentType;
end;
procedure TCGIDatamodule.SetContentType(const AValue: String);
begin
Application.ContentType:=AValue;
end;
function TCGIDatamodule.GetResponse: TStream;
begin
If Assigned(Application) then
Result:=Application.Response;
end;
procedure TCGIDatamodule.HandleRequest;
begin
If Not Assigned(FOnCGIRequest) then
Raise ECGIAppException.CreateFmt(SErrNoRequestHandler,[Name]);
FOnCGIRequest(Self)
end;
procedure TCGIDatamodule.EmitContentType;
begin
Application.EmitContentType;
end;
procedure TCGIDatamodule.AddResponse(const Msg: String);
begin
Application.AddResponse(Msg);
end;
procedure TCGIDatamodule.AddResponseLn(const Msg: String);
begin
Application.AddResponseLn(Msg);
end;
procedure TCGIDatamodule.AddResponse(const Fmt: String;
Args: array of const);
begin
Application.AddResponse(Fmt,Args);
end;
procedure TCGIDatamodule.AddResponseLn(const Fmt: String;
Args: array of const);
begin
Application.AddResponseLn(Fmt,Args);
end;
Initialization
Application:=TModuledCGIApplication.Create(Nil);
RegisterInitComponentHandler(TComponent,@InitResourceComponent);
Finalization
Application.Free;
end.