1 | unit UHtmlClasses;
|
---|
2 |
|
---|
3 | {$mode delphi}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | UXmlClasses, Classes, SysUtils, SpecializedList;
|
---|
9 |
|
---|
10 | type
|
---|
11 |
|
---|
12 | { TDomainAddress }
|
---|
13 |
|
---|
14 | TDomainAddress = class(TPersistent)
|
---|
15 | private
|
---|
16 | function GetAsString: string;
|
---|
17 | procedure SetAsString(const Value: string);
|
---|
18 | public
|
---|
19 | Levels: TListString;
|
---|
20 | constructor Create;
|
---|
21 | destructor Destroy; override;
|
---|
22 | property AsString: string read GetAsString write SetAsString;
|
---|
23 | end;
|
---|
24 |
|
---|
25 | TAddrClass = (acA, acB, acC, acD, acE);
|
---|
26 |
|
---|
27 | { TIpAddress }
|
---|
28 |
|
---|
29 | TIpAddress = class(TPersistent)
|
---|
30 | private
|
---|
31 | function GetAddrClass: TAddrClass;
|
---|
32 | function GetAsCardinal: Cardinal;
|
---|
33 | function GetAsString: string;
|
---|
34 | function GetBroadcast: Boolean;
|
---|
35 | procedure SetBroadcast(const Value: Boolean);
|
---|
36 | procedure SetAsCardinal(const Value: Cardinal);
|
---|
37 | procedure SetAsString(const Value: string);
|
---|
38 | public
|
---|
39 | Octets: array[0..3] of Byte;
|
---|
40 | procedure Assign(Source: TPersistent); override;
|
---|
41 | function IsAddressString(Value: string): Boolean;
|
---|
42 | property AsCardinal: Cardinal read GetAsCardinal write SetAsCardinal;
|
---|
43 | property AsString: string read GetAsString write SetAsString;
|
---|
44 | property AddrClass: TAddrClass read GetAddrClass;
|
---|
45 | property Broadcast: Boolean read GetBroadcast write SetBroadcast;
|
---|
46 | end;
|
---|
47 |
|
---|
48 | THostAddressState = (asDomainName, asIpAddress);
|
---|
49 | THostAddress = class(TPersistent)
|
---|
50 | private
|
---|
51 | function GetAsString: string;
|
---|
52 | procedure SetAsString(const Value: string);
|
---|
53 | public
|
---|
54 | State: THostAddressState;
|
---|
55 | DomainName: TDomainAddress;
|
---|
56 | IpAddress: TIpAddress;
|
---|
57 | constructor Create;
|
---|
58 | destructor Destroy; override;
|
---|
59 | property AsString: string read GetAsString write SetAsString;
|
---|
60 | end;
|
---|
61 |
|
---|
62 | TURL = class(TPersistent)
|
---|
63 | private
|
---|
64 | function GetAsString: string;
|
---|
65 | procedure SetAsString(Value: string);
|
---|
66 | public
|
---|
67 | Scheme: string;
|
---|
68 | UserName: string;
|
---|
69 | Password: string;
|
---|
70 | Host: THostAddress;
|
---|
71 | Port: Word;
|
---|
72 | Path: string;
|
---|
73 | Query: string;
|
---|
74 | Fragment: string;
|
---|
75 | constructor Create;
|
---|
76 | destructor Destroy; override;
|
---|
77 | property AsString: string read GetAsString write SetAsString;
|
---|
78 | end;
|
---|
79 |
|
---|
80 | { THtmlElement }
|
---|
81 |
|
---|
82 | THtmlElement = class
|
---|
83 | protected
|
---|
84 | function GetAsXmlElement: TXmlElement; virtual;
|
---|
85 | public
|
---|
86 | Id: string;
|
---|
87 | Name: string;
|
---|
88 | ClassId: string;
|
---|
89 | Style: string;
|
---|
90 | procedure Assign(Source: THtmlElement); virtual;
|
---|
91 | property AsXmlElement: TXmlElement read GetAsXmlElement;
|
---|
92 | end;
|
---|
93 |
|
---|
94 | TBlockType = (btNoTag, btBlockLevel, btInline);
|
---|
95 |
|
---|
96 | { THtmlString }
|
---|
97 |
|
---|
98 | THtmlString = class(THtmlElement)
|
---|
99 | private
|
---|
100 | function GetAsXmlElement: TXmlElement; override;
|
---|
101 | public
|
---|
102 | Text: string;
|
---|
103 | procedure Assign(Source: THtmlElement); override;
|
---|
104 | end;
|
---|
105 |
|
---|
106 | { THtmlLineBreak }
|
---|
107 |
|
---|
108 | THtmlLineBreak = class(THtmlElement)
|
---|
109 | private
|
---|
110 | function GetAsXmlElement: TXmlElement; override;
|
---|
111 | public
|
---|
112 | constructor Create;
|
---|
113 | end;
|
---|
114 |
|
---|
115 | THtmlBlock = class(THtmlElement)
|
---|
116 | protected
|
---|
117 | function GetAsXmlElement: TXmlElement; override;
|
---|
118 | public
|
---|
119 | BlockType: TBlockType;
|
---|
120 | SubItems: TListObject; // TListObject<THtmlElement>;
|
---|
121 | constructor Create;
|
---|
122 | destructor Destroy; override;
|
---|
123 | end;
|
---|
124 |
|
---|
125 | THtmlLink = class(THtmlElement)
|
---|
126 | private
|
---|
127 | function GetAsXmlElement: TXmlElement; override;
|
---|
128 | public
|
---|
129 | Target: TURL;
|
---|
130 | Content: THtmlElement;
|
---|
131 | constructor Create;
|
---|
132 | destructor Destroy; override;
|
---|
133 | end;
|
---|
134 |
|
---|
135 | TSizeUnits = (suPixels, suPercents);
|
---|
136 |
|
---|
137 | THtmlSize = record
|
---|
138 | Width: Integer;
|
---|
139 | Height: Integer;
|
---|
140 | Units: TSizeUnits;
|
---|
141 | end;
|
---|
142 |
|
---|
143 | THtmlImage = class(THtmlElement)
|
---|
144 | private
|
---|
145 | function GetAsXmlElement: TXmlElement; override;
|
---|
146 | public
|
---|
147 | Size: THtmlSize;
|
---|
148 | Source: TURL;
|
---|
149 | AlternateText: string;
|
---|
150 | constructor Create;
|
---|
151 | destructor Destroy; override;
|
---|
152 | end;
|
---|
153 |
|
---|
154 | THtmlInputType = (itText, itComboBox, itRadioButton, itReset, itPassword,
|
---|
155 | itSubmit, itHidden, itFileSelect, itButton, itCheckBox);
|
---|
156 |
|
---|
157 | { THtmlInput }
|
---|
158 |
|
---|
159 | THtmlInput = class(THtmlElement)
|
---|
160 | private
|
---|
161 | function GetAsXmlElement: TXmlElement; override;
|
---|
162 | public
|
---|
163 | InputType: THtmlInputType;
|
---|
164 | Value: Variant;
|
---|
165 | ItemName: string;
|
---|
166 | procedure Assign(Source: THtmlElement); override;
|
---|
167 | constructor Create;
|
---|
168 | destructor Destroy; override;
|
---|
169 | end;
|
---|
170 |
|
---|
171 | { THtmlForm }
|
---|
172 |
|
---|
173 | THtmlForm = class(THtmlBlock)
|
---|
174 | protected
|
---|
175 | function GetAsXmlElement: TXmlElement; override;
|
---|
176 | public
|
---|
177 | Method: string;
|
---|
178 | Action: TURL;
|
---|
179 | constructor Create;
|
---|
180 | destructor Destroy; override;
|
---|
181 | end;
|
---|
182 |
|
---|
183 | THtmlDocument = class
|
---|
184 | private
|
---|
185 | function GetAsXmlDocument: TXmlDocument;
|
---|
186 | public
|
---|
187 | Title: string;
|
---|
188 | ContentEncoding: string;
|
---|
189 | ContentLanguage: string;
|
---|
190 | Body: THtmlBlock;
|
---|
191 | Styles: TStringList;
|
---|
192 | Scripts: TStringList;
|
---|
193 | property AsXmlDocument: TXmlDocument read GetAsXmlDocument;
|
---|
194 | constructor Create;
|
---|
195 | destructor Destroy; override;
|
---|
196 | end;
|
---|
197 |
|
---|
198 | { THtmlCell }
|
---|
199 |
|
---|
200 | THtmlCell = class(THtmlElement)
|
---|
201 | private
|
---|
202 | function GetAsXmlElement: TXmlElement; override;
|
---|
203 | public
|
---|
204 | RowSpan: Integer;
|
---|
205 | ColSpan: Integer;
|
---|
206 | Value: THtmlElement;
|
---|
207 | constructor Create;
|
---|
208 | destructor Destroy; override;
|
---|
209 | end;
|
---|
210 |
|
---|
211 | { THtmlRow }
|
---|
212 |
|
---|
213 | THtmlRow = class(THtmlElement)
|
---|
214 | private
|
---|
215 | function GetAsXmlElement: TXmlElement; override;
|
---|
216 | public
|
---|
217 | Cells: TListObject; // TListObject<THtmlCell>
|
---|
218 | constructor Create;
|
---|
219 | destructor Destroy; override;
|
---|
220 | end;
|
---|
221 |
|
---|
222 | { THtmlTable }
|
---|
223 |
|
---|
224 | THtmlTable = class(THtmlElement)
|
---|
225 | protected
|
---|
226 | function GetAsXmlElement: TXmlElement; override;
|
---|
227 | public
|
---|
228 | Rows: TListObject; // TListObject<THtmlRow>
|
---|
229 | constructor Create;
|
---|
230 | destructor Destroy; override;
|
---|
231 | end;
|
---|
232 |
|
---|
233 | { TQueryString }
|
---|
234 |
|
---|
235 | TQueryString = class
|
---|
236 | Data: TStringList;
|
---|
237 | procedure SetStringServer;
|
---|
238 | procedure SetString(QueryString: string);
|
---|
239 | function GetString: string;
|
---|
240 | constructor Create;
|
---|
241 | destructor Destroy; override;
|
---|
242 | end;
|
---|
243 |
|
---|
244 | implementation
|
---|
245 |
|
---|
246 | resourcestring
|
---|
247 | SStringToIPConversionError = 'String to IP address conversion error';
|
---|
248 |
|
---|
249 |
|
---|
250 | function LeftCutString(var Source, Output: string; Delimiter: string; Allowed: string = ''): Boolean;
|
---|
251 | var
|
---|
252 | I, J: Integer;
|
---|
253 | Matched: Boolean;
|
---|
254 | begin
|
---|
255 | I := 1;
|
---|
256 | Matched := True;
|
---|
257 | while (I < Length(Source)) and Matched do begin
|
---|
258 | Matched := False;
|
---|
259 | if (Source[I] >= 'A') and (Source[I] <= 'Z') then Matched := True;
|
---|
260 | if (Source[I] >= 'a') and (Source[I] <= 'z') then Matched := True;
|
---|
261 | if (Source[I] >= '0') and (Source[I] <= '9') then Matched := True;
|
---|
262 | for J := 1 to Length(Allowed) do
|
---|
263 | if Source[I] = Allowed[J] then Matched := True;
|
---|
264 | if Matched then Inc(I);
|
---|
265 | end;
|
---|
266 | if (Delimiter = Copy(Source, I, Length(Delimiter))) or (I = Length(Source)) then begin
|
---|
267 | Output := Copy(Source, 1, I-1);
|
---|
268 | Delete(Source, 1, Length(Output) + Length(Delimiter));
|
---|
269 | Result := True;
|
---|
270 | end else begin
|
---|
271 | Output := '';
|
---|
272 | Result := False;
|
---|
273 | end;
|
---|
274 | end;
|
---|
275 |
|
---|
276 | function RightCutString(var Source, Output: string; Delimiter: string; Allowed: string = ''): Boolean;
|
---|
277 | var
|
---|
278 | I, J: Integer;
|
---|
279 | Matched: Boolean;
|
---|
280 | begin
|
---|
281 | I := Length(Source);
|
---|
282 | Matched := True;
|
---|
283 | while (I > 0) and Matched do begin
|
---|
284 | Matched := False;
|
---|
285 | if (Source[I] >= 'A') and (Source[I] <= 'Z') then Matched := True;
|
---|
286 | if (Source[I] >= 'a') and (Source[I] <= 'z') then Matched := True;
|
---|
287 | if (Source[I] >= '0') and (Source[I] <= '9') then Matched := True;
|
---|
288 | for J := 1 to Length(Allowed) do
|
---|
289 | if Source[I] = Allowed[J] then Matched := True;
|
---|
290 | if Matched then Dec(I);
|
---|
291 | end;
|
---|
292 | if (Delimiter = Copy(Source, I - Length(Delimiter) + 1, Length(Delimiter))) or (I = 0) then begin
|
---|
293 | Output := Copy(Source, I+1, Length(Source) - I);
|
---|
294 | Delete(Source, I, Length(Output) + Length(Delimiter));
|
---|
295 | Result := True;
|
---|
296 | end else begin
|
---|
297 | Output := '';
|
---|
298 | Result := False;
|
---|
299 | end;
|
---|
300 | end;
|
---|
301 |
|
---|
302 | { THtmlCell }
|
---|
303 |
|
---|
304 | function THtmlCell.GetAsXmlElement: TXmlElement;
|
---|
305 | begin
|
---|
306 | Result := inherited GetAsXmlElement;
|
---|
307 | TXmlTag(Result).Name := 'td';
|
---|
308 | with TXmlTag(Result).Attributes do begin
|
---|
309 | if ColSpan > 1 then Add('colspan', IntToStr(ColSpan));
|
---|
310 | if RowSpan > 1 then Add('rowspan', IntToStr(RowSpan));
|
---|
311 | end;
|
---|
312 | TXmlTag(Result).SubElements.Add(Value.AsXmlElement);
|
---|
313 | end;
|
---|
314 |
|
---|
315 | constructor THtmlCell.Create;
|
---|
316 | begin
|
---|
317 | ColSpan := 1;
|
---|
318 | RowSpan := 1;
|
---|
319 | end;
|
---|
320 |
|
---|
321 | destructor THtmlCell.Destroy;
|
---|
322 | begin
|
---|
323 | Value.Free;
|
---|
324 | inherited Destroy;
|
---|
325 | end;
|
---|
326 |
|
---|
327 | { THtmlRow }
|
---|
328 |
|
---|
329 | function THtmlRow.GetAsXmlElement: TXmlElement;
|
---|
330 | var
|
---|
331 | Column: Integer;
|
---|
332 | begin
|
---|
333 | Result := inherited GetAsXmlElement;
|
---|
334 | TXmlTag(Result).Name := 'tr';
|
---|
335 | for Column := 0 to Cells.Count - 1 do
|
---|
336 | TXmlTag(Result).SubElements.AddNew(THtmlCell(Cells[Column]).AsXmlElement);
|
---|
337 | end;
|
---|
338 |
|
---|
339 | constructor THtmlRow.Create;
|
---|
340 | begin
|
---|
341 | Cells := TListObject.Create;
|
---|
342 | end;
|
---|
343 |
|
---|
344 | destructor THtmlRow.Destroy;
|
---|
345 | begin
|
---|
346 | Cells.Free;
|
---|
347 | inherited Destroy;
|
---|
348 | end;
|
---|
349 |
|
---|
350 | { THtmlTable }
|
---|
351 |
|
---|
352 | function THtmlTable.GetAsXmlElement: TXmlElement;
|
---|
353 | var
|
---|
354 | Row, Column: Integer;
|
---|
355 | begin
|
---|
356 | Result := inherited;
|
---|
357 | with TXmlTag(Result) do begin
|
---|
358 | Name := 'table';
|
---|
359 | for Row := 0 to Rows.Count - 1 do
|
---|
360 | SubElements.AddNew(THtmlRow(Rows[Row]).AsXmlElement);
|
---|
361 | end;
|
---|
362 | end;
|
---|
363 |
|
---|
364 | constructor THtmlTable.Create;
|
---|
365 | begin
|
---|
366 | Rows := TListObject.Create;
|
---|
367 | end;
|
---|
368 |
|
---|
369 | destructor THtmlTable.Destroy;
|
---|
370 | begin
|
---|
371 | Rows.Free;
|
---|
372 | inherited Destroy;
|
---|
373 | end;
|
---|
374 |
|
---|
375 | { THtmlLineBreak }
|
---|
376 |
|
---|
377 | function THtmlLineBreak.GetAsXmlElement: TXmlElement;
|
---|
378 | begin
|
---|
379 | Result := inherited GetAsXmlElement;
|
---|
380 | TXmlTag(Result).Name := 'br';
|
---|
381 | end;
|
---|
382 |
|
---|
383 | constructor THtmlLineBreak.Create;
|
---|
384 | begin
|
---|
385 | end;
|
---|
386 |
|
---|
387 | { THtmlInput }
|
---|
388 |
|
---|
389 | function THtmlInput.GetAsXmlElement: TXmlElement;
|
---|
390 | var
|
---|
391 | InputTypeString: string;
|
---|
392 | begin
|
---|
393 | Result := TXmlTag.Create;
|
---|
394 | with TXmlTag(Result) do begin
|
---|
395 | Name := 'input';
|
---|
396 | case InputType of
|
---|
397 | itButton: InputTypeString := 'button';
|
---|
398 | itRadioButton: InputTypeString := 'radio';
|
---|
399 | itCheckBox: InputTypeString := 'checkbox';
|
---|
400 | itText: InputTypeString := 'text';
|
---|
401 | itFileSelect: InputTypeString := 'file';
|
---|
402 | itSubmit: InputTypeString := 'submit';
|
---|
403 | itHidden: InputTypeString := 'hidden';
|
---|
404 | itPassword: InputTypeString := 'password';
|
---|
405 | end;
|
---|
406 | Attributes.Add('type', InputTypeString);
|
---|
407 | Attributes.Add('value', Value);
|
---|
408 | if Self.ItemName <> '' then
|
---|
409 | Attributes.Add('name', Self.ItemName);
|
---|
410 | end;
|
---|
411 | end;
|
---|
412 |
|
---|
413 | procedure THtmlInput.Assign(Source: THtmlElement);
|
---|
414 | begin
|
---|
415 | inherited Assign(Source);
|
---|
416 | InputType := THtmlInput(Source).InputType;
|
---|
417 | Value := THtmlInput(Source).Value;
|
---|
418 | ItemName := THtmlInput(Source).ItemName;
|
---|
419 | end;
|
---|
420 |
|
---|
421 | constructor THtmlInput.Create;
|
---|
422 | begin
|
---|
423 |
|
---|
424 | end;
|
---|
425 |
|
---|
426 | destructor THtmlInput.Destroy;
|
---|
427 | begin
|
---|
428 | inherited Destroy;
|
---|
429 | end;
|
---|
430 |
|
---|
431 | { THtmlForm }
|
---|
432 |
|
---|
433 | function THtmlForm.GetAsXmlElement: TXmlElement;
|
---|
434 | begin
|
---|
435 | Result := TXmlTag.Create;
|
---|
436 | with TXmlTag(Result) do begin
|
---|
437 | Name := 'form';
|
---|
438 | Attributes.Add('action', Action.AsString);
|
---|
439 | Attributes.Add('method', Method);
|
---|
440 | end;
|
---|
441 | end;
|
---|
442 |
|
---|
443 | constructor THtmlForm.Create;
|
---|
444 | begin
|
---|
445 | inherited;
|
---|
446 | Action := TURL.Create;
|
---|
447 | BlockType := btBlockLevel;
|
---|
448 | Method := 'get';
|
---|
449 | end;
|
---|
450 |
|
---|
451 | destructor THtmlForm.Destroy;
|
---|
452 | begin
|
---|
453 | Action.Free;
|
---|
454 | inherited Destroy;
|
---|
455 | end;
|
---|
456 |
|
---|
457 | { THtmlDocument }
|
---|
458 |
|
---|
459 | constructor THtmlDocument.Create;
|
---|
460 | begin
|
---|
461 | Body := THtmlBlock.Create;
|
---|
462 | Styles := TStringList.Create;
|
---|
463 | Scripts := TStringList.Create;
|
---|
464 | ContentLanguage := 'en';
|
---|
465 | ContentEncoding := 'utf-8';
|
---|
466 | end;
|
---|
467 |
|
---|
468 | destructor THtmlDocument.Destroy;
|
---|
469 | begin
|
---|
470 | Body.Free;
|
---|
471 | Styles.Free;
|
---|
472 | Scripts.Free;
|
---|
473 | inherited;
|
---|
474 | end;
|
---|
475 |
|
---|
476 | function THtmlDocument.GetAsXmlDocument: TXmlDocument;
|
---|
477 | var
|
---|
478 | DocType: TXMLTag;
|
---|
479 | HTMLTag: TXMLTag;
|
---|
480 | I: Integer;
|
---|
481 | begin
|
---|
482 | Result := TXmlDocument.Create;
|
---|
483 | with Result, Content do begin
|
---|
484 | DocType := TXMlTag.Create;
|
---|
485 | DocType.Name := '!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"';
|
---|
486 | Doctype.EndTagSymbol := '';
|
---|
487 | SubElements.Add(DocType);
|
---|
488 | HTMLTag := TXMLTag.Create;
|
---|
489 | with HTMLTag do begin
|
---|
490 | Name := 'html';
|
---|
491 | with TXmlTag(SubElements[SubElements.Add(TXmlTag.Create)]) do begin
|
---|
492 | Name := 'head';
|
---|
493 | with TXmlTag(SubElements[SubElements.Add(TXmlTag.Create)]) do begin
|
---|
494 | Name := 'title';
|
---|
495 | with TXmlString(SubElements[SubElements.Add(TXmlString.Create)]) do begin
|
---|
496 | Text := Title;
|
---|
497 | end;
|
---|
498 | end;
|
---|
499 | with TXmlTag(SubElements[SubElements.Add(TXmlTag.Create)]) do begin
|
---|
500 | Name := 'meta';
|
---|
501 | Attributes.Add('http-equiv', 'Content-Language');
|
---|
502 | Attributes.Add('content', ContentLanguage);
|
---|
503 | end;
|
---|
504 | with TXmlTag(SubElements[SubElements.Add(TXmlTag.Create)]) do begin
|
---|
505 | Name := 'meta';
|
---|
506 | Attributes.Add('http-equiv', 'Content-Type');
|
---|
507 | Attributes.Add('content', 'text/html; charset=' + ContentEncoding);
|
---|
508 | end;
|
---|
509 | for I := 0 to Styles.Count - 1 do
|
---|
510 | with TXmlTag(SubElements[SubElements.Add(TXmlTag.Create)]) do begin
|
---|
511 | Name := 'link';
|
---|
512 | Attributes.Add('rel', 'stylesheet');
|
---|
513 | Attributes.Add('href', Styles[I]);
|
---|
514 | Attributes.Add('type', 'text/css');
|
---|
515 | Attributes.Add('media', 'all');
|
---|
516 | end;
|
---|
517 | for I := 0 to Scripts.Count - 1 do
|
---|
518 | with TXmlTag(SubElements[SubElements.Add(TXmlTag.Create)]) do begin
|
---|
519 | Name := 'script';
|
---|
520 | ShringEmpty := False;
|
---|
521 | Attributes.Add('type', 'text/javascript');
|
---|
522 | Attributes.Add('src', Scripts[I]);
|
---|
523 | end;
|
---|
524 | end;
|
---|
525 | with TXmlTag(SubElements[SubElements.Add(TXmlTag.Create)]) do begin
|
---|
526 | Name := 'body';
|
---|
527 | SubElements.Add(Body.AsXmlElement);
|
---|
528 | end;
|
---|
529 | end;
|
---|
530 | SubElements.Add(HTMLTag);
|
---|
531 | end;
|
---|
532 | end;
|
---|
533 |
|
---|
534 | { THtmlBlock }
|
---|
535 |
|
---|
536 | constructor THtmlBlock.Create;
|
---|
537 | begin
|
---|
538 | inherited;
|
---|
539 | SubItems := TListObject.Create;
|
---|
540 | end;
|
---|
541 |
|
---|
542 | destructor THtmlBlock.Destroy;
|
---|
543 | begin
|
---|
544 | SubItems.Free;
|
---|
545 | inherited;
|
---|
546 | end;
|
---|
547 |
|
---|
548 | function THtmlBlock.GetAsXmlElement: TXmlElement;
|
---|
549 | var
|
---|
550 | I: Integer;
|
---|
551 | begin
|
---|
552 | Result := TXmlTag.Create;
|
---|
553 | with TXmlTag(Result) do begin
|
---|
554 | case BlockType of
|
---|
555 | btBlockLevel: Name := 'div';
|
---|
556 | btInline: Name := 'span';
|
---|
557 | btNoTag: Name := '';
|
---|
558 | end;
|
---|
559 | for I := 0 to SubItems.Count - 1 do
|
---|
560 | SubElements.Add(THtmlElement(SubItems[I]).AsXmlElement);
|
---|
561 | end;
|
---|
562 | end;
|
---|
563 |
|
---|
564 | { THtmlElement }
|
---|
565 |
|
---|
566 | function THtmlElement.GetAsXmlElement: TXmlElement;
|
---|
567 | begin
|
---|
568 | Result := TXmlTag.Create;
|
---|
569 | with TXmlTag(Result).Attributes do begin
|
---|
570 | if Name <> '' then Add('name', Name);
|
---|
571 | if Style <> '' then Add('style', Style);
|
---|
572 | if ClassId <> '' then Add('class', ClassId);
|
---|
573 | if Id <> '' then Add('id', Id);
|
---|
574 | end;
|
---|
575 | end;
|
---|
576 |
|
---|
577 | procedure THtmlElement.Assign(Source: THtmlElement);
|
---|
578 | begin
|
---|
579 | Id := Source.Id;
|
---|
580 | Name := Source.Name;
|
---|
581 | ClassId := Source.ClassId;
|
---|
582 | Style := Source.Style;
|
---|
583 | end;
|
---|
584 |
|
---|
585 | { TIpAddress }
|
---|
586 |
|
---|
587 | procedure TIpAddress.Assign(Source: TPersistent);
|
---|
588 | var
|
---|
589 | I: Integer;
|
---|
590 | begin
|
---|
591 | if Assigned(Source) then begin
|
---|
592 | if Source is TIpAddress then begin
|
---|
593 | for I := 0 to High(Octets) do
|
---|
594 | Octets[I] := TIpAddress(Source).Octets[I];
|
---|
595 | end else inherited;
|
---|
596 | end else inherited;
|
---|
597 | end;
|
---|
598 |
|
---|
599 | function TIpAddress.IsAddressString(Value: string): Boolean;
|
---|
600 | var
|
---|
601 | Parts: TListString;
|
---|
602 | begin
|
---|
603 | Result := True;
|
---|
604 | try
|
---|
605 | Parts := TListString.Create;
|
---|
606 | Parts.Explode(Value, '.', StrToStr);
|
---|
607 | if Parts.Count = 4 then begin
|
---|
608 | if (StrToInt(Parts[3]) < 0) or (StrToInt(Parts[3]) > 255) then Result := False;
|
---|
609 | if (StrToInt(Parts[2]) < 0) or (StrToInt(Parts[2]) > 255) then Result := False;
|
---|
610 | if (StrToInt(Parts[1]) < 0) or (StrToInt(Parts[1]) > 255) then Result := False;
|
---|
611 | if (StrToInt(Parts[0]) < 0) or (StrToInt(Parts[0]) > 255) then Result := False;
|
---|
612 | end else Result := False;
|
---|
613 | finally
|
---|
614 | Parts.Free;
|
---|
615 | end;
|
---|
616 | end;
|
---|
617 |
|
---|
618 | function TIpAddress.GetAddrClass: TAddrClass;
|
---|
619 | begin
|
---|
620 | if (Octets[3] and $80) = 0 then Result := acA
|
---|
621 | else begin
|
---|
622 | if (Octets[3] and $40) = 0 then Result := acB
|
---|
623 | else begin
|
---|
624 | if (Octets[3] and $20) = 0 then Result := acC
|
---|
625 | else begin
|
---|
626 | if (Octets[3] and $10) = 0 then Result := acD
|
---|
627 | else Result := acE;
|
---|
628 | end;
|
---|
629 | end;
|
---|
630 | end;
|
---|
631 | end;
|
---|
632 |
|
---|
633 | function TIpAddress.GetAsCardinal: Cardinal;
|
---|
634 | begin
|
---|
635 | Result := Octets[0] or (Octets[1] shl 8) or (Octets[2] shl 16) or (Octets[3] shl 24);
|
---|
636 | end;
|
---|
637 |
|
---|
638 | function TIpAddress.GetAsString: string;
|
---|
639 | begin
|
---|
640 | Result := IntToStr(Octets[3]) + '.' + IntToStr(Octets[2]) + '.' +
|
---|
641 | IntToStr(Octets[1]) + '.' + IntToStr(Octets[0]);
|
---|
642 | end;
|
---|
643 |
|
---|
644 | function TIpAddress.GetBroadcast: Boolean;
|
---|
645 | begin
|
---|
646 | Result := AsCardinal = High(Cardinal);
|
---|
647 | end;
|
---|
648 |
|
---|
649 | procedure TIpAddress.SetAsCardinal(const Value: Cardinal);
|
---|
650 | begin
|
---|
651 | Octets[0] := Byte(Value);
|
---|
652 | Octets[1] := Byte(Value shr 8);
|
---|
653 | Octets[2] := Byte(Value shr 16);
|
---|
654 | Octets[3] := Byte(Value shr 24);
|
---|
655 | end;
|
---|
656 |
|
---|
657 | procedure TIpAddress.SetAsString(const Value: string);
|
---|
658 | var
|
---|
659 | Parts: TListString;
|
---|
660 | begin
|
---|
661 | try
|
---|
662 | Parts := TListString.Create;
|
---|
663 | Parts.Explode(Value, '.', StrToStr);
|
---|
664 | try
|
---|
665 | // if Length(Parts) = 4 then begin
|
---|
666 | Octets[0] := StrToInt(Parts[3]);
|
---|
667 | Octets[1] := StrToInt(Parts[2]);
|
---|
668 | Octets[2] := StrToInt(Parts[1]);
|
---|
669 | Octets[3] := StrToInt(Parts[0]);
|
---|
670 | // end else raise EConvertError.Create('String to IP address conversion error');
|
---|
671 | except
|
---|
672 | raise EConvertError.Create(SStringToIPConversionError);
|
---|
673 | end;
|
---|
674 | finally
|
---|
675 | Parts.Free;
|
---|
676 | end;
|
---|
677 | end;
|
---|
678 |
|
---|
679 | procedure TIpAddress.SetBroadcast(const Value: Boolean);
|
---|
680 | begin
|
---|
681 | AsCardinal := High(Cardinal);
|
---|
682 | end;
|
---|
683 |
|
---|
684 | constructor TURL.Create;
|
---|
685 | begin
|
---|
686 | Host := THostAddress.Create;
|
---|
687 | end;
|
---|
688 |
|
---|
689 | destructor TURL.Destroy;
|
---|
690 | begin
|
---|
691 | Host.Free;
|
---|
692 | inherited;
|
---|
693 | end;
|
---|
694 |
|
---|
695 | function TURL.GetAsString: string;
|
---|
696 | begin
|
---|
697 | Result := '';
|
---|
698 | if Scheme <> '' then Result := Scheme + '://';
|
---|
699 | if UserName <> '' then begin
|
---|
700 | Result := Result + UserName;
|
---|
701 | if UserName <> '' then Result := Result + ':' + Password;
|
---|
702 | Result := Result + '@';
|
---|
703 | end;
|
---|
704 | if Host.AsString <> '' then Result := Result + Host.AsString;
|
---|
705 | if Port <> 0 then Result := Result + ':' + IntToStr(Port);
|
---|
706 | if Path <> '' then Result := Result + Path;
|
---|
707 | if Query <> '' then Result := Result + '?' + Query;
|
---|
708 | if Fragment <> '' then Result := Result + '#' + Fragment;
|
---|
709 | end;
|
---|
710 |
|
---|
711 | procedure TURL.SetAsString(Value: string);
|
---|
712 | var
|
---|
713 | HostAddr: string;
|
---|
714 | HostPort: string;
|
---|
715 | begin
|
---|
716 | LeftCutString(Value, Scheme, '://');
|
---|
717 | if LeftCutString(Value, UserName, ':') then LeftCutString(Value, Password, '@')
|
---|
718 | else LeftCutString(Value, UserName, '@');
|
---|
719 | RightCutString(Value, Fragment, '#');
|
---|
720 | RightCutString(Value, Query, '?', '=&');
|
---|
721 | if LeftCutString(Value, HostAddr, ':', '.') then begin
|
---|
722 | LeftCutString(Value, HostPort, '');
|
---|
723 | Port := StrToInt(HostPort);
|
---|
724 | end else LeftCutString(Value, HostAddr, '', '.');
|
---|
725 | Host.AsString := HostAddr;
|
---|
726 | LeftCutString(Value, Path, '', '/.');
|
---|
727 | end;
|
---|
728 |
|
---|
729 |
|
---|
730 | { TDomainAddress }
|
---|
731 |
|
---|
732 | function TDomainAddress.GetAsString: string;
|
---|
733 | begin
|
---|
734 | try
|
---|
735 | Levels.Reverse;
|
---|
736 | Result := Levels.Implode('.', StrToStr);
|
---|
737 | finally
|
---|
738 | Levels.Reverse;
|
---|
739 | end;
|
---|
740 | end;
|
---|
741 |
|
---|
742 | procedure TDomainAddress.SetAsString(const Value: string);
|
---|
743 | begin
|
---|
744 | Levels.Explode(Value, '.', StrToStr);
|
---|
745 | Levels.Reverse;
|
---|
746 | end;
|
---|
747 |
|
---|
748 | constructor TDomainAddress.Create;
|
---|
749 | begin
|
---|
750 | Levels := TListString.Create;
|
---|
751 | end;
|
---|
752 |
|
---|
753 | destructor TDomainAddress.Destroy;
|
---|
754 | begin
|
---|
755 | Levels.Free;
|
---|
756 | inherited Destroy;
|
---|
757 | end;
|
---|
758 |
|
---|
759 | { THtmlLink }
|
---|
760 |
|
---|
761 | constructor THtmlLink.Create;
|
---|
762 | begin
|
---|
763 | Target := TURL.Create;
|
---|
764 | end;
|
---|
765 |
|
---|
766 | destructor THtmlLink.Destroy;
|
---|
767 | begin
|
---|
768 | Target.Free;
|
---|
769 | inherited;
|
---|
770 | end;
|
---|
771 |
|
---|
772 | function THtmlLink.GetAsXmlElement: TXmlElement;
|
---|
773 | begin
|
---|
774 | Result := TXmlTag.Create;
|
---|
775 | with TXmlTag(Result) do begin
|
---|
776 | Name := 'a';
|
---|
777 | Attributes.Add('href', Target.AsString);
|
---|
778 | if Assigned(Content) then SubElements.Add(Content.AsXmlElement);
|
---|
779 | end;
|
---|
780 | end;
|
---|
781 |
|
---|
782 | { THtmlString }
|
---|
783 |
|
---|
784 | function THtmlString.GetAsXmlElement: TXmlElement;
|
---|
785 | begin
|
---|
786 | Result := TXmlString.Create;
|
---|
787 | TXmlString(Result).Text := Text;
|
---|
788 | end;
|
---|
789 |
|
---|
790 | procedure THtmlString.Assign(Source: THtmlElement);
|
---|
791 | begin
|
---|
792 | inherited Assign(Source);
|
---|
793 | Text := THtmlString(Source).Text;
|
---|
794 | end;
|
---|
795 |
|
---|
796 | { THostAddress }
|
---|
797 |
|
---|
798 | constructor THostAddress.Create;
|
---|
799 | begin
|
---|
800 | DomainName := TDomainAddress.Create;
|
---|
801 | IpAddress := TIpAddress.Create;
|
---|
802 | State := asDomainName;
|
---|
803 | DomainName.AsString := 'localhost';
|
---|
804 | end;
|
---|
805 |
|
---|
806 | destructor THostAddress.Destroy;
|
---|
807 | begin
|
---|
808 | DomainName.Free;
|
---|
809 | IpAddress.Free;
|
---|
810 | inherited;
|
---|
811 | end;
|
---|
812 |
|
---|
813 | function THostAddress.GetAsString: string;
|
---|
814 | begin
|
---|
815 | case State of
|
---|
816 | asDomainName: Result := DomainName.AsString;
|
---|
817 | asIpAddress: Result := IpAddress.AsString;
|
---|
818 | end;
|
---|
819 | end;
|
---|
820 |
|
---|
821 | procedure THostAddress.SetAsString(const Value: string);
|
---|
822 | begin
|
---|
823 | if IpAddress.IsAddressString(Value) then begin
|
---|
824 | State := asIpAddress;
|
---|
825 | IpAddress.AsString := Value;
|
---|
826 | end else begin
|
---|
827 | State := asDomainName;
|
---|
828 | DomainName.AsString := Value;
|
---|
829 | end;
|
---|
830 | end;
|
---|
831 |
|
---|
832 | { THtmlImage }
|
---|
833 |
|
---|
834 | constructor THtmlImage.Create;
|
---|
835 | begin
|
---|
836 | Source := TURL.Create;
|
---|
837 | end;
|
---|
838 |
|
---|
839 | destructor THtmlImage.Destroy;
|
---|
840 | begin
|
---|
841 | Source.Free;
|
---|
842 | inherited;
|
---|
843 | end;
|
---|
844 |
|
---|
845 | function THtmlImage.GetAsXmlElement: TXmlElement;
|
---|
846 | begin
|
---|
847 | Result := TXmlTag.Create;
|
---|
848 | with TXmlTag(Result) do begin
|
---|
849 | Name := 'img';
|
---|
850 | Attributes.Add('src', Source.AsString);
|
---|
851 | Attributes.Add('width', IntToStr(Size.Width));
|
---|
852 | Attributes.Add('height', IntToStr(Size.Height));
|
---|
853 | Attributes.Add('alt', AlternateText);
|
---|
854 | end;
|
---|
855 | end;
|
---|
856 |
|
---|
857 | procedure TQueryString.SetStringServer;
|
---|
858 | begin
|
---|
859 | //$this->SetString($_SERVER['QUERY_STRING']);
|
---|
860 | end;
|
---|
861 |
|
---|
862 | procedure TQueryString.SetString(QueryString: string);
|
---|
863 | begin
|
---|
864 | (*
|
---|
865 | $this->Data = array();
|
---|
866 | $Parts = explode('&', $QueryString);
|
---|
867 | foreach($Parts as $Part)
|
---|
868 | {
|
---|
869 | if($Part != '')
|
---|
870 | {
|
---|
871 | $Item = explode('=', $Part);
|
---|
872 | $this->Data[$Item[0]] = $Item[1];
|
---|
873 | end;
|
---|
874 | end;*)
|
---|
875 | end;
|
---|
876 |
|
---|
877 | function TQueryString.GetString: string;
|
---|
878 | begin
|
---|
879 | (*$Parts = array();
|
---|
880 | foreach($this->Data as $Index => $Item)
|
---|
881 | {
|
---|
882 | $Parts[] = $Index.'='.$Item;
|
---|
883 | }
|
---|
884 | return(implode('&', $Parts));*)
|
---|
885 | end;
|
---|
886 |
|
---|
887 | constructor TQueryString.Create;
|
---|
888 | begin
|
---|
889 | Data := TStringList.Create;
|
---|
890 | end;
|
---|
891 |
|
---|
892 | destructor TQueryString.Destroy;
|
---|
893 | begin
|
---|
894 | Data.Free;
|
---|
895 | inherited Destroy;
|
---|
896 | end;
|
---|
897 |
|
---|
898 | end.
|
---|