LCOV - code coverage report
Current view: top level - desktop/source/deployment/registry/configuration - dp_configurationbackenddb.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 21 57 36.8 %
Date: 2015-06-13 12:38:46 Functions: 5 8 62.5 %
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/bootstrap.hxx>
      23             : #include <cppuhelper/exc_hlp.hxx>
      24             : #include <com/sun/star/uno/XComponentContext.hpp>
      25             : #include <com/sun/star/xml/dom/XDocumentBuilder.hpp>
      26             : #include <com/sun/star/xml/xpath/XXPathAPI.hpp>
      27             : #include "dp_misc.h"
      28             : 
      29             : #include "dp_configurationbackenddb.hxx"
      30             : 
      31             : 
      32             : using namespace ::com::sun::star::uno;
      33             : 
      34             : #define EXTENSION_REG_NS "http://openoffice.org/extensionmanager/configuration-registry/2010"
      35             : #define NS_PREFIX "conf"
      36             : #define ROOT_ELEMENT_NAME "configuration-backend-db"
      37             : #define KEY_ELEMENT_NAME "configuration"
      38             : 
      39             : namespace dp_registry {
      40             : namespace backend {
      41             : namespace configuration {
      42             : 
      43         392 : ConfigurationBackendDb::ConfigurationBackendDb(
      44             :     Reference<XComponentContext> const &  xContext,
      45         392 :     OUString const & url):BackendDb(xContext, url)
      46             : {
      47             : 
      48         392 : }
      49             : 
      50         657 : OUString ConfigurationBackendDb::getDbNSName()
      51             : {
      52         657 :     return OUString(EXTENSION_REG_NS);
      53             : }
      54             : 
      55        1049 : OUString ConfigurationBackendDb::getNSPrefix()
      56             : {
      57        1049 :     return OUString(NS_PREFIX);
      58             : }
      59             : 
      60         265 : OUString ConfigurationBackendDb::getRootElementName()
      61             : {
      62         265 :     return OUString(ROOT_ELEMENT_NAME);
      63             : }
      64             : 
      65           0 : OUString ConfigurationBackendDb::getKeyElementName()
      66             : {
      67           0 :     return OUString(KEY_ELEMENT_NAME);
      68             : }
      69             : 
      70             : 
      71           0 : void ConfigurationBackendDb::addEntry(OUString const & url, Data const & data)
      72             : {
      73             :     try{
      74           0 :         if (!activateEntry(url))
      75             :         {
      76             :             Reference<css::xml::dom::XNode> helpNode
      77           0 :                 = writeKeyElement(url);
      78             : 
      79           0 :             writeSimpleElement("data-url", data.dataUrl, helpNode);
      80           0 :             writeSimpleElement("ini-entry", data.iniEntry, helpNode);
      81           0 :             save();
      82             :         }
      83             :     }
      84           0 :     catch ( const css::deployment::DeploymentException& )
      85             :     {
      86           0 :         throw;
      87             :     }
      88           0 :     catch(const css::uno::Exception &)
      89             :     {
      90           0 :         Any exc( ::cppu::getCaughtException() );
      91             :         throw css::deployment::DeploymentException(
      92           0 :             "Extension Manager: failed to write data entry in configuration backend db: " +
      93           0 :             m_urlDb, 0, exc);
      94             :     }
      95           0 : }
      96             : 
      97             : 
      98             : ::boost::optional<ConfigurationBackendDb::Data>
      99           0 : ConfigurationBackendDb::getEntry(OUString const & url)
     100             : {
     101             :     try
     102             :     {
     103           0 :         ConfigurationBackendDb::Data retData;
     104           0 :         Reference<css::xml::dom::XNode> aNode = getKeyElement(url);
     105           0 :         if (aNode.is())
     106             :         {
     107           0 :             retData.dataUrl = readSimpleElement("data-url", aNode);
     108           0 :             retData.iniEntry = readSimpleElement("ini-entry", aNode);
     109             :         }
     110             :         else
     111             :         {
     112           0 :             return ::boost::optional<Data>();
     113             :         }
     114           0 :         return ::boost::optional<Data>(retData);
     115             :     }
     116           0 :     catch ( const css::deployment::DeploymentException& )
     117             :     {
     118           0 :         throw;
     119             :     }
     120           0 :     catch(const css::uno::Exception &)
     121             :     {
     122           0 :         Any exc( ::cppu::getCaughtException() );
     123             :         throw css::deployment::DeploymentException(
     124           0 :             "Extension Manager: failed to read data entry in configuration backend db: " +
     125           0 :             m_urlDb, 0, exc);
     126             :     }
     127             : }
     128             : 
     129         392 : ::std::list<OUString> ConfigurationBackendDb::getAllDataUrls()
     130             : {
     131             :     try
     132             :     {
     133         392 :         ::std::list<OUString> listRet;
     134         784 :         Reference<css::xml::dom::XDocument> doc = getDocument();
     135         784 :         Reference<css::xml::dom::XNode> root = doc->getFirstChild();
     136             : 
     137         784 :         Reference<css::xml::xpath::XXPathAPI> xpathApi = getXPathAPI();
     138         784 :         const OUString sPrefix = getNSPrefix();
     139             :         OUString sExpression(
     140         784 :             sPrefix + ":configuration/" + sPrefix + ":data-url/text()");
     141             :         Reference<css::xml::dom::XNodeList> nodes =
     142         784 :             xpathApi->selectNodeList(root, sExpression);
     143         392 :         if (nodes.is())
     144             :         {
     145         392 :             sal_Int32 length = nodes->getLength();
     146         392 :             for (sal_Int32 i = 0; i < length; i++)
     147           0 :                 listRet.push_back(nodes->item(i)->getNodeValue());
     148             :         }
     149         784 :         return listRet;
     150             :     }
     151           0 :     catch ( const css::deployment::DeploymentException& )
     152             :     {
     153           0 :         throw;
     154             :     }
     155           0 :     catch(const css::uno::Exception &)
     156             :     {
     157           0 :         Any exc( ::cppu::getCaughtException() );
     158             :         throw css::deployment::DeploymentException(
     159           0 :             "Extension Manager: failed to read data entry in configuration backend db: " +
     160           0 :             m_urlDb, 0, exc);
     161             :     }
     162             : }
     163             : 
     164             : } // namespace configuration
     165             : } // namespace backend
     166             : } // namespace dp_registry
     167             : 
     168             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11