LCOV - code coverage report
Current view: top level - desktop/source/deployment/registry - dp_backend.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 154 330 46.7 %
Date: 2014-11-03 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        3430 : PackageRegistryBackend::~PackageRegistryBackend()
      55             : {
      56        3430 : }
      57             : 
      58             : 
      59           8 : void PackageRegistryBackend::disposing( lang::EventObject const & event )
      60             :     throw (RuntimeException, std::exception)
      61             : {
      62             :     Reference<deployment::XPackage> xPackage(
      63           8 :         event.Source, UNO_QUERY_THROW );
      64          16 :     OUString url( xPackage->getURL() );
      65          16 :     ::osl::MutexGuard guard( getMutex() );
      66           8 :     if ( m_bound.erase( url ) != 1 )
      67             :     {
      68             :         SAL_WARN("desktop.deployment", "erase(" << url << ") != 1");
      69           8 :     }
      70           8 : }
      71             : 
      72             : 
      73        3430 : PackageRegistryBackend::PackageRegistryBackend(
      74             :     Sequence<Any> const & args,
      75             :     Reference<XComponentContext> const & xContext )
      76        3430 :     : t_BackendBase( getMutex() ),
      77             :       m_xComponentContext( xContext ),
      78             :       m_eContext( CONTEXT_UNKNOWN ),
      79        6860 :       m_readOnly( false )
      80             : {
      81             :     assert(xContext.is());
      82        3430 :     boost::optional<OUString> cachePath;
      83        6860 :     boost::optional<bool> readOnly;
      84        3430 :     comphelper::unwrapArgs( args, m_context, cachePath, readOnly );
      85        3430 :     if (cachePath)
      86        3430 :         m_cachePath = *cachePath;
      87        3430 :     if (readOnly)
      88        3430 :         m_readOnly = *readOnly;
      89             : 
      90        3430 :     if ( m_context == "user" )
      91        1288 :         m_eContext = CONTEXT_USER;
      92        2142 :     else if ( m_context == "shared" )
      93         840 :         m_eContext = CONTEXT_SHARED;
      94        1302 :     else if ( m_context == "bundled" )
      95         840 :         m_eContext = CONTEXT_BUNDLED;
      96         462 :     else if ( m_context == "tmp" )
      97         462 :         m_eContext = CONTEXT_TMP;
      98           0 :     else if (m_context.matchIgnoreAsciiCase("vnd.sun.star.tdoc:/"))
      99           0 :         m_eContext = CONTEXT_DOCUMENT;
     100             :     else
     101        3430 :         m_eContext = CONTEXT_UNKNOWN;
     102        3430 : }
     103             : 
     104             : 
     105          58 : void PackageRegistryBackend::check()
     106             : {
     107          58 :     ::osl::MutexGuard guard( getMutex() );
     108          58 :     if (rBHelper.bInDispose || rBHelper.bDisposed) {
     109             :         throw lang::DisposedException(
     110             :             "PackageRegistryBackend instance has already been disposed!",
     111           0 :             static_cast<OWeakObject *>(this) );
     112          58 :     }
     113          58 : }
     114             : 
     115             : 
     116        3430 : void PackageRegistryBackend::disposing()
     117             : {
     118             :     try {
     119        3436 :         for ( t_string2ref::const_iterator i = m_bound.begin(); i != m_bound.end(); ++i)
     120           6 :             i->second->removeEventListener(this);
     121        3430 :         m_bound.clear();
     122        3430 :         m_xComponentContext.clear();
     123        3430 :         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        3430 : }
     135             : 
     136             : // XPackageRegistry
     137             : 
     138          58 : 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          58 :     ::osl::ResettableMutexGuard guard( getMutex() );
     147          58 :     check();
     148             : 
     149          58 :     t_string2ref::const_iterator const iFind( m_bound.find( url ) );
     150          58 :     if (iFind != m_bound.end())
     151             :     {
     152          14 :         Reference<deployment::XPackage> xPackage( iFind->second );
     153          14 :         if (xPackage.is())
     154             :         {
     155          56 :             if (!mediaType.isEmpty() &&
     156          56 :                 mediaType != xPackage->getPackageType()->getMediaType())
     157             :                 throw lang::IllegalArgumentException
     158             :                     ("XPackageRegistry::bindPackage: media type does not match",
     159           0 :                      static_cast<OWeakObject*>(this), 1);
     160          14 :             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          14 :             return xPackage;
     165           0 :         }
     166             :     }
     167             : 
     168          44 :     guard.clear();
     169             : 
     170          88 :     Reference<deployment::XPackage> xNewPackage;
     171             :     try {
     172          58 :         xNewPackage = bindPackage_( url, mediaType, bRemoved,
     173          58 :             identifier, xCmdEnv );
     174             :     }
     175          60 :     catch (const RuntimeException &) {
     176          30 :         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          14 :     guard.reset();
     192             : 
     193             :     ::std::pair< t_string2ref::iterator, bool > insertion(
     194          14 :         m_bound.insert( t_string2ref::value_type( url, xNewPackage ) ) );
     195          14 :     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          14 :     guard.clear();
     210          14 :     xNewPackage->addEventListener( this ); // listen for disposing events
     211          72 :     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 :     ::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         980 : void PackageRegistryBackend::deleteUnusedFolders(
     255             :     OUString const & relUrl,
     256             :     ::std::list< OUString> const & usedFolders)
     257             : {
     258             :     try
     259             :     {
     260         980 :         const OUString sDataFolder = makeURL(getCachePath(), relUrl);
     261             :         ::ucbhelper::Content tempFolder(
     262        1960 :             sDataFolder, Reference<ucb::XCommandEnvironment>(), m_xComponentContext);
     263             : 
     264             :         Reference<sdbc::XResultSet> xResultSet(
     265        1960 :                  StrTitle::createCursor( tempFolder, ::ucbhelper::INCLUDE_FOLDERS_ONLY ) );
     266             : 
     267             :         // get all temp directories:
     268        1960 :         ::std::vector<OUString> tempEntries;
     269             : 
     270         980 :         const char tmp[] = ".tmp";
     271             : 
     272        1960 :         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         980 :         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         980 :         }
     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         980 : }
     302             : 
     303             : 
     304             : 
     305          14 : Package::~Package()
     306             : {
     307          14 : }
     308             : 
     309             : 
     310          14 : 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          14 :     : 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          28 :       m_identifier(identifier)
     325             : {
     326          14 :     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          14 : }
     338             : 
     339             : 
     340          14 : void Package::disposing()
     341             : {
     342          14 :     m_myBackend.clear();
     343          14 :     WeakComponentImplHelperBase::disposing();
     344          14 : }
     345             : 
     346             : 
     347          20 : void Package::check() const
     348             : {
     349          20 :     ::osl::MutexGuard guard( getMutex() );
     350          20 :     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          20 :     }
     355          20 : }
     356             : 
     357             : // XComponent
     358             : 
     359          14 : 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          14 :     WeakComponentImplHelperBase::dispose();
     364          14 : }
     365             : 
     366             : 
     367          14 : 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          14 :     WeakComponentImplHelperBase::addEventListener( xListener );
     373          14 : }
     374             : 
     375             : 
     376           6 : 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           6 :     WeakComponentImplHelperBase::removeEventListener( xListener );
     382           6 : }
     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           6 : void Package::checkAborted(
     405             :     ::rtl::Reference<AbortChannel> const & abortChannel )
     406             : {
     407           6 :     if (abortChannel.is() && abortChannel->isAborted()) {
     408             :         throw CommandAbortedException(
     409           0 :             "abort!", static_cast<OWeakObject *>(this) );
     410             :     }
     411           6 : }
     412             : 
     413             : // XPackage
     414             : 
     415          12 : Reference<task::XAbortChannel> Package::createAbortChannel()
     416             :     throw (RuntimeException, std::exception)
     417             : {
     418          12 :     check();
     419          12 :     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          14 : OUString Package::getName() throw (RuntimeException, std::exception)
     471             : {
     472          14 :     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          32 : OUString Package::getURL() throw (RuntimeException, std::exception)
     495             : {
     496          32 :     return m_url;
     497             : }
     498             : 
     499             : 
     500           4 : OUString Package::getDisplayName() throw (
     501             :     deployment::ExtensionRemovedException, RuntimeException, std::exception)
     502             : {
     503           4 :     if (m_bRemoved)
     504           0 :         throw deployment::ExtensionRemovedException();
     505           4 :     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::DeploymentException,
     520             :     deployment::ExtensionRemovedException,
     521             :     RuntimeException, std::exception)
     522             : {
     523           0 :     if (m_bRemoved)
     524           0 :         throw deployment::ExtensionRemovedException();
     525           0 :     return OUString();
     526             : }
     527             : 
     528             : 
     529           0 : Sequence<OUString> Package::getUpdateInformationURLs() throw (
     530             :     deployment::ExtensionRemovedException, RuntimeException, std::exception)
     531             : {
     532           0 :     if (m_bRemoved)
     533           0 :         throw deployment::ExtensionRemovedException();
     534           0 :     return Sequence<OUString>();
     535             : }
     536             : 
     537             : 
     538           0 : css::beans::StringPair Package::getPublisherInfo() throw (
     539             :     deployment::ExtensionRemovedException, RuntimeException, std::exception)
     540             : {
     541           0 :     if (m_bRemoved)
     542           0 :         throw deployment::ExtensionRemovedException();
     543           0 :     css::beans::StringPair aEmptyPair;
     544           0 :     return aEmptyPair;
     545             : }
     546             : 
     547             : 
     548           0 : uno::Reference< css::graphic::XGraphic > Package::getIcon( sal_Bool /*bHighContrast*/ )
     549             :     throw (deployment::ExtensionRemovedException, RuntimeException, std::exception )
     550             : {
     551           0 :     if (m_bRemoved)
     552           0 :         throw deployment::ExtensionRemovedException();
     553             : 
     554           0 :     uno::Reference< css::graphic::XGraphic > aEmpty;
     555           0 :     return aEmpty;
     556             : }
     557             : 
     558             : 
     559          32 : Reference<deployment::XPackageTypeInfo> Package::getPackageType()
     560             :     throw (RuntimeException, std::exception)
     561             : {
     562          32 :     return m_xPackageType;
     563             : }
     564             : 
     565           0 : void Package::exportTo(
     566             :     OUString const & destFolderURL, OUString const & newTitle,
     567             :     sal_Int32 nameClashAction, Reference<XCommandEnvironment> const & xCmdEnv )
     568             :     throw (deployment::ExtensionRemovedException,
     569             :            CommandFailedException, CommandAbortedException, ContentCreationException,
     570             :            RuntimeException, std::exception)
     571             : {
     572           0 :     if (m_bRemoved)
     573           0 :         throw deployment::ExtensionRemovedException();
     574             : 
     575           0 :     ::ucbhelper::Content destFolder( destFolderURL, xCmdEnv, getMyBackend()->getComponentContext() );
     576           0 :     ::ucbhelper::Content sourceContent( getURL(), xCmdEnv, getMyBackend()->getComponentContext() );
     577           0 :     bool bOk=true;
     578             :     try
     579             :     {
     580             :         bOk = destFolder.transferContent(
     581             :             sourceContent, ::ucbhelper::InsertOperation_COPY,
     582           0 :             newTitle, nameClashAction);
     583             :     }
     584           0 :     catch (const css::ucb::ContentCreationException&)
     585             :     {
     586           0 :         bOk = false;
     587             :     }
     588             : 
     589           0 :     if (!bOk)
     590           0 :         throw RuntimeException( "UCB transferContent() failed!", 0 );
     591           0 : }
     592             : 
     593           8 : void Package::fireModified()
     594             : {
     595             :     ::cppu::OInterfaceContainerHelper * container = rBHelper.getContainer(
     596           8 :         cppu::UnoType<util::XModifyListener>::get() );
     597           8 :     if (container != 0) {
     598             :         Sequence< Reference<XInterface> > elements(
     599           0 :             container->getElements() );
     600           0 :         lang::EventObject evt( static_cast<OWeakObject *>(this) );
     601           0 :         for ( sal_Int32 pos = 0; pos < elements.getLength(); ++pos )
     602             :         {
     603             :             Reference<util::XModifyListener> xListener(
     604           0 :                 elements[ pos ], UNO_QUERY );
     605           0 :             if (xListener.is())
     606           0 :                 xListener->modified( evt );
     607           0 :         }
     608             :     }
     609           8 : }
     610             : 
     611             : // XPackage
     612             : 
     613          12 : beans::Optional< beans::Ambiguous<sal_Bool> > Package::isRegistered(
     614             :     Reference<task::XAbortChannel> const & xAbortChannel,
     615             :     Reference<XCommandEnvironment> const & xCmdEnv )
     616             :     throw (deployment::DeploymentException,
     617             :            CommandFailedException, CommandAbortedException, RuntimeException, std::exception)
     618             : {
     619             :     try {
     620          12 :         ::osl::ResettableMutexGuard guard( getMutex() );
     621             :         return isRegistered_( guard,
     622             :                               AbortChannel::get(xAbortChannel),
     623          12 :                               xCmdEnv );
     624             :     }
     625           0 :     catch (const RuntimeException &) {
     626           0 :         throw;
     627             :     }
     628           0 :     catch (const CommandFailedException &) {
     629           0 :         throw;
     630             :     }
     631           0 :     catch (const CommandAbortedException &) {
     632           0 :         throw;
     633             :     }
     634           0 :     catch (const deployment::DeploymentException &) {
     635           0 :         throw;
     636             :     }
     637           0 :     catch (const Exception &) {
     638           0 :         Any exc( ::cppu::getCaughtException() );
     639             :         throw deployment::DeploymentException(
     640             :             "unexpected exception occurred!",
     641           0 :             static_cast<OWeakObject *>(this), exc );
     642             :     }
     643             : }
     644             : 
     645             : 
     646           8 : void Package::processPackage_impl(
     647             :     bool doRegisterPackage,
     648             :     bool startup,
     649             :     Reference<task::XAbortChannel> const & xAbortChannel,
     650             :     Reference<XCommandEnvironment> const & xCmdEnv )
     651             : {
     652           8 :     check();
     653           8 :     bool action = false;
     654             : 
     655             :     try {
     656             :         try {
     657           8 :             ::osl::ResettableMutexGuard guard( getMutex() );
     658             :             beans::Optional< beans::Ambiguous<sal_Bool> > option(
     659             :                 isRegistered_( guard, AbortChannel::get(xAbortChannel),
     660           8 :                                xCmdEnv ) );
     661          16 :             action = (option.IsPresent &&
     662           4 :                       (option.Value.IsAmbiguous ||
     663             :                        (doRegisterPackage ? !option.Value.Value
     664          16 :                                         : option.Value.Value)));
     665           8 :             if (action) {
     666             : 
     667           8 :                 OUString displayName = isRemoved() ? getName() : getDisplayName();
     668             :                 ProgressLevel progress(
     669             :                     xCmdEnv,
     670             :                     (doRegisterPackage
     671             :                      ? PackageRegistryBackend::StrRegisteringPackage::get()
     672             :                      : PackageRegistryBackend::StrRevokingPackage::get())
     673          16 :                     + displayName );
     674             :                 processPackage_( guard,
     675             :                                  doRegisterPackage,
     676             :                                  startup,
     677             :                                  AbortChannel::get(xAbortChannel),
     678          16 :                                  xCmdEnv );
     679           8 :             }
     680             :         }
     681           0 :         catch (lang::IllegalArgumentException &) {
     682           0 :             Any e(cppu::getCaughtException());
     683             :             throw deployment::DeploymentException(
     684             :                 ((doRegisterPackage
     685             :                   ? getResourceString(RID_STR_ERROR_WHILE_REGISTERING)
     686             :                   : getResourceString(RID_STR_ERROR_WHILE_REVOKING))
     687           0 :                  + getDisplayName()),
     688           0 :                 static_cast< OWeakObject * >(this), e);
     689             :         }
     690           0 :         catch (const RuntimeException &e) {
     691             :             SAL_WARN(
     692             :                 "desktop.deployment",
     693             :                 "unexpected RuntimeException \"" << e.Message << '"');
     694           0 :             throw;
     695             :         }
     696           0 :         catch (const CommandFailedException &) {
     697           0 :             throw;
     698             :         }
     699           0 :         catch (const CommandAbortedException &) {
     700           0 :             throw;
     701             :         }
     702           0 :         catch (const deployment::DeploymentException &) {
     703           0 :             throw;
     704             :         }
     705           0 :         catch (const Exception &) {
     706           0 :             Any exc( ::cppu::getCaughtException() );
     707             :             throw deployment::DeploymentException(
     708             :                 (doRegisterPackage
     709             :                  ? getResourceString(RID_STR_ERROR_WHILE_REGISTERING)
     710             :                  : getResourceString(RID_STR_ERROR_WHILE_REVOKING))
     711           0 :                 + getDisplayName(), static_cast<OWeakObject *>(this), exc );
     712             :         }
     713             :     }
     714           0 :     catch (...) {
     715           0 :         if (action)
     716           0 :             fireModified();
     717           0 :         throw;
     718             :     }
     719           8 :     if (action)
     720           8 :         fireModified();
     721           8 : }
     722             : 
     723             : 
     724           4 : void Package::registerPackage(
     725             :     sal_Bool startup,
     726             :     Reference<task::XAbortChannel> const & xAbortChannel,
     727             :     Reference<XCommandEnvironment> const & xCmdEnv )
     728             :     throw (deployment::DeploymentException,
     729             :            deployment::ExtensionRemovedException,
     730             :            CommandFailedException, CommandAbortedException,
     731             :            lang::IllegalArgumentException, RuntimeException, std::exception)
     732             : {
     733           4 :     if (m_bRemoved)
     734           0 :         throw deployment::ExtensionRemovedException();
     735           4 :     processPackage_impl( true /* register */, startup, xAbortChannel, xCmdEnv );
     736           4 : }
     737             : 
     738             : 
     739           4 : void Package::revokePackage(
     740             :     sal_Bool startup,
     741             :     Reference<task::XAbortChannel> const & xAbortChannel,
     742             :     Reference<XCommandEnvironment> const & xCmdEnv )
     743             :     throw (deployment::DeploymentException,
     744             :            CommandFailedException, CommandAbortedException,
     745             :            lang::IllegalArgumentException, RuntimeException, std::exception)
     746             : {
     747           4 :     processPackage_impl( false /* revoke */, startup, xAbortChannel, xCmdEnv );
     748             : 
     749           4 : }
     750             : 
     751           0 : PackageRegistryBackend * Package::getMyBackend() const
     752             : {
     753           0 :     PackageRegistryBackend * pBackend = m_myBackend.get();
     754           0 :     if (NULL == pBackend)
     755             :     {
     756             :         //May throw a DisposedException
     757           0 :         check();
     758             :         //We should never get here...
     759             :         throw RuntimeException(
     760             :             "Failed to get the BackendImpl",
     761           0 :             static_cast<OWeakObject*>(const_cast<Package *>(this)));
     762             :     }
     763           0 :     return pBackend;
     764             : }
     765             : 
     766           0 : OUString Package::getRepositoryName()
     767             :     throw (RuntimeException, std::exception)
     768             : {
     769           0 :     PackageRegistryBackend * backEnd = getMyBackend();
     770           0 :     return backEnd->getContext();
     771             : }
     772             : 
     773           0 : beans::Optional< OUString > Package::getRegistrationDataURL()
     774             :         throw (deployment::DeploymentException,
     775             :                deployment::ExtensionRemovedException,
     776             :                css::uno::RuntimeException, std::exception)
     777             : {
     778           0 :     if (m_bRemoved)
     779           0 :         throw deployment::ExtensionRemovedException();
     780           0 :     return beans::Optional<OUString>();
     781             : }
     782             : 
     783          28 : sal_Bool Package::isRemoved()
     784             :     throw (RuntimeException, std::exception)
     785             : {
     786          28 :     return m_bRemoved;
     787             : }
     788             : 
     789       14700 : Package::TypeInfo::~TypeInfo()
     790             : {
     791       14700 : }
     792             : 
     793             : // XPackageTypeInfo
     794             : 
     795        7382 : OUString Package::TypeInfo::getMediaType() throw (RuntimeException, std::exception)
     796             : {
     797        7382 :     return m_mediaType;
     798             : }
     799             : 
     800             : 
     801           0 : OUString Package::TypeInfo::getDescription()
     802             :     throw (deployment::ExtensionRemovedException, RuntimeException, std::exception)
     803             : {
     804           0 :     return getShortDescription();
     805             : }
     806             : 
     807             : 
     808         490 : OUString Package::TypeInfo::getShortDescription()
     809             :     throw (deployment::ExtensionRemovedException, RuntimeException, std::exception)
     810             : {
     811         490 :     return m_shortDescr;
     812             : }
     813             : 
     814             : 
     815        7350 : OUString Package::TypeInfo::getFileFilter() throw (RuntimeException, std::exception)
     816             : {
     817        7350 :     return m_fileFilter;
     818             : }
     819             : 
     820             : 
     821             : /**************************
     822             :  * Get Icon
     823             :  *
     824             :  * @param highContrast NOTE: disabled the returning of high contrast icons.
     825             :  *                     This bool is a noop now.
     826             :  * @param smallIcon    Return the small version of the icon
     827             :  */
     828           0 : Any Package::TypeInfo::getIcon( sal_Bool /*highContrast*/, sal_Bool smallIcon )
     829             :     throw (RuntimeException, std::exception)
     830             : {
     831           0 :     if (! smallIcon)
     832           0 :         return Any();
     833           0 :     const sal_uInt16 nIconId = m_smallIcon;
     834           0 :     return Any( &nIconId, cppu::UnoType<cppu::UnoUnsignedShortType>::get() );
     835             : }
     836             : 
     837             : }
     838             : }
     839             : 
     840             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10