--- /dev/null
+/*
+ * jSite2 - Verifier.java -
+ * Copyright © 2008 David Roden
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+package net.pterodactylus.jsite.core;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+/**
+ * Contains verifier for various settings.
+ *
+ * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
+ * @version $Id$
+ */
+public class Verifier {
+
+ /**
+ * Checks whether the given name is a valid node name.
+ *
+ * @param name
+ * The name to verify
+ * @return <code>true</code> if the name is okay, <code>false</code> if
+ * there is an error
+ */
+ public static boolean verifyNodeName(String name) {
+ return (name != null) && (name.trim().length() != 0);
+ }
+
+ /**
+ * Verifies the given hostname by trying to resolve it.
+ *
+ * @param hostname
+ * The hostname to verify
+ * @return <code>true</code> if the hostname is not empty and can be
+ * resolved, <code>false</code> otherwise
+ */
+ public static boolean verifyHostname(String hostname) {
+ if ((hostname == null) || (hostname.trim().length() == 0)) {
+ return false;
+ }
+ try {
+ InetAddress.getByName(hostname.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>.
+ *
+ * @param portString
+ * The port number string
+ * @return <code>true</code> if the port number is okay,
+ * <code>false</code> otherwise
+ */
+ public static boolean verifyPort(String portString) {
+ if ((portString == null) || (portString.trim().length() == 0)) {
+ return false;
+ }
+ try {
+ int portNumber = Integer.valueOf(portString.trim());
+ if ((portNumber > 0) && (portNumber < 65536)) {
+ return true;
+ }
+ } catch (NumberFormatException nfe1) {
+ /* ignore. */
+ }
+ return false;
+ }
+
+}