01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.xml.client.impl;
17:
18: import com.google.gwt.core.client.JavaScriptException;
19: import com.google.gwt.core.client.JavaScriptObject;
20: import com.google.gwt.xml.client.DOMException;
21: import com.google.gwt.xml.client.Text;
22:
23: /**
24: * This class is the implementation of the XML DOM Text interface.
25: */
26: class TextImpl extends CharacterDataImpl implements Text {
27:
28: protected TextImpl(JavaScriptObject o) {
29: super (o);
30: }
31:
32: /**
33: * This function delegates to the native method <code>splitText</code> in
34: * XMLParserImpl.
35: */
36: public Text splitText(int offset) {
37: try {
38: return (Text) NodeImpl.build(XMLParserImpl.splitText(this
39: .getJsObject(), offset));
40: } catch (JavaScriptException e) {
41: throw new DOMNodeException(
42: DOMException.INVALID_MODIFICATION_ERR, e, this );
43: }
44: }
45:
46: @Override
47: public String toString() {
48: StringBuffer b = new StringBuffer();
49: String[] x = getData().split("(?=[;&<>\'\"])", -1);
50: for (int i = 0; i < x.length; i++) {
51: if (x[i].startsWith(";")) {
52: b.append(";");
53: b.append(x[i].substring(1));
54: } else if (x[i].startsWith("&")) {
55: b.append("&");
56: b.append(x[i].substring(1));
57: } else if (x[i].startsWith("\"")) {
58: b.append(""");
59: b.append(x[i].substring(1));
60: } else if (x[i].startsWith("'")) {
61: b.append("'");
62: b.append(x[i].substring(1));
63: } else if (x[i].startsWith("<")) {
64: b.append("<");
65: b.append(x[i].substring(1));
66: } else if (x[i].startsWith(">")) {
67: b.append(">");
68: b.append(x[i].substring(1));
69: } else {
70: b.append(x[i]);
71: }
72: }
73: return b.toString();
74: }
75: }
|