]> source.dussan.org Git - vaadin-framework.git/commitdiff
Added support for opening debug window from get parameters and web.xml. Also not...
authorJoonas Lehtinen <joonas.lehtinen@itmill.com>
Tue, 2 Jan 2007 13:56:52 +0000 (13:56 +0000)
committerJoonas Lehtinen <joonas.lehtinen@itmill.com>
Tue, 2 Jan 2007 13:56:52 +0000 (13:56 +0000)
svn changeset:203/svn branch:toolkit

src/com/itmill/toolkit/terminal/web/ApplicationServlet.java
src/com/itmill/toolkit/terminal/web/DirectoryThemeSource.java
src/com/itmill/toolkit/terminal/web/JarThemeSource.java
src/com/itmill/toolkit/terminal/web/ServletThemeSource.java
src/com/itmill/toolkit/terminal/web/UIDLTransformerFactory.java
src/com/itmill/toolkit/terminal/web/WebPaintTarget.java

index af16b23f350565b03cc3ab3fad17fb471b1a0774..aa0770163eaf0519b8d81dd9627b3901aed11983 100644 (file)
@@ -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);
        }
 
        /**
index aa2df317f8cafa13e8b1f93ca14250ac73bf1caa..35f75648b7eb86600f909801ebfebe286b1b65f0 100644 (file)
@@ -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);
                        }
 
index f1cf08db1a92ae6ab66caa3bd1508895d59d26ee..8ffb088921b5a6e54b10a0862f749e8f84a06160 100644 (file)
@@ -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);
                        }
 
index 2c178cc8ce2ac5638b835db07772c9ac4887092d..104bb9bea8e09862b1a502a1c00fef4104643b0d 100644 (file)
@@ -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);
                        }
 
index b0c9e2874ca159407a1101cf16a4060aeb2cfdfb..616b54a46e9e285d94bc01db98dafc8ab3f19f18 100644 (file)
@@ -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
index aba975befef23e60322be25370c84b48ae8cff17..0fa63ed1b121e239494e77e2defb873ddfcd45c6 100644 (file)
@@ -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");