LCOV - code coverage report
Current view: top level - desktop/source/deployment/registry - dp_backenddb.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 240 303 79.2 %
Date: 2012-08-25 Functions: 20 21 95.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 313 809 38.7 %

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

Generated by: LCOV version 1.10