Class CronExpressionParser

java.lang.Object
com.atlassian.jira.web.component.cron.parser.CronExpressionParser

public class CronExpressionParser extends Object
Represents a cron string with accessor methods to get at the individual fields. This is only used to back our Cron editor. This will tell you via the isValidForEditor() method whether the cron string this is constructed with will be parseable via the editor. To populate the editor use the getCronEditorBean() method.

There are four modes that the editor supports:

  1. Daily Mode
  2. Days Per Week Mode
  3. Days Per Month Mode
  4. Advanced Mode

If a cron string is not valid for the editor then the only available mode will be the advanced mode and the editor state methods (e.g. getDayOfMonth() , getHoursEntry() ) will return details of the default state represented by DEFAULT_CRONSTRING as they are not able to represent the advanced cron string.

The validation that this object performs is in the context of valid cron strings that will fit into the editor. This object does not validate that the over all string is a valid cron string.

  • Field Details

    • DEFAULT_CRONSTRING

      public static final String DEFAULT_CRONSTRING
      Cron string that puts the editor into the default state.
      See Also:
  • Constructor Details

    • CronExpressionParser

      public CronExpressionParser()
      Creates a parser in default state using DEFAULT_CRONSTRING.
    • CronExpressionParser

      public CronExpressionParser(String cronString)
      Parses the given cronString to establish the state of this CronExpressionParser.
      Parameters:
      cronString - the cron string to parse.
  • Method Details

    • getCronEditorBean

      public CronEditorBean getCronEditorBean()
      Will provide the CronEditorBean which represents the state of the form for the configured cron string.
      Returns:
      the bean
    • getCronString

      public String getCronString()
      Returns the cron string that the object was constructed with. This method does not guarantee that the returned cron string is valid.
      Returns:
      unmodified cronString passed into the constructor
    • isValidForEditor

      public boolean isValidForEditor()
      Returns true only if the cron string can be handled by the cron editor UI. If this method returns false then all method but getCronString() will throw an IllegalStateException work properly.
      Returns:
      true only if the editor has a state that corresponds to this cron expression.
    • isAdvancedMode

      public boolean isAdvancedMode()
      Will return true if the passed in cron string is not valid for the editor.
      Returns:
      true if the cron string can not be handled, false otherwise.
    • isDailyMode

      public boolean isDailyMode()
      Will return true if the editors daily mode can handle the provided cron string.
      Returns:
      true only if the mode is daily.
    • isDayPerWeekMode

      public boolean isDayPerWeekMode()
      Will return true if the editors day per week mode can handle the provided cron string.
      Returns:
      true only if we are in day per week mode.
    • isDaysPerMonthMode

      public boolean isDaysPerMonthMode()
      Will return true if the editors days per month mode can handle the provided cron string.
      Returns:
      true only if we are in days per month mode.
    • isDayOfWeekOfMonth

      public boolean isDayOfWeekOfMonth()
      Returns true if isDaysPerMonthMode() is true and the string in the days of week field can be handled by the editor.
      Returns:
      true only if we are in the Nth Xday of the month mode (where N is a week in month number and X is mon,tue etc)
    • getDayOfMonth

      public String getDayOfMonth()
      Gets the day of month field specified in the cron string.
      Returns:
      1-31 or L.
    • getMinutesEntry

      public CronMinutesEntry getMinutesEntry()
      Gets the CronMinutesEntry that represents the minutes cron field.
      Returns:
      the minutes part of the cron string.
    • getHoursEntry

      public CronHoursEntry getHoursEntry()
      Gets the CronHoursEntry that represents the hours cron field.
      Returns:
      the hours part of the cron string.
    • getDaysOfWeekEntry

      public CronDayOfWeekEntry getDaysOfWeekEntry()
      Gets the CronDayOfWeekEntry that represents the day of week cron field.
      Returns:
      the days of the week part of the cronstring.
    • getIncrementInMinutes

      public int getIncrementInMinutes()
      Used to determine the total increment in minutes that are implied by the crons hour and minutes field. If the hours and minutes field have an increment then the increment will come into play. An increment of 0 implies that the increment is once per day.
      Returns:
      the increment of repetition in minutes or 0 if there is no repetition.