home *** CD-ROM | disk | FTP | other *** search
/ Freelog 52 / Freelog052.iso / Dossier / OpenOffice / f_0066 / FilesModul.xba < prev    next >
Extensible Markup Language  |  2003-06-24  |  24KB  |  687 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.  
  19.  
  20.  
  21. Function ReadCollectionPaths(FilesList() as String, sFilterName() as String)
  22. Dim FilterIndex as Integer
  23. Dim bRecursive as Boolean
  24. Dim SearchDir as String
  25. Dim i as Integer
  26. Dim n as Integer
  27. Dim a as Integer
  28. Dim s as Integer
  29. Dim t as Integer
  30. Dim sFileContent() as String
  31. Dim NewList(0,1) as String
  32. Dim Index as Integer
  33. Dim CurFileName as String
  34. Dim CurExtension as String
  35. Dim CurFileContent as String
  36. Dim XMLTemplateContentList() as String
  37. Dim bIsTemplatePath as Boolean
  38. Dim MaxIndex as Integer
  39. Dim NewContentList() as String
  40. Dim XMLTemplateContentString as String
  41. Dim ApplIndex as Integer
  42. Dim bAssignFileName as Boolean
  43.     oDocInfo = CreateUnoService("com.sun.star.document.DocumentProperties")
  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 NewList(n,1) = "vor" Then
  73.                             CurFileContent = GetRealFileContent(oDocInfo, 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. End Function
  114.  
  115.  
  116. Function GetApplicationIndex(CurFileContent as String, sFilterName() as String) as Integer
  117. Dim Index as Integer
  118. Dim i as Integer
  119.     Index = GetIndexForPartStringinMultiArray(sFilterName(), CurFileContent, 0)
  120.     If Index >= MaxApplCount Then
  121.         Index = Index - MaxApplCount
  122.     End If
  123.     For i = 0 To MaxApplCount - 1
  124.         If Applications(i, SBAPPLKEY) = Index Then
  125.             GetApplicationIndex() = i
  126.             Exit Function
  127.         End If
  128.     Next i
  129.     GetApplicationIndex() = - 1
  130. End Function
  131.  
  132.  
  133. Function InterruptProcess() as Boolean
  134.     If bCancelTask Or RetValue = 0 Then
  135.         bConversionIsRunning = False
  136.         InterruptProcess() = True
  137.         Exit Function
  138.     End if        
  139.     InterruptProcess() = False
  140. End Function
  141.  
  142.  
  143. Sub AddCollectionPath(ApplIndex as Integer, DocIndex as Integer, RecursiveIndex as Integer, sFiltername() as String, DistIndex as Integer)
  144.     MaxCollectIndex = MaxCollectIndex + 1
  145.     PathCollection(MaxCollectIndex, 0) = Applications(ApplIndex, DocIndex)
  146.     PathCollection(MaxCollectIndex, 1) = Applications(ApplIndex, RecursiveIndex)
  147.     AddFilterNameToPathItem(ApplIndex, MaxCollectIndex, sFiltername(), DistIndex)
  148. End Sub
  149.  
  150.  
  151. Sub AddFilterNameToPathItem(ApplIndex as Integer, CollectIndex as Integer, sFiltername() as String, DistIndex as Integer)
  152. Dim iKey as Integer
  153. Dim CurListString as String
  154. Dim LocExtension as String
  155. Dim LocContentString as String
  156. Dim LocXMLTemplateContent as String
  157.     iKey = Applications(ApplIndex, SBAPPLKEY)
  158.     CurListString = PathCollection(CollectIndex, 2)
  159.     LocExtension = sFilterName(iKey +DistIndex, 0)
  160.     If Len(LocExtension) > SBMAXEXTENSIONLENGTH Then             ' 7 == Length of two extensions like 'sda|sdd
  161.         LocExtension = "vor"
  162.         LocContentString = sFilterName(iKey +DistIndex, 0)
  163.         LocContentString = ReplaceString(LocContentString, "|", ";")
  164.         LocXMLTemplateContent = PathCollection(CollectIndex, 3)
  165.         If LocXMLTemplateContent = "" Then
  166.             LocXMLTemplateContent = LocContentString
  167.         Else
  168.             LocXMLTemplateContent = LocXMLTemplateContent & "|" & LocContentString
  169.         End If
  170.         PathCollection(CollectIndex, 3) = LocXMLTemplateContent
  171.     End If
  172.     If CurListString = "" Then
  173.         PathCollection(CollectIndex, 2) = LocExtension
  174.     Else
  175.         If Instr(CurListString, LocExtension) = 0 Then
  176.             PathCollection(CollectIndex, 2) = CurListString & "|" & LocExtension
  177.         End If
  178.     End If
  179. End Sub
  180.  
  181.  
  182. Sub CheckIfToAddPathToCollection(ApplIndex as Integer, bDoConvertIndex as Integer, DocIndex as Integer, RecursiveIndex as Integer, sFiltername() as String, DistIndex as Integer)
  183. Dim CollectIndex as Integer
  184. Dim bCheckDocuType as Boolean
  185.     bCheckDocuType = Applications(ApplIndex, bDoConvertIndex)
  186.     If bCheckDocuType Then
  187.         CollectIndex = GetIndexInMultiArray(PathCollection(), Applications(ApplIndex,DocIndex), 0)
  188.         If (CollectIndex >-1) Then
  189.             If Applications(ApplIndex, RecursiveIndex) <> PathCollection(CollectIndex, 1) Then
  190.                 AddCollectionPath(ApplIndex, DocIndex, RecursiveIndex, sFilterName(), DistIndex)
  191.             Else
  192.                 AddFilterNameToPathItem(ApplIndex, CollectIndex, sFilterName(), DistIndex)
  193.             End If
  194.         Else
  195.             AddCollectionPath(ApplIndex, DocIndex, RecursiveIndex, sFilterName(), DistIndex)
  196.         End If
  197.     End If
  198. End Sub
  199.  
  200.  
  201. Sub CollectPaths(sFiltername() as String)
  202. Dim i as Integer
  203. Dim    XMLTemplateContentString as String
  204.     MaxCollectIndex = -1
  205.     For i = 0 To ApplCount-1
  206.         CheckIfToAddPathToCollection(i, SBDOCCONVERT, SBDOCSOURCE, SBDOCRECURSIVE, sFilterName(), 0)
  207.     Next i
  208.     XMLTemplateCount = 0
  209.     XMLTemplateContentString = ""
  210.     For i = 0 To ApplCount-1
  211.         If WizardMode = SBXMLMODE Then
  212.             XMLTemplateCount = XMLTemplateCount + 1
  213.         End If
  214.         CheckIfToAddPathToCollection(i, SBTEMPLCONVERT, SBTEMPLSOURCE, SBTEMPLRECURSIVE, sFilterName(), MaxApplCount)
  215.     Next i
  216. End Sub
  217.  
  218.  
  219. Sub ConvertAllDocuments(sFilterName() as String)
  220. Dim FileProperties(1) as new com.sun.star.beans.PropertyValue
  221. Dim PWFileProperties(2) as New com.sun.star.beans.PropertyValue
  222. Dim WriterWebProperties(0) as new com.sun.star.beans.PropertyValue
  223. Dim OpenProperties(4) as new com.sun.star.beans.PropertyValue
  224. Dim    oInteractionHandler as Object
  225. Dim InteractionTypes(0) as Long
  226. Dim FilesList(0,2) as String
  227. Dim sViewPath as String
  228. Dim i as Integer
  229. Dim FilterIndex as Integer
  230. Dim sSourceUrl as String
  231. Dim CurFilename as String
  232. Dim oDocument as Object
  233. Dim sExtension as String
  234. Dim OldExtension as String
  235. Dim CurFound as Integer
  236. Dim TotFound as Integer
  237. Dim TargetStemDir as String
  238. Dim SourceStemDir as String
  239. Dim TargetDir as String
  240. Dim sTargetUrl as String
  241. Dim CurFilterName as String
  242. Dim ApplIndex as Integer
  243. Dim Index as Integer
  244. Dim bIsDocument as Boolean
  245. Dim bDoSave as Boolean
  246. Dim sCurFileExists as String
  247. Dim MaxFileIndex as Integer
  248. Dim bContainsBasicMacro as Boolean
  249. Dim bIsPassWordProtected as Boolean
  250. Dim iOverwrite as Integer
  251. Dim sMimeTypeorExtension as String
  252.     bConversionisrunning = True
  253.     InteractionTypes(0) = com.sun.star.task.PasswordRequestMode.PASSWORD_REENTER
  254.     oInteractionHandler = createUnoService("com.sun.star.task.InteractionHandler")
  255.     oInteractionHandler.initialize(InteractionTypes())
  256.     iGeneralOverwrite = SBOVERWRITEUNDEFINED
  257.     bConversionIsRunning = True
  258.     bLogExists = false
  259.     AbsTemplateFound = 0
  260.     AbsDocuFound = 0
  261.     CollectPaths(sFiltername())
  262.     If Not ReadCollectionPaths(FilesList(), sFilterName()) Then
  263.         TotFound = 0
  264.         SetProgressDisplay(0)
  265.         bConversionisrunning = false
  266.         FinalizeDialogButtons()    
  267.         Exit Sub
  268.     End If
  269.     TotFound = Ubound(FilesList()) + 1             
  270.     If FilesList(0,0) = "" Then                    ' Querying the number of fields in a multidimensionl Array is unsecure
  271.         TotFound = 0                            ' because it will return the value 0 (and not -1) even when the Array is empty
  272.         SetProgressDisplay(0)
  273.     End If
  274.     If TotFound > 0 Then
  275.         CreateLogDocument(OpenProperties())
  276.         InitializeProgressPage(ImportDialog)
  277.         OpenProperties(0).Name = "Hidden"
  278.         OpenProperties(0).Value = True
  279.         OpenProperties(1).Name = "AsTemplate"
  280.         OpenProperties(1).Value = False
  281.         OpenProperties(2).Name = "MacroExecutionMode"
  282.         OpenProperties(2).Value = com.sun.star.document.MacroExecMode.NEVER_EXECUTE    
  283.         OpenProperties(3).Name = "UpdateDocMode"
  284.         OpenProperties(3).Value = com.sun.star.document.UpdateDocMode.NO_UPDATE
  285.         OpenProperties(4).Name = "InteractionHandler"
  286.         OpenProperties(4).Value = oInteractionHandler
  287.         MaxFileIndex = Ubound(FilesList(),1)
  288.         FileCount = 0
  289.         For i = 0 To MaxFileIndex
  290.             sComment = ""
  291.             If InterruptProcess() Then
  292.                 Exit For
  293.             End If
  294.             bDoSave = True
  295.             sSourceUrl = FilesList(i,0)
  296.             sMimeTypeorExtension = FilesList(i,1)
  297.             CurFiltername =    GetFilterName(sMimeTypeorExtension, sFilterName(), sExtension, FilterIndex)
  298.             ApplIndex = FilesList(i,2)
  299.             If ApplIndex > Ubound(Applications) or (ApplIndex < 0) Then
  300.                 Msgbox "Applicationindex out of bounds:" & sSourcUrl
  301.             End If
  302.             sViewPath = ConvertFromUrl(sSourceUrl)     ' CutPathView(sSourceUrl, 70)
  303.             ImportDialog.LabelCurDocument.Label = Str(i+1) & "/" & MaxFileIndex + 1 & "  (" & sViewPath & ")"
  304.             Select Case lcase(sExtension)
  305.                 Case "sxw", "sxc", "sxi", "sxd", "sxs", "sxm"
  306.                     SourceStemDir = RTrimStr(Applications(ApplIndex,SBDOCSOURCE), "/")
  307.                     TargetStemDir = RTrimStr(Applications(ApplIndex,SBDOCTARGET), "/")
  308.                 Case Else                                 ' Templates and Helper-Applications remain
  309.                     SourceStemDir = RTrimStr(Applications(ApplIndex,SBTEMPLSOURCE), "/")
  310.                     TargetStemDir = RTrimStr(Applications(ApplIndex,SBTEMPLTARGET), "/")
  311.             End Select
  312.             sTargetUrl = ReplaceString(sSourceUrl, TargetStemDir, SourceStemDir)
  313.             CurFilename = GetFileNameWithoutExtension(sTargetUrl, "/")
  314.             OldExtension = GetFileNameExtension(sTargetUrl)
  315.             sTargetUrl = RTrimStr(sTargetUrl, OldExtension)
  316.             sTargetUrl = sTargetUrl & sExtension
  317.             TargetDir = RTrimStr(sTargetUrl, CurFilename & "." & sExtension)
  318.             If (oUcb.Exists(sTargetUrl)) Then
  319.                 If (iGeneralOverwrite <> SBOVERWRITEALWAYS) Then
  320.                     If (iGeneralOverwrite = SBOVERWRITEUNDEFINED) Then
  321.                         ShowOverwriteAllDialog(sTargetUrl, sTitle)
  322.                         bDoSave = (iGeneralOverwrite = SBOVERWRITEQUERY) Or (iGeneralOverwrite = SBOVERWRITEALWAYS)
  323.                     Elseif iGeneralOverwrite = SBOVERWRITENEVER Then
  324.                         bDoSave = False                    
  325.                     ElseIf ((iGeneralOverWrite = SBOVERWRITEQUERY) OR (iGeneralOverwrite = SBOVERWRITECANCEL)) Then
  326.                         ' Todo: According to AS there might come a new feature that storeasUrl could possibly rise a UI dialog. 
  327.                         ' In this case my own UI becomes obsolete
  328.                         sCurFileExists = ReplaceString(sFileExists, ConvertFromUrl(sTargetUrl), "<1>")
  329.                         sCurFileExists = ReplaceString(sCurFileExists, chr(13), "<CR>")
  330.                         iOverWrite = Msgbox (sCurFileExists, 32 + 3, sTitle)
  331.                         Select Case iOverWrite
  332.                             Case 1    ' OK
  333.                                 ' In the FileProperty-Bean this is already default
  334.                                 bDoSave = True
  335.                             Case 2     ' Abort
  336.                                 CancelTask(False)
  337.                                 bDoSave = False
  338.                             Case 7     ' No
  339.                                 bDoSave = False
  340.                         End Select
  341.                     End If
  342.                 End If
  343.             End If
  344.             If bDoSave Then
  345.                 If Not oUcb.Exists(TargetDir) Then
  346.                     bDoSave = CreateFolder(TargetDir)
  347.                 End If
  348.                 If bDoSave Then
  349.                     oDocument = StarDesktop.LoadComponentFromURL(sSourceUrl, "_default", 0, OpenProperties())
  350.                     If Not IsNull(oDocument) Then
  351.                         InsertSourceUrlToLogDocument(sSourceUrl, "")
  352.                         bIsPassWordProtected = CheckPassWordProtection(oDocument)
  353.                         CheckIfMacroExists(oDocument.BasicLibraries, sComment)
  354.                         On Local Error Goto NOSAVING
  355.                         If bIsPassWordProtected Then
  356.                             PWFileProperties(0).Name = "FilterName"
  357.                             PWFileProperties(0).Value = CurFilterName
  358.                             PWFileProperties(1).Name = "Overwrite"
  359.                             PWFileProperties(1).Value = True
  360.                             PWFileProperties(2).Name = "Password"
  361.                             PWFileProperties(2).Value = sCurPassWord
  362.                             oDocument.StoreAsUrl(sTargetUrl, PWFileProperties())
  363.                         Else
  364.                             FileProperties(0).Name = "FilterName"
  365.                             FileProperties(0).Value = CurFilterName
  366.                             FileProperties(1).Name = "Overwrite"
  367.                             FileProperties(1).Value = True
  368.                             oDocument.StoreAsUrl(sTargetUrl,FileProperties())
  369.                         End If
  370.                         ' Todo: Make sure that an errorbox pops up when saving fails
  371.                         NOSAVING:
  372.                         If Err <> 0 Then
  373.                             sCurcouldnotsaveDocument = ReplaceString(scouldnotsaveDocument, ConvertFromUrl(sTargetUrl), "<1>")
  374.                             sComment = ConcatComment(sComment, sCurCouldnotsaveDocument)
  375.                             Resume LETSGO
  376.                             LETSGO:
  377.                         Else
  378.                             FileCount = FileCount + 1
  379.                         End If
  380.                         oDocument.Dispose()
  381.                         InsertTargetUrlToLogDocument(sTargetUrl, sComment)
  382.                     Else
  383.                         sCurcouldnotopenDocument = ReplaceString(scouldnotopenDocument, ConvertFromUrl(sSourceUrl), "<1>")
  384.                         sComment = ConcatComment(sComment, sCurCouldnotopenDocument)
  385.                         InsertSourceUrlToLogDocument(sSourceUrl, sComment)                
  386.                     End If
  387.                 End If
  388.             End If
  389.         Next i
  390.     End If
  391.     AddLogStatistics()
  392.     FinalizeDialogButtons()
  393.     bConversionIsRunning = False
  394.     Exit Sub
  395. RTError:
  396.     Msgbox sRTErrorDesc, 16, sRTErrorHeader
  397. End Sub
  398.  
  399.  
  400.  
  401. Sub AddListtoFilesList(FirstList(), SecList(), NewContentList() as String)
  402. Dim sLocExtension as String
  403. Dim FirstStart as Integer
  404. Dim FirstEnd as Integer
  405. Dim i as Integer
  406. Dim s as Integer
  407.     If FirstList(0,0) = "" Then
  408.         FirstStart = Ubound(FirstList(),1)
  409.     Else
  410.         FirstStart = Ubound(FirstList(),1) + 1
  411.     End If
  412.     FirstEnd = FirstStart + Ubound(SecList(),1)
  413.     ReDim Preserve FirstList(FirstEnd,2)
  414.     s = 0
  415.     For i = FirstStart To FirstEnd
  416.         FirstList(i,0) = SecList(s,0)
  417.         FirstList(i,1) = SecList(s,1)
  418.         sLocExtension = lcase(FirstList(i,1))
  419.         Select Case sLocExtension
  420.             Case "sdw", "sdc", "sda", "sdd", "smf", "sgl", "doc", "xls", "ppt"
  421.                 AbsDocuFound = AbsDocuFound + 1
  422.             Case else
  423.                 AbsTemplateFound = AbsTemplateFound + 1
  424.         End Select
  425.         FirstList(i,2) = CStr(NewContentList(s))
  426.         s = s + 1
  427.     Next i
  428.     SetProgressDisplay(Ubound(FirstList()) + 1)
  429. End Sub
  430.  
  431.  
  432.  
  433. Function GetTargetTemplatePath(Index as Integer)
  434.     Select Case WizardMode
  435.         Case SBMICROSOFTMODE
  436.             GetTargetTemplatePath() = SOTemplatePath & "/" & sTemplateGroupName
  437.         Case SBXMLMODE
  438.             If Index = 3 Then
  439.                 ' Helper Application
  440.                 GetTargetTemplatePath = SOWorkPath
  441.             Else
  442.                 GetTargetTemplatePath = SOTemplatePath
  443.             End If
  444.     End Select
  445. End Function
  446.  
  447.  
  448. ' Retrieves the second value for a next to 'SearchString' in
  449. ' a two-dimensional string-Array
  450. Function GetFilterName(sMimetypeorExtension as String, sFilterName(), sExtension as string, FilterIndex as Integer) as String
  451. Dim i as Integer
  452. Dim MaxIndex as Integer
  453. Dim sLocFilterlist() as String
  454.     For i = 0 To Ubound(sFiltername(),1)
  455.         If Instr(1,sFilterName(i,0),sMimeTypeOrExtension) <> 0 Then
  456.             sLocFilterList() = ArrayoutofString(sFiltername(i,0),"|", MaxIndex)
  457.             If MaxIndex = 0 Then
  458.                 sExtension = sFiltername(i,2)
  459.                 GetFilterName = sFilterName(i,1)
  460.             Else
  461.                 Dim b as Integer
  462.                 Dim sLocExtensionList() as String
  463.                 b =    SearchArrayForPartString(sMimetypeOrExtension, sLocFilterList())
  464.                 sLocFilterList() = ArrayoutofString(sFiltername(i,1),"|", MaxIndex)
  465.                 GetFilterName = sLocFilterList(b)
  466.                 sLocExtensionList() = ArrayoutofString(sFilterName(i,2), "|", MaxIndex)
  467.                 sExtension = sLocExtensionList(b)
  468.             End If
  469.             Exit For
  470.         End If
  471.     Next
  472.     FilterIndex = i
  473. End Function
  474.  
  475.  
  476. Function SearchArrayforPartString(SearchString as String, LocList()) as Integer
  477. Dim i as Integer
  478. Dim a as Integer
  479. Dim StringList() as String
  480.     For i = Lbound(LocList(),1) to Ubound(LocList(),1)
  481.         StringList() = ArrayoutofString(LocList(i), "|")
  482.         For a = 0 To Ubound(StringList())
  483.             If (Instr(1, SearchString, StringList(a)) <> 0) Then
  484.                 SearchArrayForPartString() = i
  485.                 Exit Function
  486.             End If
  487.         Next a
  488.     Next i
  489.     SearchArrayForPartString() = -1    
  490. End Function
  491.  
  492.  
  493. Sub CreateLogDocument(HiddenProperties())
  494. Dim OpenProperties(0) as new com.sun.star.beans.PropertyValue
  495. Dim oTableCursor as Object
  496. Dim oLogCursor as Object
  497. Dim oLogRows as Object
  498. Dim NoArgs()
  499. Dim i as Integer
  500. Dim bLogIsThere as Boolean
  501.     If ImportDialog.chkLogfile.State = 1 Then
  502.         i = 2
  503.         OpenProperties(0).Name = "Hidden"
  504.         OpenProperties(0).Value = True
  505.         oLogDocument = StarDesktop.LoadComponentFromURL("private:factory/swriter", "_default", 4, OpenProperties())
  506.         oLogCursor = oLogDocument.Text.CreateTextCursor
  507.         oLogTable =  oLogDocument.CreateInstance("com.sun.star.text.TextTable")
  508.         oLogTable.RepeatHeadline = true
  509.         oLogCursor.Text.InsertTextContent(oLogCursor, oLogTable, True)
  510.         oLogCursor = oLogTable.GetCellbyPosition(0,0).createTextCursor()
  511.         oLogCursor.SetString(sSourceDocuments)
  512.         oLogCursor = oLogTable.GetCellbyPosition(1,0).createTextCursor()
  513.         oLogCursor.SetString(sTargetDocuments)
  514.         bInsertRow = False
  515.         sLogUrl = SOWorkPath & "/Logfile.sxw"
  516.         Do
  517.             bLogIsThere = oUcb.Exists(sLogUrl)
  518.             If bLogIsThere Then
  519.                 If i = 2 Then
  520.                     sLogUrl = ReplaceString(sLogUrl, "/Logfile_2.sxw", "/Logfile.sxw")
  521.                 Else
  522.                     sLogUrl = ReplaceString(sLogUrl, "/Logfile_" & cStr(i) & ".sxw", "/Logfile_" & cStr(i-1) & ".sxw")
  523.                 End If
  524.                 i = i + 1
  525.             End If
  526.         Loop Until Not bLogIsThere
  527.         bLogExists = True
  528.         oLogDocument.StoreAsUrl(sLogUrl, NoArgs())
  529.     End If
  530. End Sub
  531.  
  532.  
  533. Sub InsertTargetUrlToLogDocument(sTargetUrl as String, sComment as String)
  534. Dim oCell as Object
  535.     If (bLogExists) And (sTargetUrl <> "") Then
  536.         If sTargetUrl <> "" Then
  537.             oCell = oLogTable.GetCellbyPosition(1,oLogTable.Rows.Count-1)
  538. '            If ((TargetUrl <>"") AND (i = 1)) Or ((TargetUrl = "") AND (i = 0)) Then
  539.                 InsertCommentToLogCell(sComment, oCell)
  540. '            End  If
  541.             InsertHyperLinkToLogCell(sTargetUrl, oCell)
  542.             oLogDocument.Store()
  543.         End If
  544.     End If
  545. End Sub
  546.  
  547.  
  548. Sub InsertSourceUrlToLogDocument(SourceUrl as String, sComment)        '
  549. Dim oCell as Object
  550.     If bLogExists Then
  551.         If bInsertRow Then
  552.             oLogTable.Rows.InsertByIndex(oLogTable.Rows.Count,1)
  553.         Else
  554.             bInsertRow = True
  555.         End If
  556.         oCell = oLogTable.GetCellbyPosition(0,oLogTable.Rows.Count-1)
  557.         InsertCommentToLogCell(sComment, oCell)
  558.         InsertHyperLinkToLogCell(SourceUrl, oCell)
  559.         oLogDocument.Store()
  560.     End If
  561. End Sub
  562.  
  563.  
  564. Sub InsertHyperLinkToLogCell(sUrl as String, oCell as Object)
  565. Dim oLogCursor as Object
  566. Dim LocFileName as String
  567.     oLogCursor = oCell.createTextCursor()
  568.     oLogCursor.CollapseToStart()
  569.     oLogCursor.HyperLinkURL = sUrl
  570.     oLogCursor.HyperLinkName = sUrl
  571.     oLogCursor.HyperLinkTarget = sUrl
  572.     LocFileName = FileNameOutOfPath(sUrl)
  573.     oCell.InsertString(oLogCursor, LocFileName,False)
  574. End Sub            
  575.  
  576.  
  577. Sub InsertCommentToLogCell(sComment as string, oCell as Object)
  578. Dim oCommentCursor as Object
  579.     If sComment <> "" Then
  580.         oCommentCursor = oCell.createTextCursor()
  581.         oCell.insertControlCharacter(oCommentCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
  582.         oCell.insertString(oCommentCursor, sComment, false)
  583.     End If
  584. End Sub
  585.  
  586.  
  587. Sub AddLogStatistics()
  588. Dim oCell as Object
  589. Dim oLogCursor as Object
  590. Dim MaxRowIndex as Integer
  591.     If bLogExists Then
  592.         MaxRowIndex = oLogTable.Rows.Count
  593.         sLogSummary = ReplaceString(sLogSummary, FileCount, "<COUNT>")
  594.         oLogTable.Rows.InsertByIndex(MaxRowIndex, 1)
  595.         oCell = oLogTable.GetCellbyPosition(0, MaxRowIndex)
  596.         oLogCursor = oCell.createTextCursor()
  597.         oCell.InsertString(oLogCursor, sLogSummary,False)
  598.         MergeRange(oLogTable, oCell, 1)        
  599.         oLogDocument.Store()
  600.         oLogDocument.Dispose()
  601.         bLogExists = False
  602.     End If
  603. End Sub
  604.  
  605.  
  606.  
  607. Function CheckIfMacroExists(oBasicLibraries as Object, sComment as String) as Boolean
  608. Dim ModuleNames() as String
  609. Dim ModuleName as String
  610. Dim MaxLibIndex as Integer
  611. Dim MaxModuleIndex as Integer
  612. Dim bMacroExists as Boolean
  613. Dim n as Integer
  614. Dim m as Integer
  615. Dim LibName as String
  616. Dim sBasicCode as String
  617. Dim oLibrary as Object
  618.     bMacroExists = False
  619.     bMacroExists = oBasicLibraries.hasElements
  620.     If bMacroExists Then
  621.         MaxLibIndex = Ubound(oBasicLibraries.ElementNames())
  622.         For n = 0 To MaxLibIndex
  623.             LibName = oBasicLibraries.ElementNames(n)
  624.             oLibrary = oBasicLibraries.getbyName(LibName)
  625.             If oLibrary.hasElements() Then
  626.                 MaxModuleIndex = Ubound(oLibrary.ElementNames())
  627.                 For m = 0 To MaxModuleIndex
  628.                     ModuleName = oLibrary.ElementNames(m)
  629.                     sBasicCode = oLibrary.getbyName(ModuleName)
  630.                     If sBasicCode <> "" Then
  631.                         ConcatComment(sComment, sReeditMacro)
  632.                         CheckIfMacroExists() = True
  633.                         Exit Function
  634.                     End If
  635.                 Next m
  636.             End If
  637.         Next n
  638.     End If
  639.     CheckIfMacroExists() = False
  640. End Function
  641.  
  642.  
  643.  
  644. Function CheckPassWordProtection(oDocument as Object)
  645. Dim bIsPassWordProtected as Boolean
  646. Dim i as Integer
  647. Dim oArgs()
  648. Dim MaxIndex as Integer
  649. Dim sblabla as String
  650.     bIsPassWordProtected = false
  651.      oArgs() = oDocument.getArgs()
  652.      MaxIndex = Ubound(oArgs())
  653.     For i = 0 To MaxIndex
  654.         sblabla = oArgs(i).Name
  655.         If oArgs(i).Name = "Password" Then
  656.             bIsPassWordProtected = True
  657.             sCurPassWord = oArgs(i).Value
  658.             Exit For
  659.         End If
  660.     Next i
  661.     CheckPassWordProtection() = bIsPassWordProtected
  662. End Function
  663.  
  664.  
  665. Sub OpenLogDocument()
  666. Dim NoArgs() as New com.sun.star.beans.PropertyValue
  667.     OpenDocument(sLogUrl, NoArgs())
  668. End Sub
  669.  
  670.  
  671. Sub MergeRange(oTable as Object, oCell as Object, MergeCount as Integer)    
  672. Dim oTableCursor as Object
  673.     oTableCursor = oTable.createCursorByCellName(oCell.CellName)
  674.     oTableCursor.goRight(MergeCount, True)
  675.     oTableCursor.mergeRange()
  676. End Sub        
  677.  
  678.  
  679. Function ConcatComment(sComment as String, AdditionalComment as String)
  680.     If sComment = "" Then
  681.         sComment = AdditionalComment
  682.     Else
  683.         sComment = sComment & chr(13) + AdditionalComment
  684.     End If                
  685.     ConcatComment = sComment
  686. End Function
  687. </script:module>