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
;
59 using ::rtl::OUStringBuffer
;
61 //------------------------------------------------------------------------
63 #define SCFILTEROPTIONSOBJ_SERVICE "com.sun.star.ui.dialogs.FilterOptionsDialog"
64 #define SCFILTEROPTIONSOBJ_IMPLNAME "com.sun.star.comp.Calc.FilterOptionsDialog"
66 SC_SIMPLE_SERVICE_INFO( ScFilterOptionsObj
, SCFILTEROPTIONSOBJ_IMPLNAME
, SCFILTEROPTIONSOBJ_SERVICE
)
68 #define SC_UNONAME_FILENAME "URL"
69 #define SC_UNONAME_FILTERNAME "FilterName"
70 #define SC_UNONAME_FILTEROPTIONS "FilterOptions"
71 #define SC_UNONAME_INPUTSTREAM "InputStream"
73 //------------------------------------------------------------------------
75 ScFilterOptionsObj::ScFilterOptionsObj() :
80 ScFilterOptionsObj::~ScFilterOptionsObj()
84 // stuff for exService_...
86 uno::Reference
<uno::XInterface
> SAL_CALL
ScFilterOptionsObj_CreateInstance(
87 const uno::Reference
<lang::XMultiServiceFactory
>& )
91 return (::cppu::OWeakObject
*) new ScFilterOptionsObj
;
94 rtl::OUString
ScFilterOptionsObj::getImplementationName_Static()
96 return rtl::OUString::createFromAscii( SCFILTEROPTIONSOBJ_IMPLNAME
);
99 uno::Sequence
<rtl::OUString
> ScFilterOptionsObj::getSupportedServiceNames_Static()
101 uno::Sequence
<rtl::OUString
> aRet(1);
102 rtl::OUString
* pArray
= aRet
.getArray();
103 pArray
[0] = rtl::OUString::createFromAscii( SCFILTEROPTIONSOBJ_SERVICE
);
109 uno::Sequence
<beans::PropertyValue
> SAL_CALL
ScFilterOptionsObj::getPropertyValues() throw(uno::RuntimeException
)
111 uno::Sequence
<beans::PropertyValue
> aRet(1);
112 beans::PropertyValue
* pArray
= aRet
.getArray();
114 pArray
[0].Name
= rtl::OUString::createFromAscii( SC_UNONAME_FILTEROPTIONS
);
115 pArray
[0].Value
<<= aFilterOptions
;
120 void SAL_CALL
ScFilterOptionsObj::setPropertyValues( const uno::Sequence
<beans::PropertyValue
>& aProps
)
121 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
,
122 lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
)
124 const beans::PropertyValue
* pPropArray
= aProps
.getConstArray();
125 long nPropCount
= aProps
.getLength();
126 for (long i
= 0; i
< nPropCount
; i
++)
128 const beans::PropertyValue
& rProp
= pPropArray
[i
];
129 String
aPropName(rProp
.Name
);
131 if ( aPropName
.EqualsAscii( SC_UNONAME_FILENAME
) )
132 rProp
.Value
>>= aFileName
;
133 else if ( aPropName
.EqualsAscii( SC_UNONAME_FILTERNAME
) )
134 rProp
.Value
>>= aFilterName
;
135 else if ( aPropName
.EqualsAscii( SC_UNONAME_FILTEROPTIONS
) )
136 rProp
.Value
>>= aFilterOptions
;
137 else if ( aPropName
.EqualsAscii( SC_UNONAME_INPUTSTREAM
) )
138 rProp
.Value
>>= xInputStream
;
144 void SAL_CALL
ScFilterOptionsObj::setTitle( const ::rtl::OUString
& /* aTitle */ ) throw(uno::RuntimeException
)
149 sal_Int16 SAL_CALL
ScFilterOptionsObj::execute() throw(uno::RuntimeException
)
151 sal_Int16 nRet
= ui::dialogs::ExecutableDialogResults::CANCEL
;
153 String
aFilterString( aFilterName
);
155 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
156 DBG_ASSERT(pFact
, "ScAbstractFactory create fail!");
158 if ( !bExport
&& aFilterString
== ScDocShell::GetAsciiFilterName() )
160 // ascii import is special...
162 INetURLObject
aURL( aFileName
);
163 String
aExt(aURL
.getExtension());
164 String
aPrivDatName(aURL
.getName());
165 sal_Unicode cAsciiDel
;
166 if (aExt
.EqualsIgnoreCaseAscii("CSV"))
171 SvStream
* pInStream
= NULL
;
172 if ( xInputStream
.is() )
173 pInStream
= utl::UcbStreamHelper::CreateStream( xInputStream
);
175 //CHINA001 ScImportAsciiDlg* pDlg = new ScImportAsciiDlg( NULL, aPrivDatName, pInStream, cAsciiDel );
176 AbstractScImportAsciiDlg
* pDlg
= pFact
->CreateScImportAsciiDlg( NULL
, aPrivDatName
, pInStream
, RID_SCDLG_ASCII
, cAsciiDel
);
177 DBG_ASSERT(pDlg
, "Dialog create fail!");//CHINA001
178 if ( pDlg
->Execute() == RET_OK
)
180 ScAsciiOptions aOptions
;
181 pDlg
->GetOptions( aOptions
);
182 aFilterOptions
= aOptions
.WriteToString();
183 nRet
= ui::dialogs::ExecutableDialogResults::OK
;
188 else if ( aFilterString
== ScDocShell::GetWebQueryFilterName() || aFilterString
== ScDocShell::GetHtmlFilterName() )
191 ::std::auto_ptr
<AbstractScTextImportOptionsDlg
> pDlg(
192 pFact
->CreateScTextImportOptionsDlg(NULL
, RID_SCDLG_TEXT_IMPORT_OPTIONS
));
194 if (pDlg
->Execute() == RET_OK
)
196 LanguageType eLang
= pDlg
->GetLanguageType();
199 aBuf
.append(String::CreateFromInt32(static_cast<sal_Int32
>(eLang
)));
200 aBuf
.append(sal_Unicode(' '));
201 aBuf
.append(pDlg
->IsDateConversionSet() ? sal_Unicode('1') : sal_Unicode('0'));
202 aFilterOptions
= aBuf
.makeStringAndClear();
203 nRet
= ui::dialogs::ExecutableDialogResults::OK
;
208 sal_Bool bMultiByte
= sal_True
;
209 sal_Bool bDBEnc
= sal_False
;
210 sal_Bool bAscii
= sal_False
;
212 sal_Unicode cStrDel
= '"';
213 sal_Unicode cAsciiDel
= ';';
214 rtl_TextEncoding eEncoding
= RTL_TEXTENCODING_DONTKNOW
;
218 if ( aFilterString
== ScDocShell::GetAsciiFilterName() )
220 // ascii export (import is handled above)
222 INetURLObject
aURL( aFileName
);
223 String
aExt(aURL
.getExtension());
224 if (aExt
.EqualsIgnoreCaseAscii("CSV"))
229 aTitle
= ScGlobal::GetRscString( STR_EXPORT_ASCII
);
232 else if ( aFilterString
== ScDocShell::GetLotusFilterName() )
234 // lotus is only imported
235 DBG_ASSERT( !bExport
, "Filter Options for Lotus Export is not implemented" );
237 aTitle
= ScGlobal::GetRscString( STR_IMPORT_LOTUS
);
238 eEncoding
= RTL_TEXTENCODING_IBM_437
;
240 else if ( aFilterString
== ScDocShell::GetDBaseFilterName() )
245 aTitle
= ScGlobal::GetRscString( STR_EXPORT_DBF
);
250 aTitle
= ScGlobal::GetRscString( STR_IMPORT_DBF
);
252 // common for dBase import/export
253 eEncoding
= RTL_TEXTENCODING_IBM_850
;
256 else if ( aFilterString
== ScDocShell::GetDifFilterName() )
261 aTitle
= ScGlobal::GetRscString( STR_EXPORT_DIF
);
266 aTitle
= ScGlobal::GetRscString( STR_IMPORT_DIF
);
268 // common for DIF import/export
269 eEncoding
= RTL_TEXTENCODING_MS_1252
;
272 ScImportOptions
aOptions( cAsciiDel
, cStrDel
, eEncoding
);
273 //CHINA001 ScImportOptionsDlg* pDlg = new ScImportOptionsDlg( NULL, bAscii,
274 //CHINA001 &aOptions, &aTitle, bMultiByte, bDBEnc,
275 //CHINA001 !bExport );
278 AbstractScImportOptionsDlg
* pDlg
= pFact
->CreateScImportOptionsDlg( NULL
, RID_SCDLG_IMPORTOPT
,
279 bAscii
, &aOptions
, &aTitle
, bMultiByte
, bDBEnc
,
281 DBG_ASSERT(pDlg
, "Dialog create fail!");//CHINA001
282 if ( pDlg
->Execute() == RET_OK
)
284 pDlg
->GetImportOptions( aOptions
);
286 aFilterOptions
= aOptions
.BuildString();
288 aFilterOptions
= aOptions
.aStrFont
;
289 nRet
= ui::dialogs::ExecutableDialogResults::OK
;
294 xInputStream
.clear(); // don't hold the stream longer than necessary
301 void SAL_CALL
ScFilterOptionsObj::setTargetDocument( const uno::Reference
<lang::XComponent
>& /* xDoc */ )
302 throw(lang::IllegalArgumentException
, uno::RuntimeException
)
309 void SAL_CALL
ScFilterOptionsObj::setSourceDocument( const uno::Reference
<lang::XComponent
>& /* xDoc */ )
310 throw(lang::IllegalArgumentException
, uno::RuntimeException
)