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