Example #1
0
  protected static void writeHistoryFile() {
    if ((History.HISTORY_FILE.isFile() && History.HISTORY_FILE.canWrite())
        || (!History.HISTORY_FILE.exists())) {
      try {
        BufferedWriter out = new BufferedWriter(new FileWriter(History.HISTORY_FILE, false));
        out.write("<?xml version=\"1.0\"?>\n");
        out.write("<pcsim2 version=\"" + History.PLATFORM_VERSION + "\">\n");
        out.write("\t<pcf dir=\"" + history.lastPCFDirectory.getAbsolutePath() + "\"/>\n");
        out.write("\t<dcf dir=\"" + history.lastDCFDirectory.getAbsolutePath() + "\"/>\n");
        out.write("\t<scripts dir=\"" + history.lastScriptsDirectory.getAbsolutePath() + "\"/>\n");
        out.write("\t<batch dir=\"" + history.lastBatchDirectory.getAbsolutePath() + "\"/>\n");

        for (int i = 0; i < History.MAX_NUM_HISTORY_FILES; i++) {
          if (history.histFiles[i] != null) {
            out.write("\t<history file=\"" + history.histFiles[i].getAbsolutePath() + "\"/>\n");
          }
        }
        out.write("</pcsim2>");
        out.close();
      } catch (IOException e) {
        if (PC2UI.logger != null) {
          PC2UI.logger.error(
              PC2LogCategory.UI,
              PC2UI.subCat,
              "PCSim2 encountered an error while trying to write the history file information.\n"
                  + e.getMessage());
        }
      }
    }
  }
Example #2
0
 public History parse() throws SAXException, IOException {
   xr = XMLReaderFactory.createXMLReader();
   if (xr != null) {
     xr.setContentHandler(this);
     if (History.HISTORY_FILE.exists()) {
       FileReader reader = new FileReader(History.HISTORY_FILE);
       xr.parse(new InputSource(reader));
     } else {
       history = History.getInstance();
       writeHistoryFile();
     }
     return history;
   } else throw new SAXException("XMLReader did not get created successfully.");
 }