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