1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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>
39 #ifndef __FRAMEWORK_XML_ACCELERATORCONFIGURATIONWRITER_HXX_
40 #include <xml/acceleratorconfigurationwriter.hxx>
43 #ifndef __FRAMEWORK_XML_SAXNAMESPACEFILTER_HXX_
44 #include <xml/saxnamespacefilter.hxx>
47 //_______________________________________________
49 #include <threadhelp/readguard.hxx>
50 #include <threadhelp/writeguard.hxx>
52 #ifndef __FRAMEWORK_ACCELERATORCONST_H_
53 #include <acceleratorconst.h>
57 //_______________________________________________
60 #ifndef _COM_SUN_STAR_IO_XACTIVEDATASOURCE_HPP_
61 #include <com/sun/star/io/XActiveDataSource.hpp>
64 #ifndef _COM_SUN_STAR_IO_XSEEKABLE_HPP_
65 #include <com/sun/star/io/XSeekable.hpp>
68 #ifndef _COM_SUN_STAR_IO_XTRUNCATE_HPP_
69 #include <com/sun/star/io/XTruncate.hpp>
72 #ifndef _COM_SUN_STAR_EMBED_ELEMENTMODES_HPP_
73 #include <com/sun/star/embed/ElementModes.hpp>
76 #ifndef _COM_SUN_STAR_XML_SAX_INPUTSOURCE_HPP_
77 #include <com/sun/star/xml/sax/InputSource.hpp>
80 #ifndef _COM_SUN_STAR_XML_SAX_XPARSER_HPP_
81 #include <com/sun/star/xml/sax/XParser.hpp>
84 //_______________________________________________
87 #ifndef _COMPHELPER_SEQUENCEASHASHMAP_HXX
88 #include <comphelper/sequenceashashmap.hxx>
91 //_______________________________________________
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
,
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
>());
152 // <- SAFE ----------------------------------
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
;
168 // <- SAFE ----------------------------------
170 if (bForgetOldStorages
)
171 impl_ts_clearCache();
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
;
194 // <- SAFE ----------------------------------
196 // Sometimes we must live without a document root.
197 // E.g. if the document is readonly ...
198 if (!xDocumentRoot
.is())
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(),
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 .-)
230 catch(const css::uno::RuntimeException& exRun)
233 catch(const css::uno::Exception
&)
237 //-----------------------------------------------
238 void DocumentAcceleratorConfiguration::impl_ts_clearCache()
240 m_aPresetHandler
.forgetCachedStorages();
243 } // namespace framework