[cvs] epoll commit by mtraum: fixed deprecated

JCorporate Ltd jcorp at jcorp2.servlets.net
Thu Oct 14 11:11:12 PDT 2004


Log Message:
-----------
fixed deprecated

Modified Files:
--------------
    epoll/src/WEB-INF/src/com/jcorporate/epoll/controller:
        PollManager.java
        CategoryManager.java
        Booth.java
    epoll/src/WEB-INF/src/com/jcorporate/epoll/dbobj:
        Poll.java

Revision Data
-------------
Index: CategoryManager.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/epoll/src/WEB-INF/src/com/jcorporate/epoll/controller/CategoryManager.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lsrc/WEB-INF/src/com/jcorporate/epoll/controller/CategoryManager.java -Lsrc/WEB-INF/src/com/jcorporate/epoll/controller/CategoryManager.java -u -r1.3 -r1.4
--- src/WEB-INF/src/com/jcorporate/epoll/controller/CategoryManager.java
+++ src/WEB-INF/src/com/jcorporate/epoll/controller/CategoryManager.java
@@ -10,8 +10,6 @@
 import com.jcorporate.expresso.core.controller.State;
 import com.jcorporate.expresso.core.controller.Transition;
 import com.jcorporate.expresso.core.controller.ValidationException;
-import com.jcorporate.expresso.core.controller.ValidationItem;
-import com.jcorporate.expresso.core.controller.ValidationSet;
 import com.jcorporate.expresso.core.db.DBException;
 import com.jcorporate.expresso.core.dbobj.SecuredDBObject;
 import com.jcorporate.expresso.services.dbobj.GroupMembers;
@@ -65,19 +63,13 @@
         String desc = param.getParameter("CategoryDesc");
 
         try {
-            ValidationSet vs = new ValidationSet();
             ErrorCollection ec = new ErrorCollection();
             com.jcorporate.epoll.dbobj.Category c = new com.jcorporate.epoll.dbobj.Category(
                                                             param);
-            String fieldName = "CategoryDesc";
-            vs.setValidationItem(new ValidationItem(fieldName,
-                                                    c.getDescription(fieldName),
-                                                    !c.allowsNull(fieldName),
-                                                    c.getClass().getName()));
 
             try {
                 response.setFormCache();
-                response.validate(vs, ec);
+                param.validateDBObject(c, ec);
             } catch (ValidationException ve) {
                 throw new ControllerException(ve);
             }
Index: PollManager.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/epoll/src/WEB-INF/src/com/jcorporate/epoll/controller/PollManager.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lsrc/WEB-INF/src/com/jcorporate/epoll/controller/PollManager.java -Lsrc/WEB-INF/src/com/jcorporate/epoll/controller/PollManager.java -u -r1.3 -r1.4
--- src/WEB-INF/src/com/jcorporate/epoll/controller/PollManager.java
+++ src/WEB-INF/src/com/jcorporate/epoll/controller/PollManager.java
@@ -22,8 +22,6 @@
 import com.jcorporate.expresso.core.controller.State;
 import com.jcorporate.expresso.core.controller.Transition;
 import com.jcorporate.expresso.core.controller.ValidationException;
-import com.jcorporate.expresso.core.controller.ValidationItem;
-import com.jcorporate.expresso.core.controller.ValidationSet;
 import com.jcorporate.expresso.core.db.DBException;
 import com.jcorporate.expresso.core.dbobj.DBObject;
 import com.jcorporate.expresso.core.dbobj.SecuredDBObject;
@@ -202,6 +200,7 @@
 	 * @return    Output The created output element
 	 * @throws    DBException Nested DB errors working with the passed DBObject
 	 * @throws    ControllerException Nested transaction errors creating the Output
+	 * @deprecated since 10/04, use makeOutput(DBObject, fieldName, response) so the label can be localized
 	 */
 	public static Output makeOutput(DBObject dbObject, String fieldName)
 		throws DBException, ControllerException {
@@ -213,10 +212,36 @@
 		o.setName(fieldName);
 
 		// The label is from the field description
-		o.setLabel(dbObject.getDescription(fieldName));
+		o.setLabel(dbObject.getMetaData().getDescription(fieldName));
 
 		return o;
 	}
+	
+	/**
+	 * This method creates an Output object from a DBObject and a field name.
+	 *
+	 * @param    dbObject The DBObject whose fields are used to create the Output
+	 * @param    fieldName The name of the field for which to generate an Output
+	 * @param    response The ControllerResponse
+	 * @return    Output The created output element
+	 * @throws    DBException Nested DB errors working with the passed DBObject
+	 * @throws    ControllerException Nested transaction errors creating the Output
+	 */
+	public static Output makeOutput(DBObject dbObject, String fieldName, ControllerResponse response)
+		throws DBException, ControllerException {
+
+		// Create the output, set the content from the content of the field
+		Output o = new Output(dbObject.getField(fieldName));
+
+		// The name is the same as the field name
+		o.setName(fieldName);
+
+		// The label is from the field description
+		o.setLabel(response.getString(dbObject.getMetaData().getDescription(fieldName)));
+
+		return o;
+	}
+	
 	/**
 	* Handle submission of a form to add a new choice.
 	*
@@ -252,19 +277,10 @@
 
 			// Add the new choice to the DB
 			Choice c = new Choice(param);
-			ValidationSet vs = new ValidationSet();
 			ErrorCollection ec = new ErrorCollection();
-			String fieldName = "Choice";
-			vs.setValidationItem(
-				new ValidationItem(
-					fieldName,
-					c.getDescription(fieldName),
-					!c.allowsNull(fieldName),
-					c.getClass().getName()));
-
 			try {
 				response.setFormCache();
-				response.validate(vs, ec);
+				param.validateDBObject(c, ec);
 			} catch (ValidationException ve) {
 				throw new ControllerException(ve);
 			}
@@ -325,40 +341,10 @@
 			}
 
 			Poll p = new Poll(param);
-			ValidationSet vs = new ValidationSet();
 			ErrorCollection ec = new ErrorCollection();
-			String fieldName = "PollDescription";
-			vs.setValidationItem(
-				new ValidationItem(
-					fieldName,
-					p.getDescription(fieldName),
-					!p.allowsNull(fieldName),
-					p.getClass().getName()));
-			fieldName = "Open";
-			vs.setValidationItem(
-				new ValidationItem(
-					fieldName,
-					p.getDescription(fieldName),
-					!p.allowsNull(fieldName),
-					p.getClass().getName()));
-			fieldName = "Close";
-			vs.setValidationItem(
-				new ValidationItem(
-					fieldName,
-					p.getDescription(fieldName),
-					!p.allowsNull(fieldName),
-					p.getClass().getName()));
-			fieldName = "ViewBeforeClose";
-			vs.setValidationItem(
-				new ValidationItem(
-					fieldName,
-					p.getDescription(fieldName),
-					!p.allowsNull(fieldName),
-					p.getClass().getName()));
-
 			try {
 				response.setFormCache();
-				response.validate(vs, ec);
+				param.validateDBObject(p, ec);
 			} catch (ValidationException ve) {
 				throw new ControllerException(ve);
 			}
@@ -433,40 +419,10 @@
 			}
 
 			Question q = new Question(param);
-			ValidationSet vs = new ValidationSet();
 			ErrorCollection ec = new ErrorCollection();
-			String fieldName = "Question";
-			vs.setValidationItem(
-				new ValidationItem(
-					fieldName,
-					q.getDescription(fieldName),
-					!q.allowsNull(fieldName),
-					q.getClass().getName()));
-			fieldName = "Required";
-			vs.setValidationItem(
-				new ValidationItem(
-					fieldName,
-					q.getDescription(fieldName),
-					!q.allowsNull(fieldName),
-					q.getClass().getName()));
-			fieldName = "Widget";
-			vs.setValidationItem(
-				new ValidationItem(
-					fieldName,
-					q.getDescription(fieldName),
-					!q.allowsNull(fieldName),
-					q.getClass().getName()));
-			fieldName = "DisplayOrder";
-			vs.setValidationItem(
-				new ValidationItem(
-					fieldName,
-					q.getDescription(fieldName),
-					!q.allowsNull(fieldName),
-					q.getClass().getName()));
-
 			try {
 				response.setFormCache();
-				response.validate(vs, ec);
+				param.validateDBObject(q, ec);
 			} catch (ValidationException ve) {
 				throw new ControllerException(ve);
 			}
@@ -669,11 +625,11 @@
 					list.add(aCategory);
 
 					// Output - The category
-					desc = makeOutput(oneCategory, "CategoryDesc");
+					desc = makeOutput(oneCategory, "CategoryDesc", response);
 					aCategory.add(desc);
 
 					// Output - The category ID
-					id = makeOutput(oneCategory, "CategoryId");
+					id = makeOutput(oneCategory, "CategoryId", response);
 					aCategory.add(id);
 
 					// Output - The number of nested Polls defined for this category
@@ -832,11 +788,11 @@
 				list.add(aChoice);
 
 				// Output - The choice itself
-				choice = makeOutput(oneChoice, "Choice");
+				choice = makeOutput(oneChoice, "Choice", response);
 				aChoice.add(choice);
 
 				// Output - The choice id
-				id = makeOutput(oneChoice, "ChoiceId");
+				id = makeOutput(oneChoice, "ChoiceId", response);
 				aChoice.add(id);
 
 				// Output - The number of votes cast for this choice
@@ -976,11 +932,11 @@
 					list.add(aPoll);
 
 					// Output - The Poll
-					desc = makeOutput(onePoll, "PollDescription");
+					desc = makeOutput(onePoll, "PollDescription", response);
 					aPoll.add(desc);
 
 					// Output - The poll ID
-					id = makeOutput(onePoll, "PollId");
+					id = makeOutput(onePoll, "PollId", response);
 					aPoll.add(id);
 
 					// Output - The number of defined questions for this poll
@@ -1180,15 +1136,15 @@
 				list.add(aQuestion);
 
 				// Output - The question
-				question = makeOutput(oneQuestion, "Question");
+				question = makeOutput(oneQuestion, "Question", response);
 				aQuestion.add(question);
 
 				// Output - The question Id
-				id = makeOutput(oneQuestion, "QuestionId");
+				id = makeOutput(oneQuestion, "QuestionId", response);
 				aQuestion.add(id);
 
 				// Output - The type of Form element to use for this question (Radio, Checkbox, Choice, etc)
-				widget = makeOutput(oneQuestion, "Widget");
+				widget = makeOutput(oneQuestion, "Widget", response);
 				aQuestion.add(widget);
 
 				// Output - The number of nested choices defined for this question
@@ -1392,7 +1348,7 @@
 				new com.jcorporate.epoll.dbobj.Category(param);
 			c.setField("CategoryId", categoryId);
 			c.find();
-			response.add(makeOutput(c, "CategoryDesc"));
+			response.add(makeOutput(c, "CategoryDesc", response));
 
 			if (!c.allowedForUser(param.getUid(), "U")) {
 				ErrorCollection ec = new ErrorCollection();
@@ -1750,7 +1706,7 @@
 				return;
 			}
 
-			response.add(makeOutput(poll, "PollDescription"));
+			response.add(makeOutput(poll, "PollDescription", response));
 
 			Vector groupValidValue = new Vector(8);
 			groupValidValue.add(new ValidValue("", "(select to allow...)"));
@@ -2365,19 +2321,10 @@
 				return;
 			}
 
-			ValidationSet vs = new ValidationSet();
 			ErrorCollection ec = new ErrorCollection();
-			String fieldName = "CategoryDesc";
-			vs.setValidationItem(
-				new ValidationItem(
-					fieldName,
-					c.getDescription(fieldName),
-					!c.allowsNull(fieldName),
-					c.getClass().getName()));
-
 			try {
 				response.setFormCache();
-				response.validate(vs, ec);
+				param.validateDBObject(c, ec);
 			} catch (ValidationException ve) {
 				throw new ControllerException(ve);
 			}
@@ -2460,19 +2407,10 @@
 
 			// Make sure the requested choice actually exists
 			Choice c = new Choice(param);
-			ValidationSet vs = new ValidationSet();
 			ErrorCollection ec = new ErrorCollection();
-			String fieldName = "Choice";
-			vs.setValidationItem(
-				new ValidationItem(
-					fieldName,
-					c.getDescription(fieldName),
-					!c.allowsNull(fieldName),
-					c.getClass().getName()));
-
 			try {
 				response.setFormCache();
-				response.validate(vs, ec);
+				param.validateDBObject(c, ec);
 			} catch (ValidationException ve) {
 				throw new ControllerException(ve);
 			}
@@ -2554,40 +2492,10 @@
 				return;
 			}
 
-			ValidationSet vs = new ValidationSet();
 			ErrorCollection ec = new ErrorCollection();
-			String fieldName = "PollDescription";
-			vs.setValidationItem(
-				new ValidationItem(
-					fieldName,
-					p.getDescription(fieldName),
-					!p.allowsNull(fieldName),
-					p.getClass().getName()));
-			fieldName = "Open";
-			vs.setValidationItem(
-				new ValidationItem(
-					fieldName,
-					p.getDescription(fieldName),
-					!p.allowsNull(fieldName),
-					p.getClass().getName()));
-			fieldName = "Close";
-			vs.setValidationItem(
-				new ValidationItem(
-					fieldName,
-					p.getDescription(fieldName),
-					!p.allowsNull(fieldName),
-					p.getClass().getName()));
-			fieldName = "ViewBeforeClose";
-			vs.setValidationItem(
-				new ValidationItem(
-					fieldName,
-					p.getDescription(fieldName),
-					!p.allowsNull(fieldName),
-					p.getClass().getName()));
-
 			try {
 				response.setFormCache();
-				response.validate(vs, ec);
+				param.validateDBObject(p, ec);
 			} catch (ValidationException ve) {
 				throw new ControllerException(ve);
 			}
@@ -2666,40 +2574,10 @@
 
 			// Make sure the requested question actually exists
 			Question q = new Question(param);
-			ValidationSet vs = new ValidationSet();
 			ErrorCollection ec = new ErrorCollection();
-			String fieldName = "Question";
-			vs.setValidationItem(
-				new ValidationItem(
-					fieldName,
-					q.getDescription(fieldName),
-					!q.allowsNull(fieldName),
-					q.getClass().getName()));
-			fieldName = "Required";
-			vs.setValidationItem(
-				new ValidationItem(
-					fieldName,
-					q.getDescription(fieldName),
-					!q.allowsNull(fieldName),
-					q.getClass().getName()));
-			fieldName = "Widget";
-			vs.setValidationItem(
-				new ValidationItem(
-					fieldName,
-					q.getDescription(fieldName),
-					!q.allowsNull(fieldName),
-					q.getClass().getName()));
-			fieldName = "DisplayOrder";
-			vs.setValidationItem(
-				new ValidationItem(
-					fieldName,
-					q.getDescription(fieldName),
-					!q.allowsNull(fieldName),
-					q.getClass().getName()));
-
 			try {
 				response.setFormCache();
-				response.validate(vs, ec);
+				param.validateDBObject(q, ec);
 			} catch (ValidationException ve) {
 				throw new ControllerException(ve);
 			}
Index: Booth.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/epoll/src/WEB-INF/src/com/jcorporate/epoll/controller/Booth.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -Lsrc/WEB-INF/src/com/jcorporate/epoll/controller/Booth.java -Lsrc/WEB-INF/src/com/jcorporate/epoll/controller/Booth.java -u -r1.5 -r1.6
--- src/WEB-INF/src/com/jcorporate/epoll/controller/Booth.java
+++ src/WEB-INF/src/com/jcorporate/epoll/controller/Booth.java
@@ -186,11 +186,11 @@
 				list.add(aQuestion);
 
 				// Output - The question id
-				o2 = PollManager.makeOutput(oneQuestion, "QuestionId");
+				o2 = PollManager.makeOutput(oneQuestion, "QuestionId", response);
 				aQuestion.add(o2);
 
 				// Output - the question
-				o3 = PollManager.makeOutput(oneQuestion, "Question");
+				o3 = PollManager.makeOutput(oneQuestion, "Question", response);
 				aQuestion.add(o3);
 
 				// Create a list of valid values with the choices allowed for this question
@@ -355,11 +355,11 @@
 				String questionId = oneQuestion.getField("QuestionId");
 
 				// Output - The question id
-				o2 = PollManager.makeOutput(oneQuestion, "QuestionId");
+				o2 = PollManager.makeOutput(oneQuestion, "QuestionId", response);
 				aQuestion.add(o2);
 
 				// Output - The question
-				o3 = PollManager.makeOutput(oneQuestion, "Question");
+				o3 = PollManager.makeOutput(oneQuestion, "Question", response);
 				aQuestion.add(o3);
 
 				// The total number of votes cast in the poll
@@ -556,7 +556,7 @@
 			header.add(PollManager.actionPolls(categoryId));
 
 			// Output - The poll
-			Output o1 = PollManager.makeOutput(poll, "PollDescription");
+			Output o1 = PollManager.makeOutput(poll, "PollDescription", response);
 			header.add(o1);
 
 			// Temporary objects used in the loop below
Index: Poll.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/epoll/src/WEB-INF/src/com/jcorporate/epoll/dbobj/Poll.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -Lsrc/WEB-INF/src/com/jcorporate/epoll/dbobj/Poll.java -Lsrc/WEB-INF/src/com/jcorporate/epoll/dbobj/Poll.java -u -r1.6 -r1.7
--- src/WEB-INF/src/com/jcorporate/epoll/dbobj/Poll.java
+++ src/WEB-INF/src/com/jcorporate/epoll/dbobj/Poll.java
@@ -2,7 +2,6 @@
 
 import java.util.Calendar;
 import java.util.Date;
-import java.util.GregorianCalendar;
 import java.util.Vector;
 
 import com.jcorporate.expresso.core.controller.ControllerRequest;
@@ -88,14 +87,8 @@
 	* @return: String DB-compatible string containg delayed date
 	*/
 	public static String getDateWeekLater(Date dt) throws DBException {
-		Calendar cal =
-			new GregorianCalendar(
-				dt.getYear() + 1900,
-				dt.getMonth(),
-				dt.getDate(),
-				dt.getHours(),
-				dt.getMinutes(),
-				dt.getSeconds());
+		Calendar cal = Calendar.getInstance();
+		cal.setTime(dt);
 		cal.add(Calendar.DAY_OF_MONTH, 7);
 
 		return DateTime.getDateTimeForDB(


More information about the cvs mailing list