Repository navigation
Expand file tree
/
Copy pathSystem.Net.RSS.Feeds.pas
More file actions
177 lines (148 loc) · 5.39 KB
/
Copy pathSystem.Net.RSS.Feeds.pas
File metadata and controls
177 lines (148 loc) · 5.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
unit System.Net.RSS.Feeds;
interface
{$REGION 'Infos'}
// https://www.rssboard.org/rss-specification#requiredChannelElements
// https://www.rssboard.org/rss-draft-1
// https://docwiki.embarcadero.com/RADStudio/Athens/de/Benutzerdefinierte_verwaltete_Records
// https://de.wikipedia.org/wiki/RSS_(Web-Feed)
// https://blog.marcocantu.com/blog/2018-november-custom-managed-records-delphi.html
{$ENDREGION}
uses
System.Generics.Collections;
type
TFeedChannelImage = record
strict private
FURL: string;
FTitle: string;
FLink: string;
procedure SetTitle(const AValue: string);
procedure SetUrl(const AValue: string);
procedure SetLink(const AValue: string);
public
property Title: string read FTitle write SetTitle;
property URL: string read FURL write SetURL;
property Link: string read FLink write SetLink;
end;
TFeedChannelItem = record
strict private
FDescription: string;
FTitle: string;
FLink: string;
FAuthor: string;
FGuid: string;
FPubDate: TDateTime;
// DAuthor, FCategory, FComments, FEnclosure, FGuid, FPubDate, FSource ... more fields
FAdvancedFields: TArray<TPair<string, string>>;
private
function GetValueByName(const AKeyName: string): string;
public
property Description: string read FDescription write FDescription;
property Title: string read FTitle write FTitle;
property Link: string read FLink write FLink;
property Author: string read FAuthor write FAuthor;
property Guid: string read FGuid write FGuid;
property PubDate: TDateTime read FPubDate write FPubDate;
property AdvancedFields: TArray<TPair<string, string>> read FAdvancedFields;
property Values[const AName: string]: string read GetValueByName; default;
procedure AddAdvancedFields(const AKey: string; const AValue: string); overload;
procedure AddAdvancedFields(AValue: TPair<string, string>); overload;
end;
TFeedChannel = record
strict private
FDescription: string;
FLink: string;
FTitle: string;
FLanguage: string;
FCopyright: string;
FPubDate: string;
FImage: TFeedChannelImage;
FAdvancedFields: TArray<TPair<string, string>>;
FChannelItems: TArray<TFeedChannelItem>;
private
function GetValueByName(const AKeyName: string): string;
public
class operator Implicit(const AData: string): TFeedChannel;
procedure AddAdvancedFields(const AKey: string; const AValue: string); overload;
procedure AddAdvancedFields(AValue: TPair<string, string>); overload;
function CreateFeedChannelItem(): Integer;
property Description: string read FDescription write FDescription;
property Link: string read FLink write FLink;
property Title: string read FTitle write FTitle;
property Language: string read FLanguage write FLanguage;
property Copyright: string read FCopyright write FCopyright;
property PubDate: string read FPubDate write FPubDate;
property Image: TFeedChannelImage read FImage write FImage;
property AdvancedFields: TArray<TPair<string, string>> read FAdvancedFields;
property ChannelItems: TArray<TFeedChannelItem> read FChannelItems write FChannelItems;
property Values[const AName: string]: string read GetValueByName; default;
end;
implementation
uses
System.SysUtils;
{ TFeedChannelItem }
procedure TFeedChannelItem.AddAdvancedFields(const AKey, AValue: string);
begin
AddAdvancedFields(TPair<string, string>.Create(AKey, AValue));
end;
procedure TFeedChannelItem.AddAdvancedFields(AValue: TPair<string, string>);
begin
SetLength(FAdvancedFields, (Length(FAdvancedFields) + 1));
FAdvancedFields[High(FAdvancedFields)] := AValue;
end;
function TFeedChannelItem.GetValueByName(const AKeyName: string): string;
begin
Result := '';
for var Idx := Low(FAdvancedFields) to High(FAdvancedFields) do
begin
if (FAdvancedFields[Idx].Key.ToLower = AKeyName.ToLower) then
begin
Exit(FAdvancedFields[Idx].Value);
end;
end;
end;
{ TFeedChannel }
class operator TFeedChannel.Implicit(const AData: string): TFeedChannel;
begin
Result := Default(TFeedChannel); // Init my record...
Result.Title := AData;
Result.AddAdvancedFields('4711', 'Water');
end;
procedure TFeedChannel.AddAdvancedFields(const AKey, AValue: string);
begin
AddAdvancedFields(TPair<string, string>.Create(AKey, AValue));
end;
procedure TFeedChannel.AddAdvancedFields(AValue: TPair<string, string>);
begin
SetLength(FAdvancedFields, (Length(FAdvancedFields) + 1));
FAdvancedFields[High(FAdvancedFields)] := AValue;
end;
function TFeedChannel.CreateFeedChannelItem(): Integer;
begin
SetLength(FChannelItems, (Length(FChannelItems) + 1));
Result := High(FChannelItems);
end;
function TFeedChannel.GetValueByName(const AKEyName: string): string;
begin
Result := '';
for var Idx := Low(FAdvancedFields) to High(FAdvancedFields) do
begin
if (FAdvancedFields[Idx].Key.ToLower = AKeyName.ToLower) then
begin
Exit(FAdvancedFields[Idx].Value);
end;
end;
end;
{ TFeedChannelImage }
procedure TFeedChannelImage.SetLink(const AValue: string);
begin
FLink := AValue;
end;
procedure TFeedChannelImage.SetTitle(const AValue: string);
begin
FTitle := AValue;
end;
procedure TFeedChannelImage.SetUrl(const AValue: string);
begin
FUrl := AValue;
end;
end.