diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-05-03 17:04:04 +0200 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2021-05-06 10:41:11 +0200 |
commit | a8e84a2d6e634c03d62e17bcc1b617238dcc9eb1 (patch) | |
tree | 5ab180f9e3fef38ff91dec59ad6e475762910a22 /filter | |
parent | tdf#141945 sw: layout: check master frame when moving fly forward (diff) | |
download | core-a8e84a2d6e634c03d62e17bcc1b617238dcc9eb1.tar.gz core-a8e84a2d6e634c03d62e17bcc1b617238dcc9eb1.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>
(cherry picked from commit dff586735b6618d9b011823594a33287d8f7f223)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114925
Reviewed-by: Caolán McNamara <caolanm@redhat.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); } |