diff options
author | David Tardon <dtardon@redhat.com> | 2010-11-25 14:00:50 +0100 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2010-11-25 15:36:41 +0100 |
commit | f55a2a5510a1e35b474cd62c4a4a3b941f740b91 (patch) | |
tree | 7168234691d5b0f74fb000f0bf02b611c8a5b79d /desktop | |
parent | c4ea14d08bb97356bbe0ddb0cb2c1f8eae657054 (diff) |
refactor duplicate code
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/source/deployment/registry/script/dp_script.cxx | 134 |
1 files changed, 59 insertions, 75 deletions
diff --git a/desktop/source/deployment/registry/script/dp_script.cxx b/desktop/source/deployment/registry/script/dp_script.cxx index 0c99cf45e9..31b30271a9 100644 --- a/desktop/source/deployment/registry/script/dp_script.cxx +++ b/desktop/source/deployment/registry/script/dp_script.cxx @@ -82,7 +82,7 @@ class BackendImpl : public t_helper bool startup, ::rtl::Reference<AbortChannel> const & abortChannel, Reference<XCommandEnvironment> const & xCmdEnv ); - + public: PackageImpl( ::rtl::Reference<BackendImpl> const & myBackend, @@ -319,7 +319,60 @@ BackendImpl::PackageImpl::isRegistered_( beans::Ambiguous<sal_Bool>( registered, false /* IsAmbiguous */ ) ); } -//______________________________________________________________________________ +void +lcl_maybeRemoveScript( + bool const bExists, + OUString const& rName, + OUString const& rScriptURL, + Reference<css::script::XLibraryContainer3> const& xScriptLibs) +{ + if (bExists && xScriptLibs.is() && xScriptLibs->hasByName(rName)) + { + const OUString sScriptUrl = xScriptLibs->getOriginalLibraryLinkURL(rName); + if (sScriptUrl.equals(rScriptURL)) + xScriptLibs->removeLibrary(rName); + } +} + +bool +lcl_maybeAddScript( + bool const bExists, + OUString const& rName, + OUString const& rScriptURL, + Reference<css::script::XLibraryContainer3> const& xScriptLibs) +{ + if (bExists && xScriptLibs.is()) + { + bool bCanAdd = true; + if (xScriptLibs->hasByName(rName)) + { + const OUString sOriginalUrl = xScriptLibs->getOriginalLibraryLinkURL(rName); + //We assume here that library names in extensions are unique, which may not be the case + //ToDo: If the script exist in another extension, then both extensions must have the + //same id + if (sOriginalUrl.match(OUSTR("vnd.sun.star.expand:$UNO_USER_PACKAGES_CACHE")) + || sOriginalUrl.match(OUSTR("vnd.sun.star.expand:$UNO_SHARED_PACKAGES_CACHE")) + || sOriginalUrl.match(OUSTR("vnd.sun.star.expand:$BUNDLED_EXTENSIONS"))) + { + xScriptLibs->removeLibrary(rName); + bCanAdd = true; + } + else + { + bCanAdd = false; + } + } + + if (bCanAdd) + { + xScriptLibs->createLibraryLink(rName, rScriptURL, false); + return xScriptLibs->hasByName(rName); + } + } + + return false; +} + void BackendImpl::PackageImpl::processPackage_( ::osl::ResettableMutexGuard & /* guard */, bool doRegisterPackage, @@ -375,19 +428,8 @@ void BackendImpl::PackageImpl::processPackage_( //we also prevent and live deployment at startup if (!isRemoved() && !startup) { - if (bScript && xScriptLibs.is() && xScriptLibs->hasByName(m_name)) - { - const OUString sScriptUrl = xScriptLibs->getOriginalLibraryLinkURL(m_name); - if (sScriptUrl.equals(m_scriptURL)) - xScriptLibs->removeLibrary(m_name); - } - - if (bDialog && xDialogLibs.is() && xDialogLibs->hasByName(m_dialogName)) - { - const OUString sDialogUrl = xDialogLibs->getOriginalLibraryLinkURL(m_dialogName); - if (sDialogUrl.equals(m_dialogURL)) - xDialogLibs->removeLibrary(m_dialogName); - } + lcl_maybeRemoveScript(bScript, m_name, m_scriptURL, xScriptLibs); + lcl_maybeRemoveScript(bDialog, m_dialogName, m_dialogURL, xDialogLibs); } getMyBackend()->deleteDataFromDb(getURL()); return; @@ -398,72 +440,14 @@ void BackendImpl::PackageImpl::processPackage_( // Update LibraryContainer bool bScriptSuccess = false; - const bool bReadOnly = false; - bool bDialogSuccess = false; if (!startup) { //If there is a bundled extension, and the user installes the same extension //then the script from the bundled extension must be removed. If this does not work //then live deployment does not work for scripts. - if (bScript && xScriptLibs.is()) - { - bool bCanAdd = true; - if (xScriptLibs->hasByName(m_name)) - { - const OUString sOriginalUrl = xScriptLibs->getOriginalLibraryLinkURL(m_name); - //We assume here that library names in extensions are unique, which may not be the case - //ToDo: If the script exist in another extension, then both extensions must have the - //same id - if (sOriginalUrl.match(OUSTR("vnd.sun.star.expand:$UNO_USER_PACKAGES_CACHE")) - || sOriginalUrl.match(OUSTR("vnd.sun.star.expand:$UNO_SHARED_PACKAGES_CACHE")) - || sOriginalUrl.match(OUSTR("vnd.sun.star.expand:$BUNDLED_EXTENSIONS"))) - { - xScriptLibs->removeLibrary(m_name); - bCanAdd = true; - } - else - { - bCanAdd = false; - } - } - - if (bCanAdd) - { - xScriptLibs->createLibraryLink( m_name, m_scriptURL, bReadOnly ); - bScriptSuccess = xScriptLibs->hasByName( m_name ); - } - } - - - if (bDialog && xDialogLibs.is()) - { - bool bCanAdd = true; - if (xDialogLibs->hasByName(m_dialogName)) - { - const OUString sOriginalUrl = xDialogLibs->getOriginalLibraryLinkURL(m_dialogName); - //We assume here that library names in extensions are unique, which may not be the case - //ToDo: If the script exist in another extension, then both extensions must have the - //same id - if (sOriginalUrl.match(OUSTR("vnd.sun.star.expand:$UNO_USER_PACKAGES_CACHE")) - || sOriginalUrl.match(OUSTR("vnd.sun.star.expand:$UNO_SHARED_PACKAGES_CACHE")) - || sOriginalUrl.match(OUSTR("vnd.sun.star.expand:$BUNDLED_EXTENSIONS"))) - { - xDialogLibs->removeLibrary(m_dialogName); - bCanAdd = true; - } - else - { - bCanAdd = false; - } - } - - if (bCanAdd) - { - xDialogLibs->createLibraryLink( m_dialogName, m_dialogURL, bReadOnly ); - bDialogSuccess = xDialogLibs->hasByName(m_dialogName); - } - } + bScriptSuccess = lcl_maybeAddScript(bScript, m_name, m_scriptURL, xScriptLibs); + bDialogSuccess = lcl_maybeAddScript(bDialog, m_dialogName, m_dialogURL, xDialogLibs); } bool bSuccess = bScript || bDialog; // Something must have happened if( bRunning && !startup) |