LCOV - code coverage report
Current view: top level - unoxml/source/dom - attributesmap.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 82 87 94.3 %
Date: 2012-08-25 Functions: 9 9 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 61 138 44.2 %

           Branch data     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 <attributesmap.hxx>
      21                 :            : 
      22                 :            : #include <string.h>
      23                 :            : 
      24                 :            : #include <element.hxx>
      25                 :            : #include <document.hxx>
      26                 :            : 
      27                 :            : 
      28                 :            : namespace DOM
      29                 :            : {
      30                 :        334 :     CAttributesMap::CAttributesMap(::rtl::Reference<CElement> const& pElement,
      31                 :            :                 ::osl::Mutex & rMutex)
      32                 :            :         : m_pElement(pElement)
      33                 :        334 :         , m_rMutex(rMutex)
      34                 :            :     {
      35                 :        334 :     }
      36                 :            : 
      37                 :            :     /**
      38                 :            :     The number of nodes in this map.
      39                 :            :     */
      40                 :       1025 :     sal_Int32 SAL_CALL CAttributesMap::getLength() throw (RuntimeException)
      41                 :            :     {
      42         [ +  - ]:       1025 :         ::osl::MutexGuard const g(m_rMutex);
      43                 :            : 
      44                 :       1025 :         sal_Int32 count = 0;
      45                 :       1025 :         xmlNodePtr pNode = m_pElement->GetNodePtr();
      46         [ +  - ]:       1025 :         if (pNode != NULL)
      47                 :            :         {
      48                 :       1025 :             xmlAttrPtr cur = pNode->properties;
      49         [ +  + ]:       4487 :             while (cur != NULL)
      50                 :            :             {
      51                 :       3462 :                 count++;
      52                 :       3462 :                 cur = cur->next;
      53                 :            :             }
      54                 :            :         }
      55         [ +  - ]:       1025 :         return count;
      56                 :            :     }
      57                 :            : 
      58                 :            :     /**
      59                 :            :     Retrieves a node specified by local name
      60                 :            :     */
      61                 :            :     Reference< XNode > SAL_CALL
      62                 :         10 :     CAttributesMap::getNamedItem(OUString const& name) throw (RuntimeException)
      63                 :            :     {
      64         [ +  - ]:         10 :         ::osl::MutexGuard const g(m_rMutex);
      65                 :            : 
      66                 :         10 :         Reference< XNode > aNode;
      67                 :         10 :         xmlNodePtr pNode = m_pElement->GetNodePtr();
      68         [ +  - ]:         10 :         if (pNode != NULL)
      69                 :            :         {
      70         [ +  - ]:         10 :             OString o1 = OUStringToOString(name, RTL_TEXTENCODING_UTF8);
      71                 :         10 :             xmlChar* xName = (xmlChar*)o1.getStr();
      72                 :         10 :             xmlAttrPtr cur = pNode->properties;
      73         [ +  - ]:         10 :             while (cur != NULL)
      74                 :            :             {
      75         [ +  - ]:         10 :                 if( strcmp((char*)xName, (char*)cur->name) == 0)
      76                 :            :                 {
      77                 :            :                     aNode = Reference< XNode >(
      78         [ +  - ]:         10 :                             m_pElement->GetOwnerDocument().GetCNode(
      79 [ +  - ][ +  - ]:         10 :                                 reinterpret_cast<xmlNodePtr>(cur)).get() );
         [ +  - ][ +  - ]
      80                 :         10 :                     break;
      81                 :            :                 }
      82                 :          0 :                 cur = cur->next;
      83                 :         10 :             }
      84                 :            :         }
      85         [ +  - ]:         10 :         return aNode;
      86                 :            :     }
      87                 :            : 
      88                 :            :     /**
      89                 :            :     Retrieves a node specified by local name and namespace URI.
      90                 :            :     */
      91                 :            :     Reference< XNode > SAL_CALL
      92                 :          6 :     CAttributesMap::getNamedItemNS(
      93                 :            :             OUString const& namespaceURI, OUString const& localName)
      94                 :            :     throw (RuntimeException)
      95                 :            :     {
      96         [ +  - ]:          6 :         ::osl::MutexGuard const g(m_rMutex);
      97                 :            : 
      98                 :          6 :         Reference< XNode > aNode;
      99                 :          6 :         xmlNodePtr pNode = m_pElement->GetNodePtr();
     100         [ +  - ]:          6 :         if (pNode != NULL)
     101                 :            :         {
     102         [ +  - ]:          6 :             OString o1 = OUStringToOString(localName, RTL_TEXTENCODING_UTF8);
     103                 :          6 :             xmlChar* xName = (xmlChar*)o1.getStr();
     104         [ +  - ]:          6 :             OString o2 = OUStringToOString(namespaceURI, RTL_TEXTENCODING_UTF8);
     105                 :            :             xmlChar const*const xNs =
     106                 :          6 :                 reinterpret_cast<xmlChar const*>(o2.getStr());
     107         [ +  - ]:          6 :             xmlNsPtr const pNs = xmlSearchNsByHref(pNode->doc, pNode, xNs);
     108                 :          6 :             xmlAttrPtr cur = pNode->properties;
     109 [ +  - ][ +  - ]:         10 :             while (cur != NULL && pNs != NULL)
                 [ +  - ]
     110                 :            :             {
     111 [ +  - ][ +  + ]:         10 :                 if( strcmp((char*)xName, (char*)cur->name) == 0 &&
     112                 :            :                     cur->ns == pNs)
     113                 :            :                 {
     114                 :            :                     aNode = Reference< XNode >(
     115         [ +  - ]:          6 :                             m_pElement->GetOwnerDocument().GetCNode(
     116 [ +  - ][ +  - ]:          6 :                                 reinterpret_cast<xmlNodePtr>(cur)).get() );
         [ +  - ][ +  - ]
     117                 :          6 :                     break;
     118                 :            :                 }
     119                 :          4 :                 cur = cur->next;
     120                 :          6 :             }
     121                 :            :         }
     122         [ +  - ]:          6 :         return aNode;
     123                 :            :     }
     124                 :            : 
     125                 :            :     /**
     126                 :            :     Returns the indexth item in the map.
     127                 :            :     */
     128                 :            :     Reference< XNode > SAL_CALL
     129                 :        691 :     CAttributesMap::item(sal_Int32 index) throw (RuntimeException)
     130                 :            :     {
     131         [ +  - ]:        691 :         ::osl::MutexGuard const g(m_rMutex);
     132                 :            : 
     133                 :        691 :         Reference< XNode > aNode;
     134                 :        691 :         xmlNodePtr pNode = m_pElement->GetNodePtr();
     135         [ +  - ]:        691 :         if (pNode != NULL)
     136                 :            :         {
     137                 :        691 :             xmlAttrPtr cur = pNode->properties;
     138                 :        691 :             sal_Int32 count = 0;
     139         [ +  + ]:       2424 :             while (cur != NULL)
     140                 :            :             {
     141         [ +  + ]:       1733 :                 if (count == index)
     142                 :            :                 {
     143                 :            :                     aNode = Reference< XNode >(
     144         [ +  - ]:        689 :                             m_pElement->GetOwnerDocument().GetCNode(
     145 [ +  - ][ +  - ]:        689 :                                 reinterpret_cast<xmlNodePtr>(cur)).get() );
         [ +  - ][ +  - ]
     146                 :        689 :                     break;
     147                 :            :                 }
     148                 :       1044 :                 count++;
     149                 :       1044 :                 cur = cur->next;
     150                 :            :             }
     151                 :            :         }
     152         [ +  - ]:        691 :         return aNode;
     153                 :            :     }
     154                 :            : 
     155                 :            :     /**
     156                 :            :     Removes a node specified by name.
     157                 :            :     */
     158                 :            :     Reference< XNode > SAL_CALL
     159                 :          2 :     CAttributesMap::removeNamedItem(OUString const& name)
     160                 :            :     throw (RuntimeException)
     161                 :            :     {
     162                 :            :         // no MutexGuard needed: m_pElement is const
     163         [ +  - ]:          2 :         Reference< XAttr > const xAttr(m_pElement->getAttributeNode(name));
     164         [ -  + ]:          2 :         if (!xAttr.is()) {
     165                 :            :             throw DOMException(OUString(RTL_CONSTASCII_USTRINGPARAM(
     166                 :            :                     "CAttributesMap::removeNamedItem: no such attribute")),
     167                 :            :                 static_cast<OWeakObject*>(this),
     168 [ #  # ][ #  # ]:          0 :                 DOMExceptionType_NOT_FOUND_ERR);
                 [ #  # ]
     169                 :            :         }
     170                 :            :         Reference< XNode > const xRet(
     171 [ +  - ][ +  - ]:          2 :             m_pElement->removeAttributeNode(xAttr), UNO_QUERY);
     172                 :          2 :         return xRet;
     173                 :            :     }
     174                 :            : 
     175                 :            :     /**
     176                 :            :     // Removes a node specified by local name and namespace URI.
     177                 :            :     */
     178                 :            :     Reference< XNode > SAL_CALL
     179                 :          2 :     CAttributesMap::removeNamedItemNS(
     180                 :            :             OUString const& namespaceURI, OUString const& localName)
     181                 :            :     throw (RuntimeException)
     182                 :            :     {
     183                 :            :         // no MutexGuard needed: m_pElement is const
     184                 :            :         Reference< XAttr > const xAttr(
     185         [ +  - ]:          2 :             m_pElement->getAttributeNodeNS(namespaceURI, localName));
     186         [ -  + ]:          2 :         if (!xAttr.is()) {
     187                 :            :             throw DOMException(OUString(RTL_CONSTASCII_USTRINGPARAM(
     188                 :            :                     "CAttributesMap::removeNamedItemNS: no such attribute")),
     189                 :            :                 static_cast<OWeakObject*>(this),
     190 [ #  # ][ #  # ]:          0 :                 DOMExceptionType_NOT_FOUND_ERR);
                 [ #  # ]
     191                 :            :         }
     192                 :            :         Reference< XNode > const xRet(
     193 [ +  - ][ +  - ]:          2 :             m_pElement->removeAttributeNode(xAttr), UNO_QUERY);
     194                 :          2 :         return xRet;
     195                 :            :     }
     196                 :            : 
     197                 :            :     /**
     198                 :            :     // Adds a node using its nodeName attribute.
     199                 :            :     */
     200                 :            :     Reference< XNode > SAL_CALL
     201                 :          2 :     CAttributesMap::setNamedItem(Reference< XNode > const& xNode)
     202                 :            :     throw (RuntimeException)
     203                 :            :     {
     204         [ +  - ]:          2 :         Reference< XAttr > const xAttr(xNode, UNO_QUERY);
     205         [ -  + ]:          2 :         if (!xNode.is()) {
     206                 :            :             throw DOMException(OUString(RTL_CONSTASCII_USTRINGPARAM(
     207                 :            :                     "CAttributesMap::setNamedItem: XAttr argument expected")),
     208                 :            :                 static_cast<OWeakObject*>(this),
     209 [ #  # ][ #  # ]:          0 :                 DOMExceptionType_HIERARCHY_REQUEST_ERR);
                 [ #  # ]
     210                 :            :         }
     211                 :            :         // no MutexGuard needed: m_pElement is const
     212                 :            :         Reference< XNode > const xRet(
     213 [ +  - ][ +  - ]:          2 :             m_pElement->setAttributeNode(xAttr), UNO_QUERY);
     214                 :          2 :         return xRet;
     215                 :            :     }
     216                 :            : 
     217                 :            :     /**
     218                 :            :     Adds a node using its namespaceURI and localName.
     219                 :            :     */
     220                 :            :     Reference< XNode > SAL_CALL
     221                 :          2 :     CAttributesMap::setNamedItemNS(Reference< XNode > const& xNode)
     222                 :            :     throw (RuntimeException)
     223                 :            :     {
     224         [ +  - ]:          2 :         Reference< XAttr > const xAttr(xNode, UNO_QUERY);
     225         [ -  + ]:          2 :         if (!xNode.is()) {
     226                 :            :             throw DOMException(OUString(RTL_CONSTASCII_USTRINGPARAM(
     227                 :            :                     "CAttributesMap::setNamedItemNS: XAttr argument expected")),
     228                 :            :                 static_cast<OWeakObject*>(this),
     229 [ #  # ][ #  # ]:          0 :                 DOMExceptionType_HIERARCHY_REQUEST_ERR);
                 [ #  # ]
     230                 :            :         }
     231                 :            :         // no MutexGuard needed: m_pElement is const
     232                 :            :         Reference< XNode > const xRet(
     233 [ +  - ][ +  - ]:          2 :             m_pElement->setAttributeNodeNS(xAttr), UNO_QUERY);
     234                 :          2 :         return xRet;
     235                 :            :     }
     236                 :            : }
     237                 :            : 
     238                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10