summaryrefslogtreecommitdiff
path: root/oox
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-07 14:55:43 +0100
commit98af842308727765050a6e03cdb0b25b5694bd27 (patch)
treec07161555561946bc140634c8d28cc4b85a7c337 /oox
parenta8f92371317d0056212063d473bb518cfbdbf874 (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 'oox')
-rw-r--r--oox/source/core/xmlfilterbase.cxx38
1 files changed, 26 insertions, 12 deletions
diff --git a/oox/source/core/xmlfilterbase.cxx b/oox/source/core/xmlfilterbase.cxx
index 00d23a377564..491d83a5770c 100644
--- a/oox/source/core/xmlfilterbase.cxx
+++ b/oox/source/core/xmlfilterbase.cxx
@@ -61,6 +61,7 @@
#include <oox/core/filterdetect.hxx>
#include <comphelper/storagehelper.hxx>
#include <comphelper/sequence.hxx>
+#include <comphelper/ofopxmlhelper.hxx>
#include <oox/crypto/DocumentEncryption.hxx>
#include <tools/date.hxx>
@@ -961,13 +962,6 @@ void XmlFilterBase::importCustomFragments(css::uno::Reference<css::embed::XStora
Reference<XRelationshipAccess> xRelations(xDocumentStorage, UNO_QUERY);
if (xRelations.is())
{
- // These are all the custom types we recognize and can preserve.
- static const std::set<OUString> sCustomTypes = {
- "http://schemas.dell.com/ddp/2016/relationships/xenFile",
- "http://schemas.dell.com/ddp/2016/relationships/hmacFile",
- "http://schemas.dell.com/ddp/2016/relationships/metadataFile"
- };
-
uno::Sequence<uno::Sequence<beans::StringPair>> aSeqs = xRelations->getAllRelationships();
std::vector<StreamDataSequence> aCustomFragments;
@@ -987,7 +981,8 @@ void XmlFilterBase::importCustomFragments(css::uno::Reference<css::embed::XStora
sType = aPair.Second;
}
- if (sCustomTypes.find(sType) != sCustomTypes.end())
+ // Preserve non-standard (i.e. custom) entries.
+ if (!sType.match("http://schemas.openxmlformats.org"))
{
StreamDataSequence aDataSeq;
if (importBinaryData(aDataSeq, sTarget))
@@ -1009,7 +1004,7 @@ void XmlFilterBase::importCustomFragments(css::uno::Reference<css::embed::XStora
std::vector<uno::Reference<xml::dom::XDocument>> aCustomXmlDomPropsList;
//FIXME: Ideally, we should get these the relations, but it seems that is not consistently set.
// In some cases it's stored in the workbook relationships, which is unexpected. So we discover them directly.
- for (int i = 1; i < 100; ++i)
+ for (int i = 1; ; ++i)
{
Reference<XDocument> xCustDoc = importFragment("customXml/item" + OUString::number(i) + ".xml");
Reference<XDocument> xCustDocProps = importFragment("customXml/itemProps" + OUString::number(i) + ".xml");
@@ -1026,6 +1021,14 @@ void XmlFilterBase::importCustomFragments(css::uno::Reference<css::embed::XStora
aGrabBagProperties["OOXCustomXml"] <<= comphelper::containerToSequence(aCustomXmlDomList);
aGrabBagProperties["OOXCustomXmlProps"] <<= comphelper::containerToSequence(aCustomXmlDomPropsList);
+ // Save the [Content_Types].xml after parsing.
+ uno::Sequence<uno::Sequence<beans::StringPair>> aContentTypeInfo;
+ uno::Reference<io::XInputStream> xInputStream = openInputStream("[Content_Types].xml");
+ if (xInputStream.is())
+ aContentTypeInfo = comphelper::OFOPXMLHelper::ReadContentTypeSequence(xInputStream, getComponentContext());
+
+ aGrabBagProperties["OOXContentTypes"] <<= aContentTypeInfo;
+
Reference<XComponent> xModel(getModel(), UNO_QUERY);
oox::core::XmlFilterBase::putPropertiesToDocumentGrabBag(xModel, aGrabBagProperties);
}
@@ -1046,6 +1049,7 @@ void XmlFilterBase::exportCustomFragments()
uno::Sequence<StreamDataSequence> customFragments;
uno::Sequence<OUString> customFragmentTypes;
uno::Sequence<OUString> customFragmentTargets;
+ uno::Sequence<uno::Sequence<beans::StringPair>> aContentTypes;
uno::Sequence<beans::PropertyValue> propList;
xPropSet->getPropertyValue(aName) >>= propList;
@@ -1072,6 +1076,10 @@ void XmlFilterBase::exportCustomFragments()
{
propList[nProp].Value >>= customFragmentTargets;
}
+ else if (propName == "OOXContentTypes")
+ {
+ propList[nProp].Value >>= aContentTypes;
+ }
}
// Expect customXmlDomPropslist.getLength() == customXmlDomlist.getLength().
@@ -1111,10 +1119,16 @@ void XmlFilterBase::exportCustomFragments()
for (sal_Int32 j = 0; j < customFragments.getLength(); j++)
{
addRelation(customFragmentTypes[j], customFragmentTargets[j]);
- Reference<XOutputStream> xOutStream = openOutputStream(customFragmentTargets[j]);
+ const OUString aFilename = customFragmentTargets[j];
+ Reference<XOutputStream> xOutStream = openOutputStream(aFilename);
xOutStream->writeBytes(customFragments[j]);
- // BinaryXInputStream aInStrm(openOutputStream(customFragmentTargets[j]), true);
- // aInStrm.copyToStream(xOutputStream);
+ uno::Reference<XPropertySet> xProps(xOutStream, uno::UNO_QUERY);
+ if (xProps.is())
+ {
+ const OUString aType = comphelper::OFOPXMLHelper::GetContentTypeByName(aContentTypes, aFilename);
+ const OUString aContentType = (aType.getLength() ? aType : OUString("application/octet-stream"));
+ xProps->setPropertyValue("MediaType", uno::makeAny(aContentType));
+ }
}
}