1 5 package org.exoplatform.portlet.exomvc; 6 import java.io.IOException ; 7 import javax.portlet.*; 8 import org.exoplatform.commons.utils.ExceptionUtil; 9 import org.exoplatform.portlet.exomvc.config.Configuration; 10 import org.exoplatform.portlet.exomvc.config.PageConfig ; 11 18 19 public class MVCPortletFramework extends GenericPortlet { 20 final public static PortletMode CONFIG_MODE = new PortletMode("config") ; 21 22 private Configuration configuration_ ; 23 24 public void init(PortletConfig config) throws PortletException { 25 super.init(config); 26 try { 27 configuration_ = new Configuration(config) ; 28 } catch (Exception ex) { 29 ex.printStackTrace() ; 30 } 31 } 32 33 public void render (RenderRequest req, RenderResponse res) throws PortletException, java.io.IOException { 34 res.setTitle(getTitle(req)); 35 WindowState state = req.getWindowState(); 36 if (!state.equals(WindowState.MINIMIZED)) { 37 try { 38 res.setContentType("text/html") ; 39 PortletMode mode = req.getPortletMode(); 40 String pageName = req.getParameter(Page.FORWARD_PAGE) ; 41 PageConfig pconfig = configuration_.getPageConfig(mode, pageName) ; 42 Page page = pconfig.getPageObject(configuration_) ; 43 PageDecorator decorator = pconfig.getPageDecorator() ; 44 if(decorator != null) { 45 decorator.decorate(page, req, res) ; 46 } else { 47 page.render(req, res) ; 48 } 49 } catch (Throwable t) { 50 String trace = ExceptionUtil.getExoStackTrace(t) ; 51 res.getWriter().write(trace) ; 52 } 53 } 54 } 55 56 public void processAction(ActionRequest req, ActionResponse res) 57 throws PortletException, IOException { 58 try { 59 PortletMode mode = req.getPortletMode(); 60 String pageName = req.getParameter(Page.PAGE_NAME) ; 61 PageConfig pconfig = configuration_.getPageConfig(mode, pageName) ; 62 Page page = pconfig.getPageObject(configuration_) ; 63 page.processAction(req, res) ; 64 } catch (Throwable t) { 65 String trace = ExceptionUtil.getExoStackTrace(t) ; 66 } 68 } 69 70 public void destroy() { 71 configuration_.destroy() ; 72 super.destroy() ; 73 } 74 } | Popular Tags |