summaryrefslogtreecommitdiff
path: root/desktop/source/deployment/registry/script
diff options
context:
space:
mode:
authorKurt Zenker <kz@openoffice.org>2004-06-11 11:18:31 +0000
committerKurt Zenker <kz@openoffice.org>2004-06-11 11:18:31 +0000
commit3a4b9944cede71ca669ad8ca7d545c132a7112f9 (patch)
treea473af6cf1fec77d4aa4bbeb7fa451115da8f52c /desktop/source/deployment/registry/script
parent5a0e545115da7fdb5145bebdb1a7ddbb072af9f6 (diff)
INTEGRATION: CWS unopkg2 (1.2.4); FILE MERGED
2004/06/09 14:09:21 dbo 1.2.4.6: #i30026# Basic/Dialogs libs found everywhere in legacy bundles 2004/05/26 12:38:25 dbo 1.2.4.5: #i20304# string review Issue number: Submitted by: Reviewed by: 2004/05/19 12:53:49 dbo 1.2.4.4: #i20304# minor fixes 2004/05/18 18:15:28 dbo 1.2.4.3: #115885# icons, minor fixes 2004/05/14 16:56:26 dbo 1.2.4.2: #i20304# live deployment, abort feature 2004/05/11 15:14:22 dbo 1.2.4.1: #i20304# major API revision, GUI Issue number: Submitted by: Reviewed by:
Diffstat (limited to 'desktop/source/deployment/registry/script')
-rw-r--r--desktop/source/deployment/registry/script/dp_script.cxx442
1 files changed, 255 insertions, 187 deletions
diff --git a/desktop/source/deployment/registry/script/dp_script.cxx b/desktop/source/deployment/registry/script/dp_script.cxx
index 83ec341f2194..82347fd52107 100644
--- a/desktop/source/deployment/registry/script/dp_script.cxx
+++ b/desktop/source/deployment/registry/script/dp_script.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: dp_script.cxx,v $
*
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
*
- * last change: $Author: hr $ $Date: 2004-04-13 12:09:59 $
+ * last change: $Author: kz $ $Date: 2004-06-11 12:18:31 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -59,13 +59,15 @@
*
************************************************************************/
+#include "dp_script.hrc"
#include "dp_lib_container.h"
#include "dp_backend.h"
#include "dp_ucb.h"
#include "rtl/uri.hxx"
-#include "cppuhelper/exc_hlp.hxx"
#include "ucbhelper/content.hxx"
-#include "comphelper/anytostring.hxx"
+#include "cppuhelper/exc_hlp.hxx"
+#include "svtools/inettype.hxx"
+#include "com/sun/star/script/XLibraryContainer.hpp"
#include <memory>
@@ -74,6 +76,7 @@ using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::ucb;
using ::rtl::OUString;
+namespace css = ::com::sun::star;
namespace dp_registry
{
@@ -87,119 +90,150 @@ class BackendImpl : public ::dp_registry::backend::PackageRegistryBackend
{
protected:
// PackageRegistryBackend
- virtual Reference< deployment::XPackage > createPackage(
- OUString const & url,
- OUString const & mediaType, OUString const & subType,
- INetContentTypeParameterList const & params,
- Reference< XCommandEnvironment > const & xCmdEnv );
+ virtual Reference<deployment::XPackage> bindPackage_(
+ OUString const & url, OUString const & mediaType,
+ Reference<XCommandEnvironment> const & xCmdEnv );
public:
- // currently only for library containers:
- enum { LAYER_NONE, LAYER_USER, LAYER_SHARED } m_layer;
+ Reference<css::script::XLibraryContainer> m_xScriptLibs;
+ Reference<css::script::XLibraryContainer> m_xDialogLibs;
+ ::std::auto_ptr<LibraryContainer> m_basic_script_libs;
+ ::std::auto_ptr<LibraryContainer> m_dialog_libs;
- ::std::auto_ptr< LibraryContainer > m_basic_script_libs;
- ::std::auto_ptr< LibraryContainer > m_dialog_libs;
+ OUString m_strBasicLib;
+ OUString m_strDialogLib;
inline BackendImpl(
- Reference< XComponentContext > const & xComponentContext,
+ Reference<XComponentContext> const & xComponentContext,
OUString const & implName,
- Sequence< OUString > const & supported_media_types )
+ Sequence<OUString> const & supportedMediaTypes )
: PackageRegistryBackend(
- xComponentContext, implName, supported_media_types ),
- m_layer( LAYER_NONE )
+ xComponentContext, implName, supportedMediaTypes ),
+ m_strBasicLib( getResourceString(RID_STR_BASIC_LIB) ),
+ m_strDialogLib( getResourceString(RID_STR_DIALOG_LIB) )
{}
// XInitialization
- virtual void SAL_CALL initialize( Sequence< Any > const & args )
- throw (RuntimeException);
-
- // XPackageRegistry
- virtual OUString SAL_CALL detectMediaType( OUString const & url )
- throw (RuntimeException);
+ virtual void SAL_CALL initialize( Sequence<Any> const & args )
+ throw (Exception);
};
//==============================================================================
class PackageImpl : public ::dp_registry::backend::Package
{
- bool m_scriptLib;
- OUString m_libURL;
- OUString const & getLibName(
- Reference< XCommandEnvironment > const & xCmdEnv );
+protected:
+ OUString m_scriptURL;
+ OUString m_dialogURL;
+ OUString m_dialogName;
inline BackendImpl * getMyBackend() const
- { return static_cast< BackendImpl * >(m_myBackend.get()); }
-
- inline LibraryContainer * getContainer() const
- {
- return m_scriptLib ? getMyBackend()->m_basic_script_libs.get()
- : getMyBackend()->m_dialog_libs.get();
- }
-
- // OPropertySetHelper
- virtual void SAL_CALL getFastPropertyValue(
- Any & rValue, sal_Int32 nHandle ) const;
+ { return static_cast<BackendImpl *>(m_myBackend.get()); }
// Package
- virtual t_Registered getRegStatus(
+ virtual bool isRegistered_(
::osl::ResettableMutexGuard & guard,
- Reference< XCommandEnvironment > const & xCmdEnv );
- virtual bool processPackage(
- bool register_package,
+ ::rtl::Reference<AbortChannel> const & abortChannel,
+ Reference<XCommandEnvironment> const & xCmdEnv );
+ virtual void processPackage_(
::osl::ResettableMutexGuard & guard,
- Reference< XCommandEnvironment > const & xCmdEnv );
+ bool registerPackage,
+ ::rtl::Reference<AbortChannel> const & abortChannel,
+ Reference<XCommandEnvironment> const & xCmdEnv );
-public:
- PackageImpl(
- ::rtl::Reference< PackageRegistryBackend > const & myBackend,
+ inline PackageImpl(
+ ::rtl::Reference<BackendImpl> const & myBackend,
OUString const & url,
OUString const & mediaType,
- bool scriptLib )
- : Package( myBackend, url, mediaType,
- OUString() /* no name yet */,
- OUString() /* no display-name yet */,
- scriptLib
- ? OUSTR("Basic Script Library")
- : OUSTR("Dialog Library") ),
- m_scriptLib( scriptLib ),
- m_libURL( make_url( url, scriptLib ? OUSTR("script.xlb")
- : OUSTR("dialog.xlb") ) )
+ OUString const & scriptURL, OUString const & dialogURL )
+ : Package( myBackend.get(), url, mediaType,
+ OUString(), OUString(), // will be late-initialized
+ scriptURL.getLength() > 0
+ ? myBackend->m_strBasicLib : myBackend->m_strDialogLib ),
+ m_scriptURL( scriptURL ),
+ m_dialogURL( dialogURL )
{}
+
+public:
+ static PackageImpl * create(
+ ::rtl::Reference<BackendImpl> const & myBackend,
+ OUString const & url,
+ OUString const & mediaType,
+ Reference<XCommandEnvironment> const &xCmdEnv,
+ OUString const & scriptURL, OUString const & dialogURL );
+
+ // XPackage
+ virtual Any SAL_CALL getIcon( sal_Bool highContrast, sal_Bool smallIcon )
+ throw (RuntimeException);
};
//______________________________________________________________________________
+PackageImpl * PackageImpl::create(
+ ::rtl::Reference<BackendImpl> const & myBackend,
+ OUString const & url,
+ OUString const & mediaType,
+ Reference<XCommandEnvironment> const &xCmdEnv,
+ OUString const & scriptURL, OUString const & dialogURL )
+{
+ ::std::auto_ptr<PackageImpl> ret(
+ new PackageImpl( myBackend, url, mediaType, scriptURL, dialogURL ) );
+
+ // name, displayName:
+ if (dialogURL.getLength() > 0)
+ ret->m_dialogName = LibraryContainer::get_libname(
+ dialogURL, xCmdEnv, myBackend->getComponentContext() );
+ if (scriptURL.getLength() > 0)
+ ret->m_name = LibraryContainer::get_libname(
+ scriptURL, xCmdEnv, myBackend->getComponentContext() );
+ else
+ ret->m_name = ret->m_dialogName;
+ ret->m_displayName = ret->m_name;
+
+ return ret.release();
+}
+
+//______________________________________________________________________________
void BackendImpl::initialize( Sequence< Any > const & args )
- throw (RuntimeException)
+ throw (Exception)
{
PackageRegistryBackend::initialize( args );
- if (args.getLength() > 2) // optional context
+ if (! transientMode())
{
- OUString context( extract_throw< OUString >( args[ 2 ] ) );
- if (context.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("user") ))
- m_layer = LAYER_USER;
- else if (context.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("shared") ))
- m_layer = LAYER_SHARED;
- }
- if (m_layer != LAYER_NONE)
- {
- OUString basic_path(
- m_layer == LAYER_USER
- ? OUSTR("vnd.sun.star.expand:${$SYSBINDIR/"
- SAL_CONFIGFILE("bootstrap")
- ":UserInstallation}/user/basic")
- : OUSTR("vnd.sun.star.expand:${$SYSBINDIR/"
- SAL_CONFIGFILE("bootstrap")
- ":BaseInstallation}/share/basic") );
- m_basic_script_libs.reset(
- new LibraryContainer(
- make_url( basic_path, OUSTR("/script.xlc") ),
- getMutex(),
- getComponentContext() ) );
- m_dialog_libs.reset(
- new LibraryContainer(
- make_url( basic_path, OUSTR("/dialog.xlc") ),
- getMutex(),
- getComponentContext() ) );
+ if (office_is_running())
+ {
+ Reference<XComponentContext> xContext( getComponentContext() );
+ m_xScriptLibs.set(
+ xContext->getServiceManager()->createInstanceWithContext(
+ OUSTR("com.sun.star."
+ "script.ApplicationScriptLibraryContainer"),
+ xContext ), UNO_QUERY_THROW );
+ m_xDialogLibs.set(
+ xContext->getServiceManager()->createInstanceWithContext(
+ OUSTR("com.sun.star."
+ "script.ApplicationDialogLibraryContainer"),
+ xContext ), UNO_QUERY_THROW );
+ }
+ else
+ {
+ OUString basic_path(
+ m_eContext == CONTEXT_USER
+ ? OUSTR("vnd.sun.star.expand:${$SYSBINDIR/"
+ SAL_CONFIGFILE("bootstrap")
+ ":UserInstallation}/user/basic")
+ : OUSTR("vnd.sun.star.expand:${$SYSBINDIR/"
+ SAL_CONFIGFILE("bootstrap")
+ ":BaseInstallation}/share/basic") );
+ m_basic_script_libs.reset(
+ new LibraryContainer(
+ make_url( basic_path, OUSTR("/script.xlc") ),
+ getMutex(),
+ getComponentContext() ) );
+ m_dialog_libs.reset(
+ new LibraryContainer(
+ make_url( basic_path, OUSTR("/dialog.xlc") ),
+ getMutex(),
+ getComponentContext() ) );
+ }
}
}
@@ -210,148 +244,182 @@ OUString SAL_CALL getImplementationName()
}
//==============================================================================
-Reference< XInterface > SAL_CALL create(
- Reference< XComponentContext > const & xComponentContext )
+Reference<XInterface> SAL_CALL create(
+ Reference<XComponentContext> const & xComponentContext )
SAL_THROW( (Exception) )
{
- OUString const media_types [] = {
+ OUString const mediaTypes [] = {
OUSTR("application/vnd.sun.star.basic-script"),
OUSTR("application/vnd.sun.star.dialog-library")
};
return static_cast< ::cppu::OWeakObject * >(
new BackendImpl(
xComponentContext, getImplementationName(),
- Sequence< OUString >( media_types, ARLEN(media_types) ) ) );
+ Sequence<OUString >( mediaTypes, ARLEN(mediaTypes) ) ) );
}
-// XPackageRegistry
+// PackageRegistryBackend
//______________________________________________________________________________
-OUString BackendImpl::detectMediaType( OUString const & url )
- throw (RuntimeException)
+Reference<deployment::XPackage> BackendImpl::bindPackage_(
+ OUString const & url, OUString const & mediaType_,
+ Reference<XCommandEnvironment> const & xCmdEnv )
{
- ::ucb::Content ucb_content;
- if (::ucb::Content::create( url, Reference< XCommandEnvironment >(),
- ucb_content ) &&
- ucb_content.isFolder())
+ OUString mediaType( mediaType_ );
+ if (mediaType.getLength() == 0)
{
- // probe for script.xlb:
- if (create_ucb_content(
- 0, make_url( ucb_content.getURL(), OUSTR("script.xlb") ),
- Reference< XCommandEnvironment >(), false /* no throw */ ))
- return OUSTR("application/vnd.sun.star.basic-script");
- // probe for dialog.xlb:
- if (create_ucb_content(
- 0, make_url( ucb_content.getURL(), OUSTR("dialog.xlb") ),
- Reference< XCommandEnvironment >(), false /* no throw */ ))
- return OUSTR("application/vnd.sun.star.dialog-library");
+ // detect media-type:
+ ::ucb::Content ucbContent;
+ if (create_ucb_content( &ucbContent, url, xCmdEnv ) &&
+ ucbContent.isFolder())
+ {
+ // probe for script.xlb:
+ if (create_ucb_content(
+ 0, make_url( url, OUSTR("script.xlb") ),
+ xCmdEnv, false /* no throw */ ))
+ mediaType = OUSTR("application/vnd.sun.star.basic-script");
+ // probe for dialog.xlb:
+ else if (create_ucb_content(
+ 0, make_url( url, OUSTR("dialog.xlb") ),
+ xCmdEnv, false /* no throw */ ))
+ mediaType = OUSTR("application/vnd.sun.star.dialog-library");
+ }
+ if (mediaType.getLength() == 0)
+ throw lang::IllegalArgumentException(
+ m_strCannotDetectMediaType + url,
+ static_cast<OWeakObject *>(this), static_cast<sal_Int16>(-1) );
}
- return OUString();
-}
-// PackageRegistryBackend
-//______________________________________________________________________________
-Reference< deployment::XPackage > BackendImpl::createPackage(
- OUString const & url,
- OUString const & mediaType, OUString const & subType,
- INetContentTypeParameterList const & params,
- Reference< XCommandEnvironment > const & xCmdEnv )
-{
- if (subType.matchIgnoreAsciiCaseAsciiL(
- RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.basic-script") ))
- return new PackageImpl( this, url, mediaType, true );
- if (subType.matchIgnoreAsciiCaseAsciiL(
- RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.dialog-library") ))
- return new PackageImpl( this, url, mediaType, false );
+ String type, subType;
+ INetContentTypeParameterList params;
+ if (INetContentTypes::parse( mediaType, type, subType, &params ))
+ {
+ if (type.EqualsIgnoreCaseAscii("application"))
+ {
+ if (subType.EqualsIgnoreCaseAscii("vnd.sun.star.basic-script"))
+ {
+ OUString dialogURL( make_url( url, OUSTR("dialog.xlb") ) );
+ if (! create_ucb_content(
+ 0, dialogURL, xCmdEnv, false /* no throw */ ))
+ dialogURL = OUString();
+ return PackageImpl::create(
+ this, url, mediaType, xCmdEnv,
+ make_url( url, OUSTR("script.xlb") ), dialogURL );
+ }
+ else if (subType.EqualsIgnoreCaseAscii(
+ "vnd.sun.star.dialog-library"))
+ {
+ return PackageImpl::create(
+ this, url, mediaType, xCmdEnv,
+ OUString(), make_url( url, OUSTR("dialog.xlb") ) );
+ }
+ }
+ }
throw lang::IllegalArgumentException(
- OUSTR("invalid media-type given: ") + mediaType,
- static_cast< OWeakObject * >(this),
- static_cast< sal_Int16 >(-1 /* not known */) );
+ m_strUnsupportedMediaType + mediaType,
+ static_cast<OWeakObject *>(this),
+ static_cast<sal_Int16>(-1) );
}
//##############################################################################
+// XPackage
//______________________________________________________________________________
-OUString const & PackageImpl::getLibName(
- Reference< XCommandEnvironment > const & xCmdEnv )
-{
- ::osl::MutexGuard guard( getMutex() );
- if (m_name.getLength() == 0)
- {
- m_name = LibraryContainer::get_libname(
- m_libURL, xCmdEnv, getMyBackend()->getComponentContext() );
- }
- return m_name;
-}
-
-// OPropertySetHelper
-//______________________________________________________________________________
-void PackageImpl::getFastPropertyValue( Any & rValue, sal_Int32 nHandle ) const
+Any PackageImpl::getIcon( sal_Bool highContrast, sal_Bool smallIcon )
+ throw (RuntimeException)
{
- // xxx todo: upon disposing() getPropertyValue( URL )...
-// check();
- switch (nHandle)
+ OSL_ASSERT( smallIcon );
+ if (smallIcon)
{
- case NAME:
- case DISPLAY_NAME:
- {
- try
- {
- rValue <<= const_cast< PackageImpl * >(this)->getLibName( 0 );
- }
- catch (RuntimeException &)
- {
- throw;
- }
- catch (Exception &)
- {
- Any exc( ::cppu::getCaughtException() );
- throw lang::WrappedTargetException(
- OUSTR("caught exception reading Basic library name!"),
- static_cast< OWeakObject * >(
- const_cast< PackageImpl * >(this) ), exc );
- }
- break;
- }
- default:
- Package::getFastPropertyValue( rValue, nHandle );
- break;
+ sal_uInt16 ret;
+ if (m_scriptURL.getLength() > 0)
+ ret = highContrast ? RID_IMG_SCRIPTLIB_HC : RID_IMG_SCRIPTLIB;
+ else
+ ret = highContrast ? RID_IMG_DIALOGLIB_HC : RID_IMG_DIALOGLIB;
+ return makeAny(ret);
}
+ return Package::getIcon( highContrast, smallIcon );
}
// Package
//______________________________________________________________________________
-PackageImpl::t_Registered PackageImpl::getRegStatus(
+bool PackageImpl::isRegistered_(
::osl::ResettableMutexGuard & guard,
- Reference< XCommandEnvironment > const & xCmdEnv )
+ ::rtl::Reference<AbortChannel> const & abortChannel,
+ Reference<XCommandEnvironment> const & xCmdEnv )
{
BackendImpl * that = getMyBackend();
- if (that->m_layer == BackendImpl::LAYER_NONE)
- return REG_VOID;
- if (getContainer()->has( getLibName( xCmdEnv ), xCmdEnv ))
- return REG_REGISTERED;
+ if (m_scriptURL.getLength() > 0)
+ {
+ if (that->m_xScriptLibs.is())
+ return that->m_xScriptLibs->hasByName( m_name );
+ else
+ return that->m_basic_script_libs->has( m_name, xCmdEnv );
+ }
else
- return REG_NOT_REGISTERED;
+ {
+ if (that->m_xDialogLibs.is())
+ return that->m_xDialogLibs->hasByName( m_dialogName );
+ else
+ return that->m_dialog_libs->has( m_dialogName, xCmdEnv );
+ }
}
//______________________________________________________________________________
-bool PackageImpl::processPackage(
- bool register_package,
+void PackageImpl::processPackage_(
::osl::ResettableMutexGuard & guard,
- Reference< XCommandEnvironment > const & xCmdEnv )
+ bool registerPackage,
+ ::rtl::Reference<AbortChannel> const & abortChannel,
+ Reference<XCommandEnvironment> const & xCmdEnv )
{
BackendImpl * that = getMyBackend();
- // xxx todo:
- OSL_ASSERT( that->m_layer != BackendImpl::LAYER_NONE );
- that->ensure_no_running_office();
-
- LibraryContainer * container = getContainer();
- bool success;
- if (register_package)
- success = container->insert( getLibName( xCmdEnv ), m_libURL, xCmdEnv );
+ if (registerPackage)
+ {
+ if (m_scriptURL.getLength() > 0)
+ {
+ if (that->m_xScriptLibs.is())
+ that->m_xScriptLibs->createLibraryLink(
+ m_name, m_scriptURL, false /* ! read-only */ );
+ else
+ that->m_basic_script_libs->insert(
+ m_name, m_scriptURL, xCmdEnv );
+ }
+ if (m_dialogURL.getLength() > 0)
+ {
+ if (that->m_xDialogLibs.is())
+ that->m_xDialogLibs->createLibraryLink(
+ m_dialogName, m_dialogURL, false /* ! read-only */ );
+ else
+ that->m_dialog_libs->insert(
+ m_dialogName, m_dialogURL, xCmdEnv );
+ }
+ }
else // revokePackage()
- success = container->remove( getLibName( xCmdEnv ), m_libURL, xCmdEnv );
- success &= container->flush( xCmdEnv );
- return success;
+ {
+ try
+ {
+ if (m_scriptURL.getLength() > 0)
+ {
+ if (that->m_xScriptLibs.is())
+ that->m_xScriptLibs->removeLibrary( m_name );
+ else
+ that->m_basic_script_libs->remove(
+ m_name, m_scriptURL, xCmdEnv );
+ }
+ if (m_dialogURL.getLength() > 0)
+ {
+ if (that->m_xDialogLibs.is())
+ that->m_xDialogLibs->removeLibrary( m_dialogName );
+ else
+ that->m_dialog_libs->remove(
+ m_dialogName, m_dialogURL, xCmdEnv );
+ }
+ }
+ catch (lang::WrappedTargetException & exc)
+ {
+ // unwrap WrappedTargetException:
+ ::cppu::throwException( exc.TargetException );
+ }
+ }
}
} // namespace script