1 package org.apache.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.xwork2.validator.ValidationException;
23 import com.opensymphony.xwork2.validator.ValidatorContext;
24 import com.opensymphony.xwork2.validator.validators.ValidatorSupport;
27 * Validator for synced repository form. The values to be validated depends on the
28 * selected sync method to be used.
31 public class SyncedRepositoryValidator
32 extends ValidatorSupport
35 public void validate( Object obj )
36 throws ValidationException
39 String method = (String) getFieldValue( "method", obj );
40 ValidatorContext ctxt = getValidatorContext();
42 if ( method.equals( "rsync" ) )
44 String rsyncHost = (String) getFieldValue( "rsyncHost", obj );
45 if ( rsyncHost == null || rsyncHost.equals( "" ) )
47 ctxt.addActionError( "Rsync host is required." );
50 String rsyncDirectory = (String) getFieldValue( "rsyncDirectory", obj );
51 if ( rsyncDirectory == null || rsyncDirectory.equals( "" ) )
53 ctxt.addActionError( "Rsync directory is required." );
56 String rsyncMethod = (String) getFieldValue( "rsyncMethod", obj );
57 if ( rsyncMethod == null || rsyncMethod.equals( "" ) )
59 ctxt.addActionError( "Rsync method is required." );
63 if ( !rsyncMethod.equals( "anonymous" ) && !rsyncMethod.equals( "ssh" ) )
65 ctxt.addActionError( "Invalid rsync method" );
69 String username = (String) getFieldValue( "username", obj );
70 if ( username == null || username.equals( "" ) )
72 ctxt.addActionError( "Username is required." );
76 else if ( method.equals( "svn" ) )
78 String svnUrl = (String) getFieldValue( "svnUrl", obj );
79 if ( svnUrl == null || svnUrl.equals( "" ) )
81 ctxt.addActionError( "SVN url is required." );
84 String username = (String) getFieldValue( "username", obj );
85 if ( username == null || username.equals( "" ) )
87 ctxt.addActionError( "Username is required." );
90 else if ( method.equals( "cvs" ) )
92 String cvsRoot = (String) getFieldValue( "cvsRoot", obj );
93 if ( cvsRoot == null || cvsRoot.equals( "" ) )
95 ctxt.addActionError( "CVS root is required." );
98 else if ( method.equals( "file" ) )
100 String directory = (String) getFieldValue( "directory", obj );
101 if ( directory == null || directory.equals( "" ) )
103 ctxt.addActionError( "Directory is required." );
107 if ( ctxt.hasActionErrors() )