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 .
21 import lib
.MultiMethodTest
;
23 import lib
.StatusException
;
24 import util
.SOfficeFactory
;
26 import com
.sun
.star
.beans
.PropertyValue
;
27 import com
.sun
.star
.frame
.XDesktop
;
28 import com
.sun
.star
.frame
.XFrame
;
29 import com
.sun
.star
.frame
.XSynchronousFrameLoader
;
30 import com
.sun
.star
.lang
.XComponent
;
31 import com
.sun
.star
.lang
.XMultiServiceFactory
;
32 import com
.sun
.star
.uno
.UnoRuntime
;
33 import com
.sun
.star
.util
.URL
;
34 import com
.sun
.star
.util
.XURLTransformer
;
37 * Testing <code>com.sun.star.frame.XSynchronousFrameLoader</code>
40 * <li><code> load()</code></li>
41 * <li><code> cancel()</code></li>
43 * This test needs the following object relations :
45 * <li> <code>'FrameLoader.URL'</code> (of type <code>String</code>):
46 * an url of component to be loaded </li>
47 * <li> <code>'FrameLoader.Frame'</code> <b>(optional)</b>
48 * (of type <code>com.sun.star.frame.XFrame</code>):
49 * a target frame where component to be loaded. If this
50 * relation is ommited then a text document created and its
51 * frame is used. </li>
54 * @see com.sun.star.frame.XSynchronousFrameLoader
56 public class _XSynchronousFrameLoader
extends MultiMethodTest
{
58 public XSynchronousFrameLoader oObj
= null; // oObj filled by MultiMethodTest
59 private String url
= null ;
60 private XFrame frame
= null ;
61 private XComponent frameSup
= null ;
62 private PropertyValue
[] descr
= null;
65 * Retrieves all relations. If optional relation
66 * <code>FrameLoader.Frame</code> not found
67 * creates a new document and otains its frame for loading. <p>
69 * Also <code>MediaDescriptor</code> is created using
70 * URL from <code>FrameLoader.URL</code> relation.
72 * @throws StatusException If one of required relations not found.
74 public void before() {
75 url
= (String
) tEnv
.getObjRelation("FrameLoader.URL") ;
76 frame
= (XFrame
) tEnv
.getObjRelation("FrameLoader.Frame") ;
79 throw new StatusException(Status
.failed("Some relations not found")) ;
82 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
83 (XMultiServiceFactory
)tParam
.getMSF() );
85 XURLTransformer xURLTrans
= null;
87 // if frame is not contained in relations the writer frmame will be used.
90 log
.println( "creating a textdocument" );
91 frameSup
= SOF
.createTextDoc( null );
94 (XMultiServiceFactory
)tParam
.getMSF()).createInstance
95 ("com.sun.star.frame.Desktop") ;
96 XDesktop dsk
= UnoRuntime
.queryInterface
97 (XDesktop
.class, oDsk
) ;
98 frame
= dsk
.getCurrentFrame() ;
101 (XMultiServiceFactory
)tParam
.getMSF()).createInstance
102 ("com.sun.star.util.URLTransformer") ;
103 xURLTrans
= UnoRuntime
.queryInterface
104 (XURLTransformer
.class, o
) ;
106 } catch ( com
.sun
.star
.uno
.Exception e
) {
107 // Some exception occurs.FAILED
108 e
.printStackTrace( log
);
109 throw new StatusException( "Couldn't create a document.", e
);
113 URL
[] urlS
= new URL
[1];
115 urlS
[0].Complete
= url
;
116 boolean res
= xURLTrans
.parseStrict(urlS
);
117 log
.println("Parsing URL '" + url
+ "': " + res
);
118 descr
= new PropertyValue
[1] ;
119 descr
[0] = new PropertyValue();
120 descr
[0].Name
= "URL" ;
121 descr
[0].Value
= urlS
[0] ;
126 * Tries to load component to a frame. <p>
127 * Has <b> OK </b> status if <code>true</code> is returned.
129 public void _load() {
130 boolean result
= oObj
.load(descr
, frame
) ;
132 tRes
.tested("load()", result
) ;
136 * Tries to load component to a frame in separate thread to
137 * avoid blocking of the current thread and imediately
138 * cancels loading. <p>
140 * Has <b> OK </b> status if <code>flase</code> is returned,
141 * i.e. loading was not completed.
143 public void _cancel() {
144 requiredMethod("load()") ;
146 final boolean[] result
= new boolean[1] ;
150 result
[0] = oObj
.load(descr
, frame
);
158 } catch (InterruptedException ex
) {}
161 tRes
.tested("cancel()", !result
[0]) ;
165 * Disposes document if it was created for frame supplying.
167 protected void after() {
168 if (frameSup
!= null) {