LCOV - code coverage report
Current view: top level - libreoffice/sax/source/tools - fshelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 76 78 97.4 %
Date: 2012-12-27 Functions: 20 21 95.2 %
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 <sax/fshelper.hxx>
      21             : #include "fastserializer.hxx"
      22             : #include <com/sun/star/xml/sax/XFastTokenHandler.hpp>
      23             : #include <comphelper/processfactory.hxx>
      24             : #include <rtl/ustrbuf.hxx>
      25             : 
      26             : using namespace ::com::sun::star;
      27             : using namespace ::com::sun::star::uno;
      28             : 
      29             : namespace sax_fastparser {
      30             : 
      31         151 : FastSerializerHelper::FastSerializerHelper(const Reference< io::XOutputStream >& xOutputStream, bool bWriteHeader ) :
      32         151 :     mpSerializer(new FastSaxSerializer())
      33             : {
      34         151 :     Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext(), UNO_SET_THROW );
      35         151 :     Reference< lang::XMultiComponentFactory > xFactory( xContext->getServiceManager(), UNO_SET_THROW );
      36         151 :     mxTokenHandler.set( xFactory->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.sax.FastTokenHandler") ), xContext ), UNO_QUERY_THROW );
      37             : 
      38         151 :     mpSerializer->setFastTokenHandler( mxTokenHandler );
      39         151 :     mpSerializer->setOutputStream( xOutputStream );
      40         151 :     if( bWriteHeader )
      41         151 :         mpSerializer->startDocument();
      42         151 : }
      43             : 
      44         302 : FastSerializerHelper::~FastSerializerHelper()
      45             : {
      46         151 :     mpSerializer->endDocument();
      47         151 :     delete mpSerializer;
      48         151 : }
      49             : 
      50        2894 : void FastSerializerHelper::startElementInternal(sal_Int32 elementTokenId, ...)
      51             : {
      52             :     va_list args;
      53        2894 :     va_start( args, elementTokenId );
      54        2894 :     FastAttributeList* pAttrList = new FastAttributeList( mxTokenHandler );
      55             : 
      56        2116 :     while (true)
      57             :     {
      58        5010 :         sal_Int32 nName = va_arg(args, sal_Int32);
      59        5010 :         if (nName == FSEND_internal)
      60             :             break;
      61        2116 :         const char* pValue = va_arg(args, const char*);
      62        2116 :         if (pValue)
      63        2066 :             pAttrList->add(nName, pValue);
      64             :     }
      65             : 
      66        2894 :     const com::sun::star::uno::Reference<com::sun::star::xml::sax::XFastAttributeList> xAttrList(pAttrList);
      67        2894 :     mpSerializer->startFastElement(elementTokenId, xAttrList);
      68        2894 :     va_end( args );
      69        2894 : }
      70             : 
      71        1894 : void FastSerializerHelper::singleElementInternal(sal_Int32 elementTokenId, ...)
      72             : {
      73             :     va_list args;
      74        1894 :     va_start( args, elementTokenId );
      75        1894 :     FastAttributeList* pAttrList = new FastAttributeList( mxTokenHandler );
      76             : 
      77        1938 :     while (true)
      78             :     {
      79        3832 :         sal_Int32 nName = va_arg(args, sal_Int32);
      80        3832 :         if (nName == FSEND_internal)
      81             :             break;
      82        1938 :         const char* pValue = va_arg(args, const char*);
      83        1938 :         if  (pValue)
      84        1938 :             pAttrList->add(nName, pValue);
      85             :     }
      86             : 
      87        1894 :     const com::sun::star::uno::Reference<com::sun::star::xml::sax::XFastAttributeList> xAttrList(pAttrList);
      88        1894 :     mpSerializer->singleFastElement(elementTokenId, xAttrList);
      89        1894 :     va_end( args );
      90        1894 : }
      91             : 
      92        2924 : void FastSerializerHelper::endElement(sal_Int32 elementTokenId)
      93             : {
      94        2924 :     mpSerializer->endFastElement(elementTokenId);
      95        2924 : }
      96             : 
      97          29 : void FastSerializerHelper::startElement(sal_Int32 elementTokenId, XFastAttributeListRef xAttrList)
      98             : {
      99          29 :     mpSerializer->startFastElement(elementTokenId, xAttrList);
     100          29 : }
     101             : 
     102             : 
     103         656 : void FastSerializerHelper::singleElement(sal_Int32 elementTokenId, XFastAttributeListRef xAttrList)
     104             : {
     105         656 :     mpSerializer->singleFastElement(elementTokenId, xAttrList);
     106         656 : }
     107             : 
     108         108 : FastSerializerHelper* FastSerializerHelper::write(const char* value)
     109             : {
     110         108 :     return write(rtl::OUString::createFromAscii(value));
     111             : }
     112             : 
     113         707 : FastSerializerHelper* FastSerializerHelper::write(const rtl::OUString& value)
     114             : {
     115         707 :     mpSerializer->characters(value);
     116         707 :     return this;
     117             : }
     118             : 
     119           8 : FastSerializerHelper* FastSerializerHelper::write(sal_Int32 value)
     120             : {
     121           8 :     return write(::rtl::OUString::valueOf(value));
     122             : }
     123             : 
     124           0 : FastSerializerHelper* FastSerializerHelper::write(sal_Int64 value)
     125             : {
     126           0 :     return write(::rtl::OUString::valueOf(value));
     127             : }
     128             : 
     129         168 : FastSerializerHelper* FastSerializerHelper::write(double value)
     130             : {
     131         168 :     return write(::rtl::OUString::valueOf(value));
     132             : }
     133             : 
     134          20 : FastSerializerHelper* FastSerializerHelper::writeEscaped(const char* value)
     135             : {
     136          20 :     return writeEscaped(::rtl::OUString::createFromAscii(value));
     137             : }
     138             : 
     139         338 : FastSerializerHelper* FastSerializerHelper::writeEscaped(const ::rtl::OUString& value)
     140             : {
     141         338 :     return write(FastSaxSerializer::escapeXml(value));
     142             : }
     143             : 
     144          26 : FastSerializerHelper* FastSerializerHelper::writeId(sal_Int32 tokenId)
     145             : {
     146          26 :     mpSerializer->writeId(tokenId);
     147          26 :     return this;
     148             : }
     149             : 
     150          78 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > FastSerializerHelper::getOutputStream()
     151             : {
     152          78 :     return mpSerializer->getOutputStream();
     153             : }
     154             : 
     155        1191 : void FastSerializerHelper::mark( Sequence< sal_Int32 > aOrder )
     156             : {
     157        1191 :     mpSerializer->mark( aOrder );
     158        1191 : }
     159             : 
     160        1191 : void FastSerializerHelper::mergeTopMarks( MergeMarksEnum eMergeType )
     161             : {
     162        1191 :     mpSerializer->mergeTopMarks( eMergeType );
     163        1191 : }
     164             : 
     165         684 : FastAttributeList * FastSerializerHelper::createAttrList()
     166             : {
     167         684 :     return new FastAttributeList( mxTokenHandler );
     168             : }
     169             : 
     170             : 
     171          78 : }
     172             : 
     173             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10