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