fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / writerperfect / source / draw / WPGImportFilter.cxx
blob929ac9d671b2ddf484d0295064bc76b1b4fc0fd7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* WPGImportFilter: Sets up the filter, and calls OdgExporter
3 * to do the actual filtering
5 * This file is part of the LibreOffice project.
7 * This Source Code Form is subject to the terms of the Mozilla Public
8 * License, v. 2.0. If a copy of the MPL was not distributed with this
9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 /* "This product is not manufactured, approved, or supported by
13 * Corel Corporation or Corel Corporation Limited."
16 #include <osl/diagnose.h>
17 #include <rtl/tencinfo.h>
19 #include <com/sun/star/io/XInputStream.hpp>
20 #include <com/sun/star/xml/sax/XAttributeList.hpp>
21 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
22 #include <com/sun/star/xml/sax/InputSource.hpp>
23 #include <com/sun/star/xml/sax/XParser.hpp>
24 #include <com/sun/star/io/XSeekable.hpp>
25 #include <com/sun/star/uno/Reference.h>
27 #include <comphelper/componentcontext.hxx>
28 #include <xmloff/attrlist.hxx>
30 #include <libodfgen/libodfgen.hxx>
32 #include "common/DocumentHandler.hxx"
33 #include "common/WPXSvStream.hxx"
34 #include "WPGImportFilter.hxx"
36 #include <iostream>
38 using namespace ::com::sun::star::uno;
39 using com::sun::star::uno::Reference;
40 using com::sun::star::io::XInputStream;
41 using com::sun::star::io::XSeekable;
42 using com::sun::star::uno::Sequence;
43 using namespace ::rtl;
44 using com::sun::star::uno::Any;
45 using com::sun::star::uno::UNO_QUERY;
46 using com::sun::star::uno::XInterface;
47 using com::sun::star::uno::Exception;
48 using com::sun::star::uno::RuntimeException;
49 using com::sun::star::beans::PropertyValue;
50 using com::sun::star::document::XFilter;
51 using com::sun::star::document::XExtendedFilterDetection;
52 using com::sun::star::document::XImporter;
53 using com::sun::star::xml::sax::InputSource;
54 using com::sun::star::xml::sax::XAttributeList;
55 using com::sun::star::xml::sax::XDocumentHandler;
56 using com::sun::star::xml::sax::XParser;
59 sal_Bool SAL_CALL WPGImportFilter::filter( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
60 throw (RuntimeException)
62 #ifdef DEBUG
63 std::cerr << "WPGImportFilter::filter" << std::endl;
64 #endif
65 sal_Int32 nLength = aDescriptor.getLength();
66 const PropertyValue *pValue = aDescriptor.getConstArray();
67 Reference < XInputStream > xInputStream;
68 for ( sal_Int32 i = 0 ; i < nLength; i++)
70 if ( pValue[i].Name == "InputStream" )
71 pValue[i].Value >>= xInputStream;
73 if ( !xInputStream.is() )
75 OSL_ASSERT( 0 );
76 return sal_False;
79 // An XML import service: what we push sax messages to..
80 OUString sXMLImportService ( "com.sun.star.comp.Draw.XMLOasisImporter" );
81 Reference < XDocumentHandler > xInternalHandler( comphelper::ComponentContext( mxContext ).createComponent( sXMLImportService ), UNO_QUERY );
83 // The XImporter sets up an empty target document for XDocumentHandler to write to..
84 Reference < XImporter > xImporter(xInternalHandler, UNO_QUERY);
85 xImporter->setTargetDocument( mxDoc );
87 // OO Graphics Handler: abstract class to handle document SAX messages, concrete implementation here
88 // writes to in-memory target doc
89 DocumentHandler xHandler(xInternalHandler);
91 WPXSvInputStream input( xInputStream );
93 OdgGenerator exporter(&xHandler, ODF_FLAT_XML);
94 bool tmpParseResult = libwpg::WPGraphics::parse(&input, &exporter);
95 return tmpParseResult;
98 void SAL_CALL WPGImportFilter::cancel( )
99 throw (RuntimeException)
101 #ifdef DEBUG
102 std::cerr << "WPGImportFilter::cancel" << std::endl;
103 #endif
106 // XImporter
107 void SAL_CALL WPGImportFilter::setTargetDocument( const Reference< ::com::sun::star::lang::XComponent >& xDoc )
108 throw (::com::sun::star::lang::IllegalArgumentException, RuntimeException)
110 #ifdef DEBUG
111 std::cerr << "WPGImportFilter::setTargetDocument" << std::endl;
112 #endif
113 mxDoc = xDoc;
116 // XExtendedFilterDetection
117 OUString SAL_CALL WPGImportFilter::detect( com::sun::star::uno::Sequence< PropertyValue >& Descriptor )
118 throw( com::sun::star::uno::RuntimeException )
120 #ifdef DEBUG
121 std::cerr << "WPGImportFilter::detect" << std::endl;
122 #endif
123 OUString sTypeName;
124 sal_Int32 nLength = Descriptor.getLength();
125 sal_Int32 location = nLength;
126 const PropertyValue *pValue = Descriptor.getConstArray();
127 Reference < XInputStream > xInputStream;
128 for ( sal_Int32 i = 0 ; i < nLength; i++)
130 if ( pValue[i].Name == "TypeName" )
131 location=i;
132 else if ( pValue[i].Name == "InputStream" )
133 pValue[i].Value >>= xInputStream;
136 if (!xInputStream.is())
137 return OUString();
139 WPXSvInputStream input( xInputStream );
141 if (libwpg::WPGraphics::isSupported(&input))
142 sTypeName = "draw_WordPerfect_Graphics";
144 if (!sTypeName.isEmpty())
146 if ( location == nLength )
148 Descriptor.realloc(nLength+1);
149 Descriptor[location].Name = "TypeName";
152 Descriptor[location].Value <<=sTypeName;
154 return sTypeName;
158 // XInitialization
159 void SAL_CALL WPGImportFilter::initialize( const Sequence< Any >& aArguments )
160 throw (Exception, RuntimeException)
162 #ifdef DEBUG
163 std::cerr << "WPGImportFilter::initialize" << std::endl;
164 #endif
165 Sequence < PropertyValue > aAnySeq;
166 sal_Int32 nLength = aArguments.getLength();
167 if ( nLength && ( aArguments[0] >>= aAnySeq ) )
169 const PropertyValue *pValue = aAnySeq.getConstArray();
170 nLength = aAnySeq.getLength();
171 for ( sal_Int32 i = 0 ; i < nLength; i++)
173 if ( pValue[i].Name == "Type" )
175 pValue[i].Value >>= msFilterName;
176 break;
181 OUString WPGImportFilter_getImplementationName ()
182 throw (RuntimeException)
184 #ifdef DEBUG
185 std::cerr << "WPGImportFilter_getImplementationName" << std::endl;
186 #endif
187 return OUString ( "com.sun.star.comp.Draw.WPGImportFilter" );
190 #define SERVICE_NAME1 "com.sun.star.document.ImportFilter"
191 #define SERVICE_NAME2 "com.sun.star.document.ExtendedTypeDetection"
192 sal_Bool SAL_CALL WPGImportFilter_supportsService( const OUString &ServiceName )
193 throw (RuntimeException)
195 #ifdef DEBUG
196 std::cerr << "WPGImportFilter_supportsService" << std::endl;
197 #endif
198 return ( ServiceName == SERVICE_NAME1 || ServiceName == SERVICE_NAME2 );
200 Sequence< OUString > SAL_CALL WPGImportFilter_getSupportedServiceNames( )
201 throw (RuntimeException)
203 #ifdef DEBUG
204 std::cerr << "WPGImportFilter_getSupportedServiceNames" << std::endl;
205 #endif
206 Sequence < OUString > aRet(2);
207 OUString *pArray = aRet.getArray();
208 pArray[0] = OUString ( SERVICE_NAME1 );
209 pArray[1] = OUString ( SERVICE_NAME2 );
210 return aRet;
212 #undef SERVICE_NAME2
213 #undef SERVICE_NAME1
215 Reference< XInterface > SAL_CALL WPGImportFilter_createInstance( const Reference< XComponentContext > & rContext)
216 throw( Exception )
218 #ifdef DEBUG
219 std::cerr << "WPGImportFilter_createInstance" << std::endl;
220 #endif
221 return (cppu::OWeakObject *) new WPGImportFilter( rContext );
224 // XServiceInfo
225 OUString SAL_CALL WPGImportFilter::getImplementationName( )
226 throw (RuntimeException)
228 #ifdef DEBUG
229 std::cerr << "WPGImportFilter::getImplementationName" << std::endl;
230 #endif
231 return WPGImportFilter_getImplementationName();
233 sal_Bool SAL_CALL WPGImportFilter::supportsService( const OUString &rServiceName )
234 throw (RuntimeException)
236 #ifdef DEBUG
237 std::cerr << "WPGImportFilter::supportsService" << std::endl;
238 #endif
239 return WPGImportFilter_supportsService( rServiceName );
241 Sequence< OUString > SAL_CALL WPGImportFilter::getSupportedServiceNames( )
242 throw (RuntimeException)
244 #ifdef DEBUG
245 std::cerr << "WPGImportFilter::getSupportedServiceNames" << std::endl;
246 #endif
247 return WPGImportFilter_getSupportedServiceNames();
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */