LibreOffice Module desktop (master)  1
dp_compbackenddb.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 
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>
29 
30 #include "dp_compbackenddb.hxx"
31 
32 
33 using namespace ::com::sun::star::uno;
34 
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"
39 
41 
44  OUString const & url):BackendDb(xContext, url)
45 {
46 
47 }
48 
50 {
51  return EXTENSION_REG_NS;
52 }
53 
55 {
56  return NS_PREFIX;
57 }
58 
60 {
61  return ROOT_ELEMENT_NAME;
62 }
63 
65 {
66  return KEY_ELEMENT_NAME;
67 }
68 
69 void ComponentBackendDb::addEntry(OUString const & url, Data const & data)
70 {
71  try{
72  if (!activateEntry(url))
73  {
74  Reference<css::xml::dom::XNode> componentNode = writeKeyElement(url);
75  writeSimpleElement("java-type-library",
76  OUString::boolean(data.javaTypeLibrary),
77  componentNode);
78 
81  "implementation-names",
82  "name",
83  componentNode);
84 
86  data.singletons,
87  "singletons",
88  "item",
89  "key",
90  "value",
91  componentNode);
92 
93  save();
94  }
95  }
96  catch(const css::uno::Exception &)
97  {
98  Any exc( ::cppu::getCaughtException() );
99  throw css::deployment::DeploymentException(
100  "Extension Manager: failed to write data entry in backend db: " +
101  m_urlDb, nullptr, exc);
102  }
103 }
104 
106 {
107  try
108  {
109  ComponentBackendDb::Data retData;
110  Reference<css::xml::dom::XNode> aNode = getKeyElement(url);
111  if (aNode.is())
112  {
113  bool bJava = readSimpleElement("java-type-library", aNode) == "true";
114  retData.javaTypeLibrary = bJava;
115 
116  retData.implementationNames =
117  readList( aNode, "implementation-names", "name");
118 
119  retData.singletons =
120  readVectorOfPair( aNode, "singletons", "item", "key", "value");
121  }
122  return retData;
123  }
124  catch(const css::uno::Exception &)
125  {
126  Any exc( ::cppu::getCaughtException() );
127  throw css::deployment::DeploymentException(
128  "Extension Manager: failed to read data entry in backend db: " +
129  m_urlDb, nullptr, exc);
130  }
131 }
132 
133 
134 } // namespace
135 
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void writeVectorOfPair(std::vector< std::pair< OUString, OUString > > const &vecPairs, OUString const &sVectorTagName, OUString const &sPairTagName, OUString const &sFirstTagName, OUString const &sSecondTagName, css::uno::Reference< css::xml::dom::XNode > const &xParent)
void addEntry(OUString const &url, Data const &data)
ComponentBackendDb(css::uno::Reference< css::uno::XComponentContext > const &xContext, OUString const &url)
std::deque< OUString > readList(css::uno::Reference< css::xml::dom::XNode > const &parent, OUString const &sListTagName, OUString const &sMemberTagName)
css::uno::Reference< css::xml::dom::XNode > writeKeyElement(OUString const &url)
The key elements have a url attribute and are always children of the root element.
#define NS_PREFIX
Any SAL_CALL getCaughtException()
css::uno::Reference< css::xml::dom::XNode > getKeyElement(OUString const &url)
#define KEY_ELEMENT_NAME
std::vector< std::pair< OUString, OUString > > readVectorOfPair(css::uno::Reference< css::xml::dom::XNode > const &parent, OUString const &sListTagName, OUString const &sPairTagName, OUString const &sFirstTagName, OUString const &sSecondTagName)
#define EXTENSION_REG_NS
void writeSimpleElement(OUString const &sElementName, OUString const &value, css::uno::Reference< css::xml::dom::XNode > const &xParent)
static uno::Reference< css::uno::XComponentContext > xContext
Definition: init.cxx:2087
std::vector< std::pair< OUString, OUString > > singletons
OUString readSimpleElement(OUString const &sElementName, css::uno::Reference< css::xml::dom::XNode > const &xParent)
#define ROOT_ELEMENT_NAME
bool activateEntry(OUString const &url)
void writeSimpleList(std::deque< OUString > const &list, OUString const &sListTagName, OUString const &sMemberTagName, css::uno::Reference< css::xml::dom::XNode > const &xParent)