|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Result of XPath expression |
|
15 // |
|
16 |
|
17 #include <xml/dom/xmlengxpathresult.h> |
|
18 #include <stdapis/libxml2/libxml2_globals.h> |
|
19 #include <stdapis/libxml2/libxml2_xpath.h> |
|
20 #include "xmlengdomdefs.h" |
|
21 #include <xml/utils/xmlengmem.h> |
|
22 #include <xml/utils/xmlengxestrings.h> |
|
23 |
|
24 #define RESULT_OBJ (static_cast<xmlXPathObjectPtr>(iInternal)) |
|
25 |
|
26 // ----------------------------------------------------------------------------- |
|
27 // Default constructor |
|
28 // ----------------------------------------------------------------------------- |
|
29 // |
|
30 EXPORT_C RXmlEngXPathResult::RXmlEngXPathResult():iInternal(NULL) |
|
31 { |
|
32 } |
|
33 |
|
34 // --------------------------------------------------------------------------- |
|
35 // Frees any allocated memory by this instance |
|
36 // --------------------------------------------------------------------------- |
|
37 // |
|
38 EXPORT_C void RXmlEngXPathResult::Free() |
|
39 { |
|
40 xmlXPathFreeObject(RESULT_OBJ); |
|
41 } |
|
42 |
|
43 // --------------------------------------------------------------------------- |
|
44 // Retrieves type of result |
|
45 // @note Always check type of result before use it |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 EXPORT_C RXmlEngXPathResult::TXmlEngXPathResultType RXmlEngXPathResult::Type() const |
|
49 { |
|
50 return (TXmlEngXPathResultType)RESULT_OBJ->type; |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // Retrieves node-set result. |
|
55 // Non-RXmlEngNodeSet result will return NULL. No conversion is done from other |
|
56 // types. |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 EXPORT_C RXmlEngNodeSet RXmlEngXPathResult::AsNodeSet() const |
|
60 { |
|
61 return RXmlEngNodeSet(RESULT_OBJ->nodesetval); |
|
62 } |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 // Retrieves copy of result as TXmlEngParserString. |
|
66 // In this version of API this method will make conversion from other types of |
|
67 // XPath result. In the future release there will be separate method for |
|
68 // conversion (this method will return TDOMString and conversion method - |
|
69 // TString) |
|
70 // NOTE: Returns a pointer to the copy of the string, the caller must free it |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 EXPORT_C void RXmlEngXPathResult::AsStringL(RBuf8& aOutput) const |
|
74 { |
|
75 xmlChar* copy = NULL; |
|
76 if (RESULT_OBJ->type == XPATH_STRING) |
|
77 { |
|
78 if(RESULT_OBJ->stringval) |
|
79 { |
|
80 copy = xmlStrdup(RESULT_OBJ->stringval); |
|
81 OOM_IF_NULL(copy); |
|
82 } |
|
83 } |
|
84 else |
|
85 { |
|
86 copy = xmlXPathCastToString(RESULT_OBJ); |
|
87 if(OOM_FLAG) |
|
88 { |
|
89 if(copy) |
|
90 xmlFree(copy); |
|
91 OOM_HAPPENED; |
|
92 } |
|
93 } |
|
94 xmlCharAssignToRbuf8L(aOutput,copy); |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // Retrieves numeric value of the result. |
|
99 // Conversion occurs as XPath spec says if the result is not of ENumber type |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 EXPORT_C TReal RXmlEngXPathResult::AsNumber() const |
|
103 { |
|
104 if (RESULT_OBJ->type == XPATH_NUMBER) |
|
105 return RESULT_OBJ->floatval; |
|
106 else |
|
107 return xmlXPathCastToNumber(RESULT_OBJ); |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------------------------- |
|
111 // Retrieves numeric value of the result. |
|
112 // Conversion occurs as XPath spec says if the result is not of EBoolean type |
|
113 // --------------------------------------------------------------------------- |
|
114 // |
|
115 EXPORT_C TBool RXmlEngXPathResult::AsBoolean() const |
|
116 { |
|
117 if (RESULT_OBJ->type == XPATH_BOOLEAN) |
|
118 return RESULT_OBJ->boolval; |
|
119 else |
|
120 return xmlXPathCastToBoolean(RESULT_OBJ); |
|
121 } |
|
122 |
|
123 // ----------------------------------------------------------------------------- |
|
124 // Constructor |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 RXmlEngXPathResult::RXmlEngXPathResult(void* aData):iInternal(aData) |
|
128 { |
|
129 } |