Source Code Cross Referenced for AjaxServerAndClientTimeFilter.java in  » J2EE » wicket » wicket » markup » html » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » wicket » wicket.markup.html 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package wicket.markup.html;
002:
003:        import java.util.HashMap;
004:        import java.util.Map;
005:
006:        import org.apache.commons.logging.Log;
007:        import org.apache.commons.logging.LogFactory;
008:
009:        import wicket.Application;
010:        import wicket.IResponseFilter;
011:        import wicket.RequestCycle;
012:        import wicket.Session;
013:        import wicket.model.Model;
014:        import wicket.util.string.AppendingStringBuffer;
015:        import wicket.util.string.JavascriptUtils;
016:
017:        /**
018:         * This is a filter that injects javascript code to the top head portion and
019:         * after the body so that the time can me measured what the client parse time
020:         * was for this page. It also reports the total server parse/response time in
021:         * the client and logs the server response time and response size it took for a
022:         * specific response in the server log.
023:         * 
024:         * You can specify what the status text should be like this:
025:         * ServerAndClientTimeFilter.statustext=My Application, Server parsetime:
026:         * ${servertime}, Client parsetime: ${clienttime} likewise for ajax request use
027:         * ajax.ServerAndClientTimeFilter.statustext
028:         * 
029:         * @author jcompagner
030:         */
031:        public class AjaxServerAndClientTimeFilter implements  IResponseFilter {
032:            private static Log log = LogFactory
033:                    .getLog(AjaxServerAndClientTimeFilter.class);
034:
035:            /**
036:             * @see wicket.IResponseFilter#filter(java.lang.StringBuffer)
037:             */
038:            public AppendingStringBuffer filter(
039:                    AppendingStringBuffer responseBuffer) {
040:                int headIndex = responseBuffer.indexOf("<head>");
041:                int bodyIndex = responseBuffer.indexOf("</body>");
042:                int ajaxStart = responseBuffer.indexOf("<ajax-response>");
043:                int ajaxEnd = responseBuffer.indexOf("</ajax-response>");
044:                long timeTaken = System.currentTimeMillis()
045:                        - RequestCycle.get().getStartTime();
046:                if (headIndex != -1 && bodyIndex != -1) {
047:                    AppendingStringBuffer endScript = new AppendingStringBuffer(
048:                            150);
049:                    endScript.append("\n").append(
050:                            JavascriptUtils.SCRIPT_OPEN_TAG);
051:                    endScript.append("\nwindow.defaultStatus='");
052:                    endScript.append(getStatusString(timeTaken,
053:                            "ServerAndClientTimeFilter.statustext"));
054:                    endScript.append("';\n").append(
055:                            JavascriptUtils.SCRIPT_CLOSE_TAG).append("\n");
056:                    responseBuffer.insert(bodyIndex - 1, endScript);
057:                    responseBuffer
058:                            .insert(
059:                                    headIndex + 6,
060:                                    "\n"
061:                                            + JavascriptUtils.SCRIPT_OPEN_TAG
062:                                            + "\nvar clientTimeVariable = new Date().getTime();\n"
063:                                            + JavascriptUtils.SCRIPT_CLOSE_TAG
064:                                            + "\n");
065:                } else if (ajaxStart != -1 && ajaxEnd != -1) {
066:                    AppendingStringBuffer startScript = new AppendingStringBuffer(
067:                            250);
068:                    startScript
069:                            .append("<evaluate><![CDATA[window.defaultStatus='");
070:                    startScript.append(getStatusString(timeTaken,
071:                            "ajax.ServerAndClientTimeFilter.statustext"));
072:                    startScript.append("';]]></evaluate>");
073:                    responseBuffer.insert(ajaxEnd, startScript.toString());
074:                    responseBuffer
075:                            .insert(ajaxStart + 15,
076:                                    "<evaluate><![CDATA[clientTimeVariable = new Date().getTime();]]></evaluate>");
077:                }
078:                log.info(timeTaken + "ms server time taken for request "
079:                        + RequestCycle.get().getRequest().getURL()
080:                        + " response size: " + responseBuffer.length());
081:                return responseBuffer;
082:            }
083:
084:            /**
085:             * Returns a locale specific status message about the server and client
086:             * time.
087:             * 
088:             * @param timeTaken
089:             *            the server time it took
090:             * @param resourceKey
091:             *            The key for the locale specific string lookup
092:             * @return String with the status message
093:             */
094:            private String getStatusString(long timeTaken, String resourceKey) {
095:                Map map = new HashMap(4);
096:                map
097:                        .put("clienttime",
098:                                "' + (new Date().getTime() - clientTimeVariable)/1000 +  's");
099:                map.put("servertime", ((double) timeTaken) / 1000 + "s");
100:                AppendingStringBuffer defaultValue = new AppendingStringBuffer(
101:                        128);
102:                defaultValue.append("Server parsetime: ");
103:                defaultValue.append(((double) timeTaken) / 1000);
104:                defaultValue
105:                        .append("s, Client parsetime: ' + (new Date().getTime() - clientTimeVariable)/1000 +  's");
106:                String txt = Application.get().getResourceSettings()
107:                        .getLocalizer().getString(resourceKey, null,
108:                                Model.valueOf(map), Session.get().getLocale(),
109:                                Session.get().getStyle(),
110:                                defaultValue.toString());
111:                return txt;
112:            }
113:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.