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