summaryrefslogtreecommitdiffstats
path: root/writerperfect/source/wpdimp
diff options
context:
space:
mode:
Diffstat (limited to 'writerperfect/source/wpdimp')
-rw-r--r--writerperfect/source/wpdimp/WordPerfectCollector.cxx13
-rw-r--r--writerperfect/source/wpdimp/WordPerfectCollector.hxx8
-rw-r--r--writerperfect/source/wpdimp/WordPerfectImportFilter.cxx172
-rw-r--r--writerperfect/source/wpdimp/WordPerfectImportFilter.hxx60
-rw-r--r--writerperfect/source/wpdimp/makefile.mk4
-rw-r--r--writerperfect/source/wpdimp/wpft_genericfilter.cxx23
6 files changed, 260 insertions, 20 deletions
diff --git a/writerperfect/source/wpdimp/WordPerfectCollector.cxx b/writerperfect/source/wpdimp/WordPerfectCollector.cxx
index a5b57181af78..83fdec5ff9cd 100644
--- a/writerperfect/source/wpdimp/WordPerfectCollector.cxx
+++ b/writerperfect/source/wpdimp/WordPerfectCollector.cxx
@@ -36,8 +36,9 @@
#pragma warning( pop )
#endif
-WordPerfectCollector::WordPerfectCollector(WPSInputStream *pInput, DocumentHandler *pHandler) :
- DocumentCollector(pInput, pHandler)
+WordPerfectCollector::WordPerfectCollector(WPXInputStream *pInput, DocumentHandlerInterface *pHandler, const rtl::OString& password) :
+ DocumentCollector(pInput, pHandler),
+ maUtf8Password(password)
{
}
@@ -45,9 +46,13 @@ WordPerfectCollector::~WordPerfectCollector()
{
}
-bool WordPerfectCollector::parseSourceDocument(WPSInputStream &input)
+bool WordPerfectCollector::parseSourceDocument(WPXInputStream &input)
{
- WPDResult result = WPDocument::parse(&input, static_cast<WPXHLListenerImpl *>(this));
+ WPDResult result;
+ if (maUtf8Password.getLength())
+ result = WPDocument::parse(&input, static_cast<WPXDocumentInterface *>(this), maUtf8Password.getStr());
+ else
+ result = WPDocument::parse(&input, static_cast<WPXDocumentInterface *>(this), NULL);
if (result != WPD_OK)
return false;
diff --git a/writerperfect/source/wpdimp/WordPerfectCollector.hxx b/writerperfect/source/wpdimp/WordPerfectCollector.hxx
index b38cba0646b3..fce25691e951 100644
--- a/writerperfect/source/wpdimp/WordPerfectCollector.hxx
+++ b/writerperfect/source/wpdimp/WordPerfectCollector.hxx
@@ -31,13 +31,17 @@
#define _WORDPERFECTCOLLECTOR_HXX
#include "filter/DocumentCollector.hxx"
+#include "filter/DocumentHandlerInterface.hxx"
+#include <rtl/ustring.hxx>
class WordPerfectCollector : public DocumentCollector
{
public:
- WordPerfectCollector(WPSInputStream *pInput, DocumentHandler *pHandler);
+ WordPerfectCollector(WPXInputStream *pInput, DocumentHandlerInterface *pHandler, const rtl::OString& password);
virtual ~WordPerfectCollector();
- bool parseSourceDocument(WPSInputStream &pInput);
+ bool parseSourceDocument(WPXInputStream &pInput);
+private:
+ rtl::OString maUtf8Password;
};
#endif
diff --git a/writerperfect/source/wpdimp/WordPerfectImportFilter.cxx b/writerperfect/source/wpdimp/WordPerfectImportFilter.cxx
index 560940814838..606b6160f686 100644
--- a/writerperfect/source/wpdimp/WordPerfectImportFilter.cxx
+++ b/writerperfect/source/wpdimp/WordPerfectImportFilter.cxx
@@ -1,7 +1,5 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* WordPerfectImportFilter: Sets up the filter, and calls DocumentCollector
- * to do the actual filtering
- *
+/*
* Copyright (C) 2000 by Sun Microsystems, Inc.
* Copyright (C) 2002-2004 William Lachance (wlach@interlog.com)
* Copyright (C) 2004 Net Integration Technologies (http://www.net-itech.com)
@@ -32,16 +30,16 @@
#include <osl/diagnose.h>
#include <rtl/tencinfo.h>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
-#include <com/sun/star/io/XInputStream.hpp>
#include <com/sun/star/xml/sax/XAttributeList.hpp>
#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
#include <com/sun/star/xml/sax/InputSource.hpp>
#include <com/sun/star/xml/sax/XParser.hpp>
-
+#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
#include <com/sun/star/ucb/XCommandEnvironment.hpp>
#include <xmloff/attrlist.hxx>
#include <ucbhelper/content.hxx>
+#include <sfx2/passwd.hxx>
#include "filter/FilterInternal.hxx"
#include "filter/DocumentHandler.hxx"
@@ -107,11 +105,38 @@ sal_Bool SAL_CALL WordPerfectImportFilter::importImpl( const Sequence< ::com::su
OSL_ASSERT( 0 );
return sal_False;
}
- OString sFileName;
- sFileName = OUStringToOString(sURL, RTL_TEXTENCODING_INFO_ASCII);
+
+ WPXSvInputStream input( xInputStream );
+
+ OString aUtf8Passwd;
+
+#if 1
+ WPDConfidence confidence = WPDocument::isFileFormatSupported(&input);
+
+ if (WPD_CONFIDENCE_SUPPORTED_ENCRYPTION == confidence)
+ {
+ int unsuccessfulAttempts = 0;
+ while (true )
+ {
+ SfxPasswordDialog aPasswdDlg( 0 );
+ aPasswdDlg.SetMinLen(0);
+ if(!aPasswdDlg.Execute())
+ return sal_False;
+ String aPasswd = aPasswdDlg.GetPassword();
+ OUString aUniPasswd(aPasswd.GetBuffer() /*, aPasswd.Len(), RTL_TEXTENCODING_UCS2 */);
+ aUtf8Passwd = OUStringToOString(aUniPasswd, RTL_TEXTENCODING_UTF8);
+ if (WPD_PASSWORD_MATCH_OK == WPDocument::verifyPassword(&input, aUtf8Passwd.getStr()))
+ break;
+ else
+ unsuccessfulAttempts++;
+ if (unsuccessfulAttempts == 3) // timeout after 3 password atempts
+ return sal_False;
+ }
+ }
+#endif
// An XML import service: what we push sax messages to..
- OUString sXMLImportService ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.Writer.XMLImporter" ) );
+ OUString sXMLImportService ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.Writer.XMLOasisImporter" ) );
uno::Reference < XDocumentHandler > xInternalHandler( mxMSF->createInstance( sXMLImportService ), UNO_QUERY );
// The XImporter sets up an empty target document for XDocumentHandler to write to..
@@ -122,9 +147,7 @@ sal_Bool SAL_CALL WordPerfectImportFilter::importImpl( const Sequence< ::com::su
// writes to in-memory target doc
DocumentHandler xHandler(xInternalHandler);
- WPXSvInputStream input( xInputStream );
-
- WordPerfectCollector collector(&input, &xHandler);
+ WordPerfectCollector collector(&input, &xHandler, aUtf8Passwd);
collector.filter();
return true;
@@ -196,9 +219,9 @@ OUString SAL_CALL WordPerfectImportFilter::detect( com::sun::star::uno::Sequence
if (input.atEOS())
return ::rtl::OUString();
- confidence = WPDocument::isFileFormatSupported(&input, false);
+ confidence = WPDocument::isFileFormatSupported(&input);
- if (confidence == WPD_CONFIDENCE_EXCELLENT)
+ if (confidence == WPD_CONFIDENCE_EXCELLENT || confidence == WPD_CONFIDENCE_SUPPORTED_ENCRYPTION)
sTypeName = OUString( RTL_CONSTASCII_USTRINGPARAM ( "writer_WordPerfect_Document" ) );
if (sTypeName.getLength())
@@ -255,7 +278,6 @@ Sequence< OUString > SAL_CALL WordPerfectImportFilter_getSupportedServiceNames(
throw (RuntimeException)
{
Sequence < OUString > aRet(2);
-// Sequence < OUString > aRet(1);
OUString* pArray = aRet.getArray();
pArray[0] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME1 ) );
pArray[1] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME2 ) );
@@ -287,4 +309,126 @@ Sequence< OUString > SAL_CALL WordPerfectImportFilter::getSupportedServiceNames(
return WordPerfectImportFilter_getSupportedServiceNames();
}
+
+WordPerfectImportFilterDialog::WordPerfectImportFilterDialog(const ::com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory > &r ) :
+ mxMSF( r ) {}
+
+WordPerfectImportFilterDialog::~WordPerfectImportFilterDialog()
+{
+}
+
+void SAL_CALL WordPerfectImportFilterDialog::setTitle( const ::rtl::OUString& )
+ throw (::com::sun::star::uno::RuntimeException)
+{
+}
+
+sal_Int16 SAL_CALL WordPerfectImportFilterDialog::execute()
+ throw (::com::sun::star::uno::RuntimeException)
+{
+ WPXSvInputStream input( mxInputStream );
+
+ OString aUtf8Passwd;
+
+ WPDConfidence confidence = WPDocument::isFileFormatSupported(&input);
+
+ if (WPD_CONFIDENCE_SUPPORTED_ENCRYPTION == confidence)
+ {
+ int unsuccessfulAttempts = 0;
+ while (true )
+ {
+ SfxPasswordDialog aPasswdDlg(0);
+ aPasswdDlg.SetMinLen(0);
+ if(!aPasswdDlg.Execute())
+ return com::sun::star::ui::dialogs::ExecutableDialogResults::CANCEL;
+ msPassword = ::rtl::OUString(aPasswdDlg.GetPassword().GetBuffer());
+ aUtf8Passwd = OUStringToOString(msPassword, RTL_TEXTENCODING_UTF8);
+ if (WPD_PASSWORD_MATCH_OK == WPDocument::verifyPassword(&input, aUtf8Passwd.getStr()))
+ break;
+ else
+ unsuccessfulAttempts++;
+ if (unsuccessfulAttempts == 3) // timeout after 3 password atempts
+ return com::sun::star::ui::dialogs::ExecutableDialogResults::CANCEL;
+ }
+ }
+ return com::sun::star::ui::dialogs::ExecutableDialogResults::OK;
+}
+
+uno::Sequence<beans::PropertyValue> SAL_CALL WordPerfectImportFilterDialog::getPropertyValues() throw(uno::RuntimeException)
+{
+ uno::Sequence<beans::PropertyValue> aRet(1);
+ beans::PropertyValue* pArray = aRet.getArray();
+
+ pArray[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Password") );
+ pArray[0].Value <<= msPassword;
+
+ return aRet;
+}
+
+void SAL_CALL WordPerfectImportFilterDialog::setPropertyValues( const uno::Sequence<beans::PropertyValue>& aProps)
+ throw(beans::UnknownPropertyException, beans::PropertyVetoException,
+ lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
+{
+ const beans::PropertyValue* pPropArray = aProps.getConstArray();
+ long nPropCount = aProps.getLength();
+ for (long i = 0; i < nPropCount; i++)
+ {
+ const beans::PropertyValue& rProp = pPropArray[i];
+ ::rtl::OUString aPropName = rProp.Name;
+
+ if ( aPropName == ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Password")) )
+ rProp.Value >>= msPassword;
+ else if ( aPropName.equalsAscii( "InputStream" ) )
+ rProp.Value >>= mxInputStream;
+ }
+}
+
+
+// XServiceInfo
+OUString SAL_CALL WordPerfectImportFilterDialog::getImplementationName( )
+ throw (RuntimeException)
+{
+ return WordPerfectImportFilterDialog_getImplementationName();
+}
+
+sal_Bool SAL_CALL WordPerfectImportFilterDialog::supportsService( const OUString& rServiceName )
+ throw (RuntimeException)
+{
+ return WordPerfectImportFilterDialog_supportsService( rServiceName );
+}
+
+Sequence< OUString > SAL_CALL WordPerfectImportFilterDialog::getSupportedServiceNames( )
+ throw (RuntimeException)
+{
+ return WordPerfectImportFilterDialog_getSupportedServiceNames();
+}
+
+OUString WordPerfectImportFilterDialog_getImplementationName ()
+ throw (RuntimeException)
+{
+ return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.Writer.WordPerfectImportFilterDialog" ) );
+}
+
+#define SERVICE_NAME "com.sun.star.ui.dialogs.FilterOptionsDialog"
+sal_Bool SAL_CALL WordPerfectImportFilterDialog_supportsService( const OUString& ServiceName )
+ throw (RuntimeException)
+{
+ return ( ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) ) );
+}
+
+Sequence< OUString > SAL_CALL WordPerfectImportFilterDialog_getSupportedServiceNames( )
+ throw (RuntimeException)
+{
+ Sequence < OUString > aRet(1);
+ OUString* pArray = aRet.getArray();
+ pArray[0] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
+ return aRet;
+}
+#undef SERVICE_NAME
+
+uno::Reference< XInterface > SAL_CALL WordPerfectImportFilterDialog_createInstance( const uno::Reference< XMultiServiceFactory > & rSMgr)
+ throw( Exception )
+{
+ return (cppu::OWeakObject*) new WordPerfectImportFilterDialog( rSMgr );
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerperfect/source/wpdimp/WordPerfectImportFilter.hxx b/writerperfect/source/wpdimp/WordPerfectImportFilter.hxx
index 2a4cc666cdca..50b995ff70bf 100644
--- a/writerperfect/source/wpdimp/WordPerfectImportFilter.hxx
+++ b/writerperfect/source/wpdimp/WordPerfectImportFilter.hxx
@@ -33,9 +33,13 @@
#include <com/sun/star/document/XFilter.hpp>
#include <com/sun/star/document/XImporter.hpp>
#include <com/sun/star/document/XExtendedFilterDetection.hpp>
+#include <com/sun/star/beans/XPropertyAccess.hpp>
+#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include <com/sun/star/io/XInputStream.hpp>
+#include <cppuhelper/implbase3.hxx>
#include <cppuhelper/implbase5.hxx>
enum FilterType
@@ -113,6 +117,62 @@ sal_Bool SAL_CALL WordPerfectImportFilter_supportsService( const ::rtl::OUString
SAL_CALL WordPerfectImportFilter_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr)
throw ( ::com::sun::star::uno::Exception );
+
+class WordPerfectImportFilterDialog : public cppu::WeakImplHelper3 <
+ com::sun::star::ui::dialogs::XExecutableDialog,
+ com::sun::star::lang::XServiceInfo,
+ com::sun::star::beans::XPropertyAccess
+>
+{
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMSF;
+ ::rtl::OUString msPassword;
+ ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > mxInputStream;
+
+ ~WordPerfectImportFilterDialog();
+
+ // XExecutableDialog
+ virtual void SAL_CALL setTitle( const ::rtl::OUString& aTitle )
+ throw (::com::sun::star::uno::RuntimeException);
+ virtual sal_Int16 SAL_CALL execute()
+ throw (::com::sun::star::uno::RuntimeException);
+
+ // XServiceInfo
+ virtual ::rtl::OUString SAL_CALL getImplementationName( )
+ throw (::com::sun::star::uno::RuntimeException);
+ virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
+ throw (::com::sun::star::uno::RuntimeException);
+ virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( )
+ throw (::com::sun::star::uno::RuntimeException);
+
+ // XPropertyAccess
+ virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >
+ SAL_CALL getPropertyValues() throw (::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL setPropertyValues( const ::com::sun::star::uno::Sequence<
+ ::com::sun::star::beans::PropertyValue >& aProps )
+ throw (::com::sun::star::beans::UnknownPropertyException,
+ ::com::sun::star::beans::PropertyVetoException,
+ ::com::sun::star::lang::IllegalArgumentException,
+ ::com::sun::star::lang::WrappedTargetException,
+ ::com::sun::star::uno::RuntimeException);
+
+public:
+ WordPerfectImportFilterDialog(const ::com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory > &r );
+
+};
+
+::rtl::OUString WordPerfectImportFilterDialog_getImplementationName()
+ throw ( ::com::sun::star::uno::RuntimeException );
+
+sal_Bool SAL_CALL WordPerfectImportFilterDialog_supportsService( const ::rtl::OUString& ServiceName )
+ throw ( ::com::sun::star::uno::RuntimeException );
+
+::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL WordPerfectImportFilterDialog_getSupportedServiceNames( )
+ throw ( ::com::sun::star::uno::RuntimeException );
+
+::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
+SAL_CALL WordPerfectImportFilterDialog_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr)
+ throw ( ::com::sun::star::uno::Exception );
+
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerperfect/source/wpdimp/makefile.mk b/writerperfect/source/wpdimp/makefile.mk
index 745887eb8588..e2dd8d746546 100644
--- a/writerperfect/source/wpdimp/makefile.mk
+++ b/writerperfect/source/wpdimp/makefile.mk
@@ -10,6 +10,10 @@ ENABLE_EXCEPTIONS=true
INCPRE+=$(LIBWPD_CFLAGS)
.ENDIF
+.IF "$(SYSTEM_LIBWPG)" == "YES"
+INCPRE+=$(LIBWPG_CFLAGS)
+.ENDIF
+
.IF "$(SYSTEM_LIBWPS)" == "YES"
INCPRE+=$(LIBWPS_CFLAGS)
.ENDIF
diff --git a/writerperfect/source/wpdimp/wpft_genericfilter.cxx b/writerperfect/source/wpdimp/wpft_genericfilter.cxx
index 36378097ed35..216753640352 100644
--- a/writerperfect/source/wpdimp/wpft_genericfilter.cxx
+++ b/writerperfect/source/wpdimp/wpft_genericfilter.cxx
@@ -63,7 +63,15 @@ sal_Bool SAL_CALL component_writeInfo(
const OUString * pArray = rSNL.getConstArray();
for ( nPos = rSNL.getLength(); nPos--; )
xNewKey->createKey( pArray[nPos] );
+#if 0
+ xNewKey = reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( WordPerfectImportFilterDialog_getImplementationName() );
+ xNewKey = xNewKey->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
+ const Sequence< OUString > & rSNL2 = WordPerfectImportFilterDialog_getSupportedServiceNames();
+ pArray = rSNL2.getConstArray();
+ for ( nPos = rSNL2.getLength(); nPos--; )
+ xNewKey->createKey( pArray[nPos] );
+#endif
return sal_True;
}
catch (InvalidRegistryException &)
@@ -93,6 +101,21 @@ void * SAL_CALL component_getFactory(
pRet = xFactory.get();
}
}
+#if 0
+ else if ( pServiceManager && implName.equals(WordPerfectImportFilterDialog_getImplementationName()) )
+ {
+ Reference< XSingleServiceFactory > xFactory( createSingleFactory(
+ reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
+ OUString::createFromAscii( pImplName ),
+ WordPerfectImportFilterDialog_createInstance, WordPerfectImportFilterDialog_getSupportedServiceNames() ) );
+
+ if (xFactory.is())
+ {
+ xFactory->acquire();
+ pRet = xFactory.get();
+ }
+ }
+#endif
return pRet;
}