1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: filtuno.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
37 #include <tools/urlobj.hxx>
38 #include <vcl/msgbox.hxx>
39 #include <unotools/ucbstreamhelper.hxx>
41 #include "editutil.hxx"
42 #include "filtuno.hxx"
43 #include "miscuno.hxx"
44 #include "unoguard.hxx"
46 #include "imoptdlg.hxx"
47 #include "asciiopt.hxx"
49 #include "globstr.hrc"
52 #include "sc.hrc" //CHINA001
53 #include "scabstdlg.hxx" //CHINA001
54 #include "i18npool/lang.h"
58 using namespace ::com::sun::star
;
60 //------------------------------------------------------------------------
62 #define SCFILTEROPTIONSOBJ_SERVICE "com.sun.star.ui.dialogs.FilterOptionsDialog"
63 #define SCFILTEROPTIONSOBJ_IMPLNAME "com.sun.star.comp.Calc.FilterOptionsDialog"
65 SC_SIMPLE_SERVICE_INFO( ScFilterOptionsObj
, SCFILTEROPTIONSOBJ_IMPLNAME
, SCFILTEROPTIONSOBJ_SERVICE
)
67 #define SC_UNONAME_FILENAME "URL"
68 #define SC_UNONAME_FILTERNAME "FilterName"
69 #define SC_UNONAME_FILTEROPTIONS "FilterOptions"
70 #define SC_UNONAME_INPUTSTREAM "InputStream"
72 //------------------------------------------------------------------------
74 ScFilterOptionsObj::ScFilterOptionsObj() :
79 ScFilterOptionsObj::~ScFilterOptionsObj()
83 // stuff for exService_...
85 uno::Reference
<uno::XInterface
> SAL_CALL
ScFilterOptionsObj_CreateInstance(
86 const uno::Reference
<lang::XMultiServiceFactory
>& )
90 return (::cppu::OWeakObject
*) new ScFilterOptionsObj
;
93 rtl::OUString
ScFilterOptionsObj::getImplementationName_Static()
95 return rtl::OUString::createFromAscii( SCFILTEROPTIONSOBJ_IMPLNAME
);
98 uno::Sequence
<rtl::OUString
> ScFilterOptionsObj::getSupportedServiceNames_Static()
100 uno::Sequence
<rtl::OUString
> aRet(1);
101 rtl::OUString
* pArray
= aRet
.getArray();
102 pArray
[0] = rtl::OUString::createFromAscii( SCFILTEROPTIONSOBJ_SERVICE
);
108 uno::Sequence
<beans::PropertyValue
> SAL_CALL
ScFilterOptionsObj::getPropertyValues() throw(uno::RuntimeException
)
110 uno::Sequence
<beans::PropertyValue
> aRet(1);
111 beans::PropertyValue
* pArray
= aRet
.getArray();
113 pArray
[0].Name
= rtl::OUString::createFromAscii( SC_UNONAME_FILTEROPTIONS
);
114 pArray
[0].Value
<<= aFilterOptions
;
119 void SAL_CALL
ScFilterOptionsObj::setPropertyValues( const uno::Sequence
<beans::PropertyValue
>& aProps
)
120 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
,
121 lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
)
123 const beans::PropertyValue
* pPropArray
= aProps
.getConstArray();
124 long nPropCount
= aProps
.getLength();
125 for (long i
= 0; i
< nPropCount
; i
++)
127 const beans::PropertyValue
& rProp
= pPropArray
[i
];
128 String
aPropName(rProp
.Name
);
130 if ( aPropName
.EqualsAscii( SC_UNONAME_FILENAME
) )
131 rProp
.Value
>>= aFileName
;
132 else if ( aPropName
.EqualsAscii( SC_UNONAME_FILTERNAME
) )
133 rProp
.Value
>>= aFilterName
;
134 else if ( aPropName
.EqualsAscii( SC_UNONAME_FILTEROPTIONS
) )
135 rProp
.Value
>>= aFilterOptions
;
136 else if ( aPropName
.EqualsAscii( SC_UNONAME_INPUTSTREAM
) )
137 rProp
.Value
>>= xInputStream
;
143 void SAL_CALL
ScFilterOptionsObj::setTitle( const ::rtl::OUString
& /* aTitle */ ) throw(uno::RuntimeException
)
148 sal_Int16 SAL_CALL
ScFilterOptionsObj::execute() throw(uno::RuntimeException
)
150 sal_Int16 nRet
= ui::dialogs::ExecutableDialogResults::CANCEL
;
152 String
aFilterString( aFilterName
);
154 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
155 DBG_ASSERT(pFact
, "ScAbstractFactory create fail!");
157 if ( !bExport
&& aFilterString
== ScDocShell::GetAsciiFilterName() )
159 // ascii import is special...
161 INetURLObject
aURL( aFileName
);
162 String
aExt(aURL
.getExtension());
163 String
aPrivDatName(aURL
.getName());
164 sal_Unicode cAsciiDel
;
165 if (aExt
.EqualsIgnoreCaseAscii("CSV"))
170 SvStream
* pInStream
= NULL
;
171 if ( xInputStream
.is() )
172 pInStream
= utl::UcbStreamHelper::CreateStream( xInputStream
);
174 //CHINA001 ScImportAsciiDlg* pDlg = new ScImportAsciiDlg( NULL, aPrivDatName, pInStream, cAsciiDel );
175 AbstractScImportAsciiDlg
* pDlg
= pFact
->CreateScImportAsciiDlg( NULL
, aPrivDatName
, pInStream
, RID_SCDLG_ASCII
, cAsciiDel
);
176 DBG_ASSERT(pDlg
, "Dialog create fail!");//CHINA001
177 if ( pDlg
->Execute() == RET_OK
)
179 ScAsciiOptions aOptions
;
180 pDlg
->GetOptions( aOptions
);
181 aFilterOptions
= aOptions
.WriteToString();
182 nRet
= ui::dialogs::ExecutableDialogResults::OK
;
187 else if ( aFilterString
== ScDocShell::GetWebQueryFilterName() )
190 ::std::auto_ptr
<AbstractScLangChooserDlg
> pDlg(
191 pFact
->CreateScLangChooserDlg(NULL
, RID_SCDLG_LANG_CHOOSER
));
193 if (pDlg
->Execute() == RET_OK
)
195 LanguageType eLang
= pDlg
->GetLanguageType();
196 aFilterOptions
= String::CreateFromInt32(static_cast<sal_Int32
>(eLang
));
197 nRet
= ui::dialogs::ExecutableDialogResults::OK
;
202 sal_Bool bMultiByte
= sal_True
;
203 sal_Bool bDBEnc
= sal_False
;
204 sal_Bool bAscii
= sal_False
;
206 sal_Unicode cStrDel
= '"';
207 sal_Unicode cAsciiDel
= ';';
208 rtl_TextEncoding eEncoding
= RTL_TEXTENCODING_DONTKNOW
;
212 if ( aFilterString
== ScDocShell::GetAsciiFilterName() )
214 // ascii export (import is handled above)
216 INetURLObject
aURL( aFileName
);
217 String
aExt(aURL
.getExtension());
218 if (aExt
.EqualsIgnoreCaseAscii("CSV"))
223 aTitle
= ScGlobal::GetRscString( STR_EXPORT_ASCII
);
226 else if ( aFilterString
== ScDocShell::GetLotusFilterName() )
228 // lotus is only imported
229 DBG_ASSERT( !bExport
, "Filter Options for Lotus Export is not implemented" );
231 aTitle
= ScGlobal::GetRscString( STR_IMPORT_LOTUS
);
232 eEncoding
= RTL_TEXTENCODING_IBM_437
;
234 else if ( aFilterString
== ScDocShell::GetDBaseFilterName() )
239 aTitle
= ScGlobal::GetRscString( STR_EXPORT_DBF
);
244 aTitle
= ScGlobal::GetRscString( STR_IMPORT_DBF
);
246 // common for dBase import/export
247 eEncoding
= RTL_TEXTENCODING_IBM_850
;
250 else if ( aFilterString
== ScDocShell::GetDifFilterName() )
255 aTitle
= ScGlobal::GetRscString( STR_EXPORT_DIF
);
260 aTitle
= ScGlobal::GetRscString( STR_IMPORT_DIF
);
262 // common for DIF import/export
263 eEncoding
= RTL_TEXTENCODING_MS_1252
;
266 ScImportOptions
aOptions( cAsciiDel
, cStrDel
, eEncoding
);
267 //CHINA001 ScImportOptionsDlg* pDlg = new ScImportOptionsDlg( NULL, bAscii,
268 //CHINA001 &aOptions, &aTitle, bMultiByte, bDBEnc,
269 //CHINA001 !bExport );
272 AbstractScImportOptionsDlg
* pDlg
= pFact
->CreateScImportOptionsDlg( NULL
, RID_SCDLG_IMPORTOPT
,
273 bAscii
, &aOptions
, &aTitle
, bMultiByte
, bDBEnc
,
275 DBG_ASSERT(pDlg
, "Dialog create fail!");//CHINA001
276 if ( pDlg
->Execute() == RET_OK
)
278 pDlg
->GetImportOptions( aOptions
);
280 aFilterOptions
= aOptions
.BuildString();
282 aFilterOptions
= aOptions
.aStrFont
;
283 nRet
= ui::dialogs::ExecutableDialogResults::OK
;
288 xInputStream
.clear(); // don't hold the stream longer than necessary
295 void SAL_CALL
ScFilterOptionsObj::setTargetDocument( const uno::Reference
<lang::XComponent
>& /* xDoc */ )
296 throw(lang::IllegalArgumentException
, uno::RuntimeException
)
303 void SAL_CALL
ScFilterOptionsObj::setSourceDocument( const uno::Reference
<lang::XComponent
>& /* xDoc */ )
304 throw(lang::IllegalArgumentException
, uno::RuntimeException
)