root.clear();
if (textile == null || textile.length() == 0) {
return root;
}
IdGenerator idGenerator = new IdGenerator();
OutlineItem current = root;
Matcher matcher = ITEM_PATTERN.matcher(textile);
while (matcher.find()) {
int offset = matcher.start();
int length = matcher.end()-offset;
String kind = matcher.group(1);
String levelString = matcher.group(2);
String label = matcher.group(3);
String tooltip = label;
String fullLabelText = label;
if (label == null) {
label = "";
} else {
if (labelMaxLength > 0 && label.length() > labelMaxLength) {
label = label.substring(0,labelMaxLength)+"...";
}
}
int level = Integer.parseInt(levelString);
if (level <= 0) {
level = 1;
}
while (level <= current.getLevel()) {
current = current.getParent();
}
current = createOutlineItem(current,idGenerator.newId(kind,fullLabelText), offset, length, label);
current.setTooltip(tooltip);
current.setKind(kind);
}
return root;