LibreOffice Module desktop (master)  1
dp_backenddb.hxx
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 #pragma once
21 
22 #include <com/sun/star/uno/Reference.hxx>
23 #include <rtl/ustring.hxx>
24 #include <deque>
25 #include <string_view>
26 #include <vector>
27 
28 namespace com::sun::star {
29  namespace uno {
30  class XComponentContext;
31  }
32  namespace xml::dom {
33  class XDocument;
34  class XNode;
35  }
36  namespace xml::xpath {
37  class XXPathAPI;
38  }
39 }
40 
41 namespace dp_registry::backend {
42 
43 class BackendDb
44 {
45 private:
46 
47  css::uno::Reference<css::xml::dom::XDocument> m_doc;
48  css::uno::Reference<css::xml::xpath::XXPathAPI> m_xpathApi;
49 
50  BackendDb(BackendDb const &) = delete;
51  BackendDb & operator = (BackendDb const &) = delete;
52 
53 protected:
54  const css::uno::Reference<css::uno::XComponentContext> m_xContext;
55  OUString m_urlDb;
56 
57 protected:
58 
59  /* caller must make sure that only one thread accesses the function
60  */
61  css::uno::Reference<css::xml::dom::XDocument> const & getDocument();
62 
63  /* the namespace prefix is "reg" (without quotes)
64  */
65  css::uno::Reference<css::xml::xpath::XXPathAPI> const & getXPathAPI();
66  void save();
67  void removeElement(OUString const & sXPathExpression);
68 
69  css::uno::Reference<css::xml::dom::XNode> getKeyElement(
70  std::u16string_view url);
71 
72  void writeSimpleList(
73  std::deque< OUString> const & list,
74  std::u16string_view sListTagName,
75  std::u16string_view sMemberTagName,
76  css::uno::Reference<css::xml::dom::XNode> const & xParent);
77 
78  void writeVectorOfPair(
79  std::vector< std::pair< OUString, OUString > > const & vecPairs,
80  std::u16string_view sVectorTagName,
81  std::u16string_view sPairTagName,
82  std::u16string_view sFirstTagName,
83  std::u16string_view sSecondTagName,
84  css::uno::Reference<css::xml::dom::XNode> const & xParent);
85 
86  void writeSimpleElement(
87  std::u16string_view sElementName, OUString const & value,
88  css::uno::Reference<css::xml::dom::XNode> const & xParent);
89 
90  css::uno::Reference<css::xml::dom::XNode> writeKeyElement(
91  OUString const & url);
92 
93  OUString readSimpleElement(
94  std::u16string_view sElementName,
95  css::uno::Reference<css::xml::dom::XNode> const & xParent);
96 
97  std::vector< std::pair< OUString, OUString > >
99  css::uno::Reference<css::xml::dom::XNode> const & parent,
100  std::u16string_view sListTagName,
101  std::u16string_view sPairTagName,
102  std::u16string_view sFirstTagName,
103  std::u16string_view sSecondTagName);
104 
105  std::deque< OUString> readList(
106  css::uno::Reference<css::xml::dom::XNode> const & parent,
107  std::u16string_view sListTagName,
108  std::u16string_view sMemberTagName);
109 
110  /* returns the values of one particularly child element of all key elements.
111  */
112  std::vector< OUString> getOneChildFromAllEntries(
113  std::u16string_view sElementName);
114 
115 
116  /* returns the namespace which is to be written as xmlns attribute
117  into the root element.
118  */
119  virtual OUString getDbNSName()=0;
120  /* return the namespace prefix which is to be registered with the XPath API.
121 
122  The prefix can then be used in XPath expressions.
123  */
124  virtual OUString getNSPrefix()=0;
125  /* returns the name of the root element without any namespace prefix.
126  */
127  virtual OUString getRootElementName()=0;
128  /* returns the name of xml element for each entry
129  */
130  virtual OUString getKeyElementName()=0;
131 
132 public:
133  BackendDb(css::uno::Reference<css::uno::XComponentContext> const & xContext,
134  OUString const & url);
135  virtual ~BackendDb() {};
136 
137  void removeEntry(std::u16string_view url);
138 
139  /* This is called to write the "revoked" attribute to the entry.
140  This is done when XPackage::revokePackage is called.
141  */
142  void revokeEntry(std::u16string_view url);
143 
144  /* returns false if the entry does not exist yet.
145  */
146  bool activateEntry(std::u16string_view url);
147 
148  bool hasActiveEntry(std::u16string_view url);
149 
150 };
151 
152 class RegisteredDb: public BackendDb
153 {
154 
155 public:
156  RegisteredDb( css::uno::Reference<css::uno::XComponentContext> const & xContext,
157  OUString const & url);
158 
159 
160  void addEntry(OUString const & url);
161 };
162 
163 }
164 
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::xml::dom::XDocument > const & getDocument()
bool activateEntry(std::u16string_view url)
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)
OUString readSimpleElement(std::u16string_view sElementName, css::uno::Reference< css::xml::dom::XNode > const &xParent)
css::uno::Reference< css::xml::dom::XDocument > m_doc
void revokeEntry(std::u16string_view url)
std::vector< OUString > getOneChildFromAllEntries(std::u16string_view sElementName)
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.
void removeEntry(std::u16string_view url)
bool hasActiveEntry(std::u16string_view url)
css::uno::Reference< css::xml::xpath::XXPathAPI > m_xpathApi
virtual OUString getKeyElementName()=0
css::uno::Reference< css::xml::dom::XNode > getKeyElement(std::u16string_view url)
BackendDb(BackendDb const &)=delete
void writeSimpleElement(std::u16string_view sElementName, OUString const &value, css::uno::Reference< css::xml::dom::XNode > const &xParent)
void writeSimpleList(std::deque< OUString > const &list, std::u16string_view sListTagName, std::u16string_view sMemberTagName, css::uno::Reference< css::xml::dom::XNode > const &xParent)
void removeElement(OUString const &sXPathExpression)
virtual OUString getDbNSName()=0
void addEntry(OUString const &url)
std::deque< OUString > readList(css::uno::Reference< css::xml::dom::XNode > const &parent, std::u16string_view sListTagName, std::u16string_view sMemberTagName)
static uno::Reference< css::uno::XComponentContext > xContext
Definition: init.cxx:2207
const css::uno::Reference< css::uno::XComponentContext > m_xContext
RegisteredDb(css::uno::Reference< css::uno::XComponentContext > const &xContext, OUString const &url)
virtual OUString getNSPrefix()=0
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)
css::uno::Reference< css::xml::xpath::XXPathAPI > const & getXPathAPI()
virtual OUString getRootElementName()=0
BackendDb & operator=(BackendDb const &)=delete