Line data Source code
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 "../dom/document.hxx"
25 : #include <nodelist.hxx>
26 :
27 : using namespace css::uno;
28 : using namespace css::xml::dom;
29 : using namespace css::xml::xpath;
30 :
31 : namespace XPath
32 : {
33 200513 : static XPathObjectType lcl_GetType(xmlXPathObjectPtr const pXPathObj)
34 : {
35 200513 : switch (pXPathObj->type)
36 : {
37 : case XPATH_UNDEFINED:
38 0 : return XPathObjectType_XPATH_UNDEFINED;
39 : case XPATH_NODESET:
40 200450 : return XPathObjectType_XPATH_NODESET;
41 : case XPATH_BOOLEAN:
42 2 : return XPathObjectType_XPATH_BOOLEAN;
43 : case XPATH_NUMBER:
44 3 : return XPathObjectType_XPATH_NUMBER;
45 : case XPATH_STRING:
46 58 : return XPathObjectType_XPATH_STRING;
47 : case XPATH_POINT:
48 0 : return XPathObjectType_XPATH_POINT;
49 : case XPATH_RANGE:
50 0 : return XPathObjectType_XPATH_RANGE;
51 : case XPATH_LOCATIONSET:
52 0 : return XPathObjectType_XPATH_LOCATIONSET;
53 : case XPATH_USERS:
54 0 : return XPathObjectType_XPATH_USERS;
55 : case XPATH_XSLT_TREE:
56 0 : return XPathObjectType_XPATH_XSLT_TREE;
57 : default:
58 0 : return XPathObjectType_XPATH_UNDEFINED;
59 : }
60 : }
61 :
62 200513 : CXPathObject::CXPathObject(
63 : ::rtl::Reference<DOM::CDocument> const& pDocument,
64 : ::osl::Mutex & rMutex,
65 : ::boost::shared_ptr<xmlXPathObject> const& pXPathObj)
66 : : m_pDocument(pDocument)
67 : , m_rMutex(rMutex)
68 : , m_pXPathObj(pXPathObj)
69 200513 : , m_XPathObjectType(lcl_GetType(pXPathObj.get()))
70 : {
71 200513 : }
72 :
73 : /**
74 : get object type
75 : */
76 8 : XPathObjectType CXPathObject::getObjectType() throw (RuntimeException, std::exception)
77 : {
78 8 : return m_XPathObjectType;
79 : }
80 :
81 : /**
82 : get the nodes from a nodelist type object
83 : */
84 : Reference< XNodeList > SAL_CALL
85 200450 : CXPathObject::getNodeList() throw (RuntimeException, std::exception)
86 : {
87 200450 : ::osl::MutexGuard const g(m_rMutex);
88 :
89 : Reference< XNodeList > const xRet(
90 200450 : new CNodeList(m_pDocument, m_rMutex, m_pXPathObj));
91 200450 : return xRet;
92 : }
93 :
94 : /**
95 : get value of a boolean object
96 : */
97 2 : sal_Bool SAL_CALL CXPathObject::getBoolean() throw (RuntimeException, std::exception)
98 : {
99 2 : ::osl::MutexGuard const g(m_rMutex);
100 :
101 2 : return xmlXPathCastToBoolean(m_pXPathObj.get()) != 0;
102 : }
103 :
104 : /**
105 : get number as byte
106 : */
107 1 : sal_Int8 SAL_CALL CXPathObject::getByte() throw (RuntimeException, std::exception)
108 : {
109 1 : ::osl::MutexGuard const g(m_rMutex);
110 :
111 1 : return (sal_Int8) xmlXPathCastToNumber(m_pXPathObj.get());
112 : }
113 :
114 : /**
115 : get number as short
116 : */
117 1 : sal_Int16 SAL_CALL CXPathObject::getShort() throw (RuntimeException, std::exception)
118 : {
119 1 : ::osl::MutexGuard const g(m_rMutex);
120 :
121 1 : return (sal_Int16) xmlXPathCastToNumber(m_pXPathObj.get());
122 : }
123 :
124 : /**
125 : get number as long
126 : */
127 3 : sal_Int32 SAL_CALL CXPathObject::getLong() throw (RuntimeException, std::exception)
128 : {
129 3 : ::osl::MutexGuard const g(m_rMutex);
130 :
131 3 : return (sal_Int32) xmlXPathCastToNumber(m_pXPathObj.get());
132 : }
133 :
134 : /**
135 : get number as hyper
136 : */
137 1 : sal_Int64 SAL_CALL CXPathObject::getHyper() throw (RuntimeException, std::exception)
138 : {
139 1 : ::osl::MutexGuard const g(m_rMutex);
140 :
141 1 : return (sal_Int64) xmlXPathCastToNumber(m_pXPathObj.get());
142 : }
143 :
144 : /**
145 : get number as float
146 : */
147 1 : float SAL_CALL CXPathObject::getFloat() throw (RuntimeException, std::exception)
148 : {
149 1 : ::osl::MutexGuard const g(m_rMutex);
150 :
151 1 : return (float) xmlXPathCastToNumber(m_pXPathObj.get());
152 : }
153 :
154 : /**
155 : get number as double
156 : */
157 1 : double SAL_CALL CXPathObject::getDouble() throw (RuntimeException, std::exception)
158 : {
159 1 : ::osl::MutexGuard const g(m_rMutex);
160 :
161 1 : return xmlXPathCastToNumber(m_pXPathObj.get());
162 : }
163 :
164 : /**
165 : get string value
166 : */
167 61 : OUString SAL_CALL CXPathObject::getString() throw (RuntimeException, std::exception)
168 : {
169 61 : ::osl::MutexGuard const g(m_rMutex);
170 :
171 : ::boost::shared_ptr<xmlChar const> str(
172 122 : xmlXPathCastToString(m_pXPathObj.get()), xmlFree);
173 61 : sal_Char const*const pS(reinterpret_cast<sal_Char const*>(str.get()));
174 122 : return OUString(pS, strlen(pS), RTL_TEXTENCODING_UTF8);
175 : }
176 :
177 : }
178 :
179 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|