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 : #ifndef INCLUDED_DESKTOP_SOURCE_DEPLOYMENT_INC_DP_DESCRIPTIONINFOSET_HXX
21 : #define INCLUDED_DESKTOP_SOURCE_DEPLOYMENT_INC_DP_DESCRIPTIONINFOSET_HXX
22 :
23 : #include "sal/config.h"
24 :
25 : #include "boost/optional.hpp"
26 : #include "com/sun/star/uno/Reference.hxx"
27 : #include "com/sun/star/uno/Sequence.hxx"
28 : #include "sal/types.h"
29 : #include "dp_misc_api.hxx"
30 :
31 : /// @HTML
32 :
33 : namespace com { namespace sun { namespace star {
34 : namespace lang { struct Locale; }
35 : namespace uno { class XComponentContext; }
36 : namespace xml {
37 : namespace dom {
38 : class XNode;
39 : class XNodeList;
40 : }
41 : namespace xpath { class XXPathAPI; }
42 : }
43 : } } }
44 : namespace rtl { class OUString; }
45 :
46 : namespace dp_misc {
47 :
48 0 : struct DESKTOP_DEPLOYMENTMISC_DLLPUBLIC SimpleLicenseAttributes
49 : {
50 : ::rtl::OUString acceptBy;
51 : //Attribute suppress-on-update. Default is false.
52 : bool suppressOnUpdate;
53 : //Attribute suppress-if-required. Default is false.
54 : bool suppressIfRequired;
55 : };
56 :
57 :
58 : /**
59 : Access to the content of an XML <code>description</code> element.
60 :
61 : <p>This works for <code>description</code> elements in both the
62 : <code>description.xml</code> file and online update information formats.</p>
63 : */
64 : class DESKTOP_DEPLOYMENTMISC_DLLPUBLIC DescriptionInfoset {
65 : public:
66 : /**
67 : Create an instance.
68 :
69 : @param context
70 : a non-null component context
71 :
72 : @param element
73 : a <code>description</code> element; may be null (equivalent to an element
74 : with no content)
75 : */
76 : DescriptionInfoset(
77 : ::com::sun::star::uno::Reference<
78 : ::com::sun::star::uno::XComponentContext > const & context,
79 : ::com::sun::star::uno::Reference<
80 : ::com::sun::star::xml::dom::XNode > const & element);
81 :
82 : ~DescriptionInfoset();
83 :
84 : /**
85 : Return the identifier.
86 :
87 : @return
88 : the identifier, or an empty <code>optional</code> if none is specified
89 : */
90 : ::boost::optional< ::rtl::OUString > getIdentifier() const;
91 :
92 : /**
93 : Return the textual version representation.
94 :
95 : @return
96 : textual version representation
97 : */
98 : ::rtl::OUString getVersion() const;
99 :
100 : /**
101 : Returns a list of supported platforms.
102 :
103 : If the extension does not specify a platform by leaving out the platform element
104 : then we assume that the extension supports all platforms. In this case the returned
105 : sequence will have one element, which is "all".
106 : If the platform element is present but does not specify a platform then an empty
107 : sequence is returned. Examples for invalid platform elements:
108 : <pre>
109 : <platform />, <platform value="" />, <platfrom value=",">
110 : </pre>
111 :
112 : The value attribute can contain various platform tokens. They must be separated by
113 : commas.Each token will be stripped from leading and trailing white space (trim()).
114 : */
115 : ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedPlaforms() const;
116 :
117 : /**
118 : Returns the localized publisher name and the corresponding URL.
119 :
120 : In case there is no publisher element then a pair of two empty strings is returned.
121 : */
122 : ::std::pair< ::rtl::OUString, ::rtl::OUString > getLocalizedPublisherNameAndURL() const;
123 :
124 : /**
125 : Returns the URL for the release notes corresponding to the office's locale.
126 :
127 : In case there is no release-notes element then an empty string is returned.
128 : */
129 : ::rtl::OUString getLocalizedReleaseNotesURL() const;
130 :
131 : /** returns the relative path to the license file.
132 :
133 : In case there is no simple-license element then an empty string is returned.
134 : */
135 : ::rtl::OUString getLocalizedLicenseURL() const;
136 :
137 : /** returns the attributes of the simple-license element
138 :
139 : As long as there is a simple-license element, the function will return
140 : the structure. If it does not exist, then the optional object is uninitialized.
141 : */
142 : ::boost::optional<SimpleLicenseAttributes> getSimpleLicenseAttributes() const;
143 :
144 : /** returns the localized display name of the extensions.
145 :
146 : In case there is no localized display-name then an empty string is returned.
147 : */
148 : ::rtl::OUString getLocalizedDisplayName() const;
149 :
150 : /**
151 : returns the download website URL from the update information.
152 :
153 : There can be multiple URLs where each is assigned to a particular locale.
154 : The function returs the URL which locale matches best the one used in the office.
155 :
156 : The return value is an optional because it may be necessary to find out if there
157 : was a value provided or not. This is necessary to flag the extension in the update dialog
158 : properly as "browser based update". The return value will only then not be initialized
159 : if there is no <code><update-website></code>. If the element exists, then it must
160 : have at least one child element containing an URL.
161 :
162 : The <code><update-website></code> and <code><update-download></code>
163 : elements are mutually exclusiv.
164 :
165 : @return
166 : the download website URL, or an empty <code>optional</code> if none is
167 : specified
168 : */
169 : ::boost::optional< ::rtl::OUString > getLocalizedUpdateWebsiteURL() const;
170 :
171 : /** returns the relative URL to the description.
172 :
173 : The URL is relative to the root directory of the extensions.
174 : */
175 : ::rtl::OUString getLocalizedDescriptionURL() const;
176 : /**
177 : Return the dependencies.
178 :
179 : @return
180 : dependencies; will never be null
181 : */
182 : ::com::sun::star::uno::Reference< ::com::sun::star::xml::dom::XNodeList >
183 : getDependencies() const;
184 :
185 : /**
186 : Return the update information URLs.
187 :
188 : @return
189 : update information URLs
190 : */
191 : ::com::sun::star::uno::Sequence< ::rtl::OUString >
192 : getUpdateInformationUrls() const;
193 :
194 : /**
195 : Return the download URLs from the update information.
196 :
197 : Because the <code><update-download></code> and the <code><update-website></code>
198 : elements are mutually exclusive one may need to determine exacty if the element
199 : was provided.
200 :
201 : @return
202 : download URLs
203 : */
204 : ::com::sun::star::uno::Sequence< ::rtl::OUString >
205 : getUpdateDownloadUrls() const;
206 :
207 : /**
208 : Returns the URL for the icon image.
209 : */
210 : ::rtl::OUString getIconURL( sal_Bool bHighContrast ) const;
211 :
212 : bool hasDescription() const;
213 :
214 : private:
215 : SAL_DLLPRIVATE ::boost::optional< ::rtl::OUString > getOptionalValue(
216 : ::rtl::OUString const & expression) const;
217 :
218 : SAL_DLLPRIVATE ::com::sun::star::uno::Sequence< ::rtl::OUString > getUrls(
219 : ::rtl::OUString const & expression) const;
220 :
221 : /** Retrieves a child element which as lang attribute which matches the office locale.
222 :
223 : Only top-level children are taken into account. It is also assumed that they are all
224 : of the same element type and have a lang attribute. The matching algoritm is according
225 : to RFC 3066, with the exception that only one variant is allowed.
226 : @param parent
227 : the expression used to obtain the parent of the localized children. It can be null.
228 : Then a null reference is returned.
229 : */
230 : SAL_DLLPRIVATE ::com::sun::star::uno::Reference< ::com::sun::star::xml::dom::XNode >
231 : getLocalizedChild( ::rtl::OUString const & sParent) const;
232 : SAL_DLLPRIVATE ::com::sun::star::uno::Reference< ::com::sun::star::xml::dom::XNode>
233 : matchFullLocale(::com::sun::star::uno::Reference<
234 : ::com::sun::star::xml::dom::XNode > const & xParent, ::rtl::OUString const & sLocale) const;
235 : SAL_DLLPRIVATE ::com::sun::star::uno::Reference< ::com::sun::star::xml::dom::XNode>
236 : matchCountryAndLanguage(::com::sun::star::uno::Reference<
237 : ::com::sun::star::xml::dom::XNode > const & xParent,
238 : ::com::sun::star::lang::Locale const & officeLocale) const;
239 : SAL_DLLPRIVATE ::com::sun::star::uno::Reference< ::com::sun::star::xml::dom::XNode>
240 : matchLanguage(
241 : ::com::sun::star::uno::Reference< ::com::sun::star::xml::dom::XNode > const & xParent,
242 : ::com::sun::star::lang::Locale const & officeLocale) const;
243 :
244 : /** If there is no child element with a locale matching the office locale, then we use
245 : the first child. In the case of the simple-license we also use the former default locale, which
246 : was determined by the default-license-id (/description/registration/simple-license/@default-license-id)
247 : and the license-id attributes (/description/registration/simple-license/license-text/@license-id).
248 : However, since OOo 2.4 we use also the first child as default for the license
249 : unless the two attributes are present.
250 : */
251 : SAL_DLLPRIVATE ::com::sun::star::uno::Reference< ::com::sun::star::xml::dom::XNode>
252 : getChildWithDefaultLocale(
253 : ::com::sun::star::uno::Reference< ::com::sun::star::xml::dom::XNode > const & xParent) const;
254 : /**
255 : @param out_bParentExists
256 : indicates if the element node specified in sXPathParent exists.
257 : */
258 : SAL_DLLPRIVATE ::rtl::OUString getLocalizedHREFAttrFromChild(
259 : ::rtl::OUString const & sXPathParent, bool * out_bParentExists) const;
260 :
261 : static SAL_DLLPRIVATE ::rtl::OUString
262 : localeToString(::com::sun::star::lang::Locale const & locale);
263 :
264 : /** Gets the node value for a given expression. The expression is used in
265 : m_xpath-selectSingleNode. The value of the returned node is return value
266 : of this function.
267 : */
268 : SAL_DLLPRIVATE ::rtl::OUString
269 : getNodeValueFromExpression(::rtl::OUString const & expression) const;
270 :
271 : /** Check the extensions blacklist if additional extension meta data (e.g. dependencies)
272 : are defined for this extension and have to be taken into account.
273 : */
274 : SAL_DLLPRIVATE void
275 : checkBlacklist() const;
276 :
277 : /** Helper method to compare the versions with the current version
278 : */
279 : SAL_DLLPRIVATE bool
280 : checkBlacklistVersion(::rtl::OUString currentversion,
281 : ::com::sun::star::uno::Sequence< ::rtl::OUString > const & versions) const;
282 :
283 : ::com::sun::star::uno::Reference<
284 : ::com::sun::star::uno::XComponentContext > m_context;
285 : ::com::sun::star::uno::Reference<
286 : ::com::sun::star::xml::dom::XNode > m_element;
287 : ::com::sun::star::uno::Reference<
288 : ::com::sun::star::xml::xpath::XXPathAPI > m_xpath;
289 : };
290 :
291 0 : inline bool DescriptionInfoset::hasDescription() const
292 : {
293 0 : return m_element.is();
294 : }
295 :
296 : /** creates a DescriptionInfoset object.
297 :
298 : The argument sExtensionFolderURL is a file URL to extension folder containing
299 : the description.xml.
300 : */
301 : DESKTOP_DEPLOYMENTMISC_DLLPUBLIC
302 : DescriptionInfoset getDescriptionInfoset(::rtl::OUString const & sExtensionFolderURL);
303 : }
304 :
305 : #endif
306 :
307 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|