merge the formfield patch from ooo-build
[ooovba.git] / unoxml / source / xpath / xpathobject.cxx
blob991b3813de377bb59bb10593179be39c09da92c5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xpathobject.cxx,v $
10 * $Revision: 1.4.20.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <string.h>
32 #include "xpathobject.hxx"
33 #include "nodelist.hxx"
35 namespace XPath
37 CXPathObject::CXPathObject(xmlXPathObjectPtr xpathObj)
38 : m_pXPathObj(xpathObj, xmlXPathFreeObject)
40 switch (m_pXPathObj->type)
42 case XPATH_UNDEFINED:
43 m_xPathObjectType = XPathObjectType_XPATH_UNDEFINED;
44 break;
45 case XPATH_NODESET:
46 m_xPathObjectType = XPathObjectType_XPATH_NODESET;
47 break;
48 case XPATH_BOOLEAN:
49 m_xPathObjectType = XPathObjectType_XPATH_BOOLEAN;
50 break;
51 case XPATH_NUMBER:
52 m_xPathObjectType = XPathObjectType_XPATH_NUMBER;
53 break;
54 case XPATH_STRING:
55 m_xPathObjectType = XPathObjectType_XPATH_STRING;
56 break;
57 case XPATH_POINT:
58 m_xPathObjectType = XPathObjectType_XPATH_POINT;
59 break;
60 case XPATH_RANGE:
61 m_xPathObjectType = XPathObjectType_XPATH_RANGE;
62 break;
63 case XPATH_LOCATIONSET:
64 m_xPathObjectType = XPathObjectType_XPATH_LOCATIONSET;
65 break;
66 case XPATH_USERS:
67 m_xPathObjectType = XPathObjectType_XPATH_USERS;
68 break;
69 case XPATH_XSLT_TREE:
70 m_xPathObjectType = XPathObjectType_XPATH_XSLT_TREE;
71 break;
72 default:
73 m_xPathObjectType = XPathObjectType_XPATH_UNDEFINED;
74 break;
78 /**
79 get object type
81 XPathObjectType CXPathObject::getObjectType() throw (RuntimeException)
83 return m_xPathObjectType;
86 /**
87 get the nodes from a nodelist type object
89 Reference< XNodeList > SAL_CALL CXPathObject::getNodeList() throw (RuntimeException)
91 return Reference< XNodeList >(new CNodeList(m_pXPathObj));
94 /**
95 get value of a boolean object
97 sal_Bool SAL_CALL CXPathObject::getBoolean() throw (RuntimeException)
99 return (sal_Bool) xmlXPathCastToBoolean(m_pXPathObj.get());
103 get number as byte
105 sal_Int8 SAL_CALL CXPathObject::getByte() throw (RuntimeException)
107 return (sal_Int8) xmlXPathCastToNumber(m_pXPathObj.get());
111 get number as short
113 sal_Int16 SAL_CALL CXPathObject::getShort() throw (RuntimeException)
115 return (sal_Int16) xmlXPathCastToNumber(m_pXPathObj.get());
119 get number as long
121 sal_Int32 SAL_CALL CXPathObject::getLong() throw (RuntimeException)
123 return (sal_Int32) xmlXPathCastToNumber(m_pXPathObj.get());
127 get number as hyper
129 sal_Int64 SAL_CALL CXPathObject::getHyper() throw (RuntimeException)
131 return (sal_Int64) xmlXPathCastToNumber(m_pXPathObj.get());
135 get number as float
137 float SAL_CALL CXPathObject::getFloat() throw (RuntimeException)
139 return (float) xmlXPathCastToNumber(m_pXPathObj.get());
143 get number as double
145 double SAL_CALL CXPathObject::getDouble() throw (RuntimeException)
147 return xmlXPathCastToNumber(m_pXPathObj.get());
151 get string value
153 OUString SAL_CALL CXPathObject::getString() throw (RuntimeException)
155 const sal_Char* x1 = (sal_Char*) xmlXPathCastToString(m_pXPathObj.get());
156 return OUString(x1, strlen(x1), RTL_TEXTENCODING_UTF8);