Update ooo320-m1
[ooovba.git] / svtools / source / config / addxmltostorageoptions.cxx
blob06855488d2f2c9bea8b8192a0f50798c6e8b8507
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: addxmltostorageoptions.cxx,v $
10 * $Revision: 1.9 $
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_svtools.hxx"
33 #ifndef GCC
34 #endif
36 //_________________________________________________________________________________________________________________
37 // includes
38 //_________________________________________________________________________________________________________________
40 #include <svtools/addxmltostorageoptions.hxx>
41 #include <unotools/configmgr.hxx>
42 #include <unotools/configitem.hxx>
43 #include <tools/debug.hxx>
44 #include <tools/string.hxx>
45 #include <com/sun/star/uno/Any.hxx>
46 #include <com/sun/star/uno/Sequence.hxx>
48 #include <rtl/logfile.hxx>
49 #include "itemholder1.hxx"
51 //_________________________________________________________________________________________________________________
52 // namespaces
53 //_________________________________________________________________________________________________________________
55 using namespace ::utl;
56 using namespace ::rtl;
57 using namespace ::osl;
58 using namespace ::com::sun::star::uno;
60 //*****************************************************************************************************************
61 // initialize static member
62 // DON'T DO IT IN YOUR HEADER!
63 // see definition for further informations
64 //*****************************************************************************************************************
65 SvtAddXMLToStorageOptions_Impl* SvtAddXMLToStorageOptions::m_pDataContainer = 0;
66 sal_Int32 SvtAddXMLToStorageOptions::m_nRefCount = 0;
69 //_________________________________________________________________________________________________________________
70 // private declarations!
71 //_________________________________________________________________________________________________________________
73 class SvtAddXMLToStorageOptions_Impl : public ConfigItem
75 //-------------------------------------------------------------------------------------------------------------
76 // public methods
77 //-------------------------------------------------------------------------------------------------------------
79 public:
81 //---------------------------------------------------------------------------------------------------------
82 // constructor / destructor
83 //---------------------------------------------------------------------------------------------------------
85 SvtAddXMLToStorageOptions_Impl();
87 //---------------------------------------------------------------------------------------------------------
88 // overloaded methods of baseclass
89 //---------------------------------------------------------------------------------------------------------
91 //---------------------------------------------------------------------------------------------------------
92 // public interface
93 //---------------------------------------------------------------------------------------------------------
95 /*-****************************************************************************************************//**
96 @short access method to get internal values
97 @descr These method give us a chance to regulate acces to ouer internal values.
98 It's not used in the moment - but it's possible for the feature!
100 @seealso -
102 @param -
103 @return -
105 @onerror -
106 *//*-*****************************************************************************************************/
108 sal_Bool IsWriter_Add_XML_to_Storage() const { return bAddXmlToStg_Writer; }
109 sal_Bool IsCalc_Add_XML_to_Storage() const { return bAddXmlToStg_Calc; }
110 sal_Bool IsImpress_Add_XML_to_Storage() const { return bAddXmlToStg_Impress; }
111 sal_Bool IsDraw_Add_XML_to_Storage() const { return bAddXmlToStg_Draw; }
113 //-------------------------------------------------------------------------------------------------------------
114 // private methods
115 //-------------------------------------------------------------------------------------------------------------
117 private:
119 /*-****************************************************************************************************//**
120 @short return list of key names of ouer configuration management which represent oue module tree
121 @descr These methods return a static const list of key names. We need it to get needed values from our
122 configuration management.
124 @seealso -
126 @param -
127 @return A list of needed configuration keys is returned.
129 @onerror -
130 *//*-*****************************************************************************************************/
132 static Sequence< OUString > GetPropertyNames();
134 //-------------------------------------------------------------------------------------------------------------
135 // private member
136 //-------------------------------------------------------------------------------------------------------------
138 private:
140 sal_Bool bAddXmlToStg_Writer,
141 bAddXmlToStg_Calc,
142 bAddXmlToStg_Impress,
143 bAddXmlToStg_Draw;
146 //_________________________________________________________________________________________________________________
147 // definitions
148 //_________________________________________________________________________________________________________________
151 //*****************************************************************************************************************
152 // constructor
153 //*****************************************************************************************************************
154 SvtAddXMLToStorageOptions_Impl::SvtAddXMLToStorageOptions_Impl()
155 // Init baseclasses first
156 : ConfigItem( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM(
157 "Office.Common/AddXMLToStorage"))),
158 // Init member then.
159 bAddXmlToStg_Writer( FALSE ),
160 bAddXmlToStg_Calc( FALSE ),
161 bAddXmlToStg_Impress( FALSE ),
162 bAddXmlToStg_Draw( FALSE )
164 // Use our static list of configuration keys to get his values.
165 Sequence< OUString > seqNames = GetPropertyNames();
166 Sequence< Any > seqValues = GetProperties( seqNames );
168 // Copy values from list in right order to ouer internal member.
169 sal_Int32 nPropertyCount = seqValues.getLength();
170 const Any* pValue = seqValues.getConstArray();
171 for( sal_Int32 nProperty=0; nProperty<nPropertyCount; ++nProperty, ++pValue )
172 if( pValue->hasValue() )
174 switch( nProperty )
176 case 0:
177 *pValue >>= bAddXmlToStg_Writer;
178 break;
179 case 1:
180 *pValue >>= bAddXmlToStg_Calc;
181 break;
182 case 2:
183 *pValue >>= bAddXmlToStg_Impress;
184 break;
185 case 3:
186 *pValue >>= bAddXmlToStg_Draw;
187 break;
191 //*****************************************************************************************************************
192 // private method
193 //*****************************************************************************************************************
194 Sequence< OUString > SvtAddXMLToStorageOptions_Impl::GetPropertyNames()
196 // Build static list of configuration key names.
197 static const sal_Char* pProperties[] =
199 "Writer",
200 "Calc",
201 "Impress",
202 "Draw"
205 const sal_uInt16 nCnt = sizeof(pProperties) / sizeof( pProperties[0] );
206 Sequence<OUString> aNames( nCnt );
207 OUString* pNames = aNames.getArray();
208 for( sal_uInt16 n = 0; n < nCnt; ++n )
209 pNames[ n ] = OUString::createFromAscii( pProperties[ n ] );
210 return aNames;
214 //*****************************************************************************************************************
215 // constructor
216 //*****************************************************************************************************************
217 SvtAddXMLToStorageOptions::SvtAddXMLToStorageOptions()
219 // Global access, must be guarded (multithreading!).
220 MutexGuard aGuard( GetOwnStaticMutex() );
221 // Increase ouer refcount ...
222 ++m_nRefCount;
223 // ... and initialize ouer data container only if it not already exist!
224 if( !m_pDataContainer )
226 RTL_LOGFILE_CONTEXT(aLog, "svtools ( ??? ) ::SvtAddXMLToStorageOptions_Impl::ctor()");
227 m_pDataContainer = new SvtAddXMLToStorageOptions_Impl;
229 ItemHolder1::holdConfigItem(E_ADDXMLTOSTORAGEOPTIONS);
233 //*****************************************************************************************************************
234 // destructor
235 //*****************************************************************************************************************
236 SvtAddXMLToStorageOptions::~SvtAddXMLToStorageOptions()
238 // Global access, must be guarded (multithreading!)
239 MutexGuard aGuard( GetOwnStaticMutex() );
240 // Decrease ouer refcount.
241 // If last instance was deleted ...
242 // we must destroy ouer static data container!
243 if( !--m_nRefCount )
244 delete m_pDataContainer, m_pDataContainer = 0;
247 sal_Bool SvtAddXMLToStorageOptions::IsWriter_Add_XML_to_Storage() const
249 MutexGuard aGuard( GetOwnStaticMutex() );
250 return m_pDataContainer->IsWriter_Add_XML_to_Storage();
252 sal_Bool SvtAddXMLToStorageOptions::IsCalc_Add_XML_to_Storage() const
254 MutexGuard aGuard( GetOwnStaticMutex() );
255 return m_pDataContainer->IsCalc_Add_XML_to_Storage();
257 sal_Bool SvtAddXMLToStorageOptions::IsImpress_Add_XML_to_Storage() const
259 MutexGuard aGuard( GetOwnStaticMutex() );
260 return m_pDataContainer->IsImpress_Add_XML_to_Storage();
262 sal_Bool SvtAddXMLToStorageOptions::IsDraw_Add_XML_to_Storage() const
264 MutexGuard aGuard( GetOwnStaticMutex() );
265 return m_pDataContainer->IsDraw_Add_XML_to_Storage();
268 //*****************************************************************************************************************
269 // private method
270 //*****************************************************************************************************************
271 Mutex& SvtAddXMLToStorageOptions::GetOwnStaticMutex()
273 // Initialize static mutex only for one time!
274 static Mutex* pMutex = NULL;
275 // If these method first called (Mutex not already exist!) ...
276 if( pMutex == NULL )
278 // ... we must create a new one. Protect follow code with the global mutex -
279 // It must be - we create a static variable!
280 MutexGuard aGuard( Mutex::getGlobalMutex() );
281 // We must check our pointer again - because it can be that another instance of ouer class will be fastr then these!
282 if( pMutex == NULL )
284 // Create the new mutex and set it for return on static variable.
285 static Mutex aMutex;
286 pMutex = &aMutex;
289 // Return new created or already existing mutex object.
290 return *pMutex;