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 /oox | |
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 'oox')
-rw-r--r-- | oox/inc/drawingml/graphicproperties.hxx | 5 | ||||
-rw-r--r-- | oox/source/drawingml/fillproperties.cxx | 8 | ||||
-rw-r--r-- | oox/source/drawingml/graphicshapecontext.cxx | 32 | ||||
-rw-r--r-- | oox/source/drawingml/shape.cxx | 2 |
4 files changed, 29 insertions, 18 deletions
diff --git a/oox/inc/drawingml/graphicproperties.hxx b/oox/inc/drawingml/graphicproperties.hxx index 27644cd683d6..b89d3b95a80f 100644 --- a/oox/inc/drawingml/graphicproperties.hxx +++ b/oox/inc/drawingml/graphicproperties.hxx @@ -22,6 +22,8 @@ #include <sal/config.h> +#include <com/sun/star/io/XInputStream.hpp> + #include <oox/drawingml/fillproperties.hxx> #include <oox/helper/helper.hxx> @@ -36,7 +38,8 @@ namespace drawingml { struct GraphicProperties { BlipFillProperties maBlipProps; ///< Properties for the graphic. - OUString msMediaTempFile; ///< Audio/Video temporary file. + OUString m_sMediaPackageURL; ///< Audio/Video URL. + css::uno::Reference<css::io::XInputStream> m_xMediaStream; ///< Audio/Video input stream. /** Overwrites all members that are explicitly set in rSourceProps. */ void assignUsed( const GraphicProperties& rSourceProps ); diff --git a/oox/source/drawingml/fillproperties.cxx b/oox/source/drawingml/fillproperties.cxx index 80e2c25109da..fd45658d63e2 100644 --- a/oox/source/drawingml/fillproperties.cxx +++ b/oox/source/drawingml/fillproperties.cxx @@ -753,8 +753,12 @@ void GraphicProperties::pushToPropMap( PropertyMap& rPropMap, const GraphicHelpe rPropMap.setProperty(PROP_AdjustContrast, nContrast); // Media content - if( !msMediaTempFile.isEmpty() ) - rPropMap.setProperty(PROP_MediaURL, msMediaTempFile); + assert(m_xMediaStream.is() != m_sMediaPackageURL.isEmpty()); + if (m_xMediaStream.is() && !m_sMediaPackageURL.isEmpty()) + { + rPropMap.setProperty(PROP_PrivateStream, m_xMediaStream); + rPropMap.setProperty(PROP_MediaURL, m_sMediaPackageURL); + } } bool ArtisticEffectProperties::isEmpty() const diff --git a/oox/source/drawingml/graphicshapecontext.cxx b/oox/source/drawingml/graphicshapecontext.cxx index a2eac1638308..7c82395f822d 100644 --- a/oox/source/drawingml/graphicshapecontext.cxx +++ b/oox/source/drawingml/graphicshapecontext.cxx @@ -49,20 +49,19 @@ using namespace ::com::sun::star::beans; using namespace ::com::sun::star::xml::sax; using namespace ::oox::core; -static OUString lcl_CopyToTempFile(const OUString& rStream, const oox::core::XmlFilterBase& rFilter) +static uno::Reference<io::XInputStream> +lcl_GetMediaStream(const OUString& rStream, const oox::core::XmlFilterBase& rFilter) { if (rStream.isEmpty()) - return OUString(); + return nullptr; Reference< XInputStream > xInStrm( rFilter.openInputStream(rStream), UNO_SET_THROW ); - Reference< XTempFile > xTempFile( TempFile::create(rFilter.getComponentContext()) ); - Reference< XOutputStream > xOutStrm( xTempFile->getOutputStream(), UNO_SET_THROW ); - oox::BinaryXOutputStream aOutStrm( xOutStrm, false ); - oox::BinaryXInputStream aInStrm( xInStrm, false ); - aInStrm.copyToStream( aOutStrm ); - - xTempFile->setRemoveFile( false ); - return xTempFile->getUri(); + return xInStrm; +} + +static OUString lcl_GetMediaReference(const OUString& rStream) +{ + return rStream.isEmpty() ? OUString() : "vnd.sun.star.Package:" + rStream; } namespace oox { @@ -86,8 +85,11 @@ ContextHandlerRef GraphicShapeContext::onCreateContext( sal_Int32 aElementToken, return new BlipFillContext( *this, rAttribs, mpShapePtr->getGraphicProperties().maBlipProps ); case XML_wavAudioFile: { - mpShapePtr->getGraphicProperties().msMediaTempFile = - lcl_CopyToTempFile( getEmbeddedWAVAudioFile(getRelations(), rAttribs), getFilter() ); + OUString const path(getEmbeddedWAVAudioFile(getRelations(), rAttribs)); + mpShapePtr->getGraphicProperties().m_xMediaStream = + lcl_GetMediaStream(path, getFilter()); + mpShapePtr->getGraphicProperties().m_sMediaPackageURL = + lcl_GetMediaReference(path); } break; case XML_audioFile: @@ -95,8 +97,10 @@ ContextHandlerRef GraphicShapeContext::onCreateContext( sal_Int32 aElementToken, { OUString rPath = getRelations().getFragmentPathFromRelId( rAttribs.getString(R_TOKEN(link)).get() ); - mpShapePtr->getGraphicProperties().msMediaTempFile = - lcl_CopyToTempFile( rPath, getFilter() ); + mpShapePtr->getGraphicProperties().m_xMediaStream = + lcl_GetMediaStream(rPath, getFilter()); + mpShapePtr->getGraphicProperties().m_sMediaPackageURL = + lcl_GetMediaReference(rPath); } break; } diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx index 1aa23f78a08e..b635ed404706 100644 --- a/oox/source/drawingml/shape.cxx +++ b/oox/source/drawingml/shape.cxx @@ -405,7 +405,7 @@ Reference< XShape > Shape::createAndInsert( OUString aServiceName; if( rServiceName == "com.sun.star.drawing.GraphicObjectShape" && - mpGraphicPropertiesPtr && !mpGraphicPropertiesPtr->msMediaTempFile.isEmpty() ) + mpGraphicPropertiesPtr && !mpGraphicPropertiesPtr->m_sMediaPackageURL.isEmpty()) { aServiceName = finalizeServiceName( rFilterBase, "com.sun.star.presentation.MediaShape", aShapeRectHmm ); bIsEmbMedia = true; |