LCOV - code coverage report
Current view: top level - sdext/source/pdfimport/sax - emitcontext.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 28 0.0 %
Date: 2014-04-14 Functions: 0 7 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 "saxemitter.hxx"
      22             : #include "emitcontext.hxx"
      23             : #include "saxattrlist.hxx"
      24             : 
      25             : #include <rtl/strbuf.hxx>
      26             : #include <cppuhelper/exc_hlp.hxx>
      27             : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
      28             : 
      29             : #if OSL_DEBUG_LEVEL > 1
      30             : #include <osl/file.hxx>
      31             : static osl::File* pStream = NULL;
      32             : static int nIndent = 0;
      33             : #endif
      34             : 
      35             : using namespace com::sun::star;
      36             : 
      37             : namespace pdfi
      38             : {
      39             : 
      40           0 : SaxEmitter::SaxEmitter( const uno::Reference< xml::sax::XDocumentHandler >& xDocHdl ) :
      41           0 :     m_xDocHdl( xDocHdl )
      42             : {
      43             :     OSL_PRECOND(m_xDocHdl.is(), "SaxEmitter(): invalid doc handler");
      44             :     try
      45             :     {
      46           0 :         m_xDocHdl->startDocument();
      47             :     }
      48           0 :     catch( xml::sax::SAXException& )
      49             :     {
      50             :     }
      51             : #if OSL_DEBUG_LEVEL > 1
      52             :     static const char* pDir = getenv( "DBG_PDFIMPORT_DIR" );
      53             :     if( pDir )
      54             :     {
      55             :         OUString aStr( OStringToOUString( pDir, RTL_TEXTENCODING_UTF8 ) );
      56             :         OUString aFileURL;
      57             :         osl_getFileURLFromSystemPath( aStr.pData, &aFileURL.pData );
      58             :         OUStringBuffer aBuf( 256 );
      59             :         aBuf.append( aFileURL );
      60             :         aBuf.appendAscii( "/pdfimport.xml" );
      61             :         pStream = new osl::File( aBuf.makeStringAndClear() );
      62             :         if( pStream->open( osl_File_OpenFlag_Write | osl_File_OpenFlag_Create ) )
      63             :         {
      64             :             pStream->open( osl_File_OpenFlag_Write );
      65             :             pStream->setSize( 0 );
      66             :         }
      67             :     }
      68             :     else
      69             :         pStream = 0;
      70             : #endif
      71           0 : }
      72             : 
      73           0 : SaxEmitter::~SaxEmitter()
      74             : {
      75             :     try
      76             :     {
      77           0 :         m_xDocHdl->endDocument();
      78             :     }
      79           0 :     catch( xml::sax::SAXException& )
      80             :     {
      81             :     }
      82             : #if OSL_DEBUG_LEVEL > 1
      83             :     if( pStream )
      84             :     {
      85             :         pStream->close();
      86             :         delete pStream;
      87             :         pStream = 0;
      88             :     }
      89             : #endif
      90           0 : }
      91             : 
      92           0 : void SaxEmitter::beginTag( const char* pTag, const PropertyMap& rProperties )
      93             : {
      94           0 :     OUString aTag = OUString::createFromAscii( pTag );
      95             :     uno::Reference< xml::sax::XAttributeList > xAttr(
      96           0 :         new SaxAttrList( rProperties ) );
      97             :     try
      98             :     {
      99           0 :         m_xDocHdl->startElement( aTag, xAttr );
     100             :     }
     101           0 :     catch( xml::sax::SAXException& )
     102             :     {
     103           0 :     }
     104             : #if OSL_DEBUG_LEVEL > 1
     105             :     if( pStream )
     106             :     {
     107             :         sal_uInt64 nWritten = 0;
     108             :         for( int i = 0; i < nIndent; i++ )
     109             :             pStream->write( "    ", 4, nWritten );
     110             : 
     111             :         OStringBuffer aBuf( 1024 );
     112             :         aBuf.append( '<' );
     113             :         aBuf.append( pTag );
     114             :         for( PropertyMap::const_iterator it = rProperties.begin(); it != rProperties.end(); ++it )
     115             :         {
     116             :             aBuf.append( ' ' );
     117             :             aBuf.append( OUStringToOString( it->first, RTL_TEXTENCODING_UTF8 ) );
     118             :             aBuf.append( "=\"" );
     119             :             aBuf.append( OUStringToOString( it->second, RTL_TEXTENCODING_UTF8 ) );
     120             :             aBuf.append( "\"" );
     121             :         }
     122             :         aBuf.append( ">\n" );
     123             :         pStream->write( aBuf.getStr(), aBuf.getLength(), nWritten );
     124             :         nIndent++;
     125             :     }
     126             : #endif
     127           0 : }
     128             : 
     129           0 : void SaxEmitter::write( const OUString& rText )
     130             : {
     131             :     try
     132             :     {
     133           0 :         m_xDocHdl->characters( rText );
     134             :     }
     135           0 :     catch( xml::sax::SAXException& )
     136             :     {
     137             :     }
     138             : #if OSL_DEBUG_LEVEL > 1
     139             :     if( pStream )
     140             :     {
     141             :         OString aStr( OUStringToOString( rText, RTL_TEXTENCODING_UTF8 ) );
     142             :         sal_uInt64 nWritten = 0;
     143             :         pStream->write( aStr.getStr(), aStr.getLength(), nWritten );
     144             :     }
     145             : #endif
     146           0 : }
     147             : 
     148           0 : void SaxEmitter::endTag( const char* pTag )
     149             : {
     150           0 :     OUString aTag = OUString::createFromAscii( pTag );
     151             :     try
     152             :     {
     153           0 :         m_xDocHdl->endElement( aTag );
     154             :     }
     155           0 :     catch( xml::sax::SAXException& )
     156             :     {
     157           0 :     }
     158             : #if OSL_DEBUG_LEVEL > 1
     159             :     if( pStream )
     160             :     {
     161             :         sal_uInt64 nWritten = 0;
     162             :         for( int i = 0; i < nIndent; i++ )
     163             :             pStream->write( "    ", 4, nWritten );
     164             : 
     165             :         OStringBuffer aBuf( 1024 );
     166             :         aBuf.append( "</" );
     167             :         aBuf.append( pTag );
     168             :         aBuf.append( ">\n" );
     169             :         pStream->write( aBuf.getStr(), aBuf.getLength(), nWritten );
     170             :         nIndent--;
     171             :     }
     172             : #endif
     173           0 : }
     174             : 
     175           0 : XmlEmitterSharedPtr createSaxEmitter( const uno::Reference< xml::sax::XDocumentHandler >& xDocHdl )
     176             : {
     177           0 :     return XmlEmitterSharedPtr(new SaxEmitter(xDocHdl));
     178             : }
     179             : 
     180             : }
     181             : 
     182             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10