/** * @param cronStr * @throws CronParseException if cronStr is not a valid CRON string. */ public void setCronString(String cronStr) throws CronParseException { // Try original simplistic parser... CronParser cp = new CronParser(cronStr); String recurrenceStr = null; try { recurrenceStr = cp.parseToRecurrenceString(); // throws CronParseException } catch (CronParseException e) { if (!CronExpression.isValidExpression(cronStr)) { // Parse with proper expression parser throw e; } recurrenceStr = null; // valid cronstring, not parse-able to recurrence string } if (null != recurrenceStr) { recurrenceEditor.inititalizeWithRecurrenceString(recurrenceStr); TemporalValue tv = recurrenceEditor.getTemporalState(); ScheduleType rt = temporalValueToScheduleType(tv); setScheduleType(rt); } else { // its a cron string that cannot be parsed into a recurrence string, switch to cron string // editor. setScheduleType(ScheduleType.CRON); } cronEditor.setCronString(cronStr); }
protected String getYearlyCronString() throws RuntimeException { String cronStr; StringBuilder recurrenceSb = new StringBuilder(); if (yearlyEditor.isEveryMonthOnNthDay()) { String monthOfYear = Integer.toString(yearlyEditor.getMonthOfYear0().value() + 1); recurrenceSb .append(RecurrenceType.EveryMonthNameN) .append(SPACE) .append(getTimeOfRecurrence()) .append(SPACE) .append(yearlyEditor.getDayOfMonth()) .append(SPACE) .append(monthOfYear); } else if (yearlyEditor.isNthDayNameOfMonthName()) { if (yearlyEditor.getWeekOfMonth() != WeekOfMonth.LAST) { String monthOfYear = Integer.toString(yearlyEditor.getMonthOfYear1().value() + 1); String dayOfWeek = Integer.toString(yearlyEditor.getDayOfWeek().value() + 1); String weekOfMonth = Integer.toString(yearlyEditor.getWeekOfMonth().value() + 1); recurrenceSb .append(RecurrenceType.NthDayNameOfMonthName) .append(SPACE) .append(getTimeOfRecurrence()) .append(SPACE) .append(dayOfWeek) .append(SPACE) .append(weekOfMonth) .append(SPACE) .append(monthOfYear); } else { String monthOfYear = Integer.toString(yearlyEditor.getMonthOfYear1().value() + 1); String dayOfWeek = Integer.toString(yearlyEditor.getDayOfWeek().value() + 1); recurrenceSb .append(RecurrenceType.LastDayNameOfMonthName) .append(SPACE) .append(getTimeOfRecurrence()) .append(SPACE) .append(dayOfWeek) .append(SPACE) .append(monthOfYear); } } else { throw new RuntimeException(Messages.getString("schedule.noRadioBtnsSelected")); } try { cronStr = CronParser.recurrenceStringToCronString(recurrenceSb.toString()); } catch (CronParseException e) { throw new RuntimeException( Messages.getString("schedule.invalidRecurrenceString", recurrenceSb.toString())); } return cronStr; }
/** * @return * @throws RuntimeException */ protected String getDailyCronString() throws RuntimeException { String cronStr; StringBuilder recurrenceSb = new StringBuilder(); if (dailyEditor.isEveryNDays()) { return null; } else { // must be every weekday recurrenceSb.append(RecurrenceType.EveryWeekday).append(SPACE).append(getTimeOfRecurrence()); try { cronStr = CronParser.recurrenceStringToCronString(recurrenceSb.toString()); } catch (CronParseException e) { throw new RuntimeException( Messages.getString("schedule.invalidRecurrenceString", recurrenceSb.toString())); } return cronStr; } }
protected String getWeeklyCronString() throws RuntimeException { String cronStr; StringBuilder recurrenceSb = new StringBuilder(); // WeeklyOn 0 33 6 1,3,5 recurrenceSb .append(RecurrenceType.WeeklyOn) .append(SPACE) .append(getTimeOfRecurrence()) .append(SPACE) .append(weeklyEditor.getCheckedDaysAsString(VALUE_OF_SUNDAY)); try { cronStr = CronParser.recurrenceStringToCronString(recurrenceSb.toString()); } catch (CronParseException e) { throw new RuntimeException( Messages.getString("schedule.invalidRecurrenceString", recurrenceSb.toString())); } return cronStr; }