fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / writerperfect / source / draw / CMXImportFilter.cxx
blob22d7b3cdf8b5f1051da0bd784ec1ed5ff13183f9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* CMXImportFilter: Sets up the filter, and calls OdgExporter
3 * to do the actual filtering
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 /* "This product is not manufactured, approved, or supported by
11 * Corel Corporation or Corel Corporation Limited."
14 #include <osl/diagnose.h>
15 #include <rtl/tencinfo.h>
17 #include <com/sun/star/io/XInputStream.hpp>
18 #include <com/sun/star/xml/sax/XAttributeList.hpp>
19 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
20 #include <com/sun/star/xml/sax/InputSource.hpp>
21 #include <com/sun/star/xml/sax/XParser.hpp>
22 #include <com/sun/star/io/XSeekable.hpp>
23 #include <com/sun/star/uno/Reference.h>
25 #include <comphelper/componentcontext.hxx>
26 #include <xmloff/attrlist.hxx>
28 #include <libcdr/libcdr.h>
29 #include <libodfgen/libodfgen.hxx>
31 #include "common/DocumentHandler.hxx"
32 #include "common/WPXSvStream.hxx"
33 #include "CMXImportFilter.hxx"
35 #include <iostream>
37 using namespace ::com::sun::star::uno;
38 using com::sun::star::uno::Reference;
39 using com::sun::star::io::XInputStream;
40 using com::sun::star::io::XSeekable;
41 using com::sun::star::uno::Sequence;
42 using com::sun::star::uno::Any;
43 using com::sun::star::uno::UNO_QUERY;
44 using com::sun::star::uno::XInterface;
45 using com::sun::star::uno::Exception;
46 using com::sun::star::uno::RuntimeException;
47 using com::sun::star::beans::PropertyValue;
48 using com::sun::star::document::XFilter;
49 using com::sun::star::document::XExtendedFilterDetection;
50 using com::sun::star::document::XImporter;
51 using com::sun::star::xml::sax::InputSource;
52 using com::sun::star::xml::sax::XAttributeList;
53 using com::sun::star::xml::sax::XDocumentHandler;
54 using com::sun::star::xml::sax::XParser;
57 sal_Bool SAL_CALL CMXImportFilter::filter( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
58 throw (RuntimeException)
60 #ifdef DEBUG
61 std::cerr << "CMXImportFilter::filter" << std::endl;
62 #endif
63 sal_Int32 nLength = aDescriptor.getLength();
64 const PropertyValue *pValue = aDescriptor.getConstArray();
65 Reference < XInputStream > xInputStream;
66 for ( sal_Int32 i = 0 ; i < nLength; i++)
68 if ( pValue[i].Name == "InputStream" )
69 pValue[i].Value >>= xInputStream;
71 if ( !xInputStream.is() )
73 OSL_ASSERT( 0 );
74 return sal_False;
77 // An XML import service: what we push sax messages to..
78 OUString sXMLImportService ( "com.sun.star.comp.Draw.XMLOasisImporter" );
79 Reference < XDocumentHandler > xInternalHandler( comphelper::ComponentContext( mxContext ).createComponent( sXMLImportService ), UNO_QUERY );
81 // The XImporter sets up an empty target document for XDocumentHandler to write to..
82 Reference < XImporter > xImporter(xInternalHandler, UNO_QUERY);
83 xImporter->setTargetDocument( mxDoc );
85 // OO Graphics Handler: abstract class to handle document SAX messages, concrete implementation here
86 // writes to in-memory target doc
87 DocumentHandler xHandler(xInternalHandler);
89 WPXSvInputStream input( xInputStream );
91 OdgGenerator exporter(&xHandler, ODF_FLAT_XML);
92 bool tmpParseResult = libcdr::CMXDocument::parse(&input, &exporter);
93 return tmpParseResult;
96 void SAL_CALL CMXImportFilter::cancel( )
97 throw (RuntimeException)
99 #ifdef DEBUG
100 std::cerr << "CMXImportFilter::cancel" << std::endl;
101 #endif
104 // XImporter
105 void SAL_CALL CMXImportFilter::setTargetDocument( const Reference< ::com::sun::star::lang::XComponent >& xDoc )
106 throw (::com::sun::star::lang::IllegalArgumentException, RuntimeException)
108 #ifdef DEBUG
109 std::cerr << "CMXImportFilter::setTargetDocument" << std::endl;
110 #endif
111 mxDoc = xDoc;
114 // XExtendedFilterDetection
115 OUString SAL_CALL CMXImportFilter::detect( com::sun::star::uno::Sequence< PropertyValue >& Descriptor )
116 throw( com::sun::star::uno::RuntimeException )
118 #ifdef DEBUG
119 std::cerr << "CMXImportFilter::detect" << std::endl;
120 #endif
121 OUString sTypeName;
122 sal_Int32 nLength = Descriptor.getLength();
123 sal_Int32 location = nLength;
124 const PropertyValue *pValue = Descriptor.getConstArray();
125 Reference < XInputStream > xInputStream;
126 for ( sal_Int32 i = 0 ; i < nLength; i++)
128 if ( pValue[i].Name == "TypeName" )
129 location=i;
130 else if ( pValue[i].Name == "InputStream" )
131 pValue[i].Value >>= xInputStream;
134 if (!xInputStream.is())
135 return OUString();
137 WPXSvInputStream input( xInputStream );
139 if (libcdr::CMXDocument::isSupported(&input))
140 sTypeName = "draw_Corel_Presentation_Exchange";
142 if (!sTypeName.isEmpty())
144 if ( location == nLength )
146 Descriptor.realloc(nLength+1);
147 Descriptor[location].Name = "TypeName";
150 Descriptor[location].Value <<=sTypeName;
152 return sTypeName;
156 // XInitialization
157 void SAL_CALL CMXImportFilter::initialize( const Sequence< Any >& aArguments )
158 throw (Exception, RuntimeException)
160 #ifdef DEBUG
161 std::cerr << "CMXImportFilter::initialize" << std::endl;
162 #endif
163 Sequence < PropertyValue > aAnySeq;
164 sal_Int32 nLength = aArguments.getLength();
165 if ( nLength && ( aArguments[0] >>= aAnySeq ) )
167 const PropertyValue *pValue = aAnySeq.getConstArray();
168 nLength = aAnySeq.getLength();
169 for ( sal_Int32 i = 0 ; i < nLength; i++)
171 if ( pValue[i].Name == "Type" )
173 pValue[i].Value >>= msFilterName;
174 break;
179 OUString CMXImportFilter_getImplementationName ()
180 throw (RuntimeException)
182 #ifdef DEBUG
183 std::cerr << "CMXImportFilter_getImplementationName" << std::endl;
184 #endif
185 return OUString ( "com.sun.star.comp.Draw.CMXImportFilter" );
188 #define SERVICE_NAME1 "com.sun.star.document.ImportFilter"
189 #define SERVICE_NAME2 "com.sun.star.document.ExtendedTypeDetection"
190 sal_Bool SAL_CALL CMXImportFilter_supportsService( const OUString &ServiceName )
191 throw (RuntimeException)
193 #ifdef DEBUG
194 std::cerr << "CMXImportFilter_supportsService" << std::endl;
195 #endif
196 return ( ServiceName == SERVICE_NAME1 || ServiceName == SERVICE_NAME2 );
198 Sequence< OUString > SAL_CALL CMXImportFilter_getSupportedServiceNames( )
199 throw (RuntimeException)
201 #ifdef DEBUG
202 std::cerr << "CMXImportFilter_getSupportedServiceNames" << std::endl;
203 #endif
204 Sequence < OUString > aRet(2);
205 OUString *pArray = aRet.getArray();
206 pArray[0] = OUString ( SERVICE_NAME1 );
207 pArray[1] = OUString ( SERVICE_NAME2 );
208 return aRet;
210 #undef SERVICE_NAME2
211 #undef SERVICE_NAME1
213 Reference< XInterface > SAL_CALL CMXImportFilter_createInstance( const Reference< XComponentContext > & rContext)
214 throw( Exception )
216 #ifdef DEBUG
217 std::cerr << "CMXImportFilter_createInstance" << std::endl;
218 #endif
219 return (cppu::OWeakObject *) new CMXImportFilter( rContext );
222 // XServiceInfo
223 OUString SAL_CALL CMXImportFilter::getImplementationName( )
224 throw (RuntimeException)
226 #ifdef DEBUG
227 std::cerr << "CMXImportFilter::getImplementationName" << std::endl;
228 #endif
229 return CMXImportFilter_getImplementationName();
231 sal_Bool SAL_CALL CMXImportFilter::supportsService( const OUString &rServiceName )
232 throw (RuntimeException)
234 #ifdef DEBUG
235 std::cerr << "CMXImportFilter::supportsService" << std::endl;
236 #endif
237 return CMXImportFilter_supportsService( rServiceName );
239 Sequence< OUString > SAL_CALL CMXImportFilter::getSupportedServiceNames( )
240 throw (RuntimeException)
242 #ifdef DEBUG
243 std::cerr << "CMXImportFilter::getSupportedServiceNames" << std::endl;
244 #endif
245 return CMXImportFilter_getSupportedServiceNames();
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */