1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Dispatch.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod
._scripting
;
33 import java
.net
.URLEncoder
;
34 import java
.io
.PrintWriter
;
36 import lib
.StatusException
;
38 import lib
.TestEnvironment
;
39 import lib
.TestParameters
;
42 import util
.SOfficeFactory
;
44 import com
.sun
.star
.lang
.XMultiServiceFactory
;
45 import com
.sun
.star
.lang
.XComponent
;
47 import com
.sun
.star
.uno
.XInterface
;
48 import com
.sun
.star
.uno
.UnoRuntime
;
50 import com
.sun
.star
.frame
.XModel
;
51 import com
.sun
.star
.frame
.XFrame
;
52 import com
.sun
.star
.frame
.XDesktop
;
55 import com
.sun
.star
.util
.URL
;
56 import com
.sun
.star
.util
.XURLTransformer
;
60 public class Dispatch
extends TestCase
{
61 //private String scriptURL = "script://MemoryUtils.MemUsage";
62 private String scriptURL
= "script://HighlightText.showForm";
63 public void initialize( TestParameters tParam
, PrintWriter log
) {
66 public synchronized TestEnvironment
createTestEnvironment(
67 TestParameters tParam
, PrintWriter log
) throws StatusException
{
68 log
.println("creating test environment");
69 XInterface oObj
= null;
70 URL dispatchURL
= null;
73 XMultiServiceFactory xMSF
= tParam
.getMSF();
74 SOfficeFactory SOF
= null;
75 SOF
= SOfficeFactory
.getFactory( xMSF
);
76 String docPath
= util
.utils
.getFullTestURL( "ExampleSpreadSheetLatest.sxc" );
77 XComponent doc
= SOF
.loadDocument( docPath
);
78 XModel model
= ( XModel
) UnoRuntime
.queryInterface( XModel
.class,
80 XFrame frame
= model
.getCurrentController().getFrame();
81 oObj
= ( XInterface
)xMSF
.createInstanceWithArguments( "com.sun.star.comp.ScriptProtocolHandler", new Object
[] { frame
} );
83 XURLTransformer xParser
=(XURLTransformer
)
84 UnoRuntime
.queryInterface(XURLTransformer
.class,
85 tParam
.getMSF().createInstance
86 ("com.sun.star.util.URLTransformer"));
87 // Because it's an in/out parameter we must use an array of
89 URL
[] aParseURL
= new URL
[1];
90 aParseURL
[0] = new URL();
91 aParseURL
[0].Complete
= scriptURL
;
92 xParser
.parseStrict(aParseURL
);
93 dispatchURL
= aParseURL
[0];
95 } catch (com
.sun
.star
.uno
.Exception e
) {
97 throw new StatusException("Can't create object environment", e
) ;
100 TestEnvironment tEnv
= new TestEnvironment(oObj
) ;
101 tEnv
.addObjRelation( "XDispatchProvider.URL", scriptURL
);
102 tEnv
.addObjRelation( "XDispatch.URL", dispatchURL
);
106 public synchronized void disposeTestEnvironment( TestEnvironment tEnv
,
107 TestParameters tParam
) {