diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2018-03-06 22:43:34 -0500 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2018-03-26 07:46:14 +0200 |
commit | e3029244ccbd75a9e0fd9cab2e8677336b88fff5 (patch) | |
tree | 86a93d5d3ad1ebaf9ca229e3ddce6388765e8a33 /comphelper | |
parent | cf256ad5858bea8834cb5ce49e4f76bb0b14d7dd (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.
Reviewed-on: https://gerrit.libreoffice.org/50856
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
(cherry picked from commit 8f79f22a8d4b1c2d209c55cd618c24428960088f)
Change-Id: I651ed691e9a4745cd2cb4b3c4d4c5fd7287b66c2
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 d3ce7b0dc65d..bfb3dbdd0fa6 100644 --- a/comphelper/source/xml/ofopxmlhelper.cxx +++ b/comphelper/source/xml/ofopxmlhelper.cxx @@ -110,6 +110,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, |