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