2001-07-20 12:49:51 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2005-09-09 00:16:35 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2001-07-20 12:49:51 +00:00
|
|
|
*
|
2005-09-09 00:16:35 +00:00
|
|
|
* $RCSfile: xmltxtimp.cxx,v $
|
2001-07-20 12:49:51 +00:00
|
|
|
*
|
2006-06-19 16:04:29 +00:00
|
|
|
* $Revision: 1.6 $
|
2001-07-20 12:49:51 +00:00
|
|
|
*
|
2006-06-19 16:04:29 +00:00
|
|
|
* last change: $Author: hr $ $Date: 2006-06-19 17:04:29 $
|
2001-07-20 12:49:51 +00:00
|
|
|
*
|
2005-09-09 00:16:35 +00:00
|
|
|
* The Contents of this file are made available subject to
|
|
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
2001-07-20 12:49:51 +00:00
|
|
|
*
|
|
|
|
*
|
2005-09-09 00:16:35 +00:00
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
2001-07-20 12:49:51 +00:00
|
|
|
*
|
2005-09-09 00:16:35 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
2001-07-20 12:49:51 +00:00
|
|
|
*
|
2005-09-09 00:16:35 +00:00
|
|
|
* This library 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 for more details.
|
2001-07-20 12:49:51 +00:00
|
|
|
*
|
2005-09-09 00:16:35 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
2001-07-20 12:49:51 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
#ifndef _TOOLS_DEBUG_HXX
|
|
|
|
#include <tools/debug.hxx>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _COM_SUN_STAR_IO_XACTIVEDATACONTROL_HPP_
|
|
|
|
#include <com/sun/star/io/XActiveDataControl.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_IO_XACTIVEDATASOURCE_HPP_
|
|
|
|
#include <com/sun/star/io/XActiveDataSource.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_XML_SAX_XPARSER_HPP_
|
|
|
|
#include <com/sun/star/xml/sax/XParser.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_XML_SAX_XDOCUMENTHANDLER_HPP_
|
|
|
|
#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_IO_XOUTPUTSTREAM_HPP_
|
|
|
|
#include <com/sun/star/io/XOutputStream.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_TEXT_XTEXT_HPP_
|
|
|
|
#include <com/sun/star/text/XText.hpp>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _COMPHELPER_PROCESSFACTORY_HXX_
|
|
|
|
#include <comphelper/processfactory.hxx>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _UTL_STREAM_WRAPPER_HXX_
|
|
|
|
#include <unotools/streamwrap.hxx>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _RTL_USTRBUF_HXX_
|
|
|
|
#include <rtl/ustrbuf.hxx>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _SVSTOR_HXX
|
2004-10-04 16:57:53 +00:00
|
|
|
#include <sot/storage.hxx>
|
2001-07-20 12:49:51 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _SFX_ITEMPROP_HXX
|
|
|
|
#include <svtools/itemprop.hxx>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _SFXDOCFILE_HXX
|
|
|
|
#include <sfx2/docfile.hxx>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _XMLOFF_XMLIMP_HXX
|
|
|
|
#include <xmloff/xmlimp.hxx>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _XMLOFF_XMLMETAE_HXX
|
|
|
|
#include "xmloff/xmlmetae.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef _XMLOFF_XMLICTXT_HXX
|
|
|
|
#include <xmloff/xmlictxt.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _XMLOFF_XMLTOKEN_HXX
|
|
|
|
#include <xmloff/xmltoken.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _XMLOFF_XMLNMSPE_HXX
|
|
|
|
#include <xmloff/xmlnmspe.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _XMLOFF_XMLSTYLE_HXX
|
|
|
|
#include <xmloff/xmlstyle.hxx>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _SVX_EDITSOURCE_HXX
|
|
|
|
#include "editsource.hxx"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _SVX_UNOTEXT_HXX
|
|
|
|
#include "unotext.hxx"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
using namespace com::sun::star;
|
|
|
|
using namespace com::sun::star::document;
|
|
|
|
using namespace com::sun::star::uno;
|
|
|
|
using namespace com::sun::star::lang;
|
|
|
|
using namespace com::sun::star::xml::sax;
|
|
|
|
using namespace com::sun::star::text;
|
|
|
|
using namespace ::rtl;
|
|
|
|
using namespace cppu;
|
|
|
|
using namespace xmloff::token;
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class SvxXMLTextImportContext : public SvXMLImportContext
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SvxXMLTextImportContext( SvXMLImport& rImport, USHORT nPrfx, const OUString& rLName, const Reference< XAttributeList >& xAttrList, const Reference< XText >& xText );
|
|
|
|
virtual ~SvxXMLTextImportContext();
|
|
|
|
|
|
|
|
virtual SvXMLImportContext *CreateChildContext( USHORT nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList );
|
|
|
|
|
|
|
|
// SvxXMLXTableImport& getImport() const { return *(SvxXMLXTableImport*)&GetImport(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const Reference< XText > mxText;
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
2006-06-19 16:04:29 +00:00
|
|
|
SvxXMLTextImportContext::SvxXMLTextImportContext( SvXMLImport& rImport, USHORT nPrfx, const OUString& rLName, const Reference< XAttributeList >&, const Reference< XText >& xText )
|
2001-07-20 12:49:51 +00:00
|
|
|
: SvXMLImportContext( rImport, nPrfx, rLName ), mxText( xText )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SvxXMLTextImportContext::~SvxXMLTextImportContext()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SvXMLImportContext *SvxXMLTextImportContext::CreateChildContext( USHORT nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList )
|
|
|
|
{
|
|
|
|
SvXMLImportContext* pContext = NULL;
|
|
|
|
if(XML_NAMESPACE_OFFICE == nPrefix && IsXMLToken( rLocalName, XML_BODY ) )
|
|
|
|
{
|
|
|
|
pContext = new SvxXMLTextImportContext( GetImport(), nPrefix, rLocalName, xAttrList, mxText );
|
|
|
|
}
|
|
|
|
else if( XML_NAMESPACE_OFFICE == nPrefix && IsXMLToken( rLocalName, XML_AUTOMATIC_STYLES ) )
|
|
|
|
{
|
|
|
|
pContext = new SvXMLStylesContext( GetImport(), nPrefix, rLocalName, xAttrList );
|
|
|
|
GetImport().GetTextImport()->SetAutoStyles( (SvXMLStylesContext*)pContext );
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pContext = GetImport().GetTextImport()->CreateTextChildContext( GetImport(), nPrefix, rLocalName, xAttrList );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( NULL == pContext )
|
|
|
|
pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
|
|
|
|
|
|
|
|
return pContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class SvxXMLXTextImportComponent : public SvXMLImport
|
|
|
|
{
|
|
|
|
public:
|
2004-05-03 12:28:24 +00:00
|
|
|
// #110680#
|
|
|
|
SvxXMLXTextImportComponent(
|
|
|
|
const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory,
|
|
|
|
const Reference< XText > & xText );
|
|
|
|
|
2001-09-12 12:05:54 +00:00
|
|
|
virtual ~SvxXMLXTextImportComponent() throw ();
|
2001-07-20 12:49:51 +00:00
|
|
|
|
|
|
|
static sal_Bool load( const rtl::OUString& rUrl, const com::sun::star::uno::Reference< com::sun::star::container::XNameContainer >& xTable ) throw();
|
|
|
|
protected:
|
|
|
|
virtual SvXMLImportContext *CreateChildContext( USHORT nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList );
|
|
|
|
|
|
|
|
private:
|
|
|
|
const Reference< XText > mxText;
|
|
|
|
};
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
2004-05-03 12:28:24 +00:00
|
|
|
// #110680#
|
|
|
|
SvxXMLXTextImportComponent::SvxXMLXTextImportComponent(
|
|
|
|
const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory,
|
|
|
|
const Reference< XText > & xText )
|
|
|
|
: SvXMLImport(xServiceFactory),
|
|
|
|
mxText( xText )
|
2001-07-20 12:49:51 +00:00
|
|
|
{
|
|
|
|
GetTextImport()->SetCursor( mxText->createTextCursor() );
|
|
|
|
}
|
|
|
|
|
2001-09-12 12:05:54 +00:00
|
|
|
SvxXMLXTextImportComponent::~SvxXMLXTextImportComponent() throw ()
|
2001-07-20 12:49:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SvxReadXML( EditEngine& rEditEngine, SvStream& rStream, const ESelection& rSel )
|
|
|
|
{
|
|
|
|
SvxEditEngineSource aEditSource( &rEditEngine );
|
|
|
|
|
|
|
|
static const SfxItemPropertyMap SvxXMLTextImportComponentPropertyMap[] =
|
|
|
|
{
|
|
|
|
SVX_UNOEDIT_CHAR_PROPERTIES,
|
|
|
|
SVX_UNOEDIT_FONT_PROPERTIES,
|
|
|
|
// SVX_UNOEDIT_OUTLINER_PROPERTIES,
|
|
|
|
SVX_UNOEDIT_PARA_PROPERTIES,
|
2006-06-19 16:04:29 +00:00
|
|
|
{0,0,0,0,0,0}
|
2001-07-20 12:49:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
uno::Reference<text::XText > xParent;
|
|
|
|
SvxUnoText* pUnoText = new SvxUnoText( &aEditSource, SvxXMLTextImportComponentPropertyMap, xParent );
|
|
|
|
pUnoText->SetSelection( rSel );
|
|
|
|
uno::Reference<text::XText > xText( pUnoText );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
uno::Reference<lang::XMultiServiceFactory> xServiceFactory( ::comphelper::getProcessServiceFactory() );
|
|
|
|
if( !xServiceFactory.is() )
|
|
|
|
{
|
|
|
|
DBG_ERROR( "SvxXMLXTableImport::load: got no service manager" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
uno::Reference< xml::sax::XParser > xParser( xServiceFactory->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.sax.Parser" ) ) ), uno::UNO_QUERY );
|
|
|
|
if( !xParser.is() )
|
|
|
|
{
|
|
|
|
DBG_ERROR( "com.sun.star.xml.sax.Parser service missing" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Reference<io::XInputStream> xInputStream = new utl::OInputStreamWrapper( rStream );
|
|
|
|
|
|
|
|
/* testcode
|
|
|
|
const OUString aURL( RTL_CONSTASCII_USTRINGPARAM( "file:///e:/test.xml" ) );
|
|
|
|
SfxMedium aMedium( aURL, STREAM_READ | STREAM_NOCREATE, TRUE );
|
|
|
|
aMedium.IsRemote();
|
|
|
|
uno::Reference<io::XOutputStream> xOut( new utl::OOutputStreamWrapper( *aMedium.GetOutStream() ) );
|
|
|
|
|
|
|
|
aMedium.GetInStream()->Seek( 0 );
|
|
|
|
uno::Reference< io::XActiveDataSource > xSource( aMedium.GetDataSource() );
|
|
|
|
|
|
|
|
if( !xSource.is() )
|
|
|
|
{
|
|
|
|
DBG_ERROR( "got no data source from medium" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Reference< XInterface > xPipe( xServiceFactory->createInstance(OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.Pipe") ) ) );
|
|
|
|
if( !xPipe.is() )
|
|
|
|
{
|
|
|
|
DBG_ERROR( "XMLReader::Read: com.sun.star.io.Pipe service missing" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// connect pipe's output stream to the data source
|
|
|
|
xSource->setOutputStream( Reference< io::XOutputStream >::query( xPipe ) );
|
|
|
|
|
|
|
|
xml::sax::InputSource aParserInput;
|
|
|
|
aParserInput.aInputStream = uno::Reference< io::XInputStream >::query( xPipe );
|
|
|
|
aParserInput.sSystemId = aMedium.GetName();
|
|
|
|
|
|
|
|
|
|
|
|
if( xSource.is() )
|
|
|
|
{
|
|
|
|
Reference< io::XActiveDataControl > xSourceControl( xSource, UNO_QUERY );
|
|
|
|
xSourceControl->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2004-05-03 12:28:24 +00:00
|
|
|
// #110680#
|
|
|
|
// Reference< XDocumentHandler > xHandler( new SvxXMLXTextImportComponent( xText ) );
|
|
|
|
Reference< XDocumentHandler > xHandler( new SvxXMLXTextImportComponent( xServiceFactory, xText ) );
|
2001-07-20 12:49:51 +00:00
|
|
|
|
|
|
|
xParser->setDocumentHandler( xHandler );
|
|
|
|
|
|
|
|
xml::sax::InputSource aParserInput;
|
|
|
|
aParserInput.aInputStream = xInputStream;
|
|
|
|
// aParserInput.sSystemId = aMedium.GetName();
|
|
|
|
xParser->parseStream( aParserInput );
|
|
|
|
}
|
|
|
|
while(0);
|
|
|
|
}
|
|
|
|
catch( uno::Exception& e )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SvXMLImportContext *SvxXMLXTextImportComponent::CreateChildContext( USHORT nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList )
|
|
|
|
{
|
|
|
|
SvXMLImportContext* pContext;
|
|
|
|
if(XML_NAMESPACE_OFFICE == nPrefix && ( IsXMLToken( rLocalName, XML_DOCUMENT ) || IsXMLToken( rLocalName, XML_DOCUMENT_CONTENT ) ) )
|
|
|
|
{
|
|
|
|
pContext = new SvxXMLTextImportContext(*this, nPrefix, rLocalName, xAttrList, mxText );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pContext = SvXMLImport::CreateContext(nPrefix, rLocalName, xAttrList);
|
|
|
|
}
|
|
|
|
return pContext;
|
|
|
|
}
|
|
|
|
|