1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #if ! defined INCLUDED_DP_BACKENDDB_HXX
25 #define INCLUDED_DP_BACKENDDB_HXX
26 
27 #include "rtl/ustring.hxx"
28 #include <list>
29 #include <vector>
30 
31 namespace css = ::com::sun::star;
32 
33 namespace com { namespace sun { namespace star {
34         namespace uno {
35         class XComponentContext;
36         }
37         namespace xml { namespace dom {
38             class XDocument;
39             class XNode;
40         }}
41         namespace xml { namespace xpath {
42             class XXPathAPI;
43         }}
44 }}}
45 
46 namespace dp_registry {
47 namespace backend {
48 
49 class BackendDb
50 {
51 private:
52 
53     css::uno::Reference<css::xml::dom::XDocument> m_doc;
54     css::uno::Reference<css::xml::xpath::XXPathAPI> m_xpathApi;
55 
56     BackendDb(BackendDb const &);
57     BackendDb &  operator = (BackendDb const &);
58 
59 protected:
60     const css::uno::Reference<css::uno::XComponentContext> m_xContext;
61     ::rtl::OUString m_urlDb;
62 
63 protected:
64 
65     /* caller must make sure that only one thread accesses the function
66      */
67     css::uno::Reference<css::xml::dom::XDocument> getDocument();
68 
69     /* the namespace prefix is "reg" (without quotes)
70      */
71     css::uno::Reference<css::xml::xpath::XXPathAPI> getXPathAPI();
72     void save();
73     void removeElement(::rtl::OUString const & sXPathExpression);
74 
75     css::uno::Reference<css::xml::dom::XNode> getKeyElement(
76         ::rtl::OUString const & url);
77 
78     void writeSimpleList(
79         ::std::list< ::rtl::OUString> const & list,
80         ::rtl::OUString const & sListTagName,
81         ::rtl::OUString const & sMemberTagName,
82         css::uno::Reference<css::xml::dom::XNode> const & xParent);
83 
84     void writeVectorOfPair(
85         ::std::vector< ::std::pair< ::rtl::OUString, ::rtl::OUString > > const & vecPairs,
86         ::rtl::OUString const & sVectorTagName,
87         ::rtl::OUString const & sPairTagName,
88         ::rtl::OUString const & sFirstTagName,
89         ::rtl::OUString const & sSecondTagName,
90         css::uno::Reference<css::xml::dom::XNode> const & xParent);
91 
92     void writeSimpleElement(
93         ::rtl::OUString const & sElementName, ::rtl::OUString const & value,
94         css::uno::Reference<css::xml::dom::XNode> const & xParent);
95 
96     css::uno::Reference<css::xml::dom::XNode> writeKeyElement(
97         ::rtl::OUString const & url);
98 
99     ::rtl::OUString readSimpleElement(
100         ::rtl::OUString const & sElementName,
101         css::uno::Reference<css::xml::dom::XNode> const & xParent);
102 
103     ::std::vector< ::std::pair< ::rtl::OUString, ::rtl::OUString > >
104     readVectorOfPair(
105         css::uno::Reference<css::xml::dom::XNode> const & parent,
106         ::rtl::OUString const & sListTagName,
107         ::rtl::OUString const & sPairTagName,
108         ::rtl::OUString const & sFirstTagName,
109         ::rtl::OUString const & sSecondTagName);
110 
111     ::std::list< ::rtl::OUString> readList(
112         css::uno::Reference<css::xml::dom::XNode> const & parent,
113         ::rtl::OUString const & sListTagName,
114         ::rtl::OUString const & sMemberTagName);
115 
116     /* returns the values of one particularly child element of all key elements.
117      */
118     ::std::list< ::rtl::OUString> getOneChildFromAllEntries(
119         ::rtl::OUString const & sElementName);
120 
121 
122     /*  returns the namespace which is to be written as xmlns attribute
123         into the root element.
124      */
125     virtual ::rtl::OUString getDbNSName()=0;
126     /* return the namespace prefix which is to be registered with the XPath API.
127 
128        The prefix can then be used in XPath expressions.
129     */
130     virtual ::rtl::OUString getNSPrefix()=0;
131     /* returns the name of the root element without any namespace prefix.
132      */
133     virtual ::rtl::OUString getRootElementName()=0;
134     /* returns the name of xml element for each entry
135      */
136     virtual ::rtl::OUString getKeyElementName()=0;
137 
138 
139 
140 public:
141     BackendDb(css::uno::Reference<css::uno::XComponentContext> const &  xContext,
142               ::rtl::OUString const & url);
~BackendDb()143     virtual ~BackendDb() {};
144 
145     void removeEntry(::rtl::OUString const & url);
146 
147     /* This is called to write the "revoked" attribute to the entry.
148        This is done when XPackage::revokePackage is called.
149     */
150     void revokeEntry(::rtl::OUString const & url);
151 
152     /* returns false if the entry does not exist yet.
153      */
154     bool activateEntry(::rtl::OUString const & url);
155 
156     bool hasActiveEntry(::rtl::OUString const & url);
157 
158 };
159 
160 class RegisteredDb: public BackendDb
161 {
162 
163 public:
164     RegisteredDb( css::uno::Reference<css::uno::XComponentContext> const &  xContext,
165                   ::rtl::OUString const & url);
~RegisteredDb()166     virtual ~RegisteredDb() {};
167 
168 
169     virtual void addEntry(::rtl::OUString const & url);
170     virtual bool getEntry(::rtl::OUString const & url);
171 
172 };
173 
174 
175 }
176 }
177 #endif
178 
179