unit xmppMessageClass;
interface
uses xmldom, XMLIntf, msxmldom, XMLDoc;
type TMessageType = (mtChat, mtNormal, mtError, mtGroupChat, mtHeadline);
type TXMPPMessage = class(TObject)
private
fXMLDocument: string;
fType: TMessageType;
fFrom: string;
fTo: string;
fSubject: string;
fBody: string;
fThread: string;
fId: string;
protected
procedure SetType( pType: TMessageType );
procedure SetFrom( pFrom: string );
procedure SetTo( pTo: string );
procedure SetSubject( pSubject: string );
procedure SetBody( pBody: string );
procedure SetThread( pThread: string );
procedure SetId( pId: string );
public
property MessageType: TMessageType read fType write SetType;
property From: string read fFrom write SetFrom;
property To_: string read fTo write SetTo;
property Subject: string read fSubject write SetSubject;
property Body: string read fBody write SetBody;
property Thread: string read fThread write SetThread;
property Id: string read fId write SetId;
function GetXmlText(): string;
constructor Create();
end;
implementation
uses Dialogs, unMain;
constructor TXMPPMessage.Create;
begin
fXMLDocument := '';
end;
function TXMPPMessage.GetXmlText: string;
begin
Result := fXMLDocument;
end;
procedure TXMPPMessage.SetBody(pBody: string);
var
vXMLDoc: TXMLDocument;
begin
vXMLDoc := TXMLDocument.Create(Form1);
try
fBody := pBody;
vXMLDoc.XML.Text := fXMLDocument;
vXMLDoc.Active := True;
vXMLDoc.DocumentElement.ChildNodes['body'].Text := pBody;
fXMLDocument := vXMLDoc.XML.Text;
finally
vXMLDoc.Free;
end;
end;
procedure TXMPPMessage.SetFrom(pFrom: string);
var
vXMLDoc: TXMLDocument;
begin
vXMLDoc := TXMLDocument.Create(Form1);
try
fFrom := pFrom;
vXMLDoc.XML.Text := fXMLDocument;
vXMLDoc.Active := True;
vXMLDoc.DocumentElement.Attributes['from'] := pFrom;
fXMLDocument := vXMLDoc.XML.Text;
finally
vXMLDoc.Free;
end;
end;
procedure TXMPPMessage.SetId(pId: string);
var
vXMLDoc: TXMLDocument;
begin
vXMLDoc := TXMLDocument.Create(Form1);
try
fId := pId;
vXMLDoc.XML.Text := fXMLDocument;
vXMLDoc.Active := True;
vXMLDoc.DocumentElement.Attributes['id'] := pId;
fXMLDocument := vXMLDoc.XML.Text;
finally
vXMLDoc.Free;
end;
end;
procedure TXMPPMessage.SetSubject(pSubject: string);
var
vXMLDoc: TXMLDocument;
begin
vXMLDoc := TXMLDocument.Create(Form1);
try
fSubject := pSubject;
vXMLDoc.XML.Text := fXMLDocument;
vXMLDoc.Active := True;
vXMLDoc.DocumentElement.ChildNodes['subject'].Text := pSubject;
fXMLDocument := vXMLDoc.XML.Text;
finally
vXMLDoc.Free;
end;
end;
procedure TXMPPMessage.SetThread(pThread: string);
var
vXMLDoc: TXMLDocument;
begin
vXMLDoc := TXMLDocument.Create(Form1);
try
fThread := pThread;
vXMLDoc.XML.Text := fXMLDocument;
vXMLDoc.Active := True;
vXMLDoc.DocumentElement.ChildNodes['thread'].Text := pThread;
fXMLDocument := vXMLDoc.XML.Text;
finally
vXMLDoc.Free;
end;
end;
procedure TXMPPMessage.SetTo(pTo: string);
var
vXMLDoc: TXMLDocument;
begin
vXMLDoc := TXMLDocument.Create(Form1);
try
fTo := pTo;
vXMLDoc.XML.Text := fXMLDocument;
vXMLDoc.Active := True;
vXMLDoc.DocumentElement.Attributes['to'] := pTo;
fXMLDocument := vXMLDoc.XML.Text;
finally
vXMLDoc.Free;
end;
end;
procedure TXMPPMessage.SetType(pType: TMessageType);
var
vXMLDoc: TXMLDocument;
begin
vXMLDoc := TXMLDocument.Create(Form1);
try
fType := pType;
vXMLDoc.XML.Text := fXMLDocument;
vXMLDoc.Active := True;
case pType of
mtChat: vXMLDoc.DocumentElement.Attributes['type'] := 'chat';
mtNormal: vXMLDoc.DocumentElement.Attributes['type'] := 'normal';
mtError: vXMLDoc.DocumentElement.Attributes['type'] := 'error';
mtGroupChat: vXMLDoc.DocumentElement.Attributes['type'] := 'groupchat';
mtHeadline: vXMLDoc.DocumentElement.Attributes['type'] := 'headline';
end;
fXMLDocument := vXMLDoc.XML.Text;
finally
vXMLDoc.Free;
end;
end;
end.