From ca8492e5bd1d50c153140867adb8696b967b0259 Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Wed, 18 Apr 2012 14:13:41 +0000 Subject: [PATCH] Added: SaveToFile methods for Base64 encoded elements --- Shared/XMLDataBindingUtils.pas | 21 +++++++++++++++++++++ Units/DelphiXMLDataBindingGenerator.pas | 6 ++++++ Units/DelphiXMLDataBindingResources.pas | 17 +++++++++++++++++ X2XMLDataBinding.dproj | 2 +- 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/Shared/XMLDataBindingUtils.pas b/Shared/XMLDataBindingUtils.pas index 91b7528..48ede1e 100644 --- a/Shared/XMLDataBindingUtils.pas +++ b/Shared/XMLDataBindingUtils.pas @@ -57,6 +57,7 @@ const function Base64Encode(AValue: String): String; function Base64Decode(AValue: String): String; procedure Base64DecodeToStream(AValue: String; AStream: TStream); + procedure Base64DecodeToFile(AValue: String; const AFileName: String); const XMLSchemaInstanceURI = 'http://www.w3.org/2001/XMLSchema-instance'; @@ -340,6 +341,26 @@ begin end; +procedure Base64DecodeToFile(AValue: String; const AFileName: String); +var + input: TStringStream; + output: TFileStream; + +begin + input := TStringStream.Create(AValue); + try + output := TFileStream.Create(AFileName, fmCreate or fmShareDenyWrite); + try + MimeDecodeStream(input, output); + finally + FreeAndNil(output); + end; + finally + FreeAndNil(input); + end; +end; + + function GetNodeIsNil(ANode: IXMLNode): Boolean; begin Result := ANode.HasAttribute(XMLIsNilAttribute, XMLSchemaInstanceURI) and diff --git a/Units/DelphiXMLDataBindingGenerator.pas b/Units/DelphiXMLDataBindingGenerator.pas index 3304533..1f2e694 100644 --- a/Units/DelphiXMLDataBindingGenerator.pas +++ b/Units/DelphiXMLDataBindingGenerator.pas @@ -1158,7 +1158,10 @@ begin sourceCode.Add(PropertyIntfMethodGetText); if writeStream then + begin sourceCode.Add(PropertyIntfMethodStream); + sourceCode.Add(PropertyIntfMethodFile); + end; sourceCode.Add(PropertyIntfMethodGet); end; @@ -1231,7 +1234,10 @@ begin sourceCode.Add(PropertyImplMethodGetText[GetDelphiElementType(AProperty)]); if writeStream then + begin sourceCode.Add(PropertyImplMethodStream[GetDelphiElementType(AProperty)]); + sourceCode.Add(PropertyImplMethodFile[GetDelphiElementType(AProperty)]); + end; sourceCode.Add('function TXML%:s.Get%:s: %:s;'); diff --git a/Units/DelphiXMLDataBindingResources.pas b/Units/DelphiXMLDataBindingResources.pas index 2d6cb6e..f8716a3 100644 --- a/Units/DelphiXMLDataBindingResources.pas +++ b/Units/DelphiXMLDataBindingResources.pas @@ -106,6 +106,7 @@ const PropertyIntfMethodSetText = ' procedure Set%:sText(const Value: WideString);'; PropertyIntfMethodSet = ' procedure Set%:s(const Value: %:s);'; PropertyIntfMethodStream = ' procedure Save%:sToStream(AStream: TStream);'; + PropertyIntfMethodFile = ' procedure Save%:sToFile(const AFileName: string);'; PropertyInterfaceOptional = ' property Has%:s: Boolean read GetHas%:s;'; PropertyInterfaceNilReadOnly = ' property %:sIsNil: Boolean read Get%:sIsNil;'; @@ -235,6 +236,22 @@ const '' + CrLf ); + PropertyImplMethodFile: array[TDelphiElementType] of string = + ( + { dntElement } + 'procedure TXML%:s.Save%:sToFile(const AFileName: string);' + CrLf + + 'begin' + CrLf + + ' Base64DecodeToFile(Trim(ChildNodes[''%:s''].Text), AFileName);' + CrLf + + 'end;' + CrLf + + '' + CrLf, + + { dntElementNS } + 'procedure TXML%:s.Save%:sToFile(const AFileName: string);' + CrLf + + 'begin' + CrLf + + ' Base64DecodeToFile(Trim(ChildNodes.FindNode(''%:s'', ''%:s'').Text), AFileName);' + CrLf + + 'end;' + CrLf + + '' + CrLf + ); SectionComments: array[TDelphiXMLSection] of String = ( diff --git a/X2XMLDataBinding.dproj b/X2XMLDataBinding.dproj index 9da07c0..a4dc717 100644 --- a/X2XMLDataBinding.dproj +++ b/X2XMLDataBinding.dproj @@ -24,7 +24,7 @@ Delphi.Personality -FalseTrueFalseP:\hyundai\DealerAccessoryMsg_v0101.xsdFalseFalse1000FalseFalseFalseFalseFalse104312521.0.0.01.0.0.0X2XMLDataBinding.dpr +FalseTrueFalse"P:\updateserver\xsd\DealerCarTrimMsg_v0101.xsd"FalseFalse1000FalseFalseFalseFalseFalse104312521.0.0.01.0.0.0X2XMLDataBinding.dpr