libwps import filter improvements
+ some astyle modifications, + add .wk4 and .123 to the list of file extensions, + add support to open Lotus files protected by a password. Change-Id: I94d4afffd73f0999ff2b1958704cb3985fcd0cc9
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
<node oor:name="calc_WPS_Lotus_Document" oor:op="replace" >
|
||||
<prop oor:name="DetectService"><value>com.sun.star.comp.Calc.MSWorksCalcImportFilter</value></prop>
|
||||
<prop oor:name="URLPattern"/>
|
||||
<prop oor:name="Extensions"><value>wk1 wk3</value></prop>
|
||||
<prop oor:name="Extensions"><value>wk1 wk3 wk4 123</value></prop>
|
||||
<prop oor:name="MediaType"></prop>
|
||||
<prop oor:name="Preferred"><value>true</value></prop>
|
||||
<prop oor:name="PreferredFilter"><value>WPS_Lotus_Calc</value></prop>
|
||||
|
@@ -33,6 +33,7 @@ $(eval $(call gb_Library_use_libraries,wpftcalc,\
|
||||
cppu \
|
||||
cppuhelper \
|
||||
sal \
|
||||
sfx \
|
||||
sot \
|
||||
svx \
|
||||
tl \
|
||||
|
@@ -16,6 +16,7 @@
|
||||
#include <com/sun/star/ucb/XContentAccess.hpp>
|
||||
#include <comphelper/processfactory.hxx>
|
||||
#include <cppuhelper/supportsservice.hxx>
|
||||
#include <sfx2/passwd.hxx>
|
||||
#include <tools/urlobj.hxx>
|
||||
#include <ucbhelper/content.hxx>
|
||||
|
||||
@@ -191,8 +192,10 @@ bool MSWorksCalcImportFilter::doImportDocument(librevenge::RVNGInputStream &rInp
|
||||
bool needEncoding;
|
||||
const libwps::WPSConfidence confidence = libwps::WPSDocument::isFileFormatSupported(&rInput, kind, creator, needEncoding);
|
||||
|
||||
if ((kind != libwps::WPS_SPREADSHEET && kind != libwps::WPS_DATABASE) || (confidence == libwps::WPS_CONFIDENCE_NONE))
|
||||
return false;
|
||||
std::string fileEncoding("");
|
||||
if ((kind == libwps::WPS_SPREADSHEET || kind == libwps::WPS_DATABASE) && (confidence == libwps::WPS_CONFIDENCE_EXCELLENT) && needEncoding)
|
||||
if (needEncoding)
|
||||
{
|
||||
OUString title, encoding;
|
||||
if (creator == libwps::WPS_MSWORKS)
|
||||
@@ -232,7 +235,25 @@ bool MSWorksCalcImportFilter::doImportDocument(librevenge::RVNGInputStream &rInp
|
||||
SAL_WARN("writerperfect", "ignoring Exception in MSWorksCalcImportFilter::doImportDocument");
|
||||
}
|
||||
}
|
||||
return libwps::WPS_OK == libwps::WPSDocument::parse(&rInput, &rGenerator, "", fileEncoding.c_str());
|
||||
OString aUtf8Passwd;
|
||||
if (confidence==libwps::WPS_CONFIDENCE_SUPPORTED_ENCRYPTION)
|
||||
{
|
||||
// try to ask for a password
|
||||
try
|
||||
{
|
||||
ScopedVclPtrInstance< SfxPasswordDialog > aPasswdDlg(nullptr);
|
||||
aPasswdDlg->SetMinLen(1);
|
||||
if (!aPasswdDlg->Execute())
|
||||
return false;
|
||||
OUString aPasswd = aPasswdDlg->GetPassword();
|
||||
aUtf8Passwd = OUStringToOString(aPasswd, RTL_TEXTENCODING_UTF8);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return libwps::WPS_OK == libwps::WPSDocument::parse(&rInput, &rGenerator, confidence==libwps::WPS_CONFIDENCE_SUPPORTED_ENCRYPTION ? aUtf8Passwd.getStr() : nullptr, fileEncoding.c_str());
|
||||
}
|
||||
|
||||
//XExtendedFilterDetection
|
||||
@@ -326,12 +347,12 @@ sal_Bool MSWorksCalcImportFilter::filter(const css::uno::Sequence< css::beans::P
|
||||
structuredInput.addFile(sWM3Name,"WK3");
|
||||
structuredInput.addFile(sFM3Name,"FM3");
|
||||
|
||||
// If the file is valid and libwps is at least 0.4.4, doImportDocument will convert it.
|
||||
// If libwps is at most 0.4.3, doImportDocument will fail when checking if the file is supported
|
||||
// and it is ok to call again doImportDocument with the main input.
|
||||
// If the file is corrupted beyond all retrieval, doImportDocument will fail two times :-~
|
||||
if (this->doImportDocument(structuredInput, exporter, aDescriptor))
|
||||
return true;
|
||||
libwps::WPSKind kind = libwps::WPS_TEXT;
|
||||
libwps::WPSCreator creator;
|
||||
bool needEncoding;
|
||||
const libwps::WPSConfidence confidence = libwps::WPSDocument::isFileFormatSupported(&structuredInput, kind, creator, needEncoding);
|
||||
if (confidence!=libwps::WPS_CONFIDENCE_NONE)
|
||||
return this->doImportDocument(structuredInput, exporter, aDescriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -350,7 +371,7 @@ bool MSWorksCalcImportFilter::doDetectFormat(librevenge::RVNGInputStream &rInput
|
||||
bool needEncoding;
|
||||
const libwps::WPSConfidence confidence = libwps::WPSDocument::isFileFormatSupported(&rInput, kind, creator, needEncoding);
|
||||
|
||||
if ((kind == libwps::WPS_SPREADSHEET || kind == libwps::WPS_DATABASE) && confidence == libwps::WPS_CONFIDENCE_EXCELLENT)
|
||||
if ((kind == libwps::WPS_SPREADSHEET || kind == libwps::WPS_DATABASE) && confidence != libwps::WPS_CONFIDENCE_NONE)
|
||||
{
|
||||
if (creator == libwps::WPS_MSWORKS)
|
||||
{
|
||||
|
Reference in New Issue
Block a user