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 import javax.portlet.PortletSession; 13 14 import org.apache.commons.logging.Log; 15 import org.exoplatform.services.wsrp.consumer.*; 16 21 public class WSRPConfigModeHandler { 22 public static final String UI_WSRP_CONFIG = "ui-wsrp-config" ; 23 24 private Log log_ ; 25 private ConsumerEnvironment consumerEnvironment_ ; 26 private PortletConfig portletConfig_ ; 27 28 public WSRPConfigModeHandler(PortletConfig config, ConsumerEnvironment env, Log log) { 29 log_ = log ; 30 consumerEnvironment_ = env ; 31 portletConfig_ = config ; 32 } 33 34 public void render(RenderRequest request, RenderResponse response) { 35 response.setContentType("text/html") ; 36 try { 37 ResourceBundle res = portletConfig_.getResourceBundle(response.getLocale()) ; 38 UIWSRPConfig config = getUIWSRPConfig(request) ; 39 Writer w = response.getWriter() ; 40 config.render(request, response, res) ; 41 String baseURL = response.createActionURL().toString() ; 42 w.write("<div align='center' height='35'>") ; 43 writeRefreshLink(w, baseURL, res) ; 44 w.write("</div>") ; 45 } catch (Exception ex) { 46 log_.error("Error: ", ex) ; 47 } 48 } 49 50 public void processAction(ActionRequest request, ActionResponse response) throws IOException { 51 try { 52 String action = request.getParameter("action") ; 53 if ("refresh".equals(action)) { 54 request.getPortletSession().removeAttribute(UI_WSRP_CONFIG) ; 55 } 56 UIWSRPConfig config = getUIWSRPConfig(request) ; 57 config.processAction(request, response) ; 58 } catch (Exception ex) { 59 log_.error("Error: ", ex) ; 60 } 61 } 62 63 private UIWSRPConfig getUIWSRPConfig(PortletRequest request) throws Exception { 64 PortletSession session = request.getPortletSession() ; 65 UIWSRPConfig config = (UIWSRPConfig) session.getAttribute(UI_WSRP_CONFIG) ; 66 if (config == null) { 67 config = new UIWSRPConfig(consumerEnvironment_ , log_) ; 68 session.setAttribute(UI_WSRP_CONFIG, config) ; 69 } 70 71 return config ; 72 } 73 74 private void writeRefreshLink(Writer w, String baseURL, ResourceBundle res) throws IOException { 75 w.write("<a HREF='" + baseURL + "&action=refresh'>") ; 76 w. write(res.getString("WSRPConfigModeHandler.button.refresh")) ; 77 w.write("</a>") ; 78 } 79 } 80 | Popular Tags |