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

Generated by: LCOV version 1.10