KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > portletregistery > renderer > html > PortletRoleRenderer


1 /**
2  * Copyright 2001-2003 The eXo platform SARL All rights reserved.
3  * Please look at license.txt in info directory for more license detail.
4  */

5 package org.exoplatform.portlets.portletregistery.renderer.html;
6
7
8 import javax.faces.component.UIComponent;
9 import javax.faces.context.FacesContext;
10 import javax.faces.context.ResponseWriter;
11 import org.exoplatform.faces.FacesConstants;
12 import org.exoplatform.faces.core.renderer.html.HtmlBasicRenderer;
13 import org.exoplatform.portlets.portletregistery.component.UIPortletRole;
14 import java.io.IOException JavaDoc;
15 import java.util.Collection JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.ResourceBundle JavaDoc;
18
19 /**
20  * Created y the eXo platform team
21  * User: Benjamin Mestrallet
22  * Date: 19 juin 2004
23  */

24 public class PortletRoleRenderer extends HtmlBasicRenderer{
25
26   final public static String JavaDoc ADD_ROLE_ICON = "<img class='add-role-icon' SRC='/skin/blank.gif'/>";
27   final public static String JavaDoc REMOVE_ROLE_ICON = "<img class='remove-role-icon' SRC='/skin/blank.gif'/>";
28
29   private static String JavaDoc SCRIPT =
30     "<script>\n" +
31       "function submitAddPortletRoleForm(action) {\n" +
32       " document.portletRoleForm.elements['"+FacesConstants.ACTION +"'].value = action ;\n" +
33       " document.portletRoleForm.submit();\n" +
34       "}\n" +
35     "</script>\n" ;
36
37   public void encodeChildren( FacesContext context, UIComponent component ) throws IOException JavaDoc {
38     UIPortletRole uiPortletRole = (UIPortletRole) component ;
39     ResourceBundle JavaDoc res = getApplicationResourceBundle(context.getExternalContext()) ;
40     ResponseWriter w = context.getResponseWriter() ;
41     String JavaDoc baseURL = uiPortletRole.getBaseURL(context);
42     Collection JavaDoc availableRoles = uiPortletRole.getAvailableRoles() ;
43     Collection JavaDoc currentRoles = uiPortletRole.getCurrentRoles();
44     w.write("<center>") ;
45     w. write("<form name='portletRoleForm' action='"+baseURL+"' method='post'>") ;
46     w. write("<input type='hidden' name='"+ FacesConstants.ACTION +"' value=''/>");
47     w. write("<table class='UIPortletRole'>");
48     w. write("<tr>");
49     w. write("<th colspan='3'>");
50     w. write(res.getString("UIPortletRole.header.title")) ;
51     w. write("</th>");
52     w. write("</tr>");
53     w. write("<tr>");
54     w. write("<td>");
55     w. write(res.getString("UIPortletRole.label.available-roles")) ;
56     w. write("</td>");
57     w. write("<td>");
58     w. write("&nbsp;&nbsp;") ;
59     w. write("</td>");
60     w. write("<td>");
61     w. write(res.getString("UIPortletRole.label.current-roles")) ;
62     w. write("</td>");
63     w. write("</tr>");
64     w. write("<tr>") ;
65     w. write("<td>") ;
66     w. write("<select multiple size='5' name='" + UIPortletRole.AVAILABLE_ROLE_SELECT + "'>") ;
67     if(availableRoles != null){
68       for (Iterator JavaDoc iterator = availableRoles.iterator(); iterator.hasNext();) {
69         String JavaDoc availableRole = (String JavaDoc) iterator.next();
70         w. write("<option>" + availableRole + "</option>");
71       }
72     }
73     w. write("</select>") ;
74     w. write("</td>");
75     w. write("<td class='arrows'>") ;
76     w. write("<div>");
77     w. write("<a HREF=\"javascript:submitAddPortletRoleForm('"+ UIPortletRole.ADD_ROLE +"');\">");
78     w. write(ADD_ROLE_ICON);
79     w. write("</a> ");
80     w. write("</div>");
81     w. write("<div>");
82     w. write("<a HREF=\"javascript:submitAddPortletRoleForm('"+UIPortletRole.REMOVE_ROLE +"');\">");
83     w. write(REMOVE_ROLE_ICON);
84     w. write("</a> ");
85     w. write("</div>");
86     w. write("</td>") ;
87     w. write("<td>") ;
88     w. write("<select multiple size='5' name='" + UIPortletRole.CURRENT_ROLE_SELECT + "'>") ;
89     if(currentRoles != null){
90       for (Iterator JavaDoc iterator = currentRoles.iterator(); iterator.hasNext();) {
91         String JavaDoc currentRole = (String JavaDoc) iterator.next();
92         w. write("<option>" + currentRole + "</option>");
93       }
94     }
95     w. write("</select>") ;
96     w. write("</td>");
97     w. write("</tr>");
98     w. write("<tr>");
99     w. write("<td align='center' colspan='3'>") ;
100     w. write("<a HREF=\"javascript:submitAddPortletRoleForm('"+SAVE_ACTION +"');\">");
101     w. write(res.getString("UIPortletRole.button.save"));
102     w. write("</a> ");
103     w. write("<a HREF=\"javascript:submitAddPortletRoleForm('"+CANCEL_ACTION +"');\">");
104     w. write(res.getString("UIPortletRole.button.cancel"));
105     w. write("</a>");
106     w. write("</td>") ;
107     w. write("</tr>");
108     w. write("</table>");
109     w. write(SCRIPT);
110     w. write("</form>");
111     w.write("</center>");
112   }
113 }
114
Popular Tags