1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| public void setOuterHTML(Element elem, String htmlText) throws
BadLocationException, IOException {
verifyParser();
if (elem != null && elem.getParentElement() != null &&
htmlText != null) {
int start = elem.getStartOffset();
int end = elem.getEndOffset();
int startLength = getLength();
// We don't want a newline if elem is a leaf, and doesn't contain
// a newline.
boolean wantsNewline = !elem.isLeaf();
if (!wantsNewline && (end > startLength ||
getText(end - 1, 1).charAt(0) == NEWLINE[0])){
wantsNewline = true;
}
Element parent = elem.getParentElement();
int oldCount = parent.getElementCount();
insertHTML(parent, start, htmlText, wantsNewline);
// Remove old.
int newLength = getLength();
if (oldCount != parent.getElementCount()) {
int removeIndex = parent.getElementIndex(start + newLength -
startLength);
removeElements(parent, removeIndex, 1);
}
}
} |
Partager