LCOV - code coverage report
Current view: top level - libreoffice/dbaccess/source/core/recovery - storagexmlstream.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 48 0.0 %
Date: 2012-12-27 Functions: 0 17 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             : 
      21             : #include "storagexmlstream.hxx"
      22             : 
      23             : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
      24             : #include <com/sun/star/io/XActiveDataSource.hpp>
      25             : #include <com/sun/star/xml/sax/Parser.hpp>
      26             : #include <com/sun/star/xml/sax/Writer.hpp>
      27             : 
      28             : #include <comphelper/componentcontext.hxx>
      29             : #include <cppuhelper/implbase1.hxx>
      30             : #include <rtl/ref.hxx>
      31             : #include <tools/diagnose_ex.h>
      32             : #include <xmloff/attrlist.hxx>
      33             : 
      34             : #include <stack>
      35             : 
      36             : //......................................................................................................................
      37             : namespace dbaccess
      38             : {
      39             : //......................................................................................................................
      40             : 
      41             :     /** === begin UNO using === **/
      42             :     using ::com::sun::star::uno::Reference;
      43             :     using ::com::sun::star::uno::XInterface;
      44             :     using ::com::sun::star::uno::UNO_QUERY;
      45             :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      46             :     using ::com::sun::star::uno::UNO_SET_THROW;
      47             :     using ::com::sun::star::uno::Exception;
      48             :     using ::com::sun::star::uno::RuntimeException;
      49             :     using ::com::sun::star::uno::Any;
      50             :     using ::com::sun::star::uno::makeAny;
      51             :     using ::com::sun::star::uno::Sequence;
      52             :     using ::com::sun::star::uno::Type;
      53             :     using ::com::sun::star::embed::XStorage;
      54             :     using ::com::sun::star::xml::sax::XDocumentHandler;
      55             :     using ::com::sun::star::xml::sax::XAttributeList;
      56             :     using ::com::sun::star::xml::sax::XWriter;
      57             :     using ::com::sun::star::xml::sax::Writer;
      58             :     using ::com::sun::star::io::XStream;
      59             :     using ::com::sun::star::io::XOutputStream;
      60             :     using ::com::sun::star::io::XActiveDataSource;
      61             :     using ::com::sun::star::xml::sax::Parser;
      62             :     using ::com::sun::star::xml::sax::XParser;
      63             :     using ::com::sun::star::xml::sax::InputSource;
      64             :     /** === end UNO using === **/
      65             : 
      66             :     //==================================================================================================================
      67             :     //= StorageXMLOutputStream_Data
      68             :     //==================================================================================================================
      69           0 :     struct StorageXMLOutputStream_Data
      70             :     {
      71             :         Reference< XDocumentHandler >           xHandler;
      72             :         ::std::stack< ::rtl::OUString >         aElements;
      73             :         ::rtl::Reference< SvXMLAttributeList >  xAttributes;
      74             :     };
      75             : 
      76             :     //==================================================================================================================
      77             :     //= StorageXMLOutputStream
      78             :     //==================================================================================================================
      79             :     //------------------------------------------------------------------------------------------------------------------
      80           0 :     StorageXMLOutputStream::StorageXMLOutputStream( const ::comphelper::ComponentContext& i_rContext,
      81             :                                                     const Reference< XStorage >& i_rParentStorage,
      82             :                                                     const ::rtl::OUString& i_rStreamName )
      83             :         :StorageOutputStream( i_rContext, i_rParentStorage, i_rStreamName )
      84           0 :         ,m_pData( new StorageXMLOutputStream_Data )
      85             :     {
      86           0 :         const Reference< XWriter > xSaxWriter = Writer::create( i_rContext.getUNOContext() );
      87           0 :         xSaxWriter->setOutputStream( getOutputStream() );
      88             : 
      89           0 :         m_pData->xHandler.set( xSaxWriter, UNO_QUERY_THROW );
      90           0 :         m_pData->xHandler->startDocument();
      91             : 
      92           0 :         m_pData->xAttributes = new SvXMLAttributeList;
      93           0 :     }
      94             : 
      95             :     //------------------------------------------------------------------------------------------------------------------
      96           0 :     StorageXMLOutputStream::~StorageXMLOutputStream()
      97             :     {
      98           0 :     }
      99             : 
     100             :     //------------------------------------------------------------------------------------------------------------------
     101           0 :     void StorageXMLOutputStream::close()
     102             :     {
     103           0 :         ENSURE_OR_RETURN_VOID( m_pData->xHandler.is(), "illegal document handler" );
     104           0 :         m_pData->xHandler->endDocument();
     105             :         // do not call the base class, it would call closeOutput on the output stream, which is already done by
     106             :         // endDocument
     107             :     }
     108             : 
     109             :     //------------------------------------------------------------------------------------------------------------------
     110           0 :     void StorageXMLOutputStream::addAttribute( const ::rtl::OUString& i_rName, const ::rtl::OUString& i_rValue ) const
     111             :     {
     112           0 :         m_pData->xAttributes->AddAttribute( i_rName, i_rValue );
     113           0 :     }
     114             : 
     115             :     //------------------------------------------------------------------------------------------------------------------
     116           0 :     void StorageXMLOutputStream::startElement( const ::rtl::OUString& i_rElementName ) const
     117             :     {
     118           0 :         ENSURE_OR_RETURN_VOID( m_pData->xHandler.is(), "no document handler" );
     119             : 
     120           0 :         m_pData->xHandler->startElement( i_rElementName, m_pData->xAttributes.get() );
     121           0 :         m_pData->xAttributes = new SvXMLAttributeList;
     122           0 :         m_pData->aElements.push( i_rElementName );
     123             :     }
     124             : 
     125             :     //------------------------------------------------------------------------------------------------------------------
     126           0 :     void StorageXMLOutputStream::endElement() const
     127             :     {
     128           0 :         ENSURE_OR_RETURN_VOID( m_pData->xHandler.is(), "no document handler" );
     129           0 :         ENSURE_OR_RETURN_VOID( !m_pData->aElements.empty(), "no element on the stack" );
     130             : 
     131           0 :         const ::rtl::OUString sElementName( m_pData->aElements.top() );
     132           0 :         m_pData->xHandler->endElement( sElementName );
     133           0 :         m_pData->aElements.pop();
     134             :     }
     135             : 
     136             :     //------------------------------------------------------------------------------------------------------------------
     137           0 :     void StorageXMLOutputStream::ignorableWhitespace( const ::rtl::OUString& i_rWhitespace ) const
     138             :     {
     139           0 :         ENSURE_OR_RETURN_VOID( m_pData->xHandler.is(), "no document handler" );
     140             : 
     141           0 :         m_pData->xHandler->ignorableWhitespace( i_rWhitespace );
     142             :     }
     143             : 
     144             :     //------------------------------------------------------------------------------------------------------------------
     145           0 :     void StorageXMLOutputStream::characters( const ::rtl::OUString& i_rCharacters ) const
     146             :     {
     147           0 :         ENSURE_OR_RETURN_VOID( m_pData->xHandler.is(), "no document handler" );
     148             : 
     149           0 :         m_pData->xHandler->characters( i_rCharacters );
     150             :     }
     151             : 
     152             :     //==================================================================================================================
     153             :     //= StorageXMLInputStream_Data
     154             :     //==================================================================================================================
     155           0 :     struct StorageXMLInputStream_Data
     156             :     {
     157             :         Reference< XParser >    xParser;
     158             :     };
     159             : 
     160             :     //==================================================================================================================
     161             :     //= StorageXMLInputStream
     162             :     //==================================================================================================================
     163             :     //------------------------------------------------------------------------------------------------------------------
     164           0 :     StorageXMLInputStream::StorageXMLInputStream( const ::comphelper::ComponentContext& i_rContext,
     165             :                                                   const Reference< XStorage >& i_rParentStorage,
     166             :                                                   const ::rtl::OUString& i_rStreamName )
     167             :         :StorageInputStream( i_rContext, i_rParentStorage, i_rStreamName )
     168           0 :         ,m_pData( new StorageXMLInputStream_Data )
     169             :     {
     170           0 :         m_pData->xParser.set( Parser::create(i_rContext.getUNOContext()) );
     171           0 :     }
     172             : 
     173             :     //------------------------------------------------------------------------------------------------------------------
     174           0 :     void StorageXMLInputStream::import( const Reference< XDocumentHandler >& i_rHandler )
     175             :     {
     176           0 :         ENSURE_OR_THROW( i_rHandler.is(), "illegal document handler (NULL)" );
     177             : 
     178           0 :         InputSource aInputSource;
     179           0 :         aInputSource.aInputStream = getInputStream();
     180             : 
     181           0 :         m_pData->xParser->setDocumentHandler( i_rHandler );
     182           0 :         m_pData->xParser->parseStream( aInputSource );
     183           0 :     }
     184             : 
     185             :     //------------------------------------------------------------------------------------------------------------------
     186           0 :     StorageXMLInputStream::~StorageXMLInputStream()
     187             :     {
     188           0 :     }
     189             : 
     190             : //......................................................................................................................
     191             : } // namespace dbaccess
     192             : //......................................................................................................................
     193             : 
     194             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10