Saves the xml-formatted log records to a file specified by name. @param fileName the file name @return the name of the file
(String fileName)
| 656 | * @return the name of the file |
| 657 | */ |
| 658 | public String saveXML(String fileName) { |
| 659 | if (useMessageFrame()) { |
| 660 | logger.log(Level.FINE, "Cannot save XML file when running as an applet."); //$NON-NLS-1$ |
| 661 | return null; // cannot log to file in applet mode |
| 662 | } |
| 663 | if((fileName==null)||fileName.trim().equals("")) { //$NON-NLS-1$ |
| 664 | return saveXMLAs(); |
| 665 | } |
| 666 | // open temp file and get xml string |
| 667 | String xml = read(tempFileName); |
| 668 | // add closing tag to xml |
| 669 | Handler fileHandler = getFileHandler(); |
| 670 | String tail = fileHandler.getFormatter().getTail(fileHandler); |
| 671 | xml = xml+tail; |
| 672 | // write the xml |
| 673 | try { |
| 674 | BufferedWriter out = new BufferedWriter(new FileWriter(fileName)); |
| 675 | out.write(xml); |
| 676 | out.flush(); |
| 677 | out.close(); |
| 678 | return fileName; |
| 679 | } catch(IOException ex) { |
| 680 | return null; |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | /** |
| 685 | * Saves the xml-formatted log records to a file selected with a chooser. |