1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #if ! defined INCLUDED_DP_BACKENDDB_HXX
29*cdf0e10cSrcweir #define INCLUDED_DP_BACKENDDB_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "rtl/ustring.hxx"
32*cdf0e10cSrcweir #include <list>
33*cdf0e10cSrcweir #include <vector>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir namespace css = ::com::sun::star;
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir namespace com { namespace sun { namespace star {
38*cdf0e10cSrcweir         namespace uno {
39*cdf0e10cSrcweir         class XComponentContext;
40*cdf0e10cSrcweir         }
41*cdf0e10cSrcweir         namespace xml { namespace dom {
42*cdf0e10cSrcweir             class XDocument;
43*cdf0e10cSrcweir             class XNode;
44*cdf0e10cSrcweir         }}
45*cdf0e10cSrcweir         namespace xml { namespace xpath {
46*cdf0e10cSrcweir             class XXPathAPI;
47*cdf0e10cSrcweir         }}
48*cdf0e10cSrcweir }}}
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir namespace dp_registry {
51*cdf0e10cSrcweir namespace backend {
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir class BackendDb
54*cdf0e10cSrcweir {
55*cdf0e10cSrcweir private:
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir     css::uno::Reference<css::xml::dom::XDocument> m_doc;
58*cdf0e10cSrcweir     css::uno::Reference<css::xml::xpath::XXPathAPI> m_xpathApi;
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir     BackendDb(BackendDb const &);
61*cdf0e10cSrcweir     BackendDb &  operator = (BackendDb const &);
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir protected:
64*cdf0e10cSrcweir     const css::uno::Reference<css::uno::XComponentContext> m_xContext;
65*cdf0e10cSrcweir     ::rtl::OUString m_urlDb;
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir protected:
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir     /* caller must make sure that only one thread accesses the function
70*cdf0e10cSrcweir      */
71*cdf0e10cSrcweir     css::uno::Reference<css::xml::dom::XDocument> getDocument();
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir     /* the namespace prefix is "reg" (without quotes)
74*cdf0e10cSrcweir      */
75*cdf0e10cSrcweir     css::uno::Reference<css::xml::xpath::XXPathAPI> getXPathAPI();
76*cdf0e10cSrcweir     void save();
77*cdf0e10cSrcweir     void removeElement(::rtl::OUString const & sXPathExpression);
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir     css::uno::Reference<css::xml::dom::XNode> getKeyElement(
80*cdf0e10cSrcweir         ::rtl::OUString const & url);
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir     void writeSimpleList(
83*cdf0e10cSrcweir         ::std::list< ::rtl::OUString> const & list,
84*cdf0e10cSrcweir         ::rtl::OUString const & sListTagName,
85*cdf0e10cSrcweir         ::rtl::OUString const & sMemberTagName,
86*cdf0e10cSrcweir         css::uno::Reference<css::xml::dom::XNode> const & xParent);
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir     void writeVectorOfPair(
89*cdf0e10cSrcweir         ::std::vector< ::std::pair< ::rtl::OUString, ::rtl::OUString > > const & vecPairs,
90*cdf0e10cSrcweir         ::rtl::OUString const & sVectorTagName,
91*cdf0e10cSrcweir         ::rtl::OUString const & sPairTagName,
92*cdf0e10cSrcweir         ::rtl::OUString const & sFirstTagName,
93*cdf0e10cSrcweir         ::rtl::OUString const & sSecondTagName,
94*cdf0e10cSrcweir         css::uno::Reference<css::xml::dom::XNode> const & xParent);
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir     void writeSimpleElement(
97*cdf0e10cSrcweir         ::rtl::OUString const & sElementName, ::rtl::OUString const & value,
98*cdf0e10cSrcweir         css::uno::Reference<css::xml::dom::XNode> const & xParent);
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir     css::uno::Reference<css::xml::dom::XNode> writeKeyElement(
101*cdf0e10cSrcweir         ::rtl::OUString const & url);
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir     ::rtl::OUString readSimpleElement(
104*cdf0e10cSrcweir         ::rtl::OUString const & sElementName,
105*cdf0e10cSrcweir         css::uno::Reference<css::xml::dom::XNode> const & xParent);
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir     ::std::vector< ::std::pair< ::rtl::OUString, ::rtl::OUString > >
108*cdf0e10cSrcweir     readVectorOfPair(
109*cdf0e10cSrcweir         css::uno::Reference<css::xml::dom::XNode> const & parent,
110*cdf0e10cSrcweir         ::rtl::OUString const & sListTagName,
111*cdf0e10cSrcweir         ::rtl::OUString const & sPairTagName,
112*cdf0e10cSrcweir         ::rtl::OUString const & sFirstTagName,
113*cdf0e10cSrcweir         ::rtl::OUString const & sSecondTagName);
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir     ::std::list< ::rtl::OUString> readList(
116*cdf0e10cSrcweir         css::uno::Reference<css::xml::dom::XNode> const & parent,
117*cdf0e10cSrcweir         ::rtl::OUString const & sListTagName,
118*cdf0e10cSrcweir         ::rtl::OUString const & sMemberTagName);
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir     /* returns the values of one particulary child element of all key elements.
121*cdf0e10cSrcweir      */
122*cdf0e10cSrcweir     ::std::list< ::rtl::OUString> getOneChildFromAllEntries(
123*cdf0e10cSrcweir         ::rtl::OUString const & sElementName);
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir     /*  returns the namespace which is to be written as xmlns attribute
127*cdf0e10cSrcweir         into the root element.
128*cdf0e10cSrcweir      */
129*cdf0e10cSrcweir     virtual ::rtl::OUString getDbNSName()=0;
130*cdf0e10cSrcweir     /* return the namespace prefix which is to be registered with the XPath API.
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir        The prefix can then be used in XPath expressions.
133*cdf0e10cSrcweir     */
134*cdf0e10cSrcweir     virtual ::rtl::OUString getNSPrefix()=0;
135*cdf0e10cSrcweir     /* returns the name of the root element without any namespace prefix.
136*cdf0e10cSrcweir      */
137*cdf0e10cSrcweir     virtual ::rtl::OUString getRootElementName()=0;
138*cdf0e10cSrcweir     /* returns the name of xml element for each entry
139*cdf0e10cSrcweir      */
140*cdf0e10cSrcweir     virtual ::rtl::OUString getKeyElementName()=0;
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir public:
145*cdf0e10cSrcweir     BackendDb(css::uno::Reference<css::uno::XComponentContext> const &  xContext,
146*cdf0e10cSrcweir               ::rtl::OUString const & url);
147*cdf0e10cSrcweir     virtual ~BackendDb() {};
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir     void removeEntry(::rtl::OUString const & url);
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir     /* This is called to write the "revoked" attribute to the entry.
152*cdf0e10cSrcweir        This is done when XPackage::revokePackage is called.
153*cdf0e10cSrcweir     */
154*cdf0e10cSrcweir     void revokeEntry(::rtl::OUString const & url);
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir     /* returns false if the entry does not exist yet.
157*cdf0e10cSrcweir      */
158*cdf0e10cSrcweir     bool activateEntry(::rtl::OUString const & url);
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir     bool hasActiveEntry(::rtl::OUString const & url);
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir };
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir class RegisteredDb: public BackendDb
165*cdf0e10cSrcweir {
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir public:
168*cdf0e10cSrcweir     RegisteredDb( css::uno::Reference<css::uno::XComponentContext> const &  xContext,
169*cdf0e10cSrcweir                   ::rtl::OUString const & url);
170*cdf0e10cSrcweir     virtual ~RegisteredDb() {};
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir     virtual void addEntry(::rtl::OUString const & url);
174*cdf0e10cSrcweir     virtual bool getEntry(::rtl::OUString const & url);
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir };
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir }
180*cdf0e10cSrcweir }
181*cdf0e10cSrcweir #endif
182*cdf0e10cSrcweir 
183