001/*
002 * IzPack - Copyright 2001-2005 Julien Ponge, All Rights Reserved.
003 * 
004 * http://www.izforge.com/izpack/
005 * http://developer.berlios.de/projects/izpack/
006 * 
007 * Copyright 2004 Thorsten Kamann
008 * 
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 * 
013 *     http://www.apache.org/licenses/LICENSE-2.0
014 *     
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 */
021
022package com.izforge.izpack.util;
023
024import com.izforge.izpack.panels.ProcessingClient;
025import com.izforge.izpack.panels.Validator;
026
027/**
028 * A validator to check whether the field content is a port .
029 * 
030 * @author thorque
031 */
032public class IsPortValidator implements Validator
033{
034
035    public boolean validate(ProcessingClient client)
036    {
037        int port = 0;
038
039        if (client.getFieldContents(0).equals("")) { return false; }
040
041        try
042        {
043            port = Integer.parseInt(client.getFieldContents(0));
044            if (port > 0 && port < 32000) { return true; }
045        }
046        catch (Exception ex)
047        {
048            return false;
049        }
050
051        return false;
052    }
053
054}