From eab93a0129a4323533e7816e25e6ab319e1c8a33 Mon Sep 17 00:00:00 2001 From: "Maria Odea B. Ching" Date: Tue, 5 Sep 2006 12:09:18 +0000 Subject: [PATCH] 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 --- .../web/validator/IntervalValidator.java | 62 ++++++++++ .../validator/SyncedRepositoryValidator.java | 111 ++++++++++++++++++ ...gureProxiedRepositoryAction-validation.xml | 52 ++++++++ .../ConfigureRepositoryAction-validation.xml | 8 +- ...addSelectedSyncedRepository-validation.xml | 19 +++ ...igureSyncedRepositoryAction-validation.xml | 4 + .../src/main/resources/validators.xml | 18 +++ .../jsp/admin/addProxiedRepository.jsp | 4 +- .../WEB-INF/jsp/admin/addRepository.jsp | 4 +- .../WEB-INF/jsp/admin/addSyncedRepository.jsp | 6 +- .../webapp/WEB-INF/jsp/admin/configure.jsp | 4 +- .../jsp/admin/editProxiedRepository.jsp | 4 +- .../jsp/admin/editSyncedRepository.jsp | 4 +- .../WEB-INF/jsp/admin/errorMessages.jsp | 8 ++ .../admin/include/managedRepositoryForm.jspf | 4 +- .../admin/include/proxiedRepositoryForm.jspf | 4 +- 16 files changed, 302 insertions(+), 14 deletions(-) create mode 100644 archiva-webapp/src/main/java/org/apache/maven/archiva/web/validator/IntervalValidator.java create mode 100644 archiva-webapp/src/main/java/org/apache/maven/archiva/web/validator/SyncedRepositoryValidator.java create mode 100644 archiva-webapp/src/main/resources/validators.xml create mode 100644 archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/errorMessages.jsp diff --git a/archiva-webapp/src/main/java/org/apache/maven/archiva/web/validator/IntervalValidator.java b/archiva-webapp/src/main/java/org/apache/maven/archiva/web/validator/IntervalValidator.java new file mode 100644 index 000000000..63b9f3995 --- /dev/null +++ b/archiva-webapp/src/main/java/org/apache/maven/archiva/web/validator/IntervalValidator.java @@ -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 Maria Odea Ching + */ +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; + } + } +} diff --git a/archiva-webapp/src/main/java/org/apache/maven/archiva/web/validator/SyncedRepositoryValidator.java b/archiva-webapp/src/main/java/org/apache/maven/archiva/web/validator/SyncedRepositoryValidator.java new file mode 100644 index 000000000..42977bd08 --- /dev/null +++ b/archiva-webapp/src/main/java/org/apache/maven/archiva/web/validator/SyncedRepositoryValidator.java @@ -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 Maria Odea Ching + */ +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; + } + } + +} diff --git a/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/ConfigureProxiedRepositoryAction-validation.xml b/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/ConfigureProxiedRepositoryAction-validation.xml index 8eb090096..f72ec85c8 100644 --- a/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/ConfigureProxiedRepositoryAction-validation.xml +++ b/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/ConfigureProxiedRepositoryAction-validation.xml @@ -24,17 +24,69 @@ You must enter the repository identifier. + You must enter the repository name. + + You must enter the repository URL. + + + + The value must be numeric + + + + + + The value must be numeric + + + + + + + + + + + Repository type is required. + + + layout in {"legacy", "default"} + Invalid repository type. + + + + + snapshotsPolicy in { "disabled", "daily", "hourly", "never", "interval" } + Invalid snapshot policy. + + + + + releasesPolicy in { "disabled", "daily", "hourly", "never", "interval" } + Invalid releases policy. + + + + + + A managed repository must be selected. + + + diff --git a/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/ConfigureRepositoryAction-validation.xml b/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/ConfigureRepositoryAction-validation.xml index 4028336ca..8de49142b 100644 --- a/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/ConfigureRepositoryAction-validation.xml +++ b/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/ConfigureRepositoryAction-validation.xml @@ -30,10 +30,16 @@ You must enter the repository name. + You must enter the repository directory. - + + + layout in {"legacy", "default"} + Invalid repository type. + + \ No newline at end of file diff --git a/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/ConfigureSyncedRepositoryAction-addSelectedSyncedRepository-validation.xml b/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/ConfigureSyncedRepositoryAction-addSelectedSyncedRepository-validation.xml index b3697df8d..10ff70b01 100644 --- a/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/ConfigureSyncedRepositoryAction-addSelectedSyncedRepository-validation.xml +++ b/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/ConfigureSyncedRepositoryAction-addSelectedSyncedRepository-validation.xml @@ -29,6 +29,25 @@ You must enter the repository name. + + + Select repository type. + + + layout in {"legacy", "default"} + Invalid repository type. + + + + + A managed repository must be selected. + + + + + + + diff --git a/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/ConfigureSyncedRepositoryAction-validation.xml b/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/ConfigureSyncedRepositoryAction-validation.xml index 214eadcc2..43ea651aa 100644 --- a/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/ConfigureSyncedRepositoryAction-validation.xml +++ b/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/ConfigureSyncedRepositoryAction-validation.xml @@ -24,5 +24,9 @@ You must enter the synchronization method. + + method in { "rsync", "cvs", "svn", "file" } + Invalid method. + \ No newline at end of file diff --git a/archiva-webapp/src/main/resources/validators.xml b/archiva-webapp/src/main/resources/validators.xml new file mode 100644 index 000000000..758717b03 --- /dev/null +++ b/archiva-webapp/src/main/resources/validators.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addProxiedRepository.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addProxiedRepository.jsp index 801b8464e..a22e74488 100644 --- a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addProxiedRepository.jsp +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addProxiedRepository.jsp @@ -30,6 +30,8 @@

Add Proxied Repository

+ <%@ include file="errorMessages.jsp" %> + @@ -45,4 +47,4 @@ - \ No newline at end of file + diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addRepository.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addRepository.jsp index 8a2f06a10..2ebef043e 100644 --- a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addRepository.jsp +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addRepository.jsp @@ -32,7 +32,7 @@ - + <%@ include file="/WEB-INF/jsp/admin/include/managedRepositoryForm.jspf" %> @@ -45,4 +45,4 @@ - \ No newline at end of file + diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addSyncedRepository.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addSyncedRepository.jsp index bd01492a3..902a4e84e 100644 --- a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addSyncedRepository.jsp +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addSyncedRepository.jsp @@ -31,9 +31,11 @@

Add Synced Repository

+ <%@ include file="errorMessages.jsp" %> + - + <%@ include file="/WEB-INF/jsp/admin/include/syncedRepositoryForm.jspf" %> @@ -46,4 +48,4 @@ - \ No newline at end of file + 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 2271c6d4f..550c9b523 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,7 +29,7 @@
- + @@ -47,4 +47,4 @@
- \ No newline at end of file + diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editProxiedRepository.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editProxiedRepository.jsp index b22891c3b..f4c99f1ae 100644 --- a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editProxiedRepository.jsp +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editProxiedRepository.jsp @@ -30,6 +30,8 @@

Edit Proxied Repository

+ <%@ include file="errorMessages.jsp" %> + @@ -44,4 +46,4 @@ - \ No newline at end of file + diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editSyncedRepository.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editSyncedRepository.jsp index 905593214..52de6da90 100644 --- a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editSyncedRepository.jsp +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editSyncedRepository.jsp @@ -31,6 +31,8 @@

Edit Synced Repository

+ <%@ include file="errorMessages.jsp" %> + @@ -46,4 +48,4 @@ - \ No newline at end of file + diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/errorMessages.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/errorMessages.jsp new file mode 100644 index 000000000..9184a4ebd --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/errorMessages.jsp @@ -0,0 +1,8 @@ +

+ + Errors: + +

  • + + +

    \ No newline at end of file diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/managedRepositoryForm.jspf b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/managedRepositoryForm.jspf index 2dcbce3be..3bcf34061 100644 --- a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/managedRepositoryForm.jspf +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/managedRepositoryForm.jspf @@ -16,8 +16,8 @@ <%@ taglib prefix="ww" uri="/webwork" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> - - + + diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/proxiedRepositoryForm.jspf b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/proxiedRepositoryForm.jspf index 4b46713e8..fd6f93043 100644 --- a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/proxiedRepositoryForm.jspf +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/proxiedRepositoryForm.jspf @@ -15,8 +15,8 @@ --%> <%@ taglib prefix="ww" uri="/webwork" %> - - + +