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.List;
20  
21  import javax.faces.context.FacesContext;
22  
23  import org.apache.commons.logging.Log;
24  import org.apache.commons.logging.LogFactory;
25  import org.apache.jetspeed.portlets.rpad.RPADConstants;
26  import org.apache.jetspeed.portlets.rpad.RPADException;
27  import org.apache.jetspeed.portlets.rpad.Repository;
28  import org.apache.jetspeed.portlets.rpad.RepositoryManager;
29  import org.apache.jetspeed.portlets.rpad.portlet.util.FacesMessageUtil;
30  
31  public class DisplayRepositoriesPage
32  {
33      /***
34       * Logger for this class
35       */
36      private static final Log log = LogFactory
37              .getLog(DisplayRepositoriesPage.class);
38  
39      private RepositoryManager repositoryManager = null;
40  
41      public RepositoryManager getRepositoryManager()
42      {
43          if (repositoryManager == null)
44          {
45              repositoryManager = RepositoryManager.getInstance();
46          }
47          return repositoryManager;
48      }
49  
50      public String jumpDisplayPortlets()
51      {
52          return "deployer_displayPortlets";
53      }
54  
55      public String doReloadRepositories()
56      {
57          try
58          {
59              getRepositoryManager().reload();
60              FacesMessageUtil.addInfoMessage("Reload repositories.");
61          }
62          catch (Exception e)
63          {
64              //TODO i18n
65              FacesMessageUtil.addErrorMessage("Could not reload repositories.");
66              log.error("Could not reload repositories.", e);
67          }
68          return null;
69      }
70  
71      public String doAddRepository()
72      {
73          FacesContext.getCurrentInstance().getExternalContext().getSessionMap()
74                  .remove(RPADConstants.REPOSITORY);
75          return "deployer_editRepository";
76      }
77  
78      public String doEditRepository()
79      {
80          Repository repo = (Repository) FacesContext.getCurrentInstance()
81                  .getExternalContext().getRequestMap().get("repository");
82          if (repo != null)
83          {
84              FacesContext.getCurrentInstance().getExternalContext()
85                      .getSessionMap().put(RPADConstants.REPOSITORY, repo);
86              return "deployer_editRepository";
87          }
88          else
89          {
90              //TODO i18n
91              FacesMessageUtil
92                      .addWarnMessage("Could not find the target repository.");
93          }
94          return null;
95      }
96  
97      public String doDeleteRepository()
98      {
99          Repository repo = (Repository) FacesContext.getCurrentInstance()
100                 .getExternalContext().getRequestMap().get("repository");
101         if (repo != null)
102         {
103             try
104             {
105                 getRepositoryManager().removeRepository(repo.getName());
106                 //TODO i18n
107                 FacesMessageUtil
108                         .addInfoMessage("Removed the target repository.");
109             }
110             catch (RPADException e)
111             {
112                 //TODO i18n
113                 FacesMessageUtil
114                         .addErrorMessage("Could not remove the target repository.");
115             }
116         }
117         else
118         {
119             //TODO i18n
120             FacesMessageUtil
121                     .addWarnMessage("Could not find the target repository.");
122         }
123         return null;
124     }
125 
126     public List getRepositories()
127     {
128         return getRepositoryManager().getRepositories();
129     }
130 
131     public int getPageSize()
132     {
133         //TODO move to portlet.xml or somewhere..
134         return 10;
135     }
136 
137 }