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 .
18 package org
.openoffice
.test
.tools
;
20 /**************************************************************************/
22 import com
.sun
.star
.beans
.PropertyValue
;
23 import com
.sun
.star
.frame
.XController
;
24 import com
.sun
.star
.frame
.XDispatch
;
25 import com
.sun
.star
.frame
.XDispatchProvider
;
26 import com
.sun
.star
.lang
.XMultiServiceFactory
;
27 import com
.sun
.star
.uno
.UnoRuntime
;
28 import com
.sun
.star
.util
.URL
;
29 import com
.sun
.star
.util
.XURLTransformer
;
31 /**************************************************************************/
32 /** provides a small wrapper around a document view
34 public class OfficeDocumentView
36 private final XMultiServiceFactory m_orb
;
37 private final XController m_controller
;
39 /* ------------------------------------------------------------------ */
40 final public XController
getController()
45 /* ------------------------------------------------------------------ */
46 public OfficeDocumentView( XMultiServiceFactory orb
, XController controller
)
49 m_controller
= controller
;
52 /* ------------------------------------------------------------------ */
53 /** retrieves a dispatcher for the given URL, obtained at the current view of the document
55 a one-element array. The first element must contain a valid
56 <member scope="com.sun.star.util">URL::Complete</member> value. Upon return, the URL is correctly
59 the dispatcher for the URL in question
61 private XDispatch
getDispatcher( URL
[] aURL
) throws com
.sun
.star
.uno
.Exception
63 XDispatch xReturn
= null;
65 // go get the dispatch provider of its frame
66 XDispatchProvider xProvider
= UnoRuntime
.queryInterface( XDispatchProvider
.class, m_controller
.getFrame() );
67 if ( null != xProvider
)
69 // need a URLTransformer
70 XURLTransformer xTransformer
= UnoRuntime
.queryInterface( XURLTransformer
.class,
71 m_orb
.createInstance( "com.sun.star.util.URLTransformer" ) );
72 xTransformer
.parseStrict( aURL
);
74 xReturn
= xProvider
.queryDispatch( aURL
[0], "", 0 );
80 /* ------------------------------------------------------------------ */
81 /** dispatches the given URL into the view, if there's a dispatcher for it
84 <TRUE/> if the URL was successfully dispatched
86 public boolean dispatch( String i_url
) throws com
.sun
.star
.uno
.Exception
88 return dispatch( i_url
, new PropertyValue
[0] );
91 /* ------------------------------------------------------------------ */
92 private boolean dispatch( final String i_url
, final PropertyValue
[] i_arguments
) throws com
.sun
.star
.uno
.Exception
94 URL
[] completeURL
= new URL
[] { new URL() };
95 completeURL
[0].Complete
= i_url
;
96 XDispatch dispatcher
= getDispatcher( completeURL
);
97 if ( dispatcher
== null )
100 dispatcher
.dispatch( completeURL
[0], i_arguments
);