1 /*
2 * Copyright 2009 - 2010 JEuclid, http://jeuclid.sf.net
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 /* $Id $ */
18
19 package net.sourceforge.jeuclid.biparser;
20
21 import org.w3c.dom.Document;
22 import org.w3c.dom.Node;
23
24 /**
25 * this interface is used to store typcial information about a xml-node.
26 *
27 * @version $Revision: 0b66106c7ff7 $
28 *
29 */
30 public interface IBiNode {
31
32 /**
33 * get previous node, null if node is root.
34 *
35 * @return previous
36 */
37 IBiNode getPrevious();
38
39 /**
40 * set previous for this node.
41 *
42 * @param prev
43 * previous node for this node
44 */
45 void setPrevious(final IBiNode prev);
46
47 /**
48 * get parent node for this node.
49 *
50 * @return parent
51 */
52 BiNode getParent();
53
54 /**
55 * get sibling node, can be null.
56 *
57 * @return sibling
58 */
59 IBiNode getSibling();
60
61 /**
62 * set sibling for this node and set previous of sibling to this.
63 *
64 * @param sibl
65 * new sibling for this node
66 */
67 void setSibling(final IBiNode sibl);
68
69 /**
70 * add sibling to a node, not possible at a textnode. if node already has a
71 * sibling, forward to sibling.
72 *
73 * @param sibl
74 * new sibling for this node
75 */
76 void addSibling(final IBiNode sibl);
77
78 /**
79 * get reference to node in DOM-tree.
80 *
81 * @return node in DOM-tree
82 */
83 Node getNode();
84
85 /**
86 * set reference to node in DOM-tree.
87 *
88 * @param n
89 * reference in DOM-tree
90 */
91 void setNode(final Node n);
92
93 /**
94 * get length of node (number of characters).
95 *
96 * @return length of node
97 */
98 int getLength();
99
100 /**
101 * set length of node.
102 *
103 * @param len
104 * to set
105 */
106 void setLength(final int len);
107
108 /**
109 * change length of node and recursive of all parents.
110 *
111 * @param change
112 * changevalue (can be positive or negative)
113 */
114 void changeLengthRec(final int change);
115
116 /**
117 * get the type of node, can be BiNode, EmptyNode or TextNode.
118 *
119 * @return type of node
120 */
121 BiType getType();
122
123 /**
124 * insert characters to node.
125 *
126 * @param biTree
127 * reference to BiTree to which this node contains
128 * @param offset
129 * position to insert characters
130 * @param len
131 * number of characters to insert
132 * @param totalOffset
133 * offset of node to begin of text
134 * @throws ReparseException
135 * if a reparse at upper level is needed
136 * @throws NonIncrementalElementException
137 * if the subtree contains an element which cannot be
138 * incrementally updated.
139 */
140 void insert(BiTree biTree, int offset, int len, int totalOffset)
141 throws ReparseException, NonIncrementalElementException;
142
143 /**
144 * remove characters from node.
145 *
146 * @param biTree
147 * reference to BiTree to which this node contains
148 * @param offset
149 * position to remove characters
150 * @param len
151 * number of characters to remove
152 * @param totalOffset
153 * offset of node to begin of text
154 * @throws ReparseException
155 * if a reparse at upper level is needed
156 * @throws NonIncrementalElementException
157 * if the subtree contains an element which cannot be
158 * incrementally updated.
159 */
160 void remove(BiTree biTree, int offset, int len, int totalOffset)
161 throws ReparseException, NonIncrementalElementException;
162
163 /**
164 * helper method to insert or remove characters.
165 *
166 * @param insert
167 * if true call insert-method else remove-method
168 * @param biTree
169 * reference to BiTree to which this node contains
170 * @param offset
171 * position to insert/remove characters
172 * @param len
173 * number of characters to insert/remove
174 * @param totalOffset
175 * offset of node to begin of text
176 * @throws ReparseException
177 * if a reparse at upper level is needed
178 * @throws NonIncrementalElementException
179 * if the subtree contains an element which cannot be
180 * incrementally updated.
181 */
182 void forwardToSibling(final boolean insert, final BiTree biTree,
183 final int offset, final int len, final int totalOffset)
184 throws ReparseException, NonIncrementalElementException;
185
186 /**
187 * create a DOM-tree from node.
188 *
189 * @param doc
190 * Document to create DOM-tree
191 * @return root of DOM-tree
192 */
193 Node createDOMSubtree(Document doc);
194
195 /**
196 * search a DOM node in this node. if nodes are equal return offset to begin
197 * of inputtext, else null
198 *
199 * @param n
200 * DOM node to search for
201 * @param totalOffset
202 * offset of node to begin of inputtext
203 * @return position of node in inputtext
204 */
205 TextPosition searchNode(final Node n, final int totalOffset);
206
207 /**
208 * print biNode.
209 *
210 * @param level
211 * level of recursion tree
212 * @return biNode
213 */
214 String toString(int level);
215
216 /**
217 * helper method for outputting the length of node.
218 *
219 * @return formatted output of length
220 */
221 String formatLength();
222 }