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 package convwatch; 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir import java.io.File; 32*cdf0e10cSrcweir import java.util.ArrayList; 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 35*cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 36*cdf0e10cSrcweir import com.sun.star.container.XNameAccess; 37*cdf0e10cSrcweir import com.sun.star.frame.XComponentLoader; 38*cdf0e10cSrcweir import com.sun.star.frame.XDesktop; 39*cdf0e10cSrcweir import com.sun.star.frame.XModel; 40*cdf0e10cSrcweir import com.sun.star.frame.XStorable; 41*cdf0e10cSrcweir import com.sun.star.lang.XComponent; 42*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 43*cdf0e10cSrcweir import com.sun.star.sdb.XDocumentDataSource; 44*cdf0e10cSrcweir import com.sun.star.sdb.XOfficeDatabaseDocument; 45*cdf0e10cSrcweir import com.sun.star.sdb.XReportDocumentsSupplier; 46*cdf0e10cSrcweir import com.sun.star.sdb.application.XDatabaseDocumentUI; 47*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 48*cdf0e10cSrcweir import com.sun.star.uno.XInterface; 49*cdf0e10cSrcweir import com.sun.star.util.XCloseable; 50*cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo; 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir // import util.BasicMacroTools; 53*cdf0e10cSrcweir // import util.DesktopTools; 54*cdf0e10cSrcweir // import util.dbg; 55*cdf0e10cSrcweir import complexlib.ComplexTestCase; 56*cdf0e10cSrcweir import helper.OfficeProvider; 57*cdf0e10cSrcweir import helper.URLHelper; 58*cdf0e10cSrcweir import helper.OfficeWatcher; 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir // import convwatch.DB; 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir // import java.util.Date; 63*cdf0e10cSrcweir // import java.text.SimpleDateFormat; 64*cdf0e10cSrcweir // import java.text.ParsePosition; 65*cdf0e10cSrcweir // import java.sql.Time; 66*cdf0e10cSrcweir // 67*cdf0e10cSrcweir // import java.io.BufferedReader; 68*cdf0e10cSrcweir // import java.io.File; 69*cdf0e10cSrcweir // import java.io.FileReader; 70*cdf0e10cSrcweir // import java.io.IOException; 71*cdf0e10cSrcweir // import java.io.FilenameFilter; 72*cdf0e10cSrcweir // 73*cdf0e10cSrcweir // import java.util.Vector; 74*cdf0e10cSrcweir // 75*cdf0e10cSrcweir // import helper.AppProvider; 76*cdf0e10cSrcweir // import java.text.DecimalFormat; 77*cdf0e10cSrcweir // import util.DynamicClassLoader; 78*cdf0e10cSrcweir // import java.util.StringTokenizer; 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir class PropertySetHelper 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir XPropertySet m_xPropertySet; 86*cdf0e10cSrcweir public PropertySetHelper(Object _aObj) 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir m_xPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, _aObj); 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir /** 92*cdf0e10cSrcweir get a property and don't convert it 93*cdf0e10cSrcweir @param _sName the string name of the property 94*cdf0e10cSrcweir @return the object value of the property without any conversion 95*cdf0e10cSrcweir */ 96*cdf0e10cSrcweir public Object getPropertyValueAsObject(String _sName) 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir Object aObject = null; 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir if (m_xPropertySet != null) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir try 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir aObject = m_xPropertySet.getPropertyValue(_sName); 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir catch (com.sun.star.beans.UnknownPropertyException e) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir System.out.println("ERROR: UnknownPropertyException caught. '" + _sName + "'"); 109*cdf0e10cSrcweir System.out.println("Message: " + e.getMessage()); 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir catch (com.sun.star.lang.WrappedTargetException e) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir System.out.println("ERROR: WrappedTargetException caught."); 114*cdf0e10cSrcweir System.out.println("Message: " + e.getMessage()); 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir return aObject; 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir class PropertyHelper 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir /** 124*cdf0e10cSrcweir Create a PropertyValue[] from a ArrayList 125*cdf0e10cSrcweir @param _aArrayList 126*cdf0e10cSrcweir @return a PropertyValue[] 127*cdf0e10cSrcweir */ 128*cdf0e10cSrcweir public static PropertyValue[] createPropertyValueArrayFormArrayList(ArrayList _aPropertyList) 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir // copy the whole PropertyValue List to an PropertyValue Array 131*cdf0e10cSrcweir PropertyValue[] aSaveProperties = null; 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir if (_aPropertyList == null) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir aSaveProperties = new PropertyValue[0]; 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir else 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir if (_aPropertyList.size() > 0) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir aSaveProperties = new PropertyValue[_aPropertyList.size()]; 142*cdf0e10cSrcweir for (int i = 0;i<_aPropertyList.size(); i++) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir aSaveProperties[i] = (PropertyValue) _aPropertyList.get(i); 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir else 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir aSaveProperties = new PropertyValue[0]; 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir return aSaveProperties; 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir public class ReportDesignerTest extends ComplexTestCase { 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir String mTestDocumentPath; 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir /** 161*cdf0e10cSrcweir * This method returns a list of Strings, each string must be a function name in this class. 162*cdf0e10cSrcweir * @return 163*cdf0e10cSrcweir */ 164*cdf0e10cSrcweir public String[] getTestMethodNames() 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir return new String[] {"ReportDesignTest"}; // MAIN 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir private void checkIfOfficeExists(String _sOfficePathWithTrash) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir String sOfficePath = ""; 172*cdf0e10cSrcweir int nIndex = _sOfficePathWithTrash.indexOf("soffice.exe"); 173*cdf0e10cSrcweir if (nIndex > 0) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir sOfficePath = _sOfficePathWithTrash.substring(0, nIndex + 11); 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir else 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir nIndex = _sOfficePathWithTrash.indexOf("soffice"); 180*cdf0e10cSrcweir if (nIndex > 0) 181*cdf0e10cSrcweir { 182*cdf0e10cSrcweir sOfficePath = _sOfficePathWithTrash.substring(0, nIndex + 7); 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir // if (sOfficePath.startsWith("\"") || 187*cdf0e10cSrcweir // sOfficePath.startsWith("'")) 188*cdf0e10cSrcweir // { 189*cdf0e10cSrcweir // sOfficePath = sOfficePath.substring(1); 190*cdf0e10cSrcweir // } 191*cdf0e10cSrcweir sOfficePath = helper.StringHelper.removeQuoteIfExists(sOfficePath); 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir log.println(sOfficePath); 194*cdf0e10cSrcweir File sOffice = new File(sOfficePath); 195*cdf0e10cSrcweir if (! sOffice.exists()) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir log.println("ERROR: There exists no office installation at given path: '" + sOfficePath + "'"); 198*cdf0e10cSrcweir System.exit(0); 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir private static XDesktop m_xDesktop = null; 204*cdf0e10cSrcweir public static XDesktop getXDesktop() 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir if (m_xDesktop == null) 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir try 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir XInterface xInterface = (XInterface) m_xXMultiServiceFactory.createInstance( "com.sun.star.frame.Desktop" ); 212*cdf0e10cSrcweir m_xDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, xInterface); 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir catch (com.sun.star.uno.Exception e) 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir log.println("ERROR: uno.Exception caught"); 217*cdf0e10cSrcweir log.println("Message: " + e.getMessage()); 218*cdf0e10cSrcweir } 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir return m_xDesktop; 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir private void showElements(XNameAccess _xNameAccess) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir if (_xNameAccess != null) 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir String[] sElementNames = _xNameAccess.getElementNames(); 228*cdf0e10cSrcweir for(int i=0;i<sElementNames.length; i++) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir System.out.println("Value: [" + i + "] := " + sElementNames[i]); 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir else 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir System.out.println("Warning: Given object is null."); 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir private OfficeProvider m_aProvider = null; 241*cdf0e10cSrcweir private static XMultiServiceFactory m_xXMultiServiceFactory = null; 242*cdf0e10cSrcweir private void startOffice() 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir // int tempTime = param.getInt("SingleTimeOut"); 245*cdf0e10cSrcweir param.put("TimeOut", new Integer(300000)); 246*cdf0e10cSrcweir System.out.println("TimeOut: " + param.getInt("TimeOut")); 247*cdf0e10cSrcweir System.out.println("ThreadTimeOut: " + param.getInt("ThreadTimeOut")); 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir // OfficeProvider aProvider = null; 250*cdf0e10cSrcweir m_aProvider = new OfficeProvider(); 251*cdf0e10cSrcweir m_xXMultiServiceFactory = (XMultiServiceFactory) m_aProvider.getManager(param); 252*cdf0e10cSrcweir param.put("ServiceFactory", m_xXMultiServiceFactory); 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir private void stopOffice() 256*cdf0e10cSrcweir { 257*cdf0e10cSrcweir if (m_aProvider != null) 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir m_aProvider.closeExistingOffice(param, true); 260*cdf0e10cSrcweir m_aProvider = null; 261*cdf0e10cSrcweir } 262*cdf0e10cSrcweir TimeHelper.waitInSeconds(2, "Give close Office some time."); 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir private String m_sMailAddress = null; 266*cdf0e10cSrcweir private String m_sParentDistinct = null; 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir // private String m_sUPDMinor; 269*cdf0e10cSrcweir // private String m_sCWS_WORK_STAMP; 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir private static String m_sSourceVersion; 272*cdf0e10cSrcweir private static String m_sDestinationVersion; 273*cdf0e10cSrcweir private static String m_sSourceName; 274*cdf0e10cSrcweir private static String m_sDestinationName; 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir private static final int WRITER = 1; 277*cdf0e10cSrcweir private static final int CALC = 2; 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir /** 280*cdf0e10cSrcweir * This is the main test Function of current ReportDesignerTest 281*cdf0e10cSrcweir */ 282*cdf0e10cSrcweir public void ReportDesignTest() 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir convwatch.GlobalLogWriter.set(log); 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir GlobalLogWriter.get().println("Set office watcher"); 287*cdf0e10cSrcweir OfficeWatcher aWatcher = (OfficeWatcher)param.get("Watcher"); 288*cdf0e10cSrcweir GlobalLogWriter.get().setWatcher(aWatcher); 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir try 291*cdf0e10cSrcweir { 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir // -------------------- preconditions, try to find an office -------------------- 294*cdf0e10cSrcweir 295*cdf0e10cSrcweir String sAppExecutionCommand = (String) param.get("AppExecutionCommand"); 296*cdf0e10cSrcweir log.println("sAppExecutionCommand='" + sAppExecutionCommand + "'"); 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir String sUser = System.getProperty("user.name"); 299*cdf0e10cSrcweir log.println("user.name='" + sUser + "'"); 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir // String sVCSID = System.getProperty("VCSID"); 302*cdf0e10cSrcweir // log.println("VCSID='" + sVCSID + "'"); 303*cdf0e10cSrcweir // m_sMailAddress = sVCSID + "@openoffice.org"; 304*cdf0e10cSrcweir m_sMailAddress = System.getProperty("MailAddress"); 305*cdf0e10cSrcweir log.println("Assumed mail address: " + m_sMailAddress); 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir m_sParentDistinct = System.getProperty("ParentDistinct"); 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir m_sSourceVersion = System.getProperty("SourceVersion"); 310*cdf0e10cSrcweir m_sSourceName = System.getProperty("SourceName"); 311*cdf0e10cSrcweir m_sDestinationVersion = System.getProperty("DestinationVersion"); 312*cdf0e10cSrcweir m_sDestinationName = System.getProperty("DestinationName"); 313*cdf0e10cSrcweir // createDBEntry(); 314*cdf0e10cSrcweir // log.println("Current CWS: " + m_sCWS_WORK_STAMP); 315*cdf0e10cSrcweir // log.println("Current MWS: " + m_sUPDMinor); 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir if (m_sSourceVersion == null) 318*cdf0e10cSrcweir { 319*cdf0e10cSrcweir System.out.println("Error, Sourceversion is null."); 320*cdf0e10cSrcweir System.exit(1); 321*cdf0e10cSrcweir } 322*cdf0e10cSrcweir 323*cdf0e10cSrcweir sAppExecutionCommand = sAppExecutionCommand.replaceAll( "\\$\\{USERNAME\\}", sUser); 324*cdf0e10cSrcweir log.println("sAppExecutionCommand='" + sAppExecutionCommand + "'"); 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir // an other way to replace strings 327*cdf0e10cSrcweir // sAppExecutionCommand = utils.replaceAll13(sAppExecutionCommand, "${USERNAME}", sUser); 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir checkIfOfficeExists(sAppExecutionCommand); 330*cdf0e10cSrcweir param.put("AppExecutionCommand", new String(sAppExecutionCommand)); 331*cdf0e10cSrcweir 332*cdf0e10cSrcweir // System.exit(1); 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir // --------------------------- Start the given Office --------------------------- 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir startOffice(); 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir // ------------------------------ Start a test run ------------------------------ 339*cdf0e10cSrcweir 340*cdf0e10cSrcweir // String sCurrentDirectory = System.getProperty("user.dir"); 341*cdf0e10cSrcweir // log.println("Current Dir: " + sCurrentDirectory); 342*cdf0e10cSrcweir String sDocument = (String) param.get(convwatch.PropertyName.DOC_COMPARATOR_INPUT_PATH); 343*cdf0e10cSrcweir sDocument = helper.StringHelper.removeQuoteIfExists( sDocument ); 344*cdf0e10cSrcweir startTestForFile(sDocument); 345*cdf0e10cSrcweir // if (sDocument.toLowerCase().indexOf("writer") >= 0) 346*cdf0e10cSrcweir // { 347*cdf0e10cSrcweir // startTestForFile(sDocument, WRITER); 348*cdf0e10cSrcweir // } 349*cdf0e10cSrcweir // else if (sDocument.toLowerCase().indexOf("calc") >= 0) 350*cdf0e10cSrcweir // { 351*cdf0e10cSrcweir // startTestForFile(sDocument, CALC); 352*cdf0e10cSrcweir // } 353*cdf0e10cSrcweir // else 354*cdf0e10cSrcweir // { 355*cdf0e10cSrcweir // assure("Can't identify the document no 'writer' nor 'calc' in it's name given.", false); 356*cdf0e10cSrcweir // } 357*cdf0e10cSrcweir } 358*cdf0e10cSrcweir catch (AssureException e) 359*cdf0e10cSrcweir { 360*cdf0e10cSrcweir stopOffice(); 361*cdf0e10cSrcweir throw new AssureException(e.getMessage()); 362*cdf0e10cSrcweir } 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir // ------------------------------ Office shutdown ------------------------------ 365*cdf0e10cSrcweir stopOffice(); 366*cdf0e10cSrcweir } 367*cdf0e10cSrcweir 368*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 369*cdf0e10cSrcweir private void startTestForFile(String _sDocument /*, int _nType*/) 370*cdf0e10cSrcweir { 371*cdf0e10cSrcweir File aFile = new File(_sDocument); 372*cdf0e10cSrcweir assure("Test File '" + _sDocument + "' doesn't exist.", aFile.exists()); 373*cdf0e10cSrcweir 374*cdf0e10cSrcweir String sFileURL = URLHelper.getFileURLFromSystemPath(_sDocument); 375*cdf0e10cSrcweir log.println("File URL: " + sFileURL); 376*cdf0e10cSrcweir 377*cdf0e10cSrcweir XComponent xDocComponent = loadComponent(sFileURL, getXDesktop(), null); 378*cdf0e10cSrcweir log.println("Load done"); 379*cdf0e10cSrcweir // context = createUnoService("com.sun.star.sdb.DatabaseContext") 380*cdf0e10cSrcweir // oDataBase = context.getByName("hh") 381*cdf0e10cSrcweir // oDBDoc = oDataBase.DatabaseDocument 382*cdf0e10cSrcweir // 383*cdf0e10cSrcweir // dim args(1) as new com.sun.star.beans.PropertyValue 384*cdf0e10cSrcweir // args(0).Name = "ActiveConnection" 385*cdf0e10cSrcweir // args(0).Value = oDBDoc.getCurrentController().getPropertyValue("ActiveConnection") 386*cdf0e10cSrcweir // reportContainer = oDBDoc.getReportDocuments() 387*cdf0e10cSrcweir // report = reportContainer.loadComponentFromURL("Report40","",0,args) 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir try 390*cdf0e10cSrcweir { 391*cdf0e10cSrcweir XInterface x = (XInterface)m_xXMultiServiceFactory.createInstance("com.sun.star.sdb.DatabaseContext"); 392*cdf0e10cSrcweir assure("can't create instance of com.sun.star.sdb.DatabaseContext", x != null); 393*cdf0e10cSrcweir log.println("createInstance com.sun.star.sdb.DatabaseContext done"); 394*cdf0e10cSrcweir 395*cdf0e10cSrcweir XNameAccess xNameAccess = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, x); 396*cdf0e10cSrcweir showElements(xNameAccess); 397*cdf0e10cSrcweir Object aObj = xNameAccess.getByName(sFileURL); 398*cdf0e10cSrcweir // log.println("1"); 399*cdf0e10cSrcweir 400*cdf0e10cSrcweir // PropertySetHelper aHelper = new PropertySetHelper(aObj); 401*cdf0e10cSrcweir XDocumentDataSource xDataSource = (XDocumentDataSource)UnoRuntime.queryInterface(XDocumentDataSource.class, aObj); 402*cdf0e10cSrcweir // Object aDatabaseDocmuent = aHelper.getPropertyValueAsObject("DatabaseDocument"); 403*cdf0e10cSrcweir XOfficeDatabaseDocument xOfficeDBDoc = xDataSource.getDatabaseDocument(); 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir // XOfficeDatabaseDocument xOfficeDBDoc = (XOfficeDatabaseDocument)UnoRuntime.queryInterface(XOfficeDatabaseDocument.class, aDatabaseDocument); 406*cdf0e10cSrcweir assure("can't access DatabaseDocument", xOfficeDBDoc != null); 407*cdf0e10cSrcweir // log.println("2"); 408*cdf0e10cSrcweir 409*cdf0e10cSrcweir XModel xDBSource = (XModel)UnoRuntime.queryInterface(XModel.class, xOfficeDBDoc); 410*cdf0e10cSrcweir Object aController = xDBSource.getCurrentController(); 411*cdf0e10cSrcweir assure("Controller of xOfficeDatabaseDocument is empty!", aController != null); 412*cdf0e10cSrcweir // log.println("3"); 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir XDatabaseDocumentUI aDBDocUI = (XDatabaseDocumentUI)UnoRuntime.queryInterface(XDatabaseDocumentUI.class, aController); 415*cdf0e10cSrcweir aDBDocUI.connect(); 416*cdf0e10cSrcweir // if (aDBDocUI.isConnected()) 417*cdf0e10cSrcweir // { 418*cdf0e10cSrcweir // System.out.println("true"); 419*cdf0e10cSrcweir // } 420*cdf0e10cSrcweir // else 421*cdf0e10cSrcweir // { 422*cdf0e10cSrcweir // System.out.println("false"); 423*cdf0e10cSrcweir // } 424*cdf0e10cSrcweir // log.println("4"); 425*cdf0e10cSrcweir 426*cdf0e10cSrcweir // aHelper = new PropertySetHelper(aController); 427*cdf0e10cSrcweir 428*cdf0e10cSrcweir // Object aActiveConnectionObj = aHelper.getPropertyValueAsObject("ActiveConnection"); 429*cdf0e10cSrcweir Object aActiveConnectionObj = aDBDocUI.getActiveConnection(); 430*cdf0e10cSrcweir assure("ActiveConnection is empty", aActiveConnectionObj != null); 431*cdf0e10cSrcweir // log.println("5"); 432*cdf0e10cSrcweir 433*cdf0e10cSrcweir XReportDocumentsSupplier xSupplier = (XReportDocumentsSupplier)UnoRuntime.queryInterface(XReportDocumentsSupplier.class, xOfficeDBDoc); 434*cdf0e10cSrcweir xNameAccess = xSupplier.getReportDocuments(); 435*cdf0e10cSrcweir assure("xOfficeDatabaseDocument returns no Report Document", xNameAccess != null); 436*cdf0e10cSrcweir // log.println("5"); 437*cdf0e10cSrcweir 438*cdf0e10cSrcweir showElements(xNameAccess); 439*cdf0e10cSrcweir 440*cdf0e10cSrcweir ArrayList aPropertyList = new ArrayList(); 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir PropertyValue aActiveConnection = new PropertyValue(); 443*cdf0e10cSrcweir aActiveConnection.Name = "ActiveConnection"; 444*cdf0e10cSrcweir aActiveConnection.Value = aActiveConnectionObj; 445*cdf0e10cSrcweir aPropertyList.add(aActiveConnection); 446*cdf0e10cSrcweir 447*cdf0e10cSrcweir loadAndStoreReports(xNameAccess, aPropertyList /*, _nType*/ ); 448*cdf0e10cSrcweir createDBEntry(/*_nType*/); 449*cdf0e10cSrcweir } 450*cdf0e10cSrcweir catch(com.sun.star.uno.Exception e) 451*cdf0e10cSrcweir { 452*cdf0e10cSrcweir log.println("ERROR: Exception caught"); 453*cdf0e10cSrcweir log.println("Message: " + e.getMessage()); 454*cdf0e10cSrcweir } 455*cdf0e10cSrcweir 456*cdf0e10cSrcweir // String mTestDocumentPath = (String) param.get("TestDocumentPath"); 457*cdf0e10cSrcweir // System.out.println("mTestDocumentPath: '" + mTestDocumentPath + "'"); 458*cdf0e10cSrcweir // // workaround for issue using deprecated "DOCPTH" prop 459*cdf0e10cSrcweir // System.setProperty("DOCPTH", mTestDocumentPath); 460*cdf0e10cSrcweir 461*cdf0e10cSrcweir // Close the document 462*cdf0e10cSrcweir closeComponent(xDocComponent); 463*cdf0e10cSrcweir } 464*cdf0e10cSrcweir 465*cdf0e10cSrcweir private String getDocumentPoolName(/*int _nType*/) 466*cdf0e10cSrcweir { 467*cdf0e10cSrcweir return "AutogenReportDesignTest"; 468*cdf0e10cSrcweir // return getFileFormat(_nType); 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 472*cdf0e10cSrcweir private void createDBEntry(/*int _nType*/) 473*cdf0e10cSrcweir { 474*cdf0e10cSrcweir // try to connect the database 475*cdf0e10cSrcweir String sDBConnection = (String)param.get( convwatch.PropertyName.DB_CONNECTION_STRING ); 476*cdf0e10cSrcweir log.println("DBConnection: " + sDBConnection); 477*cdf0e10cSrcweir DB.init(sDBConnection); 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir // String sFixRefSubDirectory = "ReportDesign_qa_complex_" + getFileFormat(_nType); 480*cdf0e10cSrcweir String sFixRefSubDirectory = "ReportDesignFixRef"; 481*cdf0e10cSrcweir 482*cdf0e10cSrcweir String sSourceVersion = m_sSourceVersion; 483*cdf0e10cSrcweir // String sSourceVersion = sFixRefSubDirectory; 484*cdf0e10cSrcweir String sSourceName = m_sSourceName; 485*cdf0e10cSrcweir // String sSourceCreatorType = "fixref"; 486*cdf0e10cSrcweir String sSourceCreatorType = ""; 487*cdf0e10cSrcweir String sDestinationVersion = m_sDestinationVersion; 488*cdf0e10cSrcweir // if (sDestinationVersion.length() == 0) 489*cdf0e10cSrcweir // { 490*cdf0e10cSrcweir // sDestinationVersion = m_sUPDMinor; 491*cdf0e10cSrcweir // } 492*cdf0e10cSrcweir String sDestinationName = m_sDestinationName; 493*cdf0e10cSrcweir String sDestinationCreatorType = ""; 494*cdf0e10cSrcweir String sDocumentPoolDir = getOutputPath(/*_nType*/); 495*cdf0e10cSrcweir String sDocumentPoolName = getDocumentPoolName(/*_nType*/); 496*cdf0e10cSrcweir String sSpecial = ""; 497*cdf0e10cSrcweir 498*cdf0e10cSrcweir DB.insertinto_documentcompare(sSourceVersion, sSourceName, sSourceCreatorType, 499*cdf0e10cSrcweir m_sDestinationVersion, sDestinationName, sDestinationCreatorType, 500*cdf0e10cSrcweir sDocumentPoolDir, sDocumentPoolName, m_sMailAddress, 501*cdf0e10cSrcweir sSpecial, m_sParentDistinct); 502*cdf0e10cSrcweir TimeHelper.waitInSeconds(1, "wait for DB."); 503*cdf0e10cSrcweir // DB.test(); 504*cdf0e10cSrcweir // System.exit(1); 505*cdf0e10cSrcweir } 506*cdf0e10cSrcweir 507*cdf0e10cSrcweir private void loadAndStoreReports(XNameAccess _xNameAccess, ArrayList _aPropertyList /*, int _nType*/ ) 508*cdf0e10cSrcweir { 509*cdf0e10cSrcweir if (_xNameAccess != null) 510*cdf0e10cSrcweir { 511*cdf0e10cSrcweir String[] sElementNames = _xNameAccess.getElementNames(); 512*cdf0e10cSrcweir for(int i=0;i<sElementNames.length; i++) 513*cdf0e10cSrcweir { 514*cdf0e10cSrcweir String sReportName = sElementNames[i]; 515*cdf0e10cSrcweir XComponent xDoc = loadComponent(sReportName, _xNameAccess, _aPropertyList); 516*cdf0e10cSrcweir // print? or store? 517*cdf0e10cSrcweir storeComponent(sReportName, xDoc /*, _nType*/); 518*cdf0e10cSrcweir closeComponent(xDoc); 519*cdf0e10cSrcweir } 520*cdf0e10cSrcweir } 521*cdf0e10cSrcweir } 522*cdf0e10cSrcweir 523*cdf0e10cSrcweir private String getFormatExtension(Object _xComponent /* int _nType*/ ) 524*cdf0e10cSrcweir { 525*cdf0e10cSrcweir String sExtension; 526*cdf0e10cSrcweir XServiceInfo xServiceInfo = (XServiceInfo) UnoRuntime.queryInterface( XServiceInfo.class, _xComponent ); 527*cdf0e10cSrcweir if ( xServiceInfo.supportsService( "com.sun.star.sheet.SpreadsheetDocument" ) ) 528*cdf0e10cSrcweir { 529*cdf0e10cSrcweir // calc 530*cdf0e10cSrcweir sExtension = ".ods"; 531*cdf0e10cSrcweir } 532*cdf0e10cSrcweir else if (xServiceInfo.supportsService("com.sun.star.text.TextDocument")) 533*cdf0e10cSrcweir { 534*cdf0e10cSrcweir //writer 535*cdf0e10cSrcweir sExtension = ".odt"; 536*cdf0e10cSrcweir } 537*cdf0e10cSrcweir else 538*cdf0e10cSrcweir { 539*cdf0e10cSrcweir sExtension = ".UNKNOWN"; 540*cdf0e10cSrcweir } 541*cdf0e10cSrcweir return sExtension; 542*cdf0e10cSrcweir } 543*cdf0e10cSrcweir 544*cdf0e10cSrcweir // switch(_nType) 545*cdf0e10cSrcweir // { 546*cdf0e10cSrcweir // case WRITER: 547*cdf0e10cSrcweir // sExtension = ".odt"; 548*cdf0e10cSrcweir // break; 549*cdf0e10cSrcweir // case CALC: 550*cdf0e10cSrcweir // sExtension = ".ods"; 551*cdf0e10cSrcweir // break; 552*cdf0e10cSrcweir // default: 553*cdf0e10cSrcweir // sExtension = ".UNKNOWN"; 554*cdf0e10cSrcweir // } 555*cdf0e10cSrcweir // return sExtension; 556*cdf0e10cSrcweir // } 557*cdf0e10cSrcweir // private String getFileFormat(int _nType) 558*cdf0e10cSrcweir // { 559*cdf0e10cSrcweir // String sFileType; 560*cdf0e10cSrcweir // switch(_nType) 561*cdf0e10cSrcweir // { 562*cdf0e10cSrcweir // case WRITER: 563*cdf0e10cSrcweir // sFileType = "writer8"; 564*cdf0e10cSrcweir // break; 565*cdf0e10cSrcweir // case CALC: 566*cdf0e10cSrcweir // sFileType = "calc8"; 567*cdf0e10cSrcweir // break; 568*cdf0e10cSrcweir // default: 569*cdf0e10cSrcweir // sFileType = "UNKNOWN"; 570*cdf0e10cSrcweir // } 571*cdf0e10cSrcweir // return sFileType; 572*cdf0e10cSrcweir // } 573*cdf0e10cSrcweir 574*cdf0e10cSrcweir private String m_sOutputPath = null; 575*cdf0e10cSrcweir 576*cdf0e10cSrcweir private String getOutputPath(/*int _nType*/) 577*cdf0e10cSrcweir { 578*cdf0e10cSrcweir if (m_sOutputPath == null) 579*cdf0e10cSrcweir { 580*cdf0e10cSrcweir String sOutputPath = (String)param.get( convwatch.PropertyName.DOC_COMPARATOR_OUTPUT_PATH ); 581*cdf0e10cSrcweir sOutputPath = helper.StringHelper.removeQuoteIfExists(sOutputPath); 582*cdf0e10cSrcweir 583*cdf0e10cSrcweir if (!sOutputPath.endsWith("/") || // construct the output file name 584*cdf0e10cSrcweir !sOutputPath.endsWith("\\")) 585*cdf0e10cSrcweir { 586*cdf0e10cSrcweir sOutputPath += System.getProperty("file.separator"); 587*cdf0e10cSrcweir } 588*cdf0e10cSrcweir // sOutputPath += "tmp_123"; 589*cdf0e10cSrcweir sOutputPath += DateHelper.getDateTimeForFilename(); 590*cdf0e10cSrcweir sOutputPath += System.getProperty("file.separator"); 591*cdf0e10cSrcweir 592*cdf0e10cSrcweir // sOutputPath += getFileFormat(_nType); 593*cdf0e10cSrcweir // sOutputPath += System.getProperty("file.separator"); 594*cdf0e10cSrcweir 595*cdf0e10cSrcweir File aOutputFile = new File(sOutputPath); // create the directory of the given output path 596*cdf0e10cSrcweir aOutputFile.mkdirs(); 597*cdf0e10cSrcweir m_sOutputPath = sOutputPath; 598*cdf0e10cSrcweir } 599*cdf0e10cSrcweir return m_sOutputPath; 600*cdf0e10cSrcweir } 601*cdf0e10cSrcweir 602*cdf0e10cSrcweir /* 603*cdf0e10cSrcweir store given _xComponent under the given Name in DOC_COMPARATOR_INPUTPATH 604*cdf0e10cSrcweir */ 605*cdf0e10cSrcweir private void storeComponent(String _sName, Object _xComponent /*, int _nType*/ ) 606*cdf0e10cSrcweir { 607*cdf0e10cSrcweir String sOutputPath = getOutputPath(/*_nType*/); 608*cdf0e10cSrcweir 609*cdf0e10cSrcweir // add DocumentPoolName 610*cdf0e10cSrcweir sOutputPath += getDocumentPoolName(/*_nType*/); 611*cdf0e10cSrcweir sOutputPath += System.getProperty("file.separator"); 612*cdf0e10cSrcweir 613*cdf0e10cSrcweir File aOutputFile = new File(sOutputPath); // create the directory of the given output path 614*cdf0e10cSrcweir aOutputFile.mkdirs(); 615*cdf0e10cSrcweir 616*cdf0e10cSrcweir sOutputPath += _sName; 617*cdf0e10cSrcweir sOutputPath += getFormatExtension(_xComponent /*_nType*/); 618*cdf0e10cSrcweir 619*cdf0e10cSrcweir String sOutputURL = URLHelper.getFileURLFromSystemPath(sOutputPath); 620*cdf0e10cSrcweir 621*cdf0e10cSrcweir ArrayList aPropertyList = new ArrayList(); // set some properties for storeAsURL 622*cdf0e10cSrcweir 623*cdf0e10cSrcweir // PropertyValue aFileFormat = new PropertyValue(); 624*cdf0e10cSrcweir // aFileFormat.Name = "FilterName"; 625*cdf0e10cSrcweir // aFileFormat.Value = getFileFormat(_nType); 626*cdf0e10cSrcweir // aPropertyList.add(aFileFormat); 627*cdf0e10cSrcweir 628*cdf0e10cSrcweir PropertyValue aOverwrite = new PropertyValue(); // always overwrite already exist files 629*cdf0e10cSrcweir aOverwrite.Name = "Overwrite"; 630*cdf0e10cSrcweir aOverwrite.Value = Boolean.TRUE; 631*cdf0e10cSrcweir aPropertyList.add(aOverwrite); 632*cdf0e10cSrcweir 633*cdf0e10cSrcweir // store the document in an other directory 634*cdf0e10cSrcweir XStorable aStorable = (XStorable) UnoRuntime.queryInterface( XStorable.class, _xComponent); 635*cdf0e10cSrcweir if (aStorable != null) 636*cdf0e10cSrcweir { 637*cdf0e10cSrcweir log.println("store document as URL: '" + sOutputURL + "'"); 638*cdf0e10cSrcweir try 639*cdf0e10cSrcweir { 640*cdf0e10cSrcweir aStorable.storeAsURL(sOutputURL, PropertyHelper.createPropertyValueArrayFormArrayList(aPropertyList)); 641*cdf0e10cSrcweir } 642*cdf0e10cSrcweir catch (com.sun.star.io.IOException e) 643*cdf0e10cSrcweir { 644*cdf0e10cSrcweir log.println("ERROR: Exception caught"); 645*cdf0e10cSrcweir log.println("Can't write document URL: '" + sOutputURL + "'"); 646*cdf0e10cSrcweir log.println("Message: " + e.getMessage()); 647*cdf0e10cSrcweir } 648*cdf0e10cSrcweir } 649*cdf0e10cSrcweir } 650*cdf0e10cSrcweir 651*cdf0e10cSrcweir private XComponent loadComponent(String _sName, Object _xComponent, ArrayList _aPropertyList) 652*cdf0e10cSrcweir { 653*cdf0e10cSrcweir XComponent xDocComponent = null; 654*cdf0e10cSrcweir XComponentLoader xComponentLoader = (XComponentLoader) UnoRuntime.queryInterface( XComponentLoader.class, _xComponent ); 655*cdf0e10cSrcweir 656*cdf0e10cSrcweir try 657*cdf0e10cSrcweir { 658*cdf0e10cSrcweir PropertyValue[] aLoadProperties = PropertyHelper.createPropertyValueArrayFormArrayList(_aPropertyList); 659*cdf0e10cSrcweir log.println("Load component: '" + _sName + "'"); 660*cdf0e10cSrcweir xDocComponent = xComponentLoader.loadComponentFromURL(_sName, "_blank", 0, aLoadProperties); 661*cdf0e10cSrcweir log.println("Load component: '" + _sName + "' done"); 662*cdf0e10cSrcweir } 663*cdf0e10cSrcweir catch (com.sun.star.io.IOException e) 664*cdf0e10cSrcweir { 665*cdf0e10cSrcweir log.println("ERROR: Exception caught"); 666*cdf0e10cSrcweir log.println("Can't load document '" + _sName + "'"); 667*cdf0e10cSrcweir log.println("Message: " + e.getMessage()); 668*cdf0e10cSrcweir } 669*cdf0e10cSrcweir catch (com.sun.star.lang.IllegalArgumentException e) 670*cdf0e10cSrcweir { 671*cdf0e10cSrcweir log.println("ERROR: Exception caught"); 672*cdf0e10cSrcweir log.println("Illegal Arguments given to loadComponentFromURL."); 673*cdf0e10cSrcweir log.println("Message: " + e.getMessage()); 674*cdf0e10cSrcweir } 675*cdf0e10cSrcweir return xDocComponent; 676*cdf0e10cSrcweir } 677*cdf0e10cSrcweir 678*cdf0e10cSrcweir private void closeComponent(XComponent _xDoc) 679*cdf0e10cSrcweir { 680*cdf0e10cSrcweir // Close the document 681*cdf0e10cSrcweir XCloseable xCloseable = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, _xDoc); 682*cdf0e10cSrcweir try 683*cdf0e10cSrcweir { 684*cdf0e10cSrcweir xCloseable.close(true); 685*cdf0e10cSrcweir } 686*cdf0e10cSrcweir catch (com.sun.star.util.CloseVetoException e) 687*cdf0e10cSrcweir { 688*cdf0e10cSrcweir log.println("ERROR: CloseVetoException caught"); 689*cdf0e10cSrcweir log.println("CloseVetoException occured Can't close document."); 690*cdf0e10cSrcweir log.println("Message: " + e.getMessage()); 691*cdf0e10cSrcweir } 692*cdf0e10cSrcweir } 693*cdf0e10cSrcweir 694*cdf0e10cSrcweir } 695