merge the formfield patch from ooo-build
[ooovba.git] / framework / source / accelerators / documentacceleratorconfiguration.cxx
blob540a0f481a46e4f0aa3b7dc168bdff07572e4fb8
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: documentacceleratorconfiguration.cxx,v $
10 * $Revision: 1.9.244.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
33 #include <accelerators/documentacceleratorconfiguration.hxx>
35 #ifndef __FRAMEWORK_XML_ACCELERATORCONFIGURATIONREADER_HXX_
36 #include <xml/acceleratorconfigurationreader.hxx>
37 #endif
39 #ifndef __FRAMEWORK_XML_ACCELERATORCONFIGURATIONWRITER_HXX_
40 #include <xml/acceleratorconfigurationwriter.hxx>
41 #endif
43 #ifndef __FRAMEWORK_XML_SAXNAMESPACEFILTER_HXX_
44 #include <xml/saxnamespacefilter.hxx>
45 #endif
47 //_______________________________________________
48 // own includes
49 #include <threadhelp/readguard.hxx>
50 #include <threadhelp/writeguard.hxx>
52 #ifndef __FRAMEWORK_ACCELERATORCONST_H_
53 #include <acceleratorconst.h>
54 #endif
55 #include <services.h>
57 //_______________________________________________
58 // interface includes
60 #ifndef _COM_SUN_STAR_IO_XACTIVEDATASOURCE_HPP_
61 #include <com/sun/star/io/XActiveDataSource.hpp>
62 #endif
64 #ifndef _COM_SUN_STAR_IO_XSEEKABLE_HPP_
65 #include <com/sun/star/io/XSeekable.hpp>
66 #endif
68 #ifndef _COM_SUN_STAR_IO_XTRUNCATE_HPP_
69 #include <com/sun/star/io/XTruncate.hpp>
70 #endif
72 #ifndef _COM_SUN_STAR_EMBED_ELEMENTMODES_HPP_
73 #include <com/sun/star/embed/ElementModes.hpp>
74 #endif
76 #ifndef _COM_SUN_STAR_XML_SAX_INPUTSOURCE_HPP_
77 #include <com/sun/star/xml/sax/InputSource.hpp>
78 #endif
80 #ifndef _COM_SUN_STAR_XML_SAX_XPARSER_HPP_
81 #include <com/sun/star/xml/sax/XParser.hpp>
82 #endif
84 //_______________________________________________
85 // other includes
87 #ifndef _COMPHELPER_SEQUENCEASHASHMAP_HXX
88 #include <comphelper/sequenceashashmap.hxx>
89 #endif
91 //_______________________________________________
92 // const
94 namespace framework
97 //-----------------------------------------------
98 // XInterface, XTypeProvider, XServiceInfo
99 DEFINE_XINTERFACE_2(DocumentAcceleratorConfiguration ,
100 XMLBasedAcceleratorConfiguration ,
101 DIRECT_INTERFACE(css::lang::XServiceInfo) ,
102 DIRECT_INTERFACE(css::lang::XInitialization))
103 // DIRECT_INTERFACE(css::ui::XUIConfigurationStorage))
105 DEFINE_XTYPEPROVIDER_2_WITH_BASECLASS(DocumentAcceleratorConfiguration ,
106 XMLBasedAcceleratorConfiguration ,
107 css::lang::XServiceInfo ,
108 css::lang::XInitialization)
109 // css::ui::XUIConfigurationStorage)
111 DEFINE_XSERVICEINFO_MULTISERVICE(DocumentAcceleratorConfiguration ,
112 ::cppu::OWeakObject ,
113 SERVICENAME_DOCUMENTACCELERATORCONFIGURATION ,
114 IMPLEMENTATIONNAME_DOCUMENTACCELERATORCONFIGURATION)
116 DEFINE_INIT_SERVICE(DocumentAcceleratorConfiguration,
118 /*Attention
119 I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
120 to create a new instance of this class by our own supported service factory.
121 see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further informations!
126 //-----------------------------------------------
127 DocumentAcceleratorConfiguration::DocumentAcceleratorConfiguration(const css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR)
128 : XMLBasedAcceleratorConfiguration(xSMGR)
132 //-----------------------------------------------
133 DocumentAcceleratorConfiguration::~DocumentAcceleratorConfiguration()
135 m_aPresetHandler.removeStorageListener(this);
138 //-----------------------------------------------
139 void SAL_CALL DocumentAcceleratorConfiguration::initialize(const css::uno::Sequence< css::uno::Any >& lArguments)
140 throw(css::uno::Exception ,
141 css::uno::RuntimeException)
143 // SAFE -> ----------------------------------
144 WriteGuard aWriteLock(m_aLock);
146 ::comphelper::SequenceAsHashMap lArgs(lArguments);
147 m_xDocumentRoot = lArgs.getUnpackedValueOrDefault(
148 ::rtl::OUString::createFromAscii("DocumentRoot"),
149 css::uno::Reference< css::embed::XStorage >());
151 aWriteLock.unlock();
152 // <- SAFE ----------------------------------
154 impl_ts_fillCache();
157 //-----------------------------------------------
158 void SAL_CALL DocumentAcceleratorConfiguration::setStorage(const css::uno::Reference< css::embed::XStorage >& xStorage)
159 throw(css::uno::RuntimeException)
161 // Attention! xStorage must be accepted too, if it's NULL !
163 // SAFE -> ----------------------------------
164 WriteGuard aWriteLock(m_aLock);
165 sal_Bool bForgetOldStorages = m_xDocumentRoot.is();
166 m_xDocumentRoot = xStorage;
167 aWriteLock.unlock();
168 // <- SAFE ----------------------------------
170 if (bForgetOldStorages)
171 impl_ts_clearCache();
173 if (xStorage.is())
174 impl_ts_fillCache();
177 //-----------------------------------------------
178 sal_Bool SAL_CALL DocumentAcceleratorConfiguration::hasStorage()
179 throw(css::uno::RuntimeException)
181 // SAFE -> ----------------------------------
182 ReadGuard aReadLock(m_aLock);
183 return m_xDocumentRoot.is();
184 // <- SAFE ----------------------------------
187 //-----------------------------------------------
188 void DocumentAcceleratorConfiguration::impl_ts_fillCache()
190 // SAFE -> ----------------------------------
191 ReadGuard aReadLock(m_aLock);
192 css::uno::Reference< css::embed::XStorage > xDocumentRoot = m_xDocumentRoot;
193 aReadLock.unlock();
194 // <- SAFE ----------------------------------
196 // Sometimes we must live without a document root.
197 // E.g. if the document is readonly ...
198 if (!xDocumentRoot.is())
199 return;
201 // get current office locale ... but dont cache it.
202 // Otherwise we must be listener on the configuration layer
203 // which seems to superflous for this small implementation .-)
204 ::comphelper::Locale aLocale = impl_ts_getLocale();
206 // May be the current document does not contain any
207 // accelerator config? Handle it gracefully :-)
210 // Note: The used preset class is threadsafe by itself ... and live if we live!
211 // We do not need any mutex here.
213 // open the folder, where the configuration exists
214 m_aPresetHandler.connectToResource(
215 PresetHandler::E_DOCUMENT,
216 PresetHandler::RESOURCETYPE_ACCELERATOR(),
217 ::rtl::OUString(),
218 xDocumentRoot,
219 aLocale);
221 DocumentAcceleratorConfiguration::reload();
222 m_aPresetHandler.addStorageListener(this);
226 Sometimes the configuration seams to be corrupted ..
227 So it would be nice if we dont crash the office then .-)
228 #121559#
230 catch(const css::uno::RuntimeException& exRun)
231 { throw exRun; }
233 catch(const css::uno::Exception&)
237 //-----------------------------------------------
238 void DocumentAcceleratorConfiguration::impl_ts_clearCache()
240 m_aPresetHandler.forgetCachedStorages();
243 } // namespace framework