diff options
5 files changed, 429 insertions, 0 deletions
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 @@ +<?xml version="1.0"?>
+<!DOCTYPE display PUBLIC "-//Liferay//DTD Display 4.0.0//EN" "http://www.liferay.com/dtd/liferay-display_4_0_0.dtd">
+
+<display>
+ <category name="IT Mill Toolkit">
+ <portlet id="ApplicationPortlet" />
+ </category>
+</display>
\ 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 @@ +<?xml version="1.0"?>
+<!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 4.3.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_4_3_0.dtd">
+
+<liferay-portlet-app>
+
+ <portlet>
+ <portlet-name>ApplicationPortlet</portlet-name>
+ <instanceable>true</instanceable>
+ <ajaxable>false</ajaxable>
+ </portlet>
+
+ <role-mapper>
+ <role-name>administrator</role-name>
+ <role-link>Administrator</role-link>
+ </role-mapper>
+ <role-mapper>
+ <role-name>guest</role-name>
+ <role-link>Guest</role-link>
+ </role-mapper>
+ <role-mapper>
+ <role-name>power-user</role-name>
+ <role-link>Power User</role-link>
+ </role-mapper>
+ <role-mapper>
+ <role-name>user</role-name>
+ <role-link>User</role-link>
+ </role-mapper>
+
+</liferay-portlet-app>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<portlet-app
+ xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
+ version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
+
+ <portlet>
+ <portlet-name>ApplicationPortlet</portlet-name>
+ <display-name>IT Mill Toolkit Portlet</display-name>
+ <portlet-class>com.itmill.toolkit.terminal.gwt.server.ApplicationPortlet</portlet-class>
+ <supports>
+ <mime-type>text/html</mime-type>
+ <portlet-mode>view</portlet-mode>
+ <portlet-mode>edit</portlet-mode>
+ <portlet-mode>help</portlet-mode>
+ </supports>
+ <portlet-info>
+ <title>IT Mill Toolkit ApplicationPortlet</title>
+ <short-title>ApplicationPortlet</short-title>
+ </portlet-info>
+
+ <security-role-ref>
+ <role-name>administrator</role-name>
+ </security-role-ref>
+ <security-role-ref>
+ <role-name>guest</role-name>
+ </security-role-ref>
+ <security-role-ref>
+ <role-name>power-user</role-name>
+ </security-role-ref>
+ <security-role-ref>
+ <role-name>user</role-name>
+ </security-role-ref>
+ </portlet>
+
+</portlet-app>
\ 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("<form method='POST' action='" + submitUrl + "'>");
+ out.println("Application:");
+ out.println(request.getContextPath() + "/");
+ out.println("<input size='40' type='text' name='app' value='"
+ + (app != null ? app : "") + "'>");
+ out.println(" Theme:<input type='text' name='theme' value='"
+ + theme + "'><br/>");
+ out
+ .println("Force height (optional, e.g \"200px\"): <input type='text' name='height' value='"
+ + (height != null ? height : "") + "'><br/>");
+ out.println("<input type='submit' value='Save'>");
+ out.println("</form>");
+ } 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("<h1>Servlet include failed!</h1>");
+ out.print("<div>" + e + "</div>");
+ 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);
+ }
+}
|