diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2018-03-06 22:43:34 -0500 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2018-03-07 14:55:43 +0100 |
commit | 98af842308727765050a6e03cdb0b25b5694bd27 (patch) | |
tree | c07161555561946bc140634c8d28cc4b85a7c337 /comphelper | |
parent | a8f92371317d0056212063d473bb518cfbdbf874 (diff) |
oox: preserve the ContentType of custom files
Generic logic to preserve custom files with
their correct ContentType. Standard default
file extensions with respective ContentType
preserved in [Content_Types].xml.
Change-Id: I651ed691e9a4745cd2cb4b3c4d4c5fd7287b66c2
Reviewed-on: https://gerrit.libreoffice.org/50896
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
Tested-by: Jan Holesovsky <kendy@collabora.com>
Diffstat (limited to 'comphelper')
-rw-r--r-- | comphelper/source/xml/ofopxmlhelper.cxx | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/comphelper/source/xml/ofopxmlhelper.cxx b/comphelper/source/xml/ofopxmlhelper.cxx index 6946e0e3bbd6..9bd5cad0fe8f 100644 --- a/comphelper/source/xml/ofopxmlhelper.cxx +++ b/comphelper/source/xml/ofopxmlhelper.cxx @@ -112,6 +112,38 @@ uno::Sequence< uno::Sequence< beans::StringPair > > ReadContentTypeSequence( return ReadSequence_Impl( xInStream, aStringID, CONTENTTYPE_FORMAT, rContext ); } +OUString GetContentTypeByName( + const css::uno::Sequence<css::uno::Sequence<css::beans::StringPair>>& rContentTypes, + const OUString& rFilename) +{ + if (rContentTypes.getLength() < 2) + { + return OUString(); + } + + const uno::Sequence<beans::StringPair>& rDefaults = rContentTypes[0]; + const uno::Sequence<beans::StringPair>& rOverrides = rContentTypes[1]; + + // Find the extension and use it to get the type. + const sal_Int32 nDotOffset = rFilename.lastIndexOf('.'); + const OUString aExt = (nDotOffset >= 0 ? rFilename.copy(nDotOffset + 1) : rFilename); // Skip the dot. + + const std::vector<OUString> aNames = { aExt, "/" + rFilename }; + for (const OUString& aName : aNames) + { + const auto it1 = std::find_if(rOverrides.begin(), rOverrides.end(), [&aName](const beans::StringPair& rPair) + { return rPair.First == aName; }); + if (it1 != rOverrides.end()) + return it1->Second; + + const auto it2 = std::find_if(rDefaults.begin(), rDefaults.end(), [&aName](const beans::StringPair& rPair) + { return rPair.First == aName; }); + if (it2 != rDefaults.end()) + return it2->Second; + } + + return OUString(); +} void WriteRelationsInfoSequence( const uno::Reference< io::XOutputStream >& xOutStream, |