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