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