Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "elements.hxx"
21 : #include "osl/mutex.hxx"
22 : #include "osl/file.hxx"
23 : #include "fwkutil.hxx"
24 : #include "fwkbase.hxx"
25 : #include "framework.hxx"
26 : #include "libxmlutil.hxx"
27 : #include "osl/thread.hxx"
28 : #include <algorithm>
29 : #include "libxml/parser.h"
30 : #include "libxml/xpath.h"
31 : #include "libxml/xpathInternals.h"
32 : #include "rtl/bootstrap.hxx"
33 : #include "boost/optional.hpp"
34 : #include <string.h>
35 :
36 : // For backwards compatibility, the nFeatures and nRequirements flag words are
37 : // read/written as potentially signed hexadecimal numbers (though that has no
38 : // practical relevance given that each has only one flag with value 0x01
39 : // defined).
40 :
41 : using namespace osl;
42 : namespace jfw
43 : {
44 :
45 1 : OString getElement(OString const & docPath,
46 : xmlChar const * pathExpression, bool bThrowIfEmpty)
47 : {
48 : //Prepare the xml document and context
49 : OSL_ASSERT(!docPath.isEmpty());
50 1 : jfw::CXmlDocPtr doc(xmlParseFile(docPath.getStr()));
51 1 : if (doc == NULL)
52 : throw FrameworkException(
53 : JFW_E_ERROR,
54 : OString("[Java framework] Error in function getElement "
55 0 : "(elements.cxx)"));
56 :
57 2 : jfw::CXPathContextPtr context(xmlXPathNewContext(doc));
58 1 : if (xmlXPathRegisterNs(context, reinterpret_cast<xmlChar const *>("jf"),
59 1 : reinterpret_cast<xmlChar const *>(NS_JAVA_FRAMEWORK)) == -1)
60 : throw FrameworkException(
61 : JFW_E_ERROR,
62 : OString("[Java framework] Error in function getElement "
63 0 : "(elements.cxx)"));
64 :
65 2 : CXPathObjectPtr pathObj;
66 1 : pathObj = xmlXPathEvalExpression(pathExpression, context);
67 1 : OString sValue;
68 1 : if (xmlXPathNodeSetIsEmpty(pathObj->nodesetval))
69 : {
70 0 : if (bThrowIfEmpty)
71 : throw FrameworkException(
72 : JFW_E_ERROR,
73 : OString("[Java framework] Error in function getElement "
74 0 : "(elements.cxx)"));
75 : }
76 : else
77 : {
78 1 : sValue = reinterpret_cast<sal_Char*>(pathObj->nodesetval->nodeTab[0]->content);
79 : }
80 2 : return sValue;
81 : }
82 :
83 1 : OString getElementUpdated()
84 : {
85 : return getElement(jfw::getVendorSettingsPath(),
86 1 : reinterpret_cast<xmlChar const *>("/jf:javaSelection/jf:updated/text()"), true);
87 : }
88 :
89 10 : void createSettingsStructure(xmlDoc * document, bool * bNeedsSave)
90 : {
91 : OString sExcMsg("[Java framework] Error in function createSettingsStructure "
92 10 : "(elements.cxx).");
93 10 : xmlNode * root = xmlDocGetRootElement(document);
94 10 : if (root == NULL)
95 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
96 10 : bool bFound = false;
97 10 : xmlNode * cur = root->children;
98 30 : while (cur != NULL)
99 : {
100 19 : if (xmlStrcmp(cur->name, reinterpret_cast<xmlChar const *>("enabled")) == 0)
101 : {
102 9 : bFound = true;
103 9 : break;
104 : }
105 10 : cur = cur->next;
106 : }
107 10 : if (bFound)
108 : {
109 9 : *bNeedsSave = false;
110 19 : return;
111 : }
112 : //We will modify this document
113 1 : *bNeedsSave = true;
114 : // Now we create the child elements ------------------
115 : //Get xsi:nil namespace
116 : xmlNs* nsXsi = xmlSearchNsByHref(
117 1 : document, root, reinterpret_cast<xmlChar const *>(NS_SCHEMA_INSTANCE));
118 :
119 : //<enabled xsi:nil="true"
120 : xmlNode * nodeEn = xmlNewTextChild(
121 1 : root, NULL, reinterpret_cast<xmlChar const *>("enabled"), reinterpret_cast<xmlChar const *>(""));
122 1 : if (nodeEn == NULL)
123 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
124 1 : xmlSetNsProp(nodeEn, nsXsi, reinterpret_cast<xmlChar const *>("nil"), reinterpret_cast<xmlChar const *>("true"));
125 : //add a new line
126 1 : xmlNode * nodeCrLf = xmlNewText(reinterpret_cast<xmlChar const *>("\n"));
127 1 : xmlAddChild(root, nodeCrLf);
128 :
129 : //<userClassPath xsi:nil="true">
130 : xmlNode * nodeUs = xmlNewTextChild(
131 1 : root, NULL, reinterpret_cast<xmlChar const *>("userClassPath"), reinterpret_cast<xmlChar const *>(""));
132 1 : if (nodeUs == NULL)
133 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
134 1 : xmlSetNsProp(nodeUs, nsXsi, reinterpret_cast<xmlChar const *>("nil"), reinterpret_cast<xmlChar const *>("true"));
135 : //add a new line
136 1 : nodeCrLf = xmlNewText(reinterpret_cast<xmlChar const *>("\n"));
137 1 : xmlAddChild(root, nodeCrLf);
138 :
139 : //<vmParameters xsi:nil="true">
140 : xmlNode * nodeVm = xmlNewTextChild(
141 1 : root, NULL, reinterpret_cast<xmlChar const *>("vmParameters"), reinterpret_cast<xmlChar const *>(""));
142 1 : if (nodeVm == NULL)
143 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
144 1 : xmlSetNsProp(nodeVm, nsXsi, reinterpret_cast<xmlChar const *>("nil"), reinterpret_cast<xmlChar const *>("true"));
145 : //add a new line
146 1 : nodeCrLf = xmlNewText(reinterpret_cast<xmlChar const *>("\n"));
147 1 : xmlAddChild(root, nodeCrLf);
148 :
149 : //<jreLocations xsi:nil="true">
150 : xmlNode * nodeJre = xmlNewTextChild(
151 1 : root, NULL, reinterpret_cast<xmlChar const *>("jreLocations"), reinterpret_cast<xmlChar const *>(""));
152 1 : if (nodeJre == NULL)
153 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
154 1 : xmlSetNsProp(nodeJre, nsXsi, reinterpret_cast<xmlChar const *>("nil"), reinterpret_cast<xmlChar const *>("true"));
155 : //add a new line
156 1 : nodeCrLf = xmlNewText(reinterpret_cast<xmlChar const *>("\n"));
157 1 : xmlAddChild(root, nodeCrLf);
158 :
159 : //<javaInfo xsi:nil="true">
160 : xmlNode * nodeJava = xmlNewTextChild(
161 1 : root, NULL, reinterpret_cast<xmlChar const *>("javaInfo"), reinterpret_cast<xmlChar const *>(""));
162 1 : if (nodeJava == NULL)
163 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
164 1 : xmlSetNsProp(nodeJava, nsXsi, reinterpret_cast<xmlChar const *>("nil"), reinterpret_cast<xmlChar const *>("true"));
165 : //add a new line
166 1 : nodeCrLf = xmlNewText(reinterpret_cast<xmlChar const *>("\n"));
167 1 : xmlAddChild(root, nodeCrLf);
168 : }
169 :
170 :
171 :
172 174 : VersionInfo::VersionInfo(): arVersions(NULL)
173 : {
174 174 : }
175 :
176 532 : VersionInfo::~VersionInfo()
177 : {
178 266 : delete [] arVersions;
179 266 : }
180 :
181 0 : void VersionInfo::addExcludeVersion(const OUString& sVersion)
182 : {
183 0 : vecExcludeVersions.push_back(sVersion);
184 0 : }
185 :
186 150 : rtl_uString** VersionInfo::getExcludeVersions()
187 : {
188 150 : osl::MutexGuard guard(FwkMutex::get());
189 150 : if (arVersions != NULL)
190 0 : return arVersions;
191 :
192 150 : arVersions = new rtl_uString*[vecExcludeVersions.size()];
193 150 : int j=0;
194 : typedef std::vector<OUString>::const_iterator it;
195 150 : for (it i = vecExcludeVersions.begin(); i != vecExcludeVersions.end();
196 : ++i, ++j)
197 : {
198 0 : arVersions[j] = vecExcludeVersions[j].pData;
199 : }
200 150 : return arVersions;
201 : }
202 :
203 150 : sal_Int32 VersionInfo::getExcludeVersionSize()
204 : {
205 150 : return vecExcludeVersions.size();
206 : }
207 :
208 :
209 60 : NodeJava::NodeJava(Layer layer):
210 60 : m_layer(layer)
211 : {
212 : //This class reads and write to files which should only be done in
213 : //application mode
214 60 : if (getMode() == JFW_MODE_DIRECT)
215 : throw FrameworkException(
216 : JFW_E_DIRECT_MODE,
217 0 : "[Java framework] Trying to access settings files in direct mode.");
218 60 : }
219 :
220 :
221 56 : void NodeJava::load()
222 : {
223 : const OString sExcMsg("[Java framework] Error in function NodeJava::load"
224 56 : "(elements.cxx).");
225 56 : if (SHARED == m_layer)
226 : {
227 : //we do not support yet to write into the shared installation
228 :
229 : //check if shared settings exist at all.
230 28 : OUString sURL(BootParams::getSharedData());
231 28 : jfw::FileStatus s = sURL.isEmpty()
232 28 : ? FILE_DOES_NOT_EXIST : checkFileURL(sURL);
233 28 : if (s == FILE_INVALID)
234 : throw FrameworkException(
235 : JFW_E_ERROR,
236 0 : "[Java framework] Invalid file for shared Java settings.");
237 28 : else if (s == FILE_DOES_NOT_EXIST)
238 : //Writing shared data is not supported yet.
239 28 : return;
240 : }
241 28 : else if (USER == m_layer)
242 : {
243 28 : if (!prepareSettingsDocument())
244 : {
245 : SAL_INFO("jfw.level1", "no path to load user settings document from");
246 19 : return;
247 : }
248 : }
249 : else
250 : {
251 : OSL_FAIL("[Java framework] Unknown enum used.");
252 : }
253 :
254 :
255 : //Read the user elements
256 18 : OString sSettingsPath = getSettingsPath();
257 : //There must not be a share settings file
258 18 : CXmlDocPtr docUser(xmlParseFile(sSettingsPath.getStr()));
259 9 : if (docUser == NULL)
260 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
261 :
262 9 : xmlNode * cur = xmlDocGetRootElement(docUser);
263 9 : if (cur == NULL || cur->children == NULL)
264 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
265 :
266 18 : CXmlCharPtr sNil;
267 9 : cur = cur->children;
268 117 : while (cur != NULL)
269 : {
270 99 : if (xmlStrcmp(cur->name, reinterpret_cast<xmlChar const *>("enabled")) == 0)
271 : {
272 : //only overwrite share settings if xsi:nil="false"
273 9 : sNil = xmlGetNsProp(
274 9 : cur, reinterpret_cast<xmlChar const *>("nil"), reinterpret_cast<xmlChar const *>(NS_SCHEMA_INSTANCE));
275 9 : if (sNil == NULL)
276 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);;
277 9 : if (xmlStrcmp(sNil, reinterpret_cast<xmlChar const *>("false")) == 0)
278 : {
279 : CXmlCharPtr sEnabled( xmlNodeListGetString(
280 0 : docUser, cur->children, 1));
281 0 : if (xmlStrcmp(sEnabled, reinterpret_cast<xmlChar const *>("true")) == 0)
282 0 : m_enabled = boost::optional<sal_Bool>(sal_True);
283 0 : else if (xmlStrcmp(sEnabled, reinterpret_cast<xmlChar const *>("false")) == 0)
284 0 : m_enabled = boost::optional<sal_Bool>(sal_False);
285 : }
286 : }
287 90 : else if (xmlStrcmp(cur->name, reinterpret_cast<xmlChar const *>("userClassPath")) == 0)
288 : {
289 9 : sNil = xmlGetNsProp(
290 9 : cur, reinterpret_cast<xmlChar const *>("nil"), reinterpret_cast<xmlChar const *>(NS_SCHEMA_INSTANCE));
291 9 : if (sNil == NULL)
292 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
293 9 : if (xmlStrcmp(sNil, reinterpret_cast<xmlChar const *>("false")) == 0)
294 : {
295 : CXmlCharPtr sUser(xmlNodeListGetString(
296 0 : docUser, cur->children, 1));
297 0 : m_userClassPath = boost::optional<OUString>(OUString(sUser));
298 : }
299 : }
300 81 : else if (xmlStrcmp(cur->name, reinterpret_cast<xmlChar const *>("javaInfo")) == 0)
301 : {
302 9 : sNil = xmlGetNsProp(
303 9 : cur, reinterpret_cast<xmlChar const *>("nil"), reinterpret_cast<xmlChar const *>(NS_SCHEMA_INSTANCE));
304 9 : if (sNil == NULL)
305 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
306 :
307 9 : if (xmlStrcmp(sNil, reinterpret_cast<xmlChar const *>("false")) == 0)
308 : {
309 1 : if (! m_javaInfo)
310 1 : m_javaInfo = boost::optional<CNodeJavaInfo>(CNodeJavaInfo());
311 1 : m_javaInfo->loadFromNode(docUser, cur);
312 : }
313 : }
314 72 : else if (xmlStrcmp(cur->name, reinterpret_cast<xmlChar const *>("vmParameters")) == 0)
315 : {
316 9 : sNil = xmlGetNsProp(
317 9 : cur, reinterpret_cast<xmlChar const *>("nil"), reinterpret_cast<xmlChar const *>(NS_SCHEMA_INSTANCE));
318 9 : if (sNil == NULL)
319 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
320 9 : if (xmlStrcmp(sNil, reinterpret_cast<xmlChar const *>("false")) == 0)
321 : {
322 0 : if ( ! m_vmParameters)
323 0 : m_vmParameters = boost::optional<std::vector<OUString> >(
324 0 : std::vector<OUString> ());
325 :
326 0 : xmlNode * pOpt = cur->children;
327 0 : while (pOpt != NULL)
328 : {
329 0 : if (xmlStrcmp(pOpt->name, reinterpret_cast<xmlChar const *>("param")) == 0)
330 : {
331 0 : CXmlCharPtr sOpt;
332 0 : sOpt = xmlNodeListGetString(
333 0 : docUser, pOpt->children, 1);
334 0 : m_vmParameters->push_back(sOpt);
335 : }
336 0 : pOpt = pOpt->next;
337 : }
338 : }
339 : }
340 63 : else if (xmlStrcmp(cur->name, reinterpret_cast<xmlChar const *>("jreLocations")) == 0)
341 : {
342 9 : sNil = xmlGetNsProp(
343 9 : cur, reinterpret_cast<xmlChar const *>("nil"), reinterpret_cast<xmlChar const *>(NS_SCHEMA_INSTANCE));
344 9 : if (sNil == NULL)
345 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
346 9 : if (xmlStrcmp(sNil, reinterpret_cast<xmlChar const *>("false")) == 0)
347 : {
348 0 : if (! m_JRELocations)
349 0 : m_JRELocations = boost::optional<std::vector<OUString> >(
350 0 : std::vector<OUString>());
351 :
352 0 : xmlNode * pLoc = cur->children;
353 0 : while (pLoc != NULL)
354 : {
355 0 : if (xmlStrcmp(pLoc->name, reinterpret_cast<xmlChar const *>("location")) == 0)
356 : {
357 0 : CXmlCharPtr sLoc;
358 0 : sLoc = xmlNodeListGetString(
359 0 : docUser, pLoc->children, 1);
360 0 : m_JRELocations->push_back(sLoc);
361 : }
362 0 : pLoc = pLoc->next;
363 : }
364 : }
365 : }
366 99 : cur = cur->next;
367 9 : }
368 : }
369 :
370 21 : OString NodeJava::getSettingsPath() const
371 : {
372 21 : OString ret;
373 21 : switch (m_layer)
374 : {
375 21 : case USER: ret = getUserSettingsPath(); break;
376 0 : case SHARED: ret = getSharedSettingsPath(); break;
377 : default:
378 : OSL_FAIL("[Java framework] NodeJava::getSettingsPath()");
379 : }
380 21 : return ret;
381 : }
382 :
383 32 : OUString NodeJava::getSettingsURL() const
384 : {
385 32 : OUString ret;
386 32 : switch (m_layer)
387 : {
388 32 : case USER: ret = BootParams::getUserData(); break;
389 0 : case SHARED: ret = BootParams::getSharedData(); break;
390 : default:
391 : OSL_FAIL("[Java framework] NodeJava::getSettingsURL()");
392 : }
393 32 : return ret;
394 : }
395 :
396 32 : bool NodeJava::prepareSettingsDocument() const
397 : {
398 : OString sExcMsg(
399 : "[Java framework] Error in function prepareSettingsDocument"
400 32 : " (elements.cxx).");
401 32 : if (!createSettingsDocument())
402 : {
403 22 : return false;
404 : }
405 20 : OString sSettings = getSettingsPath();
406 20 : CXmlDocPtr doc(xmlParseFile(sSettings.getStr()));
407 10 : if (!doc)
408 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
409 :
410 10 : bool bNeedsSave = false;
411 10 : createSettingsStructure(doc, & bNeedsSave);
412 10 : if (bNeedsSave)
413 : {
414 1 : if (xmlSaveFormatFileEnc(
415 1 : sSettings.getStr(), doc,"UTF-8", 1) == -1)
416 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
417 : }
418 42 : return true;
419 : }
420 :
421 4 : void NodeJava::write() const
422 : {
423 : OString sExcMsg("[Java framework] Error in function NodeJava::writeSettings "
424 4 : "(elements.cxx).");
425 5 : CXmlDocPtr docUser;
426 5 : CXPathContextPtr contextUser;
427 5 : CXPathObjectPtr pathObj;
428 :
429 4 : if (!prepareSettingsDocument())
430 : {
431 : SAL_INFO("jfw.level1", "no path to write settings document to");
432 7 : return;
433 : }
434 :
435 : //Read the user elements
436 2 : OString sSettingsPath = getSettingsPath();
437 1 : docUser = xmlParseFile(sSettingsPath.getStr());
438 1 : if (docUser == NULL)
439 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
440 1 : contextUser = xmlXPathNewContext(docUser);
441 1 : if (xmlXPathRegisterNs(contextUser, reinterpret_cast<xmlChar const *>("jf"),
442 1 : reinterpret_cast<xmlChar const *>(NS_JAVA_FRAMEWORK)) == -1)
443 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
444 :
445 1 : xmlNode * root = xmlDocGetRootElement(docUser);
446 : //Get xsi:nil namespace
447 : xmlNs* nsXsi = xmlSearchNsByHref(docUser,
448 : root,
449 1 : reinterpret_cast<xmlChar const *>(NS_SCHEMA_INSTANCE));
450 :
451 : //set the <enabled> element
452 : //The element must exist
453 1 : if (m_enabled)
454 : {
455 : OString sExpression= OString(
456 0 : "/jf:java/jf:enabled");
457 0 : pathObj = xmlXPathEvalExpression(reinterpret_cast<xmlChar const *>(sExpression.getStr()),
458 0 : contextUser);
459 0 : if ( ! pathObj || xmlXPathNodeSetIsEmpty(pathObj->nodesetval))
460 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
461 :
462 0 : xmlNode * nodeEnabled = pathObj->nodesetval->nodeTab[0];
463 : xmlSetNsProp(nodeEnabled,
464 : nsXsi,
465 : reinterpret_cast<xmlChar const *>("nil"),
466 0 : reinterpret_cast<xmlChar const *>("false"));
467 :
468 0 : if (m_enabled == boost::optional<sal_Bool>(sal_True))
469 0 : xmlNodeSetContent(nodeEnabled,reinterpret_cast<xmlChar const *>("true"));
470 : else
471 0 : xmlNodeSetContent(nodeEnabled,reinterpret_cast<xmlChar const *>("false"));
472 : }
473 :
474 : //set the <userClassPath> element
475 : //The element must exist
476 1 : if (m_userClassPath)
477 : {
478 : OString sExpression= OString(
479 0 : "/jf:java/jf:userClassPath");
480 0 : pathObj = xmlXPathEvalExpression(reinterpret_cast<xmlChar const *>(sExpression.getStr()),
481 0 : contextUser);
482 0 : if ( ! pathObj || xmlXPathNodeSetIsEmpty(pathObj->nodesetval))
483 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
484 :
485 0 : xmlNode * nodeEnabled = pathObj->nodesetval->nodeTab[0];
486 0 : xmlSetNsProp(nodeEnabled, nsXsi, reinterpret_cast<xmlChar const *>("nil"),reinterpret_cast<xmlChar const *>("false"));
487 0 : xmlNodeSetContent(nodeEnabled,static_cast<xmlChar*>(CXmlCharPtr(*m_userClassPath)));
488 : }
489 :
490 : //set <javaInfo> element
491 1 : if (m_javaInfo)
492 : {
493 : OString sExpression= OString(
494 1 : "/jf:java/jf:javaInfo");
495 1 : pathObj = xmlXPathEvalExpression(reinterpret_cast<xmlChar const *>(sExpression.getStr()),
496 1 : contextUser);
497 1 : if ( ! pathObj || xmlXPathNodeSetIsEmpty(pathObj->nodesetval))
498 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
499 : m_javaInfo->writeToNode(
500 1 : docUser, pathObj->nodesetval->nodeTab[0]);
501 : }
502 :
503 : //set <vmParameters> element
504 1 : if (m_vmParameters)
505 : {
506 : OString sExpression= OString(
507 0 : "/jf:java/jf:vmParameters");
508 0 : pathObj = xmlXPathEvalExpression(reinterpret_cast<xmlChar const *>(sExpression.getStr()),
509 0 : contextUser);
510 0 : if ( ! pathObj || xmlXPathNodeSetIsEmpty(pathObj->nodesetval))
511 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
512 0 : xmlNode* vmParameters = pathObj->nodesetval->nodeTab[0];
513 : //set xsi:nil = false;
514 : xmlSetNsProp(vmParameters, nsXsi,reinterpret_cast<xmlChar const *>("nil"),
515 0 : reinterpret_cast<xmlChar const *>("false"));
516 :
517 : //remove option elements
518 0 : xmlNode* cur = vmParameters->children;
519 0 : while (cur != NULL)
520 : {
521 0 : xmlNode* lastNode = cur;
522 0 : cur = cur->next;
523 0 : xmlUnlinkNode(lastNode);
524 0 : xmlFreeNode(lastNode);
525 : }
526 : //add a new line after <vmParameters>
527 0 : if (m_vmParameters->size() > 0)
528 : {
529 0 : xmlNode * nodeCrLf = xmlNewText(reinterpret_cast<xmlChar const *>("\n"));
530 0 : xmlAddChild(vmParameters, nodeCrLf);
531 : }
532 :
533 : typedef std::vector<OUString>::const_iterator cit;
534 0 : for (cit i = m_vmParameters->begin(); i != m_vmParameters->end(); ++i)
535 : {
536 : xmlNewTextChild(vmParameters, NULL, reinterpret_cast<xmlChar const *>("param"),
537 0 : CXmlCharPtr(*i));
538 : //add a new line
539 0 : xmlNode * nodeCrLf = xmlNewText(reinterpret_cast<xmlChar const *>("\n"));
540 0 : xmlAddChild(vmParameters, nodeCrLf);
541 0 : }
542 : }
543 :
544 : //set <jreLocations> element
545 1 : if (m_JRELocations)
546 : {
547 : OString sExpression= OString(
548 0 : "/jf:java/jf:jreLocations");
549 0 : pathObj = xmlXPathEvalExpression(reinterpret_cast<xmlChar const *>(sExpression.getStr()),
550 0 : contextUser);
551 0 : if ( ! pathObj || xmlXPathNodeSetIsEmpty(pathObj->nodesetval))
552 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
553 0 : xmlNode* jreLocationsNode = pathObj->nodesetval->nodeTab[0];
554 : //set xsi:nil = false;
555 : xmlSetNsProp(jreLocationsNode, nsXsi,reinterpret_cast<xmlChar const *>("nil"),
556 0 : reinterpret_cast<xmlChar const *>("false"));
557 :
558 : //remove option elements
559 0 : xmlNode* cur = jreLocationsNode->children;
560 0 : while (cur != NULL)
561 : {
562 0 : xmlNode* lastNode = cur;
563 0 : cur = cur->next;
564 0 : xmlUnlinkNode(lastNode);
565 0 : xmlFreeNode(lastNode);
566 : }
567 : //add a new line after <vmParameters>
568 0 : if (m_JRELocations->size() > 0)
569 : {
570 0 : xmlNode * nodeCrLf = xmlNewText(reinterpret_cast<xmlChar const *>("\n"));
571 0 : xmlAddChild(jreLocationsNode, nodeCrLf);
572 : }
573 :
574 : typedef std::vector<OUString>::const_iterator cit;
575 0 : for (cit i = m_JRELocations->begin(); i != m_JRELocations->end(); ++i)
576 : {
577 : xmlNewTextChild(jreLocationsNode, NULL, reinterpret_cast<xmlChar const *>("location"),
578 0 : CXmlCharPtr(*i));
579 : //add a new line
580 0 : xmlNode * nodeCrLf = xmlNewText(reinterpret_cast<xmlChar const *>("\n"));
581 0 : xmlAddChild(jreLocationsNode, nodeCrLf);
582 0 : }
583 : }
584 :
585 1 : if (xmlSaveFormatFile(sSettingsPath.getStr(), docUser, 1) == -1)
586 1 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
587 : }
588 :
589 0 : void NodeJava::setEnabled(bool bEnabled)
590 : {
591 0 : m_enabled = boost::optional<sal_Bool>(bEnabled);
592 0 : }
593 :
594 :
595 0 : void NodeJava::setUserClassPath(const OUString & sClassPath)
596 : {
597 0 : m_userClassPath = boost::optional<OUString>(sClassPath);
598 0 : }
599 :
600 4 : void NodeJava::setJavaInfo(const JavaInfo * pInfo, bool bAutoSelect)
601 : {
602 4 : if (!m_javaInfo)
603 4 : m_javaInfo = boost::optional<CNodeJavaInfo>(CNodeJavaInfo());
604 4 : m_javaInfo->bAutoSelect = bAutoSelect;
605 4 : m_javaInfo->bNil = false;
606 :
607 4 : if (pInfo != NULL)
608 : {
609 4 : m_javaInfo->m_bEmptyNode = false;
610 4 : m_javaInfo->sVendor = pInfo->sVendor;
611 4 : m_javaInfo->sLocation = pInfo->sLocation;
612 4 : m_javaInfo->sVersion = pInfo->sVersion;
613 4 : m_javaInfo->nFeatures = pInfo->nFeatures;
614 4 : m_javaInfo->nRequirements = pInfo->nRequirements;
615 4 : m_javaInfo->arVendorData = pInfo->arVendorData;
616 : }
617 : else
618 : {
619 0 : m_javaInfo->m_bEmptyNode = true;
620 0 : OUString sEmpty;
621 0 : m_javaInfo->sVendor = sEmpty;
622 0 : m_javaInfo->sLocation = sEmpty;
623 0 : m_javaInfo->sVersion = sEmpty;
624 0 : m_javaInfo->nFeatures = 0;
625 0 : m_javaInfo->nRequirements = 0;
626 0 : m_javaInfo->arVendorData = rtl::ByteSequence();
627 : }
628 4 : }
629 :
630 0 : void NodeJava::setVmParameters(rtl_uString * * arOptions, sal_Int32 size)
631 : {
632 : OSL_ASSERT( !(arOptions == 0 && size != 0));
633 0 : if ( ! m_vmParameters)
634 0 : m_vmParameters = boost::optional<std::vector<OUString> >(
635 0 : std::vector<OUString>());
636 0 : m_vmParameters->clear();
637 0 : if (arOptions != NULL)
638 : {
639 0 : for (int i = 0; i < size; i++)
640 : {
641 0 : const OUString sOption(static_cast<rtl_uString*>(arOptions[i]));
642 0 : m_vmParameters->push_back(sOption);
643 0 : }
644 : }
645 0 : }
646 :
647 0 : void NodeJava::addJRELocation(rtl_uString * sLocation)
648 : {
649 : OSL_ASSERT( sLocation);
650 0 : if (!m_JRELocations)
651 0 : m_JRELocations = boost::optional<std::vector<OUString> >(
652 0 : std::vector<OUString> ());
653 : //only add the path if not already present
654 : std::vector<OUString>::const_iterator it =
655 : std::find(m_JRELocations->begin(), m_JRELocations->end(),
656 0 : OUString(sLocation));
657 0 : if (it == m_JRELocations->end())
658 0 : m_JRELocations->push_back(OUString(sLocation));
659 0 : }
660 :
661 10 : jfw::FileStatus NodeJava::checkSettingsFileStatus(OUString const & sURL)
662 : {
663 10 : jfw::FileStatus ret = FILE_DOES_NOT_EXIST;
664 :
665 : //check the file time
666 10 : ::osl::DirectoryItem item;
667 10 : File::RC rc = ::osl::DirectoryItem::get(sURL, item);
668 10 : if (File::E_None == rc)
669 : {
670 9 : ::osl::FileStatus stat(osl_FileStatus_Mask_Validate);
671 9 : File::RC rc_stat = item.getFileStatus(stat);
672 9 : if (File::E_None == rc_stat)
673 : {
674 9 : ret = FILE_OK;
675 : }
676 0 : else if (File::E_NOENT == rc_stat)
677 : {
678 0 : ret = FILE_DOES_NOT_EXIST;
679 : }
680 : else
681 : {
682 0 : ret = FILE_INVALID;
683 9 : }
684 : }
685 1 : else if(File::E_NOENT == rc)
686 : {
687 1 : ret = FILE_DOES_NOT_EXIST;
688 : }
689 : else
690 : {
691 0 : ret = FILE_INVALID;
692 : }
693 10 : return ret;
694 : }
695 :
696 32 : bool NodeJava::createSettingsDocument() const
697 : {
698 32 : const OUString sURL = getSettingsURL();
699 32 : if (sURL.isEmpty())
700 : {
701 22 : return false;
702 : }
703 : //make sure there is a user directory
704 : OString sExcMsg("[Java framework] Error in function createSettingsDocument "
705 20 : "(elements.cxx).");
706 : // check if javasettings.xml already exist
707 10 : if (FILE_OK == checkSettingsFileStatus(sURL))
708 9 : return true;
709 :
710 : //make sure that the directories are created in case they do not exist
711 1 : FileBase::RC rcFile = Directory::createPath(getDirFromFile(sURL));
712 1 : if (rcFile != FileBase::E_EXIST && rcFile != FileBase::E_None)
713 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
714 :
715 : //javasettings.xml does not exist yet
716 2 : CXmlDocPtr doc(xmlNewDoc(reinterpret_cast<xmlChar const *>("1.0")));
717 1 : if (! doc)
718 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
719 :
720 : //Create the root element and name spaces
721 : xmlNodePtr root = xmlNewDocNode(
722 1 : doc, NULL, reinterpret_cast<xmlChar const *>("java"), reinterpret_cast<xmlChar const *>("\n"));
723 :
724 1 : if (root == NULL)
725 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
726 :
727 1 : if (xmlNewNs(root, reinterpret_cast<xmlChar const *>(NS_JAVA_FRAMEWORK),NULL) == NULL)
728 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
729 1 : if (xmlNewNs(root,reinterpret_cast<xmlChar const *>(NS_SCHEMA_INSTANCE),reinterpret_cast<xmlChar const *>("xsi")) == NULL)
730 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
731 1 : xmlDocSetRootElement(doc, root);
732 :
733 : //Create a comment
734 : xmlNodePtr com = xmlNewComment(
735 1 : reinterpret_cast<xmlChar const *>("This is a generated file. Do not alter this file!"));
736 1 : if (com == NULL)
737 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
738 :
739 1 : if (xmlAddPrevSibling(root, com) == NULL)
740 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
741 :
742 2 : const OString path = getSettingsPath();
743 1 : if (xmlSaveFormatFileEnc(path.getStr(), doc,"UTF-8", 1) == -1)
744 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
745 33 : return true;
746 : }
747 :
748 :
749 33 : CNodeJavaInfo::CNodeJavaInfo() :
750 : m_bEmptyNode(false), bNil(true), bAutoSelect(true),
751 33 : nFeatures(0), nRequirements(0)
752 : {
753 33 : }
754 :
755 43 : CNodeJavaInfo::~CNodeJavaInfo()
756 : {
757 43 : }
758 :
759 1 : void CNodeJavaInfo::loadFromNode(xmlDoc * pDoc, xmlNode * pJavaInfo)
760 : {
761 : OString sExcMsg("[Java framework] Error in function NodeJavaInfo::loadFromNode "
762 1 : "(elements.cxx).");
763 :
764 : OSL_ASSERT(pJavaInfo && pDoc);
765 1 : if (pJavaInfo->children == NULL)
766 0 : return;
767 : //Get the xsi:nil attribute;
768 2 : CXmlCharPtr sNil;
769 1 : sNil = xmlGetNsProp(
770 1 : pJavaInfo, reinterpret_cast<xmlChar const *>("nil"), reinterpret_cast<xmlChar const *>(NS_SCHEMA_INSTANCE));
771 1 : if ( ! sNil)
772 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
773 :
774 1 : if (xmlStrcmp(sNil, reinterpret_cast<xmlChar const *>("true")) == 0)
775 0 : bNil = true;
776 1 : else if (xmlStrcmp(sNil, reinterpret_cast<xmlChar const *>("false")) == 0)
777 1 : bNil = false;
778 : else
779 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
780 1 : if (bNil)
781 0 : return;
782 :
783 : //Get javaInfo@manuallySelected attribute
784 2 : CXmlCharPtr sAutoSelect;
785 1 : sAutoSelect = xmlGetProp(
786 1 : pJavaInfo, reinterpret_cast<xmlChar const *>("autoSelect"));
787 1 : if ( ! sAutoSelect)
788 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
789 :
790 1 : if (xmlStrcmp(sAutoSelect, reinterpret_cast<xmlChar const *>("true")) == 0)
791 1 : bAutoSelect = true;
792 0 : else if (xmlStrcmp(sAutoSelect, reinterpret_cast<xmlChar const *>("false")) == 0)
793 0 : bAutoSelect = false;
794 : else
795 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
796 :
797 1 : xmlNode * cur = pJavaInfo->children;
798 :
799 15 : while (cur != NULL)
800 : {
801 13 : if (xmlStrcmp(cur->name, reinterpret_cast<xmlChar const *>("vendor")) == 0)
802 : {
803 1 : CXmlCharPtr xmlVendor;
804 1 : xmlVendor = xmlNodeListGetString(
805 1 : pDoc, cur->children, 1);
806 1 : if (! xmlVendor)
807 0 : return;
808 1 : sVendor = xmlVendor;
809 : }
810 12 : else if (xmlStrcmp(cur->name, reinterpret_cast<xmlChar const *>("location")) == 0)
811 : {
812 1 : CXmlCharPtr xmlLocation;
813 1 : xmlLocation = xmlNodeListGetString(
814 1 : pDoc, cur->children, 1);
815 1 : sLocation = xmlLocation;
816 : }
817 11 : else if (xmlStrcmp(cur->name, reinterpret_cast<xmlChar const *>("version")) == 0)
818 : {
819 1 : CXmlCharPtr xmlVersion;
820 1 : xmlVersion = xmlNodeListGetString(
821 1 : pDoc, cur->children, 1);
822 1 : sVersion = xmlVersion;
823 : }
824 10 : else if (xmlStrcmp(cur->name, reinterpret_cast<xmlChar const *>("features"))== 0)
825 : {
826 1 : CXmlCharPtr xmlFeatures;
827 1 : xmlFeatures = xmlNodeListGetString(
828 1 : pDoc, cur->children, 1);
829 2 : OUString sFeatures = xmlFeatures;
830 2 : nFeatures = sFeatures.toInt64(16);
831 : }
832 9 : else if (xmlStrcmp(cur->name, reinterpret_cast<xmlChar const *>("requirements")) == 0)
833 : {
834 1 : CXmlCharPtr xmlRequire;
835 1 : xmlRequire = xmlNodeListGetString(
836 1 : pDoc, cur->children, 1);
837 2 : OUString sRequire = xmlRequire;
838 2 : nRequirements = sRequire.toInt64(16);
839 : #ifdef MACOSX
840 : //javaldx is not used anymore in the mac build. In case the Java
841 : //corresponding to the saved settings does not exist anymore the
842 : //javavm services will look for an existing Java after creation of
843 : //the JVM failed. See stoc/source/javavm/javavm.cxx. Only if
844 : //nRequirements does not have the flag JFW_REQUIRE_NEEDRESTART the
845 : //jvm of the new selected JRE will be started. Old settings (before
846 : //OOo 3.3) still contain the flag which can be safely ignored.
847 : nRequirements &= ~JFW_REQUIRE_NEEDRESTART;
848 : #endif
849 : }
850 8 : else if (xmlStrcmp(cur->name, reinterpret_cast<xmlChar const *>("vendorData")) == 0)
851 : {
852 1 : CXmlCharPtr xmlData;
853 1 : xmlData = xmlNodeListGetString(
854 1 : pDoc, cur->children, 1);
855 1 : xmlChar* _data = static_cast<xmlChar*>(xmlData);
856 1 : if (_data)
857 : {
858 1 : rtl::ByteSequence seq(reinterpret_cast<sal_Int8*>(_data), strlen(reinterpret_cast<char*>(_data)));
859 1 : arVendorData = decodeBase16(seq);
860 1 : }
861 : }
862 13 : cur = cur->next;
863 : }
864 :
865 1 : if (sVendor.isEmpty())
866 0 : m_bEmptyNode = true;
867 : //Get the javainfo attributes
868 2 : CXmlCharPtr sVendorUpdate;
869 1 : sVendorUpdate = xmlGetProp(pJavaInfo,
870 1 : reinterpret_cast<xmlChar const *>("vendorUpdate"));
871 1 : if ( ! sVendorUpdate)
872 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
873 2 : sAttrVendorUpdate = sVendorUpdate;
874 : }
875 :
876 :
877 1 : void CNodeJavaInfo::writeToNode(xmlDoc* pDoc,
878 : xmlNode* pJavaInfoNode) const
879 :
880 : {
881 : OSL_ASSERT(pJavaInfoNode && pDoc);
882 : //write the attribute vendorSettings
883 :
884 : //javaInfo@vendorUpdate
885 : //creates the attribute if necessary
886 1 : OString sUpdated = getElementUpdated();
887 :
888 : xmlSetProp(pJavaInfoNode, reinterpret_cast<xmlChar const *>("vendorUpdate"),
889 1 : reinterpret_cast<xmlChar const *>(sUpdated.getStr()));
890 :
891 : //javaInfo@autoSelect
892 : xmlSetProp(pJavaInfoNode, reinterpret_cast<xmlChar const *>("autoSelect"),
893 1 : reinterpret_cast<xmlChar const *>(bAutoSelect ? "true" : "false"));
894 :
895 : //Set xsi:nil in javaInfo element to false
896 : //the xmlNs pointer must not be destroyed
897 : xmlNs* nsXsi = xmlSearchNsByHref(pDoc,
898 : pJavaInfoNode,
899 1 : reinterpret_cast<xmlChar const *>(NS_SCHEMA_INSTANCE));
900 :
901 : xmlSetNsProp(pJavaInfoNode,
902 : nsXsi,
903 : reinterpret_cast<xmlChar const *>("nil"),
904 1 : reinterpret_cast<xmlChar const *>("false"));
905 :
906 : //Delete the children of JavaInfo
907 1 : xmlNode* cur = pJavaInfoNode->children;
908 2 : while (cur != NULL)
909 : {
910 0 : xmlNode* lastNode = cur;
911 0 : cur = cur->next;
912 0 : xmlUnlinkNode(lastNode);
913 0 : xmlFreeNode(lastNode);
914 : }
915 :
916 : //If the JavaInfo was set with an empty value,
917 : //then we are done.
918 1 : if (m_bEmptyNode)
919 1 : return;
920 :
921 : //add a new line after <javaInfo>
922 1 : xmlNode * nodeCrLf = xmlNewText(reinterpret_cast<xmlChar const *>("\n"));
923 1 : xmlAddChild(pJavaInfoNode, nodeCrLf);
924 :
925 : //Create the vendor element
926 : xmlNewTextChild(pJavaInfoNode, NULL, reinterpret_cast<xmlChar const *>("vendor"),
927 1 : CXmlCharPtr(sVendor));
928 : //add a new line for better readability
929 1 : nodeCrLf = xmlNewText(reinterpret_cast<xmlChar const *>("\n"));
930 1 : xmlAddChild(pJavaInfoNode, nodeCrLf);
931 :
932 : //Create the location element
933 : xmlNewTextChild(pJavaInfoNode, NULL, reinterpret_cast<xmlChar const *>("location"),
934 1 : CXmlCharPtr(sLocation));
935 : //add a new line for better readability
936 1 : nodeCrLf = xmlNewText(reinterpret_cast<xmlChar const *>("\n"));
937 1 : xmlAddChild(pJavaInfoNode, nodeCrLf);
938 :
939 : //Create the version element
940 : xmlNewTextChild(pJavaInfoNode, NULL, reinterpret_cast<xmlChar const *>("version"),
941 1 : CXmlCharPtr(sVersion));
942 : //add a new line for better readability
943 1 : nodeCrLf = xmlNewText(reinterpret_cast<xmlChar const *>("\n"));
944 1 : xmlAddChild(pJavaInfoNode, nodeCrLf);
945 :
946 : //Create the features element
947 : OUString sFeatures = OUString::number(
948 2 : nFeatures, 16);
949 : xmlNewTextChild(pJavaInfoNode, NULL, reinterpret_cast<xmlChar const *>("features"),
950 1 : CXmlCharPtr(sFeatures));
951 : //add a new line for better readability
952 1 : nodeCrLf = xmlNewText(reinterpret_cast<xmlChar const *>("\n"));
953 1 : xmlAddChild(pJavaInfoNode, nodeCrLf);
954 :
955 :
956 : //Create the requirements element
957 : OUString sRequirements = OUString::number(
958 2 : nRequirements, 16);
959 : xmlNewTextChild(pJavaInfoNode, NULL, reinterpret_cast<xmlChar const *>("requirements"),
960 1 : CXmlCharPtr(sRequirements));
961 : //add a new line for better readability
962 1 : nodeCrLf = xmlNewText(reinterpret_cast<xmlChar const *>("\n"));
963 1 : xmlAddChild(pJavaInfoNode, nodeCrLf);
964 :
965 :
966 : //Create the features element
967 2 : rtl::ByteSequence data = encodeBase16(arVendorData);
968 : xmlNode* dataNode = xmlNewChild(pJavaInfoNode, NULL,
969 : reinterpret_cast<xmlChar const *>("vendorData"),
970 1 : reinterpret_cast<xmlChar const *>(""));
971 : xmlNodeSetContentLen(dataNode,
972 1 : reinterpret_cast<xmlChar*>(data.getArray()), data.getLength());
973 : //add a new line for better readability
974 1 : nodeCrLf = xmlNewText(reinterpret_cast<xmlChar const *>("\n"));
975 2 : xmlAddChild(pJavaInfoNode, nodeCrLf);
976 : }
977 :
978 4 : JavaInfo * CNodeJavaInfo::makeJavaInfo() const
979 : {
980 4 : if (bNil || m_bEmptyNode)
981 4 : return NULL;
982 0 : JavaInfo * pInfo = static_cast<JavaInfo*>(rtl_allocateMemory(sizeof(JavaInfo)));
983 0 : if (pInfo == NULL)
984 0 : return NULL;
985 0 : memset(pInfo, 0, sizeof(JavaInfo));
986 0 : pInfo->sVendor = sVendor.pData;
987 0 : rtl_uString_acquire(pInfo->sVendor);
988 0 : pInfo->sLocation = sLocation.pData;
989 0 : rtl_uString_acquire(pInfo->sLocation);
990 0 : pInfo->sVersion = sVersion.pData;
991 0 : rtl_uString_acquire(pInfo->sVersion);
992 0 : pInfo->nFeatures = nFeatures;
993 0 : pInfo->nRequirements = nRequirements;
994 0 : pInfo->arVendorData = arVendorData.getHandle();
995 0 : rtl_byte_sequence_acquire(pInfo->arVendorData);
996 0 : return pInfo;
997 : }
998 :
999 :
1000 28 : MergedSettings::MergedSettings():
1001 : m_bEnabled(false),
1002 : m_sClassPath(),
1003 : m_vmParams(),
1004 : m_JRELocations(),
1005 28 : m_javaInfo()
1006 : {
1007 28 : NodeJava settings(NodeJava::USER);
1008 28 : settings.load();
1009 56 : NodeJava sharedSettings(NodeJava::SHARED);
1010 28 : sharedSettings.load();
1011 56 : merge(sharedSettings, settings);
1012 28 : }
1013 :
1014 28 : MergedSettings::~MergedSettings()
1015 : {
1016 28 : }
1017 :
1018 28 : void MergedSettings::merge(const NodeJava & share, const NodeJava & user)
1019 : {
1020 28 : if (user.getEnabled())
1021 0 : m_bEnabled = * user.getEnabled();
1022 28 : else if (share.getEnabled())
1023 0 : m_bEnabled = * share.getEnabled();
1024 : else
1025 28 : m_bEnabled = true;
1026 :
1027 28 : if (user.getUserClassPath())
1028 0 : m_sClassPath = * user.getUserClassPath();
1029 28 : else if (share.getUserClassPath())
1030 0 : m_sClassPath = * share.getUserClassPath();
1031 :
1032 28 : if (user.getJavaInfo())
1033 1 : m_javaInfo = * user.getJavaInfo();
1034 27 : else if (share.getJavaInfo())
1035 0 : m_javaInfo = * share.getJavaInfo();
1036 :
1037 28 : if (user.getVmParameters())
1038 0 : m_vmParams = * user.getVmParameters();
1039 28 : else if (share.getVmParameters())
1040 0 : m_vmParams = * share.getVmParameters();
1041 :
1042 28 : if (user.getJRELocations())
1043 0 : m_JRELocations = * user.getJRELocations();
1044 28 : else if (share.getJRELocations())
1045 0 : m_JRELocations = * share.getJRELocations();
1046 28 : }
1047 :
1048 :
1049 0 : ::std::vector< OString> MergedSettings::getVmParametersUtf8() const
1050 : {
1051 0 : ::std::vector< OString> ret;
1052 : typedef ::std::vector< OUString>::const_iterator cit;
1053 0 : for (cit i = m_vmParams.begin(); i != m_vmParams.end(); ++i)
1054 : {
1055 0 : ret.push_back( OUStringToOString(*i, RTL_TEXTENCODING_UTF8));
1056 : }
1057 0 : return ret;
1058 : }
1059 :
1060 :
1061 :
1062 4 : JavaInfo * MergedSettings::createJavaInfo() const
1063 : {
1064 4 : return m_javaInfo.makeJavaInfo();
1065 : }
1066 : #ifdef WNT
1067 : bool MergedSettings::getJavaInfoAttrAutoSelect() const
1068 : {
1069 : return m_javaInfo.bAutoSelect;
1070 : }
1071 : #endif
1072 0 : void MergedSettings::getVmParametersArray(
1073 : rtl_uString *** parParams, sal_Int32 * size) const
1074 : {
1075 0 : osl::MutexGuard guard(FwkMutex::get());
1076 : OSL_ASSERT(parParams != NULL && size != NULL);
1077 :
1078 : *parParams = static_cast<rtl_uString **>(
1079 0 : rtl_allocateMemory(sizeof(rtl_uString*) * m_vmParams.size()));
1080 0 : if (*parParams == NULL)
1081 0 : return;
1082 :
1083 0 : int j=0;
1084 : typedef std::vector<OUString>::const_iterator it;
1085 0 : for (it i = m_vmParams.begin(); i != m_vmParams.end();
1086 : ++i, ++j)
1087 : {
1088 0 : (*parParams)[j] = i->pData;
1089 0 : rtl_uString_acquire(i->pData);
1090 : }
1091 0 : *size = m_vmParams.size();
1092 : }
1093 :
1094 0 : void MergedSettings::getJRELocations(
1095 : rtl_uString *** parLocations, sal_Int32 * size) const
1096 : {
1097 0 : osl::MutexGuard guard(FwkMutex::get());
1098 : assert(parLocations != NULL && size != NULL);
1099 :
1100 : *parLocations = static_cast<rtl_uString **>(
1101 0 : rtl_allocateMemory(sizeof(rtl_uString*) * m_JRELocations.size()));
1102 0 : if (*parLocations == NULL)
1103 0 : return;
1104 :
1105 0 : int j=0;
1106 : typedef std::vector<OUString>::const_iterator it;
1107 0 : for (it i = m_JRELocations.begin(); i != m_JRELocations.end();
1108 : ++i, ++j)
1109 : {
1110 0 : (*parLocations)[j] = i->pData;
1111 0 : rtl_uString_acquire(i->pData);
1112 : }
1113 0 : *size = m_JRELocations.size();
1114 : }
1115 : }
1116 :
1117 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|