KickJava   Java API By Example, From Geeks To Geeks.

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


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 import javax.portlet.PortletSession;
13
14 import org.apache.commons.logging.Log;
15 import org.exoplatform.services.wsrp.consumer.*;
16 /*
17  * @author Tuan Nguyne
18  * tuan08@users.sourceforge.net
19  * Tue, Feb 24, 2004 @ 14:35
20  */

21 public class WSRPConfigModeHandler {
22   public static final String JavaDoc 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 JavaDoc w = response.getWriter() ;
40       config.render(request, response, res) ;
41       String JavaDoc baseURL = response.createActionURL().toString() ;
42       w.write("<div align='center' height='35'>") ;
43       writeRefreshLink(w, baseURL, res) ;
44       w.write("</div>") ;
45     } catch (Exception JavaDoc ex) {
46       log_.error("Error: ", ex) ;
47     }
48   }
49
50   public void processAction(ActionRequest request, ActionResponse response) throws IOException JavaDoc {
51     try {
52       String JavaDoc 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 JavaDoc ex) {
59       log_.error("Error: ", ex) ;
60     }
61   }
62
63   private UIWSRPConfig getUIWSRPConfig(PortletRequest request) throws Exception JavaDoc {
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 JavaDoc w, String JavaDoc baseURL, ResourceBundle res) throws IOException JavaDoc {
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