LibreOffice Module desktop (master) 1
dp_extbackenddb.cxx
Go to the documentation of this file.
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
22#include <com/sun/star/deployment/DeploymentException.hpp>
23#include <com/sun/star/uno/XComponentContext.hpp>
24
25#include "dp_extbackenddb.hxx"
26
27
28using namespace ::com::sun::star::uno;
29
30constexpr OUStringLiteral EXTENSION_REG_NS = u"http://openoffice.org/extensionmanager/extension-registry/2010";
31constexpr OUStringLiteral NS_PREFIX = u"ext";
32constexpr OUStringLiteral ROOT_ELEMENT_NAME = u"extension-backend-db";
33constexpr OUStringLiteral KEY_ELEMENT_NAME = u"extension";
34
36
38 Reference<XComponentContext> const & xContext,
39 OUString const & url):BackendDb(xContext, url)
40{
41
42}
43
45{
46 return EXTENSION_REG_NS;
47}
48
50{
51 return NS_PREFIX;
52}
53
55{
56 return ROOT_ELEMENT_NAME;
57}
58
60{
61 return KEY_ELEMENT_NAME;
62}
63
64void ExtensionBackendDb::addEntry(OUString const & url, Data const & data)
65{
66 try{
67 //reactive revoked entry if possible.
68 if (!activateEntry(url))
69 {
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();
74 }
75 }
76 catch(const css::uno::Exception &)
77 {
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);
82 }
83}
84
86{
87 try
88 {
90 Reference<css::xml::dom::XNode> aNode = getKeyElement(url);
91
92 if (aNode.is())
93 {
94 retData.items =
95 readVectorOfPair( aNode, u"extension-items", u"item",
96 u"url", u"media-type");
97 }
98 return retData;
99 }
100 catch(const css::uno::Exception &)
101 {
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);
106 }
107}
108
109} // namespace dp_registry::backend::bundle
110
111/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< std::pair< OUString, OUString > > readVectorOfPair(css::uno::Reference< css::xml::dom::XNode > const &parent, std::u16string_view sListTagName, std::u16string_view sPairTagName, std::u16string_view sFirstTagName, std::u16string_view sSecondTagName)
css::uno::Reference< css::xml::dom::XNode > writeKeyElement(OUString const &url)
The key elements have a url attribute and are always children of the root element.
css::uno::Reference< css::xml::dom::XNode > getKeyElement(std::u16string_view url)
void writeVectorOfPair(std::vector< std::pair< OUString, OUString > > const &vecPairs, std::u16string_view sVectorTagName, std::u16string_view sPairTagName, std::u16string_view sFirstTagName, std::u16string_view sSecondTagName, css::uno::Reference< css::xml::dom::XNode > const &xParent)
bool activateEntry(std::u16string_view url)
ExtensionBackendDb(css::uno::Reference< css::uno::XComponentContext > const &xContext, OUString const &url)
void addEntry(OUString const &url, Data const &data)
constexpr OUStringLiteral EXTENSION_REG_NS
constexpr OUStringLiteral NS_PREFIX
constexpr OUStringLiteral KEY_ELEMENT_NAME
constexpr OUStringLiteral ROOT_ELEMENT_NAME
float u
static uno::Reference< css::uno::XComponentContext > xContext
Definition: init.cxx:2642
std::vector< std::pair< OUString, OUString > > items