From 1e72457fd7e4898ccf208dfb35f339916e378b50 Mon Sep 17 00:00:00 2001 From: "Maria Odea B. Ching" Date: Tue, 12 Sep 2006 08:12:25 +0000 Subject: [PATCH] Updated cron expression editor (configure.jsp). Added validation for cron expression. git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@442513 13f79535-47bb-0310-9956-ffa450edef68 --- .../web/action/admin/ConfigureAction.java | 121 +++++++++++++++++- .../webapp/WEB-INF/jsp/admin/configure.jsp | 91 ++++++++++++- 2 files changed, 204 insertions(+), 8 deletions(-) diff --git a/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/ConfigureAction.java b/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/ConfigureAction.java index ee0f245b7..be0ebf1d5 100644 --- a/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/ConfigureAction.java +++ b/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/ConfigureAction.java @@ -26,6 +26,7 @@ import org.apache.maven.archiva.configuration.InvalidConfigurationException; import org.apache.maven.archiva.indexer.RepositoryIndexException; import org.apache.maven.archiva.indexer.RepositoryIndexSearchException; import org.codehaus.plexus.xwork.action.PlexusActionSupport; +import org.codehaus.plexus.scheduler.CronExpressionValidator; import java.io.File; import java.io.IOException; @@ -49,6 +50,23 @@ public class ConfigureAction */ private Configuration configuration; + private CronExpressionValidator cronValidator; + + private String second = "0"; + + private String minute = "0"; + + private String hour = "*"; + + private String dayOfMonth = "*"; + + private String month = "*"; + + private String dayOfWeek = "?"; + + private String year; + + public String execute() throws IOException, RepositoryIndexException, RepositoryIndexSearchException, ConfigurationStoreException, InvalidConfigurationException, ConfigurationChangeException @@ -56,6 +74,19 @@ public class ConfigureAction // TODO: if this didn't come from the form, go to configure.action instead of going through with re-saving what was just loaded // TODO: if this is changed, do we move the index or recreate it? + String cronEx = ( second + " " + minute + " " + hour + " " + dayOfMonth + " " + month + + " " + dayOfWeek + " " + year ).trim(); + + //validate cron expression + cronValidator = new CronExpressionValidator(); + if( !cronValidator.validate( cronEx ) ) + { + addActionError( "Invalid Cron Expression" ); + return ERROR; + } + + configuration.setIndexerCronExpression( cronEx ); + // Normalize the path File file = new File( configuration.getIndexPath() ); configuration.setIndexPath( file.getCanonicalPath() ); @@ -79,6 +110,24 @@ public class ConfigureAction public String input() { + String[] cronEx = configuration.getIndexerCronExpression().split( " " ); + int i = 0; + + while ( i < cronEx.length ) + { + switch( i ) + { + case 0 : second = cronEx[i]; break; + case 1 : minute = cronEx[i]; break; + case 2 : hour = cronEx[i]; break; + case 3 : dayOfMonth = cronEx[i]; break; + case 4 : month = cronEx[i]; break; + case 5 : dayOfWeek = cronEx[i]; break; + case 6 : year = cronEx[i]; break; + } + i++; + } + return INPUT; } @@ -92,4 +141,74 @@ public class ConfigureAction { configuration = configurationStore.getConfigurationFromStore(); } -} \ No newline at end of file + + public String getSecond() + { + return second; + } + + public void setSecond( String second ) + { + this.second = second; + } + + public String getMinute() + { + return minute; + } + + public void setMinute( String minute ) + { + this.minute = minute; + } + + public String getHour() + { + return hour; + } + + public void setHour( String hour ) + { + this.hour = hour; + } + + public String getDayOfMonth() + { + return dayOfMonth; + } + + public void setDayOfMonth( String dayOfMonth ) + { + this.dayOfMonth = dayOfMonth; + } + + public String getYear() + { + return year; + } + + public void setYear( String year ) + { + this.year = year; + } + + public String getMonth() + { + return month; + } + + public void setMonth( String month ) + { + this.month = month; + } + + public String getDayOfWeek() + { + return dayOfWeek; + } + + public void setDayOfWeek( String dayOfWeek ) + { + this.dayOfWeek = dayOfWeek; + } +} diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/configure.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/configure.jsp index cda9c5ee3..b95e345db 100644 --- a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/configure.jsp +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/configure.jsp @@ -29,13 +29,90 @@
- - - - - - - + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+

For valid cron expression values for the Indexing Schedule, see here

+
+
+ + + Indexing Schedule Keys: + + + + + + + + + + + + + + + + + +
*every
?any
-ranges
/increments
+