2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 import com
.sun
.star
.frame
.XController
;
21 import com
.sun
.star
.frame
.XDispatch
;
22 import com
.sun
.star
.frame
.XDispatchProvider
;
23 import com
.sun
.star
.frame
.XModel
;
24 import com
.sun
.star
.lang
.XComponent
;
26 import java
.util
.StringTokenizer
;
28 import java
.util
.ArrayList
;
29 import java
.net
.Socket
;
30 import java
.net
.ServerSocket
;
32 import java
.net
.URISyntaxException
;
33 import java
.util
.Arrays
;
35 import com
.sun
.star
.awt
.XToolkitExperimental
;
36 import com
.sun
.star
.beans
.XPropertySet
;
37 import com
.sun
.star
.beans
.Property
;
38 import com
.sun
.star
.lang
.XMultiServiceFactory
;
39 import com
.sun
.star
.uno
.UnoRuntime
;
40 import com
.sun
.star
.ucb
.InteractiveAugmentedIOException
;
41 import com
.sun
.star
.ucb
.XSimpleFileAccess
;
42 import com
.sun
.star
.lang
.XServiceInfo
;
43 import com
.sun
.star
.util
.URL
;
44 import com
.sun
.star
.util
.XURLTransformer
;
45 import com
.sun
.star
.uno
.AnyConverter
;
46 import com
.sun
.star
.uno
.Type
;
47 import com
.sun
.star
.uno
.XComponentContext
;
48 import com
.sun
.star
.util
.XMacroExpander
;
50 import java
.text
.DecimalFormat
;
51 import java
.util
.Calendar
;
52 import java
.util
.Collections
;
53 import java
.util
.GregorianCalendar
;
59 * This method adds the DOCPTH to a given file
61 * @param sDocName the file which should be completed to the test doc path
62 * @return $TESTDOCPATH/sDocName
64 public static String
getFullTestDocName(String sDocName
) {
65 String docpth
= System
.getProperty("DOCPTH");
66 if (docpth
.endsWith("\\") || docpth
.endsWith("/")) {
67 docpth
= docpth
.substring(0, docpth
.length() - 1);
70 System
.out
.println("docpth:" + docpth
);
72 String pthSep
= System
.getProperty("file.separator");
74 if (docpth
.equals("unknown")) {
75 System
.out
.println("try to get tDoc from $SRC_ROOT/qadevOOo");
76 String srcRoot
= System
.getProperty(PropertyName
.SRC_ROOT
);
77 if (srcRoot
!= null) {
78 File srcR
= new File(srcRoot
);
79 String
[] list
= srcR
.list(new FilenameFilter() {
81 public boolean accept(File dir
, String name
) {
82 return name
.startsWith("qadevOOo");
86 if (list
!= null && list
[0] != null) {
87 String tDoc
= srcRoot
.concat(pthSep
).concat(list
[0]).concat(pthSep
).concat("testdocs");
89 if (new File(tDoc
).exists()) {
96 if (docpth
.startsWith("http:")) {
97 return docpth
+ "/" + sDocName
;
99 String testdocPth
= "";
101 if (docpth
.equals("unknown")) {
102 System
.out
.println("try to get tDoc from OBJDSCS");
103 String objdscPth
= System
.getProperty("OBJDSCS");
104 if (objdscPth
!= null) {
105 int i
= objdscPth
.indexOf("objdsc");
106 String arcPth
= objdscPth
.substring(0, i
- 1);
107 testdocPth
= arcPth
+ pthSep
+ "doc" + pthSep
+ "java" +
108 pthSep
+ "testdocs" + pthSep
+ sDocName
;
111 testdocPth
= docpth
+ pthSep
+ sDocName
;
118 * This method adds the DOCPTH to a given file
119 * and changes the format to an file URL
122 public static String
getFullTestURL(String sDocName
) {
123 String fullDocPath
= getFullTestDocName(sDocName
);
124 if (fullDocPath
.startsWith("http:")) {
127 if (fullDocPath
.startsWith("file:")) {
130 String prefix
= null;
132 // Windows: \\\\margritte\\qaapi\\workspace\\qadev\\testdocs/emptyChart.sds
133 if (fullDocPath
.startsWith("\\\\")) {
137 fullDocPath
= fullDocPath
.replace('\\', '/');
138 if (prefix
== null) {
139 if (fullDocPath
.startsWith("//")) {
141 } else if (fullDocPath
.startsWith("/")) {
147 if (!fullDocPath
.endsWith("/")) {
148 File aFile
= new File(fullDocPath
);
149 if (aFile
.isDirectory()) {
153 String fulldocURL
= prefix
+ fullDocPath
;
159 * This method changes a given URL to a valid file URL
162 public static String
getFullURL(String sDocName
) {
163 String fullDocPath
= sDocName
;
164 fullDocPath
= fullDocPath
.replace('\\', '/');
166 if (fullDocPath
.startsWith("http:")) {
169 if (fullDocPath
.startsWith("ftp:")) {
173 if (!fullDocPath
.startsWith("file:///")) {
174 if (fullDocPath
.startsWith("//")) {
177 if (fullDocPath
.startsWith("/")) {
186 if (!fullDocPath
.endsWith("/")) {
187 File aFile
= new File(fullDocPath
);
188 if (aFile
.isDirectory()) {
192 String fulldocURL
= prefix
+ fullDocPath
;
199 * This method gets the user dir of the connected office
202 public static String
getOfficeUserPath(XMultiServiceFactory msf
) {
203 // get a folder located in the user dir
204 String userPath
= getOfficeSettingsValue(msf
, "UserConfig");
206 // strip the returned folder to the user dir
207 if (userPath
.charAt(userPath
.length() - 1) == '/') {
208 userPath
= userPath
.substring(0, userPath
.length() - 1);
210 int index
= userPath
.lastIndexOf('/');
212 userPath
= userPath
.substring(0, index
);
219 * In the office there are some settings available. This function
220 * returns the value of the given setting name. For Example the setting name "Temp"
221 * "Temp" returns the temp folder of the office instance.
222 * @param msf a XMultiServiceFactory
223 * @param setting the name of the setting the value should be returned.
224 * For example "Temp" returns the temp folder of the current office instance.
225 * @see com.sun.star.util.PathSettings
226 * @return the value as String
228 private static String
getOfficeSettingsValue(XMultiServiceFactory msf
, String setting
) {
230 Object settings
= msf
.createInstance("com.sun.star.comp.framework.PathSettings");
231 XPropertySet pthSettings
= (XPropertySet
) AnyConverter
.toObject(
232 new Type(XPropertySet
.class), settings
);
233 return (String
) pthSettings
.getPropertyValue(setting
);
234 } catch (com
.sun
.star
.uno
.Exception ex
) {
235 throw new RuntimeException(ex
);
240 * This method returns the temp directory of the user.
241 * Since Java 1.4 it is not possible to read environment variables. To workaround
242 * this, the Java parameter -D could be used.
244 public static String
getUsersTempDir() {
245 String tempDir
= System
.getProperty("my.temp");
246 if (tempDir
== null) {
247 tempDir
= System
.getProperty("my.tmp");
248 if (tempDir
== null) {
249 tempDir
= System
.getProperty("java.io.tmpdir");
252 // remove ending file separator
253 if (tempDir
.endsWith(System
.getProperty("file.separator"))) {
254 tempDir
= tempDir
.substring(0, tempDir
.length() - 1);
262 * This method gets the temp dir of the connected office
265 public static String
getOfficeTemp(XMultiServiceFactory msf
) {
266 String url
= getOfficeUserPath(msf
) + "/test-temp/";
268 new File(new URI(url
)).mkdir();
269 } catch (URISyntaxException e
) {
270 throw new RuntimeException(e
);
276 * Gets StarOffice temp directory without 'file:///' prefix.
277 * For example is useful for Registry URL specifying.
278 * @msf Office factory for accessing its settings.
279 * @return SOffice temporary directory in form for example
280 * 'd:/Office60/user/temp/'.
282 public static String
getOfficeTempDir(XMultiServiceFactory msf
) {
284 String dir
= getOfficeTemp(msf
);
286 int idx
= dir
.indexOf("file:///");
292 dir
= dir
.substring("file:///".length());
294 idx
= dir
.indexOf(':');
296 // is the last character a '/' or a '\'?
297 boolean lastCharSet
= dir
.endsWith("/") || dir
.endsWith("\\");
299 if (idx
< 0) { // linux or solaris
301 dir
+= lastCharSet ?
"" : "/";
303 dir
+= lastCharSet ?
"" : "\\";
310 * Gets StarOffice temp directory without 'file:///' prefix.
311 * and System dependent file separator
313 public static String
getOfficeTempDirSys(XMultiServiceFactory msf
) {
315 String dir
= getOfficeTemp(msf
);
318 int idx
= dir
.indexOf("file://");
320 // remove leading 'file://'
324 sysDir
= dir
.substring("file://".length());
327 // append '/' if not there (e.g. linux)
328 if (sysDir
.charAt(sysDir
.length() - 1) != '/') {
332 // remove leading '/' and replace others with '\' on windows machines
333 if (sysDir
.indexOf(':') != -1) {
334 sysDir
= sysDir
.substring(1);
335 sysDir
= sysDir
.replace('/', '\\');
341 * converts a fileURL to a system URL
342 * @param fileURL a file URL
343 * @return a system URL
345 public static String
getSystemURL(String fileURL
) {
348 int idx
= fileURL
.indexOf("file://");
350 // remove leading 'file://'
354 sysDir
= fileURL
.substring("file://".length());
357 // remove leading '/' and replace others with '\' on windows machines
358 if (sysDir
.indexOf(':') != -1) {
359 sysDir
= sysDir
.substring(1);
360 sysDir
= sysDir
.replace('/', '\\');
366 * This method check via Office the existence of the given file URL
367 * @param msf the multiservice factory
368 * @param fileURL the file which existence should be checked
369 * @return true if the file exists, else false
371 public static boolean fileExists(XMultiServiceFactory msf
, String fileURL
) throws com
.sun
.star
.uno
.Exception
{
372 Object fileacc
= msf
.createInstance("com.sun.star.comp.ucb.SimpleFileAccess");
373 XSimpleFileAccess simpleAccess
= UnoRuntime
.queryInterface(XSimpleFileAccess
.class,
375 return simpleAccess
.exists(fileURL
);
379 * This method deletes via office the given file URL. It checks the existence
380 * of <CODE>fileURL</CODE>. If exists it will be deleted.
381 * @param xMsf the multiservice factory
382 * @param fileURL the file to delete
383 * @return true if the file could be deleted or the file does not exist
385 public static boolean deleteFile(XMultiServiceFactory xMsf
, String fileURL
) {
386 boolean delete
= true;
389 Object fileacc
= xMsf
.createInstance("com.sun.star.comp.ucb.SimpleFileAccess");
390 XSimpleFileAccess simpleAccess
= UnoRuntime
.queryInterface(XSimpleFileAccess
.class,
392 if (simpleAccess
.exists(fileURL
)) {
393 simpleAccess
.kill(fileURL
);
396 } catch (Exception e
) {
397 System
.out
.println("Couldn't delete file '" + fileURL
+ "'");
405 * This method copies via office a given file to a new one
406 * @param xMsf the multi service factory
407 * @param source the source file
408 * @param destination the destination file
409 * @return true at success
411 public static boolean copyFile(XMultiServiceFactory xMsf
, String source
, String destination
) {
414 Object fileacc
= xMsf
.createInstance("com.sun.star.comp.ucb.SimpleFileAccess");
415 XSimpleFileAccess simpleAccess
= UnoRuntime
.queryInterface(XSimpleFileAccess
.class,
417 if (!simpleAccess
.exists(destination
)) {
418 simpleAccess
.copy(source
, destination
);
422 } catch (Exception e
) {
423 System
.out
.println("Couldn't copy file '" + source
+ "' -> '" + destination
+ "'");
430 private static void overwriteFile_impl(
431 XMultiServiceFactory xMsf
, String oldF
, String newF
)
432 throws InteractiveAugmentedIOException
435 Object fileacc
= xMsf
.createInstance("com.sun.star.comp.ucb.SimpleFileAccess");
437 XSimpleFileAccess simpleAccess
= UnoRuntime
.queryInterface(XSimpleFileAccess
.class,
439 if (simpleAccess
.exists(newF
)) {
440 simpleAccess
.kill(newF
);
442 simpleAccess
.copy(oldF
, newF
);
443 } catch (InteractiveAugmentedIOException e
) {
445 } catch (com
.sun
.star
.uno
.Exception ex
) {
446 throw new RuntimeException("Could not copy " + oldF
+ " to " + newF
, ex
);
451 * Copies file to a new location using OpenOffice.org features. If the target
452 * file already exists, the file is deleted.
454 * @returns <code>true</code> if the file was successfully copied,
455 * <code>false</code> if some errors occurred (e.g. file is locked, used
456 * by another process).
458 public static boolean tryOverwriteFile(
459 XMultiServiceFactory xMsf
, String oldF
, String newF
)
462 overwriteFile_impl(xMsf
, oldF
, newF
);
463 } catch (InteractiveAugmentedIOException e
) {
471 public static boolean hasPropertyByName(XPropertySet props
, String aName
) {
472 Property
[] list
= props
.getPropertySetInfo().getProperties();
474 for (int i
= 0; i
< list
.length
; i
++) {
475 String the_name
= list
[i
].Name
;
476 if (aName
.equals(the_name
)) {
485 * This method returns the implementation name of a given object
488 public static String
getImplName(Object aObject
) {
489 XServiceInfo xSI
= UnoRuntime
.queryInterface(XServiceInfo
.class, aObject
);
490 return xSI
== null ?
"Unknown, does not implement XServiceInfo" : xSI
.getImplementationName();
495 * This method checks if an Object is void
498 public static boolean isVoid(Object aObject
) {
499 if (aObject
instanceof com
.sun
.star
.uno
.Any
) {
500 com
.sun
.star
.uno
.Any oAny
= (com
.sun
.star
.uno
.Any
) aObject
;
501 return oAny
.getType().getTypeName().equals("void");
509 * Scan localhost for the next free port-number from a starting port
510 * on. If the starting port is smaller than 1024, port number starts with
511 * 10000 as default, because numbers < 1024 are never free on unix machines.
512 * @param startPort The port where scanning starts.
513 * @return The next free port.
515 public static int getNextFreePort(int startPort
) {
516 if (startPort
< 1024) {
519 for (int port
= startPort
; port
< 65536; port
++) {
520 System
.out
.println("Scan port " + port
);
522 // first trying to establish a server-socket on localhost
523 // fails if there is already a server running
524 ServerSocket sSock
= new ServerSocket(port
);
526 } catch (IOException e
) {
527 System
.out
.println(" -> server: occupied port " + port
);
531 Socket sock
= new Socket("localhost", port
);
532 System
.out
.println(" -> socket: occupied port: " + port
);
535 } catch (IOException ex
) {
536 // ignore close exception
538 } catch (IOException e
) {
539 System
.out
.println(" -> free port");
546 public static URL
parseURL(XMultiServiceFactory xMSF
, String url
) {
547 URL
[] rUrl
= new URL
[1];
549 rUrl
[0].Complete
= url
;
551 XURLTransformer xTrans
= null;
553 Object inst
= xMSF
.createInstance("com.sun.star.util.URLTransformer");
554 xTrans
= UnoRuntime
.queryInterface(XURLTransformer
.class, inst
);
555 } catch (com
.sun
.star
.uno
.Exception e
) {
559 xTrans
.parseStrict(rUrl
);
564 public static String
getOfficeURL(XMultiServiceFactory msf
) throws com
.sun
.star
.uno
.Exception
{
565 Object settings
= msf
.createInstance("com.sun.star.util.PathSettings");
566 XPropertySet settingProps
= UnoRuntime
.queryInterface(XPropertySet
.class, settings
);
567 String path
= (String
) settingProps
.getPropertyValue("Module");
574 * Get an array of all property names from the property set. With the include
575 * and exclude parameters the properties can be filtered. <br>
576 * Set excludePropertyAttribute = 0 and includePropertyAttribute = 0
577 * to include all and exclude none.
578 * @param props The instance of XPropertySet
579 * @param includePropertyAttribute Properties without these attributes are filtered and will not be returned.
580 * @param excludePropertyAttribute Properties with these attributes are filtered and will not be returned.
581 * @param array of string names of properties that will be skipped
582 * @return A String array with all property names.
583 * @see com.sun.star.beans.XPropertySet
584 * @see com.sun.star.beans.Property
585 * @see com.sun.star.beans.PropertyAttribute
587 public static String
[] getFilteredPropertyNames(XPropertySet props
, short includePropertyAttribute
,
588 short excludePropertyAttribute
, String
[] skipList
) {
589 Property
[] the_props
= props
.getPropertySetInfo().getProperties();
590 ArrayList
<String
> l
= new ArrayList
<String
>();
591 for (int i
= 0; i
< the_props
.length
; i
++) {
592 if (Arrays
.asList(skipList
).contains(the_props
[i
].Name
))
594 boolean exclude
= ((the_props
[i
].Attributes
& excludePropertyAttribute
) != 0);
595 boolean include
= (includePropertyAttribute
== 0) ||
596 ((the_props
[i
].Attributes
& includePropertyAttribute
) != 0);
597 if (include
&& !exclude
) {
598 l
.add(the_props
[i
].Name
);
602 String
[] names
= new String
[l
.size()];
603 names
= l
.toArray(names
);
607 /** Causes the thread to sleep some time.
608 * This is the default call, which waits for 500ms.
610 public static void shortWait() {
611 pause(utils
.DEFAULT_SHORT_WAIT_MS
);
614 /** Causes the thread to sleep some time.
616 public static void pause(int milliseconds
) {
618 Thread
.sleep(milliseconds
);
619 } catch (InterruptedException e
) {
620 System
.out
.println("While waiting :" + e
);
624 public static void waitForEventIdle(XMultiServiceFactory xMSF
) {
626 XToolkitExperimental xToolkit
= UnoRuntime
.queryInterface(
627 XToolkitExperimental
.class,
628 xMSF
.createInstance("com.sun.star.awt.Toolkit"));
629 xToolkit
.processEventsToIdle();
630 } catch (com
.sun
.star
.uno
.Exception ex
) {
631 throw new RuntimeException(ex
);
636 * Validate the AppExecutionCommand. Returned is an error message, starting
637 * with "Error:", or a warning, if the command might work.
638 * @param appExecCommand The application execution command that is checked.
639 * @param os The operating system where the check runs.
640 * @return The error message, or OK, if no error was detected.
642 public static String
validateAppExecutionCommand(String appExecCommand
, String os
) {
643 String errorMessage
= "OK";
644 appExecCommand
= appExecCommand
.replace("\"", "");
645 appExecCommand
= appExecCommand
.replace("'", "");
646 StringTokenizer commandTokens
= new StringTokenizer(appExecCommand
, " \t");
647 String officeExecCommand
= "soffice";
648 StringBuilder sb
= new StringBuilder();
649 // is there a 'soffice' in the command? 2do: eliminate case sensitivity on windows
651 while (commandTokens
.hasMoreTokens() && index
== -1) {
652 sb
.append(commandTokens
.nextToken()).append(" ");
653 index
= sb
.indexOf(officeExecCommand
);
656 errorMessage
= "Error: Your 'AppExecutionCommand' parameter does not " +
657 "contain '" + officeExecCommand
+ "'.";
659 String officeExecutable
= sb
.toString();
660 // does the directory exist?
661 officeExecutable
= officeExecutable
.trim();
662 String officePath
= officeExecutable
.substring(0, index
);
663 File f
= new File(officePath
);
664 if (!f
.exists() || !f
.isDirectory()) {
665 errorMessage
= "Error: Your 'AppExecutionCommand' parameter does not " +
666 "point to a valid system directory: " + officePath
;
668 // is it an office installation?
669 f
= new File(officeExecutable
);
670 // one try for windows platform can't be wrong...
671 if (!f
.exists() || !f
.isFile()) {
672 f
= new File(officeExecutable
+ ".exe");
674 if (!f
.exists() || !f
.isFile()) {
675 errorMessage
= "Error: Your 'AppExecutionCommand' parameter does not " +
676 "point to a valid office installation.";
678 // do we have the accept parameter?
679 boolean gotNoAccept
= true;
680 while (commandTokens
.hasMoreElements()) {
681 String officeParam
= commandTokens
.nextToken();
682 if (officeParam
.indexOf("--accept=") != -1) {
684 errorMessage
= validateConnectString(officeParam
, true);
688 errorMessage
= "Error: Your 'AppExecutionCommand' parameter does not " +
689 "contain a '--accept' parameter for connecting the office.";
698 * Validate the connection string. Returned is an error message, starting
699 * with "Error:", or a warning, if the command might work.
700 * @param connectString The connection string that is checked.
701 * @param checkAppExecutionCommand If the AppExecutionCommand is checked, the error message is different.
702 * @return The error message, or OK, if no error was detected.
704 private static String
validateConnectString(String connectString
, boolean checkAppExecutionCommand
) {
705 String acceptPrefix
= "";
706 if (checkAppExecutionCommand
) {
707 acceptPrefix
= "--accept=";
710 String errorMessage
= "OK";
711 // a warning, if an unknown connection method is used
712 if (connectString
.indexOf("socket") != -1) {
713 if (connectString
.indexOf(acceptPrefix
+ "socket,host=") == -1 ||
714 connectString
.indexOf("port=") == -1) {
715 if (checkAppExecutionCommand
) {
716 errorMessage
= "Error: The '--accept' parameter contains a syntax error: It should be like: '--accept=socket,host=localhost,port=8100;urp;";
718 errorMessage
= "Error: The 'ConnectionString' parameter contains a syntax error: It should be like: 'socket,host=localhost,port=8100'";
721 } else if (connectString
.indexOf("pipe") != -1) {
722 if (connectString
.indexOf(acceptPrefix
+ "pipe,name=") == -1) {
723 if (checkAppExecutionCommand
) {
724 errorMessage
= "Error: The '--accept' parameter contains a syntax error: It should be like: '--accept=pipe,name=myuniquename;urp;'";
726 errorMessage
= "Error: The 'ConnectionString' parameter contains a syntax error: It should be like: 'pipe,name=myuniquename'";
730 if (checkAppExecutionCommand
) {
731 errorMessage
= "Warning: The '--accept' parameter contains an unknown connection method.";
733 errorMessage
= "Warning: The 'ConnectionString' parameter contains an unknown connection method.";
740 * expand macrofied strings like <CODE>${$ORIGIN/bootstrap.ini:UserInstallation}</CODE> or
742 * @param xMSF the MultiServiceFactory
743 * @param expand the string to expand
744 * @throws java.lang.Exception was thrown on any exception
745 * @return return the expanded string
746 * @see com.sun.star.util.XMacroExpander
748 public static String
expandMacro(XMultiServiceFactory xMSF
, String expand
) {
750 XPropertySet xPS
= UnoRuntime
.queryInterface(XPropertySet
.class, xMSF
);
751 XComponentContext xContext
= UnoRuntime
.queryInterface(XComponentContext
.class,
752 xPS
.getPropertyValue("DefaultContext"));
753 XMacroExpander xME
= UnoRuntime
.queryInterface(XMacroExpander
.class,
754 xContext
.getValueByName("/singletons/com.sun.star.util.theMacroExpander"));
755 return xME
.expandMacros(expand
);
756 } catch (Exception e
) {
757 throw new RuntimeException("could not expand macro", e
);
765 * dispatches given <CODE>URL</CODE> to the document <CODE>XComponent</CODE>
766 * @param xMSF the <CODE>XMultiServiceFactory</CODE>
767 * @param xDoc the document where to dispatch
768 * @param URL the <CODE>URL</CODE> to dispatch
769 * @throws java.lang.Exception throws <CODE>java.lang.Exception</CODE> on any error
771 public static void dispatchURL(XMultiServiceFactory xMSF
, XComponent xDoc
, String URL
) throws java
.lang
.Exception
{
772 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class, xDoc
);
774 XController xCont
= aModel
.getCurrentController();
776 dispatchURL(xMSF
, xCont
, URL
);
781 * dispatches given <CODE>URL</CODE> to the <CODE>XController</CODE>
782 * @param xMSF the <CODE>XMultiServiceFactory</CODE>
783 * @param xCont the <CODE>XController</CODE> to query for a XDispatchProvider
784 * @param URL the <CODE>URL</CODE> to dispatch
786 private static void dispatchURL(XMultiServiceFactory xMSF
, XController xCont
, String URL
) {
789 XDispatchProvider xDispProv
= UnoRuntime
.queryInterface(XDispatchProvider
.class, xCont
);
791 XURLTransformer xParser
= UnoRuntime
.queryInterface(
792 XURLTransformer
.class,
793 xMSF
.createInstance("com.sun.star.util.URLTransformer"));
795 // Because it's an in/out parameter we must use an array of URL objects.
796 URL
[] aParseURL
= new URL
[1];
797 aParseURL
[0] = new URL();
798 aParseURL
[0].Complete
= URL
;
799 xParser
.parseStrict(aParseURL
);
801 URL aURL
= aParseURL
[0];
803 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
804 xDispatcher
.dispatch(aURL
, null);
806 waitForEventIdle(xMSF
);
808 } catch (Exception e
) {
809 throw new RuntimeException("Could not dispatch URL '" + URL
+ "'", e
);
813 /** returns a String which contains the current date and time<br>
814 * format: [DD.MM.YYYY - HH:MM:SS::mm]
816 ** @return a String which contains the current date and time
818 public static String
getDateTime() {
820 Calendar cal
= new GregorianCalendar();
821 DecimalFormat dfmt
= new DecimalFormat("00");
822 String dateTime
= dfmt
.format(cal
.get(Calendar
.DAY_OF_MONTH
)) + "." +
823 dfmt
.format(cal
.get(Calendar
.MONTH
) + 1) + "." +
824 dfmt
.format(cal
.get(Calendar
.YEAR
)) + " - " +
825 dfmt
.format(cal
.get(Calendar
.HOUR_OF_DAY
)) + ":" +
826 dfmt
.format(cal
.get(Calendar
.MINUTE
)) + ":" +
827 dfmt
.format(cal
.get(Calendar
.SECOND
)) + "," +
828 dfmt
.format(cal
.get(Calendar
.MILLISECOND
));
829 return "[" + dateTime
+ "]";
833 * Default short wait time for the Office
835 public static final int DEFAULT_SHORT_WAIT_MS
= 500;
838 public static boolean approxEqual( double a
, double b
)
843 return (x
< 0.0 ?
-x
: x
)
844 < ((a
< 0.0 ?
-a
: a
) * (1.0 / (16777216.0 * 16777216.0)));