SessionMessages.add(req, "message", "message.Scheduler.delete");
}
private void _populateForm(ActionForm form, CronScheduledTask scheduler) {
try {
BeanUtils.copyProperties(form, scheduler);
SchedulerForm schedulerForm = ((SchedulerForm) form);
if (UtilMethods.isSet(scheduler.getJavaClassName())) {
schedulerForm.setJavaClass(scheduler.getJavaClassName());
}
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
if (scheduler.getStartDate() != null) {
schedulerForm.setHaveStartDate(true);
schedulerForm.setStartDate(sdf2.format(scheduler.getStartDate()));
} else {
schedulerForm.setHaveStartDate(false);
}
if (scheduler.getEndDate() != null) {
schedulerForm.setHaveEndDate(true);
schedulerForm.setEndDate(sdf2.format(scheduler.getEndDate()));
} else {
schedulerForm.setHaveEndDate(false);
}
schedulerForm.setCronExpression(scheduler.getCronExpression());
StringTokenizer cronExpressionTokens = new StringTokenizer(scheduler.getCronExpression());
String token;
String[] intervalTokens;
String[] rangeTokens;
// Seconds Cron Expression
if (cronExpressionTokens.hasMoreTokens()) {
token = cronExpressionTokens.nextToken();
if (token.equals("*")) {
schedulerForm.setAtInfo(false);
schedulerForm.setAt(null);
schedulerForm.setAtTimeSecond(0);
} else {
intervalTokens = token.split("/");
rangeTokens = intervalTokens[0].split("-");
if (rangeTokens.length == 2) {
schedulerForm.setAtInfo(true);
schedulerForm.setAt("isBetween");
try {
schedulerForm.setBetweenFromSecond(Integer.parseInt(rangeTokens[0]));
schedulerForm.setBetweenToSecond(Integer.parseInt(rangeTokens[1]));
} catch (Exception e) {
schedulerForm.setBetweenFromSecond(0);
schedulerForm.setBetweenToSecond(0);
}
} else {
schedulerForm.setAtInfo(true);
schedulerForm.setAt("isTime");
try {
schedulerForm.setAtTimeSecond(Integer.parseInt(intervalTokens[0]));
} catch (Exception e) {
schedulerForm.setAtTimeSecond(0);
}
}
// if (intervalTokens.length == 2) {
// ;
// }
}
}
schedulerForm.setEachInfo(false);
// Minutes Cron Expression
if (cronExpressionTokens.hasMoreTokens()) {
token = cronExpressionTokens.nextToken();
if (token.equals("*")) {
schedulerForm.setAtInfo(false);
schedulerForm.setAt(null);
schedulerForm.setAtTimeMinute(0);
} else {
intervalTokens = token.split("/");
rangeTokens = intervalTokens[0].split("-");
if (rangeTokens.length == 2) {
schedulerForm.setAtInfo(true);
schedulerForm.setAt("isBetween");
try {
schedulerForm.setBetweenFromMinute(Integer.parseInt(rangeTokens[0]));
schedulerForm.setBetweenToMinute(Integer.parseInt(rangeTokens[1]));
} catch (Exception e) {
schedulerForm.setBetweenFromMinute(0);
schedulerForm.setBetweenToMinute(0);
}
} else {
schedulerForm.setAtInfo(true);
schedulerForm.setAt("isTime");
try {
schedulerForm.setAtTimeMinute(Integer.parseInt(intervalTokens[0]));
} catch (Exception e) {
schedulerForm.setAtTimeMinute(0);
}
}
if (intervalTokens.length == 2) {
try {
schedulerForm.setEachMinutes(Integer.parseInt(intervalTokens[1]));
schedulerForm.setEachInfo(true);
} catch (Exception e) {
schedulerForm.setEachMinutes(0);
}
}
}
}
// Hours Cron Expression
if (cronExpressionTokens.hasMoreTokens()) {
token = cronExpressionTokens.nextToken();
if (token.equals("*")) {
schedulerForm.setAtInfo(false);
schedulerForm.setAt(null);
schedulerForm.setAtTimeHour(0);
} else {
intervalTokens = token.split("/");
rangeTokens = intervalTokens[0].split("-");
if (rangeTokens.length == 2) {
schedulerForm.setAtInfo(true);
schedulerForm.setAt("isBetween");
try {
schedulerForm.setBetweenFromHour(Integer.parseInt(rangeTokens[0]));
schedulerForm.setBetweenToHour(Integer.parseInt(rangeTokens[1]));
} catch (Exception e) {
schedulerForm.setBetweenFromHour(0);
schedulerForm.setBetweenToHour(0);
}
} else {
schedulerForm.setAtInfo(true);
schedulerForm.setAt("isTime");
try {
schedulerForm.setAtTimeHour(Integer.parseInt(intervalTokens[0]));
} catch (Exception e) {
schedulerForm.setAtTimeHour(0);
}
}
if (intervalTokens.length == 2) {
try {
schedulerForm.setEachHours(Integer.parseInt(intervalTokens[1]));
schedulerForm.setEachInfo(true);
} catch (Exception e) {
schedulerForm.setEachHours(0);
}
}
}
}
schedulerForm.setEveryInfo(false);
schedulerForm.setEvery(null);
// Days of Month Cron Expression
if (cronExpressionTokens.hasMoreTokens()) {
token = cronExpressionTokens.nextToken();
if (token.equals("*") || token.equals("?")) {
schedulerForm.setEveryDateDay(-1);
} else {
try {
schedulerForm.setEveryDateDay(Integer.parseInt(token));
schedulerForm.setEveryInfo(true);
schedulerForm.setEvery("isDate");
} catch (Exception e) {
schedulerForm.setEveryDateDay(-1);
}
}
}
// Months Cron Expression
if (cronExpressionTokens.hasMoreTokens()) {
token = cronExpressionTokens.nextToken();
if (token.equals("*")) {
schedulerForm.setEveryDateMonth(-1);
} else {
try {
schedulerForm.setEveryDateMonth(Integer.parseInt(token));
schedulerForm.setEveryInfo(true);
schedulerForm.setEvery("isDate");
} catch (Exception e) {
schedulerForm.setEveryDateMonth(-1);
}
}
}
// Days of Week Cron Expression
if (cronExpressionTokens.hasMoreTokens()) {
token = cronExpressionTokens.nextToken();
if ((!token.equals("*")) && (!token.equals("?"))) {
StringTokenizer daysOfWeek = new StringTokenizer(token, ",");
String dayOfWeek;
for (; daysOfWeek.hasMoreTokens();) {
dayOfWeek = daysOfWeek.nextToken();
if (dayOfWeek.equals("MON"))
schedulerForm.setMonday(true);
else if (dayOfWeek.equals("TUE"))
schedulerForm.setTuesday(true);
else if (dayOfWeek.equals("WED"))
schedulerForm.setWednesday(true);
else if (dayOfWeek.equals("THU"))
schedulerForm.setThusday(true);
else if (dayOfWeek.equals("FRI"))
schedulerForm.setFriday(true);
else if (dayOfWeek.equals("SAT"))
schedulerForm.setSaturday(true);
else if (dayOfWeek.equals("SUN"))
schedulerForm.setSunday(true);
}
schedulerForm.setEveryInfo(true);
schedulerForm.setEvery("isDays");
}
}
// Years Cron Expression
if (cronExpressionTokens.hasMoreTokens()) {
token = cronExpressionTokens.nextToken();
if (token.equals("*")) {
schedulerForm.setEveryDateYear(-1);
} else {
try {
schedulerForm.setEveryDateYear(Integer.parseInt(token));
schedulerForm.setEveryInfo(true);
schedulerForm.setEvery("isDate");
} catch (Exception e) {
schedulerForm.setEveryDateYear(-1);
}
}
}
schedulerForm.setEveryDate(schedulerForm.getEveryDateYear()+"-"+(schedulerForm.getEveryDateMonth()<10?"0"+schedulerForm.getEveryDateMonth():schedulerForm.getEveryDateMonth())+"-"+schedulerForm.getEveryDateDay());
} catch (Exception e) {
Logger.warn(this, e.getMessage());
}
}