[cvs] expresso commit by lhamel: provide ability to (optionally)
override
JCorporate Ltd
jcorp at jcorporate.com
Sun Oct 23 22:18:45 UTC 2005
Log Message:
-----------
provide ability to (optionally) override Message bundle strings, normally provided by ExpressoSchema.
Modified Files:
--------------
expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/services/controller:
SimpleRegistration.java
Revision Data
-------------
Index: SimpleRegistration.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/services/controller/SimpleRegistration.java,v
retrieving revision 1.49
retrieving revision 1.50
diff -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/services/controller/SimpleRegistration.java -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/services/controller/SimpleRegistration.java -u -r1.49 -r1.50
--- expresso-web/WEB-INF/src/com/jcorporate/expresso/services/controller/SimpleRegistration.java
+++ expresso-web/WEB-INF/src/com/jcorporate/expresso/services/controller/SimpleRegistration.java
@@ -90,6 +90,8 @@
import com.jcorporate.expresso.core.misc.StringUtil;
import com.jcorporate.expresso.core.security.SuperUser;
import com.jcorporate.expresso.core.security.User;
+import com.jcorporate.expresso.core.ExpressoSchema;
+import com.jcorporate.expresso.core.i18n.Messages;
import com.jcorporate.expresso.kernel.util.FastStringBuffer;
import com.jcorporate.expresso.services.controller.ui.DefaultAutoElement;
import com.jcorporate.expresso.services.dbobj.GroupMembers;
@@ -106,6 +108,7 @@
import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer;
+import java.util.Stack;
/**
@@ -162,7 +165,9 @@
* </p>
* Creation date: (6/23/2001 4:05:05 PM)
*
- * @author Shash Chatterjee, refactored by Michael Rimov
+ * @author Shash Chatterjee
+ * @author Michael Rimov
+ * @author Larry Hamel
*/
public class SimpleRegistration
extends com.jcorporate.expresso.services.controller.Registration {
@@ -172,8 +177,6 @@
* Registration constructor comment.
*/
public SimpleRegistration() {
- super();
-
State showDBMenu = new State("showDBMenu", "Menu of Registration Data");
showDBMenu.addOptionalParameter("loginController");
addState(showDBMenu);
@@ -693,13 +696,13 @@
user.setLoginName(loginName);
if (user.find())
- errors.addError(response.getString("registration.error.loginalreadyreg", loginName, request.getDataContext()));
+ errors.addError(response.getString("registration.error.loginalreadyreg", loginName, request.getDataContext()));
user.clear();
user.setEmail(email);
if (user.find())
- errors.addError(response.getString("registration.error.emailalreadyreg", email, request.getDataContext()));
+ errors.addError(response.getString("registration.error.emailalreadyreg", email, request.getDataContext()));
if (errors.getErrorCount() > 0) {
delayLogin(); //Make 'em pay :)
@@ -807,7 +810,7 @@
* @throws NonHandleableException upon fatal error
*/
protected ExpressoResponse processPostRegistration(ExpressoRequest request, ExpressoResponse response, User user,
- RegistrationDomain rd, String loginControllerName)
+ RegistrationDomain rd, String loginControllerName)
throws DBException, ControllerException, NonHandleableException {
boolean backToMenu = false;
@@ -948,6 +951,12 @@
* sends the email notification out. If admin. authorization is required
* this will setup the authorization process.
*
+ * Message bundle strings, normally provided by expresso, can be overridden by
+ * subclassing SimpleRegistration and overriding setupEmailValidation()
+ * to just add a job parameter like
+ * ve.addParam("schema", EmoSchema.class.getName());
+ * which will flow back into this method.
+ *
* @param request The ControllerRequest object handed down by the framework
* for this request
* @param response The ControllerResponse object returned by this
@@ -983,14 +992,30 @@
errors.addError("Account \"" + loginName + "\" not found");
}
+ // provide ability to use different schema, and thereby different message bundle, if param for alternate schema exists
+ Stack schemaStack = new Stack();
+ schemaStack.add(ExpressoSchema.class.getName()); // default schema always at root
+ String schemaClass = request.getParameter("schema");
+ if (schemaClass != null) {
+ schemaStack.add(schemaClass); // this schema's message bundle will be searched first for overriding string definitions.
+ }
+
+ Object[] emptyargs = new Object[0];
+
// Make sure the User record has not been disabled for some reason, or, already authenticated
if (errors.isEmpty()) {
if (user.getAccountStatus().equals("D")) {
- errors.addError(response.getString("registration.error.accountdisabled", loginName));
+ errors.addError(
+ Messages.getString(schemaStack, request.getLocale(),
+ "registration.error.accountdisabled", emptyargs));
} else if (user.getAccountStatus().equals("A")) {
- errors.addError(response.getString("registration.error.accountalreadyauth", loginName));
-
- Output o = new Output("infoMessage", response.getString("registration.msg.alreadyactivated"));
+ errors.addError(
+ Messages.getString(schemaStack, request.getLocale(),
+ "registration.error.accountalreadyauth", emptyargs));
+
+ Output o = new Output("infoMessage",
+ Messages.getString(schemaStack, request.getLocale(),
+ "registration.msg.alreadyactivated", emptyargs));
response.add(o);
}
@@ -1019,23 +1044,34 @@
// Create the content of the registration message to be sent
StringBuffer msg = new StringBuffer();
- msg.append(response.getString("loginAuthenticatedEM1",
- user.getLoginName(),
- Setup.getValue(dbname, "CompanyName")));
+ Object[] loginAndCompanyArgs = { user.getLoginName(),
+ Setup.getValue(dbname, "CompanyName")
+ };
+ msg.append(
+ Messages.getString(schemaStack, request.getLocale(),
+ "loginAuthenticatedEM1", loginAndCompanyArgs));
if (!userPasswd) {
// User doesn't specify password, create a random password
String password = user.randomPassword();
user.setPassword(password);
- msg.append(response.getString("loginAuthenticatedEM2",
- password));
+ Object[] passArg = {password };
+ msg.append(
+ Messages.getString(schemaStack, request.getLocale(),
+ "loginAuthenticatedEM2", passArg));
} else {
- msg.append(response.getString("loginAuthenticatedEM3"));
+ msg.append(
+ Messages.getString(schemaStack, request.getLocale(),
+ "loginAuthenticatedEM3", emptyargs));
}
- msg.append(response.getString("loginAuthenticatedEM4",
+ Object[] companyAndHomepageArgs = {
Setup.getValue(dbname, "CompanyName"),
- Setup.getValue(dbname, "HomePageURL")));
+ Setup.getValue(dbname, "HomePageURL")
+ };
+ msg.append(
+ Messages.getString(schemaStack, request.getLocale(),
+ "loginAuthenticatedEM4", companyAndHomepageArgs));
// mark this user as "activated"
user.setAccountStatus("A");
@@ -1063,14 +1099,22 @@
}
// Send the confirmation email
- user.notify(response.getString("loginAuthenticatedSubject"),
- msg.toString());
+ String subject = Messages.getString(schemaStack, request.getLocale(),
+ "loginAuthenticatedSubject", emptyargs);
+
+ user.notify(subject, msg.toString());
// Confirmation messages for the UI
- Output o1 = new Output("successMessage", response.getString("registration.msg.infomessage", user.getLoginName()));
+ Output o1 = new Output("successMessage",
+ Messages.getString(schemaStack, request.getLocale(),
+ "registration.msg.infomessage", loginAndCompanyArgs));
+
response.add(o1);
- Output o2 = new Output("infoMessage", response.getString("registration.msg.infomessage2", user.getEmail()));
+ Object[] emailArgs = { user.getEmail() };
+ Output o2 = new Output("infoMessage",
+ Messages.getString(schemaStack, request.getLocale(),
+ "registration.msg.infomessage2", emailArgs));
response.add(o2);
Transition login = new Transition();
@@ -1081,8 +1125,7 @@
Transition editPref = new Transition();
editPref.setName("editPreferences");
- editPref.addParam(CONTROLLER_PARAM_KEY,
- "com.jcorporate.expresso.services.controller.EditUserPreference");
+ editPref.addParam(CONTROLLER_PARAM_KEY, EditUserPreference.class.getName());
editPref.addParam(STATE_PARAM_KEY, "edit");
response.add(editPref);
@@ -1304,8 +1347,8 @@
if (errors.isEmpty()) {
StringBuffer msg = new StringBuffer();
String subject = null;
- Output successMessage = new Output("successMessage",
- response.getString("registration.msg.approvalsuccess", loginToApprove));
+ Output successMessage = new Output("successMessage",
+ response.getString("registration.msg.approvalsuccess", loginToApprove));
Output infoMessage = null;
if (cmd.equals("approve")) {
@@ -1371,7 +1414,7 @@
Setup.getValue(request.getDataContext(),
"HomePageURL")));
infoMessage = new Output("infoMessage",
- response.getString("registration.msg.infoapproved"));
+ response.getString("registration.msg.infoapproved"));
} else if (cmd.equals("postpone")) {
ValidationEntry ve = (ValidationEntry) request.getSession()
.getPersistentAttribute(ValidationEntry.SESSION_KEY);
More information about the cvs
mailing list