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