1 5 6 package org.exoplatform.portlets.wsrp; 7 8 import java.util.*; 9 import java.io.IOException ; 10 import java.io.Writer ; 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 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 { 29 producer_ = producer ; 30 ServiceDescription desc = producer_.getServiceDescription() ; 31 offeredPortlets_ = desc.getOfferedPortlets() ; 32 log_ = log ; 33 } 34 35 public String 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 { 41 } 42 43 public void render(RenderRequest request, RenderResponse response, ResourceBundle res) throws PortletException , IOException { 44 Writer w = response.getWriter() ; 45 String baseURL = response.createActionURL().toString() ; 46 String 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 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 w, String baseURL) throws IOException { 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 w, String baseURL, String portletHandle, 87 ResourceBundle res) throws IOException { 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 getValue(LocalizedString s) { 95 if (s == null) return "" ; 96 return s.getValue() ; 97 } 98 } 99 | Popular Tags |