|
30 | 30 | import java.awt.event.KeyEvent;
|
31 | 31 | import java.awt.event.WindowAdapter;
|
32 | 32 | import java.awt.event.WindowEvent;
|
33 |
| -import java.io.File; |
34 |
| -import java.io.FileOutputStream; |
35 |
| -import java.io.IOException; |
36 |
| -import java.io.OutputStreamWriter; |
37 |
| -import java.io.PrintWriter; |
38 |
| -import java.io.StringWriter; |
| 33 | +import java.io.*; |
39 | 34 | import java.net.URISyntaxException;
|
40 | 35 | import java.net.URL;
|
41 | 36 | import java.nio.charset.Charset;
|
| 37 | +import java.nio.file.Files; |
42 | 38 | import java.nio.file.Paths;
|
43 | 39 | import java.util.Observable;
|
44 | 40 | import java.util.Observer;
|
|
79 | 75 | import org.xmldb.api.base.XMLDBException;
|
80 | 76 | import org.xmldb.api.modules.XMLResource;
|
81 | 77 |
|
| 78 | +import static java.nio.charset.StandardCharsets.UTF_8; |
| 79 | + |
82 | 80 | class DocumentView extends JFrame {
|
83 | 81 |
|
84 | 82 | private static final long serialVersionUID = 1L;
|
@@ -410,33 +408,31 @@ private void saveAs() {
|
410 | 408 | }
|
411 | 409 |
|
412 | 410 | private void export() throws XMLDBException {
|
413 |
| - final String workDir = properties.getProperty("working-dir", System //$NON-NLS-1$ |
414 |
| - .getProperty("user.dir")); //$NON-NLS-1$ |
| 411 | + final String workDir = properties.getProperty("working-dir", System.getProperty("user.dir")); |
415 | 412 | final JFileChooser chooser = new JFileChooser(workDir);
|
416 | 413 | chooser.setMultiSelectionEnabled(false);
|
417 | 414 | chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
418 | 415 | chooser.setSelectedFile(Paths.get(resource.getId()).toFile());
|
419 |
| - if (chooser.showDialog(this, Messages.getString("DocumentView.44")) == JFileChooser.APPROVE_OPTION) { //$NON-NLS-1$ |
| 416 | + |
| 417 | + if (chooser.showDialog(this, Messages.getString("DocumentView.44")) == JFileChooser.APPROVE_OPTION) { |
420 | 418 | final File file = chooser.getSelectedFile();
|
421 | 419 | if (file.exists()
|
422 | 420 | && JOptionPane.showConfirmDialog(this,
|
423 |
| - Messages.getString("DocumentView.45"), Messages.getString("DocumentView.46"), //$NON-NLS-1$ //$NON-NLS-2$ |
| 421 | + Messages.getString("DocumentView.45"), Messages.getString("DocumentView.46"), |
424 | 422 | JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) {
|
425 | 423 | return;
|
426 | 424 | }
|
427 |
| - try { |
428 |
| - final OutputStreamWriter writer = new OutputStreamWriter( |
429 |
| - new FileOutputStream(file), Charset.forName(properties |
430 |
| - .getProperty("encoding"))); //$NON-NLS-1$ |
| 425 | + |
| 426 | + final Charset encoding = Charset.forName(properties.getProperty("encoding")); |
| 427 | + try (final Writer writer = Files.newBufferedWriter(file.toPath(), encoding)) { |
431 | 428 | writer.write(text.getText());
|
432 |
| - writer.close(); |
| 429 | + |
433 | 430 | } catch (final IOException e) {
|
434 |
| - ClientFrame.showErrorMessage(Messages.getString("DocumentView.48") //$NON-NLS-1$ |
435 |
| - + e.getMessage(), e); |
| 431 | + ClientFrame.showErrorMessage(Messages.getString("DocumentView.48") + e.getMessage(), e); |
436 | 432 | }
|
| 433 | + |
437 | 434 | final File selectedDir = chooser.getCurrentDirectory();
|
438 |
| - properties |
439 |
| - .setProperty("working-dir", selectedDir.getAbsolutePath()); //$NON-NLS-1$ |
| 435 | + properties.setProperty("working-dir", selectedDir.getAbsolutePath()); |
440 | 436 | }
|
441 | 437 | }
|
442 | 438 |
|
|
0 commit comments