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