LibreOffice Module desktop (master)  1
dp_extbackenddb.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/bootstrap.hxx>
22 #include <cppuhelper/exc_hlp.hxx>
23 #include <com/sun/star/deployment/DeploymentException.hpp>
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>
28 
29 #include "dp_extbackenddb.hxx"
30 
31 
32 using namespace ::com::sun::star::uno;
33 
34 #define EXTENSION_REG_NS "http://openoffice.org/extensionmanager/extension-registry/2010"
35 #define NS_PREFIX "ext"
36 #define ROOT_ELEMENT_NAME "extension-backend-db"
37 #define KEY_ELEMENT_NAME "extension"
38 
39 namespace dp_registry {
40 namespace backend {
41 namespace bundle {
42 
45  OUString const & url):BackendDb(xContext, url)
46 {
47 
48 }
49 
51 {
52  return OUString(EXTENSION_REG_NS);
53 }
54 
56 {
57  return OUString(NS_PREFIX);
58 }
59 
61 {
62  return OUString(ROOT_ELEMENT_NAME);
63 }
64 
66 {
67  return OUString(KEY_ELEMENT_NAME);
68 }
69 
70 void ExtensionBackendDb::addEntry(OUString const & url, Data const & data)
71 {
72  try{
73  //reactive revoked entry if possible.
74  if (!activateEntry(url))
75  {
76  Reference<css::xml::dom::XNode> extensionNodeNode = writeKeyElement(url);
77  writeVectorOfPair( data.items, "extension-items", "item",
78  "url", "media-type", extensionNodeNode);
79  save();
80  }
81  }
82  catch(const css::uno::Exception &)
83  {
84  Any exc( ::cppu::getCaughtException() );
85  throw css::deployment::DeploymentException(
86  "Extension Manager: failed to write data entry in backend db: " +
87  m_urlDb, nullptr, exc);
88  }
89 }
90 
92 {
93  try
94  {
96  Reference<css::xml::dom::XNode> aNode = getKeyElement(url);
97 
98  if (aNode.is())
99  {
100  retData.items =
101  readVectorOfPair( aNode, "extension-items", "item",
102  "url", "media-type");
103  }
104  return retData;
105  }
106  catch(const css::uno::Exception &)
107  {
108  Any exc( ::cppu::getCaughtException() );
109  throw css::deployment::DeploymentException(
110  "Extension Manager: failed to read data entry in backend db: " +
111  m_urlDb, nullptr, exc);
112  }
113 }
114 
115 } // namespace bundle
116 } // namespace backend
117 } // namespace dp_registry
118 
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define NS_PREFIX
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)
std::vector< std::pair< OUString, OUString > > items
css::uno::Reference< css::xml::dom::XNode > writeKeyElement(OUString const &url)
The key elements have an url attribute and are always children of the root element.
#define EXTENSION_REG_NS
Any SAL_CALL getCaughtException()
css::uno::Reference< css::xml::dom::XNode > getKeyElement(OUString const &url)
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 KEY_ELEMENT_NAME
static uno::Reference< css::uno::XComponentContext > xContext
Definition: init.cxx:1546
#define ROOT_ELEMENT_NAME
ExtensionBackendDb(css::uno::Reference< css::uno::XComponentContext > const &xContext, OUString const &url)
bool activateEntry(OUString const &url)