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