Source Code Cross Referenced for WRequestlet.java in  » Database-ORM » SimpleORM » simpleorm » simplewebapp » requestlet » 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 » Database ORM » SimpleORM » simpleorm.simplewebapp.requestlet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package simpleorm.simplewebapp.requestlet;
002:
003:        import simpleorm.simplewebapp.core.WException;
004:
005:        import javax.servlet.http.HttpServletRequest;
006:        import javax.servlet.http.HttpServletResponse;
007:        import javax.servlet.http.HttpServlet;
008:        import java.io.PrintWriter;
009:        import java.net.URLEncoder;
010:
011:        /**
012:         /**
013:         * An instance of this class is created for each call of Servlet.doGet|doPost.
014:         * Contains utility routines needed to make pages without JSPs.
015:         */
016:        public abstract class WRequestlet {
017:
018:            HttpServletRequest request;
019:            HttpServletResponse response;
020:            HttpServlet servlet;
021:            public PrintWriter out;
022:            boolean isGet = false; // else Post.
023:
024:            public <R extends WRequestlet> R initRequestlet(
025:                    HttpServletRequest request, HttpServletResponse response,
026:                    HttpServlet servlet, boolean get) {
027:                this .request = request;
028:                this .response = response;
029:                this .servlet = servlet;
030:                isGet = get;
031:                return (R) this ;
032:            }
033:
034:            public void doGetPost() {
035:                try {
036:                    out = response.getWriter();
037:                    onGetPost();
038:                    out.close();
039:                } catch (RuntimeException re) {
040:                    throw re;
041:                } catch (Throwable ex) {
042:                    throw new WException(ex);
043:                }
044:            }
045:
046:            abstract public void onGetPost() throws Throwable;
047:
048:            /**
049:             * Outputs raw HTML, does NOT quote it.
050:             */
051:            public void outRaw(String html) {
052:                out.print(html);
053:            }
054:
055:            /**
056:             * outEscaped(data, false)
057:             */
058:            public void outEscaped(String data) {
059:                outEscaped(data, false);
060:            }
061:
062:            /**
063:             * Outputs data after escaping it so that '&lt;' becomes '&amp;lt;' etc.<p>
064:             * <p/>
065:             * Converts spaces to '&amp;nbsp;' iff nbsp<p>
066:             * <p/>
067:             * Amazing that I need to write this myself!<p>
068:             *
069:             * @see #outRaw
070:             */
071:            public void outEscaped(String data, boolean nbsp) {
072:                if (data == null)
073:                    out.print("");
074:                else {
075:                    for (int dx = 0; dx < data.length(); dx++) {
076:                        char ch = data.charAt(dx);
077:                        switch (ch) {
078:                        case ' ':
079:                            out.print(nbsp ? "&nbsp;" : " ");
080:                            break;
081:                        case '<':
082:                            out.print("&lt;");
083:                            break;
084:                        case '>':
085:                            out.print("&gt;");
086:                            break;
087:                        case '\"':
088:                            out.print("&quot;");
089:                            break;
090:                        case '\'':
091:                            out.print("&#039;");
092:                            break;
093:                        case '\\':
094:                            out.print("&#092;");
095:                            break;
096:                        case '&':
097:                            out.print("&amp;");
098:                            break;
099:                        default:
100:                            out.print(ch); // Hopefully will be inlined
101:                            break;
102:                        }
103:                    }
104:                }
105:            }
106:
107:            /**
108:             * URL Encodes string in appropriate? encoding.
109:             * used for ?=value Get parameters on links
110:             */
111:            public void outURLEncoded(String data) throws Exception {
112:                out.print(URLEncoder.encode(data, "UTF-8"));
113:                //response.encode();
114:            }
115:
116:            /**
117:             * Convert a nibble to a hex character
118:             * @param	nibble	the nibble to convert.
119:             */
120:            public static char toHex(int nibble) {
121:                return hexDigit[(nibble & 0xF)];
122:            }
123:
124:            /** A table of hex digits */
125:            private static final char[] hexDigit = { '0', '1', '2', '3', '4',
126:                    '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
127:
128:            /** Mainly to include a JSP page after the main page processing. */
129:            public void includeRenderer(String url) throws Exception {
130:                servlet.getServletConfig().getServletContext()
131:                        .getRequestDispatcher(url).include(request, response);
132:                // Unclear what the difference between .forward and .inlcude actually is.
133:                // Both happen in line, immediately -- forward is not deferred until servlet exits.
134:                // forward changes request object to reflect forward's url.
135:                // inlclude prefents page status changes from inlcuded page.
136:                // Both ways exceptions thrown, but in Tomcat 5.5 converted to useless JasperException,
137:                // only useful stack trace in Tomcat logs (fixed 6.0, both forward & include)
138:            }
139:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.