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