merge the formfield patch from ooo-build
[ooovba.git] / framework / source / xml / eventsconfiguration.cxx
blob320f94b8a69a9a4e4472cf8d5cb8ce260d7bb54e
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: eventsconfiguration.cxx,v $
10 * $Revision: 1.8 $
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/eventsconfiguration.hxx>
34 #include <xml/eventsdocumenthandler.hxx>
35 #include <services.h>
37 #ifndef __FRAMEWORK_XML_SAXNAMESPACEFILTER_HXX_
38 #include <xml/saxnamespacefilter.hxx>
39 #endif
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 static Reference< XParser > GetSaxParser(
73 // #110897#
74 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory
77 //Reference< XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
78 //return Reference< XParser >( xServiceManager->createInstance( SERVICENAME_SAXPARSER), UNO_QUERY);
79 return Reference< XParser >( xServiceFactory->createInstance( SERVICENAME_SAXPARSER), UNO_QUERY);
82 static Reference< XDocumentHandler > GetSaxWriter(
83 // #110897#
84 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory
87 //Reference< XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
88 //return Reference< XDocumentHandler >( xServiceManager->createInstance( SERVICENAME_SAXWRITER), UNO_QUERY) ;
89 return Reference< XDocumentHandler >( xServiceFactory->createInstance( SERVICENAME_SAXWRITER), UNO_QUERY) ;
92 // #110897#
93 sal_Bool EventsConfiguration::LoadEventsConfig(
94 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
95 SvStream& rInStream, EventsConfig& aItems )
97 Reference< XParser > xParser( GetSaxParser( xServiceFactory ) );
98 Reference< XInputStream > xInputStream(
99 (::cppu::OWeakObject *)new utl::OInputStreamWrapper( rInStream ),
100 UNO_QUERY );
102 // connect stream to input stream to the parser
103 InputSource aInputSource;
105 aInputSource.aInputStream = xInputStream;
107 // create namespace filter and set events document handler inside to support xml namespaces
108 Reference< XDocumentHandler > xDocHandler( new OReadEventsDocumentHandler( aItems ));
109 Reference< XDocumentHandler > xFilter( new SaxNamespaceFilter( xDocHandler ));
111 // connect parser and filter
112 xParser->setDocumentHandler( xFilter );
116 xParser->parseStream( aInputSource );
117 return sal_True;
119 catch ( RuntimeException& )
121 return sal_False;
123 catch( SAXException& )
125 return sal_False;
127 catch( ::com::sun::star::io::IOException& )
129 return sal_False;
133 // #110897#
134 sal_Bool EventsConfiguration::StoreEventsConfig(
135 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
136 SvStream& rOutStream, const EventsConfig& aItems )
138 Reference< XDocumentHandler > xWriter( GetSaxWriter( xServiceFactory ) );
140 Reference< XOutputStream > xOutputStream(
141 (::cppu::OWeakObject *)new utl::OOutputStreamWrapper( rOutStream ),
142 UNO_QUERY );
144 Reference< ::com::sun::star::io::XActiveDataSource> xDataSource( xWriter , UNO_QUERY );
145 xDataSource->setOutputStream( xOutputStream );
149 OWriteEventsDocumentHandler aWriteEventsDocumentHandler( aItems, xWriter );
150 aWriteEventsDocumentHandler.WriteEventsDocument();
151 return sal_True;
153 catch ( RuntimeException& )
155 return sal_False;
157 catch ( SAXException& )
159 return sal_False;
161 catch ( ::com::sun::star::io::IOException& )
163 return sal_False;