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: SwXFilterOptions.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_sw.hxx"
33 #include <SwXFilterOptions.hxx>
34 #include <shellio.hxx>
36 #include <unoprnms.hxx>
37 #include <vos/mutex.hxx>
38 #include <vcl/svapp.hxx>
39 #include <vcl/msgbox.hxx>
40 #include <com/sun/star/lang/XUnoTunnel.hpp>
41 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
42 #include <unotools/ucbstreamhelper.hxx>
43 #include <unotxdoc.hxx>
45 #include "swabstdlg.hxx"
48 using namespace ::com::sun::star
;
49 using namespace ::com::sun::star::ui::dialogs
;
50 using namespace ::com::sun::star::document
;
51 using namespace ::com::sun::star::lang
;
53 #define SWFILTEROPTIONSOBJ_SERVICE RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ui.dialogs.FilterOptionsDialog")
54 #define SWFILTEROPTIONSOBJ_IMPLNAME RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Writer.FilterOptionsDialog")
55 #define FILTER_OPTIONS_NAME RTL_CONSTASCII_USTRINGPARAM("FilterOptions")
56 /*-- 2002/06/21 11:01:23---------------------------------------------------
58 -----------------------------------------------------------------------*/
59 SwXFilterOptions::SwXFilterOptions() :
63 /*-- 2002/06/21 11:01:24---------------------------------------------------
65 -----------------------------------------------------------------------*/
66 SwXFilterOptions::~SwXFilterOptions()
69 /*-- 2002/06/21 11:01:24---------------------------------------------------
71 -----------------------------------------------------------------------*/
72 ::rtl::OUString
SwXFilterOptions::getImplementationName_Static()
74 return ::rtl::OUString(SWFILTEROPTIONSOBJ_IMPLNAME
);
76 /*-- 2002/06/21 11:01:24---------------------------------------------------
78 -----------------------------------------------------------------------*/
79 uno::Sequence
< ::rtl::OUString
> SwXFilterOptions::getSupportedServiceNames_Static()
81 ::rtl::OUString
sService(SWFILTEROPTIONSOBJ_SERVICE
);
82 return uno::Sequence
< ::rtl::OUString
> (&sService
, 1);
84 /*-- 2002/06/21 11:01:25---------------------------------------------------
86 -----------------------------------------------------------------------*/
87 uno::Sequence
< beans::PropertyValue
> SwXFilterOptions::getPropertyValues() throw (uno::RuntimeException
)
89 uno::Sequence
<beans::PropertyValue
> aRet(1);
90 beans::PropertyValue
* pArray
= aRet
.getArray();
92 pArray
[0].Name
= rtl::OUString( FILTER_OPTIONS_NAME
);
93 pArray
[0].Value
<<= sFilterOptions
;
97 /*-- 2002/06/21 11:01:25---------------------------------------------------
99 -----------------------------------------------------------------------*/
100 void SwXFilterOptions::setPropertyValues( const uno::Sequence
<beans::PropertyValue
>& aProps
)
101 throw (beans::UnknownPropertyException
, beans::PropertyVetoException
,
102 IllegalArgumentException
, WrappedTargetException
, uno::RuntimeException
)
104 const beans::PropertyValue
* pPropArray
= aProps
.getConstArray();
105 long nPropCount
= aProps
.getLength();
106 for (long i
= 0; i
< nPropCount
; i
++)
108 const beans::PropertyValue
& rProp
= pPropArray
[i
];
109 ::rtl::OUString aPropName
= rProp
.Name
;
111 if ( aPropName
.equalsAscii( SW_PROP_NAME_STR(UNO_NAME_FILTER_NAME
) ) )
112 rProp
.Value
>>= sFilterName
;
113 else if ( aPropName
== ::rtl::OUString(FILTER_OPTIONS_NAME
) )
114 rProp
.Value
>>= sFilterOptions
;
115 else if ( aPropName
.equalsAscii( "InputStream" ) )
116 rProp
.Value
>>= xInputStream
;
119 /*-- 2002/06/21 11:01:25---------------------------------------------------
121 -----------------------------------------------------------------------*/
122 void SwXFilterOptions::setTitle( const ::rtl::OUString
& /*rTitle*/ )
123 throw (uno::RuntimeException
)
126 /*-- 2002.06.21 11:01:25---------------------------------------------------
128 -----------------------------------------------------------------------*/
129 sal_Int16
SwXFilterOptions::execute() throw (uno::RuntimeException
)
131 sal_Int16 nRet
= ui::dialogs::ExecutableDialogResults::CANCEL
;
133 SvStream
* pInStream
= NULL
;
134 if ( xInputStream
.is() )
135 pInStream
= utl::UcbStreamHelper::CreateStream( xInputStream
);
137 uno::Reference
< XUnoTunnel
> xTunnel(xModel
, uno::UNO_QUERY
);
138 SwDocShell
* pDocShell
= 0;
141 SwXTextDocument
* pXDoc
= reinterpret_cast< SwXTextDocument
* >(
142 sal::static_int_cast
< sal_IntPtr
>(xTunnel
->getSomething(SwXTextDocument::getUnoTunnelId())));
143 pDocShell
= pXDoc
? pXDoc
->GetDocShell() : 0;
148 SwAbstractDialogFactory
* pFact
= SwAbstractDialogFactory::Create();
149 DBG_ASSERT(pFact
, "SwAbstractDialogFactory fail!");
151 AbstractSwAsciiFilterDlg
* pAsciiDlg
= pFact
->CreateSwAsciiFilterDlg( NULL
, *pDocShell
,pInStream
, DLG_ASCII_FILTER
);
152 DBG_ASSERT(pAsciiDlg
, "Dialogdiet fail!");
153 if(RET_OK
== pAsciiDlg
->Execute())
155 SwAsciiOptions aOptions
;
156 pAsciiDlg
->FillOptions( aOptions
);
158 aOptions
.WriteUserData(sTmp
);
159 sFilterOptions
= sTmp
;
160 nRet
= ui::dialogs::ExecutableDialogResults::OK
;
170 /*-- 2002/06/21 11:01:26---------------------------------------------------
172 -----------------------------------------------------------------------*/
173 void SwXFilterOptions::setTargetDocument( const uno::Reference
< XComponent
>& xDoc
)
174 throw (IllegalArgumentException
, uno::RuntimeException
)
179 /*-- 2002/06/21 11:01:26---------------------------------------------------
181 -----------------------------------------------------------------------*/
182 void SwXFilterOptions::setSourceDocument( const uno::Reference
<XComponent
>& xDoc
)
183 throw (IllegalArgumentException
,uno::RuntimeException
)
188 /*-- 2002/06/21 11:01:26---------------------------------------------------
190 -----------------------------------------------------------------------*/
191 ::rtl::OUString
SwXFilterOptions::getImplementationName() throw(uno::RuntimeException
)
193 return ::rtl::OUString(SWFILTEROPTIONSOBJ_IMPLNAME
);
195 /*-- 2002/06/21 11:01:27---------------------------------------------------
197 -----------------------------------------------------------------------*/
198 sal_Bool
SwXFilterOptions::supportsService( const ::rtl::OUString
& rServiceName
)
199 throw(uno::RuntimeException
)
201 return rServiceName
== ::rtl::OUString(SWFILTEROPTIONSOBJ_SERVICE
);
203 /*-- 2002/06/21 11:01:28---------------------------------------------------
205 -----------------------------------------------------------------------*/
206 uno::Sequence
< ::rtl::OUString
> SwXFilterOptions::getSupportedServiceNames()
207 throw(uno::RuntimeException
)
209 return SwXFilterOptions::getSupportedServiceNames_Static();
213 uno::Reference
<uno::XInterface
> SAL_CALL
SwXFilterOptions_createInstance(
214 const uno::Reference
<lang::XMultiServiceFactory
>& )
216 ::vos::OGuard
aGuard(Application::GetSolarMutex());
218 return (::cppu::OWeakObject
*) new SwXFilterOptions
;