home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Runimage / Delphi50 / Source / Internet / SCRPTMGR.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-08-11  |  25.6 KB  |  1,021 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Borland Delphi Visual Component Library         }
  5. {                                                       }
  6. {       Copyright (c) 1999 Inprise Corporation          }
  7. {                                                       }
  8. {*******************************************************}
  9.  
  10. unit ScrptMgr;
  11.  
  12. interface
  13.  
  14. uses Classes, Messages, ImgList, HTTPApp, WebComp,
  15.   CompProd, SysUtils, Db, DbClient, PagItems, XMLBrokr, Contnrs;
  16.  
  17. type
  18.  
  19.   TScriptManager = class;
  20.  
  21.   TScriptObject = class(TInterfacedObject)
  22.   private
  23.     FParent: TObject;
  24.   public
  25.     constructor Create(AParent: TObject);
  26.   end;
  27.  
  28.   INameContent = interface
  29.   ['{8AFBBDE8-2A11-11D3-AAAB-00A024C11562}']
  30.     function GetName: string;
  31.     function GetContent: string;
  32.     function MatchName(const Name: string): Boolean;
  33.     property Name: string read GetName;
  34.     property Content: string read GetContent;
  35.   end;
  36.  
  37.   TNameContentScriptObject = class(TScriptObject, INameContent)
  38.   private
  39.     FName: string;
  40.     FContent: string;
  41.   protected
  42.     function GetName: string;
  43.     function GetContent: string;
  44.     function MatchName(const AName: string): Boolean;
  45.   public
  46.     constructor Create(AParent: TObject; const AName, AContent: string);
  47.     property Name: string read GetName;
  48.     property Content: string read GetContent;
  49.   end;
  50.  
  51.   TItemHolder = record
  52.     FIntf: IUnknown;
  53.     FObject: TScriptObject;
  54.   end;
  55.  
  56.   TScriptObjectContainer = class(TScriptObject)
  57.   private
  58.     FItems: array of TItemHolder;
  59.   protected
  60.     function Add(AObject: TScriptObject): Integer;
  61.     function GetCount: Integer;
  62.     function GetAsObject(I: Integer): TScriptObject;
  63.     function GetAsIntf(I: Integer): IUnknown;
  64.   public
  65.     destructor Destroy; override;
  66.     function FindNameObject(const AName: string): TScriptObject;
  67.     property Count: Integer read GetCount;
  68.     property Objects[I: Integer]: TScriptObject read GetAsObject;
  69.   end;
  70.  
  71.   TAddScriptElements = class;
  72.   TXMLDocuments = class;
  73.   TIncludeFiles = class;
  74.   TFunctions = class;
  75.   TScriptBlocks = class;
  76.   THTMLBlocks = class;
  77.   TVars = class;
  78.   TPassList = class;
  79.   TScriptManager = class(TInterfacedObject, IScriptManager)
  80.   private
  81.     FOptions: TWebContentOptions;
  82.     FWarnings: TStrings;
  83.     FXMLDocumentsIntf: IXMLDocuments;
  84.     FXMLDocuments: TXMLDocuments;
  85.     FIncludeFiles: TIncludeFiles;
  86.     FIncludeFilesIntf: IIncludeFiles;
  87.     FFunctions: TFunctions;
  88.     FFunctionsIntf: IFunctions;
  89.     FScriptBlocks: TScriptBlocks;
  90.     FScriptBlocksIntf: IScriptBlocks;
  91.     FVars: TVars;
  92.     FVarsIntf: IVars;
  93.     FHTMLBlocks: THTMLBlocks;
  94.     FHTMLBlocksIntf: IHTMLBlocks;
  95.     FPassList: TPassList;
  96.     FAddElements: TAddScriptElements;
  97.     FAddElementsIntf: IAddScriptElements;
  98.     procedure AddScriptComponentsInternal(List: TObject);
  99.   protected
  100.     { IScriptManager }
  101.     function GetXMLDocuments: IXMLDocuments;
  102.     function GetIncludeFiles: IIncludeFiles;
  103.     function GetHTMLBlocks: IHTMLBlocks;
  104.     function GetVars: IVars;
  105.     function GetScriptBlocks: IScriptBlocks;
  106.     procedure AddError(const S: string);
  107.     function GetFunctions: IFunctions;
  108.     function GetWarnings: TStrings;
  109.     function GetOptions: TWebContentOptions;
  110.     function GetAddElementsIntf: IAddScriptElements;
  111.   public
  112.     constructor Create(Options: TWebContentOptions);
  113.     destructor Destroy; override;
  114.     procedure AddScriptComponents(List: TObject);
  115.     property IncludeFiles: IIncludeFiles read FIncludeFilesIntf;
  116.     property ScriptBlocks: IScriptBlocks read FScriptBlocksIntf;
  117.     property Vars: IVars read FVarsIntf;
  118.     property HTMLBlocks: IHTMLBlocks read FHTMLBlocksIntf;
  119.     property PassList: TPassList read FPassList;
  120.     property Options: TWebContentOptions read GetOptions;
  121.     property AddElementsIntf: IAddScriptElements read GetAddElementsIntf;
  122.   end;
  123.  
  124.   TIncludeFile = class;
  125.   TIncludeFiles = class(TScriptObjectContainer, IIncludeFiles)
  126.   private
  127.     function GetObject(I: Integer): TIncludeFile;
  128.   protected
  129.     function GetItem(I: Integer): IIncludeFile;
  130.   public
  131.     function AddFileName(const FileName: string): TIncludeFile;
  132.     function FindFileName(const FileName: string): TIncludeFile;
  133.     property Objects[I: Integer]: TIncludeFile read GetObject;
  134.     property Items[I: Integer]: IIncludeFile read GetItem;
  135.   end;
  136.  
  137.   TIncludeFile = class(TScriptObject, IIncludeFile)
  138.   private
  139.     FFileName: string;
  140.   protected
  141.     function GetFileName: string;
  142.     property FileName: string read GetFileName;
  143.   end;
  144.  
  145.   TFunction = class;
  146.   TFunctions = class(TScriptObjectContainer, IFunctions)
  147.   private
  148.     function GetObject(I: Integer): TFunction;
  149.   protected
  150.     function GetItem(I: Integer): IFunction;
  151.   public
  152.     function AddFunction(const Name, Body: string): TFunction;
  153.     function FindFunctionName(const Name: string): TFunction;
  154.     property Objects[I: Integer]: TFunction read GetObject;
  155.     property Items[I: Integer]: IFunction read GetItem;
  156.   end;
  157.  
  158.   TFunction = class(TNameContentScriptObject, IFunction)
  159.   protected
  160.     function GetFunctionName: string;
  161.     function GetBody: string;
  162.     property FunctionName: string read GetFunctionName;
  163.     property Body: string read GetBody;
  164.   end;
  165.  
  166.   TVar = class;
  167.   TVars = class(TScriptObjectContainer, IVars)
  168.   private
  169.     function GetObject(I: Integer): TVar;
  170.   protected
  171.     function GetItem(I: Integer): IVar;
  172.   public
  173.     function AddVar(const Name, Script: string): TVar;
  174.     function FindVarName(const Name: string): TVar;
  175.     property Objects[I: Integer]: TVar read GetObject;
  176.     property Items[I: Integer]: IVar read GetItem;
  177.   end;
  178.  
  179.   TVar = class(TNameContentScriptObject, IVar)
  180.   protected
  181.     function GetVarName: string;
  182.     function GetScript: string;
  183.     property VarName: string read GetVarName;
  184.     property Script: string read GetScript;
  185.   end;
  186.  
  187.   TScriptBlock = class;
  188.   TScriptBlocks = class(TScriptObjectContainer, IScriptBlocks)
  189.   private
  190.     function GetObject(I: Integer): TScriptBlock;
  191.   protected
  192.     function GetItem(I: Integer): IScriptBlock;
  193.   public
  194.     function AddBlock(const Name, Script: string): TScriptBlock;
  195.     function FindBlockName(const Name: string): TScriptBlock;
  196.     property Objects[I: Integer]: TScriptBlock read GetObject;
  197.     property Items[I: Integer]: IScriptBlock read GetItem;
  198.   end;
  199.  
  200.   TScriptBlock = class(TNameContentScriptObject, IScriptBlock)
  201.   protected
  202.     function GetBlockName: string;
  203.     function GetScript: string;
  204.     property BlockName: string read GetBlockName;
  205.     property Script: string read GetScript;
  206.   end;
  207.  
  208.   THTMLBlock = class;
  209.   THTMLBlocks = class(TScriptObjectContainer, IHTMLBlocks)
  210.   private
  211.     function GetObject(I: Integer): THTMLBlock;
  212.   protected
  213.     function GetItem(I: Integer): IHTMLBlock;
  214.   public
  215.     function AddBlock(const Name, HTML: string): THTMLBlock;
  216.     function FindBlockName(const Name: string): THTMLBlock;
  217.     property Objects[I: Integer]: THTMLBlock read GetObject;
  218.     property Items[I: Integer]: IHTMLBlock read GetItem;
  219.   end;
  220.  
  221.   THTMLBlock = class(TNameContentScriptObject, IHTMLBlock)
  222.   protected
  223.     function GetBlockName: string;
  224.     function GetHTML: string;
  225.     property BlockName: string read GetBlockName;
  226.     property HTML: string read GetHTML;
  227.   end;
  228.  
  229.   TXMLDocument = class;
  230.   TXMLDocuments = class(TScriptObjectContainer, IXMLDocuments)
  231.   private
  232.     function GetObject(I: Integer): TXMLDocument;
  233.   protected
  234.     function GetItem(I: Integer): IXMLDocument;
  235.   public
  236.     function AddXMLBroker(XMLBroker: TXMLBroker): TXMLDocument;
  237.     function FindXMLBroker(XMLBroker: TXMLBroker): TXMLDocument;
  238.     property Objects[I: Integer]: TXMLDocument read GetObject;
  239.     property Items[I: Integer]: IXMLDocument read GetItem;
  240.   end;
  241.  
  242.   TXMLRowSets = class;
  243.   TXMLDocument = class(TScriptObject, IXMLDocument)
  244.   private
  245.     FXMLRowSets: TXMLRowSets;
  246.     FXMLRowSetsIntf: IXMLRowSets;
  247.     FXMLBroker: TXMLBroker;
  248.   protected
  249.     function GetRowSets: IXMLRowSets;
  250.     function GetComponent: TComponent;
  251.     function GetDocumentVarName: string;
  252.     function GetXMLVarName: string;
  253.  
  254.     function GetXMLBroker: TXMLBroker;
  255.     property XMLBroker: TXMLBroker read GetXMLBroker;
  256.   public
  257.     constructor Create(AXMLDocuments: TXMLDocuments);
  258.     destructor Destroy; override;
  259.   end;
  260.  
  261.   TXMLRowSet = class;
  262.   TXMLRowSets = class(TScriptObjectContainer, IXMLRowSets)
  263.   private
  264.     FXMLDocument: TXMLDocument;
  265.   protected
  266.     function FindPath(Path: TStrings): TXMLRowSet;
  267.     function AddPath(Path: TStrings): TXMLRowSet;
  268.     function GetItem(I: Integer): IXMLRowSet;
  269.  
  270.     function GetObject(I: Integer): TXMLRowSet;
  271.     property Objects[I: Integer]: TXMLRowSet read GetObject;
  272.   public
  273.     constructor Create(AXMLDocument: TXMLDocument);
  274.     destructor Destroy; override;
  275.   end;
  276.  
  277.   TXMLRowSet = class(TScriptObject, IXMLRowSet)
  278.   private
  279.     FPath: TStrings;
  280.     FXMLRowSets: TXMLRowSets;
  281.   protected
  282.     function GetPath: TStrings;
  283.     function GetRowSetVarName: string;
  284.     function GetMasterRowSetVarName: string;
  285.     function GetMasterDataSetFieldName: string;
  286.   public
  287.     constructor Create(AXMLRowSets: TXMLRowSets);
  288.     destructor Destroy; override;
  289.   end;
  290.  
  291.   TPass = class;
  292.   TPassList = class(TObjectList)
  293.   protected
  294.     function GetItem(I: Integer): TPass;
  295.   public
  296.     procedure Add(Event: TAddScriptElementsEvent; Data: Pointer);
  297.     property Items[Index: Integer]: TPass read GetItem;
  298.   end;
  299.  
  300.   TPass = class(TObject)
  301.   private
  302.     Event: TAddScriptElementsEvent;
  303.     Data: Pointer;
  304.   public
  305.     constructor Create(AEvent: TAddScriptElementsEvent; AData: Pointer);
  306.   end;
  307.  
  308.   TAddScriptElements = class(TInterfacedObject, IAddScriptElements)
  309.   private
  310.     FScriptManager: TScriptManager;
  311.     FEmptyPath: TStrings;
  312.   protected
  313.     function AddIncludeFile(FileName: string): Boolean;
  314.     function AddRowSet(XMLBroker: TComponent; Path: TStrings): Boolean;
  315.     function AddHTMLBlock(Name: string; HTML: string): Boolean;
  316.     function AddScriptBlock(Name: string; Script: string): Boolean;
  317.     function AddFunction(Name: string; Body: string): Boolean;
  318.     function AddVar(Name: string; Script: string): Boolean;
  319.     procedure AddError(Text: string);
  320.     procedure AddPass(Event: TAddScriptElementsEvent; Data: Pointer);
  321.     procedure AddScriptComponents(List: TObject);
  322.     function GetScriptManager: IScriptManager;
  323.   public
  324.     constructor Create(AScriptManager: TScriptManager);
  325.     destructor Destroy; override;
  326.   end;
  327.  
  328. implementation
  329.  
  330. uses WbmConst;
  331.  
  332.  
  333. { TScriptManager }
  334.  
  335. constructor TScriptManager.Create(Options: TWebContentOptions);
  336. begin
  337.   inherited Create;
  338.   FOptions := Options;
  339.   FXMLDocuments := TXMLDocuments.Create(Self);
  340.   FXMLDocumentsIntf := FXMLDocuments;
  341.   FIncludeFiles := TIncludeFiles.Create(Self);
  342.   FIncludeFilesIntf := FIncludeFiles;
  343.   FScriptBlocks := TScriptBlocks.Create(Self);
  344.   FScriptBlocksIntf := FScriptBlocks;
  345.   FVars := TVars.Create(Self);
  346.   FVarsIntf := FVars;
  347.   FHTMLBlocks := THTMLBlocks.Create(Self);
  348.   FHTMLBlocksIntf := FHTMLBlocks;
  349.   FFunctions := TFunctions.Create(Self);
  350.   FFunctionsIntf := FFunctions;
  351.   FWarnings := TStringList.Create;
  352.   FPassList := TPassList.Create;
  353.   FAddElements := TAddScriptElements.Create(Self);
  354.   FAddElementsIntf := FAddElements;
  355. end;
  356.  
  357. procedure TScriptManager.AddScriptComponentsInternal(List: TObject);
  358. var
  359.   Intf: IWebComponentContainer;
  360.   I: Integer;
  361.   ScriptComponent: IScriptComponent;
  362.   SubList: TObject;
  363.   Component: TComponent;
  364. begin
  365.   if List.GetInterface(IWebComponentContainer, Intf) then
  366.     for I := 0 to Intf.ComponentCount - 1 do
  367.     begin
  368.       try
  369.         Component := Intf.Components[I];
  370.         if Component.GetInterface(IScriptComponent, ScriptComponent) then
  371.         begin
  372.           ScriptComponent.AddElements(AddElementsIntf);
  373.           SubList := ScriptComponent.SubComponents;
  374.           if Assigned(SubList) then
  375.             AddScriptComponentsInternal(SubList);
  376.         end;
  377.       except
  378.         on e: Exception do
  379.           AddError(e.Message);
  380.       end;
  381.     end;
  382. end;
  383.  
  384. procedure TScriptManager.AddScriptComponents(List: TObject);
  385. begin
  386.   Assert(Assigned(AddElementsIntf), 'AddElementsIntf = nil');
  387.   AddScriptComponentsInternal(List);
  388.  
  389.   while PassList.Count > 0 do
  390.   begin
  391.     with PassList.Items[0] do
  392.       Event(Data, AddElementsIntf);
  393.     PassList.Delete(0);
  394.   end;
  395. end;
  396.  
  397. procedure TScriptManager.AddError(const S: string);
  398. begin
  399.   if FWarnings.IndexOf(S) = -1 then
  400.     FWarnings.Add(S);
  401. end;
  402.  
  403. function TScriptManager.GetXMLDocuments: IXMLDocuments;
  404. begin
  405.   Result := FXMLDocumentsIntf;
  406. end;
  407.  
  408. destructor TScriptManager.Destroy;
  409. begin
  410.   inherited;
  411.   FWarnings.Free;
  412.   FPassList.Free;
  413. end;
  414.  
  415. function TScriptManager.GetIncludeFiles: IIncludeFiles;
  416. begin
  417.   Result := FIncludeFilesIntf;
  418. end;
  419.  
  420. function TScriptManager.GetFunctions: IFunctions;
  421. begin
  422.   Result := FFunctionsIntf;
  423. end;
  424.  
  425. function TScriptManager.GetHTMLBlocks: IHTMLBlocks;
  426. begin
  427.   Result := FHTMLBlocksIntf;
  428. end;
  429.  
  430. function TScriptManager.GetVars: IVars;
  431. begin
  432.   Result := FVarsIntf;
  433. end;
  434.  
  435. function TScriptManager.GetWarnings: TStrings;
  436. begin
  437.   Result := FWarnings;
  438. end;
  439.  
  440. function TScriptManager.GetScriptBlocks: IScriptBlocks;
  441. begin
  442.   Result := FScriptBlocksIntf;
  443. end;
  444.  
  445. function TScriptManager.GetOptions: TWebContentOptions;
  446. begin
  447.   Result := FOptions;
  448. end;
  449.  
  450. function TScriptManager.GetAddElementsIntf: IAddScriptElements;
  451. begin
  452.   Result := FAddElementsIntf;
  453. end;
  454.  
  455. { TScriptObjectContainer }
  456.  
  457. function TScriptObjectContainer.Add(
  458.   AObject: TScriptObject): Integer;
  459. begin
  460.   Result := Length(FItems);
  461.   SetLength(FItems, Result+1);
  462.   FItems[Result].FObject := AObject;
  463.   FItems[Result].FIntf := AObject;
  464. end;
  465.  
  466. function TScriptObjectContainer.GetCount: Integer;
  467. begin
  468.   Result := Length(FItems);
  469. end;
  470.  
  471. function TScriptObjectContainer.GetAsIntf(I: Integer): IUnknown;
  472. begin
  473.   Result := FItems[I].FIntf;
  474. end;
  475.  
  476. function TScriptObjectContainer.GetAsObject(I: Integer): TScriptObject;
  477. begin
  478.   Result := FItems[I].FObject;
  479. end;
  480.  
  481. destructor TScriptObjectContainer.Destroy;
  482. begin
  483.   inherited Destroy;
  484. end;
  485.  
  486. function TScriptObjectContainer.FindNameObject(const AName: string): TScriptObject;
  487. var
  488.   Intf: INameContent;
  489.   I: Integer;
  490. begin
  491.   for I := 0 to Count - 1 do
  492.   begin
  493.     Result := Objects[I];
  494.     if Result.GetInterface(INameContent, Intf) then
  495.       if Intf.MatchName(AName) then
  496.         Exit;
  497.   end;
  498.   Result := nil;
  499. end;
  500.  
  501. { TXMLDocuments }
  502.  
  503. function TXMLDocuments.AddXMLBroker(
  504.   XMLBroker: TXMLBroker): TXMLDocument;
  505. begin
  506.   Result := TXMLDocument.Create(Self);
  507.   Result.FXMLBroker := XMLBroker;
  508.   inherited Add(Result);
  509. end;
  510.  
  511. function TXMLDocuments.FindXMLBroker(
  512.   XMLBroker: TXMLBroker): TXMLDocument;
  513. var
  514.   I: Integer;
  515. begin
  516.   for I := 0 to Count - 1 do
  517.   begin
  518.     Result := Objects[I];
  519.     if Result.FXMLBroker = XMLBroker then
  520.       Exit;
  521.   end;
  522.   Result := nil;
  523. end;
  524.  
  525. function TXMLDocuments.GetItem(I: Integer): IXMLDocument;
  526. begin
  527.   Result := inherited GetAsIntf(I) as IXMLDocument
  528. end;
  529.  
  530. function TXMLDocuments.GetObject(I: Integer): TXMLDocument;
  531. begin
  532.   Result := inherited GetAsObject(I) as TXMLDocument;
  533. end;
  534.  
  535. { TXMLRowSets }
  536.  
  537. function TXMLRowSets.AddPath(Path: TStrings): TXMLRowSet;
  538. begin
  539.   Result := TXMLRowSet.Create(Self);
  540.   Result.FPath.Assign(Path);
  541.   inherited Add(Result);
  542. end;
  543.  
  544. constructor TXMLRowSets.Create(AXMLDocument: TXMLDocument);
  545. begin
  546.   inherited Create(AXMLDocument);
  547.   FXMLDocument := AXMLDocument;
  548. end;
  549.  
  550. destructor TXMLRowSets.Destroy;
  551. begin
  552.   inherited Destroy;
  553. end;
  554.  
  555. function TXMLRowSets.FindPath(Path: TStrings): TXMLRowSet;
  556.   function ComparePath(APath1, APath2: TStrings): Boolean;
  557.   var
  558.     I: Integer;
  559.   begin
  560.     Result := False;
  561.     if APath1.Count = APath2.Count then
  562.     begin
  563.       for I := 0 to APath1.Count - 1 do
  564.       begin
  565.         if CompareText(APath1[I], APath2[I]) <> 0 then
  566.           Exit;
  567.       end;
  568.       Result := True;
  569.     end;
  570.   end;
  571. var
  572.   I: Integer;
  573. begin
  574.   for I := 0 to Count - 1 do
  575.   begin
  576.     Result := Objects[I];
  577.     if ComparePath(Result.FPath, Path) then
  578.       Exit;
  579.   end;
  580.   Result := nil;
  581. end;
  582.  
  583. function TXMLRowSets.GetItem(I: Integer): IXMLRowSet;
  584. begin
  585.   Result := inherited GetAsIntf(I) as IXMLRowSet;
  586.  
  587. end;
  588.  
  589. function TXMLRowSets.GetObject(I: Integer): TXMLRowSet;
  590. begin
  591.   Result := inherited GetAsObject(I) as TXMLRowSet;
  592.  
  593. end;
  594.  
  595. { TXMLRowSet }
  596.  
  597. constructor TXMLRowSet.Create(AXMLRowSets: TXMLRowSets);
  598. begin
  599.   inherited Create(AXMLRowSets);
  600.   FXMLRowSets := AXMLRowSets;
  601.   FPath := TStringList.Create;
  602. end;
  603.  
  604. destructor TXMLRowSet.Destroy;
  605. begin
  606.   FPath.Free;
  607.   inherited;
  608. end;
  609.  
  610. function TXMLRowSet.GetMasterDataSetFieldName: string;
  611. begin
  612.   if FPath.Count > 0 then
  613.     Result := Format('"%s"', [FPath[FPath.Count-1]])
  614.   else
  615.     Result := 'null';
  616. end;
  617.  
  618. function TXMLRowSet.GetMasterRowSetVarName: string;
  619. begin
  620.   if FPath.Count > 0 then
  621.     Result := FXMLRowSets.FXMLDocument.FXMLBroker.MasterRowSetVarName(FPath)
  622.   else
  623.     Result := 'null';
  624. end;
  625.  
  626. function TXMLRowSet.GetPath: TStrings;
  627. begin
  628.   Result := FPath;
  629. end;
  630.  
  631. function TXMLRowSet.GetRowSetVarName: string;
  632. begin
  633.   Result := FXMLRowSets.FXMLDocument.FXMLBroker.RowSetVarName(FPath)
  634. end;
  635.  
  636. { TXMLDocument }
  637.  
  638. constructor TXMLDocument.Create(AXMLDocuments: TXMLDocuments);
  639. begin
  640.   inherited Create(AXMLDocuments);
  641.   FXMLRowSets := TXMLRowSets.Create(Self);
  642.   FXMLRowSetsIntf := FXMLRowSets;
  643. end;
  644.  
  645. destructor TXMLDocument.Destroy;
  646. begin
  647.   inherited;
  648. end;
  649.  
  650. function TXMLDocument.GetComponent: TComponent;
  651. begin
  652.   Result := FXMLBroker;
  653. end;
  654.  
  655. function TXMLDocument.GetDocumentVarName: string;
  656. begin
  657.   Result := Format(ScriptDocumentVarName, [FXMLBroker.Name])
  658. end;
  659.  
  660. function TXMLDocument.GetRowSets: IXMLRowSets;
  661. begin
  662.   Result := FXMLRowSetsIntf;
  663. end;
  664.  
  665. function TXMLDocument.GetXMLBroker: TXMLBroker;
  666. begin
  667.   Result := FXMLBroker;
  668. end;
  669.  
  670. function TXMLDocument.GetXMLVarName: string;
  671. begin
  672.   Result := Format(ScriptXMLVarName, [FXMLBroker.Name]);
  673. end;
  674.  
  675. { TScriptObject }
  676.  
  677. constructor TScriptObject.Create(AParent: TObject);
  678. begin
  679.   inherited Create;
  680.   FParent := AParent;
  681. end;
  682.  
  683. { TScriptComponentElements }
  684.  
  685. function TAddScriptElements.AddScriptBlock(Name: string; Script: string): Boolean;
  686. begin
  687.   Result := (Name = '') or (FScriptManager.FScriptBlocks.FindBlockName(Name) = nil);
  688.   if Result then
  689.     FScriptManager.FScriptBlocks.AddBlock(Name, Script);
  690. end;
  691.  
  692. function TAddScriptElements.AddHTMLBlock(Name: string; HTML: string): Boolean;
  693. begin
  694.   Result := (Name = '') or (FScriptManager.FHTMLBlocks.FindBlockName(Name) = nil);
  695.   if Result then
  696.     FScriptManager.FHTMLBlocks.AddBlock(Name, HTML);
  697. end;
  698.  
  699. function TAddScriptElements.AddVar(Name: string; Script: string): Boolean;
  700. begin
  701.   Result := FScriptManager.FVars.FindVarName(Name) = nil;
  702.   if Result then
  703.     FScriptManager.FVars.AddVar(Name, Script);
  704. end;
  705.  
  706. function TAddScriptElements.AddRowSet(XMLBroker: TComponent;
  707.   Path: TStrings): Boolean;
  708. var
  709.   XMLDocument: TXMLDocument;
  710.   TempPath: TStrings;
  711. begin
  712.   XMLDocument := FScriptManager.FXMLDocuments.FindXMLBroker(XMLBroker as TXMLBroker);
  713.   if not Assigned(XMLDocument) then
  714.     XMLDocument := FScriptManager.FXMLDocuments.AddXMLBroker(TXMLBroker(XMLBroker));
  715.   if Path = nil then
  716.     Path := FEmptyPath;
  717.   Result := XMLDocument.FXMLRowSets.FindPath(Path) = nil;
  718.   if Result then
  719.   begin
  720.     // Define a complete rowset path
  721.     if Path.Count >= 1 then
  722.     begin
  723.       TempPath := TStringList.Create;
  724.       try
  725.         while TempPath.Count < Path.Count do
  726.         begin
  727.           if XMLDocument.FXMLRowSets.FindPath(TempPath) = nil then
  728.              XMLDocument.FXMLRowSets.AddPath(TempPath);
  729.           TempPath.Add(Path[TempPath.Count]);
  730.         end;
  731.       finally
  732.         TempPath.Free;
  733.       end;
  734.     end;
  735.     XMLDocument.FXMLRowSets.AddPath(Path);
  736.   end;
  737. end;
  738.  
  739. function TAddScriptElements.AddFunction(Name, Body: string): Boolean;
  740. begin
  741.   Result := FScriptManager.FFunctions.FindFunctionName(Name) = nil;
  742.   if Result then
  743.     FScriptManager.FFunctions.AddFunction(Name, Body);
  744. end;
  745.  
  746. function TAddScriptElements.AddIncludeFile(FileName: string): Boolean;
  747. begin
  748.   Result := FScriptManager.FIncludeFiles.FindFileName(FileName) = nil;
  749.   if Result then
  750.     FScriptManager.FIncludeFiles.AddFileName(FileName);
  751. end;
  752.  
  753. constructor TAddScriptElements.Create(AScriptManager: TScriptManager);
  754. begin
  755.   FScriptManager := AScriptManager;
  756.   FEmptyPath := TStringList.Create;
  757. end;
  758.  
  759. destructor TAddScriptElements.Destroy;
  760. begin
  761.   inherited;
  762.   FEmptyPath.Free;
  763. end;
  764.  
  765. procedure TAddScriptElements.AddError(Text: string);
  766. begin
  767.   FScriptManager.AddError(Text);
  768. end;
  769.  
  770. procedure TAddScriptElements.AddPass(Event: TAddScriptElementsEvent;
  771.   Data: Pointer);
  772. begin
  773.   FScriptManager.FPassList.Add(Event, Data);
  774. end;
  775.  
  776. function TAddScriptElements.GetScriptManager: IScriptManager;
  777. begin
  778.   FScriptManager.GetInterface(IScriptManager, Result);
  779. end;
  780.  
  781. { TIncludeFiles }
  782.  
  783. function TIncludeFiles.AddFileName(const FileName: string): TIncludeFile;
  784. begin
  785.   Result := TIncludeFile.Create(Self);
  786.   Result.FFileName := FileName;
  787.   inherited Add(Result);
  788. end;
  789.  
  790. function TIncludeFiles.FindFileName(const FileName: string): TIncludeFile;
  791. var
  792.   I: Integer;
  793. begin
  794.   for I := 0 to Count - 1 do
  795.   begin
  796.     Result := Objects[I];
  797.     if CompareText(FileName,Result.FileName) = 0 then
  798.       Exit;
  799.   end;
  800.   Result := nil;
  801. end;
  802.  
  803. function TIncludeFiles.GetItem(I: Integer): IIncludeFile;
  804. begin
  805.   Result := inherited GetAsIntf(I) as IIncludeFile;
  806. end;
  807.  
  808. function TIncludeFiles.GetObject(I: Integer): TIncludeFile;
  809. begin
  810.   Result := inherited GetAsObject(I) as TIncludeFile;
  811. end;
  812.  
  813. { TIncludeFile }
  814.  
  815. function TIncludeFile.GetFileName: string;
  816. begin
  817.   Result := FFileName;
  818. end;
  819.  
  820. { TFunctions }
  821.  
  822. function TFunctions.AddFunction(const Name,
  823.   Body: string): TFunction;
  824. begin
  825.   Result := TFunction.Create(Self, Name, Body);
  826.   inherited Add(Result);
  827. end;
  828.  
  829. function TFunctions.FindFunctionName(
  830.   const Name: string): TFunction;
  831. begin
  832.   Result := TFunction(FindNameObject(Name));
  833. end;
  834.  
  835. function TFunctions.GetItem(I: Integer): IFunction;
  836. begin
  837.   Result := inherited GetAsIntf(I) as IFunction;
  838. end;
  839.  
  840. function TFunctions.GetObject(I: Integer): TFunction;
  841. begin
  842.   Result := inherited GetAsObject(I) as TFunction;
  843. end;
  844.  
  845. { TFunction }
  846.  
  847. function TFunction.GetBody: string;
  848. begin
  849.   Result := Content;
  850. end;
  851.  
  852. function TFunction.GetFunctionName: string;
  853. begin
  854.   Result := Name;
  855. end;
  856.  
  857. { THTMLBlocks }
  858.  
  859. function THTMLBlocks.AddBlock(const Name,
  860.   HTML: string): THTMLBlock;
  861. begin
  862.   Result := THTMLBlock.Create(Self, Name, HTML);
  863.   inherited Add(Result);
  864. end;
  865.  
  866. function THTMLBlocks.FindBlockName(
  867.   const Name: string): THTMLBlock;
  868. begin
  869.   Result := THTMLBlock(FindNameObject(Name));
  870. end;
  871.  
  872. function THTMLBlocks.GetItem(I: Integer): IHTMLBlock;
  873. begin
  874.   Result := inherited GetAsIntf(I) as IHTMLBlock;
  875. end;
  876.  
  877. function THTMLBlocks.GetObject(I: Integer): THTMLBlock;
  878. begin
  879.   Result := inherited GetAsObject(I) as THTMLBlock;
  880. end;
  881.  
  882. { THTMLBlock }
  883.  
  884. function THTMLBlock.GetHTML: string;
  885. begin
  886.   Result := Content;
  887. end;
  888.  
  889. function THTMLBlock.GetBlockName: string;
  890. begin
  891.   Result := Name;
  892. end;
  893.  
  894. { TScriptBlocks }
  895.  
  896. function TScriptBlocks.AddBlock(const Name,
  897.   Script: string): TScriptBlock;
  898. begin
  899.   Result := TScriptBlock.Create(Self, Name, Script);
  900.   inherited Add(Result);
  901. end;
  902.  
  903. function TScriptBlocks.FindBlockName(
  904.   const Name: string): TScriptBlock;
  905. begin
  906.   Result := TScriptBlock(FindNameObject(Name));
  907. end;
  908.  
  909. function TScriptBlocks.GetItem(I: Integer): IScriptBlock;
  910. begin
  911.   Result := inherited GetAsIntf(I) as IScriptBlock;
  912. end;
  913.  
  914. function TScriptBlocks.GetObject(I: Integer): TScriptBlock;
  915. begin
  916.   Result := inherited GetAsObject(I) as TScriptBlock;
  917. end;
  918.  
  919. { TScriptBlock }
  920.  
  921. function TScriptBlock.GetScript: string;
  922. begin
  923.   Result := Content;
  924. end;
  925.  
  926. function TScriptBlock.GetBlockName: string;
  927. begin
  928.   Result := Name;
  929. end;
  930.  
  931. { TVars }
  932.  
  933. function TVars.AddVar(const Name,
  934.   Script: string): TVar;
  935. begin
  936.   Result := TVar.Create(Self, Name, Script);
  937.   inherited Add(Result);
  938. end;
  939.  
  940. function TVars.FindVarName(
  941.   const Name: string): TVar;
  942. begin
  943.   Result := TVar(FindNameObject(Name));
  944. end;
  945.  
  946. function TVars.GetItem(I: Integer): IVar;
  947. begin
  948.   Result := inherited GetAsIntf(I) as IVar;
  949. end;
  950.  
  951. function TVars.GetObject(I: Integer): TVar;
  952. begin
  953.   Result := inherited GetAsObject(I) as TVar;
  954. end;
  955.  
  956. { TVar }
  957.  
  958. function TVar.GetScript: string;
  959. begin
  960.   Result := Content;
  961. end;
  962.  
  963. function TVar.GetVarName: string;
  964. begin
  965.   Result := Name;
  966. end;
  967.  
  968. { TPassList }
  969.  
  970. procedure TPassList.Add(Event: TAddScriptElementsEvent; Data: Pointer);
  971. begin
  972.   inherited Add(TPass.Create(Event, Data));
  973. end;
  974.  
  975. function TPassList.GetItem(I: Integer): TPass;
  976. begin
  977.   Result := inherited Items[I] as TPass;
  978. end;
  979.  
  980. { TPass }
  981.  
  982. constructor TPass.Create(AEvent: TAddScriptElementsEvent; AData: Pointer);
  983. begin
  984.   Event := AEvent;
  985.   Data := AData;
  986. end;
  987.  
  988.  
  989. { TNameContentScriptObject }
  990.  
  991. constructor TNameContentScriptObject.Create(AParent: TObject; const AName,
  992.   AContent: string);
  993. begin
  994.   inherited Create(AParent);
  995.   FName := AName;
  996.   FContent := AContent;
  997. end;
  998.  
  999. function TNameContentScriptObject.GetContent: string;
  1000. begin
  1001.   Result := FContent;
  1002. end;
  1003.  
  1004. function TNameContentScriptObject.GetName: string;
  1005. begin
  1006.   Result := FName;
  1007. end;
  1008.  
  1009. function TNameContentScriptObject.MatchName(const AName: string): Boolean;
  1010. begin
  1011.   Result := AName = Name;
  1012. end;
  1013.  
  1014. procedure TAddScriptElements.AddScriptComponents(List: TObject);
  1015. begin
  1016.   FScriptManager.AddScriptComponents(List);
  1017. end;
  1018.  
  1019. end.
  1020.  
  1021.