MCPcopy Create free account
hub / github.com/OpenSourcePhysics/osp / saveXML

Method saveXML

src/org/opensourcephysics/controls/OSPLog.java:658–682  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 1

saveXMLAsMethod · 0.95

Calls 11

useMessageFrameMethod · 0.95
saveXMLAsMethod · 0.95
readMethod · 0.95
getFileHandlerMethod · 0.95
getTailMethod · 0.80
equalsMethod · 0.65
writeMethod · 0.65
closeMethod · 0.65
logMethod · 0.45
trimMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected