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