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 
25 // MARKER(update_precomp.py): autogen include statement, do not remove
26 #include "precompiled_framework.hxx"
27 #include <framework/statusbarconfiguration.hxx>
28 #include <xml/statusbardocumenthandler.hxx>
29 #include <xml/saxnamespacefilter.hxx>
30 #include <services.h>
31 
32 //_________________________________________________________________________________________________________________
33 //	interface includes
34 //_________________________________________________________________________________________________________________
35 #include <com/sun/star/xml/sax/XParser.hpp>
36 #include <com/sun/star/io/XActiveDataSource.hpp>
37 #include <com/sun/star/io/XInputStream.hpp>
38 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39 
40 //_________________________________________________________________________________________________________________
41 //	other includes
42 //_________________________________________________________________________________________________________________
43 
44 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
45 #include <comphelper/processfactory.hxx>
46 #endif
47 #include <unotools/streamwrap.hxx>
48 #include <tools/debug.hxx>
49 
50 //_________________________________________________________________________________________________________________
51 //	namespace
52 //_________________________________________________________________________________________________________________
53 
54 using namespace ::com::sun::star::uno;
55 using namespace ::com::sun::star::xml::sax;
56 using namespace ::com::sun::star::lang;
57 using namespace ::com::sun::star::io;
58 using namespace ::com::sun::star::container;
59 
60 
61 namespace framework
62 {
63 
64 SV_IMPL_PTRARR( StatusBarDescriptor, StatusBarItemDescriptorPtr);
65 
66 static Reference< XParser > GetSaxParser(
67 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory
68 	)
69 {
70 	return Reference< XParser >( xServiceFactory->createInstance( SERVICENAME_SAXPARSER), UNO_QUERY);
71 }
72 
73 static Reference< XDocumentHandler > GetSaxWriter(
74 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory
75 	)
76 {
77 	return Reference< XDocumentHandler >( xServiceFactory->createInstance( SERVICENAME_SAXWRITER), UNO_QUERY) ;
78 }
79 
80 sal_Bool StatusBarConfiguration::LoadStatusBar(
81 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&,
82 	SvStream&, StatusBarDescriptor& )
83 {
84     // obsolete - only support linkage of binary filters!
85     return sal_True;
86 }
87 
88 sal_Bool StatusBarConfiguration::StoreStatusBar(
89 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&,
90 	SvStream&, const StatusBarDescriptor& )
91 {
92     // obsolete - only support linkage of binary filters!
93     return sal_True;
94 }
95 
96 sal_Bool StatusBarConfiguration::LoadStatusBar(
97 	const Reference< XMultiServiceFactory >& xServiceFactory,
98     const Reference< XInputStream >& xInputStream,
99     const Reference< XIndexContainer >& rStatusbarConfiguration )
100 {
101 	Reference< XParser > xParser( GetSaxParser( xServiceFactory ) );
102 
103 	// connect stream to input stream to the parser
104 	InputSource aInputSource;
105 	aInputSource.aInputStream = xInputStream;
106 
107 	// create namespace filter and set menudocument handler inside to support xml namespaces
108 	Reference< XDocumentHandler > xDocHandler( new OReadStatusBarDocumentHandler( rStatusbarConfiguration ));
109 	Reference< XDocumentHandler > xFilter( new SaxNamespaceFilter( xDocHandler ));
110 
111 	// connect parser and filter
112 	xParser->setDocumentHandler( xFilter );
113 
114 	try
115 	{
116 		xParser->parseStream( aInputSource );
117 		return sal_True;
118 	}
119 	catch ( RuntimeException& )
120 	{
121 		return sal_False;
122 	}
123 	catch( SAXException& )
124 	{
125 		return sal_False;
126 	}
127 	catch( ::com::sun::star::io::IOException& )
128 	{
129 		return sal_False;
130 	}
131 }
132 
133 sal_Bool StatusBarConfiguration::StoreStatusBar(
134 	const Reference< XMultiServiceFactory >& xServiceFactory,
135     const Reference< XOutputStream >& xOutputStream,
136     const Reference< XIndexAccess >& rStatusbarConfiguration )
137 {
138 	Reference< XDocumentHandler > xWriter( GetSaxWriter( xServiceFactory ) );
139 	Reference< ::com::sun::star::io::XActiveDataSource> xDataSource( xWriter , UNO_QUERY );
140 	xDataSource->setOutputStream( xOutputStream );
141 
142 	try
143 	{
144 		OWriteStatusBarDocumentHandler aWriteStatusBarDocumentHandler( rStatusbarConfiguration, xWriter );
145 		aWriteStatusBarDocumentHandler.WriteStatusBarDocument();
146 		return sal_True;
147 	}
148 	catch ( RuntimeException& )
149 	{
150 		return sal_False;
151 	}
152 	catch ( SAXException& )
153 	{
154 		return sal_False;
155 	}
156 	catch ( ::com::sun::star::io::IOException& )
157 	{
158 		return sal_False;
159 	}
160 }
161 }
162 
163