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"
24 #include "../dom/document.hxx"
25 #include "nodelist.hxx"
27 using namespace css::uno
;
28 using namespace css::xml::dom
;
29 using namespace css::xml::xpath
;
33 static XPathObjectType
lcl_GetType(xmlXPathObjectPtr
const pXPathObj
)
35 switch (pXPathObj
->type
)
38 return XPathObjectType_XPATH_UNDEFINED
;
40 return XPathObjectType_XPATH_NODESET
;
42 return XPathObjectType_XPATH_BOOLEAN
;
44 return XPathObjectType_XPATH_NUMBER
;
46 return XPathObjectType_XPATH_STRING
;
48 return XPathObjectType_XPATH_POINT
;
50 return XPathObjectType_XPATH_RANGE
;
51 case XPATH_LOCATIONSET
:
52 return XPathObjectType_XPATH_LOCATIONSET
;
54 return XPathObjectType_XPATH_USERS
;
56 return XPathObjectType_XPATH_XSLT_TREE
;
58 return XPathObjectType_XPATH_UNDEFINED
;
62 CXPathObject::CXPathObject(
63 ::rtl::Reference
<DOM::CDocument
> const& pDocument
,
64 ::osl::Mutex
& rMutex
,
65 std::shared_ptr
<xmlXPathObject
> const& pXPathObj
)
66 : m_pDocument(pDocument
)
68 , m_pXPathObj(pXPathObj
)
69 , m_XPathObjectType(lcl_GetType(pXPathObj
.get()))
76 XPathObjectType
CXPathObject::getObjectType()
78 return m_XPathObjectType
;
82 get the nodes from a nodelist type object
84 Reference
< XNodeList
> SAL_CALL
85 CXPathObject::getNodeList()
87 ::osl::MutexGuard
const g(m_rMutex
);
89 Reference
< XNodeList
> const xRet(
90 new CNodeList(m_pDocument
, m_rMutex
, m_pXPathObj
));
95 get value of a boolean object
97 sal_Bool SAL_CALL
CXPathObject::getBoolean()
99 ::osl::MutexGuard
const g(m_rMutex
);
101 return xmlXPathCastToBoolean(m_pXPathObj
.get()) != 0;
107 sal_Int8 SAL_CALL
CXPathObject::getByte()
109 ::osl::MutexGuard
const g(m_rMutex
);
111 return static_cast<sal_Int8
>(xmlXPathCastToNumber(m_pXPathObj
.get()));
117 sal_Int16 SAL_CALL
CXPathObject::getShort()
119 ::osl::MutexGuard
const g(m_rMutex
);
121 return static_cast<sal_Int16
>(xmlXPathCastToNumber(m_pXPathObj
.get()));
127 sal_Int32 SAL_CALL
CXPathObject::getLong()
129 ::osl::MutexGuard
const g(m_rMutex
);
131 return static_cast<sal_Int32
>(xmlXPathCastToNumber(m_pXPathObj
.get()));
137 sal_Int64 SAL_CALL
CXPathObject::getHyper()
139 ::osl::MutexGuard
const g(m_rMutex
);
141 return static_cast<sal_Int64
>(xmlXPathCastToNumber(m_pXPathObj
.get()));
147 float SAL_CALL
CXPathObject::getFloat()
149 ::osl::MutexGuard
const g(m_rMutex
);
151 return static_cast<float>(xmlXPathCastToNumber(m_pXPathObj
.get()));
157 double SAL_CALL
CXPathObject::getDouble()
159 ::osl::MutexGuard
const g(m_rMutex
);
161 return xmlXPathCastToNumber(m_pXPathObj
.get());
167 OUString SAL_CALL
CXPathObject::getString()
169 ::osl::MutexGuard
const g(m_rMutex
);
171 std::shared_ptr
<xmlChar
const> str(
172 xmlXPathCastToString(m_pXPathObj
.get()), xmlFree
);
173 char const*const pS(reinterpret_cast<char const*>(str
.get()));
174 return OUString(pS
, strlen(pS
), RTL_TEXTENCODING_UTF8
);
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */