update credits
[LibreOffice.git] / desktop / source / deployment / registry / configuration / dp_configurationbackenddb.cxx
blob47e364e2b75438d243f0c2eba4030bb1e5a83697
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "rtl/string.h"
22 #include "rtl/bootstrap.hxx"
23 #include "cppuhelper/exc_hlp.hxx"
24 #include "com/sun/star/uno/XComponentContext.hpp"
25 #include "com/sun/star/xml/dom/XDocumentBuilder.hpp"
26 #include "com/sun/star/xml/xpath/XXPathAPI.hpp"
27 #include "dp_misc.h"
29 #include "dp_configurationbackenddb.hxx"
32 using namespace ::com::sun::star::uno;
34 #define EXTENSION_REG_NS "http://openoffice.org/extensionmanager/configuration-registry/2010"
35 #define NS_PREFIX "conf"
36 #define ROOT_ELEMENT_NAME "configuration-backend-db"
37 #define KEY_ELEMENT_NAME "configuration"
39 namespace dp_registry {
40 namespace backend {
41 namespace configuration {
43 ConfigurationBackendDb::ConfigurationBackendDb(
44 Reference<XComponentContext> const & xContext,
45 OUString const & url):BackendDb(xContext, url)
50 OUString ConfigurationBackendDb::getDbNSName()
52 return OUString(EXTENSION_REG_NS);
55 OUString ConfigurationBackendDb::getNSPrefix()
57 return OUString(NS_PREFIX);
60 OUString ConfigurationBackendDb::getRootElementName()
62 return OUString(ROOT_ELEMENT_NAME);
65 OUString ConfigurationBackendDb::getKeyElementName()
67 return OUString(KEY_ELEMENT_NAME);
71 void ConfigurationBackendDb::addEntry(OUString const & url, Data const & data)
73 try{
74 if (!activateEntry(url))
76 Reference<css::xml::dom::XNode> helpNode
77 = writeKeyElement(url);
79 writeSimpleElement("data-url", data.dataUrl, helpNode);
80 writeSimpleElement("ini-entry", data.iniEntry, helpNode);
81 save();
84 catch ( const css::deployment::DeploymentException& )
86 throw;
88 catch(const css::uno::Exception &)
90 Any exc( ::cppu::getCaughtException() );
91 throw css::deployment::DeploymentException(
92 "Extension Manager: failed to write data entry in configuration backend db: " +
93 m_urlDb, 0, exc);
98 ::boost::optional<ConfigurationBackendDb::Data>
99 ConfigurationBackendDb::getEntry(OUString const & url)
103 ConfigurationBackendDb::Data retData;
104 Reference<css::xml::dom::XNode> aNode = getKeyElement(url);
105 if (aNode.is())
107 retData.dataUrl = readSimpleElement("data-url", aNode);
108 retData.iniEntry = readSimpleElement("ini-entry", aNode);
110 else
112 return ::boost::optional<Data>();
114 return ::boost::optional<Data>(retData);
116 catch ( const css::deployment::DeploymentException& )
118 throw;
120 catch(const css::uno::Exception &)
122 Any exc( ::cppu::getCaughtException() );
123 throw css::deployment::DeploymentException(
124 "Extension Manager: failed to read data entry in configuration backend db: " +
125 m_urlDb, 0, exc);
129 ::std::list<OUString> ConfigurationBackendDb::getAllDataUrls()
133 ::std::list<OUString> listRet;
134 Reference<css::xml::dom::XDocument> doc = getDocument();
135 Reference<css::xml::dom::XNode> root = doc->getFirstChild();
137 Reference<css::xml::xpath::XXPathAPI> xpathApi = getXPathAPI();
138 const OUString sPrefix = getNSPrefix();
139 OUString sExpression(
140 sPrefix + ":configuration/" + sPrefix + ":data-url/text()");
141 Reference<css::xml::dom::XNodeList> nodes =
142 xpathApi->selectNodeList(root, sExpression);
143 if (nodes.is())
145 sal_Int32 length = nodes->getLength();
146 for (sal_Int32 i = 0; i < length; i++)
147 listRet.push_back(nodes->item(i)->getNodeValue());
149 return listRet;
151 catch ( const css::deployment::DeploymentException& )
153 throw;
155 catch(const css::uno::Exception &)
157 Any exc( ::cppu::getCaughtException() );
158 throw css::deployment::DeploymentException(
159 "Extension Manager: failed to read data entry in configuration backend db: " +
160 m_urlDb, 0, exc);
164 } // namespace configuration
165 } // namespace backend
166 } // namespace dp_registry
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */