1 package org.apache.maven.repository.manager.web.action.admin;
4 * Copyright 2005-2006 The Apache Software Foundation.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import com.opensymphony.xwork.ActionSupport;
20 import com.opensymphony.xwork.ModelDriven;
21 import com.opensymphony.xwork.Preparable;
22 import org.apache.maven.repository.configuration.AbstractRepositoryConfiguration;
23 import org.apache.maven.repository.configuration.Configuration;
24 import org.apache.maven.repository.configuration.ConfigurationChangeException;
25 import org.apache.maven.repository.configuration.ConfigurationStore;
26 import org.apache.maven.repository.configuration.ConfigurationStoreException;
27 import org.apache.maven.repository.configuration.InvalidConfigurationException;
29 import java.io.IOException;
32 * Base action for repository configuration actions.
34 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
36 public abstract class AbstractConfigureRepositoryAction
38 implements ModelDriven, Preparable
43 private ConfigurationStore configurationStore;
48 private AbstractRepositoryConfiguration repository;
51 * The repository ID to lookup when editing a repository.
53 private String repoId;
56 * The previously read configuration.
58 protected Configuration configuration;
61 throws IOException, ConfigurationStoreException, InvalidConfigurationException, ConfigurationChangeException
63 // TODO: if this didn't come from the form, go to configure.action instead of going through with re-saving what was just loaded
65 AbstractRepositoryConfiguration existingRepository = getRepository( repository.getId() );
66 if ( existingRepository != null )
68 addFieldError( "id", "A repository with that id already exists" );
72 return saveConfiguration();
76 throws IOException, ConfigurationStoreException, InvalidConfigurationException, ConfigurationChangeException
78 // TODO: if this didn't come from the form, go to configure.action instead of going through with re-saving what was just loaded
80 AbstractRepositoryConfiguration existingRepository = getRepository( repository.getId() );
81 removeRepository( existingRepository );
83 return saveConfiguration();
86 protected abstract void removeRepository( AbstractRepositoryConfiguration existingRepository );
88 protected abstract AbstractRepositoryConfiguration getRepository( String id );
90 private String saveConfiguration()
91 throws IOException, ConfigurationStoreException, InvalidConfigurationException, ConfigurationChangeException
95 configurationStore.storeConfiguration( configuration );
97 // TODO: do we need to check if indexing is needed?
99 addActionMessage( "Successfully saved configuration" );
104 protected abstract void addRepository()
107 public String input()
112 public Object getModel()
117 protected abstract AbstractRepositoryConfiguration createRepository();
119 public void prepare()
120 throws ConfigurationStoreException
122 configuration = configurationStore.getConfigurationFromStore();
124 if ( repository == null )
126 repository = getRepository( repoId );
128 if ( repository == null )
130 repository = createRepository();
134 public String getRepoId()
139 public void setRepoId( String repoId )
141 this.repoId = repoId;
144 protected AbstractRepositoryConfiguration getRepository()
149 public Configuration getConfiguration()
151 return configuration;