1*b5088357SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*b5088357SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*b5088357SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*b5088357SAndrew Rist * distributed with this work for additional information
6*b5088357SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*b5088357SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*b5088357SAndrew Rist * "License"); you may not use this file except in compliance
9*b5088357SAndrew Rist * with the License. You may obtain a copy of the License at
10*b5088357SAndrew Rist *
11*b5088357SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*b5088357SAndrew Rist *
13*b5088357SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*b5088357SAndrew Rist * software distributed under the License is distributed on an
15*b5088357SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b5088357SAndrew Rist * KIND, either express or implied. See the License for the
17*b5088357SAndrew Rist * specific language governing permissions and limitations
18*b5088357SAndrew Rist * under the License.
19*b5088357SAndrew Rist *
20*b5088357SAndrew Rist *************************************************************/
21*b5088357SAndrew Rist
22*b5088357SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_unotools.hxx"
26cdf0e10cSrcweir #ifndef GCC
27cdf0e10cSrcweir #endif
28cdf0e10cSrcweir
29cdf0e10cSrcweir #ifndef _unotools_JAVAPTIONS_HXX
30cdf0e10cSrcweir #include <unotools/javaoptions.hxx>
31cdf0e10cSrcweir #endif
32cdf0e10cSrcweir #include <com/sun/star/uno/Any.h>
33cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
34cdf0e10cSrcweir #include <rtl/logfile.hxx>
35cdf0e10cSrcweir
36cdf0e10cSrcweir
37cdf0e10cSrcweir using namespace ::com::sun::star::uno;
38cdf0e10cSrcweir using namespace ::rtl;
39cdf0e10cSrcweir
40cdf0e10cSrcweir #define C2U(cChar) OUString::createFromAscii(cChar)
41cdf0e10cSrcweir #define CFG_READONLY_DEFAULT sal_False
42cdf0e10cSrcweir /* -----------------------------10.04.01 12:39--------------------------------
43cdf0e10cSrcweir
44cdf0e10cSrcweir ---------------------------------------------------------------------------*/
45cdf0e10cSrcweir class SvtExecAppletsItem_Impl : public utl::ConfigItem
46cdf0e10cSrcweir {
47cdf0e10cSrcweir sal_Bool bExecute;
48cdf0e10cSrcweir sal_Bool bRO;
49cdf0e10cSrcweir public:
50cdf0e10cSrcweir SvtExecAppletsItem_Impl();
51cdf0e10cSrcweir
52cdf0e10cSrcweir virtual void Commit();
53cdf0e10cSrcweir void Notify( const Sequence< rtl::OUString >& );
54cdf0e10cSrcweir
IsExecuteApplets() const55cdf0e10cSrcweir sal_Bool IsExecuteApplets() const {return bExecute;}
56cdf0e10cSrcweir void SetExecuteApplets(sal_Bool bSet);
IsReadOnly() const57cdf0e10cSrcweir sal_Bool IsReadOnly() const {return bRO;}
58cdf0e10cSrcweir };
59cdf0e10cSrcweir /* -----------------------------10.02.2003 07:46------------------------------
60cdf0e10cSrcweir
61cdf0e10cSrcweir ---------------------------------------------------------------------------*/
SetExecuteApplets(sal_Bool bSet)62cdf0e10cSrcweir void SvtExecAppletsItem_Impl::SetExecuteApplets(sal_Bool bSet)
63cdf0e10cSrcweir {
64cdf0e10cSrcweir OSL_ENSURE(!bRO, "SvtExecAppletsItem_Impl::SetExecuteApplets()\nYou tried to write on a readonly value!\n");
65cdf0e10cSrcweir if (!bRO)
66cdf0e10cSrcweir {
67cdf0e10cSrcweir bExecute = bSet;
68cdf0e10cSrcweir SetModified();
69cdf0e10cSrcweir }
70cdf0e10cSrcweir }
71cdf0e10cSrcweir /* -----------------------------18.05.01 14:44--------------------------------
72cdf0e10cSrcweir
73cdf0e10cSrcweir ---------------------------------------------------------------------------*/
SvtExecAppletsItem_Impl()74cdf0e10cSrcweir SvtExecAppletsItem_Impl::SvtExecAppletsItem_Impl() :
75cdf0e10cSrcweir utl::ConfigItem(C2U("Office.Common/Java/Applet")),
76cdf0e10cSrcweir bExecute (sal_False ),
77cdf0e10cSrcweir bRO (CFG_READONLY_DEFAULT )
78cdf0e10cSrcweir {
79cdf0e10cSrcweir RTL_LOGFILE_CONTEXT(aLog, "unotools SvtExecAppletsItem_Impl::SvtExecAppletsItem_Impl()");
80cdf0e10cSrcweir
81cdf0e10cSrcweir Sequence< OUString > aNames(1);
82cdf0e10cSrcweir aNames.getArray()[0] = C2U("Enable");
83cdf0e10cSrcweir Sequence< Any > aValues = GetProperties(aNames);
84cdf0e10cSrcweir Sequence< sal_Bool > aROStates = GetReadOnlyStates(aNames);
85cdf0e10cSrcweir const Any* pValues = aValues.getConstArray();
86cdf0e10cSrcweir const sal_Bool* pROStates = aROStates.getConstArray();
87cdf0e10cSrcweir if(aValues.getLength() && aROStates.getLength() && pValues[0].hasValue())
88cdf0e10cSrcweir {
89cdf0e10cSrcweir bExecute = *(sal_Bool*)pValues[0].getValue();
90cdf0e10cSrcweir bRO = pROStates[0];
91cdf0e10cSrcweir }
92cdf0e10cSrcweir }
Commit()93cdf0e10cSrcweir void SvtExecAppletsItem_Impl::Commit()
94cdf0e10cSrcweir {
95cdf0e10cSrcweir if (bRO)
96cdf0e10cSrcweir return;
97cdf0e10cSrcweir
98cdf0e10cSrcweir Sequence< OUString > aNames(1);
99cdf0e10cSrcweir aNames.getArray()[0] = C2U("Enable");
100cdf0e10cSrcweir Sequence< Any > aValues(1);
101cdf0e10cSrcweir aValues.getArray()[0].setValue(&bExecute, ::getBooleanCppuType());
102cdf0e10cSrcweir PutProperties(aNames, aValues);
103cdf0e10cSrcweir }
104cdf0e10cSrcweir
Notify(const Sequence<rtl::OUString> &)105cdf0e10cSrcweir void SvtExecAppletsItem_Impl::Notify( const Sequence< rtl::OUString >& )
106cdf0e10cSrcweir {
107cdf0e10cSrcweir // no listeners supported yet
108cdf0e10cSrcweir }
109cdf0e10cSrcweir
110cdf0e10cSrcweir struct SvtJavaOptions_Impl
111cdf0e10cSrcweir {
112cdf0e10cSrcweir SvtExecAppletsItem_Impl aExecItem;
113cdf0e10cSrcweir Sequence<OUString> aPropertyNames;
114cdf0e10cSrcweir sal_Bool bEnabled;
115cdf0e10cSrcweir sal_Bool bSecurity;
116cdf0e10cSrcweir sal_Int32 nNetAccess;
117cdf0e10cSrcweir rtl::OUString sUserClassPath;
118cdf0e10cSrcweir
119cdf0e10cSrcweir sal_Bool bROEnabled;
120cdf0e10cSrcweir sal_Bool bROSecurity;
121cdf0e10cSrcweir sal_Bool bRONetAccess;
122cdf0e10cSrcweir sal_Bool bROUserClassPath;
123cdf0e10cSrcweir
SvtJavaOptions_ImplSvtJavaOptions_Impl124cdf0e10cSrcweir SvtJavaOptions_Impl() :
125cdf0e10cSrcweir aPropertyNames(4),
126cdf0e10cSrcweir bEnabled (sal_False),
127cdf0e10cSrcweir bSecurity (sal_False),
128cdf0e10cSrcweir nNetAccess (0),
129cdf0e10cSrcweir bROEnabled (CFG_READONLY_DEFAULT),
130cdf0e10cSrcweir bROSecurity (CFG_READONLY_DEFAULT),
131cdf0e10cSrcweir bRONetAccess (CFG_READONLY_DEFAULT),
132cdf0e10cSrcweir bROUserClassPath (CFG_READONLY_DEFAULT)
133cdf0e10cSrcweir {
134cdf0e10cSrcweir OUString* pNames = aPropertyNames.getArray();
135cdf0e10cSrcweir pNames[0] = C2U("Enable");
136cdf0e10cSrcweir pNames[1] = C2U("Security");
137cdf0e10cSrcweir pNames[2] = C2U("NetAccess");
138cdf0e10cSrcweir pNames[3] = C2U("UserClassPath");
139cdf0e10cSrcweir }
140cdf0e10cSrcweir };
141cdf0e10cSrcweir /* -----------------------------18.05.01 13:28--------------------------------
142cdf0e10cSrcweir
143cdf0e10cSrcweir ---------------------------------------------------------------------------*/
SvtJavaOptions()144cdf0e10cSrcweir SvtJavaOptions::SvtJavaOptions() :
145cdf0e10cSrcweir utl::ConfigItem(C2U("Office.Java/VirtualMachine")),
146cdf0e10cSrcweir pImpl(new SvtJavaOptions_Impl)
147cdf0e10cSrcweir {
148cdf0e10cSrcweir RTL_LOGFILE_CONTEXT(aLog, "unotools SvtJavaOptions::SvtJavaOptions()");
149cdf0e10cSrcweir
150cdf0e10cSrcweir Sequence< Any > aValues = GetProperties(pImpl->aPropertyNames);
151cdf0e10cSrcweir Sequence< sal_Bool > aROStates = GetReadOnlyStates(pImpl->aPropertyNames);
152cdf0e10cSrcweir const Any* pValues = aValues.getConstArray();
153cdf0e10cSrcweir const sal_Bool* pROStates = aROStates.getConstArray();
154cdf0e10cSrcweir if ( aValues.getLength() == pImpl->aPropertyNames.getLength() && aROStates.getLength() == pImpl->aPropertyNames.getLength() )
155cdf0e10cSrcweir {
156cdf0e10cSrcweir for ( int nProp = 0; nProp < pImpl->aPropertyNames.getLength(); nProp++ )
157cdf0e10cSrcweir {
158cdf0e10cSrcweir if( pValues[nProp].hasValue() )
159cdf0e10cSrcweir {
160cdf0e10cSrcweir switch ( nProp )
161cdf0e10cSrcweir {
162cdf0e10cSrcweir case 0: pImpl->bEnabled = *(sal_Bool*)pValues[nProp].getValue(); break;
163cdf0e10cSrcweir case 1: pImpl->bSecurity = *(sal_Bool*)pValues[nProp].getValue();break;
164cdf0e10cSrcweir case 2: pValues[nProp] >>= pImpl->nNetAccess; break;
165cdf0e10cSrcweir case 3: pValues[nProp] >>= pImpl->sUserClassPath; break;
166cdf0e10cSrcweir }
167cdf0e10cSrcweir }
168cdf0e10cSrcweir }
169cdf0e10cSrcweir pImpl->bROEnabled = pROStates[0];
170cdf0e10cSrcweir pImpl->bROSecurity = pROStates[1];
171cdf0e10cSrcweir pImpl->bRONetAccess = pROStates[2];
172cdf0e10cSrcweir pImpl->bROUserClassPath = pROStates[3];
173cdf0e10cSrcweir }
174cdf0e10cSrcweir }
175cdf0e10cSrcweir /* -----------------------------18.05.01 13:28--------------------------------
176cdf0e10cSrcweir
177cdf0e10cSrcweir ---------------------------------------------------------------------------*/
~SvtJavaOptions()178cdf0e10cSrcweir SvtJavaOptions::~SvtJavaOptions()
179cdf0e10cSrcweir {
180cdf0e10cSrcweir delete pImpl;
181cdf0e10cSrcweir }
182cdf0e10cSrcweir /*-- 18.05.01 13:28:35---------------------------------------------------
183cdf0e10cSrcweir
184cdf0e10cSrcweir -----------------------------------------------------------------------*/
Commit()185cdf0e10cSrcweir void SvtJavaOptions::Commit()
186cdf0e10cSrcweir {
187cdf0e10cSrcweir pImpl->aExecItem.Commit();
188cdf0e10cSrcweir
189cdf0e10cSrcweir sal_Int32 nOrgCount = pImpl->aPropertyNames.getLength();
190cdf0e10cSrcweir Sequence< OUString > aNames(nOrgCount);
191cdf0e10cSrcweir Sequence< Any > aValues(nOrgCount);
192cdf0e10cSrcweir sal_Int32 nRealCount = 0;
193cdf0e10cSrcweir
194cdf0e10cSrcweir const Type& rType = ::getBooleanCppuType();
195cdf0e10cSrcweir for(int nProp = 0; nProp < nOrgCount; nProp++)
196cdf0e10cSrcweir {
197cdf0e10cSrcweir switch(nProp)
198cdf0e10cSrcweir {
199cdf0e10cSrcweir case 0:
200cdf0e10cSrcweir {
201cdf0e10cSrcweir if (!pImpl->bROEnabled)
202cdf0e10cSrcweir {
203cdf0e10cSrcweir aValues[nRealCount].setValue(&pImpl->bEnabled, rType);
204cdf0e10cSrcweir aNames[nRealCount] = pImpl->aPropertyNames[nProp];
205cdf0e10cSrcweir ++nRealCount;
206cdf0e10cSrcweir }
207cdf0e10cSrcweir }
208cdf0e10cSrcweir break;
209cdf0e10cSrcweir case 1:
210cdf0e10cSrcweir {
211cdf0e10cSrcweir if (!pImpl->bROSecurity)
212cdf0e10cSrcweir {
213cdf0e10cSrcweir aValues[nRealCount].setValue(&pImpl->bSecurity, rType);
214cdf0e10cSrcweir aNames[nRealCount] = pImpl->aPropertyNames[nProp];
215cdf0e10cSrcweir ++nRealCount;
216cdf0e10cSrcweir }
217cdf0e10cSrcweir }
218cdf0e10cSrcweir break;
219cdf0e10cSrcweir case 2:
220cdf0e10cSrcweir {
221cdf0e10cSrcweir if (!pImpl->bRONetAccess)
222cdf0e10cSrcweir {
223cdf0e10cSrcweir aValues[nRealCount] <<= pImpl->nNetAccess;
224cdf0e10cSrcweir aNames[nRealCount] = pImpl->aPropertyNames[nProp];
225cdf0e10cSrcweir ++nRealCount;
226cdf0e10cSrcweir }
227cdf0e10cSrcweir }
228cdf0e10cSrcweir break;
229cdf0e10cSrcweir case 3:
230cdf0e10cSrcweir {
231cdf0e10cSrcweir if (!pImpl->bROUserClassPath)
232cdf0e10cSrcweir {
233cdf0e10cSrcweir aValues[nRealCount] <<= pImpl->sUserClassPath;
234cdf0e10cSrcweir aNames[nRealCount] = pImpl->aPropertyNames[nProp];
235cdf0e10cSrcweir ++nRealCount;
236cdf0e10cSrcweir }
237cdf0e10cSrcweir }
238cdf0e10cSrcweir break;
239cdf0e10cSrcweir }
240cdf0e10cSrcweir }
241cdf0e10cSrcweir aValues.realloc(nRealCount);
242cdf0e10cSrcweir aNames.realloc(nRealCount);
243cdf0e10cSrcweir PutProperties(aNames,aValues);
244cdf0e10cSrcweir }
245cdf0e10cSrcweir /*-- 18.05.01 13:28:35---------------------------------------------------
246cdf0e10cSrcweir
247cdf0e10cSrcweir -----------------------------------------------------------------------*/
IsEnabled() const248cdf0e10cSrcweir sal_Bool SvtJavaOptions::IsEnabled() const
249cdf0e10cSrcweir {
250cdf0e10cSrcweir return pImpl->bEnabled;
251cdf0e10cSrcweir }
252cdf0e10cSrcweir /*-- 18.05.01 13:28:35---------------------------------------------------
253cdf0e10cSrcweir
254cdf0e10cSrcweir -----------------------------------------------------------------------*/
IsSecurity() const255cdf0e10cSrcweir sal_Bool SvtJavaOptions::IsSecurity()const
256cdf0e10cSrcweir {
257cdf0e10cSrcweir return pImpl->bSecurity;
258cdf0e10cSrcweir }
259cdf0e10cSrcweir /*-- 18.05.01 13:28:35---------------------------------------------------
260cdf0e10cSrcweir
261cdf0e10cSrcweir -----------------------------------------------------------------------*/
GetNetAccess() const262cdf0e10cSrcweir sal_Int32 SvtJavaOptions::GetNetAccess() const
263cdf0e10cSrcweir {
264cdf0e10cSrcweir return pImpl->nNetAccess;
265cdf0e10cSrcweir }
266cdf0e10cSrcweir /*-- 18.05.01 13:28:36---------------------------------------------------
267cdf0e10cSrcweir
268cdf0e10cSrcweir -----------------------------------------------------------------------*/
GetUserClassPath() const269cdf0e10cSrcweir rtl::OUString& SvtJavaOptions::GetUserClassPath()const
270cdf0e10cSrcweir {
271cdf0e10cSrcweir return pImpl->sUserClassPath;
272cdf0e10cSrcweir }
273cdf0e10cSrcweir /*-- 18.05.01 13:28:37---------------------------------------------------
274cdf0e10cSrcweir
275cdf0e10cSrcweir -----------------------------------------------------------------------*/
SetEnabled(sal_Bool bSet)276cdf0e10cSrcweir void SvtJavaOptions::SetEnabled(sal_Bool bSet)
277cdf0e10cSrcweir {
278cdf0e10cSrcweir OSL_ENSURE(!pImpl->bROEnabled, "SvtJavaOptions::SetEnabled()\nYou tried to write on a readonly value!\n");
279cdf0e10cSrcweir if(!pImpl->bROEnabled && pImpl->bEnabled != bSet)
280cdf0e10cSrcweir {
281cdf0e10cSrcweir pImpl->bEnabled = bSet;
282cdf0e10cSrcweir SetModified();
283cdf0e10cSrcweir }
284cdf0e10cSrcweir }
285cdf0e10cSrcweir /*-- 18.05.01 13:28:38---------------------------------------------------
286cdf0e10cSrcweir
287cdf0e10cSrcweir -----------------------------------------------------------------------*/
SetSecurity(sal_Bool bSet)288cdf0e10cSrcweir void SvtJavaOptions::SetSecurity(sal_Bool bSet)
289cdf0e10cSrcweir {
290cdf0e10cSrcweir OSL_ENSURE(!pImpl->bROSecurity, "SvtJavaOptions::SetSecurity()\nYou tried to write on a readonly value!\n");
291cdf0e10cSrcweir if(!pImpl->bROSecurity && pImpl->bSecurity != bSet)
292cdf0e10cSrcweir {
293cdf0e10cSrcweir pImpl->bSecurity = bSet;
294cdf0e10cSrcweir SetModified();
295cdf0e10cSrcweir }
296cdf0e10cSrcweir }
297cdf0e10cSrcweir /*-- 18.05.01 13:28:38---------------------------------------------------
298cdf0e10cSrcweir
299cdf0e10cSrcweir -----------------------------------------------------------------------*/
SetNetAccess(sal_Int32 nSet)300cdf0e10cSrcweir void SvtJavaOptions::SetNetAccess(sal_Int32 nSet)
301cdf0e10cSrcweir {
302cdf0e10cSrcweir OSL_ENSURE(!pImpl->bRONetAccess, "SvtJavaOptions::SetNetAccess()\nYou tried to write on a readonly value!\n");
303cdf0e10cSrcweir if(!pImpl->bRONetAccess && pImpl->nNetAccess != nSet)
304cdf0e10cSrcweir {
305cdf0e10cSrcweir pImpl->nNetAccess = nSet;
306cdf0e10cSrcweir SetModified();
307cdf0e10cSrcweir }
308cdf0e10cSrcweir }
309cdf0e10cSrcweir /*-- 18.05.01 13:28:38---------------------------------------------------
310cdf0e10cSrcweir
311cdf0e10cSrcweir -----------------------------------------------------------------------*/
SetUserClassPath(const rtl::OUString & rSet)312cdf0e10cSrcweir void SvtJavaOptions::SetUserClassPath(const rtl::OUString& rSet)
313cdf0e10cSrcweir {
314cdf0e10cSrcweir OSL_ENSURE(!pImpl->bROUserClassPath, "SvtJavaOptions::SetUserClassPath()\nYou tried to write on a readonly value!\n");
315cdf0e10cSrcweir if(!pImpl->bROUserClassPath && pImpl->sUserClassPath != rSet)
316cdf0e10cSrcweir {
317cdf0e10cSrcweir pImpl->sUserClassPath = rSet;
318cdf0e10cSrcweir SetModified();
319cdf0e10cSrcweir }
320cdf0e10cSrcweir }
321cdf0e10cSrcweir
322cdf0e10cSrcweir /*-- 18.05.01 14:34:32---------------------------------------------------
323cdf0e10cSrcweir
324cdf0e10cSrcweir -----------------------------------------------------------------------*/
IsExecuteApplets() const325cdf0e10cSrcweir sal_Bool SvtJavaOptions::IsExecuteApplets() const
326cdf0e10cSrcweir {
327cdf0e10cSrcweir return pImpl->aExecItem.IsExecuteApplets();
328cdf0e10cSrcweir }
329cdf0e10cSrcweir /*-- 18.05.01 14:34:32---------------------------------------------------
330cdf0e10cSrcweir
331cdf0e10cSrcweir -----------------------------------------------------------------------*/
SetExecuteApplets(sal_Bool bSet)332cdf0e10cSrcweir void SvtJavaOptions::SetExecuteApplets(sal_Bool bSet)
333cdf0e10cSrcweir {
334cdf0e10cSrcweir if(!pImpl->aExecItem.IsReadOnly() && pImpl->aExecItem.IsExecuteApplets() != bSet)
335cdf0e10cSrcweir {
336cdf0e10cSrcweir pImpl->aExecItem.SetExecuteApplets(bSet);
337cdf0e10cSrcweir SetModified();
338cdf0e10cSrcweir }
339cdf0e10cSrcweir }
340cdf0e10cSrcweir /*--10.02.2003 08:40---------------------------------------------------
341cdf0e10cSrcweir
342cdf0e10cSrcweir -----------------------------------------------------------------------*/
IsReadOnly(EOption eOption) const343cdf0e10cSrcweir sal_Bool SvtJavaOptions::IsReadOnly( EOption eOption ) const
344cdf0e10cSrcweir {
345cdf0e10cSrcweir sal_Bool bRO = sal_True;
346cdf0e10cSrcweir switch(eOption)
347cdf0e10cSrcweir {
348cdf0e10cSrcweir case E_ENABLED :
349cdf0e10cSrcweir bRO = pImpl->bROEnabled;
350cdf0e10cSrcweir break;
351cdf0e10cSrcweir case E_SECURITY :
352cdf0e10cSrcweir bRO = pImpl->bROSecurity;
353cdf0e10cSrcweir break;
354cdf0e10cSrcweir case E_NETACCESS :
355cdf0e10cSrcweir bRO = pImpl->bRONetAccess;
356cdf0e10cSrcweir break;
357cdf0e10cSrcweir case E_USERCLASSPATH :
358cdf0e10cSrcweir bRO = pImpl->bROUserClassPath;
359cdf0e10cSrcweir break;
360cdf0e10cSrcweir case E_EXECUTEAPPLETS :
361cdf0e10cSrcweir bRO = pImpl->aExecItem.IsReadOnly();
362cdf0e10cSrcweir break;
363cdf0e10cSrcweir }
364cdf0e10cSrcweir return bRO;
365cdf0e10cSrcweir }
366