/* ************************************************************************ * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite * * This file is part of OpenOffice.org. * * OpenOffice.org is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License version 3 * only, as published by the Free Software Foundation. * * OpenOffice.org is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License version 3 for more details * (a copy is included in the LICENSE file that accompanied this code). * * You should have received a copy of the GNU Lesser General Public License * version 3 along with OpenOffice.org. If not, see * * for a copy of the LGPLv3 License. * ************************************************************************/ package convwatch; import java.io.File; import java.util.ArrayList; import com.sun.star.beans.PropertyValue; import com.sun.star.beans.XPropertySet; import com.sun.star.container.XNameAccess; import com.sun.star.frame.XComponentLoader; import com.sun.star.frame.XDesktop; import com.sun.star.frame.XModel; import com.sun.star.frame.XStorable; import com.sun.star.lang.XComponent; import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.sdb.XDocumentDataSource; import com.sun.star.sdb.XOfficeDatabaseDocument; import com.sun.star.sdb.XReportDocumentsSupplier; import com.sun.star.sdb.application.XDatabaseDocumentUI; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XInterface; import com.sun.star.util.XCloseable; import com.sun.star.lang.XServiceInfo; // import util.BasicMacroTools; // import util.DesktopTools; // import util.dbg; import complexlib.ComplexTestCase; import helper.OfficeProvider; import helper.URLHelper; import helper.OfficeWatcher; // import convwatch.DB; // import java.util.Date; // import java.text.SimpleDateFormat; // import java.text.ParsePosition; // import java.sql.Time; // // import java.io.BufferedReader; // import java.io.File; // import java.io.FileReader; // import java.io.IOException; // import java.io.FilenameFilter; // // import java.util.Vector; // // import helper.AppProvider; // import java.text.DecimalFormat; // import util.DynamicClassLoader; // import java.util.StringTokenizer; class PropertySetHelper { XPropertySet m_xPropertySet; public PropertySetHelper(Object _aObj) { m_xPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, _aObj); } /** get a property and don't convert it @param _sName the string name of the property @return the object value of the property without any conversion */ public Object getPropertyValueAsObject(String _sName) { Object aObject = null; if (m_xPropertySet != null) { try { aObject = m_xPropertySet.getPropertyValue(_sName); } catch (com.sun.star.beans.UnknownPropertyException e) { System.out.println("ERROR: UnknownPropertyException caught. '" + _sName + "'"); System.out.println("Message: " + e.getMessage()); } catch (com.sun.star.lang.WrappedTargetException e) { System.out.println("ERROR: WrappedTargetException caught."); System.out.println("Message: " + e.getMessage()); } } return aObject; } } class PropertyHelper { /** Create a PropertyValue[] from a ArrayList @param _aArrayList @return a PropertyValue[] */ public static PropertyValue[] createPropertyValueArrayFormArrayList(ArrayList _aPropertyList) { // copy the whole PropertyValue List to an PropertyValue Array PropertyValue[] aSaveProperties = null; if (_aPropertyList == null) { aSaveProperties = new PropertyValue[0]; } else { if (_aPropertyList.size() > 0) { aSaveProperties = new PropertyValue[_aPropertyList.size()]; for (int i = 0;i<_aPropertyList.size(); i++) { aSaveProperties[i] = (PropertyValue) _aPropertyList.get(i); } } else { aSaveProperties = new PropertyValue[0]; } } return aSaveProperties; } } public class ReportDesignerTest extends ComplexTestCase { String mTestDocumentPath; /** * This method returns a list of Strings, each string must be a function name in this class. * @return */ public String[] getTestMethodNames() { return new String[] {"ReportDesignTest"}; // MAIN } private void checkIfOfficeExists(String _sOfficePathWithTrash) { String sOfficePath = ""; int nIndex = _sOfficePathWithTrash.indexOf("soffice.exe"); if (nIndex > 0) { sOfficePath = _sOfficePathWithTrash.substring(0, nIndex + 11); } else { nIndex = _sOfficePathWithTrash.indexOf("soffice"); if (nIndex > 0) { sOfficePath = _sOfficePathWithTrash.substring(0, nIndex + 7); } } // if (sOfficePath.startsWith("\"") || // sOfficePath.startsWith("'")) // { // sOfficePath = sOfficePath.substring(1); // } sOfficePath = helper.StringHelper.removeQuoteIfExists(sOfficePath); log.println(sOfficePath); File sOffice = new File(sOfficePath); if (! sOffice.exists()) { log.println("ERROR: There exists no office installation at given path: '" + sOfficePath + "'"); System.exit(0); } } private static XDesktop m_xDesktop = null; public static XDesktop getXDesktop() { if (m_xDesktop == null) { try { XInterface xInterface = (XInterface) m_xXMultiServiceFactory.createInstance( "com.sun.star.frame.Desktop" ); m_xDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, xInterface); } catch (com.sun.star.uno.Exception e) { log.println("ERROR: uno.Exception caught"); log.println("Message: " + e.getMessage()); } } return m_xDesktop; } private void showElements(XNameAccess _xNameAccess) { if (_xNameAccess != null) { String[] sElementNames = _xNameAccess.getElementNames(); for(int i=0;i= 0) // { // startTestForFile(sDocument, WRITER); // } // else if (sDocument.toLowerCase().indexOf("calc") >= 0) // { // startTestForFile(sDocument, CALC); // } // else // { // assure("Can't identify the document no 'writer' nor 'calc' in it's name given.", false); // } } catch (AssureException e) { stopOffice(); throw new AssureException(e.getMessage()); } // ------------------------------ Office shutdown ------------------------------ stopOffice(); } // ----------------------------------------------------------------------------- private void startTestForFile(String _sDocument /*, int _nType*/) { File aFile = new File(_sDocument); assure("Test File '" + _sDocument + "' doesn't exist.", aFile.exists()); String sFileURL = URLHelper.getFileURLFromSystemPath(_sDocument); log.println("File URL: " + sFileURL); XComponent xDocComponent = loadComponent(sFileURL, getXDesktop(), null); log.println("Load done"); // context = createUnoService("com.sun.star.sdb.DatabaseContext") // oDataBase = context.getByName("hh") // oDBDoc = oDataBase.DatabaseDocument // // dim args(1) as new com.sun.star.beans.PropertyValue // args(0).Name = "ActiveConnection" // args(0).Value = oDBDoc.getCurrentController().getPropertyValue("ActiveConnection") // reportContainer = oDBDoc.getReportDocuments() // report = reportContainer.loadComponentFromURL("Report40","",0,args) try { XInterface x = (XInterface)m_xXMultiServiceFactory.createInstance("com.sun.star.sdb.DatabaseContext"); assure("can't create instance of com.sun.star.sdb.DatabaseContext", x != null); log.println("createInstance com.sun.star.sdb.DatabaseContext done"); XNameAccess xNameAccess = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, x); showElements(xNameAccess); Object aObj = xNameAccess.getByName(sFileURL); // log.println("1"); // PropertySetHelper aHelper = new PropertySetHelper(aObj); XDocumentDataSource xDataSource = (XDocumentDataSource)UnoRuntime.queryInterface(XDocumentDataSource.class, aObj); // Object aDatabaseDocmuent = aHelper.getPropertyValueAsObject("DatabaseDocument"); XOfficeDatabaseDocument xOfficeDBDoc = xDataSource.getDatabaseDocument(); // XOfficeDatabaseDocument xOfficeDBDoc = (XOfficeDatabaseDocument)UnoRuntime.queryInterface(XOfficeDatabaseDocument.class, aDatabaseDocument); assure("can't access DatabaseDocument", xOfficeDBDoc != null); // log.println("2"); XModel xDBSource = (XModel)UnoRuntime.queryInterface(XModel.class, xOfficeDBDoc); Object aController = xDBSource.getCurrentController(); assure("Controller of xOfficeDatabaseDocument is empty!", aController != null); // log.println("3"); XDatabaseDocumentUI aDBDocUI = (XDatabaseDocumentUI)UnoRuntime.queryInterface(XDatabaseDocumentUI.class, aController); aDBDocUI.connect(); // if (aDBDocUI.isConnected()) // { // System.out.println("true"); // } // else // { // System.out.println("false"); // } // log.println("4"); // aHelper = new PropertySetHelper(aController); // Object aActiveConnectionObj = aHelper.getPropertyValueAsObject("ActiveConnection"); Object aActiveConnectionObj = aDBDocUI.getActiveConnection(); assure("ActiveConnection is empty", aActiveConnectionObj != null); // log.println("5"); XReportDocumentsSupplier xSupplier = (XReportDocumentsSupplier)UnoRuntime.queryInterface(XReportDocumentsSupplier.class, xOfficeDBDoc); xNameAccess = xSupplier.getReportDocuments(); assure("xOfficeDatabaseDocument returns no Report Document", xNameAccess != null); // log.println("5"); showElements(xNameAccess); ArrayList aPropertyList = new ArrayList(); PropertyValue aActiveConnection = new PropertyValue(); aActiveConnection.Name = "ActiveConnection"; aActiveConnection.Value = aActiveConnectionObj; aPropertyList.add(aActiveConnection); loadAndStoreReports(xNameAccess, aPropertyList /*, _nType*/ ); createDBEntry(/*_nType*/); } catch(com.sun.star.uno.Exception e) { log.println("ERROR: Exception caught"); log.println("Message: " + e.getMessage()); } // String mTestDocumentPath = (String) param.get("TestDocumentPath"); // System.out.println("mTestDocumentPath: '" + mTestDocumentPath + "'"); // // workaround for issue using deprecated "DOCPTH" prop // System.setProperty("DOCPTH", mTestDocumentPath); // Close the document closeComponent(xDocComponent); } private String getDocumentPoolName(/*int _nType*/) { return "AutogenReportDesignTest"; // return getFileFormat(_nType); } // ----------------------------------------------------------------------------- private void createDBEntry(/*int _nType*/) { // try to connect the database String sDBConnection = (String)param.get( convwatch.PropertyName.DB_CONNECTION_STRING ); log.println("DBConnection: " + sDBConnection); DB.init(sDBConnection); // String sFixRefSubDirectory = "ReportDesign_qa_complex_" + getFileFormat(_nType); String sFixRefSubDirectory = "ReportDesignFixRef"; String sSourceVersion = m_sSourceVersion; // String sSourceVersion = sFixRefSubDirectory; String sSourceName = m_sSourceName; // String sSourceCreatorType = "fixref"; String sSourceCreatorType = ""; String sDestinationVersion = m_sDestinationVersion; // if (sDestinationVersion.length() == 0) // { // sDestinationVersion = m_sUPDMinor; // } String sDestinationName = m_sDestinationName; String sDestinationCreatorType = ""; String sDocumentPoolDir = getOutputPath(/*_nType*/); String sDocumentPoolName = getDocumentPoolName(/*_nType*/); String sSpecial = ""; DB.insertinto_documentcompare(sSourceVersion, sSourceName, sSourceCreatorType, m_sDestinationVersion, sDestinationName, sDestinationCreatorType, sDocumentPoolDir, sDocumentPoolName, m_sMailAddress, sSpecial, m_sParentDistinct); TimeHelper.waitInSeconds(1, "wait for DB."); // DB.test(); // System.exit(1); } private void loadAndStoreReports(XNameAccess _xNameAccess, ArrayList _aPropertyList /*, int _nType*/ ) { if (_xNameAccess != null) { String[] sElementNames = _xNameAccess.getElementNames(); for(int i=0;i