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
5Public AbsTemplateFound as Integer
6Public AbsDocuFound as Integer
7Public oLogDocument as Object
8Public oLogTable as Object
9Public bLogExists as Boolean
10Public sComment as String
11Public MaxCollectIndex as Integer
12Public bInsertRow as Boolean
13Public sLogUrl as String
14Public sCurPassWord as String
15Public FileCount as Integer
16Public XMLTemplateCount as Integer
17Public PathCollection(7,3) as String
18Public bIsFirstLogTable as Boolean
19Public bFilterTracerIsinsideTable as Boolean
20
21
22Function ReadCollectionPaths(FilesList() as String, sFilterName() as String)
23Dim FilterIndex as Integer
24Dim bRecursive as Boolean
25Dim SearchDir as String
26Dim i as Integer
27Dim n as Integer
28Dim a as Integer
29Dim s as Integer
30Dim t as Integer
31Dim sFileContent() as String
32Dim NewList(0,1) as String
33Dim Index as Integer
34Dim CurFileName as String
35Dim CurExtension as String
36Dim CurFileContent as String
37Dim XMLTemplateContentList() as String
38Dim bIsTemplatePath as Boolean
39Dim MaxIndex as Integer
40Dim NewContentList() as String
41Dim XMLTemplateContentString as String
42Dim ApplIndex as Integer
43Dim bAssignFileName as Boolean
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), &quot;|&quot;)
49		NewList() = ReadDirectories(SearchDir, bRecursive, False, False, sFileContent(), &quot;&quot;)
50		If InterruptProcess Then
51			ReadCollectionPaths() = False
52			Exit Function
53		End If
54		If Ubound(NewList()) &gt; -1 Then
55			bIsTemplatePath = FieldInList(&quot;vor&quot;, sFileContent)
56			If bIsTemplatePath Then
57				XMLTemplateContentString = PathCollection(i,3)
58				XMLTemplateContentList() = ArrayoutofString(XMLTemplateContentString, &quot;|&quot;)
59				If Ubound(XMLTemplateContentList()) &gt; -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 = &quot;&quot;
71						CurFileName = NewList(n,0)
72						If (FieldInList(NewList(n,1), XMLTemplateList())) Then
73							CurFileContent = GetRealFileContent(CurFileName)
74							t = SearchArrayforPartString(CurFileContent, XMLTemplateContentList())
75						 	bAssignFileName = (t &gt; -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 &lt; n Then
84								a = a + 1
85								NewList(a,0) = CurFileName
86								NewList(a,1) = CurExtension
87								If CurFileContent = &quot;&quot; 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 &lt; MaxIndex And a &gt; -1 Then
96						ReDim Preserve NewList(a, 1) as String
97					End If
98					If a &gt; -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	ReadCollectionPaths() = Ubound(FilesList()) &gt; -1
114End Function
115
116
117Function GetApplicationIndex(CurFileContent as String, sFilterName() as String) as Integer
118Dim Index as Integer
119Dim i as Integer
120	Index = GetIndexForPartStringinMultiArray(sFilterName(), CurFileContent, 0)
121	If Index &gt;= MaxApplCount Then
122		Index = Index - MaxApplCount
123	End If
124	For i = 0 To MaxApplCount - 1
125		If Applications(i, SBAPPLKEY) = Index Then
126			GetApplicationIndex() = i
127			Exit Function
128		End If
129	Next i
130	GetApplicationIndex() = - 1
131End Function
132
133
134Function InterruptProcess() as Boolean
135	If bCancelTask Or RetValue = 0 Then
136		bConversionIsRunning = False
137		InterruptProcess() = True
138		Exit Function
139	End if
140	InterruptProcess() = False
141End Function
142
143
144Sub AddCollectionPath(ApplIndex as Integer, DocIndex as Integer, RecursiveIndex as Integer, sFiltername() as String, DistIndex as Integer)
145	MaxCollectIndex = MaxCollectIndex + 1
146	PathCollection(MaxCollectIndex, 0) = Applications(ApplIndex, DocIndex)
147	PathCollection(MaxCollectIndex, 1) = Applications(ApplIndex, RecursiveIndex)
148	AddFilterNameToPathItem(ApplIndex, MaxCollectIndex, sFiltername(), DistIndex)
149End Sub
150
151
152Function SetExtension(LocExtension) as String
153	if (Instr(LocExtension, &quot;vnd.sun.xml.impress&quot;)) &gt; 0 then
154		SetExtension() = &quot;vor|sti|std&quot;
155	elseif (Instr(LocExtension, &quot;vnd.sun.xml.writer&quot;)) &gt; 0 then
156		SetExtension() = &quot;vor|stw&quot;
157	elseif (Instr(LocExtension, &quot;vnd.sun.xml.calc&quot;)) &gt; 0 then
158		SetExtension() = &quot;vor|stc&quot;
159	elseif (Instr(LocExtension, &quot;vnd.sun.xml.draw&quot;)) &gt; 0 then
160		SetExtension() = &quot;vor|std|sti&quot;
161	endif
162End Function
163
164Sub AddFilterNameToPathItem(ApplIndex as Integer, CollectIndex as Integer, sFiltername() as String, DistIndex as Integer)
165Dim iKey as Integer
166Dim CurListString as String
167Dim LocExtension as String
168Dim LocContentString as String
169Dim LocXMLTemplateContent as String
170	iKey = Applications(ApplIndex, SBAPPLKEY)
171	CurListString = PathCollection(CollectIndex, 2)
172	LocExtension = sFilterName(iKey +DistIndex, 0)
173	If Len(LocExtension) &gt; SBMAXEXTENSIONLENGTH Then 			&apos; 7 == Length of two extensions like &apos;sda|sdd
174		LocExtension = SetExtension(LocExtension)
175		LocContentString = sFilterName(iKey +DistIndex, 0)
176		LocContentString = ReplaceString(LocContentString, &quot;|&quot;, &quot;;&quot;)
177		LocXMLTemplateContent = PathCollection(CollectIndex, 3)
178		If LocXMLTemplateContent = &quot;&quot; Then
179			LocXMLTemplateContent = LocContentString
180		Else
181			LocXMLTemplateContent = LocXMLTemplateContent &amp; &quot;|&quot; &amp; LocContentString
182		End If
183		PathCollection(CollectIndex, 3) = LocXMLTemplateContent
184	End If
185	If CurListString = &quot;&quot; Then
186		PathCollection(CollectIndex, 2) = LocExtension
187	Else
188		If Instr(CurListString, LocExtension) = 0 Then
189			PathCollection(CollectIndex, 2) = CurListString &amp; &quot;|&quot; &amp; LocExtension
190		End If
191	End If
192End Sub
193
194
195Sub CheckIfToAddPathToCollection(ApplIndex as Integer, bDoConvertIndex as Integer, DocIndex as Integer, RecursiveIndex as Integer, sFiltername() as String, DistIndex as Integer)
196Dim CollectIndex as Integer
197Dim bCheckDocuType as Boolean
198	bCheckDocuType = Applications(ApplIndex, bDoConvertIndex)
199	If bCheckDocuType Then
200		CollectIndex = GetIndexInMultiArray(PathCollection(), Applications(ApplIndex,DocIndex), 0)
201		If (CollectIndex &gt;-1) Then
202			If Applications(ApplIndex, RecursiveIndex) &lt;&gt; PathCollection(CollectIndex, 1) Then
203				AddCollectionPath(ApplIndex, DocIndex, RecursiveIndex, sFilterName(), DistIndex)
204			Else
205				AddFilterNameToPathItem(ApplIndex, CollectIndex, sFilterName(), DistIndex)
206			End If
207		Else
208			AddCollectionPath(ApplIndex, DocIndex, RecursiveIndex, sFilterName(), DistIndex)
209		End If
210	End If
211End Sub
212
213
214Sub CollectPaths(sFiltername() as String)
215Dim i as Integer
216Dim	XMLTemplateContentString as String
217	MaxCollectIndex = -1
218	For i = 0 To ApplCount-1
219		CheckIfToAddPathToCollection(i, SBDOCCONVERT, SBDOCSOURCE, SBDOCRECURSIVE, sFilterName(), 0)
220	Next i
221	XMLTemplateCount = 0
222	XMLTemplateContentString = &quot;&quot;
223	For i = 0 To ApplCount-1
224		If WizardMode = SBXMLMODE Then
225			XMLTemplateCount = XMLTemplateCount + 1
226		End If
227		CheckIfToAddPathToCollection(i, SBTEMPLCONVERT, SBTEMPLSOURCE, SBTEMPLRECURSIVE, sFilterName(), MaxApplCount)
228	Next i
229End Sub
230
231
232Sub ConvertAllDocuments(sFilterName() as String)
233Dim FileProperties(1) as new com.sun.star.beans.PropertyValue
234Dim PWFileProperties(2) as New com.sun.star.beans.PropertyValue
235Dim WriterWebProperties(0) as new com.sun.star.beans.PropertyValue
236Dim OpenProperties(4) as new com.sun.star.beans.PropertyValue
237Dim	oInteractionHandler as Object
238Dim InteractionTypes(0) as Long
239Dim FilesList(0,2) as String
240Dim sViewPath as String
241Dim i as Integer
242Dim FilterIndex as Integer
243Dim sSourceUrl as String
244Dim CurFilename as String
245Dim oDocument as Object
246Dim sExtension as String
247Dim OldExtension as String
248Dim CurFound as Integer
249Dim TotFound as Integer
250Dim TargetStemDir as String
251Dim SourceStemDir as String
252Dim TargetDir as String
253Dim sTargetUrl as String
254Dim CurFilterName as String
255Dim ApplIndex as Integer
256Dim Index as Integer
257Dim bIsDocument as Boolean
258Dim bDoSave as Boolean
259Dim sCurFileExists as String
260Dim MaxFileIndex as Integer
261Dim bContainsBasicMacro as Boolean
262Dim bIsPassWordProtected as Boolean
263Dim iOverwrite as Integer
264Dim sMimeTypeorExtension as String
265Dim sPrevMimeTypeorExtension as String
266	bConversionisrunning = True
267	InteractionTypes(0) = com.sun.star.task.PasswordRequestMode.PASSWORD_REENTER
268	oInteractionHandler = createUnoService(&quot;com.sun.star.task.InteractionHandler&quot;)
269	oInteractionHandler.initialize(InteractionTypes())
270	iGeneralOverwrite = SBOVERWRITEUNDEFINED
271	bConversionIsRunning = True
272	bLogExists = false
273	AbsTemplateFound = 0
274	AbsDocuFound = 0
275	CollectPaths(sFiltername())
276	If Not ReadCollectionPaths(FilesList(), sFilterName()) Then
277		TotFound = 0
278		SetProgressDisplay(0)
279		bConversionisrunning = false
280		FinalizeDialogButtons()
281		Exit Sub
282	End If
283	TotFound = Ubound(FilesList()) + 1
284	If FilesList(0,0) = &quot;&quot; Then					&apos; Querying the number of fields in a multidimensionl Array is unsecure
285		TotFound = 0							&apos; because it will return the value 0 (and not -1) even when the Array is empty
286		SetProgressDisplay(0)
287	End If
288	BubbleSortList(FilesList(), true)
289	If TotFound &gt; 0 Then
290		CreateLogDocument(OpenProperties())
291		InitializeProgressPage(ImportDialog)
292		OpenProperties(0).Name = &quot;Hidden&quot;
293		OpenProperties(0).Value = True
294		OpenProperties(1).Name = &quot;AsTemplate&quot;
295		OpenProperties(1).Value = False
296		OpenProperties(2).Name = &quot;MacroExecutionMode&quot;
297		OpenProperties(2).Value = com.sun.star.document.MacroExecMode.NEVER_EXECUTE
298		OpenProperties(3).Name = &quot;UpdateDocMode&quot;
299		OpenProperties(3).Value = com.sun.star.document.UpdateDocMode.NO_UPDATE
300		OpenProperties(4).Name = &quot;InteractionHandler&quot;
301		OpenProperties(4).Value = oInteractionHandler
302		MaxFileIndex = Ubound(FilesList(),1)
303		FileCount = 0
304		For i = 0 To MaxFileIndex
305			sComment = &quot;&quot;
306			If InterruptProcess() Then
307				Exit For
308			End If
309			bDoSave = True
310			sSourceUrl = FilesList(i,0)
311			sPrevMimeTypeorExtension = sMimeTypeorExtension
312			sMimeTypeorExtension = FilesList(i,1)
313			CurFiltername =	GetFilterName(sMimeTypeorExtension, sFilterName(), sExtension, FilterIndex)
314			ApplIndex = FilesList(i,2)
315			If sMimeTypeorExtension &lt;&gt; sPrevMimeTypeorExtension Then
316				CreateLogTable(ApplIndex, sMimeTypeOrExtension, sFiltername()
317			End If
318			If ApplIndex &gt; Ubound(Applications) or (ApplIndex &lt; 0) Then
319				Msgbox &quot;Applicationindex out of bounds:&quot; &amp; sSourcUrl
320			End If
321			sViewPath = ConvertFromUrl(sSourceUrl) 	&apos; CutPathView(sSourceUrl, 70)
322			ImportDialog.LabelCurDocument.Label = Str(i+1) &amp; &quot;/&quot; &amp; MaxFileIndex + 1 &amp; &quot;  (&quot; &amp; sViewPath &amp; &quot;)&quot;
323			Select Case lcase(sExtension)
324				Case &quot;odt&quot;, &quot;ods&quot;, &quot;odp&quot;, &quot;odg&quot;, &quot;odm&quot;, &quot;odf&quot;
325					SourceStemDir = RTrimStr(Applications(ApplIndex,SBDOCSOURCE), &quot;/&quot;)
326					TargetStemDir = RTrimStr(Applications(ApplIndex,SBDOCTARGET), &quot;/&quot;)
327				Case Else 								&apos; Templates and Helper-Applications remain
328					SourceStemDir = RTrimStr(Applications(ApplIndex,SBTEMPLSOURCE), &quot;/&quot;)
329					TargetStemDir = RTrimStr(Applications(ApplIndex,SBTEMPLTARGET), &quot;/&quot;)
330			End Select
331			sTargetUrl = ReplaceString(sSourceUrl, TargetStemDir, SourceStemDir)
332			CurFilename = GetFileNameWithoutExtension(sTargetUrl, &quot;/&quot;)
333			OldExtension = GetFileNameExtension(sTargetUrl)
334			sTargetUrl = RTrimStr(sTargetUrl, OldExtension)
335			sTargetUrl = sTargetUrl &amp; sExtension
336			TargetDir = RTrimStr(sTargetUrl, CurFilename &amp; &quot;.&quot; &amp; sExtension)
337			If (oUcb.Exists(sTargetUrl)) Then
338				If (iGeneralOverwrite &lt;&gt; SBOVERWRITEALWAYS) Then
339					If (iGeneralOverwrite = SBOVERWRITEUNDEFINED) Then
340						ShowOverwriteAllDialog(sTargetUrl, sTitle)
341						bDoSave = (iGeneralOverwrite = SBOVERWRITEQUERY) Or (iGeneralOverwrite = SBOVERWRITEALWAYS)
342					Elseif iGeneralOverwrite = SBOVERWRITENEVER Then
343						bDoSave = False
344					ElseIf ((iGeneralOverWrite = SBOVERWRITEQUERY) OR (iGeneralOverwrite = SBOVERWRITECANCEL)) Then
345						&apos; Todo: According to AS there might come a new feature that storeasUrl could possibly rise a UI dialog.
346						&apos; In this case my own UI becomes obsolete
347						sCurFileExists = ReplaceString(sFileExists, ConvertFromUrl(sTargetUrl), &quot;&lt;1&gt;&quot;)
348						sCurFileExists = ReplaceString(sCurFileExists, chr(13), &quot;&lt;CR&gt;&quot;)
349						iOverWrite = Msgbox (sCurFileExists, 32 + 3, sTitle)
350						Select Case iOverWrite
351							Case 1	&apos; OK
352								&apos; In the FileProperty-Bean this is already default
353								bDoSave = True
354							Case 2 	&apos; Abort
355								CancelTask(False)
356								bDoSave = False
357							Case 7 	&apos; No
358								bDoSave = False
359						End Select
360					End If
361				End If
362			End If
363			If bDoSave Then
364				If Not oUcb.Exists(TargetDir) Then
365					bDoSave = CreateFolder(TargetDir)
366				End If
367				If bDoSave Then
368					oDocument = StarDesktop.LoadComponentFromURL(sSourceUrl, &quot;_default&quot;, 0, OpenProperties())
369					If Not IsNull(oDocument) Then
370						InsertSourceUrlToLogDocument(sSourceUrl, &quot;&quot;)
371						bIsPassWordProtected = CheckPassWordProtection(oDocument)
372						CheckIfMacroExists(oDocument.BasicLibraries, sComment)
373						On Local Error Goto NOSAVING
374						If bIsPassWordProtected Then
375							PWFileProperties(0).Name = &quot;FilterName&quot;
376							PWFileProperties(0).Value = CurFilterName
377							PWFileProperties(1).Name = &quot;Overwrite&quot;
378							PWFileProperties(1).Value = True
379							PWFileProperties(2).Name = &quot;Password&quot;
380							PWFileProperties(2).Value = sCurPassWord
381							oDocument.StoreAsUrl(sTargetUrl, PWFileProperties())
382						Else
383							FileProperties(0).Name = &quot;FilterName&quot;
384							FileProperties(0).Value = CurFilterName
385							FileProperties(1).Name = &quot;Overwrite&quot;
386							FileProperties(1).Value = True
387							oDocument.StoreAsUrl(sTargetUrl,FileProperties())
388						End If
389						&apos; Todo: Make sure that an errorbox pops up when saving fails
390						NOSAVING:
391						If Err &lt;&gt; 0 Then
392							sCurcouldnotsaveDocument = ReplaceString(scouldnotsaveDocument, ConvertFromUrl(sTargetUrl), &quot;&lt;1&gt;&quot;)
393							sComment = ConcatComment(sComment, sCurCouldnotsaveDocument)
394							Resume LETSGO
395							LETSGO:
396						Else
397							FileCount = FileCount + 1
398						End If
399						oDocument.Dispose()
400						InsertTargetUrlToLogDocument(sTargetUrl, sComment, ApplIndex)
401					Else
402						sCurcouldnotopenDocument = ReplaceString(scouldnotopenDocument, ConvertFromUrl(sSourceUrl), &quot;&lt;1&gt;&quot;)
403						sComment = ConcatComment(sComment, sCurCouldnotopenDocument)
404						InsertSourceUrlToLogDocument(sSourceUrl, sComment)
405					End If
406				End If
407			End If
408		Next i
409	End If
410	AddLogStatistics()
411	FinalizeDialogButtons()
412	bConversionIsRunning = False
413	Exit Sub
414RTError:
415	Msgbox sRTErrorDesc, 16, sRTErrorHeader
416End Sub
417
418
419
420Sub AddListtoFilesList(FirstList(), SecList(), NewContentList() as String)
421Dim sLocExtension as String
422Dim FirstStart as Integer
423Dim FirstEnd as Integer
424Dim i as Integer
425Dim s as Integer
426	If FirstList(0,0) = &quot;&quot; Then
427		FirstStart = Ubound(FirstList(),1)
428	Else
429		FirstStart = Ubound(FirstList(),1) + 1
430	End If
431	FirstEnd = FirstStart + Ubound(SecList(),1)
432	ReDim Preserve FirstList(FirstEnd,2)
433	s = 0
434	For i = FirstStart To FirstEnd
435		FirstList(i,0) = SecList(s,0)
436		FirstList(i,1) = SecList(s,1)
437		sLocExtension = lcase(FirstList(i,1))
438		Select Case sLocExtension
439			Case &quot;sdw&quot;, &quot;sdc&quot;, &quot;sda&quot;, &quot;sdd&quot;, &quot;smf&quot;, &quot;sgl&quot;, &quot;doc&quot;, &quot;xls&quot;, &quot;ppt&quot;, &quot;sxi&quot; , &quot;sxw&quot; , &quot;sxd&quot; , &quot;sxg&quot; , &quot;sxm&quot; , &quot;sxc&quot; , &quot;pps&quot;
440				AbsDocuFound = AbsDocuFound + 1
441			Case else
442				AbsTemplateFound = AbsTemplateFound + 1
443		End Select
444		FirstList(i,2) = CStr(NewContentList(s))
445		s = s + 1
446	Next i
447	SetProgressDisplay(Ubound(FirstList()) + 1)
448End Sub
449
450
451
452Function GetTargetTemplatePath(Index as Integer)
453	Select Case WizardMode
454		Case SBMICROSOFTMODE
455			GetTargetTemplatePath() = SOTemplatePath &amp; &quot;/&quot; &amp; sTemplateGroupName
456		Case SBXMLMODE
457			If Index = 3 Then
458				&apos; Helper Application
459				GetTargetTemplatePath = SOWorkPath
460			Else
461				GetTargetTemplatePath = SOTemplatePath
462			End If
463	End Select
464End Function
465
466
467&apos; Retrieves the second value for a next to &apos;SearchString&apos; in
468&apos; a two-dimensional string-Array
469Function GetFilterName(sMimetypeorExtension as String, sFilterName(), sExtension as string, FilterIndex as Integer) as String
470Dim i as Integer
471Dim MaxIndex as Integer
472Dim sLocFilterlist() as String
473	For i = 0 To Ubound(sFiltername(),1)
474		If Instr(1,sFilterName(i,0),sMimeTypeOrExtension) &lt;&gt; 0 Then
475			sLocFilterList() = ArrayoutofString(sFiltername(i,0),&quot;|&quot;, MaxIndex)
476			If MaxIndex = 0 Then
477				sExtension = sFiltername(i,2)
478				GetFilterName = sFilterName(i,1)
479			Else
480				Dim b as Integer
481				Dim sLocExtensionList() as String
482				b =	SearchArrayForPartString(sMimetypeOrExtension, sLocFilterList())
483				sLocFilterList() = ArrayoutofString(sFiltername(i,1),&quot;|&quot;, MaxIndex)
484				GetFilterName = sLocFilterList(b)
485				sLocExtensionList() = ArrayoutofString(sFilterName(i,2), &quot;|&quot;, MaxIndex)
486				sExtension = sLocExtensionList(b)
487			End If
488			Exit For
489		End If
490	Next
491	FilterIndex = i
492End Function
493
494
495Function SearchArrayforPartString(SearchString as String, LocList()) as Integer
496Dim i as Integer
497Dim a as Integer
498Dim StringList() as String
499	For i = Lbound(LocList(),1) to Ubound(LocList(),1)
500		StringList() = ArrayoutofString(LocList(i), &quot;|&quot;)
501		For a = 0 To Ubound(StringList())
502			If (Instr(1, SearchString, StringList(a)) &lt;&gt; 0) Then
503				SearchArrayForPartString() = i
504				Exit Function
505			End If
506		Next a
507	Next i
508	SearchArrayForPartString() = -1
509End Function
510
511
512Sub CreateLogTable(ApplIndex as Integer, CurFileContent as String, sFilterName() as String)
513Dim oLogCursor as Object
514Dim oLogRows as Object
515Dim FilterIndex as Integer
516Dim sDocumentType as String
517Dim oTextCursor
518Dim oCell
519	If Not bLogExists Then
520        Exit Sub
521    End If
522	bFilterTracerIsinsideTable = False
523	FilterIndex = GetIndexForPartStringinMultiArray(sFilterName(), CurFileContent, 0)
524	sDocumentType = sFiltername(FilterIndex,3)
525	oLogCursor = oLogDocument.Text.createTextCursor()
526	oLogCursor.GotoEnd(False)
527	If Not bIsFirstLogTable Then
528		oLogDocument.Text.insertControlCharacter(oLogCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
529	Else
530		bisFirstLogTable = False
531	End If
532	oLogCursor.HyperLinkURL = &quot;&quot;
533	oLogCursor.HyperLinkName = &quot;&quot;
534	oLogCursor.HyperLinkTarget = &quot;&quot;
535	oLogCursor.ParaStyleName = &quot;Heading 1&quot;
536	oLogCursor.setString(sDocumentType)
537	If WizardMode = SBMICROSOFTMODE Then
538		If bFilterTracingAvailable Then
539			If bMSApplFilterTracingAvailable(ApplIndex) Then
540				Dim CurFilterTracingPath as String
541				CurFilterTracingPath = FilterTracingLogPath(ApplIndex)
542				bFilterTracerIsinsideTable = (bTakeOverTargetName(ApplIndex) Or bTakeOverPathName(ApplIndex))
543				If Not bFilterTracerIsinsideTable Then
544					oLogCursor.CollapseToEnd()
545					oLogDocument.Text.insertControlCharacter(oLogCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
546					InsertCommandButtonatViewCursor(oLogDocument, oLogCursor, CurFilterTracingPath)
547				End If
548			End If
549		End If
550	End If
551	oLogCursor.CollapsetoEnd()
552	oLogDocument.Text.insertControlCharacter(oLogCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
553	oLogTable =  oLogDocument.CreateInstance(&quot;com.sun.star.text.TextTable&quot;)
554	oLogTable.RepeatHeadline = true
555	If bFilterTracerIsinsideTable Then
556		oLogTable.initialize(2,3)
557	End If
558	oLogCursor.Text.InsertTextContent(oLogCursor, oLogTable, True)
559	oTextCursor = oLogTable.GetCellbyPosition(0,0).createTextCursor()
560	oTextCursor.SetString(sSourceDocuments)
561	oTextCursor = oLogTable.GetCellbyPosition(1,0).createTextCursor()
562	oTextCursor.SetString(sTargetDocuments)
563	If bFilterTracerIsinsideTable Then
564		oTextCursor = oLogTable.GetCellbyPosition(2,0).createTextCursor()
565		oTextCursor.SetString(&quot;FilterTracer&quot;)
566	End If
567	bInsertRow = False
568End Sub
569
570
571Function GetSize(iWidth, iHeight) As New com.sun.star.awt.Size
572Dim aSize As New com.sun.star.awt.Size
573	aSize.Width = iWidth
574	aSize.Height = iHeight
575	GetSize() = aSize
576End Function
577
578
579Sub InsertCommandButtonatViewCursor(oLocDocument, oLocCursor, TargetUrl as String, Optional aSize)
580Dim oDocument
581Dim oController
582Dim oCommandButton
583Dim oShape
584Dim oDrawPage
585Dim oCommandControl
586Dim oEvent
587Dim oCell
588	oCommandButton = oLocDocument.createInstance(&quot;com.sun.star.form.component.CommandButton&quot;)
589	oShape = oLocDocument.CreateInstance (&quot;com.sun.star.drawing.ControlShape&quot;)
590	If IsMissing(aSize) Then
591		oShape.Size = GetSize(4000, 600)
592	End If
593	oCommandButton.Label = FileNameoutofPath(Targeturl)
594	oCommandButton.TargetFrame = &quot;_default&quot;
595	oCommandButton.ButtonType = com.sun.star.form.FormButtonType.URL
596	oCommandbutton.DispatchUrlInternal = True
597	oCommandButton.TargetURL = ConverttoUrl(TargetUrl)
598	oShape.Control = oCommandbutton
599	oLocCursor.Text.InsertTextContent(oLocCursor, oShape, True)
600End Sub
601
602
603
604Sub CreateLogDocument(HiddenProperties())
605Dim OpenProperties(0) as new com.sun.star.beans.PropertyValue
606Dim NoArgs()
607Dim i as Integer
608Dim bLogIsThere as Boolean
609	If ImportDialog.chkLogfile.State = 1 Then
610		i = 2
611		OpenProperties(0).Name = &quot;Hidden&quot;
612		OpenProperties(0).Value = True
613		oLogDocument = StarDesktop.LoadComponentFromURL(&quot;private:factory/swriter&quot;, &quot;_default&quot;, 4, OpenProperties())
614		SOWorkPath = RTrimStr(SOWorkPath,&quot;/&quot;)
615		sLogUrl = SOWorkPath &amp; &quot;/Logfile.odt&quot;
616		Do
617			bLogIsThere = oUcb.Exists(sLogUrl)
618			If bLogIsThere Then
619				If i = 2 Then
620					sLogUrl = ReplaceString(sLogUrl, &quot;/Logfile_2.odt&quot;, &quot;/Logfile.odt&quot;)
621				Else
622					sLogUrl = ReplaceString(sLogUrl, &quot;/Logfile_&quot; &amp; cStr(i) &amp; &quot;.odt&quot;, &quot;/Logfile_&quot; &amp; cStr(i-1) &amp; &quot;.odt&quot;)
623				End If
624				i = i + 1
625			End If
626		Loop Until Not bLogIsThere
627		bLogExists = True
628		oLogDocument.StoreAsUrl(sLogUrl, NoArgs())
629	End If
630End Sub
631
632
633Function GetFilterTracingLogPath(sTargetUrl as String, ApplIndex) as String
634Dim TargetFileName as String
635Dim sTargetFolder as String
636Dim CurFilterTracingPath as String
637Dim CurFilterTracingname as String
638Dim CurFilterFolder as String
639		CurFilterTracingPath = FilterTracingLogPath(ApplIndex)
640		If bTakeOverTargetName(ApplIndex) Then
641			TargetFilename = GetFileNameWithoutextension(sTargetUrl, &quot;/&quot;)
642			CurFilterFolder = DirectoryNameoutofPath(FilterTracingLogPath(ApplIndex), &quot;/&quot;)
643			CurFilterTracingpath = CurFilterFolder &amp; &quot;/&quot; &amp; TargetFilename &amp; &quot;.log&quot;
644		End If
645		If bTakeOverPathName(ApplIndex) Then  &apos;Replace the Folder in the FilterTracerpath by the Folder of the targetUrl
646			sTargetFolder = DirectoryNameoutofPath(sTargetUrl,&quot;/&quot;)
647			CurFilterTracingPath = sTargetFolder &amp; &quot;/&quot; &amp; FileNameoutofPath(CurFilterTracingPath, &quot;/&quot;)
648		End If
649		GetFilterTracingLogPath() = CurFilterTracingPath
650End Function
651
652
653Sub InsertTargetUrlToLogDocument(sTargetUrl as String, sComment as String, ApplIndex as Integer)
654Dim oCell
655Dim oTextCursor
656Dim CurFilterTracingpath as String
657	If (bLogExists) And (sTargetUrl &lt;&gt; &quot;&quot;) Then
658		If sTargetUrl &lt;&gt; &quot;&quot; Then
659			oCell = oLogTable.GetCellbyPosition(1,oLogTable.Rows.Count-1)
660			InsertCommentToLogCell(sComment, oCell)
661			InsertHyperLinkToLogCell(sTargetUrl, oCell)
662			If bFilterTracerIsinsideTable Then
663				oCell = oLogTable.getCellByPosition(2, oLogTable.Rows.Count-1)
664				oTextCursor = oCell.Text.CreateTextCursor()
665				CurFilterTracingpath = GetFilterTracingLogPath(sTargetUrl, ApplIndex)
666				InsertCommandButtonatViewCursor(oLogDocument, oTextCursor, CurFilterTracingPath)
667			End If
668			oLogDocument.Store()
669		End If
670	End If
671End Sub
672
673
674Sub InsertSourceUrlToLogDocument(SourceUrl as String, sComment)		&apos;
675Dim oCell as Object
676	If bLogExists Then
677		If bInsertRow Then
678			oLogTable.Rows.InsertByIndex(oLogTable.Rows.Count,1)
679		Else
680			bInsertRow = True
681		End If
682		oCell = oLogTable.GetCellbyPosition(0,oLogTable.Rows.Count-1)
683		InsertCommentToLogCell(sComment, oCell)
684		InsertHyperLinkToLogCell(SourceUrl, oCell)
685		oLogDocument.Store()
686	End If
687End Sub
688
689
690Sub InsertHyperLinkToLogCell(sUrl as String, oCell as Object)
691Dim oLogCursor as Object
692Dim LocFileName as String
693	oLogCursor = oCell.createTextCursor()
694	oLogCursor.CollapseToStart()
695	oLogCursor.HyperLinkURL = sUrl
696	oLogCursor.HyperLinkName = sUrl
697	oLogCursor.HyperLinkTarget = sUrl
698	LocFileName = FileNameOutOfPath(sUrl)
699	oCell.InsertString(oLogCursor, LocFileName,False)
700End Sub
701
702
703Sub InsertCommentToLogCell(sComment as string, oCell as Object)
704Dim oCommentCursor as Object
705	If sComment &lt;&gt; &quot;&quot; Then
706		oCommentCursor = oCell.createTextCursor()
707		oCell.insertControlCharacter(oCommentCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
708		oCell.insertString(oCommentCursor, sComment, false)
709	End If
710End Sub
711
712
713Sub AddLogStatistics()
714Dim oCell as Object
715Dim oLogCursor as Object
716Dim MaxRowIndex as Integer
717	If bLogExists Then
718		MaxRowIndex = oLogTable.Rows.Count
719		sLogSummary = ReplaceString(sLogSummary, FileCount, &quot;&lt;COUNT&gt;&quot;)
720&apos;		oLogTable.Rows.InsertByIndex(MaxRowIndex, 1)
721&apos;		oCell = oLogTable.GetCellbyPosition(0, MaxRowIndex)
722&apos;		oLogCursor = oCell.createTextCursor()
723&apos;		oCell.InsertString(oLogCursor, sLogSummary,False)
724&apos;		MergeRange(oLogTable, oCell, 1)
725
726		oLogCursor = oLogDocument.Text.CreateTextCursor
727		oLogCursor.gotoEnd(False)
728		oLogCursor.HyperLinkURL = &quot;&quot;
729		oLogCursor.HyperLinkName = &quot;&quot;
730		oLogCursor.HyperLinkTarget = &quot;&quot;
731		oLogCursor.SetString(sLogSummary)
732		oLogDocument.Store()
733		oLogDocument.Dispose()
734		bLogExists = False
735	End If
736End Sub
737
738
739
740Function CheckIfMacroExists(oBasicLibraries as Object, sComment as String) as Boolean
741Dim ModuleNames() as String
742Dim ModuleName as String
743Dim MaxLibIndex as Integer
744Dim MaxModuleIndex as Integer
745Dim bMacroExists as Boolean
746Dim n as Integer
747Dim m as Integer
748Dim LibName as String
749Dim sBasicCode as String
750Dim oLibrary as Object
751	bMacroExists = False
752	bMacroExists = oBasicLibraries.hasElements
753	If bMacroExists Then
754		MaxLibIndex = Ubound(oBasicLibraries.ElementNames())
755		For n = 0 To MaxLibIndex
756			LibName = oBasicLibraries.ElementNames(n)
757            If oBasicLibraries.isLibraryLoaded(LibName) Then
758    			oLibrary = oBasicLibraries.getbyName(LibName)
759    			If oLibrary.hasElements() Then
760    				MaxModuleIndex = Ubound(oLibrary.ElementNames())
761    				For m = 0 To MaxModuleIndex
762    					ModuleName = oLibrary.ElementNames(m)
763    					sBasicCode = oLibrary.getbyName(ModuleName)
764    					If sBasicCode &lt;&gt; &quot;&quot; Then
765    						ConcatComment(sComment, sReeditMacro)
766    						CheckIfMacroExists() = True
767    						Exit Function
768    					End If
769    				Next m
770                End If
771			End If
772		Next n
773	End If
774	CheckIfMacroExists() = False
775End Function
776
777
778
779Function CheckPassWordProtection(oDocument as Object)
780Dim bIsPassWordProtected as Boolean
781Dim i as Integer
782Dim oArgs()
783Dim MaxIndex as Integer
784Dim sblabla as String
785	bIsPassWordProtected = false
786 	oArgs() = oDocument.getArgs()
787 	MaxIndex = Ubound(oArgs())
788	For i = 0 To MaxIndex
789		sblabla = oArgs(i).Name
790		If oArgs(i).Name = &quot;Password&quot; Then
791			bIsPassWordProtected = True
792			sCurPassWord = oArgs(i).Value
793			Exit For
794		End If
795	Next i
796	CheckPassWordProtection() = bIsPassWordProtected
797End Function
798
799
800Sub OpenLogDocument()
801
802	bShowLogFile = True
803	ImportDialogArea.endexecute()
804
805End Sub
806
807
808Sub MergeRange(oTable as Object, oCell as Object, MergeCount as Integer)
809Dim oTableCursor as Object
810	oTableCursor = oTable.createCursorByCellName(oCell.CellName)
811	oTableCursor.goRight(MergeCount, True)
812	oTableCursor.mergeRange()
813End Sub
814
815
816Function ConcatComment(sComment as String, AdditionalComment as String)
817	If sComment = &quot;&quot; Then
818		sComment = AdditionalComment
819	Else
820		sComment = sComment &amp; chr(13) + AdditionalComment
821	End If
822	ConcatComment = sComment
823End Function
824</script:module>
825