LCOV - code coverage report
Current view: top level - xmlscript/source/xmldlg_imexp - xmldlg_addfunc.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 21 21 100.0 %
Date: 2015-06-13 12:38:46 Functions: 6 6 100.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/lang/XMultiServiceFactory.hpp>
      21             : #include <com/sun/star/io/XActiveDataSource.hpp>
      22             : #include <com/sun/star/xml/sax/Parser.hpp>
      23             : #include <com/sun/star/xml/sax/Writer.hpp>
      24             : 
      25             : #include <comphelper/processfactory.hxx>
      26             : #include <cppuhelper/implbase1.hxx>
      27             : #include <xmlscript/xml_helper.hxx>
      28             : #include <xmlscript/xmldlg_imexp.hxx>
      29             : 
      30             : using namespace ::rtl;
      31             : using namespace ::com::sun::star;
      32             : using namespace ::com::sun::star::uno;
      33             : using namespace ::com::sun::star::frame;
      34             : 
      35             : namespace xmlscript
      36             : {
      37             : 
      38          10 : class InputStreamProvider
      39             :     : public ::cppu::WeakImplHelper1< io::XInputStreamProvider >
      40             : {
      41             :     ByteSequence _bytes;
      42             : 
      43             : public:
      44           5 :     explicit InputStreamProvider( ByteSequence const & rBytes )
      45           5 :         : _bytes( rBytes )
      46             :     {
      47           5 :     }
      48             : 
      49             :     // XInputStreamProvider
      50             :     virtual Reference< io::XInputStream > SAL_CALL createInputStream()
      51             :         throw (RuntimeException, std::exception) SAL_OVERRIDE;
      52             : };
      53           3 : Reference< io::XInputStream > InputStreamProvider::createInputStream()
      54             :     throw (RuntimeException, std::exception)
      55             : {
      56           3 :     return ::xmlscript::createInputStream( _bytes );
      57             : }
      58             : 
      59           5 : Reference< io::XInputStreamProvider > SAL_CALL exportDialogModel(
      60             :     Reference< container::XNameContainer > const & xDialogModel,
      61             :     Reference< XComponentContext > const & xContext,
      62             :     Reference< XModel > const & xDocument )
      63             : {
      64           5 :     Reference< xml::sax::XWriter > xWriter = xml::sax::Writer::create(xContext);
      65             : 
      66          10 :     ByteSequence aBytes;
      67           5 :     xWriter->setOutputStream( createOutputStream( &aBytes ) );
      68             : 
      69          10 :     Reference< xml::sax::XExtendedDocumentHandler > xHandler(xWriter, UNO_QUERY_THROW);
      70           5 :     exportDialogModel( xHandler, xDialogModel, xDocument );
      71             : 
      72          10 :     return new InputStreamProvider( aBytes );
      73             : }
      74             : 
      75           3 : void SAL_CALL importDialogModel(
      76             :     Reference< io::XInputStream > const & xInput,
      77             :     Reference< container::XNameContainer > const & xDialogModel,
      78             :     Reference< XComponentContext > const & xContext,
      79             :     Reference< XModel > const & xDocument )
      80             : {
      81           3 :     Reference< xml::sax::XParser > xParser = xml::sax::Parser::create( xContext );
      82             : 
      83             :     // error handler, entity resolver omitted for this helper function
      84           3 :     xParser->setDocumentHandler( importDialogModel( xDialogModel, xContext, xDocument ) );
      85             : 
      86           6 :     xml::sax::InputSource source;
      87           3 :     source.aInputStream = xInput;
      88           3 :     source.sSystemId = "virtual file";
      89             : 
      90           6 :     xParser->parseStream( source );
      91           3 : }
      92             : 
      93             : }
      94             : 
      95             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11