LibreOffice Module unoxml (master) 1
xpathobject.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "xpathobject.hxx"
21
22#include <string.h>
23
24#include <utility>
25
26#include "../dom/document.hxx"
27#include "nodelist.hxx"
28
29using namespace css::uno;
30using namespace css::xml::dom;
31using namespace css::xml::xpath;
32
33namespace XPath
34{
35 static XPathObjectType lcl_GetType(xmlXPathObjectPtr const pXPathObj)
36 {
37 switch (pXPathObj->type)
38 {
39 case XPATH_UNDEFINED:
40 return XPathObjectType_XPATH_UNDEFINED;
41 case XPATH_NODESET:
42 return XPathObjectType_XPATH_NODESET;
43 case XPATH_BOOLEAN:
44 return XPathObjectType_XPATH_BOOLEAN;
45 case XPATH_NUMBER:
46 return XPathObjectType_XPATH_NUMBER;
47 case XPATH_STRING:
48 return XPathObjectType_XPATH_STRING;
49#if LIBXML_VERSION < 21000 || defined(LIBXML_XPTR_LOCS_ENABLED)
50 case XPATH_POINT:
51 return XPathObjectType_XPATH_POINT;
52 case XPATH_RANGE:
53 return XPathObjectType_XPATH_RANGE;
54 case XPATH_LOCATIONSET:
55 return XPathObjectType_XPATH_LOCATIONSET;
56#endif
57 case XPATH_USERS:
58 return XPathObjectType_XPATH_USERS;
59 case XPATH_XSLT_TREE:
60 return XPathObjectType_XPATH_XSLT_TREE;
61 default:
62 return XPathObjectType_XPATH_UNDEFINED;
63 }
64 }
65
68 ::osl::Mutex & rMutex,
69 std::shared_ptr<xmlXPathObject> const& pXPathObj)
70 : m_pDocument(std::move(pDocument))
71 , m_rMutex(rMutex)
72 , m_pXPathObj(pXPathObj)
73 , m_XPathObjectType(lcl_GetType(pXPathObj.get()))
74 {
75 }
76
81 {
82 return m_XPathObjectType;
83 }
84
88 Reference< XNodeList > SAL_CALL
90 {
91 ::osl::MutexGuard const g(m_rMutex);
92
93 Reference< XNodeList > const xRet(
95 return xRet;
96 }
97
102 {
103 ::osl::MutexGuard const g(m_rMutex);
104
105 return xmlXPathCastToBoolean(m_pXPathObj.get()) != 0;
106 }
107
112 {
113 ::osl::MutexGuard const g(m_rMutex);
114
115 return static_cast<sal_Int8>(xmlXPathCastToNumber(m_pXPathObj.get()));
116 }
117
121 sal_Int16 SAL_CALL CXPathObject::getShort()
122 {
123 ::osl::MutexGuard const g(m_rMutex);
124
125 return static_cast<sal_Int16>(xmlXPathCastToNumber(m_pXPathObj.get()));
126 }
127
131 sal_Int32 SAL_CALL CXPathObject::getLong()
132 {
133 ::osl::MutexGuard const g(m_rMutex);
134
135 return static_cast<sal_Int32>(xmlXPathCastToNumber(m_pXPathObj.get()));
136 }
137
141 sal_Int64 SAL_CALL CXPathObject::getHyper()
142 {
143 ::osl::MutexGuard const g(m_rMutex);
144
145 return static_cast<sal_Int64>(xmlXPathCastToNumber(m_pXPathObj.get()));
146 }
147
151 float SAL_CALL CXPathObject::getFloat()
152 {
153 ::osl::MutexGuard const g(m_rMutex);
154
155 return static_cast<float>(xmlXPathCastToNumber(m_pXPathObj.get()));
156 }
157
161 double SAL_CALL CXPathObject::getDouble()
162 {
163 ::osl::MutexGuard const g(m_rMutex);
164
165 return xmlXPathCastToNumber(m_pXPathObj.get());
166 }
167
171 OUString SAL_CALL CXPathObject::getString()
172 {
173 ::osl::MutexGuard const g(m_rMutex);
174
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);
179 }
180
181}
182
183/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< xmlXPathObject > const m_pXPathObj
Definition: xpathobject.hxx:48
virtual sal_Int64 SAL_CALL getHyper() override
get number as hyper
virtual sal_Int8 SAL_CALL getByte() override
get number as byte
virtual sal_Bool SAL_CALL getBoolean() override
get value of a boolean object
css::xml::xpath::XPathObjectType const m_XPathObjectType
Definition: xpathobject.hxx:49
virtual OUString SAL_CALL getString() override
get string value
virtual sal_Int32 SAL_CALL getLong() override
get number as long
virtual double SAL_CALL getDouble() override
get number as double
virtual sal_Int16 SAL_CALL getShort() override
get number as short
CXPathObject(::rtl::Reference< DOM::CDocument > pDocument, ::osl::Mutex &rMutex, std::shared_ptr< xmlXPathObject > const &pXPathObj)
Definition: xpathobject.cxx:66
::osl::Mutex & m_rMutex
Definition: xpathobject.hxx:47
::rtl::Reference< DOM::CDocument > const m_pDocument
Definition: xpathobject.hxx:46
virtual css::uno::Reference< css::xml::dom::XNodeList > SAL_CALL getNodeList() override
get the nodes from a nodelist type object
Definition: xpathobject.cxx:89
virtual float SAL_CALL getFloat() override
get number as float
virtual css::xml::xpath::XPathObjectType SAL_CALL getObjectType() override
get object type
Definition: xpathobject.cxx:80
const char * pS
::osl::Mutex & m_rMutex
static XPathObjectType lcl_GetType(xmlXPathObjectPtr const pXPathObj)
Definition: xpathobject.cxx:35
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
unsigned char sal_Bool
signed char sal_Int8