LibreOffice Module desktop (master) 1
dp_helpbackenddb.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_helpbackenddb.hxx"
26
27
28using namespace ::com::sun::star::uno;
29
30constexpr OUStringLiteral EXTENSION_REG_NS = u"http://openoffice.org/extensionmanager/help-registry/2010";
31constexpr OUStringLiteral NS_PREFIX = u"help";
32constexpr OUStringLiteral ROOT_ELEMENT_NAME = u"help-backend-db";
33constexpr OUStringLiteral KEY_ELEMENT_NAME = u"help";
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
64
65void HelpBackendDb::addEntry(OUString const & url, Data const & data)
66{
67 try{
68 if (!activateEntry(url))
69 {
70 Reference<css::xml::dom::XNode> helpNode
71 = writeKeyElement(url);
72
73 writeSimpleElement(u"data-url", data.dataUrl, helpNode);
74 save();
75 }
76 }
77 catch ( const css::deployment::DeploymentException& )
78 {
79 throw;
80 }
81 catch(const css::uno::Exception &)
82 {
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);
86 }
87}
88
89
90::std::optional<HelpBackendDb::Data>
91HelpBackendDb::getEntry(std::u16string_view url)
92{
93 try
94 {
95 HelpBackendDb::Data retData;
96 Reference<css::xml::dom::XNode> aNode = getKeyElement(url);
97 if (aNode.is())
98 {
99 retData.dataUrl = readSimpleElement(u"data-url", aNode);
100 }
101 else
102 {
103 return ::std::optional<Data>();
104 }
105 return ::std::optional<Data>(retData);
106 }
107 catch ( const css::deployment::DeploymentException& )
108 {
109 throw;
110 }
111 catch(const css::uno::Exception &)
112 {
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);
116 }
117}
118
119std::vector<OUString> HelpBackendDb::getAllDataUrls()
120{
121 return getOneChildFromAllEntries(u"data-url");
122}
123
124} // namespace dp_registry::backend::help
125
126/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void writeSimpleElement(std::u16string_view sElementName, OUString const &value, css::uno::Reference< css::xml::dom::XNode > const &xParent)
OUString readSimpleElement(std::u16string_view sElementName, css::uno::Reference< css::xml::dom::XNode > const &xParent)
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.
std::vector< OUString > getOneChildFromAllEntries(std::u16string_view sElementName)
css::uno::Reference< css::xml::dom::XNode > getKeyElement(std::u16string_view url)
bool activateEntry(std::u16string_view url)
virtual OUString getRootElementName() override
void addEntry(OUString const &url, Data const &data)
HelpBackendDb(css::uno::Reference< css::uno::XComponentContext > const &xContext, OUString const &url)
virtual OUString getKeyElementName() override
::std::optional< Data > getEntry(std::u16string_view url)
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