1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <rtl/string.h>
22 #include <rtl/bootstrap.hxx>
23 #include <cppuhelper/exc_hlp.hxx>
24 #include <com/sun/star/deployment/DeploymentException.hpp>
25 #include <com/sun/star/uno/XComponentContext.hpp>
26 #include <com/sun/star/xml/dom/XDocumentBuilder.hpp>
27 #include <com/sun/star/xml/xpath/XXPathAPI.hpp>
30 #include "dp_configurationbackenddb.hxx"
33 using namespace ::com::sun::star::uno
;
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"
40 namespace dp_registry
{
42 namespace configuration
{
44 ConfigurationBackendDb::ConfigurationBackendDb(
45 Reference
<XComponentContext
> const & xContext
,
46 OUString
const & url
):BackendDb(xContext
, url
)
51 OUString
ConfigurationBackendDb::getDbNSName()
53 return EXTENSION_REG_NS
;
56 OUString
ConfigurationBackendDb::getNSPrefix()
61 OUString
ConfigurationBackendDb::getRootElementName()
63 return ROOT_ELEMENT_NAME
;
66 OUString
ConfigurationBackendDb::getKeyElementName()
68 return KEY_ELEMENT_NAME
;
72 void ConfigurationBackendDb::addEntry(OUString
const & url
, Data
const & data
)
75 if (!activateEntry(url
))
77 Reference
<css::xml::dom::XNode
> helpNode
78 = writeKeyElement(url
);
80 writeSimpleElement("data-url", data
.dataUrl
, helpNode
);
81 writeSimpleElement("ini-entry", data
.iniEntry
, helpNode
);
85 catch ( const css::deployment::DeploymentException
& )
89 catch(const css::uno::Exception
&)
91 Any
exc( ::cppu::getCaughtException() );
92 throw css::deployment::DeploymentException(
93 "Extension Manager: failed to write data entry in configuration backend db: " +
94 m_urlDb
, nullptr, exc
);
99 ::boost::optional
<ConfigurationBackendDb::Data
>
100 ConfigurationBackendDb::getEntry(OUString
const & url
)
104 ConfigurationBackendDb::Data retData
;
105 Reference
<css::xml::dom::XNode
> aNode
= getKeyElement(url
);
108 retData
.dataUrl
= readSimpleElement("data-url", aNode
);
109 retData
.iniEntry
= readSimpleElement("ini-entry", aNode
);
113 return ::boost::optional
<Data
>();
115 return ::boost::optional
<Data
>(retData
);
117 catch ( const css::deployment::DeploymentException
& )
121 catch(const css::uno::Exception
&)
123 Any
exc( ::cppu::getCaughtException() );
124 throw css::deployment::DeploymentException(
125 "Extension Manager: failed to read data entry in configuration backend db: " +
126 m_urlDb
, nullptr, exc
);
130 std::vector
<OUString
> ConfigurationBackendDb::getAllDataUrls()
134 std::vector
<OUString
> listRet
;
135 Reference
<css::xml::dom::XDocument
> doc
= getDocument();
136 Reference
<css::xml::dom::XNode
> root
= doc
->getFirstChild();
138 Reference
<css::xml::xpath::XXPathAPI
> xpathApi
= getXPathAPI();
139 const OUString sPrefix
= getNSPrefix();
140 OUString
sExpression(
141 sPrefix
+ ":configuration/" + sPrefix
+ ":data-url/text()");
142 Reference
<css::xml::dom::XNodeList
> nodes
=
143 xpathApi
->selectNodeList(root
, sExpression
);
146 sal_Int32 length
= nodes
->getLength();
147 for (sal_Int32 i
= 0; i
< length
; i
++)
148 listRet
.push_back(nodes
->item(i
)->getNodeValue());
152 catch ( const css::deployment::DeploymentException
& )
156 catch(const css::uno::Exception
&)
158 Any
exc( ::cppu::getCaughtException() );
159 throw css::deployment::DeploymentException(
160 "Extension Manager: failed to read data entry in configuration backend db: " +
161 m_urlDb
, nullptr, exc
);
165 } // namespace configuration
166 } // namespace backend
167 } // namespace dp_registry
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */