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

Generated by: LCOV version 1.11