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