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