LCOV - code coverage report
Current view: top level - libreoffice/sw/source/core/docnode - nodedump.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 94 0.0 %
Date: 2012-12-17 Functions: 0 12 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             :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       4             :  *
       5             :  * The contents of this file are subject to the Mozilla Public License Version
       6             :  * 1.1 (the "License"); you may not use this file except in compliance with
       7             :  * the License or as specified alternatively below. You may obtain a copy of
       8             :  * the License at http://www.mozilla.org/MPL/
       9             :  *
      10             :  * Software distributed under the License is distributed on an "AS IS" basis,
      11             :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12             :  * for the specific language governing rights and limitations under the
      13             :  * License.
      14             :  *
      15             :  * Major Contributor(s):
      16             :  * [ Copyright (C) 2011 Lubos Lunak <l.lunak@suse.cz> (initial developer) ]
      17             :  *
      18             :  * All Rights Reserved.
      19             :  *
      20             :  * For minor contributions see the git repository.
      21             :  *
      22             :  * Alternatively, the contents of this file may be used under the terms of
      23             :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      24             :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      25             :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      26             :  * instead of those above.
      27             :  */
      28             : 
      29             : #include "doc.hxx"
      30             : #include "ndtxt.hxx"
      31             : 
      32             : #include <libxml/encoding.h>
      33             : #include <libxml/xmlwriter.h>
      34             : 
      35             : namespace
      36             : {
      37             : 
      38             : // Small helper class to ensure that we write to nodes.xml if nothing
      39             : // has been explicitly specified.
      40             : // Always use at the beginning of dumpAsXml().
      41             : // Also, there are some functions to save typing.
      42             : class WriterHelper
      43             : {
      44             : public:
      45             :     WriterHelper( xmlTextWriterPtr );
      46             :     ~WriterHelper();
      47             :     operator xmlTextWriterPtr();
      48             :     xmlTextWriterPtr operator->();
      49             :     void startElement( const char* element );
      50             :     void endElement();
      51             :     void writeFormatAttribute( const char* attribute, const char* format, ... )
      52             : #ifdef LIBXML_ATTR_FORMAT
      53             :         LIBXML_ATTR_FORMAT(3,4)
      54             : #endif
      55             :         ;
      56             : private:
      57             :     xmlTextWriterPtr writer;
      58             :     bool owns;
      59             : };
      60             : 
      61           0 : WriterHelper::WriterHelper( xmlTextWriterPtr w )
      62             :     : writer( w )
      63           0 :     , owns( false )
      64             : {
      65           0 :     if( writer == NULL )
      66             :     {
      67           0 :         writer = xmlNewTextWriterFilename( "nodes.xml", 0 );
      68           0 :         xmlTextWriterStartDocument( writer, NULL, NULL, NULL );
      69           0 :         owns = true;
      70             :     }
      71           0 : }
      72             : 
      73           0 : WriterHelper::~WriterHelper()
      74             : {
      75           0 :     if( owns )
      76             :     {
      77           0 :         xmlTextWriterEndDocument( writer );
      78           0 :         xmlFreeTextWriter( writer );
      79             :     }
      80           0 : }
      81             : 
      82           0 : WriterHelper::operator xmlTextWriterPtr()
      83             : {
      84           0 :     return writer;
      85             : }
      86             : 
      87           0 : xmlTextWriterPtr WriterHelper::operator->()
      88             : {
      89           0 :     return writer;
      90             : }
      91             : 
      92           0 : void WriterHelper::startElement( const char* element )
      93             : {
      94           0 :     xmlTextWriterStartElement( writer, BAD_CAST( element ));
      95           0 : }
      96             : 
      97           0 : void WriterHelper::endElement()
      98             : {
      99           0 :     xmlTextWriterEndElement( writer );
     100           0 : }
     101             : 
     102           0 : void WriterHelper::writeFormatAttribute( const char* attribute, const char* format, ... )
     103             : {
     104             :     va_list va;
     105           0 :     va_start( va, format );
     106           0 :     xmlTextWriterWriteVFormatAttribute( writer, BAD_CAST( attribute ), format, va );
     107           0 :     va_end( va );
     108           0 : }
     109             : 
     110             : }
     111             : 
     112           0 : void SwDoc::dumpAsXml( xmlTextWriterPtr w )
     113             : {
     114           0 :     WriterHelper writer( w );
     115           0 :     writer.startElement( "doc" );
     116           0 :     writer.writeFormatAttribute( "ptr", "%p", this );
     117           0 :     m_pNodes->dumpAsXml( writer );
     118           0 :     writer.endElement();
     119           0 : }
     120             : 
     121           0 : void SwNodes::dumpAsXml( xmlTextWriterPtr w )
     122             : {
     123           0 :     WriterHelper writer( w );
     124           0 :     writer.startElement( "swnodes" );
     125           0 :     writer.writeFormatAttribute( "ptr", "%p", this );
     126           0 :     for( unsigned int i = 0; i < Count(); ++i )
     127             :     {
     128           0 :         ( *this )[ i ]->dumpAsXml( writer );
     129             :     }
     130           0 :     writer.endElement();
     131           0 : }
     132             : 
     133           0 : void SwNode::dumpAsXml( xmlTextWriterPtr w )
     134             : {
     135           0 :     WriterHelper writer( w );
     136           0 :     const char* name = "???";
     137           0 :     switch( GetNodeType())
     138             :     {
     139             :         case ND_ENDNODE:
     140           0 :             name = "end";
     141           0 :             break;
     142             :         case ND_STARTNODE:
     143             :         case ND_TEXTNODE:
     144           0 :             abort(); // overriden
     145             :         case ND_TABLENODE:
     146           0 :             name = "table";
     147           0 :             break;
     148             :         case ND_GRFNODE:
     149           0 :             name = "grf";
     150           0 :             break;
     151             :         case ND_OLENODE:
     152           0 :             name = "ole";
     153           0 :             break;
     154             :     }
     155           0 :     writer.startElement( name );
     156           0 :     writer.writeFormatAttribute( "ptr", "%p", this );
     157           0 :     writer.writeFormatAttribute( "index", "%lu", GetIndex() );
     158           0 :     writer.endElement();
     159           0 :     if( GetNodeType() == ND_ENDNODE )
     160           0 :         writer.endElement(); // end start node
     161           0 : }
     162             : 
     163           0 : void SwStartNode::dumpAsXml( xmlTextWriterPtr w )
     164             : {
     165           0 :     WriterHelper writer( w );
     166           0 :     const char* name = "???";
     167           0 :     switch( GetStartNodeType())
     168             :     {
     169             :         case SwNormalStartNode:
     170           0 :             name = "start";
     171           0 :             break;
     172             :         case SwTableBoxStartNode:
     173           0 :             name = "tablebox";
     174           0 :             break;
     175             :         case SwFlyStartNode:
     176           0 :             name = "fly";
     177           0 :             break;
     178             :         case SwFootnoteStartNode:
     179           0 :             name = "footnote";
     180           0 :             break;
     181             :         case SwHeaderStartNode:
     182           0 :             name = "header";
     183           0 :             break;
     184             :         case SwFooterStartNode:
     185           0 :             name = "footer";
     186           0 :             break;
     187             :     }
     188           0 :     writer.startElement( name );
     189           0 :     writer.writeFormatAttribute( "ptr", "%p", this );
     190           0 :     writer.writeFormatAttribute( "index", "%lu", GetIndex() );
     191             :     // writer.endElement(); - it is a start node, so don't end, will make xml better nested
     192           0 : }
     193             : 
     194           0 : void SwTxtNode::dumpAsXml( xmlTextWriterPtr w )
     195             : {
     196           0 :     WriterHelper writer( w );
     197           0 :     writer.startElement( "text" );
     198           0 :     writer.writeFormatAttribute( "ptr", "%p", this );
     199           0 :     writer.writeFormatAttribute( "index", "%lu", GetIndex() );
     200           0 :     rtl::OUString txt = GetTxt();
     201           0 :     for( int i = 0; i < 32; ++i )
     202           0 :         txt = txt.replace( i, '*' );
     203           0 :     rtl::OString txt8 = ::rtl::OUStringToOString( txt, RTL_TEXTENCODING_UTF8 );
     204           0 :     xmlTextWriterWriteString( writer, BAD_CAST( txt8.getStr()));
     205           0 :     writer.endElement();
     206           0 : }
     207             : 
     208             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10