Node startHighlight,
Node endHighlight) {
Enumeration keys = _arrays.keys();
while (keys.hasMoreElements()) {
Vector children = new Vector();
Node textNode = (Node)keys.nextElement();
IntegerArray numbers = (IntegerArray)_arrays.get(textNode);
numbers.sort(); // word numbers in ascending order
String text = textNode.getData();
tokenizer.setText(text);
int tokenNumber = 0;
int lastOffset = 0;
for (int i = 0; i < numbers.cardinality(); i++) {
int n = numbers.at(i);
Token token;
do {
token = tokenizer.nextToken();
}
while (++tokenNumber < n);
int start = token.getStart();
int end = token.getEnd();
if (lastOffset < start)
children
.addElement(factory.makeTextNode(text.substring(lastOffset, start)));
children.addElement(startHighlight);
children.addElement(factory.makeTextNode(token.getData()));
children.addElement(endHighlight);
lastOffset = end;
}
if (lastOffset < text.length())
children.addElement(factory.makeTextNode(text.substring(lastOffset)));
Node2[] childrenArray = new Node2[children.size()];
children.toArray(childrenArray);
Node highlighted = factory.makeSubstituteElement(highlightedName,
childrenArray,
textNode);
Node2 parent = (Node2)textNode.getParent();
for (int i = 0; i < childrenArray.length; i++)
((Node2)childrenArray[i]).setParent(highlighted);