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>
30 public class Verifier {
33 * Checks whether the given name is a valid node name.
37 * @return <code>true</code> if the name is okay, <code>false</code> if
40 public static boolean verifyNodeName(String name) {
41 return (name != null) && (name.trim().length() != 0);
45 * Verifies the given hostname by trying to resolve it.
48 * The hostname to verify
49 * @return <code>true</code> if the hostname is not empty and can be
50 * resolved, <code>false</code> otherwise
52 public static boolean verifyHostname(String hostname) {
53 if ((hostname == null) || (hostname.trim().length() == 0)) {
57 InetAddress.getByName(hostname.trim());
59 } catch (UnknownHostException uhe1) {
65 * Verifies that the port number is numeric and in the range from
66 * <code>0</code> to <code>65535</code>.
69 * The port number string
70 * @return <code>true</code> if the port number is okay,
71 * <code>false</code> otherwise
73 public static boolean verifyPort(String portString) {
74 if ((portString == null) || (portString.trim().length() == 0)) {
78 int portNumber = Integer.valueOf(portString.trim());
79 if ((portNumber > 0) && (portNumber < 65536)) {
82 } catch (NumberFormatException nfe1) {