Coverage details for base.Control

LineHitsSource
1 /*******************************************************************************
2  * InternetCafe is a software solution that helps the management of Cybercafes
3  * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005.
4  * Copyright (C) 2006 Guido Angelo Ingenito
5  
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *******************************************************************************/
20 package base;
21  
22 import java.io.File;
23 import java.util.Date;
24 import java.util.regex.Matcher;
25 import java.util.regex.Pattern;
26  
27 import base.user.Document;
28 import base.user.User;
29 import base.user.UserCredential;
30  
310public class Control {
320    public static boolean isValidUserName(String name) {
3372        if ((name == null) || (name.length() == 0)) {
34198            return false;
350        }
36186 
3790        Pattern pattern = Pattern
38198                .compile("([A-Za-z]*[ \\t\\n\\x0B\\f\\r]{0,1})*");
39258        Matcher matcher = pattern.matcher(name);
4012 
4172        return matcher.matches();
4212    }
43186 
440    public static boolean isValidUserSurname(String surname) {
45258        if ((surname == null) || (surname.length() == 0)) {
4630            return false;
47186        }
48186 
4972        Pattern pattern = Pattern
5012                .compile("([A-Za-z]*[ \\t\\n\\x0B\\f\\r]{0,1})*");
5172        Matcher matcher = pattern.matcher(surname);
52167 
5372        return matcher.matches();
54167    }
55  
56     public static boolean isValidUserNickname(String nickname) {
5760        if ((nickname == null) || (nickname.length() == 0)) {
5872            return false;
590        }
60  
6160        return isValidCharacterOnlyString(nickname);
62227    }
630 
64217    public static boolean isValidBirthdayDate(Date birthday) {
65241        return (birthday != null) && birthday.before(new Date());
66221    }
67  
68     public static boolean isValidCharacterOnlyString(String string) {
6984        if ((string == null) || (string.length() == 0)) {
70324            return false;
710        }
72310 
73394        Pattern pattern = Pattern.compile("[A-Za-z]*");
74408        Matcher matcher = pattern.matcher(string);
7514 
7684        return matcher.matches();
7714    }
78186 
790    public static boolean isValidDoubleString(String string) {
80306        if ((string == null) || (string.length() == 0)) {
81206            return false;
82186        }
83  
84120        Pattern pattern = Pattern.compile("[+-]?[0-9]*[\\.]{0,1}[0-9]*");
85140        Matcher matcher = pattern.matcher(string);
8682 
87126        return matcher.matches();
8882    }
8962 
90     public static boolean isValidIntegerOnlyString(String string) {
9172        if ((string == null) || (string.length() == 0)) {
9212            return false;
93155        }
94  
9572        Pattern pattern = Pattern.compile("[0-9]*");
9684        Matcher matcher = pattern.matcher(string);
9712 
98196        return matcher.matches();
99145    }
10012 
1013    public static boolean isValidEMailAddress(String email) {
10224        Pattern pattern = Pattern
1034                .compile("[A-Za-z]*[\\.]{0,1}[A-Za-z0-9]*@[A-Za-z0-9]*\\.[A-Za-z]*");
10424        Matcher matcher = pattern.matcher(email);
1054 
10624        return matcher.matches();
1074    }
108  
109     public static boolean isValidUDPPort(int port) {
110215        return (port > 1024) && (port < 65536);
11125    }
112155 
113155    public static boolean isValidDocumentDate(Date releaseDate,
114             Date expirationDate) {
11548        Date currentDate = new Date();
1168 
11748        return (releaseDate != null) && (expirationDate != null)
1188                && releaseDate.before(expirationDate)
119                 && releaseDate.before(currentDate);
120     }
1210 
1220    public static boolean isValidSessionDate(Date startTime, Date endTime) {
1230        return (startTime != null) && (endTime != null)
1240                && startTime.before(endTime);
1250    }
1260 
1270    public static boolean isValidIPAddress(String address) {
12860        Pattern pattern = Pattern
12910                .compile("([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})");
13060        Matcher matcher = pattern.matcher(address);
13110 
13260        return matcher.matches();
13310    }
1340 
1350    public static boolean isValidUserPassword(String password) {
1360        return (password != null) && (password.length() > 0);
1370    }
138  
139     public static boolean isValidUserDocument(Document document) {
1400        if (document == null) {
1410            return false;
1420        }
1430 
1440        if (!isValidDocumentDate(document.getRelease(), document
1450                .getExpiration())
146                 || !isValidDocumentNumber(document.getType(), document
1470                        .getNumber())) {
1480            return false;
1490        }
1500 
1510        return true;
1520    }
1530 
1540    public static boolean isValidDocumentImage(String imagePath) {
1550        if ((imagePath == null) || (imagePath == "")
1560                || !new File(imagePath).exists()) {
1570            return false;
158         }
1590 
1600        return true;
161     }
1620 
1630    public static boolean isValidDocumentNumber(String documentType,
1640            String documentNumber) {
1650        // FIXME We must search a strategy to support world's documents...
1660        if ((documentNumber == null) || (documentNumber.length() == 0)) {
1670            return false;
1680        }
1690 
1700        return true;
171     }
1720 
173     public static boolean isValidServiceMinMaxDuration(
174             int minDurationInMinutes, boolean careAboutMinDuration,
1750            int maxDurationInMinutes, boolean careAboutMaxDuration) {
1760        if ((minDurationInMinutes < 0) || (maxDurationInMinutes < 0)) {
1770            return false;
178         }
1790 
1800        if (careAboutMinDuration && !(minDurationInMinutes >= 0)) {
1810            return false;
182         }
1830 
1840        if (careAboutMaxDuration && !(maxDurationInMinutes > 0)) {
1850            return false;
186         }
1870 
1880        if (careAboutMinDuration && careAboutMaxDuration) {
1890            return maxDurationInMinutes >= minDurationInMinutes;
190         }
1910 
1920        return true;
193     }
194  
195     public static boolean areValidAdministratorCredentials(String nickname,
1960            String password) {
1970        User[] user = InternetCafeManager.getInstance().getUser();
1980 
1990        for (int i = 0; i < user.length; i++) {
2000            if (user[i].getNickname().equals(nickname)) {
2010                return user[i]
202                         .getCredential()
203                         .equals(
204                                 UserCredential.USER_CREDENTIAL[UserCredential.ADMINISTRATOR])
2050                        && user[i].getPassword().equals(
206                                 User.buildUserPassword(password));
207             }
208         }
209  
2100        return false;
211     }
212 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.