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 $
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>
40 //_________________________________________________________________________________________________________________
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 //_________________________________________________________________________________________________________________
50 //_________________________________________________________________________________________________________________
52 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
53 #include <comphelper/processfactory.hxx>
55 #include <unotools/streamwrap.hxx>
56 #include <tools/debug.hxx>
58 //_________________________________________________________________________________________________________________
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
;
72 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(
82 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& xServiceFactory
85 return Reference
< XDocumentHandler
>( xServiceFactory
->createInstance( SERVICENAME_SAXWRITER
), UNO_QUERY
) ;
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
);
113 catch ( RuntimeException
& )
117 catch( SAXException
& )
121 catch( ::com::sun::star::io::IOException
& )
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();
145 catch ( RuntimeException
& )
149 catch ( SAXException
& )
153 catch ( ::com::sun::star::io::IOException
& )