1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_desktop.hxx"
30 
31 #include "rtl/string.h"
32 #include "rtl/bootstrap.hxx"
33 #include "cppuhelper/exc_hlp.hxx"
34 #include "com/sun/star/uno/XComponentContext.hpp"
35 #include "com/sun/star/xml/dom/XDocumentBuilder.hpp"
36 #include "com/sun/star/xml/xpath/XXPathAPI.hpp"
37 #include "dp_misc.h"
38 
39 #include "dp_compbackenddb.hxx"
40 
41 
42 namespace css = ::com::sun::star;
43 using namespace ::com::sun::star::uno;
44 using ::rtl::OUString;
45 
46 #define EXTENSION_REG_NS "http://openoffice.org/extensionmanager/component-registry/2010"
47 #define NS_PREFIX "comp"
48 #define ROOT_ELEMENT_NAME "component-backend-db"
49 #define KEY_ELEMENT_NAME "component"
50 
51 namespace dp_registry {
52 namespace backend {
53 namespace component {
54 
55 ComponentBackendDb::ComponentBackendDb(
56     Reference<XComponentContext> const &  xContext,
57     ::rtl::OUString const & url):BackendDb(xContext, url)
58 {
59 
60 }
61 
62 OUString ComponentBackendDb::getDbNSName()
63 {
64     return OUSTR(EXTENSION_REG_NS);
65 }
66 
67 OUString ComponentBackendDb::getNSPrefix()
68 {
69     return OUSTR(NS_PREFIX);
70 }
71 
72 OUString ComponentBackendDb::getRootElementName()
73 {
74     return OUSTR(ROOT_ELEMENT_NAME);
75 }
76 
77 OUString ComponentBackendDb::getKeyElementName()
78 {
79     return OUSTR(KEY_ELEMENT_NAME);
80 }
81 
82 void ComponentBackendDb::addEntry(::rtl::OUString const & url, Data const & data)
83 {
84     try{
85         if (!activateEntry(url))
86         {
87             Reference<css::xml::dom::XNode> componentNode = writeKeyElement(url);
88             writeSimpleElement(OUSTR("java-type-library"),
89                                OUString::valueOf((sal_Bool) data.javaTypeLibrary),
90                                componentNode);
91 
92             writeSimpleList(
93                 data.implementationNames,
94                 OUSTR("implementation-names"),
95                 OUSTR("name"),
96                 componentNode);
97 
98             writeVectorOfPair(
99                 data.singletons,
100                 OUSTR("singletons"),
101                 OUSTR("item"),
102                 OUSTR("key"),
103                 OUSTR("value"),
104                 componentNode);
105 
106             save();
107         }
108     }
109     catch(css::uno::Exception &)
110     {
111         Any exc( ::cppu::getCaughtException() );
112         throw css::deployment::DeploymentException(
113             OUSTR("Extension Manager: failed to write data entry in backend db: ") +
114             m_urlDb, 0, exc);
115     }
116 }
117 
118 ComponentBackendDb::Data ComponentBackendDb::getEntry(::rtl::OUString const & url)
119 {
120     try
121     {
122         ComponentBackendDb::Data retData;
123         Reference<css::xml::dom::XNode> aNode = getKeyElement(url);
124         if (aNode.is())
125         {
126             bool bJava = readSimpleElement(OUSTR("java-type-library"), aNode)
127                 .equals(OUSTR("true")) ? true : false;
128             retData.javaTypeLibrary = bJava;
129 
130             retData.implementationNames =
131                 readList(
132                     aNode,
133                     OUSTR("implementation-names"),
134                     OUSTR("name"));
135 
136             retData.singletons =
137                 readVectorOfPair(
138                     aNode,
139                     OUSTR("singletons"),
140                     OUSTR("item"),
141                     OUSTR("key"),
142                     OUSTR("value"));
143         }
144         return retData;
145     }
146     catch(css::uno::Exception &)
147     {
148         Any exc( ::cppu::getCaughtException() );
149         throw css::deployment::DeploymentException(
150             OUSTR("Extension Manager: failed to read data entry in backend db: ") +
151             m_urlDb, 0, exc);
152     }
153 }
154 
155 
156 } // namespace bundle
157 } // namespace backend
158 } // namespace dp_registry
159 
160