1d0626817SAndrew Rist /**************************************************************
2*e27da661Smseidel *
3d0626817SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4d0626817SAndrew Rist * or more contributor license agreements. See the NOTICE file
5d0626817SAndrew Rist * distributed with this work for additional information
6d0626817SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7d0626817SAndrew Rist * to you under the Apache License, Version 2.0 (the
8d0626817SAndrew Rist * "License"); you may not use this file except in compliance
9d0626817SAndrew Rist * with the License. You may obtain a copy of the License at
10*e27da661Smseidel *
11d0626817SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*e27da661Smseidel *
13d0626817SAndrew Rist * Unless required by applicable law or agreed to in writing,
14d0626817SAndrew Rist * software distributed under the License is distributed on an
15d0626817SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16d0626817SAndrew Rist * KIND, either express or implied. See the License for the
17d0626817SAndrew Rist * specific language governing permissions and limitations
18d0626817SAndrew Rist * under the License.
19*e27da661Smseidel *
20d0626817SAndrew Rist *************************************************************/
21d0626817SAndrew Rist
22d0626817SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_framework.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <xml/imagesconfiguration.hxx>
28cdf0e10cSrcweir #include <services.h>
29cdf0e10cSrcweir
30cdf0e10cSrcweir #include <xml/imagesdocumenthandler.hxx>
31cdf0e10cSrcweir #include <xml/saxnamespacefilter.hxx>
32cdf0e10cSrcweir
33cdf0e10cSrcweir //_________________________________________________________________________________________________________________
34cdf0e10cSrcweir // interface includes
35cdf0e10cSrcweir //_________________________________________________________________________________________________________________
36cdf0e10cSrcweir #include <com/sun/star/xml/sax/XParser.hpp>
37cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSource.hpp>
38cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp>
39cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
40cdf0e10cSrcweir
41cdf0e10cSrcweir //_________________________________________________________________________________________________________________
42cdf0e10cSrcweir // other includes
43cdf0e10cSrcweir //_________________________________________________________________________________________________________________
44cdf0e10cSrcweir
45cdf0e10cSrcweir #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
46cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
47cdf0e10cSrcweir #endif
48cdf0e10cSrcweir #include <unotools/streamwrap.hxx>
49cdf0e10cSrcweir #include <tools/debug.hxx>
50cdf0e10cSrcweir
51cdf0e10cSrcweir //_________________________________________________________________________________________________________________
52cdf0e10cSrcweir // namespace
53cdf0e10cSrcweir //_________________________________________________________________________________________________________________
54cdf0e10cSrcweir
55cdf0e10cSrcweir using namespace ::com::sun::star::uno;
56cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
57cdf0e10cSrcweir using namespace ::com::sun::star::lang;
58cdf0e10cSrcweir using namespace ::com::sun::star::io;
59cdf0e10cSrcweir
60cdf0e10cSrcweir
61cdf0e10cSrcweir namespace framework
62cdf0e10cSrcweir {
63cdf0e10cSrcweir
64cdf0e10cSrcweir SV_IMPL_PTRARR( ImageItemListDescriptor, ImageItemDescriptorPtr );
65cdf0e10cSrcweir SV_IMPL_PTRARR( ExternalImageItemListDescriptor, ExternalImageItemDescriptorPtr );
66cdf0e10cSrcweir SV_IMPL_PTRARR( ImageListDescriptor, ImageListItemDescriptorPtr );
67cdf0e10cSrcweir
GetSaxParser(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & xServiceFactory)68cdf0e10cSrcweir static Reference< XParser > GetSaxParser(
69cdf0e10cSrcweir // #110897#
70cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory
71cdf0e10cSrcweir )
72cdf0e10cSrcweir {
73cdf0e10cSrcweir //Reference< XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
74cdf0e10cSrcweir //return Reference< XParser >( xServiceManager->createInstance( SERVICENAME_SAXPARSER), UNO_QUERY);
75cdf0e10cSrcweir return Reference< XParser >( xServiceFactory->createInstance( SERVICENAME_SAXPARSER), UNO_QUERY);
76cdf0e10cSrcweir }
77cdf0e10cSrcweir
GetSaxWriter(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & xServiceFactory)78cdf0e10cSrcweir static Reference< XDocumentHandler > GetSaxWriter(
79cdf0e10cSrcweir // #110897#
80cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory
81cdf0e10cSrcweir )
82cdf0e10cSrcweir {
83cdf0e10cSrcweir //Reference< XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
84cdf0e10cSrcweir //return Reference< XDocumentHandler >( xServiceManager->createInstance( SERVICENAME_SAXWRITER), UNO_QUERY) ;
85cdf0e10cSrcweir return Reference< XDocumentHandler >( xServiceFactory->createInstance( SERVICENAME_SAXWRITER), UNO_QUERY) ;
86cdf0e10cSrcweir }
87cdf0e10cSrcweir
88cdf0e10cSrcweir // #110897#
LoadImages(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & xServiceFactory,SvStream & rInStream,ImageListsDescriptor & aItems)89cdf0e10cSrcweir sal_Bool ImagesConfiguration::LoadImages(
90cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
91cdf0e10cSrcweir SvStream& rInStream, ImageListsDescriptor& aItems )
92cdf0e10cSrcweir {
93cdf0e10cSrcweir Reference< XParser > xParser( GetSaxParser( xServiceFactory ) );
94cdf0e10cSrcweir Reference< XInputStream > xInputStream(
95cdf0e10cSrcweir (::cppu::OWeakObject *)new utl::OInputStreamWrapper( rInStream ),
96cdf0e10cSrcweir UNO_QUERY );
97cdf0e10cSrcweir
98cdf0e10cSrcweir // connect stream to input stream to the parser
99cdf0e10cSrcweir InputSource aInputSource;
100cdf0e10cSrcweir
101cdf0e10cSrcweir aInputSource.aInputStream = xInputStream;
102cdf0e10cSrcweir
103cdf0e10cSrcweir // create namespace filter and set document handler inside to support xml namespaces
104cdf0e10cSrcweir Reference< XDocumentHandler > xDocHandler( new OReadImagesDocumentHandler( aItems ));
105cdf0e10cSrcweir Reference< XDocumentHandler > xFilter( new SaxNamespaceFilter( xDocHandler ));
106cdf0e10cSrcweir
107cdf0e10cSrcweir // connect parser and filter
108cdf0e10cSrcweir xParser->setDocumentHandler( xFilter );
109cdf0e10cSrcweir
110cdf0e10cSrcweir try
111cdf0e10cSrcweir {
112cdf0e10cSrcweir xParser->parseStream( aInputSource );
113cdf0e10cSrcweir return sal_True;
114cdf0e10cSrcweir }
115cdf0e10cSrcweir catch ( RuntimeException& )
116cdf0e10cSrcweir {
117cdf0e10cSrcweir return sal_False;
118cdf0e10cSrcweir }
119cdf0e10cSrcweir catch( SAXException& )
120cdf0e10cSrcweir {
121cdf0e10cSrcweir return sal_False;
122cdf0e10cSrcweir }
123cdf0e10cSrcweir catch( ::com::sun::star::io::IOException& )
124cdf0e10cSrcweir {
125cdf0e10cSrcweir return sal_False;
126cdf0e10cSrcweir }
127cdf0e10cSrcweir }
128cdf0e10cSrcweir
129cdf0e10cSrcweir
130cdf0e10cSrcweir // #110897#
StoreImages(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & xServiceFactory,SvStream & rOutStream,const ImageListsDescriptor & aItems)131cdf0e10cSrcweir sal_Bool ImagesConfiguration::StoreImages(
132cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
133cdf0e10cSrcweir SvStream& rOutStream, const ImageListsDescriptor& aItems )
134cdf0e10cSrcweir {
135cdf0e10cSrcweir Reference< XDocumentHandler > xWriter( GetSaxWriter( xServiceFactory ) );
136cdf0e10cSrcweir
137cdf0e10cSrcweir Reference< XOutputStream > xOutputStream(
138cdf0e10cSrcweir (::cppu::OWeakObject *)new utl::OOutputStreamWrapper( rOutStream ),
139cdf0e10cSrcweir UNO_QUERY );
140cdf0e10cSrcweir
141cdf0e10cSrcweir Reference< ::com::sun::star::io::XActiveDataSource> xDataSource( xWriter , UNO_QUERY );
142cdf0e10cSrcweir xDataSource->setOutputStream( xOutputStream );
143cdf0e10cSrcweir
144cdf0e10cSrcweir try
145cdf0e10cSrcweir {
146cdf0e10cSrcweir OWriteImagesDocumentHandler aWriteImagesDocumentHandler( aItems, xWriter );
147cdf0e10cSrcweir aWriteImagesDocumentHandler.WriteImagesDocument();
148cdf0e10cSrcweir return sal_True;
149cdf0e10cSrcweir }
150cdf0e10cSrcweir catch ( RuntimeException& )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir return sal_False;
153cdf0e10cSrcweir }
154cdf0e10cSrcweir catch ( SAXException& )
155cdf0e10cSrcweir {
156cdf0e10cSrcweir return sal_False;
157cdf0e10cSrcweir }
158cdf0e10cSrcweir catch ( ::com::sun::star::io::IOException& )
159cdf0e10cSrcweir {
160cdf0e10cSrcweir return sal_False;
161cdf0e10cSrcweir }
162cdf0e10cSrcweir }
163cdf0e10cSrcweir
LoadImages(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & xServiceFactory,const::com::sun::star::uno::Reference<::com::sun::star::io::XInputStream> & rInputStream,ImageListsDescriptor & rItems)164cdf0e10cSrcweir sal_Bool ImagesConfiguration::LoadImages(
165cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
166*e27da661Smseidel const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rInputStream,
167*e27da661Smseidel ImageListsDescriptor& rItems )
168cdf0e10cSrcweir {
169cdf0e10cSrcweir Reference< XParser > xParser( GetSaxParser( xServiceFactory ) );
170cdf0e10cSrcweir
171*e27da661Smseidel // connect stream to input stream to the parser
172cdf0e10cSrcweir InputSource aInputSource;
173cdf0e10cSrcweir
174cdf0e10cSrcweir aInputSource.aInputStream = rInputStream;
175cdf0e10cSrcweir
176cdf0e10cSrcweir // create namespace filter and set document handler inside to support xml namespaces
177cdf0e10cSrcweir Reference< XDocumentHandler > xDocHandler( new OReadImagesDocumentHandler( rItems ));
178cdf0e10cSrcweir Reference< XDocumentHandler > xFilter( new SaxNamespaceFilter( xDocHandler ));
179cdf0e10cSrcweir
180cdf0e10cSrcweir // connect parser and filter
181cdf0e10cSrcweir xParser->setDocumentHandler( xFilter );
182cdf0e10cSrcweir
183cdf0e10cSrcweir try
184cdf0e10cSrcweir {
185cdf0e10cSrcweir xParser->parseStream( aInputSource );
186cdf0e10cSrcweir return sal_True;
187cdf0e10cSrcweir }
188cdf0e10cSrcweir catch ( RuntimeException& )
189cdf0e10cSrcweir {
190cdf0e10cSrcweir return sal_False;
191cdf0e10cSrcweir }
192cdf0e10cSrcweir catch( SAXException& )
193cdf0e10cSrcweir {
194cdf0e10cSrcweir return sal_False;
195cdf0e10cSrcweir }
196cdf0e10cSrcweir catch( ::com::sun::star::io::IOException& )
197cdf0e10cSrcweir {
198cdf0e10cSrcweir return sal_False;
199cdf0e10cSrcweir }
200cdf0e10cSrcweir }
201cdf0e10cSrcweir
StoreImages(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & xServiceFactory,const::com::sun::star::uno::Reference<::com::sun::star::io::XOutputStream> & rOutputStream,const ImageListsDescriptor & rItems)202cdf0e10cSrcweir sal_Bool ImagesConfiguration::StoreImages(
203cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
204*e27da661Smseidel const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& rOutputStream,
205*e27da661Smseidel const ImageListsDescriptor& rItems )
206cdf0e10cSrcweir {
207cdf0e10cSrcweir Reference< XDocumentHandler > xWriter( GetSaxWriter( xServiceFactory ) );
208cdf0e10cSrcweir
209cdf0e10cSrcweir Reference< ::com::sun::star::io::XActiveDataSource> xDataSource( xWriter , UNO_QUERY );
210cdf0e10cSrcweir xDataSource->setOutputStream( rOutputStream );
211cdf0e10cSrcweir
212cdf0e10cSrcweir try
213cdf0e10cSrcweir {
214cdf0e10cSrcweir OWriteImagesDocumentHandler aWriteImagesDocumentHandler( rItems, xWriter );
215cdf0e10cSrcweir aWriteImagesDocumentHandler.WriteImagesDocument();
216cdf0e10cSrcweir return sal_True;
217cdf0e10cSrcweir }
218cdf0e10cSrcweir catch ( RuntimeException& )
219cdf0e10cSrcweir {
220cdf0e10cSrcweir return sal_False;
221cdf0e10cSrcweir }
222cdf0e10cSrcweir catch ( SAXException& )
223cdf0e10cSrcweir {
224cdf0e10cSrcweir return sal_False;
225cdf0e10cSrcweir }
226cdf0e10cSrcweir catch ( ::com::sun::star::io::IOException& )
227cdf0e10cSrcweir {
228cdf0e10cSrcweir return sal_False;
229cdf0e10cSrcweir }
230cdf0e10cSrcweir }
231cdf0e10cSrcweir
232cdf0e10cSrcweir }
233cdf0e10cSrcweir
234