View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.jetspeed.portlets.rpad.portlet.web.deployer;
18  
19  import java.util.Map;
20  
21  import javax.faces.context.FacesContext;
22  
23  import org.apache.jetspeed.portlets.rpad.RPADConstants;
24  import org.apache.jetspeed.portlets.rpad.RPADException;
25  import org.apache.jetspeed.portlets.rpad.Repository;
26  import org.apache.jetspeed.portlets.rpad.RepositoryManager;
27  import org.apache.jetspeed.portlets.rpad.portlet.util.FacesMessageUtil;
28  import org.apache.jetspeed.portlets.rpad.simple.SimpleRepository;
29  
30  public class EditRepositoryPage
31  {
32  
33      private RepositoryManager repositoryManager = null;
34  
35      private boolean newRepository;
36  
37      private String name;
38  
39      private String path;
40  
41      public EditRepositoryPage()
42      {
43          Map sessionMap = FacesContext.getCurrentInstance().getExternalContext()
44                  .getSessionMap();
45          Repository repo = (Repository) sessionMap.get(RPADConstants.REPOSITORY);
46          if (repo != null)
47          {
48              //TODO support repositories other than SimpleRepository
49              if (repo instanceof SimpleRepository)
50              {
51                  SimpleRepository simpleRepo = (SimpleRepository) repo;
52                  newRepository = false;
53                  setName(simpleRepo.getName());
54                  setPath(simpleRepo.getConfigPath());
55              }
56              else
57              {
58                  newRepository = true;
59                  sessionMap.remove(RPADConstants.REPOSITORY);
60              }
61          }
62          else
63          {
64              newRepository = true;
65          }
66      }
67  
68      public RepositoryManager getRepositoryManager()
69      {
70          if (repositoryManager == null)
71          {
72              repositoryManager = RepositoryManager.getInstance();
73          }
74          return repositoryManager;
75      }
76  
77      public String jumpDisplayRepositories()
78      {
79          return "deployer_displayRepositories";
80      }
81  
82      public String doCreateRepository()
83      {
84          if (getRepositoryManager().getRepository(getName()) == null)
85          {
86              //TODO support repositories other than SimpleRepository
87              SimpleRepository repo = new SimpleRepository();
88              repo.setName(getName());
89              repo.setConfigPath(getPath());
90              repo.init();
91  
92              try
93              {
94                  getRepositoryManager().addRepository(getName(), repo);
95                  getRepositoryManager().reload();
96                  //  TODO i18n
97                  FacesMessageUtil.addInfoMessage(getName() + " exits.");
98                  return "deployer_displayRepositories";
99              }
100             catch (RPADException e)
101             {
102                 //TODO i18n
103                 FacesMessageUtil.addErrorMessage("Could not add a repository: "
104                         + getName());
105             }
106         }
107         else
108         {
109             //TODO i18n
110             FacesMessageUtil.addWarnMessage(getName() + " exits.");
111         }
112 
113         return null;
114     }
115 
116     public String doUpdateRepository()
117     {
118         Map sessionMap = FacesContext.getCurrentInstance().getExternalContext()
119                 .getSessionMap();
120         Repository repo = (Repository) sessionMap.get(RPADConstants.REPOSITORY);
121         if (repo != null)
122         {
123             Repository r = getRepositoryManager().getRepository(
124                     repo.getName());
125 
126             //TODO support repositories other than SimpleRepository
127             if (r instanceof SimpleRepository)
128             {
129                 SimpleRepository simpleRepo = (SimpleRepository) r;
130                 simpleRepo.setName(getName());
131                 simpleRepo.setConfigPath(getPath());
132             }
133             else
134             {
135                 //TODO i18n
136                 FacesMessageUtil
137                         .addWarnMessage("Could not get the proper repository.");
138             }
139             try
140             {
141                 getRepositoryManager().store();
142                 getRepositoryManager().reload();
143                 //TODO i18n
144                 FacesMessageUtil
145                         .addWarnMessage("Could not get the proper repository.");
146                 return null;
147             }
148             catch (RPADException e)
149             {
150                 //TODO i18n
151                 FacesMessageUtil
152                         .addErrorMessage("Could not update the target repository.");
153             }
154 
155         }
156         else
157         {
158             //TODO i18n
159             FacesMessageUtil.addWarnMessage("Your session might be expired.");
160         }
161         return "deployer_displayRepositories";
162     }
163 
164     /***
165      * @return the name
166      */
167     public String getName()
168     {
169         return name;
170     }
171 
172     /***
173      * @param name the name to set
174      */
175     public void setName(String name)
176     {
177         this.name = name;
178     }
179 
180     /***
181      * @return the newRepository
182      */
183     public boolean isNewRepository()
184     {
185         return newRepository;
186     }
187 
188     /***
189      * @param newRepository the newRepository to set
190      */
191     public void setNewRepository(boolean newRepository)
192     {
193         this.newRepository = newRepository;
194     }
195 
196     /***
197      * @return the path
198      */
199     public String getPath()
200     {
201         return path;
202     }
203 
204     /***
205      * @param path the path to set
206      */
207     public void setPath(String path)
208     {
209         this.path = path;
210     }
211 }