I had a couple of posts on getting this thing to work. I finally got a small test program working, but now this, the actuall program, doesn't.

I don't understand the error either(Will include it at the end of this post).

Here is my code, with the line throwing an exception in bold:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * guiV2.java
 *
 * Created on 2009/12/14, 03:08:56
 */
package gui;

import com.sun.org.apache.xml.internal.serialize.OutputFormat;
import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
import java.io.*;
import java.util.regex.*;
import javax.swing.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.*;
import org.xml.sax.SAXException;

/**
 *
 * @author Administrator
 */
public class guiV2 extends javax.swing.JFrame {

    private static boolean bool_warn = false;
    private static String str_warn = "";
    private static String str_smtpSrv = "";
    private static String str_smtpPort = "";
    private static String str_smtpUsr = "";
    private static String str_smtpPsw = "";
    private static String str_emailFrom = "";
    private static String str_emailTo = "";
    private static String str_altEmailTo = "";
    private static String str_jobName = "";
    private static String str_inputFolder = "";
    private static String str_fileMask = "";
    private static String str_processOrder = "";
    private static String str_retainFolder = "";
    private static String str_overrideFolder = "";
    private static String str_errorFolder = "";
    private static String str_pollInterval = "";
    private static String str_jobBatchFilepath = "";
    private static String str_jobBatchParams = "";
    private static String str_jobLogPath = "";
    private static String str_jobEmail = "";
    private static String str_jobAltEmail = "";
    private static File outputFile = new File("");

    /** Creates new form guiV2 */
    public guiV2() {
        initComponents();
        pane_startUp.setVisible(true);
        btn_done.setEnabled(false);
        pane_sysSettings.setVisible(false);
        pane_jobSettings.setVisible(false);
        pane_fileChooser.setVisible(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        btnGrp_group = new javax.swing.ButtonGroup();
        pane_startUp = new javax.swing.JPanel();
        rb_newFile = new javax.swing.JRadioButton();
        rb_existingFile = new javax.swing.JRadioButton();
        btn_continue = new javax.swing.JButton();
        btn_done = new javax.swing.JButton();
        rb_editFile = new javax.swing.JRadioButton();
        jLabel1 = new javax.swing.JLabel();
        pane_sysSettings = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        txt_smtpSrv = new javax.swing.JTextField();
        txt_smtpPort = new javax.swing.JTextField();
        txt_smtpUsr = new javax.swing.JTextField();
        txt_emailFrom = new javax.swing.JTextField();
        txt_emailTo = new javax.swing.JTextField();
        txt_altEmailTo = new javax.swing.JTextField();
        txt_smtpPsw = new javax.swing.JTextField();
        pane_jobSettings = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        lbl_jobLogPath = new javax.swing.JLabel();
        txt_jobName = new javax.swing.JTextField();
        txt_inputFolder = new javax.swing.JTextField();
        txt_fileMask = new javax.swing.JTextField();
        txt_processOrder = new javax.swing.JTextField();
        txt_retainFolder = new javax.swing.JTextField();
        lbl_jobEmailTo = new javax.swing.JLabel();
        lbl_altJobEmailTo = new javax.swing.JLabel();
        txt_overrideFolder = new javax.swing.JTextField();
        txt_errorFolder = new javax.swing.JTextField();
        txt_pollInterval = new javax.swing.JTextField();
        txt_jobBatchFilepath = new javax.swing.JTextField();
        txt_jobBatchParams = new javax.swing.JTextField();
        txt_jobLogPath = new javax.swing.JTextField();
        txt_jobEmail = new javax.swing.JTextField();
        txt_jobAltEmailTo = new javax.swing.JTextField();
        pane_fileChooser = new javax.swing.JPanel();
        fileChooser = new javax.swing.JFileChooser();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Apoller Settings");

        btnGrp_group.add(rb_newFile);
        rb_newFile.setText("New settings file");

        btnGrp_group.add(rb_existingFile);
        rb_existingFile.setText("Add job to existing file");

        btn_continue.setText("Continue");
        btn_continue.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_continueActionPerformed(evt);
            }
        });

        btn_done.setText("Done");
        btn_done.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_doneActionPerformed(evt);
            }
        });

        btnGrp_group.add(rb_editFile);
        rb_editFile.setText("Edit existing file");

        javax.swing.GroupLayout pane_startUpLayout = new javax.swing.GroupLayout(pane_startUp);
        pane_startUp.setLayout(pane_startUpLayout);
        pane_startUpLayout.setHorizontalGroup(
            pane_startUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pane_startUpLayout.createSequentialGroup()
                .addGap(50, 50, 50)
                .addComponent(rb_newFile)
                .addGap(28, 28, 28)
                .addComponent(rb_existingFile)
                .addGap(30, 30, 30)
                .addComponent(rb_editFile)
                .addContainerGap(161, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pane_startUpLayout.createSequentialGroup()
                .addGap(204, 204, 204)
                .addGroup(pane_startUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btn_done, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE)
                    .addComponent(btn_continue, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(329, 329, 329))
        );
        pane_startUpLayout.setVerticalGroup(
            pane_startUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pane_startUpLayout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addGroup(pane_startUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rb_existingFile)
                    .addComponent(rb_newFile)
                    .addComponent(rb_editFile))
                .addGap(18, 18, 18)
                .addComponent(btn_continue)
                .addGap(18, 18, 18)
                .addComponent(btn_done)
                .addContainerGap(40, Short.MAX_VALUE))
        );

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Apoller Settings");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel2.setText("System Settings");

        jLabel3.setText("SMTP Server: ");

        jLabel4.setText("SMTP Port:");

        jLabel5.setText("SMTP User:");

        jLabel6.setText("SMTP Password:");

        jLabel7.setText("Email From:");

        jLabel8.setText("Email To:");

        jLabel9.setText("Alternative Email To:");

        javax.swing.GroupLayout pane_sysSettingsLayout = new javax.swing.GroupLayout(pane_sysSettings);
        pane_sysSettings.setLayout(pane_sysSettingsLayout);
        pane_sysSettingsLayout.setHorizontalGroup(
            pane_sysSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pane_sysSettingsLayout.createSequentialGroup()
                .addGroup(pane_sysSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pane_sysSettingsLayout.createSequentialGroup()
                        .addGap(137, 137, 137)
                        .addComponent(jLabel2))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pane_sysSettingsLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(pane_sysSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8)
                            .addComponent(jLabel9))
                        .addGap(18, 18, 18)
                        .addGroup(pane_sysSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txt_smtpSrv)
                            .addComponent(txt_emailTo)
                            .addComponent(txt_altEmailTo, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
                            .addComponent(txt_emailFrom)
                            .addComponent(txt_smtpPsw)
                            .addComponent(txt_smtpUsr)
                            .addComponent(txt_smtpPort))
                        .addGap(31, 31, 31)))
                .addContainerGap())
        );
        pane_sysSettingsLayout.setVerticalGroup(
            pane_sysSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pane_sysSettingsLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addGap(18, 18, 18)
                .addGroup(pane_sysSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txt_smtpSrv, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pane_sysSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txt_smtpPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pane_sysSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txt_smtpUsr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pane_sysSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txt_smtpPsw, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pane_sysSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(txt_emailFrom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pane_sysSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txt_emailTo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pane_sysSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(txt_altEmailTo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel10.setText("Job Settings");

        jLabel11.setText("Job Name: ");

        jLabel12.setText("Input Folder:");

        jLabel13.setText("File Mask:");

        jLabel14.setText("Process Order:");

        jLabel15.setText("Retain Folder:");

        jLabel16.setText("Override Folder:");

        jLabel17.setText("Error Folder:");

        jLabel18.setText("Poll Interval:");

        jLabel19.setText("Job Batch Filepath:");

        jLabel20.setText("Job Batch Parameters:");

        lbl_jobLogPath.setText("Job Log Path:");

        lbl_jobEmailTo.setText("Job Email To:");

        lbl_altJobEmailTo.setText("Alternative Job Email To:");

        javax.swing.GroupLayout pane_jobSettingsLayout = new javax.swing.GroupLayout(pane_jobSettings);
        pane_jobSettings.setLayout(pane_jobSettingsLayout);
        pane_jobSettingsLayout.setHorizontalGroup(
            pane_jobSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pane_jobSettingsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pane_jobSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pane_jobSettingsLayout.createSequentialGroup()
                        .addComponent(jLabel10)
                        .addGap(171, 171, 171))
                    .addGroup(pane_jobSettingsLayout.createSequentialGroup()
                        .addGroup(pane_jobSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbl_altJobEmailTo)
                            .addComponent(lbl_jobEmailTo)
                            .addComponent(lbl_jobLogPath)
                            .addComponent(jLabel20)
                            .addComponent(jLabel11)
                            .addComponent(jLabel12)
                            .addComponent(jLabel13)
                            .addComponent(jLabel14)
                            .addComponent(jLabel15)
                            .addComponent(jLabel16)
                            .addComponent(jLabel17)
                            .addComponent(jLabel18)
                            .addComponent(jLabel19))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pane_jobSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txt_jobAltEmailTo)
                            .addComponent(txt_pollInterval)
                            .addComponent(txt_jobBatchFilepath)
                            .addComponent(txt_jobBatchParams, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)
                            .addComponent(txt_errorFolder, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE)
                            .addComponent(txt_overrideFolder, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE)
                            .addComponent(txt_retainFolder, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE)
                            .addComponent(txt_processOrder, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE)
                            .addComponent(txt_fileMask, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE)
                            .addComponent(txt_inputFolder)
                            .addComponent(txt_jobName, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE)
                            .addComponent(txt_jobLogPath, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE)
                            .addComponent(txt_jobEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );
        pane_jobSettingsLayout.setVerticalGroup(
            pane_jobSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pane_jobSettingsLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel10)
                .addGap(18, 18, 18)
                .addGroup(pane_jobSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(txt_jobName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pane_jobSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(txt_inputFolder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pane_jobSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(txt_fileMask, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pane_jobSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(txt_processOrder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pane_jobSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(txt_retainFolder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pane_jobSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(txt_overrideFolder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pane_jobSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(txt_errorFolder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pane_jobSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel18)
                    .addComponent(txt_pollInterval, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pane_jobSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel19)
                    .addComponent(txt_jobBatchFilepath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pane_jobSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel20)
                    .addComponent(txt_jobBatchParams, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pane_jobSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_jobLogPath)
                    .addComponent(txt_jobLogPath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pane_jobSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_jobEmailTo)
                    .addComponent(txt_jobEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pane_jobSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_altJobEmailTo)
                    .addComponent(txt_jobAltEmailTo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        fileChooser.setDialogType(javax.swing.JFileChooser.SAVE_DIALOG);
        fileChooser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fileChooserActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pane_fileChooserLayout = new javax.swing.GroupLayout(pane_fileChooser);
        pane_fileChooser.setLayout(pane_fileChooserLayout);
        pane_fileChooserLayout.setHorizontalGroup(
            pane_fileChooserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pane_fileChooserLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(fileChooser, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        pane_fileChooserLayout.setVerticalGroup(
            pane_fileChooserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pane_fileChooserLayout.createSequentialGroup()
                .addComponent(fileChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(62, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(pane_startUp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(pane_fileChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(pane_sysSettings, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(pane_jobSettings, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(586, 586, 586))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(515, 515, 515)
                        .addComponent(jLabel1)
                        .addGap(393, 393, 393))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(pane_startUp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(pane_fileChooser, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(pane_sysSettings, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(pane_jobSettings, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(12, 12, 12)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>                        

    private void btn_continueActionPerformed(java.awt.event.ActionEvent evt) {                                             
        // Check what type of action should be performed

        if (rb_existingFile.isSelected()) {
            pane_jobSettings.setVisible(true);
            btn_done.setEnabled(true);
        } else if (rb_newFile.isSelected()) {
            pane_sysSettings.setVisible(true);
            pane_jobSettings.setVisible(true);
            btn_done.setEnabled(true);
        } else if (rb_editFile.isSelected()) {
            pane_sysSettings.setVisible(true);
            btn_done.setEnabled(true);
        } else {
            JOptionPane.showMessageDialog(rootPane, "Please select an option");
        }
    }                                            

    private void btn_doneActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // First check that everything has been filled in correctly, then show the filechooser
        // System setting text fields
        str_smtpSrv = txt_smtpSrv.getText();
        str_smtpPort = txt_smtpPort.getText();
        str_smtpUsr = txt_smtpUsr.getText();
        str_smtpPsw = txt_smtpPsw.getText();
        str_emailFrom = txt_emailFrom.getText();
        str_emailTo = txt_emailTo.getText();
        str_altEmailTo = txt_altEmailTo.getText();

        // Job setting text fields
        str_jobName = txt_jobName.getText();
        str_inputFolder = txt_inputFolder.getText();
        str_fileMask = txt_fileMask.getText();
        str_processOrder = txt_processOrder.getText();
        str_retainFolder = txt_retainFolder.getText();
        str_overrideFolder = txt_overrideFolder.getText();
        str_errorFolder = txt_errorFolder.getText();
        str_pollInterval = txt_pollInterval.getText();
        str_jobBatchFilepath = txt_jobBatchFilepath.getText();
        str_jobBatchParams = txt_jobBatchParams.getText();
        str_jobLogPath = txt_jobLogPath.getText();
        str_jobEmail = txt_jobEmail.getText();
        str_jobAltEmail = txt_jobAltEmailTo.getText();

        if (rb_newFile.isSelected()) {
            if (str_smtpSrv.equals("") || str_smtpSrv.equals(null)) {
                JOptionPane.showMessageDialog(rootPane, "Email notifications have been disabled");
            } else {
                // Do system settings
                // Set port to 25(default) if it has been left blank
                if (str_smtpPort.equals("") || str_smtpPort.equals(null)) {
                    str_smtpPort = "25";
                }
                //Check emails
                if (str_emailFrom.equals("") || str_emailFrom.equals(null)) {
                    bool_warn = true;
                    str_warn = "\"Email From\" has not been filled in";
                } else {
                    if (!isEmailValid(str_emailFrom)) {
                        bool_warn = true;
                        str_warn = "\"Email From\" has been supplied with an invalid email address";
                    }
                }
                if (str_emailTo.equals("") || str_emailTo.equals(null)) {
                    bool_warn = true;
                    str_warn = "\"Email To\" has not been filled in";
                } else {
                    if (!isEmailValid(str_emailTo)) {
                        bool_warn = true;
                        str_warn = "\"Email To\" has been supplied with an invalid email address";
                    }
                }
                if (str_altEmailTo.equals("") || str_altEmailTo.equals(null)) {
                    bool_warn = true;
                    str_warn = "\"Alternative Email To\" has not been filled in";
                } else {
                    if (!isEmailValid(str_altEmailTo)) {
                        bool_warn = true;
                        str_warn = "\"Alternative Email To\" has been supplied with an invalid email address";
                    }
                }
            }

            // Do job settings
            // Job name field is mandatory
            if (str_jobName.equals("") || str_jobName.equals(null)) {
                bool_warn = true;
                str_warn = "Please supply a job name";
            }
            // Input folder field is mandatory
            if (str_inputFolder.equals("") || str_inputFolder.equals(null)) {
                bool_warn = true;
                str_warn = "Please supply an input folder location";
            }
            // Job batch filepath field is mandatory
            if (str_jobBatchFilepath.equals("") || str_jobBatchFilepath.equals(null)) {
                bool_warn = true;
                str_warn = "Please supply a job batch filepath";
            }
            // Job batch parameters field is mandatory
            if (str_jobBatchParams.equals("") || str_jobBatchParams.equals(null)) {
                bool_warn = true;
                str_warn = "Please supply at least one job batch parameter";
            }
            // Check emails
            if (str_jobEmail.equals("") || str_jobEmail.equals(null)) {
                bool_warn = true;
                str_warn = "\"Job Email To\" has not been filled in";
            } else {
                if (!isEmailValid(str_jobEmail)) {
                    System.out.println("woopwoop");
                    System.out.println("is email valid: " + isEmailValid(str_jobEmail));
                    bool_warn = true;
                    str_warn = "\"Job Email To\" has been supplied with an invalid email address";
                }
            }
            if (str_jobAltEmail.equals("") || str_jobAltEmail.equals(null)) {
                bool_warn = true;
                str_warn = "\"Job Alternative Email To\" has not been filled in";
            } else {
                if (!isEmailValid(str_jobAltEmail)) {
                    bool_warn = true;
                    str_warn = "\"Job Alternative Email To\" has been supplied with an invalid email address";
                }
            }
        } else if (rb_existingFile.isSelected()) {
            // Do job settings
            // Job name field is mandatory
            if (str_jobName.equals("") || str_jobName.equals(null)) {
                bool_warn = true;
                str_warn = "Please supply a job name";
            }
            // Input folder field is mandatory
            if (str_inputFolder.equals("") || str_inputFolder.equals(null)) {
                bool_warn = true;
                str_warn = "Please supply an input folder location";
            }
            // Job batch filepath field is mandatory
            if (str_jobBatchFilepath.equals("") || str_jobBatchFilepath.equals(null)) {
                bool_warn = true;
                str_warn = "Please supply a job batch filepath";
            }
            // Job batch parameters field is mandatory
            if (str_jobBatchParams.equals("") || str_jobBatchParams.equals(null)) {
                bool_warn = true;
                str_warn = "Please supply at least one job batch parameter";
            }
            // Check emails
            if (str_jobEmail.equals("") || str_jobEmail.equals(null)) {
                bool_warn = true;
                str_warn = "\"Job Email To\" has not been filled in";
            } else {
                if (!isEmailValid(str_jobEmail)) {
                    bool_warn = true;
                    str_warn = "\"Job Email To\" has been supplied with an invalid email address";
                }
            }
            if (str_jobAltEmail.equals("") || str_jobAltEmail.equals(null)) {
                bool_warn = true;
                str_warn = "\"Alternative Job Email To\" has not been filled in";
            } else {
                if (!isEmailValid(str_jobAltEmail)) {
                    bool_warn = true;
                    str_warn = "\"Alternative Job Email To\" has been supplied with an invalid email address";
                }
            }
        } else if (rb_editFile.isSelected()) {
            if (str_smtpSrv.equals("") || str_smtpSrv.equals(null)) {
                JOptionPane.showMessageDialog(rootPane, "Email notifications have been disabled");
            } else {
                //Check emails
                if (str_emailFrom.equals("") || str_emailFrom.equals(null)) {
                    str_emailFrom = "";
                } else {
                    if (!isEmailValid(str_emailFrom)) {
                        bool_warn = true;
                        str_warn = "\"Email From\" has been supplied with an invalid email address";
                    }
                }
                if (str_emailTo.equals("") || str_emailTo.equals(null)) {
                    str_emailTo = "";
                } else {
                    if (!isEmailValid(str_emailTo)) {
                        bool_warn = true;
                        str_warn = "\"Email To\" has been supplied with an invalid email address";
                    }
                }
                if (str_altEmailTo.equals("") || str_altEmailTo.equals(null)) {
                    str_altEmailTo = "";
                } else {
                    if (!isEmailValid(str_altEmailTo)) {
                        bool_warn = true;
                        str_warn = "\"Alternative Email To\" has been supplied with an invalid email address";
                    }
                }
            }

            // TODO Check job input
            if (str_jobName.equals("") || str_jobName.equals(null)) {
                JOptionPane.showMessageDialog(rootPane, "Job details wont be changed");
            } else {
                // do checks
                if (str_inputFolder.equals("") || str_inputFolder.equals(null)) {
                    str_inputFolder = "";
                } else {
                    //check that folder exists
                }
                if (str_jobBatchFilepath.equals("") || str_jobBatchFilepath.equals(null)) {
                    str_jobBatchFilepath = "";
                } else {
                    //check that the folder exists
                }
                if (str_jobBatchParams.equals("") || str_jobBatchParams.equals(null)) {
                    str_jobBatchParams = "";
                }
                // Check emails
                if (str_jobEmail.equals("") || str_jobEmail.equals(null)) {
                    str_jobEmail = "";
                } else {
                    if (!isEmailValid(str_jobEmail)) {
                        bool_warn = true;
                        str_warn = "\"Job Email To\" has been supplied with an invalid email address";
                    }
                }
                if (str_jobAltEmail.equals("") || str_jobAltEmail.equals(null)) {
                    str_jobAltEmail = "";
                } else {
                    if (!isEmailValid(str_jobAltEmail)) {
                        bool_warn = true;
                        str_warn = "\"Alternative Job Email To\" has been supplied with an invalid email address";
                    }
                }
            }
        }

        if (bool_warn) {
            JOptionPane.showMessageDialog(rootPane, str_warn);
            bool_warn = false;
        } else {
            pane_fileChooser.setVisible(true);
        }
    }                                        

    private void fileChooserActionPerformed(java.awt.event.ActionEvent evt) {                                            
        File file = fileChooser.getSelectedFile();
        String str_fileName = file.getAbsolutePath();
        boolean bool_output = false;
        if (rb_existingFile.isSelected()) {
            bool_output = writeToOldFile(str_fileName);
        } else if (rb_newFile.isSelected()) {
            bool_output = writeNewFile(str_fileName);
        } else if (rb_editFile.isSelected()) {
            bool_output = editExistingFile(str_fileName);
        }

        if (bool_output) {
            JOptionPane.showMessageDialog(rootPane, "The operation was succesful. Form will be reset");
            resetForm();
        } else {
            int reply = JOptionPane.showConfirmDialog(null, "The Operation was unsuccesful. Would you like the form to be reset?", "Form Reset", JOptionPane.YES_NO_OPTION);
            if (reply == JOptionPane.YES_OPTION) {
                resetForm();
            }
        }
    }                                           

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new guiV2().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                     
    private javax.swing.ButtonGroup btnGrp_group;
    private javax.swing.JButton btn_continue;
    private javax.swing.JButton btn_done;
    private javax.swing.JFileChooser fileChooser;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel lbl_altJobEmailTo;
    private javax.swing.JLabel lbl_jobEmailTo;
    private javax.swing.JLabel lbl_jobLogPath;
    private javax.swing.JPanel pane_fileChooser;
    private javax.swing.JPanel pane_jobSettings;
    private javax.swing.JPanel pane_startUp;
    private javax.swing.JPanel pane_sysSettings;
    private javax.swing.JRadioButton rb_editFile;
    private javax.swing.JRadioButton rb_existingFile;
    private javax.swing.JRadioButton rb_newFile;
    private javax.swing.JTextField txt_altEmailTo;
    private javax.swing.JTextField txt_emailFrom;
    private javax.swing.JTextField txt_emailTo;
    private javax.swing.JTextField txt_errorFolder;
    private javax.swing.JTextField txt_fileMask;
    private javax.swing.JTextField txt_inputFolder;
    private javax.swing.JTextField txt_jobAltEmailTo;
    private javax.swing.JTextField txt_jobBatchFilepath;
    private javax.swing.JTextField txt_jobBatchParams;
    private javax.swing.JTextField txt_jobEmail;
    private javax.swing.JTextField txt_jobLogPath;
    private javax.swing.JTextField txt_jobName;
    private javax.swing.JTextField txt_overrideFolder;
    private javax.swing.JTextField txt_pollInterval;
    private javax.swing.JTextField txt_processOrder;
    private javax.swing.JTextField txt_retainFolder;
    private javax.swing.JTextField txt_smtpPort;
    private javax.swing.JTextField txt_smtpPsw;
    private javax.swing.JTextField txt_smtpSrv;
    private javax.swing.JTextField txt_smtpUsr;
    // End of variables declaration                   

    public static boolean isEmailValid(String email) {
//Initialize reg ex for email.
        String expression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";
        CharSequence inputStr = email;
//Make the comparison case-insensitive.
        Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(inputStr);
        if (matcher.matches()) {
            return true;
        } else {
            return false;
        }
    }

    public boolean editExistingFile(String fileName) {
        // TODO check that the jobname's job exists. if jobname is left blank, alert, and dont change the job.
        String[] jobChanges = new String[13];
        String[] systemChanges = new String[7];
        str_jobName = txt_jobName.getText();

        if (str_jobName.equals("") || str_jobName.equals(null)) {
            systemChanges[0] = str_smtpSrv;
            systemChanges[1] = str_smtpPort;
            systemChanges[2] = str_smtpUsr;
            systemChanges[3] = str_smtpPsw;
            systemChanges[4] = str_emailFrom;
            systemChanges[5] = str_emailTo;
            systemChanges[6] = str_altEmailTo;

            return editSystemSettings(fileName, systemChanges);
        } else {
            jobChanges[0] = "";
            jobChanges[1] = str_inputFolder;
            jobChanges[2] = str_fileMask;
            jobChanges[3] = str_processOrder;
            jobChanges[4] = str_retainFolder;
            jobChanges[5] = str_overrideFolder;
            jobChanges[6] = str_errorFolder;
            jobChanges[7] = str_pollInterval;
            jobChanges[8] = str_jobBatchFilepath;
            jobChanges[9] = str_jobBatchParams;
            jobChanges[10] = str_jobLogPath;
            jobChanges[11] = str_jobEmail;
            jobChanges[12] = str_jobAltEmail;

            return editJobSettings(fileName, str_jobName, jobChanges);
        }
    }

    public boolean writeNewFile(String str_fileName) {
        str_inputFolder = txt_inputFolder.getText();
        str_retainFolder = txt_retainFolder.getText();
        str_overrideFolder = txt_overrideFolder.getText();
        str_errorFolder = txt_errorFolder.getText();
        str_jobLogPath = txt_jobLogPath.getText();
        str_jobBatchFilepath = txt_jobBatchFilepath.getText();

        //Test Filepaths (They have to exist)
        // Input Folder
        File inputFolder = new File(str_inputFolder);
        if (!inputFolder.exists()) {
            JOptionPane.showMessageDialog(rootPane, "The directory specified for \"Input Folder\" does not exist");
            return false;
        }
        // Retain Folder
        File retainFolder = new File(str_retainFolder);
        if (!retainFolder.exists()) {
            JOptionPane.showMessageDialog(rootPane, "The directory specified for \"Retain Folder\" does not exist");
            return false;
        }
        // Override Folder
        File overrideFolder = new File(str_overrideFolder);
        if (!overrideFolder.exists()) {
            JOptionPane.showMessageDialog(rootPane, "The directory specified for \"Override Folder\" does not exist");
            return false;
        }
        // Error Folder
        File errorFolder = new File(str_errorFolder);
        if (!errorFolder.exists()) {
            JOptionPane.showMessageDialog(rootPane, "The directory specified for \"Error Folder\" does not exist");
            return false;
        }
        // Override Folder
        File jobLogPath = new File(str_jobLogPath);
        if (!jobLogPath.exists()) {
            JOptionPane.showMessageDialog(rootPane, "The directory specified for \"Job Log Path\" does not exist");
            return false;
        }
        // Job Batch Filepath
        File jobBatchFilepath = new File(str_jobBatchFilepath);
        if (!jobBatchFilepath.exists()) {
            JOptionPane.showMessageDialog(rootPane, "The directory specified for \"Job Batch Filepath\" does not exist");
            return false;
        }

        String str_settings = "<?xml version=\"1.0\"?>\n" +
                "<APOLLERSETTINGS>\n" +
                "<SYSTEM>\n" +
                "<VERSION>3.1</VERSION>\n" +
                "<SMTPSRV>" + str_smtpSrv + "</SMTPSRV>\n" +
                "<SMTPPORT>" + str_smtpPort + "</SMTPPORT>\n" +
                "<SMTPUSR>" + str_smtpUsr + "</SMTPUSR>\n" +
                "<SMTPPSW>" + str_smtpPsw + "</SMTPPSW>\n" +
                "<EMAILFROM>" + str_emailFrom + "</EMAILFROM>\n" +
                "<EMAILTO>" + str_emailTo + "</EMAILTO>\n" +
                "<ALTEMAILTO>" + str_altEmailTo + "</ALTEMAILTO>\n" +
                "</SYSTEM>" +
                "<JOB>\n" +
                "<JOBNAME>" + str_jobName + "</JOBNAME>\n" +
                "<INPUTFOLDER>" + str_inputFolder + "</INPUTFOLDER>\n" +
                "<FILEMASK>" + str_fileMask + "</FILEMASK>\n" +
                "<PROCESSORDER>" + str_processOrder + "</PROCESSORDER>\n" +
                "<RETAINFOLDER>" + str_retainFolder + "</RETAINFOLDER>\n" +
                "<OVERRIDEFOLDER>" + str_overrideFolder + "</OVERRIDEFOLDER>\n" +
                "<ERRORFOLDER>" + str_errorFolder + "</ERRORFOLDER>\n" +
                "<POLLINTERVAL>" + str_pollInterval + "</POLLINTERVAL>\n" +
                "<JOBBATCHFILEPATH>" + str_jobBatchFilepath + "</JOBBATCHFILEPATH>\n" +
                "<JOBBATCHPARAMS>" + str_jobBatchParams + "</JOBBATCHPARAMS>\n" +
                "<JOBLOGPATH>" + str_jobLogPath + "</JOBLOGPATH>\n" +
                "<JOBEMAILTO>" + str_jobEmail + "</JOBEMAILTO>\n" +
                "<JOBALTEMAILTO>" + str_jobAltEmail + "</JOBALTEMAILTO>\n" +
                "</JOB>\n" +
                "</APOLLERSETTINGS>";
        boolean bool_output = false;
        try {
            BufferedWriter out = new BufferedWriter(new FileWriter(str_fileName + ".xml"));
            File testForFile = new File(str_fileName + ".xml");
            if (testForFile.exists()) {
                int reply = JOptionPane.showConfirmDialog(null, str_fileName + ".xml already exists. Are you sure you want to overwrite it?", "Form Reset", JOptionPane.YES_NO_OPTION);
                if (reply == JOptionPane.YES_OPTION) {
                    out.write(str_settings);
                    out.flush();
                    out.close();
                    bool_output = true;
                } else {
                    return false;
                }
            } else {
                out.write(str_settings);
                out.flush();
                out.close();
                bool_output = true;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return bool_output;
    }

    public boolean writeToOldFile(String str_fileName) {
        str_jobName = txt_jobName.getText();
        String str_settings = "<JOB>\n" +
                "<JOBNAME>" + str_jobName + "</JOBNAME>\n" +
                "<INPUTFOLDER>" + str_inputFolder + "</INPUTFOLDER>\n" +
                "<FILEMASK>" + str_fileMask + "</FILEMASK>\n" +
                "<PROCESSORDER>" + str_processOrder + "</PROCESSORDER>\n" +
                "<RETAINFOLDER>" + str_retainFolder + "</RETAINFOLDER>\n" +
                "<OVERRIDEFOLDER>" + str_overrideFolder + "</OVERRIDEFOLDER>\n" +
                "<ERRORFOLDER>" + str_errorFolder + "</ERRORFOLDER>\n" +
                "<POLLINTERVAL>" + str_pollInterval + "</POLLINTERVAL>\n" +
                "<JOBBATCHFILEPATH>" + str_jobBatchFilepath + "</JOBBATCHFILEPATH>\n" +
                "<JOBBATCHPARAMS>" + str_jobBatchParams + "</JOBBATCHPARAMS>\n" +
                "<JOBLOGPATH>" + str_jobLogPath + "</JOBLOGPATH>\n" +
                "<JOBEMAILTO>" + str_jobEmail + "</JOBEMAILTO>\n" +
                "<JOBALTEMAILTO>" + str_jobAltEmail + "</JOBALTEMAILTO>\n" +
                "</JOB>\n" +
                "</APOLLERSETTINGS>\n";
        System.out.println("job name: " + str_jobName);
        boolean bool_output = false;
        String str_output = "";
        // Read in the origional file
        try {
            FileInputStream fiStream = new FileInputStream(str_fileName);
            DataInputStream diStream = new DataInputStream(fiStream);
            BufferedReader bReader = new BufferedReader(new InputStreamReader(diStream));
            String inLine;
            while ((inLine = bReader.readLine()) != null) {
                str_output = str_output + inLine;
            }

            File f = new File(str_fileName);
            f.renameTo(new File(str_retainFolder + "/backup_" + str_fileName));
        } catch (IOException e) {
            e.printStackTrace();
        }

        if (str_output.indexOf("<JOBNAME>" + str_jobName + "</JOBNAME>") != -1) {
            JOptionPane.showMessageDialog(null, "A job with that job name already exists. Please use another name");
            str_jobName = "";
            return false;
        }

        //Test Filepaths (They have to exist)
        // Input Folder
        File inputFolder = new File(str_inputFolder);
        if (!inputFolder.exists()) {
            JOptionPane.showMessageDialog(rootPane, "The directory specified for \"Input Folder\" does not exist");
            return false;
        }
        // Retain Folder
        File retainFolder = new File(str_retainFolder);
        if (!retainFolder.exists()) {
            JOptionPane.showMessageDialog(rootPane, "The directory specified for \"Retain Folder\" does not exist");
            return false;
        }
        // Override Folder
        File overrideFolder = new File(str_overrideFolder);
        if (!overrideFolder.exists()) {
            JOptionPane.showMessageDialog(rootPane, "The directory specified for \"Override Folder\" does not exist");
            return false;
        }
        // Error Folder
        File errorFolder = new File(str_errorFolder);
        if (!errorFolder.exists()) {
            JOptionPane.showMessageDialog(rootPane, "The directory specified for \"Error Folder\" does not exist");
            return false;
        }
        // Override Folder
        File jobLogPath = new File(str_jobLogPath);
        if (!jobLogPath.exists()) {
            JOptionPane.showMessageDialog(rootPane, "The directory specified for \"Job Log Path\" does not exist");
            return false;
        }
        // Job Batch Filepath
        File jobBatchFilepath = new File(str_jobBatchFilepath);
        if (!jobBatchFilepath.exists()) {
            JOptionPane.showMessageDialog(rootPane, "The directory specified for \"Job Batch Filepath\" does not exist");
            return false;
        }

        try {
            BufferedWriter out = new BufferedWriter(new FileWriter(str_fileName));
            out.write(str_output.replace("</APOLLERSETTINGS>", str_settings));
            out.flush();
            out.close();
            bool_output = true;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return bool_output;
    }

    private void resetForm() {
        str_smtpSrv = "";
        str_smtpPort = "";
        str_smtpUsr = "";
        str_smtpPsw = "";
        str_emailFrom = "";
        str_emailTo = "";
        str_altEmailTo = "";
        str_jobName = "";
        str_inputFolder = "";
        str_fileMask = "";
        str_processOrder = "";
        str_retainFolder = "";
        str_overrideFolder = "";
        str_errorFolder = "";
        str_pollInterval = "";
        str_jobBatchFilepath = "";
        str_jobBatchParams = "";
        str_jobLogPath = "";
        str_jobEmail = "";
        str_jobAltEmail = "";
        txt_smtpSrv.setText("");
        txt_smtpPort.setText("");
        txt_smtpUsr.setText("");
        txt_smtpPsw.setText("");
        txt_emailFrom.setText("");
        txt_emailTo.setText("");
        txt_altEmailTo.setText("");
        txt_jobName.setText("");
        txt_inputFolder.setText("");
        txt_fileMask.setText("");
        txt_processOrder.setText("");
        txt_retainFolder.setText("");
        txt_overrideFolder.setText("");
        txt_errorFolder.setText("");
        txt_pollInterval.setText("");
        txt_jobBatchFilepath.setText("");
        txt_jobBatchParams.setText("");
        txt_jobLogPath.setText("");
        txt_jobEmail.setText("");
        txt_jobAltEmailTo.setText("");
        pane_fileChooser.setVisible(false);
        pane_jobSettings.setVisible(false);
        pane_sysSettings.setVisible(false);
        btn_done.setEnabled(false);
        rb_existingFile.setSelected(false);
        rb_newFile.setSelected(false);
        fileChooser.repaint();
    }

    public boolean editJobSettings(String fileName, String jobName, String[] changes) {
        // this is for jobs only - add job name to received variables.
        boolean validating = false;

        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = factory.newDocumentBuilder();
            Document doc = factory.newDocumentBuilder().parse(fileName);

            NodeList list = doc.getElementsByTagName(fileName);

            for (int i = 0; i < list.getLength(); i++) {
                //Get element
                Node node = (Node) list.item(i);

                if (node.getNodeName().equalsIgnoreCase("JOB")) {
                    NodeList childList = node.getChildNodes();

                    Node child = (Node) childList.item(0); // might have to be Node, not Element
                    if (child.getTextContent().equalsIgnoreCase(jobName)) {
                        for (int x = 1; x < childList.getLength(); x++) {
                            child = (Node) childList.item(x); // might have to be Node, not Element
                            if (!changes[x].equals("") && !changes[x].equals(null)) {
                                child.setNodeValue(changes[x]);
                            }
                        }
                    }
                }
            }
            try {
                OutputFormat format = new OutputFormat(doc);
                FileWriter fw = new FileWriter(fileName);
                XMLSerializer serial = new XMLSerializer(fw, format);
                serial.asDOMSerializer();
                serial.serialize(doc.getDocumentElement());
                fw.flush();
                fw.close();
            } catch (IOException io) {
                io.printStackTrace();
            }
        } catch (ParserConfigurationException pce) {
            pce.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        } catch (SAXException saxe) {
            saxe.printStackTrace();
        }

        return true;
    }

    public boolean editSystemSettings(String fileName, String[] changes) {
        // this is for system settings only - add job name to received variables.
        boolean validating = false;
        if (!changes[0].equals("") && !changes[0].equals(null)) {
            try {
                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                DocumentBuilder docBuilder = factory.newDocumentBuilder();
                [B]Document doc = factory.newDocumentBuilder().parse(fileName);[/B]
                NodeList list = doc.getElementsByTagName(fileName);

                for (int i = 0; i < list.getLength(); i++) {
                    //Get Node
                    Node node = (Node) list.item(i);
                    // change system settings
                    if (node.getNodeName().equalsIgnoreCase("SYSTEM")) {
                        NodeList childList = node.getChildNodes();
                        for (int x = 0; x < childList.getLength(); x++) {
                            if (!changes[x].equals("") && !changes[x].equals(null)) {
                                Node child = (Node) childList.item(x);
                                child.setNodeValue(changes[x]);
                            }
                        }
                    }
                }
                try {
                    OutputFormat format = new OutputFormat(doc);
                    FileWriter fw = new FileWriter(fileName);
                    XMLSerializer serial = new XMLSerializer(fw, format);
                    serial.asDOMSerializer();
                    serial.serialize(doc.getDocumentElement());
                    fw.flush();
                    fw.close();
                } catch (IOException io) {
                    io.printStackTrace();
                }
            } catch (ParserConfigurationException pce) {
                pce.printStackTrace();
            } catch (IOException ioe) {
                ioe.printStackTrace();
            } catch (SAXException saxe) {
                saxe.printStackTrace();
            }
        } else {
            return false;
        }
        return true;
    }
}

Yea, I know it isn't too pretty :)

Here's the error:

[B]java.net.MalformedURLException: unknown protocol: c[/B]
        at java.net.URL.<init>(URL.java:574)
        at java.net.URL.<init>(URL.java:464)
        at java.net.URL.<init>(URL.java:413)
        at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:650)
        at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:186)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
        at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:225)
        at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
        at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:180)
        at gui.guiV2.editSystemSettings(guiV2.java:1160)
        at gui.guiV2.editExistingFile(guiV2.java:836)
        at gui.guiV2.fileChooserActionPerformed(guiV2.java:725)
        at gui.guiV2.access$200(guiV2.java:28)
        at gui.guiV2$3.actionPerformed(guiV2.java:410)
        at javax.swing.JFileChooser.fireActionPerformed(JFileChooser.java:1717)
        at javax.swing.JFileChooser.approveSelection(JFileChooser.java:1627)
        at javax.swing.plaf.basic.BasicFileChooserUI$Handler.mouseClicked(BasicFileChooserUI.java:431)
        at sun.swing.FilePane$Handler.mouseClicked(FilePane.java:1683)
        at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253)
        at java.awt.Component.processMouseEvent(Component.java:6041)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
        at java.awt.Component.processEvent(Component.java:5803)
        at java.awt.Container.processEvent(Container.java:2058)
        at java.awt.Component.dispatchEventImpl(Component.java:4410)
        at java.awt.Container.dispatchEventImpl(Container.java:2116)
        at java.awt.Component.dispatchEvent(Component.java:4240)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3995)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
        at java.awt.Container.dispatchEventImpl(Container.java:2102)
        at java.awt.Window.dispatchEventImpl(Window.java:2429)
        at java.awt.Component.dispatchEvent(Component.java:4240)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

The filename is C:\Documents and Settings\Administrator.APC-CT2\Desktop\lodewyk.xml
I made sure of it. any idea what the problem might be? Sorry also if I put too much code in this post, I wasn't certain which parts I could leave out. Thank you for the help, in advance :)

Because bold doesn't show very good try to add some color as well next time.

Is this the line:
Document doc = factory.newDocumentBuilder().parse(fileName)

If yes the problem might be with the contents of the file.

Also I noticed this:

public boolean writeToOldFile(String str_fileName) {
        str_jobName = txt_jobName.getText();
        String str_settings = "<JOB>\n" +
                "<JOBNAME>" + str_jobName + "</JOBNAME>\n" +
                "<INPUTFOLDER>" + str_inputFolder + "</INPUTFOLDER>\n" +
                "<FILEMASK>" + str_fileMask + "</FILEMASK>\n" +
                "<PROCESSORDER>" + str_processOrder + "</PROCESSORDER>\n" +
                "<RETAINFOLDER>" + str_retainFolder + "</RETAINFOLDER>\n" +
                "<OVERRIDEFOLDER>" + str_overrideFolder + "</OVERRIDEFOLDER>\n" +
                "<ERRORFOLDER>" + str_errorFolder + "</ERRORFOLDER>\n" +
                "<POLLINTERVAL>" + str_pollInterval + "</POLLINTERVAL>\n" +
                "<JOBBATCHFILEPATH>" + str_jobBatchFilepath + "</JOBBATCHFILEPATH>\n" +
                "<JOBBATCHPARAMS>" + str_jobBatchParams + "</JOBBATCHPARAMS>\n" +
                "<JOBLOGPATH>" + str_jobLogPath + "</JOBLOGPATH>\n" +
                "<JOBEMAILTO>" + str_jobEmail + "</JOBEMAILTO>\n" +
                "<JOBALTEMAILTO>" + str_jobAltEmail + "</JOBALTEMAILTO>\n" +
                "</JOB>\n" +
                "[B]</APOLLERSETTINGS>[/B]\n";

Is it correct that you close the APOLLERSETTINGS without being open? Do you open it somewhere else?

Is this the line:
Document doc = factory.newDocumentBuilder().parse(fileName)

Is it correct that you close the APOLLERSETTINGS without being open? Do you open it somewhere else?

Yes, it's that line, thanks.

The APOLLERSETTINGS tag is opened elsewhere. The method you're seeing there is one that's already working, so it's fine.

Can you post the contents of the xml file?

<?xml version="1.0" encoding="UTF-8" ?>
- <APOLLERSETTINGS>
- <SYSTEM>
<VERSION>3.1</VERSION>
<SMTPSRV>blue</SMTPSRV>
<SMTPPORT>29</SMTPPORT>
<SMTPUSR>Me</SMTPUSR>
<SMTPPSW>Password</SMTPPSW>
<EMAILFROM>lodewyk.duminy@gmail.com</EMAILFROM>
<EMAILTO>lodewyk.duminy@gmail.com</EMAILTO>
<ALTEMAILTO>lodewyk.duminy@gmail.com</ALTEMAILTO>
</SYSTEM>
- <JOB>
<JOBNAME>The Name</JOBNAME>
<INPUTFOLDER>C:\</INPUTFOLDER>
<FILEMASK>*.txt</FILEMASK>
<PROCESSORDER>LASTMOD</PROCESSORDER>
<RETAINFOLDER>C:\</RETAINFOLDER>
<OVERRIDEFOLDER>C:\</OVERRIDEFOLDER>
<ERRORFOLDER>C:\</ERRORFOLDER>
<POLLINTERVAL>BUYA</POLLINTERVAL>
<JOBBATCHFILEPATH>C:\</JOBBATCHFILEPATH>
<JOBBATCHPARAMS>three</JOBBATCHPARAMS>
<JOBLOGPATH>C:\</JOBLOGPATH>
<JOBEMAILTO>lodewyk.duminy@gmail.com</JOBEMAILTO>
<JOBALTEMAILTO>lodewyk.duminy@gmail.com</JOBALTEMAILTO>
</JOB>
</APOLLERSETTINGS>

Thanks for the help :)

You get this exception:

java.net.MalformedURLException: unknown protocol: c

When you read the file. I assumed that your file could not be read dut to a tag error.

But then I see in your file this:

<INPUTFOLDER>C:\</INPUTFOLDER>

I am no expert in xml, But can you try this:
Call the command that gives you the exception in a separate main method and see if you get the same exception.:

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                DocumentBuilder docBuilder = factory.newDocumentBuilder();
                Document doc = factory.newDocumentBuilder().parse(fileName);

If yes, change the value of C:\ with something else and see if you will get the same error

The parse(String) requires a URI, so on windows system add "file:///" before the filename

So use
Document doc = factory.newDocumentBuilder().parse("file:///"+fileName);

Or better use
Document doc = factory.newDocumentBuilder().parse(new File(fileName));

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.