home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2004 June / VPR0406.ISO / STARSUITE7 / EVALUATION / windows / office7 / f_0080 / FilesModul.xba < prev    next >
Extensible Markup Language  |  2004-01-20  |  29KB  |  805 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.     bFilterTracerIsinsideTable = False
  509.     FilterIndex = GetIndexForPartStringinMultiArray(sFilterName(), CurFileContent, 0)
  510.     sDocumentType = sFiltername(FilterIndex,3)
  511.     oLogCursor = oLogDocument.Text.createTextCursor()
  512.     oLogCursor.GotoEnd(False)
  513.     If Not bIsFirstLogTable Then
  514.         oLogDocument.Text.insertControlCharacter(oLogCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
  515.     Else
  516.         bisFirstLogTable = False
  517.     End If
  518.     oLogCursor.HyperLinkURL = ""
  519.     oLogCursor.HyperLinkName = ""
  520.     oLogCursor.HyperLinkTarget = ""
  521.     oLogCursor.ParaStyleName = "Heading 1"
  522.     oLogCursor.setString(sDocumentType)
  523.     If WizardMode = SBMICROSOFTMODE Then
  524.         If bFilterTracingAvailable Then
  525.             If bMSApplFilterTracingAvailable(ApplIndex) Then
  526.                 Dim CurFilterTracingPath as String
  527.                 CurFilterTracingPath = FilterTracingLogPath(ApplIndex)
  528.                 bFilterTracerIsinsideTable = (bTakeOverTargetName(ApplIndex) Or bTakeOverPathName(ApplIndex))
  529.                 If Not bFilterTracerIsinsideTable Then
  530.                     oLogCursor.CollapseToEnd()
  531.                     oLogDocument.Text.insertControlCharacter(oLogCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
  532.                     InsertCommandButtonatViewCursor(oLogDocument, oLogCursor, CurFilterTracingPath)
  533.                 End If
  534.             End If
  535.         End If
  536.     End If
  537.     oLogCursor.CollapsetoEnd()
  538.     oLogDocument.Text.insertControlCharacter(oLogCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
  539.     oLogTable =  oLogDocument.CreateInstance("com.sun.star.text.TextTable")
  540.     oLogTable.RepeatHeadline = true
  541.     If bFilterTracerIsinsideTable Then
  542.         oLogTable.initialize(2,3)
  543.     End If
  544.     oLogCursor.Text.InsertTextContent(oLogCursor, oLogTable, True)
  545.     oTextCursor = oLogTable.GetCellbyPosition(0,0).createTextCursor()
  546.     oTextCursor.SetString(sSourceDocuments)    
  547.     oTextCursor = oLogTable.GetCellbyPosition(1,0).createTextCursor()
  548.     oTextCursor.SetString(sTargetDocuments)
  549.     If bFilterTracerIsinsideTable Then
  550.         oTextCursor = oLogTable.GetCellbyPosition(2,0).createTextCursor()
  551.         oTextCursor.SetString("FilterTracer")
  552.     End If
  553.     bInsertRow = False
  554. End Sub
  555.  
  556.  
  557. Function GetSize(iWidth, iHeight) As New com.sun.star.awt.Size
  558. Dim aSize As New com.sun.star.awt.Size
  559.     aSize.Width = iWidth
  560.     aSize.Height = iHeight
  561.     GetSize() = aSize
  562. End Function
  563.  
  564.  
  565. Sub InsertCommandButtonatViewCursor(oLocDocument, oLocCursor, TargetUrl as String, Optional aSize)
  566. Dim oDocument
  567. Dim oController
  568. Dim oCommandButton
  569. Dim oShape
  570. Dim oDrawPage
  571. Dim oCommandControl
  572. Dim oEvent
  573. Dim oCell
  574.     oCommandButton = oLocDocument.createInstance("com.sun.star.form.component.CommandButton")
  575.     oShape = oLocDocument.CreateInstance ("com.sun.star.drawing.ControlShape")    
  576.     If IsMissing(aSize) Then
  577.         oShape.Size = GetSize(4000, 600)
  578.     End If
  579.     oCommandButton.Label = FileNameoutofPath(Targeturl)
  580.     oCommandButton.TargetFrame = "_default"
  581.     oCommandButton.ButtonType = com.sun.star.form.FormButtonType.URL
  582.     oCommandbutton.DispatchUrlInternal = True
  583.     oCommandButton.TargetURL = ConverttoUrl(TargetUrl)
  584.     oShape.Control = oCommandbutton
  585.     oLocCursor.Text.InsertTextContent(oLocCursor, oShape, True)
  586. End Sub
  587.  
  588.  
  589.  
  590. Sub CreateLogDocument(HiddenProperties())
  591. Dim OpenProperties(0) as new com.sun.star.beans.PropertyValue
  592. Dim NoArgs()
  593. Dim i as Integer
  594. Dim bLogIsThere as Boolean
  595.     If ImportDialog.chkLogfile.State = 1 Then
  596.         i = 2
  597.         OpenProperties(0).Name = "Hidden"
  598.         OpenProperties(0).Value = True
  599.         oLogDocument = StarDesktop.LoadComponentFromURL("private:factory/swriter", "_default", 4, OpenProperties())
  600.         sLogUrl = SOWorkPath & "/Logfile.sxw"
  601.         Do
  602.             bLogIsThere = oUcb.Exists(sLogUrl)
  603.             If bLogIsThere Then
  604.                 If i = 2 Then
  605.                     sLogUrl = ReplaceString(sLogUrl, "/Logfile_2.sxw", "/Logfile.sxw")
  606.                 Else
  607.                     sLogUrl = ReplaceString(sLogUrl, "/Logfile_" & cStr(i) & ".sxw", "/Logfile_" & cStr(i-1) & ".sxw")
  608.                 End If
  609.                 i = i + 1
  610.             End If
  611.         Loop Until Not bLogIsThere
  612.         bLogExists = True
  613.         oLogDocument.StoreAsUrl(sLogUrl, NoArgs())
  614.     End If
  615. End Sub
  616.  
  617.  
  618. Function GetFilterTracingLogPath(sTargetUrl as String, ApplIndex) as String                
  619. Dim TargetFileName as String
  620. Dim sTargetFolder as String
  621. Dim CurFilterTracingPath as String
  622. Dim CurFilterTracingname as String
  623. Dim CurFilterFolder as String
  624.         CurFilterTracingPath = FilterTracingLogPath(ApplIndex)
  625.         If bTakeOverTargetName(ApplIndex) Then            
  626.             TargetFilename = GetFileNameWithoutextension(sTargetUrl, "/")
  627.             CurFilterFolder = DirectoryNameoutofPath(FilterTracingLogPath(ApplIndex), "/")
  628.             CurFilterTracingpath = CurFilterFolder & "/" & TargetFilename & ".log"
  629.         End If
  630.         If bTakeOverPathName(ApplIndex) Then  'Replace the Folder in the FilterTracerpath by the Folder of the targetUrl
  631.             sTargetFolder = DirectoryNameoutofPath(sTargetUrl,"/")
  632.             CurFilterTracingPath = sTargetFolder & "/" & FileNameoutofPath(CurFilterTracingPath, "/")
  633.         End If
  634.         GetFilterTracingLogPath() = CurFilterTracingPath
  635. End Function
  636.  
  637.  
  638. Sub InsertTargetUrlToLogDocument(sTargetUrl as String, sComment as String, ApplIndex as Integer)
  639. Dim oCell
  640. Dim oTextCursor
  641. Dim CurFilterTracingpath as String
  642.     If (bLogExists) And (sTargetUrl <> "") Then
  643.         If sTargetUrl <> "" Then
  644.             oCell = oLogTable.GetCellbyPosition(1,oLogTable.Rows.Count-1)
  645.             InsertCommentToLogCell(sComment, oCell)
  646.             InsertHyperLinkToLogCell(sTargetUrl, oCell)
  647.             If bFilterTracerIsinsideTable Then
  648.                 oCell = oLogTable.getCellByPosition(2, oLogTable.Rows.Count-1)
  649.                 oTextCursor = oCell.Text.CreateTextCursor()
  650.                 CurFilterTracingpath = GetFilterTracingLogPath(sTargetUrl, ApplIndex)
  651.                 InsertCommandButtonatViewCursor(oLogDocument, oTextCursor, CurFilterTracingPath)
  652.             End If
  653.             oLogDocument.Store()
  654.         End If
  655.     End If
  656. End Sub
  657.  
  658.  
  659. Sub InsertSourceUrlToLogDocument(SourceUrl as String, sComment)        '
  660. Dim oCell as Object
  661.     If bLogExists Then
  662.         If bInsertRow Then
  663.             oLogTable.Rows.InsertByIndex(oLogTable.Rows.Count,1)
  664.         Else
  665.             bInsertRow = True
  666.         End If
  667.         oCell = oLogTable.GetCellbyPosition(0,oLogTable.Rows.Count-1)
  668.         InsertCommentToLogCell(sComment, oCell)
  669.         InsertHyperLinkToLogCell(SourceUrl, oCell)
  670.         oLogDocument.Store()
  671.     End If
  672. End Sub
  673.  
  674.  
  675. Sub InsertHyperLinkToLogCell(sUrl as String, oCell as Object)
  676. Dim oLogCursor as Object
  677. Dim LocFileName as String
  678.     oLogCursor = oCell.createTextCursor()
  679.     oLogCursor.CollapseToStart()
  680.     oLogCursor.HyperLinkURL = sUrl
  681.     oLogCursor.HyperLinkName = sUrl
  682.     oLogCursor.HyperLinkTarget = sUrl
  683.     LocFileName = FileNameOutOfPath(sUrl)
  684.     oCell.InsertString(oLogCursor, LocFileName,False)
  685. End Sub            
  686.  
  687.  
  688. Sub InsertCommentToLogCell(sComment as string, oCell as Object)
  689. Dim oCommentCursor as Object
  690.     If sComment <> "" Then
  691.         oCommentCursor = oCell.createTextCursor()
  692.         oCell.insertControlCharacter(oCommentCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
  693.         oCell.insertString(oCommentCursor, sComment, false)
  694.     End If
  695. End Sub
  696.  
  697.  
  698. Sub AddLogStatistics()
  699. Dim oCell as Object
  700. Dim oLogCursor as Object
  701. Dim MaxRowIndex as Integer
  702.     If bLogExists Then
  703.         MaxRowIndex = oLogTable.Rows.Count
  704.         sLogSummary = ReplaceString(sLogSummary, FileCount, "<COUNT>")
  705. '        oLogTable.Rows.InsertByIndex(MaxRowIndex, 1)
  706. '        oCell = oLogTable.GetCellbyPosition(0, MaxRowIndex)
  707. '        oLogCursor = oCell.createTextCursor()
  708. '        oCell.InsertString(oLogCursor, sLogSummary,False)
  709. '        MergeRange(oLogTable, oCell, 1)
  710.  
  711.         oLogCursor = oLogDocument.Text.CreateTextCursor
  712.         oLogCursor.gotoEnd(False)
  713.         oLogCursor.HyperLinkURL = ""
  714.         oLogCursor.HyperLinkName = ""
  715.         oLogCursor.HyperLinkTarget = ""        
  716.         oLogCursor.SetString(sLogSummary)
  717.         oLogDocument.Store()
  718.         oLogDocument.Dispose()
  719.         bLogExists = False
  720.     End If
  721. End Sub
  722.  
  723.  
  724.  
  725. Function CheckIfMacroExists(oBasicLibraries as Object, sComment as String) as Boolean
  726. Dim ModuleNames() as String
  727. Dim ModuleName as String
  728. Dim MaxLibIndex as Integer
  729. Dim MaxModuleIndex as Integer
  730. Dim bMacroExists as Boolean
  731. Dim n as Integer
  732. Dim m as Integer
  733. Dim LibName as String
  734. Dim sBasicCode as String
  735. Dim oLibrary as Object
  736.     bMacroExists = False
  737.     bMacroExists = oBasicLibraries.hasElements
  738.     If bMacroExists Then
  739.         MaxLibIndex = Ubound(oBasicLibraries.ElementNames())
  740.         For n = 0 To MaxLibIndex
  741.             LibName = oBasicLibraries.ElementNames(n)
  742.             oLibrary = oBasicLibraries.getbyName(LibName)
  743.             If oLibrary.hasElements() Then
  744.                 MaxModuleIndex = Ubound(oLibrary.ElementNames())
  745.                 For m = 0 To MaxModuleIndex
  746.                     ModuleName = oLibrary.ElementNames(m)
  747.                     sBasicCode = oLibrary.getbyName(ModuleName)
  748.                     If sBasicCode <> "" Then
  749.                         ConcatComment(sComment, sReeditMacro)
  750.                         CheckIfMacroExists() = True
  751.                         Exit Function
  752.                     End If
  753.                 Next m
  754.             End If
  755.         Next n
  756.     End If
  757.     CheckIfMacroExists() = False
  758. End Function
  759.  
  760.  
  761.  
  762. Function CheckPassWordProtection(oDocument as Object)
  763. Dim bIsPassWordProtected as Boolean
  764. Dim i as Integer
  765. Dim oArgs()
  766. Dim MaxIndex as Integer
  767. Dim sblabla as String
  768.     bIsPassWordProtected = false
  769.      oArgs() = oDocument.getArgs()
  770.      MaxIndex = Ubound(oArgs())
  771.     For i = 0 To MaxIndex
  772.         sblabla = oArgs(i).Name
  773.         If oArgs(i).Name = "Password" Then
  774.             bIsPassWordProtected = True
  775.             sCurPassWord = oArgs(i).Value
  776.             Exit For
  777.         End If
  778.     Next i
  779.     CheckPassWordProtection() = bIsPassWordProtected
  780. End Function
  781.  
  782.  
  783. Sub OpenLogDocument()
  784. Dim NoArgs() as New com.sun.star.beans.PropertyValue
  785.     OpenDocument(sLogUrl, NoArgs())
  786. End Sub
  787.  
  788.  
  789. Sub MergeRange(oTable as Object, oCell as Object, MergeCount as Integer)    
  790. Dim oTableCursor as Object
  791.     oTableCursor = oTable.createCursorByCellName(oCell.CellName)
  792.     oTableCursor.goRight(MergeCount, True)
  793.     oTableCursor.mergeRange()
  794. End Sub        
  795.  
  796.  
  797. Function ConcatComment(sComment as String, AdditionalComment as String)
  798.     If sComment = "" Then
  799.         sComment = AdditionalComment
  800.     Else
  801.         sComment = sComment & chr(13) + AdditionalComment
  802.     End If                
  803.     ConcatComment = sComment
  804. End Function
  805. </script:module>