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