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