1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.portlets.rpad.portlet.web.deployer;
18
19 import java.util.Iterator;
20 import java.util.List;
21 import java.util.Map;
22
23 import javax.faces.application.FacesMessage;
24 import javax.faces.context.FacesContext;
25 import javax.faces.model.SelectItem;
26
27 import org.apache.jetspeed.portlets.rpad.PortletApplication;
28 import org.apache.jetspeed.portlets.rpad.Repository;
29 import org.apache.jetspeed.portlets.rpad.RepositoryManager;
30 import org.apache.jetspeed.portlets.rpad.portlet.deployer.PortletDeployer;
31 import org.apache.jetspeed.portlets.rpad.portlet.util.FacesMessageUtil;
32
33 public class DisplayPortletsPage
34 {
35
36 protected static final String SEARCH = "org.apache.jetspeed.portlets.rpad.portlet.web.deployer.Search";
37
38 protected static final String REPOSITORY_NAME = "org.apache.jetspeed.portlets.rpad.portlet.web.deployer.RepositoryNamee";
39
40 private String repositoryName = null;
41
42 private String search = null;
43
44 private RepositoryManager repositoryManager = null;
45
46 private PortletDeployer portletDeployer;
47
48 public DisplayPortletsPage()
49 {
50 Map sessionMap = FacesContext.getCurrentInstance().getExternalContext()
51 .getSessionMap();
52
53 String repositoryName = (String) sessionMap.get(REPOSITORY_NAME);
54 if (repositoryName != null)
55 {
56 this.repositoryName = repositoryName;
57 }
58
59 String search = (String) sessionMap.get(SEARCH);
60 if (search != null)
61 {
62 this.search = search;
63 }
64 }
65
66 public RepositoryManager getRepositoryManager()
67 {
68 if (repositoryManager == null)
69 {
70 repositoryManager = RepositoryManager.getInstance();
71 }
72 return repositoryManager;
73 }
74
75 public String doSearch()
76 {
77 Map sessionMap = FacesContext.getCurrentInstance().getExternalContext()
78 .getSessionMap();
79
80 if (getRepositoryName() != null && !getRepositoryName().equals(""))
81 {
82 sessionMap.put(REPOSITORY_NAME, getRepositoryName());
83 }
84 else
85 {
86 sessionMap.remove(REPOSITORY_NAME);
87 }
88
89 if (getSearch() != null && !getSearch().equals(""))
90 {
91 sessionMap.put(SEARCH, getSearch());
92 }
93 else
94 {
95 sessionMap.remove(SEARCH);
96 }
97
98 return null;
99 }
100
101 public String jumpUpdateRepository()
102 {
103 return "deployer_displayRepositories";
104 }
105
106 public String doRefresh()
107 {
108 return null;
109 }
110
111 public String doDeploy()
112 {
113 PortletApplication portlet = (PortletApplication) FacesContext
114 .getCurrentInstance().getExternalContext().getRequestMap().get(
115 "portlet");
116 if (portlet != null)
117 {
118 if (getPortletDeployer() != null)
119 {
120 getPortletDeployer().deploy(portlet);
121 }
122 else
123 {
124
125 FacesMessageUtil.addMessage(FacesMessage.SEVERITY_ERROR,
126 "Could not find the portlet deployer.", null);
127 }
128 }
129 else
130 {
131
132 FacesMessageUtil.addMessage(FacesMessage.SEVERITY_ERROR,
133 "Could not find the target portlet.", null);
134 }
135
136 return null;
137 }
138
139 public SelectItem[] getRepositoryNames()
140 {
141 List repos = getRepositoryManager().getRepositories();
142 SelectItem[] items = new SelectItem[repos.size() + 1];
143 items[0] = new SelectItem("");
144 int c = 1;
145 for (Iterator i = repos.iterator(); i.hasNext(); c++)
146 {
147 Repository repo = (Repository) i.next();
148 items[c] = new SelectItem(repo.getName());
149 }
150 return items;
151 }
152
153 public List getPortlets()
154 {
155
156 if (repositoryName != null)
157 {
158 return getRepositoryManager()
159 .getPortletApplications(repositoryName);
160 }
161 else
162 {
163 return getRepositoryManager().getPortletApplications();
164 }
165 }
166
167 public int getPageSize()
168 {
169
170 return 10;
171 }
172
173 /***
174 * @return the repositoryName
175 */
176 public String getRepositoryName()
177 {
178 return repositoryName;
179 }
180
181 /***
182 * @param repositoryName the repositoryName to set
183 */
184 public void setRepositoryName(String repositoryName)
185 {
186 this.repositoryName = repositoryName;
187 }
188
189 /***
190 * @return the search
191 */
192 public String getSearch()
193 {
194 return search;
195 }
196
197 /***
198 * @param search the search to set
199 */
200 public void setSearch(String search)
201 {
202 this.search = search;
203 }
204
205 /***
206 * @return the portletDeployer
207 */
208 public PortletDeployer getPortletDeployer()
209 {
210 return portletDeployer;
211 }
212
213 /***
214 * @param portletDeployer the portletDeployer to set
215 */
216 public void setPortletDeployer(PortletDeployer portletDeployer)
217 {
218 this.portletDeployer = portletDeployer;
219 }
220
221 public boolean isDeployable()
222 {
223 return portletDeployer.getStatus() == PortletDeployer.READY;
224 }
225
226 }