LCOV - code coverage report
Current view: top level - desktop/source/deployment/registry - dp_backend.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 176 326 54.0 %
Date: 2012-08-25 Functions: 33 54 61.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 155 517 30.0 %

           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                 :            : 
      30                 :            : #include "dp_backend.h"
      31                 :            : #include "dp_ucb.h"
      32                 :            : #include "rtl/oustringostreaminserter.hxx"
      33                 :            : #include "rtl/uri.hxx"
      34                 :            : #include "rtl/bootstrap.hxx"
      35                 :            : #include "sal/log.hxx"
      36                 :            : #include "osl/file.hxx"
      37                 :            : #include "cppuhelper/exc_hlp.hxx"
      38                 :            : #include "comphelper/servicedecl.hxx"
      39                 :            : #include "comphelper/unwrapargs.hxx"
      40                 :            : #include "ucbhelper/content.hxx"
      41                 :            : #include "com/sun/star/lang/WrappedTargetRuntimeException.hpp"
      42                 :            : #include "com/sun/star/deployment/InvalidRemovedParameterException.hpp"
      43                 :            : #include "com/sun/star/deployment/thePackageManagerFactory.hpp"
      44                 :            : #include "com/sun/star/ucb/InteractiveAugmentedIOException.hpp"
      45                 :            : #include "com/sun/star/ucb/IOErrorCode.hpp"
      46                 :            : #include "com/sun/star/beans/StringPair.hpp"
      47                 :            : #include "com/sun/star/sdbc/XResultSet.hpp"
      48                 :            : #include "com/sun/star/sdbc/XRow.hpp"
      49                 :            : #include "unotools/tempfile.hxx"
      50                 :            : 
      51                 :            : 
      52                 :            : using namespace ::dp_misc;
      53                 :            : using namespace ::com::sun::star;
      54                 :            : using namespace ::com::sun::star::uno;
      55                 :            : using namespace ::com::sun::star::ucb;
      56                 :            : using ::rtl::OUString;
      57                 :            : 
      58                 :            : namespace dp_registry {
      59                 :            : namespace backend {
      60                 :            : 
      61                 :            : //______________________________________________________________________________
      62 [ +  - ][ +  - ]:       2660 : PackageRegistryBackend::~PackageRegistryBackend()
      63                 :            : {
      64         [ -  + ]:       2660 : }
      65                 :            : 
      66                 :            : //______________________________________________________________________________
      67                 :         58 : void PackageRegistryBackend::disposing( lang::EventObject const & event )
      68                 :            :     throw (RuntimeException)
      69                 :            : {
      70                 :            :     Reference<deployment::XPackage> xPackage(
      71         [ +  - ]:         58 :         event.Source, UNO_QUERY_THROW );
      72 [ +  - ][ +  - ]:         58 :     OUString url( xPackage->getURL() );
      73         [ +  - ]:         58 :     ::osl::MutexGuard guard( getMutex() );
      74         [ +  - ]:         58 :     if ( m_bound.erase( url ) != 1 )
      75                 :            :     {
      76                 :            :         SAL_WARN("desktop.deployment", "erase(" << url << ") != 1");
      77         [ +  - ]:         58 :     }
      78                 :         58 : }
      79                 :            : 
      80                 :            : //______________________________________________________________________________
      81                 :       2660 : PackageRegistryBackend::PackageRegistryBackend(
      82                 :            :     Sequence<Any> const & args,
      83                 :            :     Reference<XComponentContext> const & xContext )
      84                 :       2660 :     : t_BackendBase( getMutex() ),
      85                 :            :       m_xComponentContext( xContext ),
      86                 :            :       m_eContext( CONTEXT_UNKNOWN ),
      87         [ +  - ]:       5320 :       m_readOnly( false )
      88                 :            : {
      89         [ +  - ]:       2660 :     boost::optional<OUString> cachePath;
      90         [ +  - ]:       2660 :     boost::optional<bool> readOnly;
      91         [ +  - ]:       2660 :     comphelper::unwrapArgs( args, m_context, cachePath, readOnly );
      92 [ +  - ][ +  - ]:       2660 :     if (cachePath)
      93         [ +  - ]:       2660 :         m_cachePath = *cachePath;
      94 [ +  - ][ +  - ]:       2660 :     if (readOnly)
      95         [ +  - ]:       2660 :         m_readOnly = *readOnly;
      96                 :            : 
      97         [ +  + ]:       2660 :     if ( m_context == "user" )
      98                 :        868 :         m_eContext = CONTEXT_USER;
      99         [ +  + ]:       1792 :     else if ( m_context == "shared" )
     100                 :        868 :         m_eContext = CONTEXT_SHARED;
     101         [ +  + ]:        924 :     else if ( m_context == "bundled" )
     102                 :        868 :         m_eContext = CONTEXT_BUNDLED;
     103         [ +  - ]:         56 :     else if ( m_context == "tmp" )
     104                 :         56 :         m_eContext = CONTEXT_TMP;
     105         [ #  # ]:          0 :     else if (m_context.matchIgnoreAsciiCaseAsciiL(
     106                 :          0 :                  RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.tdoc:/") ))
     107                 :          0 :         m_eContext = CONTEXT_DOCUMENT;
     108                 :            :     else
     109 [ +  - ][ +  - ]:       2660 :         m_eContext = CONTEXT_UNKNOWN;
     110                 :       2660 : }
     111                 :            : 
     112                 :            : //______________________________________________________________________________
     113                 :      10410 : void PackageRegistryBackend::check()
     114                 :            : {
     115         [ +  - ]:      10410 :     ::osl::MutexGuard guard( getMutex() );
     116 [ +  - ][ -  + ]:      10410 :     if (rBHelper.bInDispose || rBHelper.bDisposed) {
     117                 :            :         throw lang::DisposedException(
     118                 :            :             OUSTR("PackageRegistryBackend instance has already been disposed!"),
     119 [ #  # ][ #  # ]:          0 :             static_cast<OWeakObject *>(this) );
                 [ #  # ]
     120         [ +  - ]:      10410 :     }
     121                 :      10410 : }
     122                 :            : 
     123                 :            : //______________________________________________________________________________
     124                 :       2660 : void PackageRegistryBackend::disposing()
     125                 :            : {
     126                 :            :     try {
     127 [ +  - ][ +  - ]:       9068 :         for ( t_string2ref::const_iterator i = m_bound.begin(); i != m_bound.end(); ++i)
                 [ +  + ]
     128 [ +  - ][ +  - ]:       6408 :             i->second->removeEventListener(this);
         [ +  - ][ +  - ]
     129         [ +  - ]:       2660 :         m_bound.clear();
     130                 :       2660 :         m_xComponentContext.clear();
     131         [ +  - ]:       2660 :         WeakComponentImplHelperBase::disposing();
     132                 :            :     }
     133                 :          0 :     catch (const RuntimeException &) {
     134                 :          0 :         throw;
     135                 :            :     }
     136      [ #  #  # ]:          0 :     catch (const Exception &) {
     137         [ #  # ]:          0 :         Any exc( ::cppu::getCaughtException() );
     138                 :            :         throw lang::WrappedTargetRuntimeException(
     139                 :            :             OUSTR("caught unexpected exception while disposing!"),
     140   [ #  #  #  #  :          0 :             static_cast<OWeakObject *>(this), exc );
                   #  # ]
     141                 :            :     }
     142                 :       2660 : }
     143                 :            : 
     144                 :            : // XPackageRegistry
     145                 :            : //______________________________________________________________________________
     146                 :      10410 : Reference<deployment::XPackage> PackageRegistryBackend::bindPackage(
     147                 :            :     OUString const & url, OUString const & mediaType, sal_Bool  bRemoved,
     148                 :            :     OUString const & identifier, Reference<XCommandEnvironment> const & xCmdEnv )
     149                 :            :     throw (deployment::DeploymentException,
     150                 :            :            deployment::InvalidRemovedParameterException,
     151                 :            :            ucb::CommandFailedException,
     152                 :            :            lang::IllegalArgumentException, RuntimeException)
     153                 :            : {
     154         [ +  - ]:      10410 :     ::osl::ResettableMutexGuard guard( getMutex() );
     155         [ +  - ]:      10410 :     check();
     156                 :            : 
     157         [ +  - ]:      10410 :     t_string2ref::const_iterator const iFind( m_bound.find( url ) );
     158 [ +  + ][ +  - ]:      10410 :     if (iFind != m_bound.end())
     159                 :            :     {
     160         [ +  - ]:       1866 :         Reference<deployment::XPackage> xPackage( iFind->second );
     161         [ +  - ]:       1866 :         if (xPackage.is())
     162                 :            :         {
     163   [ +  -  -  + ]:       5598 :             if (!mediaType.isEmpty() &&
                 [ -  + ]
     164 [ +  - ][ +  - ]:       3732 :                 mediaType != xPackage->getPackageType()->getMediaType())
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
           [ #  #  #  # ]
     165                 :            :                 throw lang::IllegalArgumentException
     166                 :            :                     (OUSTR("XPackageRegistry::bindPackage: media type does not match"),
     167 [ #  # ][ #  # ]:          0 :                      static_cast<OWeakObject*>(this), 1);
                 [ #  # ]
     168 [ +  - ][ +  - ]:       1866 :             if (xPackage->isRemoved() != bRemoved)
                 [ -  + ]
     169                 :            :                 throw deployment::InvalidRemovedParameterException(
     170                 :            :                     OUSTR("XPackageRegistry::bindPackage: bRemoved parameter does not match"),
     171 [ #  # ][ #  # ]:          0 :                     static_cast<OWeakObject*>(this), xPackage->isRemoved(), xPackage);
         [ #  # ][ #  # ]
                 [ #  # ]
     172                 :       1866 :             return xPackage;
     173         [ -  + ]:       1866 :         }
     174                 :            :     }
     175                 :            : 
     176         [ +  - ]:       8544 :     guard.clear();
     177                 :            : 
     178                 :       8544 :     Reference<deployment::XPackage> xNewPackage;
     179                 :            :     try {
     180                 :            :         xNewPackage = bindPackage_( url, mediaType, bRemoved,
     181 [ +  - ][ +  + ]:       8544 :             identifier, xCmdEnv );
     182                 :            :     }
     183                 :          0 :     catch (const RuntimeException &) {
     184                 :          0 :         throw;
     185                 :            :     }
     186                 :       4156 :     catch (const lang::IllegalArgumentException &) {
     187                 :       2078 :         throw;
     188                 :            :     }
     189                 :          0 :     catch (const CommandFailedException &) {
     190                 :          0 :         throw;
     191                 :            :     }
     192                 :          0 :     catch (const deployment::DeploymentException &) {
     193                 :          0 :         throw;
     194                 :            :     }
     195   [ -  -  +  -  :       2078 :     catch (const Exception &) {
                   -  - ]
     196         [ #  # ]:          0 :         Any exc( ::cppu::getCaughtException() );
     197                 :            :         throw deployment::DeploymentException(
     198                 :            :             OUSTR("Error binding package: ") + url,
     199   [ #  #  #  #  :          0 :             static_cast<OWeakObject *>(this), exc );
                   #  # ]
     200                 :            :     }
     201                 :            : 
     202         [ +  - ]:       6466 :     guard.reset();
     203                 :            : 
     204                 :            :     ::std::pair< t_string2ref::iterator, bool > insertion(
     205 [ +  - ][ +  - ]:       6466 :         m_bound.insert( t_string2ref::value_type( url, xNewPackage ) ) );
                 [ +  - ]
     206         [ -  + ]:       6466 :     if (insertion.second)
     207                 :            :     { // first insertion
     208                 :            :         SAL_WARN_IF(
     209                 :            :             Reference<XInterface>(insertion.first->second) != xNewPackage,
     210                 :            :             "desktop.deployment", "mismatch");
     211                 :            :     }
     212                 :            :     else
     213                 :            :     { // found existing entry
     214         [ #  # ]:          0 :         Reference<deployment::XPackage> xPackage( insertion.first->second );
     215         [ #  # ]:          0 :         if (xPackage.is())
     216                 :          0 :             return xPackage;
     217 [ #  # ][ #  # ]:          0 :         insertion.first->second = xNewPackage;
                 [ #  # ]
     218                 :            :     }
     219                 :            : 
     220         [ +  - ]:       6466 :     guard.clear();
     221 [ +  - ][ +  - ]:       6466 :     xNewPackage->addEventListener( this ); // listen for disposing events
                 [ +  - ]
     222         [ +  - ]:      10410 :     return xNewPackage;
     223                 :            : }
     224                 :            : 
     225                 :       1612 : OUString PackageRegistryBackend::createFolder(
     226                 :            :     OUString const & relUrl,
     227                 :            :     Reference<ucb::XCommandEnvironment> const & xCmdEnv)
     228                 :            : {
     229         [ +  - ]:       1612 :     const OUString sDataFolder = makeURL(getCachePath(), relUrl);
     230                 :            :     //make sure the folder exist
     231         [ +  - ]:       1612 :     ucbhelper::Content dataContent;
     232         [ +  - ]:       1612 :     ::dp_misc::create_folder(&dataContent, sDataFolder, xCmdEnv);
     233                 :            : 
     234         [ +  - ]:       1612 :     const String baseDir(sDataFolder);
     235         [ +  - ]:       1612 :     const ::utl::TempFile aTemp(&baseDir, sal_True);
     236 [ +  - ][ +  - ]:       1612 :     const OUString url = aTemp.GetURL();
                 [ +  - ]
     237 [ +  - ][ +  - ]:       1612 :     return sDataFolder + url.copy(url.lastIndexOf('/'));
                 [ +  - ]
     238                 :            : }
     239                 :            : 
     240                 :            : //folderURL can have the extension .tmp or .tmp_
     241                 :            : //Before OOo 3.4 the created a tmp file with osl_createTempFile and
     242                 :            : //then created a Folder with a same name and a trailing '_'
     243                 :            : //If the folderURL has no '_' then there is no corresponding tmp file.
     244                 :       1116 : void PackageRegistryBackend::deleteTempFolder(
     245                 :            :     OUString const & folderUrl)
     246                 :            : {
     247         [ +  - ]:       1116 :     if (!folderUrl.isEmpty())
     248                 :            :     {
     249                 :            :         erase_path( folderUrl, Reference<XCommandEnvironment>(),
     250         [ +  - ]:       1116 :                     false /* no throw: ignore errors */ );
     251                 :            : 
     252         [ -  + ]:       1116 :         if (folderUrl[folderUrl.getLength() - 1] == '_')
     253                 :            :         {
     254                 :          0 :             const OUString  tempFile = folderUrl.copy(0, folderUrl.getLength() - 1);
     255                 :            :             erase_path( tempFile, Reference<XCommandEnvironment>(),
     256         [ #  # ]:          0 :                         false /* no throw: ignore errors */ );
     257                 :            :         }
     258                 :            :     }
     259                 :       1116 : }
     260                 :            : 
     261                 :            : //usedFolders can contain folder names which have the extension .tmp or .tmp_
     262                 :            : //Before OOo 3.4 we created a tmp file with osl_createTempFile and
     263                 :            : //then created a Folder with a same name and a trailing '_'
     264                 :            : //If the folderURL has no '_' then there is no corresponding tmp file.
     265                 :        760 : void PackageRegistryBackend::deleteUnusedFolders(
     266                 :            :     OUString const & relUrl,
     267                 :            :     ::std::list< OUString> const & usedFolders)
     268                 :            : {
     269                 :            :     try
     270                 :            :     {
     271         [ +  - ]:        760 :         const OUString sDataFolder = makeURL(getCachePath(), relUrl);
     272                 :            :         ::ucbhelper::Content tempFolder(
     273         [ +  - ]:        760 :             sDataFolder, Reference<ucb::XCommandEnvironment>());
     274                 :            : 
     275                 :            :         Reference<sdbc::XResultSet> xResultSet(
     276         [ +  - ]:        760 :                  StrTitle::createCursor( tempFolder, ::ucbhelper::INCLUDE_FOLDERS_ONLY ) );
     277                 :            : 
     278                 :            :         // get all temp directories:
     279         [ +  - ]:        760 :         ::std::vector<OUString> tempEntries;
     280                 :            : 
     281                 :        760 :         const char tmp[] = ".tmp";
     282                 :            : 
     283 [ +  - ][ +  - ]:       1256 :         while (xResultSet->next())
                 [ +  + ]
     284                 :            :         {
     285                 :            :             OUString title(
     286                 :            :                 Reference<sdbc::XRow>(
     287 [ +  - ][ +  - ]:        992 :                     xResultSet, UNO_QUERY_THROW )->getString(
     288         [ +  - ]:        496 :                         1 /* Title */ ) );
     289                 :            : 
     290         [ +  - ]:        496 :             if (title.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM(tmp)))
     291                 :            :                 tempEntries.push_back(
     292 [ +  - ][ +  - ]:        496 :                     makeURLAppendSysPathSegment(sDataFolder, title));
     293                 :        496 :         }
     294                 :            : 
     295         [ +  + ]:       1256 :         for ( ::std::size_t pos = 0; pos < tempEntries.size(); ++pos )
     296                 :            :         {
     297         [ -  + ]:        992 :             if (::std::find( usedFolders.begin(), usedFolders.end(), tempEntries[pos] ) ==
     298         [ +  - ]:        992 :                 usedFolders.end())
     299                 :            :             {
     300         [ #  # ]:          0 :                 deleteTempFolder(tempEntries[pos]);
     301                 :            :             }
     302         [ +  - ]:        760 :         }
     303                 :            :     }
     304         [ #  # ]:          0 :     catch (const ucb::InteractiveAugmentedIOException& e)
     305                 :            :     {
     306                 :            :         //In case the folder containing all the data folder does not
     307                 :            :         //exist yet, we ignore the exception
     308         [ #  # ]:          0 :         if (e.Code != ucb::IOErrorCode_NOT_EXISTING)
     309                 :          0 :             throw;
     310                 :            :     }
     311                 :            : 
     312                 :        760 : }
     313                 :            : 
     314                 :            : 
     315                 :            : //______________________________________________________________________________
     316         [ +  - ]:       6466 : Package::~Package()
     317                 :            : {
     318         [ -  + ]:       6466 : }
     319                 :            : 
     320                 :            : //______________________________________________________________________________
     321                 :       6466 : Package::Package( ::rtl::Reference<PackageRegistryBackend> const & myBackend,
     322                 :            :                   OUString const & url,
     323                 :            :                   OUString const & rName,
     324                 :            :                   OUString const & displayName,
     325                 :            :                   Reference<deployment::XPackageTypeInfo> const & xPackageType,
     326                 :            :                   bool bRemoved,
     327                 :            :                   OUString const & identifier)
     328                 :       6466 :     : t_PackageBase( getMutex() ),
     329                 :            :       m_myBackend( myBackend ),
     330                 :            :       m_url( url ),
     331                 :            :       m_name( rName ),
     332                 :            :       m_displayName( displayName ),
     333                 :            :       m_xPackageType( xPackageType ),
     334                 :            :       m_bRemoved(bRemoved),
     335                 :      12932 :       m_identifier(identifier)
     336                 :            : {
     337         [ -  + ]:       6466 :     if (m_bRemoved)
     338                 :            :     {
     339                 :            :         //We use the last segment of the URL
     340                 :            :         SAL_WARN_IF(
     341                 :            :             !m_name.isEmpty(), "desktop.deployment", "non-empty m_name");
     342                 :          0 :         OUString name = m_url;
     343                 :          0 :         rtl::Bootstrap::expandMacros(name);
     344                 :          0 :         sal_Int32 index = name.lastIndexOf('/');
     345 [ #  # ][ #  # ]:          0 :         if (index != -1 && index < name.getLength())
                 [ #  # ]
     346                 :          0 :             m_name = name.copy(index + 1);
     347                 :            :     }
     348                 :       6466 : }
     349                 :            : 
     350                 :            : //______________________________________________________________________________
     351                 :       6466 : void Package::disposing()
     352                 :            : {
     353                 :       6466 :     m_myBackend.clear();
     354                 :       6466 :     WeakComponentImplHelperBase::disposing();
     355                 :       6466 : }
     356                 :            : 
     357                 :            : //______________________________________________________________________________
     358                 :      35452 : void Package::check() const
     359                 :            : {
     360         [ +  - ]:      35452 :     ::osl::MutexGuard guard( getMutex() );
     361 [ +  - ][ -  + ]:      35452 :     if (rBHelper.bInDispose || rBHelper.bDisposed) {
     362                 :            :         throw lang::DisposedException(
     363                 :            :             OUSTR("Package instance has already been disposed!"),
     364 [ #  # ][ #  # ]:          0 :             static_cast<OWeakObject *>(const_cast<Package *>(this)));
                 [ #  # ]
     365         [ +  - ]:      35452 :     }
     366                 :      35452 : }
     367                 :            : 
     368                 :            : // XComponent
     369                 :            : //______________________________________________________________________________
     370                 :       6466 : void Package::dispose() throw (RuntimeException)
     371                 :            : {
     372                 :       6466 :     check();
     373                 :       6466 :     WeakComponentImplHelperBase::dispose();
     374                 :       6466 : }
     375                 :            : 
     376                 :            : //______________________________________________________________________________
     377                 :       6466 : void Package::addEventListener(
     378                 :            :     Reference<lang::XEventListener> const & xListener ) throw (RuntimeException)
     379                 :            : {
     380                 :       6466 :     check();
     381                 :       6466 :     WeakComponentImplHelperBase::addEventListener( xListener );
     382                 :       6466 : }
     383                 :            : 
     384                 :            : //______________________________________________________________________________
     385                 :       6408 : void Package::removeEventListener(
     386                 :            :     Reference<lang::XEventListener> const & xListener ) throw (RuntimeException)
     387                 :            : {
     388                 :       6408 :     check();
     389                 :       6408 :     WeakComponentImplHelperBase::removeEventListener( xListener );
     390                 :       6408 : }
     391                 :            : 
     392                 :            : // XModifyBroadcaster
     393                 :            : //______________________________________________________________________________
     394                 :          0 : void Package::addModifyListener(
     395                 :            :     Reference<util::XModifyListener> const & xListener )
     396                 :            :     throw (RuntimeException)
     397                 :            : {
     398                 :          0 :     check();
     399                 :          0 :     rBHelper.addListener( ::getCppuType( &xListener ), xListener );
     400                 :          0 : }
     401                 :            : 
     402                 :            : //______________________________________________________________________________
     403                 :          0 : void Package::removeModifyListener(
     404                 :            :     Reference<util::XModifyListener> const & xListener )
     405                 :            :     throw (RuntimeException)
     406                 :            : {
     407                 :          0 :     check();
     408                 :          0 :     rBHelper.removeListener( ::getCppuType( &xListener ), xListener );
     409                 :          0 : }
     410                 :            : 
     411                 :            : //______________________________________________________________________________
     412                 :       7570 : void Package::checkAborted(
     413                 :            :     ::rtl::Reference<AbortChannel> const & abortChannel )
     414                 :            : {
     415 [ +  + ][ -  + ]:       7570 :     if (abortChannel.is() && abortChannel->isAborted()) {
                 [ -  + ]
     416                 :            :         throw CommandAbortedException(
     417 [ #  # ][ #  # ]:          0 :             OUSTR("abort!"), static_cast<OWeakObject *>(this) );
                 [ #  # ]
     418                 :            :     }
     419                 :       7570 : }
     420                 :            : 
     421                 :            : // XPackage
     422                 :            : //______________________________________________________________________________
     423                 :      13128 : Reference<task::XAbortChannel> Package::createAbortChannel()
     424                 :            :     throw (RuntimeException)
     425                 :            : {
     426                 :      13128 :     check();
     427 [ +  - ][ +  - ]:      13128 :     return new AbortChannel;
     428                 :            : }
     429                 :            : 
     430                 :            : //______________________________________________________________________________
     431                 :          0 : sal_Bool Package::isBundle() throw (RuntimeException)
     432                 :            : {
     433                 :          0 :     return false; // default
     434                 :            : }
     435                 :            : 
     436                 :            : //______________________________________________________________________________
     437                 :          0 : ::sal_Int32 Package::checkPrerequisites(
     438                 :            :         const css::uno::Reference< css::task::XAbortChannel >&,
     439                 :            :         const css::uno::Reference< css::ucb::XCommandEnvironment >&,
     440                 :            :         sal_Bool)
     441                 :            :         throw (css::deployment::DeploymentException,
     442                 :            :                css::deployment::ExtensionRemovedException,
     443                 :            :                css::ucb::CommandFailedException,
     444                 :            :                css::ucb::CommandAbortedException,
     445                 :            :                css::uno::RuntimeException)
     446                 :            : {
     447         [ #  # ]:          0 :     if (m_bRemoved)
     448         [ #  # ]:          0 :         throw deployment::ExtensionRemovedException();
     449                 :          0 :     return 0;
     450                 :            : }
     451                 :            : 
     452                 :            : //______________________________________________________________________________
     453                 :          0 : ::sal_Bool Package::checkDependencies(
     454                 :            :         const css::uno::Reference< css::ucb::XCommandEnvironment >& )
     455                 :            :         throw (css::deployment::DeploymentException,
     456                 :            :                css::deployment::ExtensionRemovedException,
     457                 :            :                css::ucb::CommandFailedException,
     458                 :            :                css::uno::RuntimeException)
     459                 :            : {
     460         [ #  # ]:          0 :     if (m_bRemoved)
     461         [ #  # ]:          0 :         throw deployment::ExtensionRemovedException();
     462                 :          0 :     return true;
     463                 :            : }
     464                 :            : 
     465                 :            : 
     466                 :            : //______________________________________________________________________________
     467                 :          0 : Sequence< Reference<deployment::XPackage> > Package::getBundle(
     468                 :            :     Reference<task::XAbortChannel> const &,
     469                 :            :     Reference<XCommandEnvironment> const & )
     470                 :            :     throw (deployment::DeploymentException,
     471                 :            :            CommandFailedException, CommandAbortedException,
     472                 :            :            lang::IllegalArgumentException, RuntimeException)
     473                 :            : {
     474                 :          0 :     return Sequence< Reference<deployment::XPackage> >();
     475                 :            : }
     476                 :            : 
     477                 :            : //______________________________________________________________________________
     478                 :         76 : OUString Package::getName() throw (RuntimeException)
     479                 :            : {
     480                 :         76 :     return m_name;
     481                 :            : }
     482                 :            : 
     483                 :          0 : beans::Optional<OUString> Package::getIdentifier() throw (RuntimeException)
     484                 :            : {
     485         [ #  # ]:          0 :     if (m_bRemoved)
     486                 :          0 :         return beans::Optional<OUString>(true, m_identifier);
     487                 :            : 
     488                 :          0 :     return beans::Optional<OUString>();
     489                 :            : }
     490                 :            : 
     491                 :            : //______________________________________________________________________________
     492                 :          0 : OUString Package::getVersion() throw (
     493                 :            :     deployment::ExtensionRemovedException,
     494                 :            :     RuntimeException)
     495                 :            : {
     496         [ #  # ]:          0 :     if (m_bRemoved)
     497         [ #  # ]:          0 :         throw deployment::ExtensionRemovedException();
     498                 :          0 :     return OUString();
     499                 :            : }
     500                 :            : 
     501                 :            : //______________________________________________________________________________
     502                 :      55468 : OUString Package::getURL() throw (RuntimeException)
     503                 :            : {
     504                 :      55468 :     return m_url;
     505                 :            : }
     506                 :            : 
     507                 :            : //______________________________________________________________________________
     508                 :       2484 : OUString Package::getDisplayName() throw (
     509                 :            :     deployment::ExtensionRemovedException, RuntimeException)
     510                 :            : {
     511         [ -  + ]:       2484 :     if (m_bRemoved)
     512         [ #  # ]:          0 :         throw deployment::ExtensionRemovedException();
     513                 :       2484 :     return m_displayName;
     514                 :            : }
     515                 :            : 
     516                 :            : //______________________________________________________________________________
     517                 :          0 : OUString Package::getDescription() throw (
     518                 :            :     deployment::ExtensionRemovedException,RuntimeException)
     519                 :            : {
     520         [ #  # ]:          0 :     if (m_bRemoved)
     521         [ #  # ]:          0 :         throw deployment::ExtensionRemovedException();
     522                 :          0 :     return OUString();
     523                 :            : }
     524                 :            : 
     525                 :            : //______________________________________________________________________________
     526                 :          0 : OUString Package::getLicenseText() throw (
     527                 :            :     deployment::ExtensionRemovedException,RuntimeException)
     528                 :            : {
     529         [ #  # ]:          0 :     if (m_bRemoved)
     530         [ #  # ]:          0 :         throw deployment::ExtensionRemovedException();
     531                 :          0 :     return OUString();
     532                 :            : }
     533                 :            : 
     534                 :            : //______________________________________________________________________________
     535                 :          0 : Sequence<OUString> Package::getUpdateInformationURLs() throw (
     536                 :            :     deployment::ExtensionRemovedException, RuntimeException)
     537                 :            : {
     538         [ #  # ]:          0 :     if (m_bRemoved)
     539         [ #  # ]:          0 :         throw deployment::ExtensionRemovedException();
     540                 :          0 :     return Sequence<OUString>();
     541                 :            : }
     542                 :            : 
     543                 :            : //______________________________________________________________________________
     544                 :          0 : css::beans::StringPair Package::getPublisherInfo() throw (
     545                 :            :     deployment::ExtensionRemovedException, RuntimeException)
     546                 :            : {
     547         [ #  # ]:          0 :     if (m_bRemoved)
     548         [ #  # ]:          0 :         throw deployment::ExtensionRemovedException();
     549                 :          0 :     css::beans::StringPair aEmptyPair;
     550                 :          0 :     return aEmptyPair;
     551                 :            : }
     552                 :            : 
     553                 :            : //______________________________________________________________________________
     554                 :          0 : uno::Reference< css::graphic::XGraphic > Package::getIcon( sal_Bool /*bHighContrast*/ )
     555                 :            :     throw (deployment::ExtensionRemovedException, RuntimeException )
     556                 :            : {
     557         [ #  # ]:          0 :     if (m_bRemoved)
     558         [ #  # ]:          0 :         throw deployment::ExtensionRemovedException();
     559                 :            : 
     560                 :          0 :     uno::Reference< css::graphic::XGraphic > aEmpty;
     561                 :          0 :     return aEmpty;
     562                 :            : }
     563                 :            : 
     564                 :            : //______________________________________________________________________________
     565                 :      19916 : Reference<deployment::XPackageTypeInfo> Package::getPackageType()
     566                 :            :     throw (RuntimeException)
     567                 :            : {
     568                 :      19916 :     return m_xPackageType;
     569                 :            : }
     570                 :            : 
     571                 :            : //______________________________________________________________________________
     572                 :          0 : void Package::exportTo(
     573                 :            :     OUString const & destFolderURL, OUString const & newTitle,
     574                 :            :     sal_Int32 nameClashAction, Reference<XCommandEnvironment> const & xCmdEnv )
     575                 :            :     throw (deployment::ExtensionRemovedException,
     576                 :            :            CommandFailedException, CommandAbortedException, RuntimeException)
     577                 :            : {
     578         [ #  # ]:          0 :     if (m_bRemoved)
     579         [ #  # ]:          0 :         throw deployment::ExtensionRemovedException();
     580                 :            : 
     581         [ #  # ]:          0 :     ::ucbhelper::Content destFolder( destFolderURL, xCmdEnv );
     582 [ #  # ][ #  # ]:          0 :     ::ucbhelper::Content sourceContent( getURL(), xCmdEnv );
     583         [ #  # ]:          0 :     if (! destFolder.transferContent(
     584                 :            :             sourceContent, ::ucbhelper::InsertOperation_COPY,
     585         [ #  # ]:          0 :             newTitle, nameClashAction ))
     586 [ #  # ][ #  # ]:          0 :         throw RuntimeException( OUSTR("UCB transferContent() failed!"), 0 );
         [ #  # ][ #  # ]
                 [ #  # ]
     587                 :          0 : }
     588                 :            : 
     589                 :            : //______________________________________________________________________________
     590                 :       2984 : void Package::fireModified()
     591                 :            : {
     592                 :            :     ::cppu::OInterfaceContainerHelper * container = rBHelper.getContainer(
     593                 :            :         ::getCppuType( static_cast<Reference<
     594                 :       2984 :                        util::XModifyListener> const *>(0) ) );
     595         [ -  + ]:       2984 :     if (container != 0) {
     596                 :            :         Sequence< Reference<XInterface> > elements(
     597         [ #  # ]:          0 :             container->getElements() );
     598 [ #  # ][ #  # ]:          0 :         lang::EventObject evt( static_cast<OWeakObject *>(this) );
     599         [ #  # ]:          0 :         for ( sal_Int32 pos = 0; pos < elements.getLength(); ++pos )
     600                 :            :         {
     601                 :            :             Reference<util::XModifyListener> xListener(
     602 [ #  # ][ #  # ]:          0 :                 elements[ pos ], UNO_QUERY );
     603         [ #  # ]:          0 :             if (xListener.is())
     604 [ #  # ][ #  # ]:          0 :                 xListener->modified( evt );
     605 [ #  # ][ #  # ]:          0 :         }
     606                 :            :     }
     607                 :       2984 : }
     608                 :            : 
     609                 :            : // XPackage
     610                 :            : //______________________________________________________________________________
     611                 :      12258 : beans::Optional< beans::Ambiguous<sal_Bool> > Package::isRegistered(
     612                 :            :     Reference<task::XAbortChannel> const & xAbortChannel,
     613                 :            :     Reference<XCommandEnvironment> const & xCmdEnv )
     614                 :            :     throw (deployment::DeploymentException,
     615                 :            :            CommandFailedException, CommandAbortedException, RuntimeException)
     616                 :            : {
     617                 :            :     try {
     618         [ +  - ]:      12258 :         ::osl::ResettableMutexGuard guard( getMutex() );
     619                 :            :         return isRegistered_( guard,
     620                 :            :                               AbortChannel::get(xAbortChannel),
     621 [ +  - ][ +  - ]:      12258 :                               xCmdEnv );
                 [ +  - ]
     622                 :            :     }
     623                 :          0 :     catch (const RuntimeException &) {
     624                 :          0 :         throw;
     625                 :            :     }
     626                 :          0 :     catch (const CommandFailedException &) {
     627                 :          0 :         throw;
     628                 :            :     }
     629                 :          0 :     catch (const CommandAbortedException &) {
     630                 :          0 :         throw;
     631                 :            :     }
     632                 :          0 :     catch (const deployment::DeploymentException &) {
     633                 :          0 :         throw;
     634                 :            :     }
     635   [ #  #  #  #  :          0 :     catch (const Exception &) {
                   #  # ]
     636         [ #  # ]:          0 :         Any exc( ::cppu::getCaughtException() );
     637                 :            :         throw deployment::DeploymentException(
     638                 :            :             OUSTR("unexpected exception occurred!"),
     639   [ #  #  #  #  :          0 :             static_cast<OWeakObject *>(this), exc );
                   #  # ]
     640                 :            :     }
     641                 :            : }
     642                 :            : 
     643                 :            : //______________________________________________________________________________
     644                 :       2984 : void Package::processPackage_impl(
     645                 :            :     bool doRegisterPackage,
     646                 :            :     bool startup,
     647                 :            :     Reference<task::XAbortChannel> const & xAbortChannel,
     648                 :            :     Reference<XCommandEnvironment> const & xCmdEnv )
     649                 :            : {
     650                 :       2984 :     check();
     651                 :       2984 :     bool action = false;
     652                 :            : 
     653                 :            :     try {
     654                 :            :         try {
     655         [ +  - ]:       2984 :             ::osl::ResettableMutexGuard guard( getMutex() );
     656                 :            :             beans::Optional< beans::Ambiguous<sal_Bool> > option(
     657                 :            :                 isRegistered_( guard, AbortChannel::get(xAbortChannel),
     658 [ +  - ][ +  - ]:       2984 :                                xCmdEnv ) );
     659                 :            :             action = (option.IsPresent &&
     660                 :            :                       (option.Value.IsAmbiguous ||
     661                 :            :                        (doRegisterPackage ? !option.Value.Value
     662 [ +  - ][ +  + ]:       2984 :                                         : option.Value.Value)));
         [ +  - ][ +  - ]
                 [ +  - ]
     663         [ +  - ]:       2984 :             if (action) {
     664                 :            : 
     665 [ +  - ][ -  + ]:       2984 :                 OUString displayName = isRemoved() ? getName() : getDisplayName();
         [ #  # ][ +  - ]
     666                 :            :                 ProgressLevel progress(
     667                 :            :                     xCmdEnv,
     668                 :            :                     (doRegisterPackage
     669                 :            :                      ? PackageRegistryBackend::StrRegisteringPackage::get()
     670                 :            :                      : PackageRegistryBackend::StrRevokingPackage::get())
     671 [ +  + ][ +  - ]:       2984 :                     + displayName );
         [ +  - ][ +  - ]
     672                 :            :                 processPackage_( guard,
     673                 :            :                                  doRegisterPackage,
     674                 :            :                                  startup,
     675                 :            :                                  AbortChannel::get(xAbortChannel),
     676 [ +  - ][ +  - ]:       2984 :                                  xCmdEnv );
                 [ +  - ]
     677         [ +  - ]:       2984 :             }
     678                 :            :         }
     679                 :          0 :         catch (const RuntimeException &e) {
     680                 :            :             SAL_WARN(
     681                 :            :                 "desktop.deployment",
     682                 :            :                 "unexpected RuntimeException \"" << e.Message << '"');
     683                 :          0 :             throw;
     684                 :            :         }
     685                 :          0 :         catch (const CommandFailedException &) {
     686                 :          0 :             throw;
     687                 :            :         }
     688                 :          0 :         catch (const CommandAbortedException &) {
     689                 :          0 :             throw;
     690                 :            :         }
     691                 :          0 :         catch (const deployment::DeploymentException &) {
     692                 :          0 :             throw;
     693                 :            :         }
     694   [ #  #  #  #  :          0 :         catch (const Exception &) {
                   #  # ]
     695         [ #  # ]:          0 :             Any exc( ::cppu::getCaughtException() );
     696                 :            :             throw deployment::DeploymentException(
     697                 :            :                 (doRegisterPackage
     698                 :            :                  ? getResourceString(RID_STR_ERROR_WHILE_REGISTERING)
     699                 :            :                  : getResourceString(RID_STR_ERROR_WHILE_REVOKING))
     700   [ #  #  #  #  :          0 :                 + getDisplayName(), static_cast<OWeakObject *>(this), exc );
          #  #  #  #  #  
             #  #  #  #  
                      # ]
     701                 :            :         }
     702                 :            :     }
     703                 :          0 :     catch (...) {
     704         [ #  # ]:          0 :         if (action)
     705         [ #  # ]:          0 :             fireModified();
     706                 :          0 :         throw;
     707                 :            :     }
     708         [ +  - ]:       2984 :     if (action)
     709                 :       2984 :         fireModified();
     710                 :       2984 : }
     711                 :            : 
     712                 :            : //______________________________________________________________________________
     713                 :       2980 : void Package::registerPackage(
     714                 :            :     sal_Bool startup,
     715                 :            :     Reference<task::XAbortChannel> const & xAbortChannel,
     716                 :            :     Reference<XCommandEnvironment> const & xCmdEnv )
     717                 :            :     throw (deployment::DeploymentException,
     718                 :            :            deployment::ExtensionRemovedException,
     719                 :            :            CommandFailedException, CommandAbortedException,
     720                 :            :            lang::IllegalArgumentException, RuntimeException)
     721                 :            : {
     722         [ -  + ]:       2980 :     if (m_bRemoved)
     723         [ #  # ]:          0 :         throw deployment::ExtensionRemovedException();
     724                 :       2980 :     processPackage_impl( true /* register */, startup, xAbortChannel, xCmdEnv );
     725                 :       2980 : }
     726                 :            : 
     727                 :            : //______________________________________________________________________________
     728                 :          4 : void Package::revokePackage(
     729                 :            :     sal_Bool startup,
     730                 :            :     Reference<task::XAbortChannel> const & xAbortChannel,
     731                 :            :     Reference<XCommandEnvironment> const & xCmdEnv )
     732                 :            :     throw (deployment::DeploymentException,
     733                 :            :            CommandFailedException, CommandAbortedException,
     734                 :            :            lang::IllegalArgumentException, RuntimeException)
     735                 :            : {
     736                 :          4 :     processPackage_impl( false /* revoke */, startup, xAbortChannel, xCmdEnv );
     737                 :            : 
     738                 :          4 : }
     739                 :            : 
     740                 :          0 : PackageRegistryBackend * Package::getMyBackend() const
     741                 :            : {
     742                 :          0 :     PackageRegistryBackend * pBackend = m_myBackend.get();
     743         [ #  # ]:          0 :     if (NULL == pBackend)
     744                 :            :     {
     745                 :            :         //May throw a DisposedException
     746                 :          0 :         check();
     747                 :            :         //We should never get here...
     748                 :            :         throw RuntimeException(
     749                 :            :             OUSTR("Failed to get the BackendImpl"),
     750 [ #  # ][ #  # ]:          0 :             static_cast<OWeakObject*>(const_cast<Package *>(this)));
                 [ #  # ]
     751                 :            :     }
     752                 :          0 :     return pBackend;
     753                 :            : }
     754                 :          0 : OUString Package::getRepositoryName()
     755                 :            :     throw (RuntimeException)
     756                 :            : {
     757                 :          0 :     PackageRegistryBackend * backEnd = getMyBackend();
     758                 :          0 :     return backEnd->getContext();
     759                 :            : }
     760                 :            : 
     761                 :          0 : beans::Optional< OUString > Package::getRegistrationDataURL()
     762                 :            :         throw (deployment::ExtensionRemovedException,
     763                 :            :                css::uno::RuntimeException)
     764                 :            : {
     765         [ #  # ]:          0 :     if (m_bRemoved)
     766         [ #  # ]:          0 :         throw deployment::ExtensionRemovedException();
     767                 :          0 :     return beans::Optional<OUString>();
     768                 :            : }
     769                 :            : 
     770                 :       4856 : sal_Bool Package::isRemoved()
     771                 :            :     throw (RuntimeException)
     772                 :            : {
     773                 :       4856 :     return m_bRemoved;
     774                 :            : }
     775                 :            : 
     776                 :            : 
     777                 :            : //______________________________________________________________________________
     778                 :       5700 : Package::TypeInfo::~TypeInfo()
     779                 :            : {
     780         [ -  + ]:      11400 : }
     781                 :            : 
     782                 :            : // XPackageTypeInfo
     783                 :            : //______________________________________________________________________________
     784                 :      25616 : OUString Package::TypeInfo::getMediaType() throw (RuntimeException)
     785                 :            : {
     786                 :      25616 :     return m_mediaType;
     787                 :            : }
     788                 :            : 
     789                 :            : //______________________________________________________________________________
     790                 :          0 : OUString Package::TypeInfo::getDescription()
     791                 :            :     throw (deployment::ExtensionRemovedException, RuntimeException)
     792                 :            : {
     793                 :          0 :     return getShortDescription();
     794                 :            : }
     795                 :            : 
     796                 :            : //______________________________________________________________________________
     797                 :        380 : OUString Package::TypeInfo::getShortDescription()
     798                 :            :     throw (deployment::ExtensionRemovedException, RuntimeException)
     799                 :            : {
     800                 :        380 :     return m_shortDescr;
     801                 :            : }
     802                 :            : 
     803                 :            : //______________________________________________________________________________
     804                 :       5700 : OUString Package::TypeInfo::getFileFilter() throw (RuntimeException)
     805                 :            : {
     806                 :       5700 :     return m_fileFilter;
     807                 :            : }
     808                 :            : 
     809                 :            : //______________________________________________________________________________
     810                 :            : /**************************
     811                 :            :  * Get Icon
     812                 :            :  *
     813                 :            :  * @param highContrast NOTE: disabled the returning of high contrast icons.
     814                 :            :  *                     This bool is a noop now.
     815                 :            :  * @param smallIcon    Return the small version of the icon
     816                 :            :  */
     817                 :          0 : Any Package::TypeInfo::getIcon( sal_Bool /*highContrast*/, sal_Bool smallIcon )
     818                 :            :     throw (RuntimeException)
     819                 :            : {
     820         [ #  # ]:          0 :     if (! smallIcon)
     821                 :          0 :         return Any();
     822                 :          0 :     const sal_uInt16 nIconId = m_smallIcon;
     823         [ #  # ]:          0 :     return Any( &nIconId, getCppuType( static_cast<sal_uInt16 const *>(0) ) );
     824                 :            : }
     825                 :            : 
     826                 :            : }
     827                 :            : }
     828                 :            : 
     829                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10