1 package org.apache.archiva.web.action.admin.repositories;
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.Preparable;
23 import com.opensymphony.xwork2.Validateable;
24 import org.apache.archiva.admin.model.RepositoryAdminException;
25 import org.apache.archiva.admin.model.beans.ManagedRepository;
26 import org.apache.commons.lang.StringUtils;
27 import org.springframework.context.annotation.Scope;
28 import org.springframework.stereotype.Controller;
33 * AddManagedRepositoryAction
37 @Controller( "addManagedRepositoryAction" )
39 public class AddManagedRepositoryAction
40 extends AbstractManagedRepositoriesAction
41 implements Preparable, Validateable
44 private ManagedRepository repository;
46 private boolean stageNeeded;
48 private String action = "addRepository";
52 this.repository = new ManagedRepository();
53 this.repository.setReleases( false );
54 this.repository.setScanned( false );
55 this.repository.setBlockRedeployments( false );
60 this.repository.setReleases( true );
61 this.repository.setScanned( true );
62 this.repository.setBlockRedeployments( true );
67 public String confirmAdd()
72 public String commit()
74 repository.setLocation( getRepositoryCommonValidator().removeExpressions( repository.getLocation() ) );
76 File location = new File( repository.getLocation() );
77 if ( location.exists() )
87 String result = SUCCESS;
90 getManagedRepositoryAdmin().addManagedRepository( repository, stageNeeded, getAuditInformation() );
92 catch ( RepositoryAdminException e )
94 log.error( e.getMessage(), e );
95 addActionError( "Check your server logs, Repository Administration Exception: " + e.getMessage() );
103 public void validate()
105 // trim all unecessary trailing/leading white-spaces; always put this statement before the closing braces(after all validation).
106 trimAllRequestParameterValues();
109 private void trimAllRequestParameterValues()
111 if ( StringUtils.isNotEmpty( repository.getId() ) )
113 repository.setId( repository.getId().trim() );
116 if ( StringUtils.isNotEmpty( repository.getName() ) )
118 repository.setName( repository.getName().trim() );
121 if ( StringUtils.isNotEmpty( repository.getLocation() ) )
123 repository.setLocation( repository.getLocation().trim() );
126 if ( StringUtils.isNotEmpty( repository.getIndexDirectory() ) )
128 repository.setIndexDirectory( repository.getIndexDirectory().trim() );
132 public ManagedRepository getRepository()
137 public void setRepository( ManagedRepository repository )
139 this.repository = repository;
143 public void setStageNeeded( boolean stageNeeded )
145 this.stageNeeded = stageNeeded;
148 public String getAction()