LCOV - code coverage report
Current view: top level - writerfilter/source/dmapper - TagLogger.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 18 5.6 %
Date: 2015-06-13 12:38:46 Functions: 2 6 33.3 %
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 <libxml/xmlstring.h>
      21             : #include <string.h>
      22             : #include "TagLogger.hxx"
      23             : #include <ooxml/QNameToString.hxx>
      24             : #include <unordered_map>
      25             : 
      26             : using namespace css;
      27             : 
      28             : namespace writerfilter
      29             : {
      30           0 :     TagLogger::TagLogger()
      31           0 :         : pWriter( nullptr ), pName( "DOMAINMAPPER" )
      32             :     {
      33           0 :     }
      34             : 
      35           0 :     TagLogger::~TagLogger()
      36             :     {
      37           0 :         pWriter = nullptr;
      38           0 :         pName = nullptr;
      39           0 :     }
      40             : 
      41             : #ifdef DEBUG_WRITERFILTER
      42             :     void TagLogger::setFileName( const std::string & filename )
      43             :     {
      44             :         if ( pWriter )
      45             :             endDocument();
      46             : 
      47             :         std::string fileName;
      48             :         char * temp = getenv("TAGLOGGERTMP");
      49             : 
      50             :         if (temp != nullptr)
      51             :             fileName += temp;
      52             :         else
      53             :             fileName += "/tmp";
      54             : 
      55             :         std::string sPrefix = filename;
      56             :         size_t nLastSlash = sPrefix.find_last_of('/');
      57             :         size_t nLastBackslash = sPrefix.find_last_of('\\');
      58             :         size_t nCutPos = nLastSlash;
      59             :         if (nLastBackslash < nCutPos)
      60             :             nCutPos = nLastBackslash;
      61             :         if (nCutPos < sPrefix.size())
      62             :             sPrefix = sPrefix.substr(nCutPos + 1);
      63             : 
      64             :         fileName += "/";
      65             :         fileName += sPrefix;
      66             :         fileName += ".";
      67             :         fileName += pName;
      68             :         fileName += ".xml";
      69             : 
      70             :         pWriter = xmlNewTextWriterFilename( fileName.c_str(), 0 );
      71             :         xmlTextWriterSetIndent( pWriter, 4 );
      72             :     }
      73             : 
      74             :     void TagLogger::startDocument()
      75             :     {
      76             :         if (!pWriter)
      77             :             return;
      78             :         xmlTextWriterStartDocument( pWriter, nullptr, nullptr, nullptr );
      79             :         xmlTextWriterStartElement( pWriter, BAD_CAST( "root" ) );
      80             :     }
      81             : 
      82             :     void TagLogger::endDocument()
      83             :     {
      84             :         if (!pWriter)
      85             :             return;
      86             :         xmlTextWriterEndDocument( pWriter );
      87             :         xmlFreeTextWriter( pWriter );
      88             :         pWriter = nullptr;
      89             :     }
      90             : 
      91             : #endif
      92             : 
      93             : struct TheTagLogger:
      94             :     public rtl::Static<TagLogger, TheTagLogger>
      95             : {};
      96             : 
      97           0 :     TagLogger& TagLogger::getInstance()
      98             :     {
      99           0 :         return TheTagLogger::get();
     100             :     }
     101             : 
     102             : #ifdef DEBUG_WRITERFILTER
     103             :     void TagLogger::element(const std::string & name)
     104             :     {
     105             :         startElement(name);
     106             :         endElement();
     107             :     }
     108             : 
     109             :     void TagLogger::unoPropertySet(uno::Reference<beans::XPropertySet> rPropSet)
     110             :     {
     111             :         uno::Reference<beans::XPropertySetInfo> xPropSetInfo(rPropSet->getPropertySetInfo());
     112             :         uno::Sequence<beans::Property> aProps(xPropSetInfo->getProperties());
     113             : 
     114             :         startElement( "unoPropertySet" );
     115             : 
     116             :         for (int i = 0; i < aProps.getLength(); ++i)
     117             :         {
     118             :             startElement( "property" );
     119             :             OUString sName(aProps[i].Name);
     120             : 
     121             :             attribute( "name", sName );
     122             :             try
     123             :             {
     124             :                 attribute( "value", rPropSet->getPropertyValue( sName ) );
     125             :             }
     126             :             catch (const uno::Exception &)
     127             :             {
     128             :                 startElement( "exception" );
     129             : 
     130             :                 chars(std::string("getPropertyValue(\""));
     131             :                 chars(sName);
     132             :                 chars(std::string("\")"));
     133             : 
     134             :                 endElement( );
     135             :             }
     136             :             endElement( );
     137             :         }
     138             :         endElement( );
     139             :     }
     140             : 
     141             :     void TagLogger::startElement(const std::string & name)
     142             :     {
     143             :         if (!pWriter)
     144             :             return;
     145             :         xmlChar* xmlName = xmlCharStrdup( name.c_str() );
     146             :         xmlTextWriterStartElement( pWriter, xmlName );
     147             :         xmlFree( xmlName );
     148             :     }
     149             : #endif
     150             : 
     151           0 :     void TagLogger::attribute(const std::string & name, const std::string & value)
     152             :     {
     153           0 :         if (!pWriter)
     154           0 :             return;
     155           0 :         xmlChar* xmlName = xmlCharStrdup( name.c_str() );
     156           0 :         xmlChar* xmlValue = xmlCharStrdup( value.c_str() );
     157           0 :         xmlTextWriterWriteAttribute( pWriter, xmlName, xmlValue );
     158             : 
     159           0 :         xmlFree( xmlValue );
     160           0 :         xmlFree( xmlName );
     161             :     }
     162             : 
     163             : #ifdef DEBUG_WRITERFILTER
     164             :     void TagLogger::attribute(const std::string & name, const OUString & value)
     165             :     {
     166             :         attribute( name, OUStringToOString( value, RTL_TEXTENCODING_ASCII_US ).getStr() );
     167             :     }
     168             : 
     169             :     void TagLogger::attribute(const std::string & name, sal_uInt32 value)
     170             :     {
     171             :         if (!pWriter)
     172             :             return;
     173             :         xmlChar* xmlName = xmlCharStrdup( name.c_str() );
     174             :         xmlTextWriterWriteFormatAttribute( pWriter, xmlName,
     175             :                "%" SAL_PRIuUINT32, value );
     176             :         xmlFree( xmlName );
     177             :     }
     178             : 
     179             :     void TagLogger::attribute(const std::string & name, const uno::Any aAny)
     180             :     {
     181             :         if (!pWriter)
     182             :             return;
     183             : 
     184             :         sal_Int32 nInt = 0;
     185             :         float nFloat = 0.0;
     186             :         OUString aStr;
     187             : 
     188             :         xmlChar* xmlName = xmlCharStrdup( name.c_str() );
     189             :         if ( aAny >>= nInt )
     190             :         {
     191             :             xmlTextWriterWriteFormatAttribute( pWriter, xmlName,
     192             :                    "%" SAL_PRIdINT32, nInt );
     193             :         }
     194             :         else if ( aAny >>= nFloat )
     195             :         {
     196             :             xmlTextWriterWriteFormatAttribute( pWriter, xmlName,
     197             :                    "%f", nFloat );
     198             :         }
     199             :         else if ( aAny >>= aStr )
     200             :         {
     201             :             attribute( name, aStr );
     202             :         }
     203             :         xmlFree( xmlName );
     204             :     }
     205             : 
     206             :     void TagLogger::chars(const std::string & rChars)
     207             :     {
     208             :         if (!pWriter)
     209             :             return;
     210             :         xmlChar* xmlChars = xmlCharStrdup( rChars.c_str() );
     211             :         xmlTextWriterWriteString( pWriter, xmlChars );
     212             :         xmlFree( xmlChars );
     213             :     }
     214             : 
     215             :     void TagLogger::chars(const OUString & rChars)
     216             :     {
     217             :         chars(OUStringToOString(rChars, RTL_TEXTENCODING_ASCII_US).getStr());
     218             :     }
     219             : 
     220             :     void TagLogger::endElement()
     221             :     {
     222             :         if (!pWriter)
     223             :             return;
     224             :         xmlTextWriterEndElement( pWriter );
     225             :     }
     226             : 
     227             : #endif
     228             : 
     229          72 : }
     230             : 
     231             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11