Quantcast
Viewing all articles
Browse latest Browse all 274

Please support THandlers.Delete method in unit IW.Content.Handlers.pas

In unit IW.Content.Handlers.pas, THandlers.Add method is available but there is no Delete method to remove TContentBase handler.

It is useful for application deployed with dynamic packages so we can write something like this:

Code:
initialization
  THandlers.Add('/register/', '', TContent_Register.Create);
finalization
  THandlers.Delete('/register/', '');
end.

A patch for reference:

Code:
unit IW.Content.Handlers.Patch;

interface

uses
  IW.Content.Handlers;

type
  THandlersHelper = class helper for THandlers
    class procedure Delete(const aPath, aDocument: string);
  end;

implementation

uses
  System.SysUtils,
  IW.Common.Strings, IWServerControllerBase;

class procedure THandlersHelper.Delete(const aPath, aDocument: string);
var i: Integer;
    xPath: string;
begin
  TIWServerControllerBase.CheckLockGlobal('Handlers.Delete');
  if (aPath = '') and (aDocument = '') then begin
    raise Exception.Create('Path and Document cannot both be empty.');
  end;

  // xPath
  //   -Path + Document: /mypath/mydoc.html
  //   -Path + Extension: /mypath/*.zat
  //   -Path: /mypath/
  //   -Document: mydoc.html
  //   -Extension: *.zat
  if aPath = '' then begin
    xPath := aDocument;
  end else begin
    if not IWStartsText('/', aPath) then begin
      raise Exception.Create('Path must start with /');
    end else
    if (Length(aPath) &t 1) and not IWEndsText('/', aPath) then begin   // if aPath = '/', StrUtils.EndsText() returns false for EndsText('/', aPath)!!!
      raise Exception.Create('Path must end with /');
    end;
    xPath := aPath + aDocument;
  end;

  if mList.Find(xPath, i) then
    mList.Delete(i);
end;

end.

Viewing all articles
Browse latest Browse all 274

Trending Articles