27#include <rtl/ustring.hxx>
28#include <rtl/bootstrap.hxx>
33#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
34#include <com/sun/star/deployment/DeploymentException.hpp>
35#include <com/sun/star/deployment/ExtensionRemovedException.hpp>
36#include <com/sun/star/deployment/InvalidRemovedParameterException.hpp>
37#include <com/sun/star/ucb/ContentCreationException.hpp>
38#include <com/sun/star/ucb/CommandAbortedException.hpp>
39#include <com/sun/star/ucb/CommandFailedException.hpp>
40#include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
41#include <com/sun/star/ucb/IOErrorCode.hpp>
42#include <com/sun/star/beans/StringPair.hpp>
43#include <com/sun/star/sdbc/XResultSet.hpp>
44#include <com/sun/star/sdbc/XRow.hpp>
65 Reference<deployment::XPackage> xPackage(
66 event.Source, UNO_QUERY_THROW );
67 OUString url( xPackage->getURL() );
69 if (
m_bound.erase( url ) != 1 )
71 SAL_WARN(
"desktop.deployment",
"erase(" << url <<
") != 1");
77 Sequence<Any>
const & args,
78 Reference<XComponentContext>
const &
xContext )
84 std::optional<OUString> cachePath;
85 std::optional<bool> readOnly;
98 else if (
m_context.matchIgnoreAsciiCase(
"vnd.sun.star.tdoc:/"))
107 ::osl::MutexGuard guard(
m_aMutex );
108 if (rBHelper.bInDispose || rBHelper.bDisposed) {
109 throw lang::DisposedException(
110 "PackageRegistryBackend instance has already been disposed!",
111 static_cast<OWeakObject *
>(
this) );
119 for (
auto const& elem :
m_bound)
120 elem.second->removeEventListener(
this);
123 WeakComponentImplHelperBase::disposing();
129 Any exc( ::cppu::getCaughtException() );
130 throw lang::WrappedTargetRuntimeException(
131 "caught unexpected exception while disposing!",
132 static_cast<OWeakObject *
>(
this), exc );
139 OUString
const & url, OUString
const & mediaType,
sal_Bool bRemoved,
140 OUString
const & identifier, Reference<XCommandEnvironment>
const & xCmdEnv )
142 ::osl::ResettableMutexGuard guard(
m_aMutex );
145 t_string2ref::const_iterator
const iFind(
m_bound.find( url ) );
148 Reference<deployment::XPackage> xPackage( iFind->second );
151 if (!mediaType.isEmpty() &&
152 mediaType != xPackage->getPackageType()->getMediaType())
153 throw lang::IllegalArgumentException
154 (
"XPackageRegistry::bindPackage: media type does not match",
155 static_cast<OWeakObject*
>(
this), 1);
156 if (xPackage->isRemoved() != bRemoved)
157 throw deployment::InvalidRemovedParameterException(
158 "XPackageRegistry::bindPackage: bRemoved parameter does not match",
159 static_cast<OWeakObject*
>(
this), xPackage->isRemoved(), xPackage);
166 Reference<deployment::XPackage> xNewPackage;
174 catch (
const CommandFailedException &) {
177 catch (
const deployment::DeploymentException &) {
181 Any exc( ::cppu::getCaughtException() );
182 throw deployment::DeploymentException(
183 "Error binding package: " + url,
184 static_cast<OWeakObject *
>(
this), exc );
189 std::pair< t_string2ref::iterator, bool > insertion(
190 m_bound.emplace( url, xNewPackage ) );
191 if (insertion.second)
194 Reference<XInterface>(insertion.first->second) != xNewPackage,
195 "desktop.deployment",
"mismatch");
199 Reference<deployment::XPackage> xPackage( insertion.first->second );
202 insertion.first->second = xNewPackage;
206 xNewPackage->addEventListener(
this );
211 Reference<ucb::XCommandEnvironment>
const & xCmdEnv)
218 const OUString url = ::utl::CreateTempURL(&sDataFolder,
true);
219 return sDataFolder + url.subView(url.lastIndexOf(
'/'));
227 OUString
const & folderUrl)
229 if (!folderUrl.isEmpty())
231 erase_path( folderUrl, Reference<XCommandEnvironment>(),
234 if (folderUrl.endsWith(
"_"))
236 const OUString tempFile = folderUrl.copy(0, folderUrl.getLength() - 1);
237 erase_path( tempFile, Reference<XCommandEnvironment>(),
248 std::vector< OUString>
const & usedFolders)
256 Reference<sdbc::XResultSet> xResultSet(
257 StrTitle::createCursor( tempFolder, ::ucbhelper::INCLUDE_FOLDERS_ONLY ) );
260 std::vector<OUString> tempEntries;
262 while (xResultSet->next())
265 Reference<sdbc::XRow>(
266 xResultSet, UNO_QUERY_THROW )->
getString(
269 if (title.endsWith(
".tmp"))
270 tempEntries.push_back(
274 for (
const OUString & tempEntrie : tempEntries)
276 if (std::find( usedFolders.begin(), usedFolders.end(), tempEntrie ) ==
283 catch (
const ucb::InteractiveAugmentedIOException& e)
287 if (e.Code != ucb::IOErrorCode_NOT_EXISTING)
302 OUString displayName,
303 Reference<deployment::XPackageTypeInfo>
const & xPackageType,
307 m_myBackend(
std::move( myBackend )),
310 m_displayName(
std::move( displayName )),
311 m_xPackageType( xPackageType ),
312 m_bRemoved(bRemoved),
319 !
m_name.isEmpty(),
"desktop.deployment",
"non-empty m_name");
321 rtl::Bootstrap::expandMacros(
name);
332 WeakComponentImplHelperBase::disposing();
338 ::osl::MutexGuard guard(
m_aMutex );
339 if (rBHelper.bInDispose || rBHelper.bDisposed) {
340 throw lang::DisposedException(
341 "Package instance has already been disposed!",
342 static_cast<OWeakObject *
>(
const_cast<Package *
>(
this)));
352 WeakComponentImplHelperBase::dispose();
357 Reference<lang::XEventListener>
const & xListener )
361 WeakComponentImplHelperBase::addEventListener( xListener );
366 Reference<lang::XEventListener>
const & xListener )
370 WeakComponentImplHelperBase::removeEventListener( xListener );
376 Reference<util::XModifyListener>
const & xListener )
379 rBHelper.addListener(
cppu::UnoType<
decltype(xListener)>::get(), xListener );
384 Reference<util::XModifyListener>
const & xListener )
387 rBHelper.removeListener(
cppu::UnoType<
decltype(xListener)>::get(), xListener );
394 if (abortChannel.is() && abortChannel->isAborted()) {
395 throw CommandAbortedException(
396 "abort!",
static_cast<OWeakObject *
>(
this) );
405 return new AbortChannel;
416 const css::uno::Reference< css::task::XAbortChannel >&,
417 const css::uno::Reference< css::ucb::XCommandEnvironment >&,
421 throw deployment::ExtensionRemovedException();
427 const css::uno::Reference< css::ucb::XCommandEnvironment >& )
430 throw deployment::ExtensionRemovedException();
436 Reference<task::XAbortChannel>
const &,
437 Reference<XCommandEnvironment>
const & )
439 return Sequence< Reference<deployment::XPackage> >();
453 return beans::Optional<OUString>();
460 throw deployment::ExtensionRemovedException();
474 throw deployment::ExtensionRemovedException();
482 throw deployment::ExtensionRemovedException();
490 throw deployment::ExtensionRemovedException();
498 throw deployment::ExtensionRemovedException();
499 return Sequence<OUString>();
506 throw deployment::ExtensionRemovedException();
507 css::beans::StringPair aEmptyPair;
515 throw deployment::ExtensionRemovedException();
528 OUString
const & destFolderURL, OUString
const & newTitle,
529 sal_Int32 nameClashAction, Reference<XCommandEnvironment>
const & xCmdEnv )
532 throw deployment::ExtensionRemovedException();
541 newTitle, nameClashAction);
543 catch (
const css::ucb::ContentCreationException&)
556 if (container ==
nullptr)
559 const Sequence< Reference<XInterface> > elements(
561 lang::EventObject evt(
static_cast<OWeakObject *
>(
this) );
562 for (
const Reference<XInterface>&
x : elements )
564 Reference<util::XModifyListener> xListener(
x, UNO_QUERY );
566 xListener->modified( evt );
573 Reference<task::XAbortChannel>
const & xAbortChannel,
574 Reference<XCommandEnvironment>
const & xCmdEnv )
577 ::osl::ResettableMutexGuard guard(
m_aMutex );
579 AbortChannel::get(xAbortChannel),
585 catch (
const CommandFailedException &) {
588 catch (
const CommandAbortedException &) {
591 catch (
const deployment::DeploymentException &) {
595 Any exc( ::cppu::getCaughtException() );
596 throw deployment::DeploymentException(
597 "unexpected " + exc.getValueTypeName() +
": " + e.Message,
598 static_cast<OWeakObject *
>(
this), exc );
604 bool doRegisterPackage,
606 Reference<task::XAbortChannel>
const & xAbortChannel,
607 Reference<XCommandEnvironment>
const & xCmdEnv )
614 ::osl::ResettableMutexGuard guard(
m_aMutex );
615 beans::Optional< beans::Ambiguous<sal_Bool> >
option(
619 (
option.Value.IsAmbiguous ||
620 (doRegisterPackage ? !
option.Value.Value
625 ProgressLevel progress(
634 AbortChannel::get(xAbortChannel),
638 catch (lang::IllegalArgumentException &) {
640 throw deployment::DeploymentException(
642 ?
DpResId(RID_STR_ERROR_WHILE_REGISTERING)
643 :
DpResId(RID_STR_ERROR_WHILE_REVOKING))
645 static_cast< OWeakObject *
>(
this), e);
651 catch (
const CommandFailedException &) {
654 catch (
const CommandAbortedException &) {
657 catch (
const deployment::DeploymentException &) {
661 Any exc( ::cppu::getCaughtException() );
662 throw deployment::DeploymentException(
664 ?
DpResId(RID_STR_ERROR_WHILE_REGISTERING)
665 :
DpResId(RID_STR_ERROR_WHILE_REVOKING))
666 +
getDisplayName() +
": " + exc.getValueType().getTypeName() +
" \"" + e.Message
668 static_cast<OWeakObject *
>(
this), exc );
683 Reference<task::XAbortChannel>
const & xAbortChannel,
684 Reference<XCommandEnvironment>
const & xCmdEnv )
687 throw deployment::ExtensionRemovedException();
694 Reference<task::XAbortChannel>
const & xAbortChannel,
695 Reference<XCommandEnvironment>
const & xCmdEnv )
704 if (
nullptr == pBackend)
710 "Failed to get the BackendImpl",
711 static_cast<OWeakObject*
>(
const_cast<Package *
>(
this)));
725 throw deployment::ExtensionRemovedException();
726 return beans::Optional<OUString>();
748 return getShortDescription();
mutable::osl::Mutex m_aMutex
css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > SAL_CALL getElements() const
virtual css::uno::Reference< css::deployment::XPackage > SAL_CALL bindPackage(OUString const &url, OUString const &mediaType, sal_Bool bRemoved, OUString const &identifier, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
OUString createFolder(css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv)
virtual void SAL_CALL disposing() override
static OUString StrRegisteringPackage()
static void deleteTempFolder(OUString const &folderUrl)
virtual ~PackageRegistryBackend() override
virtual css::uno::Reference< css::deployment::XPackage > bindPackage_(OUString const &url, OUString const &mediaType, bool bRemoved, OUString const &identifier, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv)=0
static OUString StrRevokingPackage()
void deleteUnusedFolders(std::vector< OUString > const &usedFolders)
enum dp_registry::backend::PackageRegistryBackend::Context m_eContext
PackageRegistryBackend(css::uno::Sequence< css::uno::Any > const &args, css::uno::Reference< css::uno::XComponentContext > const &xContext)
const OUString & getContext() const
css::uno::Reference< css::uno::XComponentContext > m_xComponentContext
OUString const & getCachePath() const
virtual OUString SAL_CALL getDescription() override
virtual css::uno::Any SAL_CALL getIcon(sal_Bool highContrast, sal_Bool smallIcon) override
virtual OUString SAL_CALL getShortDescription() override
virtual OUString SAL_CALL getMediaType() override
virtual ~TypeInfo() override
virtual OUString SAL_CALL getFileFilter() override
virtual OUString SAL_CALL getLicenseText() override
virtual OUString SAL_CALL getName() override
virtual void SAL_CALL removeEventListener(css::uno::Reference< css::lang::XEventListener > const &xListener) override
virtual void processPackage_(::osl::ResettableMutexGuard &guard, bool registerPackage, bool startup, ::rtl::Reference< ::dp_misc::AbortChannel > const &abortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv)=0
void checkAborted(::rtl::Reference< ::dp_misc::AbortChannel > const &abortChannel)
const css::uno::Reference< css::deployment::XPackageTypeInfo > m_xPackageType
virtual void SAL_CALL addModifyListener(css::uno::Reference< css::util::XModifyListener > const &xListener) override
virtual void SAL_CALL exportTo(OUString const &destFolderURL, OUString const &newTitle, sal_Int32 nameClashAction, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
virtual OUString SAL_CALL getURL() override
virtual OUString SAL_CALL getDescription() override
virtual OUString SAL_CALL getRepositoryName() override
virtual void SAL_CALL removeModifyListener(css::uno::Reference< css::util::XModifyListener > const &xListener) override
virtual ::sal_Bool SAL_CALL checkDependencies(const css::uno::Reference< css::ucb::XCommandEnvironment > &xCmdEnv) override
virtual sal_Bool SAL_CALL isBundle() override
PackageRegistryBackend * getMyBackend() const
::rtl::Reference< PackageRegistryBackend > m_myBackend
virtual ~Package() override
virtual void SAL_CALL dispose() override
virtual void SAL_CALL registerPackage(sal_Bool startup, css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
virtual OUString SAL_CALL getDisplayName() override
virtual css::uno::Reference< css::graphic::XGraphic > SAL_CALL getIcon(sal_Bool bHighContrast) override
virtual css::beans::Optional< OUString > SAL_CALL getRegistrationDataURL() override
virtual css::beans::Optional< OUString > SAL_CALL getIdentifier() override
virtual void SAL_CALL addEventListener(css::uno::Reference< css::lang::XEventListener > const &xListener) override
virtual css::beans::StringPair SAL_CALL getPublisherInfo() override
Package(::rtl::Reference< PackageRegistryBackend > myBackend, OUString url, OUString name, OUString displayName, css::uno::Reference< css::deployment::XPackageTypeInfo > const &xPackageType, bool bRemoved, OUString identifier)
virtual OUString SAL_CALL getVersion() override
virtual css::beans::Optional< css::beans::Ambiguous< sal_Bool > > isRegistered_(::osl::ResettableMutexGuard &guard, ::rtl::Reference< ::dp_misc::AbortChannel > const &abortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv)=0
const OUString m_identifier
virtual css::uno::Sequence< css::uno::Reference< css::deployment::XPackage > > SAL_CALL getBundle(css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
virtual void SAL_CALL disposing() override
void processPackage_impl(bool registerPackage, bool startup, css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv)
virtual css::beans::Optional< css::beans::Ambiguous< sal_Bool > > SAL_CALL isRegistered(css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
virtual css::uno::Reference< css::deployment::XPackageTypeInfo > SAL_CALL getPackageType() override
virtual css::uno::Sequence< OUString > SAL_CALL getUpdateInformationURLs() override
virtual ::sal_Int32 SAL_CALL checkPrerequisites(const css::uno::Reference< css::task::XAbortChannel > &xAbortChannel, const css::uno::Reference< css::ucb::XCommandEnvironment > &xCmdEnv, sal_Bool noLicenseChecking) override
virtual css::uno::Reference< css::task::XAbortChannel > SAL_CALL createAbortChannel() override
virtual void SAL_CALL revokePackage(sal_Bool startup, css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
virtual sal_Bool SAL_CALL isRemoved() override
void transferContent(const Content &rSourceContent, InsertOperation eOperation, const OUString &rTitle, const sal_Int32 nNameClashAction, const OUString &rMimeType=OUString(), bool bMajorVersion=false, const OUString &rCommentVersion=OUString(), OUString *pResultURL=nullptr, const OUString &rDocumentId=OUString()) const
#define TOOLS_WARN_EXCEPTION(area, stream)
Reference< XComponentContext > const m_xComponentContext
OUString DpResId(TranslateId aId)
static uno::Reference< css::uno::XComponentContext > xContext
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
void unwrapArgs(const css::uno::Sequence< css::uno::Any > &seq, Args &... args)
Reference< XComponentContext > getComponentContext(Reference< XMultiServiceFactory > const &factory)
OUString getString(const Any &_rAny)
Any SAL_CALL getCaughtException()
OUString makeURL(std::u16string_view baseURL, OUString const &relPath_)
appends a relative path to a url.
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC bool create_folder(::ucbhelper::Content *ucb_content, OUString const &url, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv, bool throw_exc=true)
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC bool erase_path(OUString const &url, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv, bool throw_exc=true)
OUString makeURLAppendSysPathSegment(std::u16string_view baseURL, OUString const &segment)
appends a relative path to a url.
::cppu::WeakComponentImplHelper< css::deployment::XPackage > t_PackageBase
::cppu::WeakComponentImplHelper< css::lang::XEventListener, css::deployment::XPackageRegistry, css::lang::XServiceInfo > t_BackendBase
::boost::spirit::classic::rule< ScannerT > identifier