From: Marc Englund Date: Thu, 10 Apr 2008 13:28:37 +0000 (+0000) Subject: PortalTools initial commit X-Git-Tag: 6.7.0.beta1~4908 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1b7700ed46ea8f74117318d42cf53971ba9abd75;p=vaadin-framework.git PortalTools initial commit svn changeset:4157/svn branch:trunk --- diff --git a/WebContent/WEB-INF/liferay-display.xml b/WebContent/WEB-INF/liferay-display.xml new file mode 100644 index 0000000000..d92c1b4397 --- /dev/null +++ b/WebContent/WEB-INF/liferay-display.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/WebContent/WEB-INF/liferay-portlet.xml b/WebContent/WEB-INF/liferay-portlet.xml new file mode 100644 index 0000000000..5af07be367 --- /dev/null +++ b/WebContent/WEB-INF/liferay-portlet.xml @@ -0,0 +1,29 @@ + + + + + + + ApplicationPortlet + true + false + + + + administrator + Administrator + + + guest + Guest + + + power-user + Power User + + + user + User + + + \ No newline at end of file diff --git a/WebContent/WEB-INF/portlet.xml b/WebContent/WEB-INF/portlet.xml new file mode 100644 index 0000000000..3f414ab07b --- /dev/null +++ b/WebContent/WEB-INF/portlet.xml @@ -0,0 +1,36 @@ + + + + + ApplicationPortlet + IT Mill Toolkit Portlet + com.itmill.toolkit.terminal.gwt.server.ApplicationPortlet + + text/html + view + edit + help + + + IT Mill Toolkit ApplicationPortlet + ApplicationPortlet + + + + administrator + + + guest + + + power-user + + + user + + + + \ No newline at end of file diff --git a/portlet-src/com/itmill/toolkit/terminal/gwt/server/ApplicationPortlet.java b/portlet-src/com/itmill/toolkit/terminal/gwt/server/ApplicationPortlet.java new file mode 100644 index 0000000000..a0c31b1ecf --- /dev/null +++ b/portlet-src/com/itmill/toolkit/terminal/gwt/server/ApplicationPortlet.java @@ -0,0 +1,138 @@ +package com.itmill.toolkit.terminal.gwt.server; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Map; + +import javax.portlet.ActionRequest; +import javax.portlet.ActionResponse; +import javax.portlet.Portlet; +import javax.portlet.PortletConfig; +import javax.portlet.PortletException; +import javax.portlet.PortletMode; +import javax.portlet.PortletModeException; +import javax.portlet.PortletPreferences; +import javax.portlet.PortletRequest; +import javax.portlet.PortletRequestDispatcher; +import javax.portlet.PortletSession; +import javax.portlet.PortletURL; +import javax.portlet.RenderRequest; +import javax.portlet.RenderResponse; + +import com.itmill.toolkit.Application; +import com.itmill.toolkit.terminal.gwt.server.PortletApplicationContext.PortletInfo; +import com.itmill.toolkit.terminal.gwt.server.PortletApplicationContext.PortletInfoReceiver; + +public class ApplicationPortlet implements Portlet { + // The application to show + protected String app = "Calc"; // empty for root + // theme to use for the application + protected String theme = "default"; + // some applications might require that the height is specified + protected String height = null; // e.g "200px" + + PortletConfig config; + + public void destroy() { + config = null; + } + + public void init(PortletConfig config) throws PortletException { + this.config = config; + } + + public void processAction(ActionRequest request, ActionResponse response) + throws PortletException, IOException { + // Update preferences (configured) + PortletPreferences prefs = request.getPreferences(); + app = request.getParameter("app"); + if (app != null && app.length() > 0) { + prefs.setValue("application", app); + } else { + app = null; + } + String theme = request.getParameter("theme"); + if (theme != null && theme.length() > 0) { + prefs.setValue("theme", theme); + } else { + prefs.setValue("theme", null); + } + String height = request.getParameter("height"); + if (height != null && height.length() > 0) { + prefs.setValue("height", height); + } else { + prefs.setValue("height", null); + } + prefs.store(); + } + + public void render(RenderRequest request, RenderResponse response) + throws PortletException, IOException { + + PortletPreferences prefs = request.getPreferences(); + app = prefs.getValue("application", app); + theme = prefs.getValue("theme", "default"); + height = prefs.getValue("height", null); + + // display the IT Mill Toolkit application + writeAjaxWindow(request, response); + } + + protected void writeAjaxWindow(RenderRequest request, + RenderResponse response) throws IOException { + + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + + // TODO check user == admin + if (app == null) { + // Display the configuration UI + PortletURL submitUrl = response.createActionURL(); + try { + submitUrl.setPortletMode(PortletMode.VIEW); + } catch (PortletModeException e) { + // Fine + } + out.println("
"); + out.println("Application:"); + out.println(request.getContextPath() + "/"); + out.println(""); + out.println(" Theme:
"); + out + .println("Force height (optional, e.g \"200px\"):
"); + out.println(""); + out.println("
"); + } else { + + PortletSession sess = request.getPortletSession(); + PortletApplicationContext ctx = PortletApplicationContext + .getApplicationContext(sess); + + PortletInfo pi = ctx.setPortletInfo(request.getContextPath() + "/" + + app + (app.endsWith("/") ? "" : "/"), request + .getPortletMode(), request.getWindowState(), request + .getUserPrincipal(), (Map) request + .getAttribute(PortletRequest.USER_INFO), config); + + PortletRequestDispatcher dispatcher = sess.getPortletContext() + .getRequestDispatcher("/" + app); + + try { + dispatcher.include(request, response); + } catch (PortletException e) { + out.print("

Servlet include failed!

"); + out.print("
" + e + "
"); + return; + } + + Object app = request.getAttribute(Application.class.getName()); + if (app instanceof PortletInfoReceiver) { + ((PortletInfoReceiver) app).receivePortletInfo(pi); + } + } + } + +} diff --git a/portlet-src/com/itmill/toolkit/terminal/gwt/server/PortletApplicationContext.java b/portlet-src/com/itmill/toolkit/terminal/gwt/server/PortletApplicationContext.java new file mode 100644 index 0000000000..a87ff638c2 --- /dev/null +++ b/portlet-src/com/itmill/toolkit/terminal/gwt/server/PortletApplicationContext.java @@ -0,0 +1,218 @@ +/** + * + */ +package com.itmill.toolkit.terminal.gwt.server; + +import java.io.File; +import java.security.Principal; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import javax.portlet.PortletConfig; +import javax.portlet.PortletMode; +import javax.portlet.PortletSession; +import javax.portlet.WindowState; +import javax.servlet.http.HttpSession; + +import com.itmill.toolkit.Application; +import com.itmill.toolkit.service.ApplicationContext; + +/** + * @author marc + * + */ +public class PortletApplicationContext implements ApplicationContext { + + private final PortletSession session; + + private final Map portletInfoMap; + + PortletApplicationContext(PortletSession session) { + this.session = session; + portletInfoMap = new HashMap(); + } + + static public PortletApplicationContext getApplicationContext( + PortletSession session) { + PortletApplicationContext cx = (PortletApplicationContext) session + .getAttribute(PortletApplicationContext.class.getName()); + if (cx == null) { + cx = new PortletApplicationContext(session); + session.setAttribute(PortletApplicationContext.class.getName(), cx, + PortletSession.APPLICATION_SCOPE); + } + return cx; + } + + static public PortletApplicationContext getApplicationContext( + HttpSession session) { + PortletApplicationContext cx = (PortletApplicationContext) session + .getAttribute(PortletApplicationContext.class.getName()); + return cx; + } + + public PortletSession getPortletSession() { + return session; + } + + /* + * (non-Javadoc) + * + * @see com.itmill.toolkit.service.ApplicationContext#addTransactionListener(com.itmill.toolkit.service.ApplicationContext.TransactionListener) + */ + public void addTransactionListener(TransactionListener listener) { + WebApplicationContext cx = (WebApplicationContext) session + .getAttribute(WebApplicationContext.class.getName()); + if (cx != null) { + cx.addTransactionListener(listener); + } + } + + /* + * (non-Javadoc) + * + * @see com.itmill.toolkit.service.ApplicationContext#getApplications() + */ + public Collection getApplications() { + WebApplicationContext cx = (WebApplicationContext) session + .getAttribute(WebApplicationContext.class.getName()); + if (cx != null) { + return cx.getApplications(); + } + return null; + } + + /* + * (non-Javadoc) + * + * @see com.itmill.toolkit.service.ApplicationContext#getBaseDirectory() + */ + public File getBaseDirectory() { + WebApplicationContext cx = (WebApplicationContext) session + .getAttribute(WebApplicationContext.class.getName()); + if (cx != null) { + return cx.getBaseDirectory(); + } + return null; + } + + /* + * (non-Javadoc) + * + * @see com.itmill.toolkit.service.ApplicationContext#removeTransactionListener(com.itmill.toolkit.service.ApplicationContext.TransactionListener) + */ + public void removeTransactionListener(TransactionListener listener) { + WebApplicationContext cx = (WebApplicationContext) session + .getAttribute(WebApplicationContext.class.getName()); + if (cx != null) { + cx.removeTransactionListener(listener); + } + } + + PortletInfo setPortletInfo(String path, PortletMode mode, + WindowState state, Principal userPrincipal, Map userInfo, + PortletConfig config) { + System.err.println("SETTING PI: " + path); + PortletInfo pi = (PortletInfo) portletInfoMap.get(path); + if (pi == null) { + pi = new PortletInfo(mode, state, userPrincipal, userInfo, config); + portletInfoMap.put(path, pi); + } else { + pi.setInfo(mode, state, userPrincipal, userInfo, config); + } + return pi; + } + + public PortletInfo getPortletInfo(Application app) { + if (app != null && app.getURL() != null) { + // TODO remove + System.err.println("GETTING PI: " + app.getURL().getPath()); + return (PortletInfo) portletInfoMap.get(app.getURL().getPath()); + } + return null; + } + + public class PortletInfo { + + PortletMode mode; + WindowState state; + Principal userPrincipal; + Map userInfo; + PortletConfig config; + + public PortletInfo(PortletMode mode, WindowState state, + Principal userPrincipal, Map userInfo, PortletConfig config) { + this.mode = mode; + this.state = state; + this.userPrincipal = userPrincipal; + this.userInfo = userInfo; + this.config = config; + } + + private void setInfo(PortletMode mode, WindowState state, + Principal userPrincipal, Map userInfo, PortletConfig config) { + this.mode = mode; + this.state = state; + this.userPrincipal = userPrincipal; + this.userInfo = userInfo; + this.config = config; + } + + /** + * Gets the current portlet mode, VIEW / EDIT / HELP + * + * @return the current portlet mode + */ + public PortletMode getPortletMode() { + return mode; + } + + /** + * Gets the current window state, NORMAL / MAXIMIZED / MINIMIZED + * + * @return the current window state + */ + public WindowState getWindowState() { + return state; + } + + /** + * Gets the current UserPrincipal + * + * @return current UserPrincipal, null if not logged in + */ + public Principal getUserPrincipal() { + return userPrincipal; + } + + /** + * Gets the PortletConfig for this portlet + * + * @return the PortletConfig + */ + public PortletConfig getConfig() { + return config; + } + + /** + * Gets the user info for this portlet, as retreived from + * request.getAttribute(PortletRequest.USER_INFO); + * + * @return the user info Map + */ + public Map getUserInfo() { + return userInfo; + } + + public String toString() { + return "PortletMode: " + getPortletMode() + " WindowState: " + + getWindowState() + " UserPrincipal: " + + getUserPrincipal() + " User info: " + getUserInfo(); + } + } + + public interface PortletInfoReceiver { + public void receivePortletInfo(PortletInfo info); + } +}