public TextEdit format(IStructuredModel model, int start, int length, XMLFormattingPreferences preferences) {
setFormattingPreferences(preferences);
TextEdit edit = new MultiTextEdit();
IStructuredDocument document = model.getStructuredDocument();
// get initial document region
IStructuredDocumentRegion currentRegion = document.getRegionAtCharacterOffset(start);
if (currentRegion != null) {
int startOffset = currentRegion.getStartOffset();
// get initial dom node
IndexedRegion currentIndexedRegion = model.getIndexedRegion(startOffset);
if (currentIndexedRegion instanceof IDOMNode) {
// set up domRegion which will contain current region to be
// formatted
IDOMNode currentDOMNode = (IDOMNode) currentIndexedRegion;
DOMRegion domRegion = new DOMRegion();
domRegion.documentRegion = currentRegion;
domRegion.domNode = currentDOMNode;
XMLFormattingConstraints parentConstraints = getRegionConstraints(currentDOMNode);
/* if the whitespace strategy is declared as default, get it from the preferences */
if(XMLFormattingConstraints.DEFAULT.equals(parentConstraints.getWhitespaceStrategy()))
parentConstraints.setWhitespaceStrategy(preferences.getElementWhitespaceStrategy());
// TODO: initialize indentLevel
// initialize available line width
int lineWidth = getFormattingPreferences().getMaxLineWidth();
try {
IRegion lineInfo = document.getLineInformationOfOffset(startOffset);
lineWidth = lineWidth - (startOffset - lineInfo.getOffset());
}
catch (BadLocationException e) {
Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
}