cid#1607171 Data race condition
[LibreOffice.git] / desktop / source / deployment / registry / help / dp_helpbackenddb.cxx
blob19bb3c3ce51c8164c48dcc8a7772f99be10685f3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
25 #include "dp_helpbackenddb.hxx"
28 using namespace ::com::sun::star::uno;
30 constexpr OUStringLiteral EXTENSION_REG_NS = u"http://openoffice.org/extensionmanager/help-registry/2010";
31 constexpr OUStringLiteral NS_PREFIX = u"help";
32 constexpr OUStringLiteral ROOT_ELEMENT_NAME = u"help-backend-db";
33 constexpr OUStringLiteral KEY_ELEMENT_NAME = u"help";
35 namespace dp_registry::backend::help {
37 HelpBackendDb::HelpBackendDb(
38 Reference<XComponentContext> const & xContext,
39 OUString const & url):BackendDb(xContext, url)
44 OUString HelpBackendDb::getDbNSName()
46 return EXTENSION_REG_NS;
49 OUString HelpBackendDb::getNSPrefix()
51 return NS_PREFIX;
54 OUString HelpBackendDb::getRootElementName()
56 return ROOT_ELEMENT_NAME;
59 OUString HelpBackendDb::getKeyElementName()
61 return KEY_ELEMENT_NAME;
65 void HelpBackendDb::addEntry(OUString const & url, Data const & data)
67 try{
68 if (!activateEntry(url))
70 Reference<css::xml::dom::XNode> helpNode
71 = writeKeyElement(url);
73 writeSimpleElement(u"data-url", data.dataUrl, helpNode);
74 save();
77 catch ( const css::deployment::DeploymentException& )
79 throw;
81 catch(const css::uno::Exception &)
83 Any exc( ::cppu::getCaughtException() );
84 throw css::deployment::DeploymentException(
85 "Extension Manager: failed to write data entry in help backend db: " + m_urlDb, nullptr, exc);
90 ::std::optional<HelpBackendDb::Data>
91 HelpBackendDb::getEntry(std::u16string_view url)
93 try
95 HelpBackendDb::Data retData;
96 Reference<css::xml::dom::XNode> aNode = getKeyElement(url);
97 if (aNode.is())
99 retData.dataUrl = readSimpleElement(u"data-url", aNode);
101 else
103 return ::std::optional<Data>();
105 return ::std::optional<Data>(retData);
107 catch ( const css::deployment::DeploymentException& )
109 throw;
111 catch(const css::uno::Exception &)
113 Any exc( ::cppu::getCaughtException() );
114 throw css::deployment::DeploymentException(
115 "Extension Manager: failed to read data entry in help backend db: " + m_urlDb, nullptr, exc);
119 std::vector<OUString> HelpBackendDb::getAllDataUrls()
121 return getOneChildFromAllEntries(u"data-url");
124 } // namespace dp_registry::backend::help
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */