1*6d739b60SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*6d739b60SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*6d739b60SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*6d739b60SAndrew Rist  * distributed with this work for additional information
6*6d739b60SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*6d739b60SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*6d739b60SAndrew Rist  * "License"); you may not use this file except in compliance
9*6d739b60SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*6d739b60SAndrew Rist  *
11*6d739b60SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*6d739b60SAndrew Rist  *
13*6d739b60SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*6d739b60SAndrew Rist  * software distributed under the License is distributed on an
15*6d739b60SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*6d739b60SAndrew Rist  * KIND, either express or implied.  See the License for the
17*6d739b60SAndrew Rist  * specific language governing permissions and limitations
18*6d739b60SAndrew Rist  * under the License.
19*6d739b60SAndrew Rist  *
20*6d739b60SAndrew Rist  *************************************************************/
21*6d739b60SAndrew Rist 
22*6d739b60SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_framework.hxx"
26cdf0e10cSrcweir #include <framework/eventsconfiguration.hxx>
27cdf0e10cSrcweir #include <xml/eventsdocumenthandler.hxx>
28cdf0e10cSrcweir #include <services.h>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #ifndef __FRAMEWORK_XML_SAXNAMESPACEFILTER_HXX_
31cdf0e10cSrcweir #include <xml/saxnamespacefilter.hxx>
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir 
34cdf0e10cSrcweir //_________________________________________________________________________________________________________________
35cdf0e10cSrcweir //	interface includes
36cdf0e10cSrcweir //_________________________________________________________________________________________________________________
37cdf0e10cSrcweir #include <com/sun/star/xml/sax/XParser.hpp>
38cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSource.hpp>
39cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp>
40cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir //_________________________________________________________________________________________________________________
43cdf0e10cSrcweir //	other includes
44cdf0e10cSrcweir //_________________________________________________________________________________________________________________
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
47cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
48cdf0e10cSrcweir #endif
49cdf0e10cSrcweir #include <unotools/streamwrap.hxx>
50cdf0e10cSrcweir #include <tools/debug.hxx>
51cdf0e10cSrcweir 
52cdf0e10cSrcweir //_________________________________________________________________________________________________________________
53cdf0e10cSrcweir //	namespace
54cdf0e10cSrcweir //_________________________________________________________________________________________________________________
55cdf0e10cSrcweir 
56cdf0e10cSrcweir using namespace ::com::sun::star::uno;
57cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
58cdf0e10cSrcweir using namespace ::com::sun::star::lang;
59cdf0e10cSrcweir using namespace ::com::sun::star::io;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 
62cdf0e10cSrcweir namespace framework
63cdf0e10cSrcweir {
64cdf0e10cSrcweir 
GetSaxParser(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & xServiceFactory)65cdf0e10cSrcweir static Reference< XParser > GetSaxParser(
66cdf0e10cSrcweir 	// #110897#
67cdf0e10cSrcweir 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory
68cdf0e10cSrcweir 	)
69cdf0e10cSrcweir {
70cdf0e10cSrcweir 	//Reference< XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
71cdf0e10cSrcweir 	//return Reference< XParser >( xServiceManager->createInstance( SERVICENAME_SAXPARSER), UNO_QUERY);
72cdf0e10cSrcweir 	return Reference< XParser >( xServiceFactory->createInstance( SERVICENAME_SAXPARSER), UNO_QUERY);
73cdf0e10cSrcweir }
74cdf0e10cSrcweir 
GetSaxWriter(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & xServiceFactory)75cdf0e10cSrcweir static Reference< XDocumentHandler > GetSaxWriter(
76cdf0e10cSrcweir 	// #110897#
77cdf0e10cSrcweir 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory
78cdf0e10cSrcweir 	)
79cdf0e10cSrcweir {
80cdf0e10cSrcweir 	//Reference< XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
81cdf0e10cSrcweir 	//return Reference< XDocumentHandler >( xServiceManager->createInstance( SERVICENAME_SAXWRITER), UNO_QUERY) ;
82cdf0e10cSrcweir 	return Reference< XDocumentHandler >( xServiceFactory->createInstance( SERVICENAME_SAXWRITER), UNO_QUERY) ;
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir // #110897#
LoadEventsConfig(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & xServiceFactory,SvStream & rInStream,EventsConfig & aItems)86cdf0e10cSrcweir sal_Bool EventsConfiguration::LoadEventsConfig(
87cdf0e10cSrcweir 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
88cdf0e10cSrcweir 	SvStream& rInStream, EventsConfig& aItems )
89cdf0e10cSrcweir {
90cdf0e10cSrcweir 	Reference< XParser > xParser( GetSaxParser( xServiceFactory ) );
91cdf0e10cSrcweir 	Reference< XInputStream > xInputStream(
92cdf0e10cSrcweir 								(::cppu::OWeakObject *)new utl::OInputStreamWrapper( rInStream ),
93cdf0e10cSrcweir 								UNO_QUERY );
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 	// connect stream to input stream to the parser
96cdf0e10cSrcweir 	InputSource aInputSource;
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 	aInputSource.aInputStream = xInputStream;
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 	// create namespace filter and set events document handler inside to support xml namespaces
101cdf0e10cSrcweir 	Reference< XDocumentHandler > xDocHandler( new OReadEventsDocumentHandler( aItems ));
102cdf0e10cSrcweir 	Reference< XDocumentHandler > xFilter( new SaxNamespaceFilter( xDocHandler ));
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 	// connect parser and filter
105cdf0e10cSrcweir 	xParser->setDocumentHandler( xFilter );
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 	try
108cdf0e10cSrcweir 	{
109cdf0e10cSrcweir 		xParser->parseStream( aInputSource );
110cdf0e10cSrcweir 		return sal_True;
111cdf0e10cSrcweir 	}
112cdf0e10cSrcweir 	catch ( RuntimeException& )
113cdf0e10cSrcweir 	{
114cdf0e10cSrcweir 		return sal_False;
115cdf0e10cSrcweir 	}
116cdf0e10cSrcweir 	catch( SAXException& )
117cdf0e10cSrcweir 	{
118cdf0e10cSrcweir 		return sal_False;
119cdf0e10cSrcweir 	}
120cdf0e10cSrcweir 	catch( ::com::sun::star::io::IOException& )
121cdf0e10cSrcweir 	{
122cdf0e10cSrcweir 		return sal_False;
123cdf0e10cSrcweir 	}
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir // #110897#
StoreEventsConfig(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & xServiceFactory,SvStream & rOutStream,const EventsConfig & aItems)127cdf0e10cSrcweir sal_Bool EventsConfiguration::StoreEventsConfig(
128cdf0e10cSrcweir 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
129cdf0e10cSrcweir 	SvStream& rOutStream, const EventsConfig& aItems )
130cdf0e10cSrcweir {
131cdf0e10cSrcweir 	Reference< XDocumentHandler > xWriter( GetSaxWriter( xServiceFactory ) );
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 	Reference< XOutputStream > xOutputStream(
134cdf0e10cSrcweir 								(::cppu::OWeakObject *)new utl::OOutputStreamWrapper( rOutStream ),
135cdf0e10cSrcweir 								UNO_QUERY );
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 	Reference< ::com::sun::star::io::XActiveDataSource> xDataSource( xWriter , UNO_QUERY );
138cdf0e10cSrcweir 	xDataSource->setOutputStream( xOutputStream );
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 	try
141cdf0e10cSrcweir 	{
142cdf0e10cSrcweir 		OWriteEventsDocumentHandler aWriteEventsDocumentHandler( aItems, xWriter );
143cdf0e10cSrcweir 		aWriteEventsDocumentHandler.WriteEventsDocument();
144cdf0e10cSrcweir 		return sal_True;
145cdf0e10cSrcweir 	}
146cdf0e10cSrcweir 	catch ( RuntimeException& )
147cdf0e10cSrcweir 	{
148cdf0e10cSrcweir 		return sal_False;
149cdf0e10cSrcweir 	}
150cdf0e10cSrcweir 	catch ( SAXException& )
151cdf0e10cSrcweir 	{
152cdf0e10cSrcweir 		return sal_False;
153cdf0e10cSrcweir 	}
154cdf0e10cSrcweir 	catch ( ::com::sun::star::io::IOException& )
155cdf0e10cSrcweir 	{
156cdf0e10cSrcweir 		return sal_False;
157cdf0e10cSrcweir 	}
158cdf0e10cSrcweir }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir }
161cdf0e10cSrcweir 
162