Removed the Apache regular expression stuff and replaced it with Java's

new built-in support. In the case of the username matcher Apache's stuff
wasn't properly allowing underscores.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@1201 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2003-08-15 22:35:57 +00:00
parent 319ac0aa17
commit f85fd28c52
2 changed files with 15 additions and 26 deletions
@@ -1,5 +1,5 @@
// //
// $Id: MailUtil.java,v 1.5 2002/05/02 01:13:35 shaper Exp $ // $Id: MailUtil.java,v 1.6 2003/08/15 22:35:57 mdb Exp $
// //
// samskivert library - useful routines for java programs // samskivert library - useful routines for java programs
// Copyright (C) 2001 Michael Bayne // Copyright (C) 2001 Michael Bayne
@@ -23,8 +23,8 @@ package com.samskivert.net;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import org.apache.regexp.RE; import java.util.regex.PatternSyntaxException;
import org.apache.regexp.RESyntaxException; import java.util.regex.Pattern;
import com.samskivert.Log; import com.samskivert.Log;
@@ -80,7 +80,7 @@ public class MailUtil
*/ */
public static boolean isValidAddress (String address) public static boolean isValidAddress (String address)
{ {
return _emailre.match(address); return _emailre.matcher(address).matches();
} }
public static void main (String[] args) public static void main (String[] args)
@@ -96,13 +96,14 @@ public class MailUtil
protected static final String EMAIL_REGEX = "^([-A-Za-z0-9_.!%+]+@" + protected static final String EMAIL_REGEX = "^([-A-Za-z0-9_.!%+]+@" +
"[-a-zA-Z0-9]+(\\.[-a-zA-Z0-9]+)*\\.[-a-zA-Z0-9]+)$"; "[-a-zA-Z0-9]+(\\.[-a-zA-Z0-9]+)*\\.[-a-zA-Z0-9]+)$";
/** Used to check email addresses for validity. */ /** A compiled version of our email regular expression. */
protected static RE _emailre; protected static Pattern _emailre;
static { static {
try { try {
_emailre = new RE(EMAIL_REGEX); _emailre = Pattern.compile(EMAIL_REGEX);
} catch (RESyntaxException rese) { } catch (PatternSyntaxException pse) {
Log.warning("Unable to initialize email regexp?! " + rese); Log.warning("Unable to initialize email regexp?!");
} Log.logStackTrace(pse);
}
} }
} }
@@ -1,5 +1,5 @@
// //
// $Id: UserRepository.java,v 1.24 2002/11/01 00:43:58 mdb Exp $ // $Id: UserRepository.java,v 1.25 2003/08/15 22:35:57 mdb Exp $
// //
// samskivert library - useful routines for java programs // samskivert library - useful routines for java programs
// Copyright (C) 2001 Michael Bayne // Copyright (C) 2001 Michael Bayne
@@ -30,9 +30,6 @@ import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Properties; import java.util.Properties;
import org.apache.regexp.RE;
import org.apache.regexp.RESyntaxException;
import com.samskivert.Log; import com.samskivert.Log;
import com.samskivert.io.PersistenceException; import com.samskivert.io.PersistenceException;
import com.samskivert.jdbc.ConnectionProvider; import com.samskivert.jdbc.ConnectionProvider;
@@ -137,7 +134,8 @@ public class UserRepository extends JORARepository
} }
// check that it's only valid characters // check that it's only valid characters
if (!_userre.match(username)) { if (!username.matches("^[_A-Za-z0-9]+$")) {
Log.info("Mismatch " + username + ".");
throw new InvalidUsernameException("error.invalid_username"); throw new InvalidUsernameException("error.invalid_username");
} }
@@ -513,16 +511,6 @@ public class UserRepository extends JORARepository
protected Table _utable; protected Table _utable;
/** Used to check usernames for invalid characteres. */
protected static RE _userre;
static {
try {
_userre = new RE("^[_A-Za-z0-9]+$");
} catch (RESyntaxException rese) {
Log.warning("Unable to initialize user regexp?! " + rese);
}
}
/** The minimum allowable length of a username. */ /** The minimum allowable length of a username. */
protected static final int MINIMUM_USERNAME_LENGTH = 3; protected static final int MINIMUM_USERNAME_LENGTH = 3;
} }