summaryrefslogtreecommitdiffstats
path: root/comphelper
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2018-03-06 22:43:34 -0500
committerJan Holesovsky <kendy@collabora.com>2018-03-08 12:40:19 +0100
commit8f79f22a8d4b1c2d209c55cd618c24428960088f (patch)
tree0447e43cdca126688699ffd76665c130247b7384 /comphelper
parentoox: unit-tests for custom package preservation (diff)
downloadcore-8f79f22a8d4b1c2d209c55cd618c24428960088f.tar.gz
core-8f79f22a8d4b1c2d209c55cd618c24428960088f.zip
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/50856 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Jan Holesovsky <kendy@collabora.com>
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/source/xml/ofopxmlhelper.cxx32
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,