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