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
.uno
.UnoRuntime
;
32 import com
.sun
.star
.util
.URL
;
33 import com
.sun
.star
.util
.XURLTransformer
;
36 * Testing <code>com.sun.star.frame.XSynchronousFrameLoader</code>
39 * <li><code> load()</code></li>
40 * <li><code> cancel()</code></li>
42 * This test needs the following object relations :
44 * <li> <code>'FrameLoader.URL'</code> (of type <code>String</code>):
45 * a url of component to be loaded </li>
46 * <li> <code>'FrameLoader.Frame'</code> <b>(optional)</b>
47 * (of type <code>com.sun.star.frame.XFrame</code>):
48 * a target frame where component to be loaded. If this
49 * relation is omitted then a text document created and its
50 * frame is used. </li>
53 * @see com.sun.star.frame.XSynchronousFrameLoader
55 public class _XSynchronousFrameLoader
extends MultiMethodTest
{
57 public XSynchronousFrameLoader oObj
= null; // oObj filled by MultiMethodTest
58 private XFrame frame
= null ;
59 private XComponent frameSup
= null ;
60 private PropertyValue
[] descr
= null;
63 * Retrieves all relations. If optional relation
64 * <code>FrameLoader.Frame</code> not found
65 * creates a new document and obtains its frame for loading. <p>
67 * Also <code>MediaDescriptor</code> is created using
68 * URL from <code>FrameLoader.URL</code> relation.
70 * @throws StatusException If one of required relations not found.
73 public void before() {
74 String url
= (String
) tEnv
.getObjRelation("FrameLoader.URL") ;
75 frame
= (XFrame
) tEnv
.getObjRelation("FrameLoader.Frame") ;
78 throw new StatusException(Status
.failed("Some relations not found")) ;
81 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
84 XURLTransformer xURLTrans
= null;
86 // if frame is not contained in relations the writer frame will be used.
89 log
.println( "creating a textdocument" );
90 frameSup
= SOF
.createTextDoc( null );
92 Object oDsk
= tParam
.getMSF().createInstance
93 ("com.sun.star.frame.Desktop") ;
94 XDesktop dsk
= UnoRuntime
.queryInterface
95 (XDesktop
.class, oDsk
) ;
96 frame
= dsk
.getCurrentFrame() ;
98 Object o
= tParam
.getMSF().createInstance
99 ("com.sun.star.util.URLTransformer") ;
100 xURLTrans
= UnoRuntime
.queryInterface
101 (XURLTransformer
.class, o
) ;
103 } catch ( com
.sun
.star
.uno
.Exception e
) {
104 // Some exception occurs.FAILED
105 e
.printStackTrace( log
);
106 throw new StatusException( "Couldn't create a document.", e
);
110 URL
[] urlS
= new URL
[1];
112 urlS
[0].Complete
= url
;
113 if (xURLTrans
== null)
114 throw new IllegalStateException("xURLTrans unexpected null");
115 boolean res
= xURLTrans
.parseStrict(urlS
);
116 log
.println("Parsing URL '" + url
+ "': " + res
);
117 descr
= new PropertyValue
[1] ;
118 descr
[0] = new PropertyValue();
119 descr
[0].Name
= "URL" ;
120 descr
[0].Value
= urlS
[0] ;
125 * Tries to load component to a frame. <p>
126 * Has <b> OK </b> status if <code>true</code> is returned.
128 public void _load() {
129 boolean result
= oObj
.load(descr
, frame
) ;
131 tRes
.tested("load()", result
) ;
135 * Tries to load component to a frame in separate thread to
136 * avoid blocking of the current thread and immediately
137 * cancels loading. <p>
139 * Has <b> OK </b> status if <code>flase</code> is returned,
140 * i.e. loading was not completed.
142 public void _cancel() {
143 requiredMethod("load()") ;
145 final boolean[] result
= new boolean[1] ;
150 result
[0] = oObj
.load(descr
, frame
);
158 tRes
.tested("cancel()", !result
[0]) ;
162 * Disposes document if it was created for frame supplying.
165 protected void after() {
166 if (frameSup
!= null) {