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 $
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>
36 #ifndef __FRAMEWORK_CLASSES_IMAGESDOCUMENTHANDLER_HXX_
37 #include <xml/imagesdocumenthandler.hxx>
39 #include <xml/saxnamespacefilter.hxx>
41 //_________________________________________________________________________________________________________________
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 //_________________________________________________________________________________________________________________
51 //_________________________________________________________________________________________________________________
53 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
54 #include <comphelper/processfactory.hxx>
56 #include <unotools/streamwrap.hxx>
57 #include <tools/debug.hxx>
59 //_________________________________________________________________________________________________________________
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
;
72 SV_IMPL_PTRARR( ImageItemListDescriptor
, ImageItemDescriptorPtr
);
73 SV_IMPL_PTRARR( ExternalImageItemListDescriptor
, ExternalImageItemDescriptorPtr
);
74 SV_IMPL_PTRARR( ImageListDescriptor
, ImageListItemDescriptorPtr
);
76 static Reference
< XParser
> GetSaxParser(
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(
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
) ;
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
),
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
);
123 catch ( RuntimeException
& )
127 catch( SAXException
& )
131 catch( ::com::sun::star::io::IOException
& )
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
),
149 Reference
< ::com::sun::star::io::XActiveDataSource
> xDataSource( xWriter
, UNO_QUERY
);
150 xDataSource
->setOutputStream( xOutputStream
);
154 OWriteImagesDocumentHandler
aWriteImagesDocumentHandler( aItems
, xWriter
);
155 aWriteImagesDocumentHandler
.WriteImagesDocument();
158 catch ( RuntimeException
& )
162 catch ( SAXException
& )
166 catch ( ::com::sun::star::io::IOException
& )
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
);
196 catch ( RuntimeException
& )
200 catch( SAXException
& )
204 catch( ::com::sun::star::io::IOException
& )
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();
226 catch ( RuntimeException
& )
230 catch ( SAXException
& )
234 catch ( ::com::sun::star::io::IOException
& )