private void beautifyOrRepairHTML(String mode) { logger.info("beautifying html"); try { CodeEditor editor = currentEditor.getValue(); EditorPosition currentCursorPosition = editor.getEditorCursorPosition(); String code = editor.getCode(); if (currentEditorIsXHTML.get()) { try { Resource resource = currentXHTMLResource.get(); resource.setData(code.getBytes("UTF-8")); switch (mode) { case "format": code = formatAsXHTML(code); break; case "repair": code = repairXHTML(code); break; } resource.setData(code.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { // never happens } } editor.setCode(code); editor.setEditorCursorPosition(currentCursorPosition); editor.scrollTo(currentCursorPosition); book.setBookIsChanged(true); } catch (IOException | JDOMException e) { logger.error("", e); Dialogs.create() .owner(tabPane) .title("Formatierung nicht möglich") .message( "Kann Datei nicht formatieren. Bitte die Fehlermeldung an den Hersteller weitergeben.") .showException(e); } }