You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SyncedRepositoryValidator.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package org.apache.maven.archiva.web.validator;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import com.opensymphony.xwork2.validator.ValidationException;
  21. import com.opensymphony.xwork2.validator.ValidatorContext;
  22. import com.opensymphony.xwork2.validator.validators.ValidatorSupport;
  23. /**
  24. * Validator for synced repository form. The values to be validated depends on the
  25. * selected sync method to be used.
  26. *
  27. * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
  28. */
  29. public class SyncedRepositoryValidator
  30. extends ValidatorSupport
  31. {
  32. public void validate( Object obj )
  33. throws ValidationException
  34. {
  35. String method = (String) getFieldValue( "method", obj );
  36. ValidatorContext ctxt = getValidatorContext();
  37. if ( method.equals( "rsync" ) )
  38. {
  39. String rsyncHost = (String) getFieldValue( "rsyncHost", obj );
  40. if ( rsyncHost == null || rsyncHost.equals( "" ) )
  41. {
  42. ctxt.addActionError( "Rsync host is required." );
  43. }
  44. String rsyncDirectory = (String) getFieldValue( "rsyncDirectory", obj );
  45. if ( rsyncDirectory == null || rsyncDirectory.equals( "" ) )
  46. {
  47. ctxt.addActionError( "Rsync directory is required." );
  48. }
  49. String rsyncMethod = (String) getFieldValue( "rsyncMethod", obj );
  50. if ( rsyncMethod == null || rsyncMethod.equals( "" ) )
  51. {
  52. ctxt.addActionError( "Rsync method is required." );
  53. }
  54. else
  55. {
  56. if ( !rsyncMethod.equals( "anonymous" ) && !rsyncMethod.equals( "ssh" ) )
  57. {
  58. ctxt.addActionError( "Invalid rsync method" );
  59. }
  60. }
  61. String username = (String) getFieldValue( "username", obj );
  62. if ( username == null || username.equals( "" ) )
  63. {
  64. ctxt.addActionError( "Username is required." );
  65. }
  66. }
  67. else if ( method.equals( "svn" ) )
  68. {
  69. String svnUrl = (String) getFieldValue( "svnUrl", obj );
  70. if ( svnUrl == null || svnUrl.equals( "" ) )
  71. {
  72. ctxt.addActionError( "SVN url is required." );
  73. }
  74. String username = (String) getFieldValue( "username", obj );
  75. if ( username == null || username.equals( "" ) )
  76. {
  77. ctxt.addActionError( "Username is required." );
  78. }
  79. }
  80. else if ( method.equals( "cvs" ) )
  81. {
  82. String cvsRoot = (String) getFieldValue( "cvsRoot", obj );
  83. if ( cvsRoot == null || cvsRoot.equals( "" ) )
  84. {
  85. ctxt.addActionError( "CVS root is required." );
  86. }
  87. }
  88. else if ( method.equals( "file" ) )
  89. {
  90. String directory = (String) getFieldValue( "directory", obj );
  91. if ( directory == null || directory.equals( "" ) )
  92. {
  93. ctxt.addActionError( "Directory is required." );
  94. }
  95. }
  96. if ( ctxt.hasActionErrors() )
  97. {
  98. return;
  99. }
  100. }
  101. }