#81540# - Added static construction methods Content::create(...).

This commit is contained in:
Kai Sommerfeld 2000-12-11 06:55:59 +00:00
parent 151be67eea
commit 0591250cb3
2 changed files with 170 additions and 6 deletions

View file

@ -2,9 +2,9 @@
*
* $RCSfile: content.hxx,v $
*
* $Revision: 1.2 $
* $Revision: 1.3 $
*
* last change: $Author: kso $ $Date: 2000-12-01 07:49:56 $
* last change: $Author: kso $ $Date: 2000-12-11 07:55:08 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@ -197,6 +197,65 @@ public:
*/
Content& operator=( const Content& rOther );
/**
* Constructor. This method should be used, if the exception thrown
* by the direct ctors of this class are to 'expensive' for your
* application
*
* @param rURL is the URL of the content to create.
* @param rEnv is the environment to use for commands executed by the
* content. The command environment is used by the content
* implementation to interact with the client and to propagate
* errors.
* @param rContent will be filled by this method with the content created.
* @return true, if the operation was successful - false, otherwise.
*/
static sal_Bool
create( const rtl::OUString& rURL,
const ::com::sun::star::uno::Reference<
::com::sun::star::ucb::XCommandEnvironment >& rEnv,
Content& rContent );
/**
* Constructor. This method should be used, if the exception thrown
* by the direct ctors of this class are to 'expensive' for your
* application
*
* @param rId is the content identifier of the content to create.
* @param rEnv is the environment to use for commands executed by the
* content. The command environment is used by the content
* implementation to interact with the client and to propagate
* errors.
* @param rContent will be filled by this method with the content created.
* @return true, if the operation was successful - false, otherwise.
*/
static sal_Bool
create( const ::com::sun::star::uno::Reference<
::com::sun::star::ucb::XContentIdentifier >& rId,
const ::com::sun::star::uno::Reference<
::com::sun::star::ucb::XCommandEnvironment >& rEnv,
Content& rContent );
/**
* Constructor. This method should be used, if the exception thrown
* by the direct ctors of this class are to 'expensive' for your
* application
*
* @param xContent is the content object of the content to create.
* @param rEnv is the environment to use for commands executed by the
* content. The command environment is used by the content
* implementation to interact with the client and to propagate
* errors.
* @param rContent will be filled by this method with the content created.
* @return true, if the operation was successful - false, otherwise.
*/
static sal_Bool
create( const ::com::sun::star::uno::Reference<
::com::sun::star::ucb::XContent >& xContent,
const ::com::sun::star::uno::Reference<
::com::sun::star::ucb::XCommandEnvironment >& rEnv,
Content& rContent );
//////////////////////////////////////////////////////////////////////
// Direct access to UCB content.
//////////////////////////////////////////////////////////////////////

View file

@ -2,9 +2,9 @@
*
* $RCSfile: content.cxx,v $
*
* $Revision: 1.8 $
* $Revision: 1.9 $
*
* last change: $Author: rt $ $Date: 2000-12-04 09:35:34 $
* last change: $Author: kso $ $Date: 2000-12-11 07:55:59 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@ -253,7 +253,7 @@ Content::Content( const OUString& rURL,
{
xContent = xProvider->queryContent( xId );
}
catch ( IllegalIdentifierException )
catch ( IllegalIdentifierException& )
{
throw ContentCreationException(
OUString::createFromAscii( "No Content!" ),
@ -299,7 +299,7 @@ Content::Content( const Reference< XContentIdentifier >& rId,
{
xContent = xProvider->queryContent( rId );
}
catch ( IllegalIdentifierException )
catch ( IllegalIdentifierException& )
{
throw ContentCreationException(
OUString::createFromAscii( "No Content!" ),
@ -341,6 +341,111 @@ Content::Content( const Content& rOther )
m_xImpl = rOther.m_xImpl;
}
//=========================================================================
// static
sal_Bool Content::create( const OUString& rURL,
const Reference< XCommandEnvironment >& rEnv,
Content& rContent )
{
ucb::ContentBroker* pBroker = ucb::ContentBroker::get();
if ( !pBroker )
return sal_False;
VOS_ENSURE( pBroker->getContentProviderManagerInterface()
->queryContentProviders().getLength(),
"Content Broker not configured (no providers)!" );
Reference< XContentIdentifierFactory > xIdFac
= pBroker->getContentIdentifierFactoryInterface();
if ( !xIdFac.is() )
return sal_False;
Reference< XContentIdentifier > xId
= xIdFac->createContentIdentifier( rURL );
if ( !xId.is() )
return sal_False;
Reference< XContentProvider > xProvider
= pBroker->getContentProviderInterface();
if ( !xProvider.is() )
return sal_False;
Reference< XContent > xContent;
try
{
xContent = xProvider->queryContent( xId );
}
// catch ( IllegalIdentifierException& )
catch ( Exception& )
{
return sal_False;
}
if ( !xContent.is() )
return sal_False;
rContent.m_xImpl
= new Content_Impl( pBroker->getServiceManager(), xContent, rEnv );
return sal_True;
}
//=========================================================================
// static
sal_Bool Content::create( const Reference< XContentIdentifier >& rId,
const Reference< XCommandEnvironment >& rEnv,
Content& rContent )
{
ucb::ContentBroker* pBroker = ucb::ContentBroker::get();
if ( !pBroker )
return sal_False;
VOS_ENSURE( pBroker->getContentProviderManagerInterface()
->queryContentProviders().getLength(),
"Content Broker not configured (no providers)!" );
Reference< XContentProvider > xProvider
= pBroker->getContentProviderInterface();
if ( !xProvider.is() )
return sal_False;
Reference< XContent > xContent;
try
{
xContent = xProvider->queryContent( rId );
}
// catch ( IllegalIdentifierException& )
catch ( Exception& )
{
return sal_False;
}
if ( !xContent.is() )
return sal_False;
rContent.m_xImpl
= new Content_Impl( pBroker->getServiceManager(), xContent, rEnv );
return sal_True;
}
//=========================================================================
// static
sal_Bool Content::create( const Reference< XContent >& xContent,
const Reference< XCommandEnvironment >& rEnv,
Content& rContent )
{
ucb::ContentBroker* pBroker = ucb::ContentBroker::get();
if ( !pBroker )
return sal_False;
VOS_ENSURE( pBroker->getContentProviderManagerInterface()
->queryContentProviders().getLength(),
"Content Broker not configured (no providers)!" );
rContent.m_xImpl
= new Content_Impl( pBroker->getServiceManager(), xContent, rEnv );
return sal_True;
}
//=========================================================================
Content::~Content()
{