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
This commit is contained in:
Maria Odea B. Ching 2006-09-12 08:12:25 +00:00
parent 9c27e8b4f7
commit 1e72457fd7
2 changed files with 204 additions and 8 deletions

View File

@ -26,6 +26,7 @@ import org.apache.maven.archiva.configuration.InvalidConfigurationException;
import org.apache.maven.archiva.indexer.RepositoryIndexException; import org.apache.maven.archiva.indexer.RepositoryIndexException;
import org.apache.maven.archiva.indexer.RepositoryIndexSearchException; import org.apache.maven.archiva.indexer.RepositoryIndexSearchException;
import org.codehaus.plexus.xwork.action.PlexusActionSupport; import org.codehaus.plexus.xwork.action.PlexusActionSupport;
import org.codehaus.plexus.scheduler.CronExpressionValidator;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -49,6 +50,23 @@ public class ConfigureAction
*/ */
private Configuration configuration; 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() public String execute()
throws IOException, RepositoryIndexException, RepositoryIndexSearchException, ConfigurationStoreException, throws IOException, RepositoryIndexException, RepositoryIndexSearchException, ConfigurationStoreException,
InvalidConfigurationException, ConfigurationChangeException 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 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? // 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 // Normalize the path
File file = new File( configuration.getIndexPath() ); File file = new File( configuration.getIndexPath() );
configuration.setIndexPath( file.getCanonicalPath() ); configuration.setIndexPath( file.getCanonicalPath() );
@ -79,6 +110,24 @@ public class ConfigureAction
public String input() 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; return INPUT;
} }
@ -92,4 +141,74 @@ public class ConfigureAction
{ {
configuration = configurationStore.getConfigurationFromStore(); configuration = configurationStore.getConfigurationFromStore();
} }
}
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;
}
}

View File

@ -29,13 +29,90 @@
<div id="contentArea"> <div id="contentArea">
<ww:actionmessage/> <ww:actionmessage/>
<ww:form method="post" action="saveConfiguration" namespace="/admin" validate="true"> <ww:form method="post" action="saveConfiguration" namespace="/admin" validate="true">
<ww:textfield name="indexPath" label="Index Directory" size="100" required="true"/>
<ww:textfield name="indexerCronExpression" label="Indexing Schedule"/> <div>
<ww:hidden name="proxy.protocol" value="http"/> <table>
<ww:textfield name="proxy.host" label="HTTP Proxy Host"/> <tbody>
<ww:textfield name="proxy.port" label="HTTP Proxy Port"/> <tr>
<ww:textfield name="proxy.username" label="HTTP Proxy Username"/> <th><font size="2"><ww:label theme="simple" value="Indexing Directory*:"/></font></th>
<ww:password name="proxy.password" label="HTTP Proxy Password"/> <td><ww:textfield name="indexPath" theme="simple" size="140" required="true"/></td>
</tr>
<tr>
<th><font size="2"><ww:label theme="simple" value="Indexing Schedule:"/></font></th>
<td>
<table>
<tr>
<th><ww:label theme="simple" value="Second:"/></th>
<td><ww:textfield name="second" theme="simple" size="2"/></td>
<th><ww:label theme="simple" value="Minute:"/></th>
<td><ww:textfield name="minute" theme="simple" size="2"/></td>
<th><ww:label theme="simple" value="Hour:"/></th>
<td><ww:textfield name="hour" theme="simple" size="2"/></td>
<th><ww:label theme="simple" value="Day of Month:"/></th>
<td><ww:textfield name="dayOfMonth" theme="simple" size="2"/></td>
<th><ww:label theme="simple" value="Month:"/></th>
<td><ww:textfield name="month" theme="simple" size="2"/></td>
<th><ww:label theme="simple" value="Day of Week:"/></th>
<td><ww:textfield name="dayOfWeek" theme="simple" size="2"/></td>
<th><ww:label theme="simple" value="Year [optional]:"/></th>
<td><ww:textfield name="year" theme="simple" size="4"/></td>
</tr>
</table>
</td>
</tr>
<ww:hidden name="proxy.protocol" value="http"/>
<tr>
<th><font size="2"><ww:label theme="simple" value="HTTP Proxy Host:"/></font></th>
<td><ww:textfield name="proxy.host" theme="simple"/></td>
</tr>
<tr>
<th><font size="2"><ww:label theme="simple" value="HTTP Proxy Port:"/></font></th>
<td><ww:textfield name="proxy.port" theme="simple"/></td>
</tr>
<tr>
<th><font size="2"><ww:label theme="simple" value="HTTP Proxy Username:"/></font></th>
<td><ww:textfield name="proxy.username" theme="simple"/></td>
</tr>
<tr>
<th><font size="2"><ww:label theme="simple" value="HTTP Proxy Password:"/></font></th>
<td><ww:textfield name="proxy.password" theme="simple"/></td>
</tr>
</tbody>
</table>
</div>
<div>
<p><i>For valid cron expression values for the Indexing Schedule, see <ww:a href="http://www.opensymphony.com/quartz/api/org/quartz/CronExpression.html">here</ww:a></i></p>
</div>
<div>
<table>
<tr>
<b>Indexing Schedule Keys:</b>
</tr>
<tr>
<th>*</th>
<td>every</td>
</tr>
<tr>
<th>?</th>
<td>any</td>
</tr>
<tr>
<th>-</th>
<td>ranges</td>
</tr>
<tr>
<th>/</th>
<td>increments</td>
</tr>
</table>
</div>
<ww:submit value="Save Configuration"/> <ww:submit value="Save Configuration"/>
</ww:form> </ww:form>