LCOV - code coverage report
Current view: top level - xmlscript/source/xmldlg_imexp - xmldlg_addfunc.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 21 21 100.0 %
Date: 2014-11-03 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          20 : class InputStreamProvider
      39             :     : public ::cppu::WeakImplHelper1< io::XInputStreamProvider >
      40             : {
      41             :     ByteSequence _bytes;
      42             : 
      43             : public:
      44          10 :     inline InputStreamProvider( ByteSequence const & rBytes )
      45          10 :         : _bytes( rBytes )
      46          10 :         {}
      47             : 
      48             :     // XInputStreamProvider
      49             :     virtual Reference< io::XInputStream > SAL_CALL createInputStream()
      50             :         throw (RuntimeException, std::exception) SAL_OVERRIDE;
      51             : };
      52           6 : Reference< io::XInputStream > InputStreamProvider::createInputStream()
      53             :     throw (RuntimeException, std::exception)
      54             : {
      55           6 :     return ::xmlscript::createInputStream( _bytes );
      56             : }
      57             : 
      58          10 : Reference< io::XInputStreamProvider > SAL_CALL exportDialogModel(
      59             :     Reference< container::XNameContainer > const & xDialogModel,
      60             :     Reference< XComponentContext > const & xContext,
      61             :     Reference< XModel > const & xDocument )
      62             : {
      63          10 :     Reference< xml::sax::XWriter > xWriter = xml::sax::Writer::create(xContext);
      64             : 
      65          20 :     ByteSequence aBytes;
      66          10 :     xWriter->setOutputStream( createOutputStream( &aBytes ) );
      67             : 
      68          20 :     Reference< xml::sax::XExtendedDocumentHandler > xHandler(xWriter, UNO_QUERY_THROW);
      69          10 :     exportDialogModel( xHandler, xDialogModel, xDocument );
      70             : 
      71          20 :     return new InputStreamProvider( aBytes );
      72             : }
      73             : 
      74           6 : void SAL_CALL importDialogModel(
      75             :     Reference< io::XInputStream > const & xInput,
      76             :     Reference< container::XNameContainer > const & xDialogModel,
      77             :     Reference< XComponentContext > const & xContext,
      78             :     Reference< XModel > const & xDocument )
      79             : {
      80           6 :     Reference< xml::sax::XParser > xParser = xml::sax::Parser::create( xContext );
      81             : 
      82             :     // error handler, entity resolver omitted for this helper function
      83           6 :     xParser->setDocumentHandler( importDialogModel( xDialogModel, xContext, xDocument ) );
      84             : 
      85          12 :     xml::sax::InputSource source;
      86           6 :     source.aInputStream = xInput;
      87           6 :     source.sSystemId = "virtual file";
      88             : 
      89          12 :     xParser->parseStream( source );
      90           6 : }
      91             : 
      92             : }
      93             : 
      94             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10