2000-11-17 13:41:33 +00:00
|
|
|
/*************************************************************************
|
|
|
|
|
*
|
2005-09-09 14:56:23 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-11-17 13:41:33 +00:00
|
|
|
*
|
2005-09-09 14:56:23 +00:00
|
|
|
* $RCSfile: pkgprovider.cxx,v $
|
2000-11-17 13:41:33 +00:00
|
|
|
*
|
2006-09-17 13:00:01 +00:00
|
|
|
* $Revision: 1.19 $
|
2000-11-17 13:41:33 +00:00
|
|
|
*
|
2006-09-17 13:00:01 +00:00
|
|
|
* last change: $Author: obo $ $Date: 2006-09-17 14:00:01 $
|
2000-11-17 13:41:33 +00:00
|
|
|
*
|
2005-09-09 14:56:23 +00:00
|
|
|
* The Contents of this file are made available subject to
|
|
|
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
2000-11-17 13:41:33 +00:00
|
|
|
*
|
|
|
|
|
*
|
2005-09-09 14:56:23 +00:00
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
|
* =============================================
|
|
|
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
2000-11-17 13:41:33 +00:00
|
|
|
*
|
2005-09-09 14:56:23 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
2000-11-17 13:41:33 +00:00
|
|
|
*
|
2005-09-09 14:56:23 +00:00
|
|
|
* This library 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 for more details.
|
2000-11-17 13:41:33 +00:00
|
|
|
*
|
2005-09-09 14:56:23 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
|
* MA 02111-1307 USA
|
2000-11-17 13:41:33 +00:00
|
|
|
*
|
|
|
|
|
************************************************************************/
|
|
|
|
|
|
2006-09-17 13:00:01 +00:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
|
#include "precompiled_ucb.hxx"
|
|
|
|
|
|
2000-11-17 13:41:33 +00:00
|
|
|
/**************************************************************************
|
|
|
|
|
TODO
|
|
|
|
|
**************************************************************************
|
|
|
|
|
|
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
2000-11-29 13:16:26 +00:00
|
|
|
#include <hash_map>
|
|
|
|
|
|
2001-07-26 11:42:28 +00:00
|
|
|
#ifndef _OSL_DIAGNOSE_H_
|
|
|
|
|
#include <osl/diagnose.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2000-11-29 13:16:26 +00:00
|
|
|
#ifndef _CPPUHELPER_WEAK_HXX_
|
|
|
|
|
#include <cppuhelper/weak.hxx>
|
|
|
|
|
#endif
|
2001-07-26 11:42:28 +00:00
|
|
|
|
2000-11-17 13:41:33 +00:00
|
|
|
#ifndef _UCBHELPER_CONTENTIDENTIFIER_HXX
|
|
|
|
|
#include <ucbhelper/contentidentifier.hxx>
|
|
|
|
|
#endif
|
2000-11-29 13:16:26 +00:00
|
|
|
#ifndef _COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMEACCESS_HPP_
|
|
|
|
|
#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
|
|
|
|
|
#endif
|
2000-11-17 13:41:33 +00:00
|
|
|
|
|
|
|
|
#ifndef _PKGPROVIDER_HXX
|
|
|
|
|
#include "pkgprovider.hxx"
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef _PKGCONTENT_HXX
|
|
|
|
|
#include "pkgcontent.hxx"
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef _PKGURI_HXX
|
|
|
|
|
#include "pkguri.hxx"
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-07-26 11:42:28 +00:00
|
|
|
using namespace com::sun;
|
|
|
|
|
using namespace com::sun::star;
|
2000-11-17 13:41:33 +00:00
|
|
|
|
2000-11-29 13:16:26 +00:00
|
|
|
namespace package_ucp
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
|
//
|
|
|
|
|
// class Package.
|
|
|
|
|
//
|
|
|
|
|
//=========================================================================
|
|
|
|
|
|
|
|
|
|
class Package : public cppu::OWeakObject,
|
|
|
|
|
public com::sun::star::container::XHierarchicalNameAccess
|
|
|
|
|
{
|
|
|
|
|
friend class ContentProvider;
|
|
|
|
|
|
2001-07-26 11:42:28 +00:00
|
|
|
rtl::OUString m_aName;
|
|
|
|
|
uno::Reference< container::XHierarchicalNameAccess > m_xNA;
|
|
|
|
|
ContentProvider* m_pOwner;
|
2000-11-29 13:16:26 +00:00
|
|
|
|
|
|
|
|
public:
|
2001-07-26 11:42:28 +00:00
|
|
|
Package( const rtl::OUString& rName,
|
|
|
|
|
const uno::Reference< container::XHierarchicalNameAccess > & xNA,
|
2000-11-29 13:16:26 +00:00
|
|
|
ContentProvider* pOwner )
|
|
|
|
|
: m_aName( rName ), m_xNA( xNA ), m_pOwner( pOwner ) {}
|
2000-12-01 09:42:10 +00:00
|
|
|
virtual ~Package() { m_pOwner->removePackage( m_aName ); }
|
2000-11-29 13:16:26 +00:00
|
|
|
|
|
|
|
|
// XInterface
|
2001-07-26 11:42:28 +00:00
|
|
|
virtual uno::Any SAL_CALL
|
|
|
|
|
queryInterface( const uno::Type& aType )
|
|
|
|
|
throw( uno::RuntimeException )
|
2000-11-29 13:41:57 +00:00
|
|
|
{ return m_xNA->queryInterface( aType ); }
|
|
|
|
|
virtual void SAL_CALL
|
|
|
|
|
acquire() throw()
|
|
|
|
|
{ OWeakObject::acquire(); }
|
|
|
|
|
virtual void SAL_CALL
|
|
|
|
|
release() throw()
|
|
|
|
|
{ OWeakObject::release(); }
|
|
|
|
|
|
|
|
|
|
// XHierarchicalNameAccess
|
2001-07-26 11:42:28 +00:00
|
|
|
virtual uno::Any SAL_CALL
|
|
|
|
|
getByHierarchicalName( const rtl::OUString& aName )
|
|
|
|
|
throw( container::NoSuchElementException, uno::RuntimeException )
|
2000-11-29 13:16:26 +00:00
|
|
|
{ return m_xNA->getByHierarchicalName( aName ); }
|
|
|
|
|
virtual sal_Bool SAL_CALL
|
2001-07-26 11:42:28 +00:00
|
|
|
hasByHierarchicalName( const rtl::OUString& aName )
|
|
|
|
|
throw( uno::RuntimeException )
|
2000-11-29 13:16:26 +00:00
|
|
|
{ return m_xNA->hasByHierarchicalName( aName ); }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
|
//
|
|
|
|
|
// Packages.
|
|
|
|
|
//
|
|
|
|
|
//=========================================================================
|
|
|
|
|
|
|
|
|
|
struct equalString
|
|
|
|
|
{
|
2001-07-26 11:42:28 +00:00
|
|
|
bool operator()(
|
|
|
|
|
const rtl::OUString& rKey1, const rtl::OUString& rKey2 ) const
|
2001-05-11 08:15:05 +00:00
|
|
|
{
|
|
|
|
|
return !!( rKey1 == rKey2 );
|
|
|
|
|
}
|
2000-11-29 13:16:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct hashString
|
|
|
|
|
{
|
2001-07-26 11:42:28 +00:00
|
|
|
size_t operator()( const rtl::OUString & rName ) const
|
2000-11-29 13:16:26 +00:00
|
|
|
{
|
|
|
|
|
return rName.hashCode();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef std::hash_map
|
|
|
|
|
<
|
2001-07-26 11:42:28 +00:00
|
|
|
rtl::OUString,
|
2000-11-29 13:16:26 +00:00
|
|
|
Package*,
|
|
|
|
|
hashString,
|
|
|
|
|
equalString
|
|
|
|
|
>
|
|
|
|
|
PackageMap;
|
|
|
|
|
|
|
|
|
|
class Packages : public PackageMap {};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2000-11-17 13:41:33 +00:00
|
|
|
using namespace package_ucp;
|
|
|
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
|
//=========================================================================
|
|
|
|
|
//
|
|
|
|
|
// ContentProvider Implementation.
|
|
|
|
|
//
|
|
|
|
|
//=========================================================================
|
|
|
|
|
//=========================================================================
|
|
|
|
|
|
|
|
|
|
ContentProvider::ContentProvider(
|
2001-07-26 11:42:28 +00:00
|
|
|
const uno::Reference< lang::XMultiServiceFactory >& rSMgr )
|
2000-11-29 13:16:26 +00:00
|
|
|
: ::ucb::ContentProviderImplHelper( rSMgr ),
|
|
|
|
|
m_pPackages( 0 )
|
2000-11-17 13:41:33 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
|
// virtual
|
|
|
|
|
ContentProvider::~ContentProvider()
|
|
|
|
|
{
|
2000-11-29 13:16:26 +00:00
|
|
|
delete m_pPackages;
|
2000-11-17 13:41:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
|
//
|
|
|
|
|
// XInterface methods.
|
|
|
|
|
//
|
|
|
|
|
//=========================================================================
|
|
|
|
|
|
|
|
|
|
XINTERFACE_IMPL_3( ContentProvider,
|
2001-07-26 11:42:28 +00:00
|
|
|
lang::XTypeProvider,
|
|
|
|
|
lang::XServiceInfo,
|
|
|
|
|
star::ucb::XContentProvider );
|
2000-11-17 13:41:33 +00:00
|
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
|
//
|
|
|
|
|
// XTypeProvider methods.
|
|
|
|
|
//
|
|
|
|
|
//=========================================================================
|
|
|
|
|
|
|
|
|
|
XTYPEPROVIDER_IMPL_3( ContentProvider,
|
2001-07-26 11:42:28 +00:00
|
|
|
lang::XTypeProvider,
|
|
|
|
|
lang::XServiceInfo,
|
|
|
|
|
star::ucb::XContentProvider );
|
2000-11-17 13:41:33 +00:00
|
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
|
//
|
|
|
|
|
// XServiceInfo methods.
|
|
|
|
|
//
|
|
|
|
|
//=========================================================================
|
|
|
|
|
|
|
|
|
|
XSERVICEINFO_IMPL_1( ContentProvider,
|
2001-07-26 11:42:28 +00:00
|
|
|
rtl::OUString::createFromAscii(
|
2001-05-11 08:15:05 +00:00
|
|
|
"com.sun.star.comp.ucb.PackageContentProvider" ),
|
2001-07-26 11:42:28 +00:00
|
|
|
rtl::OUString::createFromAscii(
|
2001-05-11 08:15:05 +00:00
|
|
|
PACKAGE_CONTENT_PROVIDER_SERVICE_NAME ) );
|
2000-11-17 13:41:33 +00:00
|
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
|
//
|
|
|
|
|
// Service factory implementation.
|
|
|
|
|
//
|
|
|
|
|
//=========================================================================
|
|
|
|
|
|
|
|
|
|
ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider );
|
|
|
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
|
//
|
|
|
|
|
// XContentProvider methods.
|
|
|
|
|
//
|
|
|
|
|
//=========================================================================
|
|
|
|
|
|
|
|
|
|
// virtual
|
2001-07-26 11:42:28 +00:00
|
|
|
uno::Reference< star::ucb::XContent > SAL_CALL ContentProvider::queryContent(
|
|
|
|
|
const uno::Reference< star::ucb::XContentIdentifier >& Identifier )
|
|
|
|
|
throw( star::ucb::IllegalIdentifierException, uno::RuntimeException )
|
2000-11-17 13:41:33 +00:00
|
|
|
{
|
2001-07-26 11:42:28 +00:00
|
|
|
if ( !Identifier.is() )
|
|
|
|
|
return uno::Reference< star::ucb::XContent >();
|
2001-06-27 07:21:24 +00:00
|
|
|
|
2001-07-06 07:11:17 +00:00
|
|
|
PackageUri aUri( Identifier->getContentIdentifier() );
|
2001-07-26 11:42:28 +00:00
|
|
|
if ( !aUri.isValid() )
|
|
|
|
|
throw star::ucb::IllegalIdentifierException();
|
|
|
|
|
|
|
|
|
|
// Create a new identifier for the mormalized URL returned by
|
|
|
|
|
// PackageUri::getUri().
|
|
|
|
|
uno::Reference< star::ucb::XContentIdentifier > xId
|
2000-11-27 12:05:27 +00:00
|
|
|
= new ::ucb::ContentIdentifier( m_xSMgr, aUri.getUri() );
|
2000-11-17 13:41:33 +00:00
|
|
|
|
2001-07-12 14:05:58 +00:00
|
|
|
vos::OGuard aGuard( m_aMutex );
|
|
|
|
|
|
2000-11-17 13:41:33 +00:00
|
|
|
// Check, if a content with given id already exists...
|
2001-07-26 11:42:28 +00:00
|
|
|
uno::Reference< star::ucb::XContent > xContent
|
|
|
|
|
= queryExistingContent( xId ).getBodyPtr();
|
2000-11-17 13:41:33 +00:00
|
|
|
if ( xContent.is() )
|
|
|
|
|
return xContent;
|
|
|
|
|
|
|
|
|
|
// Create a new content. Note that the content will insert itself
|
|
|
|
|
// into providers content list by calling addContent(...) from it's ctor.
|
|
|
|
|
|
|
|
|
|
xContent = Content::create( m_xSMgr, this, Identifier ); // not xId!!!
|
|
|
|
|
|
|
|
|
|
if ( xContent.is() && !xContent->getIdentifier().is() )
|
2001-07-26 11:42:28 +00:00
|
|
|
throw star::ucb::IllegalIdentifierException();
|
2000-11-17 13:41:33 +00:00
|
|
|
|
|
|
|
|
return xContent;
|
|
|
|
|
}
|
|
|
|
|
|
2000-11-29 13:16:26 +00:00
|
|
|
//=========================================================================
|
|
|
|
|
//
|
|
|
|
|
// Other methods.
|
|
|
|
|
//
|
|
|
|
|
//=========================================================================
|
|
|
|
|
|
2001-07-26 11:42:28 +00:00
|
|
|
uno::Reference< container::XHierarchicalNameAccess >
|
2003-03-27 16:27:21 +00:00
|
|
|
ContentProvider::createPackage( const rtl::OUString & rName, const rtl::OUString & rParam )
|
2000-11-29 13:16:26 +00:00
|
|
|
{
|
|
|
|
|
vos::OGuard aGuard( m_aMutex );
|
|
|
|
|
|
|
|
|
|
if ( !rName.getLength() )
|
|
|
|
|
{
|
2001-07-26 11:42:28 +00:00
|
|
|
OSL_ENSURE( sal_False,
|
2000-11-29 13:16:26 +00:00
|
|
|
"ContentProvider::createPackage - Invalid URL!" );
|
2001-07-26 11:42:28 +00:00
|
|
|
return uno::Reference< container::XHierarchicalNameAccess >();
|
2000-11-29 13:16:26 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-27 16:27:21 +00:00
|
|
|
rtl::OUString rURL = rName + rParam;
|
|
|
|
|
|
2000-11-29 13:16:26 +00:00
|
|
|
if ( m_pPackages )
|
|
|
|
|
{
|
2003-03-27 16:27:21 +00:00
|
|
|
Packages::const_iterator it = m_pPackages->find( rURL );
|
2000-11-29 13:16:26 +00:00
|
|
|
if ( it != m_pPackages->end() )
|
|
|
|
|
{
|
|
|
|
|
// Already instanciated. Return package.
|
|
|
|
|
return (*it).second->m_xNA;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
m_pPackages = new Packages;
|
|
|
|
|
|
|
|
|
|
// Create new package...
|
|
|
|
|
try
|
|
|
|
|
{
|
2001-07-26 11:42:28 +00:00
|
|
|
uno::Sequence< uno::Any > aArguments( 1 );
|
2003-03-27 16:27:21 +00:00
|
|
|
aArguments[ 0 ] <<= rURL;
|
2000-11-29 13:16:26 +00:00
|
|
|
|
2001-07-26 11:42:28 +00:00
|
|
|
uno::Reference< uno::XInterface > xIfc
|
2000-11-29 13:16:26 +00:00
|
|
|
= m_xSMgr->createInstanceWithArguments(
|
2001-07-26 11:42:28 +00:00
|
|
|
rtl::OUString::createFromAscii(
|
2001-03-19 07:37:07 +00:00
|
|
|
"com.sun.star.packages.comp.ZipPackage" ),
|
2000-11-29 13:16:26 +00:00
|
|
|
aArguments );
|
|
|
|
|
|
|
|
|
|
if ( xIfc.is() )
|
|
|
|
|
{
|
2001-07-26 11:42:28 +00:00
|
|
|
uno::Reference<
|
|
|
|
|
container::XHierarchicalNameAccess > xNameAccess(
|
|
|
|
|
xIfc, uno::UNO_QUERY );
|
2000-11-29 13:16:26 +00:00
|
|
|
|
2001-07-26 11:42:28 +00:00
|
|
|
OSL_ENSURE( xNameAccess.is(),
|
2000-11-29 13:16:26 +00:00
|
|
|
"ContentProvider::createPackage - "
|
|
|
|
|
"Got no hierarchical name access!" );
|
|
|
|
|
|
2001-07-26 11:42:28 +00:00
|
|
|
rtl::Reference< Package> xPackage
|
2003-03-27 16:27:21 +00:00
|
|
|
= new Package( rURL, xNameAccess, this );
|
2000-11-29 13:16:26 +00:00
|
|
|
|
2003-03-27 16:27:21 +00:00
|
|
|
(*m_pPackages)[ rURL ] = xPackage.get();
|
2000-11-29 13:16:26 +00:00
|
|
|
|
2001-07-26 11:42:28 +00:00
|
|
|
return xPackage.get();
|
2000-11-29 13:16:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
2001-07-26 11:42:28 +00:00
|
|
|
catch ( uno::RuntimeException const & )
|
2000-11-29 13:16:26 +00:00
|
|
|
{
|
|
|
|
|
// createInstanceWithArguemts
|
|
|
|
|
}
|
2001-07-26 11:42:28 +00:00
|
|
|
catch ( uno::Exception const & )
|
2000-11-29 13:16:26 +00:00
|
|
|
{
|
|
|
|
|
// createInstanceWithArguemts
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-26 11:42:28 +00:00
|
|
|
return uno::Reference< container::XHierarchicalNameAccess >();
|
2000-11-29 13:16:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//=========================================================================
|
2001-07-26 11:42:28 +00:00
|
|
|
sal_Bool ContentProvider::removePackage( const rtl::OUString & rName )
|
2000-11-29 13:16:26 +00:00
|
|
|
{
|
|
|
|
|
vos::OGuard aGuard( m_aMutex );
|
|
|
|
|
|
|
|
|
|
if ( m_pPackages )
|
|
|
|
|
{
|
|
|
|
|
Packages::iterator it = m_pPackages->find( rName );
|
|
|
|
|
if ( it != m_pPackages->end() )
|
|
|
|
|
{
|
|
|
|
|
m_pPackages->erase( it );
|
|
|
|
|
return sal_True;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return sal_False;
|
|
|
|
|
}
|
|
|
|
|
|