Add XmlRPC date support

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@891 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
inoussa
2009-07-02 10:57:58 +00:00
parent c9965ea7d0
commit 440ac40b8c
2 changed files with 81 additions and 11 deletions

View File

@ -17,7 +17,12 @@ interface
uses uses
Classes, SysUtils, TypInfo, Contnrs, Classes, SysUtils, TypInfo, Contnrs,
{$IFNDEF FPC}xmldom, wst_delphi_xml{$ELSE}DOM{$ENDIF}, {$IFDEF WST_DELPHI}
xmldom, wst_delphi_xml,
{$ENDIF WST_DELPHI}
{$IFDEF FPC}
DOM, XMLWrite, XMLRead,wst_fpc_xml,
{$ENDIF FPC}
base_service_intf; base_service_intf;
const const
@ -44,6 +49,9 @@ const
XML_RPC_FALSE = '0'; XML_RPC_FALSE = '0';
XML_RPC_TRUE = '1'; XML_RPC_TRUE = '1';
stXmlRpcDate = stBase + 3;
stSimpleContent = stXmlRpcDate + 1;
type type
TwstXMLDocument = {$IFNDEF FPC}wst_delphi_xml.TXMLDocument{$ELSE}TXMLDocument{$ENDIF}; TwstXMLDocument = {$IFNDEF FPC}wst_delphi_xml.TXMLDocument{$ELSE}TXMLDocument{$ENDIF};
@ -92,6 +100,10 @@ type
property FoundState : TFoundState read FFoundState; property FoundState : TFoundState read FFoundState;
function GetScopeItemNames(const AReturnList : TStrings) : Integer;virtual;abstract; function GetScopeItemNames(const AReturnList : TStrings) : Integer;virtual;abstract;
procedure CreateInnerBuffer(
const AText : DOMString;
const ADoc : TXMLDocument
); virtual;
end; end;
{ TObjectStackItem } { TObjectStackItem }
@ -154,7 +166,19 @@ type
const ADataType : TXmlRpcDataType const ADataType : TXmlRpcDataType
):TDOMNode;override; ):TDOMNode;override;
end; end;
{ TSimpleTypeStackItem }
TSimpleTypeStackItem = class(TStackItem)
public
function FindNode(var ANodeName : string):TDOMNode; override;
function CreateBuffer(
Const AName : string;
const ADataType : TXmlRpcDataType
):TDOMNode; override;
function GetScopeItemNames(const AReturnList : TStrings) : Integer; override;
end;
{$M+} {$M+}
{ TXmlRpcBaseFormatter } { TXmlRpcBaseFormatter }
@ -442,8 +466,8 @@ type
{$M-} {$M-}
implementation implementation
Uses {$IFNDEF FPC}XMLDoc,XMLIntf,{$ELSE}XMLWrite, XMLRead,wst_fpc_xml,{$ENDIF} uses
imp_utils; Imp_utils, wst_consts;
{ TStackItem } { TStackItem }
@ -463,6 +487,14 @@ begin
FScopeType := AScopeType; FScopeType := AScopeType;
end; end;
procedure TStackItem.CreateInnerBuffer(
const AText : DOMString;
const ADoc : TXMLDocument
);
begin
ScopeObject.AppendChild(ADoc.CreateTextNode(AText));
end;
{ TObjectStackItem } { TObjectStackItem }
function TObjectStackItem.FindNode(var ANodeName: string): TDOMNode; function TObjectStackItem.FindNode(var ANodeName: string): TDOMNode;
@ -1223,8 +1255,16 @@ procedure TXmlRpcBaseFormatter.BeginObject(
const AName : string; const AName : string;
const ATypeInfo : PTypeInfo const ATypeInfo : PTypeInfo
); );
var
locScopeType : TScopeType;
begin begin
BeginScope(AName,'','',stObject,asNone); if ( ATypeInfo^.Kind = tkClass ) and
( GetTypeData(ATypeInfo)^.ClassType.InheritsFrom(TDateRemotable) )
then
locScopeType := stXmlRpcDate
else
locScopeType := stObject;
BeginScope(AName,'','',locScopeType,asNone);
end; end;
procedure TXmlRpcBaseFormatter.BeginArray( procedure TXmlRpcBaseFormatter.BeginArray(
@ -1269,10 +1309,13 @@ Var
e : TDOMNode; e : TDOMNode;
dtType : TXmlRpcDataType; dtType : TXmlRpcDataType;
begin begin
if ( AScopeType = stArray ) then case AScopeType of
dtType := xdtArray stXmlRpcDate : dtType := xdtDateTime;
else stSimpleContent : dtType := xdtString;
dtType := xdtStruct; stArray : dtType := xdtArray;
else
dtType := xdtStruct;
end;
if HasScope() then begin if HasScope() then begin
e := StackTop().CreateBuffer(AScopeName,dtType); e := StackTop().CreateBuffer(AScopeName,dtType);
end else begin end else begin
@ -1281,8 +1324,10 @@ begin
end; end;
if ( AScopeType = stObject ) then begin if ( AScopeType = stObject ) then begin
PushStack(e); PushStack(e);
end else begin end else if ( AScopeType = stArray ) then begin
PushStack(e,AStyle,''); PushStack(e,AStyle,'');
end else begin
FStack.Push(TSimpleTypeStackItem.Create(e,AScopeType));
end; end;
end; end;
@ -1588,7 +1633,8 @@ begin
dataBuffer := wst_FormatFloat(ATypeInfo,floatDt); dataBuffer := wst_FormatFloat(ATypeInfo,floatDt);
end; end;
end; end;
StackTop().ScopeObject.AppendChild(FDoc.CreateTextNode(dataBuffer)); StackTop().CreateInnerBuffer(dataBuffer,FDoc);
//StackTop().ScopeObject.AppendChild(FDoc.CreateTextNode(dataBuffer));
end; end;
function TXmlRpcBaseFormatter.Get( function TXmlRpcBaseFormatter.Get(
@ -2034,4 +2080,27 @@ begin
FIndexStack[FIndexStackIDX] := Result; FIndexStack[FIndexStackIDX] := Result;
end; end;
{ TSimpleTypeStackItem }
{$WARNINGS OFF}
function TSimpleTypeStackItem.FindNode(var ANodeName: string): TDOMNode;
begin
raise EXmlRpcException.CreateFmt(SERR_InsupportedOperation,['FindNode']);
end;
function TSimpleTypeStackItem.CreateBuffer(
const AName: string;
const ADataType: TXmlRpcDataType
) : TDOMNode;
begin
raise EXmlRpcException.CreateFmt(SERR_InsupportedOperation,['CreateBuffer']);
end;
function TSimpleTypeStackItem.GetScopeItemNames(const AReturnList: TStrings): Integer;
begin
raise EXmlRpcException.CreateFmt(SERR_InsupportedOperation,['GetScopeItemNames']);
end;
{$WARNINGS ON}
end. end.

View File

@ -17,6 +17,7 @@ unit wst_consts;
interface interface
resourcestring resourcestring
SERR_InsupportedOperation = 'Insupported operation : "%s".';
SERR_InvalidArrayLength = 'Invalid array length : %d.'; SERR_InvalidArrayLength = 'Invalid array length : %d.';
SERR_InvalidCollectionLength = 'Invalid collection length : %d.'; SERR_InvalidCollectionLength = 'Invalid collection length : %d.';
SERR_InvalidHourOffetValue = '"%d" is not a valid hour offset value.'; SERR_InvalidHourOffetValue = '"%d" is not a valid hour offset value.';