コード例 #1
0
  public Project importProject(String filename) throws Exception {
    Project p = new Project();

    BufferedReader s = null;

    try {
      s = new BufferedReader(new FileReader(filename));
    } catch (IOException e) {
      return null;
    }

    String line;
    int linen = 1;

    try {
      while ((line = s.readLine()) != null) {
        line = line.trim();

        if (line.equalsIgnoreCase("[generali]") || line.length() == 0) ;
        else if (line.startsWith("NCelle")) {
          //					StringTokenizer z = new StringTokenizer(line, "=");
          //					z.nextToken();
          //					ncelle = Integer.parseInt(z.nextToken());
        } else if (line.startsWith("NSiti")) {
          //					StringTokenizer z = new StringTokenizer(line, "=");
          //					z.nextToken();
          //					p.sites = new Site[Integer.parseInt(z.nextToken())];
        } else if (line.startsWith("[Sito")) p.add(ReadSiteFromFile(s));
        else if (line.startsWith("[Cella")) {
          Cell cell = ReadCellFromFile(s);

          final Site thesite = p.getSiteByID(cell.getSiteID());
          if (thesite == null)
            Utils.MessageBox(
                "ERROR, site id " + cell.getSiteID() + " not found.\n", "Errore Interno");
          else {
            thesite.AddCell(cell);
          }
          //					i_cell++;
        }
      }
    } catch (IOException e) {
      throw new Exception("IOException, line " + linen);
    } catch (NumberFormatException e) {
      throw new Exception("NumberFormatException, line " + linen);
    } catch (NullPointerException e) {
      throw new Exception("NullPointerException, line " + linen);
    } finally {
      if (s != null)
        try {
          s.close();
        } catch (Exception e) {
        }
    }

    return p;
  }
コード例 #2
0
  private Site ReadSiteFromFile(BufferedReader s) throws Exception {
    String line;

    String ID = "";
    String comment = "";
    SiteDBInfo dbinfo = new SiteDBInfo();

    try {
      while ((line = s.readLine()) != null) {
        line = line.trim();

        if (line.equals("")) // end of Cell definition
        break;
        else {
          if (!line.contains("=")) return null;

          final String value = line.substring(line.indexOf("=") + 1).trim();

          if (line.startsWith("Codice")) ID = value;
          else if (line.startsWith("Intesta")) comment = value;
          else if (line.startsWith("Operatore")) dbinfo.setOperatore(value);
          else if (line.startsWith("Indirizzo")) dbinfo.setIndirizzo(value);
          else if (line.startsWith("Comune")) dbinfo.setComune(value);
          else if (line.startsWith("Provincia")) dbinfo.setProvincia(value);
          else if (line.startsWith("Note")) dbinfo.setNote(value);
          else if (line.startsWith("Stato")) dbinfo.setStato(value);
          else if (line.startsWith("CodiceSito")) dbinfo.setCodiceSito(value);
        }
      }
    } catch (IOException e) {
      throw new Exception("Site::IOException");
    } catch (NumberFormatException e) {
      throw new Exception("Site::NumberFormatException");
    } catch (NullPointerException e) {
      throw new Exception("Site::NullPointerException");
    }

    Site site = new Site(ID);
    site.setComment(comment);
    site.setDbinfo(dbinfo);

    return site;
  }