/* Copyright 1999-2008 Acelet.org. All rights reserved. GPL v2 license */
/** @author Wei Jiang */
package com.acelet.s.chore;
import java.util.*;
import com.acelet.lib.Common;
import com.acelet.lib.LoggingConstants;
import com.acelet.lib.NotSupportedException;
import com.acelet.lib.Phrase;
import com.acelet.lib.XmlingToString;
import com.acelet.s.chore.Chore;
import com.acelet.s.chore.WorkingChore;
import com.acelet.s.task.TaskText;
public class ChoreText extends TaskText {
public static int NOT_SPECIFIED = -1;
public static final String triggerTypeUserText;
public static final String triggerTypeFileTimestampText;
static {
triggerTypeUserText = Phrase.get("TX_USER");
triggerTypeFileTimestampText = Phrase.get("TX_FILE_TIMESTAMP");
}
public static String getChoreBrief(Chore chore) {
return LoggingConstants.COMMON_DELIMITER + chore.name +
LoggingConstants.COMMON_DELIMITER + getChoreTerm(chore) +
LoggingConstants.COMMON_DELIMITER + translateStatus(chore.status) +
LoggingConstants.COMMON_DELIMITER + chore.hostname +
LoggingConstants.COMMON_DELIMITER + new XmlingToString(chore.getJob()).toString();
}
public static String getChoreTerm(Chore chore) {
String xmlText = new XmlingToString(chore.getTriggerObject()).toString();
StringBuffer buffer = new StringBuffer(xmlText);
buffer.append(";");
buffer.append(chore.delay);
buffer.append(";");
String fromPeriodString = "";
long fromPeriod = chore.getFromPeriod();
if (fromPeriod > Chore.NOT_SPECIFIED)
fromPeriodString = Common.getDateTimeString(fromPeriod);
buffer.append(fromPeriodString);
buffer.append("; ");
String toPeriodString = "";
long toPeriod = chore.getToPeriod();
if (toPeriod != Long.MAX_VALUE)
toPeriodString = Common.getDateTimeString(toPeriod);
buffer.append(toPeriodString);
return buffer.toString();
}
public static String translateTriggerType(int triggerType) throws Exception {
if (triggerType == Chore.TRIGGER_TYPE_USER)
return triggerTypeUserText;
else if (triggerType == Chore.TRIGGER_TYPE_FILE_TIMESTAMP)
return triggerTypeFileTimestampText;
else
throw null;
}
public static int translateTriggerType(String triggerTypeText) throws Exception {
if (triggerTypeText.equals(triggerTypeUserText))
return Chore.TRIGGER_TYPE_USER;
else if (triggerTypeText.equals(triggerTypeFileTimestampText))
return Chore.TRIGGER_TYPE_FILE_TIMESTAMP;
else
return NOT_SPECIFIED;
}
}