16d739b60SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
36d739b60SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
46d739b60SAndrew Rist * or more contributor license agreements. See the NOTICE file
56d739b60SAndrew Rist * distributed with this work for additional information
66d739b60SAndrew Rist * regarding copyright ownership. The ASF licenses this file
76d739b60SAndrew Rist * to you under the Apache License, Version 2.0 (the
86d739b60SAndrew Rist * "License"); you may not use this file except in compliance
96d739b60SAndrew Rist * with the License. You may obtain a copy of the License at
106d739b60SAndrew Rist *
116d739b60SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
126d739b60SAndrew Rist *
136d739b60SAndrew Rist * Unless required by applicable law or agreed to in writing,
146d739b60SAndrew Rist * software distributed under the License is distributed on an
156d739b60SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
166d739b60SAndrew Rist * KIND, either express or implied. See the License for the
176d739b60SAndrew Rist * specific language governing permissions and limitations
186d739b60SAndrew Rist * under the License.
196d739b60SAndrew Rist *
206d739b60SAndrew Rist *************************************************************/
216d739b60SAndrew Rist
226d739b60SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_framework.hxx"
26cdf0e10cSrcweir #include <accelerators/documentacceleratorconfiguration.hxx>
27cdf0e10cSrcweir
28cdf0e10cSrcweir #ifndef __FRAMEWORK_XML_ACCELERATORCONFIGURATIONREADER_HXX_
29cdf0e10cSrcweir #include <xml/acceleratorconfigurationreader.hxx>
30cdf0e10cSrcweir #endif
31cdf0e10cSrcweir
32cdf0e10cSrcweir #ifndef __FRAMEWORK_XML_ACCELERATORCONFIGURATIONWRITER_HXX_
33cdf0e10cSrcweir #include <xml/acceleratorconfigurationwriter.hxx>
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir
36cdf0e10cSrcweir #ifndef __FRAMEWORK_XML_SAXNAMESPACEFILTER_HXX_
37cdf0e10cSrcweir #include <xml/saxnamespacefilter.hxx>
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir
40cdf0e10cSrcweir //_______________________________________________
41cdf0e10cSrcweir // own includes
42cdf0e10cSrcweir #include <threadhelp/readguard.hxx>
43cdf0e10cSrcweir #include <threadhelp/writeguard.hxx>
44cdf0e10cSrcweir
45cdf0e10cSrcweir #ifndef __FRAMEWORK_ACCELERATORCONST_H_
46cdf0e10cSrcweir #include <acceleratorconst.h>
47cdf0e10cSrcweir #endif
48cdf0e10cSrcweir #include <services.h>
49cdf0e10cSrcweir
50cdf0e10cSrcweir //_______________________________________________
51cdf0e10cSrcweir // interface includes
52cdf0e10cSrcweir
53cdf0e10cSrcweir #ifndef _COM_SUN_STAR_IO_XACTIVEDATASOURCE_HPP_
54cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSource.hpp>
55cdf0e10cSrcweir #endif
56cdf0e10cSrcweir
57cdf0e10cSrcweir #ifndef _COM_SUN_STAR_IO_XSEEKABLE_HPP_
58cdf0e10cSrcweir #include <com/sun/star/io/XSeekable.hpp>
59cdf0e10cSrcweir #endif
60cdf0e10cSrcweir
61cdf0e10cSrcweir #ifndef _COM_SUN_STAR_IO_XTRUNCATE_HPP_
62cdf0e10cSrcweir #include <com/sun/star/io/XTruncate.hpp>
63cdf0e10cSrcweir #endif
64cdf0e10cSrcweir
65cdf0e10cSrcweir #ifndef _COM_SUN_STAR_EMBED_ELEMENTMODES_HPP_
66cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp>
67cdf0e10cSrcweir #endif
68cdf0e10cSrcweir
69cdf0e10cSrcweir #ifndef _COM_SUN_STAR_XML_SAX_INPUTSOURCE_HPP_
70cdf0e10cSrcweir #include <com/sun/star/xml/sax/InputSource.hpp>
71cdf0e10cSrcweir #endif
72cdf0e10cSrcweir
73cdf0e10cSrcweir #ifndef _COM_SUN_STAR_XML_SAX_XPARSER_HPP_
74cdf0e10cSrcweir #include <com/sun/star/xml/sax/XParser.hpp>
75cdf0e10cSrcweir #endif
76cdf0e10cSrcweir
77cdf0e10cSrcweir //_______________________________________________
78cdf0e10cSrcweir // other includes
79cdf0e10cSrcweir
80cdf0e10cSrcweir #ifndef _COMPHELPER_SEQUENCEASHASHMAP_HXX
81cdf0e10cSrcweir #include <comphelper/sequenceashashmap.hxx>
82cdf0e10cSrcweir #endif
83cdf0e10cSrcweir
84cdf0e10cSrcweir //_______________________________________________
85cdf0e10cSrcweir // const
86cdf0e10cSrcweir
87cdf0e10cSrcweir namespace framework
88cdf0e10cSrcweir {
89cdf0e10cSrcweir
90cdf0e10cSrcweir //-----------------------------------------------
91cdf0e10cSrcweir // XInterface, XTypeProvider, XServiceInfo
DEFINE_XINTERFACE_2(DocumentAcceleratorConfiguration,XMLBasedAcceleratorConfiguration,DIRECT_INTERFACE (css::lang::XServiceInfo),DIRECT_INTERFACE (css::lang::XInitialization))92cdf0e10cSrcweir DEFINE_XINTERFACE_2(DocumentAcceleratorConfiguration ,
93cdf0e10cSrcweir XMLBasedAcceleratorConfiguration ,
94cdf0e10cSrcweir DIRECT_INTERFACE(css::lang::XServiceInfo) ,
95cdf0e10cSrcweir DIRECT_INTERFACE(css::lang::XInitialization))
96cdf0e10cSrcweir // DIRECT_INTERFACE(css::ui::XUIConfigurationStorage))
97cdf0e10cSrcweir
98cdf0e10cSrcweir DEFINE_XTYPEPROVIDER_2_WITH_BASECLASS(DocumentAcceleratorConfiguration ,
99cdf0e10cSrcweir XMLBasedAcceleratorConfiguration ,
100cdf0e10cSrcweir css::lang::XServiceInfo ,
101cdf0e10cSrcweir css::lang::XInitialization)
102cdf0e10cSrcweir // css::ui::XUIConfigurationStorage)
103cdf0e10cSrcweir
104cdf0e10cSrcweir DEFINE_XSERVICEINFO_MULTISERVICE(DocumentAcceleratorConfiguration ,
105cdf0e10cSrcweir ::cppu::OWeakObject ,
106cdf0e10cSrcweir SERVICENAME_DOCUMENTACCELERATORCONFIGURATION ,
107cdf0e10cSrcweir IMPLEMENTATIONNAME_DOCUMENTACCELERATORCONFIGURATION)
108cdf0e10cSrcweir
109cdf0e10cSrcweir DEFINE_INIT_SERVICE(DocumentAcceleratorConfiguration,
110cdf0e10cSrcweir {
111cdf0e10cSrcweir /*Attention
112cdf0e10cSrcweir I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
113cdf0e10cSrcweir to create a new instance of this class by our own supported service factory.
114cdf0e10cSrcweir see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further informations!
115cdf0e10cSrcweir */
116cdf0e10cSrcweir }
117cdf0e10cSrcweir )
118cdf0e10cSrcweir
119cdf0e10cSrcweir //-----------------------------------------------
120cdf0e10cSrcweir DocumentAcceleratorConfiguration::DocumentAcceleratorConfiguration(const css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR)
121cdf0e10cSrcweir : XMLBasedAcceleratorConfiguration(xSMGR)
122cdf0e10cSrcweir {
123cdf0e10cSrcweir }
124cdf0e10cSrcweir
125cdf0e10cSrcweir //-----------------------------------------------
~DocumentAcceleratorConfiguration()126cdf0e10cSrcweir DocumentAcceleratorConfiguration::~DocumentAcceleratorConfiguration()
127cdf0e10cSrcweir {
128cdf0e10cSrcweir m_aPresetHandler.removeStorageListener(this);
129cdf0e10cSrcweir }
130cdf0e10cSrcweir
131cdf0e10cSrcweir //-----------------------------------------------
initialize(const css::uno::Sequence<css::uno::Any> & lArguments)132cdf0e10cSrcweir void SAL_CALL DocumentAcceleratorConfiguration::initialize(const css::uno::Sequence< css::uno::Any >& lArguments)
133cdf0e10cSrcweir throw(css::uno::Exception ,
134cdf0e10cSrcweir css::uno::RuntimeException)
135cdf0e10cSrcweir {
136cdf0e10cSrcweir // SAFE -> ----------------------------------
137cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock);
138cdf0e10cSrcweir
139cdf0e10cSrcweir ::comphelper::SequenceAsHashMap lArgs(lArguments);
140cdf0e10cSrcweir m_xDocumentRoot = lArgs.getUnpackedValueOrDefault(
141cdf0e10cSrcweir ::rtl::OUString::createFromAscii("DocumentRoot"),
142cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage >());
143cdf0e10cSrcweir
144cdf0e10cSrcweir aWriteLock.unlock();
145cdf0e10cSrcweir // <- SAFE ----------------------------------
146cdf0e10cSrcweir
147cdf0e10cSrcweir impl_ts_fillCache();
148cdf0e10cSrcweir }
149cdf0e10cSrcweir
150cdf0e10cSrcweir //-----------------------------------------------
setStorage(const css::uno::Reference<css::embed::XStorage> & xStorage)151cdf0e10cSrcweir void SAL_CALL DocumentAcceleratorConfiguration::setStorage(const css::uno::Reference< css::embed::XStorage >& xStorage)
152cdf0e10cSrcweir throw(css::uno::RuntimeException)
153cdf0e10cSrcweir {
154cdf0e10cSrcweir // Attention! xStorage must be accepted too, if it's NULL !
155cdf0e10cSrcweir
156cdf0e10cSrcweir // SAFE -> ----------------------------------
157cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock);
158cdf0e10cSrcweir sal_Bool bForgetOldStorages = m_xDocumentRoot.is();
159cdf0e10cSrcweir m_xDocumentRoot = xStorage;
160cdf0e10cSrcweir aWriteLock.unlock();
161cdf0e10cSrcweir // <- SAFE ----------------------------------
162cdf0e10cSrcweir
163cdf0e10cSrcweir if (bForgetOldStorages)
164cdf0e10cSrcweir impl_ts_clearCache();
165cdf0e10cSrcweir
166cdf0e10cSrcweir if (xStorage.is())
167cdf0e10cSrcweir impl_ts_fillCache();
168cdf0e10cSrcweir }
169cdf0e10cSrcweir
170cdf0e10cSrcweir //-----------------------------------------------
hasStorage()171cdf0e10cSrcweir sal_Bool SAL_CALL DocumentAcceleratorConfiguration::hasStorage()
172cdf0e10cSrcweir throw(css::uno::RuntimeException)
173cdf0e10cSrcweir {
174cdf0e10cSrcweir // SAFE -> ----------------------------------
175cdf0e10cSrcweir ReadGuard aReadLock(m_aLock);
176cdf0e10cSrcweir return m_xDocumentRoot.is();
177cdf0e10cSrcweir // <- SAFE ----------------------------------
178cdf0e10cSrcweir }
179cdf0e10cSrcweir
180cdf0e10cSrcweir //-----------------------------------------------
impl_ts_fillCache()181cdf0e10cSrcweir void DocumentAcceleratorConfiguration::impl_ts_fillCache()
182cdf0e10cSrcweir {
183cdf0e10cSrcweir // SAFE -> ----------------------------------
184cdf0e10cSrcweir ReadGuard aReadLock(m_aLock);
185cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage > xDocumentRoot = m_xDocumentRoot;
186cdf0e10cSrcweir aReadLock.unlock();
187cdf0e10cSrcweir // <- SAFE ----------------------------------
188cdf0e10cSrcweir
189cdf0e10cSrcweir // Sometimes we must live without a document root.
190cdf0e10cSrcweir // E.g. if the document is readonly ...
191cdf0e10cSrcweir if (!xDocumentRoot.is())
192cdf0e10cSrcweir return;
193cdf0e10cSrcweir
194cdf0e10cSrcweir // get current office locale ... but dont cache it.
195cdf0e10cSrcweir // Otherwise we must be listener on the configuration layer
196cdf0e10cSrcweir // which seems to superflous for this small implementation .-)
197cdf0e10cSrcweir ::comphelper::Locale aLocale = impl_ts_getLocale();
198cdf0e10cSrcweir
199cdf0e10cSrcweir // May be the current document does not contain any
200cdf0e10cSrcweir // accelerator config? Handle it gracefully :-)
201cdf0e10cSrcweir try
202cdf0e10cSrcweir {
203cdf0e10cSrcweir // Note: The used preset class is threadsafe by itself ... and live if we live!
204cdf0e10cSrcweir // We do not need any mutex here.
205cdf0e10cSrcweir
206cdf0e10cSrcweir // open the folder, where the configuration exists
207cdf0e10cSrcweir m_aPresetHandler.connectToResource(
208cdf0e10cSrcweir PresetHandler::E_DOCUMENT,
209cdf0e10cSrcweir PresetHandler::RESOURCETYPE_ACCELERATOR(),
210cdf0e10cSrcweir ::rtl::OUString(),
211cdf0e10cSrcweir xDocumentRoot,
212cdf0e10cSrcweir aLocale);
213cdf0e10cSrcweir
214cdf0e10cSrcweir DocumentAcceleratorConfiguration::reload();
215cdf0e10cSrcweir m_aPresetHandler.addStorageListener(this);
216cdf0e10cSrcweir }
217cdf0e10cSrcweir /*
218cdf0e10cSrcweir
219*796b7e2aSmseidel Sometimes the configuration seems to be corrupted...
220*796b7e2aSmseidel So it would be nice if we don't crash the office then .-)
221cdf0e10cSrcweir #121559#
222cdf0e10cSrcweir
223cdf0e10cSrcweir catch(const css::uno::RuntimeException& exRun)
224cdf0e10cSrcweir { throw exRun; }
225cdf0e10cSrcweir */
226cdf0e10cSrcweir catch(const css::uno::Exception&)
227cdf0e10cSrcweir {}
228cdf0e10cSrcweir }
229cdf0e10cSrcweir
230cdf0e10cSrcweir //-----------------------------------------------
impl_ts_clearCache()231cdf0e10cSrcweir void DocumentAcceleratorConfiguration::impl_ts_clearCache()
232cdf0e10cSrcweir {
233cdf0e10cSrcweir m_aPresetHandler.forgetCachedStorages();
234cdf0e10cSrcweir }
235cdf0e10cSrcweir
236cdf0e10cSrcweir } // namespace framework
237