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

Generated by: LCOV version 1.10