aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJoonas Lehtinen <joonas.lehtinen@itmill.com>2007-01-02 13:56:52 +0000
committerJoonas Lehtinen <joonas.lehtinen@itmill.com>2007-01-02 13:56:52 +0000
commita9a3e978445bf94e2b5efa861bb50dedfb281624 (patch)
treef305565a2f571d70e4d4240e1bce8581247a95b7 /src
parent6d22924bb2645030d2a8993415b86c7f7db5e8cf (diff)
downloadvaadin-framework-a9a3e978445bf94e2b5efa861bb50dedfb281624.tar.gz
vaadin-framework-a9a3e978445bf94e2b5efa861bb50dedfb281624.zip
Added support for opening debug window from get parameters and web.xml. Also not it is possible to disable debug-mode alltogether from web.xml.
svn changeset:203/svn branch:toolkit
Diffstat (limited to 'src')
-rw-r--r--src/com/itmill/toolkit/terminal/web/ApplicationServlet.java105
-rw-r--r--src/com/itmill/toolkit/terminal/web/DirectoryThemeSource.java6
-rw-r--r--src/com/itmill/toolkit/terminal/web/JarThemeSource.java6
-rw-r--r--src/com/itmill/toolkit/terminal/web/ServletThemeSource.java4
-rw-r--r--src/com/itmill/toolkit/terminal/web/UIDLTransformerFactory.java12
-rw-r--r--src/com/itmill/toolkit/terminal/web/WebPaintTarget.java4
6 files changed, 79 insertions, 58 deletions
diff --git a/src/com/itmill/toolkit/terminal/web/ApplicationServlet.java b/src/com/itmill/toolkit/terminal/web/ApplicationServlet.java
index af16b23f35..aa0770163e 100644
--- a/src/com/itmill/toolkit/terminal/web/ApplicationServlet.java
+++ b/src/com/itmill/toolkit/terminal/web/ApplicationServlet.java
@@ -193,7 +193,7 @@ public class ApplicationServlet extends HttpServlet implements
private String resourcePath = null;
- private boolean debugMode = false;
+ private String debugMode = "";
private int maxConcurrentTransformers;
@@ -256,9 +256,14 @@ public class ApplicationServlet extends HttpServlet implements
}
// Get the debug window parameter
- String debug = getApplicationOrSystemProperty(PARAMETER_DEBUG, "false");
+ String debug = getApplicationOrSystemProperty(PARAMETER_DEBUG, "")
+ .toLowerCase();
// Enable application specific debug
- this.debugMode = debug.equals("true");
+ if (!"".equals(debug) && !"true".equals(debug)
+ && !"false".equals(debug))
+ throw new ServletException(
+ "If debug parameter is given for an application, it must be 'true' or 'false'");
+ this.debugMode = debug;
// Get the maximum number of simultaneous transformers
this.maxConcurrentTransformers = Integer
@@ -403,7 +408,7 @@ public class ApplicationServlet extends HttpServlet implements
while ((line = reader.readLine()) != null) {
sourcePaths.add(THEME_DIRECTORY_PATH + line.trim());
}
- if (this.isDebugMode()) {
+ if (this.isDebugMode(null)) {
Log.debug("Listed " + sourcePaths.size() + " themes in "
+ THEME_LISTING_FILE + ". Loading " + sourcePaths);
}
@@ -414,7 +419,7 @@ public class ApplicationServlet extends HttpServlet implements
// If no file was found or it was empty,
// try to add themes filesystem directory if it is accessible
if (sourcePaths.size() <= 0) {
- if (this.isDebugMode()) {
+ if (this.isDebugMode(null)) {
Log.debug("No themes listed in " + THEME_LISTING_FILE
+ ". Trying to read the content of directory "
+ THEME_DIRECTORY_PATH);
@@ -572,7 +577,8 @@ public class ApplicationServlet extends HttpServlet implements
// Find the window within the application
Window window = null;
if (application.isRunning())
- window = getApplicationWindow(request, application);
+ window = getApplicationWindow(request, application,
+ unhandledParameters);
// Handle the unhandled parameters if the application is
// still running
@@ -639,7 +645,11 @@ public class ApplicationServlet extends HttpServlet implements
// rendered
String renderingMode = theme.getPreferredMode(terminalType,
themeSource);
- if (Theme.MODE_UIDL.equals(renderingMode)) {
+ if (unhandledParameters.get("renderingMode") != null)
+ renderingMode = (String) ((Object[]) unhandledParameters
+ .get("renderingMode"))[0];
+ if (Theme.MODE_UIDL.equals(renderingMode)
+ && !(window instanceof DebugWindow)) {
response.setContentType("text/html");
BufferedWriter page = new BufferedWriter(
new OutputStreamWriter(out));
@@ -659,7 +669,7 @@ public class ApplicationServlet extends HttpServlet implements
t = themeSource.getThemeByName(parentName);
themes.add(t);
}
- for (int k=themes.size()-1; k>=0; k--) {
+ for (int k = themes.size() - 1; k >= 0; k--) {
t = (Theme) themes.get(k);
Collection files = t.getFileNames(terminalType,
Theme.MODE_UIDL);
@@ -698,29 +708,32 @@ public class ApplicationServlet extends HttpServlet implements
.write("var client = new ITMillToolkitClient("
+ "document.getElementById('ajax-window'),"
+ "\""
- + appUrl + (appUrl.endsWith("/") ? "" : "/")
+ + appUrl
+ + (appUrl.endsWith("/") ? "" : "/")
+ "UIDL/"
+ "\",\""
- + resourcePath + ((Theme)themes.get(themes.size()-1)).getName() + "/"
-
- + "client/\",document.getElementById('ajax-wait'));\n");
+ + resourcePath
+ + ((Theme) themes
+ .get(themes.size() - 1))
+ .getName()
+ + "/"
- // TODO Should we also show debug information?
- /*
- * var debug =
- * document.location.href.split("debug=")[1]; if (debug &&
- * debug.split("&")[0] == "1") client.debugEnabled =
- * true;
- */
+ + "client/\",document.getElementById('ajax-wait'));\n");
- for (int k=themes.size()-1; k>=0; k--) {
+ for (int k = themes.size() - 1; k >= 0; k--) {
t = (Theme) themes.get(k);
String themeObjName = t.getName() + "Theme";
- themeObjName = themeObjName.substring(0,1).toUpperCase() + themeObjName.substring(1);
- page
- .write(" (new "+themeObjName+"(\"" + resourcePath + ((Theme)themes.get(k)).getName() + "/\")).registerTo(client);\n");
+ themeObjName = themeObjName.substring(0, 1)
+ .toUpperCase()
+ + themeObjName.substring(1);
+ page.write(" (new " + themeObjName + "(\""
+ + resourcePath
+ + ((Theme) themes.get(k)).getName()
+ + "/\")).registerTo(client);\n");
}
-
+
+ if (isDebugMode(unhandledParameters))
+ page.write("client.debugEnabled =true;\n");
page.write("client.start();\n");
page.write("</script>\n");
@@ -732,7 +745,7 @@ public class ApplicationServlet extends HttpServlet implements
}
// If other than XSLT or UIDL mode is requested
- if (!Theme.MODE_XSLT.equals(renderingMode)) {
+ if (!Theme.MODE_XSLT.equals(renderingMode) && !(window instanceof DebugWindow)) {
// TODO More informal message should be given is browser
// is not supported
response.setContentType("text/html");
@@ -1418,7 +1431,7 @@ public class ApplicationServlet extends HttpServlet implements
* @return Window mathing the given URI or null if not found.
*/
private Window getApplicationWindow(HttpServletRequest request,
- Application application) throws ServletException {
+ Application application, Map params) throws ServletException {
Window window = null;
@@ -1464,18 +1477,25 @@ public class ApplicationServlet extends HttpServlet implements
}
// Create and open new debug window for application if requested
- if (this.debugMode
- && application.getWindow(DebugWindow.WINDOW_NAME) == null)
- try {
- DebugWindow debugWindow = new DebugWindow(application, request
- .getSession(false), this);
- debugWindow.setWidth(370);
- debugWindow.setHeight(480);
- application.addWindow(debugWindow);
- } catch (Exception e) {
- throw new ServletException(
- "Failed to create debug window for application", e);
- }
+ Window debugWindow = application.getWindow(DebugWindow.WINDOW_NAME);
+ if (debugWindow == null) {
+ if (isDebugMode(params))
+ try {
+ debugWindow = new DebugWindow(application, request
+ .getSession(false), this);
+ debugWindow.setWidth(370);
+ debugWindow.setHeight(480);
+ application.addWindow(debugWindow);
+ } catch (Exception e) {
+ throw new ServletException(
+ "Failed to create debug window for application", e);
+ }
+ } else if (window != debugWindow) {
+ if (isDebugMode(params))
+ debugWindow.requestRepaint();
+ else
+ application.removeWindow(debugWindow);
+ }
return window;
}
@@ -1502,8 +1522,13 @@ public class ApplicationServlet extends HttpServlet implements
*
* @return Debug mode
*/
- public boolean isDebugMode() {
- return debugMode;
+ public boolean isDebugMode(Map parameters) {
+ if (parameters != null) {
+ Object[] debug = (Object[]) parameters.get("debug");
+ if (debug != null && !"false".equals(debug[0].toString()))
+ return true;
+ }
+ return "true".equals(debugMode);
}
/**
diff --git a/src/com/itmill/toolkit/terminal/web/DirectoryThemeSource.java b/src/com/itmill/toolkit/terminal/web/DirectoryThemeSource.java
index aa2df317f8..35f75648b7 100644
--- a/src/com/itmill/toolkit/terminal/web/DirectoryThemeSource.java
+++ b/src/com/itmill/toolkit/terminal/web/DirectoryThemeSource.java
@@ -80,7 +80,7 @@ public class DirectoryThemeSource implements ThemeSource {
}
// Debug info
- if (webAdapterServlet.isDebugMode()) {
+ if (webAdapterServlet.isDebugMode(null)) {
Log.info("Added DirectoryThemeSource: " + this.path);
}
@@ -99,7 +99,7 @@ public class DirectoryThemeSource implements ThemeSource {
}
if (this.subdirs.isEmpty()) {
- if (webAdapterServlet.isDebugMode()) {
+ if (webAdapterServlet.isDebugMode(null)) {
Log.debug(
"DirectoryThemeSource: Ignoring empty directory: "
+ path);
@@ -119,7 +119,7 @@ public class DirectoryThemeSource implements ThemeSource {
// return XSL from this theme
if (this.theme != null) {
- if (webAdapterServlet.isDebugMode()) {
+ if (webAdapterServlet.isDebugMode(null)) {
Log.info("DirectoryThemeSource: Loading XSL from: " + theme);
}
diff --git a/src/com/itmill/toolkit/terminal/web/JarThemeSource.java b/src/com/itmill/toolkit/terminal/web/JarThemeSource.java
index f1cf08db1a..8ffb088921 100644
--- a/src/com/itmill/toolkit/terminal/web/JarThemeSource.java
+++ b/src/com/itmill/toolkit/terminal/web/JarThemeSource.java
@@ -112,7 +112,7 @@ public class JarThemeSource implements ThemeSource {
}
// Debug info
- if (webAdapterServlet.isDebugMode()) {
+ if (webAdapterServlet.isDebugMode(null)) {
Log.debug("Added JarThemeSource: " + this.file + ":"
+ this.path);
}
@@ -133,7 +133,7 @@ public class JarThemeSource implements ThemeSource {
}
if (this.subdirs.isEmpty()) {
- if (webAdapterServlet.isDebugMode()) {
+ if (webAdapterServlet.isDebugMode(null)) {
Log.info("JarThemeSource: Ignoring empty JAR path: "
+ this.file + " path: " + this.path);
}
@@ -152,7 +152,7 @@ public class JarThemeSource implements ThemeSource {
// return XSL from this theme
if (this.theme != null) {
- if (webAdapterServlet.isDebugMode()) {
+ if (webAdapterServlet.isDebugMode(null)) {
Log.info("JarThemeSource: Loading XSL from: " + theme);
}
diff --git a/src/com/itmill/toolkit/terminal/web/ServletThemeSource.java b/src/com/itmill/toolkit/terminal/web/ServletThemeSource.java
index 2c178cc8ce..104bb9bea8 100644
--- a/src/com/itmill/toolkit/terminal/web/ServletThemeSource.java
+++ b/src/com/itmill/toolkit/terminal/web/ServletThemeSource.java
@@ -111,7 +111,7 @@ public class ServletThemeSource implements ThemeSource {
entry.close();
// Debug info
- if (webAdapterServlet.isDebugMode()) {
+ if (webAdapterServlet.isDebugMode(null)) {
Log.debug("Added ServletThemeSource: " + this.path);
}
@@ -137,7 +137,7 @@ public class ServletThemeSource implements ThemeSource {
// return XSL from this theme
if (this.theme != null) {
- if (webAdapterServlet.isDebugMode()) {
+ if (webAdapterServlet.isDebugMode(null)) {
Log.info("ServletThemeSource: Loading theme: " + theme);
}
diff --git a/src/com/itmill/toolkit/terminal/web/UIDLTransformerFactory.java b/src/com/itmill/toolkit/terminal/web/UIDLTransformerFactory.java
index b0c9e2874c..616b54a46e 100644
--- a/src/com/itmill/toolkit/terminal/web/UIDLTransformerFactory.java
+++ b/src/com/itmill/toolkit/terminal/web/UIDLTransformerFactory.java
@@ -131,7 +131,7 @@ public class UIDLTransformerFactory {
// list if necessary
long lastmod = this.themeSource.getModificationTime();
if (list != null && this.themeSourceModificationTime < lastmod) {
- if (webAdapterServlet.isDebugMode()) {
+ if (webAdapterServlet.isDebugMode(null)) {
Log.info(
"Theme source modified since "
+ new Date(this.themeSourceModificationTime)
@@ -151,7 +151,7 @@ public class UIDLTransformerFactory {
if (list != null && !list.isEmpty()) {
// If available, return the first available transformer
t = (UIDLTransformer) list.removeFirst();
- if (webAdapterServlet.isDebugMode()) {
+ if (webAdapterServlet.isDebugMode(null)) {
Log.info("Reserved existing transformer: " + type);
}
} else {
@@ -160,7 +160,7 @@ public class UIDLTransformerFactory {
// spool when they are released.
t = new UIDLTransformer(type, themeSource, webAdapterServlet);
transformerCount++;
- if (webAdapterServlet.isDebugMode()) {
+ if (webAdapterServlet.isDebugMode(null)) {
Log.info(
"Created new transformer ("
+ transformerCount
@@ -172,7 +172,7 @@ public class UIDLTransformerFactory {
if (list == null) {
list = new TransformerList();
this.transformerSpool.put(type, list);
- if (webAdapterServlet.isDebugMode()) {
+ if (webAdapterServlet.isDebugMode(null)) {
Log.info("Created new type: " + type);
}
}
@@ -198,7 +198,7 @@ public class UIDLTransformerFactory {
transformer.getTransformerType());
if (list != null) {
list.add(transformer);
- if (webAdapterServlet.isDebugMode()) {
+ if (webAdapterServlet.isDebugMode(null)) {
Log.info(
"Released transformer: "
+ transformer.getTransformerType()
@@ -256,7 +256,7 @@ public class UIDLTransformerFactory {
if (l != null) {
if (l.lastUsed > 0
&& l.lastUsed < (currentTime - this.cacheTime)) {
- if (webAdapterServlet.isDebugMode()) {
+ if (webAdapterServlet.isDebugMode(null)) {
Log.info(
"Removed transformer: "
+ type
diff --git a/src/com/itmill/toolkit/terminal/web/WebPaintTarget.java b/src/com/itmill/toolkit/terminal/web/WebPaintTarget.java
index aba975befe..0fa63ed1b1 100644
--- a/src/com/itmill/toolkit/terminal/web/WebPaintTarget.java
+++ b/src/com/itmill/toolkit/terminal/web/WebPaintTarget.java
@@ -101,10 +101,6 @@ public class WebPaintTarget implements PaintTarget {
//Add document declaration
this.print(UIDL_XML_DECL + "\n\n");
- // In debug mode add DOCTYPE element
- if (webAdapterServlet.isDebugMode()) {
- //this.print(UIDL_DOCTYPE_DECL + "\n\n");
- }
// Add UIDL start tag and its attributes
this.startTag("uidl");