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