bump product version to 4.1.6.2
[LibreOffice.git] / unoxml / source / xpath / xpathobject.cxx
bloba1a7797095c2b1ce6659bd1c2c8ad3a00f602dd6
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 "../dom/document.hxx"
25 #include <nodelist.hxx>
28 namespace XPath
30 static XPathObjectType lcl_GetType(xmlXPathObjectPtr const pXPathObj)
32 switch (pXPathObj->type)
34 case XPATH_UNDEFINED:
35 return XPathObjectType_XPATH_UNDEFINED;
36 case XPATH_NODESET:
37 return XPathObjectType_XPATH_NODESET;
38 case XPATH_BOOLEAN:
39 return XPathObjectType_XPATH_BOOLEAN;
40 case XPATH_NUMBER:
41 return XPathObjectType_XPATH_NUMBER;
42 case XPATH_STRING:
43 return XPathObjectType_XPATH_STRING;
44 case XPATH_POINT:
45 return XPathObjectType_XPATH_POINT;
46 case XPATH_RANGE:
47 return XPathObjectType_XPATH_RANGE;
48 case XPATH_LOCATIONSET:
49 return XPathObjectType_XPATH_LOCATIONSET;
50 case XPATH_USERS:
51 return XPathObjectType_XPATH_USERS;
52 case XPATH_XSLT_TREE:
53 return XPathObjectType_XPATH_XSLT_TREE;
54 default:
55 return XPathObjectType_XPATH_UNDEFINED;
59 CXPathObject::CXPathObject(
60 ::rtl::Reference<DOM::CDocument> const& pDocument,
61 ::osl::Mutex & rMutex,
62 ::boost::shared_ptr<xmlXPathObject> const& pXPathObj)
63 : m_pDocument(pDocument)
64 , m_rMutex(rMutex)
65 , m_pXPathObj(pXPathObj)
66 , m_XPathObjectType(lcl_GetType(pXPathObj.get()))
70 /**
71 get object type
73 XPathObjectType CXPathObject::getObjectType() throw (RuntimeException)
75 return m_XPathObjectType;
78 /**
79 get the nodes from a nodelist type object
81 Reference< XNodeList > SAL_CALL
82 CXPathObject::getNodeList() throw (RuntimeException)
84 ::osl::MutexGuard const g(m_rMutex);
86 Reference< XNodeList > const xRet(
87 new CNodeList(m_pDocument, m_rMutex, m_pXPathObj));
88 return xRet;
91 /**
92 get value of a boolean object
94 sal_Bool SAL_CALL CXPathObject::getBoolean() throw (RuntimeException)
96 ::osl::MutexGuard const g(m_rMutex);
98 return (sal_Bool) xmlXPathCastToBoolean(m_pXPathObj.get());
102 get number as byte
104 sal_Int8 SAL_CALL CXPathObject::getByte() throw (RuntimeException)
106 ::osl::MutexGuard const g(m_rMutex);
108 return (sal_Int8) xmlXPathCastToNumber(m_pXPathObj.get());
112 get number as short
114 sal_Int16 SAL_CALL CXPathObject::getShort() throw (RuntimeException)
116 ::osl::MutexGuard const g(m_rMutex);
118 return (sal_Int16) xmlXPathCastToNumber(m_pXPathObj.get());
122 get number as long
124 sal_Int32 SAL_CALL CXPathObject::getLong() throw (RuntimeException)
126 ::osl::MutexGuard const g(m_rMutex);
128 return (sal_Int32) xmlXPathCastToNumber(m_pXPathObj.get());
132 get number as hyper
134 sal_Int64 SAL_CALL CXPathObject::getHyper() throw (RuntimeException)
136 ::osl::MutexGuard const g(m_rMutex);
138 return (sal_Int64) xmlXPathCastToNumber(m_pXPathObj.get());
142 get number as float
144 float SAL_CALL CXPathObject::getFloat() throw (RuntimeException)
146 ::osl::MutexGuard const g(m_rMutex);
148 return (float) xmlXPathCastToNumber(m_pXPathObj.get());
152 get number as double
154 double SAL_CALL CXPathObject::getDouble() throw (RuntimeException)
156 ::osl::MutexGuard const g(m_rMutex);
158 return xmlXPathCastToNumber(m_pXPathObj.get());
162 get string value
164 OUString SAL_CALL CXPathObject::getString() throw (RuntimeException)
166 ::osl::MutexGuard const g(m_rMutex);
168 ::boost::shared_ptr<xmlChar const> str(
169 xmlXPathCastToString(m_pXPathObj.get()), xmlFree);
170 sal_Char const*const pS(reinterpret_cast<sal_Char const*>(str.get()));
171 return OUString(pS, strlen(pS), RTL_TEXTENCODING_UTF8);
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */