1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.pluto.portlet.admin.taglib;
17
18 import java.io.IOException;
19 import java.util.Iterator;
20 import java.util.List;
21 import java.util.Map;
22 import java.util.Set;
23
24 import javax.portlet.PortletRequest;
25 import javax.portlet.PortletSession;
26 import javax.servlet.jsp.JspException;
27 import javax.servlet.jsp.JspTagException;
28 import javax.servlet.jsp.JspWriter;
29 import javax.servlet.jsp.tagext.TagSupport;
30
31 import org.apache.pluto.Constants;
32 import org.apache.pluto.portlet.admin.PlutoAdminConstants;
33 import org.apache.pluto.portlet.admin.bean.PortletTO;
34
35 /***
36 * Taglib that creates an HTML select control containing portlet
37 * names and values as defined in the <code>PortletTO</code>
38 * class.
39 *
40 * @author Craig Doremus
41 * @see org.apache.pluto.portlet.admin.bean.PortletTO
42 *
43 */
44 public class PortletSelectTag extends TagSupport {
45
46 private Map portletMap;
47 private int row = 1;
48 private int column = 1;
49
50 public int doStartTag() throws JspException {
51 PortletRequest request = (PortletRequest)pageContext.getRequest().getAttribute(Constants.PORTLET_REQUEST);
52 PortletSession session = request.getPortletSession();
53 List portlets = (List)session.getAttribute(PlutoAdminConstants.PORTLET_APP_LIST_ATTR);
54
55 if (portletMap != null ) {
56 try {
57 JspWriter out = pageContext.getOut();
58 out.println("<select name=\"portlet" + row + "." + column + "\">");
59 Set vals = portletMap.entrySet();
60 Iterator iter = vals.iterator();
61 while (iter.hasNext()) {
62 Map.Entry item = (Map.Entry) iter.next();
63 String name = (String)item.getKey();
64 String val = (String)item.getValue();
65 out.print("<option value=\"" + name + "_" + val + "\"");
66
67 if (portlets != null) {
68 Iterator iter2 = portlets.iterator();
69 while(iter.hasNext()) {
70 PortletTO plet = (PortletTO)iter2.next();
71 int currrow = plet.getRow();
72 int currcol = plet.getCol();
73 if (row == currrow && column == currcol) {
74 out.print(" checked ");
75 break;
76 }
77 }
78 }
79 out.print(">");
80 out.print(name);
81 out.print("</option>");
82 }
83 out.println("</select>");
84 } catch (IOException e) {
85 throw new JspTagException("Error: " + e.toString());
86 }
87 }
88 return SKIP_BODY;
89 }
90
91 /***
92 * @param portletMap The portletMap to set.
93 */
94 public void setPortletMap(Map portletMap) {
95 this.portletMap = portletMap;
96 }
97 /***
98 * @param column The column to set.
99 */
100 public void setColumn(int column) {
101 this.column = column;
102 }
103 /***
104 * @param row The row to set.
105 */
106 public void setRow(int row) {
107 this.row = row;
108 }
109 }