sw HTML export: fix PNG export of Writer images containing metafiles
[LibreOffice.git] / unoxml / source / xpath / xpathobject.cxx
blobc33e6a330f8675f67e3c5c9d3dc10489977dd23b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
22 #include <string.h>
24 #include <utility>
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;
33 namespace XPath
35 static XPathObjectType lcl_GetType(xmlXPathObjectPtr const pXPathObj)
37 switch (pXPathObj->type)
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;
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))
71 , m_rMutex(rMutex)
72 , m_pXPathObj(pXPathObj)
73 , m_XPathObjectType(lcl_GetType(pXPathObj.get()))
77 /**
78 get object type
80 XPathObjectType CXPathObject::getObjectType()
82 return m_XPathObjectType;
85 /**
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));
95 return xRet;
98 /**
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;
109 get number as byte
111 sal_Int8 SAL_CALL CXPathObject::getByte()
113 ::osl::MutexGuard const g(m_rMutex);
115 return static_cast<sal_Int8>(xmlXPathCastToNumber(m_pXPathObj.get()));
119 get number as short
121 sal_Int16 SAL_CALL CXPathObject::getShort()
123 ::osl::MutexGuard const g(m_rMutex);
125 return static_cast<sal_Int16>(xmlXPathCastToNumber(m_pXPathObj.get()));
129 get number as long
131 sal_Int32 SAL_CALL CXPathObject::getLong()
133 ::osl::MutexGuard const g(m_rMutex);
135 return static_cast<sal_Int32>(xmlXPathCastToNumber(m_pXPathObj.get()));
139 get number as hyper
141 sal_Int64 SAL_CALL CXPathObject::getHyper()
143 ::osl::MutexGuard const g(m_rMutex);
145 return static_cast<sal_Int64>(xmlXPathCastToNumber(m_pXPathObj.get()));
149 get number as float
151 float SAL_CALL CXPathObject::getFloat()
153 ::osl::MutexGuard const g(m_rMutex);
155 return static_cast<float>(xmlXPathCastToNumber(m_pXPathObj.get()));
159 get number as double
161 double SAL_CALL CXPathObject::getDouble()
163 ::osl::MutexGuard const g(m_rMutex);
165 return xmlXPathCastToNumber(m_pXPathObj.get());
169 get string value
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: */