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 $
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>
37 #ifndef __FRAMEWORK_XML_SAXNAMESPACEFILTER_HXX_
38 #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 static Reference
< XParser
> GetSaxParser(
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(
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
) ;
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
),
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
);
119 catch ( RuntimeException
& )
123 catch( SAXException
& )
127 catch( ::com::sun::star::io::IOException
& )
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
),
144 Reference
< ::com::sun::star::io::XActiveDataSource
> xDataSource( xWriter
, UNO_QUERY
);
145 xDataSource
->setOutputStream( xOutputStream
);
149 OWriteEventsDocumentHandler
aWriteEventsDocumentHandler( aItems
, xWriter
);
150 aWriteEventsDocumentHandler
.WriteEventsDocument();
153 catch ( RuntimeException
& )
157 catch ( SAXException
& )
161 catch ( ::com::sun::star::io::IOException
& )