You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2006/10/13 17:09:09 UTC
svn commit: r463700 - in /james/server/trunk/src/java/org/apache/james:
services/VirtualUserTableManagement.java vut/AbstractVirtualUserTable.java
Author: norman
Date: Fri Oct 13 08:09:08 2006
New Revision: 463700
URL: http://svn.apache.org/viewvc?view=rev&rev=463700
Log:
Add javadocs. Remove code duplication. See JAMES-582
Modified:
james/server/trunk/src/java/org/apache/james/services/VirtualUserTableManagement.java
james/server/trunk/src/java/org/apache/james/vut/AbstractVirtualUserTable.java
Modified: james/server/trunk/src/java/org/apache/james/services/VirtualUserTableManagement.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/services/VirtualUserTableManagement.java?view=diff&rev=463700&r1=463699&r2=463700
==============================================================================
--- james/server/trunk/src/java/org/apache/james/services/VirtualUserTableManagement.java (original)
+++ james/server/trunk/src/java/org/apache/james/services/VirtualUserTableManagement.java Fri Oct 13 08:09:08 2006
@@ -27,10 +27,69 @@
public static final String ROLE = "org.apache.james.services.VirtualUserTableManagement";
+ /**
+ * Add regex mapping
+ *
+ * @param user the username. Null if no username should be used
+ * @param domain the domain. Null if no domain should be used
+ * @param regex the regex.
+ * @return true if successfully
+ * @throws InvalidMappingException get thrown if an invalid argument was given
+ */
public boolean addRegexMapping(String user, String domain, String regex) throws InvalidMappingException;
+
+ /**
+ * Remove regex mapping
+ *
+ * @param user the username. Null if no username should be used
+ * @param domain the domain. Null if no domain should be used
+ * @param regex the regex.
+ * @return true if successfully
+ * @throws InvalidMappingException get thrown if an invalid argument was given
+ */
public boolean removeRegexMapping(String user,String domain, String regex);
+
+ /***
+ * Add address mapping
+ *
+ * @param user the username. Null if no username should be used
+ * @param domain the domain. Null if no domain should be used
+ * @param regex the regex.
+ * @return true if successfully
+ * @throws InvalidMappingException get thrown if an invalid argument was given
+ */
public boolean addAddressMapping(String user, String domain, String address) throws InvalidMappingException;
+
+ /**
+ * Remove address mapping
+ *
+ * @param user the username. Null if no username should be used
+ * @param domain the domain. Null if no domain should be used
+ * @param regex the regex.
+ * @return true if successfully
+ * @throws InvalidMappingException get thrown if an invalid argument was given
+ */
public boolean removeAddressMapping(String user,String domain, String address);
+
+ /**
+ * Add error mapping
+ *
+ * @param user the username. Null if no username should be used
+ * @param domain the domain. Null if no domain should be used
+ * @param regex the regex.
+ * @return true if successfully
+ * @throws InvalidMappingException get thrown if an invalid argument was given
+ */
public boolean addErrorMapping(String user, String domain, String error) throws InvalidMappingException;
+
+ /**
+ * Remove error mapping
+ *
+ * @param user the username. Null if no username should be used
+ * @param domain the domain. Null if no domain should be used
+ * @param regex the regex.
+ * @return true if successfully
+ * @throws InvalidMappingException get thrown if an invalid argument was given
+ */
public boolean removeErrorMapping(String user,String domain, String error);
}
Modified: james/server/trunk/src/java/org/apache/james/vut/AbstractVirtualUserTable.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/vut/AbstractVirtualUserTable.java?view=diff&rev=463700&r1=463699&r2=463700
==============================================================================
--- james/server/trunk/src/java/org/apache/james/vut/AbstractVirtualUserTable.java (original)
+++ james/server/trunk/src/java/org/apache/james/vut/AbstractVirtualUserTable.java Fri Oct 13 08:09:08 2006
@@ -97,20 +97,12 @@
*/
public boolean addRegexMapping(String user, String domain, String regex) throws InvalidMappingException {
// TODO: More logging
-
- if (validUserString(user) == false) {
- throw new InvalidMappingException("Invalid user: " + user);
- }
- if(validDomainString(domain) == false) {
- throw new InvalidMappingException("Invalid domain: " + domain);
- }
-
try {
new Perl5Compiler().compile(regex);
} catch (MalformedPatternException e) {
throw new InvalidMappingException("Invalid regex: " + regex);
}
- return addMappingInternal(user,domain,"regex:" + regex);
+ return addMappingInternal(getUserString(user),getDomainString(domain),"regex:" + regex);
}
@@ -129,13 +121,6 @@
public boolean addAddressMapping(String user, String domain, String address) throws InvalidMappingException {
// TODO: More logging
- if (validUserString(user) == false) {
- throw new InvalidMappingException("Invalid user: " + user);
- }
- if(validDomainString(domain) == false) {
- throw new InvalidMappingException("Invalid domain: " + domain);
- }
-
if (address.indexOf('@') < 0) {
address = address + "@localhost";
}
@@ -144,7 +129,7 @@
} catch (ParseException e) {
throw new InvalidMappingException("Invalid emailAddress: " + address);
}
- return addMappingInternal(user,domain, address);
+ return addMappingInternal(getUserString(user),getDomainString(domain), address);
}
/**
@@ -166,14 +151,7 @@
public boolean addErrorMapping(String user, String domain, String error) throws InvalidMappingException {
// TODO: More logging
- if (validUserString(user) == false) {
- throw new InvalidMappingException("Invalid user: " + user);
- }
- if(validDomainString(domain) == false) {
- throw new InvalidMappingException("Invalid domain: " + domain);
- }
-
- return addMappingInternal(user,domain, "error:" + error);
+ return addMappingInternal(getUserString(user),getDomainString(domain), "error:" + error);
}
/**
@@ -233,12 +211,18 @@
*
* @param user the userString
* @return true of false
+ * @throws InvalidMappingException
*/
- private boolean validUserString(String user) {
- if(user.endsWith("@%") || user.indexOf("@") < 0) {
- return true;
+ private String getUserString(String user) throws InvalidMappingException {
+ if (user != null) {
+ if(user.endsWith("@%") || user.indexOf("@") < 0) {
+ return user;
+ } else {
+ throw new InvalidMappingException("Invalid user: " + user);
+ }
+ } else {
+ return "";
}
- return false;
}
/**
@@ -247,13 +231,20 @@
*
* @param domain the domainString
* @return true of false
+ * @throws InvalidMappingException
*/
- private boolean validDomainString(String domain) {
- if (domain.startsWith("%@") || domain.indexOf("@") < 0) {
- return true;
+ private String getDomainString(String domain) throws InvalidMappingException {
+ if(domain != null) {
+ if (domain.startsWith("%@") || domain.indexOf("@") < 0) {
+ return domain;
+ } else {
+ throw new InvalidMappingException("Invalid domain: " + domain);
+ }
+ } else {
+ return "";
}
- return false;
}
+
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org