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

Generated by: LCOV version 1.10