update dev300-m58
[ooovba.git] / framework / source / xml / statusbarconfiguration.cxx
blob618afd67967e96b7f2838839bb2f9fd6137e557a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: statusbarconfiguration.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_framework.hxx"
34 #include <xml/statusbarconfiguration.hxx>
35 #include <xml/statusbardocumenthandler.hxx>
36 #include <xml/saxnamespacefilter.hxx>
37 #include <services.h>
39 //_________________________________________________________________________________________________________________
40 // interface includes
41 //_________________________________________________________________________________________________________________
42 #include <com/sun/star/xml/sax/XParser.hpp>
43 #include <com/sun/star/io/XActiveDataSource.hpp>
44 #include <com/sun/star/io/XInputStream.hpp>
45 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
47 //_________________________________________________________________________________________________________________
48 // other includes
49 //_________________________________________________________________________________________________________________
51 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
52 #include <comphelper/processfactory.hxx>
53 #endif
54 #include <unotools/streamwrap.hxx>
55 #include <tools/debug.hxx>
57 //_________________________________________________________________________________________________________________
58 // namespace
59 //_________________________________________________________________________________________________________________
61 using namespace ::com::sun::star::uno;
62 using namespace ::com::sun::star::xml::sax;
63 using namespace ::com::sun::star::lang;
64 using namespace ::com::sun::star::io;
65 using namespace ::com::sun::star::container;
68 namespace framework
71 SV_IMPL_PTRARR( StatusBarDescriptor, StatusBarItemDescriptorPtr);
73 static Reference< XParser > GetSaxParser(
74 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory
77 return Reference< XParser >( xServiceFactory->createInstance( SERVICENAME_SAXPARSER), UNO_QUERY);
80 static Reference< XDocumentHandler > GetSaxWriter(
81 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory
84 return Reference< XDocumentHandler >( xServiceFactory->createInstance( SERVICENAME_SAXWRITER), UNO_QUERY) ;
87 sal_Bool StatusBarConfiguration::LoadStatusBar(
88 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&,
89 SvStream&, StatusBarDescriptor& )
91 // obsolete - only support linkage of binary filters!
92 return sal_True;
95 sal_Bool StatusBarConfiguration::StoreStatusBar(
96 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&,
97 SvStream&, const StatusBarDescriptor& )
99 // obsolete - only support linkage of binary filters!
100 return sal_True;
103 sal_Bool StatusBarConfiguration::LoadStatusBar(
104 const Reference< XMultiServiceFactory >& xServiceFactory,
105 const Reference< XInputStream >& xInputStream,
106 const Reference< XIndexContainer >& rStatusbarConfiguration )
108 Reference< XParser > xParser( GetSaxParser( xServiceFactory ) );
110 // connect stream to input stream to the parser
111 InputSource aInputSource;
112 aInputSource.aInputStream = xInputStream;
114 // create namespace filter and set menudocument handler inside to support xml namespaces
115 Reference< XDocumentHandler > xDocHandler( new OReadStatusBarDocumentHandler( rStatusbarConfiguration ));
116 Reference< XDocumentHandler > xFilter( new SaxNamespaceFilter( xDocHandler ));
118 // connect parser and filter
119 xParser->setDocumentHandler( xFilter );
123 xParser->parseStream( aInputSource );
124 return sal_True;
126 catch ( RuntimeException& )
128 return sal_False;
130 catch( SAXException& )
132 return sal_False;
134 catch( ::com::sun::star::io::IOException& )
136 return sal_False;
140 sal_Bool StatusBarConfiguration::StoreStatusBar(
141 const Reference< XMultiServiceFactory >& xServiceFactory,
142 const Reference< XOutputStream >& xOutputStream,
143 const Reference< XIndexAccess >& rStatusbarConfiguration )
145 Reference< XDocumentHandler > xWriter( GetSaxWriter( xServiceFactory ) );
146 Reference< ::com::sun::star::io::XActiveDataSource> xDataSource( xWriter , UNO_QUERY );
147 xDataSource->setOutputStream( xOutputStream );
151 OWriteStatusBarDocumentHandler aWriteStatusBarDocumentHandler( rStatusbarConfiguration, xWriter );
152 aWriteStatusBarDocumentHandler.WriteStatusBarDocument();
153 return sal_True;
155 catch ( RuntimeException& )
157 return sal_False;
159 catch ( SAXException& )
161 return sal_False;
163 catch ( ::com::sun::star::io::IOException& )
165 return sal_False;