]> source.dussan.org Git - vaadin-framework.git/commitdiff
More refactorings.
authorPetter Holmström <petter.holmstrom@itmill.com>
Wed, 4 Nov 2009 07:14:23 +0000 (07:14 +0000)
committerPetter Holmström <petter.holmstrom@itmill.com>
Wed, 4 Nov 2009 07:14:23 +0000 (07:14 +0000)
svn changeset:9609/svn branch:portlet_2.0

src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java
src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
src/com/vaadin/terminal/gwt/server/ApplicationPortlet.java
src/com/vaadin/terminal/gwt/server/Constants.java [new file with mode: 0644]
src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java
src/com/vaadin/terminal/gwt/server/PortletApplicationContext.java
src/com/vaadin/terminal/gwt/server/PortletCommunicationManager.java

index 325cda34341899396845592075ebdb4818f10659..b4157d4f12bfca5ff3f0dca79b168621b436a6e1 100644 (file)
@@ -5,7 +5,12 @@ 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.Collection;
 import java.util.Date;
 import java.util.Enumeration;
@@ -17,6 +22,7 @@ import java.util.Properties;
 import javax.portlet.ActionRequest;
 import javax.portlet.ActionResponse;
 import javax.portlet.GenericPortlet;
+import javax.portlet.MimeResponse;
 import javax.portlet.PortletConfig;
 import javax.portlet.PortletContext;
 import javax.portlet.PortletException;
@@ -32,30 +38,25 @@ import javax.portlet.ResourceURL;
 import javax.servlet.http.HttpServletResponse;
 
 import com.vaadin.Application;
+import com.vaadin.Application.SystemMessages;
 import com.vaadin.external.org.apache.commons.fileupload.portlet.PortletFileUpload;
+import com.vaadin.terminal.Terminal;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
 import com.vaadin.ui.Window;
 
-public abstract class AbstractApplicationPortlet extends GenericPortlet {
+/**
+ * TODO Document me!
+ * 
+ * @author peholmst
+ */
+public abstract class AbstractApplicationPortlet extends GenericPortlet
+        implements Constants {
 
-    // TODO Move some (all?) of the constants to a separate interface (shared with servlet)
-    
-    private static final String ERROR_NO_WINDOW_FOUND = "No window found. Did you remember to setMainWindow()?";
-
-    static final String THEME_DIRECTORY_PATH = "VAADIN/themes/";
-
-    private static final String WIDGETSET_DIRECTORY_PATH = "VAADIN/widgetsets/";
-
-    private static final String DEFAULT_WIDGETSET = "com.vaadin.terminal.gwt.DefaultWidgetSet";
-
-    private static final String DEFAULT_THEME_NAME = "reindeer";    
-    
-    private static final String URL_PARAMETER_REPAINT_ALL = "repaintAll";
-
-    private static final String URL_PARAMETER_RESTART_APPLICATION = "restartApplication";
-
-    private static final String URL_PARAMETER_CLOSE_APPLICATION = "closeApplication";
-
-    private static final int DEFAULT_BUFFER_SIZE = 32 * 1024;
+    /*
+     * TODO Big parts of this class are directly copy-pasted from
+     * AbstractApplicationServlet. On the long term, it would probably be wise
+     * to try to integrate the common parts into a shared super class.
+     */
 
     // TODO Close application when portlet window is closed
 
@@ -63,10 +64,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet {
 
     private Properties applicationProperties;
 
-    @Override
-    public void destroy() {
-        // TODO Auto-generated method stub
-    }
+    private boolean productionMode = false;
 
     @SuppressWarnings("unchecked")
     @Override
@@ -89,8 +87,119 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet {
             applicationProperties.setProperty(name, context
                     .getInitParameter(name));
         }
-        // TODO Check production mode
-        // TODO Check cross site protection
+        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
+             */
+            System.err.println(WARNING_XSRF_PROTECTION_DISABLED);
+        }
+    }
+
+    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?
+            System.err.println(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
+     */
+    private 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;
     }
 
     enum RequestType {
@@ -131,14 +240,25 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet {
         return PortletFileUpload.isMultipartContent(request);
     }
 
+    /**
+     * 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 {
-        System.out.println("AbstractApplicationPortlet.handleRequest() " + System.currentTimeMillis());
+        // System.out.println("AbstractApplicationPortlet.handleRequest() " +
+        // System.currentTimeMillis());
 
         RequestType requestType = getRequestType(request);
 
-        System.out.println("  RequestType: " + requestType);
-        System.out.println("  WindowID: " + request.getWindowID());
+        // System.out.println("  RequestType: " + requestType);
+        // System.out.println("  WindowID: " + request.getWindowID());
 
         if (requestType == RequestType.UNKNOWN) {
             System.out.println("Unknown request type");
@@ -228,9 +348,13 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet {
                 writeAjaxPage((RenderRequest) request,
                         (RenderResponse) response, window, application);
             }
+        } catch (final SessionExpired e) {
+            // Session has expired, notify user
+            handleServiceSessionExpired(request, response);
+        } catch (final GeneralSecurityException e) {
+            handleServiceSecurityException(request, response);
         } catch (final Throwable e) {
-            // TODO Handle exceptions
-            e.printStackTrace();
+            handleServiceException(request, response, application, e);
         } finally {
             // Notifies transaction end
             if (application != null) {
@@ -240,15 +364,12 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet {
         }
     }
 
-    // TODO Vaadin resources cannot be loaded, try to load other resources using
-    // the portlet context
-
     private void serveStaticResources(ResourceRequest request,
             ResourceResponse response) throws IOException, PortletException {
         final String resourceID = request.getResourceID();
         final PortletContext pc = getPortletContext();
 
-        System.out.println("Trying to load resource [" + resourceID + "]");
+//        System.out.println("Trying to load resource [" + resourceID + "]");
 
         InputStream is = pc.getResourceAsStream(resourceID);
         if (is != null) {
@@ -263,31 +384,31 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet {
                 os.write(buffer, 0, bytes);
             }
         } else {
-        System.err.println("Requested resource [" + resourceID
-                + "] could not be found");
-        response.setProperty(ResourceResponse.HTTP_STATUS_CODE, Integer
-                .toString(HttpServletResponse.SC_NOT_FOUND));
+            System.err.println("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 {
-        System.out.println("AbstractApplicationPortlet.processAction()");
+        // System.out.println("AbstractApplicationPortlet.processAction()");
         handleRequest(request, response);
     }
 
     @RenderMode(name = "VIEW")
     public void doRender(RenderRequest request, RenderResponse response)
             throws PortletException, IOException {
-        System.out.println("AbstractApplicationPortlet.render()");
+        // System.out.println("AbstractApplicationPortlet.render()");
         handleRequest(request, response);
     }
 
     @Override
     public void serveResource(ResourceRequest request, ResourceResponse response)
             throws PortletException, IOException {
-        System.out.println("AbstractApplicationPortlet.serveResource()");
+        // System.out.println("AbstractApplicationPortlet.serveResource()");
         handleRequest(request, response);
     }
 
@@ -430,19 +551,18 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet {
             RenderResponse response, Window window, Application application)
             throws IOException, MalformedURLException, PortletException {
 
-        System.out.println("AbstractApplicationPortlet.writeAjaxPage()");
+//        System.out.println("AbstractApplicationPortlet.writeAjaxPage()");
 
         response.setContentType("text/html");
         final BufferedWriter page = new BufferedWriter(new OutputStreamWriter(
                 response.getPortletOutputStream(), "UTF-8"));
-        ;
 
         // TODO The widgetset URL is currently hard-corded for LifeRay
 
-        String widgetsetURL = "/html/" + WIDGETSET_DIRECTORY_PATH + DEFAULT_WIDGETSET
-                + "/" + DEFAULT_WIDGETSET + ".nocache.js?"
+        String widgetsetURL = "/html/" + WIDGETSET_DIRECTORY_PATH
+                + DEFAULT_WIDGETSET + "/" + DEFAULT_WIDGETSET + ".nocache.js?"
                 + new Date().getTime();
-        
+
         String themeURI = "/html/" + THEME_DIRECTORY_PATH + DEFAULT_THEME_NAME;
 
         page.write("<script type=\"text/javascript\">\n");
@@ -479,26 +599,29 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet {
         page.write("\"},");
         // TODO Add system messages
         page.write("};\n</script>\n");
-        
-        //if (themeName != null) {
-            // Custom theme's stylesheet, load only once, in different
-            // script
-            // tag to be dominate styles injected by widget
-            // set
-            page.write("<script type=\"text/javascript\">\n");
-            page.write("//<![CDATA[\n");
-            page.write("if(!vaadin.themesLoaded['" + DEFAULT_THEME_NAME + "']) {\n");
-            page.write("var stylesheet = document.createElement('link');\n");
-            page.write("stylesheet.setAttribute('rel', 'stylesheet');\n");
-            page.write("stylesheet.setAttribute('type', 'text/css');\n");
-            page.write("stylesheet.setAttribute('href', '" + themeURI
-                    + "/styles.css');\n");
-            page
-                    .write("document.getElementsByTagName('head')[0].appendChild(stylesheet);\n");
-            page.write("vaadin.themesLoaded['" + DEFAULT_THEME_NAME + "'] = true;\n}\n");
-            page.write("//]]>\n</script>\n");
-        //} 
-        
+
+        // if (themeName != null) {
+        // Custom theme's stylesheet, load only once, in different
+        // script
+        // tag to be dominate styles injected by widget
+        // set
+        page.write("<script type=\"text/javascript\">\n");
+        page.write("//<![CDATA[\n");
+        page
+                .write("if(!vaadin.themesLoaded['" + DEFAULT_THEME_NAME
+                        + "']) {\n");
+        page.write("var stylesheet = document.createElement('link');\n");
+        page.write("stylesheet.setAttribute('rel', 'stylesheet');\n");
+        page.write("stylesheet.setAttribute('type', 'text/css');\n");
+        page.write("stylesheet.setAttribute('href', '" + themeURI
+                + "/styles.css');\n");
+        page
+                .write("document.getElementsByTagName('head')[0].appendChild(stylesheet);\n");
+        page.write("vaadin.themesLoaded['" + DEFAULT_THEME_NAME
+                + "'] = true;\n}\n");
+        page.write("//]]>\n</script>\n");
+        // }
+
         // TODO Warn if widgetset has not been loaded after 15 seconds
 
         /*- Add classnames;
@@ -549,4 +672,219 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet {
         // TODO Add support for custom class loader
         return getClass().getClassLoader();
     }
+
+    private boolean isOnUnloadRequest(PortletRequest request) {
+        return request.getParameter(ApplicationConnection.PARAM_UNLOADBURST) != null;
+    }
+
+    /**
+     * 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();
+    }
+
+    void handleServiceSessionExpired(PortletRequest request,
+            PortletResponse response) throws IOException, PortletException {
+
+        if (isOnUnloadRequest(request)) {
+            /*
+             * Request was an unload request (e.g. window close event) and the
+             * client expects no response if it fails.
+             */
+            return;
+        }
+
+        try {
+            Application.SystemMessages ci = getSystemMessages();
+            if (getRequestType(request) != RequestType.UIDL) {
+                // 'plain' http req - e.g. browser reload;
+                // just go ahead redirect the browser
+                if (response instanceof ActionResponse) {
+                    ((ActionResponse) response).sendRedirect(ci
+                            .getSessionExpiredURL());
+                } else {
+                    // TODO What to do if we are e.g. rendering?
+                }
+            } else {
+                /*
+                 * Session must be invalidated before criticalNotification as it
+                 * commits the response.
+                 */
+                request.getPortletSession().invalidate();
+
+                // send uidl redirect
+                criticalNotification(request, (ResourceResponse) response, ci
+                        .getSessionExpiredCaption(), ci
+                        .getSessionExpiredMessage(), null, ci
+                        .getSessionExpiredURL());
+
+            }
+        } catch (SystemMessageException ee) {
+            throw new PortletException(ee);
+        }
+
+    }
+
+    private void handleServiceSecurityException(PortletRequest request,
+            PortletResponse response) throws IOException, PortletException {
+        if (isOnUnloadRequest(request)) {
+            /*
+             * Request was an unload request (e.g. window close event) and the
+             * client expects no response if it fails.
+             */
+            return;
+        }
+
+        try {
+            Application.SystemMessages ci = getSystemMessages();
+            if (getRequestType(request) != RequestType.UIDL) {
+                // 'plain' http req - e.g. browser reload;
+                // just go ahead redirect the browser
+                if (response instanceof ActionResponse) {
+                    ((ActionResponse) response).sendRedirect(ci
+                            .getCommunicationErrorURL());
+                } else {
+                    // TODO What to do if we are e.g. rendering?
+                }
+            } else {
+                // send uidl redirect
+                criticalNotification(request, (ResourceResponse) response, ci
+                        .getCommunicationErrorCaption(), ci
+                        .getCommunicationErrorMessage(),
+                        INVALID_SECURITY_KEY_MSG, ci.getCommunicationErrorURL());
+                /*
+                 * Invalidate session. Portal integration will fail otherwise
+                 * since the session is not created by the portal.
+                 */
+                request.getPortletSession().invalidate();
+            }
+        } catch (SystemMessageException ee) {
+            throw new PortletException(ee);
+        }
+    }
+
+    private void handleServiceException(PortletRequest request,
+            PortletResponse response, Application application, Throwable e)
+            throws IOException, PortletException {
+        // 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.flush();
+        outWriter.close();
+        out.flush();
+    }
+
 }
index 9430d1d27678370cc5db785bde42417eeab15ea0..57e414652f5ab9df8abb51e4d0f539d78cce24eb 100644 (file)
@@ -57,7 +57,7 @@ import com.vaadin.ui.Window;
  */
 
 @SuppressWarnings("serial")
-public abstract class AbstractApplicationServlet extends HttpServlet {
+public abstract class AbstractApplicationServlet extends HttpServlet implements Constants {
     
     // TODO Move some (all?) of the constants to a separate interface (shared with portlet)
 
@@ -139,56 +139,8 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
 
     private Properties applicationProperties;
 
-    private static final String NOT_PRODUCTION_MODE_INFO = ""
-            + "=================================================================\n"
-            + "Vaadin is running in DEBUG MODE.\nAdd productionMode=true to web.xml "
-            + "to disable debug features.\nTo show debug window, add ?debug to "
-            + "your application URL.\n"
-            + "=================================================================";
-
-    private static final String WARNING_XSRF_PROTECTION_DISABLED = ""
-            + "===========================================================\n"
-            + "WARNING: Cross-site request forgery protection is disabled!\n"
-            + "===========================================================";
-
     private boolean productionMode = false;
 
-    private static final String URL_PARAMETER_RESTART_APPLICATION = "restartApplication";
-    private static final String URL_PARAMETER_CLOSE_APPLICATION = "closeApplication";
-    private static final String URL_PARAMETER_REPAINT_ALL = "repaintAll";
-    protected static final String URL_PARAMETER_THEME = "theme";
-
-    private static final String SERVLET_PARAMETER_DEBUG = "Debug";
-    private static final String SERVLET_PARAMETER_PRODUCTION_MODE = "productionMode";
-    static final String SERVLET_PARAMETER_DISABLE_XSRF_PROTECTION = "disable-xsrf-protection";
-
-    // Configurable parameter names
-    private static final String PARAMETER_VAADIN_RESOURCES = "Resources";
-
-    private static final int DEFAULT_BUFFER_SIZE = 32 * 1024;
-
-    private static final int MAX_BUFFER_SIZE = 64 * 1024;
-
-    private static final String AJAX_UIDL_URI = "/UIDL";
-
-    static final String THEME_DIRECTORY_PATH = "VAADIN/themes/";
-
-    private static final int DEFAULT_THEME_CACHETIME = 1000 * 60 * 60 * 24;
-
-    static final String WIDGETSET_DIRECTORY_PATH = "VAADIN/widgetsets/";
-
-    // Name of the default widget set, used if not specified in web.xml
-    private static final String DEFAULT_WIDGETSET = "com.vaadin.terminal.gwt.DefaultWidgetSet";
-
-    // Widget set parameter name
-    private static final String PARAMETER_WIDGETSET = "widgetset";
-
-    private static final String ERROR_NO_WINDOW_FOUND = "No window found. Did you remember to setMainWindow()?";
-
-    private static final String DEFAULT_THEME_NAME = "reindeer";
-
-    private static final String INVALID_SECURITY_KEY_MSG = "Invalid security key.";
-
     private String resourcePath = null;
 
     /**
index cfd5beb50b0e27635512547512da414746fee59f..71fa1eff2e3bffe62dce758301e50e5466738e66 100644 (file)
@@ -306,7 +306,7 @@ public abstract class AbstractCommunicationManager implements
                         synchronized (application) {
                             handleChangeVariablesError(application,
                                     uploadComponent, e,
-                                    new HashMap<String, Object>());
+                                    new HashMap<Object, Object>());
                         }
                     }
                 }
@@ -557,8 +557,9 @@ public abstract class AbstractCommunicationManager implements
                     }
                 });
 
-                for (final Iterator i = paintables.iterator(); i.hasNext();) {
-                    final Paintable p = (Paintable) i.next();
+                for (final Iterator<Paintable> i = paintables.iterator(); i
+                        .hasNext();) {
+                    final Paintable p = i.next();
 
                     // TODO CLEAN
                     if (p instanceof Window) {
@@ -692,8 +693,8 @@ public abstract class AbstractCommunicationManager implements
             // TODO We should only precache the layouts that are not
             // cached already (plagiate from usedPaintableTypes)
             int resourceIndex = 0;
-            for (final Iterator i = paintTarget.getUsedResources().iterator(); i
-                    .hasNext();) {
+            for (final Iterator<Object> i = paintTarget.getUsedResources()
+                    .iterator(); i.hasNext();) {
                 final String resource = (String) i.next();
                 InputStream is = null;
                 try {
@@ -827,13 +828,13 @@ public abstract class AbstractCommunicationManager implements
                     final VariableOwner owner = (VariableOwner) idPaintableMap
                             .get(variable[VAR_PID]);
                     if (owner != null && owner.isEnabled()) {
-                        Map m;
+                        Map<Object, Object> m;
                         if (nextVariable != null
                                 && variable[VAR_PID]
                                         .equals(nextVariable[VAR_PID])) {
                             // we have more than one value changes in row for
                             // one variable owner, collect em in HashMap
-                            m = new HashMap();
+                            m = new HashMap<Object, Object>();
                             m.put(variable[VAR_NAME], convertVariableValue(
                                     variable[VAR_TYPE].charAt(0),
                                     variable[VAR_VALUE]));
@@ -973,7 +974,7 @@ public abstract class AbstractCommunicationManager implements
     }
 
     private void handleChangeVariablesError(Application application,
-            Component owner, Exception e, Map m) {
+            Component owner, Exception e, Map<Object, Object> m) {
         boolean handled = false;
         ChangeVariablesErrorEvent errorEvent = new ChangeVariablesErrorEvent(
                 owner, e, m);
@@ -1429,9 +1430,9 @@ public abstract class AbstractCommunicationManager implements
             return value.equals(v);
         }
 
-        public Set entrySet() {
-            final Set s = new HashSet();
-            s.add(new Map.Entry() {
+        public Set<Entry<Object, Object>> entrySet() {
+            final Set<Entry<Object, Object>> s = new HashSet<Entry<Object, Object>>();
+            s.add(new Map.Entry<Object, Object>() {
 
                 public Object getKey() {
                     return name;
@@ -1459,8 +1460,8 @@ public abstract class AbstractCommunicationManager implements
             return false;
         }
 
-        public Set keySet() {
-            final Set s = new HashSet();
+        public Set<Object> keySet() {
+            final Set<Object> s = new HashSet<Object>();
             s.add(name);
             return s;
         }
@@ -1469,7 +1470,7 @@ public abstract class AbstractCommunicationManager implements
             throw new UnsupportedOperationException();
         }
 
-        public void putAll(Map t) {
+        public void putAll(Map<?, ?> t) {
             throw new UnsupportedOperationException();
         }
 
@@ -1481,8 +1482,8 @@ public abstract class AbstractCommunicationManager implements
             return 1;
         }
 
-        public Collection values() {
-            final LinkedList s = new LinkedList();
+        public Collection<Object> values() {
+            final LinkedList<Object> s = new LinkedList<Object>();
             s.add(value);
             return s;
 
index f363fcfddb5ca2d24c39c1d976f5a07b3a12fb43..e7e2bb3cfbcfa9fbc1e2aa7eb381ef565b06f1aa 100644 (file)
@@ -19,6 +19,10 @@ import javax.portlet.RenderResponse;
 import com.liferay.portal.kernel.util.PropsUtil;\r
 import com.vaadin.Application;\r
 \r
+/**\r
+ * @deprecated Use Portlet 2.0 class {@link ApplicationPortlet2} instead.\r
+ */\r
+@Deprecated\r
 @SuppressWarnings("serial")\r
 public class ApplicationPortlet implements Portlet, Serializable {\r
     // portlet configuration parameters\r
diff --git a/src/com/vaadin/terminal/gwt/server/Constants.java b/src/com/vaadin/terminal/gwt/server/Constants.java
new file mode 100644 (file)
index 0000000..1a91cc8
--- /dev/null
@@ -0,0 +1,59 @@
+package com.vaadin.terminal.gwt.server;
+
+/**
+ * TODO Document me!
+ * 
+ * @author peholmst
+ * 
+ */
+public interface Constants {
+
+    static final String NOT_PRODUCTION_MODE_INFO = ""
+            + "=================================================================\n"
+            + "Vaadin is running in DEBUG MODE.\nAdd productionMode=true to web.xml "
+            + "to disable debug features.\nTo show debug window, add ?debug to "
+            + "your application URL.\n"
+            + "=================================================================";
+
+    static final String WARNING_XSRF_PROTECTION_DISABLED = ""
+            + "===========================================================\n"
+            + "WARNING: Cross-site request forgery protection is disabled!\n"
+            + "===========================================================";
+    
+    static final String URL_PARAMETER_RESTART_APPLICATION = "restartApplication";
+    static final String URL_PARAMETER_CLOSE_APPLICATION = "closeApplication";
+    static final String URL_PARAMETER_REPAINT_ALL = "repaintAll";
+    static final String URL_PARAMETER_THEME = "theme";
+
+    static final String SERVLET_PARAMETER_DEBUG = "Debug";
+    static final String SERVLET_PARAMETER_PRODUCTION_MODE = "productionMode";
+    static final String SERVLET_PARAMETER_DISABLE_XSRF_PROTECTION = "disable-xsrf-protection";
+
+    // Configurable parameter names
+    static final String PARAMETER_VAADIN_RESOURCES = "Resources";
+
+    static final int DEFAULT_BUFFER_SIZE = 32 * 1024;
+
+    static final int MAX_BUFFER_SIZE = 64 * 1024;
+
+    static final String AJAX_UIDL_URI = "/UIDL";
+
+    final String THEME_DIRECTORY_PATH = "VAADIN/themes/";
+
+    static final int DEFAULT_THEME_CACHETIME = 1000 * 60 * 60 * 24;
+
+    static final String WIDGETSET_DIRECTORY_PATH = "VAADIN/widgetsets/";
+
+    // Name of the default widget set, used if not specified in web.xml
+    static final String DEFAULT_WIDGETSET = "com.vaadin.terminal.gwt.DefaultWidgetSet";
+
+    // Widget set parameter name
+    static final String PARAMETER_WIDGETSET = "widgetset";
+
+    static final String ERROR_NO_WINDOW_FOUND = "No window found. Did you remember to setMainWindow()?";
+
+    static final String DEFAULT_THEME_NAME = "reindeer";
+
+    static final String INVALID_SECURITY_KEY_MSG = "Invalid security key.";
+
+}
index d5c4ffcdd2fa9b6395181df64e4d9cd1136aa7cb..4dc87aa08a018b53ffd43c181d9cc197f810d4ae 100644 (file)
@@ -869,11 +869,11 @@ public class JsonPaintTarget implements PaintTarget {
     class JsonTag implements Serializable {
         boolean firstField = false;
 
-        Vector variables = new Vector();
+        Vector<Object> variables = new Vector<Object>();
 
-        Vector children = new Vector();
+        Vector<Object> children = new Vector<Object>();
 
-        Vector attr = new Vector();
+        Vector<Object> attr = new Vector<Object>();
 
         StringBuilder data = new StringBuilder();
 
@@ -945,7 +945,7 @@ public class JsonPaintTarget implements PaintTarget {
 
         public String getData() {
             final StringBuilder buf = new StringBuilder();
-            final Iterator it = children.iterator();
+            final Iterator<Object> it = children.iterator();
             while (it.hasNext()) {
                 buf.append(startField());
                 buf.append(it.next());
@@ -961,7 +961,7 @@ public class JsonPaintTarget implements PaintTarget {
             final StringBuilder buf = new StringBuilder();
             buf.append(startField());
             buf.append("{");
-            for (final Iterator iter = attr.iterator(); iter.hasNext();) {
+            for (final Iterator<Object> iter = attr.iterator(); iter.hasNext();) {
                 final String element = (String) iter.next();
                 buf.append(element);
                 if (iter.hasNext()) {
@@ -984,7 +984,7 @@ public class JsonPaintTarget implements PaintTarget {
             final StringBuilder buf = new StringBuilder();
             buf.append(startField());
             buf.append("\"v\":{");
-            final Iterator iter = variables.iterator();
+            final Iterator<Object> iter = variables.iterator();
             while (iter.hasNext()) {
                 final Variable element = (Variable) iter.next();
                 buf.append(element.getJsonPresentation());
index 6aabc34906f0a20ff5417cb99acb054563cf04a6..621ef1b2460be3cf132a6067601488425d7b71b3 100644 (file)
@@ -35,9 +35,10 @@ import com.vaadin.Application;
 \r
 /**\r
  * @author marc\r
- * \r
+ * @deprecated Use Portlet 2.0 class {@link PortletApplicationContext2} instead.\r
  */\r
-@SuppressWarnings("serial")\r
+@SuppressWarnings({"serial", "unchecked"})\r
+@Deprecated\r
 public class PortletApplicationContext extends WebApplicationContext implements\r
         Serializable {\r
 \r
index 5d36373fc99199ea2444e13875afc487dd59685c..f4e0853fe2b3629fa7c1ad1cc70edb5d9f6b6110 100644 (file)
@@ -138,7 +138,9 @@ public class PortletCommunicationManager extends AbstractCommunicationManager {
         public void criticalNotification(Request request, Response response,
                 String cap, String msg, String details, String outOfSyncURL)
                 throws IOException {
-            // TODO Implement me!
+            portlet.criticalNotification((PortletRequest) request
+                    .getWrappedRequest(), (MimeResponse) response
+                    .getWrappedResponse(), cap, msg, details, outOfSyncURL);
         }
 
         public String getRequestPathInfo(Request request) {