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.

1091 lines
34 KiB

  1. VERSION 1.0 CLASS
  2. BEGIN
  3. MultiUse = -1 'True
  4. Persistable = 0 'NotPersistable
  5. DataBindingBehavior = 0 'vbNone
  6. DataSourceBehavior = 0 'vbNone
  7. MTSTransactionMode = 0 'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "Importer"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = False
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = True
  14. Option Explicit
  15. Private Const MAX_LEVELS_C As Long = 100
  16. Private p_clsKeywordifier As Keywordifier
  17. Private p_arrTags(4) As String
  18. Private p_arrParamHhcTags(3) As String
  19. Private p_arrParamHhkTags(1) As String
  20. Private p_strDirName As String
  21. Private p_enumHelpDir As HELPDIR_E
  22. Private p_strSubDir As String
  23. Private p_strVendorString As String
  24. Private p_Nodes(MAX_LEVELS_C) As MSXML2.IXMLDOMNode
  25. Private p_intLevel As Long
  26. Public Event MissingFile(ByVal strFileName As String)
  27. Public Event CorruptFile(ByVal strFileName As String)
  28. Private Sub Class_Initialize()
  29. Set p_clsKeywordifier = New Keywordifier
  30. p_arrTags(0) = "<UL>"
  31. p_arrTags(1) = "</UL>"
  32. p_arrTags(2) = "<LI>"
  33. p_arrTags(3) = "<OBJECT" ' Note that there is no >
  34. p_arrTags(4) = "</OBJECT>"
  35. p_arrParamHhcTags(0) = """Name"""
  36. p_arrParamHhcTags(1) = """Local"""
  37. p_arrParamHhcTags(2) = """Merge"""
  38. p_arrParamHhcTags(3) = """NoLocEnuTitle:"
  39. p_arrParamHhkTags(0) = """Name"""
  40. p_arrParamHhkTags(1) = """Local"""
  41. End Sub
  42. Private Sub Class_Terminate()
  43. Set p_clsKeywordifier = Nothing
  44. End Sub
  45. Public Sub SetHelpDir( _
  46. ByVal i_enumHelpDir As Long, _
  47. ByVal i_strSubDir As String _
  48. )
  49. Dim intLength As Long
  50. Dim vntVendorString As Variant
  51. p_enumHelpDir = i_enumHelpDir
  52. p_strSubDir = i_strSubDir
  53. intLength = Len(p_strSubDir)
  54. If (intLength = 0) Then
  55. ' Nothing
  56. ElseIf (Right$(p_strSubDir, 1) = "\") Then
  57. p_strSubDir = Left$(p_strSubDir, intLength - 1) ' Remove trailing \
  58. End If
  59. If (i_enumHelpDir = HELPDIR_VENDOR_E) Then
  60. vntVendorString = g_clsParameters.Value(VENDOR_STRING_C)
  61. If (IsNull(vntVendorString)) Then
  62. Err.Raise errVendorStringNotConfigured
  63. End If
  64. p_strVendorString = vntVendorString
  65. End If
  66. End Sub
  67. 'HHCs look Like this:
  68. '
  69. '<UL>
  70. '<LI> <OBJECT type="text/sitemap">
  71. ' <param name="Name" value="Welcome">
  72. ' <param name="Comment" value="NoLocEnuTitle: Welcome">
  73. ' <param name="Local" value="MS-ITS:ntdef.chm::/default.htm">
  74. ' <param name="ImageNumber" value="21">
  75. ' </OBJECT>
  76. '<LI> <OBJECT type="text/sitemap">
  77. ' <param name="Name" value="Take ownership of a file or folder">
  78. ' <param name="Comment" value="NoLocEnuTitle: Take ownership of a file or folder">
  79. ' </OBJECT>
  80. '</UL>
  81. '
  82. '<OBJECT type="text/sitemap">
  83. '<param name="Merge" value="MS-ITS:Gstart.chm::/gstart.hhc">
  84. '</OBJECT>
  85. '
  86. '<UL>
  87. '<LI> <OBJECT type="text/sitemap">
  88. ' <param name="Name" value="Users and Computers">
  89. ' <param name="Comment" value="NoLocEnuTitle: Users and Computers">
  90. ' <param name="Local" value="sag_MNGUGtopnode.htm">
  91. ' <param name="ImageNumber" value="1">
  92. ' </OBJECT>
  93. '
  94. ' <UL>
  95. ' <LI> <OBJECT type="text/sitemap">
  96. ' <param name="Name" value="Managing servers remotely">
  97. ' <param name="Comment" value="NoLocEnuTitle: Managing servers remotely">
  98. ' <param name="Local" value="MS-ITS:adminpk.chm::/sag_adminpack.htm">
  99. ' </OBJECT>
  100. ' </UL>
  101. '
  102. ' <OBJECT type="text/sitemap">
  103. ' <param name="Merge" value="MS-ITS:comptoc.chm::/comptoc.hhc">
  104. ' </OBJECT>
  105. '
  106. ' <OBJECT type="text/sitemap">
  107. ' <param name="Merge" value="MS-ITS:msinfo32.chm::/msinfo32.hhc">
  108. ' </OBJECT>
  109. '
  110. '</UL>
  111. Public Function Hhc2Hht( _
  112. ByVal i_strPathName As String, _
  113. ByVal i_strHTMLocation As String, _
  114. Optional ByVal i_intCodePage As Long = 0 _
  115. ) As MSXML2.IXMLDOMDocument
  116. Dim DOMDoc As MSXML2.DOMDocument
  117. Dim Node As MSXML2.IXMLDOMNode
  118. Set DOMDoc = New MSXML2.DOMDocument
  119. Set Node = HhtPreamble(DOMDoc, True)
  120. p_strDirName = DirNameFromPath(i_strPathName)
  121. Set p_Nodes(p_intLevel + 1) = Node
  122. p_ProcessHhcOrHhkFile i_strPathName, True, i_strHTMLocation, i_intCodePage
  123. Set Hhc2Hht = DOMDoc
  124. End Function
  125. 'HHKs look Like this:
  126. '
  127. '<UL>
  128. '<LI> <OBJECT type="text/sitemap">
  129. ' <param name="Name" value="access">
  130. ' <param name="See Also" value="access">
  131. ' </OBJECT>
  132. '
  133. ' <UL>
  134. ' <LI> <OBJECT type="text/sitemap">
  135. ' <param name="Name" value="auditing of See auditing">
  136. ' <param name="See Also" value="auditing">
  137. ' </OBJECT>
  138. ' <LI> <OBJECT type="text/sitemap">
  139. ' <param name="Name" value="file permissions See file permissions">
  140. ' <param name="See Also" value="file permissions">
  141. ' </OBJECT>
  142. ' </UL>
  143. '
  144. '<LI> <OBJECT type="text/sitemap">
  145. ' <param name="Name" value="auditing">
  146. ' <param name="Name" value="Set, view, change, or remove auditing for a file or folder">
  147. ' <param name="See Also" value="auditing">
  148. ' </OBJECT>
  149. '
  150. ' <UL>
  151. ' <LI> <OBJECT type="text/sitemap">
  152. ' <param name="Name" value="enabling Audit Object Access">
  153. ' <param name="Name" value="Set, view, change, or remove auditing for a file or folder">
  154. ' <param name="Local" value="acl_audit_file_folder.htm">
  155. ' </OBJECT>
  156. ' <LI> <OBJECT type="text/sitemap">
  157. ' <param name="Name" value="files and folders">
  158. ' <param name="Name" value="How inheritance affects file and folder auditing">
  159. ' <param name="Local" value="acl_inherit_auditing.htm">
  160. ' <param name="Name" value="Selecting where to apply auditing entries">
  161. ' <param name="Local" value="acl_applyonto_auditing.htm">
  162. ' <param name="Name" value="Set, view, change, or remove auditing for a file or folder">
  163. ' <param name="Local" value="acl_audit_file_folder.htm">
  164. ' <param name="Name" value="Setting up permissions and auditing">
  165. ' <param name="Local" value="acl_overview.htm">
  166. ' </OBJECT>
  167. ' </UL>
  168. '</UL>
  169. '
  170. 'In the case of "Name/Name/See Also" and "Name/Name/Local", the second Name is to be ignored.
  171. 'However, in the case of "Name/Name/Local/Name/Local/...", the first Name is to be made a
  172. ' parent. The subsequent Name/Local pairs are to be made children.
  173. '
  174. 'In the past, the first Name used to be Keyword. Ie "Keyword/Name/See Also",
  175. '"Keyword/Name/Local", "Keyword/Name/Local/Name/Local/...", etc
  176. Public Function Hhk2Hht( _
  177. ByVal i_strPathName As String, _
  178. ByVal i_strHTMLocation As String, _
  179. Optional ByVal i_intCodePage As Long = 0 _
  180. ) As MSXML2.IXMLDOMDocument
  181. Dim DOMDoc As MSXML2.DOMDocument
  182. Dim Node As MSXML2.IXMLDOMNode
  183. Set DOMDoc = New MSXML2.DOMDocument
  184. Set Node = HhtPreamble(DOMDoc, True)
  185. Set p_Nodes(p_intLevel + 1) = Node
  186. p_ProcessHhcOrHhkFile i_strPathName, False, i_strHTMLocation, i_intCodePage
  187. Set Hhk2Hht = DOMDoc
  188. End Function
  189. Public Function Xls2Hht( _
  190. ByVal i_strPathName As String _
  191. ) As MSXML2.IXMLDOMDocument
  192. Dim DOMDoc As MSXML2.DOMDocument
  193. Dim Node As MSXML2.IXMLDOMNode
  194. Set DOMDoc = New MSXML2.DOMDocument
  195. Set Node = HhtPreamble(DOMDoc, True)
  196. Set p_Nodes(p_intLevel + 1) = Node
  197. p_ProcessXlsFile i_strPathName
  198. Set Xls2Hht = DOMDoc
  199. End Function
  200. Public Function Htm2Hht( _
  201. ByVal i_strPathName As String, _
  202. ByVal i_strBaseFile As String _
  203. ) As MSXML2.IXMLDOMDocument
  204. Dim DOMDoc As MSXML2.DOMDocument
  205. Dim Node As MSXML2.IXMLDOMNode
  206. Set DOMDoc = New MSXML2.DOMDocument
  207. Set Node = HhtPreamble(DOMDoc, True)
  208. Set p_Nodes(p_intLevel + 1) = Node
  209. p_ProcessHtmFile i_strPathName, i_strBaseFile
  210. Set Htm2Hht = DOMDoc
  211. End Function
  212. Private Sub p_ProcessHtmFile( _
  213. ByVal i_strPathName As String, _
  214. ByVal i_strBaseFile As String _
  215. )
  216. Dim strTitle As String
  217. Dim strLocContent As String
  218. Dim strURI As String
  219. Dim strFileName As String
  220. Dim strBaseFile As String
  221. Dim arrNameValuePairs(2, 1) As String
  222. Dim Node As MSXML2.IXMLDOMNode
  223. strTitle = XMLMakeValidString(GetHtmTitle(i_strPathName))
  224. strFileName = FileNameFromPath(i_strPathName)
  225. strURI = p_TransformURI(strFileName, i_strBaseFile)
  226. strURI = XMLMakeValidString(strURI)
  227. If (i_strBaseFile = "") Then
  228. strBaseFile = strFileName
  229. Else
  230. strBaseFile = FileNameFromPath(i_strBaseFile) & "\" & strFileName
  231. End If
  232. ' Fetch the TAXONOMY_ENTRIES node.
  233. Set Node = p_Nodes(p_intLevel + 1)
  234. arrNameValuePairs(0, 0) = HHT_TITLE_C
  235. arrNameValuePairs(0, 1) = strTitle
  236. arrNameValuePairs(1, 0) = HHT_basefile_C
  237. arrNameValuePairs(1, 1) = strBaseFile
  238. arrNameValuePairs(2, 0) = HHT_URI_C
  239. arrNameValuePairs(2, 1) = strURI
  240. XMLCreateChildElement Node, HHT_TAXONOMY_ENTRY_C, "", True, arrNameValuePairs
  241. End Sub
  242. Private Sub p_ProcessXlsFile( _
  243. ByVal i_strPathName As String _
  244. )
  245. On Error GoTo LErrorHandler
  246. Dim cnn As ADODB.Connection
  247. Dim rs As ADODB.Recordset
  248. Dim strFileName As String
  249. Dim arrNameValuePairs(3, 1) As String
  250. Dim Node As MSXML2.IXMLDOMNode
  251. Dim strTitle As String
  252. Dim strTitleOld As String
  253. Dim strURI As String
  254. Dim strURIOld As String
  255. Dim strKeywords As String
  256. Dim strKeyword As String
  257. Dim blnRecordSeen As Boolean
  258. Set cnn = New ADODB.Connection
  259. cnn.Open "DRIVER=Microsoft Excel Driver (*.xls);ReadOnly=0;DBQ=" & _
  260. i_strPathName & ";HDR=0;"
  261. Set rs = New ADODB.Recordset
  262. rs.Open "SELECT * FROM `Sheet1$`", cnn, adOpenForwardOnly, adLockReadOnly
  263. strFileName = FileNameFromPath(i_strPathName)
  264. ' Fetch the TAXONOMY_ENTRIES node.
  265. Set Node = p_Nodes(p_intLevel + 1)
  266. arrNameValuePairs(0, 0) = HHT_TITLE_C
  267. arrNameValuePairs(1, 0) = HHT_basefile_C
  268. arrNameValuePairs(1, 1) = strFileName
  269. arrNameValuePairs(2, 0) = HHT_URI_C
  270. arrNameValuePairs(3, 0) = HHT_keywords_C
  271. Do While (Not rs.EOF)
  272. strTitle = XMLMakeValidString(rs("Title") & "")
  273. strURI = XMLMakeValidString(rs("URI") & "")
  274. If (strTitle = "") Then
  275. ' Sometimes, we get a couple of blank rows at the end.
  276. GoTo LWhileEnd
  277. End If
  278. If ((strTitle <> strTitleOld) Or (strURI <> strURIOld)) Then
  279. arrNameValuePairs(0, 1) = strTitleOld
  280. arrNameValuePairs(2, 1) = strURIOld
  281. arrNameValuePairs(3, 1) = FormatKeywordsForTaxonomy(strKeywords)
  282. If (blnRecordSeen) Then
  283. XMLCreateChildElement Node, HHT_TAXONOMY_ENTRY_C, "", True, arrNameValuePairs
  284. End If
  285. strKeywords = " "
  286. strTitleOld = strTitle
  287. strURIOld = strURI
  288. End If
  289. blnRecordSeen = True
  290. strKeyword = RemoveExtraSpaces(rs("Keyword") & "")
  291. If (strKeyword <> "") Then
  292. strKeywords = strKeywords & p_clsKeywordifier.GetKID(strKeyword) & " "
  293. End If
  294. LWhileEnd:
  295. rs.MoveNext
  296. Loop
  297. If (blnRecordSeen) Then
  298. arrNameValuePairs(0, 1) = strTitleOld
  299. arrNameValuePairs(2, 1) = strURIOld
  300. arrNameValuePairs(3, 1) = FormatKeywordsForTaxonomy(strKeywords)
  301. XMLCreateChildElement Node, HHT_TAXONOMY_ENTRY_C, "", True, arrNameValuePairs
  302. End If
  303. Exit Sub
  304. LErrorHandler:
  305. Err.Clear
  306. Err.Raise errBadSpreadsheet
  307. End Sub
  308. Private Sub p_ProcessHhcOrHhkFile( _
  309. ByVal i_strPathName As String, _
  310. ByVal i_blnHhc As Boolean, _
  311. ByVal i_strHTMLocation As String, _
  312. ByVal i_intCodePage As Long _
  313. )
  314. Dim Tokenizer As Tokenizer
  315. Dim strFileName As String
  316. Dim arrNameValuePairs(1, 1) As String
  317. Dim Node As MSXML2.IXMLDOMNode
  318. Set Tokenizer = New Tokenizer
  319. Tokenizer.Init FileRead(i_strPathName, i_intCodePage)
  320. Tokenizer.NormalizeTokens p_arrTags
  321. If (i_blnHhc) Then
  322. Tokenizer.NormalizeTokens p_arrParamHhcTags
  323. Else
  324. Tokenizer.NormalizeTokens p_arrParamHhkTags
  325. End If
  326. strFileName = FileNameFromPath(i_strPathName)
  327. If (Not i_blnHhc) Then
  328. arrNameValuePairs(0, 0) = HHT_TITLE_C
  329. arrNameValuePairs(0, 1) = strFileName
  330. arrNameValuePairs(1, 0) = HHT_basefile_C
  331. arrNameValuePairs(1, 1) = strFileName
  332. ' Fetch the TAXONOMY_ENTRIES node.
  333. Set Node = p_Nodes(p_intLevel + 1)
  334. ' Create a TAXONOMY_ENTRY node for the file.
  335. Set Node = XMLCreateChildElement(Node, HHT_TAXONOMY_ENTRY_C, "", True, arrNameValuePairs)
  336. ' Push this new node on to the stack.
  337. p_intLevel = p_intLevel + 1
  338. Set p_Nodes(p_intLevel + 1) = Node
  339. End If
  340. If (i_blnHhc) Then
  341. p_ProcessHhc strFileName, Tokenizer, i_strHTMLocation, i_intCodePage
  342. Else
  343. p_ProcessHhk strFileName, Tokenizer, i_strHTMLocation
  344. End If
  345. If (Not i_blnHhc) Then
  346. p_intLevel = p_intLevel - 1
  347. End If
  348. End Sub
  349. Private Sub p_ProcessHhc( _
  350. ByVal i_strFileName As String, _
  351. ByVal u_Tokenizer As Tokenizer, _
  352. ByVal i_strHTMLocation As String, _
  353. ByVal i_intCodePage As Long _
  354. )
  355. Dim strMatch As String
  356. Do While (True)
  357. If (u_Tokenizer.GetUpToClosestMatch(p_arrTags, strMatch, , vbTextCompare) = "") Then
  358. Exit Do
  359. End If
  360. Select Case strMatch
  361. Case "<UL>"
  362. p_intLevel = p_intLevel + 1
  363. Case "</UL>"
  364. p_intLevel = p_intLevel - 1
  365. Case "<LI>"
  366. p_ProcessHhcLI i_strFileName, u_Tokenizer, i_strHTMLocation
  367. Case "<OBJECT"
  368. p_ProcessHhcObject u_Tokenizer, i_strHTMLocation, i_intCodePage
  369. Case "</OBJECT>"
  370. End Select
  371. Loop
  372. End Sub
  373. Private Sub p_ProcessHhcLI( _
  374. ByVal i_strFileName As String, _
  375. ByVal u_Tokenizer As Tokenizer, _
  376. ByVal i_strHTMLocation As String _
  377. )
  378. Dim AuxTokenizer As Tokenizer
  379. Dim DOMDoc As MSXML2.DOMDocument
  380. Dim Node As MSXML2.IXMLDOMNode
  381. Dim Element As MSXML2.IXMLDOMElement
  382. Dim Attr As MSXML2.IXMLDOMAttribute
  383. Dim strTitle As String
  384. Dim strDesc As String
  385. Dim strURI As String
  386. Dim strEntry As String
  387. Dim str As String
  388. DoEvents
  389. Set AuxTokenizer = New Tokenizer
  390. AuxTokenizer.Init u_Tokenizer.GetUpTo("</OBJECT>")
  391. With AuxTokenizer
  392. ' Parse Title and URI out of HHC Entry.
  393. ' <OBJECT type=text/sitemap>
  394. ' <PARAM NAME="Name" VALUE="Disk Management">
  395. ' <PARAM NAME="Comment" VALUE="NoLocEnuTitle: Disk Management">
  396. ' <PARAM NAME="Local" VALUE="MS-ITS:DISKconcepts.chm::/dm_overview.htm">
  397. ' </OBJECT>
  398. .GetUpTo """Name"""
  399. .GetAfter """"
  400. strTitle = XMLMakeValidString(.GetUpTo("""", i_blnIncludeMatch:=False))
  401. str = .GetUpTo("""NoLocEnuTitle: ")
  402. If (str <> "") Then
  403. strEntry = XMLMakeValidString(.GetUpTo("""", i_blnIncludeMatch:=False))
  404. Else
  405. strEntry = strTitle
  406. End If
  407. .PushBack str
  408. If (.GetUpTo("""Local""") <> "") Then
  409. .GetAfter """"
  410. strURI = XMLMakeValidString(.GetUpTo("""", i_blnIncludeMatch:=False))
  411. End If
  412. ' Create the <TAXONOMY_ENTRY> node for this Title / URI pair
  413. strDesc = p_GetDescription(strURI, i_strHTMLocation)
  414. Set p_Nodes(p_intLevel + 1) = p_CreateTaxonomyEntry( _
  415. p_Nodes(p_intLevel), strTitle, strEntry, strDesc, strURI, i_strFileName, True)
  416. End With
  417. End Sub
  418. Private Sub p_ProcessHhcObject( _
  419. ByVal u_Tokenizer As Tokenizer, _
  420. ByVal i_strHTMLocation As String, _
  421. ByVal i_intCodePage As Long _
  422. )
  423. Dim AuxTokenizer As Tokenizer
  424. Dim strURI As String
  425. Dim strFileName As String
  426. Dim strPath As String
  427. Dim intLevel As Long
  428. DoEvents
  429. Set AuxTokenizer = New Tokenizer
  430. AuxTokenizer.Init u_Tokenizer.GetUpTo("</OBJECT>")
  431. With AuxTokenizer
  432. ' Do the merge if required. We have already read OBJECT.
  433. ' <OBJECT type="text/sitemap">
  434. ' <param name="Merge" value="MS-ITS:comptoc.chm::/comptoc.hhc">
  435. ' </OBJECT>
  436. If (.GetUpTo("""Merge""") = "") Then
  437. Exit Sub
  438. End If
  439. .GetAfter """"
  440. strURI = XMLMakeValidString(.GetUpTo("""", i_blnIncludeMatch:=False))
  441. strFileName = FileNameFromURI(strURI)
  442. strPath = p_strDirName & strFileName
  443. If (FileExists(strPath)) Then
  444. intLevel = p_intLevel
  445. p_ProcessHhcOrHhkFile strPath, True, i_strHTMLocation, i_intCodePage
  446. ' Some files have mismatched <UL> </UL> pairs.
  447. If (p_intLevel <> intLevel) Then
  448. p_intLevel = intLevel
  449. WriteLog "The file " & strFileName & " is corrupt"
  450. RaiseEvent CorruptFile(strFileName)
  451. End If
  452. Else
  453. WriteLog "The file " & strFileName & " is missing"
  454. RaiseEvent MissingFile(strFileName)
  455. End If
  456. End With
  457. End Sub
  458. Private Sub p_ProcessHhk( _
  459. ByVal i_strFileName As String, _
  460. ByVal u_Tokenizer As Tokenizer, _
  461. ByVal i_strHTMLocation As String _
  462. )
  463. Dim strMatch As String
  464. Dim dictURIs As Scripting.Dictionary
  465. Dim blnGetKIDString As Boolean
  466. Dim strKIDString As String
  467. Dim vntURI As Variant
  468. Dim DOMNode As MSXML2.IXMLDOMNode
  469. Dim strTitle As String
  470. Dim intPos As Long
  471. Set dictURIs = New Scripting.Dictionary
  472. Do While (True)
  473. If (u_Tokenizer.GetUpToClosestMatch(p_arrTags, strMatch) = "") Then
  474. Exit Do
  475. End If
  476. ' After the first <UL>, we are at the top level. We must keywordify the Title.
  477. ' After the second <UL>, we are at the second level. We mustn't keywordify.
  478. Select Case strMatch
  479. Case "<UL>", "</UL>"
  480. blnGetKIDString = IIf(blnGetKIDString, False, True)
  481. If (blnGetKIDString) Then
  482. ' We are about to see the next top level entry. Reset strKIDString.
  483. strKIDString = ""
  484. End If
  485. Case "<LI>"
  486. p_ProcessHhkLI i_strFileName, u_Tokenizer, blnGetKIDString, strKIDString, _
  487. dictURIs
  488. End Select
  489. Loop
  490. For Each vntURI In dictURIs.Keys
  491. strTitle = p_GetTitle(vntURI, i_strHTMLocation)
  492. If (strTitle <> "") Then
  493. Set DOMNode = p_CreateTaxonomyEntry(p_Nodes(p_intLevel + 1), strTitle, "", "", _
  494. vntURI, i_strFileName, False)
  495. XMLSetAttribute DOMNode, HHT_keywords_C, dictURIs(vntURI)
  496. End If
  497. Next
  498. End Sub
  499. Private Function p_GetHtmFileName( _
  500. ByVal i_strURI As String, _
  501. ByVal i_strHTMLocation As String _
  502. ) As String
  503. ' i_strURI looks like one of these:
  504. ' MS-ITS:%HELP_LOCATION%\bar.chm::/foo.htm
  505. ' MS-ITS:%HELP_LOCATION%\sub\bar.chm::/foo.htm
  506. ' hcp://help/sub/foo.htm
  507. ' hcp://system/sub/bar/foo.htm
  508. ' hcp://<Vendor>/sub/bar/foo.htm
  509. ' sub/bar/foo.htm (Equivalent to the URI above)
  510. ' Each of these may have a bookmark at the end:
  511. ' MS-ITS:%HELP_LOCATION%\bar.chm::/foo.htm#gar
  512. Dim strChm As String
  513. Dim strHtm As String
  514. Dim strURI As String
  515. Dim intPos As Long
  516. ' Remove bookmark
  517. strURI = i_strURI
  518. intPos = InStrRev(strURI, "#")
  519. If (intPos <> 0) Then
  520. strURI = Mid$(strURI, 1, intPos - 1)
  521. End If
  522. intPos = InStrRev(strURI, "/")
  523. If (intPos = 0) Then
  524. Exit Function
  525. End If
  526. strHtm = Mid$(strURI, intPos + 1) ' foo.htm
  527. If (Left$(strURI, 10) = "hcp://help") Then
  528. p_GetHtmFileName = i_strHTMLocation & "\" & strHtm
  529. Else
  530. strURI = Left$(strURI, intPos) ' Everything except foo.htm
  531. If (Right$(strURI, 7) = ".chm::/") Then
  532. strURI = Left$(strURI, intPos - 7) ' String ending with bar
  533. Else
  534. strURI = Left$(strURI, intPos - 1) ' String ending with bar
  535. End If
  536. strURI = Replace$(strURI, "\", "/")
  537. intPos = InStrRev(strURI, "/")
  538. If (intPos = 0) Then
  539. intPos = InStrRev(strURI, ":")
  540. End If
  541. strChm = Mid$(strURI, intPos + 1) & ".chm" ' bar.chm
  542. p_GetHtmFileName = i_strHTMLocation & "\" & strChm & "\" & strHtm
  543. End If
  544. End Function
  545. Private Function p_GetTitle( _
  546. ByVal i_strURI As String, _
  547. ByVal i_strHTMLocation As String _
  548. ) As String
  549. On Error GoTo LDone
  550. Dim strHtmFile As String
  551. strHtmFile = p_GetHtmFileName(i_strURI, i_strHTMLocation)
  552. p_GetTitle = GetHtmTitle(strHtmFile)
  553. LDone:
  554. If (Err.Number <> 0) Then
  555. WriteLog "Couldn't get title of " & i_strURI
  556. End If
  557. End Function
  558. Private Function p_GetDescription( _
  559. ByVal i_strURI As String, _
  560. ByVal i_strHTMLocation As String _
  561. ) As String
  562. On Error GoTo LDone
  563. Dim strHtmFile As String
  564. strHtmFile = p_GetHtmFileName(i_strURI, i_strHTMLocation)
  565. p_GetDescription = GetHtmDescription(strHtmFile)
  566. LDone:
  567. End Function
  568. 'Case 1:
  569. '<OBJECT type="text/sitemap">
  570. ' <param name="Name" value="access">
  571. ' <param name="See Also" value="access">
  572. ' </OBJECT>
  573. 'Case 2:
  574. '<OBJECT type="text/sitemap">
  575. ' <param name="Name" value="auditing">
  576. ' <param name="Name" value="Set, view, change, or remove auditing for a file or folder">
  577. ' <param name="See Also" value="auditing">
  578. ' </OBJECT>
  579. 'Case 3:
  580. '<OBJECT type="text/sitemap">
  581. ' <param name="Name" value="enabling Audit Object Access">
  582. ' <param name="Name" value="Set, view, change, or remove auditing for a file or folder">
  583. ' <param name="Local" value="acl_audit_file_folder.htm">
  584. ' </OBJECT>
  585. 'Case 4:
  586. '<OBJECT type="text/sitemap">
  587. ' <param name="Name" value="files and folders">
  588. ' <param name="Name" value="How inheritance affects file and folder auditing">
  589. ' <param name="Local" value="acl_inherit_auditing.htm">
  590. ' <param name="Name" value="Selecting where to apply auditing entries">
  591. ' <param name="Local" value="acl_applyonto_auditing.htm">
  592. ' <param name="Name" value="Set, view, change, or remove auditing for a file or folder">
  593. ' <param name="Local" value="acl_audit_file_folder.htm">
  594. ' <param name="Name" value="Setting up permissions and auditing">
  595. ' <param name="Local" value="acl_overview.htm">
  596. ' </OBJECT>
  597. Private Sub p_ProcessHhkLI( _
  598. ByVal i_strFileName As String, _
  599. ByVal u_Tokenizer As Tokenizer, _
  600. ByVal i_blnGetKIDString As Boolean, _
  601. ByRef u_strKIDString As String, _
  602. ByVal o_dictURIs As Scripting.Dictionary _
  603. )
  604. Dim AuxTokenizer As Tokenizer
  605. Dim arrNameLocalPairs() As Variant
  606. Dim strTitle As String
  607. Dim strURI As String
  608. Dim strKIDString As String
  609. Dim strKIDStringMerged As String
  610. Dim intIndex As Long
  611. DoEvents
  612. Set AuxTokenizer = New Tokenizer
  613. AuxTokenizer.Init u_Tokenizer.GetUpTo("</OBJECT>")
  614. With AuxTokenizer
  615. .GetUpTo """Name"""
  616. .GetAfter """"
  617. strTitle = XMLMakeValidString(.GetUpTo("""", i_blnIncludeMatch:=False))
  618. ' FileWrite "c:\temp\foo.txt", strTitle & " ::: " & i_blnGetKIDString & vbCrLf, True
  619. arrNameLocalPairs = p_GetNameLocalPairs(AuxTokenizer)
  620. If (i_blnGetKIDString) Then
  621. strKIDString = p_clsKeywordifier.CreateKeywordsFromTitle(strTitle)
  622. u_strKIDString = strKIDString
  623. Else
  624. strKIDString = u_strKIDString
  625. End If
  626. For intIndex = 1 To UBound(arrNameLocalPairs)
  627. strURI = arrNameLocalPairs(intIndex)(1)
  628. strURI = XMLMakeValidString(LCase$(p_TransformURI(strURI, i_strFileName)))
  629. If (o_dictURIs.Exists(strURI)) Then
  630. strKIDStringMerged = _
  631. FormatKeywordsForTaxonomy(strKIDString & o_dictURIs(strURI))
  632. o_dictURIs.Remove strURI
  633. Else
  634. strKIDStringMerged = strKIDString
  635. End If
  636. o_dictURIs.Add strURI, strKIDStringMerged
  637. Next
  638. End With
  639. End Sub
  640. Private Function p_GetNameLocalPairs( _
  641. ByVal u_Tokenizer As Tokenizer _
  642. )
  643. Dim arrNameLocalPairs() As Variant
  644. Dim intIndex As Long
  645. Dim strName As String
  646. Dim strLocal As String
  647. intIndex = 0
  648. ReDim arrNameLocalPairs(intIndex)
  649. Do While (True)
  650. With u_Tokenizer
  651. If (.GetUpTo("""Name""") = "") Then
  652. GoTo LEnd
  653. End If
  654. .GetAfter """"
  655. strName = .GetUpTo("""", False)
  656. If (.GetUpTo("""Local""") = "") Then
  657. GoTo LEnd
  658. End If
  659. .GetAfter """"
  660. strLocal = .GetUpTo("""", False)
  661. intIndex = intIndex + 1
  662. ReDim Preserve arrNameLocalPairs(intIndex)
  663. arrNameLocalPairs(intIndex) = Array(strName, strLocal)
  664. End With
  665. Loop
  666. LEnd:
  667. p_GetNameLocalPairs = arrNameLocalPairs
  668. End Function
  669. Private Function p_CreateTaxonomyEntry( _
  670. ByVal i_DOMNodeParent As MSXML2.IXMLDOMNode, _
  671. ByVal i_strTitle As String, _
  672. ByVal i_strEntry As String, _
  673. ByVal i_strDescription As String, _
  674. ByVal i_strURI As String, _
  675. ByVal i_strFileName As String, _
  676. ByVal i_blnTransformURI As Boolean _
  677. ) As MSXML2.IXMLDOMNode
  678. Dim arrNameValuePairs(4, 1) As String
  679. Dim strURI As String
  680. If (i_blnTransformURI) Then
  681. strURI = p_TransformURI(i_strURI, i_strFileName)
  682. Else
  683. strURI = i_strURI
  684. End If
  685. arrNameValuePairs(0, 0) = HHT_TITLE_C
  686. arrNameValuePairs(0, 1) = i_strTitle
  687. arrNameValuePairs(1, 0) = HHT_URI_C
  688. arrNameValuePairs(1, 1) = strURI
  689. arrNameValuePairs(2, 0) = HHT_basefile_C
  690. arrNameValuePairs(2, 1) = i_strFileName
  691. arrNameValuePairs(3, 0) = HHT_DESCRIPTION_C
  692. arrNameValuePairs(3, 1) = i_strDescription
  693. arrNameValuePairs(4, 0) = HHT_ENTRY_C
  694. arrNameValuePairs(4, 1) = i_strEntry
  695. Set p_CreateTaxonomyEntry = XMLCreateChildElement(i_DOMNodeParent, HHT_TAXONOMY_ENTRY_C, "", _
  696. True, arrNameValuePairs)
  697. End Function
  698. Private Function p_TransformURI( _
  699. ByVal i_strURI As String, _
  700. ByVal i_strFileName As String _
  701. ) As String
  702. Dim strFileNameWithoutExtension As String
  703. Dim strSubDirSlash As String
  704. Dim strSubDirWack As String
  705. ' Returns:
  706. ' p_enumHelpDir = HELPDIR_HELP_MSITS_E, p_strSubDir = sub:
  707. ' (foo.htm, bar.*) -> MS-ITS:%HELP_LOCATION%\sub\bar.chm::/foo.htm
  708. ' (MS-ITS:bar.chm::/foo.htm, *) -> MS-ITS:%HELP_LOCATION%\sub\bar.chm::/foo.htm
  709. ' p_enumHelpDir = HELPDIR_HELP_HCP_E, p_strSubDir = sub:
  710. ' (foo.htm, bar.*) -> hcp://help/sub/bar/foo.htm
  711. ' (MS-ITS:bar.chm::/foo.htm, *) -> MS-ITS:%HELP_LOCATION%\sub\bar.chm::/foo.htm
  712. ' p_enumHelpDir = HELPDIR_SYSTEM_E, p_strSubDir = sub:
  713. ' (foo.htm, bar.*) -> hcp://system/sub/bar/foo.htm
  714. ' (MS-ITS:bar.chm::/foo.htm, *) -> MS-ITS:%HELP_LOCATION%\sub\bar.chm::/foo.htm
  715. ' p_enumHelpDir = HELPDIR_VENDOR_E, p_strSubDir = sub:
  716. ' (foo.htm, bar.*) -> sub/bar/foo.htm
  717. ' (MS-ITS:bar.chm::/foo.htm, *) -> MS-ITS:%HELP_LOCATION%\sub\bar.chm::/foo.htm
  718. ' If an HTM is dragged and dropped, then i_strFileName will be ""
  719. ' In this case, in the non-MS-ITS URI's, bar/ will not be present.
  720. If (p_strSubDir = "") Then
  721. strSubDirSlash = ""
  722. strSubDirWack = ""
  723. Else
  724. strSubDirSlash = p_strSubDir & "/"
  725. strSubDirWack = p_strSubDir & "\"
  726. End If
  727. If (i_strURI = "") Then
  728. p_TransformURI = i_strURI
  729. ElseIf (InStr(i_strURI, "::") = 0) Then
  730. strFileNameWithoutExtension = FileNameWithoutExtension(i_strFileName)
  731. If (p_enumHelpDir = HELPDIR_HELP_MSITS_E) Then
  732. p_TransformURI = "MS-ITS:%HELP_LOCATION%\" & strSubDirWack & _
  733. strFileNameWithoutExtension & ".chm::/" & i_strURI
  734. ElseIf (p_enumHelpDir = HELPDIR_HELP_HCP_E) Then
  735. p_TransformURI = "hcp://help/" & strSubDirSlash & i_strURI
  736. ElseIf (p_enumHelpDir = HELPDIR_SYSTEM_E) Then
  737. If (strFileNameWithoutExtension <> "") Then
  738. strFileNameWithoutExtension = strFileNameWithoutExtension & "/"
  739. End If
  740. p_TransformURI = "hcp://system/" & strSubDirSlash & _
  741. strFileNameWithoutExtension & i_strURI
  742. ElseIf (p_enumHelpDir = HELPDIR_VENDOR_E) Then
  743. If (strFileNameWithoutExtension <> "") Then
  744. strFileNameWithoutExtension = strFileNameWithoutExtension & "/"
  745. End If
  746. p_TransformURI = strSubDirSlash & strFileNameWithoutExtension & i_strURI
  747. End If
  748. Else
  749. p_TransformURI = "MS-ITS:%HELP_LOCATION%\" & strSubDirWack & Mid$(i_strURI, 8)
  750. End If
  751. End Function
  752. Public Sub ImportHHC( _
  753. ByVal i_strPathName As String, _
  754. ByVal i_strHTMLocation As String, _
  755. ByVal i_enumSKUs As Long, _
  756. ByVal i_enumHelpDir As Long, _
  757. ByVal i_strSubDir As String, _
  758. Optional ByVal i_intCodePage As Long = 0 _
  759. )
  760. Dim DOMDoc As MSXML2.DOMDocument
  761. Dim DOMNode As MSXML2.IXMLDOMNode
  762. Dim DOMNodeList As MSXML2.IXMLDOMNodeList
  763. Dim clsTaxonomy As Taxonomy
  764. Set DOMDoc = Hhc2Hht(i_strPathName, i_strHTMLocation, i_intCodePage)
  765. If (DOMDoc Is Nothing) Then
  766. Exit Sub
  767. End If
  768. Set DOMNode = XMLFindFirstNode(DOMDoc, HHT_TAXONOMY_ENTRIES_C)
  769. Set DOMNodeList = DOMNode.selectNodes(HHT_TAXONOMY_ENTRY_C)
  770. Set clsTaxonomy = New Taxonomy
  771. For Each DOMNode In DOMNodeList
  772. p_SetTypeSKUsLeafLocIncludeVisibleSubSite DOMNode, i_enumSKUs
  773. clsTaxonomy.CreateTaxonomyEntries DOMNode, ROOT_TID_C, True
  774. Next
  775. End Sub
  776. Public Sub ImportHHK( _
  777. ByVal i_strPathName As String, _
  778. ByVal i_strHTMLocation As String, _
  779. ByVal i_enumSKUs As Long, _
  780. ByVal i_enumHelpDir As Long, _
  781. ByVal i_strSubDir As String, _
  782. ByVal i_intParentTID As Long, _
  783. Optional ByVal i_intCodePage As Long = 0 _
  784. )
  785. Dim DOMDoc As MSXML2.DOMDocument
  786. Dim DOMNode As MSXML2.IXMLDOMNode
  787. Dim DOMNodeList As MSXML2.IXMLDOMNodeList
  788. Dim clsTaxonomy As Taxonomy
  789. Set DOMDoc = Hhk2Hht(i_strPathName, i_strHTMLocation, i_intCodePage)
  790. If (DOMDoc Is Nothing) Then
  791. Exit Sub
  792. End If
  793. Set DOMNode = XMLFindFirstNode(DOMDoc, HHT_TAXONOMY_ENTRIES_C)
  794. Set DOMNodeList = DOMNode.selectNodes(HHT_TAXONOMY_ENTRY_C)
  795. Set clsTaxonomy = New Taxonomy
  796. For Each DOMNode In DOMNodeList
  797. p_SetTypeSKUsLeafLocIncludeVisibleSubSite DOMNode, i_enumSKUs
  798. clsTaxonomy.CreateTaxonomyEntries DOMNode, i_intParentTID, True
  799. Next
  800. End Sub
  801. Private Sub p_SetTypeSKUsLeafLocIncludeVisibleSubSite( _
  802. ByVal u_DOMNode As MSXML2.IXMLDOMNode, _
  803. ByVal i_enumSKUs As SKU_E _
  804. )
  805. Dim DOMNode As MSXML2.IXMLDOMNode
  806. Dim blnHasChildren As Boolean
  807. XMLSetAttribute u_DOMNode, HHT_TYPE_C, 0
  808. XMLSetAttribute u_DOMNode, HHT_skus_C, i_enumSKUs
  809. XMLSetAttribute u_DOMNode, HHT_locinclude_C, LOC_INCLUDE_ALL_C
  810. XMLSetAttribute u_DOMNode, HHT_VISIBLE_C, CStr(True)
  811. XMLSetAttribute u_DOMNode, HHT_SUBSITE_C, CStr(False)
  812. If (u_DOMNode.selectNodes(HHT_TAXONOMY_ENTRY_C).length <> 0) Then
  813. blnHasChildren = True
  814. End If
  815. XMLSetAttribute u_DOMNode, HHT_leaf_C, IIf(blnHasChildren, False, True)
  816. If (blnHasChildren) Then
  817. For Each DOMNode In u_DOMNode.childNodes
  818. If (DOMNode.nodeName = HHT_TAXONOMY_ENTRY_C) Then
  819. p_SetTypeSKUsLeafLocIncludeVisibleSubSite DOMNode, i_enumSKUs
  820. End If
  821. Next
  822. End If
  823. End Sub
  824. 'Private Sub p_DisplayAndRaiseError()
  825. '
  826. ' Dim errCollection As ADODB.Errors
  827. ' Dim errSingle As ADODB.Error
  828. ' Dim strErrorText As String
  829. ' Dim intIndex As Long
  830. '
  831. ' Set errCollection = g_cnn.Errors
  832. '
  833. ' For Each errSingle In errCollection
  834. ' With errSingle
  835. ' strErrorText = strErrorText & "ADO Error #" & intIndex & ":" & vbCrLf
  836. ' strErrorText = strErrorText & vbTab & "ADO Error: #" & .Number & vbCrLf
  837. ' strErrorText = strErrorText & vbTab & "Description: " & .Description & vbCrLf
  838. ' strErrorText = strErrorText & vbTab & "Source: " & .Source & vbCrLf
  839. ' strErrorText = strErrorText & vbTab & "HelpFile: " & .HelpFile & vbCrLf
  840. ' strErrorText = strErrorText & vbTab & "HelpContext: " & .HelpContext & vbCrLf
  841. ' strErrorText = strErrorText & vbTab & "NativeError: " & .NativeError & vbCrLf
  842. ' strErrorText = strErrorText & vbTab & "SQLState: " & .SQLState & vbCrLf
  843. ' intIndex = intIndex + 1
  844. ' End With
  845. ' Next
  846. '
  847. ' With Err
  848. ' strErrorText = strErrorText & "Other Error:" & vbCrLf
  849. ' strErrorText = strErrorText & vbTab & "Number: " & .Number & vbCrLf
  850. ' strErrorText = strErrorText & vbTab & "Description: " & .Description & vbCrLf
  851. ' strErrorText = strErrorText & vbTab & "Source: " & .Source & vbCrLf
  852. ' End With
  853. '
  854. ' PrintLog 0, strErrorText
  855. ' MsgBox strErrorText, vbOKOnly
  856. '
  857. ' Err.Raise Err.Number
  858. '
  859. 'End Sub