Kaydet (Commit) 00ab8bca authored tarafından Kurt Zenker's avatar Kurt Zenker

INTEGRATION: CWS mav09 (1.7.2); FILE MERGED

2004/09/28 09:50:29 mav 1.7.2.23: #i27773# resync
2004/09/16 22:01:32 mav 1.7.2.22: RESYNC: (1.8-1.9); FILE MERGED
2004/09/13 13:39:55 mav 1.7.2.21: #i27773# do not allow typedetection to provide stream and mode
2004/09/02 14:58:20 mba 1.7.2.20: #i27773#: prepare to use DocumentBasedStorage
2004/08/17 13:58:16 mav 1.7.2.19: #i27773# BaseURL and Hierarchical object name
2004/08/17 10:09:30 mav 1.7.2.18: #i27773# slight changes
2004/08/16 09:33:31 mav 1.7.2.17: #i27773# storage format
2004/07/15 10:32:09 mav 1.7.2.16: #i27773# commit changes made offline
2004/07/01 11:48:18 mav 1.7.2.15: #i27773# links storing on deactivation
2004/06/25 11:49:11 mav 1.7.2.14: #i27773# linkage support
2004/06/24 17:13:42 mav 1.7.2.13: #i27773# reactivate linking support for OOo documents
2004/06/18 16:14:26 mav 1.7.2.12: #i27773# embedded document should not be modified if it's persistance is up to date
2004/06/18 14:18:11 mba 1.7.2.11: #i27773#: special objects implementation
2004/06/10 16:19:49 mav 1.7.2.10: #i27773# use configuration for conversion purposes
2004/05/18 12:34:41 mav 1.7.2.9: #i27773# solve resync problems
2004/05/17 18:24:28 mav 1.7.2.8: RESYNC: (1.7-1.8); FILE MERGED
2004/05/17 08:40:56 mav 1.7.2.7: #i27773# allow to storeAs/storeTo object even in loaded state
2004/05/12 15:47:25 mav 1.7.2.6: #i27773# allow to use setPersistentEntry in saveCompleted mode
2004/05/12 10:12:28 mav 1.7.2.5: #i27773# graphical replacement and persistance setting related changes
2004/05/06 16:46:36 mba 1.7.2.4: #i27773#: some bugfixes in first testing
2004/05/05 13:54:43 mba 1.7.2.3: #i27773#: typo
2004/02/23 10:02:39 mav 1.7.2.2: #115011# let object document be embedded
2004/02/19 10:31:36 mav 1.7.2.1: #115011# embedded object representation
üst e4401ac1
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: persistence.cxx,v $ * $RCSfile: persistence.cxx,v $
* *
* $Revision: 1.9 $ * $Revision: 1.10 $
* *
* last change: $Author: hr $ $Date: 2004-08-02 17:44:17 $ * last change: $Author: kz $ $Date: 2004-10-04 19:49:49 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -61,6 +61,9 @@ ...@@ -61,6 +61,9 @@
#include <commonembobj.hxx> #include <commonembobj.hxx>
#ifndef _COM_SUN_STAR_DOCUMENT_XSTORAGEBASEDDOCUMENT_HPP_
#include <com/sun/star/document/XStorageBasedDocument.hpp>
#endif
#ifndef _COM_SUN_STAR_EMBED_EMBEDSTATES_HPP_ #ifndef _COM_SUN_STAR_EMBED_EMBEDSTATES_HPP_
#include <com/sun/star/embed/EmbedStates.hpp> #include <com/sun/star/embed/EmbedStates.hpp>
#endif #endif
...@@ -119,13 +122,17 @@ ...@@ -119,13 +122,17 @@
#include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/XPropertySet.hpp>
#endif #endif
#include <comphelper/fileformat.h>
#include <comphelper/storagehelper.hxx>
#include "convert.hxx" #include "convert.hxx"
using namespace ::com::sun::star; using namespace ::com::sun::star;
//------------------------------------------------------ //------------------------------------------------------
uno::Sequence< beans::PropertyValue > GetValuableArgs_Impl( const uno::Sequence< beans::PropertyValue >& aMedDescr ) uno::Sequence< beans::PropertyValue > GetValuableArgs_Impl( const uno::Sequence< beans::PropertyValue >& aMedDescr,
sal_Bool bCanUseDocumentBaseURL )
{ {
uno::Sequence< beans::PropertyValue > aResult; uno::Sequence< beans::PropertyValue > aResult;
sal_Int32 nResLen = 0; sal_Int32 nResLen = 0;
...@@ -145,7 +152,8 @@ uno::Sequence< beans::PropertyValue > GetValuableArgs_Impl( const uno::Sequence< ...@@ -145,7 +152,8 @@ uno::Sequence< beans::PropertyValue > GetValuableArgs_Impl( const uno::Sequence<
|| aMedDescr[nInd].Name.equalsAscii( "ViewData" ) || aMedDescr[nInd].Name.equalsAscii( "ViewData" )
|| aMedDescr[nInd].Name.equalsAscii( "ViewId" ) || aMedDescr[nInd].Name.equalsAscii( "ViewId" )
|| aMedDescr[nInd].Name.equalsAscii( "MacroExecutionMode" ) || aMedDescr[nInd].Name.equalsAscii( "MacroExecutionMode" )
|| aMedDescr[nInd].Name.equalsAscii( "UpdateDocMode" ) ) || aMedDescr[nInd].Name.equalsAscii( "UpdateDocMode" )
|| aMedDescr[nInd].Name.equalsAscii( "DocumentBaseURL" ) && bCanUseDocumentBaseURL )
{ {
aResult.realloc( ++nResLen ); aResult.realloc( ++nResLen );
aResult[nResLen-1] = aMedDescr[nInd]; aResult[nResLen-1] = aMedDescr[nInd];
...@@ -248,30 +256,58 @@ uno::Reference< io::XInputStream > createTempInpStreamFromStor( ...@@ -248,30 +256,58 @@ uno::Reference< io::XInputStream > createTempInpStreamFromStor(
} }
//------------------------------------------------------
static void SetDocToEmbedded( const uno::Reference< frame::XModel > xDocument )
{
if ( xDocument.is() )
{
uno::Sequence< beans::PropertyValue > aSeq( 1 );
aSeq[0].Name = ::rtl::OUString::createFromAscii( "SetEmbedded" );
aSeq[0].Value <<= sal_True;
xDocument->attachResource( ::rtl::OUString(), aSeq );
}
}
//------------------------------------------------------ //------------------------------------------------------
void OCommonEmbeddedObject::SwitchOwnPersistence( const uno::Reference< embed::XStorage >& xNewParentStorage, void OCommonEmbeddedObject::SwitchOwnPersistence( const uno::Reference< embed::XStorage >& xNewParentStorage,
const uno::Reference< embed::XStorage >& xNewObjectStorage, const uno::Reference< embed::XStorage >& xNewObjectStorage,
const ::rtl::OUString& aNewName ) const ::rtl::OUString& aNewName )
{ {
if ( xNewParentStorage == m_xParentStorage && aNewName.equals( m_aEntryName ) )
{
OSL_ENSURE( xNewObjectStorage == m_xObjectStorage, "The storage must be the same!\n" );
return;
}
uno::Reference< lang::XComponent > xComponent( m_xObjectStorage, uno::UNO_QUERY );
OSL_ENSURE( !m_xObjectStorage.is() || xComponent.is(), "Wrong storage implementation!" );
m_xObjectStorage = xNewObjectStorage;
m_xParentStorage = xNewParentStorage;
m_aEntryName = aNewName;
#ifdef USE_STORAGEBASED_DOCUMENT
uno::Reference< document::XStorageBasedDocument > xDoc( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
if ( xDoc.is() )
xDoc->switchToStorage( m_xObjectStorage );
#endif
try { try {
uno::Reference< lang::XComponent > xComponent( m_xObjectStorage, uno::UNO_QUERY );
OSL_ENSURE( !m_xObjectStorage.is() || xComponent.is(), "Wrong storage implementation!" );
if ( xComponent.is() ) if ( xComponent.is() )
xComponent->dispose(); xComponent->dispose();
} }
catch ( uno::Exception& ) catch ( uno::Exception& )
{ {
} }
m_xObjectStorage = xNewObjectStorage;
m_xParentStorage = xNewParentStorage;
m_aEntryName = aNewName;
} }
//------------------------------------------------------ //------------------------------------------------------
void OCommonEmbeddedObject::SwitchOwnPersistence( const uno::Reference< embed::XStorage >& xNewParentStorage, void OCommonEmbeddedObject::SwitchOwnPersistence( const uno::Reference< embed::XStorage >& xNewParentStorage,
const ::rtl::OUString& aNewName ) const ::rtl::OUString& aNewName )
{ {
if ( xNewParentStorage == m_xParentStorage && aNewName.equals( m_aEntryName ) )
return;
sal_Int32 nStorageMode = m_bReadOnly ? embed::ElementModes::READ : embed::ElementModes::READWRITE; sal_Int32 nStorageMode = m_bReadOnly ? embed::ElementModes::READ : embed::ElementModes::READWRITE;
uno::Reference< embed::XStorage > xNewOwnStorage = xNewParentStorage->openStorageElement( aNewName, nStorageMode ); uno::Reference< embed::XStorage > xNewOwnStorage = xNewParentStorage->openStorageElement( aNewName, nStorageMode );
...@@ -281,19 +317,24 @@ void OCommonEmbeddedObject::SwitchOwnPersistence( const uno::Reference< embed::X ...@@ -281,19 +317,24 @@ void OCommonEmbeddedObject::SwitchOwnPersistence( const uno::Reference< embed::X
} }
//------------------------------------------------------ //------------------------------------------------------
uno::Reference< frame::XModel > OCommonEmbeddedObject::InitNewDocument_Impl() uno::Reference< util::XCloseable > OCommonEmbeddedObject::InitNewDocument_Impl()
{ {
uno::Reference< frame::XModel > xDocument( m_xFactory->createInstance( GetDocumentServiceName() ), uno::Reference< util::XCloseable > xDocument( m_xFactory->createInstance( GetDocumentServiceName() ),
uno::UNO_QUERY ); uno::UNO_QUERY );
uno::Reference< frame::XLoadable > xLoadable( xDocument, uno::UNO_QUERY ); uno::Reference< frame::XModel > xModel( xDocument, uno::UNO_QUERY );
uno::Reference< frame::XLoadable > xLoadable( xModel, uno::UNO_QUERY );
if ( !xLoadable.is() ) if ( !xLoadable.is() )
throw uno::RuntimeException(); throw uno::RuntimeException();
try try
{ {
// set the document mode to embedded
SetDocToEmbedded( xModel );
// init document as a new
xLoadable->initNew(); xLoadable->initNew();
xDocument->attachResource( xDocument->getURL(),m_aDocMediaDescriptor); xModel->attachResource( xModel->getURL(),m_aDocMediaDescriptor);
} }
catch( uno::Exception& ) catch( uno::Exception& )
{ {
...@@ -316,9 +357,9 @@ uno::Reference< frame::XModel > OCommonEmbeddedObject::InitNewDocument_Impl() ...@@ -316,9 +357,9 @@ uno::Reference< frame::XModel > OCommonEmbeddedObject::InitNewDocument_Impl()
} }
//------------------------------------------------------ //------------------------------------------------------
uno::Reference< frame::XModel > OCommonEmbeddedObject::LoadLink_Impl() uno::Reference< util::XCloseable > OCommonEmbeddedObject::LoadLink_Impl()
{ {
uno::Reference< frame::XModel > xDocument( m_xFactory->createInstance( GetDocumentServiceName() ), uno::Reference< util::XCloseable > xDocument( m_xFactory->createInstance( GetDocumentServiceName() ),
uno::UNO_QUERY ); uno::UNO_QUERY );
uno::Reference< frame::XLoadable > xLoadable( xDocument, uno::UNO_QUERY ); uno::Reference< frame::XLoadable > xLoadable( xDocument, uno::UNO_QUERY );
...@@ -333,6 +374,10 @@ uno::Reference< frame::XModel > OCommonEmbeddedObject::LoadLink_Impl() ...@@ -333,6 +374,10 @@ uno::Reference< frame::XModel > OCommonEmbeddedObject::LoadLink_Impl()
try try
{ {
// the document is not really an embedded one, it is a link
SetDocToEmbedded( uno::Reference < frame::XModel >( xDocument, uno::UNO_QUERY ) );
// load the document
xLoadable->load( aArgs ); xLoadable->load( aArgs );
} }
catch( uno::Exception& ) catch( uno::Exception& )
...@@ -357,63 +402,88 @@ uno::Reference< frame::XModel > OCommonEmbeddedObject::LoadLink_Impl() ...@@ -357,63 +402,88 @@ uno::Reference< frame::XModel > OCommonEmbeddedObject::LoadLink_Impl()
} }
//------------------------------------------------------ //------------------------------------------------------
uno::Reference< frame::XModel > OCommonEmbeddedObject::LoadDocumentFromStorage_Impl( uno::Reference< util::XCloseable > OCommonEmbeddedObject::LoadDocumentFromStorage_Impl(
const uno::Reference< embed::XStorage >& xStorage ) const uno::Reference< embed::XStorage >& xStorage )
{ {
OSL_ENSURE( xStorage.is(), "The storage can not be empty!" ); OSL_ENSURE( xStorage.is(), "The storage can not be empty!" );
uno::Reference< frame::XModel > xDocument( m_xFactory->createInstance( GetDocumentServiceName() ), uno::Reference< util::XCloseable > xDocument( m_xFactory->createInstance( GetDocumentServiceName() ), uno::UNO_QUERY );
uno::UNO_QUERY );
uno::Reference< frame::XLoadable > xLoadable( xDocument, uno::UNO_QUERY ); uno::Reference< frame::XLoadable > xLoadable( xDocument, uno::UNO_QUERY );
if ( !xLoadable.is() ) uno::Reference< document::XStorageBasedDocument > xDoc
#ifdef USE_STORAGEBASED_DOCUMENT
( xDocument, uno::UNO_QUERY )
#endif
;
if ( !xDoc.is() && !xLoadable.is() )
throw uno::RuntimeException(); throw uno::RuntimeException();
uno::Reference< io::XInputStream > xTempInpStream = createTempInpStreamFromStor( xStorage, m_xFactory ); ::rtl::OUString aFilterName;
if ( !xTempInpStream.is() ) // TODO/LATER: the filter will be provided from outside, factory will set it in object props
throw uno::RuntimeException(); try {
aFilterName = GetDefaultFilterFromServName( GetDocumentServiceName(),
::comphelper::OStorageHelper::GetXStorageFormat( xStorage ) );
} catch( uno::Exception& )
{}
::rtl::OUString aFilterName = GetDefaultFilterFromServName( GetDocumentServiceName() );
OSL_ENSURE( aFilterName.getLength(), "Wrong document service name!" ); OSL_ENSURE( aFilterName.getLength(), "Wrong document service name!" );
if ( !aFilterName.getLength() ) if ( !aFilterName.getLength() )
throw uno::RuntimeException(); // this point should not be reachable throw io::IOException();
::rtl::OUString aTempFileURL;
try
{
// no need to let the file stay after the stream is removed since the embedded document
// can not be stored directly
uno::Reference< beans::XPropertySet > xTempStreamProps( xTempInpStream, uno::UNO_QUERY_THROW );
xTempStreamProps->getPropertyValue( ::rtl::OUString::createFromAscii( "Uri" ) ) >>= aTempFileURL;
}
catch( uno::Exception& )
{
}
OSL_ENSURE( aTempFileURL.getLength(), "Coudn't retrieve temporary file URL!\n" ); sal_Int32 nLen = xDoc.is() ? 4 : 6;
uno::Sequence< beans::PropertyValue > aArgs( nLen );
uno::Sequence< beans::PropertyValue > aArgs( 4 ); aArgs[0].Name = ::rtl::OUString::createFromAscii( "DocumentBaseURL" );
aArgs[0].Name = ::rtl::OUString::createFromAscii( "URL" ); aArgs[0].Value <<= GetBaseURL_Impl();
aArgs[0].Value <<= aTempFileURL; aArgs[1].Name = ::rtl::OUString::createFromAscii( "HierarchicalDocumentName" );
aArgs[1].Name = ::rtl::OUString::createFromAscii( "InputStream" ); aArgs[1].Value <<= m_aEntryName;
aArgs[1].Value <<= xTempInpStream;
aArgs[2].Name = ::rtl::OUString::createFromAscii( "ReadOnly" ); aArgs[2].Name = ::rtl::OUString::createFromAscii( "ReadOnly" );
aArgs[2].Value <<= m_bReadOnly; aArgs[2].Value <<= m_bReadOnly;
aArgs[3].Name = ::rtl::OUString::createFromAscii( "FilterName" ); aArgs[3].Name = ::rtl::OUString::createFromAscii( "FilterName" );
aArgs[3].Value <<= aFilterName; aArgs[3].Value <<= aFilterName;
if ( !xDoc.is() )
{
uno::Reference< io::XInputStream > xTempInpStream = createTempInpStreamFromStor( xStorage, m_xFactory );
if ( !xTempInpStream.is() )
throw uno::RuntimeException();
::rtl::OUString aTempFileURL;
try
{
// no need to let the file stay after the stream is removed since the embedded document
// can not be stored directly
uno::Reference< beans::XPropertySet > xTempStreamProps( xTempInpStream, uno::UNO_QUERY_THROW );
xTempStreamProps->getPropertyValue( ::rtl::OUString::createFromAscii( "Uri" ) ) >>= aTempFileURL;
}
catch( uno::Exception& )
{
}
OSL_ENSURE( aTempFileURL.getLength(), "Coudn't retrieve temporary file URL!\n" );
aArgs[4].Name = ::rtl::OUString::createFromAscii( "URL" );
aArgs[4].Value <<= aTempFileURL; // ::rtl::OUString::createFromAscii( "private:stream" );
aArgs[5].Name = ::rtl::OUString::createFromAscii( "InputStream" );
aArgs[5].Value <<= xTempInpStream;
}
// aArgs[4].Name = ::rtl::OUString::createFromAscii( "AsTemplate" ); // aArgs[4].Name = ::rtl::OUString::createFromAscii( "AsTemplate" );
// aArgs[4].Value <<= sal_True; // aArgs[4].Value <<= sal_True;
for ( sal_Int32 nInd = 0; nInd < m_aDocMediaDescriptor.getLength(); nInd++ ) for ( sal_Int32 nInd = 0; nInd < m_aDocMediaDescriptor.getLength(); nInd++ )
{ {
aArgs.realloc( nInd + 5 ); aArgs.realloc( nInd + nLen );
aArgs[nInd+4].Name = m_aDocMediaDescriptor[nInd].Name; aArgs[nInd+nLen-1].Name = m_aDocMediaDescriptor[nInd].Name;
aArgs[nInd+4].Value = m_aDocMediaDescriptor[nInd].Value; aArgs[nInd+nLen-1].Value = m_aDocMediaDescriptor[nInd].Value;
} }
try try
{ {
xLoadable->load( aArgs ); // set the document mode to embedded
SetDocToEmbedded( uno::Reference < frame::XModel >( xDocument, uno::UNO_QUERY ) );
if ( xDoc.is() )
xDoc->loadFromStorage( xStorage, aArgs );
else
xLoadable->load( aArgs );
} }
catch( uno::Exception& ) catch( uno::Exception& )
{ {
...@@ -436,7 +506,10 @@ uno::Reference< frame::XModel > OCommonEmbeddedObject::LoadDocumentFromStorage_I ...@@ -436,7 +506,10 @@ uno::Reference< frame::XModel > OCommonEmbeddedObject::LoadDocumentFromStorage_I
} }
//------------------------------------------------------ //------------------------------------------------------
uno::Reference< io::XInputStream > OCommonEmbeddedObject::StoreDocumentToTempStream_Impl() uno::Reference< io::XInputStream > OCommonEmbeddedObject::StoreDocumentToTempStream_Impl(
sal_Int32 nStorageFormat,
const ::rtl::OUString& aBaseURL,
const ::rtl::OUString& aHierarchName )
{ {
uno::Reference < io::XOutputStream > xTempOut( uno::Reference < io::XOutputStream > xTempOut(
m_xFactory->createInstance ( ::rtl::OUString::createFromAscii( "com.sun.star.io.TempFile" ) ), m_xFactory->createInstance ( ::rtl::OUString::createFromAscii( "com.sun.star.io.TempFile" ) ),
...@@ -446,18 +519,33 @@ uno::Reference< io::XInputStream > OCommonEmbeddedObject::StoreDocumentToTempStr ...@@ -446,18 +519,33 @@ uno::Reference< io::XInputStream > OCommonEmbeddedObject::StoreDocumentToTempStr
if ( !xTempOut.is() || !aResult.is() ) if ( !xTempOut.is() || !aResult.is() )
throw uno::RuntimeException(); // TODO: throw uno::RuntimeException(); // TODO:
uno::Reference< frame::XStorable > xStorable( m_pDocHolder->GetDocument(), uno::UNO_QUERY ); uno::Reference< frame::XStorable > xStorable( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
if( !xStorable.is() ) if( !xStorable.is() )
throw uno::RuntimeException(); // TODO: throw uno::RuntimeException(); // TODO:
::rtl::OUString aFilterName = GetDefaultFilterFromServName( GetDocumentServiceName() ); ::rtl::OUString aFilterName;
try {
// TODO/LATER: the filter must be provided from outside in future
aFilterName = GetDefaultFilterFromServName( GetDocumentServiceName(),
nStorageFormat );
}
catch( uno::Exception& )
{
}
OSL_ENSURE( aFilterName.getLength(), "Wrong document service name!" ); OSL_ENSURE( aFilterName.getLength(), "Wrong document service name!" );
if ( !aFilterName.getLength() )
throw io::IOException(); // TODO:
uno::Sequence< beans::PropertyValue > aArgs( 2 ); uno::Sequence< beans::PropertyValue > aArgs( 4 );
aArgs[0].Name = ::rtl::OUString::createFromAscii( "FilterName" ); aArgs[0].Name = ::rtl::OUString::createFromAscii( "FilterName" );
aArgs[0].Value <<= aFilterName; aArgs[0].Value <<= aFilterName;
aArgs[1].Name = ::rtl::OUString::createFromAscii( "OutputStream" ); aArgs[1].Name = ::rtl::OUString::createFromAscii( "OutputStream" );
aArgs[1].Value <<= xTempOut; aArgs[1].Value <<= xTempOut;
aArgs[2].Name = ::rtl::OUString::createFromAscii( "DocumentBaseURL" );
aArgs[2].Value <<= aBaseURL;
aArgs[3].Name = ::rtl::OUString::createFromAscii( "HierarchicalDocumentName" );
aArgs[3].Value <<= aHierarchName;
xStorable->storeToURL( ::rtl::OUString::createFromAscii( "private:stream" ), aArgs ); xStorable->storeToURL( ::rtl::OUString::createFromAscii( "private:stream" ), aArgs );
try try
...@@ -488,38 +576,145 @@ void OCommonEmbeddedObject::SaveObject_Impl() ...@@ -488,38 +576,145 @@ void OCommonEmbeddedObject::SaveObject_Impl()
} }
//------------------------------------------------------ //------------------------------------------------------
void OCommonEmbeddedObject::StoreDocToStorage_Impl( const uno::Reference< embed::XStorage >& xStorage ) ::rtl::OUString OCommonEmbeddedObject::GetBaseURL_Impl()
{
::rtl::OUString aBaseURL;
sal_Int32 nInd = 0;
if ( m_xClientSite.is() )
{
try
{
uno::Reference< frame::XModel > xParentModel( m_xClientSite->getComponent(), uno::UNO_QUERY_THROW );
uno::Sequence< beans::PropertyValue > aModelProps = xParentModel->getArgs();
for ( nInd = 0; nInd < aModelProps.getLength(); nInd++ )
if ( aModelProps[nInd].Name.equals(
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentBaseURL" ) ) ) )
{
aModelProps[nInd].Value >>= aBaseURL;
break;
}
}
catch( uno::Exception& )
{}
}
if ( !aBaseURL.getLength() )
{
for ( nInd = 0; nInd < m_aDocMediaDescriptor.getLength(); nInd++ )
if ( m_aDocMediaDescriptor[nInd].Name.equals(
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentBaseURL" ) ) ) )
{
m_aDocMediaDescriptor[nInd].Value >>= aBaseURL;
break;
}
}
if ( !aBaseURL.getLength() )
aBaseURL = m_aDefaultParentBaseURL;
return aBaseURL;
}
//------------------------------------------------------
::rtl::OUString OCommonEmbeddedObject::GetBaseURLFrom_Impl(
const uno::Sequence< beans::PropertyValue >& lArguments,
const uno::Sequence< beans::PropertyValue >& lObjArgs )
{
::rtl::OUString aBaseURL;
sal_Int32 nInd = 0;
for ( nInd = 0; nInd < lArguments.getLength(); nInd++ )
if ( lArguments[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentBaseURL" ) ) ) )
{
lArguments[nInd].Value >>= aBaseURL;
break;
}
if ( !aBaseURL.getLength() )
{
for ( nInd = 0; nInd < lObjArgs.getLength(); nInd++ )
if ( lObjArgs[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultParentBaseURL" ) ) ) )
{
lObjArgs[nInd].Value >>= aBaseURL;
break;
}
}
return aBaseURL;
}
//------------------------------------------------------
void OCommonEmbeddedObject::StoreDocToStorage_Impl( const uno::Reference< embed::XStorage >& xStorage,
sal_Int32 nStorageFormat,
const ::rtl::OUString& aBaseURL,
const ::rtl::OUString& aHierarchName )
{ {
OSL_ENSURE( xStorage.is(), "No storage is provided for storing!" ); OSL_ENSURE( xStorage.is(), "No storage is provided for storing!" );
if ( !xStorage.is() ) if ( !xStorage.is() )
throw uno::RuntimeException(); // TODO: throw uno::RuntimeException(); // TODO:
// store document to temporary stream based on temporary file #ifdef USE_STORAGEBASED_DOCUMENT
uno::Reference < io::XInputStream > xTempIn = StoreDocumentToTempStream_Impl(); uno::Reference< document::XStorageBasedDocument > xDoc( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
OSL_ENSURE( xTempIn.is(), "The stream reference can not be empty!\n" ); if ( xDoc.is() )
{
::rtl::OUString aFilterName;
try {
// TODO/LATER: the filter must be provided from outside in future
aFilterName = GetDefaultFilterFromServName( GetDocumentServiceName(),
nStorageFormat );
}
catch( uno::Exception& )
{
}
// open storage based on document temporary file for reading OSL_ENSURE( aFilterName.getLength(), "Wrong document service name!" );
uno::Reference < lang::XSingleServiceFactory > xStorageFactory( if ( !aFilterName.getLength() )
m_xFactory->createInstance ( ::rtl::OUString::createFromAscii( "com.sun.star.embed.StorageFactory" ) ), throw io::IOException(); // TODO:
uno::UNO_QUERY );
uno::Sequence< uno::Any > aArgs(1); uno::Sequence< beans::PropertyValue > aArgs( 3 );
aArgs[0] <<= xTempIn; aArgs[0].Name = ::rtl::OUString::createFromAscii( "FilterName" );
uno::Reference< embed::XStorage > xTempStorage( xStorageFactory->createInstanceWithArguments( aArgs ), aArgs[0].Value <<= aFilterName;
uno::UNO_QUERY ); aArgs[2].Name = ::rtl::OUString::createFromAscii( "DocumentBaseURL" );
if ( !xTempStorage.is() ) aArgs[2].Value <<= aBaseURL;
throw uno::RuntimeException(); // TODO: aArgs[1].Name = ::rtl::OUString::createFromAscii( "HierarchicalDocumentName" );
aArgs[1].Value <<= aHierarchName;
xDoc->storeToStorage( xStorage, aArgs );
}
else
#endif
{
// store document to temporary stream based on temporary file
uno::Reference < io::XInputStream > xTempIn = StoreDocumentToTempStream_Impl( nStorageFormat, aBaseURL, aHierarchName );
OSL_ENSURE( xTempIn.is(), "The stream reference can not be empty!\n" );
// open storage based on document temporary file for reading
uno::Reference < lang::XSingleServiceFactory > xStorageFactory(
m_xFactory->createInstance ( ::rtl::OUString::createFromAscii( "com.sun.star.embed.StorageFactory" ) ),
uno::UNO_QUERY );
uno::Sequence< uno::Any > aArgs(1);
aArgs[0] <<= xTempIn;
uno::Reference< embed::XStorage > xTempStorage( xStorageFactory->createInstanceWithArguments( aArgs ),
uno::UNO_QUERY );
if ( !xTempStorage.is() )
throw uno::RuntimeException(); // TODO:
// object storage must be commited automatically // object storage must be commited automatically
xTempStorage->copyToStorage( xStorage ); xTempStorage->copyToStorage( xStorage );
}
} }
//------------------------------------------------------ //------------------------------------------------------
uno::Reference< frame::XModel > OCommonEmbeddedObject::CreateDocFromMediaDescr_Impl( uno::Reference< util::XCloseable > OCommonEmbeddedObject::CreateDocFromMediaDescr_Impl(
const uno::Sequence< beans::PropertyValue >& aMedDescr ) const uno::Sequence< beans::PropertyValue >& aMedDescr )
{ {
uno::Reference< frame::XModel > xDocument( m_xFactory->createInstance( GetDocumentServiceName() ), uno::Reference< util::XCloseable > xDocument( m_xFactory->createInstance( GetDocumentServiceName() ),
uno::UNO_QUERY ); uno::UNO_QUERY );
uno::Reference< frame::XLoadable > xLoadable( xDocument, uno::UNO_QUERY ); uno::Reference< frame::XLoadable > xLoadable( xDocument, uno::UNO_QUERY );
...@@ -528,7 +723,10 @@ uno::Reference< frame::XModel > OCommonEmbeddedObject::CreateDocFromMediaDescr_I ...@@ -528,7 +723,10 @@ uno::Reference< frame::XModel > OCommonEmbeddedObject::CreateDocFromMediaDescr_I
try try
{ {
xLoadable->load( aMedDescr ); // addAsTemplate( aMedDescr ) ); // set the document mode to embedded
SetDocToEmbedded( uno::Reference < frame::XModel >( xDocument, uno::UNO_QUERY ) );
xLoadable->load( addAsTemplate( aMedDescr ) );
} }
catch( uno::Exception& ) catch( uno::Exception& )
{ {
...@@ -551,20 +749,33 @@ uno::Reference< frame::XModel > OCommonEmbeddedObject::CreateDocFromMediaDescr_I ...@@ -551,20 +749,33 @@ uno::Reference< frame::XModel > OCommonEmbeddedObject::CreateDocFromMediaDescr_I
} }
//------------------------------------------------------ //------------------------------------------------------
uno::Reference< frame::XModel > OCommonEmbeddedObject::CreateTempDocFromLink_Impl() uno::Reference< util::XCloseable > OCommonEmbeddedObject::CreateTempDocFromLink_Impl()
{ {
uno::Reference< frame::XModel > xResult; uno::Reference< util::XCloseable > xResult;
OSL_ENSURE( m_bIsLink, "The object is not a linked one!\n" ); OSL_ENSURE( m_bIsLink, "The object is not a linked one!\n" );
uno::Sequence< beans::PropertyValue > aTempMediaDescr; uno::Sequence< beans::PropertyValue > aTempMediaDescr;
if ( m_pDocHolder->GetDocument().is() ) sal_Int32 nStorageFormat = SOFFICE_FILEFORMAT_CURRENT;
try {
nStorageFormat = ::comphelper::OStorageHelper::GetXStorageFormat( m_xParentStorage );
}
catch ( uno::Exception& )
{
OSL_ENSURE( sal_False, "Can not retrieve storage media type!\n" );
}
if ( m_pDocHolder->GetComponent().is() )
{ {
aTempMediaDescr.realloc( 3 ); aTempMediaDescr.realloc( 3 );
// TODO/LATER: may be private:stream should be used as target URL
::rtl::OUString aTempFileURL; ::rtl::OUString aTempFileURL;
uno::Reference< io::XInputStream > xTempStream = StoreDocumentToTempStream_Impl(); uno::Reference< io::XInputStream > xTempStream = StoreDocumentToTempStream_Impl( SOFFICE_FILEFORMAT_CURRENT,
::rtl::OUString(),
::rtl::OUString() );
try try
{ {
// no need to let the file stay after the stream is removed since the embedded document // no need to let the file stay after the stream is removed since the embedded document
...@@ -583,9 +794,12 @@ uno::Reference< frame::XModel > OCommonEmbeddedObject::CreateTempDocFromLink_Imp ...@@ -583,9 +794,12 @@ uno::Reference< frame::XModel > OCommonEmbeddedObject::CreateTempDocFromLink_Imp
aTempMediaDescr[1].Name = ::rtl::OUString::createFromAscii( "InputStream" ); aTempMediaDescr[1].Name = ::rtl::OUString::createFromAscii( "InputStream" );
aTempMediaDescr[1].Value <<= xTempStream; aTempMediaDescr[1].Value <<= xTempStream;
aTempMediaDescr[2].Name = ::rtl::OUString::createFromAscii( "FilterName" ); aTempMediaDescr[2].Name = ::rtl::OUString::createFromAscii( "FilterName" );
aTempMediaDescr[2].Value <<= GetDefaultFilterFromServName( GetDocumentServiceName() ); // TODO/LATER: the filter must be provided from outside in future
// aTempMediaDescr[3].Name = ::rtl::OUString::createFromAscii( "AsTemplate" ); aTempMediaDescr[2].Value <<= GetDefaultFilterFromServName(
// aTempMediaDescr[3].Value <<= sal_True; GetDocumentServiceName(),
nStorageFormat );
aTempMediaDescr[3].Name = ::rtl::OUString::createFromAscii( "AsTemplate" );
aTempMediaDescr[3].Value <<= sal_True;
} }
else else
{ {
...@@ -649,11 +863,16 @@ void SAL_CALL OCommonEmbeddedObject::setPersistentEntry( ...@@ -649,11 +863,16 @@ void SAL_CALL OCommonEmbeddedObject::setPersistentEntry(
} }
if ( m_bWaitSaveCompleted ) if ( m_bWaitSaveCompleted )
throw embed::WrongStateException( {
::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), if ( nEntryConnectionMode == embed::EntryInitModes::NO_INIT )
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); saveCompleted( ( m_xParentStorage != xStorage || !m_aEntryName.equals( sEntName ) ) );
else
throw embed::WrongStateException(
::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
}
// TODO: the OOo link will have persistence OSL_ENSURE( !m_bIsLink, "This method implementation must not be used for links!\n" );
if ( m_bIsLink ) if ( m_bIsLink )
return; return;
...@@ -664,7 +883,8 @@ void SAL_CALL OCommonEmbeddedObject::setPersistentEntry( ...@@ -664,7 +883,8 @@ void SAL_CALL OCommonEmbeddedObject::setPersistentEntry(
// detect entry existence // detect entry existence
sal_Bool bElExists = xNameAccess->hasByName( sEntName ); sal_Bool bElExists = xNameAccess->hasByName( sEntName );
m_aDocMediaDescriptor = GetValuableArgs_Impl( lArguments ); m_aDocMediaDescriptor = GetValuableArgs_Impl( lArguments,
nEntryConnectionMode != embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT );
m_bReadOnly = sal_False; m_bReadOnly = sal_False;
for ( sal_Int32 nInd = 0; nInd < lArguments.getLength(); nInd++ ) for ( sal_Int32 nInd = 0; nInd < lArguments.getLength(); nInd++ )
...@@ -678,8 +898,10 @@ void SAL_CALL OCommonEmbeddedObject::setPersistentEntry( ...@@ -678,8 +898,10 @@ void SAL_CALL OCommonEmbeddedObject::setPersistentEntry(
uno::Reference< frame::XDispatchProviderInterceptor > xDispatchInterceptor; uno::Reference< frame::XDispatchProviderInterceptor > xDispatchInterceptor;
if ( lObjArgs[nObjInd].Value >>= xDispatchInterceptor ) if ( lObjArgs[nObjInd].Value >>= xDispatchInterceptor )
m_pDocHolder->SetOutplaceDispatchInterceptor( xDispatchInterceptor ); m_pDocHolder->SetOutplaceDispatchInterceptor( xDispatchInterceptor );
}
break; else if ( lObjArgs[nObjInd].Name.equalsAscii( "DefaultParentBaseURL" ) )
{
lObjArgs[nObjInd].Value >>= m_aDefaultParentBaseURL;
} }
sal_Int32 nStorageMode = m_bReadOnly ? embed::ElementModes::READ : embed::ElementModes::READWRITE; sal_Int32 nStorageMode = m_bReadOnly ? embed::ElementModes::READ : embed::ElementModes::READWRITE;
...@@ -695,8 +917,8 @@ void SAL_CALL OCommonEmbeddedObject::setPersistentEntry( ...@@ -695,8 +917,8 @@ void SAL_CALL OCommonEmbeddedObject::setPersistentEntry(
} }
else else
{ {
m_pDocHolder->SetDocument( InitNewDocument_Impl(), m_bReadOnly ); m_pDocHolder->SetComponent( InitNewDocument_Impl(), m_bReadOnly );
if ( !m_pDocHolder->GetDocument().is() ) if ( !m_pDocHolder->GetComponent().is() )
throw io::IOException(); // TODO: can not create document throw io::IOException(); // TODO: can not create document
m_nObjectState = embed::EmbedStates::RUNNING; m_nObjectState = embed::EmbedStates::RUNNING;
...@@ -716,16 +938,16 @@ void SAL_CALL OCommonEmbeddedObject::setPersistentEntry( ...@@ -716,16 +938,16 @@ void SAL_CALL OCommonEmbeddedObject::setPersistentEntry(
else if ( nEntryConnectionMode == embed::EntryInitModes::TRUNCATE_INIT ) else if ( nEntryConnectionMode == embed::EntryInitModes::TRUNCATE_INIT )
{ {
// TODO: // TODO:
m_pDocHolder->SetDocument( InitNewDocument_Impl(), m_bReadOnly ); m_pDocHolder->SetComponent( InitNewDocument_Impl(), m_bReadOnly );
if ( !m_pDocHolder->GetDocument().is() ) if ( !m_pDocHolder->GetComponent().is() )
throw io::IOException(); // TODO: can not create document throw io::IOException(); // TODO: can not create document
m_nObjectState = embed::EmbedStates::RUNNING; m_nObjectState = embed::EmbedStates::RUNNING;
} }
else if ( nEntryConnectionMode == embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT ) else if ( nEntryConnectionMode == embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT )
{ {
m_pDocHolder->SetDocument( CreateDocFromMediaDescr_Impl( lArguments ), m_bReadOnly ); m_pDocHolder->SetComponent( CreateDocFromMediaDescr_Impl( lArguments ), m_bReadOnly );
m_nObjectState = embed::EmbedStates::RUNNING; m_nObjectState = embed::EmbedStates::RUNNING;
} }
//else if ( nEntryConnectionMode == embed::EntryInitModes::TRANSFERABLE_INIT ) //else if ( nEntryConnectionMode == embed::EntryInitModes::TRANSFERABLE_INIT )
...@@ -739,70 +961,6 @@ void SAL_CALL OCommonEmbeddedObject::setPersistentEntry( ...@@ -739,70 +961,6 @@ void SAL_CALL OCommonEmbeddedObject::setPersistentEntry(
} }
} }
//------------------------------------------------------
void SAL_CALL OCommonEmbeddedObject::storeOwn()
throw ( embed::WrongStateException,
io::IOException,
uno::Exception,
uno::RuntimeException )
{
// during switching from Activated to Running and from Running to Loaded states the object will
// ask container to store the object, the container has to make decision
// to do so or not
::osl::MutexGuard aGuard( m_aMutex );
if ( m_bDisposed )
throw lang::DisposedException(); // TODO
if ( m_nObjectState == -1 )
{
// the object is still not loaded
throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Can't store object without persistence!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
}
if ( m_bWaitSaveCompleted )
throw embed::WrongStateException(
::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
if ( m_bReadOnly )
throw io::IOException(); // TODO: access denied
if ( m_nObjectState == embed::EmbedStates::LOADED )
return; // nothing to do, the object is in loaded state
OSL_ENSURE( m_pDocHolder->GetDocument().is(), "If an object is activated or in running state it must have a document!\n" );
if ( !m_pDocHolder->GetDocument().is() )
throw uno::RuntimeException();
if ( m_bIsLink )
{
// TODO: just store the document to it's location
uno::Reference< frame::XStorable > xStorable( m_pDocHolder->GetDocument(), uno::UNO_QUERY );
if ( !xStorable.is() )
throw uno::RuntimeException(); // TODO
xStorable->store();
}
else
{
OSL_ENSURE( m_xParentStorage.is() && m_xObjectStorage.is(), "The object has no valid persistence!\n" );
if ( !m_xObjectStorage.is() )
throw io::IOException(); //TODO: access denied
StoreDocToStorage_Impl( m_xObjectStorage );
}
// TODO:
// notify listeners
if ( m_nUpdateMode == embed::EmbedUpdateModes::ALWAYS_UPDATE )
{
// TODO: update visual representation
}
}
//------------------------------------------------------ //------------------------------------------------------
void SAL_CALL OCommonEmbeddedObject::storeToEntry( const uno::Reference< embed::XStorage >& xStorage, void SAL_CALL OCommonEmbeddedObject::storeToEntry( const uno::Reference< embed::XStorage >& xStorage,
const ::rtl::OUString& sEntName, const ::rtl::OUString& sEntName,
...@@ -832,15 +990,36 @@ void SAL_CALL OCommonEmbeddedObject::storeToEntry( const uno::Reference< embed:: ...@@ -832,15 +990,36 @@ void SAL_CALL OCommonEmbeddedObject::storeToEntry( const uno::Reference< embed::
::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
OSL_ENSURE( m_bIsLink || m_xParentStorage.is() && m_xObjectStorage.is(), "The object has no valid persistence!\n" ); OSL_ENSURE( !m_bIsLink, "This method implementation must not be used for links!\n" );
if ( m_bIsLink )
return;
OSL_ENSURE( m_xParentStorage.is() && m_xObjectStorage.is(), "The object has no valid persistence!\n" );
uno::Reference< embed::XStorage > xSubStorage = // TODO/LATER: Storing to different format can be done only in running state,
xStorage->openStorageElement( sEntName, embed::ElementModes::READWRITE ); // copiing is not legal for documents with relative links.
if ( m_nObjectState == embed::EmbedStates::LOADED )
m_xParentStorage->copyElementTo( m_aEntryName, xStorage, sEntName );
else
{
uno::Reference< embed::XStorage > xSubStorage =
xStorage->openStorageElement( sEntName, embed::ElementModes::READWRITE );
if ( !xSubStorage.is() ) if ( !xSubStorage.is() )
throw uno::RuntimeException(); //TODO throw uno::RuntimeException(); //TODO
sal_Int32 nStorageFormat = SOFFICE_FILEFORMAT_CURRENT;
try {
nStorageFormat = ::comphelper::OStorageHelper::GetXStorageFormat( xStorage );
}
catch ( uno::Exception& )
{
OSL_ENSURE( sal_False, "Can not retrieve storage media type!\n" );
}
StoreDocToStorage_Impl( xSubStorage ); // TODO/LATER: support hierarchical name for embedded objects in embedded objects
StoreDocToStorage_Impl( xSubStorage, nStorageFormat, GetBaseURLFrom_Impl( lArguments, lObjArgs ), sEntName );
}
// TODO: should the listener notification be done? // TODO: should the listener notification be done?
} }
...@@ -874,7 +1053,26 @@ void SAL_CALL OCommonEmbeddedObject::storeAsEntry( const uno::Reference< embed:: ...@@ -874,7 +1053,26 @@ void SAL_CALL OCommonEmbeddedObject::storeAsEntry( const uno::Reference< embed::
::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
OSL_ENSURE( m_bIsLink || m_xParentStorage.is() && m_xObjectStorage.is(), "The object has no valid persistence!\n" ); OSL_ENSURE( !m_bIsLink, "This method implementation must not be used for links!\n" );
if ( m_bIsLink )
return;
OSL_ENSURE( m_xParentStorage.is() && m_xObjectStorage.is(), "The object has no valid persistence!\n" );
sal_Int32 nStorageFormat = SOFFICE_FILEFORMAT_CURRENT;
try {
nStorageFormat = ::comphelper::OStorageHelper::GetXStorageFormat( xStorage );
}
catch ( uno::Exception& )
{
OSL_ENSURE( sal_False, "Can not retrieve storage media type!\n" );
}
PostEvent_Impl( ::rtl::OUString::createFromAscii( "OnSaveAs" ) );
// TODO/MAV: in case storage type is changed storing can be done only in running state
if ( m_nObjectState == embed::EmbedStates::LOADED )
m_xParentStorage->copyElementTo( m_aEntryName, xStorage, sEntName );
uno::Reference< embed::XStorage > xSubStorage = uno::Reference< embed::XStorage > xSubStorage =
xStorage->openStorageElement( sEntName, embed::ElementModes::READWRITE ); xStorage->openStorageElement( sEntName, embed::ElementModes::READWRITE );
...@@ -882,12 +1080,17 @@ void SAL_CALL OCommonEmbeddedObject::storeAsEntry( const uno::Reference< embed:: ...@@ -882,12 +1080,17 @@ void SAL_CALL OCommonEmbeddedObject::storeAsEntry( const uno::Reference< embed::
if ( !xSubStorage.is() ) if ( !xSubStorage.is() )
throw uno::RuntimeException(); //TODO throw uno::RuntimeException(); //TODO
StoreDocToStorage_Impl( xSubStorage ); if ( m_nObjectState != embed::EmbedStates::LOADED )
{
// TODO/LATER: support hierarchical name for embedded objects in embedded objects
StoreDocToStorage_Impl( xSubStorage, nStorageFormat, GetBaseURLFrom_Impl( lArguments, lObjArgs ), sEntName );
}
m_bWaitSaveCompleted = sal_True; m_bWaitSaveCompleted = sal_True;
m_xNewObjectStorage = xSubStorage; m_xNewObjectStorage = xSubStorage;
m_xNewParentStorage = xStorage; m_xNewParentStorage = xStorage;
m_aEntryName = sEntName; m_aNewEntryName = sEntName;
m_aNewDocMediaDescriptor = GetValuableArgs_Impl( lArguments, sal_True );
// TODO: register listeners for storages above, in case thay are disposed // TODO: register listeners for storages above, in case thay are disposed
// an exception will be thrown on saveCompleted( true ) // an exception will be thrown on saveCompleted( true )
...@@ -912,6 +1115,10 @@ void SAL_CALL OCommonEmbeddedObject::saveCompleted( sal_Bool bUseNew ) ...@@ -912,6 +1115,10 @@ void SAL_CALL OCommonEmbeddedObject::saveCompleted( sal_Bool bUseNew )
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
} }
OSL_ENSURE( !m_bIsLink, "This method implementation must not be used for links!\n" );
if ( m_bIsLink )
return;
OSL_ENSURE( m_bWaitSaveCompleted, "Unexpected saveCompleted() call!\n" ); OSL_ENSURE( m_bWaitSaveCompleted, "Unexpected saveCompleted() call!\n" );
if ( !m_bWaitSaveCompleted ) if ( !m_bWaitSaveCompleted )
throw io::IOException(); // TODO: illegal call throw io::IOException(); // TODO: illegal call
...@@ -922,12 +1129,14 @@ void SAL_CALL OCommonEmbeddedObject::saveCompleted( sal_Bool bUseNew ) ...@@ -922,12 +1129,14 @@ void SAL_CALL OCommonEmbeddedObject::saveCompleted( sal_Bool bUseNew )
if ( bUseNew ) if ( bUseNew )
{ {
// the link object is not linked any more
// TODO: the link will have own persistence, so the link will stay the link
m_bIsLink = sal_False;
m_aLinkURL = ::rtl::OUString();
SwitchOwnPersistence( m_xNewParentStorage, m_xNewObjectStorage, m_aNewEntryName ); SwitchOwnPersistence( m_xNewParentStorage, m_xNewObjectStorage, m_aNewEntryName );
m_aDocMediaDescriptor = m_aNewDocMediaDescriptor;
uno::Reference< util::XModifiable > xModif( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
if ( xModif.is() )
xModif->setModified( sal_False );
PostEvent_Impl( ::rtl::OUString::createFromAscii( "OnSaveAsDone" ) );
} }
else else
{ {
...@@ -945,6 +1154,7 @@ void SAL_CALL OCommonEmbeddedObject::saveCompleted( sal_Bool bUseNew ) ...@@ -945,6 +1154,7 @@ void SAL_CALL OCommonEmbeddedObject::saveCompleted( sal_Bool bUseNew )
m_xNewObjectStorage = uno::Reference< embed::XStorage >(); m_xNewObjectStorage = uno::Reference< embed::XStorage >();
m_xNewParentStorage = uno::Reference< embed::XStorage >(); m_xNewParentStorage = uno::Reference< embed::XStorage >();
m_aNewEntryName = ::rtl::OUString(); m_aNewEntryName = ::rtl::OUString();
m_aNewDocMediaDescriptor.realloc( 0 );
m_bWaitSaveCompleted = sal_False; m_bWaitSaveCompleted = sal_False;
if ( bUseNew ) if ( bUseNew )
...@@ -1002,6 +1212,81 @@ sal_Bool SAL_CALL OCommonEmbeddedObject::hasEntry() ...@@ -1002,6 +1212,81 @@ sal_Bool SAL_CALL OCommonEmbeddedObject::hasEntry()
return m_aEntryName; return m_aEntryName;
} }
//------------------------------------------------------
void SAL_CALL OCommonEmbeddedObject::storeOwn()
throw ( embed::WrongStateException,
io::IOException,
uno::Exception,
uno::RuntimeException )
{
// during switching from Activated to Running and from Running to Loaded states the object will
// ask container to store the object, the container has to make decision
// to do so or not
::osl::MutexGuard aGuard( m_aMutex );
if ( m_bDisposed )
throw lang::DisposedException(); // TODO
if ( m_nObjectState == -1 )
{
// the object is still not loaded
throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Can't store object without persistence!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
}
if ( m_bWaitSaveCompleted )
throw embed::WrongStateException(
::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
if ( m_bReadOnly )
throw io::IOException(); // TODO: access denied
// nothing to do, if the object is in loaded state
if ( m_nObjectState == embed::EmbedStates::LOADED )
return;
PostEvent_Impl( ::rtl::OUString::createFromAscii( "OnSave" ) );
OSL_ENSURE( m_pDocHolder->GetComponent().is(), "If an object is activated or in running state it must have a document!\n" );
if ( !m_pDocHolder->GetComponent().is() )
throw uno::RuntimeException();
if ( m_bIsLink )
{
// TODO: just store the document to it's location
uno::Reference< frame::XStorable > xStorable( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
if ( !xStorable.is() )
throw uno::RuntimeException(); // TODO
xStorable->store();
}
else
{
OSL_ENSURE( m_xParentStorage.is() && m_xObjectStorage.is(), "The object has no valid persistence!\n" );
if ( !m_xObjectStorage.is() )
throw io::IOException(); //TODO: access denied
sal_Int32 nStorageFormat = SOFFICE_FILEFORMAT_CURRENT;
try {
nStorageFormat = ::comphelper::OStorageHelper::GetXStorageFormat( m_xParentStorage );
}
catch ( uno::Exception& )
{
OSL_ENSURE( sal_False, "Can not retrieve storage media type!\n" );
}
StoreDocToStorage_Impl( m_xObjectStorage, nStorageFormat, GetBaseURL_Impl(), m_aEntryName );
}
uno::Reference< util::XModifiable > xModif( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
if ( xModif.is() )
xModif->setModified( sal_False );
PostEvent_Impl( ::rtl::OUString::createFromAscii( "OnSaveDone" ) );
}
//------------------------------------------------------ //------------------------------------------------------
sal_Bool SAL_CALL OCommonEmbeddedObject::isReadonly() sal_Bool SAL_CALL OCommonEmbeddedObject::isReadonly()
throw ( embed::WrongStateException, throw ( embed::WrongStateException,
...@@ -1063,8 +1348,7 @@ void SAL_CALL OCommonEmbeddedObject::reload( ...@@ -1063,8 +1348,7 @@ void SAL_CALL OCommonEmbeddedObject::reload(
::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) ); uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
// TODO: get rid of useless part of MediaDescriptor m_aDocMediaDescriptor = GetValuableArgs_Impl( lArguments, sal_True );
m_aDocMediaDescriptor = GetValuableArgs_Impl( lArguments );
// TODO: use lObjArgs for StoreVisualReplacement // TODO: use lObjArgs for StoreVisualReplacement
for ( sal_Int32 nObjInd = 0; nObjInd < lObjArgs.getLength(); nObjInd++ ) for ( sal_Int32 nObjInd = 0; nObjInd < lObjArgs.getLength(); nObjInd++ )
...@@ -1087,7 +1371,7 @@ void SAL_CALL OCommonEmbeddedObject::reload( ...@@ -1087,7 +1371,7 @@ void SAL_CALL OCommonEmbeddedObject::reload(
if ( lArguments[nInd].Name.equalsAscii( "ReadOnly" ) ) if ( lArguments[nInd].Name.equalsAscii( "ReadOnly" ) )
lArguments[nInd].Value >>= m_bReadOnly; lArguments[nInd].Value >>= m_bReadOnly;
if ( bOldReadOnlyValue != m_bReadOnly ) if ( bOldReadOnlyValue != m_bReadOnly && !m_bIsLink )
{ {
// close own storage // close own storage
try { try {
...@@ -1114,6 +1398,21 @@ void SAL_CALL OCommonEmbeddedObject::breakLink( const uno::Reference< embed::XSt ...@@ -1114,6 +1398,21 @@ void SAL_CALL OCommonEmbeddedObject::breakLink( const uno::Reference< embed::XSt
uno::Exception, uno::Exception,
uno::RuntimeException ) uno::RuntimeException )
{ {
if ( !m_bIsLink )
{
// it must be a linked initialized object
throw embed::WrongStateException(
::rtl::OUString::createFromAscii( "The object is not a valid linked object!\n" ),
uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
}
else
{
// the current implementation of OOo links does not implement this method since it does not implement
// all the set of interfaces required for OOo embedded object ( XEmbedPersist is not supported ).
throw io::IOException(); // TODO:
}
#if 0
::osl::MutexGuard aGuard( m_aMutex ); ::osl::MutexGuard aGuard( m_aMutex );
if ( m_bDisposed ) if ( m_bDisposed )
throw lang::DisposedException(); // TODO throw lang::DisposedException(); // TODO
...@@ -1157,9 +1456,10 @@ void SAL_CALL OCommonEmbeddedObject::breakLink( const uno::Reference< embed::XSt ...@@ -1157,9 +1456,10 @@ void SAL_CALL OCommonEmbeddedObject::breakLink( const uno::Reference< embed::XSt
// for linked object it means that it becomes embedded object // for linked object it means that it becomes embedded object
// the document must switch it's persistence also // the document must switch it's persistence also
// TODO/LATER: handle the case when temp doc can not be created
// the document is a new embedded object so it must be marked as modified // the document is a new embedded object so it must be marked as modified
uno::Reference< frame::XModel > xDocument = CreateTempDocFromLink_Impl(); uno::Reference< util::XCloseable > xDocument = CreateTempDocFromLink_Impl();
uno::Reference< util::XModifiable > xModif( m_pDocHolder->GetDocument(), uno::UNO_QUERY ); uno::Reference< util::XModifiable > xModif( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
if ( !xModif.is() ) if ( !xModif.is() )
throw uno::RuntimeException(); throw uno::RuntimeException();
try try
...@@ -1169,8 +1469,8 @@ void SAL_CALL OCommonEmbeddedObject::breakLink( const uno::Reference< embed::XSt ...@@ -1169,8 +1469,8 @@ void SAL_CALL OCommonEmbeddedObject::breakLink( const uno::Reference< embed::XSt
catch( uno::Exception& ) catch( uno::Exception& )
{} {}
m_pDocHolder->SetDocument( xDocument, m_bReadOnly ); m_pDocHolder->SetComponent( xDocument, m_bReadOnly );
OSL_ENSURE( m_pDocHolder->GetDocument().is(), "If document cant be created, an exception must be thrown!\n" ); OSL_ENSURE( m_pDocHolder->GetComponent().is(), "If document cant be created, an exception must be thrown!\n" );
if ( m_nObjectState == embed::EmbedStates::LOADED ) if ( m_nObjectState == embed::EmbedStates::LOADED )
m_nObjectState = embed::EmbedStates::RUNNING; m_nObjectState = embed::EmbedStates::RUNNING;
...@@ -1180,6 +1480,7 @@ void SAL_CALL OCommonEmbeddedObject::breakLink( const uno::Reference< embed::XSt ...@@ -1180,6 +1480,7 @@ void SAL_CALL OCommonEmbeddedObject::breakLink( const uno::Reference< embed::XSt
m_bIsLink = sal_False; m_bIsLink = sal_False;
m_aLinkFilterName = ::rtl::OUString(); m_aLinkFilterName = ::rtl::OUString();
m_aLinkURL = ::rtl::OUString(); m_aLinkURL = ::rtl::OUString();
#endif
} }
//------------------------------------------------------ //------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment