1*2722ceddSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*2722ceddSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*2722ceddSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*2722ceddSAndrew Rist * distributed with this work for additional information
6*2722ceddSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*2722ceddSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*2722ceddSAndrew Rist * "License"); you may not use this file except in compliance
9*2722ceddSAndrew Rist * with the License. You may obtain a copy of the License at
10*2722ceddSAndrew Rist *
11*2722ceddSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*2722ceddSAndrew Rist *
13*2722ceddSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*2722ceddSAndrew Rist * software distributed under the License is distributed on an
15*2722ceddSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2722ceddSAndrew Rist * KIND, either express or implied. See the License for the
17*2722ceddSAndrew Rist * specific language governing permissions and limitations
18*2722ceddSAndrew Rist * under the License.
19*2722ceddSAndrew Rist *
20*2722ceddSAndrew Rist *************************************************************/
21*2722ceddSAndrew Rist
22*2722ceddSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_desktop.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "rtl/string.h"
28cdf0e10cSrcweir #include "rtl/bootstrap.hxx"
29cdf0e10cSrcweir #include "cppuhelper/exc_hlp.hxx"
30cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp"
31cdf0e10cSrcweir #include "com/sun/star/xml/dom/XDocumentBuilder.hpp"
32cdf0e10cSrcweir #include "com/sun/star/xml/xpath/XXPathAPI.hpp"
33cdf0e10cSrcweir #include "dp_misc.h"
34cdf0e10cSrcweir
35cdf0e10cSrcweir #include "dp_helpbackenddb.hxx"
36cdf0e10cSrcweir
37cdf0e10cSrcweir
38cdf0e10cSrcweir namespace css = ::com::sun::star;
39cdf0e10cSrcweir using namespace ::com::sun::star::uno;
40cdf0e10cSrcweir using ::rtl::OUString;
41cdf0e10cSrcweir
42cdf0e10cSrcweir #define EXTENSION_REG_NS "http://openoffice.org/extensionmanager/help-registry/2010"
43cdf0e10cSrcweir #define NS_PREFIX "help"
44cdf0e10cSrcweir #define ROOT_ELEMENT_NAME "help-backend-db"
45cdf0e10cSrcweir #define KEY_ELEMENT_NAME "help"
46cdf0e10cSrcweir
47cdf0e10cSrcweir namespace dp_registry {
48cdf0e10cSrcweir namespace backend {
49cdf0e10cSrcweir namespace help {
50cdf0e10cSrcweir
HelpBackendDb(Reference<XComponentContext> const & xContext,::rtl::OUString const & url)51cdf0e10cSrcweir HelpBackendDb::HelpBackendDb(
52cdf0e10cSrcweir Reference<XComponentContext> const & xContext,
53cdf0e10cSrcweir ::rtl::OUString const & url):BackendDb(xContext, url)
54cdf0e10cSrcweir {
55cdf0e10cSrcweir
56cdf0e10cSrcweir }
57cdf0e10cSrcweir
getDbNSName()58cdf0e10cSrcweir OUString HelpBackendDb::getDbNSName()
59cdf0e10cSrcweir {
60cdf0e10cSrcweir return OUSTR(EXTENSION_REG_NS);
61cdf0e10cSrcweir }
62cdf0e10cSrcweir
getNSPrefix()63cdf0e10cSrcweir OUString HelpBackendDb::getNSPrefix()
64cdf0e10cSrcweir {
65cdf0e10cSrcweir return OUSTR(NS_PREFIX);
66cdf0e10cSrcweir }
67cdf0e10cSrcweir
getRootElementName()68cdf0e10cSrcweir OUString HelpBackendDb::getRootElementName()
69cdf0e10cSrcweir {
70cdf0e10cSrcweir return OUSTR(ROOT_ELEMENT_NAME);
71cdf0e10cSrcweir }
72cdf0e10cSrcweir
getKeyElementName()73cdf0e10cSrcweir OUString HelpBackendDb::getKeyElementName()
74cdf0e10cSrcweir {
75cdf0e10cSrcweir return OUSTR(KEY_ELEMENT_NAME);
76cdf0e10cSrcweir }
77cdf0e10cSrcweir
78cdf0e10cSrcweir
addEntry(::rtl::OUString const & url,Data const & data)79cdf0e10cSrcweir void HelpBackendDb::addEntry(::rtl::OUString const & url, Data const & data)
80cdf0e10cSrcweir {
81cdf0e10cSrcweir try{
82cdf0e10cSrcweir if (!activateEntry(url))
83cdf0e10cSrcweir {
84cdf0e10cSrcweir Reference<css::xml::dom::XNode> helpNode
85cdf0e10cSrcweir = writeKeyElement(url);
86cdf0e10cSrcweir
87cdf0e10cSrcweir writeSimpleElement(OUSTR("data-url"), data.dataUrl, helpNode);
88cdf0e10cSrcweir save();
89cdf0e10cSrcweir }
90cdf0e10cSrcweir }
91cdf0e10cSrcweir catch (css::deployment::DeploymentException& )
92cdf0e10cSrcweir {
93cdf0e10cSrcweir throw;
94cdf0e10cSrcweir }
95cdf0e10cSrcweir catch(css::uno::Exception &)
96cdf0e10cSrcweir {
97cdf0e10cSrcweir Any exc( ::cppu::getCaughtException() );
98cdf0e10cSrcweir throw css::deployment::DeploymentException(
99cdf0e10cSrcweir OUSTR("Extension Manager: failed to write data entry in help backend db: ") +
100cdf0e10cSrcweir m_urlDb, 0, exc);
101cdf0e10cSrcweir }
102cdf0e10cSrcweir }
103cdf0e10cSrcweir
104cdf0e10cSrcweir
105cdf0e10cSrcweir ::boost::optional<HelpBackendDb::Data>
getEntry(::rtl::OUString const & url)106cdf0e10cSrcweir HelpBackendDb::getEntry(::rtl::OUString const & url)
107cdf0e10cSrcweir {
108cdf0e10cSrcweir try
109cdf0e10cSrcweir {
110cdf0e10cSrcweir HelpBackendDb::Data retData;
111cdf0e10cSrcweir Reference<css::xml::dom::XNode> aNode = getKeyElement(url);
112cdf0e10cSrcweir if (aNode.is())
113cdf0e10cSrcweir {
114cdf0e10cSrcweir retData.dataUrl = readSimpleElement(OUSTR("data-url"), aNode);
115cdf0e10cSrcweir }
116cdf0e10cSrcweir else
117cdf0e10cSrcweir {
118cdf0e10cSrcweir return ::boost::optional<Data>();
119cdf0e10cSrcweir }
120cdf0e10cSrcweir return ::boost::optional<Data>(retData);
121cdf0e10cSrcweir }
122cdf0e10cSrcweir catch (css::deployment::DeploymentException& )
123cdf0e10cSrcweir {
124cdf0e10cSrcweir throw;
125cdf0e10cSrcweir }
126cdf0e10cSrcweir catch(css::uno::Exception &)
127cdf0e10cSrcweir {
128cdf0e10cSrcweir Any exc( ::cppu::getCaughtException() );
129cdf0e10cSrcweir throw css::deployment::DeploymentException(
130cdf0e10cSrcweir OUSTR("Extension Manager: failed to read data entry in help backend db: ") +
131cdf0e10cSrcweir m_urlDb, 0, exc);
132cdf0e10cSrcweir }
133cdf0e10cSrcweir }
134cdf0e10cSrcweir
getAllDataUrls()135cdf0e10cSrcweir ::std::list<OUString> HelpBackendDb::getAllDataUrls()
136cdf0e10cSrcweir {
137cdf0e10cSrcweir try
138cdf0e10cSrcweir {
139cdf0e10cSrcweir ::std::list<OUString> listRet;
140cdf0e10cSrcweir Reference<css::xml::dom::XDocument> doc = getDocument();
141cdf0e10cSrcweir Reference<css::xml::dom::XNode> root = doc->getFirstChild();
142cdf0e10cSrcweir
143cdf0e10cSrcweir Reference<css::xml::xpath::XXPathAPI> xpathApi = getXPathAPI();
144cdf0e10cSrcweir const OUString sPrefix = getNSPrefix();
145cdf0e10cSrcweir OUString sExpression(
146cdf0e10cSrcweir sPrefix + OUSTR(":help/") + sPrefix + OUSTR(":data-url/text()"));
147cdf0e10cSrcweir Reference<css::xml::dom::XNodeList> nodes =
148cdf0e10cSrcweir xpathApi->selectNodeList(root, sExpression);
149cdf0e10cSrcweir if (nodes.is())
150cdf0e10cSrcweir {
151cdf0e10cSrcweir sal_Int32 length = nodes->getLength();
152cdf0e10cSrcweir for (sal_Int32 i = 0; i < length; i++)
153cdf0e10cSrcweir listRet.push_back(nodes->item(i)->getNodeValue());
154cdf0e10cSrcweir }
155cdf0e10cSrcweir return listRet;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir catch (css::deployment::DeploymentException& )
158cdf0e10cSrcweir {
159cdf0e10cSrcweir throw;
160cdf0e10cSrcweir }
161cdf0e10cSrcweir catch(css::uno::Exception &)
162cdf0e10cSrcweir {
163cdf0e10cSrcweir Any exc( ::cppu::getCaughtException() );
164cdf0e10cSrcweir throw css::deployment::DeploymentException(
165cdf0e10cSrcweir OUSTR("Extension Manager: failed to read data entry in help backend db: ") +
166cdf0e10cSrcweir m_urlDb, 0, exc);
167cdf0e10cSrcweir }
168cdf0e10cSrcweir }
169cdf0e10cSrcweir
170cdf0e10cSrcweir
171cdf0e10cSrcweir } // namespace help
172cdf0e10cSrcweir } // namespace backend
173cdf0e10cSrcweir } // namespace dp_registry
174cdf0e10cSrcweir
175