26#include <osl/diagnose.h>
28#include <com/sun/star/xml/dom/DOMException.hpp>
29#include <com/sun/star/xml/dom/events/XDocumentEvent.hpp>
30#include <com/sun/star/xml/dom/events/XMutationEvent.hpp>
32using namespace css::uno;
33using namespace css::xml::dom;
34using namespace css::xml::dom::events;
40 CDocument const& rDocument, ::osl::Mutex
const& rMutex,
41 NodeType const& reNodeType, xmlNodePtr
const& rpNode)
47 OUString
const& prevValue, OUString
const& newValue)
50 Reference< XMutationEvent > event(docevent->createEvent(
51 "DOMCharacterDataModified"), UNO_QUERY);
52 event->initMutationEvent(
53 "DOMCharacterDataModified",
54 true,
false, Reference< XNode >(),
55 prevValue, newValue, OUString(), AttrChangeType(0) );
57 dispatchSubtreeModified();
65 ::osl::ClearableMutexGuard guard(
m_rMutex);
67 if (m_aNodePtr !=
nullptr)
69 OUString oldValue(
reinterpret_cast<char*
>(m_aNodePtr->content), strlen(
reinterpret_cast<char*
>(m_aNodePtr->content)), RTL_TEXTENCODING_UTF8);
70 xmlNodeAddContent(m_aNodePtr,
reinterpret_cast<const xmlChar*
>(
OUStringToOString(arg, RTL_TEXTENCODING_UTF8).getStr()));
71 OUString newValue(
reinterpret_cast<char*
>(m_aNodePtr->content), strlen(
reinterpret_cast<char*
>(m_aNodePtr->content)), RTL_TEXTENCODING_UTF8);
83 ::osl::ClearableMutexGuard guard(
m_rMutex);
85 if (m_aNodePtr ==
nullptr)
89 std::shared_ptr<xmlChar const>
const pContent(
90 xmlNodeGetContent(m_aNodePtr), xmlFree);
91 std::string_view
aData(
reinterpret_cast<char const*
>(pContent.get()));
92 OUString tmp(OStringToOUString(
aData, RTL_TEXTENCODING_UTF8));
93 if (offset > tmp.getLength() || offset < 0 ||
count < 0) {
95 e.Code = DOMExceptionType_INDEX_SIZE_ERR;
98 if ((offset+
count) > tmp.getLength())
99 count = tmp.getLength() - offset;
101 OUString tmp2 = OUString::Concat(tmp.subView(0, offset)) + tmp.subView(offset+
count);
102 OUString oldValue(
reinterpret_cast<char*
>(m_aNodePtr->content), strlen(
reinterpret_cast<char*
>(m_aNodePtr->content)), RTL_TEXTENCODING_UTF8);
103 xmlNodeSetContent(m_aNodePtr,
reinterpret_cast<const xmlChar*
>(
OUStringToOString(tmp2, RTL_TEXTENCODING_UTF8).getStr()));
104 OUString newValue(
reinterpret_cast<char*
>(m_aNodePtr->content), strlen(
reinterpret_cast<char*
>(m_aNodePtr->content)), RTL_TEXTENCODING_UTF8);
117 ::osl::MutexGuard
const g(
m_rMutex);
120 if (m_aNodePtr !=
nullptr)
122 OSL_ENSURE(m_aNodePtr->content,
"character data node with NULL content, please inform lars.oppermann@sun.com!");
123 if (m_aNodePtr->content !=
nullptr)
125 aData = OUString(
reinterpret_cast<char*
>(m_aNodePtr->content), strlen(
reinterpret_cast<char*
>(m_aNodePtr->content)), RTL_TEXTENCODING_UTF8);
137 ::osl::MutexGuard
const g(
m_rMutex);
140 if (m_aNodePtr !=
nullptr)
142 OUString
aData(
reinterpret_cast<char*
>(m_aNodePtr->content), strlen(
reinterpret_cast<char*
>(m_aNodePtr->content)), RTL_TEXTENCODING_UTF8);
153 ::osl::ClearableMutexGuard guard(
m_rMutex);
155 if (m_aNodePtr ==
nullptr)
159 std::shared_ptr<xmlChar const>
const pContent(
160 xmlNodeGetContent(m_aNodePtr), xmlFree);
161 std::string_view
aData(
reinterpret_cast<char const*
>(pContent.get()));
162 OUString tmp(OStringToOUString(
aData, RTL_TEXTENCODING_UTF8));
163 if (offset > tmp.getLength() || offset < 0) {
165 e.Code = DOMExceptionType_INDEX_SIZE_ERR;
169 OUString tmp2 = tmp.subView(0, offset) +
172 OUString oldValue(
reinterpret_cast<char*
>(m_aNodePtr->content), strlen(
reinterpret_cast<char*
>(m_aNodePtr->content)), RTL_TEXTENCODING_UTF8);
173 xmlNodeSetContent(m_aNodePtr,
reinterpret_cast<const xmlChar*
>(
OUStringToOString(tmp2, RTL_TEXTENCODING_UTF8).getStr()));
174 OUString newValue(
reinterpret_cast<char*
>(m_aNodePtr->content), strlen(
reinterpret_cast<char*
>(m_aNodePtr->content)), RTL_TEXTENCODING_UTF8);
188 ::osl::ClearableMutexGuard guard(
m_rMutex);
190 if (m_aNodePtr ==
nullptr)
194 std::shared_ptr<xmlChar const>
const pContent(
195 xmlNodeGetContent(m_aNodePtr), xmlFree);
196 std::string_view
aData(
reinterpret_cast<char const*
>(pContent.get()));
197 OUString tmp(OStringToOUString(
aData, RTL_TEXTENCODING_UTF8));
198 if (offset > tmp.getLength() || offset < 0 ||
count < 0){
200 e.Code = DOMExceptionType_INDEX_SIZE_ERR;
203 if ((offset+
count) > tmp.getLength())
204 count = tmp.getLength() - offset;
206 OUString tmp2 = tmp.subView(0, offset) +
208 tmp.subView(offset+
count);
209 OUString oldValue(
reinterpret_cast<char*
>(m_aNodePtr->content), strlen(
reinterpret_cast<char*
>(m_aNodePtr->content)), RTL_TEXTENCODING_UTF8);
210 xmlNodeSetContent(m_aNodePtr,
reinterpret_cast<const xmlChar*
>(
OUStringToOString(tmp2, RTL_TEXTENCODING_UTF8).getStr()));
211 OUString newValue(
reinterpret_cast<char*
>(m_aNodePtr->content), strlen(
reinterpret_cast<char*
>(m_aNodePtr->content)), RTL_TEXTENCODING_UTF8);
223 ::osl::ClearableMutexGuard guard(
m_rMutex);
225 if (m_aNodePtr !=
nullptr)
227 OUString oldValue(
reinterpret_cast<char*
>(m_aNodePtr->content), strlen(
reinterpret_cast<char*
>(m_aNodePtr->content)), RTL_TEXTENCODING_UTF8);
228 xmlNodeSetContent(m_aNodePtr,
reinterpret_cast<const xmlChar*
>(
OUStringToOString(data, RTL_TEXTENCODING_UTF8).getStr()));
229 OUString newValue(
reinterpret_cast<char*
>(m_aNodePtr->content), strlen(
reinterpret_cast<char*
>(m_aNodePtr->content)), RTL_TEXTENCODING_UTF8);
241 ::osl::MutexGuard
const g(
m_rMutex);
244 if (m_aNodePtr !=
nullptr)
247 std::shared_ptr<xmlChar const>
const pContent(
248 xmlNodeGetContent(m_aNodePtr), xmlFree);
249 std::string_view
aData(
reinterpret_cast<char const*
>(pContent.get()));
250 OUString tmp(OStringToOUString(
aData, RTL_TEXTENCODING_UTF8));
251 if (offset > tmp.getLength() || offset < 0 ||
count < 0) {
253 e.Code = DOMExceptionType_INDEX_SIZE_ERR;
virtual OUString SAL_CALL getData() override
Return the character data of the node that implements this interface.
CCharacterData(CDocument const &rDocument, ::osl::Mutex const &rMutex, css::xml::dom::NodeType const &reNodeType, xmlNodePtr const &rpNode)
virtual void SAL_CALL replaceData(sal_Int32 offset, sal_Int32 count, const OUString &arg) override
Replace the characters starting at the specified 16-bit unit offset with the specified string.
virtual sal_Int32 SAL_CALL getLength() override
The number of 16-bit units that are available through data and the substringData method below.
virtual void SAL_CALL setData(const OUString &data) override
Set the character data of the node that implements this interface.
void dispatchEvent_Impl(OUString const &prevValue, OUString const &newValue)
virtual void SAL_CALL insertData(sal_Int32 offset, const OUString &arg) override
Insert a string at the specified 16-bit unit offset.
virtual OUString SAL_CALL subStringData(sal_Int32 offset, sal_Int32 count) override
Extracts a range of data from the node.
virtual css::uno::Reference< css::xml::dom::XDocument > SAL_CALL getOwnerDocument() override
virtual void SAL_CALL appendData(const OUString &arg) override
Append the string to the end of the character data of the node.
virtual void SAL_CALL deleteData(sal_Int32 offset, sal_Int32 count) override
Remove a range of 16-bit units from the node.
::cppu::ImplInheritanceHelper< CNode, css::xml::dom::XCharacterData > CCharacterData_Base
constexpr OUStringLiteral aData
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)