aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatti Tahvonen <matti.tahvonen@itmill.com>2009-01-09 13:55:51 +0000
committerMatti Tahvonen <matti.tahvonen@itmill.com>2009-01-09 13:55:51 +0000
commit20546f79d3e4646bfb95490c6526075668a9488a (patch)
tree5fbcea67bf20c1ba7737e2efff67a4696459b900
parent42bbeff56e6aebba793ae9c00e67b9782f2cba70 (diff)
downloadvaadin-framework-20546f79d3e4646bfb95490c6526075668a9488a.tar.gz
vaadin-framework-20546f79d3e4646bfb95490c6526075668a9488a.zip
fixes #2440. Relocated handling of uris for browser level windows form application.handleURI to servlet, fixed ticket, cleaned some code
svn changeset:6480/svn branch:trunk
-rw-r--r--src/com/itmill/toolkit/Application.java36
-rw-r--r--src/com/itmill/toolkit/terminal/gwt/client/ApplicationConfiguration.java12
-rwxr-xr-xsrc/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java1
-rw-r--r--src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java59
-rw-r--r--src/com/itmill/toolkit/tests/tickets/Ticket2440.java34
5 files changed, 89 insertions, 53 deletions
diff --git a/src/com/itmill/toolkit/Application.java b/src/com/itmill/toolkit/Application.java
index 6535c63b4a..a1ce33531c 100644
--- a/src/com/itmill/toolkit/Application.java
+++ b/src/com/itmill/toolkit/Application.java
@@ -4,7 +4,6 @@
package com.itmill.toolkit;
-import java.net.MalformedURLException;
import java.net.SocketException;
import java.net.URL;
import java.util.Collection;
@@ -699,39 +698,16 @@ public abstract class Application implements URIHandler, Terminal.ErrorListener
if (stream != null) {
stream.setCacheTime(resource.getCacheTime());
return stream;
- }
- }
-
- // Resource requests override uri handling
- return null;
- }
-
- // If the uri is in some window, handle the window uri
- if (prefix != null && prefix.length() > 0) {
- Window window = getWindow(prefix);
- if (window != null) {
- URL windowContext;
- try {
- windowContext = new URL(context, prefix + "/");
- final String windowUri = relativeUri.length() > prefix
- .length() + 1 ? relativeUri.substring(prefix
- .length() + 1) : "";
- return window.handleURI(windowContext, windowUri);
- } catch (final MalformedURLException e) {
- terminalError(new ApplicationError(e));
+ } else {
return null;
}
+ } else {
+ // Resource requests override uri handling
+ return null;
}
+ } else {
+ return null;
}
-
- // If the uri was not pointing to a window, handle the
- // uri in main window
- Window window = getMainWindow();
- if (window != null) {
- return window.handleURI(context, relativeUri);
- }
-
- return null;
}
/**
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConfiguration.java b/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConfiguration.java
index 93ce11fb69..3fe4015b9d 100644
--- a/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConfiguration.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConfiguration.java
@@ -13,6 +13,7 @@ public class ApplicationConfiguration {
private String pathInfo;
private String appUri;
private JavaScriptObject versionInfo;
+ private String windowName;
private static ArrayList<ApplicationConnection> unstartedApplications = new ArrayList<ApplicationConnection>();
private static ArrayList<ApplicationConnection> runningApplications = new ArrayList<ApplicationConnection>();
@@ -37,6 +38,14 @@ public class ApplicationConfiguration {
id = appId;
}
+ public void setInitialWindowName(String name) {
+ windowName = name;
+ }
+
+ public String getInitialWindowName() {
+ return windowName;
+ }
+
public JavaScriptObject getVersionInfoJSObject() {
return versionInfo;
}
@@ -54,6 +63,9 @@ public class ApplicationConfiguration {
this.@com.itmill.toolkit.terminal.gwt.client.ApplicationConfiguration::appUri = uri;
this.@com.itmill.toolkit.terminal.gwt.client.ApplicationConfiguration::pathInfo = jsobj.pathInfo;
this.@com.itmill.toolkit.terminal.gwt.client.ApplicationConfiguration::themeUri = jsobj.themeUri;
+ if(jsobj.windowName) {
+ this.@com.itmill.toolkit.terminal.gwt.client.ApplicationConfiguration::windowName = jsobj.windowName;
+ }
if(jsobj.versionInfo) {
this.@com.itmill.toolkit.terminal.gwt.client.ApplicationConfiguration::versionInfo = jsobj.versionInfo;
}
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java b/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java
index 19287b7f04..db7dd6dff2 100755
--- a/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java
@@ -139,6 +139,7 @@ public class ApplicationConnection {
ApplicationConfiguration cnf) {
this.widgetSet = widgetSet;
configuration = cnf;
+ windowName = configuration.getInitialWindowName();
if (isDebugMode()) {
console = new IDebugConsole(this, cnf, !isQuietDebugMode());
diff --git a/src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java b/src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java
index 498b47006e..bd577bdbd6 100644
--- a/src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java
+++ b/src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java
@@ -486,7 +486,7 @@ public class ApplicationServlet extends HttpServlet {
DownloadStream download = null;
// Handles the URI if the application is still running
- download = handleURI(application, request, response);
+ download = handleURI(application, window, request, response);
// If this is not a download request
if (download == null) {
@@ -913,6 +913,9 @@ public class ApplicationServlet extends HttpServlet {
page.write("itmill.toolkitConfigurations[\"" + appId + "\"] = {");
page.write("appUri:'" + appUrl + "', ");
page.write("pathInfo: '" + pathInfo + "', ");
+ if (window != application.getMainWindow()) {
+ page.write("windowName: '" + window.getName() + "', ");
+ }
page.write("themeUri:");
page.write(themeUri != null ? "'" + themeUri + "'" : "null");
page.write(", versionInfo : {toolkitVersion:\"");
@@ -965,6 +968,9 @@ public class ApplicationServlet extends HttpServlet {
page.write("itmill.toolkitConfigurations[\"" + appId + "\"] = {");
page.write("appUri:'" + appUrl + "', ");
page.write("pathInfo: '" + pathInfo + "', ");
+ if (window != application.getMainWindow()) {
+ page.write("windowName: '" + window.getName() + "', ");
+ }
page.write("themeUri:");
page.write(themeUri != null ? "'" + themeUri + "'" : "null");
page.write(", versionInfo : {toolkitVersion:\"");
@@ -1090,7 +1096,7 @@ public class ApplicationServlet extends HttpServlet {
* processing should be suppressed, <code>false</code> otherwise.
* @see com.itmill.toolkit.terminal.URIHandler
*/
- private DownloadStream handleURI(Application application,
+ private DownloadStream handleURI(Application application, Window window,
HttpServletRequest request, HttpServletResponse response) {
String uri = request.getPathInfo();
@@ -1098,27 +1104,56 @@ public class ApplicationServlet extends HttpServlet {
// If no URI is available
if (uri == null) {
uri = "";
- }
-
- // Removes the leading /
- while (uri.startsWith("/") && uri.length() > 0) {
- uri = uri.substring(1);
+ } 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) {
- uri = uri.replaceFirst(applicationRunnerClassname + "/", "");
+ if (uri.contains("/")) {
+ uri = uri.replaceFirst(applicationRunnerClassname + "/", "");
+ } else {
+ uri = "";
+ }
}
// Handles the uri
- DownloadStream stream = null;
try {
- stream = application.handleURI(application.getURL(), uri);
+ 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;
}
-
- return stream;
}
/**
diff --git a/src/com/itmill/toolkit/tests/tickets/Ticket2440.java b/src/com/itmill/toolkit/tests/tickets/Ticket2440.java
index 06b0aa1a64..889e02e1c4 100644
--- a/src/com/itmill/toolkit/tests/tickets/Ticket2440.java
+++ b/src/com/itmill/toolkit/tests/tickets/Ticket2440.java
@@ -5,12 +5,14 @@ import java.net.URL;
import com.itmill.toolkit.Application;
import com.itmill.toolkit.terminal.DownloadStream;
import com.itmill.toolkit.terminal.ExternalResource;
+import com.itmill.toolkit.terminal.URIHandler;
import com.itmill.toolkit.ui.Label;
import com.itmill.toolkit.ui.Link;
import com.itmill.toolkit.ui.Window;
public class Ticket2440 extends Application {
+ @Override
public void init() {
final Window main = new MainWindow();
setMainWindow(main);
@@ -19,11 +21,15 @@ public class Ticket2440 extends Application {
"Clicking the link should open a new window that should receive the URI 'msg/hello' and add that a a Label to it's ui. Currently the Label ends up in this (main) window (try reloading). Console intentionally spams during the window finding/uri handling - looks, uhm, interesting."));
}
+ @Override
public Window getWindow(String name) {
System.err.println("Looking for " + name);
if ("msg".equals(name)) {
- System.err.println(" rest uri, returning null");
- return null;
+ System.err
+ .println(" rest uri, returning new MainWindow with message from uri");
+ MainWindow restWindow = new MainWindow();
+ addWindow(restWindow);
+ return restWindow;
}
// If we already have the requested window, use it
Window w = super.getWindow(name);
@@ -38,6 +44,7 @@ public class Ticket2440 extends Application {
System.err.println(" found win");
return w;
}
+
}
private class MainWindow extends Window {
@@ -47,18 +54,23 @@ public class Ticket2440 extends Application {
addComponent(new Link("new mainwin", new ExternalResource(
Ticket2440.this.getURL() + "msg/hello"), "_blank", -1, -1,
Window.BORDER_DEFAULT));
+
+ addURIHandler(new URIHandler() {
+ public DownloadStream handleURI(URL context, String relativeUri) {
+ System.err
+ .println((getMainWindow() == getWindow() ? "mainwin: "
+ : "subwin: ")
+ + context + ", " + relativeUri);
+ addComponent(new Label(relativeUri));
+ return null;
+ }
+ });
}
+ @Override
public DownloadStream handleURI(URL context, String relativeUri) {
- System.err.println((getMainWindow() == getWindow() ? "mainwin: "
- : "subwin: ")
- + context + ", " + relativeUri);
- if (relativeUri != null && relativeUri.startsWith("msg/")) {
- addComponent(new Label(relativeUri));
- return null;
- } else {
- return super.handleURI(context, relativeUri);
- }
+ System.err.println("MainWindow.handleURI();");
+ return super.handleURI(context, relativeUri);
}
}