]> source.dussan.org Git - archiva.git/blob
31244c227bad53cf2742b11cf60ad0fc1b2f1866
[archiva.git] /
1 package org.apache.maven.repository.manager.web.action.admin;
2
3 /*
4  * Copyright 2005-2006 The Apache Software Foundation.
5  *
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
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
19 import org.apache.maven.repository.configuration.AbstractRepositoryConfiguration;
20 import org.apache.maven.repository.configuration.Configuration;
21 import org.apache.maven.repository.configuration.ConfigurationChangeException;
22 import org.apache.maven.repository.configuration.ConfigurationStore;
23 import org.apache.maven.repository.configuration.ConfigurationStoreException;
24 import org.apache.maven.repository.configuration.InvalidConfigurationException;
25 import org.apache.maven.repository.configuration.RepositoryConfiguration;
26 import org.codehaus.plexus.xwork.action.PlexusActionSupport;
27
28 import java.io.IOException;
29
30 /**
31  * Base action for repository removal actions.
32  *
33  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
34  */
35 public abstract class AbstractDeleteRepositoryAction
36     extends PlexusActionSupport
37 {
38     /**
39      * @plexus.requirement
40      */
41     private ConfigurationStore configurationStore;
42
43     /**
44      * The repository ID to lookup when editing a repository.
45      */
46     protected String repoId;
47
48     /**
49      * Which operation to select.
50      */
51     private String operation = "unmodified";
52
53     public String execute()
54         throws ConfigurationStoreException, IOException, InvalidConfigurationException, ConfigurationChangeException
55     {
56         // TODO: if this didn't come from the form, go to configure.action instead of going through with re-saving what was just loaded
57
58         if ( "delete-entry".equals( operation ) || "delete-contents".equals( operation ) )
59         {
60             Configuration configuration = configurationStore.getConfigurationFromStore();
61
62             AbstractRepositoryConfiguration existingRepository = getRepository( configuration );
63             if ( existingRepository == null )
64             {
65                 addActionError( "A repository with that id does not exist" );
66                 return ERROR;
67             }
68
69             // TODO: remove from index too!
70
71             removeRepository( configuration, existingRepository );
72
73             configurationStore.storeConfiguration( configuration );
74
75             if ( "delete-contents".equals( operation ) )
76             {
77                 removeContents( existingRepository );
78             }
79         }
80
81         return SUCCESS;
82     }
83
84     protected abstract void removeContents( AbstractRepositoryConfiguration existingRepository )
85         throws IOException;
86
87     protected abstract AbstractRepositoryConfiguration getRepository( Configuration configuration );
88
89     protected abstract void removeRepository( Configuration configuration,
90                                               AbstractRepositoryConfiguration existingRepository );
91
92     public String input()
93     {
94         return INPUT;
95     }
96
97     public String getRepoId()
98     {
99         return repoId;
100     }
101
102     public void setRepoId( String repoId )
103     {
104         this.repoId = repoId;
105     }
106
107     public String getOperation()
108     {
109         return operation;
110     }
111
112     public void setOperation( String operation )
113     {
114         this.operation = operation;
115     }
116 }