update dev300-m58
[ooovba.git] / framework / source / xml / toolboxconfiguration.cxx
blob24c1e8840f797344d0be4a69a751fefbf966caf9
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: toolboxconfiguration.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/toolboxconfiguration.hxx>
35 #include <xml/toolboxdocumenthandler.hxx>
36 #include <xml/toolboxlayoutdocumenthandler.hxx>
37 #include <xml/saxnamespacefilter.hxx>
38 #include <services.h>
40 //_________________________________________________________________________________________________________________
41 // interface includes
42 //_________________________________________________________________________________________________________________
43 #include <com/sun/star/xml/sax/XParser.hpp>
44 #include <com/sun/star/io/XActiveDataSource.hpp>
45 #include <com/sun/star/io/XInputStream.hpp>
46 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
48 //_________________________________________________________________________________________________________________
49 // other includes
50 //_________________________________________________________________________________________________________________
52 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
53 #include <comphelper/processfactory.hxx>
54 #endif
55 #include <unotools/streamwrap.hxx>
56 #include <tools/debug.hxx>
58 //_________________________________________________________________________________________________________________
59 // namespace
60 //_________________________________________________________________________________________________________________
62 using namespace ::com::sun::star::uno;
63 using namespace ::com::sun::star::xml::sax;
64 using namespace ::com::sun::star::lang;
65 using namespace ::com::sun::star::io;
66 using namespace ::com::sun::star::container;
69 namespace framework
72 static Reference< XParser > GetSaxParser(
73 // #110897#
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 // #110897#
82 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory
85 return Reference< XDocumentHandler >( xServiceFactory->createInstance( SERVICENAME_SAXWRITER), UNO_QUERY) ;
88 // #110897#
89 sal_Bool ToolBoxConfiguration::LoadToolBox(
90 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
91 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rInputStream,
92 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >& rToolbarConfiguration )
94 Reference< XParser > xParser( GetSaxParser( xServiceFactory ) );
96 // connect stream to input stream to the parser
97 InputSource aInputSource;
99 aInputSource.aInputStream = rInputStream;
101 // create namespace filter and set menudocument handler inside to support xml namespaces
102 Reference< XDocumentHandler > xDocHandler( new OReadToolBoxDocumentHandler( rToolbarConfiguration ));
103 Reference< XDocumentHandler > xFilter( new SaxNamespaceFilter( xDocHandler ));
105 // connect parser and filter
106 xParser->setDocumentHandler( xFilter );
110 xParser->parseStream( aInputSource );
111 return sal_True;
113 catch ( RuntimeException& )
115 return sal_False;
117 catch( SAXException& )
119 return sal_False;
121 catch( ::com::sun::star::io::IOException& )
123 return sal_False;
128 // #110897#
129 sal_Bool ToolBoxConfiguration::StoreToolBox(
130 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
131 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& rOutputStream,
132 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& rToolbarConfiguration )
134 Reference< XDocumentHandler > xWriter( GetSaxWriter( xServiceFactory ) );
136 Reference< ::com::sun::star::io::XActiveDataSource> xDataSource( xWriter , UNO_QUERY );
137 xDataSource->setOutputStream( rOutputStream );
141 OWriteToolBoxDocumentHandler aWriteToolBoxDocumentHandler( rToolbarConfiguration, xWriter );
142 aWriteToolBoxDocumentHandler.WriteToolBoxDocument();
143 return sal_True;
145 catch ( RuntimeException& )
147 return sal_False;
149 catch ( SAXException& )
151 return sal_False;
153 catch ( ::com::sun::star::io::IOException& )
155 return sal_False;