xref: /aoo41x/main/filter/source/placeware/filter.cxx (revision 9e0fc027)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_filter.hxx"
26 #include <com/sun/star/document/XFilter.hpp>
27 #include <com/sun/star/document/XExporter.hpp>
28 #include <com/sun/star/lang/XInitialization.hpp>
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <cppuhelper/implbase4.hxx>
31 
32 #include "exporter.hxx"
33 
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::lang;
36 
37 using ::rtl::OUString;
38 using ::com::sun::star::lang::XComponent;
39 using ::com::sun::star::beans::PropertyValue;
40 using ::com::sun::star::io::XOutputStream;
41 using ::com::sun::star::task::XStatusIndicator;
42 
43 namespace pwp {
44 
45 // -----------------------------------------------------------------------------
46 
47 class PlaceWareExportFilter : public cppu::WeakImplHelper4
48 <
49 	com::sun::star::document::XFilter,
50 	com::sun::star::document::XExporter,
51 	com::sun::star::lang::XInitialization,
52 	com::sun::star::lang::XServiceInfo
53 >
54 {
55 	Reference< XComponent > mxDoc;
56     Reference< XMultiServiceFactory > mxMSF;
57 
58 public:
59 	PlaceWareExportFilter( const Reference< XMultiServiceFactory > &rxMSF);
60 
61 	// XFilter
62     virtual sal_Bool SAL_CALL filter( const Sequence< PropertyValue >& aDescriptor ) throw(RuntimeException);
63     virtual void SAL_CALL cancel( ) throw (RuntimeException);
64 
65 	// XExporter
66     virtual void SAL_CALL setSourceDocument( const Reference< XComponent >& xDoc ) throw(IllegalArgumentException, RuntimeException);
67 
68 	// XInitialization
69     virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) throw(Exception, RuntimeException);
70 
71 	// XServiceInfo
72     virtual OUString SAL_CALL getImplementationName() throw(RuntimeException);
73     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(RuntimeException);
74     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames()  throw(RuntimeException);
75 };
76 
77 // -----------------------------------------------------------------------------
78 
PlaceWareExportFilter(const Reference<XMultiServiceFactory> & rxMSF)79 PlaceWareExportFilter::PlaceWareExportFilter(const Reference< XMultiServiceFactory > &rxMSF)
80 :	mxMSF( rxMSF )
81 {
82 }
83 
84 // -----------------------------------------------------------------------------
85 
filter(const::com::sun::star::uno::Sequence<::com::sun::star::beans::PropertyValue> & aDescriptor)86 sal_Bool SAL_CALL PlaceWareExportFilter::filter( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
87 	throw (RuntimeException)
88 {
89 	sal_Int32 nLength = aDescriptor.getLength();
90 	const PropertyValue * pValue = aDescriptor.getConstArray();
91 	OUString sFileName, sURL;
92 	Reference < XInterface > xInteractionHandler;
93 	Reference < XOutputStream > xOutputStream;
94 	Reference < XStatusIndicator > xStatusIndicator;
95 	for ( sal_Int32 i = 0 ; i < nLength; i++)
96 	{
97 		if ( pValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "OutputStream" ) ) )
98 		{
99 			pValue[i].Value >>= xOutputStream;
100 		}
101 		else if( pValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "URL" ) ) )
102 		{
103 			pValue[i].Value >>= sURL;
104 		}
105 		else if( pValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "InteractionHandler" ) ) )
106 		{
107 			pValue[i].Value >>= xInteractionHandler;
108 		}
109 		else if ( pValue[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "StatusIndicator" ) ) )
110 		{
111 			pValue[i].Value >>= xStatusIndicator;
112 		}
113 	}
114 	if ( !xOutputStream.is() )
115 	{
116 		OSL_ASSERT ( 0 );
117 		return sal_False;
118 	}
119 
120 	PlaceWareExporter aExporter( mxMSF );
121 	return aExporter.doExport( mxDoc, xOutputStream, sURL, xInteractionHandler, xStatusIndicator );
122 }
123 
124 // -----------------------------------------------------------------------------
125 
cancel()126 void SAL_CALL PlaceWareExportFilter::cancel(  )
127 	throw (RuntimeException)
128 {
129 }
130 
131 // -----------------------------------------------------------------------------
132 
133 // XExporter
setSourceDocument(const::com::sun::star::uno::Reference<::com::sun::star::lang::XComponent> & xDoc)134 void SAL_CALL PlaceWareExportFilter::setSourceDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc )
135 	throw (::com::sun::star::lang::IllegalArgumentException, RuntimeException)
136 {
137 	mxDoc = xDoc;
138 }
139 
140 // -----------------------------------------------------------------------------
141 
142 // XInitialization
initialize(const::com::sun::star::uno::Sequence<::com::sun::star::uno::Any> &)143 void SAL_CALL PlaceWareExportFilter::initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& /* aArguments */ )
144 	throw (Exception, RuntimeException)
145 {
146 }
147 
148 // -----------------------------------------------------------------------------
149 
PlaceWareExportFilter_getImplementationName()150 OUString PlaceWareExportFilter_getImplementationName ()
151 	throw (RuntimeException)
152 {
153 	return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.Impress.PlaceWareExportFilter" ) );
154 }
155 
156 // -----------------------------------------------------------------------------
157 
158 #define SERVICE_NAME "com.sun.star.document.ExportFilter"
159 
PlaceWareExportFilter_supportsService(const OUString & ServiceName)160 sal_Bool SAL_CALL PlaceWareExportFilter_supportsService( const OUString& ServiceName )
161 	throw (RuntimeException)
162 {
163     return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) );
164 }
165 
166 // -----------------------------------------------------------------------------
167 
PlaceWareExportFilter_getSupportedServiceNames()168 Sequence< OUString > SAL_CALL PlaceWareExportFilter_getSupportedServiceNames(  )
169 	throw (RuntimeException)
170 {
171 	Sequence < OUString > aRet(1);
172     OUString* pArray = aRet.getArray();
173     pArray[0] =  OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
174     return aRet;
175 }
176 #undef SERVICE_NAME
177 
178 // -----------------------------------------------------------------------------
179 
PlaceWareExportFilter_createInstance(const Reference<XMultiServiceFactory> & rSMgr)180 Reference< XInterface > SAL_CALL PlaceWareExportFilter_createInstance( const Reference< XMultiServiceFactory > & rSMgr)
181 	throw( Exception )
182 {
183 	return (cppu::OWeakObject*) new PlaceWareExportFilter( rSMgr );
184 }
185 
186 // -----------------------------------------------------------------------------
187 
188 // XServiceInfo
getImplementationName()189 OUString SAL_CALL PlaceWareExportFilter::getImplementationName(  )
190 	throw (RuntimeException)
191 {
192 	return PlaceWareExportFilter_getImplementationName();
193 }
194 
195 // -----------------------------------------------------------------------------
196 
supportsService(const OUString & rServiceName)197 sal_Bool SAL_CALL PlaceWareExportFilter::supportsService( const OUString& rServiceName )
198 	throw (RuntimeException)
199 {
200     return PlaceWareExportFilter_supportsService( rServiceName );
201 }
202 
203 // -----------------------------------------------------------------------------
204 
getSupportedServiceNames()205 ::com::sun::star::uno::Sequence< OUString > SAL_CALL PlaceWareExportFilter::getSupportedServiceNames(  )
206 	throw (RuntimeException)
207 {
208     return PlaceWareExportFilter_getSupportedServiceNames();
209 }
210 
211 // -----------------------------------------------------------------------------
212 
213 }
214