diff options
author | Michael Stahl <mstahl@redhat.com> | 2014-10-13 19:01:12 +0200 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2014-10-13 19:23:41 +0200 |
commit | 220a3686921847b71dc72b69ce98ba260b951610 (patch) | |
tree | c10fc83c4abc99dd1685a7542f954ce9f6f3388c /svx | |
parent | 8b7f96d257724656ac4a4303b17285be2ed13886 (diff) |
oox: refactor embedded media import
Currently the oox import creates a temp file and leaks it, and there is
no way to clean it up afterwards. Unfortunately it turns out that
SdrModel has no way to access the imported OOXML storage, so add a
really ugly hack to get the embedded media into the SdrMediaObj by
setting both MediaURL and PrivateStream properties (currently oox really
wants to set the properties in alphabetical order too...)
Change-Id: I5a235fbeb08e7bc17faf066de52b94867e9a79a2
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/svdraw/svdomedia.cxx | 76 | ||||
-rw-r--r-- | svx/source/unodraw/unoprov.cxx | 2 | ||||
-rw-r--r-- | svx/source/unodraw/unoshap4.cxx | 26 |
3 files changed, 79 insertions, 25 deletions
diff --git a/svx/source/svdraw/svdomedia.cxx b/svx/source/svdraw/svdomedia.cxx index e34a7285c90e..da5860b9c91f 100644 --- a/svx/source/svdraw/svdomedia.cxx +++ b/svx/source/svdraw/svdomedia.cxx @@ -66,6 +66,7 @@ struct SdrMediaObj::Impl ::avmedia::MediaItem m_MediaProperties; ::boost::shared_ptr< MediaTempFile > m_pTempFile; uno::Reference< graphic::XGraphic > m_xCachedSnapshot; + OUString m_LastFailedPkgURL; }; TYPEINIT1( SdrMediaObj, SdrRectObj ); @@ -326,6 +327,53 @@ static bool lcl_HandleJsonPackageURL( } #endif +static bool lcl_CopyToTempFile( + uno::Reference<io::XInputStream> const& xInStream, + OUString & o_rTempFileURL) +{ + OUString tempFileURL; + ::osl::FileBase::RC const err = + ::osl::FileBase::createTempFile(0, 0, & tempFileURL); + if (::osl::FileBase::E_None != err) + { + SAL_INFO("svx", "cannot create temp file"); + return false; + } + + try + { + ::ucbhelper::Content tempContent(tempFileURL, + uno::Reference<ucb::XCommandEnvironment>(), + comphelper::getProcessComponentContext()); + tempContent.writeStream(xInStream, true); // copy stream to file + } + catch (uno::Exception const& e) + { + SAL_WARN("svx", "exception: '" << e.Message << "'"); + return false; + } + o_rTempFileURL = tempFileURL; + return true; +} + +void SdrMediaObj::SetInputStream(uno::Reference<io::XInputStream> const& xStream) +{ + if (m_pImpl->m_pTempFile || m_pImpl->m_LastFailedPkgURL.isEmpty()) + { + SAL_WARN("svx", "this is only intended for embedded media"); + return; + } + OUString tempFileURL; + bool const bSuccess = lcl_CopyToTempFile(xStream, tempFileURL); + if (bSuccess) + { + m_pImpl->m_pTempFile.reset(new MediaTempFile(tempFileURL)); + m_pImpl->m_MediaProperties.setURL( + m_pImpl->m_LastFailedPkgURL, tempFileURL, ""); + } + m_pImpl->m_LastFailedPkgURL = ""; // once only +} + /// copy a stream from XStorage to temp file static bool lcl_HandlePackageURL( OUString const & rURL, @@ -357,30 +405,7 @@ static bool lcl_HandlePackageURL( SAL_WARN("svx", "no stream?"); return false; } - - OUString tempFileURL; - ::osl::FileBase::RC const err = - ::osl::FileBase::createTempFile(0, 0, & tempFileURL); - if (::osl::FileBase::E_None != err) - { - SAL_INFO("svx", "cannot create temp file"); - return false; - } - - try - { - ::ucbhelper::Content tempContent(tempFileURL, - uno::Reference<ucb::XCommandEnvironment>(), - comphelper::getProcessComponentContext()); - tempContent.writeStream(xInStream, true); // copy stream to file - } - catch (uno::Exception const& e) - { - SAL_WARN("svx", "exception: '" << e.Message << "'"); - return false; - } - o_rTempFileURL = tempFileURL; - return true; + return lcl_CopyToTempFile(xInStream, o_rTempFileURL); } void SdrMediaObj::mediaPropertiesChanged( const ::avmedia::MediaItem& rNewProperties ) @@ -420,6 +445,9 @@ void SdrMediaObj::mediaPropertiesChanged( const ::avmedia::MediaItem& rNewProper { m_pImpl->m_pTempFile.reset(); m_pImpl->m_MediaProperties.setURL("", "", ""); + // UGLY: oox import also gets here, because unlike ODF + // getDocumentStorage() is not the imported file... + m_pImpl->m_LastFailedPkgURL = url; } } else diff --git a/svx/source/unodraw/unoprov.cxx b/svx/source/unodraw/unoprov.cxx index 655fa27d0089..92460cd80beb 100644 --- a/svx/source/unodraw/unoprov.cxx +++ b/svx/source/unodraw/unoprov.cxx @@ -730,7 +730,7 @@ SfxItemPropertyMapEntry const * ImplGetSvxMediaShapePropertyMap() // #i68101# { OUString(UNO_NAME_MISC_OBJ_TITLE), OWN_ATTR_MISC_OBJ_TITLE , cppu::UnoType<OUString>::get(), 0, 0}, { OUString(UNO_NAME_MISC_OBJ_DESCRIPTION), OWN_ATTR_MISC_OBJ_DESCRIPTION , cppu::UnoType<OUString>::get(), 0, 0}, - {OUString("PrivateStream"), OWN_ATTR_MEDIA_STREAM, cppu::UnoType<css::io::XInputStream>::get(), ::com::sun::star::beans::PropertyAttribute::READONLY, 0}, + {OUString("PrivateStream"), OWN_ATTR_MEDIA_STREAM, cppu::UnoType<css::io::XInputStream>::get(), 0, 0}, {OUString("PrivateTempFileURL"), OWN_ATTR_MEDIA_TEMPFILEURL, cppu::UnoType<OUString>::get(), ::com::sun::star::beans::PropertyAttribute::READONLY, 0}, { OUString("MediaMimeType"), OWN_ATTR_MEDIA_MIMETYPE, cppu::UnoType<OUString>::get(), 0, 0}, { OUString("FallbackGraphic"), OWN_ATTR_FALLBACK_GRAPHIC, cppu::UnoType<css::graphic::XGraphic>::get(), ::com::sun::star::beans::PropertyAttribute::READONLY, 0}, diff --git a/svx/source/unodraw/unoshap4.cxx b/svx/source/unodraw/unoshap4.cxx index 3fac4a0d2f7b..b78d3629b5e0 100644 --- a/svx/source/unodraw/unoshap4.cxx +++ b/svx/source/unodraw/unoshap4.cxx @@ -808,6 +808,7 @@ SvxMediaShape::~SvxMediaShape() throw() bool SvxMediaShape::setPropertyValueImpl( const OUString& rName, const SfxItemPropertySimpleEntry* pProperty, const ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) { if( ((pProperty->nWID >= OWN_ATTR_MEDIA_URL) && (pProperty->nWID <= OWN_ATTR_MEDIA_ZOOM)) + || (pProperty->nWID == OWN_ATTR_MEDIA_STREAM) || (pProperty->nWID == OWN_ATTR_MEDIA_MIMETYPE) ) { SdrMediaObj* pMedia = static_cast< SdrMediaObj* >( mpObj.get() ); @@ -886,6 +887,31 @@ bool SvxMediaShape::setPropertyValueImpl( const OUString& rName, const SfxItemPr } break; + case OWN_ATTR_MEDIA_STREAM: + try + { + uno::Reference<io::XInputStream> xStream; + if (rValue >>= xStream) + { + pMedia->SetInputStream(xStream); + } + } + catch (const css::ucb::ContentCreationException& e) + { + throw css::lang::WrappedTargetException( + "ContentCreationException Setting InputStream!", + static_cast<OWeakObject *>(this), + makeAny(e)); + } + catch (const css::ucb::CommandFailedException& e) + { + throw css::lang::WrappedTargetException( + "CommandFailedException Setting InputStream!", + static_cast<OWeakObject *>(this), + makeAny(e)); + } + break; + default: OSL_FAIL("SvxMediaShape::setPropertyValueImpl(), unknown argument!"); } |