LCOV - code coverage report
Current view: top level - unoxml/source/dom - processinginstruction.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 43 48 89.6 %
Date: 2015-06-13 12:38:46 Functions: 8 8 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 <processinginstruction.hxx>
      21             : 
      22             : #include <string.h>
      23             : 
      24             : #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
      25             : 
      26             : using namespace css::uno;
      27             : using namespace css::xml::dom;
      28             : using namespace css::xml::sax;
      29             : 
      30             : namespace DOM
      31             : {
      32          16 :     CProcessingInstruction::CProcessingInstruction(
      33             :             CDocument const& rDocument, ::osl::Mutex const& rMutex,
      34             :             xmlNodePtr const pNode)
      35             :         : CProcessingInstruction_Base(rDocument, rMutex,
      36          16 :             NodeType_PROCESSING_INSTRUCTION_NODE, pNode)
      37             :     {
      38          16 :     }
      39             : 
      40          12 :     void CProcessingInstruction::saxify(
      41             :             const Reference< XDocumentHandler >& i_xHandler) {
      42          12 :         if (!i_xHandler.is()) throw RuntimeException();
      43          12 :         Reference< XExtendedDocumentHandler > xExtended(i_xHandler, UNO_QUERY);
      44          12 :         if (xExtended.is()) {
      45          12 :             xExtended->processingInstruction(getTarget(), getData());
      46          12 :         }
      47          12 :     }
      48             : 
      49             :     /**
      50             :     The content of this processing instruction.
      51             :     */
      52             :     OUString SAL_CALL
      53          16 :     CProcessingInstruction::getData() throw (RuntimeException, std::exception)
      54             :     {
      55          16 :         ::osl::MutexGuard const g(m_rMutex);
      56             : 
      57          16 :         if (0 == m_aNodePtr) {
      58           0 :             return OUString();
      59             :         }
      60             : 
      61             :         char const*const pContent(
      62          16 :                 reinterpret_cast<char const*>(m_aNodePtr->content));
      63          16 :         if (0 == pContent) {
      64          12 :             return OUString();
      65             :         }
      66           8 :         OUString const ret(pContent, strlen(pContent), RTL_TEXTENCODING_UTF8);
      67          20 :         return ret;
      68             :     }
      69             : 
      70             :     /**
      71             :     The target of this processing instruction.
      72             :     */
      73             :     OUString SAL_CALL
      74          13 :     CProcessingInstruction::getTarget() throw (RuntimeException, std::exception)
      75             :     {
      76          13 :         ::osl::MutexGuard const g(m_rMutex);
      77             : 
      78          13 :         if (0 == m_aNodePtr) {
      79           0 :             return OUString();
      80             :         }
      81             : 
      82             :         char const*const pName(
      83          13 :                 reinterpret_cast<char const*>(m_aNodePtr->name));
      84          13 :         if (0 == pName) {
      85           0 :             return OUString();
      86             :         }
      87          26 :         OUString const ret(pName, strlen(pName), RTL_TEXTENCODING_UTF8);
      88          26 :         return ret;
      89             :     }
      90             : 
      91             :     /**
      92             :     The content of this processing instruction.
      93             :     */
      94           2 :     void SAL_CALL CProcessingInstruction::setData(OUString const& rData)
      95             :         throw (RuntimeException, DOMException, std::exception)
      96             :     {
      97           2 :         ::osl::MutexGuard const g(m_rMutex);
      98             : 
      99           2 :         if (0 == m_aNodePtr) {
     100           0 :             throw RuntimeException();
     101             :         }
     102             : 
     103             :         OString const data(
     104           4 :                 OUStringToOString(rData, RTL_TEXTENCODING_UTF8));
     105             :         xmlChar const*const pData(
     106           2 :                 reinterpret_cast<xmlChar const*>(data.getStr()) );
     107           2 :         xmlFree(m_aNodePtr->content);
     108           4 :         m_aNodePtr->content = xmlStrdup(pData);
     109           2 :     }
     110             : 
     111             :     OUString SAL_CALL
     112           1 :     CProcessingInstruction::getNodeName() throw (RuntimeException, std::exception)
     113             :     {
     114           1 :         ::osl::MutexGuard const g(m_rMutex);
     115             : 
     116           1 :         if (0 == m_aNodePtr) {
     117           0 :             return OUString();
     118             :         }
     119             : 
     120             :         sal_Char const*const pName =
     121           1 :             reinterpret_cast<sal_Char const*>(m_aNodePtr->name);
     122           2 :         OUString const ret(pName, strlen(pName), RTL_TEXTENCODING_UTF8);
     123           2 :         return ret;
     124             :     }
     125             : 
     126           2 :     OUString SAL_CALL CProcessingInstruction::getNodeValue()
     127             :         throw (RuntimeException, std::exception)
     128             :     {
     129           2 :         return getData();
     130             :     }
     131             : 
     132             :     void SAL_CALL
     133           1 :     CProcessingInstruction::setNodeValue(OUString const& rNodeValue)
     134             :         throw (RuntimeException, DOMException, std::exception)
     135             :     {
     136           1 :         return setData(rNodeValue);
     137             :     }
     138             : }
     139             : 
     140             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11