2 * jSite2 - Verifier.java -
3 * Copyright © 2008 David Roden
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 package net.pterodactylus.jsite.core;
22 import java.net.InetAddress;
23 import java.net.UnknownHostException;
26 * Contains verifier for various settings.
28 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
31 public class Verifier {
34 * Checks whether the given name is a valid node name.
38 * @return <code>true</code> if the name is okay, <code>false</code> if
41 public static boolean verifyNodeName(String name) {
42 return (name != null) && (name.trim().length() != 0);
46 * Verifies the given hostname by trying to resolve it.
49 * The hostname to verify
50 * @return <code>true</code> if the hostname is not empty and can be
51 * resolved, <code>false</code> otherwise
53 public static boolean verifyHostname(String hostname) {
54 if ((hostname == null) || (hostname.trim().length() == 0)) {
58 InetAddress.getByName(hostname.trim());
60 } catch (UnknownHostException uhe1) {
66 * Verifies that the port number is numeric and in the range from
67 * <code>0</code> to <code>65535</code>.
70 * The port number string
71 * @return <code>true</code> if the port number is okay,
72 * <code>false</code> otherwise
74 public static boolean verifyPort(String portString) {
75 if ((portString == null) || (portString.trim().length() == 0)) {
79 int portNumber = Integer.valueOf(portString.trim());
80 if ((portNumber > 0) && (portNumber < 65536)) {
83 } catch (NumberFormatException nfe1) {