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

Generated by: LCOV version 1.10