aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--WebContent/WEB-INF/web.xml12
-rw-r--r--src/com/vaadin/Application.java843
-rw-r--r--src/com/vaadin/RootTestApplication.java22
-rw-r--r--src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java2
-rw-r--r--src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java3244
-rw-r--r--src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java195
-rw-r--r--src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java339
-rw-r--r--src/com/vaadin/terminal/gwt/server/ApplicationPortlet.java494
-rw-r--r--src/com/vaadin/terminal/gwt/server/ApplicationPortlet2.java86
-rw-r--r--src/com/vaadin/terminal/gwt/server/CommunicationManager.java14
-rw-r--r--src/com/vaadin/terminal/gwt/server/PortletApplicationContext2.java830
-rw-r--r--src/com/vaadin/terminal/gwt/server/PortletCommunicationManager.java604
-rw-r--r--src/com/vaadin/ui/AbstractComponent.java6
-rw-r--r--src/com/vaadin/ui/AbstractField.java18
-rw-r--r--src/com/vaadin/ui/Component.java6
-rw-r--r--src/com/vaadin/ui/DefaultRoot.java58
-rw-r--r--src/com/vaadin/ui/LoginForm.java25
-rw-r--r--src/com/vaadin/ui/Root.java13
-rw-r--r--src/com/vaadin/ui/Window.java2251
19 files changed, 4605 insertions, 4457 deletions
diff --git a/WebContent/WEB-INF/web.xml b/WebContent/WEB-INF/web.xml
index b83979acc6..6b40c31d96 100644
--- a/WebContent/WEB-INF/web.xml
+++ b/WebContent/WEB-INF/web.xml
@@ -30,29 +30,29 @@
</servlet>
<!-- For testing GAE - the deployment script changes this to use GAEApplicationServlet -->
- <servlet>
+<!-- <servlet>
<servlet-name>IntegrationTest</servlet-name>
<servlet-class>com.vaadin.terminal.gwt.server.ApplicationServlet</servlet-class>
<init-param>
<param-name>application</param-name>
<param-value>com.vaadin.tests.integration.IntegrationTestApplication</param-value>
</init-param>
- </servlet>
+ </servlet> -->
<servlet-mapping>
<servlet-name>VaadinApplicationRunner</servlet-name>
<url-pattern>/run/*</url-pattern>
</servlet-mapping>
- <servlet-mapping>
+<!-- <servlet-mapping>
<servlet-name>IntegrationTest</servlet-name>
<url-pattern>/integration/*</url-pattern>
- </servlet-mapping>
+ </servlet-mapping> -->
- <servlet-mapping>
+<!-- <servlet-mapping>
<servlet-name>IntegrationTest</servlet-name>
<url-pattern>/VAADIN/*</url-pattern>
- </servlet-mapping>
+ </servlet-mapping> -->
<welcome-file-list>
<welcome-file>index.html</welcome-file>
diff --git a/src/com/vaadin/Application.java b/src/com/vaadin/Application.java
index 39a70fe27f..4a6968fd66 100644
--- a/src/com/vaadin/Application.java
+++ b/src/com/vaadin/Application.java
@@ -7,13 +7,10 @@ package com.vaadin;
import java.io.Serializable;
import java.net.SocketException;
import java.net.URL;
-import java.util.Collection;
-import java.util.Collections;
import java.util.Enumeration;
import java.util.EventListener;
import java.util.EventObject;
import java.util.Hashtable;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.Locale;
import java.util.Properties;
@@ -33,6 +30,7 @@ import com.vaadin.terminal.gwt.server.ChangeVariablesErrorEvent;
import com.vaadin.terminal.gwt.server.PortletApplicationContext;
import com.vaadin.terminal.gwt.server.WebApplicationContext;
import com.vaadin.ui.AbstractComponent;
+import com.vaadin.ui.Root;
import com.vaadin.ui.Window;
/**
@@ -95,11 +93,11 @@ public abstract class Application implements URIHandler,
private final static Logger logger = Logger.getLogger(Application.class
.getName());
- /**
- * Id use for the next window that is opened. Access to this must be
- * synchronized.
- */
- private int nextWindowId = 1;
+ // /**
+ // * Id use for the next window that is opened. Access to this must be
+ // * synchronized.
+ // */
+ // private int nextWindowId = 1;
/**
* Application context the application is running in.
@@ -111,25 +109,26 @@ public abstract class Application implements URIHandler,
*/
private Object user;
- /**
- * Mapping from window name to window instance.
- */
- private final Hashtable<String, Window> windows = new Hashtable<String, Window>();
+ // /**
+ // * Mapping from window name to window instance.
+ // */
+ // private final Hashtable<String, Window> windows = new Hashtable<String,
+ // Window>();
- /**
- * Main window of the application.
- */
- private Window mainWindow = null;
+ // /**
+ // * Main window of the application.
+ // */
+ // private Window mainWindow = null;
/**
* The application's URL.
*/
private URL applicationUrl;
- /**
- * Name of the theme currently used by the application.
- */
- private String theme = null;
+ // /**
+ // * Name of the theme currently used by the application.
+ // */
+ // private String theme = null;
/**
* Application status.
@@ -151,15 +150,15 @@ public abstract class Application implements URIHandler,
*/
private LinkedList<UserChangeListener> userChangeListeners = null;
- /**
- * Window attach listeners.
- */
- private LinkedList<WindowAttachListener> windowAttachListeners = null;
-
- /**
- * Window detach listeners.
- */
- private LinkedList<WindowDetachListener> windowDetachListeners = null;
+ // /**
+ // * Window attach listeners.
+ // */
+ // private LinkedList<WindowAttachListener> windowAttachListeners = null;
+ //
+ // /**
+ // * Window detach listeners.
+ // */
+ // private LinkedList<WindowDetachListener> windowDetachListeners = null;
/**
* Application resource mapping: key <-> resource.
@@ -188,238 +187,252 @@ public abstract class Application implements URIHandler,
*/
private Terminal.ErrorListener errorHandler = this;
- /**
- * <p>
- * Gets a window by name. Returns <code>null</code> if the application is
- * not running or it does not contain a window corresponding to the name.
- * </p>
- *
- * <p>
- * All windows can be referenced by their names in url
- * <code>http://host:port/foo/bar/</code> where
- * <code>http://host:port/foo/</code> is the application url as returned by
- * getURL() and <code>bar</code> is the name of the window.
- * </p>
- *
- * <p>
- * One should note that this method can, as a side effect create new windows
- * if needed by the application. This can be achieved by overriding the
- * default implementation.
- * </p>
- *
- * <p>
- * If for some reason user opens another window with same url that is
- * already open, name is modified by adding "_12345678" postfix to the name,
- * where 12345678 is a random number. One can decide to create another
- * window-object for those windows (recommended) or to discard the postfix.
- * If the user has two browser windows pointing to the same window-object on
- * server, synchronization errors are likely to occur.
- * </p>
- *
- * <p>
- * If no browser-level windowing is used, all defaults are fine and this
- * method can be left as is. In case browser-level windows are needed, it is
- * recommended to create new window-objects on this method from their names
- * if the super.getWindow() does not find existing windows. See below for
- * implementation example: <code><pre>
- // If we already have the requested window, use it
- Window w = super.getWindow(name);
- if (w == null) {
- // If no window found, create it
- w = new Window(name);
- // set windows name to the one requested
- w.setName(name);
- // add it to this application
- addWindow(w);
- // ensure use of window specific url
- w.open(new ExternalResource(w.getURL().toString()));
- // add some content
- w.addComponent(new Label("Test window"));
- }
- return w;</pre></code>
- * </p>
- *
- * <p>
- * <strong>Note</strong> that all returned Window objects must be added to
- * this application instance.
- *
- * <p>
- * The method should return null if the window does not exists (and is not
- * created as a side-effect) or if the application is not running anymore.
- * </p>
- *
- * @param name
- * the name of the window.
- * @return the window associated with the given URI or <code>null</code>
- */
- public Window getWindow(String name) {
-
- // For closed app, do not give any windows
- if (!isRunning()) {
- return null;
- }
-
- // Gets the window by name
- final Window window = windows.get(name);
-
- return window;
- }
-
- /**
- * Adds a new window to the application.
- *
- * <p>
- * This implicitly invokes the
- * {@link com.vaadin.ui.Window#setApplication(Application)} method.
- * </p>
- *
- * <p>
- * Note that all application-level windows can be accessed by their names in
- * url <code>http://host:port/foo/bar/</code> where
- * <code>http://host:port/foo/</code> is the application url as returned by
- * getURL() and <code>bar</code> is the name of the window. Also note that
- * not all windows should be added to application - one can also add windows
- * inside other windows - these windows show as smaller windows inside those
- * windows.
- * </p>
- *
- * @param window
- * the new <code>Window</code> to add. If the name of the window
- * is <code>null</code>, an unique name is automatically given
- * for the window.
- * @throws IllegalArgumentException
- * if a window with the same name as the new window already
- * exists in the application.
- * @throws NullPointerException
- * if the given <code>Window</code> is <code>null</code>.
- */
- public void addWindow(Window window) throws IllegalArgumentException,
- NullPointerException {
-
- // Nulls can not be added to application
- if (window == null) {
- return;
- }
-
- // Check that one is not adding a sub-window to application
- if (window.getParent() != null) {
- throw new IllegalArgumentException(
- "Window was already added inside another window"
- + " - it can not be added to application also.");
- }
-
- // Gets the naming proposal from window
- String name = window.getName();
-
- // Checks that the application does not already contain
- // window having the same name
- if (name != null && windows.containsKey(name)) {
-
- // If the window is already added
- if (window == windows.get(name)) {
- return;
- }
-
- // Otherwise complain
- throw new IllegalArgumentException("Window with name '"
- + window.getName()
- + "' is already present in the application");
- }
-
- // If the name of the window is null, the window is automatically named
- if (name == null) {
- boolean accepted = false;
- while (!accepted) {
-
- // Try another name
- synchronized (this) {
- name = String.valueOf(nextWindowId);
- nextWindowId++;
- }
-
- if (!windows.containsKey(name)) {
- accepted = true;
- }
- }
- window.setName(name);
- }
-
- // Adds the window to application
- windows.put(name, window);
- window.setApplication(this);
-
- fireWindowAttachEvent(window);
-
- // If no main window is set, declare the window to be main window
- if (getMainWindow() == null) {
- mainWindow = window;
- }
- }
-
- /**
- * Send information to all listeners about new Windows associated with this
- * application.
- *
- * @param window
- */
- private void fireWindowAttachEvent(Window window) {
- // Fires the window attach event
- if (windowAttachListeners != null) {
- final Object[] listeners = windowAttachListeners.toArray();
- final WindowAttachEvent event = new WindowAttachEvent(window);
- for (int i = 0; i < listeners.length; i++) {
- ((WindowAttachListener) listeners[i]).windowAttached(event);
- }
- }
- }
-
- /**
- * Removes the specified window from the application.
- *
- * <p>
- * Removing the main window of the Application also sets the main window to
- * null. One must another window to be the main window after this with
- * {@link #setMainWindow(Window)}.
- * </p>
- *
- * <p>
- * Note that removing window from the application does not close the browser
- * window - the window is only removed from the server-side.
- * </p>
- *
- * @param window
- * the window to be removed.
- */
- public void removeWindow(Window window) {
- if (window != null && windows.contains(window)) {
-
- // Removes the window from application
- windows.remove(window.getName());
-
- // If the window was main window, clear it
- if (getMainWindow() == window) {
- setMainWindow(null);
- }
-
- // Removes the application from window
- if (window.getApplication() == this) {
- window.setApplication(null);
- }
-
- fireWindowDetachEvent(window);
- }
- }
-
- private void fireWindowDetachEvent(Window window) {
- // Fires the window detach event
- if (windowDetachListeners != null) {
- final Object[] listeners = windowDetachListeners.toArray();
- final WindowDetachEvent event = new WindowDetachEvent(window);
- for (int i = 0; i < listeners.length; i++) {
- ((WindowDetachListener) listeners[i]).windowDetached(event);
- }
- }
- }
+ // /**
+ // * <p>
+ // * Gets a window by name. Returns <code>null</code> if the application is
+ // * not running or it does not contain a window corresponding to the name.
+ // * </p>
+ // *
+ // * <p>
+ // * All windows can be referenced by their names in url
+ // * <code>http://host:port/foo/bar/</code> where
+ // * <code>http://host:port/foo/</code> is the application url as returned
+ // by
+ // * getURL() and <code>bar</code> is the name of the window.
+ // * </p>
+ // *
+ // * <p>
+ // * One should note that this method can, as a side effect create new
+ // windows
+ // * if needed by the application. This can be achieved by overriding the
+ // * default implementation.
+ // * </p>
+ // *
+ // * <p>
+ // * If for some reason user opens another window with same url that is
+ // * already open, name is modified by adding "_12345678" postfix to the
+ // name,
+ // * where 12345678 is a random number. One can decide to create another
+ // * window-object for those windows (recommended) or to discard the
+ // postfix.
+ // * If the user has two browser windows pointing to the same window-object
+ // on
+ // * server, synchronization errors are likely to occur.
+ // * </p>
+ // *
+ // * <p>
+ // * If no browser-level windowing is used, all defaults are fine and this
+ // * method can be left as is. In case browser-level windows are needed, it
+ // is
+ // * recommended to create new window-objects on this method from their
+ // names
+ // * if the super.getWindow() does not find existing windows. See below for
+ // * implementation example: <code><pre>
+ // // If we already have the requested window, use it
+ // Window w = super.getWindow(name);
+ // if (w == null) {
+ // // If no window found, create it
+ // w = new Window(name);
+ // // set windows name to the one requested
+ // w.setName(name);
+ // // add it to this application
+ // addWindow(w);
+ // // ensure use of window specific url
+ // w.open(new ExternalResource(w.getURL().toString()));
+ // // add some content
+ // w.addComponent(new Label("Test window"));
+ // }
+ // return w;</pre></code>
+ // * </p>
+ // *
+ // * <p>
+ // * <strong>Note</strong> that all returned Window objects must be added to
+ // * this application instance.
+ // *
+ // * <p>
+ // * The method should return null if the window does not exists (and is not
+ // * created as a side-effect) or if the application is not running anymore.
+ // * </p>
+ // *
+ // * @param name
+ // * the name of the window.
+ // * @return the window associated with the given URI or <code>null</code>
+ // */
+ // public Window getWindow(String name) {
+ //
+ // // For closed app, do not give any windows
+ // if (!isRunning()) {
+ // return null;
+ // }
+ //
+ // // Gets the window by name
+ // final Window window = windows.get(name);
+ //
+ // return window;
+ // }
+
+ // /**
+ // * Adds a new window to the application.
+ // *
+ // * <p>
+ // * This implicitly invokes the
+ // * {@link com.vaadin.ui.Window#setApplication(Application)} method.
+ // * </p>
+ // *
+ // * <p>
+ // * Note that all application-level windows can be accessed by their names
+ // in
+ // * url <code>http://host:port/foo/bar/</code> where
+ // * <code>http://host:port/foo/</code> is the application url as returned
+ // by
+ // * getURL() and <code>bar</code> is the name of the window. Also note that
+ // * not all windows should be added to application - one can also add
+ // windows
+ // * inside other windows - these windows show as smaller windows inside
+ // those
+ // * windows.
+ // * </p>
+ // *
+ // * @param window
+ // * the new <code>Window</code> to add. If the name of the window
+ // * is <code>null</code>, an unique name is automatically given
+ // * for the window.
+ // * @throws IllegalArgumentException
+ // * if a window with the same name as the new window already
+ // * exists in the application.
+ // * @throws NullPointerException
+ // * if the given <code>Window</code> is <code>null</code>.
+ // */
+ // public void addWindow(Window window) throws IllegalArgumentException,
+ // NullPointerException {
+ //
+ // // Nulls can not be added to application
+ // if (window == null) {
+ // return;
+ // }
+ //
+ // // Check that one is not adding a sub-window to application
+ // if (window.getParent() != null) {
+ // throw new IllegalArgumentException(
+ // "Window was already added inside another window"
+ // + " - it can not be added to application also.");
+ // }
+ //
+ // // Gets the naming proposal from window
+ // String name = window.getName();
+ //
+ // // Checks that the application does not already contain
+ // // window having the same name
+ // if (name != null && windows.containsKey(name)) {
+ //
+ // // If the window is already added
+ // if (window == windows.get(name)) {
+ // return;
+ // }
+ //
+ // // Otherwise complain
+ // throw new IllegalArgumentException("Window with name '"
+ // + window.getName()
+ // + "' is already present in the application");
+ // }
+ //
+ // // If the name of the window is null, the window is automatically named
+ // if (name == null) {
+ // boolean accepted = false;
+ // while (!accepted) {
+ //
+ // // Try another name
+ // synchronized (this) {
+ // name = String.valueOf(nextWindowId);
+ // nextWindowId++;
+ // }
+ //
+ // if (!windows.containsKey(name)) {
+ // accepted = true;
+ // }
+ // }
+ // window.setName(name);
+ // }
+ //
+ // // Adds the window to application
+ // windows.put(name, window);
+ // window.setApplication(this);
+ //
+ // fireWindowAttachEvent(window);
+ //
+ // // If no main window is set, declare the window to be main window
+ // if (getMainWindow() == null) {
+ // mainWindow = window;
+ // }
+ // }
+
+ // /**
+ // * Send information to all listeners about new Windows associated with
+ // this
+ // * application.
+ // *
+ // * @param window
+ // */
+ // private void fireWindowAttachEvent(Window window) {
+ // // Fires the window attach event
+ // if (windowAttachListeners != null) {
+ // final Object[] listeners = windowAttachListeners.toArray();
+ // final WindowAttachEvent event = new WindowAttachEvent(window);
+ // for (int i = 0; i < listeners.length; i++) {
+ // ((WindowAttachListener) listeners[i]).windowAttached(event);
+ // }
+ // }
+ // }
+
+ // /**
+ // * Removes the specified window from the application.
+ // *
+ // * <p>
+ // * Removing the main window of the Application also sets the main window
+ // to
+ // * null. One must another window to be the main window after this with
+ // * {@link #setMainWindow(Window)}.
+ // * </p>
+ // *
+ // * <p>
+ // * Note that removing window from the application does not close the
+ // browser
+ // * window - the window is only removed from the server-side.
+ // * </p>
+ // *
+ // * @param window
+ // * the window to be removed.
+ // */
+ // public void removeWindow(Window window) {
+ // if (window != null && windows.contains(window)) {
+ //
+ // // Removes the window from application
+ // windows.remove(window.getName());
+ //
+ // // If the window was main window, clear it
+ // if (getMainWindow() == window) {
+ // setMainWindow(null);
+ // }
+ //
+ // // Removes the application from window
+ // if (window.getApplication() == this) {
+ // window.setApplication(null);
+ // }
+ //
+ // fireWindowDetachEvent(window);
+ // }
+ // }
+
+ // private void fireWindowDetachEvent(Window window) {
+ // // Fires the window detach event
+ // if (windowDetachListeners != null) {
+ // final Object[] listeners = windowDetachListeners.toArray();
+ // final WindowDetachEvent event = new WindowDetachEvent(window);
+ // for (int i = 0; i < listeners.length; i++) {
+ // ((WindowDetachListener) listeners[i]).windowDetached(event);
+ // }
+ // }
+ // }
/**
* Gets the user of the application.
@@ -559,18 +572,18 @@ public abstract class Application implements URIHandler,
return applicationIsRunning;
}
- /**
- * Gets the set of windows contained by the application.
- *
- * <p>
- * Note that the returned set of windows can not be modified.
- * </p>
- *
- * @return the Unmodifiable collection of windows.
- */
- public Collection<Window> getWindows() {
- return Collections.unmodifiableCollection(windows.values());
- }
+ // /**
+ // * Gets the set of windows contained by the application.
+ // *
+ // * <p>
+ // * Note that the returned set of windows can not be modified.
+ // * </p>
+ // *
+ // * @return the Unmodifiable collection of windows.
+ // */
+ // public Collection<Window> getWindows() {
+ // return Collections.unmodifiableCollection(windows.values());
+ // }
/**
* <p>
@@ -582,85 +595,87 @@ public abstract class Application implements URIHandler,
*/
public abstract void init();
- /**
- * Gets the application's theme. The application's theme is the default
- * theme used by all the windows in it that do not explicitly specify a
- * theme. If the application theme is not explicitly set, the
- * <code>null</code> is returned.
- *
- * @return the name of the application's theme.
- */
- public String getTheme() {
- return theme;
- }
-
- /**
- * Sets the application's theme.
- * <p>
- * Note that this theme can be overridden in the the application level
- * windows with {@link com.vaadin.ui.Window#setTheme(String)}. Setting theme
- * to be <code>null</code> selects the default theme. For the available
- * theme names, see the contents of the VAADIN/themes directory.
- * </p>
- *
- * @param theme
- * the new theme for this application.
- */
- public void setTheme(String theme) {
- // Collect list of windows not having the current or future theme
- final LinkedList<Window> toBeUpdated = new LinkedList<Window>();
- final String oldAppTheme = getTheme();
- for (final Iterator<Window> i = getWindows().iterator(); i.hasNext();) {
- final Window w = i.next();
- final String windowTheme = w.getTheme();
- if ((windowTheme == null)
- || (!windowTheme.equals(theme) && windowTheme
- .equals(oldAppTheme))) {
- toBeUpdated.add(w);
- }
- }
-
- // Updates the theme
- this.theme = theme;
-
- // Ask windows to update themselves
- for (final Iterator<Window> i = toBeUpdated.iterator(); i.hasNext();) {
- i.next().requestRepaint();
- }
- }
-
- /**
- * Gets the mainWindow of the application.
- *
- * <p>
- * The main window is the window attached to the application URL (
- * {@link #getURL()}) and thus which is show by default to the user.
- * </p>
- * <p>
- * Note that each application must have at least one main window.
- * </p>
- *
- * @return the main window.
- */
- public Window getMainWindow() {
- return mainWindow;
- }
-
- /**
- * <p>
- * Sets the mainWindow. If the main window is not explicitly set, the main
- * window defaults to first created window. Setting window as a main window
- * of this application also adds the window to this application.
- * </p>
- *
- * @param mainWindow
- * the mainWindow to set.
- */
- public void setMainWindow(Window mainWindow) {
-
- addWindow(mainWindow);
- this.mainWindow = mainWindow;
- }
+ // /**
+ // * Gets the application's theme. The application's theme is the default
+ // * theme used by all the windows in it that do not explicitly specify a
+ // * theme. If the application theme is not explicitly set, the
+ // * <code>null</code> is returned.
+ // *
+ // * @return the name of the application's theme.
+ // */
+ // public String getTheme() {
+ // return theme;
+ // }
+
+ // /**
+ // * Sets the application's theme.
+ // * <p>
+ // * Note that this theme can be overridden in the the application level
+ // * windows with {@link com.vaadin.ui.Window#setTheme(String)}. Setting
+ // theme
+ // * to be <code>null</code> selects the default theme. For the available
+ // * theme names, see the contents of the VAADIN/themes directory.
+ // * </p>
+ // *
+ // * @param theme
+ // * the new theme for this application.
+ // */
+ // public void setTheme(String theme) {
+ // // Collect list of windows not having the current or future theme
+ // final LinkedList<Window> toBeUpdated = new LinkedList<Window>();
+ // final String oldAppTheme = getTheme();
+ // for (final Iterator<Window> i = getWindows().iterator(); i.hasNext();) {
+ // final Window w = i.next();
+ // final String windowTheme = w.getTheme();
+ // if ((windowTheme == null)
+ // || (!windowTheme.equals(theme) && windowTheme
+ // .equals(oldAppTheme))) {
+ // toBeUpdated.add(w);
+ // }
+ // }
+ //
+ // // Updates the theme
+ // this.theme = theme;
+ //
+ // // Ask windows to update themselves
+ // for (final Iterator<Window> i = toBeUpdated.iterator(); i.hasNext();) {
+ // i.next().requestRepaint();
+ // }
+ // }
+
+ // /**
+ // * Gets the mainWindow of the application.
+ // *
+ // * <p>
+ // * The main window is the window attached to the application URL (
+ // * {@link #getURL()}) and thus which is show by default to the user.
+ // * </p>
+ // * <p>
+ // * Note that each application must have at least one main window.
+ // * </p>
+ // *
+ // * @return the main window.
+ // */
+ // public Window getMainWindow() {
+ // return mainWindow;
+ // }
+
+ // /**
+ // * <p>
+ // * Sets the mainWindow. If the main window is not explicitly set, the main
+ // * window defaults to first created window. Setting window as a main
+ // window
+ // * of this application also adds the window to this application.
+ // * </p>
+ // *
+ // * @param mainWindow
+ // * the mainWindow to set.
+ // */
+ // public void setMainWindow(Window mainWindow) {
+ //
+ // addWindow(mainWindow);
+ // this.mainWindow = mainWindow;
+ // }
/**
* Returns an enumeration of all the names in this application.
@@ -1060,67 +1075,67 @@ public abstract class Application implements URIHandler,
public void windowDetached(WindowDetachEvent event);
}
- /**
- * Adds the window attach listener.
- *
- * Use this to get notifications each time a window is attached to the
- * application with {@link #addWindow(Window)}.
- *
- * @param listener
- * the window attach listener to add.
- */
- public void addListener(WindowAttachListener listener) {
- if (windowAttachListeners == null) {
- windowAttachListeners = new LinkedList<WindowAttachListener>();
- }
- windowAttachListeners.add(listener);
- }
-
- /**
- * Adds the window detach listener.
- *
- * Use this to get notifications each time a window is remove from the
- * application with {@link #removeWindow(Window)}.
- *
- * @param listener
- * the window detach listener to add.
- */
- public void addListener(WindowDetachListener listener) {
- if (windowDetachListeners == null) {
- windowDetachListeners = new LinkedList<WindowDetachListener>();
- }
- windowDetachListeners.add(listener);
- }
-
- /**
- * Removes the window attach listener.
- *
- * @param listener
- * the window attach listener to remove.
- */
- public void removeListener(WindowAttachListener listener) {
- if (windowAttachListeners != null) {
- windowAttachListeners.remove(listener);
- if (windowAttachListeners.isEmpty()) {
- windowAttachListeners = null;
- }
- }
- }
-
- /**
- * Removes the window detach listener.
- *
- * @param listener
- * the window detach listener to remove.
- */
- public void removeListener(WindowDetachListener listener) {
- if (windowDetachListeners != null) {
- windowDetachListeners.remove(listener);
- if (windowDetachListeners.isEmpty()) {
- windowDetachListeners = null;
- }
- }
- }
+ // /**
+ // * Adds the window attach listener.
+ // *
+ // * Use this to get notifications each time a window is attached to the
+ // * application with {@link #addWindow(Window)}.
+ // *
+ // * @param listener
+ // * the window attach listener to add.
+ // */
+ // public void addListener(WindowAttachListener listener) {
+ // if (windowAttachListeners == null) {
+ // windowAttachListeners = new LinkedList<WindowAttachListener>();
+ // }
+ // windowAttachListeners.add(listener);
+ // }
+
+ // /**
+ // * Adds the window detach listener.
+ // *
+ // * Use this to get notifications each time a window is remove from the
+ // * application with {@link #removeWindow(Window)}.
+ // *
+ // * @param listener
+ // * the window detach listener to add.
+ // */
+ // public void addListener(WindowDetachListener listener) {
+ // if (windowDetachListeners == null) {
+ // windowDetachListeners = new LinkedList<WindowDetachListener>();
+ // }
+ // windowDetachListeners.add(listener);
+ // }
+
+ // /**
+ // * Removes the window attach listener.
+ // *
+ // * @param listener
+ // * the window attach listener to remove.
+ // */
+ // public void removeListener(WindowAttachListener listener) {
+ // if (windowAttachListeners != null) {
+ // windowAttachListeners.remove(listener);
+ // if (windowAttachListeners.isEmpty()) {
+ // windowAttachListeners = null;
+ // }
+ // }
+ // }
+
+ // /**
+ // * Removes the window detach listener.
+ // *
+ // * @param listener
+ // * the window detach listener to remove.
+ // */
+ // public void removeListener(WindowDetachListener listener) {
+ // if (windowDetachListeners != null) {
+ // windowDetachListeners.remove(listener);
+ // if (windowDetachListeners.isEmpty()) {
+ // windowDetachListeners = null;
+ // }
+ // }
+ // }
/**
* Returns the URL user is redirected to on application close. If the URL is
@@ -1906,4 +1921,6 @@ public abstract class Application implements URIHandler,
}
}
+
+ public abstract Root getRoot();
} \ No newline at end of file
diff --git a/src/com/vaadin/RootTestApplication.java b/src/com/vaadin/RootTestApplication.java
new file mode 100644
index 0000000000..c64712ccd6
--- /dev/null
+++ b/src/com/vaadin/RootTestApplication.java
@@ -0,0 +1,22 @@
+package com.vaadin;
+
+import com.vaadin.ui.DefaultRoot;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Root;
+
+public class RootTestApplication extends Application {
+ private final Root root = new DefaultRoot(this, new Label(
+ "Roots, bloody roots"));
+
+ @Override
+ public void init() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public Root getRoot() {
+ return root;
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java b/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java
index 6787b36022..0d092ae29f 100644
--- a/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java
+++ b/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java
@@ -317,7 +317,7 @@ public class ApplicationConfiguration implements EntryPoint {
unknownComponents = new HashMap<String, String>();
}
unknownComponents.put("" + value, key);
- } else if (key == "com.vaadin.ui.Window") {
+ } else if (key == "com.vaadin.ui.DefaultRoot") {
windowId = "" + value;
}
}
diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java
index 84cab80a19..a0a0abb476 100644
--- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java
+++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java
@@ -1,1625 +1,1625 @@
/*
@ITMillApache2LicenseForJavaFiles@
*/
-package com.vaadin.terminal.gwt.server;
-
-import java.io.BufferedWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.io.Serializable;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.net.MalformedURLException;
-import java.security.GeneralSecurityException;
-import java.util.Date;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Properties;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.portlet.ActionRequest;
-import javax.portlet.ActionResponse;
-import javax.portlet.EventRequest;
-import javax.portlet.EventResponse;
-import javax.portlet.GenericPortlet;
-import javax.portlet.MimeResponse;
-import javax.portlet.PortalContext;
-import javax.portlet.PortletConfig;
-import javax.portlet.PortletContext;
-import javax.portlet.PortletException;
-import javax.portlet.PortletRequest;
-import javax.portlet.PortletResponse;
-import javax.portlet.PortletSession;
-import javax.portlet.PortletURL;
-import javax.portlet.RenderRequest;
-import javax.portlet.RenderResponse;
-import javax.portlet.ResourceRequest;
-import javax.portlet.ResourceResponse;
-import javax.portlet.ResourceURL;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletRequestWrapper;
-import javax.servlet.http.HttpServletResponse;
-
-import com.liferay.portal.kernel.util.PortalClassInvoker;
-import com.liferay.portal.kernel.util.PropsUtil;
-import com.vaadin.Application;
-import com.vaadin.Application.SystemMessages;
-import com.vaadin.terminal.DownloadStream;
-import com.vaadin.terminal.Terminal;
-import com.vaadin.terminal.gwt.client.ApplicationConfiguration;
-import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.ui.Window;
-
-/**
- * Portlet 2.0 base class. This replaces the servlet in servlet/portlet 1.0
- * deployments and handles various portlet requests from the browser.
- *
- * TODO Document me!
- *
- * @author peholmst
- */
-public abstract class AbstractApplicationPortlet extends GenericPortlet
- implements Constants {
-
- private static final Logger logger = Logger
- .getLogger(AbstractApplicationPortlet.class.getName());
-
- /**
- * This portlet parameter is used to add styles to the main element. E.g
- * "height:500px" generates a style="height:500px" to the main element.
- */
- public static final String PORTLET_PARAMETER_STYLE = "style";
-
- private static final String PORTAL_PARAMETER_VAADIN_THEME = "vaadin.theme";
-
- // TODO some parts could be shared with AbstractApplicationServlet
-
- // TODO Can we close the application when the portlet is removed? Do we know
- // when the portlet is removed?
-
- // TODO What happens when the portlet window is resized? Do we know when the
- // window is resized?
-
- private Properties applicationProperties;
-
- private boolean productionMode = false;
-
- @Override
- public void init(PortletConfig config) throws PortletException {
- super.init(config);
- // Stores the application parameters into Properties object
- applicationProperties = new Properties();
- for (final Enumeration<String> e = config.getInitParameterNames(); e
- .hasMoreElements();) {
- final String name = e.nextElement();
- applicationProperties.setProperty(name,
- config.getInitParameter(name));
- }
-
- // Overrides with server.xml parameters
- final PortletContext context = config.getPortletContext();
- for (final Enumeration<String> e = context.getInitParameterNames(); e
- .hasMoreElements();) {
- final String name = e.nextElement();
- applicationProperties.setProperty(name,
- context.getInitParameter(name));
- }
- checkProductionMode();
- checkCrossSiteProtection();
- }
-
- private void checkCrossSiteProtection() {
- if (getApplicationOrSystemProperty(
- SERVLET_PARAMETER_DISABLE_XSRF_PROTECTION, "false").equals(
- "true")) {
- /*
- * Print an information/warning message about running with xsrf
- * protection disabled
- */
- logger.warning(WARNING_XSRF_PROTECTION_DISABLED);
- }
- }
-
- /**
- * Checks that the version reported by the client (widgetset) matches that
- * of the server.
- *
- * @param request
- */
- private void checkWidgetsetVersion(PortletRequest request) {
- if (!AbstractApplicationServlet.VERSION.equals(getHTTPRequestParameter(
- request, "wsver"))) {
- logger.warning(String.format(WIDGETSET_MISMATCH_INFO,
- AbstractApplicationServlet.VERSION,
- getHTTPRequestParameter(request, "wsver")));
- }
- }
-
- private void checkProductionMode() {
- // Check if the application is in production mode.
- // We are in production mode if Debug=false or productionMode=true
- if (getApplicationOrSystemProperty(SERVLET_PARAMETER_DEBUG, "true")
- .equals("false")) {
- // "Debug=true" is the old way and should no longer be used
- productionMode = true;
- } else if (getApplicationOrSystemProperty(
- SERVLET_PARAMETER_PRODUCTION_MODE, "false").equals("true")) {
- // "productionMode=true" is the real way to do it
- productionMode = true;
- }
-
- if (!productionMode) {
- /* Print an information/warning message about running in debug mode */
- // TODO Maybe we need a different message for portlets?
- logger.warning(NOT_PRODUCTION_MODE_INFO);
- }
- }
-
- /**
- * Gets an application property value.
- *
- * @param parameterName
- * the Name or the parameter.
- * @return String value or null if not found
- */
- protected String getApplicationProperty(String parameterName) {
-
- String val = applicationProperties.getProperty(parameterName);
- if (val != null) {
- return val;
- }
-
- // Try lower case application properties for backward compatibility with
- // 3.0.2 and earlier
- val = applicationProperties.getProperty(parameterName.toLowerCase());
-
- return val;
- }
-
- /**
- * Gets an system property value.
- *
- * @param parameterName
- * the Name or the parameter.
- * @return String value or null if not found
- */
- protected String getSystemProperty(String parameterName) {
- String val = null;
-
- String pkgName;
- final Package pkg = getClass().getPackage();
- if (pkg != null) {
- pkgName = pkg.getName();
- } else {
- final String className = getClass().getName();
- pkgName = new String(className.toCharArray(), 0,
- className.lastIndexOf('.'));
- }
- val = System.getProperty(pkgName + "." + parameterName);
- if (val != null) {
- return val;
- }
-
- // Try lowercased system properties
- val = System.getProperty(pkgName + "." + parameterName.toLowerCase());
- return val;
- }
-
- /**
- * Gets an application or system property value.
- *
- * @param parameterName
- * the Name or the parameter.
- * @param defaultValue
- * the Default to be used.
- * @return String value or default if not found
- */
- protected String getApplicationOrSystemProperty(String parameterName,
- String defaultValue) {
-
- String val = null;
-
- // Try application properties
- val = getApplicationProperty(parameterName);
- if (val != null) {
- return val;
- }
-
- // Try system properties
- val = getSystemProperty(parameterName);
- if (val != null) {
- return val;
- }
-
- return defaultValue;
- }
-
- /**
- * Return the URL from where static files, e.g. the widgetset and the theme,
- * are served. In a standard configuration the VAADIN folder inside the
- * returned folder is what is used for widgetsets and themes.
- *
- * @param request
- * @return The location of static resources (inside which there should be a
- * VAADIN directory). Does not end with a slash (/).
- */
- protected String getStaticFilesLocation(PortletRequest request) {
- // TODO allow overriding on portlet level?
- String staticFileLocation = getPortalProperty(
- Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH,
- request.getPortalContext());
- if (staticFileLocation != null) {
- // remove trailing slash if any
- while (staticFileLocation.endsWith(".")) {
- staticFileLocation = staticFileLocation.substring(0,
- staticFileLocation.length() - 1);
- }
- return staticFileLocation;
- } else {
- // default for Liferay
- return "/html";
- }
- }
-
- protected enum RequestType {
- FILE_UPLOAD, UIDL, RENDER, STATIC_FILE, APPLICATION_RESOURCE, DUMMY, EVENT, ACTION, UNKNOWN;
- }
-
- protected RequestType getRequestType(PortletRequest request) {
- if (request instanceof RenderRequest) {
- return RequestType.RENDER;
- } else if (request instanceof ResourceRequest) {
- if (isUIDLRequest((ResourceRequest) request)) {
- return RequestType.UIDL;
- } else if (isFileUploadRequest((ResourceRequest) request)) {
- return RequestType.FILE_UPLOAD;
- } else if (isApplicationResourceRequest((ResourceRequest) request)) {
- return RequestType.APPLICATION_RESOURCE;
- } else if (isDummyRequest((ResourceRequest) request)) {
- return RequestType.DUMMY;
- } else {
- return RequestType.STATIC_FILE;
- }
- } else if (request instanceof ActionRequest) {
- return RequestType.ACTION;
- } else if (request instanceof EventRequest) {
- return RequestType.EVENT;
- }
- return RequestType.UNKNOWN;
- }
-
- private boolean isApplicationResourceRequest(ResourceRequest request) {
- return request.getResourceID() != null
- && request.getResourceID().startsWith("APP");
- }
-
- private boolean isUIDLRequest(ResourceRequest request) {
- return request.getResourceID() != null
- && request.getResourceID().equals("UIDL");
- }
-
- private boolean isDummyRequest(ResourceRequest request) {
- return request.getResourceID() != null
- && request.getResourceID().equals("DUMMY");
- }
-
- private boolean isFileUploadRequest(ResourceRequest request) {
- return "UPLOAD".equals(request.getResourceID());
- }
-
- /**
- * Returns true if the servlet is running in production mode. Production
- * mode disables all debug facilities.
- *
- * @return true if in production mode, false if in debug mode
- */
- public boolean isProductionMode() {
- return productionMode;
- }
-
- protected void handleRequest(PortletRequest request,
- PortletResponse response) throws PortletException, IOException {
- RequestType requestType = getRequestType(request);
-
- if (requestType == RequestType.UNKNOWN) {
- handleUnknownRequest(request, response);
- } else if (requestType == RequestType.DUMMY) {
- /*
- * This dummy page is used by action responses to redirect to, in
- * order to prevent the boot strap code from being rendered into
- * strange places such as iframes.
- */
- ((ResourceResponse) response).setContentType("text/html");
- final OutputStream out = ((ResourceResponse) response)
- .getPortletOutputStream();
- final PrintWriter outWriter = new PrintWriter(new BufferedWriter(
- new OutputStreamWriter(out, "UTF-8")));
- outWriter.print("<html><body>dummy page</body></html>");
- outWriter.close();
- } else if (requestType == RequestType.STATIC_FILE) {
- serveStaticResources((ResourceRequest) request,
- (ResourceResponse) response);
- } else {
- Application application = null;
- boolean transactionStarted = false;
- boolean requestStarted = false;
-
- try {
- // TODO What about PARAM_UNLOADBURST & redirectToApplication??
-
- /* Find out which application this request is related to */
- application = findApplicationInstance(request, requestType);
- if (application == null) {
- return;
- }
-
- /*
- * Get or create an application context and an application
- * manager for the session
- */
- PortletApplicationContext2 applicationContext = getApplicationContext(request
- .getPortletSession());
- applicationContext.setResponse(response);
- applicationContext.setPortletConfig(getPortletConfig());
-
- PortletCommunicationManager applicationManager = applicationContext
- .getApplicationManager(application);
-
- /* Update browser information from request */
- updateBrowserProperties(applicationContext.getBrowser(),
- request);
-
- /*
- * Call application requestStart before Application.init() is
- * called (bypasses the limitation in TransactionListener)
- */
- if (application instanceof PortletRequestListener) {
- ((PortletRequestListener) application).onRequestStart(
- request, response);
- requestStarted = true;
- }
-
- /* Start the newly created application */
- startApplication(request, application, applicationContext);
-
- /*
- * Transaction starts. Call transaction listeners. Transaction
- * end is called in the finally block below.
- */
- applicationContext.startTransaction(application, request);
- transactionStarted = true;
-
- /* Notify listeners */
-
- // Finds the window within the application
- Window window = null;
- synchronized (application) {
- if (application.isRunning()) {
- switch (requestType) {
- case FILE_UPLOAD:
- // no window
- break;
- case APPLICATION_RESOURCE:
- // use main window - should not need any window
- window = application.getMainWindow();
- break;
- default:
- window = applicationManager.getApplicationWindow(
- request, this, application, null);
- }
- // if window not found, not a problem - use null
- }
- }
-
- // TODO Should this happen before or after the transaction
- // starts?
- if (request instanceof RenderRequest) {
- applicationContext.firePortletRenderRequest(application,
- window, (RenderRequest) request,
- (RenderResponse) response);
- } else if (request instanceof ActionRequest) {
- applicationContext.firePortletActionRequest(application,
- window, (ActionRequest) request,
- (ActionResponse) response);
- } else if (request instanceof EventRequest) {
- applicationContext.firePortletEventRequest(application,
- window, (EventRequest) request,
- (EventResponse) response);
- } else if (request instanceof ResourceRequest) {
- applicationContext.firePortletResourceRequest(application,
- window, (ResourceRequest) request,
- (ResourceResponse) response);
- }
-
- /* Handle the request */
- if (requestType == RequestType.FILE_UPLOAD) {
- applicationManager.handleFileUpload(
- (ResourceRequest) request,
- (ResourceResponse) response);
- return;
- } else if (requestType == RequestType.UIDL) {
- // Handles AJAX UIDL requests
- if (isRepaintAll(request)) {
- // warn if versions do not match
- checkWidgetsetVersion(request);
- }
- applicationManager.handleUidlRequest(
- (ResourceRequest) request,
- (ResourceResponse) response, this, window);
- return;
- } else {
- /*
- * Removes the application if it has stopped
- */
- if (!application.isRunning()) {
- endApplication(request, response, application);
- return;
- }
-
- handleOtherRequest(request, response, requestType,
- application, window, applicationContext,
- applicationManager);
- }
- } catch (final SessionExpiredException e) {
- // TODO Figure out a better way to deal with
- // SessionExpiredExceptions
- logger.finest("A user session has expired");
- } catch (final GeneralSecurityException e) {
- // TODO Figure out a better way to deal with
- // GeneralSecurityExceptions
- logger.fine("General security exception, the security key was probably incorrect.");
- } catch (final Throwable e) {
- handleServiceException(request, response, application, e);
- } finally {
- // Notifies transaction end
- try {
- if (transactionStarted) {
- ((PortletApplicationContext2) application.getContext())
- .endTransaction(application, request);
- }
- } finally {
- if (requestStarted) {
- ((PortletRequestListener) application).onRequestEnd(
- request, response);
-
- }
- }
- }
- }
- }
-
- private void handleUnknownRequest(PortletRequest request,
- PortletResponse response) {
- logger.warning("Unknown request type");
- }
-
- /**
- * Handle a portlet request that is not for static files, UIDL or upload.
- * Also render requests are handled here.
- *
- * This method is called after starting the application and calling portlet
- * and transaction listeners.
- *
- * @param request
- * @param response
- * @param requestType
- * @param application
- * @param applicationContext
- * @param applicationManager
- * @throws PortletException
- * @throws IOException
- * @throws MalformedURLException
- */
- private void handleOtherRequest(PortletRequest request,
- PortletResponse response, RequestType requestType,
- Application application, Window window,
- PortletApplicationContext2 applicationContext,
- PortletCommunicationManager applicationManager)
- throws PortletException, IOException, MalformedURLException {
- if (window == null) {
- throw new PortletException(ERROR_NO_WINDOW_FOUND);
- }
-
- /*
- * Sets terminal type for the window, if not already set
- */
- if (window.getTerminal() == null) {
- window.setTerminal(applicationContext.getBrowser());
- }
-
- /*
- * Handle parameters
- */
- final Map<String, String[]> parameters = request.getParameterMap();
- if (window != null && parameters != null) {
- window.handleParameters(parameters);
- }
-
- if (requestType == RequestType.APPLICATION_RESOURCE) {
- handleURI(applicationManager, window, (ResourceRequest) request,
- (ResourceResponse) response);
- } else if (requestType == RequestType.RENDER) {
- writeAjaxPage((RenderRequest) request, (RenderResponse) response,
- window, application);
- } else if (requestType == RequestType.EVENT) {
- // nothing to do, listeners do all the work
- } else if (requestType == RequestType.ACTION) {
- // nothing to do, listeners do all the work
- } else {
- throw new IllegalStateException(
- "handleRequest() without anything to do - should never happen!");
- }
- }
-
- private void updateBrowserProperties(WebBrowser browser,
- PortletRequest request) {
- String userAgent = getHTTPHeader(request, "user-agent");
- browser.updateRequestDetails(request.getLocale(), null,
- request.isSecure(), userAgent);
- if (getHTTPRequestParameter(request, "repaintAll") != null) {
- browser.updateClientSideDetails(
- getHTTPRequestParameter(request, "sw"),
- getHTTPRequestParameter(request, "sh"),
- getHTTPRequestParameter(request, "tzo"),
- getHTTPRequestParameter(request, "rtzo"),
- getHTTPRequestParameter(request, "dstd"),
- getHTTPRequestParameter(request, "dstActive"),
- getHTTPRequestParameter(request, "curdate"),
- getHTTPRequestParameter(request, "td") != null);
- }
- }
-
- @Override
- public void processEvent(EventRequest request, EventResponse response)
- throws PortletException, IOException {
- handleRequest(request, response);
- }
-
- private boolean handleURI(PortletCommunicationManager applicationManager,
- Window window, ResourceRequest request, ResourceResponse response)
- throws IOException {
- // Handles the URI
- DownloadStream download = applicationManager.handleURI(window, request,
- response, this);
-
- // A download request
- if (download != null) {
- // Client downloads an resource
- handleDownload(download, request, response);
- return true;
- }
-
- return false;
- }
-
- private void handleDownload(DownloadStream stream, ResourceRequest request,
- ResourceResponse response) throws IOException {
-
- if (stream.getParameter("Location") != null) {
- response.setProperty(ResourceResponse.HTTP_STATUS_CODE,
- Integer.toString(HttpServletResponse.SC_MOVED_TEMPORARILY));
- response.setProperty("Location", stream.getParameter("Location"));
- return;
- }
-
- // Download from given stream
- final InputStream data = stream.getStream();
- if (data != null) {
-
- OutputStream out = null;
- try {
-
- // Sets content type
- response.setContentType(stream.getContentType());
-
- // Sets cache headers
- final long cacheTime = stream.getCacheTime();
- if (cacheTime <= 0) {
- response.setProperty("Cache-Control", "no-cache");
- response.setProperty("Pragma", "no-cache");
- response.setProperty("Expires", "0");
- } else {
- response.setProperty("Cache-Control", "max-age="
- + cacheTime / 1000);
- response.setProperty("Expires",
- "" + System.currentTimeMillis() + cacheTime);
- // Required to apply caching in some Tomcats
- response.setProperty("Pragma", "cache");
- }
-
- // Copy download stream parameters directly
- // to HTTP headers.
- final Iterator<String> i = stream.getParameterNames();
- if (i != null) {
- while (i.hasNext()) {
- final String param = i.next();
- response.setProperty(param, stream.getParameter(param));
- }
- }
-
- // suggest local filename from DownloadStream if
- // Content-Disposition
- // not explicitly set
- String contentDispositionValue = stream
- .getParameter("Content-Disposition");
- if (contentDispositionValue == null) {
- contentDispositionValue = "filename=\""
- + stream.getFileName() + "\"";
- response.setProperty("Content-Disposition",
- contentDispositionValue);
- }
-
- int bufferSize = stream.getBufferSize();
- if (bufferSize <= 0 || bufferSize > MAX_BUFFER_SIZE) {
- bufferSize = DEFAULT_BUFFER_SIZE;
- }
- final byte[] buffer = new byte[bufferSize];
- int bytesRead = 0;
-
- out = response.getPortletOutputStream();
-
- while ((bytesRead = data.read(buffer)) > 0) {
- out.write(buffer, 0, bytesRead);
- out.flush();
- }
- } finally {
- AbstractCommunicationManager.tryToCloseStream(data);
- AbstractCommunicationManager.tryToCloseStream(out);
- }
- }
- }
-
- private void serveStaticResources(ResourceRequest request,
- ResourceResponse response) throws IOException, PortletException {
- final String resourceID = request.getResourceID();
- final PortletContext pc = getPortletContext();
-
- InputStream is = pc.getResourceAsStream(resourceID);
- if (is != null) {
- final String mimetype = pc.getMimeType(resourceID);
- if (mimetype != null) {
- response.setContentType(mimetype);
- }
- final OutputStream os = response.getPortletOutputStream();
- final byte buffer[] = new byte[DEFAULT_BUFFER_SIZE];
- int bytes;
- while ((bytes = is.read(buffer)) >= 0) {
- os.write(buffer, 0, bytes);
- }
- } else {
- logger.info("Requested resource [" + resourceID
- + "] could not be found");
- response.setProperty(ResourceResponse.HTTP_STATUS_CODE,
- Integer.toString(HttpServletResponse.SC_NOT_FOUND));
- }
- }
-
- @Override
- public void processAction(ActionRequest request, ActionResponse response)
- throws PortletException, IOException {
- handleRequest(request, response);
- }
-
- @Override
- protected void doDispatch(RenderRequest request, RenderResponse response)
- throws PortletException, IOException {
- try {
- // try to let super handle - it'll call methods annotated for
- // handling, the default doXYZ(), or throw if a handler for the mode
- // is not found
- super.doDispatch(request, response);
-
- } catch (PortletException e) {
- if (e.getCause() == null) {
- // No cause interpreted as 'unknown mode' - pass that trough
- // so that the application can handle
- handleRequest(request, response);
-
- } else {
- // Something else failed, pass on
- throw e;
- }
- }
- }
-
- @Override
- public void serveResource(ResourceRequest request, ResourceResponse response)
- throws PortletException, IOException {
- handleRequest(request, response);
- }
-
- boolean requestCanCreateApplication(PortletRequest request,
- RequestType requestType) {
- if (requestType == RequestType.UIDL && isRepaintAll(request)) {
- return true;
- } else if (requestType == RequestType.RENDER) {
- // In most cases the first request is a render request that renders
- // the HTML fragment. This should create an application instance.
- return true;
- } else if (requestType == RequestType.EVENT) {
- // A portlet can also be sent an event even though it has not been
- // rendered, e.g. portlet on one page sends an event to a portlet on
- // another page and then moves the user to that page.
- return true;
- }
- return false;
- }
-
- private boolean isRepaintAll(PortletRequest request) {
- return (request.getParameter(URL_PARAMETER_REPAINT_ALL) != null)
- && (request.getParameter(URL_PARAMETER_REPAINT_ALL).equals("1"));
- }
-
- private void startApplication(PortletRequest request,
- Application application, PortletApplicationContext2 context)
- throws PortletException, MalformedURLException {
- if (!application.isRunning()) {
- Locale locale = request.getLocale();
- application.setLocale(locale);
- // No application URL when running inside a portlet
- application.start(null, applicationProperties, context);
- }
- }
-
- private void endApplication(PortletRequest request,
- PortletResponse response, Application application)
- throws IOException {
- final PortletSession session = request.getPortletSession();
- if (session != null) {
- getApplicationContext(session).removeApplication(application);
- }
- // Do not send any redirects when running inside a portlet.
- }
-
- private Application findApplicationInstance(PortletRequest request,
- RequestType requestType) throws PortletException,
- SessionExpiredException, MalformedURLException {
-
- boolean requestCanCreateApplication = requestCanCreateApplication(
- request, requestType);
-
- /* Find an existing application for this request. */
- Application application = getExistingApplication(request,
- requestCanCreateApplication);
-
- if (application != null) {
- /*
- * There is an existing application. We can use this as long as the
- * user not specifically requested to close or restart it.
- */
-
- final boolean restartApplication = (getHTTPRequestParameter(
- request, URL_PARAMETER_RESTART_APPLICATION) != null);
- final boolean closeApplication = (getHTTPRequestParameter(request,
- URL_PARAMETER_CLOSE_APPLICATION) != null);
-
- if (restartApplication) {
- closeApplication(application, request.getPortletSession(false));
- return createApplication(request);
- } else if (closeApplication) {
- closeApplication(application, request.getPortletSession(false));
- return null;
- } else {
- return application;
- }
- }
-
- // No existing application was found
-
- if (requestCanCreateApplication) {
- return createApplication(request);
- } else {
- throw new SessionExpiredException();
- }
- }
-
- private void closeApplication(Application application,
- PortletSession session) {
- if (application == null) {
- return;
- }
-
- application.close();
- if (session != null) {
- PortletApplicationContext2 context = getApplicationContext(session);
- context.removeApplication(application);
- }
- }
-
- private Application createApplication(PortletRequest request)
- throws PortletException, MalformedURLException {
- Application newApplication = getNewApplication(request);
- final PortletApplicationContext2 context = getApplicationContext(request
- .getPortletSession());
- context.addApplication(newApplication, request.getWindowID());
- return newApplication;
- }
-
- private Application getExistingApplication(PortletRequest request,
- boolean allowSessionCreation) throws MalformedURLException,
- SessionExpiredException {
-
- final PortletSession session = request
- .getPortletSession(allowSessionCreation);
-
- if (session == null) {
- throw new SessionExpiredException();
- }
-
- PortletApplicationContext2 context = getApplicationContext(session);
- Application application = context.getApplicationForWindowId(request
- .getWindowID());
- if (application == null) {
- return null;
- }
- if (application.isRunning()) {
- return application;
- }
- // application found but not running
- context.removeApplication(application);
-
- return null;
- }
-
- /**
- * Returns the URL from which the widgetset is served on the portal.
- *
- * @param widgetset
- * @param request
- * @return
- */
- protected String getWidgetsetURL(String widgetset, PortletRequest request) {
- return getStaticFilesLocation(request) + "/" + WIDGETSET_DIRECTORY_PATH
- + widgetset + "/" + widgetset + ".nocache.js?"
- + new Date().getTime();
- }
-
- /**
- * Returns the theme URI for the named theme on the portal.
- *
- * Note that this is not the only location referring to the theme URI - also
- * e.g. PortletCommunicationManager uses its own way to access the portlet
- * 2.0 theme resources.
- *
- * @param themeName
- * @param request
- * @return
- */
- protected String getThemeURI(String themeName, PortletRequest request) {
- return getStaticFilesLocation(request) + "/" + THEME_DIRECTORY_PATH
- + themeName;
- }
-
- /**
- * Writes the html host page (aka kickstart page) that starts the actual
- * Vaadin application.
- *
- * If one needs to override parts of the portlet HTML contents creation, it
- * is suggested that one overrides one of several submethods including:
- * <ul>
- * <li>
- * {@link #writeAjaxPageHtmlMainDiv(RenderRequest, RenderResponse, BufferedWriter, String)}
- * <li>
- * {@link #getVaadinConfigurationMap(RenderRequest, RenderResponse, Application, String)}
- * <li>
- * {@link #writeAjaxPageHtmlVaadinScripts(RenderRequest, RenderResponse, BufferedWriter, Application, String)}
- * </ul>
- *
- * @param request
- * the portlet request.
- * @param response
- * the portlet response to write to.
- * @param window
- * @param application
- * @throws IOException
- * if the writing failed due to input/output error.
- * @throws MalformedURLException
- * if the application is denied access the persistent data store
- * represented by the given URL.
- * @throws PortletException
- */
- protected void writeAjaxPage(RenderRequest request,
- RenderResponse response, Window window, Application application)
- throws IOException, MalformedURLException, PortletException {
-
- response.setContentType("text/html");
- final BufferedWriter page = new BufferedWriter(new OutputStreamWriter(
- response.getPortletOutputStream(), "UTF-8"));
-
- // TODO Currently, we can only load widgetsets and themes from the
- // portal
-
- String themeName = getThemeForWindow(request, window);
-
- writeAjaxPageHtmlVaadinScripts(request, response, page, application,
- themeName);
-
- /*- Add classnames;
- * .v-app
- * .v-app-loading
- * .v-app-<simpleName for app class>
- * .v-theme-<themeName, remove non-alphanum>
- */
- String appClass = "v-app-";
- try {
- appClass += getApplicationClass().getSimpleName();
- } catch (ClassNotFoundException e) {
- appClass += "unknown";
- logger.log(Level.SEVERE, "Could not find application class", e);
- }
- String themeClass = "v-theme-"
- + themeName.replaceAll("[^a-zA-Z0-9]", "");
-
- String classNames = "v-app " + themeClass + " " + appClass;
-
- String style = getApplicationProperty(PORTLET_PARAMETER_STYLE);
- String divStyle = "";
- if (style != null) {
- divStyle = "style=\"" + style + "\"";
- }
-
- writeAjaxPageHtmlMainDiv(request, response, page,
- getApplicationDomId(request), classNames, divStyle);
-
- page.close();
- }
-
- /**
- * Creates and returns a unique ID for the DIV where the application is to
- * be rendered. We need to generate a unique ID because some portals already
- * create a DIV with the portlet's Window ID as the DOM ID.
- *
- * @param request
- * PortletRequest
- * @return the id to use in the DOM
- */
- private String getApplicationDomId(PortletRequest request) {
- return "v-" + request.getWindowID();
- }
-
- /**
- * This method writes the scripts to load the widgetset and the themes as
- * well as define Vaadin configuration parameters on the HTML fragment that
- * starts the actual Vaadin application.
- *
- * @param request
- * @param response
- * @param writer
- * @param application
- * @param themeName
- * @throws IOException
- * @throws PortletException
- */
- protected void writeAjaxPageHtmlVaadinScripts(RenderRequest request,
- RenderResponse response, final BufferedWriter writer,
- Application application, String themeName) throws IOException,
- PortletException {
- String themeURI = getThemeURI(themeName, request);
-
- // fixed base theme to use - all portal pages with Vaadin
- // applications will load this exactly once
- String portalTheme = getPortalProperty(PORTAL_PARAMETER_VAADIN_THEME,
- request.getPortalContext());
-
- writer.write("<script type=\"text/javascript\">\n");
- writer.write("if(!vaadin || !vaadin.vaadinConfigurations) {\n "
- + "if(!vaadin) { var vaadin = {}} \n"
- + "vaadin.vaadinConfigurations = {};\n"
- + "if (!vaadin.themesLoaded) { vaadin.themesLoaded = {}; }\n");
- if (!isProductionMode()) {
- writer.write("vaadin.debug = true;\n");
- }
-
- writeAjaxPageScriptWidgetset(request, response, writer);
-
- Map<String, String> config = getVaadinConfigurationMap(request,
- response, application, themeURI);
- writeAjaxPageScriptConfigurations(request, response, writer, config);
-
- writer.write("</script>\n");
-
- writeAjaxPageHtmlTheme(request, writer, themeName, themeURI,
- portalTheme);
-
- // TODO Warn if widgetset has not been loaded after 15 seconds
- }
-
- /**
- * Writes the script to load the widgetset on the HTML fragment created by
- * the portlet.
- *
- * @param request
- * @param response
- * @param writer
- * @throws IOException
- */
- protected void writeAjaxPageScriptWidgetset(RenderRequest request,
- RenderResponse response, final BufferedWriter writer)
- throws IOException {
- String requestWidgetset = getApplicationOrSystemProperty(
- PARAMETER_WIDGETSET, null);
- String sharedWidgetset = getPortalProperty(
- PORTAL_PARAMETER_VAADIN_WIDGETSET, request.getPortalContext());
-
- String widgetset;
- if (requestWidgetset != null) {
- widgetset = requestWidgetset;
- } else if (sharedWidgetset != null) {
- widgetset = sharedWidgetset;
- } else {
- widgetset = DEFAULT_WIDGETSET;
- }
- String widgetsetURL = getWidgetsetURL(widgetset, request);
- writer.write("document.write('<iframe tabIndex=\"-1\" id=\"__gwt_historyFrame\" "
- + "style=\"position:absolute;width:0;height:0;border:0;overflow:"
- + "hidden;opacity:0;top:-100px;left:-100px;\" src=\"javascript:false\"></iframe>');\n");
- writer.write("document.write(\"<script language='javascript' src='"
- + widgetsetURL + "'><\\/script>\");\n}\n");
- }
-
- /**
- * Returns the configuration parameters to pass to the client.
- *
- * To add configuration parameters for the client, override, call the super
- * method and then modify the map. Overriding this method may also require
- * client side changes in {@link ApplicationConnection} and
- * {@link ApplicationConfiguration}.
- *
- * Note that this method must escape and quote the values when appropriate.
- *
- * The map returned is typically a {@link LinkedHashMap} to preserve
- * insertion order, but it is not guaranteed to be one.
- *
- * @param request
- * @param response
- * @param application
- * @param themeURI
- * @return modifiable Map from parameter name to its full value
- * @throws PortletException
- */
- protected Map<String, String> getVaadinConfigurationMap(
- RenderRequest request, RenderResponse response,
- Application application, String themeURI) throws PortletException {
- Map<String, String> config = new LinkedHashMap<String, String>();
-
- /*
- * We need this in order to get uploads to work. TODO this is not needed
- * for uploads anymore, check if this is needed for some other things
- */
- PortletURL appUri = response.createActionURL();
- config.put("appUri", "'" + appUri.toString() + "'");
- config.put("usePortletURLs", "true");
- ResourceURL uidlUrlBase = response.createResourceURL();
- uidlUrlBase.setResourceID("UIDL");
- config.put("portletUidlURLBase", "'" + uidlUrlBase.toString() + "'");
- config.put("pathInfo", "''");
- config.put("themeUri", "'" + themeURI + "'");
-
- String versionInfo = "{vaadinVersion:\""
- + AbstractApplicationServlet.VERSION
- + "\",applicationVersion:\"" + application.getVersion() + "\"}";
- config.put("versionInfo", versionInfo);
-
- // Get system messages
- Application.SystemMessages systemMessages = null;
- try {
- systemMessages = getSystemMessages();
- } catch (SystemMessageException e) {
- // failing to get the system messages is always a problem
- throw new PortletException("Failed to obtain system messages!", e);
- }
- if (systemMessages != null) {
- // Write the CommunicationError -message to client
- String caption = systemMessages.getCommunicationErrorCaption();
- if (caption != null) {
- caption = "\"" + caption + "\"";
- }
- String message = systemMessages.getCommunicationErrorMessage();
- if (message != null) {
- message = "\"" + message + "\"";
- }
- String url = systemMessages.getCommunicationErrorURL();
- if (url != null) {
- url = "\"" + url + "\"";
- }
-
- config.put("\"comErrMsg\"", "{" + "\"caption\":" + caption + ","
- + "\"message\" : " + message + "," + "\"url\" : " + url
- + "}");
-
- // Write the AuthenticationError -message to client
- caption = systemMessages.getAuthenticationErrorCaption();
- if (caption != null) {
- caption = "\"" + caption + "\"";
- }
- message = systemMessages.getAuthenticationErrorMessage();
- if (message != null) {
- message = "\"" + message + "\"";
- }
- url = systemMessages.getAuthenticationErrorURL();
- if (url != null) {
- url = "\"" + url + "\"";
- }
-
- config.put("\"authErrMsg\"", "{" + "\"caption\":" + caption + ","
- + "\"message\" : " + message + "," + "\"url\" : " + url
- + "}");
- }
-
- return config;
- }
-
- /**
- * Constructs the Vaadin configuration section for
- * {@link ApplicationConnection} and {@link ApplicationConfiguration}.
- *
- * Typically this method should not be overridden. Instead, modify
- * {@link #getVaadinConfigurationMap(RenderRequest, RenderResponse, Application, String)}
- * .
- *
- * @param request
- * @param response
- * @param writer
- * @param config
- * @throws IOException
- * @throws PortletException
- */
- protected void writeAjaxPageScriptConfigurations(RenderRequest request,
- RenderResponse response, final BufferedWriter writer,
- Map<String, String> config) throws IOException, PortletException {
-
- writer.write("vaadin.vaadinConfigurations[\""
- + getApplicationDomId(request) + "\"] = {");
-
- Iterator<String> keyIt = config.keySet().iterator();
- while (keyIt.hasNext()) {
- String key = keyIt.next();
- writer.write(key + ": " + config.get(key));
- if (keyIt.hasNext()) {
- writer.write(", ");
- }
- }
-
- writer.write("};\n");
- }
-
- /**
- * Writes the Vaadin theme loading section of the portlet HTML. Loads both
- * the portal theme and the portlet theme in this order, skipping loading of
- * themes that are already loaded (matched by name).
- *
- * @param request
- * @param writer
- * @param themeName
- * @param themeURI
- * @param portalTheme
- * @throws IOException
- */
- protected void writeAjaxPageHtmlTheme(RenderRequest request,
- final BufferedWriter writer, String themeName, String themeURI,
- String portalTheme) throws IOException {
- writer.write("<script type=\"text/javascript\">\n");
-
- if (portalTheme == null) {
- portalTheme = DEFAULT_THEME_NAME;
- }
-
- writer.write("if(!vaadin.themesLoaded['" + portalTheme + "']) {\n");
- writer.write("var defaultStylesheet = document.createElement('link');\n");
- writer.write("defaultStylesheet.setAttribute('rel', 'stylesheet');\n");
- writer.write("defaultStylesheet.setAttribute('type', 'text/css');\n");
- writer.write("defaultStylesheet.setAttribute('href', '"
- + getThemeURI(portalTheme, request) + "/styles.css');\n");
- writer.write("document.getElementsByTagName('head')[0].appendChild(defaultStylesheet);\n");
- writer.write("vaadin.themesLoaded['" + portalTheme + "'] = true;\n}\n");
-
- if (!portalTheme.equals(themeName)) {
- writer.write("if(!vaadin.themesLoaded['" + themeName + "']) {\n");
- writer.write("var stylesheet = document.createElement('link');\n");
- writer.write("stylesheet.setAttribute('rel', 'stylesheet');\n");
- writer.write("stylesheet.setAttribute('type', 'text/css');\n");
- writer.write("stylesheet.setAttribute('href', '" + themeURI
- + "/styles.css');\n");
- writer.write("document.getElementsByTagName('head')[0].appendChild(stylesheet);\n");
- writer.write("vaadin.themesLoaded['" + themeName
- + "'] = true;\n}\n");
- }
-
- writer.write("</script>\n");
- }
-
- /**
- * Method to write the div element into which that actual Vaadin application
- * is rendered.
- * <p>
- * Override this method if you want to add some custom html around around
- * the div element into which the actual Vaadin application will be
- * rendered.
- *
- * @param request
- * @param response
- * @param writer
- * @param id
- * @param classNames
- * @param divStyle
- * @throws IOException
- */
- protected void writeAjaxPageHtmlMainDiv(RenderRequest request,
- RenderResponse response, final BufferedWriter writer, String id,
- String classNames, String divStyle) throws IOException {
- writer.write("<div id=\"" + id + "\" class=\"" + classNames + "\" "
- + divStyle + ">");
- writer.write("<div class=\"v-app-loading\"></div>");
- writer.write("</div>\n");
- writer.write("<noscript>" + getNoScriptMessage() + "</noscript>");
- }
-
- /**
- * Returns a message printed for browsers without scripting support or if
- * browsers scripting support is disabled.
- */
- protected String getNoScriptMessage() {
- return "You have to enable javascript in your browser to use an application built with Vaadin.";
- }
-
- /**
- * Returns the theme for given request/window
- *
- * @param request
- * @param window
- * @return
- */
- protected String getThemeForWindow(PortletRequest request, Window window) {
- // Finds theme name
- String themeName;
-
- // theme defined for the window?
- themeName = window.getTheme();
-
- if (themeName == null) {
- // no, is the default theme defined by the portal?
- themeName = getPortalProperty(
- Constants.PORTAL_PARAMETER_VAADIN_THEME,
- request.getPortalContext());
- }
-
- if (themeName == null) {
- // no, using the default theme defined by Vaadin
- themeName = DEFAULT_THEME_NAME;
- }
-
- return themeName;
- }
-
- protected abstract Class<? extends Application> getApplicationClass()
- throws ClassNotFoundException;
-
- protected Application getNewApplication(PortletRequest request)
- throws PortletException {
- try {
- final Application application = getApplicationClass().newInstance();
- return application;
- } catch (final IllegalAccessException e) {
- throw new PortletException("getNewApplication failed", e);
- } catch (final InstantiationException e) {
- throw new PortletException("getNewApplication failed", e);
- } catch (final ClassNotFoundException e) {
- throw new PortletException("getNewApplication failed", e);
- }
- }
-
- protected ClassLoader getClassLoader() throws PortletException {
- // TODO Add support for custom class loader
- return getClass().getClassLoader();
- }
-
- /**
- * Get system messages from the current application class
- *
- * @return
- */
- protected SystemMessages getSystemMessages() {
- try {
- Class<? extends Application> appCls = getApplicationClass();
- Method m = appCls.getMethod("getSystemMessages", (Class[]) null);
- return (Application.SystemMessages) m.invoke(null, (Object[]) null);
- } catch (ClassNotFoundException e) {
- // This should never happen
- throw new SystemMessageException(e);
- } catch (SecurityException e) {
- throw new SystemMessageException(
- "Application.getSystemMessage() should be static public", e);
- } catch (NoSuchMethodException e) {
- // This is completely ok and should be silently ignored
- } catch (IllegalArgumentException e) {
- // This should never happen
- throw new SystemMessageException(e);
- } catch (IllegalAccessException e) {
- throw new SystemMessageException(
- "Application.getSystemMessage() should be static public", e);
- } catch (InvocationTargetException e) {
- // This should never happen
- throw new SystemMessageException(e);
- }
- return Application.getSystemMessages();
- }
-
- private void handleServiceException(PortletRequest request,
- PortletResponse response, Application application, Throwable e)
- throws IOException, PortletException {
- // TODO Check that this error handler is working when running inside a
- // portlet
-
- // if this was an UIDL request, response UIDL back to client
- if (getRequestType(request) == RequestType.UIDL) {
- Application.SystemMessages ci = getSystemMessages();
- criticalNotification(request, (ResourceResponse) response,
- ci.getInternalErrorCaption(), ci.getInternalErrorMessage(),
- null, ci.getInternalErrorURL());
- if (application != null) {
- application.getErrorHandler()
- .terminalError(new RequestError(e));
- } else {
- throw new PortletException(e);
- }
- } else {
- // Re-throw other exceptions
- throw new PortletException(e);
- }
-
- }
-
- @SuppressWarnings("serial")
- public class RequestError implements Terminal.ErrorEvent, Serializable {
-
- private final Throwable throwable;
-
- public RequestError(Throwable throwable) {
- this.throwable = throwable;
- }
-
- public Throwable getThrowable() {
- return throwable;
- }
-
- }
-
- /**
- * Send notification to client's application. Used to notify client of
- * critical errors and session expiration due to long inactivity. Server has
- * no knowledge of what application client refers to.
- *
- * @param request
- * the Portlet request instance.
- * @param response
- * the Portlet response to write to.
- * @param caption
- * for the notification
- * @param message
- * for the notification
- * @param details
- * a detail message to show in addition to the passed message.
- * Currently shown directly but could be hidden behind a details
- * drop down.
- * @param url
- * url to load after message, null for current page
- * @throws IOException
- * if the writing failed due to input/output error.
- */
- void criticalNotification(PortletRequest request, MimeResponse response,
- String caption, String message, String details, String url)
- throws IOException {
-
- // clients JS app is still running, but server application either
- // no longer exists or it might fail to perform reasonably.
- // send a notification to client's application and link how
- // to "restart" application.
-
- if (caption != null) {
- caption = "\"" + caption + "\"";
- }
- if (details != null) {
- if (message == null) {
- message = details;
- } else {
- message += "<br/><br/>" + details;
- }
- }
- if (message != null) {
- message = "\"" + message + "\"";
- }
- if (url != null) {
- url = "\"" + url + "\"";
- }
-
- // Set the response type
- response.setContentType("application/json; charset=UTF-8");
- final OutputStream out = response.getPortletOutputStream();
- final PrintWriter outWriter = new PrintWriter(new BufferedWriter(
- new OutputStreamWriter(out, "UTF-8")));
- outWriter.print("for(;;);[{\"changes\":[], \"meta\" : {"
- + "\"appError\": {" + "\"caption\":" + caption + ","
- + "\"message\" : " + message + "," + "\"url\" : " + url
- + "}}, \"resources\": {}, \"locales\":[]}]");
- outWriter.close();
- }
-
- /**
- * Returns a portal configuration property.
- *
- * Liferay is handled separately as
- * {@link PortalContext#getProperty(String)} does not return portal
- * properties from e.g. portal-ext.properties .
- *
- * @param name
- * @param context
- * @return
- */
- protected static String getPortalProperty(String name, PortalContext context) {
- boolean isLifeRay = context.getPortalInfo().toLowerCase()
- .contains("liferay");
-
- // TODO test on non-LifeRay platforms
-
- String value;
- if (isLifeRay) {
- value = getLifeRayPortalProperty(name);
- } else {
- value = context.getProperty(name);
- }
-
- return value;
- }
-
- private static String getLifeRayPortalProperty(String name) {
- String value;
- try {
- value = PropsUtil.get(name);
- } catch (Exception e) {
- value = null;
- }
- return value;
- }
-
- /**
- * Try to get an HTTP header value from a request using portal specific
- * APIs.
- *
- * @param name
- * HTTP header name
- * @return the value of the header (empty string if defined without a value,
- * null if the parameter is not present or retrieving it failed)
- */
- private static String getHTTPHeader(PortletRequest request, String name) {
- String value = null;
- String portalInfo = request.getPortalContext().getPortalInfo()
- .toLowerCase();
- if (portalInfo.contains("liferay")) {
- value = getLiferayHTTPHeader(request, name);
- } else if (portalInfo.contains("gatein")) {
- value = getGateInHTTPHeader(request, name);
- }
- return value;
- }
-
- /**
- * Try to get the value of a HTTP request parameter from a portlet request
- * using portal specific APIs. It is not possible to get the HTTP request
- * parameters using the official Portlet 2.0 API.
- *
- * @param name
- * HTTP request parameter name
- * @return the value of the parameter (empty string if parameter defined
- * without a value, null if the parameter is not present or
- * retrieving it failed)
- */
- private static String getHTTPRequestParameter(PortletRequest request,
- String name) {
- String value = request.getParameter(name);
- if (value == null) {
- String portalInfo = request.getPortalContext().getPortalInfo()
- .toLowerCase();
- if (portalInfo.contains("liferay")) {
- value = getLiferayHTTPRequestParameter(request, name);
- } else if (portalInfo.contains("gatein")) {
- value = getGateInHTTPRequestParameter(request, name);
- }
- }
- return value;
- }
-
- private static String getGateInHTTPRequestParameter(PortletRequest request,
- String name) {
- String value = null;
- try {
- Method getRealReq = request.getClass().getMethod("getRealRequest");
- HttpServletRequestWrapper origRequest = (HttpServletRequestWrapper) getRealReq
- .invoke(request);
- value = origRequest.getParameter(name);
- } catch (Exception e) {
- // do nothing - not on GateIn simple-portal
- }
- return value;
- }
-
- private static String getLiferayHTTPRequestParameter(
- PortletRequest request, String name) {
- try {
- // httpRequest = PortalUtil.getHttpServletRequest(request);
- HttpServletRequest httpRequest = (HttpServletRequest) PortalClassInvoker
- .invoke("com.liferay.portal.util.PortalUtil",
- "getHttpServletRequest", request);
-
- // httpRequest =
- // PortalUtil.getOriginalServletRequest(httpRequest);
- httpRequest = (HttpServletRequest) PortalClassInvoker.invoke(
- "com.liferay.portal.util.PortalUtil",
- "getOriginalServletRequest", httpRequest);
- if (httpRequest != null) {
- return httpRequest.getParameter(name);
- }
- } catch (Exception e) {
- // ignore and return null - unable to get the original request
- }
- return null;
- }
-
- private static String getGateInHTTPHeader(PortletRequest request,
- String name) {
- String value = null;
- try {
- Method getRealReq = request.getClass().getMethod("getRealRequest");
- HttpServletRequestWrapper origRequest = (HttpServletRequestWrapper) getRealReq
- .invoke(request);
- value = origRequest.getHeader(name);
- } catch (Exception e) {
- // do nothing - not on GateIn simple-portal
- }
- return value;
- }
-
- private static String getLiferayHTTPHeader(PortletRequest request,
- String name) {
- try {
- // httpRequest = PortalUtil.getHttpServletRequest(request);
- HttpServletRequest httpRequest = (HttpServletRequest) PortalClassInvoker
- .invoke("com.liferay.portal.util.PortalUtil",
- "getHttpServletRequest", request);
-
- // httpRequest =
- // PortalUtil.getOriginalServletRequest(httpRequest);
- httpRequest = (HttpServletRequest) PortalClassInvoker.invoke(
- "com.liferay.portal.util.PortalUtil",
- "getOriginalServletRequest", httpRequest);
- if (httpRequest != null) {
- return httpRequest.getHeader(name);
- }
- } catch (Exception e) {
- // ignore and return null - unable to get the original request
- }
- return null;
- }
-
- /**
- *
- * Gets the application context for a PortletSession. If no context is
- * currently stored in a session a new context is created and stored in the
- * session.
- *
- * @param portletSession
- * the portlet session.
- * @return the application context for the session.
- */
- protected PortletApplicationContext2 getApplicationContext(
- PortletSession portletSession) {
- return PortletApplicationContext2.getApplicationContext(portletSession);
- }
-
-}
+//package com.vaadin.terminal.gwt.server;
+//
+//import java.io.BufferedWriter;
+//import java.io.IOException;
+//import java.io.InputStream;
+//import java.io.OutputStream;
+//import java.io.OutputStreamWriter;
+//import java.io.PrintWriter;
+//import java.io.Serializable;
+//import java.lang.reflect.InvocationTargetException;
+//import java.lang.reflect.Method;
+//import java.net.MalformedURLException;
+//import java.security.GeneralSecurityException;
+//import java.util.Date;
+//import java.util.Enumeration;
+//import java.util.Iterator;
+//import java.util.LinkedHashMap;
+//import java.util.Locale;
+//import java.util.Map;
+//import java.util.Properties;
+//import java.util.logging.Level;
+//import java.util.logging.Logger;
+//
+//import javax.portlet.ActionRequest;
+//import javax.portlet.ActionResponse;
+//import javax.portlet.EventRequest;
+//import javax.portlet.EventResponse;
+//import javax.portlet.GenericPortlet;
+//import javax.portlet.MimeResponse;
+//import javax.portlet.PortalContext;
+//import javax.portlet.PortletConfig;
+//import javax.portlet.PortletContext;
+//import javax.portlet.PortletException;
+//import javax.portlet.PortletRequest;
+//import javax.portlet.PortletResponse;
+//import javax.portlet.PortletSession;
+//import javax.portlet.PortletURL;
+//import javax.portlet.RenderRequest;
+//import javax.portlet.RenderResponse;
+//import javax.portlet.ResourceRequest;
+//import javax.portlet.ResourceResponse;
+//import javax.portlet.ResourceURL;
+//import javax.servlet.http.HttpServletRequest;
+//import javax.servlet.http.HttpServletRequestWrapper;
+//import javax.servlet.http.HttpServletResponse;
+//
+//import com.liferay.portal.kernel.util.PortalClassInvoker;
+//import com.liferay.portal.kernel.util.PropsUtil;
+//import com.vaadin.Application;
+//import com.vaadin.Application.SystemMessages;
+//import com.vaadin.terminal.DownloadStream;
+//import com.vaadin.terminal.Terminal;
+//import com.vaadin.terminal.gwt.client.ApplicationConfiguration;
+//import com.vaadin.terminal.gwt.client.ApplicationConnection;
+//import com.vaadin.ui.Window;
+//
+///**
+// * Portlet 2.0 base class. This replaces the servlet in servlet/portlet 1.0
+// * deployments and handles various portlet requests from the browser.
+// *
+// * TODO Document me!
+// *
+// * @author peholmst
+// */
+//public abstract class AbstractApplicationPortlet extends GenericPortlet
+// implements Constants {
+//
+// private static final Logger logger = Logger
+// .getLogger(AbstractApplicationPortlet.class.getName());
+//
+// /**
+// * This portlet parameter is used to add styles to the main element. E.g
+// * "height:500px" generates a style="height:500px" to the main element.
+// */
+// public static final String PORTLET_PARAMETER_STYLE = "style";
+//
+// private static final String PORTAL_PARAMETER_VAADIN_THEME = "vaadin.theme";
+//
+// // TODO some parts could be shared with AbstractApplicationServlet
+//
+// // TODO Can we close the application when the portlet is removed? Do we know
+// // when the portlet is removed?
+//
+// // TODO What happens when the portlet window is resized? Do we know when the
+// // window is resized?
+//
+// private Properties applicationProperties;
+//
+// private boolean productionMode = false;
+//
+// @Override
+// public void init(PortletConfig config) throws PortletException {
+// super.init(config);
+// // Stores the application parameters into Properties object
+// applicationProperties = new Properties();
+// for (final Enumeration<String> e = config.getInitParameterNames(); e
+// .hasMoreElements();) {
+// final String name = e.nextElement();
+// applicationProperties.setProperty(name,
+// config.getInitParameter(name));
+// }
+//
+// // Overrides with server.xml parameters
+// final PortletContext context = config.getPortletContext();
+// for (final Enumeration<String> e = context.getInitParameterNames(); e
+// .hasMoreElements();) {
+// final String name = e.nextElement();
+// applicationProperties.setProperty(name,
+// context.getInitParameter(name));
+// }
+// checkProductionMode();
+// checkCrossSiteProtection();
+// }
+//
+// private void checkCrossSiteProtection() {
+// if (getApplicationOrSystemProperty(
+// SERVLET_PARAMETER_DISABLE_XSRF_PROTECTION, "false").equals(
+// "true")) {
+// /*
+// * Print an information/warning message about running with xsrf
+// * protection disabled
+// */
+// logger.warning(WARNING_XSRF_PROTECTION_DISABLED);
+// }
+// }
+//
+// /**
+// * Checks that the version reported by the client (widgetset) matches that
+// * of the server.
+// *
+// * @param request
+// */
+// private void checkWidgetsetVersion(PortletRequest request) {
+// if (!AbstractApplicationServlet.VERSION.equals(getHTTPRequestParameter(
+// request, "wsver"))) {
+// logger.warning(String.format(WIDGETSET_MISMATCH_INFO,
+// AbstractApplicationServlet.VERSION,
+// getHTTPRequestParameter(request, "wsver")));
+// }
+// }
+//
+// private void checkProductionMode() {
+// // Check if the application is in production mode.
+// // We are in production mode if Debug=false or productionMode=true
+// if (getApplicationOrSystemProperty(SERVLET_PARAMETER_DEBUG, "true")
+// .equals("false")) {
+// // "Debug=true" is the old way and should no longer be used
+// productionMode = true;
+// } else if (getApplicationOrSystemProperty(
+// SERVLET_PARAMETER_PRODUCTION_MODE, "false").equals("true")) {
+// // "productionMode=true" is the real way to do it
+// productionMode = true;
+// }
+//
+// if (!productionMode) {
+// /* Print an information/warning message about running in debug mode */
+// // TODO Maybe we need a different message for portlets?
+// logger.warning(NOT_PRODUCTION_MODE_INFO);
+// }
+// }
+//
+// /**
+// * Gets an application property value.
+// *
+// * @param parameterName
+// * the Name or the parameter.
+// * @return String value or null if not found
+// */
+// protected String getApplicationProperty(String parameterName) {
+//
+// String val = applicationProperties.getProperty(parameterName);
+// if (val != null) {
+// return val;
+// }
+//
+// // Try lower case application properties for backward compatibility with
+// // 3.0.2 and earlier
+// val = applicationProperties.getProperty(parameterName.toLowerCase());
+//
+// return val;
+// }
+//
+// /**
+// * Gets an system property value.
+// *
+// * @param parameterName
+// * the Name or the parameter.
+// * @return String value or null if not found
+// */
+// protected String getSystemProperty(String parameterName) {
+// String val = null;
+//
+// String pkgName;
+// final Package pkg = getClass().getPackage();
+// if (pkg != null) {
+// pkgName = pkg.getName();
+// } else {
+// final String className = getClass().getName();
+// pkgName = new String(className.toCharArray(), 0,
+// className.lastIndexOf('.'));
+// }
+// val = System.getProperty(pkgName + "." + parameterName);
+// if (val != null) {
+// return val;
+// }
+//
+// // Try lowercased system properties
+// val = System.getProperty(pkgName + "." + parameterName.toLowerCase());
+// return val;
+// }
+//
+// /**
+// * Gets an application or system property value.
+// *
+// * @param parameterName
+// * the Name or the parameter.
+// * @param defaultValue
+// * the Default to be used.
+// * @return String value or default if not found
+// */
+// protected String getApplicationOrSystemProperty(String parameterName,
+// String defaultValue) {
+//
+// String val = null;
+//
+// // Try application properties
+// val = getApplicationProperty(parameterName);
+// if (val != null) {
+// return val;
+// }
+//
+// // Try system properties
+// val = getSystemProperty(parameterName);
+// if (val != null) {
+// return val;
+// }
+//
+// return defaultValue;
+// }
+//
+// /**
+// * Return the URL from where static files, e.g. the widgetset and the theme,
+// * are served. In a standard configuration the VAADIN folder inside the
+// * returned folder is what is used for widgetsets and themes.
+// *
+// * @param request
+// * @return The location of static resources (inside which there should be a
+// * VAADIN directory). Does not end with a slash (/).
+// */
+// protected String getStaticFilesLocation(PortletRequest request) {
+// // TODO allow overriding on portlet level?
+// String staticFileLocation = getPortalProperty(
+// Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH,
+// request.getPortalContext());
+// if (staticFileLocation != null) {
+// // remove trailing slash if any
+// while (staticFileLocation.endsWith(".")) {
+// staticFileLocation = staticFileLocation.substring(0,
+// staticFileLocation.length() - 1);
+// }
+// return staticFileLocation;
+// } else {
+// // default for Liferay
+// return "/html";
+// }
+// }
+//
+// protected enum RequestType {
+// FILE_UPLOAD, UIDL, RENDER, STATIC_FILE, APPLICATION_RESOURCE, DUMMY, EVENT, ACTION, UNKNOWN;
+// }
+//
+// protected RequestType getRequestType(PortletRequest request) {
+// if (request instanceof RenderRequest) {
+// return RequestType.RENDER;
+// } else if (request instanceof ResourceRequest) {
+// if (isUIDLRequest((ResourceRequest) request)) {
+// return RequestType.UIDL;
+// } else if (isFileUploadRequest((ResourceRequest) request)) {
+// return RequestType.FILE_UPLOAD;
+// } else if (isApplicationResourceRequest((ResourceRequest) request)) {
+// return RequestType.APPLICATION_RESOURCE;
+// } else if (isDummyRequest((ResourceRequest) request)) {
+// return RequestType.DUMMY;
+// } else {
+// return RequestType.STATIC_FILE;
+// }
+// } else if (request instanceof ActionRequest) {
+// return RequestType.ACTION;
+// } else if (request instanceof EventRequest) {
+// return RequestType.EVENT;
+// }
+// return RequestType.UNKNOWN;
+// }
+//
+// private boolean isApplicationResourceRequest(ResourceRequest request) {
+// return request.getResourceID() != null
+// && request.getResourceID().startsWith("APP");
+// }
+//
+// private boolean isUIDLRequest(ResourceRequest request) {
+// return request.getResourceID() != null
+// && request.getResourceID().equals("UIDL");
+// }
+//
+// private boolean isDummyRequest(ResourceRequest request) {
+// return request.getResourceID() != null
+// && request.getResourceID().equals("DUMMY");
+// }
+//
+// private boolean isFileUploadRequest(ResourceRequest request) {
+// return "UPLOAD".equals(request.getResourceID());
+// }
+//
+// /**
+// * Returns true if the servlet is running in production mode. Production
+// * mode disables all debug facilities.
+// *
+// * @return true if in production mode, false if in debug mode
+// */
+// public boolean isProductionMode() {
+// return productionMode;
+// }
+//
+// protected void handleRequest(PortletRequest request,
+// PortletResponse response) throws PortletException, IOException {
+// RequestType requestType = getRequestType(request);
+//
+// if (requestType == RequestType.UNKNOWN) {
+// handleUnknownRequest(request, response);
+// } else if (requestType == RequestType.DUMMY) {
+// /*
+// * This dummy page is used by action responses to redirect to, in
+// * order to prevent the boot strap code from being rendered into
+// * strange places such as iframes.
+// */
+// ((ResourceResponse) response).setContentType("text/html");
+// final OutputStream out = ((ResourceResponse) response)
+// .getPortletOutputStream();
+// final PrintWriter outWriter = new PrintWriter(new BufferedWriter(
+// new OutputStreamWriter(out, "UTF-8")));
+// outWriter.print("<html><body>dummy page</body></html>");
+// outWriter.close();
+// } else if (requestType == RequestType.STATIC_FILE) {
+// serveStaticResources((ResourceRequest) request,
+// (ResourceResponse) response);
+// } else {
+// Application application = null;
+// boolean transactionStarted = false;
+// boolean requestStarted = false;
+//
+// try {
+// // TODO What about PARAM_UNLOADBURST & redirectToApplication??
+//
+// /* Find out which application this request is related to */
+// application = findApplicationInstance(request, requestType);
+// if (application == null) {
+// return;
+// }
+//
+// /*
+// * Get or create an application context and an application
+// * manager for the session
+// */
+// PortletApplicationContext2 applicationContext = getApplicationContext(request
+// .getPortletSession());
+// applicationContext.setResponse(response);
+// applicationContext.setPortletConfig(getPortletConfig());
+//
+// PortletCommunicationManager applicationManager = applicationContext
+// .getApplicationManager(application);
+//
+// /* Update browser information from request */
+// updateBrowserProperties(applicationContext.getBrowser(),
+// request);
+//
+// /*
+// * Call application requestStart before Application.init() is
+// * called (bypasses the limitation in TransactionListener)
+// */
+// if (application instanceof PortletRequestListener) {
+// ((PortletRequestListener) application).onRequestStart(
+// request, response);
+// requestStarted = true;
+// }
+//
+// /* Start the newly created application */
+// startApplication(request, application, applicationContext);
+//
+// /*
+// * Transaction starts. Call transaction listeners. Transaction
+// * end is called in the finally block below.
+// */
+// applicationContext.startTransaction(application, request);
+// transactionStarted = true;
+//
+// /* Notify listeners */
+//
+// // Finds the window within the application
+// Window window = null;
+// synchronized (application) {
+// if (application.isRunning()) {
+// switch (requestType) {
+// case FILE_UPLOAD:
+// // no window
+// break;
+// case APPLICATION_RESOURCE:
+// // use main window - should not need any window
+// window = application.getMainWindow();
+// break;
+// default:
+// window = applicationManager.getApplicationWindow(
+// request, this, application, null);
+// }
+// // if window not found, not a problem - use null
+// }
+// }
+//
+// // TODO Should this happen before or after the transaction
+// // starts?
+// if (request instanceof RenderRequest) {
+// applicationContext.firePortletRenderRequest(application,
+// window, (RenderRequest) request,
+// (RenderResponse) response);
+// } else if (request instanceof ActionRequest) {
+// applicationContext.firePortletActionRequest(application,
+// window, (ActionRequest) request,
+// (ActionResponse) response);
+// } else if (request instanceof EventRequest) {
+// applicationContext.firePortletEventRequest(application,
+// window, (EventRequest) request,
+// (EventResponse) response);
+// } else if (request instanceof ResourceRequest) {
+// applicationContext.firePortletResourceRequest(application,
+// window, (ResourceRequest) request,
+// (ResourceResponse) response);
+// }
+//
+// /* Handle the request */
+// if (requestType == RequestType.FILE_UPLOAD) {
+// applicationManager.handleFileUpload(
+// (ResourceRequest) request,
+// (ResourceResponse) response);
+// return;
+// } else if (requestType == RequestType.UIDL) {
+// // Handles AJAX UIDL requests
+// if (isRepaintAll(request)) {
+// // warn if versions do not match
+// checkWidgetsetVersion(request);
+// }
+// applicationManager.handleUidlRequest(
+// (ResourceRequest) request,
+// (ResourceResponse) response, this, window);
+// return;
+// } else {
+// /*
+// * Removes the application if it has stopped
+// */
+// if (!application.isRunning()) {
+// endApplication(request, response, application);
+// return;
+// }
+//
+// handleOtherRequest(request, response, requestType,
+// application, window, applicationContext,
+// applicationManager);
+// }
+// } catch (final SessionExpiredException e) {
+// // TODO Figure out a better way to deal with
+// // SessionExpiredExceptions
+// logger.finest("A user session has expired");
+// } catch (final GeneralSecurityException e) {
+// // TODO Figure out a better way to deal with
+// // GeneralSecurityExceptions
+// logger.fine("General security exception, the security key was probably incorrect.");
+// } catch (final Throwable e) {
+// handleServiceException(request, response, application, e);
+// } finally {
+// // Notifies transaction end
+// try {
+// if (transactionStarted) {
+// ((PortletApplicationContext2) application.getContext())
+// .endTransaction(application, request);
+// }
+// } finally {
+// if (requestStarted) {
+// ((PortletRequestListener) application).onRequestEnd(
+// request, response);
+//
+// }
+// }
+// }
+// }
+// }
+//
+// private void handleUnknownRequest(PortletRequest request,
+// PortletResponse response) {
+// logger.warning("Unknown request type");
+// }
+//
+// /**
+// * Handle a portlet request that is not for static files, UIDL or upload.
+// * Also render requests are handled here.
+// *
+// * This method is called after starting the application and calling portlet
+// * and transaction listeners.
+// *
+// * @param request
+// * @param response
+// * @param requestType
+// * @param application
+// * @param applicationContext
+// * @param applicationManager
+// * @throws PortletException
+// * @throws IOException
+// * @throws MalformedURLException
+// */
+// private void handleOtherRequest(PortletRequest request,
+// PortletResponse response, RequestType requestType,
+// Application application, Window window,
+// PortletApplicationContext2 applicationContext,
+// PortletCommunicationManager applicationManager)
+// throws PortletException, IOException, MalformedURLException {
+// if (window == null) {
+// throw new PortletException(ERROR_NO_WINDOW_FOUND);
+// }
+//
+// /*
+// * Sets terminal type for the window, if not already set
+// */
+// if (window.getTerminal() == null) {
+// window.setTerminal(applicationContext.getBrowser());
+// }
+//
+// /*
+// * Handle parameters
+// */
+// final Map<String, String[]> parameters = request.getParameterMap();
+// if (window != null && parameters != null) {
+// window.handleParameters(parameters);
+// }
+//
+// if (requestType == RequestType.APPLICATION_RESOURCE) {
+// handleURI(applicationManager, window, (ResourceRequest) request,
+// (ResourceResponse) response);
+// } else if (requestType == RequestType.RENDER) {
+// writeAjaxPage((RenderRequest) request, (RenderResponse) response,
+// window, application);
+// } else if (requestType == RequestType.EVENT) {
+// // nothing to do, listeners do all the work
+// } else if (requestType == RequestType.ACTION) {
+// // nothing to do, listeners do all the work
+// } else {
+// throw new IllegalStateException(
+// "handleRequest() without anything to do - should never happen!");
+// }
+// }
+//
+// private void updateBrowserProperties(WebBrowser browser,
+// PortletRequest request) {
+// String userAgent = getHTTPHeader(request, "user-agent");
+// browser.updateRequestDetails(request.getLocale(), null,
+// request.isSecure(), userAgent);
+// if (getHTTPRequestParameter(request, "repaintAll") != null) {
+// browser.updateClientSideDetails(
+// getHTTPRequestParameter(request, "sw"),
+// getHTTPRequestParameter(request, "sh"),
+// getHTTPRequestParameter(request, "tzo"),
+// getHTTPRequestParameter(request, "rtzo"),
+// getHTTPRequestParameter(request, "dstd"),
+// getHTTPRequestParameter(request, "dstActive"),
+// getHTTPRequestParameter(request, "curdate"),
+// getHTTPRequestParameter(request, "td") != null);
+// }
+// }
+//
+// @Override
+// public void processEvent(EventRequest request, EventResponse response)
+// throws PortletException, IOException {
+// handleRequest(request, response);
+// }
+//
+// private boolean handleURI(PortletCommunicationManager applicationManager,
+// Window window, ResourceRequest request, ResourceResponse response)
+// throws IOException {
+// // Handles the URI
+// DownloadStream download = applicationManager.handleURI(window, request,
+// response, this);
+//
+// // A download request
+// if (download != null) {
+// // Client downloads an resource
+// handleDownload(download, request, response);
+// return true;
+// }
+//
+// return false;
+// }
+//
+// private void handleDownload(DownloadStream stream, ResourceRequest request,
+// ResourceResponse response) throws IOException {
+//
+// if (stream.getParameter("Location") != null) {
+// response.setProperty(ResourceResponse.HTTP_STATUS_CODE,
+// Integer.toString(HttpServletResponse.SC_MOVED_TEMPORARILY));
+// response.setProperty("Location", stream.getParameter("Location"));
+// return;
+// }
+//
+// // Download from given stream
+// final InputStream data = stream.getStream();
+// if (data != null) {
+//
+// OutputStream out = null;
+// try {
+//
+// // Sets content type
+// response.setContentType(stream.getContentType());
+//
+// // Sets cache headers
+// final long cacheTime = stream.getCacheTime();
+// if (cacheTime <= 0) {
+// response.setProperty("Cache-Control", "no-cache");
+// response.setProperty("Pragma", "no-cache");
+// response.setProperty("Expires", "0");
+// } else {
+// response.setProperty("Cache-Control", "max-age="
+// + cacheTime / 1000);
+// response.setProperty("Expires",
+// "" + System.currentTimeMillis() + cacheTime);
+// // Required to apply caching in some Tomcats
+// response.setProperty("Pragma", "cache");
+// }
+//
+// // Copy download stream parameters directly
+// // to HTTP headers.
+// final Iterator<String> i = stream.getParameterNames();
+// if (i != null) {
+// while (i.hasNext()) {
+// final String param = i.next();
+// response.setProperty(param, stream.getParameter(param));
+// }
+// }
+//
+// // suggest local filename from DownloadStream if
+// // Content-Disposition
+// // not explicitly set
+// String contentDispositionValue = stream
+// .getParameter("Content-Disposition");
+// if (contentDispositionValue == null) {
+// contentDispositionValue = "filename=\""
+// + stream.getFileName() + "\"";
+// response.setProperty("Content-Disposition",
+// contentDispositionValue);
+// }
+//
+// int bufferSize = stream.getBufferSize();
+// if (bufferSize <= 0 || bufferSize > MAX_BUFFER_SIZE) {
+// bufferSize = DEFAULT_BUFFER_SIZE;
+// }
+// final byte[] buffer = new byte[bufferSize];
+// int bytesRead = 0;
+//
+// out = response.getPortletOutputStream();
+//
+// while ((bytesRead = data.read(buffer)) > 0) {
+// out.write(buffer, 0, bytesRead);
+// out.flush();
+// }
+// } finally {
+// AbstractCommunicationManager.tryToCloseStream(data);
+// AbstractCommunicationManager.tryToCloseStream(out);
+// }
+// }
+// }
+//
+// private void serveStaticResources(ResourceRequest request,
+// ResourceResponse response) throws IOException, PortletException {
+// final String resourceID = request.getResourceID();
+// final PortletContext pc = getPortletContext();
+//
+// InputStream is = pc.getResourceAsStream(resourceID);
+// if (is != null) {
+// final String mimetype = pc.getMimeType(resourceID);
+// if (mimetype != null) {
+// response.setContentType(mimetype);
+// }
+// final OutputStream os = response.getPortletOutputStream();
+// final byte buffer[] = new byte[DEFAULT_BUFFER_SIZE];
+// int bytes;
+// while ((bytes = is.read(buffer)) >= 0) {
+// os.write(buffer, 0, bytes);
+// }
+// } else {
+// logger.info("Requested resource [" + resourceID
+// + "] could not be found");
+// response.setProperty(ResourceResponse.HTTP_STATUS_CODE,
+// Integer.toString(HttpServletResponse.SC_NOT_FOUND));
+// }
+// }
+//
+// @Override
+// public void processAction(ActionRequest request, ActionResponse response)
+// throws PortletException, IOException {
+// handleRequest(request, response);
+// }
+//
+// @Override
+// protected void doDispatch(RenderRequest request, RenderResponse response)
+// throws PortletException, IOException {
+// try {
+// // try to let super handle - it'll call methods annotated for
+// // handling, the default doXYZ(), or throw if a handler for the mode
+// // is not found
+// super.doDispatch(request, response);
+//
+// } catch (PortletException e) {
+// if (e.getCause() == null) {
+// // No cause interpreted as 'unknown mode' - pass that trough
+// // so that the application can handle
+// handleRequest(request, response);
+//
+// } else {
+// // Something else failed, pass on
+// throw e;
+// }
+// }
+// }
+//
+// @Override
+// public void serveResource(ResourceRequest request, ResourceResponse response)
+// throws PortletException, IOException {
+// handleRequest(request, response);
+// }
+//
+// boolean requestCanCreateApplication(PortletRequest request,
+// RequestType requestType) {
+// if (requestType == RequestType.UIDL && isRepaintAll(request)) {
+// return true;
+// } else if (requestType == RequestType.RENDER) {
+// // In most cases the first request is a render request that renders
+// // the HTML fragment. This should create an application instance.
+// return true;
+// } else if (requestType == RequestType.EVENT) {
+// // A portlet can also be sent an event even though it has not been
+// // rendered, e.g. portlet on one page sends an event to a portlet on
+// // another page and then moves the user to that page.
+// return true;
+// }
+// return false;
+// }
+//
+// private boolean isRepaintAll(PortletRequest request) {
+// return (request.getParameter(URL_PARAMETER_REPAINT_ALL) != null)
+// && (request.getParameter(URL_PARAMETER_REPAINT_ALL).equals("1"));
+// }
+//
+// private void startApplication(PortletRequest request,
+// Application application, PortletApplicationContext2 context)
+// throws PortletException, MalformedURLException {
+// if (!application.isRunning()) {
+// Locale locale = request.getLocale();
+// application.setLocale(locale);
+// // No application URL when running inside a portlet
+// application.start(null, applicationProperties, context);
+// }
+// }
+//
+// private void endApplication(PortletRequest request,
+// PortletResponse response, Application application)
+// throws IOException {
+// final PortletSession session = request.getPortletSession();
+// if (session != null) {
+// getApplicationContext(session).removeApplication(application);
+// }
+// // Do not send any redirects when running inside a portlet.
+// }
+//
+// private Application findApplicationInstance(PortletRequest request,
+// RequestType requestType) throws PortletException,
+// SessionExpiredException, MalformedURLException {
+//
+// boolean requestCanCreateApplication = requestCanCreateApplication(
+// request, requestType);
+//
+// /* Find an existing application for this request. */
+// Application application = getExistingApplication(request,
+// requestCanCreateApplication);
+//
+// if (application != null) {
+// /*
+// * There is an existing application. We can use this as long as the
+// * user not specifically requested to close or restart it.
+// */
+//
+// final boolean restartApplication = (getHTTPRequestParameter(
+// request, URL_PARAMETER_RESTART_APPLICATION) != null);
+// final boolean closeApplication = (getHTTPRequestParameter(request,
+// URL_PARAMETER_CLOSE_APPLICATION) != null);
+//
+// if (restartApplication) {
+// closeApplication(application, request.getPortletSession(false));
+// return createApplication(request);
+// } else if (closeApplication) {
+// closeApplication(application, request.getPortletSession(false));
+// return null;
+// } else {
+// return application;
+// }
+// }
+//
+// // No existing application was found
+//
+// if (requestCanCreateApplication) {
+// return createApplication(request);
+// } else {
+// throw new SessionExpiredException();
+// }
+// }
+//
+// private void closeApplication(Application application,
+// PortletSession session) {
+// if (application == null) {
+// return;
+// }
+//
+// application.close();
+// if (session != null) {
+// PortletApplicationContext2 context = getApplicationContext(session);
+// context.removeApplication(application);
+// }
+// }
+//
+// private Application createApplication(PortletRequest request)
+// throws PortletException, MalformedURLException {
+// Application newApplication = getNewApplication(request);
+// final PortletApplicationContext2 context = getApplicationContext(request
+// .getPortletSession());
+// context.addApplication(newApplication, request.getWindowID());
+// return newApplication;
+// }
+//
+// private Application getExistingApplication(PortletRequest request,
+// boolean allowSessionCreation) throws MalformedURLException,
+// SessionExpiredException {
+//
+// final PortletSession session = request
+// .getPortletSession(allowSessionCreation);
+//
+// if (session == null) {
+// throw new SessionExpiredException();
+// }
+//
+// PortletApplicationContext2 context = getApplicationContext(session);
+// Application application = context.getApplicationForWindowId(request
+// .getWindowID());
+// if (application == null) {
+// return null;
+// }
+// if (application.isRunning()) {
+// return application;
+// }
+// // application found but not running
+// context.removeApplication(application);
+//
+// return null;
+// }
+//
+// /**
+// * Returns the URL from which the widgetset is served on the portal.
+// *
+// * @param widgetset
+// * @param request
+// * @return
+// */
+// protected String getWidgetsetURL(String widgetset, PortletRequest request) {
+// return getStaticFilesLocation(request) + "/" + WIDGETSET_DIRECTORY_PATH
+// + widgetset + "/" + widgetset + ".nocache.js?"
+// + new Date().getTime();
+// }
+//
+// /**
+// * Returns the theme URI for the named theme on the portal.
+// *
+// * Note that this is not the only location referring to the theme URI - also
+// * e.g. PortletCommunicationManager uses its own way to access the portlet
+// * 2.0 theme resources.
+// *
+// * @param themeName
+// * @param request
+// * @return
+// */
+// protected String getThemeURI(String themeName, PortletRequest request) {
+// return getStaticFilesLocation(request) + "/" + THEME_DIRECTORY_PATH
+// + themeName;
+// }
+//
+// /**
+// * Writes the html host page (aka kickstart page) that starts the actual
+// * Vaadin application.
+// *
+// * If one needs to override parts of the portlet HTML contents creation, it
+// * is suggested that one overrides one of several submethods including:
+// * <ul>
+// * <li>
+// * {@link #writeAjaxPageHtmlMainDiv(RenderRequest, RenderResponse, BufferedWriter, String)}
+// * <li>
+// * {@link #getVaadinConfigurationMap(RenderRequest, RenderResponse, Application, String)}
+// * <li>
+// * {@link #writeAjaxPageHtmlVaadinScripts(RenderRequest, RenderResponse, BufferedWriter, Application, String)}
+// * </ul>
+// *
+// * @param request
+// * the portlet request.
+// * @param response
+// * the portlet response to write to.
+// * @param window
+// * @param application
+// * @throws IOException
+// * if the writing failed due to input/output error.
+// * @throws MalformedURLException
+// * if the application is denied access the persistent data store
+// * represented by the given URL.
+// * @throws PortletException
+// */
+// protected void writeAjaxPage(RenderRequest request,
+// RenderResponse response, Window window, Application application)
+// throws IOException, MalformedURLException, PortletException {
+//
+// response.setContentType("text/html");
+// final BufferedWriter page = new BufferedWriter(new OutputStreamWriter(
+// response.getPortletOutputStream(), "UTF-8"));
+//
+// // TODO Currently, we can only load widgetsets and themes from the
+// // portal
+//
+// String themeName = getThemeForWindow(request, window);
+//
+// writeAjaxPageHtmlVaadinScripts(request, response, page, application,
+// themeName);
+//
+// /*- Add classnames;
+// * .v-app
+// * .v-app-loading
+// * .v-app-<simpleName for app class>
+// * .v-theme-<themeName, remove non-alphanum>
+// */
+// String appClass = "v-app-";
+// try {
+// appClass += getApplicationClass().getSimpleName();
+// } catch (ClassNotFoundException e) {
+// appClass += "unknown";
+// logger.log(Level.SEVERE, "Could not find application class", e);
+// }
+// String themeClass = "v-theme-"
+// + themeName.replaceAll("[^a-zA-Z0-9]", "");
+//
+// String classNames = "v-app " + themeClass + " " + appClass;
+//
+// String style = getApplicationProperty(PORTLET_PARAMETER_STYLE);
+// String divStyle = "";
+// if (style != null) {
+// divStyle = "style=\"" + style + "\"";
+// }
+//
+// writeAjaxPageHtmlMainDiv(request, response, page,
+// getApplicationDomId(request), classNames, divStyle);
+//
+// page.close();
+// }
+//
+// /**
+// * Creates and returns a unique ID for the DIV where the application is to
+// * be rendered. We need to generate a unique ID because some portals already
+// * create a DIV with the portlet's Window ID as the DOM ID.
+// *
+// * @param request
+// * PortletRequest
+// * @return the id to use in the DOM
+// */
+// private String getApplicationDomId(PortletRequest request) {
+// return "v-" + request.getWindowID();
+// }
+//
+// /**
+// * This method writes the scripts to load the widgetset and the themes as
+// * well as define Vaadin configuration parameters on the HTML fragment that
+// * starts the actual Vaadin application.
+// *
+// * @param request
+// * @param response
+// * @param writer
+// * @param application
+// * @param themeName
+// * @throws IOException
+// * @throws PortletException
+// */
+// protected void writeAjaxPageHtmlVaadinScripts(RenderRequest request,
+// RenderResponse response, final BufferedWriter writer,
+// Application application, String themeName) throws IOException,
+// PortletException {
+// String themeURI = getThemeURI(themeName, request);
+//
+// // fixed base theme to use - all portal pages with Vaadin
+// // applications will load this exactly once
+// String portalTheme = getPortalProperty(PORTAL_PARAMETER_VAADIN_THEME,
+// request.getPortalContext());
+//
+// writer.write("<script type=\"text/javascript\">\n");
+// writer.write("if(!vaadin || !vaadin.vaadinConfigurations) {\n "
+// + "if(!vaadin) { var vaadin = {}} \n"
+// + "vaadin.vaadinConfigurations = {};\n"
+// + "if (!vaadin.themesLoaded) { vaadin.themesLoaded = {}; }\n");
+// if (!isProductionMode()) {
+// writer.write("vaadin.debug = true;\n");
+// }
+//
+// writeAjaxPageScriptWidgetset(request, response, writer);
+//
+// Map<String, String> config = getVaadinConfigurationMap(request,
+// response, application, themeURI);
+// writeAjaxPageScriptConfigurations(request, response, writer, config);
+//
+// writer.write("</script>\n");
+//
+// writeAjaxPageHtmlTheme(request, writer, themeName, themeURI,
+// portalTheme);
+//
+// // TODO Warn if widgetset has not been loaded after 15 seconds
+// }
+//
+// /**
+// * Writes the script to load the widgetset on the HTML fragment created by
+// * the portlet.
+// *
+// * @param request
+// * @param response
+// * @param writer
+// * @throws IOException
+// */
+// protected void writeAjaxPageScriptWidgetset(RenderRequest request,
+// RenderResponse response, final BufferedWriter writer)
+// throws IOException {
+// String requestWidgetset = getApplicationOrSystemProperty(
+// PARAMETER_WIDGETSET, null);
+// String sharedWidgetset = getPortalProperty(
+// PORTAL_PARAMETER_VAADIN_WIDGETSET, request.getPortalContext());
+//
+// String widgetset;
+// if (requestWidgetset != null) {
+// widgetset = requestWidgetset;
+// } else if (sharedWidgetset != null) {
+// widgetset = sharedWidgetset;
+// } else {
+// widgetset = DEFAULT_WIDGETSET;
+// }
+// String widgetsetURL = getWidgetsetURL(widgetset, request);
+// writer.write("document.write('<iframe tabIndex=\"-1\" id=\"__gwt_historyFrame\" "
+// + "style=\"position:absolute;width:0;height:0;border:0;overflow:"
+// + "hidden;opacity:0;top:-100px;left:-100px;\" src=\"javascript:false\"></iframe>');\n");
+// writer.write("document.write(\"<script language='javascript' src='"
+// + widgetsetURL + "'><\\/script>\");\n}\n");
+// }
+//
+// /**
+// * Returns the configuration parameters to pass to the client.
+// *
+// * To add configuration parameters for the client, override, call the super
+// * method and then modify the map. Overriding this method may also require
+// * client side changes in {@link ApplicationConnection} and
+// * {@link ApplicationConfiguration}.
+// *
+// * Note that this method must escape and quote the values when appropriate.
+// *
+// * The map returned is typically a {@link LinkedHashMap} to preserve
+// * insertion order, but it is not guaranteed to be one.
+// *
+// * @param request
+// * @param response
+// * @param application
+// * @param themeURI
+// * @return modifiable Map from parameter name to its full value
+// * @throws PortletException
+// */
+// protected Map<String, String> getVaadinConfigurationMap(
+// RenderRequest request, RenderResponse response,
+// Application application, String themeURI) throws PortletException {
+// Map<String, String> config = new LinkedHashMap<String, String>();
+//
+// /*
+// * We need this in order to get uploads to work. TODO this is not needed
+// * for uploads anymore, check if this is needed for some other things
+// */
+// PortletURL appUri = response.createActionURL();
+// config.put("appUri", "'" + appUri.toString() + "'");
+// config.put("usePortletURLs", "true");
+// ResourceURL uidlUrlBase = response.createResourceURL();
+// uidlUrlBase.setResourceID("UIDL");
+// config.put("portletUidlURLBase", "'" + uidlUrlBase.toString() + "'");
+// config.put("pathInfo", "''");
+// config.put("themeUri", "'" + themeURI + "'");
+//
+// String versionInfo = "{vaadinVersion:\""
+// + AbstractApplicationServlet.VERSION
+// + "\",applicationVersion:\"" + application.getVersion() + "\"}";
+// config.put("versionInfo", versionInfo);
+//
+// // Get system messages
+// Application.SystemMessages systemMessages = null;
+// try {
+// systemMessages = getSystemMessages();
+// } catch (SystemMessageException e) {
+// // failing to get the system messages is always a problem
+// throw new PortletException("Failed to obtain system messages!", e);
+// }
+// if (systemMessages != null) {
+// // Write the CommunicationError -message to client
+// String caption = systemMessages.getCommunicationErrorCaption();
+// if (caption != null) {
+// caption = "\"" + caption + "\"";
+// }
+// String message = systemMessages.getCommunicationErrorMessage();
+// if (message != null) {
+// message = "\"" + message + "\"";
+// }
+// String url = systemMessages.getCommunicationErrorURL();
+// if (url != null) {
+// url = "\"" + url + "\"";
+// }
+//
+// config.put("\"comErrMsg\"", "{" + "\"caption\":" + caption + ","
+// + "\"message\" : " + message + "," + "\"url\" : " + url
+// + "}");
+//
+// // Write the AuthenticationError -message to client
+// caption = systemMessages.getAuthenticationErrorCaption();
+// if (caption != null) {
+// caption = "\"" + caption + "\"";
+// }
+// message = systemMessages.getAuthenticationErrorMessage();
+// if (message != null) {
+// message = "\"" + message + "\"";
+// }
+// url = systemMessages.getAuthenticationErrorURL();
+// if (url != null) {
+// url = "\"" + url + "\"";
+// }
+//
+// config.put("\"authErrMsg\"", "{" + "\"caption\":" + caption + ","
+// + "\"message\" : " + message + "," + "\"url\" : " + url
+// + "}");
+// }
+//
+// return config;
+// }
+//
+// /**
+// * Constructs the Vaadin configuration section for
+// * {@link ApplicationConnection} and {@link ApplicationConfiguration}.
+// *
+// * Typically this method should not be overridden. Instead, modify
+// * {@link #getVaadinConfigurationMap(RenderRequest, RenderResponse, Application, String)}
+// * .
+// *
+// * @param request
+// * @param response
+// * @param writer
+// * @param config
+// * @throws IOException
+// * @throws PortletException
+// */
+// protected void writeAjaxPageScriptConfigurations(RenderRequest request,
+// RenderResponse response, final BufferedWriter writer,
+// Map<String, String> config) throws IOException, PortletException {
+//
+// writer.write("vaadin.vaadinConfigurations[\""
+// + getApplicationDomId(request) + "\"] = {");
+//
+// Iterator<String> keyIt = config.keySet().iterator();
+// while (keyIt.hasNext()) {
+// String key = keyIt.next();
+// writer.write(key + ": " + config.get(key));
+// if (keyIt.hasNext()) {
+// writer.write(", ");
+// }
+// }
+//
+// writer.write("};\n");
+// }
+//
+// /**
+// * Writes the Vaadin theme loading section of the portlet HTML. Loads both
+// * the portal theme and the portlet theme in this order, skipping loading of
+// * themes that are already loaded (matched by name).
+// *
+// * @param request
+// * @param writer
+// * @param themeName
+// * @param themeURI
+// * @param portalTheme
+// * @throws IOException
+// */
+// protected void writeAjaxPageHtmlTheme(RenderRequest request,
+// final BufferedWriter writer, String themeName, String themeURI,
+// String portalTheme) throws IOException {
+// writer.write("<script type=\"text/javascript\">\n");
+//
+// if (portalTheme == null) {
+// portalTheme = DEFAULT_THEME_NAME;
+// }
+//
+// writer.write("if(!vaadin.themesLoaded['" + portalTheme + "']) {\n");
+// writer.write("var defaultStylesheet = document.createElement('link');\n");
+// writer.write("defaultStylesheet.setAttribute('rel', 'stylesheet');\n");
+// writer.write("defaultStylesheet.setAttribute('type', 'text/css');\n");
+// writer.write("defaultStylesheet.setAttribute('href', '"
+// + getThemeURI(portalTheme, request) + "/styles.css');\n");
+// writer.write("document.getElementsByTagName('head')[0].appendChild(defaultStylesheet);\n");
+// writer.write("vaadin.themesLoaded['" + portalTheme + "'] = true;\n}\n");
+//
+// if (!portalTheme.equals(themeName)) {
+// writer.write("if(!vaadin.themesLoaded['" + themeName + "']) {\n");
+// writer.write("var stylesheet = document.createElement('link');\n");
+// writer.write("stylesheet.setAttribute('rel', 'stylesheet');\n");
+// writer.write("stylesheet.setAttribute('type', 'text/css');\n");
+// writer.write("stylesheet.setAttribute('href', '" + themeURI
+// + "/styles.css');\n");
+// writer.write("document.getElementsByTagName('head')[0].appendChild(stylesheet);\n");
+// writer.write("vaadin.themesLoaded['" + themeName
+// + "'] = true;\n}\n");
+// }
+//
+// writer.write("</script>\n");
+// }
+//
+// /**
+// * Method to write the div element into which that actual Vaadin application
+// * is rendered.
+// * <p>
+// * Override this method if you want to add some custom html around around
+// * the div element into which the actual Vaadin application will be
+// * rendered.
+// *
+// * @param request
+// * @param response
+// * @param writer
+// * @param id
+// * @param classNames
+// * @param divStyle
+// * @throws IOException
+// */
+// protected void writeAjaxPageHtmlMainDiv(RenderRequest request,
+// RenderResponse response, final BufferedWriter writer, String id,
+// String classNames, String divStyle) throws IOException {
+// writer.write("<div id=\"" + id + "\" class=\"" + classNames + "\" "
+// + divStyle + ">");
+// writer.write("<div class=\"v-app-loading\"></div>");
+// writer.write("</div>\n");
+// writer.write("<noscript>" + getNoScriptMessage() + "</noscript>");
+// }
+//
+// /**
+// * Returns a message printed for browsers without scripting support or if
+// * browsers scripting support is disabled.
+// */
+// protected String getNoScriptMessage() {
+// return "You have to enable javascript in your browser to use an application built with Vaadin.";
+// }
+//
+// /**
+// * Returns the theme for given request/window
+// *
+// * @param request
+// * @param window
+// * @return
+// */
+// protected String getThemeForWindow(PortletRequest request, Window window) {
+// // Finds theme name
+// String themeName;
+//
+// // theme defined for the window?
+// themeName = window.getTheme();
+//
+// if (themeName == null) {
+// // no, is the default theme defined by the portal?
+// themeName = getPortalProperty(
+// Constants.PORTAL_PARAMETER_VAADIN_THEME,
+// request.getPortalContext());
+// }
+//
+// if (themeName == null) {
+// // no, using the default theme defined by Vaadin
+// themeName = DEFAULT_THEME_NAME;
+// }
+//
+// return themeName;
+// }
+//
+// protected abstract Class<? extends Application> getApplicationClass()
+// throws ClassNotFoundException;
+//
+// protected Application getNewApplication(PortletRequest request)
+// throws PortletException {
+// try {
+// final Application application = getApplicationClass().newInstance();
+// return application;
+// } catch (final IllegalAccessException e) {
+// throw new PortletException("getNewApplication failed", e);
+// } catch (final InstantiationException e) {
+// throw new PortletException("getNewApplication failed", e);
+// } catch (final ClassNotFoundException e) {
+// throw new PortletException("getNewApplication failed", e);
+// }
+// }
+//
+// protected ClassLoader getClassLoader() throws PortletException {
+// // TODO Add support for custom class loader
+// return getClass().getClassLoader();
+// }
+//
+// /**
+// * Get system messages from the current application class
+// *
+// * @return
+// */
+// protected SystemMessages getSystemMessages() {
+// try {
+// Class<? extends Application> appCls = getApplicationClass();
+// Method m = appCls.getMethod("getSystemMessages", (Class[]) null);
+// return (Application.SystemMessages) m.invoke(null, (Object[]) null);
+// } catch (ClassNotFoundException e) {
+// // This should never happen
+// throw new SystemMessageException(e);
+// } catch (SecurityException e) {
+// throw new SystemMessageException(
+// "Application.getSystemMessage() should be static public", e);
+// } catch (NoSuchMethodException e) {
+// // This is completely ok and should be silently ignored
+// } catch (IllegalArgumentException e) {
+// // This should never happen
+// throw new SystemMessageException(e);
+// } catch (IllegalAccessException e) {
+// throw new SystemMessageException(
+// "Application.getSystemMessage() should be static public", e);
+// } catch (InvocationTargetException e) {
+// // This should never happen
+// throw new SystemMessageException(e);
+// }
+// return Application.getSystemMessages();
+// }
+//
+// private void handleServiceException(PortletRequest request,
+// PortletResponse response, Application application, Throwable e)
+// throws IOException, PortletException {
+// // TODO Check that this error handler is working when running inside a
+// // portlet
+//
+// // if this was an UIDL request, response UIDL back to client
+// if (getRequestType(request) == RequestType.UIDL) {
+// Application.SystemMessages ci = getSystemMessages();
+// criticalNotification(request, (ResourceResponse) response,
+// ci.getInternalErrorCaption(), ci.getInternalErrorMessage(),
+// null, ci.getInternalErrorURL());
+// if (application != null) {
+// application.getErrorHandler()
+// .terminalError(new RequestError(e));
+// } else {
+// throw new PortletException(e);
+// }
+// } else {
+// // Re-throw other exceptions
+// throw new PortletException(e);
+// }
+//
+// }
+//
+// @SuppressWarnings("serial")
+// public class RequestError implements Terminal.ErrorEvent, Serializable {
+//
+// private final Throwable throwable;
+//
+// public RequestError(Throwable throwable) {
+// this.throwable = throwable;
+// }
+//
+// public Throwable getThrowable() {
+// return throwable;
+// }
+//
+// }
+//
+// /**
+// * Send notification to client's application. Used to notify client of
+// * critical errors and session expiration due to long inactivity. Server has
+// * no knowledge of what application client refers to.
+// *
+// * @param request
+// * the Portlet request instance.
+// * @param response
+// * the Portlet response to write to.
+// * @param caption
+// * for the notification
+// * @param message
+// * for the notification
+// * @param details
+// * a detail message to show in addition to the passed message.
+// * Currently shown directly but could be hidden behind a details
+// * drop down.
+// * @param url
+// * url to load after message, null for current page
+// * @throws IOException
+// * if the writing failed due to input/output error.
+// */
+// void criticalNotification(PortletRequest request, MimeResponse response,
+// String caption, String message, String details, String url)
+// throws IOException {
+//
+// // clients JS app is still running, but server application either
+// // no longer exists or it might fail to perform reasonably.
+// // send a notification to client's application and link how
+// // to "restart" application.
+//
+// if (caption != null) {
+// caption = "\"" + caption + "\"";
+// }
+// if (details != null) {
+// if (message == null) {
+// message = details;
+// } else {
+// message += "<br/><br/>" + details;
+// }
+// }
+// if (message != null) {
+// message = "\"" + message + "\"";
+// }
+// if (url != null) {
+// url = "\"" + url + "\"";
+// }
+//
+// // Set the response type
+// response.setContentType("application/json; charset=UTF-8");
+// final OutputStream out = response.getPortletOutputStream();
+// final PrintWriter outWriter = new PrintWriter(new BufferedWriter(
+// new OutputStreamWriter(out, "UTF-8")));
+// outWriter.print("for(;;);[{\"changes\":[], \"meta\" : {"
+// + "\"appError\": {" + "\"caption\":" + caption + ","
+// + "\"message\" : " + message + "," + "\"url\" : " + url
+// + "}}, \"resources\": {}, \"locales\":[]}]");
+// outWriter.close();
+// }
+//
+// /**
+// * Returns a portal configuration property.
+// *
+// * Liferay is handled separately as
+// * {@link PortalContext#getProperty(String)} does not return portal
+// * properties from e.g. portal-ext.properties .
+// *
+// * @param name
+// * @param context
+// * @return
+// */
+// protected static String getPortalProperty(String name, PortalContext context) {
+// boolean isLifeRay = context.getPortalInfo().toLowerCase()
+// .contains("liferay");
+//
+// // TODO test on non-LifeRay platforms
+//
+// String value;
+// if (isLifeRay) {
+// value = getLifeRayPortalProperty(name);
+// } else {
+// value = context.getProperty(name);
+// }
+//
+// return value;
+// }
+//
+// private static String getLifeRayPortalProperty(String name) {
+// String value;
+// try {
+// value = PropsUtil.get(name);
+// } catch (Exception e) {
+// value = null;
+// }
+// return value;
+// }
+//
+// /**
+// * Try to get an HTTP header value from a request using portal specific
+// * APIs.
+// *
+// * @param name
+// * HTTP header name
+// * @return the value of the header (empty string if defined without a value,
+// * null if the parameter is not present or retrieving it failed)
+// */
+// private static String getHTTPHeader(PortletRequest request, String name) {
+// String value = null;
+// String portalInfo = request.getPortalContext().getPortalInfo()
+// .toLowerCase();
+// if (portalInfo.contains("liferay")) {
+// value = getLiferayHTTPHeader(request, name);
+// } else if (portalInfo.contains("gatein")) {
+// value = getGateInHTTPHeader(request, name);
+// }
+// return value;
+// }
+//
+// /**
+// * Try to get the value of a HTTP request parameter from a portlet request
+// * using portal specific APIs. It is not possible to get the HTTP request
+// * parameters using the official Portlet 2.0 API.
+// *
+// * @param name
+// * HTTP request parameter name
+// * @return the value of the parameter (empty string if parameter defined
+// * without a value, null if the parameter is not present or
+// * retrieving it failed)
+// */
+// private static String getHTTPRequestParameter(PortletRequest request,
+// String name) {
+// String value = request.getParameter(name);
+// if (value == null) {
+// String portalInfo = request.getPortalContext().getPortalInfo()
+// .toLowerCase();
+// if (portalInfo.contains("liferay")) {
+// value = getLiferayHTTPRequestParameter(request, name);
+// } else if (portalInfo.contains("gatein")) {
+// value = getGateInHTTPRequestParameter(request, name);
+// }
+// }
+// return value;
+// }
+//
+// private static String getGateInHTTPRequestParameter(PortletRequest request,
+// String name) {
+// String value = null;
+// try {
+// Method getRealReq = request.getClass().getMethod("getRealRequest");
+// HttpServletRequestWrapper origRequest = (HttpServletRequestWrapper) getRealReq
+// .invoke(request);
+// value = origRequest.getParameter(name);
+// } catch (Exception e) {
+// // do nothing - not on GateIn simple-portal
+// }
+// return value;
+// }
+//
+// private static String getLiferayHTTPRequestParameter(
+// PortletRequest request, String name) {
+// try {
+// // httpRequest = PortalUtil.getHttpServletRequest(request);
+// HttpServletRequest httpRequest = (HttpServletRequest) PortalClassInvoker
+// .invoke("com.liferay.portal.util.PortalUtil",
+// "getHttpServletRequest", request);
+//
+// // httpRequest =
+// // PortalUtil.getOriginalServletRequest(httpRequest);
+// httpRequest = (HttpServletRequest) PortalClassInvoker.invoke(
+// "com.liferay.portal.util.PortalUtil",
+// "getOriginalServletRequest", httpRequest);
+// if (httpRequest != null) {
+// return httpRequest.getParameter(name);
+// }
+// } catch (Exception e) {
+// // ignore and return null - unable to get the original request
+// }
+// return null;
+// }
+//
+// private static String getGateInHTTPHeader(PortletRequest request,
+// String name) {
+// String value = null;
+// try {
+// Method getRealReq = request.getClass().getMethod("getRealRequest");
+// HttpServletRequestWrapper origRequest = (HttpServletRequestWrapper) getRealReq
+// .invoke(request);
+// value = origRequest.getHeader(name);
+// } catch (Exception e) {
+// // do nothing - not on GateIn simple-portal
+// }
+// return value;
+// }
+//
+// private static String getLiferayHTTPHeader(PortletRequest request,
+// String name) {
+// try {
+// // httpRequest = PortalUtil.getHttpServletRequest(request);
+// HttpServletRequest httpRequest = (HttpServletRequest) PortalClassInvoker
+// .invoke("com.liferay.portal.util.PortalUtil",
+// "getHttpServletRequest", request);
+//
+// // httpRequest =
+// // PortalUtil.getOriginalServletRequest(httpRequest);
+// httpRequest = (HttpServletRequest) PortalClassInvoker.invoke(
+// "com.liferay.portal.util.PortalUtil",
+// "getOriginalServletRequest", httpRequest);
+// if (httpRequest != null) {
+// return httpRequest.getHeader(name);
+// }
+// } catch (Exception e) {
+// // ignore and return null - unable to get the original request
+// }
+// return null;
+// }
+//
+// /**
+// *
+// * Gets the application context for a PortletSession. If no context is
+// * currently stored in a session a new context is created and stored in the
+// * session.
+// *
+// * @param portletSession
+// * the portlet session.
+// * @return the application context for the session.
+// */
+// protected PortletApplicationContext2 getApplicationContext(
+// PortletSession portletSession) {
+// return PortletApplicationContext2.getApplicationContext(portletSession);
+// }
+//
+// }
diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
index 6af45305e7..35ce753cab 100644
--- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
+++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
@@ -23,7 +23,6 @@ import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Locale;
-import java.util.Map;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -44,7 +43,7 @@ import com.vaadin.terminal.Terminal;
import com.vaadin.terminal.ThemeResource;
import com.vaadin.terminal.URIHandler;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.ui.Window;
+import com.vaadin.ui.Root;
/**
* Abstract implementation of the ApplicationServlet which handles all
@@ -484,10 +483,10 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
return;
} else if (requestType == RequestType.UIDL) {
// Handles AJAX UIDL requests
- Window window = applicationManager.getApplicationWindow(
- request, this, application, null);
+ Root root = applicationManager.getApplicationRoot(request,
+ this, application, null);
applicationManager.handleUidlRequest(request, response, this,
- window);
+ root);
return;
}
@@ -498,34 +497,35 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
return;
}
- // Finds the window within the application
- Window window = getApplicationWindow(request, applicationManager,
+ // Finds the root within the application
+ Root root = getApplicationRoot(request, applicationManager,
application);
- if (window == null) {
+ if (root == null) {
throw new ServletException(ERROR_NO_WINDOW_FOUND);
}
- // Sets terminal type for the window, if not already set
- if (window.getTerminal() == null) {
- window.setTerminal(webApplicationContext.getBrowser());
+ // Sets terminal type for the root, if not already set
+ if (root.getTerminal() == null) {
+ root.setTerminal(webApplicationContext.getBrowser());
}
// Handle parameters
- final Map<String, String[]> parameters = request.getParameterMap();
- if (window != null && parameters != null) {
- window.handleParameters(parameters);
- }
+ // final Map<String, String[]> parameters =
+ // request.getParameterMap();
+ // if (root != null && parameters != null) {
+ // root.handleParameters(parameters);
+ // }
/*
* Call the URI handlers and if this turns out to be a download
* request, send the file to the client
*/
- if (handleURI(applicationManager, window, request, response)) {
- return;
- }
+ // if (handleURI(applicationManager, root, request, response)) {
+ // return;
+ // }
// Send initial AJAX page that kickstarts a Vaadin application
- writeAjaxPage(request, response, window, application);
+ writeAjaxPage(request, response, root, application);
} catch (final SessionExpiredException e) {
// Session has expired, notify user
@@ -995,24 +995,25 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
}
/**
- * Returns the theme for given request/window
+ * Returns the theme for given request/root
*
* @param request
- * @param window
+ * @param root
* @return
*/
- private String getThemeForWindow(HttpServletRequest request, Window window) {
+ private String getThemeForRoot(HttpServletRequest request, Root root) {
// Finds theme name
String themeName;
if (request.getParameter(URL_PARAMETER_THEME) != null) {
themeName = request.getParameter(URL_PARAMETER_THEME);
} else {
- themeName = window.getTheme();
+ // TODO Should read annotation
+ themeName = null;
}
if (themeName == null) {
- // no explicit theme for window defined
+ // no explicit theme for root defined
if (request.getAttribute(REQUEST_DEFAULT_THEME) != null) {
// the default theme is defined in request (by portal)
themeName = (String) request
@@ -1063,33 +1064,34 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
return DEFAULT_THEME_NAME;
}
- /**
- * Calls URI handlers for the request. If an URI handler returns a
- * DownloadStream the stream is passed to the client for downloading.
- *
- * @param applicationManager
- * @param window
- * @param request
- * @param response
- * @return true if an DownloadStream was sent to the client, false otherwise
- * @throws IOException
- */
- protected boolean handleURI(CommunicationManager applicationManager,
- Window window, HttpServletRequest request,
- HttpServletResponse response) throws IOException {
- // Handles the URI
- DownloadStream download = applicationManager.handleURI(window, request,
- response, this);
-
- // A download request
- if (download != null) {
- // Client downloads an resource
- handleDownload(download, request, response);
- return true;
- }
-
- return false;
- }
+ // /**
+ // * Calls URI handlers for the request. If an URI handler returns a
+ // * DownloadStream the stream is passed to the client for downloading.
+ // *
+ // * @param applicationManager
+ // * @param window
+ // * @param request
+ // * @param response
+ // * @return true if an DownloadStream was sent to the client, false
+ // otherwise
+ // * @throws IOException
+ // */
+ // protected boolean handleURI(CommunicationManager applicationManager,
+ // Root window, HttpServletRequest request,
+ // HttpServletResponse response) throws IOException {
+ // // Handles the URI
+ // DownloadStream download = applicationManager.handleURI(window, request,
+ // response, this);
+ //
+ // // A download request
+ // if (download != null) {
+ // // Client downloads an resource
+ // handleDownload(download, request, response);
+ // return true;
+ // }
+ //
+ // return false;
+ // }
void handleServiceSessionExpired(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
@@ -1666,7 +1668,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
* <li>
* {@link #writeAjaxPageHtmlBodyStart(BufferedWriter, HttpServletRequest)}
* <li>
- * {@link #writeAjaxPageHtmlVaadinScripts(Window, String, Application, BufferedWriter, String, String, String, HttpServletRequest)}
+ * {@link #writeAjaxPageHtmlVaadinScripts(Root, String, Application, BufferedWriter, String, String, String, HttpServletRequest)}
* <li>
* {@link #writeAjaxPageHtmlMainDiv(BufferedWriter, String, String, String, HttpServletRequest)}
* <li> {@link #writeAjaxPageHtmlBodyEnd(BufferedWriter)}
@@ -1678,7 +1680,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
* the HTTP response to write to.
* @param out
* @param unhandledParameters
- * @param window
+ * @param root
* @param terminalType
* @param theme
* @throws IOException
@@ -1688,7 +1690,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
* represented by the given URL.
*/
protected void writeAjaxPage(HttpServletRequest request,
- HttpServletResponse response, Window window, Application application)
+ HttpServletResponse response, Root root, Application application)
throws IOException, MalformedURLException, ServletException {
// e.g portlets only want a html fragment
@@ -1702,7 +1704,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
final BufferedWriter page = new BufferedWriter(new OutputStreamWriter(
response.getOutputStream(), "UTF-8"));
- String title = ((window.getCaption() == null) ? "Vaadin 6" : window
+ String title = ((root.getCaption() == null) ? "Vaadin 6" : root
.getCaption());
/* Fetch relative url to application */
@@ -1713,7 +1715,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
appUrl = appUrl.substring(0, appUrl.length() - 1);
}
- String themeName = getThemeForWindow(request, window);
+ String themeName = getThemeForRoot(request, root);
String themeUri = getThemeUri(themeName, request);
@@ -1737,8 +1739,8 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
}
appId = appId + "-" + hashCode;
- writeAjaxPageHtmlVaadinScripts(window, themeName, application, page,
- appUrl, themeUri, appId, request);
+ writeAjaxPageHtmlVaadinScripts(themeName, application, page, appUrl,
+ themeUri, appId, request);
/*- Add classnames;
* .v-app
@@ -1852,7 +1854,6 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
* <p>
* Override this method if you want to add some custom html around scripts.
*
- * @param window
* @param themeName
* @param application
* @param page
@@ -1863,7 +1864,8 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
* @throws ServletException
* @throws IOException
*/
- protected void writeAjaxPageHtmlVaadinScripts(Window window,
+ protected void writeAjaxPageHtmlVaadinScripts(
+ // Window window,
String themeName, Application application,
final BufferedWriter page, String appUrl, String themeUri,
String appId, HttpServletRequest request) throws ServletException,
@@ -1925,10 +1927,10 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
page.write("vaadin.vaadinConfigurations[\"" + appId + "\"] = {");
page.write("appUri:'" + appUrl + "', ");
- if (window != application.getMainWindow()) {
- page.write("windowName: \""
- + JsonPaintTarget.escapeJSON(window.getName()) + "\", ");
- }
+ // if (window != application.getMainWindow()) {
+ // page.write("windowName: \""
+ // + JsonPaintTarget.escapeJSON(window.getName()) + "\", ");
+ // }
if (isStandalone()) {
page.write("standalone: true, ");
}
@@ -2246,49 +2248,50 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
}
/**
- * Gets the existing application or create a new one. Get a window within an
+ * Gets the existing application or create a new one. Get a root within an
* application based on the requested URI.
*
* @param request
* the HTTP Request.
* @param application
- * the Application to query for window.
- * @return Window matching the given URI or null if not found.
+ * the Application to query for root.
+ * @return Root matching the given URI or null if not found.
* @throws ServletException
* if an exception has occurred that interferes with the
* servlet's normal operation.
*/
- protected Window getApplicationWindow(HttpServletRequest request,
+ protected Root getApplicationRoot(HttpServletRequest request,
CommunicationManager applicationManager, Application application)
throws ServletException {
-
- // Finds the window where the request is handled
- Window assumedWindow = null;
- String path = getRequestPathInfo(request);
-
- // Main window as the URI is empty
- if (!(path == null || path.length() == 0 || path.equals("/"))) {
- if (path.startsWith("/APP/")) {
- // Use main window for application resources
- return application.getMainWindow();
- }
- String windowName = null;
- if (path.charAt(0) == '/') {
- path = path.substring(1);
- }
- final int index = path.indexOf('/');
- if (index < 0) {
- windowName = path;
- path = "";
- } else {
- windowName = path.substring(0, index);
- }
- assumedWindow = application.getWindow(windowName);
-
- }
-
- return applicationManager.getApplicationWindow(request, this,
- application, assumedWindow);
+ return application.getRoot();
+ //
+ // // Finds the window where the request is handled
+ // Window assumedWindow = null;
+ // String path = getRequestPathInfo(request);
+ //
+ // // Main window as the URI is empty
+ // if (!(path == null || path.length() == 0 || path.equals("/"))) {
+ // if (path.startsWith("/APP/")) {
+ // // Use main window for application resources
+ // return application.getMainWindow();
+ // }
+ // String windowName = null;
+ // if (path.charAt(0) == '/') {
+ // path = path.substring(1);
+ // }
+ // final int index = path.indexOf('/');
+ // if (index < 0) {
+ // windowName = path;
+ // path = "";
+ // } else {
+ // windowName = path.substring(0, index);
+ // }
+ // assumedWindow = application.getWindow(windowName);
+ //
+ // }
+ //
+ // return applicationManager.getApplicationWindow(request, this,
+ // application, assumedWindow);
}
/**
diff --git a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
index c952623156..db07a5ac33 100644
--- a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
+++ b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
@@ -16,7 +16,6 @@ import java.io.PrintWriter;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.net.URL;
import java.security.GeneralSecurityException;
import java.text.CharacterIterator;
import java.text.DateFormat;
@@ -67,6 +66,7 @@ import com.vaadin.terminal.gwt.server.ComponentSizeValidator.InvalidLayout;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.AbstractField;
import com.vaadin.ui.Component;
+import com.vaadin.ui.Root;
import com.vaadin.ui.Window;
/**
@@ -690,14 +690,14 @@ public abstract class AbstractCommunicationManager implements
* @param request
* @param response
* @param callback
- * @param window
+ * @param root
* target window for the UIDL request, can be null if target not
* found
* @throws IOException
* @throws InvalidUIDLSecurityKeyException
*/
protected void doHandleUidlRequest(Request request, Response response,
- Callback callback, Window window) throws IOException,
+ Callback callback, Root root) throws IOException,
InvalidUIDLSecurityKeyException {
requestThemeName = request.getParameter("theme");
@@ -734,7 +734,7 @@ public abstract class AbstractCommunicationManager implements
// Finds the window within the application
if (application.isRunning()) {
// Returns if no window found
- if (window == null) {
+ if (root == null) {
// This should not happen, no windows exists but
// application is still open.
logger.warning("Could not get window for application with request ID "
@@ -748,8 +748,7 @@ public abstract class AbstractCommunicationManager implements
}
// Change all variables based on request parameters
- if (!handleVariables(request, response, callback, application,
- window)) {
+ if (!handleVariables(request, response, callback, application, root)) {
// var inconsistency; the client is probably out-of-sync
SystemMessages ci = null;
@@ -780,7 +779,7 @@ public abstract class AbstractCommunicationManager implements
}
paintAfterVariableChanges(request, response, callback, repaintAll,
- outWriter, window, analyzeLayouts);
+ outWriter, root, analyzeLayouts);
if (closingWindowName != null) {
currentlyOpenWindowsInClient.remove(closingWindowName);
@@ -866,11 +865,11 @@ public abstract class AbstractCommunicationManager implements
*/
private void paintAfterVariableChanges(Request request, Response response,
Callback callback, boolean repaintAll, final PrintWriter outWriter,
- Window window, boolean analyzeLayouts) throws PaintException,
+ Root root, boolean analyzeLayouts) throws PaintException,
IOException {
if (repaintAll) {
- makeAllPaintablesDirty(window);
+ makeAllPaintablesDirty(root);
}
// Removes application if it has stopped during variable changes
@@ -901,18 +900,18 @@ public abstract class AbstractCommunicationManager implements
// If the browser-window has been closed - we do not need to paint it at
// all
- if (window.getName().equals(closingWindowName)) {
+ if (root.getName().equals(closingWindowName)) {
outWriter.print("\"changes\":[]");
} else {
// re-get window - may have been changed
- Window newWindow = doGetApplicationWindow(request, callback,
- application, window);
- if (newWindow != window) {
- window = newWindow;
+ Root newRoot = doGetApplicationWindow(request, callback,
+ application, root);
+ if (newRoot != root) {
+ root = newRoot;
repaintAll = true;
}
- writeUidlResponce(callback, repaintAll, outWriter, window,
+ writeUidlResponce(callback, repaintAll, outWriter, root,
analyzeLayouts);
}
@@ -923,7 +922,7 @@ public abstract class AbstractCommunicationManager implements
}
public void writeUidlResponce(Callback callback, boolean repaintAll,
- final PrintWriter outWriter, Window window, boolean analyzeLayouts)
+ final PrintWriter outWriter, Root root, boolean analyzeLayouts)
throws PaintException {
outWriter.print("\"changes\":[");
@@ -933,17 +932,17 @@ public abstract class AbstractCommunicationManager implements
JsonPaintTarget paintTarget = new JsonPaintTarget(this, outWriter,
!repaintAll);
- OpenWindowCache windowCache = currentlyOpenWindowsInClient.get(window
+ OpenWindowCache windowCache = currentlyOpenWindowsInClient.get(root
.getName());
if (windowCache == null) {
windowCache = new OpenWindowCache();
- currentlyOpenWindowsInClient.put(window.getName(), windowCache);
+ currentlyOpenWindowsInClient.put(root.getName(), windowCache);
}
// Paints components
if (repaintAll) {
paintables = new ArrayList<Paintable>();
- paintables.add(window);
+ paintables.add(root);
// Reset sent locales
locales = null;
@@ -967,7 +966,7 @@ public abstract class AbstractCommunicationManager implements
dirtyPaintables.remove(p);
}
}
- paintables = getDirtyVisibleComponents(window);
+ paintables = getDirtyVisibleComponents(root);
}
if (paintables != null) {
@@ -1003,10 +1002,10 @@ public abstract class AbstractCommunicationManager implements
final Paintable p = i.next();
// TODO CLEAN
- if (p instanceof Window) {
- final Window w = (Window) p;
- if (w.getTerminal() == null) {
- w.setTerminal(application.getMainWindow().getTerminal());
+ if (p instanceof Root) {
+ final Root r = (Root) p;
+ if (r.getTerminal() == null) {
+ r.setTerminal(application.getRoot().getTerminal());
}
}
/*
@@ -1037,15 +1036,15 @@ public abstract class AbstractCommunicationManager implements
.validateComponentRelativeSizes(w.getContent(),
null, null);
- // Also check any existing subwindows
- if (w.getChildWindows() != null) {
- for (Window subWindow : w.getChildWindows()) {
- invalidComponentRelativeSizes = ComponentSizeValidator
- .validateComponentRelativeSizes(
- subWindow.getContent(),
- invalidComponentRelativeSizes, null);
- }
- }
+ // // Also check any existing subwindows
+ // if (w.getChildWindows() != null) {
+ // for (Window subWindow : w.getChildWindows()) {
+ // invalidComponentRelativeSizes = ComponentSizeValidator
+ // .validateComponentRelativeSizes(
+ // subWindow.getContent(),
+ // invalidComponentRelativeSizes, null);
+ // }
+ // }
}
}
}
@@ -1134,8 +1133,8 @@ public abstract class AbstractCommunicationManager implements
final String resource = (String) i.next();
InputStream is = null;
try {
- is = callback.getThemeResourceAsStream(getTheme(window),
- resource);
+ is = callback
+ .getThemeResourceAsStream(getTheme(root), resource);
} catch (final Exception e) {
// FIXME: Handle exception
logger.log(Level.FINER, "Failed to get theme resource stream.",
@@ -1205,8 +1204,8 @@ public abstract class AbstractCommunicationManager implements
return maxInactiveInterval;
}
- private String getTheme(Window window) {
- String themeName = window.getTheme();
+ private String getTheme(Root root) {
+ String themeName = null;// window.getTheme();
String requestThemeName = getRequestTheme();
if (requestThemeName != null) {
@@ -1222,19 +1221,19 @@ public abstract class AbstractCommunicationManager implements
return requestThemeName;
}
- public void makeAllPaintablesDirty(Window window) {
+ public void makeAllPaintablesDirty(Root root) {
// If repaint is requested, clean all ids in this root window
for (final Iterator<String> it = idPaintableMap.keySet().iterator(); it
.hasNext();) {
final Component c = (Component) idPaintableMap.get(it.next());
- if (isChildOf(window, c)) {
+ if (isChildOf(root, c)) {
it.remove();
paintableIdMap.remove(c);
}
}
// clean WindowCache
- OpenWindowCache openWindowCache = currentlyOpenWindowsInClient
- .get(window.getName());
+ OpenWindowCache openWindowCache = currentlyOpenWindowsInClient.get(root
+ .getName());
if (openWindowCache != null) {
openWindowCache.clear();
}
@@ -1260,7 +1259,7 @@ public abstract class AbstractCommunicationManager implements
* @return true if successful, false if there was an inconsistency
*/
private boolean handleVariables(Request request, Response response,
- Callback callback, Application application2, Window window)
+ Callback callback, Application application2, Root root)
throws IOException, InvalidUIDLSecurityKeyException {
boolean success = true;
@@ -1313,7 +1312,7 @@ public abstract class AbstractCommunicationManager implements
new CharArrayWriter());
paintAfterVariableChanges(request, response, callback,
- true, outWriter, window, false);
+ true, outWriter, root, false);
}
@@ -1386,7 +1385,7 @@ public abstract class AbstractCommunicationManager implements
&& ((Window) owner).getParent() == null) {
final Boolean close = (Boolean) m.get("close");
if (close != null && close.booleanValue()) {
- closingWindowName = ((Window) owner).getName();
+ closingWindowName = ((Root) owner).getName();
}
}
} catch (Exception e) {
@@ -1827,97 +1826,99 @@ public abstract class AbstractCommunicationManager implements
* @param assumedWindow
* @return
*/
- protected Window doGetApplicationWindow(Request request, Callback callback,
- Application application, Window assumedWindow) {
-
- Window window = null;
-
- // If the client knows which window to use, use it if possible
- String windowClientRequestedName = request.getParameter("windowName");
-
- if (assumedWindow != null
- && application.getWindows().contains(assumedWindow)) {
- windowClientRequestedName = assumedWindow.getName();
- }
- if (windowClientRequestedName != null) {
- window = application.getWindow(windowClientRequestedName);
- if (window != null) {
- return window;
- }
- }
-
- // If client does not know what window it wants
- if (window == null && !request.isRunningInPortlet()) {
- // This is only supported if the application is running inside a
- // servlet
-
- // Get the path from URL
- String path = callback.getRequestPathInfo(request);
-
- /*
- * If the path is specified, create name from it.
- *
- * An exception is if UIDL request have come this far. This happens
- * if main window is refreshed. In that case we always return main
- * window (infamous hacky support for refreshes if only main window
- * is used). However we are not returning with main window here (we
- * will later if things work right), because the code is so cryptic
- * that nobody really knows what it does.
- */
- boolean pathMayContainWindowName = path != null
- && path.length() > 0 && !path.equals("/");
- if (pathMayContainWindowName) {
- boolean uidlRequest = path.startsWith("/UIDL");
- if (!uidlRequest) {
- String windowUrlName = null;
- if (path.charAt(0) == '/') {
- path = path.substring(1);
- }
- final int index = path.indexOf('/');
- if (index < 0) {
- windowUrlName = path;
- path = "";
- } else {
- windowUrlName = path.substring(0, index);
- path = path.substring(index + 1);
- }
-
- window = application.getWindow(windowUrlName);
- }
- }
-
- }
-
- // By default, use mainwindow
- if (window == null) {
- window = application.getMainWindow();
- // Return null if no main window was found
- if (window == null) {
- return null;
- }
- }
-
- // If the requested window is already open, resolve conflict
- if (currentlyOpenWindowsInClient.containsKey(window.getName())) {
- String newWindowName = window.getName();
-
- synchronized (AbstractCommunicationManager.class) {
- while (currentlyOpenWindowsInClient.containsKey(newWindowName)) {
- newWindowName = window.getName() + "_"
- + nextUnusedWindowSuffix++;
- }
- }
-
- window = application.getWindow(newWindowName);
-
- // If everything else fails, use main window even in case of
- // conflicts
- if (window == null) {
- window = application.getMainWindow();
- }
- }
-
- return window;
+ protected Root doGetApplicationWindow(Request request, Callback callback,
+ Application application, Root assumedRoot) {
+ return application.getRoot();
+
+ // Window window = null;
+ //
+ // // If the client knows which window to use, use it if possible
+ // String windowClientRequestedName =
+ // request.getParameter("windowName");
+ //
+ // if (assumedWindow != null
+ // && application.getWindows().contains(assumedWindow)) {
+ // windowClientRequestedName = assumedWindow.getName();
+ // }
+ // if (windowClientRequestedName != null) {
+ // window = application.getWindow(windowClientRequestedName);
+ // if (window != null) {
+ // return window;
+ // }
+ // }
+ //
+ // // If client does not know what window it wants
+ // if (window == null && !request.isRunningInPortlet()) {
+ // // This is only supported if the application is running inside a
+ // // servlet
+ //
+ // // Get the path from URL
+ // String path = callback.getRequestPathInfo(request);
+ //
+ // /*
+ // * If the path is specified, create name from it.
+ // *
+ // * An exception is if UIDL request have come this far. This happens
+ // * if main window is refreshed. In that case we always return main
+ // * window (infamous hacky support for refreshes if only main window
+ // * is used). However we are not returning with main window here (we
+ // * will later if things work right), because the code is so cryptic
+ // * that nobody really knows what it does.
+ // */
+ // boolean pathMayContainWindowName = path != null
+ // && path.length() > 0 && !path.equals("/");
+ // if (pathMayContainWindowName) {
+ // boolean uidlRequest = path.startsWith("/UIDL");
+ // if (!uidlRequest) {
+ // String windowUrlName = null;
+ // if (path.charAt(0) == '/') {
+ // path = path.substring(1);
+ // }
+ // final int index = path.indexOf('/');
+ // if (index < 0) {
+ // windowUrlName = path;
+ // path = "";
+ // } else {
+ // windowUrlName = path.substring(0, index);
+ // path = path.substring(index + 1);
+ // }
+ //
+ // window = application.getWindow(windowUrlName);
+ // }
+ // }
+ //
+ // }
+ //
+ // // By default, use mainwindow
+ // if (window == null) {
+ // window = application.getMainWindow();
+ // // Return null if no main window was found
+ // if (window == null) {
+ // return null;
+ // }
+ // }
+ //
+ // // If the requested window is already open, resolve conflict
+ // if (currentlyOpenWindowsInClient.containsKey(window.getName())) {
+ // String newWindowName = window.getName();
+ //
+ // synchronized (AbstractCommunicationManager.class) {
+ // while (currentlyOpenWindowsInClient.containsKey(newWindowName)) {
+ // newWindowName = window.getName() + "_"
+ // + nextUnusedWindowSuffix++;
+ // }
+ // }
+ //
+ // window = application.getWindow(newWindowName);
+ //
+ // // If everything else fails, use main window even in case of
+ // // conflicts
+ // if (window == null) {
+ // window = application.getMainWindow();
+ // }
+ // }
+ //
+ // return window;
}
/**
@@ -2029,7 +2030,7 @@ public abstract class AbstractCommunicationManager implements
* root window for which dirty components is to be fetched
* @return
*/
- private ArrayList<Paintable> getDirtyVisibleComponents(Window w) {
+ private ArrayList<Paintable> getDirtyVisibleComponents(Root r) {
final ArrayList<Paintable> resultset = new ArrayList<Paintable>(
dirtyPaintables);
@@ -2048,18 +2049,18 @@ public abstract class AbstractCommunicationManager implements
resultset.remove(p);
i.remove();
} else {
- Window componentsRoot = component.getWindow();
+ Root componentsRoot = component.getRoot();
if (componentsRoot == null) {
// This should not happen unless somebody has overriden
// getApplication or getWindow in an illegal way.
throw new IllegalStateException(
"component.getWindow() returned null for a component attached to the application");
}
- if (componentsRoot.getParent() != null) {
- // this is a subwindow
- componentsRoot = componentsRoot.getParent();
- }
- if (componentsRoot != w) {
+ // if (componentsRoot.getParent() != null) {
+ // // this is a subwindow
+ // componentsRoot = componentsRoot.getParent();
+ // }
+ if (componentsRoot != r) {
resultset.remove(p);
} else if (component.getParent() != null
&& !component.getParent().isVisible()) {
@@ -2240,32 +2241,34 @@ public abstract class AbstractCommunicationManager implements
// Handles the uri
try {
- URL context = application.getURL();
- if (window == application.getMainWindow()) {
- DownloadStream stream = null;
- /*
- * Application.handleURI run first. Handles possible
- * ApplicationResources.
- */
- stream = application.handleURI(context, uri);
- if (stream == null) {
- stream = window.handleURI(context, uri);
- }
- return stream;
- } else {
- // Resolve the prefix end index
- final int index = uri.indexOf('/');
- if (index > 0) {
- String prefix = uri.substring(0, index);
- URL windowContext;
- windowContext = new URL(context, prefix + "/");
- final String windowUri = (uri.length() > prefix.length() + 1) ? uri
- .substring(prefix.length() + 1) : "";
- return window.handleURI(windowContext, windowUri);
- } else {
- return null;
- }
- }
+ throw new RuntimeException("Not ported to use roots");
+ // URL context = application.getURL();
+ // if (window == application.getMainWindow()) {
+ // DownloadStream stream = null;
+ // /*
+ // * Application.handleURI run first. Handles possible
+ // * ApplicationResources.
+ // */
+ // stream = application.handleURI(context, uri);
+ // if (stream == null) {
+ // stream = window.handleURI(context, uri);
+ // }
+ // return stream;
+ // } else {
+ // // Resolve the prefix end index
+ // final int index = uri.indexOf('/');
+ // if (index > 0) {
+ // String prefix = uri.substring(0, index);
+ // URL windowContext;
+ // windowContext = new URL(context, prefix + "/");
+ // final String windowUri = (uri.length() > prefix.length() + 1) ?
+ // uri
+ // .substring(prefix.length() + 1) : "";
+ // return window.handleURI(windowContext, windowUri);
+ // } else {
+ // return null;
+ // }
+ // }
} catch (final Throwable t) {
application.getErrorHandler().terminalError(
diff --git a/src/com/vaadin/terminal/gwt/server/ApplicationPortlet.java b/src/com/vaadin/terminal/gwt/server/ApplicationPortlet.java
index 2623807b59..ef646a0748 100644
--- a/src/com/vaadin/terminal/gwt/server/ApplicationPortlet.java
+++ b/src/com/vaadin/terminal/gwt/server/ApplicationPortlet.java
@@ -1,250 +1,250 @@
/*
@ITMillApache2LicenseForJavaFiles@
*/
-package com.vaadin.terminal.gwt.server;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.io.Serializable;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.portlet.ActionRequest;
-import javax.portlet.ActionResponse;
-import javax.portlet.PortalContext;
-import javax.portlet.Portlet;
-import javax.portlet.PortletConfig;
-import javax.portlet.PortletException;
-import javax.portlet.PortletRequestDispatcher;
-import javax.portlet.PortletSession;
-import javax.portlet.RenderRequest;
-import javax.portlet.RenderResponse;
-
-import com.liferay.portal.kernel.util.PropsUtil;
-import com.vaadin.Application;
-
-/**
- * Portlet main class for Portlet 1.0 (JSR-168) portlets which consist of a
- * portlet and a servlet. For Portlet 2.0 (JSR-286, no servlet required), use
- * {@link ApplicationPortlet2} instead.
- */
-@SuppressWarnings("serial")
-public class ApplicationPortlet implements Portlet, Serializable {
- // portlet configuration parameters
- private static final String PORTLET_PARAMETER_APPLICATION = "application";
- private static final String PORTLET_PARAMETER_STYLE = "style";
- private static final String PORTLET_PARAMETER_WIDGETSET = "widgetset";
-
- // The application to show
- protected String app = null;
- // some applications might require forced height (and, more seldom, width)
- protected String style = null; // e.g "height:500px;"
- // force the portlet to use this widgetset - portlet level setting
- protected String portletWidgetset = null;
-
- public void destroy() {
-
- }
-
- public void init(PortletConfig config) throws PortletException {
- app = config.getInitParameter(PORTLET_PARAMETER_APPLICATION);
- if (app == null) {
- throw new PortletException(
- "No porlet application url defined in portlet.xml. Define the '"
- + PORTLET_PARAMETER_APPLICATION
- + "' init parameter to be the servlet deployment path.");
- }
- style = config.getInitParameter(PORTLET_PARAMETER_STYLE);
- // enable forcing the selection of the widgetset in portlet
- // configuration for a single portlet (backwards compatibility)
- portletWidgetset = config.getInitParameter(PORTLET_PARAMETER_WIDGETSET);
- }
-
- public void processAction(ActionRequest request, ActionResponse response)
- throws PortletException, IOException {
- PortletApplicationContext.dispatchRequest(this, request, response);
- }
-
- public void render(RenderRequest request, RenderResponse response)
- throws PortletException, IOException {
-
- // display the Vaadin application
- writeAjaxWindow(request, response);
- }
-
- protected void writeAjaxWindow(RenderRequest request,
- RenderResponse response) throws IOException {
-
- response.setContentType("text/html");
- if (app != null) {
- PortletSession sess = request.getPortletSession();
- PortletApplicationContext ctx = PortletApplicationContext
- .getApplicationContext(sess);
-
- PortletRequestDispatcher dispatcher = sess.getPortletContext()
- .getRequestDispatcher("/" + app);
-
- try {
- // portal-wide settings
- PortalContext portalCtx = request.getPortalContext();
-
- boolean isLifeRay = portalCtx.getPortalInfo().toLowerCase()
- .contains("liferay");
-
- request.setAttribute(ApplicationServlet.REQUEST_FRAGMENT,
- "true");
-
- // fixed base theme to use - all portal pages with Vaadin
- // applications will load this exactly once
- String portalTheme = getPortalProperty(
- Constants.PORTAL_PARAMETER_VAADIN_THEME, portalCtx);
-
- String portalWidgetset = getPortalProperty(
- Constants.PORTAL_PARAMETER_VAADIN_WIDGETSET, portalCtx);
-
- // location of the widgetset(s) and default theme (to which
- // /VAADIN/widgetsets/...
- // is appended)
- String portalResourcePath = getPortalProperty(
- Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH,
- portalCtx);
-
- if (portalResourcePath != null) {
- // if portalResourcePath is defined, set it as a request
- // parameter which will override the default location in
- // servlet
- request.setAttribute(
- ApplicationServlet.REQUEST_VAADIN_STATIC_FILE_PATH,
- portalResourcePath);
- }
-
- // - if the user has specified a widgetset for this portlet, use
- // it from the portlet (not fully supported)
- // - otherwise, if specified, use the portal-wide widgetset
- // and widgetset path settings (recommended)
- // - finally, default to use the default widgetset if nothing
- // else is found
- if (portletWidgetset != null) {
- request.setAttribute(ApplicationServlet.REQUEST_WIDGETSET,
- portletWidgetset);
- }
- if (portalWidgetset != null) {
- request.setAttribute(
- ApplicationServlet.REQUEST_SHARED_WIDGETSET,
- portalWidgetset);
- }
-
- if (style != null) {
- request.setAttribute(ApplicationServlet.REQUEST_APPSTYLE,
- style);
- }
-
- // portalTheme is only used if the shared portal resource
- // directory is defined
- if (portalTheme != null && portalResourcePath != null) {
- request.setAttribute(
- ApplicationServlet.REQUEST_DEFAULT_THEME,
- portalTheme);
-
- String defaultThemeUri = null;
- defaultThemeUri = portalResourcePath + "/"
- + AbstractApplicationServlet.THEME_DIRECTORY_PATH
- + portalTheme;
- /*
- * Make sure portal default Vaadin theme is included in DOM.
- * Vaadin portlet themes do not "inherit" base theme, so we
- * need to force loading of the common base theme.
- */
- OutputStream out = response.getPortletOutputStream();
-
- // Using portal-wide theme
- String loadDefaultTheme = ("<script type=\"text/javascript\">\n"
- + "if(!vaadin) { var vaadin = {} } \n"
- + "if(!vaadin.themesLoaded) { vaadin.themesLoaded = {} } \n"
- + "if(!vaadin.themesLoaded['"
- + portalTheme
- + "']) {\n"
- + "var stylesheet = document.createElement('link');\n"
- + "stylesheet.setAttribute('rel', 'stylesheet');\n"
- + "stylesheet.setAttribute('type', 'text/css');\n"
- + "stylesheet.setAttribute('href', '"
- + defaultThemeUri
- + "/styles.css');\n"
- + "document.getElementsByTagName('head')[0].appendChild(stylesheet);\n"
- + "vaadin.themesLoaded['"
- + portalTheme
- + "'] = true;\n}\n" + "</script>\n");
- out.write(loadDefaultTheme.getBytes());
- }
-
- dispatcher.include(request, response);
-
- if (isLifeRay) {
- /*
- * Temporary support to heartbeat Liferay session when using
- * Vaadin based portlet. We hit an extra xhr to liferay
- * servlet to extend the session lifetime after each Vaadin
- * request. This hack can be removed when supporting portlet
- * 2.0 and resourceRequests.
- *
- * TODO make this configurable, this is not necessary with
- * some custom session configurations.
- */
- OutputStream out = response.getPortletOutputStream();
-
- String lifeRaySessionHearbeatHack = ("<script type=\"text/javascript\">"
- + "if(!vaadin.postRequestHooks) {"
- + " vaadin.postRequestHooks = {};"
- + "}"
- + "vaadin.postRequestHooks.liferaySessionHeartBeat = function() {"
- + " if (Liferay && Liferay.Session && Liferay.Session.setCookie) {"
- + " Liferay.Session.setCookie();"
- + " }"
- + "};" + "</script>");
- out.write(lifeRaySessionHearbeatHack.getBytes());
- }
-
- } catch (PortletException e) {
- PrintWriter out = response.getWriter();
- out.print("<h1>Servlet include failed!</h1>");
- Logger.getLogger(AbstractApplicationPortlet.class.getName())
- .log(Level.WARNING, "Servlet include failed", e);
- ctx.setPortletApplication(this, null);
- return;
- }
-
- Application app = (Application) request
- .getAttribute(Application.class.getName());
- ctx.setPortletApplication(this, app);
- ctx.firePortletRenderRequest(this, request, response);
-
- }
- }
-
- private String getPortalProperty(String name, PortalContext context) {
- boolean isLifeRay = context.getPortalInfo().toLowerCase()
- .contains("liferay");
-
- // TODO test on non-LifeRay platforms
-
- String value;
- if (isLifeRay) {
- value = getLifeRayPortalProperty(name);
- } else {
- value = context.getProperty(name);
- }
-
- return value;
- }
-
- private String getLifeRayPortalProperty(String name) {
- String value;
- try {
- value = PropsUtil.get(name);
- } catch (Exception e) {
- value = null;
- }
- return value;
- }
-}
+//package com.vaadin.terminal.gwt.server;
+//
+//import java.io.IOException;
+//import java.io.OutputStream;
+//import java.io.PrintWriter;
+//import java.io.Serializable;
+//import java.util.logging.Level;
+//import java.util.logging.Logger;
+//
+//import javax.portlet.ActionRequest;
+//import javax.portlet.ActionResponse;
+//import javax.portlet.PortalContext;
+//import javax.portlet.Portlet;
+//import javax.portlet.PortletConfig;
+//import javax.portlet.PortletException;
+//import javax.portlet.PortletRequestDispatcher;
+//import javax.portlet.PortletSession;
+//import javax.portlet.RenderRequest;
+//import javax.portlet.RenderResponse;
+//
+//import com.liferay.portal.kernel.util.PropsUtil;
+//import com.vaadin.Application;
+//
+///**
+// * Portlet main class for Portlet 1.0 (JSR-168) portlets which consist of a
+// * portlet and a servlet. For Portlet 2.0 (JSR-286, no servlet required), use
+// * {@link ApplicationPortlet2} instead.
+// */
+//@SuppressWarnings("serial")
+//public class ApplicationPortlet implements Portlet, Serializable {
+// // portlet configuration parameters
+// private static final String PORTLET_PARAMETER_APPLICATION = "application";
+// private static final String PORTLET_PARAMETER_STYLE = "style";
+// private static final String PORTLET_PARAMETER_WIDGETSET = "widgetset";
+//
+// // The application to show
+// protected String app = null;
+// // some applications might require forced height (and, more seldom, width)
+// protected String style = null; // e.g "height:500px;"
+// // force the portlet to use this widgetset - portlet level setting
+// protected String portletWidgetset = null;
+//
+// public void destroy() {
+//
+// }
+//
+// public void init(PortletConfig config) throws PortletException {
+// app = config.getInitParameter(PORTLET_PARAMETER_APPLICATION);
+// if (app == null) {
+// throw new PortletException(
+// "No porlet application url defined in portlet.xml. Define the '"
+// + PORTLET_PARAMETER_APPLICATION
+// + "' init parameter to be the servlet deployment path.");
+// }
+// style = config.getInitParameter(PORTLET_PARAMETER_STYLE);
+// // enable forcing the selection of the widgetset in portlet
+// // configuration for a single portlet (backwards compatibility)
+// portletWidgetset = config.getInitParameter(PORTLET_PARAMETER_WIDGETSET);
+// }
+//
+// public void processAction(ActionRequest request, ActionResponse response)
+// throws PortletException, IOException {
+// PortletApplicationContext.dispatchRequest(this, request, response);
+// }
+//
+// public void render(RenderRequest request, RenderResponse response)
+// throws PortletException, IOException {
+//
+// // display the Vaadin application
+// writeAjaxWindow(request, response);
+// }
+//
+// protected void writeAjaxWindow(RenderRequest request,
+// RenderResponse response) throws IOException {
+//
+// response.setContentType("text/html");
+// if (app != null) {
+// PortletSession sess = request.getPortletSession();
+// PortletApplicationContext ctx = PortletApplicationContext
+// .getApplicationContext(sess);
+//
+// PortletRequestDispatcher dispatcher = sess.getPortletContext()
+// .getRequestDispatcher("/" + app);
+//
+// try {
+// // portal-wide settings
+// PortalContext portalCtx = request.getPortalContext();
+//
+// boolean isLifeRay = portalCtx.getPortalInfo().toLowerCase()
+// .contains("liferay");
+//
+// request.setAttribute(ApplicationServlet.REQUEST_FRAGMENT,
+// "true");
+//
+// // fixed base theme to use - all portal pages with Vaadin
+// // applications will load this exactly once
+// String portalTheme = getPortalProperty(
+// Constants.PORTAL_PARAMETER_VAADIN_THEME, portalCtx);
+//
+// String portalWidgetset = getPortalProperty(
+// Constants.PORTAL_PARAMETER_VAADIN_WIDGETSET, portalCtx);
+//
+// // location of the widgetset(s) and default theme (to which
+// // /VAADIN/widgetsets/...
+// // is appended)
+// String portalResourcePath = getPortalProperty(
+// Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH,
+// portalCtx);
+//
+// if (portalResourcePath != null) {
+// // if portalResourcePath is defined, set it as a request
+// // parameter which will override the default location in
+// // servlet
+// request.setAttribute(
+// ApplicationServlet.REQUEST_VAADIN_STATIC_FILE_PATH,
+// portalResourcePath);
+// }
+//
+// // - if the user has specified a widgetset for this portlet, use
+// // it from the portlet (not fully supported)
+// // - otherwise, if specified, use the portal-wide widgetset
+// // and widgetset path settings (recommended)
+// // - finally, default to use the default widgetset if nothing
+// // else is found
+// if (portletWidgetset != null) {
+// request.setAttribute(ApplicationServlet.REQUEST_WIDGETSET,
+// portletWidgetset);
+// }
+// if (portalWidgetset != null) {
+// request.setAttribute(
+// ApplicationServlet.REQUEST_SHARED_WIDGETSET,
+// portalWidgetset);
+// }
+//
+// if (style != null) {
+// request.setAttribute(ApplicationServlet.REQUEST_APPSTYLE,
+// style);
+// }
+//
+// // portalTheme is only used if the shared portal resource
+// // directory is defined
+// if (portalTheme != null && portalResourcePath != null) {
+// request.setAttribute(
+// ApplicationServlet.REQUEST_DEFAULT_THEME,
+// portalTheme);
+//
+// String defaultThemeUri = null;
+// defaultThemeUri = portalResourcePath + "/"
+// + AbstractApplicationServlet.THEME_DIRECTORY_PATH
+// + portalTheme;
+// /*
+// * Make sure portal default Vaadin theme is included in DOM.
+// * Vaadin portlet themes do not "inherit" base theme, so we
+// * need to force loading of the common base theme.
+// */
+// OutputStream out = response.getPortletOutputStream();
+//
+// // Using portal-wide theme
+// String loadDefaultTheme = ("<script type=\"text/javascript\">\n"
+// + "if(!vaadin) { var vaadin = {} } \n"
+// + "if(!vaadin.themesLoaded) { vaadin.themesLoaded = {} } \n"
+// + "if(!vaadin.themesLoaded['"
+// + portalTheme
+// + "']) {\n"
+// + "var stylesheet = document.createElement('link');\n"
+// + "stylesheet.setAttribute('rel', 'stylesheet');\n"
+// + "stylesheet.setAttribute('type', 'text/css');\n"
+// + "stylesheet.setAttribute('href', '"
+// + defaultThemeUri
+// + "/styles.css');\n"
+// + "document.getElementsByTagName('head')[0].appendChild(stylesheet);\n"
+// + "vaadin.themesLoaded['"
+// + portalTheme
+// + "'] = true;\n}\n" + "</script>\n");
+// out.write(loadDefaultTheme.getBytes());
+// }
+//
+// dispatcher.include(request, response);
+//
+// if (isLifeRay) {
+// /*
+// * Temporary support to heartbeat Liferay session when using
+// * Vaadin based portlet. We hit an extra xhr to liferay
+// * servlet to extend the session lifetime after each Vaadin
+// * request. This hack can be removed when supporting portlet
+// * 2.0 and resourceRequests.
+// *
+// * TODO make this configurable, this is not necessary with
+// * some custom session configurations.
+// */
+// OutputStream out = response.getPortletOutputStream();
+//
+// String lifeRaySessionHearbeatHack = ("<script type=\"text/javascript\">"
+// + "if(!vaadin.postRequestHooks) {"
+// + " vaadin.postRequestHooks = {};"
+// + "}"
+// + "vaadin.postRequestHooks.liferaySessionHeartBeat = function() {"
+// + " if (Liferay && Liferay.Session && Liferay.Session.setCookie) {"
+// + " Liferay.Session.setCookie();"
+// + " }"
+// + "};" + "</script>");
+// out.write(lifeRaySessionHearbeatHack.getBytes());
+// }
+//
+// } catch (PortletException e) {
+// PrintWriter out = response.getWriter();
+// out.print("<h1>Servlet include failed!</h1>");
+// Logger.getLogger(AbstractApplicationPortlet.class.getName())
+// .log(Level.WARNING, "Servlet include failed", e);
+// ctx.setPortletApplication(this, null);
+// return;
+// }
+//
+// Application app = (Application) request
+// .getAttribute(Application.class.getName());
+// ctx.setPortletApplication(this, app);
+// ctx.firePortletRenderRequest(this, request, response);
+//
+// }
+// }
+//
+// private String getPortalProperty(String name, PortalContext context) {
+// boolean isLifeRay = context.getPortalInfo().toLowerCase()
+// .contains("liferay");
+//
+// // TODO test on non-LifeRay platforms
+//
+// String value;
+// if (isLifeRay) {
+// value = getLifeRayPortalProperty(name);
+// } else {
+// value = context.getProperty(name);
+// }
+//
+// return value;
+// }
+//
+// private String getLifeRayPortalProperty(String name) {
+// String value;
+// try {
+// value = PropsUtil.get(name);
+// } catch (Exception e) {
+// value = null;
+// }
+// return value;
+// }
+// }
diff --git a/src/com/vaadin/terminal/gwt/server/ApplicationPortlet2.java b/src/com/vaadin/terminal/gwt/server/ApplicationPortlet2.java
index ec373908f7..70baba5eb2 100644
--- a/src/com/vaadin/terminal/gwt/server/ApplicationPortlet2.java
+++ b/src/com/vaadin/terminal/gwt/server/ApplicationPortlet2.java
@@ -1,46 +1,46 @@
/*
@ITMillApache2LicenseForJavaFiles@
*/
-
-package com.vaadin.terminal.gwt.server;
-
-import javax.portlet.PortletConfig;
-import javax.portlet.PortletException;
-
-import com.vaadin.Application;
-
-/**
- * TODO Write documentation, fix JavaDoc tags.
- *
- * @author peholmst
- */
-public class ApplicationPortlet2 extends AbstractApplicationPortlet {
-
- private Class<? extends Application> applicationClass;
-
- @SuppressWarnings("unchecked")
- @Override
- public void init(PortletConfig config) throws PortletException {
- super.init(config);
- final String applicationClassName = config
- .getInitParameter("application");
- if (applicationClassName == null) {
- throw new PortletException(
- "Application not specified in portlet parameters");
- }
-
- try {
- applicationClass = (Class<? extends Application>) getClassLoader()
- .loadClass(applicationClassName);
- } catch (final ClassNotFoundException e) {
- throw new PortletException("Failed to load application class: "
- + applicationClassName);
- }
- }
-
- @Override
- protected Class<? extends Application> getApplicationClass() {
- return applicationClass;
- }
-
-}
+//
+//package com.vaadin.terminal.gwt.server;
+//
+//import javax.portlet.PortletConfig;
+//import javax.portlet.PortletException;
+//
+//import com.vaadin.Application;
+//
+///**
+// * TODO Write documentation, fix JavaDoc tags.
+// *
+// * @author peholmst
+// */
+//public class ApplicationPortlet2 extends AbstractApplicationPortlet {
+//
+// private Class<? extends Application> applicationClass;
+//
+// @SuppressWarnings("unchecked")
+// @Override
+// public void init(PortletConfig config) throws PortletException {
+// super.init(config);
+// final String applicationClassName = config
+// .getInitParameter("application");
+// if (applicationClassName == null) {
+// throw new PortletException(
+// "Application not specified in portlet parameters");
+// }
+//
+// try {
+// applicationClass = (Class<? extends Application>) getClassLoader()
+// .loadClass(applicationClassName);
+// } catch (final ClassNotFoundException e) {
+// throw new PortletException("Failed to load application class: "
+// + applicationClassName);
+// }
+// }
+//
+// @Override
+// protected Class<? extends Application> getApplicationClass() {
+// return applicationClass;
+// }
+//
+// }
diff --git a/src/com/vaadin/terminal/gwt/server/CommunicationManager.java b/src/com/vaadin/terminal/gwt/server/CommunicationManager.java
index 5851621a20..14cccc618a 100644
--- a/src/com/vaadin/terminal/gwt/server/CommunicationManager.java
+++ b/src/com/vaadin/terminal/gwt/server/CommunicationManager.java
@@ -23,6 +23,7 @@ import com.vaadin.terminal.Paintable;
import com.vaadin.terminal.StreamVariable;
import com.vaadin.terminal.VariableOwner;
import com.vaadin.ui.Component;
+import com.vaadin.ui.Root;
import com.vaadin.ui.Window;
/**
@@ -278,13 +279,13 @@ public class CommunicationManager extends AbstractCommunicationManager {
*/
public void handleUidlRequest(HttpServletRequest request,
HttpServletResponse response,
- AbstractApplicationServlet applicationServlet, Window window)
+ AbstractApplicationServlet applicationServlet, Root root)
throws IOException, ServletException,
InvalidUIDLSecurityKeyException {
doHandleUidlRequest(new HttpServletRequestWrapper(request),
new HttpServletResponseWrapper(response),
new AbstractApplicationServletWrapper(applicationServlet),
- window);
+ root);
}
/**
@@ -295,7 +296,7 @@ public class CommunicationManager extends AbstractCommunicationManager {
* the HTTP Request.
* @param application
* the Application to query for window.
- * @param assumedWindow
+ * @param assumedRoot
* if the window has been already resolved once, this parameter
* must contain the window.
* @return Window matching the given URI or null if not found.
@@ -303,13 +304,12 @@ public class CommunicationManager extends AbstractCommunicationManager {
* if an exception has occurred that interferes with the
* servlet's normal operation.
*/
- Window getApplicationWindow(HttpServletRequest request,
+ Root getApplicationRoot(HttpServletRequest request,
AbstractApplicationServlet applicationServlet,
- Application application, Window assumedWindow)
- throws ServletException {
+ Application application, Root assumedRoot) throws ServletException {
return doGetApplicationWindow(new HttpServletRequestWrapper(request),
new AbstractApplicationServletWrapper(applicationServlet),
- application, assumedWindow);
+ application, assumedRoot);
}
/**
diff --git a/src/com/vaadin/terminal/gwt/server/PortletApplicationContext2.java b/src/com/vaadin/terminal/gwt/server/PortletApplicationContext2.java
index aba772a26e..df9adc7d0b 100644
--- a/src/com/vaadin/terminal/gwt/server/PortletApplicationContext2.java
+++ b/src/com/vaadin/terminal/gwt/server/PortletApplicationContext2.java
@@ -1,418 +1,418 @@
/*
@ITMillApache2LicenseForJavaFiles@
*/
-package com.vaadin.terminal.gwt.server;
-
-import java.io.File;
-import java.io.Serializable;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.LinkedHashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.portlet.ActionRequest;
-import javax.portlet.ActionResponse;
-import javax.portlet.EventRequest;
-import javax.portlet.EventResponse;
-import javax.portlet.MimeResponse;
-import javax.portlet.PortletConfig;
-import javax.portlet.PortletMode;
-import javax.portlet.PortletModeException;
-import javax.portlet.PortletResponse;
-import javax.portlet.PortletSession;
-import javax.portlet.PortletURL;
-import javax.portlet.RenderRequest;
-import javax.portlet.RenderResponse;
-import javax.portlet.ResourceRequest;
-import javax.portlet.ResourceResponse;
-import javax.portlet.ResourceURL;
-import javax.portlet.StateAwareResponse;
-import javax.servlet.http.HttpSessionBindingListener;
-import javax.xml.namespace.QName;
-
-import com.vaadin.Application;
-import com.vaadin.terminal.ApplicationResource;
-import com.vaadin.terminal.ExternalResource;
-import com.vaadin.ui.Window;
-
-/**
- * TODO Write documentation, fix JavaDoc tags.
- *
- * This is automatically registered as a {@link HttpSessionBindingListener} when
- * {@link PortletSession#setAttribute()} is called with the context as value.
- *
- * @author peholmst
- */
-@SuppressWarnings("serial")
-public class PortletApplicationContext2 extends AbstractWebApplicationContext {
-
- private static final Logger logger = Logger
- .getLogger(PortletApplicationContext2.class.getName());
-
- protected Map<Application, Set<PortletListener>> portletListeners = new HashMap<Application, Set<PortletListener>>();
-
- protected transient PortletSession session;
- protected transient PortletConfig portletConfig;
-
- protected HashMap<String, Application> portletWindowIdToApplicationMap = new HashMap<String, Application>();
-
- private transient PortletResponse response;
-
- private final Map<String, QName> eventActionDestinationMap = new HashMap<String, QName>();
- private final Map<String, Serializable> eventActionValueMap = new HashMap<String, Serializable>();
-
- private final Map<String, String> sharedParameterActionNameMap = new HashMap<String, String>();
- private final Map<String, String> sharedParameterActionValueMap = new HashMap<String, String>();
-
- public File getBaseDirectory() {
- String resultPath = session.getPortletContext().getRealPath("/");
- if (resultPath != null) {
- return new File(resultPath);
- } else {
- try {
- final URL url = session.getPortletContext().getResource("/");
- return new File(url.getFile());
- } catch (final Exception e) {
- // FIXME: Handle exception
- logger.log(
- Level.INFO,
- "Cannot access base directory, possible security issue "
- + "with Application Server or Servlet Container",
- e);
- }
- }
- return null;
- }
-
- protected PortletCommunicationManager getApplicationManager(
- Application application) {
- PortletCommunicationManager mgr = (PortletCommunicationManager) applicationToAjaxAppMgrMap
- .get(application);
-
- if (mgr == null) {
- // Creates a new manager
- mgr = createPortletCommunicationManager(application);
- applicationToAjaxAppMgrMap.put(application, mgr);
- }
- return mgr;
- }
-
- protected PortletCommunicationManager createPortletCommunicationManager(
- Application application) {
- return new PortletCommunicationManager(application);
- }
-
- public static PortletApplicationContext2 getApplicationContext(
- PortletSession session) {
- Object cxattr = session.getAttribute(PortletApplicationContext2.class
- .getName());
- PortletApplicationContext2 cx = null;
- // can be false also e.g. if old context comes from another
- // classloader when using
- // <private-session-attributes>false</private-session-attributes>
- // and redeploying the portlet - see #7461
- if (cxattr instanceof PortletApplicationContext2) {
- cx = (PortletApplicationContext2) cxattr;
- }
- if (cx == null) {
- cx = new PortletApplicationContext2();
- session.setAttribute(PortletApplicationContext2.class.getName(), cx);
- }
- if (cx.session == null) {
- cx.session = session;
- }
- return cx;
- }
-
- @Override
- protected void removeApplication(Application application) {
- super.removeApplication(application);
- // values() is backed by map, removes the key-value pair from the map
- portletWindowIdToApplicationMap.values().remove(application);
- }
-
- protected void addApplication(Application application,
- String portletWindowId) {
- applications.add(application);
- portletWindowIdToApplicationMap.put(portletWindowId, application);
- }
-
- public Application getApplicationForWindowId(String portletWindowId) {
- return portletWindowIdToApplicationMap.get(portletWindowId);
- }
-
- public PortletSession getPortletSession() {
- return session;
- }
-
- public PortletConfig getPortletConfig() {
- return portletConfig;
- }
-
- public void setPortletConfig(PortletConfig config) {
- portletConfig = config;
- }
-
- public void addPortletListener(Application app, PortletListener listener) {
- Set<PortletListener> l = portletListeners.get(app);
- if (l == null) {
- l = new LinkedHashSet<PortletListener>();
- portletListeners.put(app, l);
- }
- l.add(listener);
- }
-
- public void removePortletListener(Application app, PortletListener listener) {
- Set<PortletListener> l = portletListeners.get(app);
- if (l != null) {
- l.remove(listener);
- }
- }
-
- public void firePortletRenderRequest(Application app, Window window,
- RenderRequest request, RenderResponse response) {
- Set<PortletListener> listeners = portletListeners.get(app);
- if (listeners != null) {
- for (PortletListener l : listeners) {
- l.handleRenderRequest(request, new RestrictedRenderResponse(
- response), window);
- }
- }
- }
-
- public void firePortletActionRequest(Application app, Window window,
- ActionRequest request, ActionResponse response) {
- String key = request.getParameter(ActionRequest.ACTION_NAME);
- if (eventActionDestinationMap.containsKey(key)) {
- // this action request is only to send queued portlet events
- response.setEvent(eventActionDestinationMap.get(key),
- eventActionValueMap.get(key));
- // cleanup
- eventActionDestinationMap.remove(key);
- eventActionValueMap.remove(key);
- } else if (sharedParameterActionNameMap.containsKey(key)) {
- // this action request is only to set shared render parameters
- response.setRenderParameter(sharedParameterActionNameMap.get(key),
- sharedParameterActionValueMap.get(key));
- // cleanup
- sharedParameterActionNameMap.remove(key);
- sharedParameterActionValueMap.remove(key);
- } else {
- // normal action request, notify listeners
- Set<PortletListener> listeners = portletListeners.get(app);
- if (listeners != null) {
- for (PortletListener l : listeners) {
- l.handleActionRequest(request, response, window);
- }
- }
- }
- }
-
- public void firePortletEventRequest(Application app, Window window,
- EventRequest request, EventResponse response) {
- Set<PortletListener> listeners = portletListeners.get(app);
- if (listeners != null) {
- for (PortletListener l : listeners) {
- l.handleEventRequest(request, response, window);
- }
- }
- }
-
- public void firePortletResourceRequest(Application app, Window window,
- ResourceRequest request, ResourceResponse response) {
- Set<PortletListener> listeners = portletListeners.get(app);
- if (listeners != null) {
- for (PortletListener l : listeners) {
- l.handleResourceRequest(request, response, window);
- }
- }
- }
-
- public interface PortletListener extends Serializable {
-
- public void handleRenderRequest(RenderRequest request,
- RenderResponse response, Window window);
-
- public void handleActionRequest(ActionRequest request,
- ActionResponse response, Window window);
-
- public void handleEventRequest(EventRequest request,
- EventResponse response, Window window);
-
- public void handleResourceRequest(ResourceRequest request,
- ResourceResponse response, Window window);
- }
-
- /**
- * This is for use by {@link AbstractApplicationPortlet} only.
- *
- * TODO cleaner implementation, now "semi-static"!
- *
- * @param mimeResponse
- */
- void setResponse(PortletResponse response) {
- this.response = response;
- }
-
- @Override
- public String generateApplicationResourceURL(ApplicationResource resource,
- String mapKey) {
- if (response instanceof MimeResponse) {
- ResourceURL resourceURL = ((MimeResponse) response)
- .createResourceURL();
- final String filename = resource.getFilename();
- if (filename == null) {
- resourceURL.setResourceID("APP/" + mapKey + "/");
- } else {
- resourceURL.setResourceID("APP/" + mapKey + "/"
- + urlEncode(filename));
- }
- return resourceURL.toString();
- } else {
- // in a background thread or otherwise outside a request
- // TODO exception ??
- return null;
- }
- }
-
- /**
- * Creates a new action URL.
- *
- * @param action
- * @return action URL or null if called outside a MimeRequest (outside a
- * UIDL request or similar)
- */
- public PortletURL generateActionURL(String action) {
- PortletURL url = null;
- if (response instanceof MimeResponse) {
- url = ((MimeResponse) response).createActionURL();
- url.setParameter("javax.portlet.action", action);
- } else {
- return null;
- }
- return url;
- }
-
- /**
- * Sends a portlet event to the indicated destination.
- *
- * Internally, an action may be created and opened, as an event cannot be
- * sent directly from all types of requests.
- *
- * The event destinations and values need to be kept in the context until
- * sent. Any memory leaks if the action fails are limited to the session.
- *
- * Event names for events sent and received by a portlet need to be declared
- * in portlet.xml .
- *
- * @param window
- * a window in which a temporary action URL can be opened if
- * necessary
- * @param name
- * event name
- * @param value
- * event value object that is Serializable and, if appropriate,
- * has a valid JAXB annotation
- */
- public void sendPortletEvent(Window window, QName name, Serializable value)
- throws IllegalStateException {
- if (response instanceof MimeResponse) {
- String actionKey = "" + System.currentTimeMillis();
- while (eventActionDestinationMap.containsKey(actionKey)) {
- actionKey = actionKey + ".";
- }
- PortletURL actionUrl = generateActionURL(actionKey);
- if (actionUrl != null) {
- eventActionDestinationMap.put(actionKey, name);
- eventActionValueMap.put(actionKey, value);
- window.open(new ExternalResource(actionUrl.toString()));
- } else {
- // this should never happen as we already know the response is a
- // MimeResponse
- throw new IllegalStateException(
- "Portlet events can only be sent from a portlet request");
- }
- } else if (response instanceof StateAwareResponse) {
- ((StateAwareResponse) response).setEvent(name, value);
- } else {
- throw new IllegalStateException(
- "Portlet events can only be sent from a portlet request");
- }
- }
-
- /**
- * Sets a shared portlet parameter.
- *
- * Internally, an action may be created and opened, as shared parameters
- * cannot be set directly from all types of requests.
- *
- * The parameters and values need to be kept in the context until sent. Any
- * memory leaks if the action fails are limited to the session.
- *
- * Shared parameters set or read by a portlet need to be declared in
- * portlet.xml .
- *
- * @param window
- * a window in which a temporary action URL can be opened if
- * necessary
- * @param name
- * parameter identifier
- * @param value
- * parameter value
- */
- public void setSharedRenderParameter(Window window, String name,
- String value) throws IllegalStateException {
- if (response instanceof MimeResponse) {
- String actionKey = "" + System.currentTimeMillis();
- while (sharedParameterActionNameMap.containsKey(actionKey)) {
- actionKey = actionKey + ".";
- }
- PortletURL actionUrl = generateActionURL(actionKey);
- if (actionUrl != null) {
- sharedParameterActionNameMap.put(actionKey, name);
- sharedParameterActionValueMap.put(actionKey, value);
- window.open(new ExternalResource(actionUrl.toString()));
- } else {
- // this should never happen as we already know the response is a
- // MimeResponse
- throw new IllegalStateException(
- "Shared parameters can only be set from a portlet request");
- }
- } else if (response instanceof StateAwareResponse) {
- ((StateAwareResponse) response).setRenderParameter(name, value);
- } else {
- throw new IllegalStateException(
- "Shared parameters can only be set from a portlet request");
- }
- }
-
- /**
- * Sets the portlet mode. This may trigger a new render request.
- *
- * Portlet modes used by a portlet need to be declared in portlet.xml .
- *
- * @param window
- * a window in which the render URL can be opened if necessary
- * @param portletMode
- * the portlet mode to switch to
- * @throws PortletModeException
- * if the portlet mode is not allowed for some reason
- * (configuration, permissions etc.)
- */
- public void setPortletMode(Window window, PortletMode portletMode)
- throws IllegalStateException, PortletModeException {
- if (response instanceof MimeResponse) {
- PortletURL url = ((MimeResponse) response).createRenderURL();
- url.setPortletMode(portletMode);
- window.open(new ExternalResource(url.toString()));
- } else if (response instanceof StateAwareResponse) {
- ((StateAwareResponse) response).setPortletMode(portletMode);
- } else {
- throw new IllegalStateException(
- "Portlet mode can only be changed from a portlet request");
- }
- }
-}
+//package com.vaadin.terminal.gwt.server;
+//
+//import java.io.File;
+//import java.io.Serializable;
+//import java.net.URL;
+//import java.util.HashMap;
+//import java.util.LinkedHashSet;
+//import java.util.Map;
+//import java.util.Set;
+//import java.util.logging.Level;
+//import java.util.logging.Logger;
+//
+//import javax.portlet.ActionRequest;
+//import javax.portlet.ActionResponse;
+//import javax.portlet.EventRequest;
+//import javax.portlet.EventResponse;
+//import javax.portlet.MimeResponse;
+//import javax.portlet.PortletConfig;
+//import javax.portlet.PortletMode;
+//import javax.portlet.PortletModeException;
+//import javax.portlet.PortletResponse;
+//import javax.portlet.PortletSession;
+//import javax.portlet.PortletURL;
+//import javax.portlet.RenderRequest;
+//import javax.portlet.RenderResponse;
+//import javax.portlet.ResourceRequest;
+//import javax.portlet.ResourceResponse;
+//import javax.portlet.ResourceURL;
+//import javax.portlet.StateAwareResponse;
+//import javax.servlet.http.HttpSessionBindingListener;
+//import javax.xml.namespace.QName;
+//
+//import com.vaadin.Application;
+//import com.vaadin.terminal.ApplicationResource;
+//import com.vaadin.terminal.ExternalResource;
+//import com.vaadin.ui.Window;
+//
+///**
+// * TODO Write documentation, fix JavaDoc tags.
+// *
+// * This is automatically registered as a {@link HttpSessionBindingListener} when
+// * {@link PortletSession#setAttribute()} is called with the context as value.
+// *
+// * @author peholmst
+// */
+//@SuppressWarnings("serial")
+//public class PortletApplicationContext2 extends AbstractWebApplicationContext {
+//
+// private static final Logger logger = Logger
+// .getLogger(PortletApplicationContext2.class.getName());
+//
+// protected Map<Application, Set<PortletListener>> portletListeners = new HashMap<Application, Set<PortletListener>>();
+//
+// protected transient PortletSession session;
+// protected transient PortletConfig portletConfig;
+//
+// protected HashMap<String, Application> portletWindowIdToApplicationMap = new HashMap<String, Application>();
+//
+// private transient PortletResponse response;
+//
+// private final Map<String, QName> eventActionDestinationMap = new HashMap<String, QName>();
+// private final Map<String, Serializable> eventActionValueMap = new HashMap<String, Serializable>();
+//
+// private final Map<String, String> sharedParameterActionNameMap = new HashMap<String, String>();
+// private final Map<String, String> sharedParameterActionValueMap = new HashMap<String, String>();
+//
+// public File getBaseDirectory() {
+// String resultPath = session.getPortletContext().getRealPath("/");
+// if (resultPath != null) {
+// return new File(resultPath);
+// } else {
+// try {
+// final URL url = session.getPortletContext().getResource("/");
+// return new File(url.getFile());
+// } catch (final Exception e) {
+// // FIXME: Handle exception
+// logger.log(
+// Level.INFO,
+// "Cannot access base directory, possible security issue "
+// + "with Application Server or Servlet Container",
+// e);
+// }
+// }
+// return null;
+// }
+//
+// protected PortletCommunicationManager getApplicationManager(
+// Application application) {
+// PortletCommunicationManager mgr = (PortletCommunicationManager) applicationToAjaxAppMgrMap
+// .get(application);
+//
+// if (mgr == null) {
+// // Creates a new manager
+// mgr = createPortletCommunicationManager(application);
+// applicationToAjaxAppMgrMap.put(application, mgr);
+// }
+// return mgr;
+// }
+//
+// protected PortletCommunicationManager createPortletCommunicationManager(
+// Application application) {
+// return new PortletCommunicationManager(application);
+// }
+//
+// public static PortletApplicationContext2 getApplicationContext(
+// PortletSession session) {
+// Object cxattr = session.getAttribute(PortletApplicationContext2.class
+// .getName());
+// PortletApplicationContext2 cx = null;
+// // can be false also e.g. if old context comes from another
+// // classloader when using
+// // <private-session-attributes>false</private-session-attributes>
+// // and redeploying the portlet - see #7461
+// if (cxattr instanceof PortletApplicationContext2) {
+// cx = (PortletApplicationContext2) cxattr;
+// }
+// if (cx == null) {
+// cx = new PortletApplicationContext2();
+// session.setAttribute(PortletApplicationContext2.class.getName(), cx);
+// }
+// if (cx.session == null) {
+// cx.session = session;
+// }
+// return cx;
+// }
+//
+// @Override
+// protected void removeApplication(Application application) {
+// super.removeApplication(application);
+// // values() is backed by map, removes the key-value pair from the map
+// portletWindowIdToApplicationMap.values().remove(application);
+// }
+//
+// protected void addApplication(Application application,
+// String portletWindowId) {
+// applications.add(application);
+// portletWindowIdToApplicationMap.put(portletWindowId, application);
+// }
+//
+// public Application getApplicationForWindowId(String portletWindowId) {
+// return portletWindowIdToApplicationMap.get(portletWindowId);
+// }
+//
+// public PortletSession getPortletSession() {
+// return session;
+// }
+//
+// public PortletConfig getPortletConfig() {
+// return portletConfig;
+// }
+//
+// public void setPortletConfig(PortletConfig config) {
+// portletConfig = config;
+// }
+//
+// public void addPortletListener(Application app, PortletListener listener) {
+// Set<PortletListener> l = portletListeners.get(app);
+// if (l == null) {
+// l = new LinkedHashSet<PortletListener>();
+// portletListeners.put(app, l);
+// }
+// l.add(listener);
+// }
+//
+// public void removePortletListener(Application app, PortletListener listener) {
+// Set<PortletListener> l = portletListeners.get(app);
+// if (l != null) {
+// l.remove(listener);
+// }
+// }
+//
+// public void firePortletRenderRequest(Application app, Window window,
+// RenderRequest request, RenderResponse response) {
+// Set<PortletListener> listeners = portletListeners.get(app);
+// if (listeners != null) {
+// for (PortletListener l : listeners) {
+// l.handleRenderRequest(request, new RestrictedRenderResponse(
+// response), window);
+// }
+// }
+// }
+//
+// public void firePortletActionRequest(Application app, Window window,
+// ActionRequest request, ActionResponse response) {
+// String key = request.getParameter(ActionRequest.ACTION_NAME);
+// if (eventActionDestinationMap.containsKey(key)) {
+// // this action request is only to send queued portlet events
+// response.setEvent(eventActionDestinationMap.get(key),
+// eventActionValueMap.get(key));
+// // cleanup
+// eventActionDestinationMap.remove(key);
+// eventActionValueMap.remove(key);
+// } else if (sharedParameterActionNameMap.containsKey(key)) {
+// // this action request is only to set shared render parameters
+// response.setRenderParameter(sharedParameterActionNameMap.get(key),
+// sharedParameterActionValueMap.get(key));
+// // cleanup
+// sharedParameterActionNameMap.remove(key);
+// sharedParameterActionValueMap.remove(key);
+// } else {
+// // normal action request, notify listeners
+// Set<PortletListener> listeners = portletListeners.get(app);
+// if (listeners != null) {
+// for (PortletListener l : listeners) {
+// l.handleActionRequest(request, response, window);
+// }
+// }
+// }
+// }
+//
+// public void firePortletEventRequest(Application app, Window window,
+// EventRequest request, EventResponse response) {
+// Set<PortletListener> listeners = portletListeners.get(app);
+// if (listeners != null) {
+// for (PortletListener l : listeners) {
+// l.handleEventRequest(request, response, window);
+// }
+// }
+// }
+//
+// public void firePortletResourceRequest(Application app, Window window,
+// ResourceRequest request, ResourceResponse response) {
+// Set<PortletListener> listeners = portletListeners.get(app);
+// if (listeners != null) {
+// for (PortletListener l : listeners) {
+// l.handleResourceRequest(request, response, window);
+// }
+// }
+// }
+//
+// public interface PortletListener extends Serializable {
+//
+// public void handleRenderRequest(RenderRequest request,
+// RenderResponse response, Window window);
+//
+// public void handleActionRequest(ActionRequest request,
+// ActionResponse response, Window window);
+//
+// public void handleEventRequest(EventRequest request,
+// EventResponse response, Window window);
+//
+// public void handleResourceRequest(ResourceRequest request,
+// ResourceResponse response, Window window);
+// }
+//
+// /**
+// * This is for use by {@link AbstractApplicationPortlet} only.
+// *
+// * TODO cleaner implementation, now "semi-static"!
+// *
+// * @param mimeResponse
+// */
+// void setResponse(PortletResponse response) {
+// this.response = response;
+// }
+//
+// @Override
+// public String generateApplicationResourceURL(ApplicationResource resource,
+// String mapKey) {
+// if (response instanceof MimeResponse) {
+// ResourceURL resourceURL = ((MimeResponse) response)
+// .createResourceURL();
+// final String filename = resource.getFilename();
+// if (filename == null) {
+// resourceURL.setResourceID("APP/" + mapKey + "/");
+// } else {
+// resourceURL.setResourceID("APP/" + mapKey + "/"
+// + urlEncode(filename));
+// }
+// return resourceURL.toString();
+// } else {
+// // in a background thread or otherwise outside a request
+// // TODO exception ??
+// return null;
+// }
+// }
+//
+// /**
+// * Creates a new action URL.
+// *
+// * @param action
+// * @return action URL or null if called outside a MimeRequest (outside a
+// * UIDL request or similar)
+// */
+// public PortletURL generateActionURL(String action) {
+// PortletURL url = null;
+// if (response instanceof MimeResponse) {
+// url = ((MimeResponse) response).createActionURL();
+// url.setParameter("javax.portlet.action", action);
+// } else {
+// return null;
+// }
+// return url;
+// }
+//
+// /**
+// * Sends a portlet event to the indicated destination.
+// *
+// * Internally, an action may be created and opened, as an event cannot be
+// * sent directly from all types of requests.
+// *
+// * The event destinations and values need to be kept in the context until
+// * sent. Any memory leaks if the action fails are limited to the session.
+// *
+// * Event names for events sent and received by a portlet need to be declared
+// * in portlet.xml .
+// *
+// * @param window
+// * a window in which a temporary action URL can be opened if
+// * necessary
+// * @param name
+// * event name
+// * @param value
+// * event value object that is Serializable and, if appropriate,
+// * has a valid JAXB annotation
+// */
+// public void sendPortletEvent(Window window, QName name, Serializable value)
+// throws IllegalStateException {
+// if (response instanceof MimeResponse) {
+// String actionKey = "" + System.currentTimeMillis();
+// while (eventActionDestinationMap.containsKey(actionKey)) {
+// actionKey = actionKey + ".";
+// }
+// PortletURL actionUrl = generateActionURL(actionKey);
+// if (actionUrl != null) {
+// eventActionDestinationMap.put(actionKey, name);
+// eventActionValueMap.put(actionKey, value);
+// window.open(new ExternalResource(actionUrl.toString()));
+// } else {
+// // this should never happen as we already know the response is a
+// // MimeResponse
+// throw new IllegalStateException(
+// "Portlet events can only be sent from a portlet request");
+// }
+// } else if (response instanceof StateAwareResponse) {
+// ((StateAwareResponse) response).setEvent(name, value);
+// } else {
+// throw new IllegalStateException(
+// "Portlet events can only be sent from a portlet request");
+// }
+// }
+//
+// /**
+// * Sets a shared portlet parameter.
+// *
+// * Internally, an action may be created and opened, as shared parameters
+// * cannot be set directly from all types of requests.
+// *
+// * The parameters and values need to be kept in the context until sent. Any
+// * memory leaks if the action fails are limited to the session.
+// *
+// * Shared parameters set or read by a portlet need to be declared in
+// * portlet.xml .
+// *
+// * @param window
+// * a window in which a temporary action URL can be opened if
+// * necessary
+// * @param name
+// * parameter identifier
+// * @param value
+// * parameter value
+// */
+// public void setSharedRenderParameter(Window window, String name,
+// String value) throws IllegalStateException {
+// if (response instanceof MimeResponse) {
+// String actionKey = "" + System.currentTimeMillis();
+// while (sharedParameterActionNameMap.containsKey(actionKey)) {
+// actionKey = actionKey + ".";
+// }
+// PortletURL actionUrl = generateActionURL(actionKey);
+// if (actionUrl != null) {
+// sharedParameterActionNameMap.put(actionKey, name);
+// sharedParameterActionValueMap.put(actionKey, value);
+// window.open(new ExternalResource(actionUrl.toString()));
+// } else {
+// // this should never happen as we already know the response is a
+// // MimeResponse
+// throw new IllegalStateException(
+// "Shared parameters can only be set from a portlet request");
+// }
+// } else if (response instanceof StateAwareResponse) {
+// ((StateAwareResponse) response).setRenderParameter(name, value);
+// } else {
+// throw new IllegalStateException(
+// "Shared parameters can only be set from a portlet request");
+// }
+// }
+//
+// /**
+// * Sets the portlet mode. This may trigger a new render request.
+// *
+// * Portlet modes used by a portlet need to be declared in portlet.xml .
+// *
+// * @param window
+// * a window in which the render URL can be opened if necessary
+// * @param portletMode
+// * the portlet mode to switch to
+// * @throws PortletModeException
+// * if the portlet mode is not allowed for some reason
+// * (configuration, permissions etc.)
+// */
+// public void setPortletMode(Window window, PortletMode portletMode)
+// throws IllegalStateException, PortletModeException {
+// if (response instanceof MimeResponse) {
+// PortletURL url = ((MimeResponse) response).createRenderURL();
+// url.setPortletMode(portletMode);
+// window.open(new ExternalResource(url.toString()));
+// } else if (response instanceof StateAwareResponse) {
+// ((StateAwareResponse) response).setPortletMode(portletMode);
+// } else {
+// throw new IllegalStateException(
+// "Portlet mode can only be changed from a portlet request");
+// }
+// }
+// }
diff --git a/src/com/vaadin/terminal/gwt/server/PortletCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/PortletCommunicationManager.java
index d9fa9ecd6c..6500e39b4b 100644
--- a/src/com/vaadin/terminal/gwt/server/PortletCommunicationManager.java
+++ b/src/com/vaadin/terminal/gwt/server/PortletCommunicationManager.java
@@ -1,305 +1,305 @@
/*
@ITMillApache2LicenseForJavaFiles@
*/
-package com.vaadin.terminal.gwt.server;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.portlet.ClientDataRequest;
-import javax.portlet.MimeResponse;
-import javax.portlet.PortletRequest;
-import javax.portlet.PortletResponse;
-import javax.portlet.PortletSession;
-import javax.portlet.ResourceRequest;
-import javax.portlet.ResourceResponse;
-import javax.portlet.ResourceURL;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequestWrapper;
-
-import com.vaadin.Application;
-import com.vaadin.terminal.DownloadStream;
-import com.vaadin.terminal.Paintable;
-import com.vaadin.terminal.StreamVariable;
-import com.vaadin.terminal.VariableOwner;
-import com.vaadin.ui.Component;
-import com.vaadin.ui.Window;
-
-/**
- * TODO document me!
- *
- * @author peholmst
- *
- */
-@SuppressWarnings("serial")
-public class PortletCommunicationManager extends AbstractCommunicationManager {
-
- private transient ResourceResponse currentUidlResponse;
-
- private static class PortletRequestWrapper implements Request {
-
- private final PortletRequest request;
-
- public PortletRequestWrapper(PortletRequest request) {
- this.request = request;
- }
-
- public Object getAttribute(String name) {
- return request.getAttribute(name);
- }
-
- public int getContentLength() {
- return ((ClientDataRequest) request).getContentLength();
- }
-
- public InputStream getInputStream() throws IOException {
- return ((ClientDataRequest) request).getPortletInputStream();
- }
-
- public String getParameter(String name) {
- String value = request.getParameter(name);
- if (value == null) {
- // for GateIn portlet container simple-portal
- try {
- Method getRealReq = request.getClass().getMethod(
- "getRealRequest");
- HttpServletRequestWrapper origRequest = (HttpServletRequestWrapper) getRealReq
- .invoke(request);
- value = origRequest.getParameter(name);
- } catch (Exception e) {
- // do nothing - not on GateIn simple-portal
- }
- }
- return value;
- }
-
- public String getRequestID() {
- return "WindowID:" + request.getWindowID();
- }
-
- public Session getSession() {
- return new PortletSessionWrapper(request.getPortletSession());
- }
-
- public Object getWrappedRequest() {
- return request;
- }
-
- public boolean isRunningInPortlet() {
- return true;
- }
-
- public void setAttribute(String name, Object o) {
- request.setAttribute(name, o);
- }
-
- }
-
- private static class PortletResponseWrapper implements Response {
-
- private final PortletResponse response;
-
- public PortletResponseWrapper(PortletResponse response) {
- this.response = response;
- }
-
- public OutputStream getOutputStream() throws IOException {
- return ((MimeResponse) response).getPortletOutputStream();
- }
-
- public Object getWrappedResponse() {
- return response;
- }
-
- public void setContentType(String type) {
- ((MimeResponse) response).setContentType(type);
- }
- }
-
- private static class PortletSessionWrapper implements Session {
-
- private final PortletSession session;
-
- public PortletSessionWrapper(PortletSession session) {
- this.session = session;
- }
-
- public Object getAttribute(String name) {
- return session.getAttribute(name);
- }
-
- public int getMaxInactiveInterval() {
- return session.getMaxInactiveInterval();
- }
-
- public Object getWrappedSession() {
- return session;
- }
-
- public boolean isNew() {
- return session.isNew();
- }
-
- public void setAttribute(String name, Object o) {
- session.setAttribute(name, o);
- }
-
- }
-
- private static class AbstractApplicationPortletWrapper implements Callback {
-
- private final AbstractApplicationPortlet portlet;
-
- public AbstractApplicationPortletWrapper(
- AbstractApplicationPortlet portlet) {
- this.portlet = portlet;
- }
-
- public void criticalNotification(Request request, Response response,
- String cap, String msg, String details, String outOfSyncURL)
- throws IOException {
- portlet.criticalNotification(
- (PortletRequest) request.getWrappedRequest(),
- (MimeResponse) response.getWrappedResponse(), cap, msg,
- details, outOfSyncURL);
- }
-
- public String getRequestPathInfo(Request request) {
- if (request.getWrappedRequest() instanceof ResourceRequest) {
- return ((ResourceRequest) request.getWrappedRequest())
- .getResourceID();
- } else {
- // We do not use paths in portlet mode
- throw new UnsupportedOperationException(
- "PathInfo only available when using ResourceRequests");
- }
- }
-
- public InputStream getThemeResourceAsStream(String themeName,
- String resource) throws IOException {
- return portlet.getPortletContext().getResourceAsStream(
- "/" + AbstractApplicationPortlet.THEME_DIRECTORY_PATH
- + themeName + "/" + resource);
- }
-
- }
-
- public PortletCommunicationManager(Application application) {
- super(application);
- }
-
- public void handleFileUpload(ResourceRequest request,
- ResourceResponse response) throws IOException {
- String contentType = request.getContentType();
- String name = request.getParameter("name");
- String ownerId = request.getParameter("rec-owner");
- VariableOwner variableOwner = getVariableOwner(ownerId);
- StreamVariable streamVariable = ownerToNameToStreamVariable.get(
- variableOwner).get(name);
-
- if (contentType.contains("boundary")) {
- doHandleSimpleMultipartFileUpload(
- new PortletRequestWrapper(request),
- new PortletResponseWrapper(response), streamVariable, name,
- variableOwner, contentType.split("boundary=")[1]);
- } else {
- doHandleXhrFilePost(new PortletRequestWrapper(request),
- new PortletResponseWrapper(response), streamVariable, name,
- variableOwner, request.getContentLength());
- }
-
- }
-
- @Override
- protected void unregisterPaintable(Component p) {
- super.unregisterPaintable(p);
- if (ownerToNameToStreamVariable != null) {
- ownerToNameToStreamVariable.remove(p);
- }
- }
-
- public void handleUidlRequest(ResourceRequest request,
- ResourceResponse response,
- AbstractApplicationPortlet applicationPortlet, Window window)
- throws InvalidUIDLSecurityKeyException, IOException {
- currentUidlResponse = response;
- doHandleUidlRequest(new PortletRequestWrapper(request),
- new PortletResponseWrapper(response),
- new AbstractApplicationPortletWrapper(applicationPortlet),
- window);
- currentUidlResponse = null;
- }
-
- DownloadStream handleURI(Window window, ResourceRequest request,
- ResourceResponse response,
- AbstractApplicationPortlet applicationPortlet) {
- return handleURI(window, new PortletRequestWrapper(request),
- new PortletResponseWrapper(response),
- new AbstractApplicationPortletWrapper(applicationPortlet));
- }
-
- /**
- * Gets the existing application or creates a new one. Get a window within
- * an application based on the requested URI.
- *
- * @param request
- * the portlet Request.
- * @param applicationPortlet
- * @param application
- * the Application to query for window.
- * @param assumedWindow
- * if the window has been already resolved once, this parameter
- * must contain the window.
- * @return Window matching the given URI or null if not found.
- * @throws ServletException
- * if an exception has occurred that interferes with the
- * servlet's normal operation.
- */
- Window getApplicationWindow(PortletRequest request,
- AbstractApplicationPortlet applicationPortlet,
- Application application, Window assumedWindow) {
-
- return doGetApplicationWindow(new PortletRequestWrapper(request),
- new AbstractApplicationPortletWrapper(applicationPortlet),
- application, assumedWindow);
- }
-
- private Map<VariableOwner, Map<String, StreamVariable>> ownerToNameToStreamVariable;
-
- @Override
- String getStreamVariableTargetUrl(VariableOwner owner, String name,
- StreamVariable value) {
- if (ownerToNameToStreamVariable == null) {
- ownerToNameToStreamVariable = new HashMap<VariableOwner, Map<String, StreamVariable>>();
- }
- Map<String, StreamVariable> nameToReceiver = ownerToNameToStreamVariable
- .get(owner);
- if (nameToReceiver == null) {
- nameToReceiver = new HashMap<String, StreamVariable>();
- ownerToNameToStreamVariable.put(owner, nameToReceiver);
- }
- nameToReceiver.put(name, value);
- ResourceURL resurl = currentUidlResponse.createResourceURL();
- resurl.setResourceID("UPLOAD");
- resurl.setParameter("name", name);
- resurl.setParameter("rec-owner", getPaintableId((Paintable) owner));
- resurl.setProperty("name", name);
- resurl.setProperty("rec-owner", getPaintableId((Paintable) owner));
- return resurl.toString();
- }
-
- @Override
- protected void cleanStreamVariable(VariableOwner owner, String name) {
- Map<String, StreamVariable> map = ownerToNameToStreamVariable
- .get(owner);
- map.remove(name);
- if (map.isEmpty()) {
- ownerToNameToStreamVariable.remove(owner);
- }
- }
-
-}
+//package com.vaadin.terminal.gwt.server;
+//
+//import java.io.IOException;
+//import java.io.InputStream;
+//import java.io.OutputStream;
+//import java.lang.reflect.Method;
+//import java.util.HashMap;
+//import java.util.Map;
+//
+//import javax.portlet.ClientDataRequest;
+//import javax.portlet.MimeResponse;
+//import javax.portlet.PortletRequest;
+//import javax.portlet.PortletResponse;
+//import javax.portlet.PortletSession;
+//import javax.portlet.ResourceRequest;
+//import javax.portlet.ResourceResponse;
+//import javax.portlet.ResourceURL;
+//import javax.servlet.ServletException;
+//import javax.servlet.http.HttpServletRequestWrapper;
+//
+//import com.vaadin.Application;
+//import com.vaadin.terminal.DownloadStream;
+//import com.vaadin.terminal.Paintable;
+//import com.vaadin.terminal.StreamVariable;
+//import com.vaadin.terminal.VariableOwner;
+//import com.vaadin.ui.Component;
+//import com.vaadin.ui.Window;
+//
+///**
+// * TODO document me!
+// *
+// * @author peholmst
+// *
+// */
+//@SuppressWarnings("serial")
+//public class PortletCommunicationManager extends AbstractCommunicationManager {
+//
+// private transient ResourceResponse currentUidlResponse;
+//
+// private static class PortletRequestWrapper implements Request {
+//
+// private final PortletRequest request;
+//
+// public PortletRequestWrapper(PortletRequest request) {
+// this.request = request;
+// }
+//
+// public Object getAttribute(String name) {
+// return request.getAttribute(name);
+// }
+//
+// public int getContentLength() {
+// return ((ClientDataRequest) request).getContentLength();
+// }
+//
+// public InputStream getInputStream() throws IOException {
+// return ((ClientDataRequest) request).getPortletInputStream();
+// }
+//
+// public String getParameter(String name) {
+// String value = request.getParameter(name);
+// if (value == null) {
+// // for GateIn portlet container simple-portal
+// try {
+// Method getRealReq = request.getClass().getMethod(
+// "getRealRequest");
+// HttpServletRequestWrapper origRequest = (HttpServletRequestWrapper) getRealReq
+// .invoke(request);
+// value = origRequest.getParameter(name);
+// } catch (Exception e) {
+// // do nothing - not on GateIn simple-portal
+// }
+// }
+// return value;
+// }
+//
+// public String getRequestID() {
+// return "WindowID:" + request.getWindowID();
+// }
+//
+// public Session getSession() {
+// return new PortletSessionWrapper(request.getPortletSession());
+// }
+//
+// public Object getWrappedRequest() {
+// return request;
+// }
+//
+// public boolean isRunningInPortlet() {
+// return true;
+// }
+//
+// public void setAttribute(String name, Object o) {
+// request.setAttribute(name, o);
+// }
+//
+// }
+//
+// private static class PortletResponseWrapper implements Response {
+//
+// private final PortletResponse response;
+//
+// public PortletResponseWrapper(PortletResponse response) {
+// this.response = response;
+// }
+//
+// public OutputStream getOutputStream() throws IOException {
+// return ((MimeResponse) response).getPortletOutputStream();
+// }
+//
+// public Object getWrappedResponse() {
+// return response;
+// }
+//
+// public void setContentType(String type) {
+// ((MimeResponse) response).setContentType(type);
+// }
+// }
+//
+// private static class PortletSessionWrapper implements Session {
+//
+// private final PortletSession session;
+//
+// public PortletSessionWrapper(PortletSession session) {
+// this.session = session;
+// }
+//
+// public Object getAttribute(String name) {
+// return session.getAttribute(name);
+// }
+//
+// public int getMaxInactiveInterval() {
+// return session.getMaxInactiveInterval();
+// }
+//
+// public Object getWrappedSession() {
+// return session;
+// }
+//
+// public boolean isNew() {
+// return session.isNew();
+// }
+//
+// public void setAttribute(String name, Object o) {
+// session.setAttribute(name, o);
+// }
+//
+// }
+//
+// private static class AbstractApplicationPortletWrapper implements Callback {
+//
+// private final AbstractApplicationPortlet portlet;
+//
+// public AbstractApplicationPortletWrapper(
+// AbstractApplicationPortlet portlet) {
+// this.portlet = portlet;
+// }
+//
+// public void criticalNotification(Request request, Response response,
+// String cap, String msg, String details, String outOfSyncURL)
+// throws IOException {
+// portlet.criticalNotification(
+// (PortletRequest) request.getWrappedRequest(),
+// (MimeResponse) response.getWrappedResponse(), cap, msg,
+// details, outOfSyncURL);
+// }
+//
+// public String getRequestPathInfo(Request request) {
+// if (request.getWrappedRequest() instanceof ResourceRequest) {
+// return ((ResourceRequest) request.getWrappedRequest())
+// .getResourceID();
+// } else {
+// // We do not use paths in portlet mode
+// throw new UnsupportedOperationException(
+// "PathInfo only available when using ResourceRequests");
+// }
+// }
+//
+// public InputStream getThemeResourceAsStream(String themeName,
+// String resource) throws IOException {
+// return portlet.getPortletContext().getResourceAsStream(
+// "/" + AbstractApplicationPortlet.THEME_DIRECTORY_PATH
+// + themeName + "/" + resource);
+// }
+//
+// }
+//
+// public PortletCommunicationManager(Application application) {
+// super(application);
+// }
+//
+// public void handleFileUpload(ResourceRequest request,
+// ResourceResponse response) throws IOException {
+// String contentType = request.getContentType();
+// String name = request.getParameter("name");
+// String ownerId = request.getParameter("rec-owner");
+// VariableOwner variableOwner = getVariableOwner(ownerId);
+// StreamVariable streamVariable = ownerToNameToStreamVariable.get(
+// variableOwner).get(name);
+//
+// if (contentType.contains("boundary")) {
+// doHandleSimpleMultipartFileUpload(
+// new PortletRequestWrapper(request),
+// new PortletResponseWrapper(response), streamVariable, name,
+// variableOwner, contentType.split("boundary=")[1]);
+// } else {
+// doHandleXhrFilePost(new PortletRequestWrapper(request),
+// new PortletResponseWrapper(response), streamVariable, name,
+// variableOwner, request.getContentLength());
+// }
+//
+// }
+//
+// @Override
+// protected void unregisterPaintable(Component p) {
+// super.unregisterPaintable(p);
+// if (ownerToNameToStreamVariable != null) {
+// ownerToNameToStreamVariable.remove(p);
+// }
+// }
+//
+// public void handleUidlRequest(ResourceRequest request,
+// ResourceResponse response,
+// AbstractApplicationPortlet applicationPortlet, Window window)
+// throws InvalidUIDLSecurityKeyException, IOException {
+// currentUidlResponse = response;
+// doHandleUidlRequest(new PortletRequestWrapper(request),
+// new PortletResponseWrapper(response),
+// new AbstractApplicationPortletWrapper(applicationPortlet),
+// window);
+// currentUidlResponse = null;
+// }
+//
+// DownloadStream handleURI(Window window, ResourceRequest request,
+// ResourceResponse response,
+// AbstractApplicationPortlet applicationPortlet) {
+// return handleURI(window, new PortletRequestWrapper(request),
+// new PortletResponseWrapper(response),
+// new AbstractApplicationPortletWrapper(applicationPortlet));
+// }
+//
+// /**
+// * Gets the existing application or creates a new one. Get a window within
+// * an application based on the requested URI.
+// *
+// * @param request
+// * the portlet Request.
+// * @param applicationPortlet
+// * @param application
+// * the Application to query for window.
+// * @param assumedWindow
+// * if the window has been already resolved once, this parameter
+// * must contain the window.
+// * @return Window matching the given URI or null if not found.
+// * @throws ServletException
+// * if an exception has occurred that interferes with the
+// * servlet's normal operation.
+// */
+// Window getApplicationWindow(PortletRequest request,
+// AbstractApplicationPortlet applicationPortlet,
+// Application application, Window assumedWindow) {
+//
+// return doGetApplicationWindow(new PortletRequestWrapper(request),
+// new AbstractApplicationPortletWrapper(applicationPortlet),
+// application, assumedWindow);
+// }
+//
+// private Map<VariableOwner, Map<String, StreamVariable>> ownerToNameToStreamVariable;
+//
+// @Override
+// String getStreamVariableTargetUrl(VariableOwner owner, String name,
+// StreamVariable value) {
+// if (ownerToNameToStreamVariable == null) {
+// ownerToNameToStreamVariable = new HashMap<VariableOwner, Map<String, StreamVariable>>();
+// }
+// Map<String, StreamVariable> nameToReceiver = ownerToNameToStreamVariable
+// .get(owner);
+// if (nameToReceiver == null) {
+// nameToReceiver = new HashMap<String, StreamVariable>();
+// ownerToNameToStreamVariable.put(owner, nameToReceiver);
+// }
+// nameToReceiver.put(name, value);
+// ResourceURL resurl = currentUidlResponse.createResourceURL();
+// resurl.setResourceID("UPLOAD");
+// resurl.setParameter("name", name);
+// resurl.setParameter("rec-owner", getPaintableId((Paintable) owner));
+// resurl.setProperty("name", name);
+// resurl.setProperty("rec-owner", getPaintableId((Paintable) owner));
+// return resurl.toString();
+// }
+//
+// @Override
+// protected void cleanStreamVariable(VariableOwner owner, String name) {
+// Map<String, StreamVariable> map = ownerToNameToStreamVariable
+// .get(owner);
+// map.remove(name);
+// if (map.isEmpty()) {
+// ownerToNameToStreamVariable.remove(owner);
+// }
+// }
+//
+// }
diff --git a/src/com/vaadin/ui/AbstractComponent.java b/src/com/vaadin/ui/AbstractComponent.java
index eda2fd64ad..b6eefec7be 100644
--- a/src/com/vaadin/ui/AbstractComponent.java
+++ b/src/com/vaadin/ui/AbstractComponent.java
@@ -609,11 +609,11 @@ public abstract class AbstractComponent implements Component, MethodEventSource
* Gets the parent window of the component. Don't add a JavaDoc comment
* here, we use the default documentation from implemented interface.
*/
- public Window getWindow() {
+ public Root getRoot() {
if (parent == null) {
return null;
} else {
- return parent.getWindow();
+ return parent.getRoot();
}
}
@@ -651,7 +651,7 @@ public abstract class AbstractComponent implements Component, MethodEventSource
if (this instanceof Focusable) {
final Application app = getApplication();
if (app != null) {
- getWindow().setFocusedComponent((Focusable) this);
+ // getRoot().setFocusedComponent((Focusable) this);
delayedFocus = false;
} else {
delayedFocus = true;
diff --git a/src/com/vaadin/ui/AbstractField.java b/src/com/vaadin/ui/AbstractField.java
index 7899569ea8..5df0ac8fe6 100644
--- a/src/com/vaadin/ui/AbstractField.java
+++ b/src/com/vaadin/ui/AbstractField.java
@@ -1118,17 +1118,17 @@ public abstract class AbstractField extends AbstractComponent implements Field,
@Override
public void attach() {
super.attach();
- if (actionManager != null) {
- actionManager.setViewer(getWindow());
- }
+ // if (actionManager != null) {
+ // actionManager.setViewer(getRoot());
+ // }
}
@Override
public void detach() {
super.detach();
- if (actionManager != null) {
- actionManager.setViewer((Window) null);
- }
+ // if (actionManager != null) {
+ // actionManager.setViewer((Window) null);
+ // }
}
/**
@@ -1257,9 +1257,9 @@ public abstract class AbstractField extends AbstractComponent implements Field,
protected ActionManager getActionManager() {
if (actionManager == null) {
actionManager = new ActionManager();
- if (getWindow() != null) {
- actionManager.setViewer(getWindow());
- }
+ // if (getRoot() != null) {
+ // actionManager.setViewer(getRoot());
+ // }
}
return actionManager;
}
diff --git a/src/com/vaadin/ui/Component.java b/src/com/vaadin/ui/Component.java
index 2d794c39b0..e5e1bb473e 100644
--- a/src/com/vaadin/ui/Component.java
+++ b/src/com/vaadin/ui/Component.java
@@ -573,7 +573,7 @@ public interface Component extends Paintable, VariableOwner, Sizeable,
* @return the parent window of the component or <code>null</code> if it is
* not attached to a window or is itself a window
*/
- public Window getWindow();
+ public Root getRoot();
/**
* Gets the application object to which the component is attached.
@@ -606,7 +606,7 @@ public interface Component extends Paintable, VariableOwner, Sizeable,
* <p>
* Reimplementing the {@code attach()} method is useful for tasks that need
* to get a reference to the parent, window, or application object with the
- * {@link #getParent()}, {@link #getWindow()}, and {@link #getApplication()}
+ * {@link #getParent()}, {@link #getRoot()}, and {@link #getApplication()}
* methods. A component does not yet know these objects in the constructor,
* so in such case, the methods will return {@code null}. For example, the
* following is invalid:
@@ -661,7 +661,7 @@ public interface Component extends Paintable, VariableOwner, Sizeable,
* Notifies the component that it is detached from the application.
*
* <p>
- * The {@link #getApplication()} and {@link #getWindow()} methods might
+ * The {@link #getApplication()} and {@link #getRoot()} methods might
* return <code>null</code> after this method is called.
* </p>
*
diff --git a/src/com/vaadin/ui/DefaultRoot.java b/src/com/vaadin/ui/DefaultRoot.java
new file mode 100644
index 0000000000..1bc4e7631f
--- /dev/null
+++ b/src/com/vaadin/ui/DefaultRoot.java
@@ -0,0 +1,58 @@
+package com.vaadin.ui;
+
+import java.util.Collections;
+import java.util.Iterator;
+
+import com.vaadin.Application;
+import com.vaadin.terminal.PaintException;
+import com.vaadin.terminal.PaintTarget;
+import com.vaadin.terminal.Terminal;
+import com.vaadin.terminal.gwt.client.ui.VView;
+
+@ClientWidget(VView.class)
+public class DefaultRoot extends AbstractComponentContainer implements Root {
+ private final Component content;
+ private Terminal terminal;
+ private final Application application;
+
+ public DefaultRoot(Application application, Component content) {
+ this.application = application;
+ this.content = content;
+ addComponent(content);
+ }
+
+ @Override
+ public Root getRoot() {
+ return this;
+ }
+
+ public void replaceComponent(Component oldComponent, Component newComponent) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Application getApplication() {
+ return application;
+ }
+
+ @Override
+ public void paintContent(PaintTarget target) throws PaintException {
+ content.paint(target);
+ }
+
+ public Iterator<Component> getComponentIterator() {
+ return Collections.singleton(content).iterator();
+ }
+
+ public String getName() {
+ return "";
+ }
+
+ public Terminal getTerminal() {
+ return terminal;
+ }
+
+ public void setTerminal(Terminal terminal) {
+ this.terminal = terminal;
+ }
+}
diff --git a/src/com/vaadin/ui/LoginForm.java b/src/com/vaadin/ui/LoginForm.java
index 509a072c27..add2a53ff2 100644
--- a/src/com/vaadin/ui/LoginForm.java
+++ b/src/com/vaadin/ui/LoginForm.java
@@ -79,7 +79,7 @@ public class LoginForm extends CustomComponent {
public void handleParameters(Map<String, String[]> parameters) {
if (parameters.containsKey("username")) {
- getWindow().addURIHandler(uriHandler);
+ // getWindow().addURIHandler(uriHandler);
HashMap<String, String> params = new HashMap<String, String>();
// expecting single params
@@ -102,9 +102,9 @@ public class LoginForm extends CustomComponent {
public DownloadStream handleURI(URL context, String relativeUri) {
if (relativeUri != null && relativeUri.contains("loginHandler")) {
- if (window != null) {
- window.removeURIHandler(this);
- }
+ // if (window != null) {
+ // window.removeURIHandler(this);
+ // }
DownloadStream downloadStream = new DownloadStream(
new ByteArrayInputStream(responce.getBytes()),
"text/html", "loginSuccesfull");
@@ -116,7 +116,7 @@ public class LoginForm extends CustomComponent {
}
};
- private Window window;
+ // private Window window;
public LoginForm() {
iframe.setType(Embedded.TYPE_BROWSER);
@@ -135,7 +135,8 @@ public class LoginForm extends CustomComponent {
*/
protected byte[] getLoginHTML() {
String appUri = getApplication().getURL().toString()
- + getWindow().getName() + "/";
+ // + getWindow().getName()
+ + "/";
try {
return ("<!DOCTYPE html PUBLIC \"-//W3C//DTD "
@@ -190,21 +191,21 @@ public class LoginForm extends CustomComponent {
public void attach() {
super.attach();
getApplication().addResource(loginPage);
- getWindow().addParameterHandler(paramHandler);
+ // getWindow().addParameterHandler(paramHandler);
iframe.setSource(loginPage);
}
@Override
public void detach() {
getApplication().removeResource(loginPage);
- getWindow().removeParameterHandler(paramHandler);
+ // getWindow().removeParameterHandler(paramHandler);
// store window temporary to properly remove uri handler once
// response is handled. (May happen if login handler removes login
// form
- window = getWindow();
- if (window.getParent() != null) {
- window = window.getParent();
- }
+ // window = getRoot();
+ // if (window.getParent() != null) {
+ // window = window.getParent();
+ // }
super.detach();
}
diff --git a/src/com/vaadin/ui/Root.java b/src/com/vaadin/ui/Root.java
new file mode 100644
index 0000000000..a1a2fc37bc
--- /dev/null
+++ b/src/com/vaadin/ui/Root.java
@@ -0,0 +1,13 @@
+package com.vaadin.ui;
+
+import com.vaadin.terminal.Terminal;
+
+public interface Root extends Component {
+
+ public String getName();
+
+ public Terminal getTerminal();
+
+ public void setTerminal(Terminal terminal);
+
+}
diff --git a/src/com/vaadin/ui/Window.java b/src/com/vaadin/ui/Window.java
index ddd1f6fc3b..649bbe145e 100644
--- a/src/com/vaadin/ui/Window.java
+++ b/src/com/vaadin/ui/Window.java
@@ -6,15 +6,6 @@ package com.vaadin.ui;
import java.io.Serializable;
import java.lang.reflect.Method;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Set;
import com.vaadin.Application;
import com.vaadin.event.FieldEvents.BlurEvent;
@@ -27,14 +18,10 @@ import com.vaadin.event.ShortcutAction;
import com.vaadin.event.ShortcutAction.KeyCode;
import com.vaadin.event.ShortcutAction.ModifierKey;
import com.vaadin.event.ShortcutListener;
-import com.vaadin.terminal.DownloadStream;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
-import com.vaadin.terminal.ParameterHandler;
import com.vaadin.terminal.Resource;
import com.vaadin.terminal.Sizeable;
-import com.vaadin.terminal.Terminal;
-import com.vaadin.terminal.URIHandler;
import com.vaadin.terminal.gwt.client.ui.VView;
import com.vaadin.terminal.gwt.client.ui.VWindow;
@@ -85,8 +72,7 @@ import com.vaadin.terminal.gwt.client.ui.VWindow;
*/
@SuppressWarnings("serial")
@ClientWidget(VWindow.class)
-public class Window extends Panel implements URIHandler, ParameterHandler,
- FocusNotifier, BlurNotifier {
+public class Window extends Panel implements FocusNotifier, BlurNotifier {
/**
* <b>Application window only</b>. A border style used for opening resources
@@ -106,57 +92,62 @@ public class Window extends Panel implements URIHandler, ParameterHandler,
*/
public static final int BORDER_DEFAULT = 2;
- /**
- * <b>Application window only</b>. The user terminal for this window.
- */
- private Terminal terminal = null;
-
- /**
- * <b>Application window only</b>. The application this window is attached
- * to or null.
- */
- private Application application = null;
-
- /**
- * <b>Application window only</b>. List of URI handlers for this window.
- */
- private LinkedList<URIHandler> uriHandlerList = null;
-
- /**
- * <b>Application window only</b>. List of parameter handlers for this
- * window.
- */
- private LinkedList<ParameterHandler> parameterHandlerList = null;
-
- /**
- * <b>Application window only</b>. List of sub windows in this window. A sub
- * window cannot have other sub windows.
- */
- private final LinkedHashSet<Window> subwindows = new LinkedHashSet<Window>();
-
- /**
- * <b>Application window only</b>. Explicitly specified theme of this window
- * or null if the application theme should be used.
- */
- private String theme = null;
-
- /**
- * <b>Application window only</b>. Resources to be opened automatically on
- * next repaint. The list is automatically cleared when it has been sent to
- * the client.
- */
- private final LinkedList<OpenResource> openList = new LinkedList<OpenResource>();
-
- /**
- * <b>Application window only</b>. Unique name of the window used to
- * identify it.
- */
- private String name = null;
-
- /**
- * <b>Application window only.</b> Border mode of the Window.
- */
- private int border = BORDER_DEFAULT;
+ // /**
+ // * <b>Application window only</b>. The user terminal for this window.
+ // */
+ // private Terminal terminal = null;
+ //
+ // /**
+ // * <b>Application window only</b>. The application this window is attached
+ // * to or null.
+ // */
+ // private Application application = null;
+ //
+ // /**
+ // * <b>Application window only</b>. List of URI handlers for this window.
+ // */
+ // private LinkedList<URIHandler> uriHandlerList = null;
+ //
+ // /**
+ // * <b>Application window only</b>. List of parameter handlers for this
+ // * window.
+ // */
+ // private LinkedList<ParameterHandler> parameterHandlerList = null;
+ //
+ // /**
+ // * <b>Application window only</b>. List of sub windows in this window. A
+ // sub
+ // * window cannot have other sub windows.
+ // */
+ // private final LinkedHashSet<Window> subwindows = new
+ // LinkedHashSet<Window>();
+ //
+ // /**
+ // * <b>Application window only</b>. Explicitly specified theme of this
+ // window
+ // * or null if the application theme should be used.
+ // */
+ // private String theme = null;
+ //
+ // /**
+ // * <b>Application window only</b>. Resources to be opened automatically on
+ // * next repaint. The list is automatically cleared when it has been sent
+ // to
+ // * the client.
+ // */
+ // private final LinkedList<OpenResource> openList = new
+ // LinkedList<OpenResource>();
+ //
+ // /**
+ // * <b>Application window only</b>. Unique name of the window used to
+ // * identify it.
+ // */
+ // private String name = null;
+ //
+ // /**
+ // * <b>Application window only.</b> Border mode of the Window.
+ // */
+ // private int border = BORDER_DEFAULT;
/**
* <b>Sub window only</b>. Top offset in pixels for the sub window (relative
@@ -170,12 +161,13 @@ public class Window extends Panel implements URIHandler, ParameterHandler,
*/
private int positionX = -1;
- /**
- * <b>Application window only</b>. A list of notifications that are waiting
- * to be sent to the client. Cleared (set to null) when the notifications
- * have been sent.
- */
- private LinkedList<Notification> notifications;
+ // /**
+ // * <b>Application window only</b>. A list of notifications that are
+ // waiting
+ // * to be sent to the client. Cleared (set to null) when the notifications
+ // * have been sent.
+ // */
+ // private LinkedList<Notification> notifications;
/**
* <b>Sub window only</b>. Modality flag for sub window.
@@ -210,12 +202,13 @@ public class Window extends Panel implements URIHandler, ParameterHandler,
*/
private Focusable pendingFocus;
- /**
- * <b>Application window only</b>. A list of javascript commands that are
- * waiting to be sent to the client. Cleared (set to null) when the commands
- * have been sent.
- */
- private ArrayList<String> jsExecQueue = null;
+ // /**
+ // * <b>Application window only</b>. A list of javascript commands that are
+ // * waiting to be sent to the client. Cleared (set to null) when the
+ // commands
+ // * have been sent.
+ // */
+ // private ArrayList<String> jsExecQueue = null;
/**
* The component that should be scrolled into view after the next repaint.
@@ -269,287 +262,297 @@ public class Window extends Panel implements URIHandler, ParameterHandler,
super.addComponent(c);
}
- /**
- * <b>Application window only</b>. Gets the user terminal.
- *
- * @return the user terminal
- */
- public Terminal getTerminal() {
- return terminal;
- }
+ // /**
+ // * <b>Application window only</b>. Gets the user terminal.
+ // *
+ // * @return the user terminal
+ // */
+ // public Terminal getTerminal() {
+ // return terminal;
+ // }
/* ********************************************************************* */
- /**
- * Gets the parent window of the component.
- * <p>
- * This is always the window itself.
- * </p>
- * <p>
- * <b>This method is not meant to be overridden. Due to CDI requirements we
- * cannot declare it as final even though it should be final.</b>
- * </p>
- *
- * @see Component#getWindow()
- * @return the window itself
- */
- @Override
- public Window getWindow() {
- return this;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.vaadin.ui.AbstractComponent#getApplication()
- */
- @Override
- public Application getApplication() {
- if (getParent() == null) {
- return application;
- }
- return getParent().getApplication();
- }
-
- /**
- * Gets the parent component of the window.
- *
- * <p>
- * The parent of an application window is always null. The parent of a sub
- * window is the application window the sub window is attached to.
- * </p>
- * <p>
- * <b>This method is not meant to be overridden. Due to CDI requirements we
- * cannot declare it as final even though it should be final.</b>
- * </p>
- *
- *
- * @return the parent window
- * @see Component#getParent()
- */
- @Override
- public Window getParent() {
- return (Window) super.getParent();
- }
+ // /**
+ // * Gets the parent window of the component.
+ // * <p>
+ // * This is always the window itself.
+ // * </p>
+ // * <p>
+ // * <b>This method is not meant to be overridden. Due to CDI requirements
+ // we
+ // * cannot declare it as final even though it should be final.</b>
+ // * </p>
+ // *
+ // * @see Component#getRoot()
+ // * @return the window itself
+ // */
+ // @Override
+ // public Root getRoot() {
+ // return this;
+ // }
+
+ // /*
+ // * (non-Javadoc)
+ // *
+ // * @see com.vaadin.ui.AbstractComponent#getApplication()
+ // */
+ // @Override
+ // public Application getApplication() {
+ // if (getParent() == null) {
+ // return application;
+ // }
+ // return getParent().getApplication();
+ // }
+
+ // /**
+ // * Gets the parent component of the window.
+ // *
+ // * <p>
+ // * The parent of an application window is always null. The parent of a sub
+ // * window is the application window the sub window is attached to.
+ // * </p>
+ // * <p>
+ // * <b>This method is not meant to be overridden. Due to CDI requirements
+ // we
+ // * cannot declare it as final even though it should be final.</b>
+ // * </p>
+ // *
+ // *
+ // * @return the parent window
+ // * @see Component#getParent()
+ // */
+ // @Override
+ // public Window getParent() {
+ // return (Window) super.getParent();
+ // }
/* ********************************************************************* */
- /**
- * <b>Application window only</b>. Adds a new URI handler to this window. If
- * this is a sub window the URI handler is attached to the parent
- * application window.
- *
- * @param handler
- * the URI handler to add.
- */
- public void addURIHandler(URIHandler handler) {
- if (getParent() != null) {
- // this is subwindow, attach to main level instead
- // TODO hold internal list also and remove on detach
- Window mainWindow = getParent();
- mainWindow.addURIHandler(handler);
- } else {
- if (uriHandlerList == null) {
- uriHandlerList = new LinkedList<URIHandler>();
- }
- synchronized (uriHandlerList) {
- if (!uriHandlerList.contains(handler)) {
- uriHandlerList.addLast(handler);
- }
- }
- }
- }
-
- /**
- * <b>Application window only</b>. Removes the URI handler from this window.
- * If this is a sub window the URI handler is removed from the parent
- * application window.
- *
- * @param handler
- * the URI handler to remove.
- */
- public void removeURIHandler(URIHandler handler) {
- if (getParent() != null) {
- // this is subwindow
- Window mainWindow = getParent();
- mainWindow.removeURIHandler(handler);
- } else {
- if (handler == null || uriHandlerList == null) {
- return;
- }
- synchronized (uriHandlerList) {
- uriHandlerList.remove(handler);
- if (uriHandlerList.isEmpty()) {
- uriHandlerList = null;
- }
- }
- }
- }
-
- /**
- * <b>Application window only</b>. Handles an URI by passing the URI to all
- * URI handlers defined using {@link #addURIHandler(URIHandler)}. All URI
- * handlers are called for each URI but no more than one handler may return
- * a {@link DownloadStream}. If more than one stream is returned a
- * {@code RuntimeException} is thrown.
- *
- * @param context
- * The URL of the application
- * @param relativeUri
- * The URI relative to {@code context}
- * @return A {@code DownloadStream} that one of the URI handlers returned,
- * null if no {@code DownloadStream} was returned.
- */
- public DownloadStream handleURI(URL context, String relativeUri) {
-
- DownloadStream result = null;
- if (uriHandlerList != null) {
- Object[] handlers;
- synchronized (uriHandlerList) {
- handlers = uriHandlerList.toArray();
- }
- for (int i = 0; i < handlers.length; i++) {
- final DownloadStream ds = ((URIHandler) handlers[i]).handleURI(
- context, relativeUri);
- if (ds != null) {
- if (result != null) {
- throw new RuntimeException("handleURI for " + context
- + " uri: '" + relativeUri
- + "' returns ambigious result.");
- }
- result = ds;
- }
- }
- }
- return result;
- }
+ // /**
+ // * <b>Application window only</b>. Adds a new URI handler to this window.
+ // If
+ // * this is a sub window the URI handler is attached to the parent
+ // * application window.
+ // *
+ // * @param handler
+ // * the URI handler to add.
+ // */
+ // public void addURIHandler(URIHandler handler) {
+ // if (getParent() != null) {
+ // // this is subwindow, attach to main level instead
+ // // TODO hold internal list also and remove on detach
+ // Window mainWindow = getParent();
+ // mainWindow.addURIHandler(handler);
+ // } else {
+ // if (uriHandlerList == null) {
+ // uriHandlerList = new LinkedList<URIHandler>();
+ // }
+ // synchronized (uriHandlerList) {
+ // if (!uriHandlerList.contains(handler)) {
+ // uriHandlerList.addLast(handler);
+ // }
+ // }
+ // }
+ // }
+
+ // /**
+ // * <b>Application window only</b>. Removes the URI handler from this
+ // window.
+ // * If this is a sub window the URI handler is removed from the parent
+ // * application window.
+ // *
+ // * @param handler
+ // * the URI handler to remove.
+ // */
+ // public void removeURIHandler(URIHandler handler) {
+ // if (getParent() != null) {
+ // // this is subwindow
+ // Window mainWindow = getParent();
+ // mainWindow.removeURIHandler(handler);
+ // } else {
+ // if (handler == null || uriHandlerList == null) {
+ // return;
+ // }
+ // synchronized (uriHandlerList) {
+ // uriHandlerList.remove(handler);
+ // if (uriHandlerList.isEmpty()) {
+ // uriHandlerList = null;
+ // }
+ // }
+ // }
+ // }
+
+ // /**
+ // * <b>Application window only</b>. Handles an URI by passing the URI to
+ // all
+ // * URI handlers defined using {@link #addURIHandler(URIHandler)}. All URI
+ // * handlers are called for each URI but no more than one handler may
+ // return
+ // * a {@link DownloadStream}. If more than one stream is returned a
+ // * {@code RuntimeException} is thrown.
+ // *
+ // * @param context
+ // * The URL of the application
+ // * @param relativeUri
+ // * The URI relative to {@code context}
+ // * @return A {@code DownloadStream} that one of the URI handlers returned,
+ // * null if no {@code DownloadStream} was returned.
+ // */
+ // public DownloadStream handleURI(URL context, String relativeUri) {
+ //
+ // DownloadStream result = null;
+ // if (uriHandlerList != null) {
+ // Object[] handlers;
+ // synchronized (uriHandlerList) {
+ // handlers = uriHandlerList.toArray();
+ // }
+ // for (int i = 0; i < handlers.length; i++) {
+ // final DownloadStream ds = ((URIHandler) handlers[i]).handleURI(
+ // context, relativeUri);
+ // if (ds != null) {
+ // if (result != null) {
+ // throw new RuntimeException("handleURI for " + context
+ // + " uri: '" + relativeUri
+ // + "' returns ambigious result.");
+ // }
+ // result = ds;
+ // }
+ // }
+ // }
+ // return result;
+ // }
/* ********************************************************************* */
- /**
- * <b>Application window only</b>. Adds a new parameter handler to this
- * window. If this is a sub window the parameter handler is attached to the
- * parent application window.
- *
- * @param handler
- * the parameter handler to add.
- */
- public void addParameterHandler(ParameterHandler handler) {
- if (getParent() != null) {
- // this is subwindow
- // TODO hold internal list also and remove on detach
- Window mainWindow = getParent();
- mainWindow.addParameterHandler(handler);
- } else {
- if (parameterHandlerList == null) {
- parameterHandlerList = new LinkedList<ParameterHandler>();
- }
- synchronized (parameterHandlerList) {
- if (!parameterHandlerList.contains(handler)) {
- parameterHandlerList.addLast(handler);
- }
- }
- }
-
- }
-
- /**
- * <b>Application window only</b>. Removes the parameter handler from this
- * window. If this is a sub window the parameter handler is removed from the
- * parent application window.
- *
- * @param handler
- * the parameter handler to remove.
- */
- public void removeParameterHandler(ParameterHandler handler) {
- if (getParent() != null) {
- // this is subwindow
- Window mainWindow = getParent();
- mainWindow.removeParameterHandler(handler);
- } else {
- if (handler == null || parameterHandlerList == null) {
- return;
- }
- synchronized (parameterHandlerList) {
- parameterHandlerList.remove(handler);
- if (parameterHandlerList.isEmpty()) {
- parameterHandlerList = null;
- }
- }
- }
- }
-
- /**
- * <b>Application window only</b>. Handles parameters by passing the
- * parameters to all {@code ParameterHandler}s defined using
- * {@link #addParameterHandler(ParameterHandler)}. All
- * {@code ParameterHandler}s are called for each set of parameters.
- *
- * @param parameters
- * a map containing the parameter names and values
- * @see ParameterHandler#handleParameters(Map)
- */
- public void handleParameters(Map<String, String[]> parameters) {
- if (parameterHandlerList != null) {
- Object[] handlers;
- synchronized (parameterHandlerList) {
- handlers = parameterHandlerList.toArray();
- }
- for (int i = 0; i < handlers.length; i++) {
- ((ParameterHandler) handlers[i]).handleParameters(parameters);
- }
- }
- }
+ // /**
+ // * <b>Application window only</b>. Adds a new parameter handler to this
+ // * window. If this is a sub window the parameter handler is attached to
+ // the
+ // * parent application window.
+ // *
+ // * @param handler
+ // * the parameter handler to add.
+ // */
+ // public void addParameterHandler(ParameterHandler handler) {
+ // if (getParent() != null) {
+ // // this is subwindow
+ // // TODO hold internal list also and remove on detach
+ // Window mainWindow = getParent();
+ // mainWindow.addParameterHandler(handler);
+ // } else {
+ // if (parameterHandlerList == null) {
+ // parameterHandlerList = new LinkedList<ParameterHandler>();
+ // }
+ // synchronized (parameterHandlerList) {
+ // if (!parameterHandlerList.contains(handler)) {
+ // parameterHandlerList.addLast(handler);
+ // }
+ // }
+ // }
+ //
+ // }
+
+ // /**
+ // * <b>Application window only</b>. Removes the parameter handler from this
+ // * window. If this is a sub window the parameter handler is removed from
+ // the
+ // * parent application window.
+ // *
+ // * @param handler
+ // * the parameter handler to remove.
+ // */
+ // public void removeParameterHandler(ParameterHandler handler) {
+ // if (getParent() != null) {
+ // // this is subwindow
+ // Window mainWindow = getParent();
+ // mainWindow.removeParameterHandler(handler);
+ // } else {
+ // if (handler == null || parameterHandlerList == null) {
+ // return;
+ // }
+ // synchronized (parameterHandlerList) {
+ // parameterHandlerList.remove(handler);
+ // if (parameterHandlerList.isEmpty()) {
+ // parameterHandlerList = null;
+ // }
+ // }
+ // }
+ // }
+
+ // /**
+ // * <b>Application window only</b>. Handles parameters by passing the
+ // * parameters to all {@code ParameterHandler}s defined using
+ // * {@link #addParameterHandler(ParameterHandler)}. All
+ // * {@code ParameterHandler}s are called for each set of parameters.
+ // *
+ // * @param parameters
+ // * a map containing the parameter names and values
+ // * @see ParameterHandler#handleParameters(Map)
+ // */
+ // public void handleParameters(Map<String, String[]> parameters) {
+ // if (parameterHandlerList != null) {
+ // Object[] handlers;
+ // synchronized (parameterHandlerList) {
+ // handlers = parameterHandlerList.toArray();
+ // }
+ // for (int i = 0; i < handlers.length; i++) {
+ // ((ParameterHandler) handlers[i]).handleParameters(parameters);
+ // }
+ // }
+ // }
/* ********************************************************************* */
- /**
- * <b>Application window only</b>. Gets the theme for this window.
- * <p>
- * If the theme for this window is not explicitly set, the application theme
- * name is returned. If the window is not attached to an application, the
- * terminal default theme name is returned. If the theme name cannot be
- * determined, null is returned
- * </p>
- * <p>
- * Subwindows do not support themes and return the theme used by the parent
- * window
- * </p>
- *
- * @return the name of the theme used for the window
- */
- public String getTheme() {
- if (getParent() != null) {
- return (getParent()).getTheme();
- }
- if (theme != null) {
- return theme;
- }
- if ((application != null) && (application.getTheme() != null)) {
- return application.getTheme();
- }
- if (terminal != null) {
- return terminal.getDefaultTheme();
- }
- return null;
- }
-
- /**
- * <b>Application window only</b>. Sets the name of the theme to use for
- * this window. Changing the theme will cause the page to be reloaded.
- *
- * @param theme
- * the name of the new theme for this window or null to use the
- * application theme.
- */
- public void setTheme(String theme) {
- if (getParent() != null) {
- throw new UnsupportedOperationException(
- "Setting theme for sub-windows is not supported.");
- }
- this.theme = theme;
- requestRepaint();
- }
+ // /**
+ // * <b>Application window only</b>. Gets the theme for this window.
+ // * <p>
+ // * If the theme for this window is not explicitly set, the application
+ // theme
+ // * name is returned. If the window is not attached to an application, the
+ // * terminal default theme name is returned. If the theme name cannot be
+ // * determined, null is returned
+ // * </p>
+ // * <p>
+ // * Subwindows do not support themes and return the theme used by the
+ // parent
+ // * window
+ // * </p>
+ // *
+ // * @return the name of the theme used for the window
+ // */
+ // public String getTheme() {
+ // if (getParent() != null) {
+ // return (getParent()).getTheme();
+ // }
+ // if (theme != null) {
+ // return theme;
+ // }
+ // if ((application != null) && (application.getTheme() != null)) {
+ // return application.getTheme();
+ // }
+ // if (terminal != null) {
+ // return terminal.getDefaultTheme();
+ // }
+ // return null;
+ // }
+
+ // /**
+ // * <b>Application window only</b>. Sets the name of the theme to use for
+ // * this window. Changing the theme will cause the page to be reloaded.
+ // *
+ // * @param theme
+ // * the name of the new theme for this window or null to use the
+ // * application theme.
+ // */
+ // public void setTheme(String theme) {
+ // if (getParent() != null) {
+ // throw new UnsupportedOperationException(
+ // "Setting theme for sub-windows is not supported.");
+ // }
+ // this.theme = theme;
+ // requestRepaint();
+ // }
/*
* (non-Javadoc)
@@ -561,12 +564,12 @@ public class Window extends Panel implements URIHandler, ParameterHandler,
throws PaintException {
// Sets the window name
- final String name = getName();
- target.addAttribute("name", name == null ? "" : name);
+ // final String name = getName();
+ // target.addAttribute("name", name == null ? "" : name);
// Sets the window theme
- final String theme = getTheme();
- target.addAttribute("theme", theme == null ? "" : theme);
+ // final String theme = getTheme();
+ // target.addAttribute("theme", theme == null ? "" : theme);
if (modal) {
target.addAttribute("modal", true);
@@ -600,10 +603,10 @@ public class Window extends Panel implements URIHandler, ParameterHandler,
}
// Marks the main window
- if (getApplication() != null
- && this == getApplication().getMainWindow()) {
- target.addAttribute("main", true);
- }
+ // if (getApplication() != null
+ // && this == getApplication().getMainWindow()) {
+ // target.addAttribute("main", true);
+ // }
if (getContent() != null) {
if (getContent().getHeightUnits() == Sizeable.UNITS_PERCENTAGE) {
@@ -615,28 +618,28 @@ public class Window extends Panel implements URIHandler, ParameterHandler,
}
// Open requested resource
- synchronized (openList) {
- if (!openList.isEmpty()) {
- for (final Iterator<OpenResource> i = openList.iterator(); i
- .hasNext();) {
- (i.next()).paintContent(target);
- }
- openList.clear();
- }
- }
+ // synchronized (openList) {
+ // if (!openList.isEmpty()) {
+ // for (final Iterator<OpenResource> i = openList.iterator(); i
+ // .hasNext();) {
+ // (i.next()).paintContent(target);
+ // }
+ // openList.clear();
+ // }
+ // }
// Contents of the window panel is painted
super.paintContent(target);
- // Add executable javascripts if needed
- if (jsExecQueue != null) {
- for (String script : jsExecQueue) {
- target.startTag("execJS");
- target.addAttribute("script", script);
- target.endTag("execJS");
- }
- jsExecQueue = null;
- }
+ // // Add executable javascripts if needed
+ // if (jsExecQueue != null) {
+ // for (String script : jsExecQueue) {
+ // target.startTag("execJS");
+ // target.addAttribute("script", script);
+ // target.endTag("execJS");
+ // }
+ // jsExecQueue = null;
+ // }
// Window position
target.addVariable(this, "positionx", getPositionX());
@@ -645,53 +648,54 @@ public class Window extends Panel implements URIHandler, ParameterHandler,
// Window closing
target.addVariable(this, "close", false);
- if (getParent() == null) {
- // Paint subwindows
- for (final Iterator<Window> i = subwindows.iterator(); i.hasNext();) {
- final Window w = i.next();
- w.paint(target);
- }
- } else {
- // mark subwindows
- target.addAttribute("sub", true);
- }
-
- // Paint notifications
- if (notifications != null) {
- target.startTag("notifications");
- for (final Iterator<Notification> it = notifications.iterator(); it
- .hasNext();) {
- final Notification n = it.next();
- target.startTag("notification");
- if (n.getCaption() != null) {
- target.addAttribute("caption", n.getCaption());
- }
- if (n.getMessage() != null) {
- target.addAttribute("message", n.getMessage());
- }
- if (n.getIcon() != null) {
- target.addAttribute("icon", n.getIcon());
- }
- if (!n.isHtmlContentAllowed()) {
- target.addAttribute(
- VView.NOTIFICATION_HTML_CONTENT_NOT_ALLOWED, true);
- }
- target.addAttribute("position", n.getPosition());
- target.addAttribute("delay", n.getDelayMsec());
- if (n.getStyleName() != null) {
- target.addAttribute("style", n.getStyleName());
- }
- target.endTag("notification");
- }
- target.endTag("notifications");
- notifications = null;
- }
+ // if (getParent() == null) {
+ // // Paint subwindows
+ // for (final Iterator<Window> i = subwindows.iterator(); i.hasNext();)
+ // {
+ // final Window w = i.next();
+ // w.paint(target);
+ // }
+ // } else {
+ // // mark subwindows
+ // target.addAttribute("sub", true);
+ // }
+
+ // // Paint notifications
+ // if (notifications != null) {
+ // target.startTag("notifications");
+ // for (final Iterator<Notification> it = notifications.iterator(); it
+ // .hasNext();) {
+ // final Notification n = it.next();
+ // target.startTag("notification");
+ // if (n.getCaption() != null) {
+ // target.addAttribute("caption", n.getCaption());
+ // }
+ // if (n.getMessage() != null) {
+ // target.addAttribute("message", n.getMessage());
+ // }
+ // if (n.getIcon() != null) {
+ // target.addAttribute("icon", n.getIcon());
+ // }
+ // if (!n.isHtmlContentAllowed()) {
+ // target.addAttribute(
+ // VView.NOTIFICATION_HTML_CONTENT_NOT_ALLOWED, true);
+ // }
+ // target.addAttribute("position", n.getPosition());
+ // target.addAttribute("delay", n.getDelayMsec());
+ // if (n.getStyleName() != null) {
+ // target.addAttribute("style", n.getStyleName());
+ // }
+ // target.endTag("notification");
+ // }
+ // target.endTag("notifications");
+ // notifications = null;
+ // }
if (pendingFocus != null) {
// ensure focused component is still attached to this main window
- if (pendingFocus.getWindow() == this
- || (pendingFocus.getWindow() != null && pendingFocus
- .getWindow().getParent() == this)) {
+ if (pendingFocus.getRoot() == this
+ || (pendingFocus.getRoot() != null && pendingFocus
+ .getRoot().getParent() == this)) {
target.addAttribute("focused", pendingFocus);
}
pendingFocus = null;
@@ -713,7 +717,7 @@ public class Window extends Panel implements URIHandler, ParameterHandler,
*/
public void scrollIntoView(Component component)
throws IllegalArgumentException {
- if (component.getWindow() != this) {
+ if (component.getRoot() != this) {
throw new IllegalArgumentException(
"The component where to scroll must be inside this window.");
}
@@ -721,405 +725,421 @@ public class Window extends Panel implements URIHandler, ParameterHandler,
requestRepaint();
}
- /**
- * Opens the given resource in this window. The contents of this Window is
- * replaced by the {@code Resource}.
- *
- * @param resource
- * the resource to show in this window
- */
- public void open(Resource resource) {
- synchronized (openList) {
- if (!openList.contains(resource)) {
- openList.add(new OpenResource(resource, null, -1, -1,
- BORDER_DEFAULT));
- }
- }
- requestRepaint();
- }
+ // /**
+ // * Opens the given resource in this window. The contents of this Window is
+ // * replaced by the {@code Resource}.
+ // *
+ // * @param resource
+ // * the resource to show in this window
+ // */
+ // public void open(Resource resource) {
+ // synchronized (openList) {
+ // if (!openList.contains(resource)) {
+ // openList.add(new OpenResource(resource, null, -1, -1,
+ // BORDER_DEFAULT));
+ // }
+ // }
+ // requestRepaint();
+ // }
/* ********************************************************************* */
- /**
- * Opens the given resource in a window with the given name.
- * <p>
- * The supplied {@code windowName} is used as the target name in a
- * window.open call in the client. This means that special values such as
- * "_blank", "_self", "_top", "_parent" have special meaning. An empty or
- * <code>null</code> window name is also a special case.
- * </p>
- * <p>
- * "", null and "_self" as {@code windowName} all causes the resource to be
- * opened in the current window, replacing any old contents. For
- * downloadable content you should avoid "_self" as "_self" causes the
- * client to skip rendering of any other changes as it considers them
- * irrelevant (the page will be replaced by the resource). This can speed up
- * the opening of a resource, but it might also put the client side into an
- * inconsistent state if the window content is not completely replaced e.g.,
- * if the resource is downloaded instead of displayed in the browser.
- * </p>
- * <p>
- * "_blank" as {@code windowName} causes the resource to always be opened in
- * a new window or tab (depends on the browser and browser settings).
- * </p>
- * <p>
- * "_top" and "_parent" as {@code windowName} works as specified by the HTML
- * standard.
- * </p>
- * <p>
- * Any other {@code windowName} will open the resource in a window with that
- * name, either by opening a new window/tab in the browser or by replacing
- * the contents of an existing window with that name.
- * </p>
- *
- * @param resource
- * the resource.
- * @param windowName
- * the name of the window.
- */
- public void open(Resource resource, String windowName) {
- synchronized (openList) {
- if (!openList.contains(resource)) {
- openList.add(new OpenResource(resource, windowName, -1, -1,
- BORDER_DEFAULT));
- }
- }
- requestRepaint();
- }
-
- /**
- * Opens the given resource in a window with the given size, border and
- * name. For more information on the meaning of {@code windowName}, see
- * {@link #open(Resource, String)}.
- *
- * @param resource
- * the resource.
- * @param windowName
- * the name of the window.
- * @param width
- * the width of the window in pixels
- * @param height
- * the height of the window in pixels
- * @param border
- * the border style of the window. See {@link #BORDER_NONE
- * Window.BORDER_* constants}
- */
- public void open(Resource resource, String windowName, int width,
- int height, int border) {
- synchronized (openList) {
- if (!openList.contains(resource)) {
- openList.add(new OpenResource(resource, windowName, width,
- height, border));
- }
- }
- requestRepaint();
- }
+ // /**
+ // * Opens the given resource in a window with the given name.
+ // * <p>
+ // * The supplied {@code windowName} is used as the target name in a
+ // * window.open call in the client. This means that special values such as
+ // * "_blank", "_self", "_top", "_parent" have special meaning. An empty or
+ // * <code>null</code> window name is also a special case.
+ // * </p>
+ // * <p>
+ // * "", null and "_self" as {@code windowName} all causes the resource to
+ // be
+ // * opened in the current window, replacing any old contents. For
+ // * downloadable content you should avoid "_self" as "_self" causes the
+ // * client to skip rendering of any other changes as it considers them
+ // * irrelevant (the page will be replaced by the resource). This can speed
+ // up
+ // * the opening of a resource, but it might also put the client side into
+ // an
+ // * inconsistent state if the window content is not completely replaced
+ // e.g.,
+ // * if the resource is downloaded instead of displayed in the browser.
+ // * </p>
+ // * <p>
+ // * "_blank" as {@code windowName} causes the resource to always be opened
+ // in
+ // * a new window or tab (depends on the browser and browser settings).
+ // * </p>
+ // * <p>
+ // * "_top" and "_parent" as {@code windowName} works as specified by the
+ // HTML
+ // * standard.
+ // * </p>
+ // * <p>
+ // * Any other {@code windowName} will open the resource in a window with
+ // that
+ // * name, either by opening a new window/tab in the browser or by replacing
+ // * the contents of an existing window with that name.
+ // * </p>
+ // *
+ // * @param resource
+ // * the resource.
+ // * @param windowName
+ // * the name of the window.
+ // */
+ // public void open(Resource resource, String windowName) {
+ // synchronized (openList) {
+ // if (!openList.contains(resource)) {
+ // openList.add(new OpenResource(resource, windowName, -1, -1,
+ // BORDER_DEFAULT));
+ // }
+ // }
+ // requestRepaint();
+ // }
+
+ // /**
+ // * Opens the given resource in a window with the given size, border and
+ // * name. For more information on the meaning of {@code windowName}, see
+ // * {@link #open(Resource, String)}.
+ // *
+ // * @param resource
+ // * the resource.
+ // * @param windowName
+ // * the name of the window.
+ // * @param width
+ // * the width of the window in pixels
+ // * @param height
+ // * the height of the window in pixels
+ // * @param border
+ // * the border style of the window. See {@link #BORDER_NONE
+ // * Window.BORDER_* constants}
+ // */
+ // public void open(Resource resource, String windowName, int width,
+ // int height, int border) {
+ // synchronized (openList) {
+ // if (!openList.contains(resource)) {
+ // openList.add(new OpenResource(resource, windowName, width,
+ // height, border));
+ // }
+ // }
+ // requestRepaint();
+ // }
/* ********************************************************************* */
- /**
- * Gets the full URL of the window. The returned URL is window specific and
- * can be used to directly refer to the window.
- * <p>
- * Note! This method can not be used for portlets.
- * </p>
- *
- * @return the URL of the window or null if the window is not attached to an
- * application
- */
- public URL getURL() {
-
- if (application == null) {
- return null;
- }
-
- try {
- return new URL(application.getURL(), getName() + "/");
- } catch (final MalformedURLException e) {
- throw new RuntimeException(
- "Internal problem getting window URL, please report");
- }
- }
-
- /**
- * <b>Application window only</b>. Gets the unique name of the window. The
- * name of the window is used to uniquely identify it.
- * <p>
- * The name also determines the URL that can be used for direct access to a
- * window. All windows can be accessed through
- * {@code http://host:port/app/win} where {@code http://host:port/app} is
- * the application URL (as returned by {@link Application#getURL()} and
- * {@code win} is the window name.
- * </p>
- * <p>
- * Note! Portlets do not support direct window access through URLs.
- * </p>
- *
- * @return the Name of the Window.
- */
- public String getName() {
- return name;
- }
-
- /**
- * Returns the border style of the window.
- *
- * @see #setBorder(int)
- * @return the border style for the window
- */
- public int getBorder() {
- return border;
- }
-
- /**
- * Sets the border style for this window. Valid values are
- * {@link Window#BORDER_NONE}, {@link Window#BORDER_MINIMAL},
- * {@link Window#BORDER_DEFAULT}.
- * <p>
- * <b>Note!</b> Setting this seems to currently have no effect whatsoever on
- * the window.
- * </p>
- *
- * @param border
- * the border style to set
- */
- public void setBorder(int border) {
- this.border = border;
- }
-
- /**
- * Sets the application this window is attached to.
- *
- * <p>
- * This method is called by the framework and should not be called directly
- * from application code. {@link com.vaadin.Application#addWindow(Window)}
- * should be used to add the window to an application and
- * {@link com.vaadin.Application#removeWindow(Window)} to remove the window
- * from the application.
- * </p>
- * <p>
- * This method invokes {@link Component#attach()} and
- * {@link Component#detach()} methods when necessary.
- * <p>
- *
- * @param application
- * the application the window is attached to
- */
- public void setApplication(Application application) {
-
- // If the application is not changed, dont do nothing
- if (application == this.application) {
- return;
- }
-
- // Sends detach event if the window is connected to application
- if (this.application != null) {
- detach();
- }
-
- // Connects to new parent
- this.application = application;
-
- // Sends the attach event if connected to a window
- if (application != null) {
- attach();
- }
- }
-
- /**
- * <b>Application window only</b>. Sets the unique name of the window. The
- * name of the window is used to uniquely identify it inside the
- * application.
- * <p>
- * The name also determines the URL that can be used for direct access to a
- * window. All windows can be accessed through
- * {@code http://host:port/app/win} where {@code http://host:port/app} is
- * the application URL (as returned by {@link Application#getURL()} and
- * {@code win} is the window name.
- * </p>
- * <p>
- * This method can only be called before the window is added to an
- * application.
- * </p>
- * <p>
- * Note! Portlets do not support direct window access through URLs.
- * </p>
- *
- * @param name
- * the new name for the window or null if the application should
- * automatically assign a name to it
- * @throws IllegalStateException
- * if the window is attached to an application
- */
- public void setName(String name) throws IllegalStateException {
-
- // The name can not be changed in application
- if (getApplication() != null) {
- throw new IllegalStateException(
- "Window name can not be changed while "
- + "the window is in application");
- }
-
- this.name = name;
- }
-
- /**
- * Sets the user terminal. Used by the terminal adapter, should never be
- * called from application code.
- *
- * @param type
- * the terminal to set.
- */
- public void setTerminal(Terminal type) {
- terminal = type;
- }
-
- /**
- * Private class for storing properties related to opening resources.
- */
- private class OpenResource implements Serializable {
-
- /**
- * The resource to open
- */
- private final Resource resource;
-
- /**
- * The name of the target window
- */
- private final String name;
-
- /**
- * The width of the target window
- */
- private final int width;
-
- /**
- * The height of the target window
- */
- private final int height;
-
- /**
- * The border style of the target window
- */
- private final int border;
-
- /**
- * Creates a new open resource.
- *
- * @param resource
- * The resource to open
- * @param name
- * The name of the target window
- * @param width
- * The width of the target window
- * @param height
- * The height of the target window
- * @param border
- * The border style of the target window
- */
- private OpenResource(Resource resource, String name, int width,
- int height, int border) {
- this.resource = resource;
- this.name = name;
- this.width = width;
- this.height = height;
- this.border = border;
- }
-
- /**
- * Paints the open request. Should be painted inside the window.
- *
- * @param target
- * the paint target
- * @throws PaintException
- * if the paint operation fails
- */
- private void paintContent(PaintTarget target) throws PaintException {
- target.startTag("open");
- target.addAttribute("src", resource);
- if (name != null && name.length() > 0) {
- target.addAttribute("name", name);
- }
- if (width >= 0) {
- target.addAttribute("width", width);
- }
- if (height >= 0) {
- target.addAttribute("height", height);
- }
- switch (border) {
- case Window.BORDER_MINIMAL:
- target.addAttribute("border", "minimal");
- break;
- case Window.BORDER_NONE:
- target.addAttribute("border", "none");
- break;
- }
-
- target.endTag("open");
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.vaadin.ui.Panel#changeVariables(java.lang.Object, java.util.Map)
- */
- @Override
- public void changeVariables(Object source, Map<String, Object> variables) {
-
- boolean sizeHasChanged = false;
- // size is handled in super class, but resize events only in windows ->
- // so detect if size change occurs before super.changeVariables()
- if (variables.containsKey("height")
- && (getHeightUnits() != UNITS_PIXELS || (Integer) variables
- .get("height") != getHeight())) {
- sizeHasChanged = true;
- }
- if (variables.containsKey("width")
- && (getWidthUnits() != UNITS_PIXELS || (Integer) variables
- .get("width") != getWidth())) {
- sizeHasChanged = true;
- }
-
- super.changeVariables(source, variables);
-
- // Positioning
- final Integer positionx = (Integer) variables.get("positionx");
- if (positionx != null) {
- final int x = positionx.intValue();
- // This is information from the client so it is already using the
- // position. No need to repaint.
- setPositionX(x < 0 ? -1 : x, false);
- }
- final Integer positiony = (Integer) variables.get("positiony");
- if (positiony != null) {
- final int y = positiony.intValue();
- // This is information from the client so it is already using the
- // position. No need to repaint.
- setPositionY(y < 0 ? -1 : y, false);
- }
-
- if (isClosable()) {
- // Closing
- final Boolean close = (Boolean) variables.get("close");
- if (close != null && close.booleanValue()) {
- close();
- }
- }
-
- // fire event if size has really changed
- if (sizeHasChanged) {
- fireResize();
- }
-
- if (variables.containsKey(FocusEvent.EVENT_ID)) {
- fireEvent(new FocusEvent(this));
- } else if (variables.containsKey(BlurEvent.EVENT_ID)) {
- fireEvent(new BlurEvent(this));
- }
-
- }
+ // /**
+ // * Gets the full URL of the window. The returned URL is window specific
+ // and
+ // * can be used to directly refer to the window.
+ // * <p>
+ // * Note! This method can not be used for portlets.
+ // * </p>
+ // *
+ // * @return the URL of the window or null if the window is not attached to
+ // an
+ // * application
+ // */
+ // public URL getURL() {
+ //
+ // if (application == null) {
+ // return null;
+ // }
+ //
+ // try {
+ // return new URL(application.getURL(), getName() + "/");
+ // } catch (final MalformedURLException e) {
+ // throw new RuntimeException(
+ // "Internal problem getting window URL, please report");
+ // }
+ // }
+
+ // /**
+ // * <b>Application window only</b>. Gets the unique name of the window. The
+ // * name of the window is used to uniquely identify it.
+ // * <p>
+ // * The name also determines the URL that can be used for direct access to
+ // a
+ // * window. All windows can be accessed through
+ // * {@code http://host:port/app/win} where {@code http://host:port/app} is
+ // * the application URL (as returned by {@link Application#getURL()} and
+ // * {@code win} is the window name.
+ // * </p>
+ // * <p>
+ // * Note! Portlets do not support direct window access through URLs.
+ // * </p>
+ // *
+ // * @return the Name of the Window.
+ // */
+ // public String getName() {
+ // return name;
+ // }
+
+ // /**
+ // * Returns the border style of the window.
+ // *
+ // * @see #setBorder(int)
+ // * @return the border style for the window
+ // */
+ // public int getBorder() {
+ // return border;
+ // }
+
+ // /**
+ // * Sets the border style for this window. Valid values are
+ // * {@link Window#BORDER_NONE}, {@link Window#BORDER_MINIMAL},
+ // * {@link Window#BORDER_DEFAULT}.
+ // * <p>
+ // * <b>Note!</b> Setting this seems to currently have no effect whatsoever
+ // on
+ // * the window.
+ // * </p>
+ // *
+ // * @param border
+ // * the border style to set
+ // */
+ // public void setBorder(int border) {
+ // this.border = border;
+ // }
+
+ // /**
+ // * Sets the application this window is attached to.
+ // *
+ // * <p>
+ // * This method is called by the framework and should not be called
+ // directly
+ // * from application code. {@link com.vaadin.Application#addWindow(Window)}
+ // * should be used to add the window to an application and
+ // * {@link com.vaadin.Application#removeWindow(Window)} to remove the
+ // window
+ // * from the application.
+ // * </p>
+ // * <p>
+ // * This method invokes {@link Component#attach()} and
+ // * {@link Component#detach()} methods when necessary.
+ // * <p>
+ // *
+ // * @param application
+ // * the application the window is attached to
+ // */
+ // public void setApplication(Application application) {
+ //
+ // // If the application is not changed, dont do nothing
+ // if (application == this.application) {
+ // return;
+ // }
+ //
+ // // Sends detach event if the window is connected to application
+ // if (this.application != null) {
+ // detach();
+ // }
+ //
+ // // Connects to new parent
+ // this.application = application;
+ //
+ // // Sends the attach event if connected to a window
+ // if (application != null) {
+ // attach();
+ // }
+ // }
+
+ // /**
+ // * <b>Application window only</b>. Sets the unique name of the window. The
+ // * name of the window is used to uniquely identify it inside the
+ // * application.
+ // * <p>
+ // * The name also determines the URL that can be used for direct access to
+ // a
+ // * window. All windows can be accessed through
+ // * {@code http://host:port/app/win} where {@code http://host:port/app} is
+ // * the application URL (as returned by {@link Application#getURL()} and
+ // * {@code win} is the window name.
+ // * </p>
+ // * <p>
+ // * This method can only be called before the window is added to an
+ // * application.
+ // * </p>
+ // * <p>
+ // * Note! Portlets do not support direct window access through URLs.
+ // * </p>
+ // *
+ // * @param name
+ // * the new name for the window or null if the application should
+ // * automatically assign a name to it
+ // * @throws IllegalStateException
+ // * if the window is attached to an application
+ // */
+ // public void setName(String name) throws IllegalStateException {
+ //
+ // // The name can not be changed in application
+ // if (getApplication() != null) {
+ // throw new IllegalStateException(
+ // "Window name can not be changed while "
+ // + "the window is in application");
+ // }
+ //
+ // this.name = name;
+ // }
+
+ // /**
+ // * Sets the user terminal. Used by the terminal adapter, should never be
+ // * called from application code.
+ // *
+ // * @param type
+ // * the terminal to set.
+ // */
+ // public void setTerminal(Terminal type) {
+ // terminal = type;
+ // }
+
+ // /**
+ // * Private class for storing properties related to opening resources.
+ // */
+ // private class OpenResource implements Serializable {
+ //
+ // /**
+ // * The resource to open
+ // */
+ // private final Resource resource;
+ //
+ // /**
+ // * The name of the target window
+ // */
+ // private final String name;
+ //
+ // /**
+ // * The width of the target window
+ // */
+ // private final int width;
+ //
+ // /**
+ // * The height of the target window
+ // */
+ // private final int height;
+ //
+ // /**
+ // * The border style of the target window
+ // */
+ // private final int border;
+ //
+ // /**
+ // * Creates a new open resource.
+ // *
+ // * @param resource
+ // * The resource to open
+ // * @param name
+ // * The name of the target window
+ // * @param width
+ // * The width of the target window
+ // * @param height
+ // * The height of the target window
+ // * @param border
+ // * The border style of the target window
+ // */
+ // private OpenResource(Resource resource, String name, int width,
+ // int height, int border) {
+ // this.resource = resource;
+ // this.name = name;
+ // this.width = width;
+ // this.height = height;
+ // this.border = border;
+ // }
+ //
+ // /**
+ // * Paints the open request. Should be painted inside the window.
+ // *
+ // * @param target
+ // * the paint target
+ // * @throws PaintException
+ // * if the paint operation fails
+ // */
+ // private void paintContent(PaintTarget target) throws PaintException {
+ // target.startTag("open");
+ // target.addAttribute("src", resource);
+ // if (name != null && name.length() > 0) {
+ // target.addAttribute("name", name);
+ // }
+ // if (width >= 0) {
+ // target.addAttribute("width", width);
+ // }
+ // if (height >= 0) {
+ // target.addAttribute("height", height);
+ // }
+ // switch (border) {
+ // case Window.BORDER_MINIMAL:
+ // target.addAttribute("border", "minimal");
+ // break;
+ // case Window.BORDER_NONE:
+ // target.addAttribute("border", "none");
+ // break;
+ // }
+ //
+ // target.endTag("open");
+ // }
+ // }
+ //
+ // /*
+ // * (non-Javadoc)
+ // *
+ // * @see com.vaadin.ui.Panel#changeVariables(java.lang.Object,
+ // java.util.Map)
+ // */
+ // @Override
+ // public void changeVariables(Object source, Map<String, Object> variables)
+ // {
+ //
+ // boolean sizeHasChanged = false;
+ // // size is handled in super class, but resize events only in windows ->
+ // // so detect if size change occurs before super.changeVariables()
+ // if (variables.containsKey("height")
+ // && (getHeightUnits() != UNITS_PIXELS || (Integer) variables
+ // .get("height") != getHeight())) {
+ // sizeHasChanged = true;
+ // }
+ // if (variables.containsKey("width")
+ // && (getWidthUnits() != UNITS_PIXELS || (Integer) variables
+ // .get("width") != getWidth())) {
+ // sizeHasChanged = true;
+ // }
+ //
+ // super.changeVariables(source, variables);
+ //
+ // // Positioning
+ // final Integer positionx = (Integer) variables.get("positionx");
+ // if (positionx != null) {
+ // final int x = positionx.intValue();
+ // // This is information from the client so it is already using the
+ // // position. No need to repaint.
+ // setPositionX(x < 0 ? -1 : x, false);
+ // }
+ // final Integer positiony = (Integer) variables.get("positiony");
+ // if (positiony != null) {
+ // final int y = positiony.intValue();
+ // // This is information from the client so it is already using the
+ // // position. No need to repaint.
+ // setPositionY(y < 0 ? -1 : y, false);
+ // }
+ //
+ // if (isClosable()) {
+ // // Closing
+ // final Boolean close = (Boolean) variables.get("close");
+ // if (close != null && close.booleanValue()) {
+ // close();
+ // }
+ // }
+ //
+ // // fire event if size has really changed
+ // if (sizeHasChanged) {
+ // fireResize();
+ // }
+ //
+ // if (variables.containsKey(FocusEvent.EVENT_ID)) {
+ // fireEvent(new FocusEvent(this));
+ // } else if (variables.containsKey(BlurEvent.EVENT_ID)) {
+ // fireEvent(new BlurEvent(this));
+ // }
+ //
+ // }
/**
* Method that handles window closing (from UI).
@@ -1138,7 +1158,7 @@ public class Window extends Panel implements URIHandler, ParameterHandler,
* </p>
*/
protected void close() {
- Window parent = getParent();
+ Window parent = (Window) getParent();
if (parent == null) {
fireClose();
} else {
@@ -1411,53 +1431,54 @@ public class Window extends Panel implements URIHandler, ParameterHandler,
fireEvent(new ResizeEvent(this));
}
- private void attachWindow(Window w) {
- subwindows.add(w);
- w.setParent(this);
- requestRepaint();
- }
-
- /**
- * Adds a window inside another window.
- *
- * <p>
- * Adding windows inside another window creates "subwindows". These windows
- * should not be added to application directly and are not accessible
- * directly with any url. Addding windows implicitly sets their parents.
- * </p>
- *
- * <p>
- * Only one level of subwindows are supported. Thus you can add windows
- * inside such windows whose parent is <code>null</code>.
- * </p>
- *
- * @param window
- * @throws IllegalArgumentException
- * if a window is added inside non-application level window.
- * @throws NullPointerException
- * if the given <code>Window</code> is <code>null</code>.
- */
- public void addWindow(Window window) throws IllegalArgumentException,
- NullPointerException {
-
- if (window == null) {
- throw new NullPointerException("Argument must not be null");
- }
-
- if (window.getApplication() != null) {
- throw new IllegalArgumentException(
- "Window was already added to application"
- + " - it can not be added to another window also.");
- } else if (getParent() != null) {
- throw new IllegalArgumentException(
- "You can only add windows inside application-level windows.");
- } else if (window.subwindows.size() > 0) {
- throw new IllegalArgumentException(
- "Only one level of subwindows are supported.");
- }
-
- attachWindow(window);
- }
+ // private void attachWindow(Window w) {
+ // // subwindows.add(w);
+ // w.setParent(this);
+ // requestRepaint();
+ // }
+
+ // /**
+ // * Adds a window inside another window.
+ // *
+ // * <p>
+ // * Adding windows inside another window creates "subwindows". These
+ // windows
+ // * should not be added to application directly and are not accessible
+ // * directly with any url. Addding windows implicitly sets their parents.
+ // * </p>
+ // *
+ // * <p>
+ // * Only one level of subwindows are supported. Thus you can add windows
+ // * inside such windows whose parent is <code>null</code>.
+ // * </p>
+ // *
+ // * @param window
+ // * @throws IllegalArgumentException
+ // * if a window is added inside non-application level window.
+ // * @throws NullPointerException
+ // * if the given <code>Window</code> is <code>null</code>.
+ // */
+ // public void addWindow(Window window) throws IllegalArgumentException,
+ // NullPointerException {
+ //
+ // if (window == null) {
+ // throw new NullPointerException("Argument must not be null");
+ // }
+ //
+ // if (window.getApplication() != null) {
+ // throw new IllegalArgumentException(
+ // "Window was already added to application"
+ // + " - it can not be added to another window also.");
+ // } else if (getParent() != null) {
+ // throw new IllegalArgumentException(
+ // "You can only add windows inside application-level windows.");
+ // } else if (window.subwindows.size() > 0) {
+ // throw new IllegalArgumentException(
+ // "Only one level of subwindows are supported.");
+ // }
+ //
+ // attachWindow(window);
+ // }
/**
* Remove the given subwindow from this window.
@@ -1473,10 +1494,10 @@ public class Window extends Panel implements URIHandler, ParameterHandler,
* @return true if the subwindow was removed, false otherwise
*/
public boolean removeWindow(Window window) {
- if (!subwindows.remove(window)) {
- // Window window is not a subwindow of this window.
- return false;
- }
+ // if (!subwindows.remove(window)) {
+ // // Window window is not a subwindow of this window.
+ // return false;
+ // }
window.setParent(null);
window.fireClose();
requestRepaint();
@@ -1493,44 +1514,47 @@ public class Window extends Panel implements URIHandler, ParameterHandler,
* (depends on the order getting to dirty list. e.g. which window got
* variable changes).
*/
- private int bringToFrontSequence = 0;
-
- /**
- * If there are currently several sub windows visible, calling this method
- * makes this window topmost.
- * <p>
- * This method can only be called if this window is a sub window and
- * connected a top level window. Else an illegal state exception is thrown.
- * Also if there are modal windows and this window is not modal, and illegal
- * state exception is thrown.
- * <p>
- * <strong> Note, this API works on sub windows only. Browsers can't reorder
- * OS windows.</strong>
- */
- public void bringToFront() {
- Window parent = getParent();
- if (parent == null) {
- throw new IllegalStateException(
- "Window must be attached to parent before calling bringToFront method.");
- }
- for (Window w : parent.getChildWindows()) {
- if (w.isModal() && !isModal()) {
- throw new IllegalStateException(
- "There are modal windows currently visible, non-modal window cannot be brought to front.");
- }
- }
- bringToFront = getParent().bringToFrontSequence++;
- requestRepaint();
- }
-
- /**
- * Get the set of all child windows.
- *
- * @return Set of child windows.
- */
- public Set<Window> getChildWindows() {
- return Collections.unmodifiableSet(subwindows);
- }
+ // private int bringToFrontSequence = 0;
+
+ // /**
+ // * If there are currently several sub windows visible, calling this method
+ // * makes this window topmost.
+ // * <p>
+ // * This method can only be called if this window is a sub window and
+ // * connected a top level window. Else an illegal state exception is
+ // thrown.
+ // * Also if there are modal windows and this window is not modal, and
+ // illegal
+ // * state exception is thrown.
+ // * <p>
+ // * <strong> Note, this API works on sub windows only. Browsers can't
+ // reorder
+ // * OS windows.</strong>
+ // */
+ // public void bringToFront() {
+ // Window parent = getParent();
+ // if (parent == null) {
+ // throw new IllegalStateException(
+ // "Window must be attached to parent before calling bringToFront method.");
+ // }
+ // for (Window w : parent.getChildWindows()) {
+ // if (w.isModal() && !isModal()) {
+ // throw new IllegalStateException(
+ // "There are modal windows currently visible, non-modal window cannot be brought to front.");
+ // }
+ // }
+ // bringToFront = getParent().bringToFrontSequence++;
+ // requestRepaint();
+ // }
+
+ // /**
+ // * Get the set of all child windows.
+ // *
+ // * @return Set of child windows.
+ // */
+ // public Set<Window> getChildWindows() {
+ // return Collections.unmodifiableSet(subwindows);
+ // }
/**
* Sets sub-window modal, so that widgets behind it cannot be accessed.
@@ -1606,161 +1630,165 @@ public class Window extends Panel implements URIHandler, ParameterHandler,
requestRepaint();
}
- /**
- * Shows a notification message on the middle of the window. The message
- * automatically disappears ("humanized message").
- *
- * Care should be taken to to avoid XSS vulnerabilities as the caption is
- * rendered as html.
- *
- * @see #showNotification(com.vaadin.ui.Window.Notification)
- * @see Notification
- *
- * @param caption
- * The message
- */
- public void showNotification(String caption) {
- addNotification(new Notification(caption));
- }
-
- /**
- * Shows a notification message the window. The position and behavior of the
- * message depends on the type, which is one of the basic types defined in
- * {@link Notification}, for instance Notification.TYPE_WARNING_MESSAGE.
- *
- * Care should be taken to to avoid XSS vulnerabilities as the caption is
- * rendered as html.
- *
- * @see #showNotification(com.vaadin.ui.Window.Notification)
- * @see Notification
- *
- * @param caption
- * The message
- * @param type
- * The message type
- */
- public void showNotification(String caption, int type) {
- addNotification(new Notification(caption, type));
- }
-
- /**
- * Shows a notification consisting of a bigger caption and a smaller
- * description on the middle of the window. The message automatically
- * disappears ("humanized message").
- *
- * Care should be taken to to avoid XSS vulnerabilities as the caption and
- * description are rendered as html.
- *
- * @see #showNotification(com.vaadin.ui.Window.Notification)
- * @see Notification
- *
- * @param caption
- * The caption of the message
- * @param description
- * The message description
- *
- */
- public void showNotification(String caption, String description) {
- addNotification(new Notification(caption, description));
- }
-
- /**
- * Shows a notification consisting of a bigger caption and a smaller
- * description. The position and behavior of the message depends on the
- * type, which is one of the basic types defined in {@link Notification},
- * for instance Notification.TYPE_WARNING_MESSAGE.
- *
- * Care should be taken to to avoid XSS vulnerabilities as the caption and
- * description are rendered as html.
- *
- * @see #showNotification(com.vaadin.ui.Window.Notification)
- * @see Notification
- *
- * @param caption
- * The caption of the message
- * @param description
- * The message description
- * @param type
- * The message type
- */
- public void showNotification(String caption, String description, int type) {
- addNotification(new Notification(caption, description, type));
- }
-
- /**
- * Shows a notification consisting of a bigger caption and a smaller
- * description. The position and behavior of the message depends on the
- * type, which is one of the basic types defined in {@link Notification},
- * for instance Notification.TYPE_WARNING_MESSAGE.
- *
- * Care should be taken to avoid XSS vulnerabilities if html content is
- * allowed.
- *
- * @see #showNotification(com.vaadin.ui.Window.Notification)
- * @see Notification
- *
- * @param caption
- * The message caption
- * @param description
- * The message description
- * @param type
- * The type of message
- * @param htmlContentAllowed
- * Whether html in the caption and description should be
- * displayed as html or as plain text
- */
- public void showNotification(String caption, String description, int type,
- boolean htmlContentAllowed) {
- addNotification(new Notification(caption, description, type,
- htmlContentAllowed));
- }
-
- /**
- * Shows a notification message.
- *
- * @see Notification
- * @see #showNotification(String)
- * @see #showNotification(String, int)
- * @see #showNotification(String, String)
- * @see #showNotification(String, String, int)
- *
- * @param notification
- * The notification message to show
- */
- public void showNotification(Notification notification) {
- addNotification(notification);
- }
-
- private void addNotification(Notification notification) {
- if (notifications == null) {
- notifications = new LinkedList<Notification>();
- }
- notifications.add(notification);
- requestRepaint();
- }
-
- /**
- * This method is used by Component.Focusable objects to request focus to
- * themselves. Focus renders must be handled at window level (instead of
- * Component.Focusable) due we want the last focused component to be focused
- * in client too. Not the one that is rendered last (the case we'd get if
- * implemented in Focusable only).
- *
- * To focus component from Vaadin application, use Focusable.focus(). See
- * {@link Focusable}.
- *
- * @param focusable
- * to be focused on next paint
- */
- void setFocusedComponent(Focusable focusable) {
- if (getParent() != null) {
- // focus is handled by main windows
- (getParent()).setFocusedComponent(focusable);
- } else {
- pendingFocus = focusable;
- requestRepaint();
- }
- }
+ // /**
+ // * Shows a notification message on the middle of the window. The message
+ // * automatically disappears ("humanized message").
+ // *
+ // * Care should be taken to to avoid XSS vulnerabilities as the caption is
+ // * rendered as html.
+ // *
+ // * @see #showNotification(com.vaadin.ui.Window.Notification)
+ // * @see Notification
+ // *
+ // * @param caption
+ // * The message
+ // */
+ // public void showNotification(String caption) {
+ // addNotification(new Notification(caption));
+ // }
+
+ // /**
+ // * Shows a notification message the window. The position and behavior of
+ // the
+ // * message depends on the type, which is one of the basic types defined in
+ // * {@link Notification}, for instance Notification.TYPE_WARNING_MESSAGE.
+ // *
+ // * Care should be taken to to avoid XSS vulnerabilities as the caption is
+ // * rendered as html.
+ // *
+ // * @see #showNotification(com.vaadin.ui.Window.Notification)
+ // * @see Notification
+ // *
+ // * @param caption
+ // * The message
+ // * @param type
+ // * The message type
+ // */
+ // public void showNotification(String caption, int type) {
+ // addNotification(new Notification(caption, type));
+ // }
+
+ // /**
+ // * Shows a notification consisting of a bigger caption and a smaller
+ // * description on the middle of the window. The message automatically
+ // * disappears ("humanized message").
+ // *
+ // * Care should be taken to to avoid XSS vulnerabilities as the caption and
+ // * description are rendered as html.
+ // *
+ // * @see #showNotification(com.vaadin.ui.Window.Notification)
+ // * @see Notification
+ // *
+ // * @param caption
+ // * The caption of the message
+ // * @param description
+ // * The message description
+ // *
+ // */
+ // public void showNotification(String caption, String description) {
+ // addNotification(new Notification(caption, description));
+ // }
+
+ // /**
+ // * Shows a notification consisting of a bigger caption and a smaller
+ // * description. The position and behavior of the message depends on the
+ // * type, which is one of the basic types defined in {@link Notification},
+ // * for instance Notification.TYPE_WARNING_MESSAGE.
+ // *
+ // * Care should be taken to to avoid XSS vulnerabilities as the caption and
+ // * description are rendered as html.
+ // *
+ // * @see #showNotification(com.vaadin.ui.Window.Notification)
+ // * @see Notification
+ // *
+ // * @param caption
+ // * The caption of the message
+ // * @param description
+ // * The message description
+ // * @param type
+ // * The message type
+ // */
+ // public void showNotification(String caption, String description, int
+ // type) {
+ // addNotification(new Notification(caption, description, type));
+ // }
+
+ // /**
+ // * Shows a notification consisting of a bigger caption and a smaller
+ // * description. The position and behavior of the message depends on the
+ // * type, which is one of the basic types defined in {@link Notification},
+ // * for instance Notification.TYPE_WARNING_MESSAGE.
+ // *
+ // * Care should be taken to avoid XSS vulnerabilities if html content is
+ // * allowed.
+ // *
+ // * @see #showNotification(com.vaadin.ui.Window.Notification)
+ // * @see Notification
+ // *
+ // * @param caption
+ // * The message caption
+ // * @param description
+ // * The message description
+ // * @param type
+ // * The type of message
+ // * @param htmlContentAllowed
+ // * Whether html in the caption and description should be
+ // * displayed as html or as plain text
+ // */
+ // public void showNotification(String caption, String description, int
+ // type,
+ // boolean htmlContentAllowed) {
+ // addNotification(new Notification(caption, description, type,
+ // htmlContentAllowed));
+ // }
+
+ // /**
+ // * Shows a notification message.
+ // *
+ // * @see Notification
+ // * @see #showNotification(String)
+ // * @see #showNotification(String, int)
+ // * @see #showNotification(String, String)
+ // * @see #showNotification(String, String, int)
+ // *
+ // * @param notification
+ // * The notification message to show
+ // */
+ // public void showNotification(Notification notification) {
+ // addNotification(notification);
+ // }
+ //
+ // private void addNotification(Notification notification) {
+ // if (notifications == null) {
+ // notifications = new LinkedList<Notification>();
+ // }
+ // notifications.add(notification);
+ // requestRepaint();
+ // }
+
+ // /**
+ // * This method is used by Component.Focusable objects to request focus to
+ // * themselves. Focus renders must be handled at window level (instead of
+ // * Component.Focusable) due we want the last focused component to be
+ // focused
+ // * in client too. Not the one that is rendered last (the case we'd get if
+ // * implemented in Focusable only).
+ // *
+ // * To focus component from Vaadin application, use Focusable.focus(). See
+ // * {@link Focusable}.
+ // *
+ // * @param focusable
+ // * to be focused on next paint
+ // */
+ // void setFocusedComponent(Focusable focusable) {
+ // if (getParent() != null) {
+ // // focus is handled by main windows
+ // (getParent()).setFocusedComponent(focusable);
+ // } else {
+ // pendingFocus = focusable;
+ // requestRepaint();
+ // }
+ // }
/**
* A notification message, used to display temporary messages to the user -
@@ -2097,41 +2125,44 @@ public class Window extends Panel implements URIHandler, ParameterHandler,
}
}
- /**
- * Executes JavaScript in this window.
- *
- * <p>
- * This method allows one to inject javascript from the server to client. A
- * client implementation is not required to implement this functionality,
- * but currently all web-based clients do implement this.
- * </p>
- *
- * <p>
- * Executing javascript this way often leads to cross-browser compatibility
- * issues and regressions that are hard to resolve. Use of this method
- * should be avoided and instead it is recommended to create new widgets
- * with GWT. For more info on creating own, reusable client-side widgets in
- * Java, read the corresponding chapter in Book of Vaadin.
- * </p>
- *
- * @param script
- * JavaScript snippet that will be executed.
- */
- public void executeJavaScript(String script) {
-
- if (getParent() != null) {
- throw new UnsupportedOperationException(
- "Only application level windows can execute javascript.");
- }
-
- if (jsExecQueue == null) {
- jsExecQueue = new ArrayList<String>();
- }
-
- jsExecQueue.add(script);
-
- requestRepaint();
- }
+ // /**
+ // * Executes JavaScript in this window.
+ // *
+ // * <p>
+ // * This method allows one to inject javascript from the server to client.
+ // A
+ // * client implementation is not required to implement this functionality,
+ // * but currently all web-based clients do implement this.
+ // * </p>
+ // *
+ // * <p>
+ // * Executing javascript this way often leads to cross-browser
+ // compatibility
+ // * issues and regressions that are hard to resolve. Use of this method
+ // * should be avoided and instead it is recommended to create new widgets
+ // * with GWT. For more info on creating own, reusable client-side widgets
+ // in
+ // * Java, read the corresponding chapter in Book of Vaadin.
+ // * </p>
+ // *
+ // * @param script
+ // * JavaScript snippet that will be executed.
+ // */
+ // public void executeJavaScript(String script) {
+ //
+ // if (getParent() != null) {
+ // throw new UnsupportedOperationException(
+ // "Only application level windows can execute javascript.");
+ // }
+ //
+ // if (jsExecQueue == null) {
+ // jsExecQueue = new ArrayList<String>();
+ // }
+ //
+ // jsExecQueue.add(script);
+ //
+ // requestRepaint();
+ // }
/**
* Returns the closable status of the sub window. If a sub window is
@@ -2334,24 +2365,24 @@ public class Window extends Panel implements URIHandler, ParameterHandler,
removeListener(BlurEvent.EVENT_ID, BlurEvent.class, listener);
}
- /**
- * {@inheritDoc}
- *
- * If the window is a sub-window focusing will cause the sub-window to be
- * brought on top of other sub-windows on gain keyboard focus.
- */
- @Override
- public void focus() {
- if (getParent() != null) {
- /*
- * When focusing a sub-window it basically means it should be
- * brought to the front. Instead of just moving the keyboard focus
- * we focus the window and bring it top-most.
- */
- bringToFront();
- } else {
- super.focus();
- }
- }
+ // /**
+ // * {@inheritDoc}
+ // *
+ // * If the window is a sub-window focusing will cause the sub-window to be
+ // * brought on top of other sub-windows on gain keyboard focus.
+ // */
+ // @Override
+ // public void focus() {
+ // if (getParent() != null) {
+ // /*
+ // * When focusing a sub-window it basically means it should be
+ // * brought to the front. Instead of just moving the keyboard focus
+ // * we focus the window and bring it top-most.
+ // */
+ // bringToFront();
+ // } else {
+ // super.focus();
+ // }
+ // }
}