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 $
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>
39 //_________________________________________________________________________________________________________________
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 //_________________________________________________________________________________________________________________
49 //_________________________________________________________________________________________________________________
51 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
52 #include <comphelper/processfactory.hxx>
54 #include <unotools/streamwrap.hxx>
55 #include <tools/debug.hxx>
57 //_________________________________________________________________________________________________________________
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
;
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!
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!
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
);
126 catch ( RuntimeException
& )
130 catch( SAXException
& )
134 catch( ::com::sun::star::io::IOException
& )
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();
155 catch ( RuntimeException
& )
159 catch ( SAXException
& )
163 catch ( ::com::sun::star::io::IOException
& )