• R/O
  • SSH
  • HTTPS

mantisbtmonitor: Commit


Commit MetaInfo

Revision64 (tree)
Time2021-11-12 06:16:01
Authorderekwildstar

Log Message

Documentação atualizada
Funções de parsing e scraping ajustadas para usar as funções utilitárias
bugs de parsing corrigidos
otimizações de parsing aplicadas

Change Summary

Incremental Difference

--- trunk/client/prj/MantisBTMonitor.dproj (revision 63)
+++ trunk/client/prj/MantisBTMonitor.dproj (revision 64)
@@ -114,9 +114,8 @@
114114 <AppDPIAwarenessMode>PerMonitor</AppDPIAwarenessMode>
115115 <VerInfo_MinorVer>0</VerInfo_MinorVer>
116116 <VerInfo_Release>0</VerInfo_Release>
117- <VerInfo_Build>912</VerInfo_Build>
118117 <VerInfo_Locale>1033</VerInfo_Locale>
119- <VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.912;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=;ProgramID=com.embarcadero.$(MSBuildProjectName)</VerInfo_Keys>
118+ <VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.11;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=;ProgramID=com.embarcadero.$(MSBuildProjectName)</VerInfo_Keys>
120119 <Debugger_RunParams>/desenvolvimento</Debugger_RunParams>
121120 <VerInfo_AutoGenVersion>false</VerInfo_AutoGenVersion>
122121 <VerInfo_AutoIncVersion>true</VerInfo_AutoIncVersion>
@@ -123,6 +122,7 @@
123122 <DCC_DebugInformation>2</DCC_DebugInformation>
124123 <DCC_SymbolReferenceInfo>2</DCC_SymbolReferenceInfo>
125124 <DCC_DebugInfoInExe>true</DCC_DebugInfoInExe>
125+ <VerInfo_Build>11</VerInfo_Build>
126126 <DCC_MapFile>3</DCC_MapFile>
127127 </PropertyGroup>
128128 <ItemGroup>
--- trunk/client/src/lib/UScrapFunctions.pas (revision 63)
+++ trunk/client/src/lib/UScrapFunctions.pas (revision 64)
@@ -231,7 +231,8 @@
231231 uses
232232 WinApi.Windows, WinApi.WinInet, System.SysUtils, MSHTML,
233233 KRK.Rtl.Win.WinInet.Utilities, KRK.RegExp.Utils, UConfigurations,
234- Vcl.Graphics, System.Variants, Vcl.Forms, System.JSON;
234+ Vcl.Graphics, System.Variants, Vcl.Forms, System.JSON,
235+ KRK.Internet.MSHTML.Utilities;
235236
236237 function FixEncoding(AText: String): String; // era olevariant, caso de pau de acentuação
237238 var
@@ -747,8 +748,6 @@
747748
748749 if HasAttachments then
749750 begin
750- var HTMLDOMTextNode: IHTMLDOMTextNode;
751-
752751 // Extrai as informações de anexos contidos em todos os <div> existentes em
753752 // AUnparsedComment e exclui todos os <div>
754753 HTMLCollection := AUnparsedComment.Children as IHTMLElementCollection;
@@ -766,19 +765,17 @@
766765 // abaixo
767766 if Pos(WideString('open'),HTMLElement.id) > 0 then
768767 begin
769- // <a>, dentro do <div> da vez, que contém o nome do anexo
770- HTMLAnchorElement := ((HTMLElement.Children as IHTMLElementCollection4).item(1) as IHTMLAnchorElement);
771- // Nó de texto puro (texto entre elementos). O nó de texto só é
772- // acessível por meio da propriedade ChildNodes, sendo, neste caso o
773- // nó de índice = 2. Ao se usar Children, o elemento de índice 2 é o
774- // outro <a>.
775- HTMLDOMTextNode := (((HTMLElement as IHTMLDomNode).childNodes as IHTMLDOMChildrenCollection).item(2) as IHTMLDOMTextNode);
768+ // <a>, dentro do <div> da vez, que contém o nome do anexo. Eu não
769+ // precisaria ter usado HTMLAnchorElement aqui porque eu vou precisar
770+ // apenas de seu InnerText mais adiante. Um simples IHTMLElement seria
771+ // suficiente, mas usei ele pra não ter que criar uma variável a mais
772+ HTMLAnchorElement := NthChildElement(HTMLElement,1) as IHTMLAnchorElement;
776773
777774 SetLength(AComment.Attachments,Length(AComment.Attachments) + 1);
778775
779776 AComment.Attachments[High(AComment.Attachments)].Id := ParseAttachmentIdFromDivId(HTMLElement.id);
780777 AComment.Attachments[High(AComment.Attachments)].FileName := FixEncoding((HTMLAnchorElement as IHTMLElement).InnerText);
781- AComment.Attachments[High(AComment.Attachments)].FileSize := ExtractFileSize(HTMLDOMTextNode.toString);
778+ AComment.Attachments[High(AComment.Attachments)].FileSize := ExtractFileSize(HTMLElement.innerText);
782779 end;
783780
784781 (AUnparsedComment as IHTMLDOMNode).removeChild(HTMLCollection.Item(i,i) as IHTMLDOMNode);
@@ -862,7 +859,7 @@
862859 end;
863860
864861 // Salva em Text apenas o comentário!
865- AComment.Text := AUnparsedComment.innerHTML;
862+ AComment.Text := Trim(AUnparsedComment.innerHTML);
866863 // Obtém o tipo do comentário
867864 AComment.ComentType := GetCommentType(AUnparsedComment);
868865 end;
@@ -1080,19 +1077,19 @@
10801077 // detalhes do comentário
10811078 HTMLTableCell := (HTMLElement as IHTMLTableRow).cells.item(0,0) as IHTMLTableCell;
10821079 // HTMLTableCell.ChildNodes[1] é o <div> que contém todos os outros
1083- // elementos que contém os detalhes do comentário. Abaixo está a
1084- // forma de acessar este <div> usando lastChild. Para acessar como uma
1085- // coleção use a interface IHTMLDOMChildrenCollection
1080+ // elementos que contém os detalhes do comentário. Este trata-se do
1081+ // último <div> dentro de HTMLTableCell. Anteriormente eu utilizava
1082+ // lastChild de IHTMLDomNode, mas ao percorrer os nós por meio do DOM
1083+ // precisamos lidar com os nós de texto plano existentes entre os nós
1084+ // XML/HTML e isso não é muito prático. LastChildElement faz um ótimo
1085+ // trabalho sem precisar descer ao nível do DOM
1086+ CommentDetails := LastChildElement(HTMLTableCell as IHTMLElement,'div') as IHTMLDivElement;
10861087
1087- CommentDetails := (HTMLTableCell as IHTMLDOMNode).lastChild as IHTMLDivElement;
1088-// var HTMLDOMNode: IHTMLDOMNode := (HTMLTableCell as IHTMLDOMNode).lastChild;
1089-// CommentDetails := IHTMLDivElement(HTMLDOMNode);
1090-
10911088 Comment.Id := ParseCommentId(HTMLElement.Id);
1092- Comment.Creator := FixEncoding((((((CommentDetails as IHTMLDOMNode).childNodes as IHTMLDOMChildrenCollection).item(0) as IHTMLDOMNode).childNodes as IHTMLDOMChildrenCollection).item(1) as IHTMLElement).InnerText);
1093- Comment.CreatorId := ExtractUserId((((((CommentDetails as IHTMLDOMNode).childNodes as IHTMLDOMChildrenCollection).item(0) as IHTMLDOMNode).childNodes as IHTMLDOMChildrenCollection).item(1) as IHTMLAnchorElement).href);
1089+ Comment.Creator := NthChildElement(FirstChildElement(CommentDetails as IHTMLElement),1).InnerText;
1090+ Comment.CreatorId := ExtractUserId((NthChildElement(FirstChildElement(CommentDetails as IHTMLElement),1) as IHTMLAnchorElement).href);
10941091
1095- AuxString := (((CommentDetails as IHTMLDOMNode).childNodes as IHTMLDOMChildrenCollection).item(1) as IHTMLElement).InnerText;
1092+ AuxString := NthChildElement(CommentDetails as IHTMLElement,1).InnerText;
10961093
10971094 Comment.IsPrivate := Pos('privado',AuxString) > 0;
10981095
@@ -1101,7 +1098,7 @@
11011098
11021099 Comment.Created := ExtractDateTime(AuxString);
11031100
1104- Comment.LastUpdate := ExtractDateTime((((CommentDetails as IHTMLDOMNode).childNodes as IHTMLDOMChildrenCollection).item(3) as IHTMLElement).InnerText);
1101+ Comment.LastUpdate := ExtractDateTime(NthChildElement(CommentDetails as IHTMLElement,3).InnerText);
11051102 // Neste ponto, CommentDetails passa a ser o último <div> dentro do
11061103 // <div> mais externo que contém os detalhes do comentário apenas para
11071104 // economizar uma variável. Este <div> é aquele pode conter botões
@@ -1108,7 +1105,7 @@
11081105 // para manipulação do comentário. Este <div> vem vazio quando o
11091106 // usuário logado não possui qualquer permissão para modificar o
11101107 // comentário de alguma forma
1111- CommentDetails := (CommentDetails as IHTMLDOMNode).lastChild as IHTMLDivElement;
1108+ CommentDetails := LastChildElement(CommentDetails as IHTMLElement) as IHTMLDivElement;
11121109 // Obtendo as permissões do usuário atualmente logado para o
11131110 // comentário atual
11141111 FormsCollection := (CommentDetails as IHTMLElement2).getElementsByTagName('form');
@@ -1215,10 +1212,11 @@
12151212 SetLength(ATask.FHistory,Length(ATask.FHistory) + 1);
12161213
12171214 ATask.FHistory[High(ATask.FHistory)].Moment := ExtractDateTime(((HTMLElement as IHTMLTableRow).cells.item(0,0) as IHTMLElement).innerText);
1218- ATask.FHistory[High(ATask.FHistory)].User := FixEncoding(((HTMLElement as IHTMLTableRow).cells.item(1,1) as IHTMLElement).innerText);
1219- ATask.FHistory[High(ATask.FHistory)].UserId := ExtractUserId((((HTMLElement as IHTMLTableRow).cells.item(1,1) as IHTMLDOMNode).firstChild as IHTMLAnchorElement).href);
1220- ATask.FHistory[High(ATask.FHistory)].Action := FixEncoding(((HTMLElement as IHTMLTableRow).cells.item(2,2) as IHTMLElement).innerText);
1221- ATask.FHistory[High(ATask.FHistory)].Data := FixEncoding(((HTMLElement as IHTMLTableRow).cells.item(3,3) as IHTMLElement).innerText);
1215+ ATask.FHistory[High(ATask.FHistory)].User := ((HTMLElement as IHTMLTableRow).cells.item(1,1) as IHTMLElement).innerText;
1216+ //ATask.FHistory[High(ATask.FHistory)].UserId := ExtractUserId((((HTMLElement as IHTMLTableRow).cells.item(1,1) as IHTMLDOMNode).firstChild as IHTMLAnchorElement).href);
1217+ ATask.FHistory[High(ATask.FHistory)].UserId := ExtractUserId((FirstChildElement((HTMLElement as IHTMLTableRow).cells.item(1,1) as IHTMLElement) as IHTMLAnchorElement).href);
1218+ ATask.FHistory[High(ATask.FHistory)].Action := ((HTMLElement as IHTMLTableRow).cells.item(2,2) as IHTMLElement).innerText;
1219+ ATask.FHistory[High(ATask.FHistory)].Data := ((HTMLElement as IHTMLTableRow).cells.item(3,3) as IHTMLElement).innerText;
12221220 end;
12231221 end;
12241222 // Se chegar aqui, de fato nada de errado aconteceu e podemos retornar
Show on old repository browser