KickJava   Java API By Example, From Geeks To Geeks.

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


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
6 package org.exoplatform.portlets.portletregistery.renderer.html;
7
8
9 import javax.faces.component.UIComponent;
10 import javax.faces.context.FacesContext;
11 import javax.faces.context.ResponseWriter;
12 import org.exoplatform.faces.FacesConstants;
13 import org.exoplatform.faces.core.renderer.html.HtmlBasicRenderer;
14 import org.exoplatform.portlets.portletregistery.component.UIPortletList;
15 import org.exoplatform.services.portletcontainer.pci.PortletData;
16 import java.io.IOException JavaDoc;
17 import java.util.Iterator JavaDoc;
18 import java.util.Map JavaDoc;
19 import java.util.ResourceBundle JavaDoc;
20 import java.util.Set JavaDoc;
21
22 /**
23  * Created y the eXo platform team
24  * User: Benjamin Mestrallet
25  * Date: 18 juin 2004
26  */

27 public class AddPortletRenderer extends HtmlBasicRenderer {
28   private static String JavaDoc SCRIPT =
29     "<script>\n" +
30       "function submitAddPortletForm(action) {\n" +
31       " document.portletForm.elements['"+FacesConstants.ACTION +"'].value = action ;\n" +
32       " document.portletForm.submit();\n" +
33       "}\n" +
34     "</script>\n" ;
35
36   final public void encodeChildren(FacesContext context, UIComponent component ) throws IOException JavaDoc {
37     UIPortletList uiPortletList = (UIPortletList) component ;
38     ResourceBundle JavaDoc res = getApplicationResourceBundle(context.getExternalContext()) ;
39     ResponseWriter w = context.getResponseWriter() ;
40     String JavaDoc baseURL = uiPortletList.getBaseURL(context);
41     Map JavaDoc allPortletMetaData = uiPortletList.getAllPortletMetaData() ;
42     Set JavaDoc keys = allPortletMetaData.keySet();
43     w.write("<center>") ;
44     w. write("<form name='portletForm' action='"+baseURL+"' method='post'>") ;
45     w. write("<input type='hidden' name='"+ FacesConstants.ACTION +"' value=''/>");
46     w. write("<table cellspacing='1' cellpadding='3'>");
47     w. write("<tr>");
48     w. write("<th colspan='3'>");
49     w. write(res.getString("UIPortletList.header.title")) ;
50     w. write("</th>");
51     w. write("</tr>");
52     Iterator JavaDoc i = keys.iterator() ;
53     while(i.hasNext()) {
54       String JavaDoc key = (String JavaDoc) i.next() ;
55       PortletData portlet = (PortletData) allPortletMetaData.get(key) ;
56       String JavaDoc portletTitle = portlet.getPortletName() ;
57       String JavaDoc portletDescription = portlet.getDescription("en") ;
58       if(portletDescription == null) portletDescription = "N/A" ;
59       w. write("<tr>") ;
60       w. write("<td width='10'>") ;
61       w. write("<input style='width: 15px' type='checkbox' name='portletId'" +
62                             " value='" + key +"'/>") ;
63       w. write("</td>");
64       w. write("<td>") ;
65       w. write(portletTitle) ;
66       w. write("</td>") ;
67       w. write("<td style='padding: 2px 20px 2px 10px'>") ;
68       w. write(portletDescription) ;
69       w. write("</td>") ;
70       w. write("</tr>");
71     }
72     w. write("<tr>");
73     w. write("<td align='center' colspan='3'>") ;
74     w. write("<a HREF=\"javascript:submitAddPortletForm('"+SAVE_ACTION +"');\">");
75     w. write(res.getString("UIPortletList.button.save"));
76     w. write("</a> ");
77     w. write("<a HREF=\"javascript:submitAddPortletForm('"+CANCEL_ACTION +"');\">");
78     w. write(res.getString("UIPortletList.button.cancel"));
79     w. write("</a>");
80     w. write("</td>") ;
81     w. write("</tr>");
82     w. write("</table>");
83     w. write(SCRIPT);
84     w. write("</form>");
85     w.write("</center>");
86   }
87 }
Popular Tags