1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "xpathobject.hxx"
26 #include "../dom/document.hxx"
27 #include "nodelist.hxx"
29 using namespace css::uno
;
30 using namespace css::xml::dom
;
31 using namespace css::xml::xpath
;
35 static XPathObjectType
lcl_GetType(xmlXPathObjectPtr
const pXPathObj
)
37 switch (pXPathObj
->type
)
40 return XPathObjectType_XPATH_UNDEFINED
;
42 return XPathObjectType_XPATH_NODESET
;
44 return XPathObjectType_XPATH_BOOLEAN
;
46 return XPathObjectType_XPATH_NUMBER
;
48 return XPathObjectType_XPATH_STRING
;
49 #if LIBXML_VERSION < 21000 || defined(LIBXML_XPTR_LOCS_ENABLED)
51 return XPathObjectType_XPATH_POINT
;
53 return XPathObjectType_XPATH_RANGE
;
54 case XPATH_LOCATIONSET
:
55 return XPathObjectType_XPATH_LOCATIONSET
;
58 return XPathObjectType_XPATH_USERS
;
60 return XPathObjectType_XPATH_XSLT_TREE
;
62 return XPathObjectType_XPATH_UNDEFINED
;
66 CXPathObject::CXPathObject(
67 ::rtl::Reference
<DOM::CDocument
> pDocument
,
68 ::osl::Mutex
& rMutex
,
69 std::shared_ptr
<xmlXPathObject
> const& pXPathObj
)
70 : m_pDocument(std::move(pDocument
))
72 , m_pXPathObj(pXPathObj
)
73 , m_XPathObjectType(lcl_GetType(pXPathObj
.get()))
80 XPathObjectType
CXPathObject::getObjectType()
82 return m_XPathObjectType
;
86 get the nodes from a nodelist type object
88 Reference
< XNodeList
> SAL_CALL
89 CXPathObject::getNodeList()
91 ::osl::MutexGuard
const g(m_rMutex
);
93 Reference
< XNodeList
> const xRet(
94 new CNodeList(m_pDocument
, m_rMutex
, m_pXPathObj
));
99 get value of a boolean object
101 sal_Bool SAL_CALL
CXPathObject::getBoolean()
103 ::osl::MutexGuard
const g(m_rMutex
);
105 return xmlXPathCastToBoolean(m_pXPathObj
.get()) != 0;
111 sal_Int8 SAL_CALL
CXPathObject::getByte()
113 ::osl::MutexGuard
const g(m_rMutex
);
115 return static_cast<sal_Int8
>(xmlXPathCastToNumber(m_pXPathObj
.get()));
121 sal_Int16 SAL_CALL
CXPathObject::getShort()
123 ::osl::MutexGuard
const g(m_rMutex
);
125 return static_cast<sal_Int16
>(xmlXPathCastToNumber(m_pXPathObj
.get()));
131 sal_Int32 SAL_CALL
CXPathObject::getLong()
133 ::osl::MutexGuard
const g(m_rMutex
);
135 return static_cast<sal_Int32
>(xmlXPathCastToNumber(m_pXPathObj
.get()));
141 sal_Int64 SAL_CALL
CXPathObject::getHyper()
143 ::osl::MutexGuard
const g(m_rMutex
);
145 return static_cast<sal_Int64
>(xmlXPathCastToNumber(m_pXPathObj
.get()));
151 float SAL_CALL
CXPathObject::getFloat()
153 ::osl::MutexGuard
const g(m_rMutex
);
155 return static_cast<float>(xmlXPathCastToNumber(m_pXPathObj
.get()));
161 double SAL_CALL
CXPathObject::getDouble()
163 ::osl::MutexGuard
const g(m_rMutex
);
165 return xmlXPathCastToNumber(m_pXPathObj
.get());
171 OUString SAL_CALL
CXPathObject::getString()
173 ::osl::MutexGuard
const g(m_rMutex
);
175 std::shared_ptr
<xmlChar
const> str(
176 xmlXPathCastToString(m_pXPathObj
.get()), xmlFree
);
177 char const*const pS(reinterpret_cast<char const*>(str
.get()));
178 return OUString(pS
, strlen(pS
), RTL_TEXTENCODING_UTF8
);
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */