Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/unoxml/source/dom/processinginstruction.cxx
Line
Count
Source
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
    CProcessingInstruction::CProcessingInstruction(
33
            CDocument const& rDocument, ::osl::Mutex const& rMutex,
34
            xmlNodePtr const pNode)
35
0
        : CProcessingInstruction_Base(rDocument, rMutex,
36
0
            NodeType_PROCESSING_INSTRUCTION_NODE, pNode)
37
0
    {
38
0
    }
39
40
    void CProcessingInstruction::saxify(
41
0
            const Reference< XDocumentHandler >& i_xHandler) {
42
0
        if (!i_xHandler.is()) throw RuntimeException();
43
0
        Reference< XExtendedDocumentHandler > xExtended(i_xHandler, UNO_QUERY);
44
0
        if (xExtended.is()) {
45
0
            xExtended->processingInstruction(getTarget(), getData());
46
0
        }
47
0
    }
48
49
    /**
50
    The content of this processing instruction.
51
    */
52
    OUString SAL_CALL
53
    CProcessingInstruction::getData()
54
0
    {
55
0
        ::osl::MutexGuard const g(m_rMutex);
56
57
0
        if (nullptr == m_aNodePtr) {
58
0
            return OUString();
59
0
        }
60
61
0
        char const*const pContent(
62
0
                reinterpret_cast<char const*>(m_aNodePtr->content));
63
0
        if (nullptr == pContent) {
64
0
            return OUString();
65
0
        }
66
0
        OUString const ret(pContent, strlen(pContent), RTL_TEXTENCODING_UTF8);
67
0
        return ret;
68
0
    }
69
70
    /**
71
    The target of this processing instruction.
72
    */
73
    OUString SAL_CALL
74
    CProcessingInstruction::getTarget()
75
0
    {
76
0
        ::osl::MutexGuard const g(m_rMutex);
77
78
0
        if (nullptr == m_aNodePtr) {
79
0
            return OUString();
80
0
        }
81
82
0
        char const*const pName(
83
0
                reinterpret_cast<char const*>(m_aNodePtr->name));
84
0
        if (nullptr == pName) {
85
0
            return OUString();
86
0
        }
87
0
        OUString const ret(pName, strlen(pName), RTL_TEXTENCODING_UTF8);
88
0
        return ret;
89
0
    }
90
91
    /**
92
    The content of this processing instruction.
93
    */
94
    void SAL_CALL CProcessingInstruction::setData(OUString const& rData)
95
0
    {
96
0
        ::osl::MutexGuard const g(m_rMutex);
97
98
0
        if (nullptr == m_aNodePtr) {
99
0
            throw RuntimeException();
100
0
        }
101
102
0
        OString const data(
103
0
                OUStringToOString(rData, RTL_TEXTENCODING_UTF8));
104
0
        xmlChar const*const pData(
105
0
                reinterpret_cast<xmlChar const*>(data.getStr()) );
106
0
        xmlFree(m_aNodePtr->content);
107
0
        m_aNodePtr->content = xmlStrdup(pData);
108
0
    }
109
110
    OUString SAL_CALL
111
    CProcessingInstruction::getNodeName()
112
0
    {
113
0
        ::osl::MutexGuard const g(m_rMutex);
114
115
0
        if (nullptr == m_aNodePtr) {
116
0
            return OUString();
117
0
        }
118
119
0
        char const*const pName =
120
0
            reinterpret_cast<char const*>(m_aNodePtr->name);
121
0
        OUString const ret(pName, strlen(pName), RTL_TEXTENCODING_UTF8);
122
0
        return ret;
123
0
    }
124
125
    OUString SAL_CALL CProcessingInstruction::getNodeValue()
126
0
    {
127
0
        return getData();
128
0
    }
129
130
    void SAL_CALL
131
    CProcessingInstruction::setNodeValue(OUString const& rNodeValue)
132
0
    {
133
0
        return setData(rNodeValue);
134
0
    }
135
}
136
137
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */