2001-04-23 04:46:42 -05:00
<?xml version="1.0" encoding="UTF-8"?>
2001-05-30 11:08:07 -05:00
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
2002-01-11 02:49:32 -06:00
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="FilesModul" script:language="StarBasic">Option Explicit
2001-04-23 04:46:42 -05:00
Public AbsTemplateFound as Integer
Public AbsDocuFound as Integer
2001-05-21 09:52:58 -05:00
Public oLogDocument as Object
Public oLogTable as Object
2001-08-09 10:35:42 -05:00
Public bInsertRow as Boolean
2001-04-23 04:46:42 -05:00
Function ReadApplicationDirectories(ApplIndex as Integer, FilesList(),bIsDocument as Boolean, sFiltername()) as Integer
Dim bCheckDocuType as Boolean
Dim FilterIndex as Integer
Dim bRecursive as Boolean
Dim sSourceDir as String
Dim bCheckRealType as Boolean
Dim a as Integer
Dim sFileContent() as String
2001-05-21 09:52:58 -05:00
Dim NewList() as String
2001-04-23 04:46:42 -05:00
Dim Index as Integer
Dim sLocExtension as String
2001-05-21 09:52:58 -05:00
Index = Applications(ApplIndex,SBAPPLKEY)
2001-04-23 04:46:42 -05:00
sLocExtension = ""
If bIsDocument Then
2001-05-21 09:52:58 -05:00
bCheckDocuType = Applications(ApplIndex,SBDOCCONVERT)
2001-04-23 04:46:42 -05:00
bCheckRealType = False
2001-05-21 09:52:58 -05:00
bRecursive = Applications(ApplIndex,SBDOCRECURSIVE)
2001-04-23 04:46:42 -05:00
FilterIndex = Index
2001-05-21 09:52:58 -05:00
sSourceDir = Applications(ApplIndex,SBDOCSOURCE)
2001-04-23 04:46:42 -05:00
Else
' Templates
2001-05-21 09:52:58 -05:00
bCheckDocuType = Applications(ApplIndex,SBTEMPLCONVERT)
2001-04-23 04:46:42 -05:00
' In SO the documenttype cannot be derived from the extension name
bCheckRealType = WizardMode = SBXMLMODE
If bCheckRealType Then
' Note: StarOffice-Math-Documents cannot be treated like templates
bCheckRealType = Index <> 3
If bCheckRealType Then
sLocExtension = "vor"
End If
bIsDocument = Not bCheckRealType
End If
2001-05-21 09:52:58 -05:00
bRecursive = Applications(ApplIndex,SBTEMPLRECURSIVE)
2001-04-23 04:46:42 -05:00
FilterIndex = Index + MaxApplCount
2001-05-21 09:52:58 -05:00
sSourceDir = Applications(ApplIndex,SBTEMPLSOURCE)
2001-04-23 04:46:42 -05:00
End If
If bCheckDocuType Then
sFileContent() = GetMimeTypeList(sFilterName(FilterIndex))
NewList() = ReadDirectories(sSourceDir, bRecursive, bCheckRealType, False, sFileContent(), sLocExtension)
2001-05-21 09:52:58 -05:00
If Ubound(NewList()) > -1 Then
2001-07-12 04:39:01 -05:00
AddListtoFilesList(FilesList(), NewList(), ApplIndex)
2001-06-21 08:14:32 -05:00
ImportDialog.LabelRetrieval.Label = sProgressPage_2 & " " & ReplaceString(sProgressPage_5, Str(Ubound(FilesList()) + 1) & " ", "%1")
2001-05-21 09:52:58 -05:00
End If
2001-04-23 04:46:42 -05:00
End If
2001-05-21 09:52:58 -05:00
ReadApplicationDirectories() = Ubound(NewList(),1) + 1
2001-04-23 04:46:42 -05:00
End Function
Sub ShowCurrentProgress(bIsDocument as Boolean, CurFound as Integer)
If bIsDocument Then
AbsDocuFound = AbsDocuFound + CurFound
ImportDialog.LabelCurDocumentRetrieval.Label = sProgressFound & " " & CStr(AbsDocuFound) & " " & sProgressMoreDocs
Else
AbsTemplateFound = AbsTemplateFound + CurFound
ImportDialog.LabelCurTemplateRetrieval.Label = sProgressFound & " " & CStr(AbsTemplateFound) & " " & sProgressMoreTemplates
End If
End Sub
2001-05-21 09:52:58 -05:00
2001-04-23 04:46:42 -05:00
Sub ConvertAllDocuments(sFilterName())
2001-08-15 06:50:32 -05:00
Dim FileProperties(0) as new com.sun.star.beans.PropertyValue
Dim WriterWebProperties(0) as new com.sun.star.beans.PropertyValue
Dim OpenProperties(1) as new com.sun.star.beans.PropertyValue
2001-05-21 09:52:58 -05:00
Dim FilesList(0,2) as String
2001-04-23 04:46:42 -05:00
Dim sViewPath as String
Dim i as Integer
Dim FilterIndex as Integer
Dim sFullName as String
Dim sFileName as String
Dim oDocument as Object
Dim sExtension as String
Dim OldExtension as String
Dim CurFound as Integer
2001-06-21 08:14:32 -05:00
Dim TotFound as Integer
2001-04-23 04:46:42 -05:00
Dim TargetStemDir as String
Dim SourceStemDir as String
Dim TargetDir as String
Dim TargetFile as String
Dim CurFilterName as String
Dim ApplIndex as Integer
Dim Index as Integer
Dim bIsDocument as Boolean
Dim iOverWrite as Integer
Dim bDoSave as Boolean
Dim sCurFileExists as String
Dim oModel as Object
2001-05-21 09:52:58 -05:00
Dim MaxFileIndex as Integer
2001-08-10 09:15:50 -05:00
Dim sOldExtension as String
2001-08-10 03:28:06 -05:00
bConversionIsRunnig = True
2001-04-23 04:46:42 -05:00
AbsTemplateFound = 0
AbsDocuFound = 0
For i = 0 To ApplCount-1
'templates
bIsDocument = False
CurFound = ReadApplicationDirectories(i, FilesList(), bIsDocument, sFilterName())
ShowCurrentProgress(bIsDocument, CurFound)
Next i
For i = 0 To ApplCount-1
'documents
bIsDocument = True
CurFound = ReadApplicationDirectories(i, FilesList(), bIsDocument, sFilterName())
ShowCurrentProgress(bIsDocument, CurFound)
Next i
2001-06-21 08:14:32 -05:00
TotFound = AbsTemplateFound + AbsDocuFound
2001-08-09 10:35:42 -05:00
CreateLogDocument(OpenProperties())
2001-06-21 08:14:32 -05:00
If TotFound > 0 Then
InitializeProgressPage(ImportDialog)
OpenProperties(0).Name = "Hidden"
OpenProperties(0).Value = True
2001-08-15 06:50:32 -05:00
OpenProperties(1).Name = "AsTemplate"
2001-06-21 08:14:32 -05:00
MaxFileIndex = Ubound(FilesList(),1)
For i = 0 To MaxFileIndex
2002-01-11 02:49:32 -06:00
If bCancelTask Or RetValue = 0 Then
2001-08-10 03:28:06 -05:00
bConversionIsRunnig = False
Exit Sub
2001-06-21 08:14:32 -05:00
End if
2001-08-10 03:28:06 -05:00
bDoSave = True
2001-06-21 08:14:32 -05:00
sFullName = FilesList(i,0)
CurFiltername = GetFilterName(FilesList(i,1), sFilterName(), sExtension, FilterIndex)
ApplIndex = FilesList(i,2)
sViewPath = CutPathView(sFullName, 60)
ImportDialog.LabelCurDocument.Label = Str(i+1) & "/" & MaxFileIndex + 1 & " (" & sViewPath & ")"
2001-08-10 09:15:50 -05:00
sOldExtension = GetFileNameExtension(sFullName, "/")
Select Case sOldExtension
Case "vor", "dot", "xlt", "pot"
2001-08-15 06:50:32 -05:00
OpenProperties(1).Value = False
2001-08-10 09:15:50 -05:00
Case Else
2001-11-15 04:38:00 -06:00
OpenProperties(1).Value = False
2001-08-10 09:15:50 -05:00
End Select
2001-08-15 06:50:32 -05:00
oDocument = StarDesktop.LoadComponentFromURL(sFullName, "_blank", 0, OpenProperties())
2001-06-21 08:14:32 -05:00
If bSetFonts Then
CheckScripts(oDocument, 1)
2001-04-23 04:46:42 -05:00
End If
2001-06-21 08:14:32 -05:00
If Not IsNull(oDocument) Then
Select Case sExtension
2001-08-15 06:50:32 -05:00
Case "sxw", "sxc", "sxi", "sxd", "sxs", "sxm"
2001-06-21 08:14:32 -05:00
SourceStemDir = RTrimStr(Applications(ApplIndex,SBDOCSOURCE), "/")
TargetStemDir = RTrimStr(Applications(ApplIndex,SBDOCTARGET), "/")
Case Else ' Templates and Helper-Applications remain
SourceStemDir = RTrimStr(Applications(ApplIndex,SBTEMPLSOURCE), "/")
TargetStemDir = RTrimStr(Applications(ApplIndex,SBTEMPLTARGET), "/")
End Select
TargetFile = ReplaceString(sFullname, TargetStemDir, SourceStemDir)
sFileName = GetFileNameWithoutExtension(TargetFile, "/")
OldExtension = GetFileNameExtension(TargetFile)
TargetFile = RTrimStr(TargetFile, OldExtension)
TargetFile = TargetFile & sExtension
TargetDir = RTrimStr(TargetFile, sFileName & "." & sExtension)
If Not oUcb.Exists(TargetDir) Then
2001-11-30 09:54:17 -06:00
CreateFolder(TargetDir)
2001-06-21 08:14:32 -05:00
End If
If oUcb.Exists(TargetFile) Then
sCurFileExists = ReplaceString(sFileExists, ConvertFromUrl(TargetFile), "<1>")
sCurFileExists = ReplaceString(sCurFileExists, chr(13), "<CR>")
iOverWrite = Msgbox (sCurFileExists, 32 + 3, sTitle)
Select Case iOverWrite
Case 1 ' OK
' In the FileProperty-Bean this is already default
bDoSave = True
Case 2 ' Abort
2001-08-10 03:28:06 -05:00
CancelTask(False)
bDoSave = False
2001-06-21 08:14:32 -05:00
Case 7 ' No
bDoSave = False
End Select
End If
If bDoSave Then
2001-08-09 10:35:42 -05:00
InsertDocNamesToLogDocument(sFullName, TargetFile)
2001-10-17 04:47:56 -05:00
On Local Error Resume Next
2001-08-15 06:50:32 -05:00
FileProperties(0).Name = "FilterName"
FileProperties(0).Value = CurFilterName
oDocument.StoreAsUrl(TargetFile,FileProperties())
2001-06-21 08:14:32 -05:00
oDocument.Dispose()
2001-10-17 04:47:56 -05:00
On Local Error Goto 0
2001-06-21 08:14:32 -05:00
End If
End If
Next i
End If
2001-11-06 10:16:14 -06:00
ImportDialog.cmdCancel.Label = sCloseButton
ImportDialog.cmdGoOn.Label = sReady
ImportDialog.cmdGoOn.Enabled = True
2001-08-10 03:28:06 -05:00
bConversionIsRunnig = False
2001-04-23 04:46:42 -05:00
Exit Sub
RTError:
Msgbox sRTErrorDesc, 16, sRTErrorHeader
End Sub
2001-07-12 04:39:01 -05:00
Sub AddListtoFilesList(FirstList(), SecList(), ApplIndex as Integer)
2001-04-23 04:46:42 -05:00
Dim FirstStart as Integer, FirstEnd as Integer, i as Integer, s as Integer
2001-07-12 04:39:01 -05:00
If FirstList(0,0) = "" Then
FirstStart = Ubound(FirstList(),1)
Else
FirstStart = Ubound(FirstList(),1) + 1
End If
2001-05-21 09:52:58 -05:00
FirstEnd = FirstStart + Ubound(SecList(),1)
ReDim Preserve FirstList(FirstEnd,2)
s = 0
2001-04-23 04:46:42 -05:00
For i = FirstStart To FirstEnd
FirstList(i,0) = SecList(s,0)
FirstList(i,1) = SecList(s,1)
FirstList(i,2) = CStr(ApplIndex)
s = s + 1
Next i
End Sub
Function GetTargetTemplatePath(Index as Integer)
Select Case WizardMode
Case SBMICROSOFTMODE
2001-07-12 04:39:01 -05:00
GetTargetTemplatePath() = SOTemplatePath & "/" & sTemplateGroupName
2001-04-23 04:46:42 -05:00
Case SBXMLMODE
If Index = 3 Then
' Helper Application
GetTargetTemplatePath = SOWorkPath
Else
GetTargetTemplatePath = SOTemplatePath
End If
End Select
End Function
' Retrieves the second value for a next to 'SearchString' in
' a two-dimensional string-Array
Function GetFilterName(sMimetypeorExtension as String, sFilterName(), sExtension as string, FilterIndex as Integer) as String
Dim i as Integer
Dim MaxIndex as Integer
Dim sLocFilterlist() as String
For i = 0 To Ubound(sFiltername(),1)
If Instr(1,sFilterName(i,0),sMimeTypeOrExtension) <> 0 Then
sLocFilterList() = ArrayoutofString(sFiltername(i,0),"|", MaxIndex)
If MaxIndex = 0 Then
sExtension = sFiltername(i,2)
GetFilterName = sFilterName(i,1)
Else
Dim a as Integer
Dim sLocExtensionList() as String
a = SearchArrayForPartString(sMimetypeOrExtension, sLocFilterList())
sLocFilterList() = ArrayoutofString(sFiltername(i,1),"|", MaxIndex)
GetFilterName = sLocFilterList(a)
sLocExtensionList() = ArrayoutofString(sFilterName(i,2), "|", MaxIndex)
sExtension = sLocExtensionList(a)
End If
Exit For
End If
Next
FilterIndex = i
End Function
Function SearchArrayforPartString(SearchString as String, LocList()) as Integer
Dim i as integer
For i = Lbound(LocList(),1) to Ubound(LocList(),1)
If Instr(1,LocList(i), SearchString) <> 0 Then
SearchArrayForPartString() = i
Exit Function
End if
Next
IndexinArray = -1
End Function
Function GetMimeTypeList(BigFiltername as STring)
2001-08-10 09:15:50 -05:00
Dim sBigList() as String
Dim sSmallList() as String
2001-04-23 04:46:42 -05:00
Dim sMimeTypeList()
2001-08-10 09:15:50 -05:00
Dim BigMaxIndex as Integer
Dim n as Integer
sBigList() = ArrayoutofString(BigFilterName,"|", BigMaxIndex)
For n = 0 To BigMaxIndex
sSmallList() = ArrayoutofString(sBigList(n),";")
sMimeTypeList() = AddListToList(sMimeTypeList(), sSmallList())
Next n
2001-04-23 04:46:42 -05:00
GetMimetypeList() = sMimeTypeList()
2001-05-21 09:52:58 -05:00
End Function
Sub CreateLogDocument(HiddenProperties())
Dim oTableCursor as Object
Dim oLogCursor as Object
Dim oLogRows as Object
Dim sLogUrl as String
Dim NoArgs()
Dim i as Integer
Dim bLogExists as Boolean
If ImportDialog.chkLogfile.State = 1 Then
i = 2
2001-11-05 08:35:36 -06:00
oLogDocument = StarDesktop.LoadComponentFromURL("private:factory/swriter", "_blank", 4, NoArgs())' HiddenProperties()) ' HiddenProperties())
2001-05-21 09:52:58 -05:00
oLogCursor = oLogDocument.Text.CreateTextCursor
oLogTable = oLogDocument.CreateInstance("com.sun.star.text.TextTable")
oLogCursor.Text.InsertTextContent(oLogCursor, oLogTable, True)
oLogCursor = oLogTable.GetCellbyPosition(0,0).createTextCursor
oLogCursor.SetString(sSourceDocuments)
oLogCursor = oLogTable.GetCellbyPosition(1,0).createTextCursor
oLogCursor.SetString(sTargetDocuments)
2001-08-09 10:35:42 -05:00
bInsertRow = False
2001-05-21 09:52:58 -05:00
sLogUrl = SOWorkPath & "/Logfile.sxw"
Do
bLogExists = oUcb.Exists(sLogUrl)
If bLogExists Then
If i = 2 Then
sLogUrl = ReplaceString(sLogUrl, "/Logfile_2.sxw", "/Logfile.sxw")
Else
sLogUrl = ReplaceString(sLogUrl, "/Logfile_" & cStr(i) & ".sxw", "/Logfile_" & cStr(i-1) & ".sxw")
End If
i = i + 1
End If
Loop Until Not bLogExists
2001-08-09 10:35:42 -05:00
oLogDocument.StoreAsUrl(sLogUrl, NoArgs())
2001-05-21 09:52:58 -05:00
EndIf
End Sub
2001-08-09 10:35:42 -05:00
Sub InsertDocNamesToLogDocument(SourceUrl as String, TargetUrl as String)
Dim oCell as Object
2001-05-21 09:52:58 -05:00
Dim oLogCursor as Object
Dim UrlList(1) as String
Dim LocFileName as String
Dim LocUrl as String
Dim i as Integer
If ImportDialog.chkLogfile.State = 1 Then
2001-08-09 10:35:42 -05:00
If bInsertRow Then
2001-05-21 09:52:58 -05:00
oLogTable.Rows.InsertByIndex(oLogTable.Rows.Count,1)
2001-08-09 10:35:42 -05:00
Else
bInsertRow = True
2001-05-21 09:52:58 -05:00
End If
UrlList(0) = SourceUrl
UrlList(1) = TargetUrl
For i = 0 To 1
2001-08-09 10:35:42 -05:00
oCell = oLogTable.GetCellbyPosition(i,oLogTable.Rows.Count-1)
oLogCursor = oCell.createTextCursor()
2001-05-21 09:52:58 -05:00
LocUrl = UrlList(i)
oLogCursor.HyperLinkURL = LocUrl
oLogCursor.HyperLinkName = LocUrl
oLogCursor.HyperLinkTarget = LocUrl
2001-10-17 04:47:56 -05:00
LocFileName = FileNameOutOfPath(LocUrl)
2001-08-09 10:35:42 -05:00
oCell.InsertString(oLogCursor, LocFileName,False)
2001-05-21 09:52:58 -05:00
Next i
oLogDocument.Store()
End If
End Sub</script:module>