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 :
21 : #include "rtl/string.h"
22 : #include "rtl/strbuf.hxx"
23 : #include "rtl/bootstrap.hxx"
24 : #include "cppuhelper/exc_hlp.hxx"
25 : #include "osl/file.hxx"
26 : #include "com/sun/star/uno/XComponentContext.hpp"
27 : #include "com/sun/star/xml/dom/DocumentBuilder.hpp"
28 : #include "com/sun/star/xml/xpath/XPathAPI.hpp"
29 : #include "com/sun/star/io/XActiveDataSource.hpp"
30 : #include "com/sun/star/io/XActiveDataControl.hpp"
31 : #include "dp_ucb.h"
32 : #include "dp_misc.h"
33 : #include "ucbhelper/content.hxx"
34 : #include "xmlscript/xml_helper.hxx"
35 : #include "dp_backenddb.hxx"
36 :
37 :
38 : using namespace ::com::sun::star::uno;
39 :
40 :
41 : namespace dp_registry {
42 : namespace backend {
43 :
44 0 : BackendDb::BackendDb(
45 : Reference<css::uno::XComponentContext> const & xContext,
46 : OUString const & url):
47 0 : m_xContext(xContext)
48 : {
49 0 : m_urlDb = dp_misc::expandUnoRcUrl(url);
50 0 : }
51 :
52 0 : void BackendDb::save()
53 : {
54 0 : const Reference<css::io::XActiveDataSource> xDataSource(m_doc,css::uno::UNO_QUERY_THROW);
55 0 : ::rtl::ByteSequence bytes;
56 0 : xDataSource->setOutputStream(::xmlscript::createOutputStream(&bytes));
57 0 : const Reference<css::io::XActiveDataControl> xDataControl(m_doc,css::uno::UNO_QUERY_THROW);
58 0 : xDataControl->start();
59 :
60 : const Reference<css::io::XInputStream> xData(
61 0 : ::xmlscript::createInputStream(bytes));
62 0 : ::ucbhelper::Content ucbDb(m_urlDb, 0, m_xContext);
63 0 : ucbDb.writeStream(xData, true /*replace existing*/);
64 0 : }
65 :
66 0 : css::uno::Reference<css::xml::dom::XDocument> BackendDb::getDocument()
67 : {
68 0 : if (!m_doc.is())
69 : {
70 : const Reference<css::xml::dom::XDocumentBuilder> xDocBuilder(
71 0 : css::xml::dom::DocumentBuilder::create(m_xContext) );
72 :
73 0 : ::osl::DirectoryItem item;
74 0 : ::osl::File::RC err = ::osl::DirectoryItem::get(m_urlDb, item);
75 0 : if (err == ::osl::File::E_None)
76 : {
77 : ::ucbhelper::Content descContent(
78 : m_urlDb, css::uno::Reference<css::ucb::XCommandEnvironment>(),
79 0 : m_xContext);
80 0 : Reference<css::io::XInputStream> xIn = descContent.openStream();
81 0 : m_doc = xDocBuilder->parse(xIn);
82 : }
83 0 : else if (err == ::osl::File::E_NOENT)
84 : {
85 : //Create a new document and insert some basic stuff
86 0 : m_doc = xDocBuilder->newDocument();
87 : const Reference<css::xml::dom::XElement> rootNode =
88 0 : m_doc->createElementNS(getDbNSName(), getNSPrefix() +
89 0 : ":" + getRootElementName());
90 :
91 0 : m_doc->appendChild(Reference<css::xml::dom::XNode>(
92 0 : rootNode, UNO_QUERY_THROW));
93 0 : save();
94 : }
95 : else
96 : throw css::uno::RuntimeException(
97 : "Extension manager could not access database file:"
98 0 : + m_urlDb, 0);
99 :
100 0 : if (!m_doc.is())
101 : throw css::uno::RuntimeException(
102 : "Extension manager could not get root node of data base file: "
103 0 : + m_urlDb, 0);
104 : }
105 :
106 0 : return m_doc;
107 : }
108 :
109 0 : Reference<css::xml::xpath::XXPathAPI> BackendDb::getXPathAPI()
110 : {
111 0 : if (!m_xpathApi.is())
112 : {
113 0 : m_xpathApi = css::xml::xpath::XPathAPI::create( m_xContext );
114 :
115 0 : m_xpathApi->registerNS( getNSPrefix(), getDbNSName() );
116 : }
117 :
118 0 : return m_xpathApi;
119 : }
120 :
121 0 : void BackendDb::removeElement(OUString const & sXPathExpression)
122 : {
123 : try
124 : {
125 0 : const Reference<css::xml::dom::XDocument> doc = getDocument();
126 0 : const Reference<css::xml::dom::XNode> root = doc->getFirstChild();
127 0 : const Reference<css::xml::xpath::XXPathAPI> xpathApi = getXPathAPI();
128 : //find the extension element that is to be removed
129 : const Reference<css::xml::dom::XNode> aNode =
130 0 : xpathApi->selectSingleNode(root, sXPathExpression);
131 :
132 0 : if (aNode.is())
133 : {
134 0 : root->removeChild(aNode);
135 0 : save();
136 0 : }
137 :
138 : #if OSL_DEBUG_LEVEL > 0
139 : //There must not be any other entry with the same url
140 : const Reference<css::xml::dom::XNode> nextNode =
141 : xpathApi->selectSingleNode(root, sXPathExpression);
142 : OSL_ASSERT(! nextNode.is());
143 : #endif
144 : }
145 0 : catch(const css::uno::Exception &)
146 : {
147 0 : Any exc( ::cppu::getCaughtException() );
148 : throw css::deployment::DeploymentException(
149 0 : "Extension Manager: failed to write data entry in backend db: " +
150 0 : m_urlDb, 0, exc);
151 : }
152 0 : }
153 :
154 0 : void BackendDb::removeEntry(OUString const & url)
155 : {
156 0 : const OUString sKeyElement = getKeyElementName();
157 0 : const OUString sPrefix = getNSPrefix();
158 0 : OUStringBuffer sExpression(500);
159 0 : sExpression.append(sPrefix);
160 0 : sExpression.appendAscii(":");
161 0 : sExpression.append(sKeyElement);
162 0 : sExpression.append("[@url = \"");
163 0 : sExpression.append(url);
164 0 : sExpression.appendAscii("\"]");
165 :
166 0 : removeElement(sExpression.makeStringAndClear());
167 0 : }
168 :
169 0 : void BackendDb::revokeEntry(OUString const & url)
170 : {
171 : try
172 : {
173 0 : Reference<css::xml::dom::XElement> entry = Reference<css::xml::dom::XElement>(getKeyElement(url), UNO_QUERY);
174 0 : if (entry.is())
175 : {
176 0 : entry->setAttribute("revoked", "true");
177 0 : save();
178 0 : }
179 : }
180 0 : catch(const css::uno::Exception &)
181 : {
182 0 : Any exc( ::cppu::getCaughtException() );
183 : throw css::deployment::DeploymentException(
184 0 : "Extension Manager: failed to revoke data entry in backend db: " +
185 0 : m_urlDb, 0, exc);
186 : }
187 0 : }
188 :
189 0 : bool BackendDb::activateEntry(OUString const & url)
190 : {
191 : try
192 : {
193 0 : bool ret = false;
194 0 : Reference<css::xml::dom::XElement> entry = Reference<css::xml::dom::XElement>(getKeyElement(url), UNO_QUERY);
195 0 : if (entry.is())
196 : {
197 : //no attribute "active" means it is active, that is, registered.
198 0 : entry->removeAttribute("revoked");
199 0 : save();
200 0 : ret = true;
201 : }
202 0 : return ret;
203 : }
204 0 : catch(const css::uno::Exception &)
205 : {
206 0 : Any exc( ::cppu::getCaughtException() );
207 : throw css::deployment::DeploymentException(
208 0 : "Extension Manager: failed to revoke data entry in backend db: " +
209 0 : m_urlDb, 0, exc);
210 : }
211 : }
212 :
213 0 : bool BackendDb::hasActiveEntry(OUString const & url)
214 : {
215 : try
216 : {
217 0 : bool ret = false;
218 0 : Reference<css::xml::dom::XElement> entry = Reference<css::xml::dom::XElement>(getKeyElement(url), UNO_QUERY);
219 0 : if (entry.is())
220 : {
221 0 : OUString sActive = entry->getAttribute("revoked");
222 0 : if (!(sActive == "true"))
223 0 : ret = true;
224 : }
225 0 : return ret;
226 :
227 : }
228 0 : catch(const css::uno::Exception &)
229 : {
230 0 : Any exc( ::cppu::getCaughtException() );
231 : throw css::deployment::DeploymentException(
232 0 : "Extension Manager: failed to determine an active entry in backend db: " +
233 0 : m_urlDb, 0, exc);
234 : }
235 : }
236 :
237 0 : Reference<css::xml::dom::XNode> BackendDb::getKeyElement(
238 : OUString const & url)
239 : {
240 : try
241 : {
242 0 : const OUString sPrefix = getNSPrefix();
243 0 : const OUString sKeyElement = getKeyElementName();
244 0 : OUStringBuffer sExpression(500);
245 0 : sExpression.append(sPrefix);
246 0 : sExpression.appendAscii(":");
247 0 : sExpression.append(sKeyElement);
248 0 : sExpression.append("[@url = \"");
249 0 : sExpression.append(url);
250 0 : sExpression.appendAscii("\"]");
251 :
252 0 : const Reference<css::xml::dom::XDocument> doc = getDocument();
253 0 : const Reference<css::xml::dom::XNode> root = doc->getFirstChild();
254 0 : const Reference<css::xml::xpath::XXPathAPI> xpathApi = getXPathAPI();
255 0 : return xpathApi->selectSingleNode(root, sExpression.makeStringAndClear());
256 : }
257 0 : catch(const css::uno::Exception &)
258 : {
259 0 : Any exc( ::cppu::getCaughtException() );
260 : throw css::deployment::DeploymentException(
261 0 : "Extension Manager: failed to read key element in backend db: " +
262 0 : m_urlDb, 0, exc);
263 : }
264 : }
265 :
266 : //Only writes the data if there is at least one entry
267 0 : void BackendDb::writeVectorOfPair(
268 : ::std::vector< ::std::pair< OUString, OUString > > const & vecPairs,
269 : OUString const & sVectorTagName,
270 : OUString const & sPairTagName,
271 : OUString const & sFirstTagName,
272 : OUString const & sSecondTagName,
273 : css::uno::Reference<css::xml::dom::XNode> const & xParent)
274 : {
275 : try{
276 0 : if (vecPairs.empty())
277 0 : return;
278 0 : const OUString sNameSpace = getDbNSName();
279 : OSL_ASSERT(!sNameSpace.isEmpty());
280 0 : const OUString sPrefix(getNSPrefix() + ":");
281 0 : const Reference<css::xml::dom::XDocument> doc = getDocument();
282 0 : const Reference<css::xml::dom::XNode> root = doc->getFirstChild();
283 :
284 : const Reference<css::xml::dom::XElement> vectorNode(
285 0 : doc->createElementNS(sNameSpace, sPrefix + sVectorTagName));
286 :
287 0 : xParent->appendChild(
288 : Reference<css::xml::dom::XNode>(
289 0 : vectorNode, css::uno::UNO_QUERY_THROW));
290 : typedef ::std::vector< ::std::pair< OUString, OUString > >::const_iterator CIT;
291 0 : for (CIT i = vecPairs.begin(); i != vecPairs.end(); ++i)
292 : {
293 : const Reference<css::xml::dom::XElement> pairNode(
294 0 : doc->createElementNS(sNameSpace, sPrefix + sPairTagName));
295 :
296 0 : vectorNode->appendChild(
297 : Reference<css::xml::dom::XNode>(
298 0 : pairNode, css::uno::UNO_QUERY_THROW));
299 :
300 : const Reference<css::xml::dom::XElement> firstNode(
301 0 : doc->createElementNS(sNameSpace, sPrefix + sFirstTagName));
302 :
303 0 : pairNode->appendChild(
304 : Reference<css::xml::dom::XNode>(
305 0 : firstNode, css::uno::UNO_QUERY_THROW));
306 :
307 : const Reference<css::xml::dom::XText> firstTextNode(
308 0 : doc->createTextNode( i->first));
309 :
310 0 : firstNode->appendChild(
311 : Reference<css::xml::dom::XNode>(
312 0 : firstTextNode, css::uno::UNO_QUERY_THROW));
313 :
314 : const Reference<css::xml::dom::XElement> secondNode(
315 0 : doc->createElementNS(sNameSpace, sPrefix + sSecondTagName));
316 :
317 0 : pairNode->appendChild(
318 : Reference<css::xml::dom::XNode>(
319 0 : secondNode, css::uno::UNO_QUERY_THROW));
320 :
321 : const Reference<css::xml::dom::XText> secondTextNode(
322 0 : doc->createTextNode( i->second));
323 :
324 0 : secondNode->appendChild(
325 : Reference<css::xml::dom::XNode>(
326 0 : secondTextNode, css::uno::UNO_QUERY_THROW));
327 0 : }
328 : }
329 0 : catch(const css::uno::Exception &)
330 : {
331 0 : Any exc( ::cppu::getCaughtException() );
332 : throw css::deployment::DeploymentException(
333 0 : "Extension Manager: failed to write data entry in backend db: " +
334 0 : m_urlDb, 0, exc);
335 : }
336 : }
337 :
338 : ::std::vector< ::std::pair< OUString, OUString > >
339 0 : BackendDb::readVectorOfPair(
340 : Reference<css::xml::dom::XNode> const & parent,
341 : OUString const & sListTagName,
342 : OUString const & sPairTagName,
343 : OUString const & sFirstTagName,
344 : OUString const & sSecondTagName)
345 : {
346 : try
347 : {
348 : OSL_ASSERT(parent.is());
349 0 : const OUString sPrefix(getNSPrefix() + ":");
350 0 : const Reference<css::xml::xpath::XXPathAPI> xpathApi = getXPathAPI();
351 : const OUString sExprPairs(
352 0 : sPrefix + sListTagName + "/" + sPrefix + sPairTagName);
353 : const Reference<css::xml::dom::XNodeList> listPairs =
354 0 : xpathApi->selectNodeList(parent, sExprPairs);
355 :
356 0 : ::std::vector< ::std::pair< OUString, OUString > > retVector;
357 0 : sal_Int32 length = listPairs->getLength();
358 0 : for (sal_Int32 i = 0; i < length; i++)
359 : {
360 0 : const Reference<css::xml::dom::XNode> aPair = listPairs->item(i);
361 0 : const OUString sExprFirst(sPrefix + sFirstTagName + "/text()");
362 : const Reference<css::xml::dom::XNode> first =
363 0 : xpathApi->selectSingleNode(aPair, sExprFirst);
364 :
365 0 : const OUString sExprSecond(sPrefix + sSecondTagName + "/text()");
366 : const Reference<css::xml::dom::XNode> second =
367 0 : xpathApi->selectSingleNode(aPair, sExprSecond);
368 : OSL_ASSERT(first.is() && second.is());
369 :
370 : retVector.push_back(::std::make_pair(
371 0 : first->getNodeValue(), second->getNodeValue()));
372 0 : }
373 0 : return retVector;
374 : }
375 0 : catch(const css::uno::Exception &)
376 : {
377 0 : Any exc( ::cppu::getCaughtException() );
378 : throw css::deployment::DeploymentException(
379 0 : "Extension Manager: failed to read data entry in backend db: " +
380 0 : m_urlDb, 0, exc);
381 : }
382 : }
383 :
384 : //Only writes the data if there is at least one entry
385 0 : void BackendDb::writeSimpleList(
386 : ::std::list< OUString> const & list,
387 : OUString const & sListTagName,
388 : OUString const & sMemberTagName,
389 : Reference<css::xml::dom::XNode> const & xParent)
390 : {
391 : try
392 : {
393 0 : if (list.empty())
394 0 : return;
395 0 : const OUString sNameSpace = getDbNSName();
396 0 : const OUString sPrefix(getNSPrefix() + ":");
397 0 : const Reference<css::xml::dom::XDocument> doc = getDocument();
398 :
399 : const Reference<css::xml::dom::XElement> listNode(
400 0 : doc->createElementNS(sNameSpace, sPrefix + sListTagName));
401 :
402 0 : xParent->appendChild(
403 : Reference<css::xml::dom::XNode>(
404 0 : listNode, css::uno::UNO_QUERY_THROW));
405 :
406 : typedef ::std::list<OUString>::const_iterator ITC_ITEMS;
407 0 : for (ITC_ITEMS i = list.begin(); i != list.end(); ++i)
408 : {
409 : const Reference<css::xml::dom::XNode> memberNode(
410 0 : doc->createElementNS(sNameSpace, sPrefix + sMemberTagName), css::uno::UNO_QUERY_THROW);
411 :
412 0 : listNode->appendChild(memberNode);
413 :
414 : const Reference<css::xml::dom::XNode> textNode(
415 0 : doc->createTextNode( *i), css::uno::UNO_QUERY_THROW);
416 :
417 0 : memberNode->appendChild(textNode);
418 0 : }
419 : }
420 0 : catch(const css::uno::Exception &)
421 : {
422 0 : Any exc( ::cppu::getCaughtException() );
423 : throw css::deployment::DeploymentException(
424 0 : "Extension Manager: failed to write data entry in backend db: " +
425 0 : m_urlDb, 0, exc);
426 : }
427 : }
428 :
429 : //Writes only the element if is has a value.
430 : //The prefix is automatically added to the element name
431 0 : void BackendDb::writeSimpleElement(
432 : OUString const & sElementName, OUString const & value,
433 : Reference<css::xml::dom::XNode> const & xParent)
434 : {
435 : try
436 : {
437 0 : if (value.isEmpty())
438 0 : return;
439 0 : const OUString sPrefix = getNSPrefix();
440 0 : const Reference<css::xml::dom::XDocument> doc = getDocument();
441 0 : const OUString sNameSpace = getDbNSName();
442 : const Reference<css::xml::dom::XNode> dataNode(
443 0 : doc->createElementNS(sNameSpace, sPrefix + ":" + sElementName),
444 0 : UNO_QUERY_THROW);
445 0 : xParent->appendChild(dataNode);
446 :
447 : const Reference<css::xml::dom::XNode> dataValue(
448 0 : doc->createTextNode(value), UNO_QUERY_THROW);
449 0 : dataNode->appendChild(dataValue);
450 : }
451 0 : catch(const css::uno::Exception &)
452 : {
453 0 : Any exc( ::cppu::getCaughtException() );
454 : throw css::deployment::DeploymentException(
455 0 : "Extension Manager: failed to write data entry(writeSimpleElement) in backend db: " +
456 0 : m_urlDb, 0, exc);
457 : }
458 :
459 : }
460 :
461 : /** The key elements have an url attribute and are always children of the root
462 : element.
463 : */
464 0 : Reference<css::xml::dom::XNode> BackendDb::writeKeyElement(
465 : OUString const & url)
466 : {
467 : try
468 : {
469 0 : const OUString sNameSpace = getDbNSName();
470 0 : const OUString sPrefix = getNSPrefix();
471 0 : const OUString sElementName = getKeyElementName();
472 0 : const Reference<css::xml::dom::XDocument> doc = getDocument();
473 0 : const Reference<css::xml::dom::XNode> root = doc->getFirstChild();
474 :
475 : //Check if there are an entry with the same url. This can be the case if the
476 : //the status of an XPackage is ambiguous. In this case a call to activateExtension
477 : //(dp_extensionmanager.cxx), will register the package again. See also
478 : //Package::processPackage_impl in dp_backend.cxx.
479 : //A package can become
480 : //invalid after its successful registration, for example if a second extension with
481 : //the same service is installed.
482 : const OUString sExpression(
483 0 : sPrefix + ":" + sElementName + "[@url = \"" + url + "\"]");
484 : const Reference<css::xml::dom::XNode> existingNode =
485 0 : getXPathAPI()->selectSingleNode(root, sExpression);
486 0 : if (existingNode.is())
487 : {
488 : OSL_ASSERT(false);
489 : //replace the existing entry.
490 0 : removeEntry(url);
491 : }
492 :
493 : const Reference<css::xml::dom::XElement> keyElement(
494 0 : doc->createElementNS(sNameSpace, sPrefix + ":" + sElementName));
495 :
496 0 : keyElement->setAttribute("url", url);
497 :
498 : const Reference<css::xml::dom::XNode> keyNode(
499 0 : keyElement, UNO_QUERY_THROW);
500 0 : root->appendChild(keyNode);
501 0 : return keyNode;
502 : }
503 0 : catch(const css::uno::Exception &)
504 : {
505 0 : Any exc( ::cppu::getCaughtException() );
506 : throw css::deployment::DeploymentException(
507 0 : "Extension Manager: failed to write key element in backend db: " +
508 0 : m_urlDb, 0, exc);
509 : }
510 : }
511 :
512 0 : OUString BackendDb::readSimpleElement(
513 : OUString const & sElementName, Reference<css::xml::dom::XNode> const & xParent)
514 : {
515 : try
516 : {
517 0 : const OUString sPrefix = getNSPrefix();
518 0 : const OUString sExpr(sPrefix + ":" + sElementName + "/text()");
519 0 : const Reference<css::xml::xpath::XXPathAPI> xpathApi = getXPathAPI();
520 : const Reference<css::xml::dom::XNode> val =
521 0 : xpathApi->selectSingleNode(xParent, sExpr);
522 0 : if (val.is())
523 0 : return val->getNodeValue();
524 0 : return OUString();
525 : }
526 0 : catch(const css::uno::Exception &)
527 : {
528 0 : Any exc( ::cppu::getCaughtException() );
529 : throw css::deployment::DeploymentException(
530 0 : "Extension Manager: failed to read data (readSimpleElement) in backend db: " +
531 0 : m_urlDb, 0, exc);
532 : }
533 : }
534 :
535 :
536 0 : ::std::list< OUString> BackendDb::readList(
537 : Reference<css::xml::dom::XNode> const & parent,
538 : OUString const & sListTagName,
539 : OUString const & sMemberTagName)
540 : {
541 : try
542 : {
543 : OSL_ASSERT(parent.is());
544 0 : const OUString sPrefix(getNSPrefix() + ":");
545 0 : const Reference<css::xml::xpath::XXPathAPI> xpathApi = getXPathAPI();
546 : const OUString sExprList(
547 0 : sPrefix + sListTagName + "/" + sPrefix + sMemberTagName + "/text()");
548 : const Reference<css::xml::dom::XNodeList> list =
549 0 : xpathApi->selectNodeList(parent, sExprList);
550 :
551 0 : ::std::list<OUString > retList;
552 0 : sal_Int32 length = list->getLength();
553 0 : for (sal_Int32 i = 0; i < length; i++)
554 : {
555 0 : const Reference<css::xml::dom::XNode> member = list->item(i);
556 0 : retList.push_back(member->getNodeValue());
557 0 : }
558 0 : return retList;
559 : }
560 0 : catch(const css::uno::Exception &)
561 : {
562 0 : Any exc( ::cppu::getCaughtException() );
563 : throw css::deployment::DeploymentException(
564 0 : "Extension Manager: failed to read data entry in backend db: " +
565 0 : m_urlDb, 0, exc);
566 : }
567 : }
568 :
569 0 : ::std::list<OUString> BackendDb::getOneChildFromAllEntries(
570 : OUString const & name)
571 : {
572 : try
573 : {
574 0 : ::std::list<OUString> listRet;
575 0 : Reference<css::xml::dom::XDocument> doc = getDocument();
576 0 : Reference<css::xml::dom::XNode> root = doc->getFirstChild();
577 :
578 0 : Reference<css::xml::xpath::XXPathAPI> xpathApi = getXPathAPI();
579 0 : const OUString sPrefix = getNSPrefix();
580 0 : const OUString sKeyElement = getKeyElementName();
581 0 : OUStringBuffer buf(512);
582 0 : buf.append(sPrefix);
583 0 : buf.appendAscii(":");
584 0 : buf.append(sKeyElement);
585 0 : buf.appendAscii("/");
586 0 : buf.append(sPrefix);
587 0 : buf.appendAscii(":");
588 0 : buf.append(name);
589 0 : buf.append("/text()");
590 :
591 : Reference<css::xml::dom::XNodeList> nodes =
592 0 : xpathApi->selectNodeList(root, buf.makeStringAndClear());
593 0 : if (nodes.is())
594 : {
595 0 : sal_Int32 length = nodes->getLength();
596 0 : for (sal_Int32 i = 0; i < length; i++)
597 0 : listRet.push_back(nodes->item(i)->getNodeValue());
598 : }
599 0 : return listRet;
600 : }
601 0 : catch ( const css::deployment::DeploymentException& )
602 : {
603 0 : throw;
604 : }
605 0 : catch(const css::uno::Exception &)
606 : {
607 0 : Any exc( ::cppu::getCaughtException() );
608 : throw css::deployment::DeploymentException(
609 0 : "Extension Manager: failed to read data entry in backend db: " +
610 0 : m_urlDb, 0, exc);
611 : }
612 : }
613 :
614 :
615 0 : RegisteredDb::RegisteredDb(
616 : Reference<XComponentContext> const & xContext,
617 0 : OUString const & url):BackendDb(xContext, url)
618 : {
619 0 : }
620 :
621 0 : void RegisteredDb::addEntry(OUString const & url)
622 : {
623 : try{
624 0 : if (!activateEntry(url))
625 : {
626 0 : const OUString sNameSpace = getDbNSName();
627 0 : const OUString sPrefix = getNSPrefix();
628 0 : const OUString sEntry = getKeyElementName();
629 :
630 0 : Reference<css::xml::dom::XDocument> doc = getDocument();
631 0 : Reference<css::xml::dom::XNode> root = doc->getFirstChild();
632 :
633 : #if OSL_DEBUG_LEVEL > 0
634 : //There must not be yet an entry with the same url
635 : OUString sExpression(
636 : sPrefix + ":" + sEntry + "[@url = \"" + url + "\"]");
637 : Reference<css::xml::dom::XNode> _extensionNode =
638 : getXPathAPI()->selectSingleNode(root, sExpression);
639 : OSL_ASSERT(! _extensionNode.is());
640 : #endif
641 : Reference<css::xml::dom::XElement> helpElement(
642 0 : doc->createElementNS(sNameSpace, sPrefix + ":" + sEntry));
643 :
644 0 : helpElement->setAttribute("url", url);
645 :
646 : Reference<css::xml::dom::XNode> helpNode(
647 0 : helpElement, UNO_QUERY_THROW);
648 0 : root->appendChild(helpNode);
649 :
650 0 : save();
651 : }
652 : }
653 0 : catch(const css::uno::Exception &)
654 : {
655 0 : Any exc( ::cppu::getCaughtException() );
656 : throw css::deployment::DeploymentException(
657 0 : "Extension Manager: failed to write data entry in backend db: " +
658 0 : m_urlDb, 0, exc);
659 : }
660 0 : }
661 :
662 0 : bool RegisteredDb::getEntry(OUString const & url)
663 : {
664 : try
665 : {
666 0 : const OUString sPrefix = getNSPrefix();
667 0 : const OUString sEntry = getKeyElementName();
668 : const OUString sExpression(
669 0 : sPrefix + ":" + sEntry + "[@url = \"" + url + "\"]");
670 0 : Reference<css::xml::dom::XDocument> doc = getDocument();
671 0 : Reference<css::xml::dom::XNode> root = doc->getFirstChild();
672 :
673 0 : Reference<css::xml::xpath::XXPathAPI> xpathApi = getXPathAPI();
674 : Reference<css::xml::dom::XNode> aNode =
675 0 : xpathApi->selectSingleNode(root, sExpression);
676 :
677 0 : return aNode.is();
678 : }
679 0 : catch(const css::uno::Exception &)
680 : {
681 0 : Any exc( ::cppu::getCaughtException() );
682 : throw css::deployment::DeploymentException(
683 0 : "Extension Manager: failed to read data entry in backend db: " +
684 0 : m_urlDb, 0, exc);
685 : }
686 : }
687 :
688 : } // namespace backend
689 : } // namespace dp_registry
690 :
691 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|