diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-05-03 17:04:04 +0200 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-05-03 18:38:38 +0200 |
commit | dff586735b6618d9b011823594a33287d8f7f223 (patch) | |
tree | b68025662bc28e5fbb9c0af689b74e719e86a68a /filter | |
parent | tdf#80149: sc_subsequent_export: Add unittest (diff) | |
download | core-dff586735b6618d9b011823594a33287d8f7f223.tar.gz core-dff586735b6618d9b011823594a33287d8f7f223.zip |
tdf#123476: also use filter by extension when its service is the same
... as passed explicitly in the media descriptor, for 0-byte files.
This makes proper handling for such files when passing module name
in command line, like --writer for DOCX.
Change-Id: If8fd51e65dcf8a67b2653026f5fc1d5c964074af
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114924
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'filter')
-rw-r--r-- | filter/source/textfilterdetect/filterdetect.cxx | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/filter/source/textfilterdetect/filterdetect.cxx b/filter/source/textfilterdetect/filterdetect.cxx index 09efe5e595e0..19696ec9fa17 100644 --- a/filter/source/textfilterdetect/filterdetect.cxx +++ b/filter/source/textfilterdetect/filterdetect.cxx @@ -135,7 +135,7 @@ bool IsHTMLStream( const uno::Reference<io::XInputStream>& xInStream ) * writes the type name to rType, the filter name to rMediaDesc. */ bool HandleEmptyFileUrlByExtension(MediaDescriptor& rMediaDesc, const OUString& rExt, - OUString& rType) + OUString& rType, OUString& rService) { OUString aURL = rMediaDesc.getUnpackedValueOrDefault(MediaDescriptor::PROP_URL(), OUString()); if (!tools::isEmptyFileUrl(aURL)) @@ -156,6 +156,7 @@ bool HandleEmptyFileUrlByExtension(MediaDescriptor& rMediaDesc, const OUString& rMediaDesc[MediaDescriptor::PROP_FILTERNAME()] <<= pFilter->GetFilterName(); rType = pFilter->GetTypeName(); + rService = pFilter->GetServiceName(); return true; } } @@ -216,14 +217,25 @@ OUString SAL_CALL PlainTextFilterDetect::detect(uno::Sequence<beans::PropertyVal OUString aName = aParser.getName().toAsciiLowerCase(); // Decide which filter to use based on the document service first, - // then on extension if that's not available. + // then on extension if that's not available. Make exception for 0-byte files + // whose extensions are handled by the same service as passed document service. + OUString aEmptyType, aEmptyService; + bool bEmpty = HandleEmptyFileUrlByExtension(aMediaDesc, aExt, aEmptyType, aEmptyService); + if (bEmpty && aDocService == aEmptyService) + { + aDocService.clear(); // don't fallback to text filter, use extension-based match + // TODO: maybe reset aExt when it's "xls" + } + if (aDocService == CALC_DOCSERVICE) aMediaDesc[MediaDescriptor::PROP_FILTERNAME()] <<= OUString(CALC_TEXT_FILTER); else if (aDocService == WRITER_DOCSERVICE) aMediaDesc[MediaDescriptor::PROP_FILTERNAME()] <<= OUString(WRITER_TEXT_FILTER); else if (aExt == "csv" || aExt == "tsv" || aExt == "tab" || aExt == "xls" || aName.endsWith(".csv.gz")) aMediaDesc[MediaDescriptor::PROP_FILTERNAME()] <<= OUString(CALC_TEXT_FILTER); - else if (!HandleEmptyFileUrlByExtension(aMediaDesc, aExt, aType)) + else if (bEmpty) + aType = aEmptyType; // aMediaDesc is already updated in HandleEmptyFileUrlByExtension + else aMediaDesc[MediaDescriptor::PROP_FILTERNAME()] <<= OUString(WRITER_TEXT_FILTER); } |