1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the  "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 #include "XalanSourceTreeText.hpp"
19 
20 
21 
22 #include <xalanc/XalanDOM/XalanDOMException.hpp>
23 
24 
25 
26 #include <xalanc/PlatformSupport/DOMStringHelper.hpp>
27 
28 
29 
30 #include "XalanSourceTreeComment.hpp"
31 #include "XalanSourceTreeDocumentFragment.hpp"
32 #include "XalanSourceTreeElement.hpp"
33 #include "XalanSourceTreeProcessingInstruction.hpp"
34 #include "XalanSourceTreeHelper.hpp"
35 
36 
37 
38 namespace XALAN_CPP_NAMESPACE {
39 
40 
41 
42 static const XalanDOMString     s_emptyString(XalanMemMgrs::getDummyMemMgr());
43 
44 
45 
XalanSourceTreeText(const XalanDOMString & theData,XalanNode * theParentNode,XalanNode * thePreviousSibling,XalanNode * theNextSibling,IndexType theIndex)46 XalanSourceTreeText::XalanSourceTreeText(
47             const XalanDOMString&   theData,
48             XalanNode*              theParentNode,
49             XalanNode*              thePreviousSibling,
50             XalanNode*              theNextSibling,
51             IndexType               theIndex) :
52     XalanText(),
53     m_data(theData),
54     m_parentNode(theParentNode),
55     m_previousSibling(thePreviousSibling),
56     m_nextSibling(theNextSibling),
57     m_index(theIndex)
58 {
59 }
60 
61 
62 
~XalanSourceTreeText()63 XalanSourceTreeText::~XalanSourceTreeText()
64 {
65 }
66 
67 
68 
69 const XalanDOMString&
getNodeName() const70 XalanSourceTreeText::getNodeName() const
71 {
72     return s_nameString;
73 }
74 
75 
76 
77 const XalanDOMString&
getNodeValue() const78 XalanSourceTreeText::getNodeValue() const
79 {
80     return m_data;
81 }
82 
83 
84 
85 XalanSourceTreeText::NodeType
getNodeType() const86 XalanSourceTreeText::getNodeType() const
87 {
88     return TEXT_NODE;
89 }
90 
91 
92 
93 XalanNode*
getParentNode() const94 XalanSourceTreeText::getParentNode() const
95 {
96     return m_parentNode;
97 }
98 
99 
100 
101 const XalanNodeList*
getChildNodes() const102 XalanSourceTreeText::getChildNodes() const
103 {
104     throw XalanDOMException(XalanDOMException::NOT_SUPPORTED_ERR);
105 
106     // Dummy return value...
107     return 0;
108 }
109 
110 
111 
112 XalanNode*
getFirstChild() const113 XalanSourceTreeText::getFirstChild() const
114 {
115     return 0;
116 }
117 
118 
119 
120 XalanNode*
getLastChild() const121 XalanSourceTreeText::getLastChild() const
122 {
123     return 0;
124 }
125 
126 
127 
128 XalanNode*
getPreviousSibling() const129 XalanSourceTreeText::getPreviousSibling() const
130 {
131     return m_previousSibling;
132 }
133 
134 
135 
136 XalanNode*
getNextSibling() const137 XalanSourceTreeText::getNextSibling() const
138 {
139     return m_nextSibling;
140 }
141 
142 
143 
144 const XalanNamedNodeMap*
getAttributes() const145 XalanSourceTreeText::getAttributes() const
146 {
147     return 0;
148 }
149 
150 
151 
152 XalanDocument*
getOwnerDocument() const153 XalanSourceTreeText::getOwnerDocument() const
154 {
155     assert(m_parentNode != 0);
156 
157     return m_parentNode->getOwnerDocument();
158 }
159 
160 
161 
162 const XalanDOMString&
getNamespaceURI() const163 XalanSourceTreeText::getNamespaceURI() const
164 {
165     return s_emptyString;
166 }
167 
168 
169 
170 const XalanDOMString&
getPrefix() const171 XalanSourceTreeText::getPrefix() const
172 {
173     return s_emptyString;
174 }
175 
176 
177 
178 const XalanDOMString&
getLocalName() const179 XalanSourceTreeText::getLocalName() const
180 {
181     return s_emptyString;
182 }
183 
184 
185 
186 bool
isIndexed() const187 XalanSourceTreeText::isIndexed() const
188 {
189     return true;
190 }
191 
192 
193 
194 XalanSourceTreeText::IndexType
getIndex() const195 XalanSourceTreeText::getIndex() const
196 {
197     return m_index;
198 }
199 
200 
201 
202 const XalanDOMString&
getData() const203 XalanSourceTreeText::getData() const
204 {
205     return m_data;
206 }
207 
208 
209 
210 bool
isWhitespace() const211 XalanSourceTreeText::isWhitespace() const
212 {
213     return false;
214 }
215 
216 
217 
218 void
setParent(XalanSourceTreeElement * theParent)219 XalanSourceTreeText::setParent(XalanSourceTreeElement*  theParent)
220 {
221     m_parentNode = theParent;
222 }
223 
224 
225 
226 void
setParent(XalanSourceTreeDocumentFragment * theParent)227 XalanSourceTreeText::setParent(XalanSourceTreeDocumentFragment* theParent)
228 {
229     m_parentNode = theParent;
230 }
231 
232 
233 
234 void
setPreviousSibling(XalanSourceTreeComment * thePreviousSibling)235 XalanSourceTreeText::setPreviousSibling(XalanSourceTreeComment*     thePreviousSibling)
236 {
237     m_previousSibling = thePreviousSibling;
238 }
239 
240 
241 
242 void
setPreviousSibling(XalanSourceTreeElement * thePreviousSibling)243 XalanSourceTreeText::setPreviousSibling(XalanSourceTreeElement*     thePreviousSibling)
244 {
245     m_previousSibling = thePreviousSibling;
246 }
247 
248 
249 
250 void
setPreviousSibling(XalanSourceTreeProcessingInstruction * thePreviousSibling)251 XalanSourceTreeText::setPreviousSibling(XalanSourceTreeProcessingInstruction*   thePreviousSibling)
252 {
253     m_previousSibling = thePreviousSibling;
254 }
255 
256 
257 
258 void
setPreviousSibling(XalanSourceTreeText * thePreviousSibling)259 XalanSourceTreeText::setPreviousSibling(XalanSourceTreeText*    thePreviousSibling)
260 {
261     m_previousSibling = thePreviousSibling;
262 }
263 
264 
265 
266 void
appendSiblingNode(XalanSourceTreeComment * theSibling)267 XalanSourceTreeText::appendSiblingNode(XalanSourceTreeComment*  theSibling)
268 {
269     XalanSourceTreeHelper::appendSibling(this, m_nextSibling, theSibling);
270 }
271 
272 
273 
274 void
appendSiblingNode(XalanSourceTreeElement * theSibling)275 XalanSourceTreeText::appendSiblingNode(XalanSourceTreeElement*  theSibling)
276 {
277     XalanSourceTreeHelper::appendSibling(this, m_nextSibling, theSibling);
278 }
279 
280 
281 
282 void
appendSiblingNode(XalanSourceTreeProcessingInstruction * theSibling)283 XalanSourceTreeText::appendSiblingNode(XalanSourceTreeProcessingInstruction*    theSibling)
284 {
285     XalanSourceTreeHelper::appendSibling(this, m_nextSibling, theSibling);
286 }
287 
288 
289 
290 void
appendSiblingNode(XalanSourceTreeText * theSibling)291 XalanSourceTreeText::appendSiblingNode(XalanSourceTreeText*     theSibling)
292 {
293     XalanSourceTreeHelper::appendSibling(this, m_nextSibling, theSibling);
294 }
295 
296 
297 
298 static XalanDOMString   s_staticNameString(XalanMemMgrs::getDummyMemMgr());
299 
300 
301 
302 const XalanDOMString&   XalanSourceTreeText::s_nameString = s_staticNameString;
303 
304 
305 
306 const XalanDOMChar  s_text[] =
307 {
308     XalanUnicode::charNumberSign,
309     XalanUnicode::charLetter_t,
310     XalanUnicode::charLetter_e,
311     XalanUnicode::charLetter_x,
312     XalanUnicode::charLetter_t,
313     0
314 };
315 
316 
317 
318 void
initialize(MemoryManager & theManager)319 XalanSourceTreeText::initialize(MemoryManager& theManager)
320 {
321     XalanDOMString theBuffer(s_text, theManager);
322 
323     s_staticNameString.swap(theBuffer);
324 }
325 
326 
327 
328 void
terminate()329 XalanSourceTreeText::terminate()
330 {
331     releaseMemory(s_staticNameString, XalanMemMgrs::getDummyMemMgr());
332 }
333 
334 
335 
336 }
337