1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <sal/config.h>
25 #include <string_view>
27 #include <com/sun/star/uno/Reference.hxx>
28 #include <com/sun/star/uno/Sequence.hxx>
29 #include <sal/types.h>
30 #include "dp_misc_api.hxx"
34 namespace com::sun::star
{
35 namespace uno
{ class XComponentContext
; }
41 namespace xpath
{ class XXPathAPI
; }
47 struct DESKTOP_DEPLOYMENTMISC_DLLPUBLIC SimpleLicenseAttributes
50 //Attribute suppress-on-update. Default is false.
51 bool suppressOnUpdate
;
52 //Attribute suppress-if-required. Default is false.
53 bool suppressIfRequired
;
58 Access to the content of an XML <code>description</code> element.
60 <p>This works for <code>description</code> elements in both the
61 <code>description.xml</code> file and online update information formats.</p>
63 class DESKTOP_DEPLOYMENTMISC_DLLPUBLIC DescriptionInfoset
{
69 a non-null component context
72 a <code>description</code> element; may be null (equivalent to an element
76 css::uno::Reference
< css::uno::XComponentContext
> const & context
,
77 css::uno::Reference
< css::xml::dom::XNode
> const & element
);
79 ~DescriptionInfoset();
82 Return the identifier.
85 the identifier, or an empty <code>optional</code> if none is specified
87 ::std::optional
< OUString
> getIdentifier() const;
90 Return the textual version representation.
93 textual version representation
95 OUString
getVersion() const;
98 Returns a list of supported platforms.
100 If the extension does not specify a platform by leaving out the platform element
101 then we assume that the extension supports all platforms. In this case the returned
102 sequence will have one element, which is "all".
103 If the platform element is present but does not specify a platform then an empty
104 sequence is returned. Examples for invalid platform elements:
106 <platform />, <platform value="" />, <platform value=",">
109 The value attribute can contain various platform tokens. They must be separated by
110 commas.Each token will be stripped from leading and trailing white space (trim()).
112 css::uno::Sequence
< OUString
> getSupportedPlatforms() const;
115 Returns the localized publisher name and the corresponding URL.
117 In case there is no publisher element then a pair of two empty strings is returned.
119 std::pair
< OUString
, OUString
> getLocalizedPublisherNameAndURL() const;
122 Returns the URL for the release notes corresponding to the office's locale.
124 In case there is no release-notes element then an empty string is returned.
126 OUString
getLocalizedReleaseNotesURL() const;
128 /** returns the relative path to the license file.
130 In case there is no simple-license element then an empty string is returned.
132 OUString
getLocalizedLicenseURL() const;
134 /** returns the attributes of the simple-license element
136 As long as there is a simple-license element, the function will return
137 the structure. If it does not exist, then the optional object is uninitialized.
139 ::std::optional
<SimpleLicenseAttributes
> getSimpleLicenseAttributes() const;
141 /** returns the localized display name of the extensions.
143 In case there is no localized display-name then an empty string is returned.
145 OUString
getLocalizedDisplayName() const;
148 returns the download website URL from the update information.
150 There can be multiple URLs where each is assigned to a particular locale.
151 The function returns the URL which locale matches best the one used in the office.
153 The return value is an optional because it may be necessary to find out if there
154 was a value provided or not. This is necessary to flag the extension in the update dialog
155 properly as "browser based update". The return value will only then not be initialized
156 if there is no <code><update-website></code>. If the element exists, then it must
157 have at least one child element containing a URL.
159 The <code><update-website></code> and <code><update-download></code>
160 elements are mutually exclusive.
163 the download website URL, or an empty <code>optional</code> if none is
166 ::std::optional
< OUString
> getLocalizedUpdateWebsiteURL() const;
168 /** returns the relative URL to the description.
170 The URL is relative to the root directory of the extensions.
172 OUString
getLocalizedDescriptionURL() const;
174 Return the dependencies.
177 dependencies; will never be null
179 css::uno::Reference
< css::xml::dom::XNodeList
>
180 getDependencies() const;
183 Return the update information URLs.
186 update information URLs
188 css::uno::Sequence
< OUString
> getUpdateInformationUrls() const;
191 Return the download URLs from the update information.
193 Because the <code><update-download></code> and the <code><update-website></code>
194 elements are mutually exclusive one may need to determine exactly if the element
200 css::uno::Sequence
< OUString
> getUpdateDownloadUrls() const;
203 Returns the URL for the icon image.
205 OUString
getIconURL( bool bHighContrast
) const;
207 bool hasDescription() const;
210 SAL_DLLPRIVATE ::std::optional
< OUString
> getOptionalValue(
211 OUString
const & expression
) const;
213 SAL_DLLPRIVATE
css::uno::Sequence
< OUString
> getUrls(
214 OUString
const & expression
) const;
216 /** Retrieves a child element which as lang attribute which matches the office locale.
218 Only top-level children are taken into account. It is also assumed that they are all
219 of the same element type and have a lang attribute. The matching algorithm is according
220 to RFC 3066, with the exception that only one variant is allowed.
222 the expression used to obtain the parent of the localized children. It can be null.
223 Then a null reference is returned.
225 SAL_DLLPRIVATE
css::uno::Reference
< css::xml::dom::XNode
>
226 getLocalizedChild( OUString
const & sParent
) const;
227 SAL_DLLPRIVATE
css::uno::Reference
< css::xml::dom::XNode
>
229 css::uno::Reference
< css::xml::dom::XNode
> const & xParent
,
230 std::u16string_view rTag
) const;
232 /** If there is no child element with a locale matching the office locale, then we use
233 the first child. In the case of the simple-license we also use the former default locale, which
234 was determined by the default-license-id (/description/registration/simple-license/@default-license-id)
235 and the license-id attributes (/description/registration/simple-license/license-text/@license-id).
236 However, since OOo 2.4 we use also the first child as default for the license
237 unless the two attributes are present.
239 SAL_DLLPRIVATE
css::uno::Reference
< css::xml::dom::XNode
>
240 getChildWithDefaultLocale(
241 css::uno::Reference
< css::xml::dom::XNode
> const & xParent
) const;
243 @param out_bParentExists
244 indicates if the element node specified in sXPathParent exists.
246 SAL_DLLPRIVATE OUString
getLocalizedHREFAttrFromChild(
247 OUString
const & sXPathParent
, bool * out_bParentExists
) const;
249 /** Gets the node value for a given expression. The expression is used in
250 m_xpath-selectSingleNode. The value of the returned node is return value
253 SAL_DLLPRIVATE OUString
254 getNodeValueFromExpression(OUString
const & expression
) const;
256 /** Check the extensions denylist if additional extension meta data (e.g. dependencies)
257 are defined for this extension and have to be taken into account.
260 checkDenylist() const;
262 /** Helper method to compare the versions with the current version
264 SAL_DLLPRIVATE
static bool
265 checkDenylistVersion(std::u16string_view currentversion
,
266 css::uno::Sequence
< OUString
> const & versions
);
268 css::uno::Reference
< css::uno::XComponentContext
> m_context
;
269 css::uno::Reference
< css::xml::dom::XNode
> m_element
;
270 css::uno::Reference
< css::xml::xpath::XXPathAPI
> m_xpath
;
273 inline bool DescriptionInfoset::hasDescription() const
275 return m_element
.is();
278 /** creates a DescriptionInfoset object.
280 The argument sExtensionFolderURL is a file URL to extension folder containing
283 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC
284 DescriptionInfoset
getDescriptionInfoset(std::u16string_view sExtensionFolderURL
);
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */