]> source.dussan.org Git - vaadin-framework.git/commitdiff
relocated uri handling logic to CommunicationManager
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 9 Jan 2009 14:03:11 +0000 (14:03 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 9 Jan 2009 14:03:11 +0000 (14:03 +0000)
svn changeset:6481/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java
src/com/itmill/toolkit/terminal/gwt/server/CommunicationManager.java

index bd577bdbd6ad13591f463fa795a2db40619614f8..d442b1ed17226b1f204bf719129efa54be18a4c8 100644 (file)
@@ -486,7 +486,8 @@ public class ApplicationServlet extends HttpServlet {
             DownloadStream download = null;
 
             // Handles the URI if the application is still running
-            download = handleURI(application, window, request, response);
+            download = getApplicationManager(application).handleURI(window,
+                    request, response);
 
             // If this is not a download request
             if (download == null) {
@@ -1080,82 +1081,6 @@ public class ApplicationServlet extends HttpServlet {
         return testingToolsServerUri;
     }
 
-    /**
-     * Handles the requested URI. An application can add handlers to do special
-     * processing, when a certain URI is requested. The handlers are invoked
-     * before any windows URIs are processed and if a DownloadStream is returned
-     * it is sent to the client.
-     * 
-     * @param application
-     *            the Application owning the URI.
-     * @param request
-     *            the HTTP request instance.
-     * @param response
-     *            the HTTP response to write to.
-     * @return boolean <code>true</code> if the request was handled and further
-     *         processing should be suppressed, <code>false</code> otherwise.
-     * @see com.itmill.toolkit.terminal.URIHandler
-     */
-    private DownloadStream handleURI(Application application, Window window,
-            HttpServletRequest request, HttpServletResponse response) {
-
-        String uri = request.getPathInfo();
-
-        // If no URI is available
-        if (uri == null) {
-            uri = "";
-        } else {
-            // Removes the leading /
-            while (uri.startsWith("/") && uri.length() > 0) {
-                uri = uri.substring(1);
-            }
-        }
-
-        // If using application runner, remove package and class name
-        if (isApplicationRunnerServlet) {
-            if (uri.contains("/")) {
-                uri = uri.replaceFirst(applicationRunnerClassname + "/", "");
-            } else {
-                uri = "";
-            }
-        }
-
-        // 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 inded
-                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.terminalError(new URIHandlerErrorImpl(application, t));
-            return null;
-        }
-    }
-
     /**
      * Handles the requested URI. An application can add handlers to do special
      * processing, when a certain URI is requested. The handlers are invoked
index fcdd96dcd9301e757a025a1ea535785e1ded55fa..ced2dd593ed827a1a9ffa108def048c9fca13a8d 100644 (file)
@@ -14,6 +14,7 @@ import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.net.URL;
 import java.security.GeneralSecurityException;
 import java.text.DateFormatSymbols;
 import java.text.SimpleDateFormat;
@@ -45,6 +46,7 @@ import com.itmill.toolkit.external.org.apache.commons.fileupload.FileItemStream;
 import com.itmill.toolkit.external.org.apache.commons.fileupload.FileUploadException;
 import com.itmill.toolkit.external.org.apache.commons.fileupload.ProgressListener;
 import com.itmill.toolkit.external.org.apache.commons.fileupload.servlet.ServletFileUpload;
+import com.itmill.toolkit.terminal.DownloadStream;
 import com.itmill.toolkit.terminal.PaintException;
 import com.itmill.toolkit.terminal.Paintable;
 import com.itmill.toolkit.terminal.URIHandler;
@@ -1376,4 +1378,83 @@ public class CommunicationManager implements Paintable.RepaintRequestListener {
         }
 
     }
+
+    /**
+     * Handles the requested URI. An application can add handlers to do special
+     * processing, when a certain URI is requested. The handlers are invoked
+     * before any windows URIs are processed and if a DownloadStream is returned
+     * it is sent to the client.
+     * 
+     * @param application
+     *            the Application owning the URI.
+     * @param request
+     *            the HTTP request instance.
+     * @param response
+     *            the HTTP response to write to.
+     * @return boolean <code>true</code> if the request was handled and further
+     *         processing should be suppressed, <code>false</code> otherwise.
+     * @see com.itmill.toolkit.terminal.URIHandler
+     */
+    DownloadStream handleURI(Window window, HttpServletRequest request,
+            HttpServletResponse response) {
+
+        String uri = request.getPathInfo();
+
+        // If no URI is available
+        if (uri == null) {
+            uri = "";
+        } else {
+            // Removes the leading /
+            while (uri.startsWith("/") && uri.length() > 0) {
+                uri = uri.substring(1);
+            }
+        }
+
+        // If using application runner, remove package and class name
+        if (applicationServlet.isApplicationRunnerServlet) {
+            if (uri.contains("/")) {
+                uri = uri
+                        .replaceFirst(
+                                applicationServlet.applicationRunnerClassname
+                                        + "/", "");
+            } else {
+                uri = "";
+            }
+        }
+
+        // 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 inded
+                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.terminalError(new URIHandlerErrorImpl(application, t));
+            return null;
+        }
+    }
 }