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