home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2002 October / VPR0210A.ISO / OPENOFFICE / f_0255 / FilesModul.xba < prev    next >
Extensible Markup Language  |  2002-02-19  |  13KB  |  355 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 bInsertRow as Boolean
  10.  
  11. Function ReadApplicationDirectories(ApplIndex as Integer, FilesList(),bIsDocument as Boolean, sFiltername()) as Integer
  12. Dim bCheckDocuType as Boolean
  13. Dim FilterIndex as Integer
  14. Dim bRecursive as Boolean
  15. Dim sSourceDir as String
  16. Dim bCheckRealType as Boolean
  17. Dim a as Integer
  18. Dim sFileContent() as String
  19. Dim NewList() as String
  20. Dim Index as Integer
  21. Dim sLocExtension as String
  22.     Index = Applications(ApplIndex,SBAPPLKEY)
  23.     sLocExtension = ""
  24.     If bIsDocument Then
  25.         bCheckDocuType = Applications(ApplIndex,SBDOCCONVERT)
  26.         bCheckRealType = False
  27.         bRecursive = Applications(ApplIndex,SBDOCRECURSIVE)
  28.         FilterIndex = Index
  29.         sSourceDir = Applications(ApplIndex,SBDOCSOURCE)
  30.     Else
  31.         ' Templates
  32.         bCheckDocuType = Applications(ApplIndex,SBTEMPLCONVERT)
  33.         ' In SO the documenttype cannot be derived from the extension name
  34.         bCheckRealType = WizardMode = SBXMLMODE
  35.         If bCheckRealType Then
  36.             ' Note: StarOffice-Math-Documents cannot be treated like templates
  37.             bCheckRealType = Index <> 3
  38.             If bCheckRealType Then
  39.                 sLocExtension = "vor"
  40.             End If
  41.             bIsDocument = Not bCheckRealType
  42.         End If
  43.         bRecursive = Applications(ApplIndex,SBTEMPLRECURSIVE)
  44.         FilterIndex = Index + MaxApplCount
  45.         sSourceDir = Applications(ApplIndex,SBTEMPLSOURCE)
  46.     End If
  47.     If bCheckDocuType Then
  48.         sFileContent() = GetMimeTypeList(sFilterName(FilterIndex))
  49.         NewList() = ReadDirectories(sSourceDir, bRecursive, bCheckRealType, False, sFileContent(), sLocExtension)
  50.         If Ubound(NewList()) > -1 Then
  51.             AddListtoFilesList(FilesList(), NewList(), ApplIndex)
  52.             ImportDialog.LabelRetrieval.Label = sProgressPage_2 &  "  " & ReplaceString(sProgressPage_5, Str(Ubound(FilesList()) + 1) & " ", "%1")
  53.         End If
  54.     End If
  55.     ReadApplicationDirectories() = Ubound(NewList(),1) + 1
  56. End Function
  57.  
  58.  
  59. Sub    ShowCurrentProgress(bIsDocument as Boolean, CurFound as Integer)
  60.     If bIsDocument Then
  61.         AbsDocuFound = AbsDocuFound + CurFound
  62.         ImportDialog.LabelCurDocumentRetrieval.Label =  sProgressFound & " " & CStr(AbsDocuFound) &  " " & sProgressMoreDocs
  63.     Else
  64.         AbsTemplateFound = AbsTemplateFound + CurFound
  65.         ImportDialog.LabelCurTemplateRetrieval.Label = sProgressFound & " " & CStr(AbsTemplateFound) & " " & sProgressMoreTemplates
  66.   End If
  67. End Sub
  68.  
  69.  
  70. Sub ConvertAllDocuments(sFilterName())
  71. Dim FileProperties(0) as new com.sun.star.beans.PropertyValue
  72. Dim WriterWebProperties(0) as new com.sun.star.beans.PropertyValue
  73. Dim OpenProperties(1) as new com.sun.star.beans.PropertyValue
  74. Dim FilesList(0,2) as String
  75. Dim sViewPath as String
  76. Dim i as Integer
  77. Dim FilterIndex as Integer
  78. Dim sFullName as String
  79. Dim sFileName as String
  80. Dim oDocument as Object
  81. Dim sExtension as String
  82. Dim OldExtension as String
  83. Dim CurFound as Integer
  84. Dim TotFound as Integer
  85. Dim TargetStemDir as String
  86. Dim SourceStemDir as String
  87. Dim TargetDir as String
  88. Dim TargetFile as String
  89. Dim CurFilterName as String
  90. Dim ApplIndex as Integer
  91. Dim Index as Integer
  92. Dim bIsDocument as Boolean
  93. Dim iOverWrite as Integer
  94. Dim bDoSave as Boolean
  95. Dim sCurFileExists as String
  96. Dim oModel as Object
  97. Dim MaxFileIndex as Integer
  98. Dim sOldExtension as String
  99.     bConversionIsRunnig = True
  100.     AbsTemplateFound = 0
  101.     AbsDocuFound = 0
  102.     For i = 0 To ApplCount-1
  103.         'templates
  104.         bIsDocument = False
  105.         CurFound = ReadApplicationDirectories(i, FilesList(), bIsDocument, sFilterName())
  106.         ShowCurrentProgress(bIsDocument, CurFound)
  107.     Next i
  108.     For i = 0 To ApplCount-1
  109.         'documents
  110.         bIsDocument = True
  111.         CurFound = ReadApplicationDirectories(i, FilesList(), bIsDocument, sFilterName())
  112.         ShowCurrentProgress(bIsDocument, CurFound)
  113.     Next i
  114.     TotFound = AbsTemplateFound + AbsDocuFound
  115.     CreateLogDocument(OpenProperties())
  116.     If TotFound > 0 Then
  117.         InitializeProgressPage(ImportDialog)
  118.         OpenProperties(0).Name = "Hidden"
  119.         OpenProperties(0).Value = True
  120.         OpenProperties(1).Name = "AsTemplate"
  121.         MaxFileIndex = Ubound(FilesList(),1)
  122.         For i = 0 To MaxFileIndex
  123.             If bCancelTask Or RetValue = 0 Then
  124.                 bConversionIsRunnig = False
  125.                 Exit Sub
  126.             End if
  127.             bDoSave = True
  128.             sFullName = FilesList(i,0)
  129.             CurFiltername =    GetFilterName(FilesList(i,1), sFilterName(), sExtension, FilterIndex)
  130.             ApplIndex = FilesList(i,2)
  131.             sViewPath = CutPathView(sFullName, 60)
  132.             ImportDialog.LabelCurDocument.Label = Str(i+1) & "/" & MaxFileIndex + 1 & "  (" & sViewPath & ")"
  133.             
  134.             sOldExtension = GetFileNameExtension(sFullName, "/")
  135.             Select Case sOldExtension
  136.                 Case "vor", "dot", "xlt", "pot"
  137.                     OpenProperties(1).Value = False
  138.                 Case Else
  139.                     OpenProperties(1).Value = False
  140.             End Select
  141.             oDocument = StarDesktop.LoadComponentFromURL(sFullName, "_blank", 0, OpenProperties())
  142.             If bSetFonts Then
  143.                 CheckScripts(oDocument, 1)
  144.             End If
  145.  
  146.             If Not IsNull(oDocument) Then
  147.                 Select Case sExtension
  148.                     Case "sxw", "sxc", "sxi", "sxd", "sxs", "sxm"
  149.                         SourceStemDir = RTrimStr(Applications(ApplIndex,SBDOCSOURCE), "/")
  150.                         TargetStemDir = RTrimStr(Applications(ApplIndex,SBDOCTARGET), "/")
  151.                     Case Else                                 ' Templates and Helper-Applications remain
  152.                         SourceStemDir = RTrimStr(Applications(ApplIndex,SBTEMPLSOURCE), "/")
  153.                         TargetStemDir = RTrimStr(Applications(ApplIndex,SBTEMPLTARGET), "/")
  154.                 End Select
  155.  
  156.                 TargetFile = ReplaceString(sFullname, TargetStemDir, SourceStemDir)
  157.                 sFileName = GetFileNameWithoutExtension(TargetFile, "/")
  158.                 OldExtension = GetFileNameExtension(TargetFile)
  159.  
  160.                 TargetFile = RTrimStr(TargetFile, OldExtension)
  161.                 TargetFile = TargetFile & sExtension
  162.                 TargetDir = RTrimStr(TargetFile, sFileName & "." & sExtension)
  163.                 If Not oUcb.Exists(TargetDir) Then
  164.                     CreateFolder(TargetDir)
  165.                 End If
  166.                 If oUcb.Exists(TargetFile) Then
  167.                     sCurFileExists = ReplaceString(sFileExists, ConvertFromUrl(TargetFile), "<1>")
  168.                     sCurFileExists = ReplaceString(sCurFileExists, chr(13), "<CR>")
  169.                     iOverWrite = Msgbox (sCurFileExists, 32 + 3, sTitle)
  170.                     Select Case iOverWrite
  171.                         Case 1    ' OK
  172.                             ' In the FileProperty-Bean this is already default
  173.                             bDoSave = True
  174.                         Case 2     ' Abort
  175.                             CancelTask(False)
  176.                             bDoSave = False
  177.                         Case 7     ' No
  178.                             bDoSave = False
  179.                     End Select
  180.                 End If
  181.                 If bDoSave Then
  182.                     InsertDocNamesToLogDocument(sFullName, TargetFile)
  183.                     On Local Error Resume Next
  184.                     FileProperties(0).Name = "FilterName"
  185.                     FileProperties(0).Value = CurFilterName
  186.                     oDocument.StoreAsUrl(TargetFile,FileProperties())
  187.                     oDocument.Dispose()
  188.                     On Local Error Goto 0
  189.                 End If
  190.             End If
  191.         Next i
  192.     End If
  193.     ImportDialog.cmdCancel.Label = sCloseButton
  194.     ImportDialog.cmdGoOn.Label = sReady
  195.     ImportDialog.cmdGoOn.Enabled = True
  196.     bConversionIsRunnig = False
  197.     Exit Sub
  198. RTError:
  199.     Msgbox sRTErrorDesc, 16, sRTErrorHeader
  200. End Sub
  201.  
  202.  
  203. Sub AddListtoFilesList(FirstList(), SecList(), ApplIndex as Integer)
  204. Dim FirstStart as Integer, FirstEnd as Integer, i as Integer, s as Integer
  205.     If FirstList(0,0) = "" Then
  206.         FirstStart = Ubound(FirstList(),1)
  207.     Else
  208.         FirstStart = Ubound(FirstList(),1) + 1
  209.     End If
  210.     FirstEnd = FirstStart + Ubound(SecList(),1)
  211.     ReDim Preserve FirstList(FirstEnd,2)
  212.     s = 0
  213.     For i = FirstStart To FirstEnd
  214.         FirstList(i,0) = SecList(s,0)
  215.         FirstList(i,1) = SecList(s,1)
  216.         FirstList(i,2) = CStr(ApplIndex)
  217.         s = s + 1
  218.     Next i
  219. End Sub
  220.  
  221.  
  222. Function GetTargetTemplatePath(Index as Integer)
  223.     Select Case WizardMode
  224.         Case SBMICROSOFTMODE
  225.             GetTargetTemplatePath() = SOTemplatePath & "/" & sTemplateGroupName
  226.         Case SBXMLMODE
  227.             If Index = 3 Then
  228.                 ' Helper Application
  229.                 GetTargetTemplatePath = SOWorkPath
  230.             Else
  231.                 GetTargetTemplatePath = SOTemplatePath
  232.             End If
  233.     End Select
  234. End Function
  235.  
  236.  
  237. ' Retrieves the second value for a next to 'SearchString' in
  238. ' a two-dimensional string-Array
  239. Function GetFilterName(sMimetypeorExtension as String, sFilterName(), sExtension as string, FilterIndex as Integer) as String
  240. Dim i as Integer
  241. Dim MaxIndex as Integer
  242. Dim sLocFilterlist() as String
  243.     For i = 0 To Ubound(sFiltername(),1)
  244.         If Instr(1,sFilterName(i,0),sMimeTypeOrExtension) <> 0 Then
  245.             sLocFilterList() = ArrayoutofString(sFiltername(i,0),"|", MaxIndex)
  246.             If MaxIndex = 0 Then
  247.                 sExtension = sFiltername(i,2)
  248.                 GetFilterName = sFilterName(i,1)
  249.             Else
  250.                 Dim a as Integer
  251.                 Dim sLocExtensionList() as String
  252.                 a =    SearchArrayForPartString(sMimetypeOrExtension, sLocFilterList())
  253.                 sLocFilterList() = ArrayoutofString(sFiltername(i,1),"|", MaxIndex)
  254.                 GetFilterName = sLocFilterList(a)
  255.                 sLocExtensionList() = ArrayoutofString(sFilterName(i,2), "|", MaxIndex)
  256.                 sExtension = sLocExtensionList(a)
  257.             End If
  258.             Exit For
  259.         End If
  260.     Next
  261.     FilterIndex = i
  262. End Function
  263.  
  264.  
  265. Function SearchArrayforPartString(SearchString as String, LocList()) as Integer
  266. Dim i as integer
  267.     For i = Lbound(LocList(),1) to Ubound(LocList(),1)
  268.         If Instr(1,LocList(i), SearchString) <> 0 Then
  269.             SearchArrayForPartString() = i
  270.             Exit Function
  271.         End if
  272.     Next
  273.     IndexinArray = -1
  274. End Function
  275.  
  276.  
  277. Function GetMimeTypeList(BigFiltername as STring)
  278. Dim sBigList() as String
  279. Dim sSmallList() as String
  280. Dim sMimeTypeList()
  281. Dim BigMaxIndex as Integer
  282. Dim n as Integer
  283.     sBigList() = ArrayoutofString(BigFilterName,"|", BigMaxIndex)
  284.     For n = 0 To BigMaxIndex
  285.         sSmallList() = ArrayoutofString(sBigList(n),";")
  286.         sMimeTypeList() = AddListToList(sMimeTypeList(), sSmallList())
  287.     Next n
  288.     GetMimetypeList() = sMimeTypeList()
  289. End Function
  290.  
  291.  
  292. Sub CreateLogDocument(HiddenProperties())
  293. Dim oTableCursor as Object
  294. Dim oLogCursor as Object
  295. Dim oLogRows as Object
  296. Dim sLogUrl as String
  297. Dim NoArgs()
  298. Dim i as Integer
  299. Dim bLogExists as Boolean
  300.     If ImportDialog.chkLogfile.State = 1 Then
  301.         i = 2
  302.         oLogDocument = StarDesktop.LoadComponentFromURL("private:factory/swriter", "_blank", 4, NoArgs())' HiddenProperties()) ' HiddenProperties())
  303.         oLogCursor = oLogDocument.Text.CreateTextCursor
  304.         oLogTable =  oLogDocument.CreateInstance("com.sun.star.text.TextTable")
  305.         oLogCursor.Text.InsertTextContent(oLogCursor, oLogTable, True)
  306.         oLogCursor = oLogTable.GetCellbyPosition(0,0).createTextCursor
  307.         oLogCursor.SetString(sSourceDocuments)
  308.         oLogCursor = oLogTable.GetCellbyPosition(1,0).createTextCursor
  309.         oLogCursor.SetString(sTargetDocuments)
  310.         bInsertRow = False
  311.         sLogUrl = SOWorkPath & "/Logfile.sxw"
  312.         Do
  313.             bLogExists = oUcb.Exists(sLogUrl)
  314.             If bLogExists Then
  315.                 If i = 2 Then
  316.                     sLogUrl = ReplaceString(sLogUrl, "/Logfile_2.sxw", "/Logfile.sxw")
  317.                 Else
  318.                     sLogUrl = ReplaceString(sLogUrl, "/Logfile_" & cStr(i) & ".sxw", "/Logfile_" & cStr(i-1) & ".sxw")
  319.                 End If
  320.                 i = i + 1
  321.             End If
  322.         Loop Until Not bLogExists
  323.         oLogDocument.StoreAsUrl(sLogUrl, NoArgs())
  324.     EndIf
  325. End Sub
  326.  
  327.  
  328. Sub InsertDocNamesToLogDocument(SourceUrl as String, TargetUrl as String)
  329. Dim oCell as Object
  330. Dim oLogCursor as Object
  331. Dim UrlList(1) as String
  332. Dim LocFileName as String
  333. Dim LocUrl as String
  334. Dim i as Integer
  335.     If ImportDialog.chkLogfile.State = 1 Then
  336.         If bInsertRow Then
  337.             oLogTable.Rows.InsertByIndex(oLogTable.Rows.Count,1)
  338.         Else
  339.             bInsertRow = True
  340.         End If
  341.         UrlList(0) = SourceUrl
  342.         UrlList(1) = TargetUrl
  343.         For i = 0 To 1
  344.             oCell = oLogTable.GetCellbyPosition(i,oLogTable.Rows.Count-1)
  345.             oLogCursor = oCell.createTextCursor()
  346.             LocUrl = UrlList(i)
  347.             oLogCursor.HyperLinkURL = LocUrl
  348.             oLogCursor.HyperLinkName = LocUrl
  349.             oLogCursor.HyperLinkTarget = LocUrl
  350.             LocFileName = FileNameOutOfPath(LocUrl)
  351.             oCell.InsertString(oLogCursor, LocFileName,False)
  352.         Next i 
  353.         oLogDocument.Store()
  354.     End If
  355. End Sub</script:module>