LCOV - code coverage report
Current view: top level - desktop/source/deployment/registry - dp_backend.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 154 327 47.1 %
Date: 2014-04-11 Functions: 31 54 57.4 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10