| Line | Hits | Source |
|---|---|---|
| 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 | ||
| 31 | 0 | public class Control { |
| 32 | 0 | public static boolean isValidUserName(String name) { |
| 33 | 72 | if ((name == null) || (name.length() == 0)) { |
| 34 | 198 | return false; |
| 35 | 0 | } |
| 36 | 186 | |
| 37 | 90 | Pattern pattern = Pattern |
| 38 | 198 | .compile("([A-Za-z]*[ \\t\\n\\x0B\\f\\r]{0,1})*"); |
| 39 | 258 | Matcher matcher = pattern.matcher(name); |
| 40 | 12 | |
| 41 | 72 | return matcher.matches(); |
| 42 | 12 | } |
| 43 | 186 | |
| 44 | 0 | public static boolean isValidUserSurname(String surname) { |
| 45 | 258 | if ((surname == null) || (surname.length() == 0)) { |
| 46 | 30 | return false; |
| 47 | 186 | } |
| 48 | 186 | |
| 49 | 72 | Pattern pattern = Pattern |
| 50 | 12 | .compile("([A-Za-z]*[ \\t\\n\\x0B\\f\\r]{0,1})*"); |
| 51 | 72 | Matcher matcher = pattern.matcher(surname); |
| 52 | 167 | |
| 53 | 72 | return matcher.matches(); |
| 54 | 167 | } |
| 55 | ||
| 56 | public static boolean isValidUserNickname(String nickname) { | |
| 57 | 60 | if ((nickname == null) || (nickname.length() == 0)) { |
| 58 | 72 | return false; |
| 59 | 0 | } |
| 60 | ||
| 61 | 60 | return isValidCharacterOnlyString(nickname); |
| 62 | 227 | } |
| 63 | 0 | |
| 64 | 217 | public static boolean isValidBirthdayDate(Date birthday) { |
| 65 | 241 | return (birthday != null) && birthday.before(new Date()); |
| 66 | 221 | } |
| 67 | ||
| 68 | public static boolean isValidCharacterOnlyString(String string) { | |
| 69 | 84 | if ((string == null) || (string.length() == 0)) { |
| 70 | 324 | return false; |
| 71 | 0 | } |
| 72 | 310 | |
| 73 | 394 | Pattern pattern = Pattern.compile("[A-Za-z]*"); |
| 74 | 408 | Matcher matcher = pattern.matcher(string); |
| 75 | 14 | |
| 76 | 84 | return matcher.matches(); |
| 77 | 14 | } |
| 78 | 186 | |
| 79 | 0 | public static boolean isValidDoubleString(String string) { |
| 80 | 306 | if ((string == null) || (string.length() == 0)) { |
| 81 | 206 | return false; |
| 82 | 186 | } |
| 83 | ||
| 84 | 120 | Pattern pattern = Pattern.compile("[+-]?[0-9]*[\\.]{0,1}[0-9]*"); |
| 85 | 140 | Matcher matcher = pattern.matcher(string); |
| 86 | 82 | |
| 87 | 126 | return matcher.matches(); |
| 88 | 82 | } |
| 89 | 62 | |
| 90 | public static boolean isValidIntegerOnlyString(String string) { | |
| 91 | 72 | if ((string == null) || (string.length() == 0)) { |
| 92 | 12 | return false; |
| 93 | 155 | } |
| 94 | ||
| 95 | 72 | Pattern pattern = Pattern.compile("[0-9]*"); |
| 96 | 84 | Matcher matcher = pattern.matcher(string); |
| 97 | 12 | |
| 98 | 196 | return matcher.matches(); |
| 99 | 145 | } |
| 100 | 12 | |
| 101 | 3 | public static boolean isValidEMailAddress(String email) { |
| 102 | 24 | Pattern pattern = Pattern |
| 103 | 4 | .compile("[A-Za-z]*[\\.]{0,1}[A-Za-z0-9]*@[A-Za-z0-9]*\\.[A-Za-z]*"); |
| 104 | 24 | Matcher matcher = pattern.matcher(email); |
| 105 | 4 | |
| 106 | 24 | return matcher.matches(); |
| 107 | 4 | } |
| 108 | ||
| 109 | public static boolean isValidUDPPort(int port) { | |
| 110 | 215 | return (port > 1024) && (port < 65536); |
| 111 | 25 | } |
| 112 | 155 | |
| 113 | 155 | public static boolean isValidDocumentDate(Date releaseDate, |
| 114 | Date expirationDate) { | |
| 115 | 48 | Date currentDate = new Date(); |
| 116 | 8 | |
| 117 | 48 | return (releaseDate != null) && (expirationDate != null) |
| 118 | 8 | && releaseDate.before(expirationDate) |
| 119 | && releaseDate.before(currentDate); | |
| 120 | } | |
| 121 | 0 | |
| 122 | 0 | public static boolean isValidSessionDate(Date startTime, Date endTime) { |
| 123 | 0 | return (startTime != null) && (endTime != null) |
| 124 | 0 | && startTime.before(endTime); |
| 125 | 0 | } |
| 126 | 0 | |
| 127 | 0 | public static boolean isValidIPAddress(String address) { |
| 128 | 60 | Pattern pattern = Pattern |
| 129 | 10 | .compile("([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})"); |
| 130 | 60 | Matcher matcher = pattern.matcher(address); |
| 131 | 10 | |
| 132 | 60 | return matcher.matches(); |
| 133 | 10 | } |
| 134 | 0 | |
| 135 | 0 | public static boolean isValidUserPassword(String password) { |
| 136 | 0 | return (password != null) && (password.length() > 0); |
| 137 | 0 | } |
| 138 | ||
| 139 | public static boolean isValidUserDocument(Document document) { | |
| 140 | 0 | if (document == null) { |
| 141 | 0 | return false; |
| 142 | 0 | } |
| 143 | 0 | |
| 144 | 0 | if (!isValidDocumentDate(document.getRelease(), document |
| 145 | 0 | .getExpiration()) |
| 146 | || !isValidDocumentNumber(document.getType(), document | |
| 147 | 0 | .getNumber())) { |
| 148 | 0 | return false; |
| 149 | 0 | } |
| 150 | 0 | |
| 151 | 0 | return true; |
| 152 | 0 | } |
| 153 | 0 | |
| 154 | 0 | public static boolean isValidDocumentImage(String imagePath) { |
| 155 | 0 | if ((imagePath == null) || (imagePath == "") |
| 156 | 0 | || !new File(imagePath).exists()) { |
| 157 | 0 | return false; |
| 158 | } | |
| 159 | 0 | |
| 160 | 0 | return true; |
| 161 | } | |
| 162 | 0 | |
| 163 | 0 | public static boolean isValidDocumentNumber(String documentType, |
| 164 | 0 | String documentNumber) { |
| 165 | 0 | // FIXME We must search a strategy to support world's documents... |
| 166 | 0 | if ((documentNumber == null) || (documentNumber.length() == 0)) { |
| 167 | 0 | return false; |
| 168 | 0 | } |
| 169 | 0 | |
| 170 | 0 | return true; |
| 171 | } | |
| 172 | 0 | |
| 173 | public static boolean isValidServiceMinMaxDuration( | |
| 174 | int minDurationInMinutes, boolean careAboutMinDuration, | |
| 175 | 0 | int maxDurationInMinutes, boolean careAboutMaxDuration) { |
| 176 | 0 | if ((minDurationInMinutes < 0) || (maxDurationInMinutes < 0)) { |
| 177 | 0 | return false; |
| 178 | } | |
| 179 | 0 | |
| 180 | 0 | if (careAboutMinDuration && !(minDurationInMinutes >= 0)) { |
| 181 | 0 | return false; |
| 182 | } | |
| 183 | 0 | |
| 184 | 0 | if (careAboutMaxDuration && !(maxDurationInMinutes > 0)) { |
| 185 | 0 | return false; |
| 186 | } | |
| 187 | 0 | |
| 188 | 0 | if (careAboutMinDuration && careAboutMaxDuration) { |
| 189 | 0 | return maxDurationInMinutes >= minDurationInMinutes; |
| 190 | } | |
| 191 | 0 | |
| 192 | 0 | return true; |
| 193 | } | |
| 194 | ||
| 195 | public static boolean areValidAdministratorCredentials(String nickname, | |
| 196 | 0 | String password) { |
| 197 | 0 | User[] user = InternetCafeManager.getInstance().getUser(); |
| 198 | 0 | |
| 199 | 0 | for (int i = 0; i < user.length; i++) { |
| 200 | 0 | if (user[i].getNickname().equals(nickname)) { |
| 201 | 0 | return user[i] |
| 202 | .getCredential() | |
| 203 | .equals( | |
| 204 | UserCredential.USER_CREDENTIAL[UserCredential.ADMINISTRATOR]) | |
| 205 | 0 | && user[i].getPassword().equals( |
| 206 | User.buildUserPassword(password)); | |
| 207 | } | |
| 208 | } | |
| 209 | ||
| 210 | 0 | return false; |
| 211 | } | |
| 212 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |