1*cdf0e10cSrcweir /* 2*cdf0e10cSrcweir * ************************************************************************ 3*cdf0e10cSrcweir * 4*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5*cdf0e10cSrcweir * 6*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 7*cdf0e10cSrcweir * 8*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 9*cdf0e10cSrcweir * 10*cdf0e10cSrcweir * This file is part of OpenOffice.org. 11*cdf0e10cSrcweir * 12*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 13*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 14*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 15*cdf0e10cSrcweir * 16*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 17*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 18*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 20*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 21*cdf0e10cSrcweir * 22*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 23*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 24*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 25*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 26*cdf0e10cSrcweir * 27*cdf0e10cSrcweir * *********************************************************************** 28*cdf0e10cSrcweir */ 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir package graphical; 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 33*cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 34*cdf0e10cSrcweir import com.sun.star.container.XNameAccess; 35*cdf0e10cSrcweir import com.sun.star.frame.FrameSearchFlag; 36*cdf0e10cSrcweir import com.sun.star.frame.XComponentLoader; 37*cdf0e10cSrcweir import com.sun.star.frame.XDesktop; 38*cdf0e10cSrcweir import com.sun.star.frame.XModel; 39*cdf0e10cSrcweir import com.sun.star.frame.XStorable; 40*cdf0e10cSrcweir import com.sun.star.lang.XComponent; 41*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 42*cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo; 43*cdf0e10cSrcweir import com.sun.star.sdb.XOfficeDatabaseDocument; 44*cdf0e10cSrcweir import com.sun.star.sdb.XReportDocumentsSupplier; 45*cdf0e10cSrcweir import com.sun.star.sdb.application.XDatabaseDocumentUI; 46*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 47*cdf0e10cSrcweir import com.sun.star.uno.XInterface; 48*cdf0e10cSrcweir import com.sun.star.util.XCloseable; 49*cdf0e10cSrcweir import complexlib.Assurance; 50*cdf0e10cSrcweir // import complexlib.ComplexTestCase.AssureException; 51*cdf0e10cSrcweir import helper.OfficeProvider; 52*cdf0e10cSrcweir import helper.PropertyHelper; 53*cdf0e10cSrcweir import helper.URLHelper; 54*cdf0e10cSrcweir import java.io.File; 55*cdf0e10cSrcweir import java.util.ArrayList; 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir /** 58*cdf0e10cSrcweir * 59*cdf0e10cSrcweir * @author ll93751 60*cdf0e10cSrcweir */ 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir class PropertySetHelper 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir XPropertySet m_xPropertySet; 65*cdf0e10cSrcweir public PropertySetHelper(Object _aObj) 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir m_xPropertySet = UnoRuntime.queryInterface(XPropertySet.class, _aObj); 68*cdf0e10cSrcweir } 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir /** 71*cdf0e10cSrcweir get a property and don't convert it 72*cdf0e10cSrcweir @param _sName the string name of the property 73*cdf0e10cSrcweir @return the object value of the property without any conversion 74*cdf0e10cSrcweir */ 75*cdf0e10cSrcweir public Object getPropertyValueAsObject(String _sName) 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir Object aObject = null; 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir if (m_xPropertySet != null) 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir try 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir aObject = m_xPropertySet.getPropertyValue(_sName); 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir catch (com.sun.star.beans.UnknownPropertyException e) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir System.out.println("ERROR: UnknownPropertyException caught. '" + _sName + "'"); 88*cdf0e10cSrcweir System.out.println("Message: " + e.getMessage()); 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir catch (com.sun.star.lang.WrappedTargetException e) 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir System.out.println("ERROR: WrappedTargetException caught."); 93*cdf0e10cSrcweir System.out.println("Message: " + e.getMessage()); 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir return aObject; 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir public class OpenOfficeDatabaseReportExtractor extends Assurance 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir private ParameterHelper m_aParameterHelper; 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir public OpenOfficeDatabaseReportExtractor(ParameterHelper _aParameter) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir m_aParameterHelper = _aParameter; 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir private XDesktop m_xDesktop = null; 110*cdf0e10cSrcweir private XDesktop getXDesktop() 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir if (m_xDesktop == null) 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir try 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir XInterface xInterface = (XInterface) getMultiServiceFactory().createInstance( "com.sun.star.frame.Desktop" ); 118*cdf0e10cSrcweir m_xDesktop = UnoRuntime.queryInterface(XDesktop.class, xInterface); 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir catch (com.sun.star.uno.Exception e) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir GlobalLogWriter.println("ERROR: uno.Exception caught"); 123*cdf0e10cSrcweir GlobalLogWriter.println("Message: " + e.getMessage()); 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir return m_xDesktop; 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir private void showElements(XNameAccess _xNameAccess) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir if (_xNameAccess != null) 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir String[] sElementNames = _xNameAccess.getElementNames(); 134*cdf0e10cSrcweir for(int i=0;i<sElementNames.length; i++) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir System.out.println("Value: [" + i + "] := " + sElementNames[i]); 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir else 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir System.out.println("Warning: Given object is null."); 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir private OfficeProvider m_aProvider = null; 147*cdf0e10cSrcweir private XMultiServiceFactory m_xMultiServiceFactory = null; 148*cdf0e10cSrcweir private XMultiServiceFactory getMultiServiceFactory() 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir if (m_xMultiServiceFactory == null) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir m_xMultiServiceFactory = m_aParameterHelper.getMultiServiceFactory(); 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir return m_xMultiServiceFactory; 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir // private void startOffice() 157*cdf0e10cSrcweir // { 158*cdf0e10cSrcweir // // int tempTime = m_aParameterHelper.getTestParameters().getInt("SingleTimeOut"); 159*cdf0e10cSrcweir // param.put("TimeOut", new Integer(300000)); 160*cdf0e10cSrcweir // System.out.println("TimeOut: " + param.getInt("TimeOut")); 161*cdf0e10cSrcweir // System.out.println("ThreadTimeOut: " + param.getInt("ThreadTimeOut")); 162*cdf0e10cSrcweir // 163*cdf0e10cSrcweir // // OfficeProvider aProvider = null; 164*cdf0e10cSrcweir // m_aProvider = new OfficeProvider(); 165*cdf0e10cSrcweir // m_xXMultiServiceFactory = (XMultiServiceFactory) m_aProvider.getManager(param); 166*cdf0e10cSrcweir // param.put("ServiceFactory", m_xXMultiServiceFactory); 167*cdf0e10cSrcweir // } 168*cdf0e10cSrcweir // 169*cdf0e10cSrcweir // private void stopOffice() 170*cdf0e10cSrcweir // { 171*cdf0e10cSrcweir // if (m_aProvider != null) 172*cdf0e10cSrcweir // { 173*cdf0e10cSrcweir // m_aProvider.closeExistingOffice(param, true); 174*cdf0e10cSrcweir // m_aProvider = null; 175*cdf0e10cSrcweir // } 176*cdf0e10cSrcweir // TimeHelper.waitInSeconds(2, "Give close Office some time."); 177*cdf0e10cSrcweir // } 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir private String m_sMailAddress = null; 180*cdf0e10cSrcweir private String m_sParentDistinct = null; 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir // private String m_sUPDMinor; 183*cdf0e10cSrcweir // private String m_sCWS_WORK_STAMP; 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir private static String m_sSourceVersion; 186*cdf0e10cSrcweir private static String m_sDestinationVersion; 187*cdf0e10cSrcweir private static String m_sSourceName; 188*cdf0e10cSrcweir private static String m_sDestinationName; 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir private static final int WRITER = 1; 191*cdf0e10cSrcweir private static final int CALC = 2; 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir /** 194*cdf0e10cSrcweir * This is the main test Function of current ReportDesignerTest 195*cdf0e10cSrcweir * @param _sDocument 196*cdf0e10cSrcweir * @return 197*cdf0e10cSrcweir */ 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir public ArrayList<String> load(String _sDocument /*, int _nType*/) 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir // We need to copy the database file to a place where we have write access, NEVER use the docpool for this 202*cdf0e10cSrcweir String sOutputPath = m_aParameterHelper.getOutputPath(); 203*cdf0e10cSrcweir File aOutputPath = new File(sOutputPath); 204*cdf0e10cSrcweir aOutputPath.mkdirs(); 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir String sFilename = FileHelper.getBasename(_sDocument); 207*cdf0e10cSrcweir String sDestinationFile = FileHelper.appendPath(sOutputPath, sFilename); 208*cdf0e10cSrcweir FileHelper.copy(_sDocument, sDestinationFile); 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir // now the fix reference of the AbsoluteReferenceFile should exist. 211*cdf0e10cSrcweir assure("There exists no file: " + sDestinationFile, FileHelper.exists(sDestinationFile)); 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir String sFileURL = URLHelper.getFileURLFromSystemPath(sDestinationFile); 214*cdf0e10cSrcweir GlobalLogWriter.println("File URL: " + sFileURL); 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir ArrayList<PropertyValue> aPropertyList = new ArrayList<PropertyValue>(); 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir // FYI: it is not allowed to open the document read only 219*cdf0e10cSrcweir // PropertyValue aReadOnly = new PropertyValue(); // always overwrite already exist files 220*cdf0e10cSrcweir // aReadOnly.Name = "ReadOnly"; 221*cdf0e10cSrcweir // aReadOnly.Value = Boolean.TRUE; 222*cdf0e10cSrcweir // aPropertyList.add(aReadOnly); 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir XComponent xDocComponent = loadComponent(sFileURL, getXDesktop(), aPropertyList); 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir GlobalLogWriter.println("Load done"); 227*cdf0e10cSrcweir // context = createUnoService("com.sun.star.sdb.DatabaseContext") 228*cdf0e10cSrcweir // oDataBase = context.getByName("hh") 229*cdf0e10cSrcweir // oDBDoc = oDataBase.DatabaseDocument 230*cdf0e10cSrcweir // 231*cdf0e10cSrcweir // dim args(1) as new com.sun.star.beans.PropertyValue 232*cdf0e10cSrcweir // args(0).Name = "ActiveConnection" 233*cdf0e10cSrcweir // args(0).Value = oDBDoc.getCurrentController().getPropertyValue("ActiveConnection") 234*cdf0e10cSrcweir // reportContainer = oDBDoc.getReportDocuments() 235*cdf0e10cSrcweir // report = reportContainer.loadComponentFromURL("Report40","",0,args) 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir ArrayList<String> aList = null; 238*cdf0e10cSrcweir try 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir // XInterface x = (XInterface)getMultiServiceFactory().createInstance("com.sun.star.sdb.DatabaseContext"); 241*cdf0e10cSrcweir // assure("can't create instance of com.sun.star.sdb.DatabaseContext", x != null); 242*cdf0e10cSrcweir // GlobalLogWriter.println("createInstance com.sun.star.sdb.DatabaseContext done"); 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir // XNameAccess xNameAccess = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, x); 245*cdf0e10cSrcweir // showElements(xNameAccess); 246*cdf0e10cSrcweir // Object aObj = xNameAccess.getByName(sFileURL); 247*cdf0e10cSrcweir // GlobalLogWriter.println("1"); 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir // PropertySetHelper aHelper = new PropertySetHelper(aObj); 250*cdf0e10cSrcweir // XDocumentDataSource xDataSource = (XDocumentDataSource)UnoRuntime.queryInterface(XDocumentDataSource.class, aObj); 251*cdf0e10cSrcweir // Object aDatabaseDocument = aHelper.getPropertyValueAsObject("DatabaseDocument"); 252*cdf0e10cSrcweir // XOfficeDatabaseDocument xOfficeDBDoc = xDataSource.getDatabaseDocument(); 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir XOfficeDatabaseDocument xOfficeDBDoc = UnoRuntime.queryInterface(XOfficeDatabaseDocument.class, xDocComponent); 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir // XOfficeDatabaseDocument xOfficeDBDoc = (XOfficeDatabaseDocument)UnoRuntime.queryInterface(XOfficeDatabaseDocument.class, xDataSource); 257*cdf0e10cSrcweir assure("can't access DatabaseDocument", xOfficeDBDoc != null); 258*cdf0e10cSrcweir // GlobalLogWriter.println("2"); 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir XModel xDBSource = UnoRuntime.queryInterface(XModel.class, xOfficeDBDoc); 261*cdf0e10cSrcweir Object aController = xDBSource.getCurrentController(); 262*cdf0e10cSrcweir assure("Controller of xOfficeDatabaseDocument is empty!", aController != null); 263*cdf0e10cSrcweir // GlobalLogWriter.println("3"); 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir XDatabaseDocumentUI aDBDocUI = UnoRuntime.queryInterface(XDatabaseDocumentUI.class, aController); 266*cdf0e10cSrcweir aDBDocUI.connect(); 267*cdf0e10cSrcweir boolean isConnect = aDBDocUI.isConnected(); 268*cdf0e10cSrcweir if (isConnect) 269*cdf0e10cSrcweir { 270*cdf0e10cSrcweir GlobalLogWriter.println("Connection is true"); 271*cdf0e10cSrcweir } 272*cdf0e10cSrcweir else 273*cdf0e10cSrcweir { 274*cdf0e10cSrcweir GlobalLogWriter.println("Connection is false"); 275*cdf0e10cSrcweir } 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir // aHelper = new PropertySetHelper(aController); 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir XReportDocumentsSupplier xSupplier = UnoRuntime.queryInterface(XReportDocumentsSupplier.class, xOfficeDBDoc); 280*cdf0e10cSrcweir XNameAccess xNameAccess = xSupplier.getReportDocuments(); 281*cdf0e10cSrcweir assure("xOfficeDatabaseDocument returns no Report Document", xNameAccess != null); 282*cdf0e10cSrcweir // GlobalLogWriter.println("5"); 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir showElements(xNameAccess); 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir // Object aActiveConnectionObj = aHelper.getPropertyValueAsObject("ActiveConnection"); 287*cdf0e10cSrcweir Object aActiveConnectionObj = aDBDocUI.getActiveConnection(); 288*cdf0e10cSrcweir assure("ActiveConnection is empty", aActiveConnectionObj != null); 289*cdf0e10cSrcweir // GlobalLogWriter.println("5"); 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir ArrayList<PropertyValue> aPropertyList2 = new ArrayList<PropertyValue>(); 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir PropertyValue aActiveConnection = new PropertyValue(); 294*cdf0e10cSrcweir aActiveConnection.Name = "ActiveConnection"; 295*cdf0e10cSrcweir aActiveConnection.Value = aActiveConnectionObj; 296*cdf0e10cSrcweir aPropertyList2.add(aActiveConnection); 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir aList = loadAndStoreReports(xNameAccess, aPropertyList2 /*, _nType*/ ); 299*cdf0e10cSrcweir createDBEntry(/*_nType*/); 300*cdf0e10cSrcweir } 301*cdf0e10cSrcweir catch(Exception/*com.sun.star.uno.Exception*/ e) 302*cdf0e10cSrcweir { 303*cdf0e10cSrcweir GlobalLogWriter.println("ERROR: Exception caught"); 304*cdf0e10cSrcweir GlobalLogWriter.println("Message: " + e.getMessage()); 305*cdf0e10cSrcweir } 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir // String mTestDocumentPath = (String) param.get("TestDocumentPath"); 308*cdf0e10cSrcweir // System.out.println("mTestDocumentPath: '" + mTestDocumentPath + "'"); 309*cdf0e10cSrcweir // // workaround for issue using deprecated "DOCPTH" prop 310*cdf0e10cSrcweir // System.setProperty("DOCPTH", mTestDocumentPath); 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir // Close the document 313*cdf0e10cSrcweir // util.utils.shortWait(2000); 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir closeComponent(xDocComponent); 316*cdf0e10cSrcweir return aList; 317*cdf0e10cSrcweir } 318*cdf0e10cSrcweir 319*cdf0e10cSrcweir private String getDocumentPoolName(/*int _nType*/) 320*cdf0e10cSrcweir { 321*cdf0e10cSrcweir return "AutogenReportDesignTest"; 322*cdf0e10cSrcweir // return getFileFormat(_nType); 323*cdf0e10cSrcweir } 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 326*cdf0e10cSrcweir private void createDBEntry(/*int _nType*/) 327*cdf0e10cSrcweir { 328*cdf0e10cSrcweir // try to connect the database 329*cdf0e10cSrcweir String sDBConnection = (String)m_aParameterHelper.getTestParameters().get( convwatch.PropertyName.DB_CONNECTION_STRING ); 330*cdf0e10cSrcweir if (sDBConnection != null && sDBConnection.length() > 0) 331*cdf0e10cSrcweir { 332*cdf0e10cSrcweir GlobalLogWriter.println("DBConnection: " + sDBConnection); 333*cdf0e10cSrcweir // TODO: DB 334*cdf0e10cSrcweir // DB.init(sDBConnection); 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir // String sFixRefSubDirectory = "ReportDesign_qa_complex_" + getFileFormat(_nType); 337*cdf0e10cSrcweir String sFixRefSubDirectory = "ReportDesignFixRef"; 338*cdf0e10cSrcweir 339*cdf0e10cSrcweir String sSourceVersion = m_sSourceVersion; 340*cdf0e10cSrcweir // String sSourceVersion = sFixRefSubDirectory; 341*cdf0e10cSrcweir String sSourceName = m_sSourceName; 342*cdf0e10cSrcweir // String sSourceCreatorType = "fixref"; 343*cdf0e10cSrcweir String sSourceCreatorType = ""; 344*cdf0e10cSrcweir String sDestinationVersion = m_sDestinationVersion; 345*cdf0e10cSrcweir // if (sDestinationVersion.length() == 0) 346*cdf0e10cSrcweir // { 347*cdf0e10cSrcweir // sDestinationVersion = m_sUPDMinor; 348*cdf0e10cSrcweir // } 349*cdf0e10cSrcweir String sDestinationName = m_sDestinationName; 350*cdf0e10cSrcweir String sDestinationCreatorType = ""; 351*cdf0e10cSrcweir String sDocumentPoolDir = getOutputPath(/*_nType*/); 352*cdf0e10cSrcweir String sDocumentPoolName = getDocumentPoolName(/*_nType*/); 353*cdf0e10cSrcweir String sSpecial = ""; 354*cdf0e10cSrcweir 355*cdf0e10cSrcweir // TODO: DB 356*cdf0e10cSrcweir // DB.insertinto_documentcompare(sSourceVersion, sSourceName, sSourceCreatorType, 357*cdf0e10cSrcweir // m_sDestinationVersion, sDestinationName, sDestinationCreatorType, 358*cdf0e10cSrcweir // sDocumentPoolDir, sDocumentPoolName, m_sMailAddress, 359*cdf0e10cSrcweir // sSpecial, m_sParentDistinct); 360*cdf0e10cSrcweir TimeHelper.waitInSeconds(1, "wait for DB."); 361*cdf0e10cSrcweir // DB.test(); 362*cdf0e10cSrcweir // System.exit(1); 363*cdf0e10cSrcweir } 364*cdf0e10cSrcweir } 365*cdf0e10cSrcweir 366*cdf0e10cSrcweir private ArrayList<String> loadAndStoreReports(XNameAccess _xNameAccess, ArrayList<PropertyValue> _aPropertyList /*, int _nType*/ ) 367*cdf0e10cSrcweir { 368*cdf0e10cSrcweir ArrayList<String> aList = new ArrayList<String>(); 369*cdf0e10cSrcweir if (_xNameAccess != null) 370*cdf0e10cSrcweir { 371*cdf0e10cSrcweir String[] sElementNames = _xNameAccess.getElementNames(); 372*cdf0e10cSrcweir for(int i=0;i<sElementNames.length; i++) 373*cdf0e10cSrcweir { 374*cdf0e10cSrcweir String sReportName = sElementNames[i]; 375*cdf0e10cSrcweir XComponent xDoc = loadComponent(sReportName, _xNameAccess, _aPropertyList); 376*cdf0e10cSrcweir if (xDoc != null) 377*cdf0e10cSrcweir { 378*cdf0e10cSrcweir // util.utils.shortWait(1000); 379*cdf0e10cSrcweir // print? or store? 380*cdf0e10cSrcweir String sDocumentPathName = storeComponent(sReportName, xDoc /*, _nType*/); 381*cdf0e10cSrcweir aList.add(sDocumentPathName); 382*cdf0e10cSrcweir // util.utils.shortWait(1000); 383*cdf0e10cSrcweir closeComponent(xDoc); 384*cdf0e10cSrcweir // util.utils.shortWait(1000); 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir else 387*cdf0e10cSrcweir { 388*cdf0e10cSrcweir System.out.println("Leave out maybe due to errors."); 389*cdf0e10cSrcweir } 390*cdf0e10cSrcweir // sBackPath contains the path where to find the extracted ODB Document 391*cdf0e10cSrcweir } 392*cdf0e10cSrcweir } 393*cdf0e10cSrcweir return aList; 394*cdf0e10cSrcweir } 395*cdf0e10cSrcweir 396*cdf0e10cSrcweir private String getFormatExtension(Object _xComponent /* int _nType*/ ) 397*cdf0e10cSrcweir { 398*cdf0e10cSrcweir String sExtension; 399*cdf0e10cSrcweir XServiceInfo xServiceInfo = UnoRuntime.queryInterface( XServiceInfo.class, _xComponent ); 400*cdf0e10cSrcweir if ( xServiceInfo.supportsService( "com.sun.star.sheet.SpreadsheetDocument" ) ) 401*cdf0e10cSrcweir { 402*cdf0e10cSrcweir // calc 403*cdf0e10cSrcweir sExtension = ".ods"; 404*cdf0e10cSrcweir } 405*cdf0e10cSrcweir else if (xServiceInfo.supportsService("com.sun.star.text.TextDocument")) 406*cdf0e10cSrcweir { 407*cdf0e10cSrcweir //writer 408*cdf0e10cSrcweir sExtension = ".odt"; 409*cdf0e10cSrcweir } 410*cdf0e10cSrcweir else 411*cdf0e10cSrcweir { 412*cdf0e10cSrcweir sExtension = ".UNKNOWN"; 413*cdf0e10cSrcweir } 414*cdf0e10cSrcweir return sExtension; 415*cdf0e10cSrcweir } 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir // switch(_nType) 418*cdf0e10cSrcweir // { 419*cdf0e10cSrcweir // case WRITER: 420*cdf0e10cSrcweir // sExtension = ".odt"; 421*cdf0e10cSrcweir // break; 422*cdf0e10cSrcweir // case CALC: 423*cdf0e10cSrcweir // sExtension = ".ods"; 424*cdf0e10cSrcweir // break; 425*cdf0e10cSrcweir // default: 426*cdf0e10cSrcweir // sExtension = ".UNKNOWN"; 427*cdf0e10cSrcweir // } 428*cdf0e10cSrcweir // return sExtension; 429*cdf0e10cSrcweir // } 430*cdf0e10cSrcweir // private String getFileFormat(int _nType) 431*cdf0e10cSrcweir // { 432*cdf0e10cSrcweir // String sFileType; 433*cdf0e10cSrcweir // switch(_nType) 434*cdf0e10cSrcweir // { 435*cdf0e10cSrcweir // case WRITER: 436*cdf0e10cSrcweir // sFileType = "writer8"; 437*cdf0e10cSrcweir // break; 438*cdf0e10cSrcweir // case CALC: 439*cdf0e10cSrcweir // sFileType = "calc8"; 440*cdf0e10cSrcweir // break; 441*cdf0e10cSrcweir // default: 442*cdf0e10cSrcweir // sFileType = "UNKNOWN"; 443*cdf0e10cSrcweir // } 444*cdf0e10cSrcweir // return sFileType; 445*cdf0e10cSrcweir // } 446*cdf0e10cSrcweir 447*cdf0e10cSrcweir private String m_sOutputPath = null; 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir private String getOutputPath(/*int _nType*/) 450*cdf0e10cSrcweir { 451*cdf0e10cSrcweir if (m_sOutputPath == null) 452*cdf0e10cSrcweir { 453*cdf0e10cSrcweir String sOutputPath = (String)m_aParameterHelper.getTestParameters().get( convwatch.PropertyName.DOC_COMPARATOR_OUTPUT_PATH ); 454*cdf0e10cSrcweir sOutputPath = helper.StringHelper.removeQuoteIfExists(sOutputPath); 455*cdf0e10cSrcweir 456*cdf0e10cSrcweir // sOutputPath += "tmp_123"; 457*cdf0e10cSrcweir sOutputPath = FileHelper.appendPath(sOutputPath, DateHelper.getDateTimeForFilename()); 458*cdf0e10cSrcweir // sOutputPath += System.getProperty("file.separator"); 459*cdf0e10cSrcweir 460*cdf0e10cSrcweir // sOutputPath += getFileFormat(_nType); 461*cdf0e10cSrcweir // sOutputPath += System.getProperty("file.separator"); 462*cdf0e10cSrcweir 463*cdf0e10cSrcweir File aOutputFile = new File(sOutputPath); // create the directory of the given output path 464*cdf0e10cSrcweir aOutputFile.mkdirs(); 465*cdf0e10cSrcweir m_sOutputPath = sOutputPath; 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir return m_sOutputPath; 468*cdf0e10cSrcweir } 469*cdf0e10cSrcweir 470*cdf0e10cSrcweir /* 471*cdf0e10cSrcweir store given _xComponent under the given Name in DOC_COMPARATOR_INPUTPATH 472*cdf0e10cSrcweir */ 473*cdf0e10cSrcweir private String storeComponent(String _sName, Object _xComponent /*, int _nType*/ ) 474*cdf0e10cSrcweir { 475*cdf0e10cSrcweir String sOutputPath = getOutputPath(/*_nType*/); 476*cdf0e10cSrcweir 477*cdf0e10cSrcweir // // add DocumentPoolName 478*cdf0e10cSrcweir // sOutputPath = FileHelper.appendPath(sOutputPath, getDocumentPoolName(/*_nType*/)); 479*cdf0e10cSrcweir // // sOutputPath += System.getProperty("file.separator"); 480*cdf0e10cSrcweir // 481*cdf0e10cSrcweir // File aOutputFile = new File(sOutputPath); // create the directory of the given output path 482*cdf0e10cSrcweir // aOutputFile.mkdirs(); 483*cdf0e10cSrcweir 484*cdf0e10cSrcweir 485*cdf0e10cSrcweir String sName = _sName + getFormatExtension(_xComponent /*_nType*/); 486*cdf0e10cSrcweir sOutputPath = FileHelper.appendPath(sOutputPath, sName); 487*cdf0e10cSrcweir 488*cdf0e10cSrcweir // we need the name and path 489*cdf0e10cSrcweir String sBackPathName = sOutputPath; 490*cdf0e10cSrcweir 491*cdf0e10cSrcweir String sOutputURL = URLHelper.getFileURLFromSystemPath(sOutputPath); 492*cdf0e10cSrcweir 493*cdf0e10cSrcweir ArrayList<PropertyValue> aPropertyList = new ArrayList<PropertyValue>(); // set some properties for storeAsURL 494*cdf0e10cSrcweir 495*cdf0e10cSrcweir // PropertyValue aFileFormat = new PropertyValue(); 496*cdf0e10cSrcweir // aFileFormat.Name = "FilterName"; 497*cdf0e10cSrcweir // aFileFormat.Value = getFileFormat(_nType); 498*cdf0e10cSrcweir // aPropertyList.add(aFileFormat); 499*cdf0e10cSrcweir 500*cdf0e10cSrcweir PropertyValue aOverwrite = new PropertyValue(); // always overwrite already exist files 501*cdf0e10cSrcweir aOverwrite.Name = "Overwrite"; 502*cdf0e10cSrcweir aOverwrite.Value = Boolean.TRUE; 503*cdf0e10cSrcweir aPropertyList.add(aOverwrite); 504*cdf0e10cSrcweir 505*cdf0e10cSrcweir // store the document in an other directory 506*cdf0e10cSrcweir XStorable aStorable = UnoRuntime.queryInterface( XStorable.class, _xComponent); 507*cdf0e10cSrcweir if (aStorable != null) 508*cdf0e10cSrcweir { 509*cdf0e10cSrcweir GlobalLogWriter.println("store document as URL: '" + sOutputURL + "'"); 510*cdf0e10cSrcweir try 511*cdf0e10cSrcweir { 512*cdf0e10cSrcweir aStorable.storeAsURL(sOutputURL, PropertyHelper.createPropertyValueArrayFormArrayList(aPropertyList)); 513*cdf0e10cSrcweir } 514*cdf0e10cSrcweir catch (com.sun.star.io.IOException e) 515*cdf0e10cSrcweir { 516*cdf0e10cSrcweir GlobalLogWriter.println("ERROR: Exception caught"); 517*cdf0e10cSrcweir GlobalLogWriter.println("Can't write document URL: '" + sOutputURL + "'"); 518*cdf0e10cSrcweir GlobalLogWriter.println("Message: " + e.getMessage()); 519*cdf0e10cSrcweir } 520*cdf0e10cSrcweir } 521*cdf0e10cSrcweir return sBackPathName; 522*cdf0e10cSrcweir } 523*cdf0e10cSrcweir 524*cdf0e10cSrcweir private XComponent loadComponent(String _sName, Object _xComponent, ArrayList _aPropertyList) 525*cdf0e10cSrcweir { 526*cdf0e10cSrcweir XComponent xDocComponent = null; 527*cdf0e10cSrcweir XComponentLoader xComponentLoader = UnoRuntime.queryInterface( XComponentLoader.class, _xComponent ); 528*cdf0e10cSrcweir 529*cdf0e10cSrcweir try 530*cdf0e10cSrcweir { 531*cdf0e10cSrcweir PropertyValue[] aLoadProperties = PropertyHelper.createPropertyValueArrayFormArrayList(_aPropertyList); 532*cdf0e10cSrcweir GlobalLogWriter.println("Load component: '" + _sName + "'"); 533*cdf0e10cSrcweir xDocComponent = xComponentLoader.loadComponentFromURL(_sName, "_blank", FrameSearchFlag.ALL, aLoadProperties); 534*cdf0e10cSrcweir GlobalLogWriter.println("Load component: '" + _sName + "' done"); 535*cdf0e10cSrcweir } 536*cdf0e10cSrcweir catch (com.sun.star.io.IOException e) 537*cdf0e10cSrcweir { 538*cdf0e10cSrcweir GlobalLogWriter.println("ERROR: Exception caught"); 539*cdf0e10cSrcweir GlobalLogWriter.println("Can't load document '" + _sName + "'"); 540*cdf0e10cSrcweir GlobalLogWriter.println("Message: " + e.getMessage()); 541*cdf0e10cSrcweir } 542*cdf0e10cSrcweir catch (com.sun.star.lang.IllegalArgumentException e) 543*cdf0e10cSrcweir { 544*cdf0e10cSrcweir GlobalLogWriter.println("ERROR: Exception caught"); 545*cdf0e10cSrcweir GlobalLogWriter.println("Illegal Arguments given to loadComponentFromURL."); 546*cdf0e10cSrcweir GlobalLogWriter.println("Message: " + e.getMessage()); 547*cdf0e10cSrcweir } 548*cdf0e10cSrcweir return xDocComponent; 549*cdf0e10cSrcweir } 550*cdf0e10cSrcweir 551*cdf0e10cSrcweir private void closeComponent(XComponent _xDoc) 552*cdf0e10cSrcweir { 553*cdf0e10cSrcweir // Close the document 554*cdf0e10cSrcweir XCloseable xCloseable = UnoRuntime.queryInterface(XCloseable.class, _xDoc); 555*cdf0e10cSrcweir try 556*cdf0e10cSrcweir { 557*cdf0e10cSrcweir xCloseable.close(true); 558*cdf0e10cSrcweir } 559*cdf0e10cSrcweir catch (com.sun.star.util.CloseVetoException e) 560*cdf0e10cSrcweir { 561*cdf0e10cSrcweir GlobalLogWriter.println("ERROR: CloseVetoException caught"); 562*cdf0e10cSrcweir GlobalLogWriter.println("CloseVetoException occured Can't close document."); 563*cdf0e10cSrcweir GlobalLogWriter.println("Message: " + e.getMessage()); 564*cdf0e10cSrcweir } 565*cdf0e10cSrcweir } 566*cdf0e10cSrcweir 567*cdf0e10cSrcweir } 568