File: Text.java

package info (click to toggle)
axis 1.4-12+deb6u1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze-lts
  • size: 51,832 kB
  • ctags: 44,779
  • sloc: java: 129,119; xml: 10,573; jsp: 983; sh: 84; cs: 36; makefile: 29
file content (231 lines) | stat: -rw-r--r-- 6,235 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/*
 * Copyright 2002-2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.axis.message;

import org.apache.axis.InternalException;
import org.w3c.dom.DOMException;

/**
 * A representation of a node whose value is text. A <CODE>
 *   Text</CODE> object may represent text that is content or text
 *   that is a comment.
 *
 * @author Davanum Srinivas (dims@yahoo.com)
 * @author Heejune Ahn      (cityboy@tmax.co.kr)
 */
public class Text extends NodeImpl implements javax.xml.soap.Text {

    public Text(org.w3c.dom.CharacterData data) {
        if ( data == null )
        {
           throw new IllegalArgumentException( "Text value may not be null." );
        }
        textRep = data;
    }

    public Text(String s) {
        try {
            org.w3c.dom.Document doc = org.apache.axis.utils.XMLUtils.newDocument();
            textRep = doc.createTextNode(s);
        } catch (javax.xml.parsers.ParserConfigurationException e) {
            throw new InternalException(e);
        }
    }

    public Text()
    {
        this((String)null);
    }

    /**
     * Retrieves whether this <CODE>Text</CODE> object
     * represents a comment.
     * @return  <CODE>true</CODE> if this <CODE>Text</CODE> object is
     *     a comment; <CODE>false</CODE> otherwise
     */
    public boolean isComment() {
        String temp = textRep.getNodeValue().trim();
        if(temp.startsWith("<!--") && temp.endsWith("-->"))
            return true;
        return false;
    }

    /**
     * Implementation of DOM TEXT Interface
     * *************************************************************
     */

    // Overriding the MessageElement Method, where it throws exeptions.
    public String getNodeValue() throws DOMException {
        return textRep.getNodeValue();
    }

    // Overriding the MessageElement Method, where it throws exeptions.
    public void setNodeValue(String nodeValue) throws DOMException{
        setDirty();
        textRep.setNodeValue(nodeValue);
    }

    /**
     * Use the textRep, and convert it to org.apache.axis.Text
     * in order to keep the Axis SOAP strcture after operation
     *
     * This work would be easier if constructor, Text(org.w3c.dom.Text)
     * is defined
     *
     * @since SAAJ 1.2
     * @param offset
     * @return
     * @throws DOMException
     */
    public org.w3c.dom.Text splitText(int offset) throws DOMException
    {
        int length = textRep.getLength();
        // take the first part, and save the second part for new Text
        // length check and exception will be thrown here, no need to duplicated check
        String tailData = textRep.substringData(offset,length);
        textRep.deleteData(offset,length);

        // insert the first part again as a new node
        Text tailText = new Text(tailData);
        org.w3c.dom.Node myParent = getParentNode();
        if(myParent != null){
            org.w3c.dom.NodeList brothers = myParent.getChildNodes();
            for(int i = 0;i  < brothers.getLength(); i++){
                if(brothers.item(i).equals(this)){
                    myParent.insertBefore(tailText, this);
                    return tailText;
                }
            }
        }
        return tailText;
    }

    /**
     * @since SAAJ 1.2
     */
    public String getData() throws DOMException {
        return textRep.getData();
    }

    /**
     * @since SAAJ 1.2
     */
    public void setData(String data) throws DOMException  {
        textRep.setData(data);
    }

    /**
     * @since SAAJ 1.2
     *
     * @return
     */
    public int getLength(){
        return textRep.getLength();
    }

    /**
     * @since SAAJ 1.2
     * @param offset
     * @param count
     * @return
     * @throws DOMException
     */
    public String substringData(int offset, int count)throws DOMException {
        return textRep.substringData(offset,count);
    }

    /**
     *
     * @since SAAJ 1.2
     * @param arg
     * @throws DOMException
     */
    public void appendData(String arg) throws DOMException {
        textRep.appendData(arg);
    }

    /**
     * @since SAAJ 1.2
     * @param offset
     * @param arg
     * @throws DOMException
     */
    public void insertData(int offset,  String arg)throws DOMException {
        textRep.insertData(offset, arg);
    }

    /**
     * @since SAAJ 1.2
     * @param offset
     * @param count
     * @param arg
     * @throws DOMException
     */
    public void replaceData(int offset, int count, String arg) throws DOMException   {
        textRep.replaceData(offset, count, arg);
    }

    /**
     * @since SAAJ 1.2
     * @param offset
     * @param count
     * @throws DOMException
     */
    public void deleteData(int offset, int count) throws DOMException {
        textRep.deleteData(offset, count);
    }

    public String toString()
    {
        return textRep.getNodeValue();
    }

    public boolean equals( Object obj )
    {
        if ( !( obj instanceof Text ) )
        {
            return false;
        }
        return this == obj || hashCode() == obj.hashCode();
    }

    public int hashCode()
    {
        if ( textRep == null )
        {
           return -1;
        }
        return ( textRep.getData() != null ? textRep.getData().hashCode() : 0 );
    }

    /**
     *  DOM Level 3 stubs
     */

    public String getWholeText() {
        throw new RuntimeException("not implemented");
    }

    public boolean isElementContentWhitespace() {
        throw new RuntimeException("not implemented");
    }

    public org.w3c.dom.Text replaceWholeText(String content) {
        throw new RuntimeException("not implemented");
    }
}