示例#1
0
  protected boolean fill(String value, boolean initial_state) {
    try {

      //
      fromString(value);

      // fire event
      if (initial_state) fireDocumentRestored();
      else fireDocumentChanged();

      return true;
    } catch (Exception e) {
      LogUtils.report(e);
      return false;
    }
  }
示例#2
0
  /**
   * Initialize the document by parsing it from a string.
   *
   * @see #fromString
   */
  public boolean init(String value) {
    try {
      // source
      resetStatus();

      // init data
      initData();
      fromString(value);

      // fire event
      fireDocumentInit();

      return true;
    } catch (Exception e) {
      LogUtils.report(e);
      return false;
    }
  }
示例#3
0
  /**
   * Save the document to a file.
   *
   * @see #write
   */
  public boolean save(String filename) {

    try {
      setFilename(filename);

      // write to tmp file
      File tmpfile = File.createTempFile("gwb", null);
      write(new FileOutputStream(tmpfile));

      // copy to dest file and delete tmp file
      FileUtils.copy(tmpfile, new File(filename));
      tmpfile.delete();

      //

      //
      fireDocumentInit();
      return true;
    } catch (Exception e) {
      LogUtils.report(e);
      return false;
    }
  }
示例#4
0
  /**
   * Read the document from a file.
   * @param merge if <code>true</code> the content of the file is
   * appended to the current document, when possible
   * @param warning if <code>true</true> report when the file cannot
   * be parsed
   * @see #read
   */
  public boolean open(File file, boolean merge, boolean warning) {
    try {
      FileInputStream fis = new FileInputStream(file);

      // read structure
      try {
        read(fis, merge);
      } catch (Exception e) {
        System.err.println("Got exception: " + e.getMessage());
        init();
        if (warning) throw e;
        return false;
      }

      //
      setFilename(file.getAbsolutePath());
      fireDocumentInit();
      return true;
    } catch (Exception e) {
      LogUtils.report(e);
      return false;
    }
  }