summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2021-05-03 17:04:04 +0200
committerMike Kaganski <mike.kaganski@collabora.com>2021-05-11 07:18:15 +0200
commitdb759800abb62a9abda39c16d6f529d1a76207b6 (patch)
tree274e7fa1a13366a8ce9b50f80cf3c1d6dbaef23f
parent069eb92600bc1abaf5cd08bb786402f820a17c3c (diff)
tdf#123476: also use filter by extension when its service is the samedistro/collabora/co-2021
... 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> (cherry picked from commit a8e84a2d6e634c03d62e17bcc1b617238dcc9eb1) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115278 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
-rw-r--r--filter/source/textfilterdetect/filterdetect.cxx18
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);
}