LibreOffice Module unoxml (master) 1
processinginstruction.cxx
Go to the documentation of this file.
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
21
22#include <string.h>
23
24#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
25
26using namespace css::uno;
27using namespace css::xml::dom;
28using namespace css::xml::sax;
29
30namespace DOM
31{
33 CDocument const& rDocument, ::osl::Mutex const& rMutex,
34 xmlNodePtr const pNode)
35 : CProcessingInstruction_Base(rDocument, rMutex,
36 NodeType_PROCESSING_INSTRUCTION_NODE, pNode)
37 {
38 }
39
41 const Reference< XDocumentHandler >& i_xHandler) {
42 if (!i_xHandler.is()) throw RuntimeException();
43 Reference< XExtendedDocumentHandler > xExtended(i_xHandler, UNO_QUERY);
44 if (xExtended.is()) {
45 xExtended->processingInstruction(getTarget(), getData());
46 }
47 }
48
52 OUString SAL_CALL
54 {
55 ::osl::MutexGuard const g(m_rMutex);
56
57 if (nullptr == m_aNodePtr) {
58 return OUString();
59 }
60
61 char const*const pContent(
62 reinterpret_cast<char const*>(m_aNodePtr->content));
63 if (nullptr == pContent) {
64 return OUString();
65 }
66 OUString const ret(pContent, strlen(pContent), RTL_TEXTENCODING_UTF8);
67 return ret;
68 }
69
73 OUString SAL_CALL
75 {
76 ::osl::MutexGuard const g(m_rMutex);
77
78 if (nullptr == m_aNodePtr) {
79 return OUString();
80 }
81
82 char const*const pName(
83 reinterpret_cast<char const*>(m_aNodePtr->name));
84 if (nullptr == pName) {
85 return OUString();
86 }
87 OUString const ret(pName, strlen(pName), RTL_TEXTENCODING_UTF8);
88 return ret;
89 }
90
94 void SAL_CALL CProcessingInstruction::setData(OUString const& rData)
95 {
96 ::osl::MutexGuard const g(m_rMutex);
97
98 if (nullptr == m_aNodePtr) {
99 throw RuntimeException();
100 }
101
102 OString const data(
103 OUStringToOString(rData, RTL_TEXTENCODING_UTF8));
104 xmlChar const*const pData(
105 reinterpret_cast<xmlChar const*>(data.getStr()) );
106 xmlFree(m_aNodePtr->content);
107 m_aNodePtr->content = xmlStrdup(pData);
108 }
109
110 OUString SAL_CALL
112 {
113 ::osl::MutexGuard const g(m_rMutex);
114
115 if (nullptr == m_aNodePtr) {
116 return OUString();
117 }
118
119 char const*const pName =
120 reinterpret_cast<char const*>(m_aNodePtr->name);
121 OUString const ret(pName, strlen(pName), RTL_TEXTENCODING_UTF8);
122 return ret;
123 }
124
126 {
127 return getData();
128 }
129
130 void SAL_CALL
131 CProcessingInstruction::setNodeValue(OUString const& rNodeValue)
132 {
133 return setData(rNodeValue);
134 }
135}
136
137/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const char * pName
virtual OUString SAL_CALL getNodeName() override
virtual void SAL_CALL setData(const OUString &data) override
The content of this processing instruction.
virtual OUString SAL_CALL getData() override
The content of this processing instruction.
virtual void saxify(const css::uno::Reference< css::xml::sax::XDocumentHandler > &i_xHandler) override
virtual OUString SAL_CALL getTarget() override
The target of this processing instruction.
virtual void SAL_CALL setNodeValue(OUString const &rNodeValue) override
virtual OUString SAL_CALL getNodeValue() override
CProcessingInstruction(CDocument const &rDocument, ::osl::Mutex const &rMutex, xmlNodePtr const pNode)
::osl::Mutex & m_rMutex
std::unique_ptr< sal_Int32[]> pData
Definition: attr.cxx:38
::cppu::ImplInheritanceHelper< CNode, css::xml::dom::XProcessingInstruction > CProcessingInstruction_Base
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)