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