001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.axis2.saaj;
020:
021: import org.apache.axiom.om.OMContainer;
022: import org.apache.axiom.om.OMException;
023: import org.apache.axiom.om.impl.dom.DOOMAbstractFactory;
024: import org.apache.axiom.om.impl.dom.TextImpl;
025: import org.w3c.dom.DOMException;
026:
027: import javax.xml.soap.SOAPElement;
028: import javax.xml.soap.Text;
029: import javax.xml.stream.XMLStreamException;
030:
031: public class TextImplEx extends NodeImplEx implements Text {
032:
033: //TODO: assign textNode
034:
035: private TextImpl textNode;
036:
037: private org.w3c.dom.Node previousSibling;
038: private org.w3c.dom.Node nextSibling;
039:
040: public TextImplEx(String data, SOAPElement parent) {
041: super (((SOAPElementImpl) parent).getOMFactory());
042: textNode = (TextImpl) DOOMAbstractFactory.getOMFactory()
043: .createOMText(data);
044: this .parentElement = parent;
045: }
046:
047: public TextImplEx(String data, SOAPElement parent,
048: org.w3c.dom.Node prevSibling, org.w3c.dom.Node nextSibling) {
049: super (((SOAPElementImpl) parent).getOMFactory());
050: textNode = (TextImpl) DOOMAbstractFactory.getOMFactory()
051: .createOMText(data);
052: this .parentElement = parent;
053: this .previousSibling = prevSibling;
054: this .nextSibling = nextSibling;
055: }
056:
057: public void setNextSibling(org.w3c.dom.Node nextSibling) {
058: this .nextSibling = nextSibling;
059: }
060:
061: public void setPreviousSibling(org.w3c.dom.Node previousSibling) {
062: this .previousSibling = previousSibling;
063: }
064:
065: /**
066: * Retrieves whether this <CODE>Text</CODE> object represents a comment.
067: *
068: * @return <CODE>true</CODE> if this <CODE>Text</CODE> object is a comment; <CODE>false</CODE>
069: * otherwise
070: */
071: public boolean isComment() {
072: String value = textNode.getText();
073: return value.startsWith("<!--") && value.endsWith("-->");
074: }
075:
076: /** The name of this node, depending on its type; see the table above. */
077: public String getNodeName() {
078: return textNode.getNodeName();
079: }
080:
081: /** A code representing the type of the underlying object, as defined above. */
082: public short getNodeType() {
083: return textNode.getNodeType();
084: }
085:
086: /**
087: * Breaks this node into two nodes at the specified <code>offset</code>, keeping both in the
088: * tree as siblings. After being split, this node will contain all the content up to the
089: * <code>offset</code> point. A new node of the same type, which contains all the content at and
090: * after the <code>offset</code> point, is returned. If the original node had a parent node, the
091: * new node is inserted as the next sibling of the original node. When the <code>offset</code>
092: * is equal to the length of this node, the new node has no data.
093: *
094: * @param offset The 16-bit unit offset at which to split, starting from <code>0</code>.
095: * @return The new node, of the same type as this node.
096: * @throws DOMException INDEX_SIZE_ERR: Raised if the specified offset is negative or greater
097: * than the number of 16-bit units in <code>data</code>.
098: * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
099: */
100: public org.w3c.dom.Text splitText(int offset) throws DOMException {
101: return textNode.splitText(offset);
102: }
103:
104: public boolean isElementContentWhitespace() {
105: // TODO - Fixme.
106: throw new UnsupportedOperationException("TODO");
107: }
108:
109: public String getWholeText() {
110: // TODO - Fixme.
111: throw new UnsupportedOperationException("TODO");
112: }
113:
114: public org.w3c.dom.Text replaceWholeText(String content)
115: throws DOMException {
116: // TODO - Fixme.
117: throw new UnsupportedOperationException("TODO");
118: }
119:
120: /**
121: * The character data of the node that implements this interface. The DOM implementation may not
122: * put arbitrary limits on the amount of data that may be stored in a <code>CharacterData</code>
123: * node. However, implementation limits may mean that the entirety of a node's data may not fit
124: * into a single <code>DOMString</code>. In such cases, the user may call
125: * <code>substringData</code> to retrieve the data in appropriately sized pieces.
126: *
127: * @throws DOMException NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
128: * @throws DOMException DOMSTRING_SIZE_ERR: Raised when it would return more characters than fit
129: * in a <code>DOMString</code> variable on the implementation platform.
130: */
131: public String getData() throws DOMException {
132: return textNode.getData();
133: }
134:
135: /**
136: * The character data of the node that implements this interface. The DOM implementation may not
137: * put arbitrary limits on the amount of data that may be stored in a <code>CharacterData</code>
138: * node. However, implementation limits may mean that the entirety of a node's data may not fit
139: * into a single <code>DOMString</code>. In such cases, the user may call
140: * <code>substringData</code> to retrieve the data in appropriately sized pieces.
141: *
142: * @throws DOMException NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
143: * @throws DOMException DOMSTRING_SIZE_ERR: Raised when it would return more characters than fit
144: * in a <code>DOMString</code> variable on the implementation platform.
145: */
146: public void setData(String data) throws DOMException {
147: textNode.setData(data);
148: }
149:
150: /**
151: * Extracts a range of data from the node.
152: *
153: * @param offset Start offset of substring to extract.
154: * @param count The number of 16-bit units to extract.
155: * @return The specified substring. If the sum of <code>offset</code> and <code>count</code>
156: * exceeds the <code>length</code>, then all 16-bit units to the end of the data are
157: * returned.
158: * @throws DOMException INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is negative
159: * or greater than the number of 16-bit units in <code>data</code>, or if
160: * the specified <code>count</code> is negative. <br>DOMSTRING_SIZE_ERR:
161: * Raised if the specified range of text does not fit into a
162: * <code>DOMString</code>.
163: */
164: public String substringData(int offset, int count)
165: throws DOMException {
166: return textNode.substringData(offset, count);
167: }
168:
169: /**
170: * Append the string to the end of the character data of the node. Upon success,
171: * <code>data</code> provides access to the concatenation of <code>data</code> and the
172: * <code>DOMString</code> specified.
173: *
174: * @param value The <code>DOMString</code> to append.
175: * @throws DOMException NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
176: */
177: public void appendData(String value) throws DOMException {
178: textNode.appendData(value);
179: }
180:
181: /**
182: * Insert a string at the specified 16-bit unit offset.
183: *
184: * @param offset The character offset at which to insert.
185: * @param data The <code>DOMString</code> to insert.
186: * @throws DOMException INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is negative
187: * or greater than the number of 16-bit units in <code>data</code>.
188: * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
189: */
190: public void insertData(int offset, String data) throws DOMException {
191: textNode.insertData(offset, data);
192: }
193:
194: /**
195: * Remove a range of 16-bit units from the node. Upon success, <code>data</code> and
196: * <code>length</code> reflect the change.
197: *
198: * @param offset The offset from which to start removing.
199: * @param count The number of 16-bit units to delete. If the sum of <code>offset</code> and
200: * <code>count</code> exceeds <code>length</code> then all 16-bit units from
201: * <code>offset</code> to the end of the data are deleted.
202: * @throws DOMException INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is negative
203: * or greater than the number of 16-bit units in <code>data</code>, or if
204: * the specified <code>count</code> is negative. <br>NO_MODIFICATION_ALLOWED_ERR:
205: * Raised if this node is readonly.
206: */
207: public void deleteData(int offset, int count) throws DOMException {
208: textNode.deleteData(offset, count);
209: }
210:
211: /**
212: * Replace the characters starting at the specified 16-bit unit offset with the specified
213: * string.
214: *
215: * @param offset The offset from which to start replacing.
216: * @param count The number of 16-bit units to replace. If the sum of <code>offset</code> and
217: * <code>count</code> exceeds <code>length</code>, then all 16-bit units to the
218: * end of the data are replaced; (i.e., the effect is the same as a
219: * <code>remove</code> method call with the same range, followed by an
220: * <code>append</code> method invocation).
221: * @param data The <code>DOMString</code> with which the range must be replaced.
222: * @throws DOMException INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is negative
223: * or greater than the number of 16-bit units in <code>data</code>, or if
224: * the specified <code>count</code> is negative. <br>NO_MODIFICATION_ALLOWED_ERR:
225: * Raised if this node is readonly.
226: */
227: public void replaceData(int offset, int count, String data)
228: throws DOMException {
229: textNode.replaceData(offset, count, data);
230: }
231:
232: /* (non-Javadoc)
233: * @see org.apache.axiom.om.impl.OMNodeEx#setParent(org.apache.axiom.om.OMContainer)
234: */
235: public void setParent(OMContainer element) {
236: textNode.setParent(element);
237: }
238:
239: /* (non-Javadoc)
240: * @see org.apache.axiom.om.OMNode#getParent()
241: */
242: public OMContainer getParent() {
243: return textNode.getParent();
244: }
245:
246: /* (non-Javadoc)
247: * @see org.apache.axiom.om.OMNode#discard()
248: */
249: public void discard() throws OMException {
250: textNode.discard();
251: }
252:
253: public void internalSerialize(
254: javax.xml.stream.XMLStreamWriter writer)
255: throws XMLStreamException {
256: textNode.internalSerialize(writer);
257: }
258:
259: public void internalSerializeAndConsume(
260: javax.xml.stream.XMLStreamWriter writer)
261: throws XMLStreamException {
262: textNode.internalSerializeAndConsume(writer);
263: }
264:
265: /**
266: * Retrieve the text value (data) of this
267: *
268: * @return The text value (data) of this
269: */
270: public String getValue() {
271: return textNode.getData();
272: }
273:
274: public String getNodeValue() {
275: return textNode.getData();
276: }
277:
278: /**
279: * If this is a Text node then this method will set its value, otherwise it sets the value of
280: * the immediate (Text) child of this node. The value of the immediate child of this node can be
281: * set only if, there is one child node and that node is a Text node, or if there are no
282: * children in which case a child Text node will be created.
283: *
284: * @param value the text to set
285: * @throws IllegalStateException if the node is not a Text node and either has more than one
286: * child node or has a child node that is not a Text node
287: */
288: public void setValue(String value) {
289: textNode.setData(value);
290: }
291:
292: public void setNodeValue(String value) {
293: textNode.setData(value);
294: }
295:
296: public String toString() {
297: return getValue();
298: }
299:
300: public org.w3c.dom.Node getNextSibling() {
301: return toSAAJNode(nextSibling);
302: }
303:
304: public org.w3c.dom.Node getPreviousSibling() {
305: return toSAAJNode(previousSibling);
306: }
307: }
|