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>
30 static XPathObjectType
lcl_GetType(xmlXPathObjectPtr
const pXPathObj
)
32 switch (pXPathObj
->type
)
35 return XPathObjectType_XPATH_UNDEFINED
;
37 return XPathObjectType_XPATH_NODESET
;
39 return XPathObjectType_XPATH_BOOLEAN
;
41 return XPathObjectType_XPATH_NUMBER
;
43 return XPathObjectType_XPATH_STRING
;
45 return XPathObjectType_XPATH_POINT
;
47 return XPathObjectType_XPATH_RANGE
;
48 case XPATH_LOCATIONSET
:
49 return XPathObjectType_XPATH_LOCATIONSET
;
51 return XPathObjectType_XPATH_USERS
;
53 return XPathObjectType_XPATH_XSLT_TREE
;
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
)
65 , m_pXPathObj(pXPathObj
)
66 , m_XPathObjectType(lcl_GetType(pXPathObj
.get()))
73 XPathObjectType
CXPathObject::getObjectType() throw (RuntimeException
)
75 return m_XPathObjectType
;
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
));
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());
104 sal_Int8 SAL_CALL
CXPathObject::getByte() throw (RuntimeException
)
106 ::osl::MutexGuard
const g(m_rMutex
);
108 return (sal_Int8
) xmlXPathCastToNumber(m_pXPathObj
.get());
114 sal_Int16 SAL_CALL
CXPathObject::getShort() throw (RuntimeException
)
116 ::osl::MutexGuard
const g(m_rMutex
);
118 return (sal_Int16
) xmlXPathCastToNumber(m_pXPathObj
.get());
124 sal_Int32 SAL_CALL
CXPathObject::getLong() throw (RuntimeException
)
126 ::osl::MutexGuard
const g(m_rMutex
);
128 return (sal_Int32
) xmlXPathCastToNumber(m_pXPathObj
.get());
134 sal_Int64 SAL_CALL
CXPathObject::getHyper() throw (RuntimeException
)
136 ::osl::MutexGuard
const g(m_rMutex
);
138 return (sal_Int64
) xmlXPathCastToNumber(m_pXPathObj
.get());
144 float SAL_CALL
CXPathObject::getFloat() throw (RuntimeException
)
146 ::osl::MutexGuard
const g(m_rMutex
);
148 return (float) xmlXPathCastToNumber(m_pXPathObj
.get());
154 double SAL_CALL
CXPathObject::getDouble() throw (RuntimeException
)
156 ::osl::MutexGuard
const g(m_rMutex
);
158 return xmlXPathCastToNumber(m_pXPathObj
.get());
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: */