Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <accelerators/documentacceleratorconfiguration.hxx>
30 : :
31 : : #include <xml/acceleratorconfigurationreader.hxx>
32 : :
33 : : #include <xml/acceleratorconfigurationwriter.hxx>
34 : :
35 : : #include <xml/saxnamespacefilter.hxx>
36 : :
37 : : #include <threadhelp/readguard.hxx>
38 : : #include <threadhelp/writeguard.hxx>
39 : :
40 : : #include <acceleratorconst.h>
41 : : #include <services.h>
42 : :
43 : : #include <com/sun/star/io/XActiveDataSource.hpp>
44 : :
45 : : #include <com/sun/star/io/XSeekable.hpp>
46 : :
47 : : #include <com/sun/star/io/XTruncate.hpp>
48 : :
49 : : #include <com/sun/star/embed/ElementModes.hpp>
50 : :
51 : : #include <com/sun/star/xml/sax/InputSource.hpp>
52 : :
53 : : #include <com/sun/star/xml/sax/XParser.hpp>
54 : :
55 : : #include <comphelper/sequenceashashmap.hxx>
56 : :
57 : :
58 : : namespace framework
59 : : {
60 : :
61 : : //-----------------------------------------------
62 : : // XInterface, XTypeProvider, XServiceInfo
63 [ + + ][ + - ]: 176790 : DEFINE_XINTERFACE_2(DocumentAcceleratorConfiguration ,
64 : : XMLBasedAcceleratorConfiguration ,
65 : : DIRECT_INTERFACE(css::lang::XServiceInfo) ,
66 : : DIRECT_INTERFACE(css::lang::XInitialization))
67 : : // DIRECT_INTERFACE(css::ui::XUIConfigurationStorage))
68 : :
69 [ # # ][ # # ]: 0 : DEFINE_XTYPEPROVIDER_2_WITH_BASECLASS(DocumentAcceleratorConfiguration ,
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
[ # # # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
70 : : XMLBasedAcceleratorConfiguration ,
71 : : css::lang::XServiceInfo ,
72 : : css::lang::XInitialization)
73 : : // css::ui::XUIConfigurationStorage)
74 : :
75 [ + - ][ + - ]: 2750 : DEFINE_XSERVICEINFO_MULTISERVICE(DocumentAcceleratorConfiguration ,
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ # # ][ # # ]
76 : : ::cppu::OWeakObject ,
77 : : SERVICENAME_DOCUMENTACCELERATORCONFIGURATION ,
78 : : IMPLEMENTATIONNAME_DOCUMENTACCELERATORCONFIGURATION)
79 : :
80 : 1125 : DEFINE_INIT_SERVICE(DocumentAcceleratorConfiguration,
81 : : {
82 : : /*Attention
83 : : I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
84 : : to create a new instance of this class by our own supported service factory.
85 : : see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further informations!
86 : : */
87 : : }
88 : : )
89 : :
90 : : //-----------------------------------------------
91 : 1125 : DocumentAcceleratorConfiguration::DocumentAcceleratorConfiguration(const css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR)
92 [ + - ]: 1125 : : XMLBasedAcceleratorConfiguration(xSMGR)
93 : : {
94 : 1125 : }
95 : :
96 : : //-----------------------------------------------
97 : 1125 : DocumentAcceleratorConfiguration::~DocumentAcceleratorConfiguration()
98 : : {
99 [ + - ]: 1125 : m_aPresetHandler.removeStorageListener(this);
100 [ - + ]: 2250 : }
101 : :
102 : : //-----------------------------------------------
103 : 1125 : void SAL_CALL DocumentAcceleratorConfiguration::initialize(const css::uno::Sequence< css::uno::Any >& lArguments)
104 : : throw(css::uno::Exception ,
105 : : css::uno::RuntimeException)
106 : : {
107 : : // SAFE -> ----------------------------------
108 [ + - ]: 1125 : WriteGuard aWriteLock(m_aLock);
109 : :
110 [ + - ]: 1125 : ::comphelper::SequenceAsHashMap lArgs(lArguments);
111 : : m_xDocumentRoot = lArgs.getUnpackedValueOrDefault(
112 : : ::rtl::OUString("DocumentRoot"),
113 [ + - ][ + - ]: 1125 : css::uno::Reference< css::embed::XStorage >());
114 : :
115 [ + - ]: 1125 : aWriteLock.unlock();
116 : : // <- SAFE ----------------------------------
117 : :
118 [ + - ][ + - ]: 1125 : impl_ts_fillCache();
[ + - ]
119 : 1125 : }
120 : :
121 : : //-----------------------------------------------
122 : 16 : void SAL_CALL DocumentAcceleratorConfiguration::setStorage(const css::uno::Reference< css::embed::XStorage >& xStorage)
123 : : throw(css::uno::RuntimeException)
124 : : {
125 : : // Attention! xStorage must be accepted too, if it's NULL !
126 : :
127 : : // SAFE -> ----------------------------------
128 [ + - ]: 16 : WriteGuard aWriteLock(m_aLock);
129 : 16 : sal_Bool bForgetOldStorages = m_xDocumentRoot.is();
130 [ + - ]: 16 : m_xDocumentRoot = xStorage;
131 [ + - ]: 16 : aWriteLock.unlock();
132 : : // <- SAFE ----------------------------------
133 : :
134 [ + - ]: 16 : if (bForgetOldStorages)
135 [ + - ]: 16 : impl_ts_clearCache();
136 : :
137 [ + - ]: 16 : if (xStorage.is())
138 [ + - ][ + - ]: 16 : impl_ts_fillCache();
139 : 16 : }
140 : :
141 : : //-----------------------------------------------
142 : 0 : sal_Bool SAL_CALL DocumentAcceleratorConfiguration::hasStorage()
143 : : throw(css::uno::RuntimeException)
144 : : {
145 : : // SAFE -> ----------------------------------
146 [ # # ]: 0 : ReadGuard aReadLock(m_aLock);
147 [ # # ]: 0 : return m_xDocumentRoot.is();
148 : : // <- SAFE ----------------------------------
149 : : }
150 : :
151 : : //-----------------------------------------------
152 : 1141 : void DocumentAcceleratorConfiguration::impl_ts_fillCache()
153 : : {
154 : : // SAFE -> ----------------------------------
155 [ + - ]: 1141 : ReadGuard aReadLock(m_aLock);
156 : 1141 : css::uno::Reference< css::embed::XStorage > xDocumentRoot = m_xDocumentRoot;
157 [ + - ]: 1141 : aReadLock.unlock();
158 : : // <- SAFE ----------------------------------
159 : :
160 : : // Sometimes we must live without a document root.
161 : : // E.g. if the document is readonly ...
162 [ - + ]: 1141 : if (!xDocumentRoot.is())
163 : 1141 : return;
164 : :
165 : : // get current office locale ... but dont cache it.
166 : : // Otherwise we must be listener on the configuration layer
167 : : // which seems to superflous for this small implementation .-)
168 [ + - ]: 1141 : ::comphelper::Locale aLocale = impl_ts_getLocale();
169 : :
170 : : // May be the current document does not contain any
171 : : // accelerator config? Handle it gracefully :-)
172 : : try
173 : : {
174 : : // Note: The used preset class is threadsafe by itself ... and live if we live!
175 : : // We do not need any mutex here.
176 : :
177 : : // open the folder, where the configuration exists
178 : : m_aPresetHandler.connectToResource(
179 : : PresetHandler::E_DOCUMENT,
180 : : PresetHandler::RESOURCETYPE_ACCELERATOR(),
181 : : ::rtl::OUString(),
182 : : xDocumentRoot,
183 [ + - ][ + - ]: 1141 : aLocale);
[ # # ]
184 : :
185 [ + - ]: 1141 : DocumentAcceleratorConfiguration::reload();
186 [ + - ]: 1141 : m_aPresetHandler.addStorageListener(this);
187 : : }
188 [ # # ]: 0 : catch(const css::uno::Exception&)
189 [ + - ][ - + ]: 1141 : {}
[ + - ][ + - ]
190 : : }
191 : :
192 : : //-----------------------------------------------
193 : 16 : void DocumentAcceleratorConfiguration::impl_ts_clearCache()
194 : : {
195 : 16 : m_aPresetHandler.forgetCachedStorages();
196 : 16 : }
197 : :
198 : : } // namespace framework
199 : :
200 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|