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.

EditRemoteRepositoryAction.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package org.apache.maven.archiva.web.action.admin.repositories;
  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.Preparable;
  21. import org.apache.commons.lang.StringUtils;
  22. import org.apache.maven.archiva.configuration.Configuration;
  23. import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
  24. import org.codehaus.plexus.redback.role.RoleManagerException;
  25. import java.io.IOException;
  26. /**
  27. * EditRemoteRepositoryAction
  28. *
  29. * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
  30. * @version $Id$
  31. *
  32. * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="editRemoteRepositoryAction"
  33. */
  34. public class EditRemoteRepositoryAction
  35. extends AbstractRemoteRepositoriesAction
  36. implements Preparable
  37. {
  38. /**
  39. * The model for this action.
  40. */
  41. private RemoteRepositoryConfiguration repository;
  42. /**
  43. * The repository id to edit.
  44. */
  45. private String repoid;
  46. public void prepare()
  47. {
  48. String id = repoid;
  49. if ( StringUtils.isNotBlank( repoid ) )
  50. {
  51. this.repository = archivaConfiguration.getConfiguration().findRemoteRepositoryById( id );
  52. }
  53. }
  54. public String input()
  55. {
  56. if ( StringUtils.isBlank( repoid ) )
  57. {
  58. addActionError( "Edit failure, unable to edit a repository with a blank repository id." );
  59. return ERROR;
  60. }
  61. return INPUT;
  62. }
  63. public String commit()
  64. {
  65. Configuration configuration = archivaConfiguration.getConfiguration();
  66. // We are in edit mode, remove the old repository configuration.
  67. removeRepository( repository.getId(), configuration );
  68. // Save the repository configuration.
  69. String result;
  70. try
  71. {
  72. addRepository( repository, configuration );
  73. result = saveConfiguration( configuration );
  74. }
  75. catch ( IOException e )
  76. {
  77. addActionError( "I/O Exception: " + e.getMessage() );
  78. result = INPUT;
  79. }
  80. catch ( RoleManagerException e )
  81. {
  82. addActionError( "Role Manager Exception: " + e.getMessage() );
  83. result = INPUT;
  84. }
  85. return result;
  86. }
  87. public RemoteRepositoryConfiguration getRepository()
  88. {
  89. return repository;
  90. }
  91. public void setRepository( RemoteRepositoryConfiguration repository )
  92. {
  93. this.repository = repository;
  94. }
  95. public String getRepoid()
  96. {
  97. return repoid;
  98. }
  99. public void setRepoid( String repoid )
  100. {
  101. this.repoid = repoid;
  102. }
  103. }