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