LCOV - code coverage report
Current view: top level - desktop/source/deployment/registry - dp_backenddb.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 213 311 68.5 %
Date: 2014-04-11 Functions: 18 21 85.7 %
Legend: Lines: hit not hit

          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        1470 : BackendDb::BackendDb(
      45             :     Reference<css::uno::XComponentContext> const &  xContext,
      46             :     OUString const & url):
      47        1470 :     m_xContext(xContext)
      48             : {
      49        1470 :     m_urlDb = dp_misc::expandUnoRcUrl(url);
      50        1470 : }
      51             : 
      52         329 : void BackendDb::save()
      53             : {
      54         329 :     const Reference<css::io::XActiveDataSource> xDataSource(m_doc,css::uno::UNO_QUERY_THROW);
      55         658 :     ::rtl::ByteSequence bytes;
      56         329 :     xDataSource->setOutputStream(::xmlscript::createOutputStream(&bytes));
      57         658 :     const Reference<css::io::XActiveDataControl> xDataControl(m_doc,css::uno::UNO_QUERY_THROW);
      58         329 :     xDataControl->start();
      59             : 
      60             :     const Reference<css::io::XInputStream> xData(
      61         658 :         ::xmlscript::createInputStream(bytes));
      62         658 :     ::ucbhelper::Content ucbDb(m_urlDb, 0, m_xContext);
      63         658 :     ucbDb.writeStream(xData, true /*replace existing*/);
      64         329 : }
      65             : 
      66         507 : css::uno::Reference<css::xml::dom::XDocument> BackendDb::getDocument()
      67             : {
      68         507 :     if (!m_doc.is())
      69             :     {
      70             :         const Reference<css::xml::dom::XDocumentBuilder> xDocBuilder(
      71         493 :             css::xml::dom::DocumentBuilder::create(m_xContext) );
      72             : 
      73         986 :         ::osl::DirectoryItem item;
      74         493 :         ::osl::File::RC err = ::osl::DirectoryItem::get(m_urlDb, item);
      75         493 :         if (err == ::osl::File::E_None)
      76             :         {
      77             :             ::ucbhelper::Content descContent(
      78             :                 m_urlDb, css::uno::Reference<css::ucb::XCommandEnvironment>(),
      79         170 :                 m_xContext);
      80         340 :             Reference<css::io::XInputStream> xIn = descContent.openStream();
      81         340 :             m_doc = xDocBuilder->parse(xIn);
      82             :         }
      83         323 :         else if (err == ::osl::File::E_NOENT)
      84             :         {
      85             :             //Create a new document and insert some basic stuff
      86         323 :             m_doc = xDocBuilder->newDocument();
      87             :             const Reference<css::xml::dom::XElement> rootNode =
      88        1615 :                 m_doc->createElementNS(getDbNSName(), getNSPrefix() +
      89        1615 :                                        ":" + getRootElementName());
      90             : 
      91         323 :             m_doc->appendChild(Reference<css::xml::dom::XNode>(
      92         323 :                                    rootNode, UNO_QUERY_THROW));
      93         323 :             save();
      94             :         }
      95             :         else
      96             :             throw css::uno::RuntimeException(
      97             :                 "Extension manager could not access database file:"
      98           0 :                 + m_urlDb, 0);
      99             : 
     100         493 :         if (!m_doc.is())
     101             :             throw css::uno::RuntimeException(
     102             :                 "Extension manager could not get root node of data base file: "
     103         493 :                       + m_urlDb, 0);
     104             :     }
     105             : 
     106         507 :     return m_doc;
     107             : }
     108             : 
     109         508 : Reference<css::xml::xpath::XXPathAPI> BackendDb::getXPathAPI()
     110             : {
     111         508 :     if (!m_xpathApi.is())
     112             :     {
     113         493 :         m_xpathApi = css::xml::xpath::XPathAPI::create( m_xContext );
     114             : 
     115         493 :         m_xpathApi->registerNS( getNSPrefix(), getDbNSName() );
     116             :     }
     117             : 
     118         508 :     return m_xpathApi;
     119             : }
     120             : 
     121           4 : void BackendDb::removeElement(OUString const & sXPathExpression)
     122             : {
     123             :     try
     124             :     {
     125           4 :         const Reference<css::xml::dom::XDocument> doc = getDocument();
     126           8 :         const Reference<css::xml::dom::XNode> root = doc->getFirstChild();
     127           8 :         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           8 :             xpathApi->selectSingleNode(root, sXPathExpression);
     131             : 
     132           4 :         if (aNode.is())
     133             :         {
     134           2 :             root->removeChild(aNode);
     135           2 :             save();
     136           4 :         }
     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           4 : }
     153             : 
     154           4 : void BackendDb::removeEntry(OUString const & url)
     155             : {
     156           4 :     const OUString sKeyElement = getKeyElementName();
     157           8 :     const OUString sPrefix = getNSPrefix();
     158           8 :     OUStringBuffer sExpression(500);
     159           4 :     sExpression.append(sPrefix);
     160           4 :     sExpression.appendAscii(":");
     161           4 :     sExpression.append(sKeyElement);
     162           4 :     sExpression.append("[@url = \"");
     163           4 :     sExpression.append(url);
     164           4 :     sExpression.appendAscii("\"]");
     165             : 
     166           8 :     removeElement(sExpression.makeStringAndClear());
     167           4 : }
     168             : 
     169           2 : void BackendDb::revokeEntry(OUString const & url)
     170             : {
     171             :     try
     172             :     {
     173           2 :         Reference<css::xml::dom::XElement> entry = Reference<css::xml::dom::XElement>(getKeyElement(url), UNO_QUERY);
     174           2 :         if (entry.is())
     175             :         {
     176           2 :             entry->setAttribute("revoked", "true");
     177           2 :             save();
     178           2 :         }
     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           2 : }
     188             : 
     189           2 : bool BackendDb::activateEntry(OUString const & url)
     190             : {
     191             :     try
     192             :     {
     193           2 :         bool ret = false;
     194           2 :         Reference<css::xml::dom::XElement> entry = Reference<css::xml::dom::XElement>(getKeyElement(url), UNO_QUERY);
     195           2 :         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           2 :         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           8 : Reference<css::xml::dom::XNode> BackendDb::getKeyElement(
     238             :     OUString const & url)
     239             : {
     240             :     try
     241             :     {
     242           8 :         const OUString sPrefix = getNSPrefix();
     243          16 :         const OUString sKeyElement = getKeyElementName();
     244          16 :         OUStringBuffer sExpression(500);
     245           8 :         sExpression.append(sPrefix);
     246           8 :         sExpression.appendAscii(":");
     247           8 :         sExpression.append(sKeyElement);
     248           8 :         sExpression.append("[@url = \"");
     249           8 :         sExpression.append(url);
     250           8 :         sExpression.appendAscii("\"]");
     251             : 
     252          16 :         const Reference<css::xml::dom::XDocument> doc = getDocument();
     253          16 :         const Reference<css::xml::dom::XNode> root = doc->getFirstChild();
     254          16 :         const Reference<css::xml::xpath::XXPathAPI> xpathApi = getXPathAPI();
     255          16 :         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           2 : 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           2 :         if (vecPairs.empty())
     277           3 :             return;
     278           1 :         const OUString sNameSpace = getDbNSName();
     279             :         OSL_ASSERT(!sNameSpace.isEmpty());
     280           2 :         const OUString sPrefix(getNSPrefix() + ":");
     281           2 :         const Reference<css::xml::dom::XDocument> doc = getDocument();
     282           2 :         const Reference<css::xml::dom::XNode> root = doc->getFirstChild();
     283             : 
     284             :         const Reference<css::xml::dom::XElement> vectorNode(
     285           2 :             doc->createElementNS(sNameSpace, sPrefix + sVectorTagName));
     286             : 
     287           1 :         xParent->appendChild(
     288             :             Reference<css::xml::dom::XNode>(
     289           1 :                 vectorNode, css::uno::UNO_QUERY_THROW));
     290             :         typedef ::std::vector< ::std::pair< OUString, OUString > >::const_iterator CIT;
     291           2 :         for (CIT i = vecPairs.begin(); i != vecPairs.end(); ++i)
     292             :         {
     293             :             const Reference<css::xml::dom::XElement> pairNode(
     294           1 :                 doc->createElementNS(sNameSpace, sPrefix + sPairTagName));
     295             : 
     296           1 :             vectorNode->appendChild(
     297             :                 Reference<css::xml::dom::XNode>(
     298           1 :                     pairNode, css::uno::UNO_QUERY_THROW));
     299             : 
     300             :             const Reference<css::xml::dom::XElement> firstNode(
     301           2 :                 doc->createElementNS(sNameSpace, sPrefix + sFirstTagName));
     302             : 
     303           1 :             pairNode->appendChild(
     304             :                 Reference<css::xml::dom::XNode>(
     305           1 :                     firstNode, css::uno::UNO_QUERY_THROW));
     306             : 
     307             :             const Reference<css::xml::dom::XText> firstTextNode(
     308           2 :                 doc->createTextNode( i->first));
     309             : 
     310           1 :             firstNode->appendChild(
     311             :                 Reference<css::xml::dom::XNode>(
     312           1 :                     firstTextNode, css::uno::UNO_QUERY_THROW));
     313             : 
     314             :             const Reference<css::xml::dom::XElement> secondNode(
     315           2 :                 doc->createElementNS(sNameSpace, sPrefix + sSecondTagName));
     316             : 
     317           1 :             pairNode->appendChild(
     318             :                 Reference<css::xml::dom::XNode>(
     319           1 :                     secondNode, css::uno::UNO_QUERY_THROW));
     320             : 
     321             :             const Reference<css::xml::dom::XText> secondTextNode(
     322           2 :                 doc->createTextNode( i->second));
     323             : 
     324           1 :             secondNode->appendChild(
     325             :                 Reference<css::xml::dom::XNode>(
     326           1 :                     secondTextNode, css::uno::UNO_QUERY_THROW));
     327           2 :         }
     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           2 : 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           2 :         const OUString sPrefix(getNSPrefix() + ":");
     350           4 :         const Reference<css::xml::xpath::XXPathAPI> xpathApi = getXPathAPI();
     351             :         const OUString sExprPairs(
     352           4 :             sPrefix + sListTagName + "/" + sPrefix + sPairTagName);
     353             :         const Reference<css::xml::dom::XNodeList> listPairs =
     354           4 :             xpathApi->selectNodeList(parent, sExprPairs);
     355             : 
     356           4 :         ::std::vector< ::std::pair< OUString, OUString > > retVector;
     357           2 :         sal_Int32 length = listPairs->getLength();
     358           3 :         for (sal_Int32 i = 0; i < length; i++)
     359             :         {
     360           1 :             const Reference<css::xml::dom::XNode> aPair = listPairs->item(i);
     361           2 :             const OUString sExprFirst(sPrefix + sFirstTagName + "/text()");
     362             :             const Reference<css::xml::dom::XNode> first =
     363           2 :                 xpathApi->selectSingleNode(aPair, sExprFirst);
     364             : 
     365           2 :             const OUString sExprSecond(sPrefix + sSecondTagName + "/text()");
     366             :             const Reference<css::xml::dom::XNode> second =
     367           2 :                 xpathApi->selectSingleNode(aPair, sExprSecond);
     368             :             OSL_ASSERT(first.is() && second.is());
     369             : 
     370             :             retVector.push_back(::std::make_pair(
     371           1 :                                     first->getNodeValue(), second->getNodeValue()));
     372           1 :         }
     373           4 :         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           1 : 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           1 :         if (list.empty())
     394           1 :             return;
     395           1 :         const OUString sNameSpace = getDbNSName();
     396           2 :         const OUString sPrefix(getNSPrefix() + ":");
     397           2 :         const Reference<css::xml::dom::XDocument> doc = getDocument();
     398             : 
     399             :         const Reference<css::xml::dom::XElement> listNode(
     400           2 :             doc->createElementNS(sNameSpace, sPrefix + sListTagName));
     401             : 
     402           1 :         xParent->appendChild(
     403             :             Reference<css::xml::dom::XNode>(
     404           1 :                 listNode, css::uno::UNO_QUERY_THROW));
     405             : 
     406             :         typedef ::std::list<OUString>::const_iterator ITC_ITEMS;
     407           2 :         for (ITC_ITEMS i = list.begin(); i != list.end(); ++i)
     408             :         {
     409             :             const Reference<css::xml::dom::XNode> memberNode(
     410           1 :                 doc->createElementNS(sNameSpace, sPrefix + sMemberTagName), css::uno::UNO_QUERY_THROW);
     411             : 
     412           1 :             listNode->appendChild(memberNode);
     413             : 
     414             :             const Reference<css::xml::dom::XNode> textNode(
     415           2 :                 doc->createTextNode( *i), css::uno::UNO_QUERY_THROW);
     416             : 
     417           1 :             memberNode->appendChild(textNode);
     418           2 :         }
     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           1 : void BackendDb::writeSimpleElement(
     432             :     OUString const & sElementName, OUString const & value,
     433             :     Reference<css::xml::dom::XNode> const & xParent)
     434             : {
     435             :     try
     436             :     {
     437           1 :         if (value.isEmpty())
     438           1 :             return;
     439           1 :         const OUString sPrefix = getNSPrefix();
     440           2 :         const Reference<css::xml::dom::XDocument> doc = getDocument();
     441           2 :         const OUString sNameSpace = getDbNSName();
     442             :         const Reference<css::xml::dom::XNode> dataNode(
     443           2 :             doc->createElementNS(sNameSpace, sPrefix + ":" + sElementName),
     444           2 :             UNO_QUERY_THROW);
     445           1 :         xParent->appendChild(dataNode);
     446             : 
     447             :         const Reference<css::xml::dom::XNode> dataValue(
     448           2 :             doc->createTextNode(value), UNO_QUERY_THROW);
     449           2 :         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           2 : Reference<css::xml::dom::XNode> BackendDb::writeKeyElement(
     465             :     OUString const & url)
     466             : {
     467             :     try
     468             :     {
     469           2 :         const OUString sNameSpace = getDbNSName();
     470           4 :         const OUString sPrefix = getNSPrefix();
     471           4 :         const OUString sElementName = getKeyElementName();
     472           4 :         const Reference<css::xml::dom::XDocument> doc = getDocument();
     473           4 :         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           4 :             sPrefix + ":" + sElementName + "[@url = \"" + url + "\"]");
     484             :         const Reference<css::xml::dom::XNode> existingNode =
     485           4 :             getXPathAPI()->selectSingleNode(root, sExpression);
     486           2 :         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           4 :             doc->createElementNS(sNameSpace, sPrefix +  ":" + sElementName));
     495             : 
     496           2 :         keyElement->setAttribute("url", url);
     497             : 
     498             :         const Reference<css::xml::dom::XNode> keyNode(
     499           4 :             keyElement, UNO_QUERY_THROW);
     500           2 :         root->appendChild(keyNode);
     501           4 :         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           1 : OUString BackendDb::readSimpleElement(
     513             :     OUString const & sElementName, Reference<css::xml::dom::XNode> const & xParent)
     514             : {
     515             :     try
     516             :     {
     517           1 :         const OUString sPrefix = getNSPrefix();
     518           2 :         const OUString sExpr(sPrefix + ":" + sElementName + "/text()");
     519           2 :         const Reference<css::xml::xpath::XXPathAPI> xpathApi = getXPathAPI();
     520             :         const Reference<css::xml::dom::XNode> val =
     521           2 :             xpathApi->selectSingleNode(xParent, sExpr);
     522           1 :         if (val.is())
     523           1 :             return val->getNodeValue();
     524           1 :         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           1 : ::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           1 :         const OUString sPrefix(getNSPrefix() + ":");
     545           2 :         const Reference<css::xml::xpath::XXPathAPI> xpathApi = getXPathAPI();
     546             :         const OUString sExprList(
     547           2 :             sPrefix + sListTagName + "/" + sPrefix + sMemberTagName + "/text()");
     548             :         const Reference<css::xml::dom::XNodeList> list =
     549           2 :             xpathApi->selectNodeList(parent, sExprList);
     550             : 
     551           2 :         ::std::list<OUString > retList;
     552           1 :         sal_Int32 length = list->getLength();
     553           2 :         for (sal_Int32 i = 0; i < length; i++)
     554             :         {
     555           1 :             const Reference<css::xml::dom::XNode> member = list->item(i);
     556           1 :             retList.push_back(member->getNodeValue());
     557           1 :         }
     558           2 :         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         245 : ::std::list<OUString> BackendDb::getOneChildFromAllEntries(
     570             :     OUString const & name)
     571             : {
     572             :     try
     573             :     {
     574         245 :         ::std::list<OUString> listRet;
     575         490 :         Reference<css::xml::dom::XDocument> doc = getDocument();
     576         490 :         Reference<css::xml::dom::XNode> root = doc->getFirstChild();
     577             : 
     578         490 :         Reference<css::xml::xpath::XXPathAPI> xpathApi = getXPathAPI();
     579         490 :         const OUString sPrefix = getNSPrefix();
     580         490 :         const OUString sKeyElement = getKeyElementName();
     581         490 :         OUStringBuffer buf(512);
     582         245 :         buf.append(sPrefix);
     583         245 :         buf.appendAscii(":");
     584         245 :         buf.append(sKeyElement);
     585         245 :         buf.appendAscii("/");
     586         245 :         buf.append(sPrefix);
     587         245 :         buf.appendAscii(":");
     588         245 :         buf.append(name);
     589         245 :         buf.append("/text()");
     590             : 
     591             :         Reference<css::xml::dom::XNodeList> nodes =
     592         490 :             xpathApi->selectNodeList(root, buf.makeStringAndClear());
     593         245 :         if (nodes.is())
     594             :         {
     595         245 :             sal_Int32 length = nodes->getLength();
     596         245 :             for (sal_Int32 i = 0; i < length; i++)
     597           0 :                 listRet.push_back(nodes->item(i)->getNodeValue());
     598             :         }
     599         490 :         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         490 : RegisteredDb::RegisteredDb(
     616             :     Reference<XComponentContext> const &  xContext,
     617         490 :     OUString const & url):BackendDb(xContext, url)
     618             : {
     619         490 : }
     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: */

Generated by: LCOV version 1.10