Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

753 lines
24 KiB

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  3. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  4. Begin VB.Form frmMain
  5. BorderStyle = 1 'Fixed Single
  6. Caption = "RemoveDupMatchingSpace"
  7. ClientHeight = 5355
  8. ClientLeft = 1575
  9. ClientTop = 1740
  10. ClientWidth = 9810
  11. LinkTopic = "Form1"
  12. MaxButton = 0 'False
  13. MinButton = 0 'False
  14. ScaleHeight = 5355
  15. ScaleWidth = 9810
  16. Begin VB.TextBox txtCabFile
  17. Height = 285
  18. Left = 1200
  19. TabIndex = 10
  20. Top = 135
  21. Width = 7935
  22. End
  23. Begin VB.CommandButton cmdSave
  24. Caption = "..."
  25. Height = 255
  26. Left = 9270
  27. TabIndex = 3
  28. Top = 885
  29. Width = 420
  30. End
  31. Begin VB.TextBox txtSaveReport
  32. Height = 285
  33. Left = 1200
  34. TabIndex = 2
  35. Top = 915
  36. Width = 7950
  37. End
  38. Begin MSComctlLib.ProgressBar prgBar
  39. Height = 240
  40. Left = 15
  41. TabIndex = 8
  42. Top = 4845
  43. Width = 9735
  44. _ExtentX = 17171
  45. _ExtentY = 423
  46. _Version = 393216
  47. Appearance = 1
  48. End
  49. Begin VB.TextBox txtLog
  50. Height = 3120
  51. Left = 0
  52. MultiLine = -1 'True
  53. ScrollBars = 2 'Vertical
  54. TabIndex = 7
  55. Top = 1650
  56. Width = 9720
  57. End
  58. Begin MSComctlLib.StatusBar stbProgress
  59. Align = 2 'Align Bottom
  60. Height = 240
  61. Left = 0
  62. TabIndex = 6
  63. Top = 5115
  64. Width = 9810
  65. _ExtentX = 17304
  66. _ExtentY = 423
  67. Style = 1
  68. _Version = 393216
  69. BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628}
  70. NumPanels = 1
  71. BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628}
  72. EndProperty
  73. EndProperty
  74. End
  75. Begin MSComDlg.CommonDialog dlg
  76. Left = 7515
  77. Top = 5100
  78. _ExtentX = 847
  79. _ExtentY = 847
  80. _Version = 393216
  81. End
  82. Begin VB.CommandButton cmdBrowse
  83. Caption = "..."
  84. Height = 255
  85. Left = 9285
  86. TabIndex = 1
  87. Top = 120
  88. Width = 420
  89. End
  90. Begin VB.CommandButton cmdClose
  91. Caption = "&Close"
  92. Height = 375
  93. Left = 8835
  94. TabIndex = 5
  95. Top = 1230
  96. Width = 855
  97. End
  98. Begin VB.CommandButton cmdGo
  99. Caption = "&OK"
  100. Height = 375
  101. Left = 7980
  102. TabIndex = 4
  103. Top = 1230
  104. Width = 855
  105. End
  106. Begin VB.Label Label2
  107. Caption = "&Output Cab:"
  108. Height = 255
  109. Left = 75
  110. TabIndex = 9
  111. Top = 945
  112. Width = 975
  113. End
  114. Begin VB.Label Label1
  115. Caption = "&Input CAB:"
  116. Height = 255
  117. Left = 120
  118. TabIndex = 0
  119. Top = 120
  120. Width = 975
  121. End
  122. End
  123. Attribute VB_Name = "frmMain"
  124. Attribute VB_GlobalNameSpace = False
  125. Attribute VB_Creatable = False
  126. Attribute VB_PredeclaredId = True
  127. Attribute VB_Exposed = False
  128. Option Explicit
  129. ' Utility Stuff, all this could go to a COM Object and be distributed
  130. ' like this.
  131. Private m_WsShell As IWshShell ' Used to Shell and Wait for Sub-Processes
  132. Private m_fso As Scripting.FileSystemObject ' For filesystem operations
  133. Private m_fh As Scripting.TextStream
  134. Private m_ProcessingState As ProcessingState
  135. Private Type SubSiteEntry
  136. strSubSite As String
  137. oDictSubSite As Scripting.Dictionary
  138. End Type
  139. Private m_aListSubSites() As SubSiteEntry
  140. Private Type oDomHhtEntry
  141. strHhtFile As String
  142. oDomHht As DOMDocument
  143. End Type
  144. Private m_aDomHht() As oDomHhtEntry
  145. Private m_lRemovedKeywords As Long
  146. Private m_lRemovedTaxoEntries As Long
  147. Enum ProcessingState
  148. PROC_PROCESSING = 2 ^ 0
  149. PROC_STOP_PROCESSING_NOW = 2 ^ 2
  150. PROC_PROCESSING_STOPPED = 2 ^ 3
  151. End Enum
  152. Private Sub Form_Initialize()
  153. Set m_WsShell = CreateObject("Wscript.Shell")
  154. Set m_fso = New Scripting.FileSystemObject
  155. End Sub
  156. Private Sub Form_Load()
  157. Me.Caption = App.EXEName & ": Duplicate Matching Space Removal Utility"
  158. WriteLog Me.Caption, False
  159. WriteLog String$(60, "="), False
  160. Dim strCommand As String
  161. strCommand = Trim$(Command$)
  162. If (strCommand = "") Then
  163. Exit Sub
  164. End If
  165. txtCabFile = GetOption(strCommand, "i", True)
  166. txtSaveReport = GetOption(strCommand, "o", True)
  167. cmdGo_Click
  168. cmdClose_Click
  169. End Sub
  170. Function Cab2Folder(ByVal strCabFile As String)
  171. Cab2Folder = ""
  172. ' We grab a Temporary Filename and create a folder out of it
  173. Dim strFolder As String
  174. strFolder = m_fso.GetSpecialFolder(TemporaryFolder) + "\" + m_fso.GetTempName
  175. m_fso.CreateFolder strFolder
  176. ' We uncab CAB contents into the Source CAB Contents dir.
  177. Dim strcmd As String
  178. strcmd = "cabarc X """ + strCabFile + """ " + strFolder + "\"
  179. m_WsShell.Run strcmd, True, True
  180. Cab2Folder = strFolder
  181. End Function
  182. Sub Folder2Cab( _
  183. ByVal strFolder As String, _
  184. ByVal strCabFile As String _
  185. )
  186. ' We recab using the Destination directory contents
  187. ' cabarc -r -p -s 6144 N ..\algo.cab *.*
  188. If (m_fso.FileExists(strCabFile)) Then
  189. m_fso.DeleteFile strCabFile, Force:=True
  190. End If
  191. Dim strcmd As String
  192. strcmd = "cabarc -s 6144 N """ + strCabFile + """ " + strFolder + "\*.*"
  193. m_WsShell.Run strcmd, True, True
  194. End Sub
  195. Sub WriteLog(strMsg As String, Optional ByVal bWriteToStatusBar As Boolean = True)
  196. With Me
  197. .txtLog = .txtLog & vbCrLf & strMsg
  198. If (bWriteToStatusBar) Then
  199. .stbProgress.SimpleText = strMsg
  200. End If
  201. End With
  202. DoEvents
  203. End Sub
  204. Private Function p_getTemplateName( _
  205. ByVal strBase As String, _
  206. Optional ByVal strFolder As String = "", _
  207. Optional ByVal strExt As String = "", _
  208. Optional ByVal strPreAmble As String = "", _
  209. Optional ByVal strTrailer As String = "" _
  210. ) As String
  211. p_getTemplateName = ""
  212. strBase = Trim$(strBase)
  213. If Len(strBase) = 0 Then GoTo Common_Exit
  214. Dim strCandidateFileName As String
  215. Dim lx As Long: lx = 1
  216. Do
  217. strCandidateFileName = _
  218. IIf(strFolder = "", m_fso.GetParentFolderName(strBase), strFolder) & "\" & _
  219. strPreAmble & _
  220. m_fso.GetBaseName(strBase) & _
  221. strTrailer & IIf(lx > 1, "_" & lx, "") & "." & _
  222. IIf(strExt = "", m_fso.GetExtensionName(strBase), strExt)
  223. lx = lx + 1
  224. Loop While (m_fso.FileExists(strCandidateFileName))
  225. p_getTemplateName = m_fso.GetFileName(strCandidateFileName)
  226. Common_Exit:
  227. End Function
  228. ' ============ END UTILITY STUFF ========================
  229. ' ============ BoilerPlate Form Code
  230. Private Sub cmdBrowse_Click()
  231. dlg.Filter = "All Files (*.*)|*.*|Cab Files (*.cab)|*.cab"
  232. dlg.FilterIndex = 2
  233. dlg.ShowOpen
  234. If (Len(dlg.FileName) > 0) Then
  235. Me.txtCabFile = dlg.FileName
  236. End If
  237. End Sub
  238. Private Sub cmdSave_Click()
  239. dlg.Filter = "All Files (*.*)|*.*|Text Files (*.cab)|*.cab"
  240. dlg.FilterIndex = 2
  241. dlg.FileName = p_getTemplateName(dlg.FileName, strTrailer:="_out")
  242. dlg.ShowSave
  243. If (Len(dlg.FileName) > 0) Then
  244. Me.txtSaveReport = dlg.FileName
  245. End If
  246. End Sub
  247. Private Sub cmdClose_Click()
  248. If (m_ProcessingState = PROC_PROCESSING) Then
  249. m_ProcessingState = PROC_STOP_PROCESSING_NOW
  250. Else
  251. Unload Me
  252. End If
  253. End Sub
  254. Private Sub cmdGo_Click()
  255. With Me
  256. .txtCabFile.Text = Trim$(Me.txtCabFile.Text)
  257. If (Len(.txtCabFile.Text) = 0 Or _
  258. LCase$(m_fso.GetExtensionName(.txtCabFile.Text)) <> "cab") Then
  259. MsgBox "Please specify valid input and output cabs"
  260. GoTo Common_Exit
  261. End If
  262. .txtSaveReport.Text = Trim$(Me.txtSaveReport.Text)
  263. If (Len(.txtSaveReport.Text) = 0) Then
  264. MsgBox "You must Specify an output report file"
  265. GoTo Common_Exit
  266. End If
  267. SetRunningState True
  268. FixCab .txtCabFile.Text, .txtSaveReport.Text
  269. SetRunningState False
  270. End With
  271. Common_Exit:
  272. End Sub
  273. Private Sub SetRunningState(ByVal bRunning As Boolean)
  274. With Me
  275. .cmdGo.Enabled = Not bRunning
  276. .cmdBrowse.Enabled = Not bRunning
  277. .cmdSave.Enabled = Not bRunning
  278. .txtCabFile.Enabled = Not bRunning
  279. .txtSaveReport.Enabled = Not bRunning
  280. If (bRunning) Then
  281. .cmdClose.Caption = "&Stop"
  282. Else
  283. .cmdClose.Caption = "&Close"
  284. End If
  285. End With
  286. End Sub
  287. Sub FixCab(ByVal strCabFile As String, ByVal strSaveCab As String)
  288. Dim strErrMsg As String: strErrMsg = ""
  289. If (Not m_fso.FileExists(strCabFile)) Then
  290. MsgBox "Cannot find " & strCabFile
  291. GoTo Common_Exit
  292. End If
  293. Dim strCabFolder As String
  294. prgBar.Visible = True
  295. WriteLog "Uncabbing " & strCabFile
  296. strCabFolder = Cab2Folder(strCabFile)
  297. WriteLog "Running Report "
  298. Dim bSuccess As Boolean
  299. bSuccess = RemoveDupUris(strCabFolder)
  300. If (bSuccess) Then
  301. WriteLog "Recabbing to " & strSaveCab
  302. Folder2Cab strCabFolder, strSaveCab
  303. Else
  304. WriteLog "Error, Fix Failed"
  305. End If
  306. ' Now we delete the Temporary Folders
  307. WriteLog "Deleting Temporary Files"
  308. m_fso.DeleteFolder strCabFolder, Force:=True
  309. Common_Exit:
  310. WriteLog "Done" + IIf(Len(strErrMsg) > 0, " - " + strErrMsg, "")
  311. prgBar.Visible = False
  312. End Sub
  313. ' ========================================================
  314. ' Utility functions to get at different places in the
  315. ' package_description.xml and HHT files
  316. ' ========================================================
  317. Private Function GetPackage(ByVal strCabFolder As String) As DOMDocument
  318. Set GetPackage = Nothing
  319. Dim oDomPkg As DOMDocument: Set oDomPkg = New DOMDocument
  320. Dim strPkgFile As String: strPkgFile = strCabFolder + "\package_description.xml"
  321. oDomPkg.async = False
  322. oDomPkg.Load strPkgFile
  323. If (oDomPkg.parseError <> 0) Then
  324. p_DisplayParseError oDomPkg.parseError
  325. GoTo Common_Exit
  326. End If
  327. Set GetPackage = oDomPkg
  328. Common_Exit:
  329. End Function
  330. Private Function p_GetHht( _
  331. ByRef oDomHhtNode As IXMLDOMNode, _
  332. ByVal strCabFolder As String, _
  333. Optional ByRef strHhtFile As String = "" _
  334. ) As IXMLDOMNode
  335. Set p_GetHht = Nothing
  336. If (oDomHhtNode Is Nothing) Then GoTo Common_Exit
  337. strHhtFile = oDomHhtNode.Attributes.getNamedItem("FILE").Text
  338. ' Let's load the HHT
  339. Dim oDomHht As DOMDocument: Set oDomHht = New DOMDocument
  340. oDomHht.async = False
  341. oDomHht.Load strCabFolder + "\" + strHhtFile
  342. If (oDomHht.parseError <> 0) Then
  343. p_DisplayParseError oDomHht.parseError
  344. GoTo Common_Exit
  345. End If
  346. Set p_GetHht = oDomHht
  347. Common_Exit:
  348. End Function
  349. Private Function p_GetAttribute(ByRef oNode As IXMLDOMNode, ByRef strAttrib As String) As String
  350. p_GetAttribute = ""
  351. Dim oAttrib As IXMLDOMAttribute
  352. Set oAttrib = oNode.Attributes.getNamedItem(strAttrib)
  353. If (Not oAttrib Is Nothing) Then
  354. p_GetAttribute = oAttrib.Value
  355. End If
  356. Common_Exit:
  357. End Function
  358. ' ========================================================
  359. ' ============= End BoilerPlate Form Code ================
  360. ' ========================================================
  361. Function RemoveDupUris( _
  362. ByVal strCabFolder As String _
  363. ) As Boolean
  364. RemoveDupUris = False
  365. m_lRemovedKeywords = 0
  366. m_lRemovedTaxoEntries = 0
  367. Dim oDomPkg As DOMDocument: Set oDomPkg = GetPackage(strCabFolder)
  368. WriteLog "Processing Fix for: " + _
  369. oDomPkg.selectSingleNode("HELPCENTERPACKAGE/SKU").Attributes.getNamedItem("VALUE").Text + _
  370. " [ " + _
  371. oDomPkg.selectSingleNode("HELPCENTERPACKAGE/SKU").Attributes.getNamedItem("DISPLAYNAME").Text + _
  372. " ]"
  373. Dim lTotalTaxoEntries As Long: lTotalTaxoEntries = 0
  374. ' Now we parse Package_Description.xml to find the HHT Files
  375. Dim oMetadataNode As IXMLDOMNode
  376. Set oMetadataNode = oDomPkg.selectSingleNode("HELPCENTERPACKAGE/METADATA")
  377. Dim oDOMNodeList As IXMLDOMNodeList, oDomNode As IXMLDOMNode
  378. Dim oDomHhtNode As IXMLDOMNode
  379. Dim oDomHht As DOMDocument
  380. Dim strHhtFile As String
  381. Dim lTotalKwCount As Long: lTotalKwCount = 0
  382. ' First we need to gather the List of SubSites as they define
  383. ' Search Scopes.
  384. Dim oDictSubSite As Scripting.Dictionary: Set oDictSubSite = New Scripting.Dictionary
  385. oDictSubSite.CompareMode = TextCompare
  386. ' I add the root Sub-Site
  387. ReDim Preserve m_aListSubSites(0)
  388. With m_aListSubSites(0)
  389. .strSubSite = "Root"
  390. Set .oDictSubSite = oDictSubSite
  391. End With
  392. ' We go through all the HHTs looking for the SubSites
  393. Dim lx As Long
  394. For Each oDomHhtNode In oMetadataNode.selectNodes("HHT")
  395. Set oDomHht = p_GetHht(oDomHhtNode, strCabFolder, strHhtFile)
  396. ReDim Preserve m_aDomHht(lx)
  397. With m_aDomHht(lx)
  398. Set .oDomHht = oDomHht
  399. .strHhtFile = strCabFolder + "\" + strHhtFile
  400. End With
  401. Set oDOMNodeList = oDomHht.selectNodes("//TAXONOMY_ENTRY[ @SUBSITE ]")
  402. If (Not oDOMNodeList Is Nothing) Then
  403. For Each oDomNode In oDOMNodeList
  404. Dim strSubSite As String
  405. Set oDictSubSite = New Scripting.Dictionary
  406. oDictSubSite.CompareMode = TextCompare
  407. strSubSite = p_GetAttribute(oDomNode, "CATEGORY") + "/" + _
  408. p_GetAttribute(oDomNode, "ENTRY")
  409. ReDim Preserve m_aListSubSites(UBound(m_aListSubSites) + 1)
  410. With m_aListSubSites(UBound(m_aListSubSites))
  411. .strSubSite = strSubSite
  412. Set .oDictSubSite = oDictSubSite
  413. End With
  414. WriteLog "Adding SubSite '" & m_aListSubSites(UBound(m_aListSubSites)).strSubSite & _
  415. "' to list"
  416. Next
  417. End If
  418. lx = lx + 1
  419. Next
  420. For lx = 0 To UBound(m_aDomHht)
  421. ' Let's load the HHT
  422. Set oDomHht = m_aDomHht(lx).oDomHht
  423. Dim oTaxoEntriesList As IXMLDOMNodeList
  424. ' Let's make these queries Super-HHT ready.
  425. lTotalKwCount = lTotalKwCount + oDomHht.selectNodes("//TAXONOMY_ENTRY/KEYWORD").length
  426. oDomHht.setProperty "SelectionLanguage", "XPath"
  427. Set oTaxoEntriesList = oDomHht.selectNodes("//TAXONOMY_ENTRY[ string-length( @URI ) > 0 ]")
  428. Dim lTaxoEntries As Long: lTaxoEntries = oTaxoEntriesList.length
  429. WriteLog strHhtFile & ": There are " & lTaxoEntries & " Taxonomy Entries to process"
  430. lTotalTaxoEntries = lTotalTaxoEntries + lTaxoEntries
  431. prgBar.Max = lTaxoEntries + 1
  432. prgBar.Value = 1
  433. Dim oTaxoEntry As IXMLDOMNode
  434. For Each oTaxoEntry In oTaxoEntriesList
  435. p_Add2SubSite oTaxoEntry
  436. prgBar.Value = prgBar.Value + 1
  437. Next
  438. Next lx
  439. ' OK I finished with the SubSites, so now I will check that ALL URIs in the
  440. ' Root Subsite do not have equivalents in SubSites
  441. With m_aListSubSites(0)
  442. Dim strURI As Variant
  443. For Each strURI In .oDictSubSite.Keys
  444. If (p_bIsAlreadyInChildSubSite(strURI)) Then
  445. Dim oTe As IXMLDOMNode: Set oTe = .oDictSubSite.Item(strURI)
  446. p_RemoveEntry oTe, p_bIsNavigableEntry(oTe)
  447. End If
  448. Next
  449. End With
  450. WriteLog "The total number of Taxonomy Entries Processed was " & lTotalTaxoEntries, False
  451. lTotalTaxoEntries = 0
  452. ' OK, now that I finished, I need to save all these guys to their
  453. ' original locations and count the resulting keywords.
  454. Dim lTotalResultingKwCount As Long: lTotalResultingKwCount = 0
  455. For lx = 0 To UBound(m_aDomHht)
  456. With m_aDomHht(lx)
  457. lTotalResultingKwCount = lTotalResultingKwCount + .oDomHht.selectNodes("//TAXONOMY_ENTRY/KEYWORD").length
  458. lTotalTaxoEntries = lTotalTaxoEntries + .oDomHht.selectNodes("//TAXONOMY_ENTRY[ string-length( @URI ) > 0 ]").length
  459. .oDomHht.Save .strHhtFile
  460. End With
  461. Next lx
  462. WriteLog "The previous total of Keywords in Taxonomy Entries was " & lTotalKwCount, False
  463. WriteLog "The number of duplicate matching space Keyword Entries removed was " & m_lRemovedKeywords, False
  464. WriteLog "The resulting number of Keywords in Taxonomy Entries is " & lTotalResultingKwCount, False
  465. WriteLog "The number of irrelevant non-navigable Taxonomy Entries removed was " & m_lRemovedTaxoEntries
  466. WriteLog "The total number of Taxonomy Entries Remaining is " & lTotalTaxoEntries, False
  467. RemoveDupUris = True
  468. Common_Exit:
  469. If (Not m_fh Is Nothing) Then m_fh.Close: Set m_fh = Nothing
  470. Exit Function
  471. End Function
  472. Private Sub p_Add2SubSite(ByRef oTaxoEntry As IXMLDOMNode)
  473. Dim oDictSubSite As Scripting.Dictionary
  474. Dim lx As Long
  475. Dim bAdded2SubSite As Boolean: bAdded2SubSite = False
  476. ' I first skipthe root Sub-site as I will only add to this
  477. ' IF the oTAXOENTRY did not fint in any other Search Scope
  478. For lx = 1 To UBound(m_aListSubSites)
  479. If (p_bIsInThisSubSite(m_aListSubSites(lx), oTaxoEntry)) Then
  480. p_Add2ThisSubSite m_aListSubSites(lx), oTaxoEntry
  481. bAdded2SubSite = True
  482. End If
  483. Next lx
  484. If (Not bAdded2SubSite) Then
  485. ' We need to add it to the Root SubSite
  486. ' Then we'll figure out if we can get rid of it\
  487. p_Add2ThisSubSite m_aListSubSites(0), oTaxoEntry
  488. End If
  489. End Sub
  490. Private Function p_bIsInThisSubSite( _
  491. ByRef SS As SubSiteEntry, _
  492. ByRef oTaxoEntry As IXMLDOMNode _
  493. ) As Boolean
  494. p_bIsInThisSubSite = False
  495. Dim strCategory As String
  496. strCategory = p_GetAttribute(oTaxoEntry, "CATEGORY")
  497. p_bIsInThisSubSite = (InStr(1, strCategory, SS.strSubSite, vbBinaryCompare) > 0)
  498. ' If (p_bIsInThisSubSite) Then Stop
  499. Common_Exit:
  500. End Function
  501. Private Sub p_Add2ThisSubSite( _
  502. ByRef SS As SubSiteEntry, _
  503. ByRef oTaxoEntry As IXMLDOMNode _
  504. )
  505. Dim strURI As String
  506. strURI = p_GetAttribute(oTaxoEntry, "URI")
  507. With SS
  508. If (.oDictSubSite.Exists(strURI)) Then
  509. ' The URI existed so there is some duplication going on.
  510. ' OK, now we need to
  511. ' (A) Find what is the Best Candidate to stay
  512. ' (B) Put the Best Candidate as the one in the Dictionary
  513. ' (C) DEcide what to do with the other Taxonomy Entry.
  514. ' IF the Taxonomy Entry is NON Navigable then
  515. ' WE will get rid of the Entire Taxonomy Entry
  516. ' ELSE (the TaxoEntry is NAvigable)
  517. ' WE will remove simply the Keywords
  518. '
  519. ' Dim oTD As IXMLDOMNode: Set oTD = .oDictSubSite.Item(strURI)
  520. ' WriteLog "oTd@Category = '" & p_GetAttribute(oTD, "CATEGORY") & "'", False
  521. ' WriteLog "oTaxoEntry@Category = '" & p_GetAttribute(oTaxoEntry, "CATEGORY") & "'", False
  522. Dim oBestEntry As IXMLDOMNode, oWorstEntry As IXMLDOMNode
  523. ' Set oWorstEntry = oTaxoEntry
  524. FindBestEntry oTaxoEntry, .oDictSubSite.Item(strURI), _
  525. oBestEntry, oWorstEntry
  526. If (oBestEntry.selectNodes("KEYWORD").length = 0) Then
  527. WriteLog "Warning: The following Topic was added with NO Keywords." & vbCrLf & _
  528. vbTab & "Topic: " & p_GetAttribute(oBestEntry, "TITLE") & vbCrLf & _
  529. vbTab & "Category: " & p_GetAttribute(oBestEntry, "CATEGORY") & vbCrLf & _
  530. vbTab & "Uri: " & p_GetAttribute(oBestEntry, "URI"), False
  531. End If
  532. Set .oDictSubSite.Item(strURI) = oBestEntry
  533. '
  534. p_RemoveEntry oWorstEntry, p_bIsNavigableEntry(oWorstEntry)
  535. Else
  536. ' First time we see this URI, so we just add it to the list for
  537. ' the SubSite.
  538. .oDictSubSite.Add strURI, oTaxoEntry
  539. End If
  540. End With
  541. End Sub
  542. Private Sub FindBestEntry( _
  543. ByVal oTe1 As IXMLDOMNode, _
  544. ByVal oTe2 As IXMLDOMNode, _
  545. ByRef oBestEntry As IXMLDOMNode, _
  546. ByRef oWorstEntry As IXMLDOMNode _
  547. )
  548. If (p_bIsNavigableEntry(oTe1)) Then
  549. Set oBestEntry = oTe1
  550. Set oWorstEntry = oTe2
  551. Else
  552. Set oBestEntry = oTe2
  553. Set oWorstEntry = oTe1
  554. End If
  555. End Sub
  556. Private Function p_bIsNavigableEntry(ByRef oTaxoEntry As IXMLDOMNode) As Boolean
  557. p_bIsNavigableEntry = False
  558. Dim strCategory As String
  559. strCategory = p_GetAttribute(oTaxoEntry, "CATEGORY")
  560. Dim rv As Boolean
  561. rv = ((InStr(1, strCategory, "search_only", vbTextCompare) = 0) And _
  562. (InStr(1, strCategory, "_hhk", vbTextCompare) = 0) _
  563. )
  564. p_bIsNavigableEntry = rv
  565. Common_Exit:
  566. End Function
  567. Private Sub p_RemoveEntry( _
  568. ByRef oTaxoEntry As IXMLDOMNode, _
  569. ByVal bKeywordsOnly As Boolean _
  570. )
  571. Dim oKWList As IXMLDOMNodeList, oKWNode As IXMLDOMNode
  572. Set oKWList = oTaxoEntry.selectNodes("KEYWORD")
  573. If (Not oKWList Is Nothing) Then
  574. m_lRemovedKeywords = m_lRemovedKeywords + oKWList.length
  575. If (bKeywordsOnly) Then
  576. For Each oKWNode In oKWList
  577. oTaxoEntry.removeChild oKWNode
  578. Next
  579. End If
  580. End If
  581. If (Not bKeywordsOnly) Then
  582. oTaxoEntry.parentNode.removeChild oTaxoEntry
  583. m_lRemovedTaxoEntries = m_lRemovedTaxoEntries + 1
  584. End If
  585. End Sub
  586. Private Function p_bIsAlreadyInChildSubSite(ByVal strURI As String) As Boolean
  587. p_bIsAlreadyInChildSubSite = False
  588. Dim lx As Long
  589. For lx = 1 To UBound(m_aListSubSites)
  590. If (m_aListSubSites(lx).oDictSubSite.Exists(strURI)) Then
  591. p_bIsAlreadyInChildSubSite = True
  592. Exit For
  593. End If
  594. Next lx
  595. End Function
  596. ' =================================================================================
  597. Private Sub p_DisplayParseError( _
  598. ByRef i_ParseError As IXMLDOMParseError _
  599. )
  600. Dim strError As String
  601. strError = "Error: " & i_ParseError.reason & _
  602. "Line: " & i_ParseError.Line & vbCrLf & _
  603. "Linepos: " & i_ParseError.linepos & vbCrLf & _
  604. "srcText: " & i_ParseError.srcText
  605. MsgBox strError, vbOKOnly, "Error while parsing"
  606. End Sub