2004-04-13 11:08:09 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 03:10:37 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2004-04-13 11:08:09 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2004-04-13 11:08:09 +00:00
|
|
|
*
|
2008-04-11 03:10:37 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2004-04-13 11:08:09 +00:00
|
|
|
*
|
2008-04-11 03:10:37 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2004-04-13 11:08:09 +00:00
|
|
|
*
|
2008-04-11 03:10:37 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2004-04-13 11:08:09 +00:00
|
|
|
*
|
2008-04-11 03:10:37 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2004-04-13 11:08:09 +00:00
|
|
|
*
|
2008-04-11 03:10:37 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2004-04-13 11:08:09 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-17 08:43:11 +00:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_desktop.hxx"
|
|
|
|
|
2004-06-11 11:11:52 +00:00
|
|
|
#include "dp_registry.hrc"
|
2004-04-13 11:08:09 +00:00
|
|
|
#include "dp_misc.h"
|
2004-06-11 11:11:52 +00:00
|
|
|
#include "dp_resource.h"
|
|
|
|
#include "dp_interact.h"
|
2004-04-13 11:08:09 +00:00
|
|
|
#include "dp_ucb.h"
|
|
|
|
#include "osl/diagnose.h"
|
|
|
|
#include "rtl/ustrbuf.hxx"
|
|
|
|
#include "rtl/uri.hxx"
|
2004-11-09 13:10:54 +00:00
|
|
|
#include "cppuhelper/compbase2.hxx"
|
2004-06-11 11:11:52 +00:00
|
|
|
#include "cppuhelper/exc_hlp.hxx"
|
2006-03-06 09:21:54 +00:00
|
|
|
#include "comphelper/sequence.hxx"
|
2004-11-09 13:10:54 +00:00
|
|
|
#include "ucbhelper/content.hxx"
|
2004-04-13 11:08:09 +00:00
|
|
|
#include "com/sun/star/uno/DeploymentException.hpp"
|
|
|
|
#include "com/sun/star/lang/DisposedException.hpp"
|
|
|
|
#include "com/sun/star/lang/WrappedTargetRuntimeException.hpp"
|
|
|
|
#include "com/sun/star/lang/XServiceInfo.hpp"
|
|
|
|
#include "com/sun/star/lang/XSingleComponentFactory.hpp"
|
|
|
|
#include "com/sun/star/lang/XSingleServiceFactory.hpp"
|
2004-11-09 13:10:54 +00:00
|
|
|
#include "com/sun/star/util/XUpdatable.hpp"
|
2004-04-13 11:08:09 +00:00
|
|
|
#include "com/sun/star/container/XContentEnumerationAccess.hpp"
|
2004-08-12 11:09:56 +00:00
|
|
|
#include "com/sun/star/deployment/PackageRegistryBackend.hpp"
|
2004-04-13 11:08:09 +00:00
|
|
|
#include <hash_map>
|
2004-11-09 13:10:54 +00:00
|
|
|
#include <set>
|
|
|
|
#include <hash_set>
|
2004-04-13 11:08:09 +00:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
using namespace ::dp_misc;
|
|
|
|
using namespace ::com::sun::star;
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::ucb;
|
|
|
|
using ::rtl::OUString;
|
|
|
|
|
2009-01-22 17:12:19 +00:00
|
|
|
|
2004-08-12 11:09:56 +00:00
|
|
|
namespace dp_registry {
|
2004-04-13 11:08:09 +00:00
|
|
|
|
2004-11-09 13:10:54 +00:00
|
|
|
namespace backend {
|
|
|
|
namespace bundle {
|
|
|
|
Reference<deployment::XPackageRegistry> create(
|
|
|
|
Reference<deployment::XPackageRegistry> const & xRootRegistry,
|
|
|
|
OUString const & context, OUString const & cachePath, bool readOnly,
|
|
|
|
Reference<XComponentContext> const & xComponentContext );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
typedef ::cppu::WeakComponentImplHelper2<
|
|
|
|
deployment::XPackageRegistry, util::XUpdatable > t_helper;
|
2004-04-13 11:08:09 +00:00
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
class PackageRegistryImpl : private MutexHolder, public t_helper
|
|
|
|
{
|
2004-11-09 13:10:54 +00:00
|
|
|
struct ci_string_hash {
|
|
|
|
::std::size_t operator () ( OUString const & str ) const {
|
2004-08-12 11:09:56 +00:00
|
|
|
return str.toAsciiLowerCase().hashCode();
|
|
|
|
}
|
2004-04-13 11:08:09 +00:00
|
|
|
};
|
2004-11-09 13:10:54 +00:00
|
|
|
struct ci_string_equals {
|
|
|
|
bool operator () ( OUString const & str1, OUString const & str2 ) const{
|
2004-08-12 11:09:56 +00:00
|
|
|
return str1.equalsIgnoreAsciiCase( str2 );
|
|
|
|
}
|
2004-04-13 11:08:09 +00:00
|
|
|
};
|
|
|
|
typedef ::std::hash_map<
|
2004-06-11 11:11:52 +00:00
|
|
|
OUString, Reference<deployment::XPackageRegistry>,
|
2004-04-13 11:08:09 +00:00
|
|
|
ci_string_hash, ci_string_equals > t_string2registry;
|
2004-11-09 13:10:54 +00:00
|
|
|
typedef ::std::hash_map<
|
|
|
|
OUString, OUString,
|
|
|
|
ci_string_hash, ci_string_equals > t_string2string;
|
|
|
|
typedef ::std::set<
|
|
|
|
Reference<deployment::XPackageRegistry> > t_registryset;
|
2004-04-13 11:08:09 +00:00
|
|
|
|
2004-11-09 13:10:54 +00:00
|
|
|
t_string2registry m_mediaType2backend;
|
|
|
|
t_string2string m_filter2mediaType;
|
|
|
|
t_registryset m_ambiguousBackends;
|
|
|
|
t_registryset m_allBackends;
|
|
|
|
::std::vector< Reference<deployment::XPackageTypeInfo> > m_typesInfos;
|
2004-04-13 11:08:09 +00:00
|
|
|
|
2004-08-12 11:09:56 +00:00
|
|
|
void insertBackend(
|
|
|
|
Reference<deployment::XPackageRegistry> const & xBackend );
|
|
|
|
|
2004-04-13 11:08:09 +00:00
|
|
|
protected:
|
2004-06-11 11:11:52 +00:00
|
|
|
inline void check();
|
2004-04-13 11:08:09 +00:00
|
|
|
virtual void SAL_CALL disposing();
|
|
|
|
|
2004-06-11 11:11:52 +00:00
|
|
|
virtual ~PackageRegistryImpl();
|
2004-08-12 11:09:56 +00:00
|
|
|
PackageRegistryImpl() : t_helper( getMutex() ) {}
|
2004-11-09 13:10:54 +00:00
|
|
|
|
2004-08-12 11:09:56 +00:00
|
|
|
public:
|
|
|
|
static Reference<deployment::XPackageRegistry> create(
|
|
|
|
OUString const & context,
|
|
|
|
OUString const & cachePath, bool readOnly,
|
|
|
|
Reference<XComponentContext> const & xComponentContext );
|
2004-04-13 11:08:09 +00:00
|
|
|
|
2004-11-09 13:10:54 +00:00
|
|
|
// XUpdatable
|
|
|
|
virtual void SAL_CALL update() throw (RuntimeException);
|
|
|
|
|
2004-04-13 11:08:09 +00:00
|
|
|
// XPackageRegistry
|
2004-06-11 11:11:52 +00:00
|
|
|
virtual Reference<deployment::XPackage> SAL_CALL bindPackage(
|
2010-05-04 12:37:01 +02:00
|
|
|
OUString const & url, OUString const & mediaType, sal_Bool bNoFileAccess,
|
2004-06-11 11:11:52 +00:00
|
|
|
Reference<XCommandEnvironment> const & xCmdEnv )
|
|
|
|
throw (deployment::DeploymentException, CommandFailedException,
|
|
|
|
lang::IllegalArgumentException, RuntimeException);
|
2004-11-09 13:10:54 +00:00
|
|
|
virtual Sequence< Reference<deployment::XPackageTypeInfo> > SAL_CALL
|
|
|
|
getSupportedPackageTypes() throw (RuntimeException);
|
2004-04-13 11:08:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//______________________________________________________________________________
|
2004-06-11 11:11:52 +00:00
|
|
|
inline void PackageRegistryImpl::check()
|
2004-04-13 11:08:09 +00:00
|
|
|
{
|
2004-06-11 11:11:52 +00:00
|
|
|
::osl::MutexGuard guard( getMutex() );
|
2004-08-12 11:09:56 +00:00
|
|
|
if (rBHelper.bInDispose || rBHelper.bDisposed) {
|
2004-04-13 11:08:09 +00:00
|
|
|
throw lang::DisposedException(
|
|
|
|
OUSTR("PackageRegistry instance has already been disposed!"),
|
2004-06-11 11:11:52 +00:00
|
|
|
static_cast<OWeakObject *>(this) );
|
2004-04-13 11:08:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//______________________________________________________________________________
|
|
|
|
void PackageRegistryImpl::disposing()
|
|
|
|
{
|
2004-11-09 13:10:54 +00:00
|
|
|
// dispose all backends:
|
|
|
|
t_registryset::const_iterator iPos( m_allBackends.begin() );
|
|
|
|
t_registryset::const_iterator const iEnd( m_allBackends.end() );
|
|
|
|
for ( ; iPos != iEnd; ++iPos ) {
|
2004-04-13 11:08:09 +00:00
|
|
|
try_dispose( *iPos );
|
2004-11-09 13:10:54 +00:00
|
|
|
}
|
|
|
|
m_mediaType2backend = t_string2registry();
|
|
|
|
m_ambiguousBackends = t_registryset();
|
|
|
|
m_allBackends = t_registryset();
|
2004-04-13 11:08:09 +00:00
|
|
|
|
|
|
|
t_helper::disposing();
|
|
|
|
}
|
|
|
|
|
|
|
|
//______________________________________________________________________________
|
|
|
|
PackageRegistryImpl::~PackageRegistryImpl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//______________________________________________________________________________
|
2004-11-09 13:10:54 +00:00
|
|
|
OUString normalizeMediaType( OUString const & mediaType )
|
2004-04-13 11:08:09 +00:00
|
|
|
{
|
|
|
|
::rtl::OUStringBuffer buf;
|
|
|
|
sal_Int32 index = 0;
|
2004-08-12 11:09:56 +00:00
|
|
|
for (;;) {
|
2004-04-13 11:08:09 +00:00
|
|
|
buf.append( mediaType.getToken( 0, '/', index ).trim() );
|
|
|
|
if (index < 0)
|
|
|
|
break;
|
|
|
|
buf.append( static_cast< sal_Unicode >('/') );
|
|
|
|
}
|
|
|
|
return buf.makeStringAndClear();
|
|
|
|
}
|
|
|
|
|
|
|
|
//______________________________________________________________________________
|
2010-02-10 10:27:57 +01:00
|
|
|
|
2004-08-12 11:09:56 +00:00
|
|
|
void PackageRegistryImpl::insertBackend(
|
|
|
|
Reference<deployment::XPackageRegistry> const & xBackend )
|
2004-04-13 11:08:09 +00:00
|
|
|
{
|
2004-11-09 13:10:54 +00:00
|
|
|
m_allBackends.insert( xBackend );
|
|
|
|
typedef ::std::hash_set<OUString, ::rtl::OUStringHash> t_stringset;
|
|
|
|
t_stringset ambiguousFilters;
|
|
|
|
|
|
|
|
const Sequence< Reference<deployment::XPackageTypeInfo> > packageTypes(
|
|
|
|
xBackend->getSupportedPackageTypes() );
|
|
|
|
for ( sal_Int32 pos = 0; pos < packageTypes.getLength(); ++pos )
|
|
|
|
{
|
|
|
|
Reference<deployment::XPackageTypeInfo> const & xPackageType =
|
|
|
|
packageTypes[ pos ];
|
|
|
|
m_typesInfos.push_back( xPackageType );
|
|
|
|
|
|
|
|
const OUString mediaType( normalizeMediaType(
|
|
|
|
xPackageType->getMediaType() ) );
|
|
|
|
::std::pair<t_string2registry::iterator, bool> mb_insertion(
|
|
|
|
m_mediaType2backend.insert( t_string2registry::value_type(
|
|
|
|
mediaType, xBackend ) ) );
|
2010-02-10 10:27:57 +01:00
|
|
|
if (mb_insertion.second)
|
|
|
|
{
|
2004-11-09 13:10:54 +00:00
|
|
|
// add parameterless media-type, too:
|
|
|
|
sal_Int32 semi = mediaType.indexOf( ';' );
|
|
|
|
if (semi >= 0) {
|
|
|
|
m_mediaType2backend.insert(
|
|
|
|
t_string2registry::value_type(
|
|
|
|
mediaType.copy( 0, semi ), xBackend ) );
|
|
|
|
}
|
|
|
|
const OUString fileFilter( xPackageType->getFileFilter() );
|
2010-02-10 10:27:57 +01:00
|
|
|
//The package backend shall also be called to determine the mediatype
|
|
|
|
//(XPackageRegistry.bindPackage) when the URL points to a directory.
|
|
|
|
const bool bExtension = mediaType.equals(OUSTR("application/vnd.sun.star.package-bundle"));
|
2004-11-09 13:10:54 +00:00
|
|
|
if (fileFilter.getLength() == 0 ||
|
|
|
|
fileFilter.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("*.*") ) ||
|
2010-02-10 10:27:57 +01:00
|
|
|
fileFilter.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("*") ) ||
|
|
|
|
bExtension)
|
2004-11-09 13:10:54 +00:00
|
|
|
{
|
|
|
|
m_ambiguousBackends.insert( xBackend );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sal_Int32 nIndex = 0;
|
|
|
|
do {
|
|
|
|
OUString token( fileFilter.getToken( 0, ';', nIndex ) );
|
|
|
|
if (token.matchAsciiL( RTL_CONSTASCII_STRINGPARAM("*.") ))
|
|
|
|
token = token.copy( 1 );
|
|
|
|
if (token.getLength() == 0)
|
|
|
|
continue;
|
|
|
|
// mark any further wildcards ambig:
|
|
|
|
bool ambig = (token.indexOf('*') >= 0 ||
|
|
|
|
token.indexOf('?') >= 0);
|
|
|
|
if (! ambig) {
|
|
|
|
::std::pair<t_string2string::iterator, bool> ins(
|
|
|
|
m_filter2mediaType.insert(
|
|
|
|
t_string2string::value_type(
|
|
|
|
token, mediaType ) ) );
|
|
|
|
ambig = !ins.second;
|
|
|
|
if (ambig) {
|
|
|
|
// filter has already been in: add previously
|
|
|
|
// added backend to ambig set
|
|
|
|
const t_string2registry::const_iterator iFind(
|
|
|
|
m_mediaType2backend.find(
|
|
|
|
/* media-type of pr. added backend */
|
|
|
|
ins.first->second ) );
|
|
|
|
OSL_ASSERT(
|
|
|
|
iFind != m_mediaType2backend.end() );
|
|
|
|
if (iFind != m_mediaType2backend.end())
|
|
|
|
m_ambiguousBackends.insert( iFind->second );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ambig) {
|
|
|
|
m_ambiguousBackends.insert( xBackend );
|
|
|
|
// mark filter to be removed later from filters map:
|
|
|
|
ambiguousFilters.insert( token );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (nIndex >= 0);
|
|
|
|
}
|
|
|
|
}
|
2004-08-12 11:09:56 +00:00
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
2004-11-09 13:10:54 +00:00
|
|
|
else {
|
2004-08-12 11:09:56 +00:00
|
|
|
::rtl::OUStringBuffer buf;
|
|
|
|
buf.appendAscii(
|
|
|
|
RTL_CONSTASCII_STRINGPARAM(
|
|
|
|
"more than one PackageRegistryBackend for "
|
|
|
|
"media-type=\"") );
|
|
|
|
buf.append( mediaType );
|
|
|
|
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\" => ") );
|
|
|
|
buf.append( Reference<lang::XServiceInfo>(
|
|
|
|
xBackend, UNO_QUERY_THROW )->
|
|
|
|
getImplementationName() );
|
|
|
|
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\"!") );
|
|
|
|
OSL_ENSURE( 0, ::rtl::OUStringToOString(
|
|
|
|
buf.makeStringAndClear(),
|
|
|
|
RTL_TEXTENCODING_UTF8 ) );
|
|
|
|
}
|
|
|
|
#endif
|
2004-06-11 11:11:52 +00:00
|
|
|
}
|
2004-08-12 11:09:56 +00:00
|
|
|
|
2004-11-09 13:10:54 +00:00
|
|
|
// cut out ambiguous filters:
|
|
|
|
t_stringset::const_iterator iPos( ambiguousFilters.begin() );
|
|
|
|
const t_stringset::const_iterator iEnd( ambiguousFilters.end() );
|
|
|
|
for ( ; iPos != iEnd; ++iPos ) {
|
|
|
|
m_filter2mediaType.erase( *iPos );
|
|
|
|
}
|
2004-08-12 11:09:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//______________________________________________________________________________
|
|
|
|
Reference<deployment::XPackageRegistry> PackageRegistryImpl::create(
|
|
|
|
OUString const & context,
|
|
|
|
OUString const & cachePath, bool readOnly,
|
|
|
|
Reference<XComponentContext> const & xComponentContext )
|
|
|
|
{
|
|
|
|
PackageRegistryImpl * that = new PackageRegistryImpl;
|
|
|
|
Reference<deployment::XPackageRegistry> xRet(that);
|
2004-04-13 11:08:09 +00:00
|
|
|
|
2004-06-11 11:11:52 +00:00
|
|
|
// auto-detect all registered package registries:
|
|
|
|
Reference<container::XEnumeration> xEnum(
|
|
|
|
Reference<container::XContentEnumerationAccess>(
|
2004-08-12 11:09:56 +00:00
|
|
|
xComponentContext->getServiceManager(),
|
2004-06-11 11:11:52 +00:00
|
|
|
UNO_QUERY_THROW )->createContentEnumeration(
|
|
|
|
OUSTR("com.sun.star.deployment.PackageRegistryBackend") ) );
|
|
|
|
if (xEnum.is())
|
2004-04-13 11:08:09 +00:00
|
|
|
{
|
2004-06-11 11:11:52 +00:00
|
|
|
while (xEnum->hasMoreElements())
|
2004-04-13 11:08:09 +00:00
|
|
|
{
|
2004-06-11 11:11:52 +00:00
|
|
|
Any element( xEnum->nextElement() );
|
2004-08-12 11:09:56 +00:00
|
|
|
Sequence<Any> registryArgs(
|
|
|
|
cachePath.getLength() == 0 ? 1 : 3 );
|
|
|
|
registryArgs[ 0 ] <<= context;
|
2004-06-11 11:11:52 +00:00
|
|
|
if (cachePath.getLength() > 0)
|
2004-04-13 11:08:09 +00:00
|
|
|
{
|
2004-06-11 11:11:52 +00:00
|
|
|
Reference<lang::XServiceInfo> xServiceInfo(
|
|
|
|
element, UNO_QUERY_THROW );
|
|
|
|
OUString registryCachePath(
|
2004-11-09 13:10:54 +00:00
|
|
|
makeURL( cachePath,
|
|
|
|
::rtl::Uri::encode(
|
|
|
|
xServiceInfo->getImplementationName(),
|
|
|
|
rtl_UriCharClassPchar,
|
|
|
|
rtl_UriEncodeIgnoreEscapes,
|
|
|
|
RTL_TEXTENCODING_UTF8 ) ) );
|
2004-08-12 11:09:56 +00:00
|
|
|
registryArgs[ 1 ] <<= registryCachePath;
|
|
|
|
registryArgs[ 2 ] <<= readOnly;
|
2004-06-11 11:11:52 +00:00
|
|
|
if (! readOnly)
|
|
|
|
create_folder( 0, registryCachePath,
|
|
|
|
Reference<XCommandEnvironment>() );
|
|
|
|
}
|
2004-04-13 11:08:09 +00:00
|
|
|
|
2004-06-11 11:11:52 +00:00
|
|
|
Reference<deployment::XPackageRegistry> xBackend;
|
2004-08-12 11:09:56 +00:00
|
|
|
Reference<lang::XSingleComponentFactory> xFac( element, UNO_QUERY );
|
|
|
|
if (xFac.is()) {
|
2004-06-11 11:11:52 +00:00
|
|
|
xBackend.set(
|
|
|
|
xFac->createInstanceWithArgumentsAndContext(
|
2004-08-12 11:09:56 +00:00
|
|
|
registryArgs, xComponentContext ), UNO_QUERY );
|
2004-06-11 11:11:52 +00:00
|
|
|
}
|
2004-08-12 11:09:56 +00:00
|
|
|
else {
|
2004-06-11 11:11:52 +00:00
|
|
|
Reference<lang::XSingleServiceFactory> xSingleServiceFac(
|
|
|
|
element, UNO_QUERY_THROW );
|
|
|
|
xBackend.set(
|
|
|
|
xSingleServiceFac->createInstanceWithArguments(
|
|
|
|
registryArgs ), UNO_QUERY );
|
|
|
|
}
|
2004-08-12 11:09:56 +00:00
|
|
|
if (! xBackend.is()) {
|
2004-06-11 11:11:52 +00:00
|
|
|
throw DeploymentException(
|
|
|
|
OUSTR("cannot instantiate PackageRegistryBackend service: ")
|
|
|
|
+ Reference<lang::XServiceInfo>(
|
|
|
|
element, UNO_QUERY_THROW )->getImplementationName(),
|
2004-08-12 11:09:56 +00:00
|
|
|
static_cast<OWeakObject *>(that) );
|
2004-06-11 11:11:52 +00:00
|
|
|
}
|
2004-04-13 11:08:09 +00:00
|
|
|
|
2004-08-12 11:09:56 +00:00
|
|
|
that->insertBackend( xBackend );
|
2004-04-13 11:08:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-10 10:27:57 +01:00
|
|
|
// Insert bundle back-end.
|
|
|
|
// Always register as last, because we want to add extensions also as folders
|
|
|
|
// and as a default we accept every folder, which was not recognized by the other
|
|
|
|
// backends.
|
2010-05-04 12:37:01 +02:00
|
|
|
Reference<deployment::XPackageRegistry> extensionBackend =
|
2004-08-12 11:09:56 +00:00
|
|
|
::dp_registry::backend::bundle::create(
|
2010-05-04 12:37:01 +02:00
|
|
|
that, context, cachePath, readOnly, xComponentContext);
|
|
|
|
that->insertBackend(extensionBackend);
|
|
|
|
|
|
|
|
Reference<lang::XServiceInfo> xServiceInfo(
|
|
|
|
extensionBackend, UNO_QUERY_THROW );
|
|
|
|
|
|
|
|
OSL_ASSERT(xServiceInfo.is());
|
|
|
|
OUString registryCachePath(
|
|
|
|
makeURL( cachePath,
|
|
|
|
::rtl::Uri::encode(
|
|
|
|
xServiceInfo->getImplementationName(),
|
|
|
|
rtl_UriCharClassPchar,
|
|
|
|
rtl_UriEncodeIgnoreEscapes,
|
|
|
|
RTL_TEXTENCODING_UTF8 ) ) );
|
|
|
|
create_folder( 0, registryCachePath, Reference<XCommandEnvironment>());
|
|
|
|
|
2004-04-13 11:08:09 +00:00
|
|
|
|
2004-11-09 13:10:54 +00:00
|
|
|
#if OSL_DEBUG_LEVEL > 1
|
|
|
|
// dump tables:
|
|
|
|
{
|
|
|
|
t_registryset allBackends;
|
2009-01-22 17:12:19 +00:00
|
|
|
dp_misc::TRACE("> [dp_registry.cxx] media-type detection:\n\n" );
|
2004-11-09 13:10:54 +00:00
|
|
|
for ( t_string2string::const_iterator iPos(
|
|
|
|
that->m_filter2mediaType.begin() );
|
|
|
|
iPos != that->m_filter2mediaType.end(); ++iPos )
|
|
|
|
{
|
|
|
|
::rtl::OUStringBuffer buf;
|
|
|
|
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("extension \"") );
|
|
|
|
buf.append( iPos->first );
|
|
|
|
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(
|
|
|
|
"\" maps to media-type \"") );
|
|
|
|
buf.append( iPos->second );
|
|
|
|
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(
|
|
|
|
"\" maps to backend ") );
|
|
|
|
const Reference<deployment::XPackageRegistry> xBackend(
|
|
|
|
that->m_mediaType2backend.find( iPos->second )->second );
|
|
|
|
allBackends.insert( xBackend );
|
|
|
|
buf.append( Reference<lang::XServiceInfo>(
|
|
|
|
xBackend, UNO_QUERY_THROW )
|
|
|
|
->getImplementationName() );
|
2009-01-22 17:12:19 +00:00
|
|
|
dp_misc::writeConsole( buf.makeStringAndClear() + OUSTR("\n"));
|
2004-11-09 13:10:54 +00:00
|
|
|
}
|
2009-01-22 17:12:19 +00:00
|
|
|
dp_misc::TRACE( "> [dp_registry.cxx] ambiguous backends:\n\n" );
|
2004-11-09 13:10:54 +00:00
|
|
|
for ( t_registryset::const_iterator iPos(
|
|
|
|
that->m_ambiguousBackends.begin() );
|
|
|
|
iPos != that->m_ambiguousBackends.end(); ++iPos )
|
|
|
|
{
|
|
|
|
::rtl::OUStringBuffer buf;
|
|
|
|
buf.append(
|
|
|
|
Reference<lang::XServiceInfo>(
|
|
|
|
*iPos, UNO_QUERY_THROW )->getImplementationName() );
|
|
|
|
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(": ") );
|
|
|
|
const Sequence< Reference<deployment::XPackageTypeInfo> > types(
|
|
|
|
(*iPos)->getSupportedPackageTypes() );
|
|
|
|
for ( sal_Int32 pos = 0; pos < types.getLength(); ++pos ) {
|
|
|
|
Reference<deployment::XPackageTypeInfo> const & xInfo =
|
|
|
|
types[ pos ];
|
|
|
|
buf.append( xInfo->getMediaType() );
|
|
|
|
const OUString filter( xInfo->getFileFilter() );
|
|
|
|
if (filter.getLength() > 0) {
|
|
|
|
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" (") );
|
|
|
|
buf.append( filter );
|
|
|
|
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(")") );
|
|
|
|
}
|
|
|
|
if (pos < (types.getLength() - 1))
|
|
|
|
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(", ") );
|
|
|
|
}
|
2009-01-22 17:12:19 +00:00
|
|
|
dp_misc::TRACE(buf.makeStringAndClear() + OUSTR("\n\n"));
|
2004-11-09 13:10:54 +00:00
|
|
|
}
|
|
|
|
allBackends.insert( that->m_ambiguousBackends.begin(),
|
|
|
|
that->m_ambiguousBackends.end() );
|
|
|
|
OSL_ASSERT( allBackends == that->m_allBackends );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-08-12 11:09:56 +00:00
|
|
|
return xRet;
|
2004-04-13 11:08:09 +00:00
|
|
|
}
|
|
|
|
|
2004-11-09 13:10:54 +00:00
|
|
|
// XUpdatable: broadcast to backends
|
|
|
|
//______________________________________________________________________________
|
|
|
|
void PackageRegistryImpl::update() throw (RuntimeException)
|
|
|
|
{
|
|
|
|
check();
|
|
|
|
t_registryset::const_iterator iPos( m_allBackends.begin() );
|
|
|
|
const t_registryset::const_iterator iEnd( m_allBackends.end() );
|
|
|
|
for ( ; iPos != iEnd; ++iPos ) {
|
|
|
|
const Reference<util::XUpdatable> xUpdatable( *iPos, UNO_QUERY );
|
|
|
|
if (xUpdatable.is())
|
|
|
|
xUpdatable->update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-13 11:08:09 +00:00
|
|
|
// XPackageRegistry
|
|
|
|
//______________________________________________________________________________
|
2004-06-11 11:11:52 +00:00
|
|
|
Reference<deployment::XPackage> PackageRegistryImpl::bindPackage(
|
2010-05-04 12:37:01 +02:00
|
|
|
OUString const & url, OUString const & mediaType_, sal_Bool bNoFileAccess,
|
2004-06-11 11:11:52 +00:00
|
|
|
Reference<XCommandEnvironment> const & xCmdEnv )
|
|
|
|
throw (deployment::DeploymentException, CommandFailedException,
|
|
|
|
lang::IllegalArgumentException, RuntimeException)
|
2004-04-13 11:08:09 +00:00
|
|
|
{
|
2004-06-11 11:11:52 +00:00
|
|
|
check();
|
2004-11-09 13:10:54 +00:00
|
|
|
OUString mediaType(mediaType_);
|
|
|
|
if (mediaType.getLength() == 0)
|
|
|
|
{
|
2007-06-05 14:06:17 +00:00
|
|
|
::ucbhelper::Content ucbContent;
|
2004-11-09 13:10:54 +00:00
|
|
|
if (create_ucb_content(
|
2010-02-10 10:27:57 +01:00
|
|
|
&ucbContent, url, xCmdEnv, false /* no throw */ )
|
|
|
|
&& !ucbContent.isFolder())
|
2004-11-09 13:10:54 +00:00
|
|
|
{
|
2005-01-21 16:13:19 +00:00
|
|
|
OUString title( ucbContent.getPropertyValue(
|
|
|
|
StrTitle::get() ).get<OUString>() );
|
2004-11-09 13:10:54 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
const t_string2string::const_iterator iFind(
|
|
|
|
m_filter2mediaType.find(title) );
|
|
|
|
if (iFind != m_filter2mediaType.end()) {
|
|
|
|
mediaType = iFind->second;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sal_Int32 point = title.indexOf( '.', 1 /* consume . */ );
|
|
|
|
if (point < 0)
|
|
|
|
break;
|
|
|
|
title = title.copy(point);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-06-11 11:11:52 +00:00
|
|
|
if (mediaType.getLength() == 0)
|
2004-04-13 11:08:09 +00:00
|
|
|
{
|
2004-11-09 13:10:54 +00:00
|
|
|
// try ambiguous backends:
|
|
|
|
t_registryset::const_iterator iPos( m_ambiguousBackends.begin() );
|
|
|
|
const t_registryset::const_iterator iEnd( m_ambiguousBackends.end() );
|
2004-06-11 11:11:52 +00:00
|
|
|
for ( ; iPos != iEnd; ++iPos )
|
2004-04-13 11:08:09 +00:00
|
|
|
{
|
2004-08-12 11:09:56 +00:00
|
|
|
try {
|
2010-05-04 12:37:01 +02:00
|
|
|
return (*iPos)->bindPackage( url, mediaType, bNoFileAccess, xCmdEnv );
|
2004-06-11 11:11:52 +00:00
|
|
|
}
|
2004-08-12 11:09:56 +00:00
|
|
|
catch (lang::IllegalArgumentException &) {
|
2004-06-11 11:11:52 +00:00
|
|
|
}
|
2004-04-13 11:08:09 +00:00
|
|
|
}
|
2004-06-11 11:11:52 +00:00
|
|
|
throw lang::IllegalArgumentException(
|
|
|
|
getResourceString(RID_STR_CANNOT_DETECT_MEDIA_TYPE) + url,
|
|
|
|
static_cast<OWeakObject *>(this), static_cast<sal_Int16>(-1) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-11-09 13:10:54 +00:00
|
|
|
// get backend by media-type:
|
2004-04-13 11:08:09 +00:00
|
|
|
t_string2registry::const_iterator iFind(
|
2004-11-09 13:10:54 +00:00
|
|
|
m_mediaType2backend.find( normalizeMediaType(mediaType) ) );
|
|
|
|
if (iFind == m_mediaType2backend.end()) {
|
2004-04-13 11:08:09 +00:00
|
|
|
// xxx todo: more sophisticated media-type argument parsing...
|
|
|
|
sal_Int32 q = mediaType.indexOf( ';' );
|
2004-08-12 11:09:56 +00:00
|
|
|
if (q >= 0) {
|
2004-11-09 13:10:54 +00:00
|
|
|
iFind = m_mediaType2backend.find(
|
2004-04-13 11:08:09 +00:00
|
|
|
normalizeMediaType(
|
2004-11-09 13:10:54 +00:00
|
|
|
// cut parameters:
|
|
|
|
mediaType.copy( 0, q ) ) );
|
2004-04-13 11:08:09 +00:00
|
|
|
}
|
|
|
|
}
|
2004-11-09 13:10:54 +00:00
|
|
|
if (iFind == m_mediaType2backend.end()) {
|
2004-06-11 11:11:52 +00:00
|
|
|
throw lang::IllegalArgumentException(
|
|
|
|
getResourceString(RID_STR_UNSUPPORTED_MEDIA_TYPE) + mediaType,
|
|
|
|
static_cast<OWeakObject *>(this), static_cast<sal_Int16>(-1) );
|
2004-11-09 13:10:54 +00:00
|
|
|
}
|
2010-05-04 12:37:01 +02:00
|
|
|
return iFind->second->bindPackage( url, mediaType, bNoFileAccess, xCmdEnv );
|
2004-04-13 11:08:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//______________________________________________________________________________
|
2004-11-09 13:10:54 +00:00
|
|
|
Sequence< Reference<deployment::XPackageTypeInfo> >
|
|
|
|
PackageRegistryImpl::getSupportedPackageTypes() throw (RuntimeException)
|
2004-04-13 11:08:09 +00:00
|
|
|
{
|
2006-03-06 09:21:54 +00:00
|
|
|
return comphelper::containerToSequence(m_typesInfos);
|
2004-08-12 11:09:56 +00:00
|
|
|
}
|
|
|
|
|
2004-11-09 13:10:54 +00:00
|
|
|
} // anon namespace
|
|
|
|
|
2004-08-12 11:09:56 +00:00
|
|
|
//==============================================================================
|
|
|
|
Reference<deployment::XPackageRegistry> SAL_CALL create(
|
|
|
|
OUString const & context,
|
|
|
|
OUString const & cachePath, bool readOnly,
|
|
|
|
Reference<XComponentContext> const & xComponentContext )
|
|
|
|
{
|
|
|
|
return PackageRegistryImpl::create(
|
|
|
|
context, cachePath, readOnly, xComponentContext );
|
2004-04-13 11:08:09 +00:00
|
|
|
}
|
|
|
|
|
2004-11-09 13:10:54 +00:00
|
|
|
} // namespace dp_registry
|
2004-04-13 11:08:09 +00:00
|
|
|
|