1 package org.apache.maven.archiva.web.validator;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import com.opensymphony.xwork.validator.ValidationException;
23 import com.opensymphony.xwork.validator.ValidatorContext;
24 import com.opensymphony.xwork.validator.validators.ValidatorSupport;
27 * Validator for synced repository form. The values to be validated depends on the
28 * selected sync method to be used.
30 * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
32 public class SyncedRepositoryValidator
33 extends ValidatorSupport
36 public void validate( Object obj )
37 throws ValidationException
40 String method = (String) getFieldValue( "method", obj );
41 ValidatorContext ctxt = getValidatorContext();
43 if ( method.equals( "rsync" ) )
45 String rsyncHost = (String) getFieldValue( "rsyncHost", obj );
46 if ( rsyncHost == null || rsyncHost.equals( "" ) )
48 ctxt.addActionError( "Rsync host is required." );
51 String rsyncDirectory = (String) getFieldValue( "rsyncDirectory", obj );
52 if ( rsyncDirectory == null || rsyncDirectory.equals( "" ) )
54 ctxt.addActionError( "Rsync directory is required." );
57 String rsyncMethod = (String) getFieldValue( "rsyncMethod", obj );
58 if ( rsyncMethod == null || rsyncMethod.equals( "" ) )
60 ctxt.addActionError( "Rsync method is required." );
64 if ( !rsyncMethod.equals( "anonymous" ) && !rsyncMethod.equals( "ssh" ) )
66 ctxt.addActionError( "Invalid rsync method" );
70 String username = (String) getFieldValue( "username", obj );
71 if ( username == null || username.equals( "" ) )
73 ctxt.addActionError( "Username is required." );
77 else if ( method.equals( "svn" ) )
79 String svnUrl = (String) getFieldValue( "svnUrl", obj );
80 if ( svnUrl == null || svnUrl.equals( "" ) )
82 ctxt.addActionError( "SVN url is required." );
85 String username = (String) getFieldValue( "username", obj );
86 if ( username == null || username.equals( "" ) )
88 ctxt.addActionError( "Username is required." );
91 else if ( method.equals( "cvs" ) )
93 String cvsRoot = (String) getFieldValue( "cvsRoot", obj );
94 if ( cvsRoot == null || cvsRoot.equals( "" ) )
96 ctxt.addActionError( "CVS root is required." );
99 else if ( method.equals( "file" ) )
101 String directory = (String) getFieldValue( "directory", obj );
102 if ( directory == null || directory.equals( "" ) )
104 ctxt.addActionError( "Directory is required." );
108 if ( ctxt.hasActionErrors() )