示例#1
0
  private void carregaConfig() {
    try {
      File file = new File("config.xml");
      SAXBuilder builder = new SAXBuilder();
      Document doc = builder.build(file);
      Element root = doc.getRootElement();
      List list = root.getChildren();
      Iterator i = list.iterator();

      while (i.hasNext()) {
        Element xml = (Element) i.next();

        Config c = new Config();
        c.setPathRouterSnapshot(xml.getChildText("pathRouterSnapshot"));
        c.setPathDestSnapshot(xml.getChildText("pathDestSnapshot"));
        c.setSmtpHostEmail(xml.getChildText("smtpHostEmail"));
        c.setSmtpPortEmail(Integer.parseInt(xml.getChildText("smtpPortEmail")));
        c.setUserEmail(xml.getChildText("userEmail"));
        c.setPassEmail(xml.getChildText("passEmail"));
        c.setHostFTP(xml.getChildText("hostFTP"));
        c.setPortaFTP(Integer.parseInt(xml.getChildText("portaFTP")));
        c.setUserFTP(xml.getChildText("userFTP"));
        c.setPassFTP(xml.getChildText("passFTP"));
        c.setPathDestFTP(xml.getChildText("pathDestFTP"));

        txtPathAlarmeRouter.setText(c.getPathRouterSnapshot());
        txtPathDestRouter.setText(c.getPathDestSnapshot());
        txtSmtpHostEmail.setText(c.getSmtpHostEmail());
        txtSmtpPortaEmail.setValue(c.getSmtpPortEmail());
        txtUserEmail.setText(c.getUserEmail());
        txtPassEmail.setText(c.getPassEmail());
        txtHostFTP.setText(c.getHostFTP());
        txtPortaFTP.setValue(c.getPortaFTP());
        txtUserFTP.setText(c.getUserFTP());
        txtPassFTP.setText(c.getPassFTP());
        txtPathDestFTP.setText(c.getPathDestFTP());
      }
    } catch (JDOMException ex) {
      System.out.println(ex.getMessage());
    } catch (IOException ex) {
      System.out.println(ex.getMessage());
    }
  }
示例#2
0
  private void btnSaveActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnSaveActionPerformed
    String pathAlarmeRouter = txtPathAlarmeRouter.getText();
    String pathDestRouter = txtPathDestRouter.getText();
    String smtpHostEmail = txtSmtpHostEmail.getText().trim();
    Integer smtpPortaEmail = (Integer) txtSmtpPortaEmail.getValue();
    String userEmail = txtUserEmail.getText().trim();
    String passEmail = String.valueOf(txtPassEmail.getPassword());
    String hostFTP = txtHostFTP.getText().trim();
    Integer portaFTP = (Integer) txtPortaFTP.getValue();
    String userFTP = txtUserFTP.getText().trim();
    String passFTP = String.valueOf(txtPassFTP.getPassword());
    String pathDestFTP = txtPathDestFTP.getText();

    Config c = new Config();
    c.setPathRouterSnapshot(pathAlarmeRouter);
    c.setPathDestSnapshot(pathDestRouter);
    c.setSmtpHostEmail(smtpHostEmail);
    c.setSmtpPortEmail(smtpPortaEmail);
    c.setUserEmail(userEmail);
    c.setPassEmail(passEmail);
    c.setHostFTP(hostFTP);
    c.setPortaFTP(portaFTP);
    c.setUserFTP(userFTP);
    c.setPassFTP(passFTP);
    c.setPathDestFTP(pathDestFTP);

    List<Config> list = new ArrayList<Config>();
    list.add(c);

    XStream xs = new XStream(new DomDriver());
    String toXML = xs.toXML(list);

    File file = new File("config.xml");
    PrintWriter pw = null;
    try {
      pw = new PrintWriter(file);
      pw.append(toXML);

      JOptionPane.showMessageDialog(null, "Dados salvos com sucesso");

    } catch (FileNotFoundException ex) {
      JOptionPane.showMessageDialog(null, ex.getMessage(), "ERRO", JOptionPane.ERROR_MESSAGE);
      Logger.getLogger(ConfigView.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
      pw.close();
    }
  } // GEN-LAST:event_btnSaveActionPerformed