Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "rtl/string.h"
31 : : #include "rtl/bootstrap.hxx"
32 : : #include "cppuhelper/exc_hlp.hxx"
33 : : #include "com/sun/star/uno/XComponentContext.hpp"
34 : : #include "com/sun/star/xml/dom/XDocumentBuilder.hpp"
35 : : #include "com/sun/star/xml/xpath/XXPathAPI.hpp"
36 : : #include "dp_misc.h"
37 : :
38 : : #include "dp_configurationbackenddb.hxx"
39 : :
40 : :
41 : : namespace css = ::com::sun::star;
42 : : using namespace ::com::sun::star::uno;
43 : : using ::rtl::OUString;
44 : :
45 : : #define EXTENSION_REG_NS "http://openoffice.org/extensionmanager/configuration-registry/2010"
46 : : #define NS_PREFIX "conf"
47 : : #define ROOT_ELEMENT_NAME "configuration-backend-db"
48 : : #define KEY_ELEMENT_NAME "configuration"
49 : :
50 : : namespace dp_registry {
51 : : namespace backend {
52 : : namespace configuration {
53 : :
54 : 380 : ConfigurationBackendDb::ConfigurationBackendDb(
55 : : Reference<XComponentContext> const & xContext,
56 : 380 : ::rtl::OUString const & url):BackendDb(xContext, url)
57 : : {
58 : :
59 : 380 : }
60 : :
61 : 4846 : OUString ConfigurationBackendDb::getDbNSName()
62 : : {
63 : 4846 : return OUSTR(EXTENSION_REG_NS);
64 : : }
65 : :
66 : 19166 : OUString ConfigurationBackendDb::getNSPrefix()
67 : : {
68 : 19166 : return OUSTR(NS_PREFIX);
69 : : }
70 : :
71 : 188 : OUString ConfigurationBackendDb::getRootElementName()
72 : : {
73 : 188 : return OUSTR(ROOT_ELEMENT_NAME);
74 : : }
75 : :
76 : 15862 : OUString ConfigurationBackendDb::getKeyElementName()
77 : : {
78 : 15862 : return OUSTR(KEY_ELEMENT_NAME);
79 : : }
80 : :
81 : :
82 : 1922 : void ConfigurationBackendDb::addEntry(::rtl::OUString const & url, Data const & data)
83 : : {
84 : : try{
85 [ + - ][ + - ]: 1922 : if (!activateEntry(url))
86 : : {
87 : : Reference<css::xml::dom::XNode> helpNode
88 [ + - ]: 1922 : = writeKeyElement(url);
89 : :
90 [ + - ][ + - ]: 1922 : writeSimpleElement(OUSTR("data-url"), data.dataUrl, helpNode);
91 [ + - ][ + - ]: 1922 : writeSimpleElement(OUSTR("ini-entry"), data.iniEntry, helpNode);
92 [ + - ]: 1922 : save();
93 : : }
94 : : }
95 : 0 : catch ( const css::deployment::DeploymentException& )
96 : : {
97 : 0 : throw;
98 : : }
99 [ # # # ]: 0 : catch(const css::uno::Exception &)
100 : : {
101 [ # # ]: 0 : Any exc( ::cppu::getCaughtException() );
102 : : throw css::deployment::DeploymentException(
103 : : OUSTR("Extension Manager: failed to write data entry in configuration backend db: ") +
104 [ # # # # : 0 : m_urlDb, 0, exc);
# # ]
105 : : }
106 : 1922 : }
107 : :
108 : :
109 : : ::boost::optional<ConfigurationBackendDb::Data>
110 : 0 : ConfigurationBackendDb::getEntry(::rtl::OUString const & url)
111 : : {
112 : : try
113 : : {
114 : 0 : ConfigurationBackendDb::Data retData;
115 [ # # ]: 0 : Reference<css::xml::dom::XNode> aNode = getKeyElement(url);
116 [ # # ]: 0 : if (aNode.is())
117 : : {
118 [ # # ][ # # ]: 0 : retData.dataUrl = readSimpleElement(OUSTR("data-url"), aNode);
119 [ # # ][ # # ]: 0 : retData.iniEntry = readSimpleElement(OUSTR("ini-entry"), aNode);
120 : : }
121 : : else
122 : : {
123 [ # # ]: 0 : return ::boost::optional<Data>();
124 : : }
125 [ # # ]: 0 : return ::boost::optional<Data>(retData);
126 : : }
127 : 0 : catch ( const css::deployment::DeploymentException& )
128 : : {
129 : 0 : throw;
130 : : }
131 [ # # # ]: 0 : catch(const css::uno::Exception &)
132 : : {
133 [ # # ]: 0 : Any exc( ::cppu::getCaughtException() );
134 : : throw css::deployment::DeploymentException(
135 : : OUSTR("Extension Manager: failed to read data entry in configuration backend db: ") +
136 [ # # # # : 0 : m_urlDb, 0, exc);
# # ]
137 : : }
138 : : }
139 : :
140 : 380 : ::std::list<OUString> ConfigurationBackendDb::getAllDataUrls()
141 : : {
142 : : try
143 : : {
144 [ + - ]: 380 : ::std::list<OUString> listRet;
145 [ + - ]: 380 : Reference<css::xml::dom::XDocument> doc = getDocument();
146 [ + - ][ + - ]: 380 : Reference<css::xml::dom::XNode> root = doc->getFirstChild();
147 : :
148 [ + - ]: 380 : Reference<css::xml::xpath::XXPathAPI> xpathApi = getXPathAPI();
149 [ + - ]: 380 : const OUString sPrefix = getNSPrefix();
150 : : OUString sExpression(
151 [ + - ][ + - ]: 380 : sPrefix + OUSTR(":configuration/") + sPrefix + OUSTR(":data-url/text()"));
152 : : Reference<css::xml::dom::XNodeList> nodes =
153 [ + - ][ + - ]: 380 : xpathApi->selectNodeList(root, sExpression);
154 [ + - ]: 380 : if (nodes.is())
155 : : {
156 [ + - ][ + - ]: 380 : sal_Int32 length = nodes->getLength();
157 [ + + ]: 814 : for (sal_Int32 i = 0; i < length; i++)
158 [ + - ][ + - ]: 434 : listRet.push_back(nodes->item(i)->getNodeValue());
[ + - ][ + - ]
[ + - ]
159 : : }
160 : 380 : return listRet;
161 : : }
162 : 0 : catch ( const css::deployment::DeploymentException& )
163 : : {
164 : 0 : throw;
165 : : }
166 [ # # # ]: 0 : catch(const css::uno::Exception &)
167 : : {
168 [ # # ]: 0 : Any exc( ::cppu::getCaughtException() );
169 : : throw css::deployment::DeploymentException(
170 : : OUSTR("Extension Manager: failed to read data entry in configuration backend db: ") +
171 [ # # # # : 0 : m_urlDb, 0, exc);
# # ]
172 : : }
173 : : }
174 : :
175 : : } // namespace configuration
176 : : } // namespace backend
177 : : } // namespace dp_registry
178 : :
179 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|