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

Generated by: LCOV version 1.10