2004-02-25 16:54:31 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 08:25:09 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2004-02-25 16:54:31 +00:00
|
|
|
*
|
2008-04-11 08:25:09 +00:00
|
|
|
* Copyright 2008 by Sun Microsystems, Inc.
|
2004-02-25 16:54:31 +00:00
|
|
|
*
|
2008-04-11 08:25:09 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2004-02-25 16:54:31 +00:00
|
|
|
*
|
2008-04-11 08:25:09 +00:00
|
|
|
* $RCSfile: imagesconfiguration.cxx,v $
|
2008-06-24 16:05:44 +00:00
|
|
|
* $Revision: 1.9 $
|
2004-02-25 16:54:31 +00:00
|
|
|
*
|
2008-04-11 08:25:09 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2004-02-25 16:54:31 +00:00
|
|
|
*
|
2008-04-11 08:25:09 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2004-02-25 16:54:31 +00:00
|
|
|
*
|
2008-04-11 08:25:09 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2004-02-25 16:54:31 +00:00
|
|
|
*
|
2008-04-11 08:25:09 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2004-02-25 16:54:31 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-16 13:30:04 +00:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_framework.hxx"
|
2004-02-25 16:54:31 +00:00
|
|
|
#include <xml/imagesconfiguration.hxx>
|
2009-09-08 04:57:32 +00:00
|
|
|
#include <services.h>
|
2004-02-25 16:54:31 +00:00
|
|
|
|
|
|
|
#ifndef __FRAMEWORK_CLASSES_IMAGESDOCUMENTHANDLER_HXX_
|
|
|
|
#include <xml/imagesdocumenthandler.hxx>
|
|
|
|
#endif
|
|
|
|
#include <xml/saxnamespacefilter.hxx>
|
|
|
|
|
|
|
|
//_________________________________________________________________________________________________________________
|
|
|
|
// interface includes
|
|
|
|
//_________________________________________________________________________________________________________________
|
|
|
|
#include <com/sun/star/xml/sax/XParser.hpp>
|
|
|
|
#include <com/sun/star/io/XActiveDataSource.hpp>
|
|
|
|
#include <com/sun/star/io/XInputStream.hpp>
|
|
|
|
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
|
|
|
|
|
|
|
//_________________________________________________________________________________________________________________
|
|
|
|
// other includes
|
|
|
|
//_________________________________________________________________________________________________________________
|
|
|
|
|
|
|
|
#ifndef _UNOTOOLS_PROCESSFACTORY_HXX
|
|
|
|
#include <comphelper/processfactory.hxx>
|
|
|
|
#endif
|
|
|
|
#include <unotools/streamwrap.hxx>
|
|
|
|
#include <tools/debug.hxx>
|
|
|
|
|
|
|
|
//_________________________________________________________________________________________________________________
|
|
|
|
// namespace
|
|
|
|
//_________________________________________________________________________________________________________________
|
|
|
|
|
|
|
|
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( ImageItemListDescriptor, ImageItemDescriptorPtr );
|
|
|
|
SV_IMPL_PTRARR( ExternalImageItemListDescriptor, ExternalImageItemDescriptorPtr );
|
|
|
|
SV_IMPL_PTRARR( ImageListDescriptor, ImageListItemDescriptorPtr );
|
|
|
|
|
2004-05-03 12:23:25 +00:00
|
|
|
static Reference< XParser > GetSaxParser(
|
|
|
|
// #110897#
|
|
|
|
const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory
|
|
|
|
)
|
2004-02-25 16:54:31 +00:00
|
|
|
{
|
2004-05-03 12:23:25 +00:00
|
|
|
//Reference< XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
|
2009-09-08 04:57:32 +00:00
|
|
|
//return Reference< XParser >( xServiceManager->createInstance( SERVICENAME_SAXPARSER), UNO_QUERY);
|
|
|
|
return Reference< XParser >( xServiceFactory->createInstance( SERVICENAME_SAXPARSER), UNO_QUERY);
|
2004-02-25 16:54:31 +00:00
|
|
|
}
|
|
|
|
|
2004-05-03 12:23:25 +00:00
|
|
|
static Reference< XDocumentHandler > GetSaxWriter(
|
|
|
|
// #110897#
|
|
|
|
const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory
|
|
|
|
)
|
2004-02-25 16:54:31 +00:00
|
|
|
{
|
2004-05-03 12:23:25 +00:00
|
|
|
//Reference< XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
|
2009-09-08 04:57:32 +00:00
|
|
|
//return Reference< XDocumentHandler >( xServiceManager->createInstance( SERVICENAME_SAXWRITER), UNO_QUERY) ;
|
|
|
|
return Reference< XDocumentHandler >( xServiceFactory->createInstance( SERVICENAME_SAXWRITER), UNO_QUERY) ;
|
2004-02-25 16:54:31 +00:00
|
|
|
}
|
|
|
|
|
2004-05-03 12:23:25 +00:00
|
|
|
// #110897#
|
|
|
|
sal_Bool ImagesConfiguration::LoadImages(
|
|
|
|
const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
|
|
|
|
SvStream& rInStream, ImageListsDescriptor& aItems )
|
2004-02-25 16:54:31 +00:00
|
|
|
{
|
2004-05-03 12:23:25 +00:00
|
|
|
Reference< XParser > xParser( GetSaxParser( xServiceFactory ) );
|
2004-02-25 16:54:31 +00:00
|
|
|
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 document handler inside to support xml namespaces
|
|
|
|
Reference< XDocumentHandler > xDocHandler( new OReadImagesDocumentHandler( 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-03 12:23:25 +00:00
|
|
|
// #110897#
|
|
|
|
sal_Bool ImagesConfiguration::StoreImages(
|
|
|
|
const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
|
|
|
|
SvStream& rOutStream, const ImageListsDescriptor& aItems )
|
2004-02-25 16:54:31 +00:00
|
|
|
{
|
2004-05-03 12:23:25 +00:00
|
|
|
Reference< XDocumentHandler > xWriter( GetSaxWriter( xServiceFactory ) );
|
2004-02-25 16:54:31 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
OWriteImagesDocumentHandler aWriteImagesDocumentHandler( aItems, xWriter );
|
|
|
|
aWriteImagesDocumentHandler.WriteImagesDocument();
|
|
|
|
return sal_True;
|
|
|
|
}
|
|
|
|
catch ( RuntimeException& )
|
|
|
|
{
|
|
|
|
return sal_False;
|
|
|
|
}
|
|
|
|
catch ( SAXException& )
|
|
|
|
{
|
|
|
|
return sal_False;
|
|
|
|
}
|
|
|
|
catch ( ::com::sun::star::io::IOException& )
|
|
|
|
{
|
|
|
|
return sal_False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-06 16:03:47 +00:00
|
|
|
sal_Bool ImagesConfiguration::LoadImages(
|
|
|
|
const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
|
|
|
|
const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rInputStream,
|
|
|
|
ImageListsDescriptor& rItems )
|
|
|
|
{
|
|
|
|
Reference< XParser > xParser( GetSaxParser( xServiceFactory ) );
|
|
|
|
|
|
|
|
// connect stream to input stream to the parser
|
|
|
|
InputSource aInputSource;
|
|
|
|
|
|
|
|
aInputSource.aInputStream = rInputStream;
|
|
|
|
|
|
|
|
// create namespace filter and set document handler inside to support xml namespaces
|
|
|
|
Reference< XDocumentHandler > xDocHandler( new OReadImagesDocumentHandler( rItems ));
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool ImagesConfiguration::StoreImages(
|
|
|
|
const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
|
|
|
|
const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& rOutputStream,
|
|
|
|
const ImageListsDescriptor& rItems )
|
|
|
|
{
|
|
|
|
Reference< XDocumentHandler > xWriter( GetSaxWriter( xServiceFactory ) );
|
|
|
|
|
|
|
|
Reference< ::com::sun::star::io::XActiveDataSource> xDataSource( xWriter , UNO_QUERY );
|
|
|
|
xDataSource->setOutputStream( rOutputStream );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
OWriteImagesDocumentHandler aWriteImagesDocumentHandler( rItems, xWriter );
|
|
|
|
aWriteImagesDocumentHandler.WriteImagesDocument();
|
|
|
|
return sal_True;
|
|
|
|
}
|
|
|
|
catch ( RuntimeException& )
|
|
|
|
{
|
|
|
|
return sal_False;
|
|
|
|
}
|
|
|
|
catch ( SAXException& )
|
|
|
|
{
|
|
|
|
return sal_False;
|
|
|
|
}
|
|
|
|
catch ( ::com::sun::star::io::IOException& )
|
|
|
|
{
|
|
|
|
return sal_False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-25 16:54:31 +00:00
|
|
|
}
|
2008-06-24 16:05:44 +00:00
|
|
|
|