/* Copyright 1999-2008 Acelet.org. All rights reserved. GPL v2 license */
/** @author Wei Jiang */
package com.acelet.s.task;
import java.util.*;
import com.acelet.lib.Common;
import com.acelet.lib.LoggingConstants;
import com.acelet.lib.Phrase;
import com.acelet.lib.XmlingToString;
import com.acelet.s.task.Task;
import com.acelet.s.task.WorkingTask;
public class TaskText {
public static String repeatingNotSpecifiedText;
public static String repeatingOnceText;
public static String repeatingMinutelyText;
public static String repeatingHourlyText;
public static String repeatingDailyText;
public static String repeatingWeeklyText;
public static String repeatingMonthlyText;
public static String repeatingWeekDayMonthlyText;
public static String repeatingAtSpecifiedTimesText;
public static String repeatingSuperSchedulerStartupText;
public static String repeatingStandbyText;
public static String repeatingImmediatelyOnceText;
public static String repeatingOncallText;
public static String whichWeekFirstText;
public static String whichWeekSecondText;
public static String whichWeekThirdText;
public static String whichWeekFourthText;
public static String whichWeekLastText;
public static String weekDayMondayText;
public static String weekDayTuesdayText;
public static String weekDayWednesdayText;
public static String weekDayThursdayText;
public static String weekDayFridayText;
public static String weekDaySaturdayText;
public static String weekDaySundayText;
public static Vector monthTextVector;
static {
repeatingNotSpecifiedText = Phrase.get("TX_REPEATING_NOT_SPECIFIED");
repeatingOnceText = Phrase.get("TX_REPEATING_ONCE");
repeatingMinutelyText = Phrase.get("TX_REPEATING_MINUTELY");
repeatingHourlyText = Phrase.get("TX_REPEATING_HOURLY");
repeatingDailyText = Phrase.get("TX_REPEATING_DAILY");
repeatingWeeklyText = Phrase.get("TX_REPEATING_WEEKLY");
repeatingMonthlyText = Phrase.get("TX_REPEATING_MONTHLY");
repeatingWeekDayMonthlyText = Phrase.get("TX_REPEATING_WEEK_DAY_MONTHLY");
repeatingAtSpecifiedTimesText = Phrase.get("TX_REPEATING_AT_SPECIFIED_TIMES");
repeatingSuperSchedulerStartupText = Phrase.get("TX_REPEATING_SUPER_SCHEDULER_STARTUP");
repeatingStandbyText = Phrase.get("TX_REPEATING_STANDBY");
repeatingImmediatelyOnceText = Phrase.get("TX_REPEATING_IMMEDIATELY_ONCE");
repeatingOncallText = Phrase.get("TX_REPEATING_ONCALL");
whichWeekFirstText = Phrase.get("TX_FIRST");
whichWeekSecondText = Phrase.get("TX_SECOND");
whichWeekThirdText = Phrase.get("TX_THIRD");
whichWeekFourthText = Phrase.get("TX_FOURTH");
whichWeekLastText = Phrase.get("TX_LAST");
weekDayMondayText = Phrase.get("TX_MONDAY");
weekDayTuesdayText = Phrase.get("TX_TUESDAY");
weekDayWednesdayText = Phrase.get("TX_WEDNESDAY");
weekDayThursdayText = Phrase.get("TX_THURSDAY");
weekDayFridayText = Phrase.get("TX_FRIDAY");
weekDaySaturdayText = Phrase.get("TX_SATURDAY");
weekDaySundayText = Phrase.get("TX_SUNDAY");
monthTextVector = new Vector();
monthTextVector.add(Phrase.get("TX_JANUARY"));
monthTextVector.add(Phrase.get("TX_FEBRUARY"));
monthTextVector.add(Phrase.get("TX_MARCH"));
monthTextVector.add(Phrase.get("TX_APRIL"));
monthTextVector.add(Phrase.get("TX_MAY"));
monthTextVector.add(Phrase.get("TX_JUNE"));
monthTextVector.add(Phrase.get("TX_JULY"));
monthTextVector.add(Phrase.get("TX_AUGUST"));
monthTextVector.add(Phrase.get("TX_SEPTEMBER"));
monthTextVector.add(Phrase.get("TX_OCTOBER"));
monthTextVector.add(Phrase.get("TX_NOVEMBER"));
monthTextVector.add(Phrase.get("TX_DECEMBER"));
}
public static String getTaskBrief(Task task) {
return LoggingConstants.COMMON_DELIMITER + task.name +
LoggingConstants.COMMON_DELIMITER + getTaskTerm(task) +
LoggingConstants.COMMON_DELIMITER + translateStatus(task.status) +
LoggingConstants.COMMON_DELIMITER + task.hostname +
LoggingConstants.COMMON_DELIMITER + new XmlingToString(task.getJob()).toString();
}
public static String getTaskTerm(Task task) {
boolean shouldAddAdvanced = true;
int repeating = task.getRepeating();
if (repeating == Task.NOT_SPECIFIED)
shouldAddAdvanced = false;
StringBuffer buffer = new StringBuffer(translateRepeating(repeating));
if (repeating == Task.REPEATING_ONCE) {
shouldAddAdvanced = false;
} else if (repeating == Task.REPEATING_MINUTELY) {
buffer.append(": " + task.getMinutelyPeriod());
buffer.append(" " + Phrase.get("TX_MINUTE_"));
} else if (repeating == Task.REPEATING_HOURLY) {
buffer.append(": " + task.getHourlyPeriod());
buffer.append(" " + Phrase.get("TX_HOUR_"));
} else if (repeating == Task.REPEATING_DAILY) {
buffer.append(": " + task.getDailyPeriod());
buffer.append(" " + Phrase.get("TX_DAY_"));
} else if (repeating == Task.REPEATING_WEEKLY) {
buffer.append(": " + task.getWeeklyPeriod());
buffer.append(" " + Phrase.get("TX_WEEK_") + " ");
buffer.append(translateWeekDay(task.getWeeklyWeekDay()));
} else if (repeating == Task.REPEATING_MONTHLY) {
buffer.append(": " + task.getMonthlyPeriod());
buffer.append(" " + Phrase.get("TX_MONTH_"));
buffer.append(" " + Phrase.get("TX_ON") + " ");
int monthlyTheDay = task.getMonthlyTheDay();
if (monthlyTheDay >= Task.LAST_DAY)
buffer.append(Phrase.get("TX_LAST_DAY"));
else
buffer.append(monthlyTheDay);
} else if (repeating == Task.REPEATING_WEEK_DAY_MONTHLY) {
buffer.append(": " + task.getMonthlyPeriod());
buffer.append(" " + Phrase.get("TX_MONTH_"));
buffer.append(" " + translateWhichWeek(task.getMonthlyWhichWeek()));
buffer.append(" " + translateWeekDay(task.getMonthlyWhichWeekWeekDay()));
} else if (repeating == Task.REPEATING_AT_SPECIFIED_TIMES) {
buffer.append(": " + task.getSpecifiedTimes());
shouldAddAdvanced = true;
} else if (repeating == Task.REPEATING_SUPER_SCHEDULER_STARTUP) {
shouldAddAdvanced = false;
} else if (repeating == Task.REPEATING_STANDBY) {
shouldAddAdvanced = false;
} else if (repeating == Task.REPEATING_IMMEDIATELY_ONCE) {
shouldAddAdvanced = false;
} else if (repeating == Task.REPEATING_ONCALL) {
shouldAddAdvanced = false;
}
if (shouldAddAdvanced) {
buffer.append("; ");
buffer.append(translateHolidayPolicy(task.getHolidayPolicy()));
buffer.append("; ");
String startTimeString = "";
if (task.getStartTime() != Task.NOT_SPECIFIED)
startTimeString = Common.getDateTimeString(task.getStartTime());
buffer.append(startTimeString);
buffer.append("; ");
String expirationString = "";
long expiration = task.getExpiration();
if (expiration < Long.MAX_VALUE)
expirationString = Common.getDateTimeString(expiration);
buffer.append(expirationString);
}
return buffer.toString();
}
public static String translateHolidayPolicy(int policy) {
if (policy == Task.HOLIDAY_POLICY_SAME)
return Phrase.get("TX_THE_SAME_DAY");
else if (policy == Task.HOLIDAY_POLICY_PREVIOUS)
return Phrase.get("TX_PREVIOUS_BUSINESS_DAY");
else if (policy == Task.HOLIDAY_POLICY_NEXT)
return Phrase.get("TX_NEXT_BUSINESS_DAY");
else if (policy == Task.HOLIDAY_POLICY_SKIP)
return Phrase.get("TX_SKIP");
else
return null;
}
public static int translateRepeating(String repeatingText) {
int repeating = Task.NOT_SPECIFIED;
if (repeatingText.equals(repeatingOnceText))
repeating = Task.REPEATING_ONCE;
else if (repeatingText.equals(repeatingMinutelyText))
repeating = Task.REPEATING_MINUTELY;
else if (repeatingText.equals(repeatingHourlyText))
repeating = Task.REPEATING_HOURLY;
else if (repeatingText.equals(repeatingDailyText))
repeating = Task.REPEATING_DAILY;
else if (repeatingText.equals(repeatingWeeklyText))
repeating = Task.REPEATING_WEEKLY;
else if (repeatingText.equals(repeatingMonthlyText))
repeating = Task.REPEATING_MONTHLY;
else if (repeatingText.equals(repeatingWeekDayMonthlyText))
repeating = Task.REPEATING_WEEK_DAY_MONTHLY;
else if (repeatingText.equals(repeatingAtSpecifiedTimesText))
repeating = Task.REPEATING_AT_SPECIFIED_TIMES;
else if (repeatingText.equals(repeatingSuperSchedulerStartupText))
repeating = Task.REPEATING_SUPER_SCHEDULER_STARTUP;
else if (repeatingText.equals(repeatingStandbyText))
repeating = Task.REPEATING_STANDBY;
return repeating;
}
public static String translateRepeating(int repeating) {
if (repeating == Task.NOT_SPECIFIED)
return repeatingNotSpecifiedText;
else if (repeating == Task.REPEATING_ONCE)
return repeatingOnceText;
else if (repeating == Task.REPEATING_MINUTELY)
return repeatingMinutelyText;
else if (repeating == Task.REPEATING_HOURLY)
return repeatingHourlyText;
else if (repeating == Task.REPEATING_DAILY)
return repeatingDailyText;
else if (repeating == Task.REPEATING_WEEKLY)
return repeatingWeeklyText;
else if (repeating == Task.REPEATING_MONTHLY)
return repeatingMonthlyText;
else if (repeating == Task.REPEATING_WEEK_DAY_MONTHLY)
return repeatingWeekDayMonthlyText;
else if (repeating == Task.REPEATING_AT_SPECIFIED_TIMES)
return repeatingAtSpecifiedTimesText;
else if (repeating == Task.REPEATING_SUPER_SCHEDULER_STARTUP)
return repeatingSuperSchedulerStartupText;
else if (repeating == Task.REPEATING_STANDBY)
return repeatingStandbyText;
else if (repeating == Task.REPEATING_IMMEDIATELY_ONCE)
return repeatingImmediatelyOnceText;
else if (repeating == Task.REPEATING_ONCALL)
return repeatingOncallText;
else
return "";
}
public static String translateStatus(int status) {
if (status == Task.STATUS_ACTIVE)
return Phrase.get("TX_ACTIVE");
else if (status == Task.STATUS_INACTIVE)
return Phrase.get("TX_INACTIVE");
else if (status == Task.STATUS_STANDBY)
return Phrase.get("TX_STANDBY");
else if (status == Task.STATUS_SUSPENDED)
return Phrase.get("TX_SUSPENDED");
else if (status == Task.STATUS_ERROR)
return Phrase.get("TX_ERROR");
else if (status == WorkingTask.STATUS_STARTED)
return Phrase.get("TX_STARTED");
else if (status == WorkingTask.STATUS_DONE)
return Phrase.get("TX_DONE");
else if (status == WorkingTask.STATUS_ERROR)
return Phrase.get("TX_ERROR");
else if (status == WorkingTask.STATUS_MISSED)
return Phrase.get("TX_MISSED");
else if (status == WorkingTask.STATUS_EXCEEDED_DURATION)
return Phrase.get("TX_EXCEEDED_DURATION");
else if (status == WorkingTask.STATUS_KILLED)
return Phrase.get("TX_KILLED");
else if (status == WorkingTask.STATUS_LOST)
return Phrase.get("TX_LOST");
else
return "";
}
public static String translateWeekDay(int weekDay) {
if (weekDay == Calendar.MONDAY)
return weekDayMondayText;
else if (weekDay == Calendar.TUESDAY)
return weekDayTuesdayText;
else if (weekDay == Calendar.WEDNESDAY)
return weekDayWednesdayText;
else if (weekDay == Calendar.THURSDAY)
return weekDayThursdayText;
else if (weekDay == Calendar.FRIDAY)
return weekDayFridayText;
else if (weekDay == Calendar.SATURDAY)
return weekDaySaturdayText;
else if (weekDay == Calendar.SUNDAY)
return weekDaySundayText;
else
return "";
}
public static int translateWeekDay(String weekDayText) {
int weekDay = Task.NOT_SPECIFIED;
if (weekDayText.equals(weekDayMondayText))
weekDay = Calendar.MONDAY;
else if (weekDayText.equals(weekDayTuesdayText))
weekDay = Calendar.TUESDAY;
else if (weekDayText.equals(weekDayWednesdayText))
weekDay = Calendar.WEDNESDAY;
else if (weekDayText.equals(weekDayThursdayText))
weekDay = Calendar.THURSDAY;
else if (weekDayText.equals(weekDayFridayText))
weekDay = Calendar.FRIDAY;
else if (weekDayText.equals(weekDaySaturdayText))
weekDay = Calendar.SATURDAY;
else if (weekDayText.equals(weekDaySundayText))
weekDay = Calendar.SUNDAY;
return weekDay;
}
public static String translateWhichWeek(int whichWeek) {
if (whichWeek == 1)
return whichWeekFirstText;
else if (whichWeek == 2)
return whichWeekSecondText;
else if (whichWeek == 3)
return whichWeekThirdText;
else if (whichWeek == 4)
return whichWeekFourthText;
else if (whichWeek == Task.LAST_WEEK)
return whichWeekLastText;
else
return "";
}
public static int translateWhichWeek(String whichWeekText) {
int whichWeek = Task.NOT_SPECIFIED;
if (whichWeekText.equals(whichWeekFirstText))
whichWeek = 1;
else if (whichWeekText.equals(whichWeekSecondText))
whichWeek = 2;
else if (whichWeekText.equals(whichWeekThirdText))
whichWeek = 3;
else if (whichWeekText.equals(whichWeekFourthText))
whichWeek = 4;
else if (whichWeekText.equals(whichWeekLastText))
whichWeek = Task.LAST_WEEK;
return whichWeek;
}
}