summaryrefslogtreecommitdiff
path: root/unoxml/source/dom/characterdata.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'unoxml/source/dom/characterdata.cxx')
-rw-r--r--unoxml/source/dom/characterdata.cxx77
1 files changed, 57 insertions, 20 deletions
diff --git a/unoxml/source/dom/characterdata.cxx b/unoxml/source/dom/characterdata.cxx
index 8a8407678272..6cd3d9f2c1d5 100644
--- a/unoxml/source/dom/characterdata.cxx
+++ b/unoxml/source/dom/characterdata.cxx
@@ -25,18 +25,29 @@
*
************************************************************************/
+#include <characterdata.hxx>
+
+#include <string.h>
+
+#include <boost/shared_ptr.hpp>
+
#include <com/sun/star/xml/dom/events/XDocumentEvent.hpp>
-#include "characterdata.hxx"
+
#include "../events/mutationevent.hxx"
-#include <string.h>
+
namespace DOM
{
- CCharacterData::CCharacterData()
- {}
+ CCharacterData::CCharacterData(
+ CDocument const& rDocument, ::osl::Mutex const& rMutex,
+ NodeType const& reNodeType, xmlNodePtr const& rpNode)
+ : CCharacterData_Base(rDocument, rMutex, reNodeType, rpNode)
+ {
+ }
- void CCharacterData::_dispatchEvent(const OUString& prevValue, const OUString& newValue)
+ void CCharacterData::dispatchEvent_Impl(
+ OUString const& prevValue, OUString const& newValue)
{
Reference< XDocumentEvent > docevent(getOwnerDocument(), UNO_QUERY);
Reference< XMutationEvent > event(docevent->createEvent(
@@ -49,23 +60,22 @@ namespace DOM
dispatchSubtreeModified();
}
- void CCharacterData::init_characterdata(const xmlNodePtr aNodePtr)
- {
- init_node(aNodePtr);
- }
-
/**
Append the string to the end of the character data of the node.
*/
void SAL_CALL CCharacterData::appendData(const OUString& arg)
throw (RuntimeException, DOMException)
{
+ ::osl::ClearableMutexGuard guard(m_rMutex);
+
if (m_aNodePtr != NULL)
{
OUString oldValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
xmlNodeAddContent(m_aNodePtr, (const xmlChar*)(OUStringToOString(arg, RTL_TEXTENCODING_UTF8).getStr()));
OUString newValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
- _dispatchEvent(oldValue, newValue);
+
+ guard.clear(); // release mutex before calling event handlers
+ dispatchEvent_Impl(oldValue, newValue);
}
}
@@ -75,10 +85,14 @@ namespace DOM
void SAL_CALL CCharacterData::deleteData(sal_Int32 offset, sal_Int32 count)
throw (RuntimeException, DOMException)
{
+ ::osl::ClearableMutexGuard guard(m_rMutex);
+
if (m_aNodePtr != NULL)
{
// get current data
- OString aData((const sal_Char*)xmlNodeGetContent(m_aNodePtr));
+ ::boost::shared_ptr<xmlChar const> const pContent(
+ xmlNodeGetContent(m_aNodePtr), xmlFree);
+ OString aData(reinterpret_cast<sal_Char const*>(pContent.get()));
OUString tmp(aData, aData.getLength(), RTL_TEXTENCODING_UTF8);
if (offset > tmp.getLength() || offset < 0 || count < 0) {
DOMException e;
@@ -93,8 +107,9 @@ namespace DOM
OUString oldValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
xmlNodeSetContent(m_aNodePtr, (const xmlChar*)(OUStringToOString(tmp2, RTL_TEXTENCODING_UTF8).getStr()));
OUString newValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
- _dispatchEvent(oldValue, newValue);
+ guard.clear(); // release mutex before calling event handlers
+ dispatchEvent_Impl(oldValue, newValue);
}
}
@@ -104,6 +119,8 @@ namespace DOM
*/
OUString SAL_CALL CCharacterData::getData() throw (RuntimeException)
{
+ ::osl::MutexGuard const g(m_rMutex);
+
OUString aData;
if (m_aNodePtr != NULL)
{
@@ -120,8 +137,10 @@ namespace DOM
The number of 16-bit units that are available through data and the
substringData method below.
*/
- sal_Int32 CCharacterData::getLength() throw (RuntimeException)
+ sal_Int32 SAL_CALL CCharacterData::getLength() throw (RuntimeException)
{
+ ::osl::MutexGuard const g(m_rMutex);
+
sal_Int32 length = 0;
if (m_aNodePtr != NULL)
{
@@ -137,10 +156,14 @@ namespace DOM
void SAL_CALL CCharacterData::insertData(sal_Int32 offset, const OUString& arg)
throw (RuntimeException, DOMException)
{
+ ::osl::ClearableMutexGuard guard(m_rMutex);
+
if (m_aNodePtr != NULL)
{
// get current data
- OString aData((const sal_Char*)xmlNodeGetContent(m_aNodePtr));
+ ::boost::shared_ptr<xmlChar const> const pContent(
+ xmlNodeGetContent(m_aNodePtr), xmlFree);
+ OString aData(reinterpret_cast<sal_Char const*>(pContent.get()));
OUString tmp(aData, aData.getLength(), RTL_TEXTENCODING_UTF8);
if (offset > tmp.getLength() || offset < 0) {
DOMException e;
@@ -154,8 +177,9 @@ namespace DOM
OUString oldValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
xmlNodeSetContent(m_aNodePtr, (const xmlChar*)(OUStringToOString(tmp2, RTL_TEXTENCODING_UTF8).getStr()));
OUString newValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
- _dispatchEvent(oldValue, newValue);
+ guard.clear(); // release mutex before calling event handlers
+ dispatchEvent_Impl(oldValue, newValue);
}
}
@@ -167,10 +191,14 @@ namespace DOM
void SAL_CALL CCharacterData::replaceData(sal_Int32 offset, sal_Int32 count, const OUString& arg)
throw (RuntimeException, DOMException)
{
+ ::osl::ClearableMutexGuard guard(m_rMutex);
+
if (m_aNodePtr != NULL)
{
// get current data
- OString aData((const sal_Char*)xmlNodeGetContent(m_aNodePtr));
+ ::boost::shared_ptr<xmlChar const> const pContent(
+ xmlNodeGetContent(m_aNodePtr), xmlFree);
+ OString aData(reinterpret_cast<sal_Char const*>(pContent.get()));
OUString tmp(aData, aData.getLength(), RTL_TEXTENCODING_UTF8);
if (offset > tmp.getLength() || offset < 0 || count < 0){
DOMException e;
@@ -186,7 +214,9 @@ namespace DOM
OUString oldValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
xmlNodeSetContent(m_aNodePtr, (const xmlChar*)(OUStringToOString(tmp2, RTL_TEXTENCODING_UTF8).getStr()));
OUString newValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
- _dispatchEvent(oldValue, newValue);
+
+ guard.clear(); // release mutex before calling event handlers
+ dispatchEvent_Impl(oldValue, newValue);
}
}
@@ -196,13 +226,16 @@ namespace DOM
void SAL_CALL CCharacterData::setData(const OUString& data)
throw (RuntimeException, DOMException)
{
+ ::osl::ClearableMutexGuard guard(m_rMutex);
+
if (m_aNodePtr != NULL)
{
OUString oldValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
xmlNodeSetContent(m_aNodePtr, (const xmlChar*)(OUStringToOString(data, RTL_TEXTENCODING_UTF8).getStr()));
OUString newValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
- _dispatchEvent(oldValue, newValue);
+ guard.clear(); // release mutex before calling event handlers
+ dispatchEvent_Impl(oldValue, newValue);
}
}
@@ -212,11 +245,15 @@ namespace DOM
OUString SAL_CALL CCharacterData::subStringData(sal_Int32 offset, sal_Int32 count)
throw (RuntimeException, DOMException)
{
+ ::osl::MutexGuard const g(m_rMutex);
+
OUString aStr;
if (m_aNodePtr != NULL)
{
// get current data
- OString aData((const sal_Char*)xmlNodeGetContent(m_aNodePtr));
+ ::boost::shared_ptr<xmlChar const> const pContent(
+ xmlNodeGetContent(m_aNodePtr), xmlFree);
+ OString aData(reinterpret_cast<sal_Char const*>(pContent.get()));
OUString tmp(aData, aData.getLength(), RTL_TEXTENCODING_UTF8);
if (offset > tmp.getLength() || offset < 0 || count < 0) {
DOMException e;