LCOV - code coverage report
Current view: top level - xmlscript/source/xml_helper - xml_element.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 27 36 75.0 %
Date: 2015-06-13 12:38:46 Functions: 8 11 72.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 <xmlscript/xml_helper.hxx>
      21             : #include <osl/diagnose.h>
      22             : 
      23             : using namespace com::sun::star;
      24             : using namespace com::sun::star::uno;
      25             : 
      26             : namespace xmlscript
      27             : {
      28             : 
      29         227 : void XMLElement::addAttribute( OUString const & rAttrName, OUString const & rValue )
      30             : {
      31         227 :     _attrNames.push_back( rAttrName );
      32         227 :     _attrValues.push_back( rValue );
      33         227 : }
      34             : 
      35          16 : void XMLElement::addSubElement( Reference< xml::sax::XAttributeList > const & xElem )
      36             : {
      37          16 :     _subElems.push_back( xElem );
      38          16 : }
      39             : 
      40           0 : Reference< xml::sax::XAttributeList > XMLElement::getSubElement( sal_Int32 nIndex )
      41             : {
      42           0 :     return _subElems[ (size_t)nIndex ];
      43             : }
      44             : 
      45          42 : void XMLElement::dumpSubElements( Reference< xml::sax::XDocumentHandler > const & xOut )
      46             : {
      47          58 :     for ( size_t nPos = 0; nPos < _subElems.size(); ++nPos )
      48             :     {
      49          16 :         XMLElement * pElem = static_cast< XMLElement * >( _subElems[ nPos ].get() );
      50          16 :         pElem->dump( xOut );
      51             :     }
      52          42 : }
      53             : 
      54          32 : void XMLElement::dump( Reference< xml::sax::XDocumentHandler > const & xOut )
      55             : {
      56          32 :     xOut->ignorableWhitespace( OUString() );
      57          32 :     xOut->startElement( _name, static_cast< xml::sax::XAttributeList * >( this ) );
      58             :     // write sub elements
      59          32 :     dumpSubElements( xOut );
      60          32 :     xOut->ignorableWhitespace( OUString() );
      61          32 :     xOut->endElement( _name );
      62          32 : }
      63             : 
      64             : // XAttributeList
      65          68 : sal_Int16 XMLElement::getLength()
      66             :     throw (RuntimeException, std::exception)
      67             : {
      68          68 :     return static_cast<sal_Int16>(_attrNames.size());
      69             : }
      70             : 
      71         245 : OUString XMLElement::getNameByIndex( sal_Int16 nPos )
      72             :     throw (RuntimeException, std::exception)
      73             : {
      74             :     OSL_ASSERT( (size_t)nPos < _attrNames.size() );
      75         245 :     return _attrNames[ nPos ];
      76             : }
      77             : 
      78           8 : OUString XMLElement::getTypeByIndex( sal_Int16 nPos )
      79             :     throw (RuntimeException, std::exception)
      80             : {
      81             :     OSL_ASSERT( (size_t)nPos < _attrNames.size() );
      82             :     static_cast<void>(nPos);
      83             :     // xxx todo
      84           8 :     return OUString();
      85             : }
      86             : 
      87           0 : OUString XMLElement::getTypeByName( OUString const & /*rName*/ )
      88             :     throw (RuntimeException, std::exception)
      89             : {
      90             :     // xxx todo
      91           0 :     return OUString();
      92             : }
      93             : 
      94         243 : OUString XMLElement::getValueByIndex( sal_Int16 nPos )
      95             :     throw (RuntimeException, std::exception)
      96             : {
      97             :     OSL_ASSERT( (size_t)nPos < _attrNames.size() );
      98         243 :     return _attrValues[ nPos ];
      99             : }
     100             : 
     101           0 : OUString XMLElement::getValueByName( OUString const & rName )
     102             :     throw (RuntimeException, std::exception)
     103             : {
     104           0 :     for ( size_t nPos = 0; nPos < _attrNames.size(); ++nPos )
     105             :     {
     106           0 :         if (_attrNames[ nPos ] == rName)
     107             :         {
     108           0 :             return _attrValues[ nPos ];
     109             :         }
     110             :     }
     111           0 :     return OUString();
     112             : }
     113             : 
     114             : }
     115             : 
     116             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11