home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 December / CHIP_CD_2004-12.iso / bonus / oo / OOo_1.1.3_ru_RU_infra_WinIntel_install.exe / $PLUGINSDIR / f_0068 / FilesModul.xba < prev    next >
Extensible Markup Language  |  2004-04-07  |  29KB  |  808 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
  3. <script:module xmlns:script="http://openoffice.org/2000/script" script:name="FilesModul" script:language="StarBasic">Option Explicit
  4.  
  5. Public AbsTemplateFound as Integer
  6. Public AbsDocuFound as Integer
  7. Public oLogDocument as Object
  8. Public oLogTable as Object
  9. Public bLogExists as Boolean
  10. Public sComment as String
  11. Public MaxCollectIndex as Integer
  12. Public bInsertRow as Boolean
  13. Public sLogUrl as String
  14. Public sCurPassWord as String
  15. Public FileCount as Integer
  16. Public XMLTemplateCount as Integer
  17. Public PathCollection(7,3) as String
  18. Public bIsFirstLogTable as Boolean
  19. Public bFilterTracerIsinsideTable as Boolean
  20.  
  21.  
  22. Function ReadCollectionPaths(FilesList() as String, sFilterName() as String)
  23. Dim FilterIndex as Integer
  24. Dim bRecursive as Boolean
  25. Dim SearchDir as String
  26. Dim i as Integer
  27. Dim n as Integer
  28. Dim a as Integer
  29. Dim s as Integer
  30. Dim t as Integer
  31. Dim sFileContent() as String
  32. Dim NewList(0,1) as String
  33. Dim Index as Integer
  34. Dim CurFileName as String
  35. Dim CurExtension as String
  36. Dim CurFileContent as String
  37. Dim XMLTemplateContentList() as String
  38. Dim bIsTemplatePath as Boolean
  39. Dim MaxIndex as Integer
  40. Dim NewContentList() as String
  41. Dim XMLTemplateContentString as String
  42. Dim ApplIndex as Integer
  43. Dim bAssignFileName as Boolean
  44.     oDocInfo = CreateUnoService("com.sun.star.document.DocumentProperties")
  45.     bInterruptSearch = False
  46.     For i = 0 To MaxCollectIndex
  47.         SearchDir = PathCollection(i,0)
  48.         bRecursive = PathCollection(i,1)
  49.         sFileContent() = ArrayoutofString(PathCollection(i,2), "|")
  50.         NewList() = ReadDirectories(SearchDir, bRecursive, False, False, sFileContent(), "")
  51.         If InterruptProcess Then
  52.             ReadCollectionPaths() = False
  53.             Exit Function
  54.         End If
  55.         If Ubound(NewList()) > -1 Then
  56.             bIsTemplatePath = FieldInList("vor", sFileContent)
  57.             If bIsTemplatePath Then
  58.                 XMLTemplateContentString = PathCollection(i,3)
  59.                 XMLTemplateContentList() = ArrayoutofString(XMLTemplateContentString, "|")
  60.                 If Ubound(XMLTemplateContentList()) > -1 Then
  61.                     MaxIndex = Ubound(NewList())
  62.                     ReDim Preserve NewList(MaxIndex, 1) as String
  63.                     ReDim Preserve NewContentList(MaxIndex) as String
  64.                     a = -1
  65.                     For n = 0 To MaxIndex
  66.                         bAssignFileName = True
  67.                         If InterruptProcess() Then
  68.                             ReadCollectionPaths() = False
  69.                             Exit Function
  70.                         End If
  71.                         CurFileContent = ""
  72.                         CurFileName = NewList(n,0)                                                    
  73.                         If NewList(n,1) = "vor" Then
  74.                             CurFileContent = GetRealFileContent(oDocInfo, CurFileName)
  75.                             t = SearchArrayforPartString(CurFileContent, XMLTemplateContentList())
  76.                              bAssignFileName = (t > -1)
  77.                              If bAssignFileName Then
  78.                                  CurFileContent = XMLTemplateContentList(t)
  79.                              End If
  80.                             NewList(n,1) = CurFileContent
  81.                         End If
  82.                         CurExtension = NewList(n,1)
  83.                         If bAssignFileName Then
  84.                             If a < n Then
  85.                                 a = a + 1
  86.                                 NewList(a,0) = CurFileName
  87.                                 NewList(a,1) = CurExtension
  88.                                 If CurFileContent = "" Then
  89.                                     CurFileContent = CurExtension
  90.                                 End If
  91.                                 ApplIndex = GetApplicationIndex(CurFileContent, sFiltername())
  92.                                 NewContentList(a) = ApplIndex
  93.                             End If
  94.                         End If
  95.                     Next n
  96.                     If a < MaxIndex And a > -1 Then
  97.                         ReDim Preserve NewList(a, 1) as String
  98.                     End If
  99.                     If a > -1 Then
  100.                         AddListtoFilesList(FilesList(), NewList(), NewContentList())
  101.                     End If
  102.                 End If
  103.             Else
  104.                 MaxIndex = Ubound(NewList())
  105.                 ReDim Preserve NewContentList(MaxIndex) as String
  106.                 For s = 0 To MaxIndex
  107.                     CurExtension = NewList(s,1)
  108.                     NewContentList(s) = GetApplicationIndex(CurExtension, sFiltername())
  109.                 Next s
  110.                 AddListtoFilesList(FilesList(), NewList(), NewContentList())
  111.             End If
  112.         End If
  113.     Next i
  114.     ReadCollectionPaths() = Ubound(FilesList()) > -1
  115. End Function
  116.  
  117.  
  118. Function GetApplicationIndex(CurFileContent as String, sFilterName() as String) as Integer
  119. Dim Index as Integer
  120. Dim i as Integer
  121.     Index = GetIndexForPartStringinMultiArray(sFilterName(), CurFileContent, 0)
  122.     If Index >= MaxApplCount Then
  123.         Index = Index - MaxApplCount
  124.     End If
  125.     For i = 0 To MaxApplCount - 1
  126.         If Applications(i, SBAPPLKEY) = Index Then
  127.             GetApplicationIndex() = i
  128.             Exit Function
  129.         End If
  130.     Next i
  131.     GetApplicationIndex() = - 1
  132. End Function
  133.  
  134.  
  135. Function InterruptProcess() as Boolean
  136.     If bCancelTask Or RetValue = 0 Then
  137.         bConversionIsRunning = False
  138.         InterruptProcess() = True
  139.         Exit Function
  140.     End if        
  141.     InterruptProcess() = False
  142. End Function
  143.  
  144.  
  145. Sub AddCollectionPath(ApplIndex as Integer, DocIndex as Integer, RecursiveIndex as Integer, sFiltername() as String, DistIndex as Integer)
  146.     MaxCollectIndex = MaxCollectIndex + 1
  147.     PathCollection(MaxCollectIndex, 0) = Applications(ApplIndex, DocIndex)
  148.     PathCollection(MaxCollectIndex, 1) = Applications(ApplIndex, RecursiveIndex)
  149.     AddFilterNameToPathItem(ApplIndex, MaxCollectIndex, sFiltername(), DistIndex)
  150. End Sub
  151.  
  152.  
  153. Sub AddFilterNameToPathItem(ApplIndex as Integer, CollectIndex as Integer, sFiltername() as String, DistIndex as Integer)
  154. Dim iKey as Integer
  155. Dim CurListString as String
  156. Dim LocExtension as String
  157. Dim LocContentString as String
  158. Dim LocXMLTemplateContent as String
  159.     iKey = Applications(ApplIndex, SBAPPLKEY)
  160.     CurListString = PathCollection(CollectIndex, 2)
  161.     LocExtension = sFilterName(iKey +DistIndex, 0)
  162.     If Len(LocExtension) > SBMAXEXTENSIONLENGTH Then             ' 7 == Length of two extensions like 'sda|sdd
  163.         LocExtension = "vor"
  164.         LocContentString = sFilterName(iKey +DistIndex, 0)
  165.         LocContentString = ReplaceString(LocContentString, "|", ";")
  166.         LocXMLTemplateContent = PathCollection(CollectIndex, 3)
  167.         If LocXMLTemplateContent = "" Then
  168.             LocXMLTemplateContent = LocContentString
  169.         Else
  170.             LocXMLTemplateContent = LocXMLTemplateContent & "|" & LocContentString
  171.         End If
  172.         PathCollection(CollectIndex, 3) = LocXMLTemplateContent
  173.     End If
  174.     If CurListString = "" Then
  175.         PathCollection(CollectIndex, 2) = LocExtension
  176.     Else
  177.         If Instr(CurListString, LocExtension) = 0 Then
  178.             PathCollection(CollectIndex, 2) = CurListString & "|" & LocExtension
  179.         End If
  180.     End If
  181. End Sub
  182.  
  183.  
  184. Sub CheckIfToAddPathToCollection(ApplIndex as Integer, bDoConvertIndex as Integer, DocIndex as Integer, RecursiveIndex as Integer, sFiltername() as String, DistIndex as Integer)
  185. Dim CollectIndex as Integer
  186. Dim bCheckDocuType as Boolean
  187.     bCheckDocuType = Applications(ApplIndex, bDoConvertIndex)
  188.     If bCheckDocuType Then
  189.         CollectIndex = GetIndexInMultiArray(PathCollection(), Applications(ApplIndex,DocIndex), 0)
  190.         If (CollectIndex >-1) Then
  191.             If Applications(ApplIndex, RecursiveIndex) <> PathCollection(CollectIndex, 1) Then
  192.                 AddCollectionPath(ApplIndex, DocIndex, RecursiveIndex, sFilterName(), DistIndex)
  193.             Else
  194.                 AddFilterNameToPathItem(ApplIndex, CollectIndex, sFilterName(), DistIndex)
  195.             End If
  196.         Else
  197.             AddCollectionPath(ApplIndex, DocIndex, RecursiveIndex, sFilterName(), DistIndex)
  198.         End If
  199.     End If
  200. End Sub
  201.  
  202.  
  203. Sub CollectPaths(sFiltername() as String)
  204. Dim i as Integer
  205. Dim    XMLTemplateContentString as String
  206.     MaxCollectIndex = -1
  207.     For i = 0 To ApplCount-1
  208.         CheckIfToAddPathToCollection(i, SBDOCCONVERT, SBDOCSOURCE, SBDOCRECURSIVE, sFilterName(), 0)
  209.     Next i
  210.     XMLTemplateCount = 0
  211.     XMLTemplateContentString = ""
  212.     For i = 0 To ApplCount-1
  213.         If WizardMode = SBXMLMODE Then
  214.             XMLTemplateCount = XMLTemplateCount + 1
  215.         End If
  216.         CheckIfToAddPathToCollection(i, SBTEMPLCONVERT, SBTEMPLSOURCE, SBTEMPLRECURSIVE, sFilterName(), MaxApplCount)
  217.     Next i
  218. End Sub
  219.  
  220.  
  221. Sub ConvertAllDocuments(sFilterName() as String)
  222. Dim FileProperties(1) as new com.sun.star.beans.PropertyValue
  223. Dim PWFileProperties(2) as New com.sun.star.beans.PropertyValue
  224. Dim WriterWebProperties(0) as new com.sun.star.beans.PropertyValue
  225. Dim OpenProperties(4) as new com.sun.star.beans.PropertyValue
  226. Dim    oInteractionHandler as Object
  227. Dim InteractionTypes(0) as Long
  228. Dim FilesList(0,2) as String
  229. Dim sViewPath as String
  230. Dim i as Integer
  231. Dim FilterIndex as Integer
  232. Dim sSourceUrl as String
  233. Dim CurFilename as String
  234. Dim oDocument as Object
  235. Dim sExtension as String
  236. Dim OldExtension as String
  237. Dim CurFound as Integer
  238. Dim TotFound as Integer
  239. Dim TargetStemDir as String
  240. Dim SourceStemDir as String
  241. Dim TargetDir as String
  242. Dim sTargetUrl as String
  243. Dim CurFilterName as String
  244. Dim ApplIndex as Integer
  245. Dim Index as Integer
  246. Dim bIsDocument as Boolean
  247. Dim bDoSave as Boolean
  248. Dim sCurFileExists as String
  249. Dim MaxFileIndex as Integer
  250. Dim bContainsBasicMacro as Boolean
  251. Dim bIsPassWordProtected as Boolean
  252. Dim iOverwrite as Integer
  253. Dim sMimeTypeorExtension as String
  254. Dim sPrevMimeTypeorExtension as String
  255.     bConversionisrunning = True
  256.     InteractionTypes(0) = com.sun.star.task.PasswordRequestMode.PASSWORD_REENTER
  257.     oInteractionHandler = createUnoService("com.sun.star.task.InteractionHandler")
  258.     oInteractionHandler.initialize(InteractionTypes())
  259.     iGeneralOverwrite = SBOVERWRITEUNDEFINED
  260.     bConversionIsRunning = True
  261.     bLogExists = false
  262.     AbsTemplateFound = 0
  263.     AbsDocuFound = 0
  264.     CollectPaths(sFiltername())
  265.     If Not ReadCollectionPaths(FilesList(), sFilterName()) Then
  266.         TotFound = 0
  267.         SetProgressDisplay(0)
  268.         bConversionisrunning = false
  269.         FinalizeDialogButtons()    
  270.         Exit Sub
  271.     End If
  272.     TotFound = Ubound(FilesList()) + 1             
  273.     If FilesList(0,0) = "" Then                    ' Querying the number of fields in a multidimensionl Array is unsecure
  274.         TotFound = 0                            ' because it will return the value 0 (and not -1) even when the Array is empty
  275.         SetProgressDisplay(0)
  276.     End If
  277.     BubbleSortList(FilesList(), true)
  278.     If TotFound > 0 Then
  279.         CreateLogDocument(OpenProperties())
  280.         InitializeProgressPage(ImportDialog)
  281.         OpenProperties(0).Name = "Hidden"
  282.         OpenProperties(0).Value = True
  283.         OpenProperties(1).Name = "AsTemplate"
  284.         OpenProperties(1).Value = False
  285.         OpenProperties(2).Name = "MacroExecutionMode"
  286.         OpenProperties(2).Value = com.sun.star.document.MacroExecMode.NEVER_EXECUTE    
  287.         OpenProperties(3).Name = "UpdateDocMode"
  288.         OpenProperties(3).Value = com.sun.star.document.UpdateDocMode.NO_UPDATE
  289.         OpenProperties(4).Name = "InteractionHandler"
  290.         OpenProperties(4).Value = oInteractionHandler
  291.         MaxFileIndex = Ubound(FilesList(),1)
  292.         FileCount = 0
  293.         For i = 0 To MaxFileIndex
  294.             sComment = ""
  295.             If InterruptProcess() Then
  296.                 Exit For
  297.             End If
  298.             bDoSave = True
  299.             sSourceUrl = FilesList(i,0)
  300.             sPrevMimeTypeorExtension = sMimeTypeorExtension
  301.             sMimeTypeorExtension = FilesList(i,1)
  302.             CurFiltername =    GetFilterName(sMimeTypeorExtension, sFilterName(), sExtension, FilterIndex)
  303.             ApplIndex = FilesList(i,2)
  304.             If sMimeTypeorExtension <> sPrevMimeTypeorExtension Then
  305.                 CreateLogTable(ApplIndex, sMimeTypeOrExtension, sFiltername()
  306.             End If
  307.             If ApplIndex > Ubound(Applications) or (ApplIndex < 0) Then
  308.                 Msgbox "Applicationindex out of bounds:" & sSourcUrl
  309.             End If
  310.             sViewPath = ConvertFromUrl(sSourceUrl)     ' CutPathView(sSourceUrl, 70)
  311.             ImportDialog.LabelCurDocument.Label = Str(i+1) & "/" & MaxFileIndex + 1 & "  (" & sViewPath & ")"
  312.             Select Case lcase(sExtension)
  313.                 Case "sxw", "sxc", "sxi", "sxd", "sxs", "sxm"
  314.                     SourceStemDir = RTrimStr(Applications(ApplIndex,SBDOCSOURCE), "/")
  315.                     TargetStemDir = RTrimStr(Applications(ApplIndex,SBDOCTARGET), "/")
  316.                 Case Else                                 ' Templates and Helper-Applications remain
  317.                     SourceStemDir = RTrimStr(Applications(ApplIndex,SBTEMPLSOURCE), "/")
  318.                     TargetStemDir = RTrimStr(Applications(ApplIndex,SBTEMPLTARGET), "/")
  319.             End Select
  320.             sTargetUrl = ReplaceString(sSourceUrl, TargetStemDir, SourceStemDir)
  321.             CurFilename = GetFileNameWithoutExtension(sTargetUrl, "/")
  322.             OldExtension = GetFileNameExtension(sTargetUrl)
  323.             sTargetUrl = RTrimStr(sTargetUrl, OldExtension)
  324.             sTargetUrl = sTargetUrl & sExtension
  325.             TargetDir = RTrimStr(sTargetUrl, CurFilename & "." & sExtension)
  326.             If (oUcb.Exists(sTargetUrl)) Then
  327.                 If (iGeneralOverwrite <> SBOVERWRITEALWAYS) Then
  328.                     If (iGeneralOverwrite = SBOVERWRITEUNDEFINED) Then
  329.                         ShowOverwriteAllDialog(sTargetUrl, sTitle)
  330.                         bDoSave = (iGeneralOverwrite = SBOVERWRITEQUERY) Or (iGeneralOverwrite = SBOVERWRITEALWAYS)
  331.                     Elseif iGeneralOverwrite = SBOVERWRITENEVER Then
  332.                         bDoSave = False                    
  333.                     ElseIf ((iGeneralOverWrite = SBOVERWRITEQUERY) OR (iGeneralOverwrite = SBOVERWRITECANCEL)) Then
  334.                         ' Todo: According to AS there might come a new feature that storeasUrl could possibly rise a UI dialog. 
  335.                         ' In this case my own UI becomes obsolete
  336.                         sCurFileExists = ReplaceString(sFileExists, ConvertFromUrl(sTargetUrl), "<1>")
  337.                         sCurFileExists = ReplaceString(sCurFileExists, chr(13), "<CR>")
  338.                         iOverWrite = Msgbox (sCurFileExists, 32 + 3, sTitle)
  339.                         Select Case iOverWrite
  340.                             Case 1    ' OK
  341.                                 ' In the FileProperty-Bean this is already default
  342.                                 bDoSave = True
  343.                             Case 2     ' Abort
  344.                                 CancelTask(False)
  345.                                 bDoSave = False
  346.                             Case 7     ' No
  347.                                 bDoSave = False
  348.                         End Select
  349.                     End If
  350.                 End If
  351.             End If
  352.             If bDoSave Then
  353.                 If Not oUcb.Exists(TargetDir) Then
  354.                     bDoSave = CreateFolder(TargetDir)
  355.                 End If
  356.                 If bDoSave Then
  357.                     oDocument = StarDesktop.LoadComponentFromURL(sSourceUrl, "_default", 0, OpenProperties())
  358.                     If Not IsNull(oDocument) Then
  359.                         InsertSourceUrlToLogDocument(sSourceUrl, "")
  360.                         bIsPassWordProtected = CheckPassWordProtection(oDocument)
  361.                         CheckIfMacroExists(oDocument.BasicLibraries, sComment)
  362.                         On Local Error Goto NOSAVING
  363.                         If bIsPassWordProtected Then
  364.                             PWFileProperties(0).Name = "FilterName"
  365.                             PWFileProperties(0).Value = CurFilterName
  366.                             PWFileProperties(1).Name = "Overwrite"
  367.                             PWFileProperties(1).Value = True
  368.                             PWFileProperties(2).Name = "Password"
  369.                             PWFileProperties(2).Value = sCurPassWord
  370.                             oDocument.StoreAsUrl(sTargetUrl, PWFileProperties())
  371.                         Else
  372.                             FileProperties(0).Name = "FilterName"
  373.                             FileProperties(0).Value = CurFilterName
  374.                             FileProperties(1).Name = "Overwrite"
  375.                             FileProperties(1).Value = True
  376.                             oDocument.StoreAsUrl(sTargetUrl,FileProperties())
  377.                         End If
  378.                         ' Todo: Make sure that an errorbox pops up when saving fails
  379.                         NOSAVING:
  380.                         If Err <> 0 Then
  381.                             sCurcouldnotsaveDocument = ReplaceString(scouldnotsaveDocument, ConvertFromUrl(sTargetUrl), "<1>")
  382.                             sComment = ConcatComment(sComment, sCurCouldnotsaveDocument)
  383.                             Resume LETSGO
  384.                             LETSGO:
  385.                         Else
  386.                             FileCount = FileCount + 1
  387.                         End If
  388.                         oDocument.Dispose()
  389.                         InsertTargetUrlToLogDocument(sTargetUrl, sComment, ApplIndex)
  390.                     Else
  391.                         sCurcouldnotopenDocument = ReplaceString(scouldnotopenDocument, ConvertFromUrl(sSourceUrl), "<1>")
  392.                         sComment = ConcatComment(sComment, sCurCouldnotopenDocument)
  393.                         InsertSourceUrlToLogDocument(sSourceUrl, sComment)
  394.                     End If
  395.                 End If
  396.             End If
  397.         Next i
  398.     End If
  399.     AddLogStatistics()
  400.     FinalizeDialogButtons()
  401.     bConversionIsRunning = False
  402.     Exit Sub
  403. RTError:
  404.     Msgbox sRTErrorDesc, 16, sRTErrorHeader
  405. End Sub
  406.  
  407.  
  408.  
  409. Sub AddListtoFilesList(FirstList(), SecList(), NewContentList() as String)
  410. Dim sLocExtension as String
  411. Dim FirstStart as Integer
  412. Dim FirstEnd as Integer
  413. Dim i as Integer
  414. Dim s as Integer
  415.     If FirstList(0,0) = "" Then
  416.         FirstStart = Ubound(FirstList(),1)
  417.     Else
  418.         FirstStart = Ubound(FirstList(),1) + 1
  419.     End If
  420.     FirstEnd = FirstStart + Ubound(SecList(),1)
  421.     ReDim Preserve FirstList(FirstEnd,2)
  422.     s = 0
  423.     For i = FirstStart To FirstEnd
  424.         FirstList(i,0) = SecList(s,0)
  425.         FirstList(i,1) = SecList(s,1)
  426.         sLocExtension = lcase(FirstList(i,1))
  427.         Select Case sLocExtension
  428.             Case "sdw", "sdc", "sda", "sdd", "smf", "sgl", "doc", "xls", "ppt"
  429.                 AbsDocuFound = AbsDocuFound + 1
  430.             Case else
  431.                 AbsTemplateFound = AbsTemplateFound + 1
  432.         End Select
  433.         FirstList(i,2) = CStr(NewContentList(s))
  434.         s = s + 1
  435.     Next i
  436.     SetProgressDisplay(Ubound(FirstList()) + 1)
  437. End Sub
  438.  
  439.  
  440.  
  441. Function GetTargetTemplatePath(Index as Integer)
  442.     Select Case WizardMode
  443.         Case SBMICROSOFTMODE
  444.             GetTargetTemplatePath() = SOTemplatePath & "/" & sTemplateGroupName
  445.         Case SBXMLMODE
  446.             If Index = 3 Then
  447.                 ' Helper Application
  448.                 GetTargetTemplatePath = SOWorkPath
  449.             Else
  450.                 GetTargetTemplatePath = SOTemplatePath
  451.             End If
  452.     End Select
  453. End Function
  454.  
  455.  
  456. ' Retrieves the second value for a next to 'SearchString' in
  457. ' a two-dimensional string-Array
  458. Function GetFilterName(sMimetypeorExtension as String, sFilterName(), sExtension as string, FilterIndex as Integer) as String
  459. Dim i as Integer
  460. Dim MaxIndex as Integer
  461. Dim sLocFilterlist() as String
  462.     For i = 0 To Ubound(sFiltername(),1)
  463.         If Instr(1,sFilterName(i,0),sMimeTypeOrExtension) <> 0 Then
  464.             sLocFilterList() = ArrayoutofString(sFiltername(i,0),"|", MaxIndex)
  465.             If MaxIndex = 0 Then
  466.                 sExtension = sFiltername(i,2)
  467.                 GetFilterName = sFilterName(i,1)
  468.             Else
  469.                 Dim b as Integer
  470.                 Dim sLocExtensionList() as String
  471.                 b =    SearchArrayForPartString(sMimetypeOrExtension, sLocFilterList())
  472.                 sLocFilterList() = ArrayoutofString(sFiltername(i,1),"|", MaxIndex)
  473.                 GetFilterName = sLocFilterList(b)
  474.                 sLocExtensionList() = ArrayoutofString(sFilterName(i,2), "|", MaxIndex)
  475.                 sExtension = sLocExtensionList(b)
  476.             End If
  477.             Exit For
  478.         End If
  479.     Next
  480.     FilterIndex = i
  481. End Function
  482.  
  483.  
  484. Function SearchArrayforPartString(SearchString as String, LocList()) as Integer
  485. Dim i as Integer
  486. Dim a as Integer
  487. Dim StringList() as String
  488.     For i = Lbound(LocList(),1) to Ubound(LocList(),1)
  489.         StringList() = ArrayoutofString(LocList(i), "|")
  490.         For a = 0 To Ubound(StringList())
  491.             If (Instr(1, SearchString, StringList(a)) <> 0) Then
  492.                 SearchArrayForPartString() = i
  493.                 Exit Function
  494.             End If
  495.         Next a
  496.     Next i
  497.     SearchArrayForPartString() = -1    
  498. End Function
  499.  
  500.  
  501. Sub CreateLogTable(ApplIndex as Integer, CurFileContent as String, sFilterName() as String)
  502. Dim oLogCursor as Object
  503. Dim oLogRows as Object
  504. Dim FilterIndex as Integer
  505. Dim sDocumentType as String
  506. Dim oTextCursor
  507. Dim oCell
  508.     If NOt bLogExists Then
  509.         Exit Sub
  510.     End If
  511.     bFilterTracerIsinsideTable = False
  512.     FilterIndex = GetIndexForPartStringinMultiArray(sFilterName(), CurFileContent, 0)
  513.     sDocumentType = sFiltername(FilterIndex,3)
  514.     oLogCursor = oLogDocument.Text.createTextCursor()
  515.     oLogCursor.GotoEnd(False)
  516.     If Not bIsFirstLogTable Then
  517.         oLogDocument.Text.insertControlCharacter(oLogCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
  518.     Else
  519.         bisFirstLogTable = False
  520.     End If
  521.     oLogCursor.HyperLinkURL = ""
  522.     oLogCursor.HyperLinkName = ""
  523.     oLogCursor.HyperLinkTarget = ""
  524.     oLogCursor.ParaStyleName = "Heading 1"
  525.     oLogCursor.setString(sDocumentType)
  526.     If WizardMode = SBMICROSOFTMODE Then
  527.         If bFilterTracingAvailable Then
  528.             If bMSApplFilterTracingAvailable(ApplIndex) Then
  529.                 Dim CurFilterTracingPath as String
  530.                 CurFilterTracingPath = FilterTracingLogPath(ApplIndex)
  531.                 bFilterTracerIsinsideTable = (bTakeOverTargetName(ApplIndex) Or bTakeOverPathName(ApplIndex))
  532.                 If Not bFilterTracerIsinsideTable Then
  533.                     oLogCursor.CollapseToEnd()
  534.                     oLogDocument.Text.insertControlCharacter(oLogCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
  535.                     InsertCommandButtonatViewCursor(oLogDocument, oLogCursor, CurFilterTracingPath)
  536.                 End If
  537.             End If
  538.         End If
  539.     End If
  540.     oLogCursor.CollapsetoEnd()
  541.     oLogDocument.Text.insertControlCharacter(oLogCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
  542.     oLogTable =  oLogDocument.CreateInstance("com.sun.star.text.TextTable")
  543.     oLogTable.RepeatHeadline = true
  544.     If bFilterTracerIsinsideTable Then
  545.         oLogTable.initialize(2,3)
  546.     End If
  547.     oLogCursor.Text.InsertTextContent(oLogCursor, oLogTable, True)
  548.     oTextCursor = oLogTable.GetCellbyPosition(0,0).createTextCursor()
  549.     oTextCursor.SetString(sSourceDocuments)    
  550.     oTextCursor = oLogTable.GetCellbyPosition(1,0).createTextCursor()
  551.     oTextCursor.SetString(sTargetDocuments)
  552.     If bFilterTracerIsinsideTable Then
  553.         oTextCursor = oLogTable.GetCellbyPosition(2,0).createTextCursor()
  554.         oTextCursor.SetString("FilterTracer")
  555.     End If
  556.     bInsertRow = False
  557. End Sub
  558.  
  559.  
  560. Function GetSize(iWidth, iHeight) As New com.sun.star.awt.Size
  561. Dim aSize As New com.sun.star.awt.Size
  562.     aSize.Width = iWidth
  563.     aSize.Height = iHeight
  564.     GetSize() = aSize
  565. End Function
  566.  
  567.  
  568. Sub InsertCommandButtonatViewCursor(oLocDocument, oLocCursor, TargetUrl as String, Optional aSize)
  569. Dim oDocument
  570. Dim oController
  571. Dim oCommandButton
  572. Dim oShape
  573. Dim oDrawPage
  574. Dim oCommandControl
  575. Dim oEvent
  576. Dim oCell
  577.     oCommandButton = oLocDocument.createInstance("com.sun.star.form.component.CommandButton")
  578.     oShape = oLocDocument.CreateInstance ("com.sun.star.drawing.ControlShape")    
  579.     If IsMissing(aSize) Then
  580.         oShape.Size = GetSize(4000, 600)
  581.     End If
  582.     oCommandButton.Label = FileNameoutofPath(Targeturl)
  583.     oCommandButton.TargetFrame = "_default"
  584.     oCommandButton.ButtonType = com.sun.star.form.FormButtonType.URL
  585.     oCommandbutton.DispatchUrlInternal = True
  586.     oCommandButton.TargetURL = ConverttoUrl(TargetUrl)
  587.     oShape.Control = oCommandbutton
  588.     oLocCursor.Text.InsertTextContent(oLocCursor, oShape, True)
  589. End Sub
  590.  
  591.  
  592.  
  593. Sub CreateLogDocument(HiddenProperties())
  594. Dim OpenProperties(0) as new com.sun.star.beans.PropertyValue
  595. Dim NoArgs()
  596. Dim i as Integer
  597. Dim bLogIsThere as Boolean
  598.     If ImportDialog.chkLogfile.State = 1 Then
  599.         i = 2
  600.         OpenProperties(0).Name = "Hidden"
  601.         OpenProperties(0).Value = True
  602.         oLogDocument = StarDesktop.LoadComponentFromURL("private:factory/swriter", "_default", 4, OpenProperties())
  603.         sLogUrl = SOWorkPath & "/Logfile.sxw"
  604.         Do
  605.             bLogIsThere = oUcb.Exists(sLogUrl)
  606.             If bLogIsThere Then
  607.                 If i = 2 Then
  608.                     sLogUrl = ReplaceString(sLogUrl, "/Logfile_2.sxw", "/Logfile.sxw")
  609.                 Else
  610.                     sLogUrl = ReplaceString(sLogUrl, "/Logfile_" & cStr(i) & ".sxw", "/Logfile_" & cStr(i-1) & ".sxw")
  611.                 End If
  612.                 i = i + 1
  613.             End If
  614.         Loop Until Not bLogIsThere
  615.         bLogExists = True
  616.         oLogDocument.StoreAsUrl(sLogUrl, NoArgs())
  617.     End If
  618. End Sub
  619.  
  620.  
  621. Function GetFilterTracingLogPath(sTargetUrl as String, ApplIndex) as String                
  622. Dim TargetFileName as String
  623. Dim sTargetFolder as String
  624. Dim CurFilterTracingPath as String
  625. Dim CurFilterTracingname as String
  626. Dim CurFilterFolder as String
  627.         CurFilterTracingPath = FilterTracingLogPath(ApplIndex)
  628.         If bTakeOverTargetName(ApplIndex) Then            
  629.             TargetFilename = GetFileNameWithoutextension(sTargetUrl, "/")
  630.             CurFilterFolder = DirectoryNameoutofPath(FilterTracingLogPath(ApplIndex), "/")
  631.             CurFilterTracingpath = CurFilterFolder & "/" & TargetFilename & ".log"
  632.         End If
  633.         If bTakeOverPathName(ApplIndex) Then  'Replace the Folder in the FilterTracerpath by the Folder of the targetUrl
  634.             sTargetFolder = DirectoryNameoutofPath(sTargetUrl,"/")
  635.             CurFilterTracingPath = sTargetFolder & "/" & FileNameoutofPath(CurFilterTracingPath, "/")
  636.         End If
  637.         GetFilterTracingLogPath() = CurFilterTracingPath
  638. End Function
  639.  
  640.  
  641. Sub InsertTargetUrlToLogDocument(sTargetUrl as String, sComment as String, ApplIndex as Integer)
  642. Dim oCell
  643. Dim oTextCursor
  644. Dim CurFilterTracingpath as String
  645.     If (bLogExists) And (sTargetUrl <> "") Then
  646.         If sTargetUrl <> "" Then
  647.             oCell = oLogTable.GetCellbyPosition(1,oLogTable.Rows.Count-1)
  648.             InsertCommentToLogCell(sComment, oCell)
  649.             InsertHyperLinkToLogCell(sTargetUrl, oCell)
  650.             If bFilterTracerIsinsideTable Then
  651.                 oCell = oLogTable.getCellByPosition(2, oLogTable.Rows.Count-1)
  652.                 oTextCursor = oCell.Text.CreateTextCursor()
  653.                 CurFilterTracingpath = GetFilterTracingLogPath(sTargetUrl, ApplIndex)
  654.                 InsertCommandButtonatViewCursor(oLogDocument, oTextCursor, CurFilterTracingPath)
  655.             End If
  656.             oLogDocument.Store()
  657.         End If
  658.     End If
  659. End Sub
  660.  
  661.  
  662. Sub InsertSourceUrlToLogDocument(SourceUrl as String, sComment)        '
  663. Dim oCell as Object
  664.     If bLogExists Then
  665.         If bInsertRow Then
  666.             oLogTable.Rows.InsertByIndex(oLogTable.Rows.Count,1)
  667.         Else
  668.             bInsertRow = True
  669.         End If
  670.         oCell = oLogTable.GetCellbyPosition(0,oLogTable.Rows.Count-1)
  671.         InsertCommentToLogCell(sComment, oCell)
  672.         InsertHyperLinkToLogCell(SourceUrl, oCell)
  673.         oLogDocument.Store()
  674.     End If
  675. End Sub
  676.  
  677.  
  678. Sub InsertHyperLinkToLogCell(sUrl as String, oCell as Object)
  679. Dim oLogCursor as Object
  680. Dim LocFileName as String
  681.     oLogCursor = oCell.createTextCursor()
  682.     oLogCursor.CollapseToStart()
  683.     oLogCursor.HyperLinkURL = sUrl
  684.     oLogCursor.HyperLinkName = sUrl
  685.     oLogCursor.HyperLinkTarget = sUrl
  686.     LocFileName = FileNameOutOfPath(sUrl)
  687.     oCell.InsertString(oLogCursor, LocFileName,False)
  688. End Sub            
  689.  
  690.  
  691. Sub InsertCommentToLogCell(sComment as string, oCell as Object)
  692. Dim oCommentCursor as Object
  693.     If sComment <> "" Then
  694.         oCommentCursor = oCell.createTextCursor()
  695.         oCell.insertControlCharacter(oCommentCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
  696.         oCell.insertString(oCommentCursor, sComment, false)
  697.     End If
  698. End Sub
  699.  
  700.  
  701. Sub AddLogStatistics()
  702. Dim oCell as Object
  703. Dim oLogCursor as Object
  704. Dim MaxRowIndex as Integer
  705.     If bLogExists Then
  706.         MaxRowIndex = oLogTable.Rows.Count
  707.         sLogSummary = ReplaceString(sLogSummary, FileCount, "<COUNT>")
  708. '        oLogTable.Rows.InsertByIndex(MaxRowIndex, 1)
  709. '        oCell = oLogTable.GetCellbyPosition(0, MaxRowIndex)
  710. '        oLogCursor = oCell.createTextCursor()
  711. '        oCell.InsertString(oLogCursor, sLogSummary,False)
  712. '        MergeRange(oLogTable, oCell, 1)
  713.  
  714.         oLogCursor = oLogDocument.Text.CreateTextCursor
  715.         oLogCursor.gotoEnd(False)
  716.         oLogCursor.HyperLinkURL = ""
  717.         oLogCursor.HyperLinkName = ""
  718.         oLogCursor.HyperLinkTarget = ""        
  719.         oLogCursor.SetString(sLogSummary)
  720.         oLogDocument.Store()
  721.         oLogDocument.Dispose()
  722.         bLogExists = False
  723.     End If
  724. End Sub
  725.  
  726.  
  727.  
  728. Function CheckIfMacroExists(oBasicLibraries as Object, sComment as String) as Boolean
  729. Dim ModuleNames() as String
  730. Dim ModuleName as String
  731. Dim MaxLibIndex as Integer
  732. Dim MaxModuleIndex as Integer
  733. Dim bMacroExists as Boolean
  734. Dim n as Integer
  735. Dim m as Integer
  736. Dim LibName as String
  737. Dim sBasicCode as String
  738. Dim oLibrary as Object
  739.     bMacroExists = False
  740.     bMacroExists = oBasicLibraries.hasElements
  741.     If bMacroExists Then
  742.         MaxLibIndex = Ubound(oBasicLibraries.ElementNames())
  743.         For n = 0 To MaxLibIndex
  744.             LibName = oBasicLibraries.ElementNames(n)
  745.             oLibrary = oBasicLibraries.getbyName(LibName)
  746.             If oLibrary.hasElements() Then
  747.                 MaxModuleIndex = Ubound(oLibrary.ElementNames())
  748.                 For m = 0 To MaxModuleIndex
  749.                     ModuleName = oLibrary.ElementNames(m)
  750.                     sBasicCode = oLibrary.getbyName(ModuleName)
  751.                     If sBasicCode <> "" Then
  752.                         ConcatComment(sComment, sReeditMacro)
  753.                         CheckIfMacroExists() = True
  754.                         Exit Function
  755.                     End If
  756.                 Next m
  757.             End If
  758.         Next n
  759.     End If
  760.     CheckIfMacroExists() = False
  761. End Function
  762.  
  763.  
  764.  
  765. Function CheckPassWordProtection(oDocument as Object)
  766. Dim bIsPassWordProtected as Boolean
  767. Dim i as Integer
  768. Dim oArgs()
  769. Dim MaxIndex as Integer
  770. Dim sblabla as String
  771.     bIsPassWordProtected = false
  772.      oArgs() = oDocument.getArgs()
  773.      MaxIndex = Ubound(oArgs())
  774.     For i = 0 To MaxIndex
  775.         sblabla = oArgs(i).Name
  776.         If oArgs(i).Name = "Password" Then
  777.             bIsPassWordProtected = True
  778.             sCurPassWord = oArgs(i).Value
  779.             Exit For
  780.         End If
  781.     Next i
  782.     CheckPassWordProtection() = bIsPassWordProtected
  783. End Function
  784.  
  785.  
  786. Sub OpenLogDocument()
  787. Dim NoArgs() as New com.sun.star.beans.PropertyValue
  788.     OpenDocument(sLogUrl, NoArgs())
  789. End Sub
  790.  
  791.  
  792. Sub MergeRange(oTable as Object, oCell as Object, MergeCount as Integer)    
  793. Dim oTableCursor as Object
  794.     oTableCursor = oTable.createCursorByCellName(oCell.CellName)
  795.     oTableCursor.goRight(MergeCount, True)
  796.     oTableCursor.mergeRange()
  797. End Sub        
  798.  
  799.  
  800. Function ConcatComment(sComment as String, AdditionalComment as String)
  801.     If sComment = "" Then
  802.         sComment = AdditionalComment
  803.     Else
  804.         sComment = sComment & chr(13) + AdditionalComment
  805.     End If                
  806.     ConcatComment = sComment
  807. End Function
  808. </script:module>