Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / desktop / source / deployment / registry / component / dp_compbackenddb.cxx
blob143b4c3d168538e8417720105e0f60f12999a510
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/deployment/DeploymentException.hpp>
25 #include <com/sun/star/uno/XComponentContext.hpp>
26 #include <com/sun/star/xml/dom/XDocumentBuilder.hpp>
27 #include <com/sun/star/xml/xpath/XXPathAPI.hpp>
28 #include <dp_misc.h>
30 #include "dp_compbackenddb.hxx"
33 using namespace ::com::sun::star::uno;
35 #define EXTENSION_REG_NS "http://openoffice.org/extensionmanager/component-registry/2010"
36 #define NS_PREFIX "comp"
37 #define ROOT_ELEMENT_NAME "component-backend-db"
38 #define KEY_ELEMENT_NAME "component"
40 namespace dp_registry {
41 namespace backend {
42 namespace component {
44 ComponentBackendDb::ComponentBackendDb(
45 Reference<XComponentContext> const & xContext,
46 OUString const & url):BackendDb(xContext, url)
51 OUString ComponentBackendDb::getDbNSName()
53 return EXTENSION_REG_NS;
56 OUString ComponentBackendDb::getNSPrefix()
58 return NS_PREFIX;
61 OUString ComponentBackendDb::getRootElementName()
63 return ROOT_ELEMENT_NAME;
66 OUString ComponentBackendDb::getKeyElementName()
68 return KEY_ELEMENT_NAME;
71 void ComponentBackendDb::addEntry(OUString const & url, Data const & data)
73 try{
74 if (!activateEntry(url))
76 Reference<css::xml::dom::XNode> componentNode = writeKeyElement(url);
77 writeSimpleElement("java-type-library",
78 OUString::boolean(data.javaTypeLibrary),
79 componentNode);
81 writeSimpleList(
82 data.implementationNames,
83 "implementation-names",
84 "name",
85 componentNode);
87 writeVectorOfPair(
88 data.singletons,
89 "singletons",
90 "item",
91 "key",
92 "value",
93 componentNode);
95 save();
98 catch(const css::uno::Exception &)
100 Any exc( ::cppu::getCaughtException() );
101 throw css::deployment::DeploymentException(
102 "Extension Manager: failed to write data entry in backend db: " +
103 m_urlDb, nullptr, exc);
107 ComponentBackendDb::Data ComponentBackendDb::getEntry(OUString const & url)
111 ComponentBackendDb::Data retData;
112 Reference<css::xml::dom::XNode> aNode = getKeyElement(url);
113 if (aNode.is())
115 bool bJava = readSimpleElement("java-type-library", aNode) == "true";
116 retData.javaTypeLibrary = bJava;
118 retData.implementationNames =
119 readList( aNode, "implementation-names", "name");
121 retData.singletons =
122 readVectorOfPair( aNode, "singletons", "item", "key", "value");
124 return retData;
126 catch(const css::uno::Exception &)
128 Any exc( ::cppu::getCaughtException() );
129 throw css::deployment::DeploymentException(
130 "Extension Manager: failed to read data entry in backend db: " +
131 m_urlDb, nullptr, exc);
136 } // namespace bundle
137 } // namespace backend
138 } // namespace dp_registry
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */