externalize verifier for variouos stuff
[jSite2.git] / src / net / pterodactylus / jsite / gui / EditNodeDialog.java
index 260466e..2e49055 100644 (file)
@@ -25,8 +25,6 @@ import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
 import java.awt.Insets;
 import java.awt.event.ActionEvent;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
 
 import javax.swing.BorderFactory;
 import javax.swing.JButton;
@@ -36,6 +34,7 @@ import javax.swing.JPanel;
 import javax.swing.JTextField;
 import javax.swing.border.EtchedBorder;
 
+import net.pterodactylus.jsite.core.Verifier;
 import net.pterodactylus.jsite.i18n.I18n;
 import net.pterodactylus.jsite.i18n.I18nable;
 import net.pterodactylus.jsite.i18n.gui.I18nAction;
@@ -246,65 +245,18 @@ public class EditNodeDialog extends JDialog implements I18nable {
        //
 
        /**
-        * Checks the name textfield for valid input.
-        *
-        * @return <code>true</code> if the name textfield seem okay,
-        *         <code>false</code> if there is an error
-        */
-       private boolean verifyName() {
-               return (nameTextField.getText().trim().length() != 0);
-       }
-
-       /**
-        * Verifies the hostname textfield by resolving the given name.
-        *
-        * @return <code>true</code> if the hostname is not empty and can be
-        *         resolved, <code>false</code> otherwise
-        */
-       private boolean verifyHostname() {
-               if (hostnameTextField.getText().trim().length() == 0) {
-                       return false;
-               }
-               try {
-                       InetAddress.getByName(hostnameTextField.getText().trim());
-                       return true;
-               } catch (UnknownHostException uhe1) {
-                       return false;
-               }
-       }
-
-       /**
-        * Verifies that the port number is numeric and in the range from
-        * <code>0</code> to <code>65535</code>.
-        *
-        * @return <code>true</code> if the port number is okay,
-        *         <code>false</code> otherwise
-        */
-       private boolean verifyPort() {
-               try {
-                       int portNumber = Integer.valueOf(portTextField.getText().trim());
-                       if ((portNumber > 0) && (portNumber < 65536)) {
-                               return true;
-                       }
-               } catch (NumberFormatException nfe1) {
-                       /* ignore. */
-               }
-               return false;
-       }
-
-       /**
         * Confirms the node settings and closes the dialog.
         */
        private void confirm() {
-               if (!verifyName()) {
+               if (!Verifier.verifyNodeName(nameTextField.getText())) {
                        JOptionPane.showMessageDialog(this, I18n.get("editNodeDialog.error.name.message"), I18n.get("editNodeDialog.error.name.title"), JOptionPane.ERROR_MESSAGE);
                        return;
                }
-               if (!verifyHostname()) {
+               if (!Verifier.verifyHostname(hostnameTextField.getText())) {
                        JOptionPane.showMessageDialog(this, I18n.get("editNodeDialog.error.hostname.message"), I18n.get("editNodeDialog.error.hostname.title"), JOptionPane.ERROR_MESSAGE);
                        return;
                }
-               if (!verifyPort()) {
+               if (!Verifier.verifyPort(portTextField.getText())) {
                        JOptionPane.showMessageDialog(this, I18n.get("editNodeDialog.error.port.message"), I18n.get("editNodeDialog.error.port.title"), JOptionPane.ERROR_MESSAGE);
                        return;
                }