LCOV - code coverage report
Current view: top level - editeng/source/xml - xmltxtimp.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 49 0.0 %
Date: 2014-04-14 Functions: 0 10 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 "editxml.hxx"
      40             : #include <editeng/editeng.hxx>
      41             : #include <editeng/unotext.hxx>
      42             : #include <editeng/unoprnms.hxx>
      43             : #include <editeng/unoipset.hxx>
      44             : 
      45             : using namespace com::sun::star;
      46             : using namespace com::sun::star::document;
      47             : using namespace com::sun::star::uno;
      48             : using namespace com::sun::star::lang;
      49             : using namespace com::sun::star::xml::sax;
      50             : using namespace com::sun::star::text;
      51             : using namespace ::rtl;
      52             : using namespace cppu;
      53             : using namespace xmloff::token;
      54             : 
      55             : 
      56             : 
      57             : 
      58             : class SvxXMLTextImportContext : public SvXMLImportContext
      59             : {
      60             : public:
      61             :     SvxXMLTextImportContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName, const uno::Reference< XAttributeList >& xAttrList, const uno::Reference< XText >& xText );
      62             :     virtual ~SvxXMLTextImportContext();
      63             : 
      64             :     virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList ) SAL_OVERRIDE;
      65             : 
      66             : //  SvxXMLXTableImport& getImport() const { return *(SvxXMLXTableImport*)&GetImport(); }
      67             : 
      68             : private:
      69             :     const uno::Reference< XText > mxText;
      70             : };
      71             : 
      72             : 
      73             : 
      74           0 : SvxXMLTextImportContext::SvxXMLTextImportContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName, const uno::Reference< XAttributeList >&, const uno::Reference< XText >& xText )
      75           0 : : SvXMLImportContext( rImport, nPrfx, rLName ), mxText( xText )
      76             : {
      77           0 : }
      78             : 
      79           0 : SvxXMLTextImportContext::~SvxXMLTextImportContext()
      80             : {
      81           0 : }
      82             : 
      83           0 : SvXMLImportContext *SvxXMLTextImportContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList )
      84             : {
      85           0 :     SvXMLImportContext* pContext = NULL;
      86           0 :     if(XML_NAMESPACE_OFFICE == nPrefix && IsXMLToken( rLocalName, XML_BODY ) )
      87             :     {
      88           0 :         pContext = new SvxXMLTextImportContext( GetImport(), nPrefix, rLocalName, xAttrList, mxText );
      89             :     }
      90           0 :     else if( XML_NAMESPACE_OFFICE == nPrefix && IsXMLToken( rLocalName, XML_AUTOMATIC_STYLES ) )
      91             :     {
      92           0 :         pContext = new SvXMLStylesContext( GetImport(), nPrefix, rLocalName, xAttrList );
      93           0 :         GetImport().GetTextImport()->SetAutoStyles( (SvXMLStylesContext*)pContext );
      94             : 
      95             :     }
      96             :     else
      97             :     {
      98           0 :         pContext = GetImport().GetTextImport()->CreateTextChildContext( GetImport(), nPrefix, rLocalName, xAttrList );
      99             :     }
     100             : 
     101           0 :     if( NULL == pContext )
     102           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     103             : 
     104           0 :     return pContext;
     105             : }
     106             : 
     107             : 
     108             : 
     109             : class SvxXMLXTextImportComponent : public SvXMLImport
     110             : {
     111             : public:
     112             :     SvxXMLXTextImportComponent(
     113             :         const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > xContext,
     114             :         const uno::Reference< XText > & xText );
     115             : 
     116             :     virtual ~SvxXMLXTextImportComponent() throw ();
     117             : 
     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::uno::XComponentContext > xContext,
     129             :     const uno::Reference< XText > & xText )
     130             : :   SvXMLImport(xContext, ""),
     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             :         { OUString(), 0, css::uno::Type(), 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<uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
     164             : 
     165           0 :             uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create( xContext );
     166             : 
     167           0 :             uno::Reference<io::XInputStream> xInputStream = new utl::OInputStreamWrapper( rStream );
     168             : 
     169             : /* testcode
     170             :             const OUString aURL( "file:///e:/test.xml" );
     171             :             SfxMedium aMedium( aURL, STREAM_READ | STREAM_NOCREATE, sal_True );
     172             :             aMedium.IsRemote();
     173             :             uno::Reference<io::XOutputStream> xOut( new utl::OOutputStreamWrapper( *aMedium.GetOutStream() ) );
     174             : 
     175             :             aMedium.GetInStream()->Seek( 0 );
     176             :             uno::Reference< io::XActiveDataSource > xSource( aMedium.GetDataSource() );
     177             : 
     178             :             if( !xSource.is() )
     179             :             {
     180             :                 OSL_FAIL( "got no data source from medium" );
     181             :                 break;
     182             :             }
     183             : 
     184             :             uno::Reference< XInterface > xPipe( Pipe::create(comphelper::getComponentContext(xServiceFactory)), UNO_QUERY );
     185             : 
     186             :             // connect pipe's output stream to the data source
     187             :             xSource->setOutputStream( uno::Reference< io::XOutputStream >::query( xPipe ) );
     188             : 
     189             :             xml::sax::InputSource aParserInput;
     190             :             aParserInput.aInputStream = uno::Reference< io::XInputStream >::query( xPipe );
     191             :             aParserInput.sSystemId = aMedium.GetName();
     192             : 
     193             : 
     194             :             if( xSource.is() )
     195             :             {
     196             :                 uno::Reference< io::XActiveDataControl > xSourceControl( xSource, UNO_QUERY );
     197             :                 xSourceControl->start();
     198             :             }
     199             : 
     200             : */
     201             : 
     202             :             // uno::Reference< XDocumentHandler > xHandler( new SvxXMLXTextImportComponent( xText ) );
     203           0 :             uno::Reference< XDocumentHandler > xHandler( new SvxXMLXTextImportComponent( xContext, xText ) );
     204             : 
     205           0 :             xParser->setDocumentHandler( xHandler );
     206             : 
     207           0 :             xml::sax::InputSource aParserInput;
     208           0 :             aParserInput.aInputStream = xInputStream;
     209             : //          aParserInput.sSystemId = aMedium.GetName();
     210           0 :             xParser->parseStream( aParserInput );
     211             :         }
     212             :         while(false);
     213             :     }
     214           0 :     catch( const uno::Exception& )
     215             :     {
     216           0 :     }
     217           0 : }
     218             : 
     219           0 : SvXMLImportContext *SvxXMLXTextImportComponent::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList )
     220             : {
     221             :     SvXMLImportContext* pContext;
     222           0 :     if(XML_NAMESPACE_OFFICE == nPrefix && ( IsXMLToken( rLocalName, XML_DOCUMENT ) || IsXMLToken( rLocalName, XML_DOCUMENT_CONTENT ) ) )
     223             :     {
     224           0 :          pContext = new SvxXMLTextImportContext(*this, nPrefix, rLocalName, xAttrList, mxText );
     225             :     }
     226             :     else
     227             :     {
     228           0 :         pContext = SvXMLImport::CreateContext(nPrefix, rLocalName, xAttrList);
     229             :     }
     230           0 :     return pContext;
     231             : }
     232             : 
     233             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10