From 5567686227524b134a38ddf13142108764d98132 Mon Sep 17 00:00:00 2001 From: naru Date: Thu, 3 Apr 2003 19:17:42 +0000 Subject: [PATCH] Removed TXMLDocument and related codes and added XDOMJ --- bottleclient/LogForm.dfm | 10 +-- bottleclient/LogForm.pas | 9 +-- bottleclient/Logs.pas | 193 ++++++++++++++++++++++++++++++++++++----------- 3 files changed, 156 insertions(+), 56 deletions(-) diff --git a/bottleclient/LogForm.dfm b/bottleclient/LogForm.dfm index e8aba93..d87dcd3 100755 --- a/bottleclient/LogForm.dfm +++ b/bottleclient/LogForm.dfm @@ -1,6 +1,6 @@ object frmLog: TfrmLog - Left = 331 - Top = 618 + Left = 535 + Top = 498 Width = 494 Height = 480 Caption = #12525#12464' - '#12480#12502#12523#12463#12522#12483#12463#12391#20877#29983 @@ -340,12 +340,6 @@ object frmLog: TfrmLog OnClick = mnCloseTabClick end end - object XMLDocument: TXMLDocument - Options = [doNodeAutoCreate, doNodeAutoIndent, doAttrNull, doAutoPrefix, doNamespaceDecl] - Left = 208 - Top = 56 - DOMVendorDesc = 'MSXML' - end object OpenDialog: TOpenDialog DefaultExt = 'xml' Filter = 'XML'#12501#12449#12452#12523'(*.xml)|*.xml|'#12377#12409#12390#12398#12501#12449#12452#12523'(*.*)|*.*' diff --git a/bottleclient/LogForm.pas b/bottleclient/LogForm.pas index 664ad23..9824c80 100755 --- a/bottleclient/LogForm.pas +++ b/bottleclient/LogForm.pas @@ -5,8 +5,7 @@ interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls, ToolWin, StdCtrls, ExtCtrls, SsParser, BottleDef, Menus, - Clipbrd, Logs, ShellAPI, Commctrl, DirectSstp, Contnrs, xmldom, XMLIntf, - XMLDoc, StrUtils, msxmldom; + Clipbrd, Logs, ShellAPI, Commctrl, DirectSstp, Contnrs, StrUtils; type TSaveLogType = (stLog, stLogWithChannels, stText, stXML); @@ -50,7 +49,6 @@ type PopupMenuTab: TPopupMenu; mnCloseTab: TMenuItem; tbtnFindBottle: TToolButton; - XMLDocument: TXMLDocument; tbtnOpenLog: TToolButton; OpenDialog: TOpenDialog; tbtnInsertCue: TToolButton; @@ -100,6 +98,7 @@ type // FDragTabIndex: integer; //ƒ^ƒuƒhƒ‰ƒbƒOƒhƒƒbƒvŠÖ˜A FDragTabDest: integer; //ƒhƒƒbƒv‚·‚éˆÊ’u(‚·‚®‰E‚É‚­‚éƒ^ƒu‚̃Cƒ“ƒfƒbƒNƒX) + // procedure UpdateScript(const Script: String); procedure UpdateScriptConversationColor(const Script: String); procedure UpdateScriptScript(const Script: String); @@ -492,7 +491,7 @@ begin SaveDialog.DefaultExt := 'xml'; SaveDialog.FilterIndex := 3; if SaveDialog.Execute then - SelectedBottleLog.SaveToXmlFile(SaveDialog.FileName, XMLDocument); + SelectedBottleLog.SaveToXmlFile(SaveDialog.FileName); end; procedure TfrmLog.lvwLogData(Sender: TObject; Item: TListItem); @@ -943,7 +942,7 @@ begin for i := 0 to OpenDialog.Files.Count-1 do begin BottleLog := TBottleLogList.Create(ExtractFileName(OpenDialog.Files[i])); try - BottleLog.LoadFromXMLFile(OpenDialog.Files[i], XMLDocument); + BottleLog.LoadFromXMLFile(OpenDialog.Files[i]); except on E: EXMLFileOpenException do begin Beep; diff --git a/bottleclient/Logs.pas b/bottleclient/Logs.pas index e33dc0e..e246156 100755 --- a/bottleclient/Logs.pas +++ b/bottleclient/Logs.pas @@ -4,8 +4,7 @@ interface uses Contnrs, Classes, SysUtils, Dialogs, Forms, HttpThread, BottleDef, - DateUtils, IdURI, xmldom, XMLIntf, - msxmldom, XMLDoc; + DateUtils, IdURI, XDOM_2_3_J3; type @@ -103,8 +102,8 @@ type procedure SaveToText(const FileName: String); procedure SaveToSstpLog(const FileName: String; const WithChannel: boolean = false); - procedure SaveToXMLFile(const FileName: String; XMLDocument: TXMLDocument); - procedure LoadFromXMLFile(const FileName: String; XMLDocument: TXMLDocument); + procedure SaveToXMLFile(const FileName: String); + procedure LoadFromXMLFile(const FileName: String); end; var @@ -425,50 +424,90 @@ begin FHttpThread.Resume; end; -procedure TBottleLogList.LoadFromXMLFile(const FileName: String; - XMLDocument: TXMLDocument); -var i: integer; +procedure TBottleLogList.LoadFromXMLFile(const FileName: String); +var i, j, votes, agrees: integer; Time: TDateTime; - ANode: IXMLNode; + ANode, Child: TdomElement; Item: TLogItem; + DOM: TdomDocument; + Parser: TXmlToDomParser; + Impl: TDomImplementation; + Str, mid, channel, script, ghost: String; begin Self.Clear; - XMLDocument.XML.LoadFromFile(FileName); - with XMLDocument do begin + Impl := TDomImplementation.create(nil); + try + Parser := TXmlToDomParser.create(nil); + Parser.DOMImpl := Impl; try - Active := true; - except - on E: Exception do - raise EXMLFileOpenException.Create('—LŒø‚ÈXMLŒ`Ž®‚Å‚Í‚ ‚è‚Ü‚¹‚ñB'#13#10 + E.Message); - end; - if DocumentElement = nil then - raise EXMLFileOpenException.Create('—LŒø‚ÈŒ`Ž®‚Å‚Í‚ ‚è‚Ü‚¹‚ñBƒ‹[ƒgƒ^ƒO‚ª‚ ‚è‚Ü‚¹‚ñ'); - if DocumentElement.NodeName <> 'bottlelog' then - raise EXMLFileOpenException.Create('—LŒø‚ÈŒ`Ž®‚Å‚Í‚ ‚è‚Ü‚¹‚ñBbottlelog‚ªŒ©‚‚©‚è‚Ü‚¹‚ñ'); - if DocumentElement.Attributes['version'] <> '1.0' then - raise EXMLFileOpenException.Create('—LŒø‚ÈŒ`Ž®‚Å‚Í‚ ‚è‚Ü‚¹‚ñB‚±‚̃ƒOƒtƒ@ƒCƒ‹‚̃o[ƒWƒ‡ƒ“‚͓ǂݍž‚ß‚Ü‚¹‚ñ'); - for i := 0 to DocumentElement.ChildNodes.Count-1 do begin - ANode := DocumentElement.ChildNodes[i]; - Item := nil; try - if TryStrToDateTime(ANode.ChildValues['date'], Time) then begin - Item := TLogItem.Create( - ltBottle, - ANode.Attributes['mid'], - ANode.ChildNodes['channel'].Text, - ANode.ChildNodes['script'].Text, - ANode.ChildNodes['ghost'].Text, - Time - ); - Item.Votes := StrToIntDef(ANode.ChildNodes['votes'].Text, 0); - Item.Agrees := StrToIntDef(ANode.ChildNodes['agrees'].Text, 0); - Item.State := lsOpened; - Self.Add(Item); + DOM := Parser.fileToDom(FileName); + if not DOM.validate(nil, erReplace) then + raise EXMLFileOpenException.Create('—LŒø‚ȃ{ƒgƒ‹ƒƒOŒ`Ž®‚Å‚Í‚ ‚è‚Ü‚¹‚ñB'); + with DOM do + begin + if DocumentElement = nil then + raise EXMLFileOpenException.Create('—LŒø‚ÈŒ`Ž®‚Å‚Í‚ ‚è‚Ü‚¹‚ñBƒ‹[ƒgƒ^ƒO‚ª‚ ‚è‚Ü‚¹‚ñ'); + if DocumentElement.nodeName <> 'bottlelog' then + raise EXMLFileOpenException.Create('—LŒø‚ÈŒ`Ž®‚Å‚Í‚ ‚è‚Ü‚¹‚ñBbottlelog‚ªŒ©‚‚©‚è‚Ü‚¹‚ñ'); + Str := DocumentElement.getAttribute('version'); + if Str <> '1.0' then + raise EXMLFileOpenException.CreateFmt('—LŒø‚ÈŒ`Ž®‚Å‚Í‚ ‚è‚Ü‚¹‚ñB'+ + '‚±‚̃ƒOƒtƒ@ƒCƒ‹‚̃o[ƒWƒ‡ƒ“(%s)‚͓ǂݍž‚ß‚Ü‚¹‚ñ', [Str]); + + for i := 0 to DocumentElement.childNodes.length-1 do + begin + if documentElement.childNodes.item(i).nodeType <> ntElement_Node then + Continue; + ANode := documentElement.childNodes.item(i) as TdomElement; + if ANode.nodeName <> 'message' then + Continue; + mid := ANode.getAttribute('mid'); + channel := ''; + script := ''; + ghost := ''; + votes := 0; + agrees := 0; + Time := Now; + for j := 0 to ANode.childNodes.length-1 do + begin + if ANode.childNodes.item(j).nodeType <> ntElement_Node then + Continue; + Child := ANode.childNodes.item(j) as TdomElement; + if Child.nodeName = 'channel' then + channel := Child.textContent + else if Child.nodeName = 'script' then + script := Child.textContent + else if Child.nodeName = 'ghost' then + ghost := Child.textContent + else if Child.nodeName = 'votes' then + votes := StrToIntDef(Child.textContent, 0) + else if Child.nodeName = 'agrees' then + agrees := StrToIntDef(Child.textContent, 0) + else if Child.nodeName = 'date' then + TryStrToDateTime(Child.textContent, Time); + end; + Item := TLogItem.Create(ltBottle, mid, channel, script, ghost, time); + Item.Votes := votes; + Item.Agrees := agrees; + Item.State := lsOpened; + try + Self.Add(Item); + except + Item.Free; + end; + end; end; except - Item.Free; + on E: EParserException do + raise EXMLFileOpenException.Create('XML‰ðÍƒGƒ‰[' + E.Message); end; + finally + Parser.DOMImpl.freeDocument(DOM); + Parser.Free; end; + finally + Impl.Free; end; end; @@ -518,13 +557,81 @@ begin end; end; -procedure TBottleLogList.SaveToXMLFile(const FileName: String; - XMLDocument: TXMLDocument); +procedure TBottleLogList.SaveToXMLFile(const FileName: String); var i: integer; - ANode, BNode: IXMLNode; + MessageNode, Child: TdomElement; Item: TLogItem; + DOM: TdomDocument; + Parser: TXmlToDomParser; + Impl: TDomImplementation; + FS: TFileStream; begin - with XMLDocument do begin + Impl := TDomImplementation.create(nil); + try + Parser := TXmlToDomParser.create(nil); + Parser.DOMImpl := Impl; + try + try + DOM := Parser.fileToDom(ExtractFilePath(Application.ExeName)+'xbtl.dat'); + with DOM do + begin + documentElement.setAttribute('saved', + FormatDateTime('yy/mm/dd hh:nn:ss', Now)); + documentElement.setAttribute('generator', VersionString); + documentElement.setAttribute('version', '1.0'); + for i := 0 to Self.Count-1 do begin + Item := Self.GetBottles(i); + MessageNode := TdomElement.create(DOM, 'message'); + MessageNode.setAttribute('mid', Item.MID); + documentElement.appendChild(MessageNode); + + // “ú•t + Child := createElement('date'); + Child.appendChild(createTextNode(FormatDateTime('yy/mm/dd hh:nn:ss', Item.LogTime))); + MessageNode.appendChild(Child); + // ƒ`ƒƒƒ“ƒlƒ‹ + Child := createElement('channel'); + Child.appendChild(createTextNode(Item.Channel)); + MessageNode.appendChild(Child); + // ƒXƒNƒŠƒvƒg + Child := createElement('script'); + Child.appendChild(createTextNode(Item.Script)); + MessageNode.appendChild(Child); + // “Š•[ + Child := createElement('votes'); + Child.appendChild(createTextNode(IntToStr(Item.Votes))); + MessageNode.appendChild(Child); + // “¯ˆÓ + Child := createElement('agrees'); + Child.appendChild(createTextNode(IntToStr(Item.Agrees))); + MessageNode.appendChild(Child); + // ƒS[ƒXƒg + Child := createElement('ghost'); + Child.appendChild(createTextNode(Item.Ghost)); + MessageNode.appendChild(Child); + + end; + end; + FS := TFileStream.Create(FileName, fmCreate or fmShareExclusive); + try + DOM.writeCodeAsShiftJIS(FS); + finally + FS.Free; + end; + except + ShowMessage('xbtl.dat‚ðÄƒCƒ“ƒXƒg[ƒ‹‚µ‚Ä‚­‚¾‚³‚¢B'); + end; + finally + Parser.DOMImpl.freeDocument(DOM); + Parser.Free; + end; + finally + Impl.Free; + end; + + + + {with XMLDocument do begin try XML.LoadFromFile(ExtractFilePath(Application.ExeName)+'xbtl.dat'); Active := true; @@ -554,7 +661,7 @@ begin BNode.Text := Item.Ghost; end; end; - XMLDocument.XML.SaveToFile(FileName); + XMLDocument.XML.SaveToFile(FileName);} end; procedure TBottleLogList.SetOnLoaded(const Value: TNotifyEvent); -- 2.11.0