LCOV - code coverage report
Current view: top level - desktop/source/deployment/manager - dp_informationprovider.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 3 113 2.7 %
Date: 2012-08-25 Functions: 2 9 22.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 260 0.8 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <cppuhelper/implbase3.hxx>
      30                 :            : #include "comphelper/servicedecl.hxx"
      31                 :            : 
      32                 :            : #include "com/sun/star/deployment/UpdateInformationProvider.hpp"
      33                 :            : #include "com/sun/star/deployment/XPackage.hpp"
      34                 :            : #include "com/sun/star/deployment/XPackageInformationProvider.hpp"
      35                 :            : #include "com/sun/star/deployment/ExtensionManager.hpp"
      36                 :            : #include "com/sun/star/deployment/XUpdateInformationProvider.hpp"
      37                 :            : #include "com/sun/star/lang/XServiceInfo.hpp"
      38                 :            : #include "com/sun/star/registry/XRegistryKey.hpp"
      39                 :            : #include "com/sun/star/task/XAbortChannel.hpp"
      40                 :            : #include "com/sun/star/uno/XComponentContext.hpp"
      41                 :            : #include "com/sun/star/ucb/XCommandEnvironment.hpp"
      42                 :            : #include "com/sun/star/xml/dom/XElement.hpp"
      43                 :            : #include "com/sun/star/xml/dom/XNode.hpp"
      44                 :            : 
      45                 :            : #include "com/sun/star/uno/Reference.hxx"
      46                 :            : #include "rtl/ustring.hxx"
      47                 :            : #include "ucbhelper/content.hxx"
      48                 :            : 
      49                 :            : #include "dp_dependencies.hxx"
      50                 :            : #include "dp_descriptioninfoset.hxx"
      51                 :            : #include "dp_identifier.hxx"
      52                 :            : #include "dp_version.hxx"
      53                 :            : #include "dp_misc.h"
      54                 :            : #include "dp_update.hxx"
      55                 :            : 
      56                 :            : namespace beans      = com::sun::star::beans ;
      57                 :            : namespace deployment = com::sun::star::deployment ;
      58                 :            : namespace lang       = com::sun::star::lang ;
      59                 :            : namespace registry   = com::sun::star::registry ;
      60                 :            : namespace task       = com::sun::star::task ;
      61                 :            : namespace css_ucb    = com::sun::star::ucb ;
      62                 :            : namespace uno        = com::sun::star::uno ;
      63                 :            : namespace xml = com::sun::star::xml ;
      64                 :            : 
      65                 :            : #define UNISTRING(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
      66                 :            : 
      67                 :            : namespace dp_info {
      68                 :            : 
      69                 :            : class PackageInformationProvider :
      70                 :            :         public ::cppu::WeakImplHelper1< deployment::XPackageInformationProvider >
      71                 :            : 
      72                 :            : {
      73                 :            :     public:
      74                 :            :                  PackageInformationProvider( uno::Reference< uno::XComponentContext >const& xContext);
      75                 :            :     virtual     ~PackageInformationProvider();
      76                 :            : 
      77                 :            :     static uno::Sequence< rtl::OUString > getServiceNames();
      78                 :            :     static rtl::OUString getImplName();
      79                 :            : 
      80                 :            :     // XPackageInformationProvider
      81                 :            :     virtual rtl::OUString SAL_CALL getPackageLocation( const rtl::OUString& extensionId )
      82                 :            :         throw ( uno::RuntimeException );
      83                 :            :     virtual uno::Sequence< uno::Sequence< rtl::OUString > > SAL_CALL isUpdateAvailable( const rtl::OUString& extensionId )
      84                 :            :         throw ( uno::RuntimeException );
      85                 :            :     virtual uno::Sequence< uno::Sequence< rtl::OUString > > SAL_CALL getExtensionList()
      86                 :            :         throw ( uno::RuntimeException );
      87                 :            : //---------
      88                 :            : private:
      89                 :            : 
      90                 :            :     uno::Reference< uno::XComponentContext> mxContext;
      91                 :            : 
      92                 :            :     rtl::OUString getPackageLocation( const rtl::OUString& repository,
      93                 :            :                                       const rtl::OUString& _sExtensionId );
      94                 :            : 
      95                 :            :     uno::Reference< deployment::XUpdateInformationProvider > mxUpdateInformation;
      96                 :            : };
      97                 :            : 
      98                 :            : //------------------------------------------------------------------------------
      99                 :            : 
     100                 :          0 : PackageInformationProvider::PackageInformationProvider( uno::Reference< uno::XComponentContext > const& xContext) :
     101                 :            :     mxContext( xContext ),
     102         [ #  # ]:          0 :     mxUpdateInformation( deployment::UpdateInformationProvider::create( xContext ) )
     103                 :            : {
     104                 :          0 : }
     105                 :            : 
     106                 :            : //------------------------------------------------------------------------------
     107                 :            : 
     108                 :          0 : PackageInformationProvider::~PackageInformationProvider()
     109                 :            : {
     110         [ #  # ]:          0 : }
     111                 :            : 
     112                 :            : //------------------------------------------------------------------------------
     113                 :          0 : rtl::OUString PackageInformationProvider::getPackageLocation(
     114                 :            :     const rtl::OUString & repository,
     115                 :            :     const rtl::OUString& _rExtensionId )
     116                 :            : {
     117                 :          0 :     rtl::OUString aLocationURL;
     118                 :            :     uno::Reference<deployment::XExtensionManager> xManager =
     119         [ #  # ]:          0 :         deployment::ExtensionManager::get(mxContext);
     120                 :            : 
     121         [ #  # ]:          0 :     if ( xManager.is() )
     122                 :            :     {
     123                 :            :         const uno::Sequence< uno::Reference< deployment::XPackage > > packages(
     124         [ #  # ]:          0 :                 xManager->getDeployedExtensions(
     125                 :            :                     repository,
     126                 :            :                     uno::Reference< task::XAbortChannel >(),
     127         [ #  # ]:          0 :                     uno::Reference< css_ucb::XCommandEnvironment > () ) );
     128                 :            : 
     129         [ #  # ]:          0 :         for ( int pos = packages.getLength(); pos--; )
     130                 :            :         {
     131                 :            :             try
     132                 :            :             {
     133 [ #  # ][ #  # ]:          0 :                 const rtl::OUString aName = packages[ pos ]->getName();
     134 [ #  # ][ #  # ]:          0 :                 const beans::Optional< rtl::OUString > aID = packages[ pos ]->getIdentifier();
     135 [ #  # ][ #  # ]:          0 :                 if ( aID.IsPresent && aID.Value.compareTo( _rExtensionId ) == 0 )
                 [ #  # ]
     136                 :            :                 {
     137 [ #  # ][ #  # ]:          0 :                     aLocationURL = packages[ pos ]->getURL();
     138                 :            :                     break;
     139 [ #  # ][ #  # ]:          0 :                 }
                 [ #  # ]
     140                 :            :             }
     141         [ #  # ]:          0 :             catch ( uno::RuntimeException & ) {}
     142         [ #  # ]:          0 :         }
     143                 :            :     }
     144                 :            : 
     145                 :          0 :     return aLocationURL;
     146                 :            : }
     147                 :            : 
     148                 :            : //------------------------------------------------------------------------------
     149                 :            : 
     150                 :            : rtl::OUString SAL_CALL
     151                 :          0 : PackageInformationProvider::getPackageLocation( const rtl::OUString& _sExtensionId )
     152                 :            :     throw ( uno::RuntimeException )
     153                 :            : {
     154         [ #  # ]:          0 :     rtl::OUString aLocationURL = getPackageLocation( UNISTRING("user"), _sExtensionId );
     155                 :            : 
     156         [ #  # ]:          0 :     if ( aLocationURL.isEmpty() )
     157                 :            :     {
     158 [ #  # ][ #  # ]:          0 :         aLocationURL = getPackageLocation( UNISTRING("shared"), _sExtensionId );
     159                 :            :     }
     160         [ #  # ]:          0 :     if ( aLocationURL.isEmpty() )
     161                 :            :     {
     162 [ #  # ][ #  # ]:          0 :         aLocationURL = getPackageLocation( UNISTRING("bundled"), _sExtensionId );
     163                 :            :     }
     164         [ #  # ]:          0 :     if ( !aLocationURL.isEmpty() )
     165                 :            :     {
     166 [ #  # ][ #  # ]:          0 :         ::ucbhelper::Content aContent( aLocationURL, NULL );
     167 [ #  # ][ #  # ]:          0 :         aLocationURL = aContent.getURL();
     168                 :            :     }
     169                 :          0 :     return aLocationURL;
     170                 :            : }
     171                 :            : 
     172                 :            : //------------------------------------------------------------------------------
     173                 :            : 
     174                 :            : uno::Sequence< uno::Sequence< rtl::OUString > > SAL_CALL
     175                 :          0 : PackageInformationProvider::isUpdateAvailable( const rtl::OUString& _sExtensionId )
     176                 :            :     throw ( uno::RuntimeException )
     177                 :            : {
     178         [ #  # ]:          0 :     uno::Sequence< uno::Sequence< rtl::OUString > > aList;
     179                 :            : 
     180                 :            :     uno::Reference<deployment::XExtensionManager> extMgr =
     181         [ #  # ]:          0 :         deployment::ExtensionManager::get(mxContext);
     182                 :            : 
     183         [ #  # ]:          0 :     if (!extMgr.is())
     184                 :            :     {
     185                 :            :         OSL_ASSERT(0);
     186                 :            :         return aList;
     187                 :            :     }
     188         [ #  # ]:          0 :     std::vector<std::pair<uno::Reference<deployment::XPackage>, uno::Any > > errors;
     189         [ #  # ]:          0 :     dp_misc::UpdateInfoMap updateInfoMap;
     190         [ #  # ]:          0 :     if (!_sExtensionId.isEmpty())
     191                 :            :     {
     192         [ #  # ]:          0 :         std::vector<uno::Reference<deployment::XPackage> > vecExtensions;
     193                 :          0 :         uno::Reference<deployment::XPackage> extension;
     194                 :            :         try
     195                 :            :         {
     196                 :            :             extension = dp_misc::getExtensionWithHighestVersion(
     197         [ #  # ]:          0 :                 extMgr->getExtensionsWithSameIdentifier(
     198 [ #  # ][ #  # ]:          0 :                     _sExtensionId, _sExtensionId, uno::Reference<css_ucb::XCommandEnvironment>()));
         [ #  # ][ #  # ]
                 [ #  # ]
     199         [ #  # ]:          0 :             vecExtensions.push_back(extension);
     200                 :            :         }
     201         [ #  # ]:          0 :         catch (lang::IllegalArgumentException &)
     202                 :            :         {
     203                 :            :             OSL_ASSERT(0);
     204                 :            :         }
     205                 :            :         updateInfoMap = dp_misc::getOnlineUpdateInfos(
     206 [ #  # ][ #  # ]:          0 :             mxContext, extMgr, mxUpdateInformation, &vecExtensions, errors);
     207                 :            :     }
     208                 :            :     else
     209                 :            :     {
     210                 :            :         updateInfoMap = dp_misc::getOnlineUpdateInfos(
     211 [ #  # ][ #  # ]:          0 :             mxContext, extMgr, mxUpdateInformation, NULL, errors);
     212                 :            :     }
     213                 :            : 
     214                 :          0 :     int nCount = 0;
     215         [ #  # ]:          0 :     for (dp_misc::UpdateInfoMap::iterator i(updateInfoMap.begin()); i != updateInfoMap.end(); ++i)
     216                 :            :     {
     217                 :          0 :         dp_misc::UpdateInfo const & info = i->second;
     218                 :            : 
     219                 :          0 :         rtl::OUString sOnlineVersion;
     220         [ #  # ]:          0 :         if (info.info.is())
     221                 :            :         {
     222                 :            :             // check, if there are unsatisfied dependencies and ignore this online update
     223         [ #  # ]:          0 :             dp_misc::DescriptionInfoset infoset(mxContext, info.info);
     224                 :            :             uno::Sequence< uno::Reference< xml::dom::XElement > >
     225         [ #  # ]:          0 :                 ds( dp_misc::Dependencies::check( infoset ) );
     226         [ #  # ]:          0 :             if ( ! ds.getLength() )
     227 [ #  # ][ #  # ]:          0 :                 sOnlineVersion = info.version;
     228                 :            :         }
     229                 :            : 
     230                 :          0 :         rtl::OUString sVersionUser;
     231                 :          0 :         rtl::OUString sVersionShared;
     232                 :          0 :         rtl::OUString sVersionBundled;
     233         [ #  # ]:          0 :         uno::Sequence< uno::Reference< deployment::XPackage> > extensions;
     234                 :            :         try {
     235         [ #  # ]:          0 :             extensions = extMgr->getExtensionsWithSameIdentifier(
     236         [ #  # ]:          0 :                 dp_misc::getIdentifier(info.extension), info.extension->getName(),
     237 [ #  # ][ #  # ]:          0 :                 uno::Reference<css_ucb::XCommandEnvironment>());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     238         [ #  # ]:          0 :         } catch (lang::IllegalArgumentException& ) {
     239                 :            :             OSL_ASSERT(0);
     240                 :            :         }
     241                 :            :         OSL_ASSERT(extensions.getLength() == 3);
     242 [ #  # ][ #  # ]:          0 :         if (extensions[0].is() )
     243 [ #  # ][ #  # ]:          0 :             sVersionUser = extensions[0]->getVersion();
                 [ #  # ]
     244 [ #  # ][ #  # ]:          0 :         if (extensions[1].is() )
     245 [ #  # ][ #  # ]:          0 :             sVersionShared = extensions[1]->getVersion();
                 [ #  # ]
     246 [ #  # ][ #  # ]:          0 :         if (extensions[2].is() )
     247 [ #  # ][ #  # ]:          0 :             sVersionBundled = extensions[2]->getVersion();
                 [ #  # ]
     248                 :            : 
     249 [ #  # ][ #  # ]:          0 :         bool bSharedReadOnly = extMgr->isReadOnlyRepository(OUSTR("shared"));
                 [ #  # ]
     250                 :            : 
     251                 :            :         dp_misc::UPDATE_SOURCE sourceUser = dp_misc::isUpdateUserExtension(
     252         [ #  # ]:          0 :             bSharedReadOnly, sVersionUser, sVersionShared, sVersionBundled, sOnlineVersion);
     253                 :            :         dp_misc::UPDATE_SOURCE sourceShared = dp_misc::isUpdateSharedExtension(
     254         [ #  # ]:          0 :             bSharedReadOnly, sVersionShared, sVersionBundled, sOnlineVersion);
     255                 :            : 
     256                 :          0 :         rtl::OUString updateVersionUser;
     257                 :          0 :         rtl::OUString updateVersionShared;
     258         [ #  # ]:          0 :         if (sourceUser != dp_misc::UPDATE_SOURCE_NONE)
     259                 :            :             updateVersionUser = dp_misc::getHighestVersion(
     260         [ #  # ]:          0 :                 rtl::OUString(), sVersionShared, sVersionBundled, sOnlineVersion);
     261         [ #  # ]:          0 :         if (sourceShared  != dp_misc::UPDATE_SOURCE_NONE)
     262                 :            :             updateVersionShared = dp_misc::getHighestVersion(
     263         [ #  # ]:          0 :                 rtl::OUString(), rtl::OUString(), sVersionBundled, sOnlineVersion);
     264                 :          0 :         rtl::OUString updateVersion;
     265 [ #  # ][ #  # ]:          0 :         if (dp_misc::compareVersions(updateVersionUser, updateVersionShared) == dp_misc::GREATER)
     266                 :          0 :             updateVersion = updateVersionUser;
     267                 :            :         else
     268                 :          0 :             updateVersion = updateVersionShared;
     269         [ #  # ]:          0 :         if (!updateVersion.isEmpty())
     270                 :            :         {
     271                 :            : 
     272         [ #  # ]:          0 :             rtl::OUString aNewEntry[2];
     273                 :          0 :             aNewEntry[0] = i->first;
     274                 :          0 :             aNewEntry[1] = updateVersion;
     275         [ #  # ]:          0 :             aList.realloc( ++nCount );
     276 [ #  # ][ #  # ]:          0 :             aList[ nCount-1 ] = ::uno::Sequence< rtl::OUString >( aNewEntry, 2 );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     277                 :            :         }
     278         [ #  # ]:          0 :     }
     279                 :          0 :     return aList;
     280                 :            : }
     281                 :            : 
     282                 :            : //------------------------------------------------------------------------------
     283                 :          0 : uno::Sequence< uno::Sequence< rtl::OUString > > SAL_CALL PackageInformationProvider::getExtensionList()
     284                 :            :     throw ( uno::RuntimeException )
     285                 :            : {
     286                 :            :     const uno::Reference<deployment::XExtensionManager> mgr =
     287         [ #  # ]:          0 :         deployment::ExtensionManager::get(mxContext);
     288                 :            : 
     289         [ #  # ]:          0 :     if (!mgr.is())
     290         [ #  # ]:          0 :         return uno::Sequence< uno::Sequence< rtl::OUString > >();
     291                 :            : 
     292                 :            :     const uno::Sequence< uno::Sequence< uno::Reference<deployment::XPackage > > >
     293         [ #  # ]:          0 :         allExt =  mgr->getAllExtensions(
     294                 :            :             uno::Reference< task::XAbortChannel >(),
     295         [ #  # ]:          0 :             uno::Reference< css_ucb::XCommandEnvironment > () );
     296                 :            : 
     297         [ #  # ]:          0 :     uno::Sequence< uno::Sequence< rtl::OUString > > retList;
     298                 :            : 
     299                 :          0 :     sal_Int32 cAllIds = allExt.getLength();
     300         [ #  # ]:          0 :     retList.realloc(cAllIds);
     301                 :            : 
     302         [ #  # ]:          0 :     for (sal_Int32 i = 0; i < cAllIds; i++)
     303                 :            :     {
     304                 :            :         //The inner sequence contains extensions with the same identifier from
     305                 :            :         //all the different repositories, that is user, share, bundled.
     306                 :            :         const uno::Sequence< uno::Reference< deployment::XPackage > > &
     307                 :          0 :             seqExtension = allExt[i];
     308                 :          0 :         sal_Int32 cExt = seqExtension.getLength();
     309                 :            :         OSL_ASSERT(cExt == 3);
     310         [ #  # ]:          0 :         for (sal_Int32 j = 0; j < cExt; j++)
     311                 :            :         {
     312                 :            :             //ToDo according to the old code the first found extenions is used
     313                 :            :             //even if another one with the same id has a better version.
     314                 :          0 :             uno::Reference< deployment::XPackage > const & xExtension( seqExtension[j] );
     315         [ #  # ]:          0 :             if (xExtension.is())
     316                 :            :             {
     317         [ #  # ]:          0 :                 rtl::OUString aNewEntry[2];
     318         [ #  # ]:          0 :                 aNewEntry[0] = dp_misc::getIdentifier(xExtension);
     319 [ #  # ][ #  # ]:          0 :                 aNewEntry[1] = xExtension->getVersion();
     320 [ #  # ][ #  # ]:          0 :                 retList[i] = ::uno::Sequence< rtl::OUString >( aNewEntry, 2 );
         [ #  # ][ #  # ]
     321 [ #  # ][ #  # ]:          0 :                 break;
     322                 :            :             }
     323                 :            :         }
     324                 :            :     }
     325 [ #  # ][ #  # ]:          0 :     return retList;
                 [ #  # ]
     326                 :            : }
     327                 :            : 
     328                 :            : 
     329                 :            : //------------------------------------------------------------------------------
     330                 :            : 
     331                 :            : namespace sdecl = comphelper::service_decl;
     332                 :        124 : sdecl::class_<PackageInformationProvider> servicePIP;
     333                 :        124 : extern sdecl::ServiceDecl const serviceDecl(
     334                 :            :     servicePIP,
     335                 :            :     // a private one:
     336                 :            :     "com.sun.star.comp.deployment.PackageInformationProvider",
     337                 :            :     "com.sun.star.comp.deployment.PackageInformationProvider" );
     338                 :            : 
     339 [ +  - ][ +  - ]:        372 : } // namespace dp_info
     340                 :            : 
     341                 :            : 
     342                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10