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: _XSynchronousFrameLoader.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 ************************************************************************/
33 import lib
.MultiMethodTest
;
35 import lib
.StatusException
;
36 import util
.SOfficeFactory
;
38 import com
.sun
.star
.beans
.PropertyValue
;
39 import com
.sun
.star
.frame
.XDesktop
;
40 import com
.sun
.star
.frame
.XFrame
;
41 import com
.sun
.star
.frame
.XSynchronousFrameLoader
;
42 import com
.sun
.star
.lang
.XComponent
;
43 import com
.sun
.star
.lang
.XMultiServiceFactory
;
44 import com
.sun
.star
.uno
.UnoRuntime
;
45 import com
.sun
.star
.util
.URL
;
46 import com
.sun
.star
.util
.XURLTransformer
;
49 * Testing <code>com.sun.star.frame.XSynchronousFrameLoader</code>
52 * <li><code> load()</code></li>
53 * <li><code> cancel()</code></li>
55 * This test needs the following object relations :
57 * <li> <code>'FrameLoader.URL'</code> (of type <code>String</code>):
58 * an url of component to be loaded </li>
59 * <li> <code>'FrameLoader.Frame'</code> <b>(optional)</b>
60 * (of type <code>com.sun.star.frame.XFrame</code>):
61 * a target frame where component to be loaded. If this
62 * relation is ommited then a text document created and its
63 * frame is used. </li>
66 * @see com.sun.star.frame.XSynchronousFrameLoader
68 public class _XSynchronousFrameLoader
extends MultiMethodTest
{
70 public XSynchronousFrameLoader oObj
= null; // oObj filled by MultiMethodTest
71 private String url
= null ;
72 private XFrame frame
= null ;
73 private XComponent frameSup
= null ;
74 private PropertyValue
[] descr
= null;
77 * Retrieves all relations. If optional relation
78 * <code>FrameLoader.Frame</code> not found
79 * creates a new document and otains its frame for loading. <p>
81 * Also <code>MediaDescriptor</code> is created using
82 * URL from <code>FrameLoader.URL</code> relation.
84 * @throws StatusException If one of required relations not found.
86 public void before() {
87 url
= (String
) tEnv
.getObjRelation("FrameLoader.URL") ;
88 frame
= (XFrame
) tEnv
.getObjRelation("FrameLoader.Frame") ;
91 throw new StatusException(Status
.failed("Some relations not found")) ;
94 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
95 (XMultiServiceFactory
)tParam
.getMSF() );
97 XURLTransformer xURLTrans
= null;
99 // if frame is not contained in relations the writer frmame will be used.
102 log
.println( "creating a textdocument" );
103 frameSup
= SOF
.createTextDoc( null );
106 (XMultiServiceFactory
)tParam
.getMSF()).createInstance
107 ("com.sun.star.frame.Desktop") ;
108 XDesktop dsk
= (XDesktop
) UnoRuntime
.queryInterface
109 (XDesktop
.class, oDsk
) ;
110 frame
= dsk
.getCurrentFrame() ;
113 (XMultiServiceFactory
)tParam
.getMSF()).createInstance
114 ("com.sun.star.util.URLTransformer") ;
115 xURLTrans
= (XURLTransformer
) UnoRuntime
.queryInterface
116 (XURLTransformer
.class, o
) ;
118 } catch ( com
.sun
.star
.uno
.Exception e
) {
119 // Some exception occures.FAILED
120 e
.printStackTrace( log
);
121 throw new StatusException( "Couldn't create a document.", e
);
125 URL
[] urlS
= new URL
[1];
127 urlS
[0].Complete
= url
;
128 boolean res
= xURLTrans
.parseStrict(urlS
);
129 log
.println("Parsing URL '" + url
+ "': " + res
);
130 descr
= new PropertyValue
[1] ;
131 descr
[0] = new PropertyValue();
132 descr
[0].Name
= "URL" ;
133 descr
[0].Value
= urlS
[0] ;
138 * Tries to load component to a frame. <p>
139 * Has <b> OK </b> status if <code>true</code> is returned.
141 public void _load() {
142 boolean result
= oObj
.load(descr
, frame
) ;
144 tRes
.tested("load()", result
) ;
148 * Tries to load component to a frame in separate thread to
149 * avoid blocking of the current thread and imediately
150 * cancels loading. <p>
152 * Has <b> OK </b> status if <code>flase</code> is returned,
153 * i.e. loading was not completed.
155 public void _cancel() {
156 requiredMethod("load()") ;
158 final boolean[] result
= new boolean[1] ;
162 result
[0] = oObj
.load(descr
, frame
);
170 } catch (InterruptedException ex
) {}
173 tRes
.tested("cancel()", !result
[0]) ;
177 * Disposes document if it was created for frame supplying.
179 protected void after() {
180 if (frameSup
!= null) {