1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sourceforge.jeuclid.biparser;
20
21 import org.w3c.dom.Document;
22 import org.w3c.dom.Node;
23
24
25
26
27
28
29
30 public final class EmptyNode extends AbstractBiNode {
31
32
33
34
35
36
37
38 public EmptyNode(final int length) {
39 this.setLength(length);
40 }
41
42
43
44
45
46
47 public BiType getType() {
48 return BiType.EMPTY;
49 }
50
51
52
53
54
55
56 public void insert(final BiTree biTree, final int offset, final int length,
57 final int totalOffset) throws ReparseException,
58 NonIncrementalElementException {
59 int position;
60 String insert;
61
62
63
64
65
66 if (offset <= this.getLength()) {
67
68 position = totalOffset + offset;
69 insert = biTree.getText().substring(position, position + length);
70
71 if (insert.contains("<") || insert.contains(">")) {
72
73 throw new ReparseException();
74 }
75
76 this.changeLengthRec(length);
77
78 } else {
79
80 this.forwardToSibling(true, biTree, offset - this.getLength(),
81 length, totalOffset + this.getLength());
82 }
83 }
84
85
86
87
88 public void remove(final BiTree biTree, final int offset, final int length,
89 final int totalOffset) throws ReparseException,
90 NonIncrementalElementException {
91
92
93
94
95 if (offset <= this.getLength()) {
96
97 if (offset == 0 && length >= this.getLength()) {
98
99 throw new ReparseException();
100
101 } else {
102
103
104 if (offset + length <= this.getLength()) {
105 this.changeLengthRec(-length);
106
107 } else {
108
109 this.changeLengthRec(offset - this.getLength());
110
111
112 this.forwardToSibling(false, biTree, 0, offset + length
113 - this.getLength(), totalOffset + this.getLength());
114 }
115 }
116 } else {
117
118 this.forwardToSibling(false, biTree, offset - this.getLength(),
119 length, totalOffset + this.getLength());
120 }
121 }
122
123
124
125
126
127
128
129
130 public Node createDOMSubtree(final Document doc) {
131 return null;
132 }
133
134
135 @Override
136 public TextPosition searchNode(final Node node, final int totalOffset) {
137
138 if (this.getSibling() != null) {
139 return this.getSibling().searchNode(node,
140 totalOffset + this.getLength());
141 }
142
143 return null;
144 }
145
146 @Override
147 public String toString() {
148 final StringBuffer sb = new StringBuffer(32);
149
150 sb.append("[EMTPY length: ");
151 sb.append(this.getLength());
152 sb.append(']');
153
154 return sb.toString();
155 }
156
157
158 public String toString(final int level) {
159 final StringBuffer sb = new StringBuffer(32);
160 final String nl = System.getProperty("line.separator");
161
162 sb.append(this.formatLength());
163 sb.append(':');
164 for (int i = 0; i <= level; i++) {
165 sb.append(' ');
166 }
167
168 sb.append("EMTPY");
169
170 if (this.getSibling() != null) {
171 sb.append(nl);
172 sb.append(this.getSibling().toString(level));
173 }
174
175 return sb.toString();
176 }
177 }