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.codehaus.redback.components.scheduler.CronExpressionValidator;
28 import org.springframework.context.annotation.Scope;
29 import org.springframework.stereotype.Controller;
34 * AddManagedRepositoryAction
38 @Controller( "addManagedRepositoryAction" )
40 public class AddManagedRepositoryAction
41 extends AbstractManagedRepositoriesAction
42 implements Preparable, Validateable
45 private ManagedRepository repository;
47 private boolean stageNeeded;
49 private String action = "addRepository";
53 this.repository = new ManagedRepository();
54 this.repository.setReleases( false );
55 this.repository.setScanned( false );
56 this.repository.setBlockRedeployments( false );
61 this.repository.setReleases( true );
62 this.repository.setScanned( true );
63 this.repository.setBlockRedeployments( true );
68 public String confirmAdd()
73 public String commit()
75 repository.setLocation( getRepositoryCommonValidator().removeExpressions( repository.getLocation() ) );
77 File location = new File( repository.getLocation() );
78 if ( location.exists() )
88 String result = SUCCESS;
91 getManagedRepositoryAdmin().addManagedRepository( repository, stageNeeded, getAuditInformation() );
93 catch ( RepositoryAdminException e )
95 log.error( e.getMessage(), e );
96 addActionError( "Check your server logs, Repository Administration Exception: " + e.getMessage() );
104 public void validate()
106 CronExpressionValidator validator = new CronExpressionValidator();
108 if ( !validator.validate( repository.getCronExpression() ) )
110 addFieldError( "repository.cronExpression", "Invalid cron expression." );
113 // trim all unecessary trailing/leading white-spaces; always put this statement before the closing braces(after all validation).
114 trimAllRequestParameterValues();
117 private void trimAllRequestParameterValues()
119 if ( StringUtils.isNotEmpty( repository.getId() ) )
121 repository.setId( repository.getId().trim() );
124 if ( StringUtils.isNotEmpty( repository.getName() ) )
126 repository.setName( repository.getName().trim() );
129 if ( StringUtils.isNotEmpty( repository.getLocation() ) )
131 repository.setLocation( repository.getLocation().trim() );
134 if ( StringUtils.isNotEmpty( repository.getIndexDirectory() ) )
136 repository.setIndexDirectory( repository.getIndexDirectory().trim() );
140 public ManagedRepository getRepository()
145 public void setRepository( ManagedRepository repository )
147 this.repository = repository;
151 public void setStageNeeded( boolean stageNeeded )
153 this.stageNeeded = stageNeeded;
156 public String getAction()