KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > wsrp > UIProducer


1 /*
2 * Copyright 2001-2004 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.wsrp;
7
8 import java.util.*;
9 import java.io.IOException JavaDoc;
10 import java.io.Writer JavaDoc ;
11 import javax.portlet.* ;
12
13 import org.apache.commons.logging.Log;
14 import org.exoplatform.services.wsrp.consumer.*;
15 import org.exoplatform.services.wsrp.type.*;
16 /*
17  * A part of the business logic of this portlet was taken from the WSRP4J project
18  * @author Tuan Nguyne
19  * tuan08@users.sourceforge.net
20  * Tue, Feb 24, 2004 @ 14:35
21  */

22 public class UIProducer {
23   private Log log_ ;
24   private boolean visible_ ;
25   private Producer producer_ ;
26   private PortletDescription[] offeredPortlets_ ;
27
28   public UIProducer(Producer producer, Log log) throws Exception JavaDoc {
29     producer_ = producer ;
30     ServiceDescription desc = producer_.getServiceDescription() ;
31     offeredPortlets_ = desc.getOfferedPortlets() ;
32     log_ = log ;
33   }
34
35   public String JavaDoc getId() { return producer_.getID() ; }
36
37   public void setVisible(boolean b) { visible_ = b ; }
38   public boolean isVisible() { return visible_ ; }
39
40   public void processAction(ActionRequest request, ActionResponse response) throws Exception JavaDoc {
41   }
42
43   public void render(RenderRequest request, RenderResponse response, ResourceBundle res) throws PortletException , IOException JavaDoc {
44     Writer JavaDoc w = response.getWriter() ;
45     String JavaDoc baseURL = response.createActionURL().toString() ;
46     String JavaDoc producerDesc = producer_.getDescription() ;
47     if (producerDesc == null) producerDesc = "" ;
48     w.write("<table class='UIProducer'>") ;
49     w. write("<tr>") ;
50     w. write("<th colspan='3' height='30'>") ;
51     writeProducerLink(w, baseURL) ;
52     w. write("<br/>" + producerDesc) ;
53     w. write("</th>") ;
54     w. write("</tr>") ;
55     if (visible_) {
56       w. write("<tr>") ;
57       w. write("<th>") ; w.write(res.getString("UIProducer.header.portlet-title")); w.write("</th>") ;
58       w. write("<th width='*'>") ; w.write(res.getString("UIProducer.header.portlet-description")); w.write("</th>") ;
59       w. write("<th>") ; w.write("-"); w.write("</th>") ;
60       w. write("</tr>") ;
61       if(offeredPortlets_ != null){
62         for(int i = 0 ; i < offeredPortlets_.length ; i++) {
63           PortletDescription pdesc = offeredPortlets_[i] ;
64           String JavaDoc clazz = "odd";
65           if (i % 2 == 0)
66             clazz = "even";
67             w.write("<tr class='" + clazz + "'>") ;
68           w. write("<td>") ; w.write(getValue(pdesc.getTitle())); w.write("</td>") ;
69           w. write("<td width='*'>") ; w.write(getValue(pdesc.getDescription())); w.write("</td>") ;
70           w. write("<td align='center'>") ;
71           writeSelectLink(w, baseURL, pdesc.getPortletHandle(), res) ;
72           w. write("</td>") ;
73           w.write("</tr>") ;
74         }
75       }
76     }
77     w.write("</table>") ;
78   }
79
80   private void writeProducerLink(Writer JavaDoc w, String JavaDoc baseURL) throws IOException JavaDoc {
81     w.write("<a HREF='" + baseURL + "&producerId=" + producer_.getID() + "&action=selectProducer'>") ;
82     w.write(producer_.getName()) ;
83     w.write("</a>") ;
84   }
85
86   private void writeSelectLink(Writer JavaDoc w, String JavaDoc baseURL, String JavaDoc portletHandle,
87       ResourceBundle res) throws IOException JavaDoc {
88     w.write("<a HREF='" + baseURL + "&producerId=" + producer_.getID() +
89             "&portletHandle=" + portletHandle + "&action=selectPortlet'>") ;
90     w.write(res.getString("UIProducer.button.select")) ;
91     w.write("</a>") ;
92   }
93
94   private String JavaDoc getValue(LocalizedString s) {
95     if (s == null) return "" ;
96     return s.getValue() ;
97   }
98 }
99
Popular Tags