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