[cvs] expresso commit by mtraum: add i18n capability to
ValidationEntry and
JCorporate Ltd
jcorp at jcorporate.com
Fri Mar 11 17:16:06 UTC 2005
Log Message:
-----------
add i18n capability to ValidationEntry and use it for sending Change Password emails (F. Galli)
Modified Files:
--------------
expresso/expresso-web/expresso/doc:
ChangeLog.xml
expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/services/validation:
LoginEmailValidator.java
ChangePasswordValidator.java
ValidationEntry.java
expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/services/controller:
SimpleLoginController.java
Revision Data
-------------
Index: ChangeLog.xml
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/expresso/doc/ChangeLog.xml,v
retrieving revision 1.292
retrieving revision 1.293
diff -Lexpresso-web/expresso/doc/ChangeLog.xml -Lexpresso-web/expresso/doc/ChangeLog.xml -u -r1.292 -r1.293
--- expresso-web/expresso/doc/ChangeLog.xml
+++ expresso-web/expresso/doc/ChangeLog.xml
@@ -5,6 +5,12 @@
<project name="Expresso">
<version name="5.6.1" releaseDate="Not released yet">
<comment>Continued Updates</comment>
+ <new-feature title="Change password emails can now be internationalized">
+ <explanation>ValidationEntry was not capable of getting the user's locale, which meant that any email's set by it
+ could not be internationalized. This capability has been added and is being utilitzed for the change password email
+ </explanation>
+ <contributor>Francesco Galli</contributor>
+ </new-feature>
<bug-fix title="JobQueue entries are now deleted when requesting user is deleted">
<explanation>When a user was deleted, their JobQueue entries were not. This is now fixed.
</explanation>
Index: ChangePasswordValidator.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/services/validation/ChangePasswordValidator.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/services/validation/ChangePasswordValidator.java -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/services/validation/ChangePasswordValidator.java -u -r1.18 -r1.19
--- expresso-web/WEB-INF/src/com/jcorporate/expresso/services/validation/ChangePasswordValidator.java
+++ expresso-web/WEB-INF/src/com/jcorporate/expresso/services/validation/ChangePasswordValidator.java
@@ -63,6 +63,10 @@
*/
package com.jcorporate.expresso.services.validation;
+import java.util.Hashtable;
+import java.util.Locale;
+import java.util.Vector;
+
import com.jcorporate.expresso.core.ExpressoSchema;
import com.jcorporate.expresso.core.controller.Controller;
import com.jcorporate.expresso.core.controller.ControllerException;
@@ -76,9 +80,6 @@
import com.jcorporate.expresso.core.security.User;
import com.jcorporate.expresso.services.dbobj.Setup;
-import java.util.Hashtable;
-import java.util.Vector;
-
/**
* This class is a helper class that allows the LoginController controller to
@@ -145,12 +146,29 @@
schema = ExpressoSchema.class.getName();
}
+ String localeCountry = (String) params.get(ValidationEntry.PRM_LOC_COUNTRY);
+ String localeLanguage = (String) params.get(ValidationEntry.PRM_LOC_LANGUAGE);
+ Locale locale = null;
+ if (localeCountry != null && localeLanguage != null) {
+ locale = new Locale(localeLanguage, localeCountry);
+ }
+
// Send email notification
- ValidationEntry.notifyByEmail(dbName,
- Setup.getValue(dbName, "MAILFrom"),
- addresses,
- Messages.getString(schema, "passwdRequestedSubject"),
- Messages.getString(schema, "passwdRequested", args));
+ if (locale != null) {
+ ValidationEntry.notifyByEmail(dbName,
+ Setup.getValue(dbName, "MAILFrom"),
+ addresses,
+ Messages.getString(schema, locale, "passwdRequestedSubject"),
+ Messages.getString(schema, locale, "passwdRequested", args));
+ }
+ else {
+ ValidationEntry.notifyByEmail(dbName,
+ Setup.getValue(dbName, "MAILFrom"),
+ addresses,
+ Messages.getString(schema, "passwdRequestedSubject"),
+ Messages.getString(schema, "passwdRequested", args));
+ }
+
} catch (DBException dbe) {
throw new AuthValidationException("DB error accessing user \"" +
loginName + "\"", dbe);
@@ -201,5 +219,5 @@
return response;
}
-
+
}
Index: LoginEmailValidator.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/services/validation/LoginEmailValidator.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/services/validation/LoginEmailValidator.java -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/services/validation/LoginEmailValidator.java -u -r1.17 -r1.18
--- expresso-web/WEB-INF/src/com/jcorporate/expresso/services/validation/LoginEmailValidator.java
+++ expresso-web/WEB-INF/src/com/jcorporate/expresso/services/validation/LoginEmailValidator.java
@@ -63,6 +63,10 @@
*/
package com.jcorporate.expresso.services.validation;
+import java.util.Hashtable;
+import java.util.Locale;
+import java.util.Vector;
+
import com.jcorporate.expresso.core.controller.Controller;
import com.jcorporate.expresso.core.controller.ControllerException;
import com.jcorporate.expresso.core.controller.ControllerRequest;
@@ -75,9 +79,6 @@
import com.jcorporate.expresso.core.security.User;
import com.jcorporate.expresso.services.dbobj.Setup;
-import java.util.Hashtable;
-import java.util.Vector;
-
/**
* This class is a helper class that allows the LoginController controller to
@@ -139,11 +140,32 @@
loginName, URL, Setup.getValue(dbName, "CompanyName"),
Setup.getValue(dbName, "HomePageURL")
};
-
+
+ String localeCountry = (String) params.get(ValidationEntry.PRM_LOC_COUNTRY);
+ String localeLanguage = (String) params.get(ValidationEntry.PRM_LOC_LANGUAGE);
+ Locale locale = null;
+ if (localeCountry != null && localeLanguage != null) {
+ locale = new Locale(localeLanguage, localeCountry);
+ }
+
// Send email notification
- ValidationEntry.notifyByEmail(dbName,
- Setup.getValue(dbName, "MAILFrom"), addresses,
- getString("loginReqSubject"), getString("loginReqEM1", args));
+ if (locale != null) {
+ ValidationEntry.notifyByEmail(dbName,
+ Setup.getValue(dbName, "MAILFrom"),
+ addresses,
+ Messages.getString(locale, "loginReqSubject"),
+ Messages.getString(locale, "loginReqEM1", args));
+ }
+ else {
+ ValidationEntry.notifyByEmail(dbName,
+ Setup.getValue(dbName, "MAILFrom"),
+ addresses,
+ Messages.getString("loginReqSubject"),
+ Messages.getString("loginReqEM1", args));
+
+ }
+
+
} catch (DBException dbe) {
throw new AuthValidationException("DB error accessing user \"" +
loginName + "\"", dbe);
@@ -203,34 +225,4 @@
return response;
}
- /**
- * Convenience version of the above with no arguments.
- *
- * @param stringCode the string to localize
- * @return The local-language string corresponding to the given code to
- * return the local language by considering the user as well.
- */
- protected String getString(String stringCode) {
- Object[] args = {};
-
- return Messages.getString("com.jcorporate.expresso.core.ExpressoSchema",
- stringCode, args);
- }
- /* getString(String) */
-
- /**
- * Pass on a call to retrieve an appropriate localized string from the
- * correct Schema object. This version of the call is overridden with more
- * sophisticated versions in DBController (which knows the username)
- *
- * @param stringCode the string to localize
- * @param args formatting arguments
- * @return java.lang.String to return the local language by considering the
- * user as well.
- */
- protected String getString(String stringCode, Object[] args) {
- return Messages.getString("com.jcorporate.expresso.core.ExpressoSchema",
- stringCode, args);
- }
- /* getString(String, Object[]) */
}
Index: ValidationEntry.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/services/validation/ValidationEntry.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/services/validation/ValidationEntry.java -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/services/validation/ValidationEntry.java -u -r1.26 -r1.27
--- expresso-web/WEB-INF/src/com/jcorporate/expresso/services/validation/ValidationEntry.java
+++ expresso-web/WEB-INF/src/com/jcorporate/expresso/services/validation/ValidationEntry.java
@@ -64,6 +64,19 @@
package com.jcorporate.expresso.services.validation;
+import java.io.Serializable;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+import org.apache.log4j.Logger;
+
import com.jcorporate.expresso.core.db.DBException;
import com.jcorporate.expresso.core.dbobj.SecuredDBObject;
import com.jcorporate.expresso.core.job.Job;
@@ -83,17 +96,6 @@
import com.jcorporate.expresso.services.dbobj.Setup;
import com.jcorporate.expresso.services.dbobj.ValidationQueue;
import com.jcorporate.expresso.services.dbobj.ValidationQueueParam;
-import org.apache.log4j.Logger;
-
-import java.io.Serializable;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.List;
-import java.util.StringTokenizer;
-import java.util.Vector;
/**
@@ -252,6 +254,21 @@
*/
protected ValidationQueue vq = null;
+ /**
+ * Locale for i18n'ed email.
+ */
+ protected Locale locale = null;
+
+ /**
+ * Parameter name for locale country
+ */
+ public static String PRM_LOC_COUNTRY = "$$$country";
+
+ /**
+ * Parameter name for locale language
+ */
+ public static String PRM_LOC_LANGUAGE = "$$$language";
+
/**
* current parameter number
*/
@@ -823,6 +840,11 @@
addParam(PRM_VAL_SERVER, valServer);
addParam(PRM_VAL_PORT, valPort);
addParam(PRM_VAL_CTX, valContextPath);
+ if (locale != null) {
+ addParam(PRM_LOC_COUNTRY, getLocale().getCountry());
+ addParam(PRM_LOC_LANGUAGE, getLocale().getLanguage());
+ }
+
jq.setField(JobQueue.FLD_STATUS_CODE, AVAILABLE);
jq.update();
} catch (DBException dbe) {
@@ -902,5 +924,21 @@
}
return CookieBase64.encodeNoPadding(possibleNumbers);
+ }
+ /**
+ * Get the locale of the validation entry
+ *
+ * @return Returns the locale.
+ */
+ public Locale getLocale() {
+ return locale;
+ }
+ /**
+ * Set the locale of the validation entry
+ *
+ * @param locale The locale to set.
+ */
+ public void setLocale(Locale locale) {
+ this.locale = locale;
}
}
Index: SimpleLoginController.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/services/controller/SimpleLoginController.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/services/controller/SimpleLoginController.java -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/services/controller/SimpleLoginController.java -u -r1.31 -r1.32
--- expresso-web/WEB-INF/src/com/jcorporate/expresso/services/controller/SimpleLoginController.java
+++ expresso-web/WEB-INF/src/com/jcorporate/expresso/services/controller/SimpleLoginController.java
@@ -64,6 +64,18 @@
package com.jcorporate.expresso.services.controller;
+import java.util.Enumeration;
+import java.util.Vector;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.log4j.Logger;
+import org.apache.struts.Globals;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.config.ForwardConfig;
+
import com.jcorporate.expresso.core.ExpressoConstants;
import com.jcorporate.expresso.core.controller.Controller;
import com.jcorporate.expresso.core.controller.ControllerException;
@@ -92,16 +104,6 @@
import com.jcorporate.expresso.services.dbobj.Setup;
import com.jcorporate.expresso.services.validation.AuthValidationException;
import com.jcorporate.expresso.services.validation.ValidationEntry;
-import org.apache.log4j.Logger;
-import org.apache.struts.Globals;
-import org.apache.struts.action.ActionForward;
-import org.apache.struts.config.ForwardConfig;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.util.Enumeration;
-import java.util.Vector;
/**
* Main Login Controller - used for login/logout and basic interaction with
@@ -709,6 +711,7 @@
ValidationEntry ve = new ValidationEntry(request.getDataContext());
ve.setValidationHandler("com.jcorporate.expresso.services.validation.ChangePasswordValidator");
ve.setTitle("Change Password Validation");
+ ve.setLocale(request.getLocale());
ve.setDesc("user=" + loginName + ", db=" +
request.getDataContext());
ve.setServer(hreq.getServerName());
More information about the cvs
mailing list