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