Files
libreoffice/framework/source/xml/toolboxconfiguration.cxx
Rüdiger Timm 243c2eee0a INTEGRATION: CWS binfilter (1.2.24); FILE MERGED
2004/04/19 09:46:30 aw 1.2.24.1: #110098#
Necessary adaptions to framework after resynching binfilter to SRC680m33
2004-05-03 12:23:58 +00:00

255 lines
8.0 KiB
C++

#ifndef __FRAMEWORK_CLASSES_TOOLBOXCONFIGURATION_HXX_
#include <xml/toolboxconfiguration.hxx>
#endif
#ifndef __FRAMEWORK_CLASSES_TOOLBOXDOCUMENTHANDLER_HXX_
#include <xml/toolboxdocumenthandler.hxx>
#endif
#ifndef __FRAMEWORK_CLASSES_TOOLBOXLAYOUTDOCUMENTHANDLER_HXX_
#include <xml/toolboxlayoutdocumenthandler.hxx>
#endif
#ifndef __FRAMEWORK_SERVICES_SAXNAMESPACEFILTER_HXX_
#include <xml/saxnamespacefilter.hxx>
#endif
//_________________________________________________________________________________________________________________
// interface includes
//_________________________________________________________________________________________________________________
#ifndef _COM_SUN_STAR_XML_SAX_XPARSER_HPP_
#include <com/sun/star/xml/sax/XParser.hpp>
#endif
#ifndef _COM_SUN_STAR_IO_XACTIVEDATASOURCE_HPP_
#include <com/sun/star/io/XActiveDataSource.hpp>
#endif
#ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_HPP_
#include <com/sun/star/io/XInputStream.hpp>
#endif
#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#endif
//_________________________________________________________________________________________________________________
// other includes
//_________________________________________________________________________________________________________________
#ifndef _UNOTOOLS_PROCESSFACTORY_HXX
#include <comphelper/processfactory.hxx>
#endif
#ifndef _UTL_STREAM_WRAPPER_HXX_
#include <unotools/streamwrap.hxx>
#endif
#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif
//_________________________________________________________________________________________________________________
// namespace
//_________________________________________________________________________________________________________________
using namespace ::rtl;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::xml::sax;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::io;
namespace framework
{
SV_IMPL_PTRARR( ToolBoxDescriptor, ToolBoxItemDescriptorPtr);
SV_IMPL_PTRARR( ToolBoxLayoutDescriptor, ToolBoxLayoutItemDescriptorPtr);
static Reference< XParser > GetSaxParser(
// #110897#
const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory
)
{
//Reference< XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
//return Reference< XParser >( xServiceManager->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.xml.sax.Parser" )), UNO_QUERY);
return Reference< XParser >( xServiceFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.xml.sax.Parser" )), UNO_QUERY);
}
static Reference< XDocumentHandler > GetSaxWriter(
// #110897#
const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory
)
{
//Reference< XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
//return Reference< XDocumentHandler >( xServiceManager->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.xml.sax.Writer" )), UNO_QUERY) ;
return Reference< XDocumentHandler >( xServiceFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.xml.sax.Writer" )), UNO_QUERY) ;
}
// #110897#
sal_Bool ToolBoxConfiguration::LoadToolBox(
const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
SvStream& rInStream,
ToolBoxDescriptor& aItems )
{
Reference< XParser > xParser( GetSaxParser( xServiceFactory ) );
Reference< XInputStream > xInputStream(
(::cppu::OWeakObject *)new utl::OInputStreamWrapper( rInStream ),
UNO_QUERY );
// connect stream to input stream to the parser
InputSource aInputSource;
aInputSource.aInputStream = xInputStream;
// create namespace filter and set menudocument handler inside to support xml namespaces
Reference< XDocumentHandler > xDocHandler( new OReadToolBoxDocumentHandler( aItems ));
Reference< XDocumentHandler > xFilter( new SaxNamespaceFilter( xDocHandler ));
// connect parser and filter
xParser->setDocumentHandler( xFilter );
try
{
xParser->parseStream( aInputSource );
return sal_True;
}
catch ( RuntimeException& )
{
return sal_False;
}
catch( SAXException& )
{
return sal_False;
}
catch( ::com::sun::star::io::IOException& )
{
return sal_False;
}
return sal_False;
}
// #110897#
sal_Bool ToolBoxConfiguration::StoreToolBox(
const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
SvStream& rOutStream,
const ToolBoxDescriptor& aItems )
{
Reference< XDocumentHandler > xWriter( GetSaxWriter( xServiceFactory ) );
Reference< XOutputStream > xOutputStream(
(::cppu::OWeakObject *)new utl::OOutputStreamWrapper( rOutStream ),
UNO_QUERY );
Reference< ::com::sun::star::io::XActiveDataSource> xDataSource( xWriter , UNO_QUERY );
xDataSource->setOutputStream( xOutputStream );
try
{
OWriteToolBoxDocumentHandler aWriteToolBoxDocumentHandler( aItems, xWriter );
aWriteToolBoxDocumentHandler.WriteToolBoxDocument();
return sal_True;
}
catch ( RuntimeException& )
{
return sal_False;
}
catch ( SAXException& )
{
return sal_False;
}
catch ( ::com::sun::star::io::IOException& )
{
return sal_False;
}
return sal_False;
}
// #110897#
sal_Bool ToolBoxConfiguration::LoadToolBoxLayout(
const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
SvStream& rInStream,
ToolBoxLayoutDescriptor& aItems )
{
Reference< XParser > xParser( GetSaxParser( xServiceFactory ) );
Reference< XInputStream > xInputStream(
(::cppu::OWeakObject *)new utl::OInputStreamWrapper( rInStream ),
UNO_QUERY );
// connect stream to input stream to the parser
InputSource aInputSource;
aInputSource.aInputStream = xInputStream;
// create namespace filter and set menudocument handler inside to support xml namespaces
Reference< XDocumentHandler > xDocHandler( new OReadToolBoxLayoutDocumentHandler( aItems ));
Reference< XDocumentHandler > xFilter( new SaxNamespaceFilter( xDocHandler ));
// connect parser and filter
xParser->setDocumentHandler( xFilter );
try
{
xParser->parseStream( aInputSource );
return sal_True;
}
catch ( RuntimeException& )
{
return sal_False;
}
catch( SAXException& )
{
return sal_False;
}
catch( ::com::sun::star::io::IOException& )
{
return sal_False;
}
return sal_False;
}
// #110897#
sal_Bool ToolBoxConfiguration::StoreToolBoxLayout(
const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
SvStream& rOutStream,
ToolBoxLayoutDescriptor& aItems )
{
Reference< XDocumentHandler > xWriter( GetSaxWriter( xServiceFactory ) );
Reference< XOutputStream > xOutputStream(
(::cppu::OWeakObject *)new utl::OOutputStreamWrapper( rOutStream ),
UNO_QUERY );
Reference< ::com::sun::star::io::XActiveDataSource> xDataSource( xWriter , UNO_QUERY );
xDataSource->setOutputStream( xOutputStream );
try
{
OWriteToolBoxLayoutDocumentHandler aWriteToolBoxLayoutDocumentHandler( aItems, xWriter );
aWriteToolBoxLayoutDocumentHandler.WriteToolBoxLayoutDocument();
return sal_True;
}
catch ( RuntimeException& )
{
return sal_False;
}
catch ( SAXException& )
{
return sal_False;
}
catch ( ::com::sun::star::io::IOException& )
{
return sal_False;
}
return sal_False;
}
}