You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by cr...@locus.apache.org on 2000/10/15 05:35:02 UTC
cvs commit: jakarta-struts/src/example/org/apache/struts/example ApplicationResources.properties DatabaseServlet.java EditRegistrationAction.java EditSubscriptionAction.java LogonForm.java RegistrationForm.java SaveRegistrationAction.java SaveSubscriptionAction.java Subscription.java SubscriptionForm.java User.java
craigmcc 00/10/14 20:35:01
Modified: src/example/org/apache/struts/example
ApplicationResources.properties
DatabaseServlet.java EditRegistrationAction.java
EditSubscriptionAction.java LogonForm.java
RegistrationForm.java SaveRegistrationAction.java
SaveSubscriptionAction.java Subscription.java
SubscriptionForm.java User.java
Log:
Bring the Struts example application up-to-date with respect to recent
changes in the org.apache.struts.action and org.apache.struts.util
packages:
- Use reset() methods on each form bean to reset properties to default
values.
- Eliminate special-case handling for changing strings from null to "",
since it is unnecesasry.
- Use PropertyUtils.copyProperties() to populate form beans (in the
/editRegistration and /editSubscription actions) and to update the
underlying data beans (in the /saveRegistration and /saveSubscription
actions).
- Added an "autoConnect" property to the Subscription object, which can
be used to demonstrate that checkboxes now work correctly.
In addition, the following bugs were fixed:
- Correct the XML generation when DatabaseServlet so that it would not
generate the literal string "null" for a null String property value.
Revision Changes Path
1.4 +2 -0 jakarta-struts/src/example/org/apache/struts/example/ApplicationResources.properties
Index: ApplicationResources.properties
===================================================================
RCS file: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/ApplicationResources.properties,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ApplicationResources.properties 2000/08/01 20:03:22 1.3
+++ ApplicationResources.properties 2000/10/15 03:34:51 1.4
@@ -21,6 +21,7 @@
errors.footer=</ul><hr>
errors.header=<h3><font color="red">Validation Error</font></h3>You must correct the following error(s) before proceeding:<ul>
errors.ioException=I/O exception rendering error messages: {0}
+heading.autoConnect=Auto
heading.subscriptions=Current Subscriptions
heading.host=Host Name
heading.user=User Name
@@ -41,6 +42,7 @@
mainMenu.title=MailReader Demonstration Application - Main Menu
option.imap=IMAP Protocol
option.pop3=POP3 Protocol
+prompt.autoConnect=Auto Connect:
prompt.fromAddress=From Address:
prompt.fullName=Full Name:
prompt.mailHostname=Mail Server:
1.4 +32 -17 jakarta-struts/src/example/org/apache/struts/example/DatabaseServlet.java
Index: DatabaseServlet.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/DatabaseServlet.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DatabaseServlet.java 2000/08/01 20:03:22 1.3
+++ DatabaseServlet.java 2000/10/15 03:34:51 1.4
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/DatabaseServlet.java,v 1.3 2000/08/01 20:03:22 craigmcc Exp $
- * $Revision: 1.3 $
- * $Date: 2000/08/01 20:03:22 $
+ * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/DatabaseServlet.java,v 1.4 2000/10/15 03:34:51 craigmcc Exp $
+ * $Revision: 1.4 $
+ * $Date: 2000/10/15 03:34:51 $
*
* ====================================================================
*
@@ -90,7 +90,7 @@
* Demonstration Application.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.3 $ $Date: 2000/08/01 20:03:22 $
+ * @version $Revision: 1.4 $ $Date: 2000/10/15 03:34:51 $
*/
public final class DatabaseServlet
@@ -318,21 +318,36 @@
Enumeration users = database.elements();
while (users.hasMoreElements()) {
User user = (User) users.nextElement();
- writer.println(" <user" +
- " username=\"" + user.getUsername() + "\"" +
- " password=\"" + user.getPassword() + "\"" +
- " fullName=\"" + user.getFullName() + "\"" +
- " fromAddress=\"" + user.getFromAddress() + "\"" +
- " replyToAddress=\"" + user.getReplyToAddress() + "\"" +
- ">");
+ writer.print(" <user");
+ if (user.getUsername() != null)
+ writer.print(" username=\"" + user.getUsername() + "\"");
+ if (user.getPassword() != null)
+ writer.print(" password=\"" + user.getPassword() + "\"");
+ if (user.getFullName() != null)
+ writer.print(" fullName=\"" + user.getFullName() + "\"");
+ if (user.getFromAddress() != null)
+ writer.print(" fromAddress=\"" + user.getFromAddress() + "\"");
+ if (user.getReplyToAddress() != null)
+ writer.print(" replyToAddress=\"" + user.getReplyToAddress() + "\"");
+ writer.println(">");
Subscription subscriptions[] = user.getSubscriptions();
for (int i = 0; i < subscriptions.length; i++) {
- writer.println(" <subscription" +
- " host=\"" + subscriptions[i].getHost() + "\"" +
- " type=\"" + subscriptions[i].getType() + "\"" +
- " username=\"" + subscriptions[i].getUsername() + "\"" +
- " password=\"" + subscriptions[i].getPassword() + "\"" +
- "/>");
+ writer.print(" <subscription");
+ writer.print(" autoConnect=\"" +
+ subscriptions[i].getAutoConnect() + "\"");
+ if (subscriptions[i].getHost() != null)
+ writer.print(" host=\"" + subscriptions[i].getHost() +
+ "\"");
+ if (subscriptions[i].getType() != null)
+ writer.print(" type=\"" + subscriptions[i].getType() +
+ "\"");
+ if (subscriptions[i].getUsername() != null)
+ writer.print(" username=\"" +
+ subscriptions[i].getUsername() + "\"");
+ if (subscriptions[i].getPassword() != null)
+ writer.print(" password=\"" +
+ subscriptions[i].getPassword() + "\"");
+ writer.println("/>");
}
writer.println(" </user>");
}
1.8 +32 -12 jakarta-struts/src/example/org/apache/struts/example/EditRegistrationAction.java
Index: EditRegistrationAction.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/EditRegistrationAction.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- EditRegistrationAction.java 2000/10/12 21:53:40 1.7
+++ EditRegistrationAction.java 2000/10/15 03:34:52 1.8
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/EditRegistrationAction.java,v 1.7 2000/10/12 21:53:40 craigmcc Exp $
- * $Revision: 1.7 $
- * $Date: 2000/10/12 21:53:40 $
+ * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/EditRegistrationAction.java,v 1.8 2000/10/15 03:34:52 craigmcc Exp $
+ * $Revision: 1.8 $
+ * $Date: 2000/10/15 03:34:52 $
*
* ====================================================================
*
@@ -64,6 +64,7 @@
import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
import java.util.Locale;
import java.util.Vector;
import javax.servlet.RequestDispatcher;
@@ -77,6 +78,7 @@
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.util.MessageResources;
+import org.apache.struts.util.PropertyUtils;
/**
@@ -85,7 +87,7 @@
* User (if any).
*
* @author Craig R. McClanahan
- * @version $Revision: 1.7 $ $Date: 2000/10/12 21:53:40 $
+ * @version $Revision: 1.8 $ $Date: 2000/10/15 03:34:52 $
*/
public final class EditRegistrationAction extends Action {
@@ -122,6 +124,9 @@
String action = request.getParameter("action");
if (action == null)
action = "Create";
+ if (servlet.getDebug() >= 1)
+ servlet.log("EditRegistrationAction: Processing " + action +
+ " action");
// Is there a currently logged on user?
User user = null;
@@ -129,7 +134,7 @@
user = (User) session.getAttribute(Constants.USER_KEY);
if (user == null) {
if (servlet.getDebug() >= 1)
- servlet.log("EditRegistrationAction: User is not logged on in session "
+ servlet.log(" User is not logged on in session "
+ session.getId());
return (servlet.findForward("logon"));
}
@@ -137,21 +142,36 @@
// Populate the user registration form
if (form == null) {
+ if (servlet.getDebug() >= 1)
+ servlet.log(" Creating new RegistrationForm bean under key "
+ + mapping.getAttribute());
form = new RegistrationForm();
session.setAttribute(mapping.getAttribute(), form);
}
RegistrationForm regform = (RegistrationForm) form;
- regform.setAction(action);
if (user != null) {
- regform.setUsername(user.getUsername());
- regform.setPassword(null);
- regform.setPassword2(null);
- regform.setFullName(user.getFullName());
- regform.setFromAddress(user.getFromAddress());
- regform.setReplyToAddress(user.getReplyToAddress());
+ if (servlet.getDebug() >= 1)
+ servlet.log(" Populating form from " + user);
+ try {
+ PropertyUtils.copyProperties(regform, user);
+ regform.setAction(action);
+ regform.setPassword(null);
+ regform.setPassword2(null);
+ } catch (InvocationTargetException e) {
+ Throwable t = e.getTargetException();
+ if (t == null)
+ t = e;
+ servlet.log("RegistrationForm.populate", t);
+ throw new ServletException("RegistrationForm.populate", t);
+ } catch (Throwable t) {
+ servlet.log("RegistrationForm.populate", t);
+ throw new ServletException("RegistrationForm.populate", t);
+ }
}
// Forward control to the edit user registration page
+ if (servlet.getDebug() >= 1)
+ servlet.log(" Forwarding to 'success' page");
return (mapping.findForward("success"));
}
1.8 +31 -10 jakarta-struts/src/example/org/apache/struts/example/EditSubscriptionAction.java
Index: EditSubscriptionAction.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/EditSubscriptionAction.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- EditSubscriptionAction.java 2000/10/12 21:53:41 1.7
+++ EditSubscriptionAction.java 2000/10/15 03:34:52 1.8
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/EditSubscriptionAction.java,v 1.7 2000/10/12 21:53:41 craigmcc Exp $
- * $Revision: 1.7 $
- * $Date: 2000/10/12 21:53:41 $
+ * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/EditSubscriptionAction.java,v 1.8 2000/10/15 03:34:52 craigmcc Exp $
+ * $Revision: 1.8 $
+ * $Date: 2000/10/15 03:34:52 $
*
* ====================================================================
*
@@ -64,6 +64,7 @@
import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
import java.util.Locale;
import java.util.Vector;
import javax.servlet.RequestDispatcher;
@@ -77,6 +78,7 @@
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.util.MessageResources;
+import org.apache.struts.util.PropertyUtils;
/**
@@ -84,7 +86,7 @@
* <code>SubscriptionForm</code> from the currently specified subscription.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.7 $ $Date: 2000/10/12 21:53:41 $
+ * @version $Revision: 1.8 $ $Date: 2000/10/15 03:34:52 $
*/
public final class EditSubscriptionAction extends Action {
@@ -122,12 +124,15 @@
if (action == null)
action = "Create";
String host = request.getParameter("host");
+ if (servlet.getDebug() >= 1)
+ servlet.log("EditSubscriptionAction: Processing " + action +
+ " action");
// Is there a currently logged on user?
User user = (User) session.getAttribute(Constants.USER_KEY);
if (user == null) {
if (servlet.getDebug() >= 1)
- servlet.log("EditSubscriptionAction: User is not logged on in session "
+ servlet.log(" User is not logged on in session "
+ session.getId());
return (servlet.findForward("logon"));
}
@@ -142,7 +147,7 @@
}
if (subscription == null) {
if (servlet.getDebug() >= 1)
- servlet.log("EditSubscriptionAction: No subscription for user " +
+ servlet.log(" No subscription for user " +
user.getUsername() + " and host " + host);
return (mapping.findForward("failure"));
}
@@ -150,17 +155,33 @@
// Populate the subscription form
if (form == null) {
+ if (servlet.getDebug() >= 1)
+ servlet.log(" Creating new SubscriptionForm bean under key "
+ + mapping.getAttribute());
form = new SubscriptionForm();
session.setAttribute(mapping.getAttribute(), form);
}
SubscriptionForm subform = (SubscriptionForm) form;
subform.setAction(action);
- subform.setHost(subscription.getHost());
- subform.setUsername(subscription.getUsername());
- subform.setPassword(subscription.getPassword());
- subform.setType(subscription.getType());
+ if (servlet.getDebug() >= 1)
+ servlet.log(" Populating form from " + subscription);
+ try {
+ PropertyUtils.copyProperties(subform, subscription);
+ subform.setAction(action);
+ } catch (InvocationTargetException e) {
+ Throwable t = e.getTargetException();
+ if (t == null)
+ t = e;
+ servlet.log("SubscriptionForm.populate", t);
+ throw new ServletException("SubscriptionForm.populate", t);
+ } catch (Throwable t) {
+ servlet.log("SubscriptionForm.populate", t);
+ throw new ServletException("SubscriptionForm.populate", t);
+ }
// Forward control to the edit subscription page
+ if (servlet.getDebug() >= 1)
+ servlet.log(" Forwarding to 'success' page");
return (mapping.findForward("success"));
}
1.5 +23 -15 jakarta-struts/src/example/org/apache/struts/example/LogonForm.java
Index: LogonForm.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/LogonForm.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- LogonForm.java 2000/10/12 21:53:41 1.4
+++ LogonForm.java 2000/10/15 03:34:53 1.5
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/LogonForm.java,v 1.4 2000/10/12 21:53:41 craigmcc Exp $
- * $Revision: 1.4 $
- * $Date: 2000/10/12 21:53:41 $
+ * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/LogonForm.java,v 1.5 2000/10/15 03:34:53 craigmcc Exp $
+ * $Revision: 1.5 $
+ * $Date: 2000/10/15 03:34:53 $
*
* ====================================================================
*
@@ -79,7 +79,7 @@
* </ul>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.4 $ $Date: 2000/10/12 21:53:41 $
+ * @version $Revision: 1.5 $ $Date: 2000/10/15 03:34:53 $
*/
public final class LogonForm extends ActionForm {
@@ -91,13 +91,13 @@
/**
* The password.
*/
- private String password = "";
+ private String password = null;
/**
* The username.
*/
- private String username = "";
+ private String username = null;
// ----------------------------------------------------------- Properties
@@ -120,10 +120,7 @@
*/
public void setPassword(String password) {
- if (password == null)
- this.password = "";
- else
- this.password = password;
+ this.password = password;
}
@@ -145,10 +142,7 @@
*/
public void setUsername(String username) {
- if (username == null)
- this.username = "";
- else
- this.username = username;
+ this.username = username;
}
@@ -157,13 +151,27 @@
/**
+ * Reset all properties to their default values.
+ *
+ * @param mapping The mapping used to select this instance
+ * @param request The servlet request we are processing
+ */
+ public void reset(ActionMapping mapping, HttpServletRequest request) {
+
+ this.password = null;
+ this.username = null;
+
+ }
+
+
+ /**
* Validate the properties that have been set from this HTTP request,
* and return an <code>ActionErrors</code> object that encapsulates any
* validation errors that have been found. If no errors are found, return
* <code>null</code> or an <code>ActionErrors</code> object with no
* recorded error messages.
*
- * @param mapping The ActionMapping used to select this instance
+ * @param mapping The mapping used to select this instance
* @param request The servlet request we are processing
*/
public ActionErrors validate(ActionMapping mapping,
1.8 +37 -39 jakarta-struts/src/example/org/apache/struts/example/RegistrationForm.java
Index: RegistrationForm.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/RegistrationForm.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- RegistrationForm.java 2000/10/12 21:53:42 1.7
+++ RegistrationForm.java 2000/10/15 03:34:53 1.8
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/RegistrationForm.java,v 1.7 2000/10/12 21:53:42 craigmcc Exp $
- * $Revision: 1.7 $
- * $Date: 2000/10/12 21:53:42 $
+ * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/RegistrationForm.java,v 1.8 2000/10/15 03:34:53 craigmcc Exp $
+ * $Revision: 1.8 $
+ * $Date: 2000/10/15 03:34:53 $
*
* ====================================================================
*
@@ -90,7 +90,7 @@
* </ul>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.7 $ $Date: 2000/10/12 21:53:42 $
+ * @version $Revision: 1.8 $ $Date: 2000/10/15 03:34:53 $
*/
public final class RegistrationForm extends ActionForm {
@@ -108,38 +108,38 @@
/**
* The from address.
*/
- private String fromAddress = "";
+ private String fromAddress = null;
/**
* The full name.
*/
- private String fullName = "";
+ private String fullName = null;
/**
* The password.
*/
- private String password = "";
+ private String password = null;
/**
* The confirmation password.
*/
- private String password2 = "";
+ private String password2 = null;
/**
* The reply to address.
*/
- private String replyToAddress = "";
+ private String replyToAddress = null;
/**
* The username.
*/
- private String username = "";
+ private String username = null;
// ----------------------------------------------------------- Properties
@@ -162,10 +162,7 @@
*/
public void setAction(String action) {
- if (action == null)
- this.action = "";
- else
- this.action = action;
+ this.action = action;
}
@@ -187,10 +184,7 @@
*/
public void setFromAddress(String fromAddress) {
- if (fromAddress == null)
- this.fromAddress = "";
- else
- this.fromAddress = fromAddress;
+ this.fromAddress = fromAddress;
}
@@ -212,10 +206,7 @@
*/
public void setFullName(String fullName) {
- if (fullName == null)
- this.fullName = "";
- else
- this.fullName = fullName;
+ this.fullName = fullName;
}
@@ -237,10 +228,7 @@
*/
public void setPassword(String password) {
- if (password == null)
- this.password = "";
- else
- this.password = password;
+ this.password = password;
}
@@ -262,10 +250,7 @@
*/
public void setPassword2(String password2) {
- if (password2 == null)
- this.password2 = "";
- else
- this.password2 = password2;
+ this.password2 = password2;
}
@@ -287,10 +272,7 @@
*/
public void setReplyToAddress(String replyToAddress) {
- if (replyToAddress == null)
- this.replyToAddress = "";
- else
- this.replyToAddress = replyToAddress;
+ this.replyToAddress = replyToAddress;
}
@@ -312,10 +294,7 @@
*/
public void setUsername(String username) {
- if (username == null)
- this.username = "";
- else
- this.username = username;
+ this.username = username;
}
@@ -324,13 +303,32 @@
/**
+ * Reset all properties to their default values.
+ *
+ * @param mapping The mapping used to select this instance
+ * @param request The servlet request we are processing
+ */
+ public void reset(ActionMapping mapping, HttpServletRequest request) {
+
+ this.action = "Create";
+ this.fromAddress = null;
+ this.fullName = null;
+ this.password = null;
+ this.password2 = null;
+ this.replyToAddress = null;
+ this.username = null;
+
+ }
+
+
+ /**
* Validate the properties that have been set from this HTTP request,
* and return an <code>ActionErrors</code> object that encapsulates any
* validation errors that have been found. If no errors are found, return
* <code>null</code> or an <code>ActionErrors</code> object with no
* recorded error messages.
*
- * @param mapping The ActionMapping used to select this instance
+ * @param mapping The mapping used to select this instance
* @param request The servlet request we are processing
*/
public ActionErrors validate(ActionMapping mapping,
1.10 +35 -24 jakarta-struts/src/example/org/apache/struts/example/SaveRegistrationAction.java
Index: SaveRegistrationAction.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/SaveRegistrationAction.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- SaveRegistrationAction.java 2000/10/12 21:53:42 1.9
+++ SaveRegistrationAction.java 2000/10/15 03:34:53 1.10
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/SaveRegistrationAction.java,v 1.9 2000/10/12 21:53:42 craigmcc Exp $
- * $Revision: 1.9 $
- * $Date: 2000/10/12 21:53:42 $
+ * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/SaveRegistrationAction.java,v 1.10 2000/10/15 03:34:53 craigmcc Exp $
+ * $Revision: 1.10 $
+ * $Date: 2000/10/15 03:34:53 $
*
* ====================================================================
*
@@ -64,6 +64,7 @@
import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
import java.util.Locale;
import java.util.Hashtable;
import javax.servlet.RequestDispatcher;
@@ -79,6 +80,7 @@
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.util.MessageResources;
+import org.apache.struts.util.PropertyUtils;
/**
@@ -87,7 +89,7 @@
* registration is created, the user is also implicitly logged on.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.9 $ $Date: 2000/10/12 21:53:42 $
+ * @version $Revision: 1.10 $ $Date: 2000/10/15 03:34:53 $
*/
public final class SaveRegistrationAction extends Action {
@@ -127,16 +129,23 @@
action = "Create";
Hashtable database = (Hashtable)
servlet.getServletContext().getAttribute(Constants.DATABASE_KEY);
+ if (servlet.getDebug() >= 1)
+ servlet.log("SaveRegistrationAction: Processing " + action +
+ " action");
// Is there a currently logged on user (unless creating)?
User user = (User) session.getAttribute(Constants.USER_KEY);
- if (!"Create".equals(action) && (user == null))
+ if (!"Create".equals(action) && (user == null)) {
+ if (servlet.getDebug() >= 1)
+ servlet.log(" User is not logged on in session "
+ + session.getId());
return (servlet.findForward("logon"));
+ }
// Was this transaction cancelled?
if (isCancelled(request)) {
if (servlet.getDebug() >= 1)
- servlet.log("SaveRegistrationAction: Transaction '" + action +
+ servlet.log(" Transaction '" + action +
"' was cancelled");
if (mapping.getAttribute() != null)
session.removeAttribute(mapping.getAttribute());
@@ -144,9 +153,9 @@
return (mapping.findForward("success"));
}
- // All required validations were done in the form bean
-
// Validate the request parameters specified by the user
+ if (servlet.getDebug() >= 1)
+ servlet.log(" Performing extra validations");
String value = null;
ActionErrors errors = new ActionErrors();
value = regform.getUsername();
@@ -177,26 +186,26 @@
user = new User();
user.setUsername(regform.getUsername());
}
- if (regform.getPassword().length() > 0)
- user.setPassword(regform.getPassword());
- if (regform.getFullName().length() > 0)
- user.setFullName(regform.getFullName());
- else
- user.setFullName(null);
- if (regform.getFromAddress().length() > 0)
- user.setFromAddress(regform.getFromAddress());
- else
- user.setFromAddress(null);
- if (regform.getReplyToAddress().length() > 0)
- user.setReplyToAddress(regform.getReplyToAddress());
- else
- user.setReplyToAddress(null);
+ try {
+ PropertyUtils.copyProperties(user, regform);
+ } catch (InvocationTargetException e) {
+ Throwable t = e.getTargetException();
+ if (t == null)
+ t = e;
+ servlet.log("Registration.populate", t);
+ throw new ServletException("Registration.populate", t);
+ } catch (Throwable t) {
+ servlet.log("Registration.populate", t);
+ throw new ServletException("Subscription.populate", t);
+ }
+
+
+ // Log the user in if appropriate
if ("Create".equals(action)) {
database.put(user.getUsername(), user);
session.setAttribute(Constants.USER_KEY, user);
if (servlet.getDebug() >= 1)
- servlet.log("SaveRegisrationAction: User '" +
- user.getUsername() +
+ servlet.log(" User '" + user.getUsername() +
"' logged on in session " + session.getId());
}
@@ -205,6 +214,8 @@
session.removeAttribute(mapping.getAttribute());
// Forward control to the specified success URI
+ if (servlet.getDebug() >= 1)
+ servlet.log(" Forwarding to success page");
return (mapping.findForward("success"));
}
1.10 +33 -17 jakarta-struts/src/example/org/apache/struts/example/SaveSubscriptionAction.java
Index: SaveSubscriptionAction.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/SaveSubscriptionAction.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- SaveSubscriptionAction.java 2000/10/12 21:53:42 1.9
+++ SaveSubscriptionAction.java 2000/10/15 03:34:54 1.10
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/SaveSubscriptionAction.java,v 1.9 2000/10/12 21:53:42 craigmcc Exp $
- * $Revision: 1.9 $
- * $Date: 2000/10/12 21:53:42 $
+ * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/SaveSubscriptionAction.java,v 1.10 2000/10/15 03:34:54 craigmcc Exp $
+ * $Revision: 1.10 $
+ * $Date: 2000/10/15 03:34:54 $
*
* ====================================================================
*
@@ -64,6 +64,7 @@
import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
import java.util.Locale;
import java.util.Hashtable;
import javax.servlet.RequestDispatcher;
@@ -79,6 +80,7 @@
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.util.MessageResources;
+import org.apache.struts.util.PropertyUtils;
/**
@@ -86,7 +88,7 @@
* updates the mail subscription entered by the user.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.9 $ $Date: 2000/10/12 21:53:42 $
+ * @version $Revision: 1.10 $ $Date: 2000/10/15 03:34:54 $
*/
public final class SaveSubscriptionAction extends Action {
@@ -124,18 +126,24 @@
String action = request.getParameter("action");
if (action == null)
action = "?";
+ if (servlet.getDebug() >= 1)
+ servlet.log("SaveSubscriptionAction: Processing " + action +
+ " action");
// Is there a currently logged on user?
User user = (User) session.getAttribute(Constants.USER_KEY);
- if (user == null)
+ if (user == null) {
+ if (servlet.getDebug() >= 1)
+ servlet.log(" User is not logged on in session "
+ + session.getId());
return (servlet.findForward("logon"));
+ }
// Is there a related Subscription object?
Subscription subscription =
(Subscription) session.getAttribute(Constants.SUBSCRIPTION_KEY);
if (subscription == null) {
- servlet.log("SaveSubscriptionAction: " +
- "Missing subscription for user '" +
+ servlet.log(" Missing subscription for user '" +
user.getUsername() + "'");
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
messages.getMessage("error.noSubscription"));
@@ -145,7 +153,7 @@
// Was this transaction cancelled?
if (isCancelled(request)) {
if (servlet.getDebug() >= 1)
- servlet.log("SaveSubscriptionAction: Transaction '" + action +
+ servlet.log(" Transaction '" + action +
"' was cancelled");
if (mapping.getAttribute() != null)
session.removeAttribute(mapping.getAttribute());
@@ -156,7 +164,7 @@
// Was this transaction a Delete?
if (action.equals("Delete")) {
if (servlet.getDebug() >= 1)
- servlet.log("SaveSubscriptionAction: Deleting mail server '" +
+ servlet.log(" Deleting mail server '" +
subscription.getHost() + "' for user '" +
user.getUsername() + "'");
subscription.setHost(null);
@@ -170,14 +178,20 @@
// All required validations were done by the form itself
// Update the persistent subscription information
- if (subform.getHost().length() > 0)
- subscription.setHost(subform.getHost());
- if (subform.getUsername().length() > 0)
- subscription.setUsername(subform.getUsername());
- if (subform.getPassword().length() > 0)
- subscription.setPassword(subform.getPassword());
- if (subform.getType().length() > 0)
- subscription.setType(subform.getType());
+ if (servlet.getDebug() >= 1)
+ servlet.log(" Populating database from form bean");
+ try {
+ PropertyUtils.copyProperties(subscription, subform);
+ } catch (InvocationTargetException e) {
+ Throwable t = e.getTargetException();
+ if (t == null)
+ t = e;
+ servlet.log("Subscription.populate", t);
+ throw new ServletException("Subscription.populate", t);
+ } catch (Throwable t) {
+ servlet.log("Subscription.populate", t);
+ throw new ServletException("Subscription.populate", t);
+ }
// Remove any obsolete session objects
if (mapping.getAttribute() != null)
@@ -185,6 +199,8 @@
session.removeAttribute(Constants.SUBSCRIPTION_KEY);
// Forward control to the specified success URI
+ if (servlet.getDebug() >= 1)
+ servlet.log(" Forwarding to success page");
return (mapping.findForward("success"));
}
1.3 +55 -4 jakarta-struts/src/example/org/apache/struts/example/Subscription.java
Index: Subscription.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/Subscription.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Subscription.java 2000/08/01 20:03:24 1.2
+++ Subscription.java 2000/10/15 03:34:54 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/Subscription.java,v 1.2 2000/08/01 20:03:24 craigmcc Exp $
- * $Revision: 1.2 $
- * $Date: 2000/08/01 20:03:24 $
+ * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/Subscription.java,v 1.3 2000/10/15 03:34:54 craigmcc Exp $
+ * $Revision: 1.3 $
+ * $Date: 2000/10/15 03:34:54 $
*
* ====================================================================
*
@@ -71,7 +71,7 @@
* specific mail server.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.2 $ $Date: 2000/08/01 20:03:24 $
+ * @version $Revision: 1.3 $ $Date: 2000/10/15 03:34:54 $
*/
public final class Subscription implements Serializable {
@@ -81,6 +81,12 @@
/**
+ * Should we auto-connect at startup time?
+ */
+ private boolean autoConnect = false;
+
+
+ /**
* The mail host for this subscription.
*/
private String host = null;
@@ -114,6 +120,28 @@
/**
+ * Return the auto-connect flag.
+ */
+ public boolean getAutoConnect() {
+
+ return (this.autoConnect);
+
+ }
+
+
+ /**
+ * Set the auto-connect flag.
+ *
+ * @param autoConnect The new auto-connect flag
+ */
+ public void setAutoConnect(boolean autoConnect) {
+
+ this.autoConnect = autoConnect;
+
+ }
+
+
+ /**
* Return the host name.
*/
public String getHost() {
@@ -232,6 +260,29 @@
// ======================================================= Public Methods
+
+
+ /**
+ * Return a String representation of this object.
+ */
+ public String toString() {
+
+ StringBuffer sb = new StringBuffer("Subscription[username=");
+ sb.append(username);
+ if (host != null) {
+ sb.append(", host=");
+ sb.append(host);
+ }
+ if (user != null) {
+ sb.append(", user=");
+ sb.append(user.getUsername());
+ }
+ sb.append(", autoConnect=");
+ sb.append(autoConnect);
+ sb.append("]");
+ return (sb.toString());
+
+ }
}
1.8 +59 -29 jakarta-struts/src/example/org/apache/struts/example/SubscriptionForm.java
Index: SubscriptionForm.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/SubscriptionForm.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- SubscriptionForm.java 2000/10/12 21:53:43 1.7
+++ SubscriptionForm.java 2000/10/15 03:34:55 1.8
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/SubscriptionForm.java,v 1.7 2000/10/12 21:53:43 craigmcc Exp $
- * $Revision: 1.7 $
- * $Date: 2000/10/12 21:53:43 $
+ * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/SubscriptionForm.java,v 1.8 2000/10/15 03:34:55 craigmcc Exp $
+ * $Revision: 1.8 $
+ * $Date: 2000/10/15 03:34:55 $
*
* ====================================================================
*
@@ -84,7 +84,7 @@
* </ul>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.7 $ $Date: 2000/10/12 21:53:43 $
+ * @version $Revision: 1.8 $ $Date: 2000/10/15 03:34:55 $
*/
public final class SubscriptionForm extends ActionForm {
@@ -100,27 +100,33 @@
/**
+ * Should we auto-connect at startup time?
+ */
+ private boolean autoConnect = false;
+
+
+ /**
* The host name.
*/
- private String host = "";
+ private String host = null;
/**
* The password.
*/
- private String password = "";
+ private String password = null;
/**
* The subscription type.
*/
- private String type = "";
+ private String type = null;
/**
* The username.
*/
- private String username = "";
+ private String username = null;
// ----------------------------------------------------------- Properties
@@ -142,12 +148,30 @@
* @param action The new maintenance action.
*/
public void setAction(String action) {
+
+ this.action = action;
+
+ }
+
+
+ /**
+ * Return the auto-connect flag.
+ */
+ public boolean getAutoConnect() {
+
+ return (this.autoConnect);
+
+ }
- if (action == null)
- this.action = "";
- else
- this.action = action;
+ /**
+ * Set the auto-connect flag.
+ *
+ * @param autoConnect The new auto-connect flag
+ */
+ public void setAutoConnect(boolean autoConnect) {
+
+ this.autoConnect = autoConnect;
}
@@ -168,10 +192,7 @@
*/
public void setHost(String host) {
- if (host == null)
- this.host = "";
- else
- this.host = host;
+ this.host = host;
}
@@ -193,10 +214,7 @@
*/
public void setPassword(String password) {
- if (password == null)
- this.password = "";
- else
- this.password = password;
+ this.password = password;
}
@@ -218,10 +236,7 @@
*/
public void setType(String type) {
- if (type == null)
- this.type = "";
- else
- this.type = type;
+ this.type = type;
}
@@ -243,10 +258,7 @@
*/
public void setUsername(String username) {
- if (username == null)
- this.username = "";
- else
- this.username = username;
+ this.username = username;
}
@@ -255,13 +267,31 @@
/**
+ * Reset all properties to their default values.
+ *
+ * @param mapping The mapping used to select this instance
+ * @param request The servlet request we are processing
+ */
+ public void reset(ActionMapping mapping, HttpServletRequest request) {
+
+ this.action = "Create";
+ this.autoConnect = false;
+ this.host = null;
+ this.password = null;
+ this.type = null;
+ this.username = null;
+
+ }
+
+
+ /**
* Validate the properties that have been set from this HTTP request,
* and return an <code>ActionErrors</code> object that encapsulates any
* validation errors that have been found. If no errors are found, return
* <code>null</code> or an <code>ActionErrors</code> object with no
* recorded error messages.
*
- * @param mapping The ActionMapping used to select this instance
+ * @param mapping The mapping used to select this instance
* @param request The servlet request we are processing
*/
public ActionErrors validate(ActionMapping mapping,
1.3 +25 -4 jakarta-struts/src/example/org/apache/struts/example/User.java
Index: User.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/User.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- User.java 2000/08/01 20:03:25 1.2
+++ User.java 2000/10/15 03:34:55 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/User.java,v 1.2 2000/08/01 20:03:25 craigmcc Exp $
- * $Revision: 1.2 $
- * $Date: 2000/08/01 20:03:25 $
+ * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/User.java,v 1.3 2000/10/15 03:34:55 craigmcc Exp $
+ * $Revision: 1.3 $
+ * $Date: 2000/10/15 03:34:55 $
*
* ====================================================================
*
@@ -72,7 +72,7 @@
* Object that represents a registered user of the mail reader application.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.2 $ $Date: 2000/08/01 20:03:25 $
+ * @version $Revision: 1.3 $ $Date: 2000/10/15 03:34:55 $
*/
public final class User implements Serializable {
@@ -264,6 +264,27 @@
}
return (results);
}
+
+ }
+
+
+ /**
+ * Return a String representation of this object.
+ */
+ public String toString() {
+
+ StringBuffer sb = new StringBuffer("User[username=");
+ sb.append(username);
+ if (fullName != null) {
+ sb.append(", fullName=");
+ sb.append(fullName);
+ }
+ if (replyToAddress != null) {
+ sb.append(", replyToAddres=");
+ sb.append(replyToAddress);
+ }
+ sb.append("]");
+ return (sb.toString());
}