KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > pluto > portlet > admin > taglib > PortletSelectTag


1 /*
2  * Copyright 2003,2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.pluto.portlet.admin.taglib;
17
18 import java.io.IOException JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.List JavaDoc;
21 import java.util.Map JavaDoc;
22 import java.util.Set JavaDoc;
23
24 import javax.portlet.PortletRequest;
25 import javax.portlet.PortletSession;
26 import javax.servlet.jsp.JspException JavaDoc;
27 import javax.servlet.jsp.JspTagException JavaDoc;
28 import javax.servlet.jsp.JspWriter JavaDoc;
29 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
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 JavaDoc {
45
46     private Map JavaDoc portletMap = null;
47     private int row = 1;
48     private int column = 1;
49
50     public int doStartTag() throws JspException JavaDoc {
51     PortletRequest request = (PortletRequest)pageContext.getRequest().getAttribute(Constants.PORTLET_REQUEST);
52     PortletSession session = request.getPortletSession();
53     List JavaDoc portlets = (List JavaDoc)session.getAttribute(PlutoAdminConstants.PORTLET_APP_LIST_ATTR);
54
55     if (portletMap != null ) {
56           try {
57             JspWriter JavaDoc out = pageContext.getOut();
58             out.println("<select name=\"portlet" + row + "." + column + "\">");
59             Set JavaDoc vals = portletMap.entrySet();
60             Iterator JavaDoc iter = vals.iterator();
61             while (iter.hasNext()) {
62                 Map.Entry JavaDoc item = (Map.Entry JavaDoc) iter.next();
63                 String JavaDoc name = (String JavaDoc)item.getKey();
64                 String JavaDoc val = (String JavaDoc)item.getValue();
65                 out.print("<option value=\"" + name + "_" + val + "\"");
66                 //find out what portlet should be the 'checked' one
67
if (portlets != null) {
68                     Iterator JavaDoc 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 JavaDoc e) {
85             throw new JspTagException JavaDoc("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 JavaDoc 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 }
110
Popular Tags