Source Code Cross Referenced for ReflectHandler.java in  » Web-Server » Brazil » sunlabs » brazil » handler » 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 » Web Server » Brazil » sunlabs.brazil.handler 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ReflectHandler.java
003:         *
004:         * Brazil project web application Framework,
005:         * export version: 1.1 
006:         * Copyright (c) 1998-2000 Sun Microsystems, Inc.
007:         *
008:         * Sun Public License Notice
009:         *
010:         * The contents of this file are subject to the Sun Public License Version 
011:         * 1.0 (the "License"). You may not use this file except in compliance with 
012:         * the License. A copy of the License is included as the file "license.terms",
013:         * and also available at http://www.sun.com/
014:         * 
015:         * The Original Code is from:
016:         *    Brazil project web application Framework release 1.1.
017:         * The Initial Developer of the Original Code is: suhler.
018:         * Portions created by suhler are Copyright (C) Sun Microsystems, Inc.
019:         * All Rights Reserved.
020:         * 
021:         * Contributor(s): cstevens, suhler.
022:         *
023:         * Version:  1.9
024:         * Created by suhler on 98/09/14
025:         * Last modified by suhler on 00/05/31 13:45:51
026:         */
027:
028:        package sunlabs.brazil.handler;
029:
030:        import sunlabs.brazil.server.Handler; // Interface that defines a handler
031:        import sunlabs.brazil.server.Request; // Encapulates an http request
032:        import sunlabs.brazil.server.Server; // Contains data specific to the server
033:
034:        import sunlabs.brazil.util.http.HttpUtil;
035:
036:        import java.io.IOException; // Request methods can throw this
037:
038:        /* Other classes used by this handler */
039:
040:        import java.util.Dictionary;
041:        import java.util.Enumeration;
042:        import java.util.Hashtable;
043:
044:        /**
045:         * Handler for reflecting query data back to the client.
046:         * This is the example handler to demonstrate how a typical
047:         * handler is witten.  If query data is present, it is formatted into
048:         * an HTML table, and displayed to the user.
049:         *
050:         * @author		Stephen Uhler
051:         * @version		1.9, 00/05/31
052:         */
053:
054:        public class ReflectHandler implements  Handler {
055:
056:            /**
057:             * Initialize the handler.
058:             * Handler objects are created by the server using newInstance().
059:             * The init method is called first, and exactly one for each instance,
060:             * and may be used for one-time initializations.
061:             * This handler doesn't require any.
062:             *
063:             * @param server  A reference to the server.
064:             * @param prefix  A string identifying this instance of the
065:             *                handler.  It is used by the
066:             *		  {@link sunlabs.brazil.server.ChainHandler} to
067:             *                provide the prefix to be prepended onto each
068:             *                property intended for this handler.
069:             * @return true  Only if the handler is successfully initialized.
070:             */
071:
072:            public boolean init(Server server, String prefix) {
073:                return true;
074:            }
075:
076:            /** 
077:             * Dispatch and handle the request.
078:             * This version justs reflects the HTTP header information.
079:             * It is commonly placed downstream of the
080:             * {@link CgiHandler} to allow HTML forms to be tested before
081:             * the cgi script is written.
082:             * @param request  The request object contains all of the information
083:             *                 about the request, as well as methods to manipulate
084:             *                 it.  Although multiple threads may call this method
085:             *                 connurrently, each will have its own request object.
086:             */
087:
088:            public boolean respond(Request request) throws IOException {
089:
090:                //  If there is no query information, return false, allowing
091:                //  another handler in the chain to process the request.
092:
093:                Dictionary table = request.getQueryData(null);
094:                if (table.size() == 0) {
095:                    return false;
096:                }
097:                String queryTable = formatTable(table, "Query Data");
098:
099:                String result = "<title>Request Reflector</title>"
100:                        + "<h1>Request Summary</h1>" + queryTable
101:                        + formatTable(request.headers, "Http Data")
102:                        + "<h1>Other  Stuff</h1>" + "method=<b>"
103:                        + request.method + "</b><br>" + "url=<b>" + request.url
104:                        + "</b><br>" + "version=<b>" + request.protocol
105:                        + "</b><br>"
106:                        + formatTable(request.props, "Server State");
107:                request.sendResponse(result);
108:                return true;
109:            }
110:
111:            /**
112:             * Turn a hash table into html format.  This is a static method
113:             * so it may be used in other handlers.
114:             * @param table		The table to format
115:             * @return		The html fragment
116:             */
117:
118:            public static String formatTable(Dictionary data, String caption) {
119:                StringBuffer html = new StringBuffer();
120:                html.append("<table border=1>\r\n");
121:                html.append("<caption>" + caption + "</caption>\r\n");
122:                Enumeration keys = data.keys();
123:                while (keys.hasMoreElements()) {
124:                    String key = (String) keys.nextElement();
125:                    html.append("<tr><th>" + HttpUtil.htmlEncode(key)
126:                            + "</th><td>"
127:                            + HttpUtil.htmlEncode((String) data.get(key))
128:                            + "</td></tr>\r\n");
129:                }
130:                html.append("</table>\r\n");
131:                return html.toString();
132:            }
133:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.