All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.redhogs.cronparser.format.CronExpressionFormatter Maven / Gradle / Ivy

There is a newer version: 3.5
Show newest version
package net.redhogs.cronparser.format;

import java.text.ParseException;
import java.util.Locale;

import net.redhogs.cronparser.CronExpressionDescriptor;
import net.redhogs.cronparser.Options;

import org.quartz.CronExpression;
import org.springframework.format.Formatter;

/**
 * A Spring formatter that can be used to format a Quartz cron expression.
 *
 * 

It can be used like

* *
* <bean id="conversionService" * class="org.springframework.format.support.FormattingConversionServiceFactoryBean"> * <property name="formatters"> * <set> * <bean class="net.redhogs.cronparser.format.CronExpressionFormatter"/> * </set> * </property> * </bean> *
* * In ThymeLeaf, a cron expression can be displayed as ${{cronExpression}}. */ public class CronExpressionFormatter implements Formatter { private Options options; public CronExpressionFormatter() { } public CronExpressionFormatter(Options options) { this.options = options; } @Override public String print(CronExpression cron, Locale locale) { String cronExpression = cron.getCronExpression(); try { return options == null ? CronExpressionDescriptor.getDescription(cronExpression, locale) : CronExpressionDescriptor.getDescription(cronExpression, options, locale); } catch (ParseException e) { return cronExpression; } } @Override public CronExpression parse(String text, Locale locale) throws ParseException { throw new UnsupportedOperationException("Parsing cron human readable string is not implemeted."); } }



© 2015 - 2025 Weber Informatics LLC | Privacy Policy