cid#1607171 Data race condition
[LibreOffice.git] / desktop / source / deployment / registry / package / dp_extbackenddb.cxx
blob8e656c5d7dc8aee5ddeebc7407436af99b69f66a
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_extbackenddb.hxx"
28 using namespace ::com::sun::star::uno;
30 constexpr OUStringLiteral EXTENSION_REG_NS = u"http://openoffice.org/extensionmanager/extension-registry/2010";
31 constexpr OUStringLiteral NS_PREFIX = u"ext";
32 constexpr OUStringLiteral ROOT_ELEMENT_NAME = u"extension-backend-db";
33 constexpr OUStringLiteral KEY_ELEMENT_NAME = u"extension";
35 namespace dp_registry::backend::bundle {
37 ExtensionBackendDb::ExtensionBackendDb(
38 Reference<XComponentContext> const & xContext,
39 OUString const & url):BackendDb(xContext, url)
44 OUString ExtensionBackendDb::getDbNSName()
46 return EXTENSION_REG_NS;
49 OUString ExtensionBackendDb::getNSPrefix()
51 return NS_PREFIX;
54 OUString ExtensionBackendDb::getRootElementName()
56 return ROOT_ELEMENT_NAME;
59 OUString ExtensionBackendDb::getKeyElementName()
61 return KEY_ELEMENT_NAME;
64 void ExtensionBackendDb::addEntry(OUString const & url, Data const & data)
66 try{
67 //reactive revoked entry if possible.
68 if (!activateEntry(url))
70 Reference<css::xml::dom::XNode> extensionNodeNode = writeKeyElement(url);
71 writeVectorOfPair( data.items, u"extension-items", u"item",
72 u"url", u"media-type", extensionNodeNode);
73 save();
76 catch(const css::uno::Exception &)
78 Any exc( ::cppu::getCaughtException() );
79 throw css::deployment::DeploymentException(
80 "Extension Manager: failed to write data entry in backend db: " +
81 m_urlDb, nullptr, exc);
85 ExtensionBackendDb::Data ExtensionBackendDb::getEntry(std::u16string_view url)
87 try
89 ExtensionBackendDb::Data retData;
90 Reference<css::xml::dom::XNode> aNode = getKeyElement(url);
92 if (aNode.is())
94 retData.items =
95 readVectorOfPair( aNode, u"extension-items", u"item",
96 u"url", u"media-type");
98 return retData;
100 catch(const css::uno::Exception &)
102 Any exc( ::cppu::getCaughtException() );
103 throw css::deployment::DeploymentException(
104 "Extension Manager: failed to read data entry in backend db: " +
105 m_urlDb, nullptr, exc);
109 } // namespace dp_registry::backend::bundle
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */