Kaydet (Commit) aa85497d authored tarafından Michael Stahl's avatar Michael Stahl

xmlfix3: unoxml: fix CChildList: member pointer does not keep document alive

üst cb42fe10
......@@ -25,11 +25,17 @@
*
************************************************************************/
#include "childlist.hxx"
#include <childlist.hxx>
#include <libxml/tree.h>
#include <node.hxx>
namespace DOM
{
CChildList::CChildList(CNode const& rBase)
: m_pNode(rBase.m_aNodePtr)
CChildList::CChildList(::rtl::Reference<CNode> const& pBase)
: m_pNode(pBase)
{
}
......@@ -41,7 +47,10 @@ namespace DOM
sal_Int32 length = 0;
if (m_pNode != NULL)
{
xmlNodePtr cur = m_pNode->children;
xmlNodePtr cur = m_pNode->m_aNodePtr;
if (0 != cur) {
cur = cur->children;
}
while (cur != NULL)
{
length++;
......@@ -54,21 +63,23 @@ namespace DOM
/**
Returns the indexth item in the collection.
*/
Reference< XNode > SAL_CALL CChildList::item(sal_Int32 index) throw (RuntimeException)
Reference< XNode > SAL_CALL CChildList::item(sal_Int32 index)
throw (RuntimeException)
{
Reference< XNode >aNode;
if (m_pNode != NULL)
{
xmlNodePtr cur = m_pNode->children;
xmlNodePtr cur = m_pNode->m_aNodePtr;
if (0 != cur) {
cur = cur->children;
}
while (cur != NULL)
{
if (index-- == 0) {
aNode = Reference< XNode >(CNode::getCNode(cur).get());
break;
return Reference< XNode >(CNode::getCNode(cur).get());
}
cur = cur->next;
}
}
return aNode;
return 0;
}
}
......@@ -25,18 +25,18 @@
*
************************************************************************/
#ifndef _CHILDLIST_HXX
#define _CHILDLIST_HXX
#ifndef DOM_CHILDLIST_HXX
#define DOM_CHILDLIST_HXX
#include <map>
#include <sal/types.h>
#include <cppuhelper/implbase1.hxx>
#include <rtl/ref.hxx>
#include <com/sun/star/uno/Reference.h>
#include <com/sun/star/uno/Exception.hpp>
#include <com/sun/star/xml/dom/XNode.hpp>
#include <com/sun/star/xml/dom/XNodeList.hpp>
#include "node.hxx"
#include "libxml/tree.h"
#include <cppuhelper/implbase1.hxx>
using ::rtl::OUString;
using namespace com::sun::star::uno;
......@@ -44,12 +44,17 @@ using namespace com::sun::star::xml::dom;
namespace DOM
{
class CChildList : public cppu::WeakImplHelper1< XNodeList >
class CNode;
class CChildList
: public cppu::WeakImplHelper1< XNodeList >
{
private:
const xmlNodePtr m_pNode;
::rtl::Reference<CNode> const m_pNode;
public:
CChildList(CNode const& rBase);
CChildList(::rtl::Reference<CNode> const& pBase);
/**
The number of nodes in the list.
*/
......@@ -57,7 +62,8 @@ namespace DOM
/**
Returns the indexth item in the collection.
*/
virtual Reference< XNode > SAL_CALL item(sal_Int32 index) throw (RuntimeException);
virtual Reference< XNode > SAL_CALL item(sal_Int32 index)
throw (RuntimeException);
};
}
......
......@@ -562,9 +562,7 @@ namespace DOM
if (0 == m_aNodePtr) {
return 0;
}
Reference< XNodeList > const xNodeList(
new CChildList(*CNode::getCNode(m_aNodePtr)));
// XXX check for errors?
Reference< XNodeList > const xNodeList(new CChildList(this));
return xNodeList;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment