Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <recording/dispatchrecordersupplier.hxx>
21 : #include <services.h>
22 :
23 : #include <com/sun/star/frame/XRecordableDispatch.hpp>
24 :
25 : #include <vcl/svapp.hxx>
26 :
27 : namespace framework{
28 :
29 : // XInterface, XTypeProvider
30 :
31 0 : DEFINE_XSERVICEINFO_MULTISERVICE(
32 : DispatchRecorderSupplier,
33 : ::cppu::OWeakObject,
34 : "com.sun.star.frame.DispatchRecorderSupplier",
35 : IMPLEMENTATIONNAME_DISPATCHRECORDERSUPPLIER)
36 :
37 0 : DEFINE_INIT_SERVICE(
38 : DispatchRecorderSupplier,
39 : {
40 : /*Attention
41 : I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
42 : to create a new instance of this class by our own supported service factory.
43 : see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further information!
44 : */
45 : }
46 : )
47 :
48 : /**
49 : @short standard constructor to create instance
50 : @descr Because an instance will be initialized by her interface methods
51 : it's not necessary to do anything here.
52 : */
53 0 : DispatchRecorderSupplier::DispatchRecorderSupplier( const css::uno::Reference< css::lang::XMultiServiceFactory >& )
54 0 : : m_xDispatchRecorder( NULL )
55 : {
56 0 : }
57 :
58 : /**
59 : @short standard destructor
60 : @descr We are a helper and not a real service. So we don't provide
61 : dispose() functionality. This supplier dies by ref count mechanism
62 : and should release all internal used ones too.
63 : */
64 0 : DispatchRecorderSupplier::~DispatchRecorderSupplier()
65 : {
66 0 : m_xDispatchRecorder = NULL;
67 0 : }
68 :
69 : /**
70 : @short set a new dispatch recorder on this supplier
71 : @descr Because there can exist more then one recorder implementations
72 : (to generate java/basic/... scripts from recorded data) it must
73 : be possible to set it on a supplier.
74 :
75 : @see getDispatchRecorder()
76 :
77 : @param xRecorder
78 : the new recorder to set it
79 : <br><NULL/> isn't recommended, because recording without a
80 : valid recorder can't work. But it's not checked here. So user
81 : of this supplier can decide that without changing this
82 : implementation.
83 :
84 : @change 09.04.2002 by Andreas Schluens
85 : */
86 0 : void SAL_CALL DispatchRecorderSupplier::setDispatchRecorder( const css::uno::Reference< css::frame::XDispatchRecorder >& xRecorder ) throw (css::uno::RuntimeException, std::exception)
87 : {
88 0 : SolarMutexGuard g;
89 0 : m_xDispatchRecorder=xRecorder;
90 0 : }
91 :
92 : /**
93 : @short provides access to the dispatch recorder of this supplier
94 : @descr Such recorder can be used outside to record dispatches.
95 : But normaly he is used internally only. Of course he must used
96 : from outside to get the recorded data e.g. for saving it as a
97 : script.
98 :
99 : @see setDispatchRecorder()
100 :
101 : @return the internal used dispatch recorder
102 : <br>May it can be <NULL/> if no one was set before.
103 :
104 : @change 09.04.2002 by Andreas Schluens
105 : */
106 0 : css::uno::Reference< css::frame::XDispatchRecorder > SAL_CALL DispatchRecorderSupplier::getDispatchRecorder() throw (css::uno::RuntimeException, std::exception)
107 : {
108 0 : SolarMutexGuard g;
109 0 : return m_xDispatchRecorder;
110 : }
111 :
112 : /**
113 : @short execute a dispatch request and record it
114 : @descr If given dispatch object provides right recording interface it
115 : will be used. If it's not supported it record the pure dispatch
116 : parameters only. There is no code neither the possibility to
117 : check if recording is enabled or not.
118 :
119 : @param aURL the command URL
120 : @param lArguments optional arguments (see com.sun.star.document.MediaDescriptor for further information)
121 : @param xDispatcher the original dispatch object which should be recorded
122 :
123 : @change 09.04.2002 by Andreas Schluens
124 : */
125 0 : void SAL_CALL DispatchRecorderSupplier::dispatchAndRecord( const css::util::URL& aURL ,
126 : const css::uno::Sequence< css::beans::PropertyValue >& lArguments ,
127 : const css::uno::Reference< css::frame::XDispatch >& xDispatcher ) throw (css::uno::RuntimeException, std::exception)
128 : {
129 0 : SolarMutexClearableGuard aReadLock;
130 0 : css::uno::Reference< css::frame::XDispatchRecorder > xRecorder = m_xDispatchRecorder;
131 0 : aReadLock.clear();
132 :
133 : // clear unspecific situations
134 0 : if (!xDispatcher.is())
135 0 : throw css::uno::RuntimeException("specification violation: dispatcher is NULL", static_cast< ::cppu::OWeakObject* >(this));
136 :
137 0 : if (!xRecorder.is())
138 0 : throw css::uno::RuntimeException("specification violation: no valid dispatch recorder available", static_cast< ::cppu::OWeakObject* >(this));
139 :
140 : // check, if given dispatch supports record functionality by itself ...
141 : // or must be wrapped.
142 : css::uno::Reference< css::frame::XRecordableDispatch > xRecordable(
143 : xDispatcher,
144 0 : css::uno::UNO_QUERY);
145 :
146 0 : if (xRecordable.is())
147 0 : xRecordable->dispatchAndRecord(aURL,lArguments,xRecorder);
148 : else
149 : {
150 : // There is no reason to wait for information about success
151 : // of this request. Because status information of a dispatch
152 : // are not guaranteed. So we execute it and record used
153 : // parameters only.
154 0 : xDispatcher->dispatch(aURL,lArguments);
155 0 : xRecorder->recordDispatch(aURL,lArguments);
156 0 : }
157 0 : }
158 :
159 : } // namespace framework
160 :
161 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|