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