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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_desktop.hxx"
26
27 #include "rtl/string.h"
28 #include "rtl/bootstrap.hxx"
29 #include "cppuhelper/exc_hlp.hxx"
30 #include "com/sun/star/uno/XComponentContext.hpp"
31 #include "com/sun/star/xml/dom/XDocumentBuilder.hpp"
32 #include "com/sun/star/xml/xpath/XXPathAPI.hpp"
33 #include "dp_misc.h"
34
35 #include "dp_configurationbackenddb.hxx"
36
37
38 namespace css = ::com::sun::star;
39 using namespace ::com::sun::star::uno;
40 using ::rtl::OUString;
41
42 #define EXTENSION_REG_NS "http://openoffice.org/extensionmanager/configuration-registry/2010"
43 #define NS_PREFIX "conf"
44 #define ROOT_ELEMENT_NAME "configuration-backend-db"
45 #define KEY_ELEMENT_NAME "configuration"
46
47 namespace dp_registry {
48 namespace backend {
49 namespace configuration {
50
ConfigurationBackendDb(Reference<XComponentContext> const & xContext,::rtl::OUString const & url)51 ConfigurationBackendDb::ConfigurationBackendDb(
52 Reference<XComponentContext> const & xContext,
53 ::rtl::OUString const & url):BackendDb(xContext, url)
54 {
55
56 }
57
getDbNSName()58 OUString ConfigurationBackendDb::getDbNSName()
59 {
60 return OUSTR(EXTENSION_REG_NS);
61 }
62
getNSPrefix()63 OUString ConfigurationBackendDb::getNSPrefix()
64 {
65 return OUSTR(NS_PREFIX);
66 }
67
getRootElementName()68 OUString ConfigurationBackendDb::getRootElementName()
69 {
70 return OUSTR(ROOT_ELEMENT_NAME);
71 }
72
getKeyElementName()73 OUString ConfigurationBackendDb::getKeyElementName()
74 {
75 return OUSTR(KEY_ELEMENT_NAME);
76 }
77
78
addEntry(::rtl::OUString const & url,Data const & data)79 void ConfigurationBackendDb::addEntry(::rtl::OUString const & url, Data const & data)
80 {
81 try{
82 if (!activateEntry(url))
83 {
84 Reference<css::xml::dom::XNode> helpNode
85 = writeKeyElement(url);
86
87 writeSimpleElement(OUSTR("data-url"), data.dataUrl, helpNode);
88 writeSimpleElement(OUSTR("ini-entry"), data.iniEntry, helpNode);
89 save();
90 }
91 }
92 catch (css::deployment::DeploymentException& )
93 {
94 throw;
95 }
96 catch(css::uno::Exception &)
97 {
98 Any exc( ::cppu::getCaughtException() );
99 throw css::deployment::DeploymentException(
100 OUSTR("Extension Manager: failed to write data entry in configuration backend db: ") +
101 m_urlDb, 0, exc);
102 }
103 }
104
105
106 ::boost::optional<ConfigurationBackendDb::Data>
getEntry(::rtl::OUString const & url)107 ConfigurationBackendDb::getEntry(::rtl::OUString const & url)
108 {
109 try
110 {
111 ConfigurationBackendDb::Data retData;
112 Reference<css::xml::dom::XNode> aNode = getKeyElement(url);
113 if (aNode.is())
114 {
115 retData.dataUrl = readSimpleElement(OUSTR("data-url"), aNode);
116 retData.iniEntry = readSimpleElement(OUSTR("ini-entry"), aNode);
117 }
118 else
119 {
120 return ::boost::optional<Data>();
121 }
122 return ::boost::optional<Data>(retData);
123 }
124 catch (css::deployment::DeploymentException& )
125 {
126 throw;
127 }
128 catch(css::uno::Exception &)
129 {
130 Any exc( ::cppu::getCaughtException() );
131 throw css::deployment::DeploymentException(
132 OUSTR("Extension Manager: failed to read data entry in configuration backend db: ") +
133 m_urlDb, 0, exc);
134 }
135 }
136
getAllDataUrls()137 ::std::list<OUString> ConfigurationBackendDb::getAllDataUrls()
138 {
139 try
140 {
141 ::std::list<OUString> listRet;
142 Reference<css::xml::dom::XDocument> doc = getDocument();
143 Reference<css::xml::dom::XNode> root = doc->getFirstChild();
144
145 Reference<css::xml::xpath::XXPathAPI> xpathApi = getXPathAPI();
146 const OUString sPrefix = getNSPrefix();
147 OUString sExpression(
148 sPrefix + OUSTR(":configuration/") + sPrefix + OUSTR(":data-url/text()"));
149 Reference<css::xml::dom::XNodeList> nodes =
150 xpathApi->selectNodeList(root, sExpression);
151 if (nodes.is())
152 {
153 sal_Int32 length = nodes->getLength();
154 for (sal_Int32 i = 0; i < length; i++)
155 listRet.push_back(nodes->item(i)->getNodeValue());
156 }
157 return listRet;
158 }
159 catch (css::deployment::DeploymentException& )
160 {
161 throw;
162 }
163 catch(css::uno::Exception &)
164 {
165 Any exc( ::cppu::getCaughtException() );
166 throw css::deployment::DeploymentException(
167 OUSTR("Extension Manager: failed to read data entry in configuration backend db: ") +
168 m_urlDb, 0, exc);
169 }
170 }
171
getAllIniEntries()172 ::std::list<OUString> ConfigurationBackendDb::getAllIniEntries()
173 {
174 return getOneChildFromAllEntries(OUSTR("ini-entry"));
175 }
176
177
178
179 } // namespace configuration
180 } // namespace backend
181 } // namespace dp_registry
182
183