update dev300-m58
[ooovba.git] / framework / source / xml / imagesconfiguration.cxx
blob995da4124021e8226b2b4c56c651b951a58a6008
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: imagesconfiguration.cxx,v $
10 * $Revision: 1.9 $
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_framework.hxx"
33 #include <xml/imagesconfiguration.hxx>
34 #include <services.h>
36 #ifndef __FRAMEWORK_CLASSES_IMAGESDOCUMENTHANDLER_HXX_
37 #include <xml/imagesdocumenthandler.hxx>
38 #endif
39 #include <xml/saxnamespacefilter.hxx>
41 //_________________________________________________________________________________________________________________
42 // interface includes
43 //_________________________________________________________________________________________________________________
44 #include <com/sun/star/xml/sax/XParser.hpp>
45 #include <com/sun/star/io/XActiveDataSource.hpp>
46 #include <com/sun/star/io/XInputStream.hpp>
47 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
49 //_________________________________________________________________________________________________________________
50 // other includes
51 //_________________________________________________________________________________________________________________
53 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
54 #include <comphelper/processfactory.hxx>
55 #endif
56 #include <unotools/streamwrap.hxx>
57 #include <tools/debug.hxx>
59 //_________________________________________________________________________________________________________________
60 // namespace
61 //_________________________________________________________________________________________________________________
63 using namespace ::com::sun::star::uno;
64 using namespace ::com::sun::star::xml::sax;
65 using namespace ::com::sun::star::lang;
66 using namespace ::com::sun::star::io;
69 namespace framework
72 SV_IMPL_PTRARR( ImageItemListDescriptor, ImageItemDescriptorPtr );
73 SV_IMPL_PTRARR( ExternalImageItemListDescriptor, ExternalImageItemDescriptorPtr );
74 SV_IMPL_PTRARR( ImageListDescriptor, ImageListItemDescriptorPtr );
76 static Reference< XParser > GetSaxParser(
77 // #110897#
78 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory
81 //Reference< XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
82 //return Reference< XParser >( xServiceManager->createInstance( SERVICENAME_SAXPARSER), UNO_QUERY);
83 return Reference< XParser >( xServiceFactory->createInstance( SERVICENAME_SAXPARSER), UNO_QUERY);
86 static Reference< XDocumentHandler > GetSaxWriter(
87 // #110897#
88 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory
91 //Reference< XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
92 //return Reference< XDocumentHandler >( xServiceManager->createInstance( SERVICENAME_SAXWRITER), UNO_QUERY) ;
93 return Reference< XDocumentHandler >( xServiceFactory->createInstance( SERVICENAME_SAXWRITER), UNO_QUERY) ;
96 // #110897#
97 sal_Bool ImagesConfiguration::LoadImages(
98 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
99 SvStream& rInStream, ImageListsDescriptor& aItems )
101 Reference< XParser > xParser( GetSaxParser( xServiceFactory ) );
102 Reference< XInputStream > xInputStream(
103 (::cppu::OWeakObject *)new utl::OInputStreamWrapper( rInStream ),
104 UNO_QUERY );
106 // connect stream to input stream to the parser
107 InputSource aInputSource;
109 aInputSource.aInputStream = xInputStream;
111 // create namespace filter and set document handler inside to support xml namespaces
112 Reference< XDocumentHandler > xDocHandler( new OReadImagesDocumentHandler( aItems ));
113 Reference< XDocumentHandler > xFilter( new SaxNamespaceFilter( xDocHandler ));
115 // connect parser and filter
116 xParser->setDocumentHandler( xFilter );
120 xParser->parseStream( aInputSource );
121 return sal_True;
123 catch ( RuntimeException& )
125 return sal_False;
127 catch( SAXException& )
129 return sal_False;
131 catch( ::com::sun::star::io::IOException& )
133 return sal_False;
138 // #110897#
139 sal_Bool ImagesConfiguration::StoreImages(
140 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
141 SvStream& rOutStream, const ImageListsDescriptor& aItems )
143 Reference< XDocumentHandler > xWriter( GetSaxWriter( xServiceFactory ) );
145 Reference< XOutputStream > xOutputStream(
146 (::cppu::OWeakObject *)new utl::OOutputStreamWrapper( rOutStream ),
147 UNO_QUERY );
149 Reference< ::com::sun::star::io::XActiveDataSource> xDataSource( xWriter , UNO_QUERY );
150 xDataSource->setOutputStream( xOutputStream );
154 OWriteImagesDocumentHandler aWriteImagesDocumentHandler( aItems, xWriter );
155 aWriteImagesDocumentHandler.WriteImagesDocument();
156 return sal_True;
158 catch ( RuntimeException& )
160 return sal_False;
162 catch ( SAXException& )
164 return sal_False;
166 catch ( ::com::sun::star::io::IOException& )
168 return sal_False;
172 sal_Bool ImagesConfiguration::LoadImages(
173 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
174 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rInputStream,
175 ImageListsDescriptor& rItems )
177 Reference< XParser > xParser( GetSaxParser( xServiceFactory ) );
179 // connect stream to input stream to the parser
180 InputSource aInputSource;
182 aInputSource.aInputStream = rInputStream;
184 // create namespace filter and set document handler inside to support xml namespaces
185 Reference< XDocumentHandler > xDocHandler( new OReadImagesDocumentHandler( rItems ));
186 Reference< XDocumentHandler > xFilter( new SaxNamespaceFilter( xDocHandler ));
188 // connect parser and filter
189 xParser->setDocumentHandler( xFilter );
193 xParser->parseStream( aInputSource );
194 return sal_True;
196 catch ( RuntimeException& )
198 return sal_False;
200 catch( SAXException& )
202 return sal_False;
204 catch( ::com::sun::star::io::IOException& )
206 return sal_False;
210 sal_Bool ImagesConfiguration::StoreImages(
211 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
212 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& rOutputStream,
213 const ImageListsDescriptor& rItems )
215 Reference< XDocumentHandler > xWriter( GetSaxWriter( xServiceFactory ) );
217 Reference< ::com::sun::star::io::XActiveDataSource> xDataSource( xWriter , UNO_QUERY );
218 xDataSource->setOutputStream( rOutputStream );
222 OWriteImagesDocumentHandler aWriteImagesDocumentHandler( rItems, xWriter );
223 aWriteImagesDocumentHandler.WriteImagesDocument();
224 return sal_True;
226 catch ( RuntimeException& )
228 return sal_False;
230 catch ( SAXException& )
232 return sal_False;
234 catch ( ::com::sun::star::io::IOException& )
236 return sal_False;