LibreOffice Module desktop (master)  1
dp_helpbackenddb.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_helpbackenddb.hxx"
31 
32 
33 using namespace ::com::sun::star::uno;
34 
35 #define EXTENSION_REG_NS "http://openoffice.org/extensionmanager/help-registry/2010"
36 #define NS_PREFIX "help"
37 #define ROOT_ELEMENT_NAME "help-backend-db"
38 #define KEY_ELEMENT_NAME "help"
39 
40 namespace dp_registry {
41 namespace backend {
42 namespace help {
43 
46  OUString const & url):BackendDb(xContext, url)
47 {
48 
49 }
50 
52 {
53  return EXTENSION_REG_NS;
54 }
55 
57 {
58  return NS_PREFIX;
59 }
60 
62 {
63  return ROOT_ELEMENT_NAME;
64 }
65 
67 {
68  return KEY_ELEMENT_NAME;
69 }
70 
71 
72 void HelpBackendDb::addEntry(OUString const & url, Data const & data)
73 {
74  try{
75  if (!activateEntry(url))
76  {
77  Reference<css::xml::dom::XNode> helpNode
78  = writeKeyElement(url);
79 
80  writeSimpleElement("data-url", data.dataUrl, helpNode);
81  save();
82  }
83  }
84  catch ( const css::deployment::DeploymentException& )
85  {
86  throw;
87  }
88  catch(const css::uno::Exception &)
89  {
90  Any exc( ::cppu::getCaughtException() );
91  throw css::deployment::DeploymentException(
92  "Extension Manager: failed to write data entry in help backend db: " + m_urlDb, nullptr, exc);
93  }
94 }
95 
96 
98 HelpBackendDb::getEntry(OUString const & url)
99 {
100  try
101  {
102  HelpBackendDb::Data retData;
103  Reference<css::xml::dom::XNode> aNode = getKeyElement(url);
104  if (aNode.is())
105  {
106  retData.dataUrl = readSimpleElement("data-url", aNode);
107  }
108  else
109  {
110  return ::boost::optional<Data>();
111  }
112  return ::boost::optional<Data>(retData);
113  }
114  catch ( const css::deployment::DeploymentException& )
115  {
116  throw;
117  }
118  catch(const css::uno::Exception &)
119  {
120  Any exc( ::cppu::getCaughtException() );
121  throw css::deployment::DeploymentException(
122  "Extension Manager: failed to read data entry in help backend db: " + m_urlDb, nullptr, exc);
123  }
124 }
125 
126 std::vector<OUString> HelpBackendDb::getAllDataUrls()
127 {
128  return getOneChildFromAllEntries("data-url");
129 }
130 
131 } // namespace help
132 } // namespace backend
133 } // namespace dp_registry
134 
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void addEntry(OUString const &url, Data const &data)
virtual OUString getKeyElementName() override
#define KEY_ELEMENT_NAME
#define NS_PREFIX
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.
::boost::optional< Data > getEntry(OUString const &url)
Any SAL_CALL getCaughtException()
virtual OUString getRootElementName() override
css::uno::Reference< css::xml::dom::XNode > getKeyElement(OUString const &url)
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:1858
std::vector< OUString > getOneChildFromAllEntries(OUString const &sElementName)
#define EXTENSION_REG_NS
HelpBackendDb(css::uno::Reference< css::uno::XComponentContext > const &xContext, OUString const &url)
OUString readSimpleElement(OUString const &sElementName, css::uno::Reference< css::xml::dom::XNode > const &xParent)
#define ROOT_ELEMENT_NAME
bool activateEntry(OUString const &url)