LibreOffice Module unotest (master) 1
OfficeDocumentView.java
Go to the documentation of this file.
1/*
2 * This file is part of the LibreOffice project.
3 *
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/.
7 *
8 * This file incorporates work covered by the following license notice:
9 *
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 .
17 */
18package org.openoffice.test.tools;
19
20/**************************************************************************/
21
22import com.sun.star.beans.PropertyValue;
23import com.sun.star.frame.XController;
24import com.sun.star.frame.XDispatch;
25import com.sun.star.frame.XDispatchProvider;
26import com.sun.star.lang.XMultiServiceFactory;
27import com.sun.star.uno.UnoRuntime;
28import com.sun.star.util.URL;
29import com.sun.star.util.XURLTransformer;
30
31/**************************************************************************/
35{
36 private final XMultiServiceFactory m_orb;
37 private final XController m_controller;
38
39 /* ------------------------------------------------------------------ */
40 final public XController getController()
41 {
42 return m_controller;
43 }
44
45 /* ------------------------------------------------------------------ */
46 public OfficeDocumentView( XMultiServiceFactory orb, XController controller )
47 {
48 m_orb = orb;
49 m_controller = controller;
50 }
51
52 /* ------------------------------------------------------------------ */
61 private XDispatch getDispatcher( URL[] aURL ) throws com.sun.star.uno.Exception
62 {
63 XDispatch xReturn = null;
64
65 // go get the dispatch provider of its frame
66 XDispatchProvider xProvider = UnoRuntime.queryInterface( XDispatchProvider.class, m_controller.getFrame() );
67 if ( null != xProvider )
68 {
69 // need a URLTransformer
70 XURLTransformer xTransformer = UnoRuntime.queryInterface( XURLTransformer.class,
71 m_orb.createInstance( "com.sun.star.util.URLTransformer" ) );
72 xTransformer.parseStrict( aURL );
73
74 xReturn = xProvider.queryDispatch( aURL[0], "", 0 );
75 }
76 return xReturn;
77 }
78
79
80 /* ------------------------------------------------------------------ */
86 public boolean dispatch( String i_url ) throws com.sun.star.uno.Exception
87 {
88 return dispatch( i_url, new PropertyValue[0] );
89 }
90
91 /* ------------------------------------------------------------------ */
92 private boolean dispatch( final String i_url, final PropertyValue[] i_arguments ) throws com.sun.star.uno.Exception
93 {
94 URL[] completeURL = new URL[] { new URL() };
95 completeURL[0].Complete = i_url;
96 XDispatch dispatcher = getDispatcher( completeURL );
97 if ( dispatcher == null )
98 return false;
99
100 dispatcher.dispatch( completeURL[0], i_arguments );
101 return true;
102 }
103
104}
provides a small wrapper around a document view
XDispatch getDispatcher(URL[] aURL)
retrieves a dispatcher for the given URL, obtained at the current view of the document
boolean dispatch(String i_url)
dispatches the given URL into the view, if there's a dispatcher for it
boolean dispatch(final String i_url, final PropertyValue[] i_arguments)
OfficeDocumentView(XMultiServiceFactory orb, XController controller)
URL aURL