001 /* 002 * Copyright 2009 - 2010 JEuclid, http://jeuclid.sf.net 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 /* $Id $ */ 018 019 package net.sourceforge.jeuclid.biparser; 020 021 import org.w3c.dom.Document; 022 import org.w3c.dom.Node; 023 024 /** 025 * this interface is used to store typcial information about a xml-node. 026 * 027 * @version $Revision: 0b66106c7ff7 $ 028 * 029 */ 030 public interface IBiNode { 031 032 /** 033 * get previous node, null if node is root. 034 * 035 * @return previous 036 */ 037 IBiNode getPrevious(); 038 039 /** 040 * set previous for this node. 041 * 042 * @param prev 043 * previous node for this node 044 */ 045 void setPrevious(final IBiNode prev); 046 047 /** 048 * get parent node for this node. 049 * 050 * @return parent 051 */ 052 BiNode getParent(); 053 054 /** 055 * get sibling node, can be null. 056 * 057 * @return sibling 058 */ 059 IBiNode getSibling(); 060 061 /** 062 * set sibling for this node and set previous of sibling to this. 063 * 064 * @param sibl 065 * new sibling for this node 066 */ 067 void setSibling(final IBiNode sibl); 068 069 /** 070 * add sibling to a node, not possible at a textnode. if node already has a 071 * sibling, forward to sibling. 072 * 073 * @param sibl 074 * new sibling for this node 075 */ 076 void addSibling(final IBiNode sibl); 077 078 /** 079 * get reference to node in DOM-tree. 080 * 081 * @return node in DOM-tree 082 */ 083 Node getNode(); 084 085 /** 086 * set reference to node in DOM-tree. 087 * 088 * @param n 089 * reference in DOM-tree 090 */ 091 void setNode(final Node n); 092 093 /** 094 * get length of node (number of characters). 095 * 096 * @return length of node 097 */ 098 int getLength(); 099 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 }