LCOV - code coverage report
Current view: top level - editeng/source/xml - xmltxtimp.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 44 0.0 %
Date: 2015-06-13 12:38:46 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 "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 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 ) SAL_OVERRIDE;
      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( static_cast<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::uno::XComponentContext >& rContext,
     113             :         const uno::Reference< XText > & rText );
     114             : 
     115             :     virtual ~SvxXMLXTextImportComponent() throw ();
     116             : 
     117             : private:
     118             :     const uno::Reference< XText > mxText;
     119             : };
     120             : 
     121             : 
     122             : 
     123           0 : SvxXMLXTextImportComponent::SvxXMLXTextImportComponent(
     124             :     const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext,
     125             :     const uno::Reference< XText > & xText )
     126             : :   SvXMLImport(xContext, ""),
     127           0 :     mxText( xText )
     128             : {
     129           0 :     GetTextImport()->SetCursor( mxText->createTextCursor() );
     130           0 : }
     131             : 
     132           0 : SvxXMLXTextImportComponent::~SvxXMLXTextImportComponent() throw ()
     133             : {
     134           0 : }
     135             : 
     136           0 : void SvxReadXML( EditEngine& rEditEngine, SvStream& rStream, const ESelection& rSel )
     137             : {
     138           0 :     SvxEditEngineSource aEditSource( &rEditEngine );
     139             : 
     140             :     static const SfxItemPropertyMapEntry SvxXMLTextImportComponentPropertyMap[] =
     141             :     {
     142           0 :         SVX_UNOEDIT_CHAR_PROPERTIES,
     143           0 :         SVX_UNOEDIT_FONT_PROPERTIES,
     144             : //      SVX_UNOEDIT_OUTLINER_PROPERTIES,
     145           0 :         SVX_UNOEDIT_PARA_PROPERTIES,
     146             :         { OUString(), 0, css::uno::Type(), 0, 0 }
     147           0 :     };
     148           0 :     static SvxItemPropertySet aSvxXMLTextImportComponentPropertySet( SvxXMLTextImportComponentPropertyMap, EditEngine::GetGlobalItemPool() );
     149             : 
     150           0 :     uno::Reference<text::XText > xParent;
     151           0 :     SvxUnoText* pUnoText = new SvxUnoText( &aEditSource, &aSvxXMLTextImportComponentPropertySet, xParent );
     152           0 :     pUnoText->SetSelection( rSel );
     153           0 :     uno::Reference<text::XText > xText( pUnoText );
     154             : 
     155             :     try
     156             :     {
     157             :         do
     158             :         {
     159           0 :             uno::Reference<uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
     160             : 
     161           0 :             uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create( xContext );
     162             : 
     163           0 :             uno::Reference<io::XInputStream> xInputStream = new utl::OInputStreamWrapper( rStream );
     164             : 
     165             : /* testcode
     166             :             const OUString aURL( "file:///e:/test.xml" );
     167             :             SfxMedium aMedium( aURL, StreamMode::READ | STREAM_NOCREATE, sal_True );
     168             :             uno::Reference<io::XOutputStream> xOut( new utl::OOutputStreamWrapper( *aMedium.GetOutStream() ) );
     169             : 
     170             :             aMedium.GetInStream()->Seek( 0 );
     171             :             uno::Reference< io::XActiveDataSource > xSource( aMedium.GetDataSource() );
     172             : 
     173             :             if( !xSource.is() )
     174             :             {
     175             :                 OSL_FAIL( "got no data source from medium" );
     176             :                 break;
     177             :             }
     178             : 
     179             :             uno::Reference< XInterface > xPipe( Pipe::create(comphelper::getComponentContext(xServiceFactory)), UNO_QUERY );
     180             : 
     181             :             // connect pipe's output stream to the data source
     182             :             xSource->setOutputStream( uno::Reference< io::XOutputStream >::query( xPipe ) );
     183             : 
     184             :             xml::sax::InputSource aParserInput;
     185             :             aParserInput.aInputStream = uno::Reference< io::XInputStream >::query( xPipe );
     186             :             aParserInput.sSystemId = aMedium.GetName();
     187             : 
     188             : 
     189             :             if( xSource.is() )
     190             :             {
     191             :                 uno::Reference< io::XActiveDataControl > xSourceControl( xSource, UNO_QUERY );
     192             :                 xSourceControl->start();
     193             :             }
     194             : 
     195             : */
     196             : 
     197             :             // uno::Reference< XDocumentHandler > xHandler( new SvxXMLXTextImportComponent( xText ) );
     198           0 :             uno::Reference< XDocumentHandler > xHandler( new SvxXMLXTextImportComponent( xContext, xText ) );
     199             : 
     200           0 :             xParser->setDocumentHandler( xHandler );
     201             : 
     202           0 :             xml::sax::InputSource aParserInput;
     203           0 :             aParserInput.aInputStream = xInputStream;
     204             : //          aParserInput.sSystemId = aMedium.GetName();
     205           0 :             xParser->parseStream( aParserInput );
     206             :         }
     207             :         while(false);
     208             :     }
     209           0 :     catch( const uno::Exception& )
     210             :     {
     211           0 :     }
     212           0 : }
     213             : 
     214             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11