{$MODE FPC}
{$MODESWITCH RESULT}
{$MODESWITCH DEFAULTPARAMETERS}
unit dxml_sax_switchable;

interface

uses
  dansiview,
  dxml_sax;

type
TXmlReaderSwitchable = object(TXmlReader)
public type
  TOnDocumentBegin = procedure(Self: Pointer) of object;
  TOnDocumentEnd = procedure(Self: Pointer) of object;
  TOnHeaderBegin = procedure(Self: Pointer; const HeaderTag: TAnsiView) of object;
  TOnHeaderEnd = procedure (Self: Pointer; const HeaderTag: TAnsiView) of object;
  TOnOpenTagBegin = procedure (Self: Pointer; Parser: PXmlParser; const Name: TAnsiView) of object;
  TOnAttribute = procedure (Self: Pointer; const Name, Value: TAnsiView) of object;
  TOnOpenTagEnd = procedure (Self: Pointer; const Name: TAnsiView) of object;
  TOnContent = procedure (Self: Pointer; const Content: TAnsiView) of object;
  TOnCloseTag = procedure (Self: Pointer; const Name: TAnsiView) of object;
private
  FOnDocumentBegin: TOnDocumentBegin;
  FOnDocumentEnd: TOnDocumentEnd;
  FOnHeaderBegin: TOnHeaderBegin;
  FOnHeaderEnd: TOnHeaderEnd;
  FOnOpenTagBegin: TOnOpenTagBegin;
  FOnAttribute: TOnAttribute;
  FOnOpenTagEnd: TOnOpenTagEnd;
  FOnContent: TOnContent;
  FOnCloseTag: TOnCloseTag;
protected
  procedure SetOnDocumentBegin(aOnDocumentBegin: TOnDocumentBegin);
  procedure SetOnDocumentEnd(aOnDocumentEnd: TOnDocumentEnd);
  procedure SetOnHeaderBegin(aOnHeaderBegin: TOnHeaderBegin);
  procedure SetOnHeaderEnd(aOnHeaderEnd: TOnHeaderEnd);
  procedure SetOnOpenTagBegin(aOnOpenTagBegin: TOnOpenTagBegin);
  procedure SetOnAttribute(aOnAttribute: TOnAttribute);
  procedure SetOnOpenTagEnd(aOnOpenTagEnd: TOnOpenTagEnd);
  procedure SetOnContent(aOnContent: TOnContent);
  procedure SetOnCloseTag(aOnCloseTag: TOnCloseTag);
public
  constructor Init;
  procedure OnDocumentBegin; virtual;
  procedure OnDocumentEnd; virtual;
  procedure OnHeaderBegin(const HeaderTag: TAnsiView); virtual;
  procedure OnHeaderEnd(const HeaderTag: TAnsiView); virtual;
  procedure OnOpenTagBegin(Parser: PXmlParser; const Name: TAnsiView); virtual;
  procedure OnAttribute(const Name, Value: TAnsiView); virtual;
  procedure OnOpenTagEnd(const Name: TAnsiView); virtual;
  procedure OnContent(const Content: TAnsiView); virtual;
  procedure OnCloseTag(const Name: TAnsiView); virtual;
end;

implementation

procedure TXmlReaderSwitchable.SetOnDocumentBegin(aOnDocumentBegin: TOnDocumentBegin);
begin
  FOnDocumentBegin := aOnDocumentBegin;
end;

procedure TXmlReaderSwitchable.SetOnDocumentEnd(aOnDocumentEnd: TOnDocumentEnd);
begin
  FOnDocumentEnd := aOnDocumentEnd;
end;

procedure TXmlReaderSwitchable.SetOnHeaderBegin(aOnHeaderBegin: TOnHeaderBegin);
begin
  FOnHeaderBegin := aOnHeaderBegin;
end;

procedure TXmlReaderSwitchable.SetOnHeaderEnd(aOnHeaderEnd: TOnHeaderEnd);
begin
  FOnHeaderEnd := aOnHeaderEnd;
end;

procedure TXmlReaderSwitchable.SetOnOpenTagBegin(aOnOpenTagBegin: TOnOpenTagBegin);
begin
  FOnOpenTagBegin := aOnOpenTagBegin;
end;

procedure TXmlReaderSwitchable.SetOnAttribute(aOnAttribute: TOnAttribute);
begin
  FOnAttribute := aOnAttribute;
end;

procedure TXmlReaderSwitchable.SetOnOpenTagEnd(aOnOpenTagEnd: TOnOpenTagEnd);
begin
  FOnOpenTagEnd := aOnOpenTagEnd;
end;

procedure TXmlReaderSwitchable.SetOnContent(aOnContent: TOnContent);
begin
  FOnContent := aOnContent;
end;

procedure TXmlReaderSwitchable.SetOnCloseTag(aOnCloseTag: TOnCloseTag);
begin
  FOnCloseTag := aOnCloseTag;
end;

constructor TXmlReaderSwitchable.Init;
begin
  SetOnDocumentBegin(nil);
  SetOnDocumentEnd(nil);
  SetOnHeaderBegin(nil);
  SetOnHeaderEnd(nil);
  SetOnOpenTagBegin(nil);
  SetOnAttribute(nil);
  SetOnOpenTagEnd(nil);
  SetOnContent(nil);
  SetOnCloseTag(nil);
end;

procedure TXmlReaderSwitchable.OnDocumentBegin;
begin
  if FOnDocumentBegin <> nil then
    FOnDocumentBegin(@Self);
end;

procedure TXmlReaderSwitchable.OnDocumentEnd;
begin
  if FOnDocumentEnd <> nil then
    FOnDocumentEnd(@Self);
end;

procedure TXmlReaderSwitchable.OnHeaderBegin(const HeaderTag: TAnsiView);
begin
  if FOnHeaderBegin <> nil then
    FOnHeaderBegin(@Self, HeaderTag);
end;

procedure TXmlReaderSwitchable.OnHeaderEnd(const HeaderTag: TAnsiView);
begin
  if FOnHeaderEnd <> nil then
    FOnHeaderEnd(@Self, HeaderTag);
end;

procedure TXmlReaderSwitchable.OnOpenTagBegin(Parser: PXmlParser; const Name: TAnsiView);
begin
  if FOnOpenTagBegin <> nil then
    FOnOpenTagBegin(@Self, Parser, Name);
end;

procedure TXmlReaderSwitchable.OnAttribute(const Name, Value: TAnsiView);
begin
  if FOnAttribute <> nil then
    FOnAttribute(@Self, Name, Value);
end;

procedure TXmlReaderSwitchable.OnOpenTagEnd(const Name: TAnsiView);
begin
  if FOnOpenTagEnd <> nil then
    FOnOpenTagEnd(@Self, Name);
end;

procedure TXmlReaderSwitchable.OnContent(const Content: TAnsiView);
begin
  if FOnContent <> nil then
    FOnContent(@Self, Content);
end;

procedure TXmlReaderSwitchable.OnCloseTag(const Name: TAnsiView);
begin
  if FOnCloseTag <> nil then
    FOnCloseTag(@Self, Name);
end;

end.
