LCOV - code coverage report
Current view: top level - libreoffice/editeng/source/xml - xmltxtimp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 51 0.0 %
Date: 2012-12-27 Functions: 0 9 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <com/sun/star/io/Pipe.hpp>
      21             : #include <com/sun/star/io/XActiveDataControl.hpp>
      22             : #include <com/sun/star/io/XActiveDataSource.hpp>
      23             : #include <com/sun/star/xml/sax/Parser.hpp>
      24             : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
      25             : #include <com/sun/star/io/XOutputStream.hpp>
      26             : #include <com/sun/star/text/XText.hpp>
      27             : #include <comphelper/processfactory.hxx>
      28             : #include <unotools/streamwrap.hxx>
      29             : #include <rtl/ustrbuf.hxx>
      30             : #include <sot/storage.hxx>
      31             : #include <svl/itemprop.hxx>
      32             : #include <xmloff/xmlimp.hxx>
      33             : #include <xmloff/xmlmetae.hxx>
      34             : #include <xmloff/xmlictxt.hxx>
      35             : #include <xmloff/xmltoken.hxx>
      36             : #include <xmloff/xmlnmspe.hxx>
      37             : #include <xmloff/xmlstyle.hxx>
      38             : #include "editsource.hxx"
      39             : #include <editeng/editeng.hxx>
      40             : #include <editeng/unotext.hxx>
      41             : #include <editeng/unoprnms.hxx>
      42             : #include <editeng/unoipset.hxx>
      43             : 
      44             : using namespace com::sun::star;
      45             : using namespace com::sun::star::document;
      46             : using namespace com::sun::star::uno;
      47             : using namespace com::sun::star::lang;
      48             : using namespace com::sun::star::xml::sax;
      49             : using namespace com::sun::star::text;
      50             : using namespace ::rtl;
      51             : using namespace cppu;
      52             : using namespace xmloff::token;
      53             : 
      54             : 
      55             : ///////////////////////////////////////////////////////////////////////
      56             : 
      57             : class SvxXMLTextImportContext : public SvXMLImportContext
      58             : {
      59             : public:
      60             :     SvxXMLTextImportContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName, const uno::Reference< XAttributeList >& xAttrList, const uno::Reference< XText >& xText );
      61             :     virtual ~SvxXMLTextImportContext();
      62             : 
      63             :     virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList );
      64             : 
      65             : //  SvxXMLXTableImport& getImport() const { return *(SvxXMLXTableImport*)&GetImport(); }
      66             : 
      67             : private:
      68             :     const uno::Reference< XText > mxText;
      69             : };
      70             : 
      71             : ///////////////////////////////////////////////////////////////////////
      72             : 
      73           0 : SvxXMLTextImportContext::SvxXMLTextImportContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName, const uno::Reference< XAttributeList >&, const uno::Reference< XText >& xText )
      74           0 : : SvXMLImportContext( rImport, nPrfx, rLName ), mxText( xText )
      75             : {
      76           0 : }
      77             : 
      78           0 : SvxXMLTextImportContext::~SvxXMLTextImportContext()
      79             : {
      80           0 : }
      81             : 
      82           0 : SvXMLImportContext *SvxXMLTextImportContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList )
      83             : {
      84           0 :     SvXMLImportContext* pContext = NULL;
      85           0 :     if(XML_NAMESPACE_OFFICE == nPrefix && IsXMLToken( rLocalName, XML_BODY ) )
      86             :     {
      87           0 :         pContext = new SvxXMLTextImportContext( GetImport(), nPrefix, rLocalName, xAttrList, mxText );
      88             :     }
      89           0 :     else if( XML_NAMESPACE_OFFICE == nPrefix && IsXMLToken( rLocalName, XML_AUTOMATIC_STYLES ) )
      90             :     {
      91           0 :         pContext = new SvXMLStylesContext( GetImport(), nPrefix, rLocalName, xAttrList );
      92           0 :         GetImport().GetTextImport()->SetAutoStyles( (SvXMLStylesContext*)pContext );
      93             : 
      94             :     }
      95             :     else
      96             :     {
      97           0 :         pContext = GetImport().GetTextImport()->CreateTextChildContext( GetImport(), nPrefix, rLocalName, xAttrList );
      98             :     }
      99             : 
     100           0 :     if( NULL == pContext )
     101           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     102             : 
     103           0 :     return pContext;
     104             : }
     105             : 
     106             : ///////////////////////////////////////////////////////////////////////
     107             : 
     108             : class SvxXMLXTextImportComponent : public SvXMLImport
     109             : {
     110             : public:
     111             :     SvxXMLXTextImportComponent(
     112             :         const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory,
     113             :         const uno::Reference< XText > & xText );
     114             : 
     115             :     virtual ~SvxXMLXTextImportComponent() throw ();
     116             : 
     117             :     static sal_Bool load( const rtl::OUString& rUrl, const com::sun::star::uno::Reference< com::sun::star::container::XNameContainer >& xTable ) throw();
     118             : protected:
     119             :     virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList );
     120             : 
     121             : private:
     122             :     const uno::Reference< XText > mxText;
     123             : };
     124             : 
     125             : // --------------------------------------------------------------------
     126             : 
     127           0 : SvxXMLXTextImportComponent::SvxXMLXTextImportComponent(
     128             :     const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory,
     129             :     const uno::Reference< XText > & xText )
     130             : :   SvXMLImport(xServiceFactory),
     131           0 :     mxText( xText )
     132             : {
     133           0 :     GetTextImport()->SetCursor( mxText->createTextCursor() );
     134           0 : }
     135             : 
     136           0 : SvxXMLXTextImportComponent::~SvxXMLXTextImportComponent() throw ()
     137             : {
     138           0 : }
     139             : 
     140           0 : void SvxReadXML( EditEngine& rEditEngine, SvStream& rStream, const ESelection& rSel )
     141             : {
     142           0 :     SvxEditEngineSource aEditSource( &rEditEngine );
     143             : 
     144             :     static const SfxItemPropertyMapEntry SvxXMLTextImportComponentPropertyMap[] =
     145             :     {
     146           0 :         SVX_UNOEDIT_CHAR_PROPERTIES,
     147           0 :         SVX_UNOEDIT_FONT_PROPERTIES,
     148             : //      SVX_UNOEDIT_OUTLINER_PROPERTIES,
     149           0 :         SVX_UNOEDIT_PARA_PROPERTIES,
     150             :         {0,0,0,0,0,0}
     151           0 :     };
     152           0 :     static SvxItemPropertySet aSvxXMLTextImportComponentPropertySet( SvxXMLTextImportComponentPropertyMap, EditEngine::GetGlobalItemPool() );
     153             : 
     154           0 :     uno::Reference<text::XText > xParent;
     155           0 :     SvxUnoText* pUnoText = new SvxUnoText( &aEditSource, &aSvxXMLTextImportComponentPropertySet, xParent );
     156           0 :     pUnoText->SetSelection( rSel );
     157           0 :     uno::Reference<text::XText > xText( pUnoText );
     158             : 
     159             :     try
     160             :     {
     161             :         do
     162             :         {
     163           0 :             uno::Reference<lang::XMultiServiceFactory> xServiceFactory( ::comphelper::getProcessServiceFactory() );
     164           0 :             uno::Reference<uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
     165           0 :             if( !xServiceFactory.is() )
     166             :             {
     167             :                 OSL_FAIL( "SvxXMLXTableImport::load: got no service manager" );
     168             :                 break;
     169             :             }
     170             : 
     171           0 :             uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create( xContext );
     172             : 
     173           0 :             uno::Reference<io::XInputStream> xInputStream = new utl::OInputStreamWrapper( rStream );
     174             : 
     175             : /* testcode
     176             :             const OUString aURL( RTL_CONSTASCII_USTRINGPARAM( "file:///e:/test.xml" ) );
     177             :             SfxMedium aMedium( aURL, STREAM_READ | STREAM_NOCREATE, sal_True );
     178             :             aMedium.IsRemote();
     179             :             uno::Reference<io::XOutputStream> xOut( new utl::OOutputStreamWrapper( *aMedium.GetOutStream() ) );
     180             : 
     181             :             aMedium.GetInStream()->Seek( 0 );
     182             :             uno::Reference< io::XActiveDataSource > xSource( aMedium.GetDataSource() );
     183             : 
     184             :             if( !xSource.is() )
     185             :             {
     186             :                 OSL_FAIL( "got no data source from medium" );
     187             :                 break;
     188             :             }
     189             : 
     190             :             uno::Reference< XInterface > xPipe( Pipe::create(comphelper::getComponentContext(xServiceFactory)), UNO_QUERY );
     191             : 
     192             :             // connect pipe's output stream to the data source
     193             :             xSource->setOutputStream( uno::Reference< io::XOutputStream >::query( xPipe ) );
     194             : 
     195             :             xml::sax::InputSource aParserInput;
     196             :             aParserInput.aInputStream = uno::Reference< io::XInputStream >::query( xPipe );
     197             :             aParserInput.sSystemId = aMedium.GetName();
     198             : 
     199             : 
     200             :             if( xSource.is() )
     201             :             {
     202             :                 uno::Reference< io::XActiveDataControl > xSourceControl( xSource, UNO_QUERY );
     203             :                 xSourceControl->start();
     204             :             }
     205             : 
     206             : */
     207             : 
     208             :             // uno::Reference< XDocumentHandler > xHandler( new SvxXMLXTextImportComponent( xText ) );
     209           0 :             uno::Reference< XDocumentHandler > xHandler( new SvxXMLXTextImportComponent( xServiceFactory, xText ) );
     210             : 
     211           0 :             xParser->setDocumentHandler( xHandler );
     212             : 
     213           0 :             xml::sax::InputSource aParserInput;
     214           0 :             aParserInput.aInputStream = xInputStream;
     215             : //          aParserInput.sSystemId = aMedium.GetName();
     216           0 :             xParser->parseStream( aParserInput );
     217             :         }
     218             :         while(0);
     219             :     }
     220           0 :     catch( const uno::Exception& )
     221             :     {
     222           0 :     }
     223           0 : }
     224             : 
     225           0 : SvXMLImportContext *SvxXMLXTextImportComponent::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList )
     226             : {
     227             :     SvXMLImportContext* pContext;
     228           0 :     if(XML_NAMESPACE_OFFICE == nPrefix && ( IsXMLToken( rLocalName, XML_DOCUMENT ) || IsXMLToken( rLocalName, XML_DOCUMENT_CONTENT ) ) )
     229             :     {
     230           0 :          pContext = new SvxXMLTextImportContext(*this, nPrefix, rLocalName, xAttrList, mxText );
     231             :     }
     232             :     else
     233             :     {
     234           0 :         pContext = SvXMLImport::CreateContext(nPrefix, rLocalName, xAttrList);
     235             :     }
     236           0 :     return pContext;
     237             : }
     238             : 
     239             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10