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: filter.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_filter.hxx"
33 #include <com/sun/star/document/XFilter.hpp>
34 #include <com/sun/star/document/XExporter.hpp>
35 #include <com/sun/star/lang/XInitialization.hpp>
36 #include <com/sun/star/lang/XServiceInfo.hpp>
37 #include <cppuhelper/implbase4.hxx>
39 #include "exporter.hxx"
41 using namespace ::com::sun::star::uno
;
42 using namespace ::com::sun::star::lang
;
44 using ::rtl::OUString
;
45 using ::com::sun::star::lang::XComponent
;
46 using ::com::sun::star::beans::PropertyValue
;
47 using ::com::sun::star::io::XOutputStream
;
48 using ::com::sun::star::task::XStatusIndicator
;
52 // -----------------------------------------------------------------------------
54 class PlaceWareExportFilter
: public cppu::WeakImplHelper4
56 com::sun::star::document::XFilter
,
57 com::sun::star::document::XExporter
,
58 com::sun::star::lang::XInitialization
,
59 com::sun::star::lang::XServiceInfo
62 Reference
< XComponent
> mxDoc
;
63 Reference
< XMultiServiceFactory
> mxMSF
;
66 PlaceWareExportFilter( const Reference
< XMultiServiceFactory
> &rxMSF
);
69 virtual sal_Bool SAL_CALL
filter( const Sequence
< PropertyValue
>& aDescriptor
) throw(RuntimeException
);
70 virtual void SAL_CALL
cancel( ) throw (RuntimeException
);
73 virtual void SAL_CALL
setSourceDocument( const Reference
< XComponent
>& xDoc
) throw(IllegalArgumentException
, RuntimeException
);
76 virtual void SAL_CALL
initialize( const Sequence
< Any
>& aArguments
) throw(Exception
, RuntimeException
);
79 virtual OUString SAL_CALL
getImplementationName() throw(RuntimeException
);
80 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) throw(RuntimeException
);
81 virtual Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() throw(RuntimeException
);
84 // -----------------------------------------------------------------------------
86 PlaceWareExportFilter::PlaceWareExportFilter(const Reference
< XMultiServiceFactory
> &rxMSF
)
91 // -----------------------------------------------------------------------------
93 sal_Bool SAL_CALL
PlaceWareExportFilter::filter( const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& aDescriptor
)
94 throw (RuntimeException
)
96 sal_Int32 nLength
= aDescriptor
.getLength();
97 const PropertyValue
* pValue
= aDescriptor
.getConstArray();
98 OUString sFileName
, sURL
;
99 Reference
< XInterface
> xInteractionHandler
;
100 Reference
< XOutputStream
> xOutputStream
;
101 Reference
< XStatusIndicator
> xStatusIndicator
;
102 for ( sal_Int32 i
= 0 ; i
< nLength
; i
++)
104 if ( pValue
[i
].Name
.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "OutputStream" ) ) )
106 pValue
[i
].Value
>>= xOutputStream
;
108 else if( pValue
[i
].Name
.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "URL" ) ) )
110 pValue
[i
].Value
>>= sURL
;
112 else if( pValue
[i
].Name
.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "InteractionHandler" ) ) )
114 pValue
[i
].Value
>>= xInteractionHandler
;
116 else if ( pValue
[i
].Name
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "StatusIndicator" ) ) )
118 pValue
[i
].Value
>>= xStatusIndicator
;
121 if ( !xOutputStream
.is() )
127 PlaceWareExporter
aExporter( mxMSF
);
128 return aExporter
.doExport( mxDoc
, xOutputStream
, sURL
, xInteractionHandler
, xStatusIndicator
);
131 // -----------------------------------------------------------------------------
133 void SAL_CALL
PlaceWareExportFilter::cancel( )
134 throw (RuntimeException
)
138 // -----------------------------------------------------------------------------
141 void SAL_CALL
PlaceWareExportFilter::setSourceDocument( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XComponent
>& xDoc
)
142 throw (::com::sun::star::lang::IllegalArgumentException
, RuntimeException
)
147 // -----------------------------------------------------------------------------
150 void SAL_CALL
PlaceWareExportFilter::initialize( const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>& /* aArguments */ )
151 throw (Exception
, RuntimeException
)
155 // -----------------------------------------------------------------------------
157 OUString
PlaceWareExportFilter_getImplementationName ()
158 throw (RuntimeException
)
160 return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.Impress.PlaceWareExportFilter" ) );
163 // -----------------------------------------------------------------------------
165 #define SERVICE_NAME "com.sun.star.document.ExportFilter"
167 sal_Bool SAL_CALL
PlaceWareExportFilter_supportsService( const OUString
& ServiceName
)
168 throw (RuntimeException
)
170 return ServiceName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME
) );
173 // -----------------------------------------------------------------------------
175 Sequence
< OUString
> SAL_CALL
PlaceWareExportFilter_getSupportedServiceNames( )
176 throw (RuntimeException
)
178 Sequence
< OUString
> aRet(1);
179 OUString
* pArray
= aRet
.getArray();
180 pArray
[0] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME
) );
185 // -----------------------------------------------------------------------------
187 Reference
< XInterface
> SAL_CALL
PlaceWareExportFilter_createInstance( const Reference
< XMultiServiceFactory
> & rSMgr
)
190 return (cppu::OWeakObject
*) new PlaceWareExportFilter( rSMgr
);
193 // -----------------------------------------------------------------------------
196 OUString SAL_CALL
PlaceWareExportFilter::getImplementationName( )
197 throw (RuntimeException
)
199 return PlaceWareExportFilter_getImplementationName();
202 // -----------------------------------------------------------------------------
204 sal_Bool SAL_CALL
PlaceWareExportFilter::supportsService( const OUString
& rServiceName
)
205 throw (RuntimeException
)
207 return PlaceWareExportFilter_supportsService( rServiceName
);
210 // -----------------------------------------------------------------------------
212 ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
PlaceWareExportFilter::getSupportedServiceNames( )
213 throw (RuntimeException
)
215 return PlaceWareExportFilter_getSupportedServiceNames();
218 // -----------------------------------------------------------------------------