LCOV - code coverage report
Current view: top level - libreoffice/sax/source/tools - fshelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 71 73 97.3 %
Date: 2012-12-17 Functions: 18 19 94.7 %
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         302 : FastSerializerHelper::FastSerializerHelper(const Reference< io::XOutputStream >& xOutputStream, bool bWriteHeader ) :
      32         302 :     mpSerializer(new FastSaxSerializer())
      33             : {
      34         302 :     Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext(), UNO_SET_THROW );
      35         302 :     Reference< lang::XMultiComponentFactory > xFactory( xContext->getServiceManager(), UNO_SET_THROW );
      36         302 :     mxTokenHandler.set( xFactory->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.sax.FastTokenHandler") ), xContext ), UNO_QUERY_THROW );
      37             : 
      38         302 :     mpSerializer->setFastTokenHandler( mxTokenHandler );
      39         302 :     mpSerializer->setOutputStream( xOutputStream );
      40         302 :     if( bWriteHeader )
      41         302 :         mpSerializer->startDocument();
      42         302 : }
      43             : 
      44         604 : FastSerializerHelper::~FastSerializerHelper()
      45             : {
      46         302 :     mpSerializer->endDocument();
      47         302 :     delete mpSerializer;
      48         302 : }
      49             : 
      50        5792 : void FastSerializerHelper::startElementV(sal_Int32 elementTokenId, va_list args)
      51             : {
      52        5792 :     FastAttributeList* pAttrList = new FastAttributeList( mxTokenHandler );
      53             : 
      54        4250 :     while (true)
      55             :     {
      56       10042 :         sal_Int32 nName = va_arg(args, sal_Int32);
      57       10042 :         if (nName == FSEND)
      58             :             break;
      59        4250 :         const char* pValue = va_arg(args, const char*);
      60        4250 :         if (pValue)
      61        4150 :             pAttrList->add(nName, pValue);
      62             :     }
      63             : 
      64        5792 :     const com::sun::star::uno::Reference<com::sun::star::xml::sax::XFastAttributeList> xAttrList(pAttrList);
      65        5792 :     mpSerializer->startFastElement(elementTokenId, xAttrList);
      66        5792 : }
      67             : 
      68        3794 : void FastSerializerHelper::singleElementV(sal_Int32 elementTokenId, va_list args)
      69             : {
      70        3794 :     FastAttributeList* pAttrList = new FastAttributeList( mxTokenHandler );
      71             : 
      72        3882 :     while (true)
      73             :     {
      74        7676 :         sal_Int32 nName = va_arg(args, sal_Int32);
      75        7676 :         if (nName == FSEND)
      76             :             break;
      77        3882 :         const char* pValue = va_arg(args, const char*);
      78        3882 :         if  (pValue)
      79        3882 :             pAttrList->add(nName, pValue);
      80             :     }
      81             : 
      82        3794 :     const com::sun::star::uno::Reference<com::sun::star::xml::sax::XFastAttributeList> xAttrList(pAttrList);
      83        3794 :     mpSerializer->singleFastElement(elementTokenId, xAttrList);
      84        3794 : }
      85             : 
      86        5852 : void FastSerializerHelper::endElement(sal_Int32 elementTokenId)
      87             : {
      88        5852 :     mpSerializer->endFastElement(elementTokenId);
      89        5852 : }
      90             : 
      91          58 : void FastSerializerHelper::startElementV(sal_Int32 elementTokenId, XFastAttributeListRef xAttrList)
      92             : {
      93          58 :     mpSerializer->startFastElement(elementTokenId, xAttrList);
      94          58 : }
      95             : 
      96             : 
      97        1312 : void FastSerializerHelper::singleElementV(sal_Int32 elementTokenId, XFastAttributeListRef xAttrList)
      98             : {
      99        1312 :     mpSerializer->singleFastElement(elementTokenId, xAttrList);
     100        1312 : }
     101             : 
     102         216 : FastSerializerHelper* FastSerializerHelper::write(const char* value)
     103             : {
     104         216 :     return write(rtl::OUString::createFromAscii(value));
     105             : }
     106             : 
     107        1414 : FastSerializerHelper* FastSerializerHelper::write(const rtl::OUString& value)
     108             : {
     109        1414 :     mpSerializer->characters(value);
     110        1414 :     return this;
     111             : }
     112             : 
     113          16 : FastSerializerHelper* FastSerializerHelper::write(sal_Int32 value)
     114             : {
     115          16 :     return write(::rtl::OUString::valueOf(value));
     116             : }
     117             : 
     118           0 : FastSerializerHelper* FastSerializerHelper::write(sal_Int64 value)
     119             : {
     120           0 :     return write(::rtl::OUString::valueOf(value));
     121             : }
     122             : 
     123         336 : FastSerializerHelper* FastSerializerHelper::write(double value)
     124             : {
     125         336 :     return write(::rtl::OUString::valueOf(value));
     126             : }
     127             : 
     128          40 : FastSerializerHelper* FastSerializerHelper::writeEscaped(const char* value)
     129             : {
     130          40 :     return writeEscaped(::rtl::OUString::createFromAscii(value));
     131             : }
     132             : 
     133         676 : FastSerializerHelper* FastSerializerHelper::writeEscaped(const ::rtl::OUString& value)
     134             : {
     135         676 :     return write(FastSaxSerializer::escapeXml(value));
     136             : }
     137             : 
     138          52 : FastSerializerHelper* FastSerializerHelper::writeId(sal_Int32 tokenId)
     139             : {
     140          52 :     mpSerializer->writeId(tokenId);
     141          52 :     return this;
     142             : }
     143             : 
     144         156 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > FastSerializerHelper::getOutputStream()
     145             : {
     146         156 :     return mpSerializer->getOutputStream();
     147             : }
     148             : 
     149        2382 : void FastSerializerHelper::mark( Sequence< sal_Int32 > aOrder )
     150             : {
     151        2382 :     mpSerializer->mark( aOrder );
     152        2382 : }
     153             : 
     154        2382 : void FastSerializerHelper::mergeTopMarks( MergeMarksEnum eMergeType )
     155             : {
     156        2382 :     mpSerializer->mergeTopMarks( eMergeType );
     157        2382 : }
     158             : 
     159        1368 : FastAttributeList * FastSerializerHelper::createAttrList()
     160             : {
     161        1368 :     return new FastAttributeList( mxTokenHandler );
     162             : }
     163             : 
     164             : 
     165             : }
     166             : 
     167             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10