summaryrefslogtreecommitdiff
path: root/desktop/source/deployment/registry/dp_backend.cxx
blob: d1cd8df497c700d2b49973b20a090b92ebbd2029 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <sal/config.h>

#include <cassert>

#include "dp_backend.h"
#include "dp_ucb.h"
#include <rtl/ustring.hxx>
#include <rtl/uri.hxx>
#include <rtl/bootstrap.hxx>
#include <osl/file.hxx>
#include <cppuhelper/exc_hlp.hxx>
#include <comphelper/servicedecl.hxx>
#include <comphelper/unwrapargs.hxx>
#include <ucbhelper/content.hxx>
#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
#include <com/sun/star/deployment/InvalidRemovedParameterException.hpp>
#include <com/sun/star/deployment/thePackageManagerFactory.hpp>
#include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
#include <com/sun/star/ucb/IOErrorCode.hpp>
#include <com/sun/star/beans/StringPair.hpp>
#include <com/sun/star/sdbc/XResultSet.hpp>
#include <com/sun/star/sdbc/XRow.hpp>
#include <unotools/tempfile.hxx>


using namespace ::dp_misc;
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::ucb;

namespace dp_registry {
namespace backend {


PackageRegistryBackend::~PackageRegistryBackend()
{
}


void PackageRegistryBackend::disposing( lang::EventObject const & event )
    throw (RuntimeException, std::exception)
{
    Reference<deployment::XPackage> xPackage(
        event.Source, UNO_QUERY_THROW );
    OUString url( xPackage->getURL() );
    ::osl::MutexGuard guard( getMutex() );
    if ( m_bound.erase( url ) != 1 )
    {
        SAL_WARN("desktop.deployment", "erase(" << url << ") != 1");
    }
}


PackageRegistryBackend::PackageRegistryBackend(
    Sequence<Any> const & args,
    Reference<XComponentContext> const & xContext )
    : t_BackendBase( getMutex() ),
      m_xComponentContext( xContext ),
      m_eContext( CONTEXT_UNKNOWN ),
      m_readOnly( false )
{
    assert(xContext.is());
    boost::optional<OUString> cachePath;
    boost::optional<bool> readOnly;
    comphelper::unwrapArgs( args, m_context, cachePath, readOnly );
    if (cachePath)
        m_cachePath = *cachePath;
    if (readOnly)
        m_readOnly = *readOnly;

    if ( m_context == "user" )
        m_eContext = CONTEXT_USER;
    else if ( m_context == "shared" )
        m_eContext = CONTEXT_SHARED;
    else if ( m_context == "bundled" )
        m_eContext = CONTEXT_BUNDLED;
    else if ( m_context == "tmp" )
        m_eContext = CONTEXT_TMP;
    else if (m_context.matchIgnoreAsciiCase("vnd.sun.star.tdoc:/"))
        m_eContext = CONTEXT_DOCUMENT;
    else
        m_eContext = CONTEXT_UNKNOWN;
}


void PackageRegistryBackend::check()
{
    ::osl::MutexGuard guard( getMutex() );
    if (rBHelper.bInDispose || rBHelper.bDisposed) {
        throw lang::DisposedException(
            "PackageRegistryBackend instance has already been disposed!",
            static_cast<OWeakObject *>(this) );
    }
}


void PackageRegistryBackend::disposing()
{
    try {
        for ( t_string2ref::const_iterator i = m_bound.begin(); i != m_bound.end(); ++i)
            i->second->removeEventListener(this);
        m_bound.clear();
        m_xComponentContext.clear();
        WeakComponentImplHelperBase::disposing();
    }
    catch (const RuntimeException &) {
        throw;
    }
    catch (const Exception &) {
        Any exc( ::cppu::getCaughtException() );
        throw lang::WrappedTargetRuntimeException(
            "caught unexpected exception while disposing!",
            static_cast<OWeakObject *>(this), exc );
    }
}

// XPackageRegistry

Reference<deployment::XPackage> PackageRegistryBackend::bindPackage(
    OUString const & url, OUString const & mediaType, sal_Bool  bRemoved,
    OUString const & identifier, Reference<XCommandEnvironment> const & xCmdEnv )
    throw (deployment::DeploymentException,
           deployment::InvalidRemovedParameterException,
           ucb::CommandFailedException,
           lang::IllegalArgumentException, RuntimeException, std::exception)
{
    ::osl::ResettableMutexGuard guard( getMutex() );
    check();

    t_string2ref::const_iterator const iFind( m_bound.find( url ) );
    if (iFind != m_bound.end())
    {
        Reference<deployment::XPackage> xPackage( iFind->second );
        if (xPackage.is())
        {
            if (!mediaType.isEmpty() &&
                mediaType != xPackage->getPackageType()->getMediaType())
                throw lang::IllegalArgumentException
                    ("XPackageRegistry::bindPackage: media type does not match",
                     static_cast<OWeakObject*>(this), 1);
            if (xPackage->isRemoved() != bRemoved)
                throw deployment::InvalidRemovedParameterException(
                    "XPackageRegistry::bindPackage: bRemoved parameter does not match",
                    static_cast<OWeakObject*>(this), xPackage->isRemoved(), xPackage);
            return xPackage;
        }
    }

    guard.clear();

    Reference<deployment::XPackage> xNewPackage;
    try {
        xNewPackage = bindPackage_( url, mediaType, bRemoved,
            identifier, xCmdEnv );
    }
    catch (const RuntimeException &) {
        throw;
    }
    catch (const CommandFailedException &) {
        throw;
    }
    catch (const deployment::DeploymentException &) {
        throw;
    }
    catch (const Exception &) {
        Any exc( ::cppu::getCaughtException() );
        throw deployment::DeploymentException(
            "Error binding package: " + url,
            static_cast<OWeakObject *>(this), exc );
    }

    guard.reset();

    ::std::pair< t_string2ref::iterator, bool > insertion(
        m_bound.insert( t_string2ref::value_type( url, xNewPackage ) ) );
    if (insertion.second)
    { // first insertion
        SAL_WARN_IF(
            Reference<XInterface>(insertion.first->second) != xNewPackage,
            "desktop.deployment", "mismatch");
    }
    else
    { // found existing entry
        Reference<deployment::XPackage> xPackage( insertion.first->second );
        if (xPackage.is())
            return xPackage;
        insertion.first->second = xNewPackage;
    }

    guard.clear();
    xNewPackage->addEventListener( this ); // listen for disposing events
    return xNewPackage;
}

OUString PackageRegistryBackend::createFolder(
    OUString const & relUrl,
    Reference<ucb::XCommandEnvironment> const & xCmdEnv)
{
    const OUString sDataFolder = makeURL(getCachePath(), relUrl);
    //make sure the folder exist
    ucbhelper::Content dataContent;
    ::dp_misc::create_folder(&dataContent, sDataFolder, xCmdEnv);

    const OUString baseDir(sDataFolder);
    ::utl::TempFile aTemp(&baseDir, true);
    const OUString url = aTemp.GetURL();
    return sDataFolder + url.copy(url.lastIndexOf('/'));
}

//folderURL can have the extension .tmp or .tmp_
//Before OOo 3.4 the created a tmp file with osl_createTempFile and
//then created a Folder with a same name and a trailing '_'
//If the folderURL has no '_' then there is no corresponding tmp file.
void PackageRegistryBackend::deleteTempFolder(
    OUString const & folderUrl)
{
    if (!folderUrl.isEmpty())
    {
        erase_path( folderUrl, Reference<XCommandEnvironment>(),
                    false /* no throw: ignore errors */ );

        if (folderUrl.endsWith("_"))
        {
            const OUString  tempFile = folderUrl.copy(0, folderUrl.getLength() - 1);
            erase_path( tempFile, Reference<XCommandEnvironment>(),
                        false /* no throw: ignore errors */ );
        }
    }
}

//usedFolders can contain folder names which have the extension .tmp or .tmp_
//Before OOo 3.4 we created a tmp file with osl_createTempFile and
//then created a Folder with a same name and a trailing '_'
//If the folderURL has no '_' then there is no corresponding tmp file.
void PackageRegistryBackend::deleteUnusedFolders(
    OUString const & relUrl,
    ::std::list< OUString> const & usedFolders)
{
    try
    {
        const OUString sDataFolder = makeURL(getCachePath(), relUrl);
        ::ucbhelper::Content tempFolder(
            sDataFolder, Reference<ucb::XCommandEnvironment>(), m_xComponentContext);

        Reference<sdbc::XResultSet> xResultSet(
                 StrTitle::createCursor( tempFolder, ::ucbhelper::INCLUDE_FOLDERS_ONLY ) );

        // get all temp directories:
        ::std::vector<OUString> tempEntries;

        const char tmp[] = ".tmp";

        while (xResultSet->next())
        {
            OUString title(
                Reference<sdbc::XRow>(
                    xResultSet, UNO_QUERY_THROW )->getString(
                        1 /* Title */ ) );

            if (title.endsWith(tmp))
                tempEntries.push_back(
                    makeURLAppendSysPathSegment(sDataFolder, title));
        }

        for ( ::std::size_t pos = 0; pos < tempEntries.size(); ++pos )
        {
            if (::std::find( usedFolders.begin(), usedFolders.end(), tempEntries[pos] ) ==
                usedFolders.end())
            {
                deleteTempFolder(tempEntries[pos]);
            }
        }
    }
    catch (const ucb::InteractiveAugmentedIOException& e)
    {
        //In case the folder containing all the data folder does not
        //exist yet, we ignore the exception
        if (e.Code != ucb::IOErrorCode_NOT_EXISTING)
            throw;
    }

}



Package::~Package()
{
}


Package::Package( ::rtl::Reference<PackageRegistryBackend> const & myBackend,
                  OUString const & url,
                  OUString const & rName,
                  OUString const & displayName,
                  Reference<deployment::XPackageTypeInfo> const & xPackageType,
                  bool bRemoved,
                  OUString const & identifier)
    : t_PackageBase( getMutex() ),
      m_myBackend( myBackend ),
      m_url( url ),
      m_name( rName ),
      m_displayName( displayName ),
      m_xPackageType( xPackageType ),
      m_bRemoved(bRemoved),
      m_identifier(identifier)
{
    if (m_bRemoved)
    {
        //We use the last segment of the URL
        SAL_WARN_IF(
            !m_name.isEmpty(), "desktop.deployment", "non-empty m_name");
        OUString name = m_url;
        rtl::Bootstrap::expandMacros(name);
        sal_Int32 index = name.lastIndexOf('/');
        if (index != -1 && index < name.getLength())
            m_name = name.copy(index + 1);
    }
}


void Package::disposing()
{
    m_myBackend.clear();
    WeakComponentImplHelperBase::disposing();
}


void Package::check() const
{
    ::osl::MutexGuard guard( getMutex() );
    if (rBHelper.bInDispose || rBHelper.bDisposed) {
        throw lang::DisposedException(
            "Package instance has already been disposed!",
            static_cast<OWeakObject *>(const_cast<Package *>(this)));
    }
}

// XComponent

void Package::dispose() throw (RuntimeException, std::exception)
{
    //Do not call check here. We must not throw an exception here if the object
    //is being disposed or is already disposed. See com.sun.star.lang.XComponent
    WeakComponentImplHelperBase::dispose();
}


void Package::addEventListener(
    Reference<lang::XEventListener> const & xListener ) throw (RuntimeException, std::exception)
{
    //Do not call check here. We must not throw an exception here if the object
    //is being disposed or is already disposed. See com.sun.star.lang.XComponent
    WeakComponentImplHelperBase::addEventListener( xListener );
}


void Package::removeEventListener(
    Reference<lang::XEventListener> const & xListener ) throw (RuntimeException, std::exception)
{
    //Do not call check here. We must not throw an exception here if the object
    //is being disposed or is already disposed. See com.sun.star.lang.XComponent
    WeakComponentImplHelperBase::removeEventListener( xListener );
}

// XModifyBroadcaster

void Package::addModifyListener(
    Reference<util::XModifyListener> const & xListener )
    throw (RuntimeException, std::exception)
{
    check();
    rBHelper.addListener( ::getCppuType( &xListener ), xListener );
}


void Package::removeModifyListener(
    Reference<util::XModifyListener> const & xListener )
    throw (RuntimeException, std::exception)
{
    check();
    rBHelper.removeListener( ::getCppuType( &xListener ), xListener );
}


void Package::checkAborted(
    ::rtl::Reference<AbortChannel> const & abortChannel )
{
    if (abortChannel.is() && abortChannel->isAborted()) {
        throw CommandAbortedException(
            "abort!", static_cast<OWeakObject *>(this) );
    }
}

// XPackage

Reference<task::XAbortChannel> Package::createAbortChannel()
    throw (RuntimeException, std::exception)
{
    check();
    return new AbortChannel;
}


sal_Bool Package::isBundle() throw (RuntimeException, std::exception)
{
    return false; // default
}


::sal_Int32 Package::checkPrerequisites(
        const css::uno::Reference< css::task::XAbortChannel >&,
        const css::uno::Reference< css::ucb::XCommandEnvironment >&,
        sal_Bool)
        throw (css::deployment::DeploymentException,
               css::deployment::ExtensionRemovedException,
               css::ucb::CommandFailedException,
               css::ucb::CommandAbortedException,
               css::uno::RuntimeException, std::exception)
{
    if (m_bRemoved)
        throw deployment::ExtensionRemovedException();
    return 0;
}


sal_Bool Package::checkDependencies(
        const css::uno::Reference< css::ucb::XCommandEnvironment >& )
        throw (css::deployment::DeploymentException,
               css::deployment::ExtensionRemovedException,
               css::ucb::CommandFailedException,
               css::uno::RuntimeException, std::exception)
{
    if (m_bRemoved)
        throw deployment::ExtensionRemovedException();
    return true;
}



Sequence< Reference<deployment::XPackage> > Package::getBundle(
    Reference<task::XAbortChannel> const &,
    Reference<XCommandEnvironment> const & )
    throw (deployment::DeploymentException,
           CommandFailedException, CommandAbortedException,
           lang::IllegalArgumentException, RuntimeException, std::exception)
{
    return Sequence< Reference<deployment::XPackage> >();
}


OUString Package::getName() throw (RuntimeException, std::exception)
{
    return m_name;
}

beans::Optional<OUString> Package::getIdentifier() throw (RuntimeException, std::exception)
{
    if (m_bRemoved)
        return beans::Optional<OUString>(true, m_identifier);

    return beans::Optional<OUString>();
}


OUString Package::getVersion() throw (
    deployment::ExtensionRemovedException,
    RuntimeException, std::exception)
{
    if (m_bRemoved)
        throw deployment::ExtensionRemovedException();
    return OUString();
}


OUString Package::getURL() throw (RuntimeException, std::exception)
{
    return m_url;
}


OUString Package::getDisplayName() throw (
    deployment::ExtensionRemovedException, RuntimeException, std::exception)
{
    if (m_bRemoved)
        throw deployment::ExtensionRemovedException();
    return m_displayName;
}


OUString Package::getDescription() throw (
    deployment::ExtensionRemovedException,RuntimeException, std::exception)
{
    if (m_bRemoved)
        throw deployment::ExtensionRemovedException();
    return OUString();
}


OUString Package::getLicenseText()throw (
    deployment::DeploymentException,
    deployment::ExtensionRemovedException,
    RuntimeException, std::exception)
{
    if (m_bRemoved)
        throw deployment::ExtensionRemovedException();
    return OUString();
}


Sequence<OUString> Package::getUpdateInformationURLs() throw (
    deployment::ExtensionRemovedException, RuntimeException, std::exception)
{
    if (m_bRemoved)
        throw deployment::ExtensionRemovedException();
    return Sequence<OUString>();
}


css::beans::StringPair Package::getPublisherInfo() throw (
    deployment::ExtensionRemovedException, RuntimeException, std::exception)
{
    if (m_bRemoved)
        throw deployment::ExtensionRemovedException();
    css::beans::StringPair aEmptyPair;
    return aEmptyPair;
}


uno::Reference< css::graphic::XGraphic > Package::getIcon( sal_Bool /*bHighContrast*/ )
    throw (deployment::ExtensionRemovedException, RuntimeException, std::exception )
{
    if (m_bRemoved)
        throw deployment::ExtensionRemovedException();

    uno::Reference< css::graphic::XGraphic > aEmpty;
    return aEmpty;
}


Reference<deployment::XPackageTypeInfo> Package::getPackageType()
    throw (RuntimeException, std::exception)
{
    return m_xPackageType;
}

void Package::exportTo(
    OUString const & destFolderURL, OUString const & newTitle,
    sal_Int32 nameClashAction, Reference<XCommandEnvironment> const & xCmdEnv )
    throw (deployment::ExtensionRemovedException,
           CommandFailedException, CommandAbortedException, ContentCreationException,
           RuntimeException, std::exception)
{
    if (m_bRemoved)
        throw deployment::ExtensionRemovedException();

    ::ucbhelper::Content destFolder( destFolderURL, xCmdEnv, getMyBackend()->getComponentContext() );
    ::ucbhelper::Content sourceContent( getURL(), xCmdEnv, getMyBackend()->getComponentContext() );
    bool bOk=true;
    try
    {
        bOk = destFolder.transferContent(
            sourceContent, ::ucbhelper::InsertOperation_COPY,
            newTitle, nameClashAction);
    }
    catch (const css::ucb::ContentCreationException&)
    {
        bOk = false;
    }

    if (!bOk)
        throw RuntimeException( "UCB transferContent() failed!", 0 );
}

void Package::fireModified()
{
    ::cppu::OInterfaceContainerHelper * container = rBHelper.getContainer(
        cppu::UnoType<util::XModifyListener>::get() );
    if (container != 0) {
        Sequence< Reference<XInterface> > elements(
            container->getElements() );
        lang::EventObject evt( static_cast<OWeakObject *>(this) );
        for ( sal_Int32 pos = 0; pos < elements.getLength(); ++pos )
        {
            Reference<util::XModifyListener> xListener(
                elements[ pos ], UNO_QUERY );
            if (xListener.is())
                xListener->modified( evt );
        }
    }
}

// XPackage

beans::Optional< beans::Ambiguous<sal_Bool> > Package::isRegistered(
    Reference<task::XAbortChannel> const & xAbortChannel,
    Reference<XCommandEnvironment> const & xCmdEnv )
    throw (deployment::DeploymentException,
           CommandFailedException, CommandAbortedException, RuntimeException, std::exception)
{
    try {
        ::osl::ResettableMutexGuard guard( getMutex() );
        return isRegistered_( guard,
                              AbortChannel::get(xAbortChannel),
                              xCmdEnv );
    }
    catch (const RuntimeException &) {
        throw;
    }
    catch (const CommandFailedException &) {
        throw;
    }
    catch (const CommandAbortedException &) {
        throw;
    }
    catch (const deployment::DeploymentException &) {
        throw;
    }
    catch (const Exception &) {
        Any exc( ::cppu::getCaughtException() );
        throw deployment::DeploymentException(
            "unexpected exception occurred!",
            static_cast<OWeakObject *>(this), exc );
    }
}


void Package::processPackage_impl(
    bool doRegisterPackage,
    bool startup,
    Reference<task::XAbortChannel> const & xAbortChannel,
    Reference<XCommandEnvironment> const & xCmdEnv )
{
    check();
    bool action = false;

    try {
        try {
            ::osl::ResettableMutexGuard guard( getMutex() );
            beans::Optional< beans::Ambiguous<sal_Bool> > option(
                isRegistered_( guard, AbortChannel::get(xAbortChannel),
                               xCmdEnv ) );
            action = (option.IsPresent &&
                      (option.Value.IsAmbiguous ||
                       (doRegisterPackage ? !option.Value.Value
                                        : option.Value.Value)));
            if (action) {

                OUString displayName = isRemoved() ? getName() : getDisplayName();
                ProgressLevel progress(
                    xCmdEnv,
                    (doRegisterPackage
                     ? PackageRegistryBackend::StrRegisteringPackage::get()
                     : PackageRegistryBackend::StrRevokingPackage::get())
                    + displayName );
                processPackage_( guard,
                                 doRegisterPackage,
                                 startup,
                                 AbortChannel::get(xAbortChannel),
                                 xCmdEnv );
            }
        }
        catch (lang::IllegalArgumentException &) {
            Any e(cppu::getCaughtException());
            throw deployment::DeploymentException(
                ((doRegisterPackage
                  ? getResourceString(RID_STR_ERROR_WHILE_REGISTERING)
                  : getResourceString(RID_STR_ERROR_WHILE_REVOKING))
                 + getDisplayName()),
                static_cast< OWeakObject * >(this), e);
        }
        catch (const RuntimeException &e) {
            SAL_WARN(
                "desktop.deployment",
                "unexpected RuntimeException \"" << e.Message << '"');
            throw;
        }
        catch (const CommandFailedException &) {
            throw;
        }
        catch (const CommandAbortedException &) {
            throw;
        }
        catch (const deployment::DeploymentException &) {
            throw;
        }
        catch (const Exception &) {
            Any exc( ::cppu::getCaughtException() );
            throw deployment::DeploymentException(
                (doRegisterPackage
                 ? getResourceString(RID_STR_ERROR_WHILE_REGISTERING)
                 : getResourceString(RID_STR_ERROR_WHILE_REVOKING))
                + getDisplayName(), static_cast<OWeakObject *>(this), exc );
        }
    }
    catch (...) {
        if (action)
            fireModified();
        throw;
    }
    if (action)
        fireModified();
}


void Package::registerPackage(
    sal_Bool startup,
    Reference<task::XAbortChannel> const & xAbortChannel,
    Reference<XCommandEnvironment> const & xCmdEnv )
    throw (deployment::DeploymentException,
           deployment::ExtensionRemovedException,
           CommandFailedException, CommandAbortedException,
           lang::IllegalArgumentException, RuntimeException, std::exception)
{
    if (m_bRemoved)
        throw deployment::ExtensionRemovedException();
    processPackage_impl( true /* register */, startup, xAbortChannel, xCmdEnv );
}


void Package::revokePackage(
    sal_Bool startup,
    Reference<task::XAbortChannel> const & xAbortChannel,
    Reference<XCommandEnvironment> const & xCmdEnv )
    throw (deployment::DeploymentException,
           CommandFailedException, CommandAbortedException,
           lang::IllegalArgumentException, RuntimeException, std::exception)
{
    processPackage_impl( false /* revoke */, startup, xAbortChannel, xCmdEnv );

}

PackageRegistryBackend * Package::getMyBackend() const
{
    PackageRegistryBackend * pBackend = m_myBackend.get();
    if (NULL == pBackend)
    {
        //May throw a DisposedException
        check();
        //We should never get here...
        throw RuntimeException(
            "Failed to get the BackendImpl",
            static_cast<OWeakObject*>(const_cast<Package *>(this)));
    }
    return pBackend;
}

OUString Package::getRepositoryName()
    throw (RuntimeException, std::exception)
{
    PackageRegistryBackend * backEnd = getMyBackend();
    return backEnd->getContext();
}

beans::Optional< OUString > Package::getRegistrationDataURL()
        throw (deployment::DeploymentException,
               deployment::ExtensionRemovedException,
               css::uno::RuntimeException, std::exception)
{
    if (m_bRemoved)
        throw deployment::ExtensionRemovedException();
    return beans::Optional<OUString>();
}

sal_Bool Package::isRemoved()
    throw (RuntimeException, std::exception)
{
    return m_bRemoved;
}

Package::TypeInfo::~TypeInfo()
{
}

// XPackageTypeInfo

OUString Package::TypeInfo::getMediaType() throw (RuntimeException, std::exception)
{
    return m_mediaType;
}


OUString Package::TypeInfo::getDescription()
    throw (deployment::ExtensionRemovedException, RuntimeException, std::exception)
{
    return getShortDescription();
}


OUString Package::TypeInfo::getShortDescription()
    throw (deployment::ExtensionRemovedException, RuntimeException, std::exception)
{
    return m_shortDescr;
}


OUString Package::TypeInfo::getFileFilter() throw (RuntimeException, std::exception)
{
    return m_fileFilter;
}


/**************************
 * Get Icon
 *
 * @param highContrast NOTE: disabled the returning of high contrast icons.
 *                     This bool is a noop now.
 * @param smallIcon    Return the small version of the icon
 */
Any Package::TypeInfo::getIcon( sal_Bool /*highContrast*/, sal_Bool smallIcon )
    throw (RuntimeException, std::exception)
{
    if (! smallIcon)
        return Any();
    const sal_uInt16 nIconId = m_smallIcon;
    return Any( &nIconId, cppu::UnoType<cppu::UnoUnsignedShortType>::get() );
}

}
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */