summaryrefslogtreecommitdiff
path: root/unoxml/source/xpath
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@suse.cz>2011-03-23 16:59:02 +0100
committerJan Holesovsky <kendy@suse.cz>2011-03-23 16:59:02 +0100
commit90087ebb40a6cf12c9464da4e4ea7cc8b5f24bc5 (patch)
treebb3d6cb01c18dd12ae7ec77234cd43a6092d5a4b /unoxml/source/xpath
parent5d7d145d411c8974ceb12ac08759e7ccf3bb9b27 (diff)
parent82c070266d0440348c61c710e0caa89ae1e74b1b (diff)
Merge commit 'ooo/DEV300_m103'
Conflicts: binfilter/bf_xmloff/source/forms/formcellbinding.hxx binfilter/bf_xmloff/source/forms/xmloff_elementexport.cxx binfilter/bf_xmloff/source/forms/xmloff_formcellbinding.cxx filter/source/xsltfilter/makefile.mk unoxml/source/dom/characterdata.cxx unoxml/source/dom/document.cxx unoxml/source/dom/documentbuilder.cxx unoxml/source/dom/element.cxx unoxml/source/dom/elementlist.cxx unoxml/source/dom/node.cxx unoxml/source/dom/node.hxx unoxml/source/dom/text.cxx unoxml/source/events/event.cxx unoxml/source/events/event.hxx unoxml/source/events/eventdispatcher.cxx unoxml/source/events/eventdispatcher.hxx unoxml/source/events/mouseevent.cxx unoxml/source/events/mouseevent.hxx unoxml/source/events/mutationevent.cxx unoxml/source/events/mutationevent.hxx unoxml/source/events/uievent.cxx unoxml/source/events/uievent.hxx unoxml/source/xpath/nodelist.cxx unoxml/source/xpath/nodelist.hxx unoxml/source/xpath/xpathobject.cxx
Diffstat (limited to 'unoxml/source/xpath')
-rw-r--r--unoxml/source/xpath/makefile.mk52
-rw-r--r--unoxml/source/xpath/nodelist.cxx30
-rw-r--r--unoxml/source/xpath/nodelist.hxx30
-rw-r--r--unoxml/source/xpath/xpathapi.cxx133
-rw-r--r--unoxml/source/xpath/xpathapi.hxx30
-rw-r--r--unoxml/source/xpath/xpathobject.cxx112
-rw-r--r--unoxml/source/xpath/xpathobject.hxx39
7 files changed, 252 insertions, 174 deletions
diff --git a/unoxml/source/xpath/makefile.mk b/unoxml/source/xpath/makefile.mk
deleted file mode 100644
index 7b1ccdae742b..000000000000
--- a/unoxml/source/xpath/makefile.mk
+++ /dev/null
@@ -1,52 +0,0 @@
-#*************************************************************************
-#
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
-# Copyright 2000, 2010 Oracle and/or its affiliates.
-#
-# OpenOffice.org - a multi-platform office productivity suite
-#
-# This file is part of OpenOffice.org.
-#
-# OpenOffice.org is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Lesser General Public License version 3
-# only, as published by the Free Software Foundation.
-#
-# OpenOffice.org is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Lesser General Public License version 3 for more details
-# (a copy is included in the LICENSE file that accompanied this code).
-#
-# You should have received a copy of the GNU Lesser General Public License
-# version 3 along with OpenOffice.org. If not, see
-# <http://www.openoffice.org/license.html>
-# for a copy of the LGPLv3 License.
-#
-#*************************************************************************
-
-PRJ=../..
-
-PRJNAME=unoxml
-TARGET=xpathimpl
-ENABLE_EXCEPTIONS=TRUE
-
-# --- Settings -----------------------------------------------------
-
-.INCLUDE : settings.mk
-
-.IF "$(SYSTEM_LIBXML)" == "YES"
-CFLAGS+=-DSYSTEM_LIBXML $(LIBXML_CFLAGS)
-.ENDIF
-
-# --- Files --------------------------------------------------------
-
-SLOFILES = \
- $(SLO)$/xpathobject.obj \
- $(SLO)$/nodelist.obj \
- $(SLO)$/xpathapi.obj
-
-# --- Targets ------------------------------------------------------
-
-.INCLUDE : target.mk
-
diff --git a/unoxml/source/xpath/nodelist.cxx b/unoxml/source/xpath/nodelist.cxx
index 49a1484939d2..6d9d4b78528f 100644
--- a/unoxml/source/xpath/nodelist.cxx
+++ b/unoxml/source/xpath/nodelist.cxx
@@ -26,13 +26,18 @@
*
************************************************************************/
-#include "nodelist.hxx"
-#include "../dom/node.hxx"
+#include <nodelist.hxx>
+
+#include "../dom/document.hxx"
namespace XPath
{
- CNodeList::CNodeList(const Reference< XNode >& rContextNode, boost::shared_ptr<xmlXPathObject>& rxpathObj)
- : m_xContextNode(rContextNode)
+ CNodeList::CNodeList(
+ ::rtl::Reference<DOM::CDocument> const& pDocument,
+ ::osl::Mutex & rMutex,
+ boost::shared_ptr<xmlXPathObject> const& rxpathObj)
+ : m_pDocument(pDocument)
+ , m_rMutex(rMutex)
, m_pNodeSet(0)
{
if (rxpathObj != NULL && rxpathObj->type == XPATH_NODESET)
@@ -47,6 +52,8 @@ namespace XPath
*/
sal_Int32 SAL_CALL CNodeList::getLength() throw (RuntimeException)
{
+ ::osl::MutexGuard const g(m_rMutex);
+
sal_Int32 value = 0;
if (m_pNodeSet != NULL)
value = xmlXPathNodeSetGetLength(m_pNodeSet);
@@ -56,12 +63,17 @@ namespace XPath
/**
Returns the indexth item in the collection.
*/
- Reference< XNode > SAL_CALL CNodeList::item(sal_Int32 index) throw (RuntimeException)
+ Reference< XNode > SAL_CALL CNodeList::item(sal_Int32 index)
+ throw (RuntimeException)
{
- Reference< XNode > aNode;
- if (m_pNodeSet != NULL)
- aNode = Reference< XNode >(DOM::CNode::get(xmlXPathNodeSetItem(m_pNodeSet, index)));
- return aNode;
+ ::osl::MutexGuard const g(m_rMutex);
+
+ if (0 == m_pNodeSet) {
+ return 0;
+ }
+ xmlNodePtr const pNode = xmlXPathNodeSetItem(m_pNodeSet, index);
+ Reference< XNode > const xNode(m_pDocument->GetCNode(pNode).get());
+ return xNode;
}
}
diff --git a/unoxml/source/xpath/nodelist.hxx b/unoxml/source/xpath/nodelist.hxx
index af8770199dda..ed3543ee815e 100644
--- a/unoxml/source/xpath/nodelist.hxx
+++ b/unoxml/source/xpath/nodelist.hxx
@@ -26,39 +26,52 @@
*
************************************************************************/
-#ifndef _NODELIST_HXX
-#define _NODELIST_HXX
+#ifndef XPATH_NODELIST_HXX
+#define XPATH_NODELIST_HXX
-#include <vector>
#include <sal/types.h>
+#include <rtl/ref.hxx>
+
#include <cppuhelper/implbase1.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 <com/sun/star/xml/xpath/XXPathObject.hpp>
+
#include "libxml/tree.h"
#include "libxml/xpath.h"
+
#include <boost/shared_ptr.hpp>
+
using ::rtl::OUString;
using namespace com::sun::star::uno;
-using namespace com::sun::star::lang;
using namespace com::sun::star::xml::dom;
using namespace com::sun::star::xml::xpath;
+namespace DOM {
+ class CDocument;
+}
+
namespace XPath
{
class CNodeList : public cppu::WeakImplHelper1< XNodeList >
{
private:
- const Reference< XNode > m_xContextNode;
+ /// #i115995# keep document alive
+ ::rtl::Reference< DOM::CDocument > const m_pDocument;
+ ::osl::Mutex & m_rMutex;
+ /// retain the result set in case the CXPathObject is released
boost::shared_ptr<xmlXPathObject> m_pXPathObj;
xmlNodeSetPtr m_pNodeSet;
public:
- CNodeList(const Reference< XNode >& contextNode, boost::shared_ptr<xmlXPathObject> &rxpathObj);
+ CNodeList(
+ ::rtl::Reference<DOM::CDocument> const& pDocument,
+ ::osl::Mutex & rMutex,
+ boost::shared_ptr<xmlXPathObject> const& rxpathObj);
/**
The number of nodes in the list.
*/
@@ -66,7 +79,8 @@ namespace XPath
/**
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);
};
}
diff --git a/unoxml/source/xpath/xpathapi.cxx b/unoxml/source/xpath/xpathapi.cxx
index ee729a9451e3..dac4b2e2ca9d 100644
--- a/unoxml/source/xpath/xpathapi.cxx
+++ b/unoxml/source/xpath/xpathapi.cxx
@@ -26,19 +26,26 @@
*
************************************************************************/
-#include "xpathapi.hxx"
-#include "nodelist.hxx"
-#include "xpathobject.hxx"
-#include "../dom/node.hxx"
+#include <xpathapi.hxx>
-#include <rtl/ustrbuf.hxx>
+#include <stdarg.h>
+#include <string.h>
+#include <libxml/tree.h>
#include <libxml/xmlerror.h>
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
-#include <stdarg.h>
-#include <string.h>
+#include <rtl/ustrbuf.hxx>
+
+#include <nodelist.hxx>
+#include <xpathobject.hxx>
+
+#include "../dom/node.hxx"
+#include "../dom/document.hxx"
+
+
+using ::com::sun::star::lang::XMultiServiceFactory;
namespace XPath
@@ -106,6 +113,8 @@ namespace XPath
const OUString& aURI)
throw (RuntimeException)
{
+ ::osl::MutexGuard const g(m_Mutex);
+
m_nsmap.insert(nsmap_t::value_type(aPrefix, aURI));
}
@@ -114,13 +123,16 @@ namespace XPath
const OUString& aURI)
throw (RuntimeException)
{
- if ((m_nsmap.find(aPrefix))->second.equals(aURI))
+ ::osl::MutexGuard const g(m_Mutex);
+
+ if ((m_nsmap.find(aPrefix))->second.equals(aURI)) {
m_nsmap.erase(aPrefix);
+ }
}
// register all namespaces stored in the namespace list for this object
// with the current xpath evaluation context
- static void _registerNamespaces(
+ static void lcl_registerNamespaces(
xmlXPathContextPtr ctx,
const nsmap_t& nsmap)
{
@@ -138,13 +150,16 @@ namespace XPath
}
}
- // get all ns decls on a node (and parent nodes, if any) and register them
- static void _collectNamespaces(
- CXPathAPI* pAPI,
- const Reference< XNode >& namespaceNode)
+ // get all ns decls on a node (and parent nodes, if any)
+ static void lcl_collectNamespaces(
+ nsmap_t & rNamespaces, Reference< XNode > const& xNamespaceNode)
{
- // get namespace decls from node...
- xmlNodePtr pNode = DOM::CNode::getNodePtr(namespaceNode);
+ DOM::CNode *const pCNode(DOM::CNode::GetImplementation(xNamespaceNode));
+ if (!pCNode) { throw RuntimeException(); }
+
+ ::osl::MutexGuard const g(pCNode->GetOwnerDocument().GetMutex());
+
+ xmlNodePtr pNode = pCNode->GetNodePtr();
while (pNode != 0) {
xmlNsPtr curDef = pNode->nsDef;
while (curDef != 0) {
@@ -152,16 +167,32 @@ namespace XPath
OUString aURI((sal_Char*)xHref, strlen((char*)xHref), RTL_TEXTENCODING_UTF8);
const xmlChar* xPre = curDef->prefix;
OUString aPrefix((sal_Char*)xPre, strlen((char*)xPre), RTL_TEXTENCODING_UTF8);
- pAPI->registerNS(aPrefix, aURI);
+ // we could already have this prefix from a child node
+ if (rNamespaces.find(aPrefix) == rNamespaces.end())
+ {
+ rNamespaces.insert(::std::make_pair(aPrefix, aURI));
+ }
curDef = curDef->next;
}
pNode = pNode->parent;
}
}
+ static void lcl_collectRegisterNamespaces(
+ CXPathAPI & rAPI, Reference< XNode > const& xNamespaceNode)
+ {
+ nsmap_t namespaces;
+ lcl_collectNamespaces(namespaces, xNamespaceNode);
+ for (nsmap_t::const_iterator iter = namespaces.begin();
+ iter != namespaces.end(); ++iter)
+ {
+ rAPI.registerNS(iter->first, iter->second);
+ }
+ }
+
// register function and variable lookup functions with the current
// xpath evaluation context
- static void _registerExtensions(
+ static void lcl_registerExtensions(
xmlXPathContextPtr ctx,
const extensions_t& extensions)
{
@@ -210,7 +241,7 @@ namespace XPath
const Reference< XNode >& namespaceNode)
throw (RuntimeException, XPathException)
{
- _collectNamespaces(this, namespaceNode);
+ lcl_collectRegisterNamespaces(*this, namespaceNode);
return selectNodeList(contextNode, expr);
}
@@ -237,7 +268,7 @@ namespace XPath
const Reference< XNode >& namespaceNode )
throw (RuntimeException, XPathException)
{
- _collectNamespaces(this, namespaceNode);
+ lcl_collectRegisterNamespaces(*this, namespaceNode);
return selectSingleNode(contextNode, expr);
}
@@ -308,15 +339,34 @@ namespace XPath
* the context Node
*/
Reference< XXPathObject > SAL_CALL CXPathAPI::eval(
- const Reference< XNode >& contextNode,
+ Reference< XNode > const& xContextNode,
const OUString& expr)
throw (RuntimeException, XPathException)
{
- xmlXPathContextPtr xpathCtx;
- xmlXPathObjectPtr xpathObj;
+ if (!xContextNode.is()) { throw RuntimeException(); }
+
+ nsmap_t nsmap;
+ extensions_t extensions;
+
+ {
+ ::osl::MutexGuard const g(m_Mutex);
+ nsmap = m_nsmap;
+ extensions = m_extensions;
+ }
// get the node and document
- xmlNodePtr pNode = DOM::CNode::getNodePtr(contextNode);
+ ::rtl::Reference<DOM::CDocument> const pCDoc(
+ dynamic_cast<DOM::CDocument*>( DOM::CNode::GetImplementation(
+ xContextNode->getOwnerDocument())));
+ if (!pCDoc.is()) { throw RuntimeException(); }
+
+ DOM::CNode *const pCNode = DOM::CNode::GetImplementation(xContextNode);
+ if (!pCNode) { throw RuntimeException(); }
+
+ ::osl::MutexGuard const g(pCDoc->GetMutex()); // lock the document!
+
+ xmlNodePtr const pNode = pCNode->GetNodePtr();
+ if (!pNode) { throw RuntimeException(); }
xmlDocPtr pDoc = pNode->doc;
/* NB: workaround for #i87252#:
@@ -331,8 +381,9 @@ namespace XPath
}
/* Create xpath evaluation context */
- xpathCtx = xmlXPathNewContext(pDoc);
- if (xpathCtx == NULL) throw XPathException();
+ ::boost::shared_ptr<xmlXPathContext> const xpathCtx(
+ xmlXPathNewContext(pDoc), xmlXPathFreeContext);
+ if (xpathCtx == NULL) { throw XPathException(); }
// set context node
xpathCtx->node = pNode;
@@ -341,20 +392,21 @@ namespace XPath
xmlSetGenericErrorFunc(NULL, generic_error_func);
// register namespaces and extension
- _registerNamespaces(xpathCtx, m_nsmap);
- _registerExtensions(xpathCtx, m_extensions);
+ lcl_registerNamespaces(xpathCtx.get(), nsmap);
+ lcl_registerExtensions(xpathCtx.get(), extensions);
/* run the query */
OString o1 = OUStringToOString(expr, RTL_TEXTENCODING_UTF8);
xmlChar *xStr = (xmlChar*)o1.getStr();
- if ((xpathObj = xmlXPathEval(xStr, xpathCtx)) == NULL) {
+ ::boost::shared_ptr<xmlXPathObject> const xpathObj(
+ xmlXPathEval(xStr, xpathCtx.get()), xmlXPathFreeObject);
+ if (0 == xpathObj) {
// OSL_ENSURE(xpathCtx->lastError == NULL, xpathCtx->lastError->message);
- xmlXPathFreeContext(xpathCtx);
throw XPathException();
}
- xmlXPathFreeContext(xpathCtx);
- Reference< XXPathObject > aObj(new CXPathObject(xpathObj, contextNode));
- return aObj;
+ Reference<XXPathObject> const xObj(
+ new CXPathObject(pCDoc, pCDoc->GetMutex(), xpathObj));
+ return xObj;
}
/**
@@ -366,7 +418,7 @@ namespace XPath
const Reference< XNode >& namespaceNode)
throw (RuntimeException, XPathException)
{
- _collectNamespaces(this, namespaceNode);
+ lcl_collectRegisterNamespaces(*this, namespaceNode);
return eval(contextNode, expr);
}
@@ -379,9 +431,12 @@ namespace XPath
const OUString& aName)
throw (RuntimeException)
{
+ ::osl::MutexGuard const g(m_Mutex);
+
// get extension from service manager
- Reference< XXPathExtension > aExtension(m_aFactory->createInstance(aName), UNO_QUERY_THROW);
- m_extensions.push_back( aExtension );
+ Reference< XXPathExtension > const xExtension(
+ m_aFactory->createInstance(aName), UNO_QUERY_THROW);
+ m_extensions.push_back(xExtension);
}
/**
@@ -389,14 +444,14 @@ namespace XPath
* XPathAPI instance
*/
void SAL_CALL CXPathAPI::registerExtensionInstance(
- const Reference< XXPathExtension>& aExtension)
+ Reference< XXPathExtension> const& xExtension)
throw (RuntimeException)
{
- if (aExtension.is()) {
- m_extensions.push_back( aExtension );
- } else {
+ if (!xExtension.is()) {
throw RuntimeException();
}
+ ::osl::MutexGuard const g(m_Mutex);
+ m_extensions.push_back( xExtension );
}
}
diff --git a/unoxml/source/xpath/xpathapi.hxx b/unoxml/source/xpath/xpathapi.hxx
index 4bc57a958014..dc8e0536656c 100644
--- a/unoxml/source/xpath/xpathapi.hxx
+++ b/unoxml/source/xpath/xpathapi.hxx
@@ -26,14 +26,16 @@
*
************************************************************************/
-#ifndef _XPATHAPI_HXX
-#define _XPATHAPI_HXX
+#ifndef XPATH_XPATHAPI_HXX
+#define XPATH_XPATHAPI_HXX
#include <map>
#include <vector>
#include <sal/types.h>
+
#include <cppuhelper/implbase2.hxx>
+
#include <com/sun/star/uno/Reference.h>
#include <com/sun/star/uno/Sequence.h>
@@ -51,11 +53,9 @@
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
-#include "libxml/tree.h"
using ::rtl::OUString;
using namespace com::sun::star::uno;
-using namespace com::sun::star::lang;
using namespace com::sun::star::xml::dom;
using namespace com::sun::star::xml::xpath;
@@ -64,28 +64,40 @@ namespace XPath
typedef std::map<OUString, OUString> nsmap_t;
typedef std::vector< Reference<XXPathExtension> > extensions_t;
+ typedef ::cppu::WeakImplHelper2
+ < XXPathAPI
+ , ::com::sun::star::lang::XServiceInfo
+ > CXPathAPI_Base;
+
class CXPathAPI
- : public ::cppu::WeakImplHelper2< XXPathAPI, XServiceInfo >
+ : public CXPathAPI_Base
{
private:
+ ::osl::Mutex m_Mutex;
nsmap_t m_nsmap;
- const Reference< XMultiServiceFactory > m_aFactory;
+ const Reference< ::com::sun::star::lang::XMultiServiceFactory > m_aFactory;
extensions_t m_extensions;
public:
// ctor
- CXPathAPI(const Reference< XMultiServiceFactory >& rSMgr);
+ CXPathAPI(
+ const Reference< ::com::sun::star::lang::XMultiServiceFactory >&
+ rSMgr);
// call for factory
- static Reference< XInterface > getInstance(const Reference < XMultiServiceFactory >& xFactory);
+ static Reference< XInterface > getInstance(
+ const Reference < ::com::sun::star::lang::XMultiServiceFactory >&
+ xFactory);
// static helpers for service info and component management
static const char* aImplementationName;
static const char* aSupportedServiceNames[];
static OUString _getImplementationName();
static Sequence< OUString > _getSupportedServiceNames();
- static Reference< XInterface > _getInstance(const Reference< XMultiServiceFactory >& rSMgr);
+ static Reference< XInterface > _getInstance(
+ const Reference< ::com::sun::star::lang::XMultiServiceFactory >&
+ rSMgr);
// XServiceInfo
virtual OUString SAL_CALL getImplementationName()
diff --git a/unoxml/source/xpath/xpathobject.cxx b/unoxml/source/xpath/xpathobject.cxx
index c33eeb6477dc..c9d84bd4173f 100644
--- a/unoxml/source/xpath/xpathobject.cxx
+++ b/unoxml/source/xpath/xpathobject.cxx
@@ -26,67 +26,75 @@
*
************************************************************************/
+#include <xpathobject.hxx>
+
#include <string.h>
-#include "xpathobject.hxx"
-#include "nodelist.hxx"
+
+#include "../dom/document.hxx"
+#include <nodelist.hxx>
+
namespace XPath
{
- CXPathObject::CXPathObject(xmlXPathObjectPtr xpathObj, const Reference< XNode >& contextNode)
- : m_pXPathObj(xpathObj, xmlXPathFreeObject), m_xContextNode(contextNode)
+ static XPathObjectType lcl_GetType(xmlXPathObjectPtr const pXPathObj)
{
- switch (m_pXPathObj->type)
+ switch (pXPathObj->type)
{
- case XPATH_UNDEFINED:
- m_xPathObjectType = XPathObjectType_XPATH_UNDEFINED;
- break;
- case XPATH_NODESET:
- m_xPathObjectType = XPathObjectType_XPATH_NODESET;
- break;
- case XPATH_BOOLEAN:
- m_xPathObjectType = XPathObjectType_XPATH_BOOLEAN;
- break;
- case XPATH_NUMBER:
- m_xPathObjectType = XPathObjectType_XPATH_NUMBER;
- break;
- case XPATH_STRING:
- m_xPathObjectType = XPathObjectType_XPATH_STRING;
- break;
- case XPATH_POINT:
- m_xPathObjectType = XPathObjectType_XPATH_POINT;
- break;
- case XPATH_RANGE:
- m_xPathObjectType = XPathObjectType_XPATH_RANGE;
- break;
- case XPATH_LOCATIONSET:
- m_xPathObjectType = XPathObjectType_XPATH_LOCATIONSET;
- break;
- case XPATH_USERS:
- m_xPathObjectType = XPathObjectType_XPATH_USERS;
- break;
- case XPATH_XSLT_TREE:
- m_xPathObjectType = XPathObjectType_XPATH_XSLT_TREE;
- break;
- default:
- m_xPathObjectType = XPathObjectType_XPATH_UNDEFINED;
- break;
+ case XPATH_UNDEFINED:
+ return XPathObjectType_XPATH_UNDEFINED;
+ case XPATH_NODESET:
+ return XPathObjectType_XPATH_NODESET;
+ case XPATH_BOOLEAN:
+ return XPathObjectType_XPATH_BOOLEAN;
+ case XPATH_NUMBER:
+ return XPathObjectType_XPATH_NUMBER;
+ case XPATH_STRING:
+ return XPathObjectType_XPATH_STRING;
+ case XPATH_POINT:
+ return XPathObjectType_XPATH_POINT;
+ case XPATH_RANGE:
+ return XPathObjectType_XPATH_RANGE;
+ case XPATH_LOCATIONSET:
+ return XPathObjectType_XPATH_LOCATIONSET;
+ case XPATH_USERS:
+ return XPathObjectType_XPATH_USERS;
+ case XPATH_XSLT_TREE:
+ return XPathObjectType_XPATH_XSLT_TREE;
+ default:
+ return XPathObjectType_XPATH_UNDEFINED;
}
}
+ CXPathObject::CXPathObject(
+ ::rtl::Reference<DOM::CDocument> const& pDocument,
+ ::osl::Mutex & rMutex,
+ ::boost::shared_ptr<xmlXPathObject> const& pXPathObj)
+ : m_pDocument(pDocument)
+ , m_rMutex(rMutex)
+ , m_pXPathObj(pXPathObj)
+ , m_XPathObjectType(lcl_GetType(pXPathObj.get()))
+ {
+ }
+
/**
get object type
*/
XPathObjectType CXPathObject::getObjectType() throw (RuntimeException)
{
- return m_xPathObjectType;
+ return m_XPathObjectType;
}
/**
get the nodes from a nodelist type object
*/
- Reference< XNodeList > SAL_CALL CXPathObject::getNodeList() throw (RuntimeException)
+ Reference< XNodeList > SAL_CALL
+ CXPathObject::getNodeList() throw (RuntimeException)
{
- return Reference< XNodeList >(new CNodeList(m_xContextNode, m_pXPathObj));
+ ::osl::MutexGuard const g(m_rMutex);
+
+ Reference< XNodeList > const xRet(
+ new CNodeList(m_pDocument, m_rMutex, m_pXPathObj));
+ return xRet;
}
/**
@@ -94,6 +102,8 @@ namespace XPath
*/
sal_Bool SAL_CALL CXPathObject::getBoolean() throw (RuntimeException)
{
+ ::osl::MutexGuard const g(m_rMutex);
+
return (sal_Bool) xmlXPathCastToBoolean(m_pXPathObj.get());
}
@@ -102,6 +112,8 @@ namespace XPath
*/
sal_Int8 SAL_CALL CXPathObject::getByte() throw (RuntimeException)
{
+ ::osl::MutexGuard const g(m_rMutex);
+
return (sal_Int8) xmlXPathCastToNumber(m_pXPathObj.get());
}
@@ -110,6 +122,8 @@ namespace XPath
*/
sal_Int16 SAL_CALL CXPathObject::getShort() throw (RuntimeException)
{
+ ::osl::MutexGuard const g(m_rMutex);
+
return (sal_Int16) xmlXPathCastToNumber(m_pXPathObj.get());
}
@@ -118,6 +132,8 @@ namespace XPath
*/
sal_Int32 SAL_CALL CXPathObject::getLong() throw (RuntimeException)
{
+ ::osl::MutexGuard const g(m_rMutex);
+
return (sal_Int32) xmlXPathCastToNumber(m_pXPathObj.get());
}
@@ -126,6 +142,8 @@ namespace XPath
*/
sal_Int64 SAL_CALL CXPathObject::getHyper() throw (RuntimeException)
{
+ ::osl::MutexGuard const g(m_rMutex);
+
return (sal_Int64) xmlXPathCastToNumber(m_pXPathObj.get());
}
@@ -134,6 +152,8 @@ namespace XPath
*/
float SAL_CALL CXPathObject::getFloat() throw (RuntimeException)
{
+ ::osl::MutexGuard const g(m_rMutex);
+
return (float) xmlXPathCastToNumber(m_pXPathObj.get());
}
@@ -142,6 +162,8 @@ namespace XPath
*/
double SAL_CALL CXPathObject::getDouble() throw (RuntimeException)
{
+ ::osl::MutexGuard const g(m_rMutex);
+
return xmlXPathCastToNumber(m_pXPathObj.get());
}
@@ -150,8 +172,12 @@ namespace XPath
*/
OUString SAL_CALL CXPathObject::getString() throw (RuntimeException)
{
- const sal_Char* x1 = (sal_Char*) xmlXPathCastToString(m_pXPathObj.get());
- return OUString(x1, strlen(x1), RTL_TEXTENCODING_UTF8);
+ ::osl::MutexGuard const g(m_rMutex);
+
+ ::boost::shared_ptr<xmlChar const> str(
+ xmlXPathCastToString(m_pXPathObj.get()), xmlFree);
+ sal_Char const*const pS(reinterpret_cast<sal_Char const*>(str.get()));
+ return OUString(pS, strlen(pS), RTL_TEXTENCODING_UTF8);
}
}
diff --git a/unoxml/source/xpath/xpathobject.hxx b/unoxml/source/xpath/xpathobject.hxx
index b8eda758bc58..8e507aa0c19b 100644
--- a/unoxml/source/xpath/xpathobject.hxx
+++ b/unoxml/source/xpath/xpathobject.hxx
@@ -26,38 +26,48 @@
*
************************************************************************/
-#ifndef _XPATHOBJECT_HXX
-#define _XPATHOBJECT_HXX
+#ifndef XPATH_XPATHOBJECT_HXX
+#define XPATH_XPATHOBJECT_HXX
+
+#include <boost/shared_ptr.hpp>
+
+#include <libxml/tree.h>
+#include <libxml/xpath.h>
-#include <map>
#include <sal/types.h>
+#include <rtl/ref.hxx>
+
#include <cppuhelper/implbase1.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 <com/sun/star/xml/xpath/XXPathObject.hpp>
-#include <libxml/tree.h>
-#include <libxml/xpath.h>
-#include <boost/shared_ptr.hpp>
+
using ::rtl::OUString;
using namespace com::sun::star::uno;
-using namespace com::sun::star::lang;
using namespace com::sun::star::xml::dom;
using namespace com::sun::star::xml::xpath;
+
+namespace DOM {
+ class CDocument;
+}
+
namespace XPath
{
class CXPathObject : public cppu::WeakImplHelper1< XXPathObject >
{
private:
- boost::shared_ptr<xmlXPathObject> m_pXPathObj;
- const Reference< XNode > m_xContextNode;
- XPathObjectType m_xPathObjectType;
+ ::rtl::Reference< DOM::CDocument > const m_pDocument;
+ ::osl::Mutex & m_rMutex;
+ boost::shared_ptr<xmlXPathObject> const m_pXPathObj;
+ XPathObjectType const m_XPathObjectType;
public:
- CXPathObject(xmlXPathObjectPtr xpathObj, const Reference< XNode >& contextNode);
+ CXPathObject( ::rtl::Reference<DOM::CDocument> const& pDocument,
+ ::osl::Mutex & rMutex,
+ ::boost::shared_ptr<xmlXPathObject> const& pXPathObj);
/**
get object type
@@ -67,7 +77,8 @@ namespace XPath
/**
get the nodes from a nodelist type object
*/
- virtual Reference< XNodeList > SAL_CALL getNodeList() throw (RuntimeException);
+ virtual Reference< XNodeList > SAL_CALL getNodeList()
+ throw (RuntimeException);
/**
get value of a boolean object