PR: MRM-150

Added validation on the forms.


git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@440329 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Maria Odea B. Ching 2006-09-05 12:09:18 +00:00
parent b4554beeb3
commit eab93a0129
16 changed files with 302 additions and 14 deletions

View File

@ -0,0 +1,62 @@
package org.apache.maven.archiva.web.validator;
/*
* Copyright 2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.opensymphony.xwork.validator.validators.ValidatorSupport;
import com.opensymphony.xwork.validator.ValidationException;
import com.opensymphony.xwork.validator.ValidatorContext;
/**
*
* @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
*/
public class IntervalValidator
extends ValidatorSupport
{
public void validate( Object obj )
throws ValidationException
{
String snapshotsPolicy = ( String ) getFieldValue( "snapshotsPolicy", obj );
String releasesPolicy = ( String ) getFieldValue( "releasesPolicy", obj );
Integer snapshotsInterval = ( Integer ) getFieldValue( "snapshotsInterval", obj );
Integer releasesInterval = ( Integer ) getFieldValue( "releasesInterval", obj );
ValidatorContext ctxt = getValidatorContext();
if( !snapshotsPolicy.equals( "interval" ) )
{
if( snapshotsInterval.intValue() != 0 )
{
ctxt.addActionError( "Snapshots Interval must be set to zero." );
}
}
if( !releasesPolicy.equals( "interval" ) )
{
if( releasesInterval.intValue() != 0 )
{
ctxt.addActionError( "Releases Interval must be set to zero." );
}
}
if( ctxt.hasActionErrors() )
{
return;
}
}
}

View File

@ -0,0 +1,111 @@
package org.apache.maven.archiva.web.validator;
/*
* Copyright 2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.opensymphony.xwork.validator.validators.ValidatorSupport;
import com.opensymphony.xwork.validator.ValidationException;
import com.opensymphony.xwork.validator.ValidatorContext;
/**
* Validator for synced repository form. The values to be validated depends on the
* selected sync method to be used.
*
* @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
*/
public class SyncedRepositoryValidator
extends ValidatorSupport
{
public void validate( Object obj )
throws ValidationException
{
String method = ( String ) getFieldValue( "method", obj );
ValidatorContext ctxt = getValidatorContext();
if( method.equals( "rsync" ) )
{
String rsyncHost = ( String ) getFieldValue( "rsyncHost", obj );
if( rsyncHost == null || rsyncHost.equals("") )
{
ctxt.addActionError( "Rsync host is required." );
}
String rsyncDirectory = ( String ) getFieldValue( "rsyncDirectory", obj );
if( rsyncDirectory == null || rsyncDirectory.equals("") )
{
ctxt.addActionError( "Rsync directory is required." );
}
String rsyncMethod = ( String ) getFieldValue( "rsyncMethod", obj );
if( rsyncMethod == null || rsyncMethod.equals("") )
{
ctxt.addActionError( "Rsync method is required." );
}
else
{
if( !rsyncMethod.equals( "anonymous" ) && !rsyncMethod.equals( "ssh" ) )
{
ctxt.addActionError( "Invalid rsync method" );
}
}
String username = ( String ) getFieldValue( "username", obj );
if( username == null || username.equals("") )
{
ctxt.addActionError( "Username is required." );
}
}
else if ( method.equals( "svn" ) )
{
String svnUrl = ( String ) getFieldValue( "svnUrl", obj );
if( svnUrl == null || svnUrl.equals("") )
{
ctxt.addActionError( "SVN url is required." );
}
String username = ( String ) getFieldValue( "username", obj );
if( username == null || username.equals("") )
{
ctxt.addActionError( "Username is required." );
}
}
else if ( method.equals( "cvs" ) )
{
String cvsRoot = ( String ) getFieldValue( "cvsRoot", obj );
if( cvsRoot == null || cvsRoot.equals("") )
{
ctxt.addActionError( "CVS root is required." );
}
}
else if ( method.equals( "file" ) )
{
String directory = ( String ) getFieldValue( "directory", obj );
if( directory == null || directory.equals("") )
{
ctxt.addActionError( "Directory is required." );
}
}
if( ctxt.hasActionErrors() )
{
return;
}
}
}

View File

@ -24,17 +24,69 @@
<field-validator type="requiredstring">
<message>You must enter the repository identifier.</message>
</field-validator>
<!--field-validator type="regex">
<param name="expression"><![CDATA[([A-Z][a-z][0-9])]]></param>
<message>Id must not have special characters.</message>
</field-validator-->
</field>
<field name="name">
<field-validator type="requiredstring">
<message>You must enter the repository name.</message>
</field-validator>
</field>
<!-- deng todo: check if the entered repo url exists -->
<field name="url">
<field-validator type="requiredstring">
<message>You must enter the repository URL.</message>
</field-validator>
</field>
<field name="snapshotsInterval">
<field-validator type="regex">
<param name="expression"><![CDATA[([0-9])]]></param>
<message>The value must be numeric</message>
</field-validator>
</field>
<field name="releasesInterval">
<field-validator type="regex">
<param name="expression"><![CDATA[([0-9])]]></param>
<message>The value must be numeric</message>
</field-validator>
</field>
<!-- deng todo: check if the interval validator is still valid -->
<validator type="interval">
<message/>
</validator>
<field name="layout">
<field-validator type="required">
<message>Repository type is required.</message>
</field-validator>
<field-validator type="fieldexpression">
<param name="expression">layout in {"legacy", "default"} </param>
<message>Invalid repository type.</message>
</field-validator>
</field>
<field name="snapshotsPolicy">
<field-validator type="fieldexpression">
<param name="expression">snapshotsPolicy in { "disabled", "daily", "hourly", "never", "interval" }</param>
<message>Invalid snapshot policy.</message>
</field-validator>
</field>
<field name="releasesPolicy">
<field-validator type="fieldexpression">
<param name="expression">releasesPolicy in { "disabled", "daily", "hourly", "never", "interval" }</param>
<message>Invalid releases policy.</message>
</field-validator>
</field>
<field name="managedRepository">
<field-validator type="requiredstring">
<message>A managed repository must be selected.</message>
</field-validator>
</field>
<!-- TODO: validate managed repository -->
<!-- TODO: validate layout -->
<!-- TODO: validate policies -->

View File

@ -30,10 +30,16 @@
<message>You must enter the repository name.</message>
</field-validator>
</field>
<!-- deng todo: validate if the specified directory exists -->
<field name="directory">
<field-validator type="requiredstring">
<message>You must enter the repository directory.</message>
</field-validator>
</field>
<!-- TODO: validate layout -->
<field name="layout">
<field-validator type="fieldexpression">
<param name="expression">layout in {"legacy", "default"} </param>
<message>Invalid repository type.</message>
</field-validator>
</field>
</validators>

View File

@ -29,6 +29,25 @@
<message>You must enter the repository name.</message>
</field-validator>
</field>
<field name="layout">
<field-validator type="requiredstring">
<message>Select repository type.</message>
</field-validator>
<field-validator type="fieldexpression">
<param name="expression">layout in {"legacy", "default"} </param>
<message>Invalid repository type.</message>
</field-validator>
</field>
<field name="managedRepository">
<field-validator type="requiredstring">
<message>A managed repository must be selected.</message>
</field-validator>
</field>
<validator type="syncedrepo">
<message/>
</validator>
<!-- TODO: validate managed repository -->
<!-- TODO: validate layout -->
<!-- TODO: validate sync settings, depending on what method -->

View File

@ -24,5 +24,9 @@
<field-validator type="requiredstring">
<message>You must enter the synchronization method.</message>
</field-validator>
<field-validator type="fieldexpression">
<param name="expression">method in { "rsync", "cvs", "svn", "file" }</param>
<message>Invalid method.</message>
</field-validator>
</field>
</validators>

View File

@ -0,0 +1,18 @@
<validators>
<validator name="required" class="com.opensymphony.xwork.validator.validators.RequiredFieldValidator"/>
<validator name="requiredstring" class="com.opensymphony.xwork.validator.validators.RequiredStringValidator"/>
<validator name="int" class="com.opensymphony.xwork.validator.validators.IntRangeFieldValidator"/>
<validator name="double" class="com.opensymphony.xwork.validator.validators.DoubleRangeFieldValidator"/>
<validator name="date" class="com.opensymphony.xwork.validator.validators.DateRangeFieldValidator"/>
<validator name="expression" class="com.opensymphony.xwork.validator.validators.ExpressionValidator"/>
<validator name="fieldexpression" class="com.opensymphony.xwork.validator.validators.FieldExpressionValidator"/>
<validator name="email" class="com.opensymphony.xwork.validator.validators.EmailValidator"/>
<validator name="url" class="com.opensymphony.xwork.validator.validators.URLValidator"/>
<validator name="visitor" class="com.opensymphony.xwork.validator.validators.VisitorFieldValidator"/>
<validator name="conversion" class="com.opensymphony.xwork.validator.validators.ConversionErrorFieldValidator"/>
<validator name="stringlength" class="com.opensymphony.xwork.validator.validators.StringLengthFieldValidator"/>
<validator name="regex" class="com.opensymphony.xwork.validator.validators.RegexFieldValidator"/>
<validator name="interval" class="org.apache.maven.archiva.web.validator.IntervalValidator"/>
<validator name="syncedrepo" class="org.apache.maven.archiva.web.validator.SyncedRepositoryValidator"/>
</validators>

View File

@ -30,6 +30,8 @@
<h2>Add Proxied Repository</h2>
<%@ include file="errorMessages.jsp" %>
<ww:actionmessage/>
<ww:form method="post" action="addProxiedRepository" namespace="/admin" validate="true">
<ww:textfield name="id" label="Identifier" size="10"/>
@ -45,4 +47,4 @@
</div>
</body>
</html>
</html>

View File

@ -32,7 +32,7 @@
<ww:actionmessage/>
<ww:form method="post" action="addRepository" namespace="/admin" validate="true">
<ww:textfield name="id" label="Identifier" size="10"/>
<ww:textfield name="id" label="Identifier" size="10" required="true"/>
<%@ include file="/WEB-INF/jsp/admin/include/managedRepositoryForm.jspf" %>
<ww:checkbox name="indexed" fieldValue="true" value="true" label="Indexed"/>
<ww:submit value="Add Repository"/>
@ -45,4 +45,4 @@
</div>
</body>
</html>
</html>

View File

@ -31,9 +31,11 @@
<h2>Add Synced Repository</h2>
<%@ include file="errorMessages.jsp" %>
<ww:actionmessage/>
<ww:form method="post" action="addSelectedSyncedRepository" namespace="/admin" validate="true">
<ww:textfield name="id" label="Identifier" size="10"/>
<ww:textfield name="id" label="Identifier" size="10" required="true"/>
<%@ include file="/WEB-INF/jsp/admin/include/syncedRepositoryForm.jspf" %>
<ww:submit value="Add Repository"/>
@ -46,4 +48,4 @@
</div>
</body>
</html>
</html>

View File

@ -29,7 +29,7 @@
<div id="contentArea">
<ww:actionmessage/>
<ww:form method="post" action="saveConfiguration" namespace="/admin" validate="true">
<ww:textfield name="indexPath" label="Index Directory" size="100"/>
<ww:textfield name="indexPath" label="Index Directory" size="100" required="true"/>
<ww:textfield name="indexerCronExpression" label="Indexing Schedule"/>
<ww:textfield name="reporterCronExpression" label="Reporting Schedule"/>
<ww:hidden name="proxy.protocol" value="http"/>
@ -47,4 +47,4 @@
</div>
</body>
</html>
</html>

View File

@ -30,6 +30,8 @@
<h2>Edit Proxied Repository</h2>
<%@ include file="errorMessages.jsp" %>
<ww:actionmessage/>
<ww:form method="post" action="editProxiedRepository" namespace="/admin" validate="true">
<ww:hidden name="id"/>
@ -44,4 +46,4 @@
</div>
</body>
</html>
</html>

View File

@ -31,6 +31,8 @@
<h2>Edit Synced Repository</h2>
<%@ include file="errorMessages.jsp" %>
<ww:actionmessage/>
<ww:form method="post" action="editSyncedRepository" namespace="/admin" validate="true">
<ww:hidden name="id"/>
@ -46,4 +48,4 @@
</div>
</body>
</html>
</html>

View File

@ -0,0 +1,8 @@
<p>
<ww:if test="hasActionErrors()">
<b style="color: red;" >Errors:</b>
<ww:iterator value="actionErrors">
<li style="color: red;"><ww:property/></li>
</ww:iterator>
</ww:if>
</p>

View File

@ -16,8 +16,8 @@
<%@ taglib prefix="ww" uri="/webwork" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<ww:textfield name="name" label="Name" size="50" />
<ww:textfield name="directory" label="Directory" size="100" />
<ww:textfield name="name" label="Name" size="50" required="true" />
<ww:textfield name="directory" label="Directory" size="100" required="true"/>
<ww:select list="#@java.util.LinkedHashMap@{'default' : 'Maven 2.x Repository', 'legacy' : 'Maven 1.x Repository'}"
name="layout" label="Type" />
<ww:checkbox name="includeSnapshots" fieldValue="true" label="Snapshots Included" />

View File

@ -15,8 +15,8 @@
--%>
<%@ taglib prefix="ww" uri="/webwork" %>
<ww:textfield name="name" label="Name" size="50" />
<ww:textfield name="url" label="URL" size="50" />
<ww:textfield name="name" label="Name" size="50" required="true"/>
<ww:textfield name="url" label="URL" size="50" required="true"/>
<ww:select list="#@java.util.LinkedHashMap@{'default' : 'Maven 2.x Repository', 'legacy' : 'Maven 1.x Repository'}"
name="layout" label="Type" />
<ww:select name="snapshotsPolicy" label="Snapshots" list="#@java.util.LinkedHashMap@{