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 <cppuhelper/exc_hlp.hxx>
22 #include <com/sun/star/deployment/DeploymentException.hpp>
23 #include <com/sun/star/uno/XComponentContext.hpp>
24 #include <com/sun/star/xml/xpath/XXPathAPI.hpp>
26 #include "dp_configurationbackenddb.hxx"
29 using namespace ::com::sun::star::uno
;
31 constexpr OUStringLiteral EXTENSION_REG_NS
= u
"http://openoffice.org/extensionmanager/configuration-registry/2010";
32 constexpr OUStringLiteral NS_PREFIX
= u
"conf";
33 constexpr OUStringLiteral ROOT_ELEMENT_NAME
= u
"configuration-backend-db";
34 constexpr OUStringLiteral KEY_ELEMENT_NAME
= u
"configuration";
36 namespace dp_registry::backend::configuration
{
38 ConfigurationBackendDb::ConfigurationBackendDb(
39 Reference
<XComponentContext
> const & xContext
,
40 OUString
const & url
):BackendDb(xContext
, url
)
45 OUString
ConfigurationBackendDb::getDbNSName()
47 return EXTENSION_REG_NS
;
50 OUString
ConfigurationBackendDb::getNSPrefix()
55 OUString
ConfigurationBackendDb::getRootElementName()
57 return ROOT_ELEMENT_NAME
;
60 OUString
ConfigurationBackendDb::getKeyElementName()
62 return KEY_ELEMENT_NAME
;
66 void ConfigurationBackendDb::addEntry(OUString
const & url
, Data
const & data
)
69 if (!activateEntry(url
))
71 Reference
<css::xml::dom::XNode
> helpNode
72 = writeKeyElement(url
);
74 writeSimpleElement(u
"data-url", data
.dataUrl
, helpNode
);
75 writeSimpleElement(u
"ini-entry", data
.iniEntry
, helpNode
);
79 catch ( const css::deployment::DeploymentException
& )
83 catch(const css::uno::Exception
&)
85 Any
exc( ::cppu::getCaughtException() );
86 throw css::deployment::DeploymentException(
87 "Extension Manager: failed to write data entry in configuration backend db: " +
88 m_urlDb
, nullptr, exc
);
93 ::std::optional
<ConfigurationBackendDb::Data
>
94 ConfigurationBackendDb::getEntry(std::u16string_view url
)
98 ConfigurationBackendDb::Data retData
;
99 Reference
<css::xml::dom::XNode
> aNode
= getKeyElement(url
);
102 retData
.dataUrl
= readSimpleElement(u
"data-url", aNode
);
103 retData
.iniEntry
= readSimpleElement(u
"ini-entry", aNode
);
107 return ::std::optional
<Data
>();
109 return ::std::optional
<Data
>(retData
);
111 catch ( const css::deployment::DeploymentException
& )
115 catch(const css::uno::Exception
&)
117 Any
exc( ::cppu::getCaughtException() );
118 throw css::deployment::DeploymentException(
119 "Extension Manager: failed to read data entry in configuration backend db: " +
120 m_urlDb
, nullptr, exc
);
124 std::vector
<OUString
> ConfigurationBackendDb::getAllDataUrls()
128 std::vector
<OUString
> listRet
;
129 Reference
<css::xml::dom::XDocument
> doc
= getDocument();
130 Reference
<css::xml::dom::XNode
> root
= doc
->getFirstChild();
132 Reference
<css::xml::xpath::XXPathAPI
> xpathApi
= getXPathAPI();
133 const OUString sPrefix
= getNSPrefix();
134 OUString
sExpression(
135 sPrefix
+ ":configuration/" + sPrefix
+ ":data-url/text()");
136 Reference
<css::xml::dom::XNodeList
> nodes
=
137 xpathApi
->selectNodeList(root
, sExpression
);
140 sal_Int32 length
= nodes
->getLength();
141 for (sal_Int32 i
= 0; i
< length
; i
++)
142 listRet
.push_back(nodes
->item(i
)->getNodeValue());
146 catch ( const css::deployment::DeploymentException
& )
150 catch(const css::uno::Exception
&)
152 Any
exc( ::cppu::getCaughtException() );
153 throw css::deployment::DeploymentException(
154 "Extension Manager: failed to read data entry in configuration backend db: " +
155 m_urlDb
, nullptr, exc
);
159 } // namespace dp_registry::backend::configuration
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */