2010-10-12 15:53:47 +02:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2012-09-27 13:52:10 +01:00
/*
* This file is part of the LibreOffice project .
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License , v . 2.0 . If a copy of the MPL was not distributed with this
* file , You can obtain one at http : //mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice :
*
* Licensed to the Apache Software Foundation ( ASF ) under one or more
* contributor license agreements . See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership . The ASF licenses this file to you under the Apache
* License , Version 2.0 ( the " License " ) ; you may not use this file
* except in compliance with the License . You may obtain a copy of
* the License at http : //www.apache.org/licenses/LICENSE-2.0 .
*/
2003-10-27 12:05:38 +00:00
# include <commonembobj.hxx>
2007-05-22 18:35:24 +00:00
# include <com/sun/star/embed/Aspects.hpp>
2004-10-04 18:49:49 +00:00
# include <com/sun/star/document/XStorageBasedDocument.hpp>
2003-10-27 12:05:38 +00:00
# include <com/sun/star/embed/EmbedStates.hpp>
# include <com/sun/star/embed/EmbedVerbs.hpp>
# include <com/sun/star/embed/EntryInitModes.hpp>
# include <com/sun/star/embed/XStorage.hpp>
2006-01-20 08:50:17 +00:00
# include <com/sun/star/embed/XOptimizedStorage.hpp>
2003-10-27 12:05:38 +00:00
# include <com/sun/star/embed/ElementModes.hpp>
# include <com/sun/star/embed/EmbedUpdateModes.hpp>
2012-12-03 16:33:30 +02:00
# include <com/sun/star/embed/StorageFactory.hpp>
2012-08-23 17:23:26 +02:00
# include <com/sun/star/io/TempFile.hpp>
2003-10-27 12:05:38 +00:00
# include <com/sun/star/frame/XModel.hpp>
# include <com/sun/star/frame/XStorable.hpp>
# include <com/sun/star/frame/XLoadable.hpp>
# include <com/sun/star/frame/XComponentLoader.hpp>
2007-04-16 15:50:13 +00:00
# include <com/sun/star/frame/XModule.hpp>
2003-10-27 12:05:38 +00:00
# include <com/sun/star/lang/XMultiServiceFactory.hpp>
# include <com/sun/star/lang/XSingleServiceFactory.hpp>
# include <com/sun/star/lang/DisposedException.hpp>
# include <com/sun/star/util/XModifiable.hpp>
# include <com/sun/star/container/XNameAccess.hpp>
2007-05-22 18:35:24 +00:00
# include <com/sun/star/container/XChild.hpp>
2003-10-27 12:05:38 +00:00
# include <com/sun/star/util/XCloseable.hpp>
2004-08-02 16:44:17 +00:00
# include <com/sun/star/beans/XPropertySet.hpp>
2004-11-26 15:15:37 +00:00
# include <com/sun/star/beans/IllegalTypeException.hpp>
2009-09-14 10:57:16 +00:00
# include <com/sun/star/chart2/XChartDocument.hpp>
2004-08-02 16:44:17 +00:00
2004-10-04 18:49:49 +00:00
# include <comphelper/fileformat.h>
2012-09-19 13:15:15 +02:00
# include <comphelper/processfactory.hxx>
2004-10-04 18:49:49 +00:00
# include <comphelper/storagehelper.hxx>
2007-07-06 09:06:51 +00:00
# include <comphelper/mimeconfighelper.hxx>
2010-01-06 21:34:53 +01:00
# include <comphelper/namedvaluecollection.hxx>
2006-01-20 08:50:17 +00:00
2010-01-27 10:53:30 +01:00
# include <tools/diagnose_ex.h>
2014-06-25 14:57:44 +02:00
# include "persistence.hxx"
2010-01-27 10:53:30 +01:00
2003-10-27 12:05:38 +00:00
using namespace : : com : : sun : : star ;
2004-10-04 18:49:49 +00:00
uno : : Sequence < beans : : PropertyValue > GetValuableArgs_Impl ( const uno : : Sequence < beans : : PropertyValue > & aMedDescr ,
2014-04-17 11:39:18 +02:00
bool bCanUseDocumentBaseURL )
2004-05-10 16:51:24 +00:00
{
uno : : Sequence < beans : : PropertyValue > aResult ;
sal_Int32 nResLen = 0 ;
for ( sal_Int32 nInd = 0 ; nInd < aMedDescr . getLength ( ) ; nInd + + )
{
2012-04-06 19:49:53 +02:00
if ( aMedDescr [ nInd ] . Name = = " ComponentData " | | aMedDescr [ nInd ] . Name = = " DocumentTitle "
| | aMedDescr [ nInd ] . Name = = " InteractionHandler " | | aMedDescr [ nInd ] . Name = = " JumpMark "
2014-11-10 15:05:25 +01:00
// || aMedDescr[nInd].Name == "Password" // makes no sense for embedded objects
2012-04-06 19:49:53 +02:00
| | aMedDescr [ nInd ] . Name = = " Preview " | | aMedDescr [ nInd ] . Name = = " ReadOnly "
| | aMedDescr [ nInd ] . Name = = " StartPresentation " | | aMedDescr [ nInd ] . Name = = " RepairPackage "
| | aMedDescr [ nInd ] . Name = = " StatusIndicator " | | aMedDescr [ nInd ] . Name = = " ViewData "
| | aMedDescr [ nInd ] . Name = = " ViewId " | | aMedDescr [ nInd ] . Name = = " MacroExecutionMode "
| | aMedDescr [ nInd ] . Name = = " UpdateDocMode "
| | ( aMedDescr [ nInd ] . Name = = " DocumentBaseURL " & & bCanUseDocumentBaseURL ) )
2004-05-10 16:51:24 +00:00
{
aResult . realloc ( + + nResLen ) ;
aResult [ nResLen - 1 ] = aMedDescr [ nInd ] ;
}
}
return aResult ;
}
2014-02-22 21:20:15 +01:00
2003-10-27 12:05:38 +00:00
uno : : Sequence < beans : : PropertyValue > addAsTemplate ( const uno : : Sequence < beans : : PropertyValue > & aOrig )
{
2014-04-17 11:39:18 +02:00
bool bAsTemplateSet = false ;
2003-10-27 12:05:38 +00:00
sal_Int32 nLength = aOrig . getLength ( ) ;
uno : : Sequence < beans : : PropertyValue > aResult ( nLength ) ;
for ( sal_Int32 nInd = 0 ; nInd < nLength ; nInd + + )
{
aResult [ nInd ] . Name = aOrig [ nInd ] . Name ;
2012-04-06 14:28:18 +02:00
if ( aResult [ nInd ] . Name = = " AsTemplate " )
2003-10-27 12:05:38 +00:00
{
2016-04-20 17:16:42 +02:00
aResult [ nInd ] . Value < < = true ;
2014-04-17 11:39:18 +02:00
bAsTemplateSet = true ;
2003-10-27 12:05:38 +00:00
}
else
aResult [ nInd ] . Value = aOrig [ nInd ] . Value ;
}
if ( ! bAsTemplateSet )
{
aResult . realloc ( nLength + 1 ) ;
2013-11-15 11:05:19 +02:00
aResult [ nLength ] . Name = " AsTemplate " ;
2016-04-20 17:16:42 +02:00
aResult [ nLength ] . Value < < = true ;
2003-10-27 12:05:38 +00:00
}
return aResult ;
}
2014-02-22 21:20:15 +01:00
2003-10-27 12:05:38 +00:00
uno : : Reference < io : : XInputStream > createTempInpStreamFromStor (
const uno : : Reference < embed : : XStorage > & xStorage ,
2012-12-03 16:33:30 +02:00
const uno : : Reference < uno : : XComponentContext > & xContext )
2003-10-27 12:05:38 +00:00
{
2013-05-27 00:22:20 +03:00
SAL_WARN_IF ( ! xStorage . is ( ) , " embeddedobj.common " , " The storage can not be empty! " ) ;
2003-10-27 12:05:38 +00:00
uno : : Reference < io : : XInputStream > xResult ;
2012-12-03 16:33:30 +02:00
uno : : Reference < io : : XStream > xTempStream ( io : : TempFile : : create ( xContext ) , uno : : UNO_QUERY_THROW ) ;
2003-10-27 12:05:38 +00:00
2012-12-03 16:33:30 +02:00
uno : : Reference < lang : : XSingleServiceFactory > xStorageFactory ( embed : : StorageFactory : : create ( xContext ) ) ;
2003-10-27 12:05:38 +00:00
2012-08-23 17:23:26 +02:00
uno : : Sequence < uno : : Any > aArgs ( 2 ) ;
aArgs [ 0 ] < < = xTempStream ;
aArgs [ 1 ] < < = embed : : ElementModes : : READWRITE ;
uno : : Reference < embed : : XStorage > xTempStorage ( xStorageFactory - > createInstanceWithArguments ( aArgs ) ,
uno : : UNO_QUERY ) ;
if ( ! xTempStorage . is ( ) )
throw uno : : RuntimeException ( ) ; // TODO:
2003-10-27 12:05:38 +00:00
2012-08-23 17:23:26 +02:00
try
{
xStorage - > copyToStorage ( xTempStorage ) ;
} catch ( const uno : : Exception & e )
{
throw embed : : StorageWrappedTargetException (
2014-05-26 14:29:07 +02:00
" Can't copy storage! " ,
2012-08-23 17:23:26 +02:00
uno : : Reference < uno : : XInterface > ( ) ,
uno : : makeAny ( e ) ) ;
}
try {
uno : : Reference < lang : : XComponent > xComponent ( xTempStorage , uno : : UNO_QUERY ) ;
2013-05-27 00:22:20 +03:00
SAL_WARN_IF ( ! xComponent . is ( ) , " embeddedobj.common " , " Wrong storage implementation! " ) ;
2012-08-23 17:23:26 +02:00
if ( xComponent . is ( ) )
xComponent - > dispose ( ) ;
}
catch ( const uno : : Exception & )
{
}
2003-10-27 12:05:38 +00:00
2012-08-23 17:23:26 +02:00
try {
uno : : Reference < io : : XOutputStream > xTempOut = xTempStream - > getOutputStream ( ) ;
if ( xTempOut . is ( ) )
xTempOut - > closeOutput ( ) ;
}
catch ( const uno : : Exception & )
{
2003-10-27 12:05:38 +00:00
}
2012-08-23 17:23:26 +02:00
xResult = xTempStream - > getInputStream ( ) ;
2003-10-27 12:05:38 +00:00
return xResult ;
}
2014-02-22 21:20:15 +01:00
2010-01-27 10:53:30 +01:00
static void TransferMediaType ( const uno : : Reference < embed : : XStorage > & i_rSource , const uno : : Reference < embed : : XStorage > & i_rTarget )
{
try
{
const uno : : Reference < beans : : XPropertySet > xSourceProps ( i_rSource , uno : : UNO_QUERY_THROW ) ;
const uno : : Reference < beans : : XPropertySet > xTargetProps ( i_rTarget , uno : : UNO_QUERY_THROW ) ;
2013-04-07 12:06:47 +02:00
const OUString sMediaTypePropName ( " MediaType " ) ;
2010-01-27 10:53:30 +01:00
xTargetProps - > setPropertyValue ( sMediaTypePropName , xSourceProps - > getPropertyValue ( sMediaTypePropName ) ) ;
}
catch ( const uno : : Exception & )
{
DBG_UNHANDLED_EXCEPTION ( ) ;
}
}
2014-02-22 21:20:15 +01:00
2013-01-08 15:29:57 +02:00
static uno : : Reference < util : : XCloseable > CreateDocument ( const uno : : Reference < uno : : XComponentContext > & _rxContext ,
2013-04-07 12:06:47 +02:00
const OUString & _rDocumentServiceName , bool _bEmbeddedScriptSupport , const bool i_bDocumentRecoverySupport )
2008-03-06 18:30:56 +00:00
{
2010-01-06 21:34:53 +01:00
: : comphelper : : NamedValueCollection aArguments ;
2014-04-17 11:39:18 +02:00
aArguments . put ( " EmbeddedObject " , true ) ;
aArguments . put ( " EmbeddedScriptSupport " , _bEmbeddedScriptSupport ) ;
aArguments . put ( " DocumentRecoverySupport " , i_bDocumentRecoverySupport ) ;
2008-03-06 18:30:56 +00:00
uno : : Reference < uno : : XInterface > xDocument ;
try
{
2013-01-08 15:29:57 +02:00
xDocument = _rxContext - > getServiceManager ( ) - > createInstanceWithArgumentsAndContext (
_rDocumentServiceName , aArguments . getWrappedPropertyValues ( ) , _rxContext ) ;
2008-03-06 18:30:56 +00:00
}
catch ( const uno : : Exception & )
{
2010-08-19 09:18:38 +02:00
// if an embedded object implementation does not support XInitialization,
// the default factory from cppuhelper will throw an
2008-03-06 18:30:56 +00:00
// IllegalArgumentException when we try to create the instance with arguments.
// Okay, so we fall back to creating the instance without any arguments.
2014-01-28 07:57:32 +01:00
OSL_FAIL ( " Consider implementing interface XInitialization to avoid duplicate construction " ) ;
2013-01-08 15:29:57 +02:00
xDocument = _rxContext - > getServiceManager ( ) - > createInstanceWithContext ( _rDocumentServiceName , _rxContext ) ;
2008-03-06 18:30:56 +00:00
}
2013-09-24 11:55:58 +02:00
SAL_WARN_IF ( ! xDocument . is ( ) , " embeddedobj.common " , " Service " < < _rDocumentServiceName < < " is not available? " ) ;
2008-03-06 18:30:56 +00:00
return uno : : Reference < util : : XCloseable > ( xDocument , uno : : UNO_QUERY ) ;
}
2014-02-22 21:20:15 +01:00
2015-03-09 16:52:13 +00:00
static void SetDocToEmbedded ( const uno : : Reference < frame : : XModel > & rDocument , const OUString & aModuleName )
2004-10-04 18:49:49 +00:00
{
2015-03-09 16:52:13 +00:00
if ( rDocument . is ( ) )
2004-10-04 18:49:49 +00:00
{
uno : : Sequence < beans : : PropertyValue > aSeq ( 1 ) ;
2013-11-15 11:05:19 +02:00
aSeq [ 0 ] . Name = " SetEmbedded " ;
2016-04-20 17:16:42 +02:00
aSeq [ 0 ] . Value < < = true ;
2015-03-09 16:52:13 +00:00
rDocument - > attachResource ( OUString ( ) , aSeq ) ;
2007-04-16 15:50:13 +00:00
2011-12-21 19:54:11 -02:00
if ( ! aModuleName . isEmpty ( ) )
2007-04-16 15:50:13 +00:00
{
try
{
2015-03-09 16:52:13 +00:00
uno : : Reference < frame : : XModule > xModule ( rDocument , uno : : UNO_QUERY_THROW ) ;
2007-04-16 15:50:13 +00:00
xModule - > setIdentifier ( aModuleName ) ;
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2007-04-16 15:50:13 +00:00
{ }
}
2004-10-04 18:49:49 +00:00
}
}
2014-02-22 21:20:15 +01:00
2003-11-25 12:21:47 +00:00
void OCommonEmbeddedObject : : SwitchOwnPersistence ( const uno : : Reference < embed : : XStorage > & xNewParentStorage ,
const uno : : Reference < embed : : XStorage > & xNewObjectStorage ,
2013-04-07 12:06:47 +02:00
const OUString & aNewName )
2003-11-25 12:21:47 +00:00
{
2004-10-04 18:49:49 +00:00
if ( xNewParentStorage = = m_xParentStorage & & aNewName . equals ( m_aEntryName ) )
{
2013-05-27 00:22:20 +03:00
SAL_WARN_IF ( xNewObjectStorage ! = m_xObjectStorage , " embeddedobj.common " , " The storage must be the same! " ) ;
2004-10-04 18:49:49 +00:00
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 ;
2006-10-06 09:37:30 +00:00
// the linked document should not be switched
if ( ! m_bIsLink )
{
uno : : Reference < document : : XStorageBasedDocument > xDoc ( m_pDocHolder - > GetComponent ( ) , uno : : UNO_QUERY ) ;
if ( xDoc . is ( ) )
autorecovery: save/recover forms and reports
Still some lose ends. Most notably, the current code contains cases for other sub component types,
but has no real implementation - attempting to save/recover those other types will yield multiple
assertions only. Also, recovery of SRB-reports has not been tested, yet, chances are good there's
some work ahead here.
Other known open issues:
- recovering sub components immediately shows them, instead of initially hiding them, and showing
only when the main document window is shown
- the implementation currently is no real session save, which would require saving information about
*unmodified* open sub components (though not their actual content), and restoring them upon
recovery.
- doing an implicit "connect" at the controller of the to-be-recovered database document is a requirement
to actually load the sub components, but might yield problems in case this requires interaction
(e.g. a login). Need to investigate
- the "recovery" storage is not removed from the database document storage after un/successful recovery
- cancelling the recovery of a "modified" database document always suggests to store this doc somewhere
2010-01-15 15:21:15 +01:00
SwitchDocToStorage_Impl ( xDoc , m_xObjectStorage ) ;
2006-10-06 09:37:30 +00:00
}
2004-10-04 18:49:49 +00:00
2003-11-25 12:21:47 +00:00
try {
if ( xComponent . is ( ) )
xComponent - > dispose ( ) ;
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2003-11-25 12:21:47 +00:00
{
}
}
2014-02-22 21:20:15 +01:00
2003-11-25 12:21:47 +00:00
void OCommonEmbeddedObject : : SwitchOwnPersistence ( const uno : : Reference < embed : : XStorage > & xNewParentStorage ,
2013-04-07 12:06:47 +02:00
const OUString & aNewName )
2003-11-25 12:21:47 +00:00
{
2004-10-04 18:49:49 +00:00
if ( xNewParentStorage = = m_xParentStorage & & aNewName . equals ( m_aEntryName ) )
return ;
2004-05-10 16:51:24 +00:00
sal_Int32 nStorageMode = m_bReadOnly ? embed : : ElementModes : : READ : embed : : ElementModes : : READWRITE ;
2003-11-25 12:21:47 +00:00
uno : : Reference < embed : : XStorage > xNewOwnStorage = xNewParentStorage - > openStorageElement ( aNewName , nStorageMode ) ;
2013-05-27 00:22:20 +03:00
SAL_WARN_IF ( ! xNewOwnStorage . is ( ) , " embeddedobj.common " , " The method can not return empty reference! " ) ;
2003-11-25 12:21:47 +00:00
SwitchOwnPersistence ( xNewParentStorage , xNewOwnStorage , aNewName ) ;
}
2014-02-22 21:20:15 +01:00
2010-01-27 10:53:30 +01:00
void OCommonEmbeddedObject : : EmbedAndReparentDoc_Impl ( const uno : : Reference < util : : XCloseable > & i_rxDocument ) const
{
SetDocToEmbedded ( uno : : Reference < frame : : XModel > ( i_rxDocument , uno : : UNO_QUERY ) , m_aModuleName ) ;
try
{
uno : : Reference < container : : XChild > xChild ( i_rxDocument , uno : : UNO_QUERY ) ;
if ( xChild . is ( ) )
xChild - > setParent ( m_xParent ) ;
}
catch ( const lang : : NoSupportException & )
{
2013-05-27 00:22:20 +03:00
SAL_WARN ( " embeddedobj.common " , " OCommonEmbeddedObject::EmbedAndReparentDoc: cannot set parent at document! " ) ;
2010-01-27 10:53:30 +01:00
}
}
2014-02-22 21:20:15 +01:00
2004-10-04 18:49:49 +00:00
uno : : Reference < util : : XCloseable > OCommonEmbeddedObject : : InitNewDocument_Impl ( )
2003-10-27 12:05:38 +00:00
{
2013-01-08 15:29:57 +02:00
uno : : Reference < util : : XCloseable > xDocument ( CreateDocument ( m_xContext , GetDocumentServiceName ( ) ,
2010-01-06 21:34:53 +01:00
m_bEmbeddedScriptSupport , m_bDocumentRecoverySupport ) ) ;
2003-10-27 12:05:38 +00:00
2004-10-04 18:49:49 +00:00
uno : : Reference < frame : : XModel > xModel ( xDocument , uno : : UNO_QUERY ) ;
uno : : Reference < frame : : XLoadable > xLoadable ( xModel , uno : : UNO_QUERY ) ;
2003-10-27 12:05:38 +00:00
if ( ! xLoadable . is ( ) )
throw uno : : RuntimeException ( ) ;
try
{
2007-11-01 16:50:22 +00:00
// set the document mode to embedded as the first action on document!!!
2010-01-27 10:53:30 +01:00
EmbedAndReparentDoc_Impl ( xDocument ) ;
2004-10-04 18:49:49 +00:00
2010-01-27 10:53:30 +01:00
// if we have a storage to recover the document from, do not use initNew, but instead load from that storage
bool bInitNew = true ;
if ( m_xRecoveryStorage . is ( ) )
2007-11-01 16:50:22 +00:00
{
2010-01-27 10:53:30 +01:00
uno : : Reference < document : : XStorageBasedDocument > xDoc ( xLoadable , uno : : UNO_QUERY ) ;
2013-05-27 00:22:20 +03:00
SAL_WARN_IF ( ! xDoc . is ( ) , " embeddedobj.common " , " OCommonEmbeddedObject::InitNewDocument_Impl: cannot recover from a storage when the document is not storage based! " ) ;
2010-01-27 10:53:30 +01:00
if ( xDoc . is ( ) )
{
: : comphelper : : NamedValueCollection aLoadArgs ;
FillDefaultLoadArgs_Impl ( m_xRecoveryStorage , aLoadArgs ) ;
xDoc - > loadFromStorage ( m_xRecoveryStorage , aLoadArgs . getPropertyValues ( ) ) ;
SwitchDocToStorage_Impl ( xDoc , m_xObjectStorage ) ;
bInitNew = false ;
}
2007-11-01 16:50:22 +00:00
}
2010-01-27 10:53:30 +01:00
if ( bInitNew )
2007-11-01 16:50:22 +00:00
{
2010-01-27 10:53:30 +01:00
// init document as a new
xLoadable - > initNew ( ) ;
2007-11-01 16:50:22 +00:00
}
2010-02-09 23:10:16 +01:00
xModel - > attachResource ( xModel - > getURL ( ) , m_aDocMediaDescriptor ) ;
2003-10-27 12:05:38 +00:00
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2003-10-27 12:05:38 +00:00
{
uno : : Reference < util : : XCloseable > xCloseable ( xDocument , uno : : UNO_QUERY ) ;
if ( xCloseable . is ( ) )
{
try
{
2016-04-20 17:16:42 +02:00
xCloseable - > close ( true ) ;
2003-10-27 12:05:38 +00:00
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2003-10-27 12:05:38 +00:00
{
}
}
throw ; // TODO
}
return xDocument ;
}
2014-02-22 21:20:15 +01:00
2004-10-04 18:49:49 +00:00
uno : : Reference < util : : XCloseable > OCommonEmbeddedObject : : LoadLink_Impl ( )
2003-10-27 12:05:38 +00:00
{
2013-01-08 15:29:57 +02:00
uno : : Reference < util : : XCloseable > xDocument ( CreateDocument ( m_xContext , GetDocumentServiceName ( ) ,
2010-01-06 21:34:53 +01:00
m_bEmbeddedScriptSupport , m_bDocumentRecoverySupport ) ) ;
2003-10-27 12:05:38 +00:00
uno : : Reference < frame : : XLoadable > xLoadable ( xDocument , uno : : UNO_QUERY ) ;
if ( ! xLoadable . is ( ) )
throw uno : : RuntimeException ( ) ;
2005-01-31 08:01:35 +00:00
sal_Int32 nLen = 2 ;
uno : : Sequence < beans : : PropertyValue > aArgs ( nLen ) ;
2013-11-15 11:05:19 +02:00
aArgs [ 0 ] . Name = " URL " ;
2003-10-27 12:05:38 +00:00
aArgs [ 0 ] . Value < < = m_aLinkURL ;
2013-11-15 11:05:19 +02:00
aArgs [ 1 ] . Name = " FilterName " ;
2003-10-27 12:05:38 +00:00
aArgs [ 1 ] . Value < < = m_aLinkFilterName ;
2005-01-31 08:01:35 +00:00
if ( m_bLinkHasPassword )
{
aArgs . realloc ( + + nLen ) ;
2013-11-15 11:05:19 +02:00
aArgs [ nLen - 1 ] . Name = " Password " ;
2005-01-31 08:01:35 +00:00
aArgs [ nLen - 1 ] . Value < < = m_aLinkPassword ;
}
aArgs . realloc ( m_aDocMediaDescriptor . getLength ( ) + nLen ) ;
for ( sal_Int32 nInd = 0 ; nInd < m_aDocMediaDescriptor . getLength ( ) ; nInd + + )
{
aArgs [ nInd + nLen ] . Name = m_aDocMediaDescriptor [ nInd ] . Name ;
aArgs [ nInd + nLen ] . Value = m_aDocMediaDescriptor [ nInd ] . Value ;
}
2003-10-27 12:05:38 +00:00
try
{
2004-10-04 18:49:49 +00:00
// the document is not really an embedded one, it is a link
2010-01-27 10:53:30 +01:00
EmbedAndReparentDoc_Impl ( xDocument ) ;
2007-11-01 16:50:22 +00:00
2004-10-04 18:49:49 +00:00
// load the document
2003-10-27 12:05:38 +00:00
xLoadable - > load ( aArgs ) ;
2005-01-31 08:01:35 +00:00
if ( ! m_bLinkHasPassword )
{
// check if there is a password to cache
uno : : Reference < frame : : XModel > xModel ( xLoadable , uno : : UNO_QUERY_THROW ) ;
uno : : Sequence < beans : : PropertyValue > aProps = xModel - > getArgs ( ) ;
for ( sal_Int32 nInd = 0 ; nInd < aProps . getLength ( ) ; nInd + + )
2012-04-06 14:09:04 +02:00
if ( aProps [ nInd ] . Name = = " Password " & & ( aProps [ nInd ] . Value > > = m_aLinkPassword ) )
2005-01-31 08:01:35 +00:00
{
2014-04-17 11:39:18 +02:00
m_bLinkHasPassword = true ;
2005-01-31 08:01:35 +00:00
break ;
}
}
2003-10-27 12:05:38 +00:00
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2003-10-27 12:05:38 +00:00
{
uno : : Reference < util : : XCloseable > xCloseable ( xDocument , uno : : UNO_QUERY ) ;
if ( xCloseable . is ( ) )
{
try
{
2016-04-20 17:16:42 +02:00
xCloseable - > close ( true ) ;
2003-10-27 12:05:38 +00:00
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2003-10-27 12:05:38 +00:00
{
}
}
throw ; // TODO
}
return xDocument ;
}
2014-02-22 21:20:15 +01:00
2013-04-07 12:06:47 +02:00
OUString OCommonEmbeddedObject : : GetFilterName ( sal_Int32 nVersion ) const
2008-03-05 17:25:21 +00:00
{
2013-04-07 12:06:47 +02:00
OUString aFilterName = GetPresetFilterName ( ) ;
2011-12-21 19:54:11 -02:00
if ( aFilterName . isEmpty ( ) )
2008-03-05 17:25:21 +00:00
{
try {
2013-01-08 15:29:57 +02:00
: : comphelper : : MimeConfigurationHelper aHelper ( m_xContext ) ;
2008-03-05 17:25:21 +00:00
aFilterName = aHelper . GetDefaultFilterFromServiceName ( GetDocumentServiceName ( ) , nVersion ) ;
2015-05-04 15:50:02 +02:00
// If no filter is found, fall back to the FileFormatVersion=6200 filter, Base only has that.
if ( aFilterName . isEmpty ( ) & & nVersion = = SOFFICE_FILEFORMAT_CURRENT )
aFilterName = aHelper . GetDefaultFilterFromServiceName ( GetDocumentServiceName ( ) , SOFFICE_FILEFORMAT_60 ) ;
2011-12-09 02:56:30 +09:00
} catch ( const uno : : Exception & )
2008-03-05 17:25:21 +00:00
{ }
}
return aFilterName ;
}
2014-02-22 21:20:15 +01:00
2010-01-27 10:53:30 +01:00
void OCommonEmbeddedObject : : FillDefaultLoadArgs_Impl ( const uno : : Reference < embed : : XStorage > & i_rxStorage ,
: : comphelper : : NamedValueCollection & o_rLoadArgs ) const
{
o_rLoadArgs . put ( " DocumentBaseURL " , GetBaseURL_Impl ( ) ) ;
o_rLoadArgs . put ( " HierarchicalDocumentName " , m_aEntryName ) ;
o_rLoadArgs . put ( " ReadOnly " , m_bReadOnly ) ;
2013-04-07 12:06:47 +02:00
OUString aFilterName = GetFilterName ( : : comphelper : : OStorageHelper : : GetXStorageFormat ( i_rxStorage ) ) ;
2013-05-27 00:22:20 +03:00
SAL_WARN_IF ( aFilterName . isEmpty ( ) , " embeddedobj.common " , " OCommonEmbeddedObject::FillDefaultLoadArgs_Impl: Wrong document service name! " ) ;
2011-12-21 19:54:11 -02:00
if ( aFilterName . isEmpty ( ) )
2010-01-27 10:53:30 +01:00
throw io : : IOException ( ) ; // TODO: error message/code
o_rLoadArgs . put ( " FilterName " , aFilterName ) ;
}
2014-02-22 21:20:15 +01:00
autorecovery: save/recover forms and reports
Still some lose ends. Most notably, the current code contains cases for other sub component types,
but has no real implementation - attempting to save/recover those other types will yield multiple
assertions only. Also, recovery of SRB-reports has not been tested, yet, chances are good there's
some work ahead here.
Other known open issues:
- recovering sub components immediately shows them, instead of initially hiding them, and showing
only when the main document window is shown
- the implementation currently is no real session save, which would require saving information about
*unmodified* open sub components (though not their actual content), and restoring them upon
recovery.
- doing an implicit "connect" at the controller of the to-be-recovered database document is a requirement
to actually load the sub components, but might yield problems in case this requires interaction
(e.g. a login). Need to investigate
- the "recovery" storage is not removed from the database document storage after un/successful recovery
- cancelling the recovery of a "modified" database document always suggests to store this doc somewhere
2010-01-15 15:21:15 +01:00
uno : : Reference < util : : XCloseable > OCommonEmbeddedObject : : LoadDocumentFromStorage_Impl ( )
2003-10-27 12:05:38 +00:00
{
2010-01-27 10:53:30 +01:00
ENSURE_OR_THROW ( m_xObjectStorage . is ( ) , " no object storage " ) ;
const uno : : Reference < embed : : XStorage > xSourceStorage ( m_xRecoveryStorage . is ( ) ? m_xRecoveryStorage : m_xObjectStorage ) ;
2003-10-27 12:05:38 +00:00
2013-01-08 15:29:57 +02:00
uno : : Reference < util : : XCloseable > xDocument ( CreateDocument ( m_xContext , GetDocumentServiceName ( ) ,
2010-01-06 21:34:53 +01:00
m_bEmbeddedScriptSupport , m_bDocumentRecoverySupport ) ) ;
2005-11-10 15:28:54 +00:00
2009-09-14 10:57:16 +00:00
//#i103460# ODF: take the size given from the parent frame as default
uno : : Reference < chart2 : : XChartDocument > xChart ( xDocument , uno : : UNO_QUERY ) ;
if ( xChart . is ( ) )
{
uno : : Reference < embed : : XVisualObject > xChartVisualObject ( xChart , uno : : UNO_QUERY ) ;
if ( xChartVisualObject . is ( ) )
xChartVisualObject - > setVisualAreaSize ( embed : : Aspects : : MSOLE_CONTENT , m_aDefaultSizeForChart_In_100TH_MM ) ;
}
2003-10-27 12:05:38 +00:00
uno : : Reference < frame : : XLoadable > xLoadable ( xDocument , uno : : UNO_QUERY ) ;
2013-05-06 10:47:20 +03:00
uno : : Reference < document : : XStorageBasedDocument > xDoc ( xDocument , uno : : UNO_QUERY ) ;
2007-07-06 09:06:51 +00:00
if ( ! xDoc . is ( ) & & ! xLoadable . is ( ) ) ///BUG: This should be || instead of && ?
2003-10-27 12:05:38 +00:00
throw uno : : RuntimeException ( ) ;
2010-01-27 10:53:30 +01:00
: : comphelper : : NamedValueCollection aLoadArgs ;
FillDefaultLoadArgs_Impl ( xSourceStorage , aLoadArgs ) ;
2004-10-13 17:03:30 +00:00
uno : : Reference < io : : XInputStream > xTempInpStream ;
2004-10-04 18:49:49 +00:00
if ( ! xDoc . is ( ) )
{
2013-01-08 15:29:57 +02:00
xTempInpStream = createTempInpStreamFromStor ( xSourceStorage , m_xContext ) ;
2004-10-04 18:49:49 +00:00
if ( ! xTempInpStream . is ( ) )
throw uno : : RuntimeException ( ) ;
2013-04-07 12:06:47 +02:00
OUString aTempFileURL ;
2004-10-04 18:49:49 +00:00
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 ) ;
2013-06-29 21:24:12 +02:00
xTempStreamProps - > getPropertyValue ( " Uri " ) > > = aTempFileURL ;
2004-10-04 18:49:49 +00:00
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2004-10-04 18:49:49 +00:00
{
}
2015-06-23 09:58:19 +02:00
SAL_WARN_IF ( aTempFileURL . isEmpty ( ) , " embeddedobj.common " , " Couldn't retrieve temporary file URL! " ) ;
2004-10-04 18:49:49 +00:00
2010-01-27 10:53:30 +01:00
aLoadArgs . put ( " URL " , aTempFileURL ) ;
aLoadArgs . put ( " InputStream " , xTempInpStream ) ;
2004-10-04 18:49:49 +00:00
}
2003-10-27 12:05:38 +00:00
2010-01-27 10:53:30 +01:00
aLoadArgs . merge ( m_aDocMediaDescriptor , true ) ;
2004-05-10 16:51:24 +00:00
2003-10-27 12:05:38 +00:00
try
{
2007-11-01 16:50:22 +00:00
// set the document mode to embedded as the first step!!!
2010-01-27 10:53:30 +01:00
EmbedAndReparentDoc_Impl ( xDocument ) ;
2007-11-01 16:50:22 +00:00
2004-10-04 18:49:49 +00:00
if ( xDoc . is ( ) )
autorecovery: save/recover forms and reports
Still some lose ends. Most notably, the current code contains cases for other sub component types,
but has no real implementation - attempting to save/recover those other types will yield multiple
assertions only. Also, recovery of SRB-reports has not been tested, yet, chances are good there's
some work ahead here.
Other known open issues:
- recovering sub components immediately shows them, instead of initially hiding them, and showing
only when the main document window is shown
- the implementation currently is no real session save, which would require saving information about
*unmodified* open sub components (though not their actual content), and restoring them upon
recovery.
- doing an implicit "connect" at the controller of the to-be-recovered database document is a requirement
to actually load the sub components, but might yield problems in case this requires interaction
(e.g. a login). Need to investigate
- the "recovery" storage is not removed from the database document storage after un/successful recovery
- cancelling the recovery of a "modified" database document always suggests to store this doc somewhere
2010-01-15 15:21:15 +01:00
{
2010-01-27 10:53:30 +01:00
xDoc - > loadFromStorage ( xSourceStorage , aLoadArgs . getPropertyValues ( ) ) ;
if ( xSourceStorage ! = m_xObjectStorage )
autorecovery: save/recover forms and reports
Still some lose ends. Most notably, the current code contains cases for other sub component types,
but has no real implementation - attempting to save/recover those other types will yield multiple
assertions only. Also, recovery of SRB-reports has not been tested, yet, chances are good there's
some work ahead here.
Other known open issues:
- recovering sub components immediately shows them, instead of initially hiding them, and showing
only when the main document window is shown
- the implementation currently is no real session save, which would require saving information about
*unmodified* open sub components (though not their actual content), and restoring them upon
recovery.
- doing an implicit "connect" at the controller of the to-be-recovered database document is a requirement
to actually load the sub components, but might yield problems in case this requires interaction
(e.g. a login). Need to investigate
- the "recovery" storage is not removed from the database document storage after un/successful recovery
- cancelling the recovery of a "modified" database document always suggests to store this doc somewhere
2010-01-15 15:21:15 +01:00
SwitchDocToStorage_Impl ( xDoc , m_xObjectStorage ) ;
}
2004-10-04 18:49:49 +00:00
else
2010-01-27 10:53:30 +01:00
xLoadable - > load ( aLoadArgs . getPropertyValues ( ) ) ;
2003-10-27 12:05:38 +00:00
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2003-10-27 12:05:38 +00:00
{
uno : : Reference < util : : XCloseable > xCloseable ( xDocument , uno : : UNO_QUERY ) ;
if ( xCloseable . is ( ) )
{
try
{
2016-04-20 17:16:42 +02:00
xCloseable - > close ( true ) ;
2003-10-27 12:05:38 +00:00
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2003-10-27 12:05:38 +00:00
{
2010-01-27 10:53:30 +01:00
DBG_UNHANDLED_EXCEPTION ( ) ;
2003-10-27 12:05:38 +00:00
}
}
throw ; // TODO
}
return xDocument ;
}
2014-02-22 21:20:15 +01:00
2004-10-04 18:49:49 +00:00
uno : : Reference < io : : XInputStream > OCommonEmbeddedObject : : StoreDocumentToTempStream_Impl (
sal_Int32 nStorageFormat ,
2013-04-07 12:06:47 +02:00
const OUString & aBaseURL ,
const OUString & aHierarchName )
2003-10-27 12:05:38 +00:00
{
uno : : Reference < io : : XOutputStream > xTempOut (
2013-01-08 15:29:57 +02:00
io : : TempFile : : create ( m_xContext ) ,
2012-08-23 17:23:26 +02:00
uno : : UNO_QUERY_THROW ) ;
2003-10-27 12:05:38 +00:00
uno : : Reference < io : : XInputStream > aResult ( xTempOut , uno : : UNO_QUERY ) ;
2012-08-23 17:23:26 +02:00
if ( ! aResult . is ( ) )
2003-10-27 12:05:38 +00:00
throw uno : : RuntimeException ( ) ; // TODO:
2005-10-27 12:58:41 +00:00
uno : : Reference < frame : : XStorable > xStorable ;
{
osl : : MutexGuard aGuard ( m_aMutex ) ;
if ( m_pDocHolder )
2015-10-30 14:22:53 +02:00
xStorable . set ( m_pDocHolder - > GetComponent ( ) , uno : : UNO_QUERY ) ;
2005-10-27 12:58:41 +00:00
}
2003-10-27 12:05:38 +00:00
if ( ! xStorable . is ( ) )
throw uno : : RuntimeException ( ) ; // TODO:
2013-04-07 12:06:47 +02:00
OUString aFilterName = GetFilterName ( nStorageFormat ) ;
2004-10-04 18:49:49 +00:00
2013-05-27 00:22:20 +03:00
SAL_WARN_IF ( aFilterName . isEmpty ( ) , " embeddedobj.common " , " Wrong document service name! " ) ;
2011-12-21 19:54:11 -02:00
if ( aFilterName . isEmpty ( ) )
2004-10-04 18:49:49 +00:00
throw io : : IOException ( ) ; // TODO:
2003-10-27 12:05:38 +00:00
2004-10-04 18:49:49 +00:00
uno : : Sequence < beans : : PropertyValue > aArgs ( 4 ) ;
2013-11-15 11:05:19 +02:00
aArgs [ 0 ] . Name = " FilterName " ;
2003-10-27 12:05:38 +00:00
aArgs [ 0 ] . Value < < = aFilterName ;
2013-11-15 11:05:19 +02:00
aArgs [ 1 ] . Name = " OutputStream " ;
2003-10-27 12:05:38 +00:00
aArgs [ 1 ] . Value < < = xTempOut ;
2013-11-15 11:05:19 +02:00
aArgs [ 2 ] . Name = " DocumentBaseURL " ;
2004-10-04 18:49:49 +00:00
aArgs [ 2 ] . Value < < = aBaseURL ;
2013-11-15 11:05:19 +02:00
aArgs [ 3 ] . Name = " HierarchicalDocumentName " ;
2004-10-04 18:49:49 +00:00
aArgs [ 3 ] . Value < < = aHierarchName ;
2003-10-27 12:05:38 +00:00
2015-11-04 08:29:36 +02:00
xStorable - > storeToURL ( " private:stream " , aArgs ) ;
2003-10-27 12:05:38 +00:00
try
{
xTempOut - > closeOutput ( ) ;
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2003-10-27 12:05:38 +00:00
{
2013-05-27 00:22:20 +03:00
SAL_WARN ( " embeddedobj.common " , " Looks like stream was closed already " ) ;
2003-10-27 12:05:38 +00:00
}
return aResult ;
}
2014-02-22 21:20:15 +01:00
2003-10-27 12:05:38 +00:00
void OCommonEmbeddedObject : : SaveObject_Impl ( )
{
if ( m_xClientSite . is ( ) )
{
2007-05-22 18:35:24 +00:00
try
{
// check whether the component is modified,
// if not there is no need for storing
uno : : Reference < util : : XModifiable > xModifiable ( m_pDocHolder - > GetComponent ( ) , uno : : UNO_QUERY ) ;
if ( xModifiable . is ( ) & & ! xModifiable - > isModified ( ) )
return ;
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2007-05-22 18:35:24 +00:00
{ }
2003-10-27 12:05:38 +00:00
try {
m_xClientSite - > saveObject ( ) ;
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2003-10-27 12:05:38 +00:00
{
2013-05-27 00:22:20 +03:00
SAL_WARN ( " embeddedobj.common " , " The object was not stored! " ) ;
2003-10-27 12:05:38 +00:00
}
}
}
2014-02-22 21:20:15 +01:00
2013-04-07 12:06:47 +02:00
OUString OCommonEmbeddedObject : : GetBaseURL_Impl ( ) const
2004-10-04 18:49:49 +00:00
{
2013-04-07 12:06:47 +02:00
OUString aBaseURL ;
2004-10-04 18:49:49 +00:00
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 + + )
2014-12-18 13:23:46 +01:00
if ( aModelProps [ nInd ] . Name = = " DocumentBaseURL " )
2004-10-04 18:49:49 +00:00
{
aModelProps [ nInd ] . Value > > = aBaseURL ;
break ;
}
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2004-10-04 18:49:49 +00:00
{ }
}
2011-12-21 19:54:11 -02:00
if ( aBaseURL . isEmpty ( ) )
2004-10-04 18:49:49 +00:00
{
for ( nInd = 0 ; nInd < m_aDocMediaDescriptor . getLength ( ) ; nInd + + )
2014-12-18 13:23:46 +01:00
if ( m_aDocMediaDescriptor [ nInd ] . Name = = " DocumentBaseURL " )
2004-10-04 18:49:49 +00:00
{
m_aDocMediaDescriptor [ nInd ] . Value > > = aBaseURL ;
break ;
}
}
2011-12-21 19:54:11 -02:00
if ( aBaseURL . isEmpty ( ) )
2004-10-04 18:49:49 +00:00
aBaseURL = m_aDefaultParentBaseURL ;
return aBaseURL ;
}
2014-02-22 21:20:15 +01:00
2013-04-07 12:06:47 +02:00
OUString OCommonEmbeddedObject : : GetBaseURLFrom_Impl (
2004-10-04 18:49:49 +00:00
const uno : : Sequence < beans : : PropertyValue > & lArguments ,
const uno : : Sequence < beans : : PropertyValue > & lObjArgs )
{
2013-04-07 12:06:47 +02:00
OUString aBaseURL ;
2004-10-04 18:49:49 +00:00
sal_Int32 nInd = 0 ;
for ( nInd = 0 ; nInd < lArguments . getLength ( ) ; nInd + + )
2012-04-06 14:09:04 +02:00
if ( lArguments [ nInd ] . Name = = " DocumentBaseURL " )
2004-10-04 18:49:49 +00:00
{
lArguments [ nInd ] . Value > > = aBaseURL ;
break ;
}
2011-12-21 19:54:11 -02:00
if ( aBaseURL . isEmpty ( ) )
2004-10-04 18:49:49 +00:00
{
for ( nInd = 0 ; nInd < lObjArgs . getLength ( ) ; nInd + + )
2012-04-06 14:09:04 +02:00
if ( lObjArgs [ nInd ] . Name = = " DefaultParentBaseURL " )
2004-10-04 18:49:49 +00:00
{
lObjArgs [ nInd ] . Value > > = aBaseURL ;
break ;
}
}
return aBaseURL ;
}
autorecovery: save/recover forms and reports
Still some lose ends. Most notably, the current code contains cases for other sub component types,
but has no real implementation - attempting to save/recover those other types will yield multiple
assertions only. Also, recovery of SRB-reports has not been tested, yet, chances are good there's
some work ahead here.
Other known open issues:
- recovering sub components immediately shows them, instead of initially hiding them, and showing
only when the main document window is shown
- the implementation currently is no real session save, which would require saving information about
*unmodified* open sub components (though not their actual content), and restoring them upon
recovery.
- doing an implicit "connect" at the controller of the to-be-recovered database document is a requirement
to actually load the sub components, but might yield problems in case this requires interaction
(e.g. a login). Need to investigate
- the "recovery" storage is not removed from the database document storage after un/successful recovery
- cancelling the recovery of a "modified" database document always suggests to store this doc somewhere
2010-01-15 15:21:15 +01:00
void OCommonEmbeddedObject : : SwitchDocToStorage_Impl ( const uno : : Reference < document : : XStorageBasedDocument > & xDoc , const uno : : Reference < embed : : XStorage > & xStorage )
{
xDoc - > switchToStorage ( xStorage ) ;
2010-01-26 13:19:11 +01:00
autorecovery: save/recover forms and reports
Still some lose ends. Most notably, the current code contains cases for other sub component types,
but has no real implementation - attempting to save/recover those other types will yield multiple
assertions only. Also, recovery of SRB-reports has not been tested, yet, chances are good there's
some work ahead here.
Other known open issues:
- recovering sub components immediately shows them, instead of initially hiding them, and showing
only when the main document window is shown
- the implementation currently is no real session save, which would require saving information about
*unmodified* open sub components (though not their actual content), and restoring them upon
recovery.
- doing an implicit "connect" at the controller of the to-be-recovered database document is a requirement
to actually load the sub components, but might yield problems in case this requires interaction
(e.g. a login). Need to investigate
- the "recovery" storage is not removed from the database document storage after un/successful recovery
- cancelling the recovery of a "modified" database document always suggests to store this doc somewhere
2010-01-15 15:21:15 +01:00
uno : : Reference < util : : XModifiable > xModif ( xDoc , uno : : UNO_QUERY ) ;
if ( xModif . is ( ) )
2016-04-20 17:16:42 +02:00
xModif - > setModified ( false ) ;
autorecovery: save/recover forms and reports
Still some lose ends. Most notably, the current code contains cases for other sub component types,
but has no real implementation - attempting to save/recover those other types will yield multiple
assertions only. Also, recovery of SRB-reports has not been tested, yet, chances are good there's
some work ahead here.
Other known open issues:
- recovering sub components immediately shows them, instead of initially hiding them, and showing
only when the main document window is shown
- the implementation currently is no real session save, which would require saving information about
*unmodified* open sub components (though not their actual content), and restoring them upon
recovery.
- doing an implicit "connect" at the controller of the to-be-recovered database document is a requirement
to actually load the sub components, but might yield problems in case this requires interaction
(e.g. a login). Need to investigate
- the "recovery" storage is not removed from the database document storage after un/successful recovery
- cancelling the recovery of a "modified" database document always suggests to store this doc somewhere
2010-01-15 15:21:15 +01:00
2010-01-26 13:19:11 +01:00
if ( m_xRecoveryStorage . is ( ) )
m_xRecoveryStorage . clear ( ) ;
autorecovery: save/recover forms and reports
Still some lose ends. Most notably, the current code contains cases for other sub component types,
but has no real implementation - attempting to save/recover those other types will yield multiple
assertions only. Also, recovery of SRB-reports has not been tested, yet, chances are good there's
some work ahead here.
Other known open issues:
- recovering sub components immediately shows them, instead of initially hiding them, and showing
only when the main document window is shown
- the implementation currently is no real session save, which would require saving information about
*unmodified* open sub components (though not their actual content), and restoring them upon
recovery.
- doing an implicit "connect" at the controller of the to-be-recovered database document is a requirement
to actually load the sub components, but might yield problems in case this requires interaction
(e.g. a login). Need to investigate
- the "recovery" storage is not removed from the database document storage after un/successful recovery
- cancelling the recovery of a "modified" database document always suggests to store this doc somewhere
2010-01-15 15:21:15 +01:00
}
2014-06-13 11:12:50 -04:00
namespace {
2014-02-22 21:20:15 +01:00
2014-06-13 11:12:50 -04:00
OUString getStringPropertyValue ( const uno : : Sequence < beans : : PropertyValue > & rProps , const OUString & rName )
{
OUString aStr ;
for ( sal_Int32 i = 0 ; i < rProps . getLength ( ) ; + + i )
{
if ( rProps [ i ] . Name = = rName )
{
rProps [ i ] . Value > > = aStr ;
break ;
}
}
return aStr ;
}
}
void OCommonEmbeddedObject : : StoreDocToStorage_Impl (
const uno : : Reference < embed : : XStorage > & xStorage ,
const uno : : Sequence < beans : : PropertyValue > & rMediaArgs ,
const uno : : Sequence < beans : : PropertyValue > & rObjArgs ,
sal_Int32 nStorageFormat ,
const OUString & aHierarchName ,
bool bAttachToTheStorage )
2003-10-27 12:05:38 +00:00
{
2013-05-27 00:22:20 +03:00
SAL_WARN_IF ( ! xStorage . is ( ) , " embeddedobj.common " , " No storage is provided for storing! " ) ;
2003-10-27 12:05:38 +00:00
if ( ! xStorage . is ( ) )
throw uno : : RuntimeException ( ) ; // TODO:
2005-10-27 12:58:41 +00:00
uno : : Reference < document : : XStorageBasedDocument > xDoc ;
{
osl : : MutexGuard aGuard ( m_aMutex ) ;
if ( m_pDocHolder )
2015-10-30 14:22:53 +02:00
xDoc . set ( m_pDocHolder - > GetComponent ( ) , uno : : UNO_QUERY ) ;
2005-10-27 12:58:41 +00:00
}
2014-06-13 11:12:50 -04:00
OUString aBaseURL = GetBaseURLFrom_Impl ( rMediaArgs , rObjArgs ) ;
2004-10-04 18:49:49 +00:00
if ( xDoc . is ( ) )
{
2013-04-07 12:06:47 +02:00
OUString aFilterName = GetFilterName ( nStorageFormat ) ;
2003-10-27 12:05:38 +00:00
2015-04-30 15:21:28 +02:00
// No filter found? Try the older format, e.g. Base has only that.
if ( aFilterName . isEmpty ( ) & & nStorageFormat = = SOFFICE_FILEFORMAT_CURRENT )
aFilterName = GetFilterName ( SOFFICE_FILEFORMAT_60 ) ;
2013-05-27 00:22:20 +03:00
SAL_WARN_IF ( aFilterName . isEmpty ( ) , " embeddedobj.common " , " Wrong document service name! " ) ;
2011-12-21 19:54:11 -02:00
if ( aFilterName . isEmpty ( ) )
2004-10-04 18:49:49 +00:00
throw io : : IOException ( ) ; // TODO:
2003-10-27 12:05:38 +00:00
2014-06-13 11:12:50 -04:00
uno : : Sequence < beans : : PropertyValue > aArgs ( 5 ) ;
2013-11-15 11:05:19 +02:00
aArgs [ 0 ] . Name = " FilterName " ;
2004-10-04 18:49:49 +00:00
aArgs [ 0 ] . Value < < = aFilterName ;
2013-11-15 11:05:19 +02:00
aArgs [ 1 ] . Name = " HierarchicalDocumentName " ;
2004-10-04 18:49:49 +00:00
aArgs [ 1 ] . Value < < = aHierarchName ;
2014-06-13 11:12:50 -04:00
aArgs [ 2 ] . Name = " DocumentBaseURL " ;
aArgs [ 2 ] . Value < < = aBaseURL ;
aArgs [ 3 ] . Name = " SourceShellID " ;
aArgs [ 3 ] . Value < < = getStringPropertyValue ( rObjArgs , " SourceShellID " ) ;
aArgs [ 4 ] . Name = " DestinationShellID " ;
aArgs [ 4 ] . Value < < = getStringPropertyValue ( rObjArgs , " DestinationShellID " ) ;
2004-10-04 18:49:49 +00:00
xDoc - > storeToStorage ( xStorage , aArgs ) ;
2006-02-01 18:04:52 +00:00
if ( bAttachToTheStorage )
autorecovery: save/recover forms and reports
Still some lose ends. Most notably, the current code contains cases for other sub component types,
but has no real implementation - attempting to save/recover those other types will yield multiple
assertions only. Also, recovery of SRB-reports has not been tested, yet, chances are good there's
some work ahead here.
Other known open issues:
- recovering sub components immediately shows them, instead of initially hiding them, and showing
only when the main document window is shown
- the implementation currently is no real session save, which would require saving information about
*unmodified* open sub components (though not their actual content), and restoring them upon
recovery.
- doing an implicit "connect" at the controller of the to-be-recovered database document is a requirement
to actually load the sub components, but might yield problems in case this requires interaction
(e.g. a login). Need to investigate
- the "recovery" storage is not removed from the database document storage after un/successful recovery
- cancelling the recovery of a "modified" database document always suggests to store this doc somewhere
2010-01-15 15:21:15 +01:00
SwitchDocToStorage_Impl ( xDoc , xStorage ) ;
2004-10-04 18:49:49 +00:00
}
else
{
// store document to temporary stream based on temporary file
uno : : Reference < io : : XInputStream > xTempIn = StoreDocumentToTempStream_Impl ( nStorageFormat , aBaseURL , aHierarchName ) ;
2005-10-27 12:58:41 +00:00
2013-05-27 00:22:20 +03:00
SAL_WARN_IF ( ! xTempIn . is ( ) , " embeddedobj.common " , " The stream reference can not be empty! " ) ;
2004-10-04 18:49:49 +00:00
// open storage based on document temporary file for reading
2013-01-16 15:23:16 +02:00
uno : : Reference < lang : : XSingleServiceFactory > xStorageFactory = embed : : StorageFactory : : create ( m_xContext ) ;
2004-10-04 18:49:49 +00:00
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:
2003-10-27 12:05:38 +00:00
2014-11-10 15:05:25 +01:00
// object storage must be committed automatically
2004-10-04 18:49:49 +00:00
xTempStorage - > copyToStorage ( xStorage ) ;
}
2003-10-27 12:05:38 +00:00
}
2014-02-22 21:20:15 +01:00
2004-10-04 18:49:49 +00:00
uno : : Reference < util : : XCloseable > OCommonEmbeddedObject : : CreateDocFromMediaDescr_Impl (
2003-10-27 12:05:38 +00:00
const uno : : Sequence < beans : : PropertyValue > & aMedDescr )
{
2013-01-08 15:29:57 +02:00
uno : : Reference < util : : XCloseable > xDocument ( CreateDocument ( m_xContext , GetDocumentServiceName ( ) ,
2010-01-06 21:34:53 +01:00
m_bEmbeddedScriptSupport , m_bDocumentRecoverySupport ) ) ;
2003-10-27 12:05:38 +00:00
uno : : Reference < frame : : XLoadable > xLoadable ( xDocument , uno : : UNO_QUERY ) ;
if ( ! xLoadable . is ( ) )
throw uno : : RuntimeException ( ) ;
try
{
2007-11-01 16:50:22 +00:00
// set the document mode to embedded as the first action on the document!!!
2010-01-27 10:53:30 +01:00
EmbedAndReparentDoc_Impl ( xDocument ) ;
2007-11-01 16:50:22 +00:00
2004-10-04 18:49:49 +00:00
xLoadable - > load ( addAsTemplate ( aMedDescr ) ) ;
2003-10-27 12:05:38 +00:00
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2003-10-27 12:05:38 +00:00
{
uno : : Reference < util : : XCloseable > xCloseable ( xDocument , uno : : UNO_QUERY ) ;
if ( xCloseable . is ( ) )
{
try
{
2016-04-20 17:16:42 +02:00
xCloseable - > close ( true ) ;
2003-10-27 12:05:38 +00:00
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2003-10-27 12:05:38 +00:00
{
}
}
throw ; // TODO
}
return xDocument ;
}
2014-02-22 21:20:15 +01:00
2004-10-04 18:49:49 +00:00
uno : : Reference < util : : XCloseable > OCommonEmbeddedObject : : CreateTempDocFromLink_Impl ( )
2003-10-27 12:05:38 +00:00
{
2004-10-04 18:49:49 +00:00
uno : : Reference < util : : XCloseable > xResult ;
2003-10-27 12:05:38 +00:00
2013-05-27 00:22:20 +03:00
SAL_WARN_IF ( ! m_bIsLink , " embeddedobj.common " , " The object is not a linked one! " ) ;
2003-10-27 12:05:38 +00:00
uno : : Sequence < beans : : PropertyValue > aTempMediaDescr ;
2004-10-04 18:49:49 +00:00
sal_Int32 nStorageFormat = SOFFICE_FILEFORMAT_CURRENT ;
try {
nStorageFormat = : : comphelper : : OStorageHelper : : GetXStorageFormat ( m_xParentStorage ) ;
}
2011-12-09 02:56:30 +09:00
catch ( const beans : : IllegalTypeException & )
2004-11-26 15:15:37 +00:00
{
// the container just has an unknown type, use current file format
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2004-10-04 18:49:49 +00:00
{
2013-05-27 00:22:20 +03:00
SAL_WARN ( " embeddedobj.common " , " Can not retrieve storage media type! " ) ;
2004-10-04 18:49:49 +00:00
}
if ( m_pDocHolder - > GetComponent ( ) . is ( ) )
2003-10-27 12:05:38 +00:00
{
2005-01-18 14:08:35 +00:00
aTempMediaDescr . realloc ( 4 ) ;
2004-08-02 16:44:17 +00:00
2004-10-04 18:49:49 +00:00
// TODO/LATER: may be private:stream should be used as target URL
2013-04-07 12:06:47 +02:00
OUString aTempFileURL ;
2004-10-04 18:49:49 +00:00
uno : : Reference < io : : XInputStream > xTempStream = StoreDocumentToTempStream_Impl ( SOFFICE_FILEFORMAT_CURRENT ,
2013-04-07 12:06:47 +02:00
OUString ( ) ,
OUString ( ) ) ;
2004-08-02 16:44:17 +00:00
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 ( xTempStream , uno : : UNO_QUERY_THROW ) ;
2013-06-29 21:24:12 +02:00
xTempStreamProps - > getPropertyValue ( " Uri " ) > > = aTempFileURL ;
2004-08-02 16:44:17 +00:00
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2004-08-02 16:44:17 +00:00
{
}
2013-05-27 00:22:20 +03:00
SAL_WARN_IF ( aTempFileURL . isEmpty ( ) , " embeddedobj.common " , " Couldn't retrieve temporary file URL! " ) ;
2004-08-02 16:44:17 +00:00
2013-11-15 11:05:19 +02:00
aTempMediaDescr [ 0 ] . Name = " URL " ;
2004-08-02 16:44:17 +00:00
aTempMediaDescr [ 0 ] . Value < < = aTempFileURL ;
2013-11-15 11:05:19 +02:00
aTempMediaDescr [ 1 ] . Name = " InputStream " ;
2004-08-02 16:44:17 +00:00
aTempMediaDescr [ 1 ] . Value < < = xTempStream ;
2013-11-15 11:05:19 +02:00
aTempMediaDescr [ 2 ] . Name = " FilterName " ;
2008-03-05 17:25:21 +00:00
aTempMediaDescr [ 2 ] . Value < < = GetFilterName ( nStorageFormat ) ;
2013-11-15 11:05:19 +02:00
aTempMediaDescr [ 3 ] . Name = " AsTemplate " ;
2016-04-20 17:16:42 +02:00
aTempMediaDescr [ 3 ] . Value < < = true ;
2003-10-27 12:05:38 +00:00
}
else
{
2004-08-02 16:44:17 +00:00
aTempMediaDescr . realloc ( 2 ) ;
2013-11-15 11:05:19 +02:00
aTempMediaDescr [ 0 ] . Name = " URL " ;
2003-10-27 12:05:38 +00:00
aTempMediaDescr [ 0 ] . Value < < = m_aLinkURL ;
2013-11-15 11:05:19 +02:00
aTempMediaDescr [ 1 ] . Name = " FilterName " ;
2003-10-27 12:05:38 +00:00
aTempMediaDescr [ 1 ] . Value < < = m_aLinkFilterName ;
}
xResult = CreateDocFromMediaDescr_Impl ( aTempMediaDescr ) ;
return xResult ;
}
2014-02-22 21:20:15 +01:00
2003-11-14 14:24:28 +00:00
void SAL_CALL OCommonEmbeddedObject : : setPersistentEntry (
2003-10-27 12:05:38 +00:00
const uno : : Reference < embed : : XStorage > & xStorage ,
2013-04-07 12:06:47 +02:00
const OUString & sEntName ,
2003-10-27 12:05:38 +00:00
sal_Int32 nEntryConnectionMode ,
2003-12-08 11:49:52 +00:00
const uno : : Sequence < beans : : PropertyValue > & lArguments ,
const uno : : Sequence < beans : : PropertyValue > & lObjArgs )
2003-10-27 12:05:38 +00:00
throw ( lang : : IllegalArgumentException ,
embed : : WrongStateException ,
io : : IOException ,
uno : : Exception ,
2014-02-25 21:31:58 +01:00
uno : : RuntimeException , std : : exception )
2003-10-27 12:05:38 +00:00
{
// the type of the object must be already set
// a kind of typedetection should be done in the factory
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
if ( m_bDisposed )
throw lang : : DisposedException ( ) ; // TODO
if ( ! xStorage . is ( ) )
2014-05-26 14:29:07 +02:00
throw lang : : IllegalArgumentException ( " No parent storage is provided! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ,
2003-10-27 12:05:38 +00:00
1 ) ;
2011-12-21 19:54:11 -02:00
if ( sEntName . isEmpty ( ) )
2014-05-26 14:29:07 +02:00
throw lang : : IllegalArgumentException ( " Empty element name is provided! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ,
2003-10-27 12:05:38 +00:00
2 ) ;
2004-05-10 16:51:24 +00:00
// May be LOADED should be forbidden here ???
if ( ( m_nObjectState ! = - 1 | | nEntryConnectionMode = = embed : : EntryInitModes : : NO_INIT )
& & ( m_nObjectState = = - 1 | | nEntryConnectionMode ! = embed : : EntryInitModes : : NO_INIT ) )
2003-10-27 12:05:38 +00:00
{
// if the object is not loaded
2013-02-23 15:06:20 +01:00
// it can not get persistent representation without initialization
2003-10-27 12:05:38 +00:00
// if the object is loaded
2013-02-23 15:06:20 +01:00
// it can switch persistent representation only without initialization
2003-10-27 12:05:38 +00:00
throw embed : : WrongStateException (
2014-05-26 14:29:07 +02:00
" Can't change persistent representation of activated object! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2003-10-27 12:05:38 +00:00
}
if ( m_bWaitSaveCompleted )
2004-10-04 18:49:49 +00:00
{
if ( nEntryConnectionMode = = embed : : EntryInitModes : : NO_INIT )
2010-12-01 15:29:44 +01:00
{
// saveCompleted is expected, handle it accordingly
if ( m_xNewParentStorage = = xStorage & & m_aNewEntryName . equals ( sEntName ) )
{
2016-04-20 17:16:42 +02:00
saveCompleted ( true ) ;
2010-12-01 15:29:44 +01:00
return ;
}
// if a completely different entry is provided, switch first back to the old persistence in saveCompleted
// and then switch to the target persistence
2014-04-17 11:39:18 +02:00
bool bSwitchFurther = ( m_xParentStorage ! = xStorage | | ! m_aEntryName . equals ( sEntName ) ) ;
2016-04-20 17:16:42 +02:00
saveCompleted ( false ) ;
2010-12-01 15:29:44 +01:00
if ( ! bSwitchFurther )
return ;
}
2004-10-04 18:49:49 +00:00
else
throw embed : : WrongStateException (
2014-05-26 14:29:07 +02:00
" The object waits for saveCompleted() call! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2004-10-04 18:49:49 +00:00
}
2003-10-27 12:05:38 +00:00
2005-01-18 14:08:35 +00:00
// for now support of this interface is required to allow breaking of links and converting them to normal embedded
// objects, so the persist name must be handled correctly ( althowgh no real persist entry is used )
// OSL_ENSURE( !m_bIsLink, "This method implementation must not be used for links!\n" );
2003-11-14 14:24:28 +00:00
if ( m_bIsLink )
2005-01-18 14:08:35 +00:00
{
m_aEntryName = sEntName ;
2003-11-14 14:24:28 +00:00
return ;
2005-01-18 14:08:35 +00:00
}
2003-11-14 14:24:28 +00:00
2003-10-27 12:05:38 +00:00
uno : : Reference < container : : XNameAccess > xNameAccess ( xStorage , uno : : UNO_QUERY ) ;
if ( ! xNameAccess . is ( ) )
throw uno : : RuntimeException ( ) ; //TODO
// detect entry existence
2014-04-17 11:39:18 +02:00
bool bElExists = xNameAccess - > hasByName ( sEntName ) ;
2003-10-27 12:05:38 +00:00
2004-10-04 18:49:49 +00:00
m_aDocMediaDescriptor = GetValuableArgs_Impl ( lArguments ,
nEntryConnectionMode ! = embed : : EntryInitModes : : MEDIA_DESCRIPTOR_INIT ) ;
2004-05-10 16:51:24 +00:00
2014-04-17 11:39:18 +02:00
m_bReadOnly = false ;
2003-10-27 12:05:38 +00:00
for ( sal_Int32 nInd = 0 ; nInd < lArguments . getLength ( ) ; nInd + + )
2012-04-06 14:28:18 +02:00
if ( lArguments [ nInd ] . Name = = " ReadOnly " )
2003-10-27 12:05:38 +00:00
lArguments [ nInd ] . Value > > = m_bReadOnly ;
2004-05-10 16:51:24 +00:00
// TODO: use lObjArgs for StoreVisualReplacement
for ( sal_Int32 nObjInd = 0 ; nObjInd < lObjArgs . getLength ( ) ; nObjInd + + )
2012-04-06 14:28:18 +02:00
if ( lObjArgs [ nObjInd ] . Name = = " OutplaceDispatchInterceptor " )
2004-05-10 16:51:24 +00:00
{
uno : : Reference < frame : : XDispatchProviderInterceptor > xDispatchInterceptor ;
if ( lObjArgs [ nObjInd ] . Value > > = xDispatchInterceptor )
m_pDocHolder - > SetOutplaceDispatchInterceptor ( xDispatchInterceptor ) ;
2004-10-04 18:49:49 +00:00
}
2012-04-06 14:28:18 +02:00
else if ( lObjArgs [ nObjInd ] . Name = = " DefaultParentBaseURL " )
2004-10-04 18:49:49 +00:00
{
lObjArgs [ nObjInd ] . Value > > = m_aDefaultParentBaseURL ;
2004-05-10 16:51:24 +00:00
}
2012-04-06 14:28:18 +02:00
else if ( lObjArgs [ nObjInd ] . Name = = " Parent " )
2007-05-22 18:35:24 +00:00
{
lObjArgs [ nObjInd ] . Value > > = m_xParent ;
}
2012-04-06 14:28:18 +02:00
else if ( lObjArgs [ nObjInd ] . Name = = " IndividualMiscStatus " )
2006-11-01 17:20:05 +00:00
{
sal_Int64 nMiscStatus = 0 ;
lObjArgs [ nObjInd ] . Value > > = nMiscStatus ;
m_nMiscStatus | = nMiscStatus ;
}
2012-04-06 14:28:18 +02:00
else if ( lObjArgs [ nObjInd ] . Name = = " CloneFrom " )
2007-05-22 18:35:24 +00:00
{
uno : : Reference < embed : : XEmbeddedObject > xObj ;
lObjArgs [ nObjInd ] . Value > > = xObj ;
if ( xObj . is ( ) )
{
2014-04-17 11:39:18 +02:00
m_bHasClonedSize = true ;
2007-08-02 16:05:11 +00:00
m_aClonedSize = xObj - > getVisualAreaSize ( embed : : Aspects : : MSOLE_CONTENT ) ;
m_nClonedMapUnit = xObj - > getMapUnit ( embed : : Aspects : : MSOLE_CONTENT ) ;
2007-05-22 18:35:24 +00:00
}
}
2012-04-06 14:28:18 +02:00
else if ( lObjArgs [ nObjInd ] . Name = = " OutplaceFrameProperties " )
2007-04-16 15:50:13 +00:00
{
uno : : Sequence < uno : : Any > aOutFrameProps ;
2008-03-06 18:30:56 +00:00
uno : : Sequence < beans : : NamedValue > aOutFramePropsTyped ;
2007-04-16 15:50:13 +00:00
if ( lObjArgs [ nObjInd ] . Value > > = aOutFrameProps )
2008-03-06 18:30:56 +00:00
{
m_pDocHolder - > SetOutplaceFrameProperties ( aOutFrameProps ) ;
}
else if ( lObjArgs [ nObjInd ] . Value > > = aOutFramePropsTyped )
{
aOutFrameProps . realloc ( aOutFramePropsTyped . getLength ( ) ) ;
uno : : Any * pProp = aOutFrameProps . getArray ( ) ;
for ( const beans : : NamedValue * pTypedProp = aOutFramePropsTyped . getConstArray ( ) ;
pTypedProp ! = aOutFramePropsTyped . getConstArray ( ) + aOutFramePropsTyped . getLength ( ) ;
+ + pTypedProp , + + pProp
)
{
* pProp < < = * pTypedProp ;
}
2007-04-16 15:50:13 +00:00
m_pDocHolder - > SetOutplaceFrameProperties ( aOutFrameProps ) ;
2008-03-06 18:30:56 +00:00
}
else
2013-05-27 00:22:20 +03:00
SAL_WARN ( " embeddedobj.common " , " OCommonEmbeddedObject::setPersistentEntry: illegal type for argument 'OutplaceFrameProperties'! " ) ;
2007-04-16 15:50:13 +00:00
}
2012-04-06 14:28:18 +02:00
else if ( lObjArgs [ nObjInd ] . Name = = " ModuleName " )
2007-04-16 15:50:13 +00:00
{
lObjArgs [ nObjInd ] . Value > > = m_aModuleName ;
}
2012-04-06 14:28:18 +02:00
else if ( lObjArgs [ nObjInd ] . Name = = " EmbeddedScriptSupport " )
2008-03-06 18:30:56 +00:00
{
OSL_VERIFY ( lObjArgs [ nObjInd ] . Value > > = m_bEmbeddedScriptSupport ) ;
}
2012-04-06 14:28:18 +02:00
else if ( lObjArgs [ nObjInd ] . Name = = " DocumentRecoverySupport " )
2010-01-06 21:34:53 +01:00
{
OSL_VERIFY ( lObjArgs [ nObjInd ] . Value > > = m_bDocumentRecoverySupport ) ;
}
2012-04-06 14:28:18 +02:00
else if ( lObjArgs [ nObjInd ] . Name = = " RecoveryStorage " )
autorecovery: save/recover forms and reports
Still some lose ends. Most notably, the current code contains cases for other sub component types,
but has no real implementation - attempting to save/recover those other types will yield multiple
assertions only. Also, recovery of SRB-reports has not been tested, yet, chances are good there's
some work ahead here.
Other known open issues:
- recovering sub components immediately shows them, instead of initially hiding them, and showing
only when the main document window is shown
- the implementation currently is no real session save, which would require saving information about
*unmodified* open sub components (though not their actual content), and restoring them upon
recovery.
- doing an implicit "connect" at the controller of the to-be-recovered database document is a requirement
to actually load the sub components, but might yield problems in case this requires interaction
(e.g. a login). Need to investigate
- the "recovery" storage is not removed from the database document storage after un/successful recovery
- cancelling the recovery of a "modified" database document always suggests to store this doc somewhere
2010-01-15 15:21:15 +01:00
{
2010-01-26 13:19:11 +01:00
OSL_VERIFY ( lObjArgs [ nObjInd ] . Value > > = m_xRecoveryStorage ) ;
autorecovery: save/recover forms and reports
Still some lose ends. Most notably, the current code contains cases for other sub component types,
but has no real implementation - attempting to save/recover those other types will yield multiple
assertions only. Also, recovery of SRB-reports has not been tested, yet, chances are good there's
some work ahead here.
Other known open issues:
- recovering sub components immediately shows them, instead of initially hiding them, and showing
only when the main document window is shown
- the implementation currently is no real session save, which would require saving information about
*unmodified* open sub components (though not their actual content), and restoring them upon
recovery.
- doing an implicit "connect" at the controller of the to-be-recovered database document is a requirement
to actually load the sub components, but might yield problems in case this requires interaction
(e.g. a login). Need to investigate
- the "recovery" storage is not removed from the database document storage after un/successful recovery
- cancelling the recovery of a "modified" database document always suggests to store this doc somewhere
2010-01-15 15:21:15 +01:00
}
2008-03-06 18:30:56 +00:00
2004-05-10 16:51:24 +00:00
sal_Int32 nStorageMode = m_bReadOnly ? embed : : ElementModes : : READ : embed : : ElementModes : : READWRITE ;
2003-10-27 12:05:38 +00:00
2003-11-25 12:21:47 +00:00
SwitchOwnPersistence ( xStorage , sEntName ) ;
2003-10-27 12:05:38 +00:00
2004-05-10 16:51:24 +00:00
if ( nEntryConnectionMode = = embed : : EntryInitModes : : DEFAULT_INIT )
2003-10-27 12:05:38 +00:00
{
if ( bElExists )
{
// the initialization from existing storage allows to leave object in loaded state
2004-05-10 16:51:24 +00:00
m_nObjectState = embed : : EmbedStates : : LOADED ;
2003-10-27 12:05:38 +00:00
}
else
{
2004-10-04 18:49:49 +00:00
m_pDocHolder - > SetComponent ( InitNewDocument_Impl ( ) , m_bReadOnly ) ;
if ( ! m_pDocHolder - > GetComponent ( ) . is ( ) )
2003-10-27 12:05:38 +00:00
throw io : : IOException ( ) ; // TODO: can not create document
2004-05-10 16:51:24 +00:00
m_nObjectState = embed : : EmbedStates : : RUNNING ;
2003-10-27 12:05:38 +00:00
}
}
else
{
2004-05-10 16:51:24 +00:00
if ( ( nStorageMode & embed : : ElementModes : : READWRITE ) ! = embed : : ElementModes : : READWRITE )
2003-10-27 12:05:38 +00:00
throw io : : IOException ( ) ;
2004-05-10 16:51:24 +00:00
if ( nEntryConnectionMode = = embed : : EntryInitModes : : NO_INIT )
2003-10-27 12:05:38 +00:00
{
// the document just already changed its storage to store to
2003-11-14 14:24:28 +00:00
// the links to OOo documents for now ignore this call
// TODO: OOo links will have persistence so it will be switched here
2003-10-27 12:05:38 +00:00
}
2004-05-10 16:51:24 +00:00
else if ( nEntryConnectionMode = = embed : : EntryInitModes : : TRUNCATE_INIT )
2003-10-27 12:05:38 +00:00
{
2010-01-27 10:53:30 +01:00
if ( m_xRecoveryStorage . is ( ) )
TransferMediaType ( m_xRecoveryStorage , m_xObjectStorage ) ;
2003-10-27 12:05:38 +00:00
// TODO:
2004-10-04 18:49:49 +00:00
m_pDocHolder - > SetComponent ( InitNewDocument_Impl ( ) , m_bReadOnly ) ;
2003-10-27 12:05:38 +00:00
2004-10-04 18:49:49 +00:00
if ( ! m_pDocHolder - > GetComponent ( ) . is ( ) )
2003-10-27 12:05:38 +00:00
throw io : : IOException ( ) ; // TODO: can not create document
2004-05-10 16:51:24 +00:00
m_nObjectState = embed : : EmbedStates : : RUNNING ;
2003-10-27 12:05:38 +00:00
}
2004-05-10 16:51:24 +00:00
else if ( nEntryConnectionMode = = embed : : EntryInitModes : : MEDIA_DESCRIPTOR_INIT )
2003-10-27 12:05:38 +00:00
{
2004-10-04 18:49:49 +00:00
m_pDocHolder - > SetComponent ( CreateDocFromMediaDescr_Impl ( lArguments ) , m_bReadOnly ) ;
2004-05-10 16:51:24 +00:00
m_nObjectState = embed : : EmbedStates : : RUNNING ;
2003-10-27 12:05:38 +00:00
}
2004-05-10 16:51:24 +00:00
//else if ( nEntryConnectionMode == embed::EntryInitModes::TRANSFERABLE_INIT )
2003-10-27 12:05:38 +00:00
//{
//TODO:
//}
else
2014-05-26 14:29:07 +02:00
throw lang : : IllegalArgumentException ( " Wrong connection mode is provided! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ,
2003-10-27 12:05:38 +00:00
3 ) ;
}
}
2014-02-22 21:20:15 +01:00
2003-10-27 12:05:38 +00:00
void SAL_CALL OCommonEmbeddedObject : : storeToEntry ( const uno : : Reference < embed : : XStorage > & xStorage ,
2013-04-07 12:06:47 +02:00
const OUString & sEntName ,
2003-12-08 11:49:52 +00:00
const uno : : Sequence < beans : : PropertyValue > & lArguments ,
const uno : : Sequence < beans : : PropertyValue > & lObjArgs )
2003-10-27 12:05:38 +00:00
throw ( lang : : IllegalArgumentException ,
embed : : WrongStateException ,
io : : IOException ,
uno : : Exception ,
2014-02-25 21:31:58 +01:00
uno : : RuntimeException , std : : exception )
2003-10-27 12:05:38 +00:00
{
2005-10-27 12:58:41 +00:00
: : osl : : ResettableMutexGuard aGuard ( m_aMutex ) ;
2003-10-27 12:05:38 +00:00
if ( m_bDisposed )
throw lang : : DisposedException ( ) ; // TODO
if ( m_nObjectState = = - 1 )
{
// the object is still not loaded
2014-05-26 14:29:07 +02:00
throw embed : : WrongStateException ( " Can't store object without persistence! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2003-10-27 12:05:38 +00:00
}
if ( m_bWaitSaveCompleted )
throw embed : : WrongStateException (
2014-05-26 14:29:07 +02:00
" The object waits for saveCompleted() call! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2003-10-27 12:05:38 +00:00
2005-01-18 14:08:35 +00:00
// for now support of this interface is required to allow breaking of links and converting them to normal embedded
// objects, so the persist name must be handled correctly ( althowgh no real persist entry is used )
// OSL_ENSURE( !m_bIsLink, "This method implementation must not be used for links!\n" );
2004-10-04 18:49:49 +00:00
if ( m_bIsLink )
return ;
OSL_ENSURE ( m_xParentStorage . is ( ) & & m_xObjectStorage . is ( ) , " The object has no valid persistence! \n " ) ;
2003-10-27 12:05:38 +00:00
2004-11-26 15:15:37 +00:00
sal_Int32 nTargetStorageFormat = SOFFICE_FILEFORMAT_CURRENT ;
sal_Int32 nOriginalStorageFormat = SOFFICE_FILEFORMAT_CURRENT ;
try {
nTargetStorageFormat = : : comphelper : : OStorageHelper : : GetXStorageFormat ( xStorage ) ;
}
2011-12-09 02:56:30 +09:00
catch ( const beans : : IllegalTypeException & )
2004-11-26 15:15:37 +00:00
{
// the container just has an unknown type, use current file format
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2004-11-26 15:15:37 +00:00
{
2013-05-27 00:22:20 +03:00
SAL_WARN ( " embeddedobj.common " , " Can not retrieve target storage media type! " ) ;
2004-11-26 15:15:37 +00:00
}
2014-05-15 23:28:55 +02:00
if ( nTargetStorageFormat = = SOFFICE_FILEFORMAT_60 )
{
SAL_INFO ( " embeddedobj.common " , " fdo#78159: Storing OOoXML as ODF " ) ;
nTargetStorageFormat = SOFFICE_FILEFORMAT_CURRENT ;
// setting MediaType is done later anyway, no need to do it here
}
2004-11-26 15:15:37 +00:00
try
{
nOriginalStorageFormat = : : comphelper : : OStorageHelper : : GetXStorageFormat ( m_xParentStorage ) ;
}
2011-12-09 02:56:30 +09:00
catch ( const beans : : IllegalTypeException & )
2004-11-26 15:15:37 +00:00
{
// the container just has an unknown type, use current file format
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2004-11-26 15:15:37 +00:00
{
2013-05-27 00:22:20 +03:00
SAL_WARN ( " embeddedobj.common " , " Can not retrieve own storage media type! " ) ;
2004-11-26 15:15:37 +00:00
}
2014-04-17 11:39:18 +02:00
bool bTryOptimization = false ;
2006-01-20 08:50:17 +00:00
for ( sal_Int32 nInd = 0 ; nInd < lObjArgs . getLength ( ) ; nInd + + )
{
2014-11-10 15:05:25 +01:00
// StoreVisualReplacement and VisualReplacement args have no sense here
2012-04-06 14:28:18 +02:00
if ( lObjArgs [ nInd ] . Name = = " CanTryOptimization " )
2006-01-20 08:50:17 +00:00
lObjArgs [ nInd ] . Value > > = bTryOptimization ;
}
2014-04-17 11:39:18 +02:00
bool bSwitchBackToLoaded = false ;
2004-11-26 15:15:37 +00:00
// Storing to different format can be done only in running state.
2004-10-04 18:49:49 +00:00
if ( m_nObjectState = = embed : : EmbedStates : : LOADED )
2004-11-26 15:15:37 +00:00
{
2006-01-20 08:50:17 +00:00
// TODO/LATER: copying is not legal for documents with relative links.
2004-11-26 15:15:37 +00:00
if ( nTargetStorageFormat = = nOriginalStorageFormat )
2006-01-20 08:50:17 +00:00
{
2014-04-17 11:39:18 +02:00
bool bOptimizationWorks = false ;
2006-01-20 08:50:17 +00:00
if ( bTryOptimization )
{
try
{
// try to use optimized copying
uno : : Reference < embed : : XOptimizedStorage > xSource ( m_xParentStorage , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < embed : : XOptimizedStorage > xTarget ( xStorage , uno : : UNO_QUERY_THROW ) ;
xSource - > copyElementDirectlyTo ( m_aEntryName , xTarget , sEntName ) ;
2014-04-17 11:39:18 +02:00
bOptimizationWorks = true ;
2006-01-20 08:50:17 +00:00
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2006-01-20 08:50:17 +00:00
{
}
}
if ( ! bOptimizationWorks )
m_xParentStorage - > copyElementTo ( m_aEntryName , xStorage , sEntName ) ;
}
2004-11-26 15:15:37 +00:00
else
{
changeState ( embed : : EmbedStates : : RUNNING ) ;
2014-04-17 11:39:18 +02:00
bSwitchBackToLoaded = true ;
2004-11-26 15:15:37 +00:00
}
}
if ( m_nObjectState ! = embed : : EmbedStates : : LOADED )
2004-10-04 18:49:49 +00:00
{
uno : : Reference < embed : : XStorage > xSubStorage =
xStorage - > openStorageElement ( sEntName , embed : : ElementModes : : READWRITE ) ;
2003-10-27 12:05:38 +00:00
2004-10-04 18:49:49 +00:00
if ( ! xSubStorage . is ( ) )
throw uno : : RuntimeException ( ) ; //TODO
2005-10-27 12:58:41 +00:00
aGuard . clear ( ) ;
2004-10-04 18:49:49 +00:00
// TODO/LATER: support hierarchical name for embedded objects in embedded objects
2014-06-13 11:12:50 -04:00
StoreDocToStorage_Impl (
xSubStorage , lArguments , lObjArgs , nTargetStorageFormat , sEntName , false ) ;
2005-10-27 12:58:41 +00:00
aGuard . reset ( ) ;
2004-11-26 15:15:37 +00:00
if ( bSwitchBackToLoaded )
changeState ( embed : : EmbedStates : : LOADED ) ;
2004-10-04 18:49:49 +00:00
}
2003-10-27 12:05:38 +00:00
// TODO: should the listener notification be done?
}
2014-02-22 21:20:15 +01:00
2003-10-27 12:05:38 +00:00
void SAL_CALL OCommonEmbeddedObject : : storeAsEntry ( const uno : : Reference < embed : : XStorage > & xStorage ,
2013-04-07 12:06:47 +02:00
const OUString & sEntName ,
2003-12-08 11:49:52 +00:00
const uno : : Sequence < beans : : PropertyValue > & lArguments ,
const uno : : Sequence < beans : : PropertyValue > & lObjArgs )
2003-10-27 12:05:38 +00:00
throw ( lang : : IllegalArgumentException ,
embed : : WrongStateException ,
io : : IOException ,
uno : : Exception ,
2014-02-25 21:31:58 +01:00
uno : : RuntimeException , std : : exception )
2003-10-27 12:05:38 +00:00
{
2003-12-08 11:49:52 +00:00
// TODO: use lObjArgs
2005-10-27 12:58:41 +00:00
: : osl : : ResettableMutexGuard aGuard ( m_aMutex ) ;
2003-10-27 12:05:38 +00:00
if ( m_bDisposed )
throw lang : : DisposedException ( ) ; // TODO
if ( m_nObjectState = = - 1 )
{
// the object is still not loaded
2014-05-26 14:29:07 +02:00
throw embed : : WrongStateException ( " Can't store object without persistence! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2003-10-27 12:05:38 +00:00
}
if ( m_bWaitSaveCompleted )
throw embed : : WrongStateException (
2014-05-26 14:29:07 +02:00
" The object waits for saveCompleted() call! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2003-10-27 12:05:38 +00:00
2005-01-18 14:08:35 +00:00
// for now support of this interface is required to allow breaking of links and converting them to normal embedded
// objects, so the persist name must be handled correctly ( althowgh no real persist entry is used )
// OSL_ENSURE( !m_bIsLink, "This method implementation must not be used for links!\n" );
2004-10-04 18:49:49 +00:00
if ( m_bIsLink )
2005-01-18 14:08:35 +00:00
{
m_aNewEntryName = sEntName ;
2004-10-04 18:49:49 +00:00
return ;
2005-01-18 14:08:35 +00:00
}
2004-10-04 18:49:49 +00:00
OSL_ENSURE ( m_xParentStorage . is ( ) & & m_xObjectStorage . is ( ) , " The object has no valid persistence! \n " ) ;
2004-11-26 15:15:37 +00:00
sal_Int32 nTargetStorageFormat = SOFFICE_FILEFORMAT_CURRENT ;
sal_Int32 nOriginalStorageFormat = SOFFICE_FILEFORMAT_CURRENT ;
2004-10-04 18:49:49 +00:00
try {
2004-11-26 15:15:37 +00:00
nTargetStorageFormat = : : comphelper : : OStorageHelper : : GetXStorageFormat ( xStorage ) ;
}
2011-12-09 02:56:30 +09:00
catch ( const beans : : IllegalTypeException & )
2004-11-26 15:15:37 +00:00
{
// the container just has an unknown type, use current file format
2004-10-04 18:49:49 +00:00
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2004-10-04 18:49:49 +00:00
{
2013-05-27 00:22:20 +03:00
SAL_WARN ( " embeddedobj.common " , " Can not retrieve target storage media type! " ) ;
2004-11-26 15:15:37 +00:00
}
2014-05-15 23:28:55 +02:00
if ( nTargetStorageFormat = = SOFFICE_FILEFORMAT_60 )
{
SAL_INFO ( " embeddedobj.common " , " fdo#78159: Storing OOoXML as ODF " ) ;
nTargetStorageFormat = SOFFICE_FILEFORMAT_CURRENT ;
// setting MediaType is done later anyway, no need to do it here
}
2004-11-26 15:15:37 +00:00
try
{
nOriginalStorageFormat = : : comphelper : : OStorageHelper : : GetXStorageFormat ( m_xParentStorage ) ;
}
2011-12-09 02:56:30 +09:00
catch ( const beans : : IllegalTypeException & )
2004-11-26 15:15:37 +00:00
{
// the container just has an unknown type, use current file format
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2004-11-26 15:15:37 +00:00
{
2013-05-27 00:22:20 +03:00
SAL_WARN ( " embeddedobj.common " , " Can not retrieve own storage media type! " ) ;
2004-10-04 18:49:49 +00:00
}
2015-11-06 09:35:43 +01:00
PostEvent_Impl ( " OnSaveAs " ) ;
2004-10-04 18:49:49 +00:00
2014-04-17 11:39:18 +02:00
bool bTryOptimization = false ;
2006-01-20 08:50:17 +00:00
for ( sal_Int32 nInd = 0 ; nInd < lObjArgs . getLength ( ) ; nInd + + )
{
2014-11-10 15:05:25 +01:00
// StoreVisualReplacement and VisualReplacement args have no sense here
2012-04-06 14:28:18 +02:00
if ( lObjArgs [ nInd ] . Name = = " CanTryOptimization " )
2006-01-20 08:50:17 +00:00
lObjArgs [ nInd ] . Value > > = bTryOptimization ;
}
2014-04-17 11:39:18 +02:00
bool bSwitchBackToLoaded = false ;
2004-11-26 15:15:37 +00:00
// Storing to different format can be done only in running state.
2004-10-04 18:49:49 +00:00
if ( m_nObjectState = = embed : : EmbedStates : : LOADED )
2004-11-26 15:15:37 +00:00
{
2006-01-20 08:50:17 +00:00
// TODO/LATER: copying is not legal for documents with relative links.
2004-11-26 15:15:37 +00:00
if ( nTargetStorageFormat = = nOriginalStorageFormat )
2006-01-20 08:50:17 +00:00
{
2014-04-17 11:39:18 +02:00
bool bOptimizationWorks = false ;
2006-01-20 08:50:17 +00:00
if ( bTryOptimization )
{
try
{
// try to use optimized copying
uno : : Reference < embed : : XOptimizedStorage > xSource ( m_xParentStorage , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < embed : : XOptimizedStorage > xTarget ( xStorage , uno : : UNO_QUERY_THROW ) ;
xSource - > copyElementDirectlyTo ( m_aEntryName , xTarget , sEntName ) ;
2014-04-17 11:39:18 +02:00
bOptimizationWorks = true ;
2006-01-20 08:50:17 +00:00
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2006-01-20 08:50:17 +00:00
{
}
}
if ( ! bOptimizationWorks )
m_xParentStorage - > copyElementTo ( m_aEntryName , xStorage , sEntName ) ;
}
2004-11-26 15:15:37 +00:00
else
{
changeState ( embed : : EmbedStates : : RUNNING ) ;
2014-04-17 11:39:18 +02:00
bSwitchBackToLoaded = true ;
2004-11-26 15:15:37 +00:00
}
}
2003-10-27 12:05:38 +00:00
uno : : Reference < embed : : XStorage > xSubStorage =
2004-05-10 16:51:24 +00:00
xStorage - > openStorageElement ( sEntName , embed : : ElementModes : : READWRITE ) ;
2003-10-27 12:05:38 +00:00
if ( ! xSubStorage . is ( ) )
throw uno : : RuntimeException ( ) ; //TODO
2004-10-04 18:49:49 +00:00
if ( m_nObjectState ! = embed : : EmbedStates : : LOADED )
{
2005-10-27 12:58:41 +00:00
aGuard . clear ( ) ;
2004-10-04 18:49:49 +00:00
// TODO/LATER: support hierarchical name for embedded objects in embedded objects
2014-06-13 11:12:50 -04:00
StoreDocToStorage_Impl (
xSubStorage , lArguments , lObjArgs , nTargetStorageFormat , sEntName , false ) ;
2005-10-27 12:58:41 +00:00
aGuard . reset ( ) ;
2004-11-26 15:15:37 +00:00
if ( bSwitchBackToLoaded )
changeState ( embed : : EmbedStates : : LOADED ) ;
2004-10-04 18:49:49 +00:00
}
2003-10-27 12:05:38 +00:00
2014-04-17 11:39:18 +02:00
m_bWaitSaveCompleted = true ;
2003-10-27 12:05:38 +00:00
m_xNewObjectStorage = xSubStorage ;
m_xNewParentStorage = xStorage ;
2004-10-04 18:49:49 +00:00
m_aNewEntryName = sEntName ;
2014-04-17 11:39:18 +02:00
m_aNewDocMediaDescriptor = GetValuableArgs_Impl ( lArguments , true ) ;
2003-10-27 12:05:38 +00:00
// TODO: register listeners for storages above, in case thay are disposed
// an exception will be thrown on saveCompleted( true )
// TODO: should the listener notification be done here or in saveCompleted?
}
2014-02-22 21:20:15 +01:00
2003-10-27 12:05:38 +00:00
void SAL_CALL OCommonEmbeddedObject : : saveCompleted ( sal_Bool bUseNew )
throw ( embed : : WrongStateException ,
uno : : Exception ,
2014-02-25 21:31:58 +01:00
uno : : RuntimeException , std : : exception )
2003-10-27 12:05:38 +00:00
{
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
if ( m_bDisposed )
throw lang : : DisposedException ( ) ; // TODO
if ( m_nObjectState = = - 1 )
{
// the object is still not loaded
2014-05-26 14:29:07 +02:00
throw embed : : WrongStateException ( " Can't store object without persistence! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2003-10-27 12:05:38 +00:00
}
2005-01-18 14:08:35 +00:00
// for now support of this interface is required to allow breaking of links and converting them to normal embedded
// objects, so the persist name must be handled correctly ( althowgh no real persist entry is used )
// OSL_ENSURE( !m_bIsLink, "This method implementation must not be used for links!\n" );
2004-10-04 18:49:49 +00:00
if ( m_bIsLink )
2005-01-18 14:08:35 +00:00
{
if ( bUseNew )
m_aEntryName = m_aNewEntryName ;
2014-11-12 14:24:10 +05:30
m_aNewEntryName . clear ( ) ;
2004-10-04 18:49:49 +00:00
return ;
2005-01-18 14:08:35 +00:00
}
2004-10-04 18:49:49 +00:00
2004-11-15 16:24:44 +00:00
// it is allowed to call saveCompleted( false ) for nonstored objects
if ( ! m_bWaitSaveCompleted & & ! bUseNew )
return ;
2013-05-27 00:22:20 +03:00
SAL_WARN_IF ( ! m_bWaitSaveCompleted , " embeddedobj.common " , " Unexpected saveCompleted() call! " ) ;
2003-10-27 12:05:38 +00:00
if ( ! m_bWaitSaveCompleted )
throw io : : IOException ( ) ; // TODO: illegal call
OSL_ENSURE ( m_xNewObjectStorage . is ( ) & & m_xNewParentStorage . is ( ) , " Internal object information is broken! \n " ) ;
if ( ! m_xNewObjectStorage . is ( ) | | ! m_xNewParentStorage . is ( ) )
throw uno : : RuntimeException ( ) ; // TODO: broken internal information
if ( bUseNew )
{
2003-11-25 12:21:47 +00:00
SwitchOwnPersistence ( m_xNewParentStorage , m_xNewObjectStorage , m_aNewEntryName ) ;
2004-10-04 18:49:49 +00:00
m_aDocMediaDescriptor = m_aNewDocMediaDescriptor ;
uno : : Reference < util : : XModifiable > xModif ( m_pDocHolder - > GetComponent ( ) , uno : : UNO_QUERY ) ;
if ( xModif . is ( ) )
2016-04-20 17:16:42 +02:00
xModif - > setModified ( false ) ;
2004-10-04 18:49:49 +00:00
2015-11-06 09:35:43 +01:00
PostEvent_Impl ( " OnSaveAsDone " ) ;
2003-11-25 12:21:47 +00:00
}
else
{
2003-10-27 12:05:38 +00:00
try {
2003-11-25 12:21:47 +00:00
uno : : Reference < lang : : XComponent > xComponent ( m_xNewObjectStorage , uno : : UNO_QUERY ) ;
2013-05-27 00:22:20 +03:00
SAL_WARN_IF ( ! xComponent . is ( ) , " embeddedobj.common " , " Wrong storage implementation! " ) ;
2003-10-27 12:05:38 +00:00
if ( xComponent . is ( ) )
xComponent - > dispose ( ) ;
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2003-10-27 12:05:38 +00:00
{
}
}
2015-10-30 14:22:53 +02:00
m_xNewObjectStorage . clear ( ) ;
m_xNewParentStorage . clear ( ) ;
2014-11-12 14:24:10 +05:30
m_aNewEntryName . clear ( ) ;
2004-10-04 18:49:49 +00:00
m_aNewDocMediaDescriptor . realloc ( 0 ) ;
2014-04-17 11:39:18 +02:00
m_bWaitSaveCompleted = false ;
2003-10-27 12:05:38 +00:00
if ( bUseNew )
{
// TODO: notify listeners
2004-05-10 16:51:24 +00:00
if ( m_nUpdateMode = = embed : : EmbedUpdateModes : : ALWAYS_UPDATE )
2003-10-27 12:05:38 +00:00
{
// TODO: update visual representation
}
}
}
2014-02-22 21:20:15 +01:00
2003-10-27 12:05:38 +00:00
sal_Bool SAL_CALL OCommonEmbeddedObject : : hasEntry ( )
throw ( embed : : WrongStateException ,
2014-02-25 21:31:58 +01:00
uno : : RuntimeException , std : : exception )
2003-10-27 12:05:38 +00:00
{
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
if ( m_bDisposed )
throw lang : : DisposedException ( ) ; // TODO
if ( m_bWaitSaveCompleted )
throw embed : : WrongStateException (
2014-05-26 14:29:07 +02:00
" The object waits for saveCompleted() call! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2003-10-27 12:05:38 +00:00
if ( m_xObjectStorage . is ( ) )
2016-04-20 17:16:42 +02:00
return true ;
2003-10-27 12:05:38 +00:00
2016-04-20 17:16:42 +02:00
return false ;
2003-10-27 12:05:38 +00:00
}
2014-02-22 21:20:15 +01:00
2013-04-07 12:06:47 +02:00
OUString SAL_CALL OCommonEmbeddedObject : : getEntryName ( )
2003-10-27 12:05:38 +00:00
throw ( embed : : WrongStateException ,
2014-02-25 21:31:58 +01:00
uno : : RuntimeException , std : : exception )
2003-10-27 12:05:38 +00:00
{
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
if ( m_bDisposed )
throw lang : : DisposedException ( ) ; // TODO
if ( m_nObjectState = = - 1 )
{
// the object is still not loaded
2014-05-26 14:29:07 +02:00
throw embed : : WrongStateException ( " The object persistence is not initialized! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2003-10-27 12:05:38 +00:00
}
if ( m_bWaitSaveCompleted )
throw embed : : WrongStateException (
2014-05-26 14:29:07 +02:00
" The object waits for saveCompleted() call! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2003-10-27 12:05:38 +00:00
return m_aEntryName ;
}
2014-02-22 21:20:15 +01:00
2004-10-04 18:49:49 +00:00
void SAL_CALL OCommonEmbeddedObject : : storeOwn ( )
throw ( embed : : WrongStateException ,
io : : IOException ,
uno : : Exception ,
2014-02-25 21:31:58 +01:00
uno : : RuntimeException , std : : exception )
2004-10-04 18:49:49 +00:00
{
// 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
2005-10-27 12:58:41 +00:00
: : osl : : ResettableMutexGuard aGuard ( m_aMutex ) ;
2004-10-04 18:49:49 +00:00
if ( m_bDisposed )
throw lang : : DisposedException ( ) ; // TODO
if ( m_nObjectState = = - 1 )
{
// the object is still not loaded
2014-05-26 14:29:07 +02:00
throw embed : : WrongStateException ( " Can't store object without persistence! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2004-10-04 18:49:49 +00:00
}
if ( m_bWaitSaveCompleted )
throw embed : : WrongStateException (
2014-05-26 14:29:07 +02:00
" The object waits for saveCompleted() call! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2004-10-04 18:49:49 +00:00
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 ;
2015-11-06 09:35:43 +01:00
PostEvent_Impl ( " OnSave " ) ;
2004-10-04 18:49:49 +00:00
2013-05-27 00:22:20 +03:00
SAL_WARN_IF ( ! m_pDocHolder - > GetComponent ( ) . is ( ) , " embeddedobj.common " , " If an object is activated or in running state it must have a document! " ) ;
2004-10-04 18:49:49 +00:00
if ( ! m_pDocHolder - > GetComponent ( ) . is ( ) )
throw uno : : RuntimeException ( ) ;
if ( m_bIsLink )
{
2016-01-09 22:55:28 +01:00
// TODO: just store the document to its location
2004-10-04 18:49:49 +00:00
uno : : Reference < frame : : XStorable > xStorable ( m_pDocHolder - > GetComponent ( ) , uno : : UNO_QUERY ) ;
if ( ! xStorable . is ( ) )
throw uno : : RuntimeException ( ) ; // TODO
2005-10-27 12:58:41 +00:00
// free the main mutex for the storing time
aGuard . clear ( ) ;
2004-10-04 18:49:49 +00:00
xStorable - > store ( ) ;
2005-10-27 12:58:41 +00:00
aGuard . reset ( ) ;
2004-10-04 18:49:49 +00:00
}
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 ) ;
}
2011-12-09 02:56:30 +09:00
catch ( const beans : : IllegalTypeException & )
2004-11-26 15:15:37 +00:00
{
// the container just has an unknown type, use current file format
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2004-10-04 18:49:49 +00:00
{
2013-05-27 00:22:20 +03:00
SAL_WARN ( " embeddedobj.common " , " Can not retrieve storage media type! " ) ;
2004-10-04 18:49:49 +00:00
}
2014-05-15 23:28:55 +02:00
if ( nStorageFormat = = SOFFICE_FILEFORMAT_60 )
{
SAL_INFO ( " embeddedobj.common " , " fdo#78159: Storing OOoXML as ODF " ) ;
nStorageFormat = SOFFICE_FILEFORMAT_CURRENT ;
// setting MediaType is done later anyway, no need to do it here
}
2004-10-04 18:49:49 +00:00
2005-10-27 12:58:41 +00:00
aGuard . clear ( ) ;
2014-06-13 11:12:50 -04:00
uno : : Sequence < beans : : PropertyValue > aEmpty ;
2015-02-14 19:52:19 +01:00
uno : : Sequence < beans : : PropertyValue > aMediaArgs ( 1 ) ;
aMediaArgs [ 0 ] . Name = " DocumentBaseURL " ;
aMediaArgs [ 0 ] . Value < < = GetBaseURL_Impl ( ) ;
StoreDocToStorage_Impl ( m_xObjectStorage , aMediaArgs , aEmpty , nStorageFormat , m_aEntryName , true ) ;
2005-10-27 12:58:41 +00:00
aGuard . reset ( ) ;
2004-10-04 18:49:49 +00:00
}
uno : : Reference < util : : XModifiable > xModif ( m_pDocHolder - > GetComponent ( ) , uno : : UNO_QUERY ) ;
if ( xModif . is ( ) )
2016-04-20 17:16:42 +02:00
xModif - > setModified ( false ) ;
2004-10-04 18:49:49 +00:00
2015-11-06 09:35:43 +01:00
PostEvent_Impl ( " OnSaveDone " ) ;
2004-10-04 18:49:49 +00:00
}
2014-02-22 21:20:15 +01:00
2003-10-27 12:05:38 +00:00
sal_Bool SAL_CALL OCommonEmbeddedObject : : isReadonly ( )
throw ( embed : : WrongStateException ,
2014-02-25 21:31:58 +01:00
uno : : RuntimeException , std : : exception )
2003-10-27 12:05:38 +00:00
{
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
if ( m_bDisposed )
throw lang : : DisposedException ( ) ; // TODO
if ( m_nObjectState = = - 1 )
{
// the object is still not loaded
2014-05-26 14:29:07 +02:00
throw embed : : WrongStateException ( " The object persistence is not initialized! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2003-10-27 12:05:38 +00:00
}
if ( m_bWaitSaveCompleted )
throw embed : : WrongStateException (
2014-05-26 14:29:07 +02:00
" The object waits for saveCompleted() call! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2003-10-27 12:05:38 +00:00
return m_bReadOnly ;
}
2014-02-22 21:20:15 +01:00
2003-10-27 12:05:38 +00:00
void SAL_CALL OCommonEmbeddedObject : : reload (
2003-12-08 11:49:52 +00:00
const uno : : Sequence < beans : : PropertyValue > & lArguments ,
const uno : : Sequence < beans : : PropertyValue > & lObjArgs )
2003-10-27 12:05:38 +00:00
throw ( lang : : IllegalArgumentException ,
embed : : WrongStateException ,
io : : IOException ,
uno : : Exception ,
2014-02-25 21:31:58 +01:00
uno : : RuntimeException , std : : exception )
2003-10-27 12:05:38 +00:00
{
2003-12-08 11:49:52 +00:00
// TODO: use lObjArgs
2003-12-15 08:49:27 +00:00
// for now this method is used only to switch readonly state
2003-12-08 11:49:52 +00:00
2003-10-27 12:05:38 +00:00
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
if ( m_bDisposed )
throw lang : : DisposedException ( ) ; // TODO
if ( m_nObjectState = = - 1 )
{
// the object is still not loaded
2014-05-26 14:29:07 +02:00
throw embed : : WrongStateException ( " The object persistence is not initialized! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2003-10-27 12:05:38 +00:00
}
2004-05-10 16:51:24 +00:00
if ( m_nObjectState ! = embed : : EmbedStates : : LOADED )
2003-12-15 08:49:27 +00:00
{
// the object is still not loaded
throw embed : : WrongStateException (
2014-05-26 14:29:07 +02:00
" The object must be in loaded state to be reloaded! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2003-12-15 08:49:27 +00:00
}
2003-10-27 12:05:38 +00:00
if ( m_bWaitSaveCompleted )
throw embed : : WrongStateException (
2014-05-26 14:29:07 +02:00
" The object waits for saveCompleted() call! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2003-10-27 12:05:38 +00:00
2005-01-18 14:08:35 +00:00
if ( m_bIsLink )
{
// reload of the link
2013-04-07 12:06:47 +02:00
OUString aOldLinkFilter = m_aLinkFilterName ;
2005-01-18 14:08:35 +00:00
2013-04-07 12:06:47 +02:00
OUString aNewLinkFilter ;
2005-01-18 14:08:35 +00:00
for ( sal_Int32 nInd = 0 ; nInd < lArguments . getLength ( ) ; nInd + + )
{
2012-04-06 14:28:18 +02:00
if ( lArguments [ nInd ] . Name = = " URL " )
2005-01-18 14:08:35 +00:00
{
// the new URL
lArguments [ nInd ] . Value > > = m_aLinkURL ;
2014-11-12 14:24:10 +05:30
m_aLinkFilterName . clear ( ) ;
2005-01-18 14:08:35 +00:00
}
2012-04-06 14:28:18 +02:00
else if ( lArguments [ nInd ] . Name = = " FilterName " )
2005-01-18 14:08:35 +00:00
{
lArguments [ nInd ] . Value > > = aNewLinkFilter ;
2014-11-12 14:24:10 +05:30
m_aLinkFilterName . clear ( ) ;
2005-01-18 14:08:35 +00:00
}
}
2013-01-08 15:29:57 +02:00
: : comphelper : : MimeConfigurationHelper aHelper ( m_xContext ) ;
2011-12-21 19:54:11 -02:00
if ( m_aLinkFilterName . isEmpty ( ) )
2005-01-18 14:08:35 +00:00
{
2011-12-21 19:54:11 -02:00
if ( ! aNewLinkFilter . isEmpty ( ) )
2005-01-18 14:08:35 +00:00
m_aLinkFilterName = aNewLinkFilter ;
else
{
uno : : Sequence < beans : : PropertyValue > aArgs ( 1 ) ;
2013-11-15 11:05:19 +02:00
aArgs [ 0 ] . Name = " URL " ;
2005-01-18 14:08:35 +00:00
aArgs [ 0 ] . Value < < = m_aLinkURL ;
2014-02-16 22:51:15 +01:00
m_aLinkFilterName = aHelper . UpdateMediaDescriptorWithFilterName ( aArgs , false ) ;
2005-01-18 14:08:35 +00:00
}
}
if ( ! aOldLinkFilter . equals ( m_aLinkFilterName ) )
{
uno : : Sequence < beans : : NamedValue > aObject = aHelper . GetObjectPropsByFilter ( m_aLinkFilterName ) ;
// TODO/LATER: probably the document holder could be cleaned explicitly as in the destructor
m_pDocHolder - > release ( ) ;
2015-11-10 10:14:40 +01:00
m_pDocHolder = nullptr ;
2005-01-18 14:08:35 +00:00
LinkInit_Impl ( aObject , lArguments , lObjArgs ) ;
}
}
2014-04-17 11:39:18 +02:00
m_aDocMediaDescriptor = GetValuableArgs_Impl ( lArguments , true ) ;
2004-05-10 16:51:24 +00:00
// TODO: use lObjArgs for StoreVisualReplacement
for ( sal_Int32 nObjInd = 0 ; nObjInd < lObjArgs . getLength ( ) ; nObjInd + + )
2012-04-06 14:28:18 +02:00
if ( lObjArgs [ nObjInd ] . Name = = " OutplaceDispatchInterceptor " )
2004-05-10 16:51:24 +00:00
{
uno : : Reference < frame : : XDispatchProviderInterceptor > xDispatchInterceptor ;
if ( lObjArgs [ nObjInd ] . Value > > = xDispatchInterceptor )
m_pDocHolder - > SetOutplaceDispatchInterceptor ( xDispatchInterceptor ) ;
break ;
}
2003-10-27 12:05:38 +00:00
// TODO:
2003-12-15 08:49:27 +00:00
// when document allows reloading through API the object can be reloaded not only in loaded state
2014-04-17 11:39:18 +02:00
bool bOldReadOnlyValue = m_bReadOnly ;
2003-12-15 08:49:27 +00:00
2014-04-17 11:39:18 +02:00
m_bReadOnly = false ;
2003-12-15 08:49:27 +00:00
for ( sal_Int32 nInd = 0 ; nInd < lArguments . getLength ( ) ; nInd + + )
2012-04-06 14:28:18 +02:00
if ( lArguments [ nInd ] . Name = = " ReadOnly " )
2003-12-15 08:49:27 +00:00
lArguments [ nInd ] . Value > > = m_bReadOnly ;
2004-10-04 18:49:49 +00:00
if ( bOldReadOnlyValue ! = m_bReadOnly & & ! m_bIsLink )
2003-12-15 08:49:27 +00:00
{
// close own storage
try {
uno : : Reference < lang : : XComponent > xComponent ( m_xObjectStorage , uno : : UNO_QUERY ) ;
OSL_ENSURE ( ! m_xObjectStorage . is ( ) | | xComponent . is ( ) , " Wrong storage implementation! " ) ;
if ( xComponent . is ( ) )
xComponent - > dispose ( ) ;
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2003-12-15 08:49:27 +00:00
{
}
2004-05-10 16:51:24 +00:00
sal_Int32 nStorageMode = m_bReadOnly ? embed : : ElementModes : : READ : embed : : ElementModes : : READWRITE ;
m_xObjectStorage = m_xParentStorage - > openStorageElement ( m_aEntryName , nStorageMode ) ;
2003-12-15 08:49:27 +00:00
}
2003-10-27 12:05:38 +00:00
}
2014-07-11 10:50:29 -04:00
sal_Bool SAL_CALL OCommonEmbeddedObject : : isStored ( ) throw ( css : : uno : : RuntimeException , std : : exception )
{
uno : : Reference < container : : XNameAccess > xNA ( m_xObjectStorage , uno : : UNO_QUERY ) ;
if ( ! xNA . is ( ) )
return false ;
return xNA - > getElementNames ( ) . getLength ( ) > 0 ;
}
2014-02-22 21:20:15 +01:00
2003-11-04 13:30:21 +00:00
void SAL_CALL OCommonEmbeddedObject : : breakLink ( const uno : : Reference < embed : : XStorage > & xStorage ,
2013-04-07 12:06:47 +02:00
const OUString & sEntName )
2003-11-04 13:30:21 +00:00
throw ( lang : : IllegalArgumentException ,
embed : : WrongStateException ,
io : : IOException ,
uno : : Exception ,
2014-02-25 21:31:58 +01:00
uno : : RuntimeException , std : : exception )
2003-11-04 13:30:21 +00:00
{
2005-01-18 14:08:35 +00:00
: : osl : : ResettableMutexGuard aGuard ( m_aMutex ) ;
if ( m_bDisposed )
throw lang : : DisposedException ( ) ; // TODO
2004-10-04 18:49:49 +00:00
if ( ! m_bIsLink )
{
// it must be a linked initialized object
throw embed : : WrongStateException (
2014-05-26 14:29:07 +02:00
" The object is not a valid linked object! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2004-10-04 18:49:49 +00:00
}
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 ).
}
2003-11-04 13:30:21 +00:00
if ( ! xStorage . is ( ) )
2014-05-26 14:29:07 +02:00
throw lang : : IllegalArgumentException ( " No parent storage is provided! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ,
2003-11-04 13:30:21 +00:00
1 ) ;
2011-12-21 19:54:11 -02:00
if ( sEntName . isEmpty ( ) )
2014-05-26 14:29:07 +02:00
throw lang : : IllegalArgumentException ( " Empty element name is provided! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ,
2003-11-04 13:30:21 +00:00
2 ) ;
if ( ! m_bIsLink | | m_nObjectState = = - 1 )
{
// it must be a linked initialized object
throw embed : : WrongStateException (
2014-05-26 14:29:07 +02:00
" The object is not a valid linked object! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2003-11-04 13:30:21 +00:00
}
if ( m_bWaitSaveCompleted )
throw embed : : WrongStateException (
2014-05-26 14:29:07 +02:00
" The object waits for saveCompleted() call! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2003-11-04 13:30:21 +00:00
uno : : Reference < container : : XNameAccess > xNameAccess ( xStorage , uno : : UNO_QUERY ) ;
if ( ! xNameAccess . is ( ) )
throw uno : : RuntimeException ( ) ; //TODO
2014-04-17 11:39:18 +02:00
m_bReadOnly = false ;
2003-11-04 13:30:21 +00:00
2003-11-25 12:21:47 +00:00
if ( m_xParentStorage ! = xStorage | | ! m_aEntryName . equals ( sEntName ) )
SwitchOwnPersistence ( xStorage , sEntName ) ;
2003-11-04 13:30:21 +00:00
// for linked object it means that it becomes embedded object
// the document must switch it's persistence also
2004-10-04 18:49:49 +00:00
// TODO/LATER: handle the case when temp doc can not be created
2003-11-04 13:30:21 +00:00
// the document is a new embedded object so it must be marked as modified
2004-10-04 18:49:49 +00:00
uno : : Reference < util : : XCloseable > xDocument = CreateTempDocFromLink_Impl ( ) ;
uno : : Reference < util : : XModifiable > xModif ( m_pDocHolder - > GetComponent ( ) , uno : : UNO_QUERY ) ;
2003-11-04 13:30:21 +00:00
if ( ! xModif . is ( ) )
throw uno : : RuntimeException ( ) ;
try
{
2016-04-20 17:16:42 +02:00
xModif - > setModified ( true ) ;
2003-11-04 13:30:21 +00:00
}
2011-12-09 02:56:30 +09:00
catch ( const uno : : Exception & )
2003-11-04 13:30:21 +00:00
{ }
2004-10-04 18:49:49 +00:00
m_pDocHolder - > SetComponent ( xDocument , m_bReadOnly ) ;
2014-04-18 00:26:02 +03:00
SAL_WARN_IF ( ! m_pDocHolder - > GetComponent ( ) . is ( ) , " embeddedobj.common " , " If document can't be created, an exception must be thrown! " ) ;
2003-11-04 13:30:21 +00:00
2004-05-10 16:51:24 +00:00
if ( m_nObjectState = = embed : : EmbedStates : : LOADED )
2005-01-18 14:08:35 +00:00
{
// the state is changed and can not be switched to loaded state back without saving
2004-05-10 16:51:24 +00:00
m_nObjectState = embed : : EmbedStates : : RUNNING ;
2014-04-17 11:39:18 +02:00
StateChangeNotification_Impl ( false , embed : : EmbedStates : : LOADED , m_nObjectState , aGuard ) ;
2005-01-18 14:08:35 +00:00
}
2004-05-10 16:51:24 +00:00
else if ( m_nObjectState = = embed : : EmbedStates : : ACTIVE )
2003-11-04 13:30:21 +00:00
m_pDocHolder - > Show ( ) ;
2014-04-17 11:39:18 +02:00
m_bIsLink = false ;
2014-11-12 14:24:10 +05:30
m_aLinkFilterName . clear ( ) ;
m_aLinkURL . clear ( ) ;
2003-11-04 13:30:21 +00:00
}
2014-02-22 21:20:15 +01:00
2003-10-27 12:05:38 +00:00
sal_Bool SAL_CALL OCommonEmbeddedObject : : isLink ( )
throw ( embed : : WrongStateException ,
2014-02-25 21:31:58 +01:00
uno : : RuntimeException , std : : exception )
2003-10-27 12:05:38 +00:00
{
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
if ( m_bDisposed )
throw lang : : DisposedException ( ) ; // TODO
return m_bIsLink ;
}
2014-02-22 21:20:15 +01:00
2013-04-07 12:06:47 +02:00
OUString SAL_CALL OCommonEmbeddedObject : : getLinkURL ( )
2003-11-04 13:30:21 +00:00
throw ( embed : : WrongStateException ,
uno : : Exception ,
2014-02-25 21:31:58 +01:00
uno : : RuntimeException , std : : exception )
2003-10-27 12:05:38 +00:00
{
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
if ( m_bDisposed )
throw lang : : DisposedException ( ) ; // TODO
if ( ! m_bIsLink )
throw embed : : WrongStateException (
2014-05-26 14:29:07 +02:00
" The object is not a link object! " ,
2014-05-26 15:26:03 +02:00
static_cast < : : cppu : : OWeakObject * > ( this ) ) ;
2003-10-27 12:05:38 +00:00
return m_aLinkURL ;
}
2010-10-12 15:53:47 +02:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */