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