merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / config / javaoptions.cxx
blobcff0c538cd7ca37ab01c4af71eb0a5dce4d4ec24
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: javaoptions.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 #ifndef _SVTOOLS_JAVAPTIONS_HXX
37 #include <javaoptions.hxx>
38 #endif
39 #include <com/sun/star/uno/Any.h>
40 #include <com/sun/star/uno/Sequence.hxx>
41 #include <rtl/logfile.hxx>
44 using namespace ::com::sun::star::uno;
45 using namespace ::rtl;
47 #define C2U(cChar) OUString::createFromAscii(cChar)
48 #define CFG_READONLY_DEFAULT sal_False
49 /* -----------------------------10.04.01 12:39--------------------------------
51 ---------------------------------------------------------------------------*/
52 class SvtExecAppletsItem_Impl : public utl::ConfigItem
54 sal_Bool bExecute;
55 sal_Bool bRO;
56 public:
57 SvtExecAppletsItem_Impl();
59 virtual void Commit();
61 sal_Bool IsExecuteApplets() const {return bExecute;}
62 void SetExecuteApplets(sal_Bool bSet);
63 sal_Bool IsReadOnly() const {return bRO;}
65 /* -----------------------------10.02.2003 07:46------------------------------
67 ---------------------------------------------------------------------------*/
68 void SvtExecAppletsItem_Impl::SetExecuteApplets(sal_Bool bSet)
70 OSL_ENSURE(!bRO, "SvtExecAppletsItem_Impl::SetExecuteApplets()\nYou tried to write on a readonly value!\n");
71 if (!bRO)
73 bExecute = bSet;
74 SetModified();
77 /* -----------------------------18.05.01 14:44--------------------------------
79 ---------------------------------------------------------------------------*/
80 SvtExecAppletsItem_Impl::SvtExecAppletsItem_Impl() :
81 utl::ConfigItem(C2U("Office.Common/Java/Applet")),
82 bExecute (sal_False ),
83 bRO (CFG_READONLY_DEFAULT )
85 RTL_LOGFILE_CONTEXT(aLog, "svtools SvtExecAppletsItem_Impl::SvtExecAppletsItem_Impl()");
87 Sequence< OUString > aNames(1);
88 aNames.getArray()[0] = C2U("Enable");
89 Sequence< Any > aValues = GetProperties(aNames);
90 Sequence< sal_Bool > aROStates = GetReadOnlyStates(aNames);
91 const Any* pValues = aValues.getConstArray();
92 const sal_Bool* pROStates = aROStates.getConstArray();
93 if(aValues.getLength() && aROStates.getLength() && pValues[0].hasValue())
95 bExecute = *(sal_Bool*)pValues[0].getValue();
96 bRO = pROStates[0];
99 void SvtExecAppletsItem_Impl::Commit()
101 if (bRO)
102 return;
104 Sequence< OUString > aNames(1);
105 aNames.getArray()[0] = C2U("Enable");
106 Sequence< Any > aValues(1);
107 aValues.getArray()[0].setValue(&bExecute, ::getBooleanCppuType());
108 PutProperties(aNames, aValues);
112 struct SvtJavaOptions_Impl
114 SvtExecAppletsItem_Impl aExecItem;
115 Sequence<OUString> aPropertyNames;
116 sal_Bool bEnabled;
117 sal_Bool bSecurity;
118 sal_Int32 nNetAccess;
119 rtl::OUString sUserClassPath;
121 sal_Bool bROEnabled;
122 sal_Bool bROSecurity;
123 sal_Bool bRONetAccess;
124 sal_Bool bROUserClassPath;
126 SvtJavaOptions_Impl() :
127 aPropertyNames(4),
128 bEnabled (sal_False),
129 bSecurity (sal_False),
130 nNetAccess (0),
131 bROEnabled (CFG_READONLY_DEFAULT),
132 bROSecurity (CFG_READONLY_DEFAULT),
133 bRONetAccess (CFG_READONLY_DEFAULT),
134 bROUserClassPath (CFG_READONLY_DEFAULT)
136 OUString* pNames = aPropertyNames.getArray();
137 pNames[0] = C2U("Enable");
138 pNames[1] = C2U("Security");
139 pNames[2] = C2U("NetAccess");
140 pNames[3] = C2U("UserClassPath");
143 /* -----------------------------18.05.01 13:28--------------------------------
145 ---------------------------------------------------------------------------*/
146 SvtJavaOptions::SvtJavaOptions() :
147 utl::ConfigItem(C2U("Office.Java/VirtualMachine")),
148 pImpl(new SvtJavaOptions_Impl)
150 RTL_LOGFILE_CONTEXT(aLog, "svtools SvtJavaOptions::SvtJavaOptions()");
152 Sequence< Any > aValues = GetProperties(pImpl->aPropertyNames);
153 Sequence< sal_Bool > aROStates = GetReadOnlyStates(pImpl->aPropertyNames);
154 const Any* pValues = aValues.getConstArray();
155 const sal_Bool* pROStates = aROStates.getConstArray();
156 if ( aValues.getLength() == pImpl->aPropertyNames.getLength() && aROStates.getLength() == pImpl->aPropertyNames.getLength() )
158 for ( int nProp = 0; nProp < pImpl->aPropertyNames.getLength(); nProp++ )
160 if( pValues[nProp].hasValue() )
162 switch ( nProp )
164 case 0: pImpl->bEnabled = *(sal_Bool*)pValues[nProp].getValue(); break;
165 case 1: pImpl->bSecurity = *(sal_Bool*)pValues[nProp].getValue();break;
166 case 2: pValues[nProp] >>= pImpl->nNetAccess; break;
167 case 3: pValues[nProp] >>= pImpl->sUserClassPath; break;
171 pImpl->bROEnabled = pROStates[0];
172 pImpl->bROSecurity = pROStates[1];
173 pImpl->bRONetAccess = pROStates[2];
174 pImpl->bROUserClassPath = pROStates[3];
177 /* -----------------------------18.05.01 13:28--------------------------------
179 ---------------------------------------------------------------------------*/
180 SvtJavaOptions::~SvtJavaOptions()
182 delete pImpl;
184 /*-- 18.05.01 13:28:35---------------------------------------------------
186 -----------------------------------------------------------------------*/
187 void SvtJavaOptions::Commit()
189 pImpl->aExecItem.Commit();
191 sal_Int32 nOrgCount = pImpl->aPropertyNames.getLength();
192 Sequence< OUString > aNames(nOrgCount);
193 Sequence< Any > aValues(nOrgCount);
194 sal_Int32 nRealCount = 0;
196 const Type& rType = ::getBooleanCppuType();
197 for(int nProp = 0; nProp < nOrgCount; nProp++)
199 switch(nProp)
201 case 0:
203 if (!pImpl->bROEnabled)
205 aValues[nRealCount].setValue(&pImpl->bEnabled, rType);
206 aNames[nRealCount] = pImpl->aPropertyNames[nProp];
207 ++nRealCount;
210 break;
211 case 1:
213 if (!pImpl->bROSecurity)
215 aValues[nRealCount].setValue(&pImpl->bSecurity, rType);
216 aNames[nRealCount] = pImpl->aPropertyNames[nProp];
217 ++nRealCount;
220 break;
221 case 2:
223 if (!pImpl->bRONetAccess)
225 aValues[nRealCount] <<= pImpl->nNetAccess;
226 aNames[nRealCount] = pImpl->aPropertyNames[nProp];
227 ++nRealCount;
230 break;
231 case 3:
233 if (!pImpl->bROUserClassPath)
235 aValues[nRealCount] <<= pImpl->sUserClassPath;
236 aNames[nRealCount] = pImpl->aPropertyNames[nProp];
237 ++nRealCount;
240 break;
243 aValues.realloc(nRealCount);
244 aNames.realloc(nRealCount);
245 PutProperties(aNames,aValues);
247 /*-- 18.05.01 13:28:35---------------------------------------------------
249 -----------------------------------------------------------------------*/
250 sal_Bool SvtJavaOptions::IsEnabled() const
252 return pImpl->bEnabled;
254 /*-- 18.05.01 13:28:35---------------------------------------------------
256 -----------------------------------------------------------------------*/
257 sal_Bool SvtJavaOptions::IsSecurity()const
259 return pImpl->bSecurity;
261 /*-- 18.05.01 13:28:35---------------------------------------------------
263 -----------------------------------------------------------------------*/
264 sal_Int32 SvtJavaOptions::GetNetAccess() const
266 return pImpl->nNetAccess;
268 /*-- 18.05.01 13:28:36---------------------------------------------------
270 -----------------------------------------------------------------------*/
271 rtl::OUString& SvtJavaOptions::GetUserClassPath()const
273 return pImpl->sUserClassPath;
275 /*-- 18.05.01 13:28:37---------------------------------------------------
277 -----------------------------------------------------------------------*/
278 void SvtJavaOptions::SetEnabled(sal_Bool bSet)
280 OSL_ENSURE(!pImpl->bROEnabled, "SvtJavaOptions::SetEnabled()\nYou tried to write on a readonly value!\n");
281 if(!pImpl->bROEnabled && pImpl->bEnabled != bSet)
283 pImpl->bEnabled = bSet;
284 SetModified();
287 /*-- 18.05.01 13:28:38---------------------------------------------------
289 -----------------------------------------------------------------------*/
290 void SvtJavaOptions::SetSecurity(sal_Bool bSet)
292 OSL_ENSURE(!pImpl->bROSecurity, "SvtJavaOptions::SetSecurity()\nYou tried to write on a readonly value!\n");
293 if(!pImpl->bROSecurity && pImpl->bSecurity != bSet)
295 pImpl->bSecurity = bSet;
296 SetModified();
299 /*-- 18.05.01 13:28:38---------------------------------------------------
301 -----------------------------------------------------------------------*/
302 void SvtJavaOptions::SetNetAccess(sal_Int32 nSet)
304 OSL_ENSURE(!pImpl->bRONetAccess, "SvtJavaOptions::SetNetAccess()\nYou tried to write on a readonly value!\n");
305 if(!pImpl->bRONetAccess && pImpl->nNetAccess != nSet)
307 pImpl->nNetAccess = nSet;
308 SetModified();
311 /*-- 18.05.01 13:28:38---------------------------------------------------
313 -----------------------------------------------------------------------*/
314 void SvtJavaOptions::SetUserClassPath(const rtl::OUString& rSet)
316 OSL_ENSURE(!pImpl->bROUserClassPath, "SvtJavaOptions::SetUserClassPath()\nYou tried to write on a readonly value!\n");
317 if(!pImpl->bROUserClassPath && pImpl->sUserClassPath != rSet)
319 pImpl->sUserClassPath = rSet;
320 SetModified();
324 /*-- 18.05.01 14:34:32---------------------------------------------------
326 -----------------------------------------------------------------------*/
327 sal_Bool SvtJavaOptions::IsExecuteApplets() const
329 return pImpl->aExecItem.IsExecuteApplets();
331 /*-- 18.05.01 14:34:32---------------------------------------------------
333 -----------------------------------------------------------------------*/
334 void SvtJavaOptions::SetExecuteApplets(sal_Bool bSet)
336 if(!pImpl->aExecItem.IsReadOnly() && pImpl->aExecItem.IsExecuteApplets() != bSet)
338 pImpl->aExecItem.SetExecuteApplets(bSet);
339 SetModified();
342 /*--10.02.2003 08:40---------------------------------------------------
344 -----------------------------------------------------------------------*/
345 sal_Bool SvtJavaOptions::IsReadOnly( EOption eOption ) const
347 sal_Bool bRO = sal_True;
348 switch(eOption)
350 case E_ENABLED :
351 bRO = pImpl->bROEnabled;
352 break;
353 case E_SECURITY :
354 bRO = pImpl->bROSecurity;
355 break;
356 case E_NETACCESS :
357 bRO = pImpl->bRONetAccess;
358 break;
359 case E_USERCLASSPATH :
360 bRO = pImpl->bROUserClassPath;
361 break;
362 case E_EXECUTEAPPLETS :
363 bRO = pImpl->aExecItem.IsReadOnly();
364 break;
366 return bRO;