Changeset 28 for trunk/UAcronym.pas
- Timestamp:
- Jul 12, 2016, 4:28:22 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UAcronym.pas
r27 r28 7 7 uses 8 8 Classes, SysUtils, Contnrs, XMLConf, XMLRead, XMLWrite, DOM, UXMLUtils, 9 SpecializedList, fphttpclient ;9 SpecializedList, fphttpclient, Dialogs; 10 10 11 11 type … … 119 119 Variable: TImportVariable; 120 120 Flag: TImportPatternFlag; 121 Repetition: Boolean; 121 122 procedure Assign(Source: TImportPattern); 122 123 procedure SaveToNode(Node: TDOMNode); … … 167 168 LastTime: TDateTime; 168 169 Sources: TImportSources; 170 ItemCount: Integer; 169 171 function DownloadHTTP(URL: string; Stream: TStream): Boolean; 170 172 procedure Process; … … 265 267 Variable := Source.Variable; 266 268 Flag := Source.Flag; 269 Repetition := Source.Repetition; 267 270 end; 268 271 … … 273 276 WriteInteger(Node, 'Variable', Integer(Variable)); 274 277 WriteInteger(Node, 'Flag', Integer(Flag)); 278 WriteBoolean(Node, 'Repetition', Repetition); 275 279 end; 276 280 … … 281 285 Variable := TImportVariable(ReadInteger(Node, 'Variable', 0)); 282 286 Flag := TImportPatternFlag(ReadInteger(Node, 'Flag', 0)); 287 Repetition := ReadBoolean(Node, 'Repetition', False); 283 288 end; 284 289 … … 295 300 var 296 301 HTTPClient: TFPHTTPClient; 302 FormData: TStringList; 297 303 begin 298 304 HTTPClient := TFPHttpClient.Create(nil); 299 305 HTTPClient.OnPassword := DoPassword; 306 FormData := TStringList.Create; 307 (* 308 FormData.action=clientlogin 309 &loginreturnurl=http://example.com/& 310 logintoken=29590a3037d325be70b93fb8258ed29257448cfb%2B%5C& 311 username=Bob& 312 password=secret& 313 rememberMe=1 314 HTTPClient.FormPost(URL, FormData, Stream); 315 *) 300 316 HTTPClient.Get(URL, Stream); 317 FormData.Free; 301 318 HTTPClient.Free; 302 319 Result := True; … … 502 519 NewAcronym: TAcronymEntry; 503 520 P: Integer; 521 P1, P2: Integer; 504 522 Q: Integer; 505 523 I: Integer; … … 507 525 LastLength: Integer; 508 526 begin 527 ItemCount := 0; 509 528 Stream := TMemoryStream.Create; 510 529 NewAcronym := TAcronymEntry.Create; … … 547 566 repeat 548 567 LastLength := Length(S); 549 for I := 0 to Format.ItemPatterns.Count - 1 do 550 with TImportPattern(Format.ItemPatterns[I]) do 551 if Flag <> ipfSkip then begin 552 if Length(StartString) > 0 then begin 553 P := Pos(StartString, S); 554 if P > 0 then Delete(S, 1, P + Length(StartString) - 1); 568 I := 0; 569 while I < Format.ItemPatterns.Count do 570 with TImportPattern(Format.ItemPatterns[I]) do begin 571 if Flag <> ipfSkip then begin 572 if Length(StartString) > 0 then begin 573 P := Pos(StartString, S); 574 if P > 0 then Delete(S, 1, P + Length(StartString) - 1); 575 end; 576 577 if ((Length(StartString) > 0) and (P > 0)) or (Length(StartString) = 0) then begin 578 P := Pos(EndString, S); 579 T := StripHTML(Copy(S, 1, P - 1)); 580 T := StringReplace(T, '"', '"', [rfReplaceAll]); 581 T := StringReplace(T, '™', 'TM', [rfReplaceAll]); 582 T := StringReplace(T, '&', '&', [rfReplaceAll]); 583 T := StringReplace(T, ' ', ' ', [rfReplaceAll]); // No break space 584 T := Trim(T); 585 case Variable of 586 ivAcronym: NewAcronym.Name := T; 587 ivMeaning: NewAcronym.Meaning := T; 588 end; 589 Delete(S, 1, P + Length(EndString) - 1); 590 591 if (Flag = ipfNewItem) and (Trim(NewAcronym.Name) <> '') and 592 (Trim(NewAcronym.Meaning) <> '') then begin 593 Sources.AcronymDb.AddAcronym(NewAcronym.Name, NewAcronym.Meaning); 594 Inc(ItemCount); 595 end; 596 597 if Repetition then begin 598 if Length(StartString) > 0 then begin 599 P1 := Pos(StartString, S); 600 if P1 > 0 then begin 601 P2 := Pos(TImportPattern(Format.ItemPatterns[(I + 1) mod Format.ItemPatterns.Count]).StartString, S); 602 if (P2 > 0) and (P1 < P2) then Continue; 603 end; 604 end; 605 end; 606 end; 555 607 end; 556 557 if ((Length(StartString) > 0) and (P > 0)) or (Length(StartString) = 0) then begin 558 P := Pos(EndString, S); 559 T := StripHTML(Copy(S, 1, P - 1)); 560 T := StringReplace(T, '"', '"', [rfReplaceAll]); 561 T := StringReplace(T, '™', 'TM', [rfReplaceAll]); 562 T := StringReplace(T, '&', '&', [rfReplaceAll]); 563 T := Trim(T); 564 case Variable of 565 ivAcronym: NewAcronym.Name := T; 566 ivMeaning: NewAcronym.Meaning := T; 567 end; 568 Delete(S, 1, P + Length(EndString) - 1); 569 570 if (Flag = ipfNewItem) and (Trim(NewAcronym.Name) <> '') and 571 (Trim(NewAcronym.Meaning) <> '') then 572 Sources.AcronymDb.AddAcronym(NewAcronym.Name, NewAcronym.Meaning); 573 end; 608 Inc(I); 574 609 end; 575 610 until Length(S) = LastLength;
Note:
See TracChangeset
for help on using the changeset viewer.