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


001:        package simpleorm.simplewebapp.context;
002:
003:        import simpleorm.simplewebapp.core.WException;
004:        import simpleorm.simplewebapp.core.WPage;
005:
006:        import java.net.URLEncoder;
007:        import java.io.OutputStream;
008:        import java.util.List;
009:
010:        import org.apache.commons.fileupload.FileItem;
011:
012:        /**
013:         * Peer (one to one) with WPage, Provides all the interfacing between WPage and the server.
014:         * Attempts to unify the JSP Page context with the Servlet
015:         * doGet|Post parameters.<p>
016:         *
017:         * It is always created, even if there is no page context at all (eg. if during unit tests) in which
018:         * case its methods return dummy values.<p>
019:         *
020:         * PageContext is an ugly class because it is JSP specific, and cannot
021:         * be easily used from servlets.
022:         * However, its methods are many and have a nasty relationship to
023:         * Servlet ones.<p>
024:         * <p/>
025:         * For example,  PageContext.getOut() returns a different, incompatible
026:         * class to HttpServelet.getWriter().
027:         * It is unclear what the relationship of other fields such as getAttribute
028:         * really are.<p>
029:         * <p/>
030:         * This class also provides an opportunity to mock out the web server entriely
031:         * and unit test just the WebBean.<p>
032:         * <p/>
033:         * Subtypes for JSP, Servlet, Test cases.
034:         */
035:        abstract public class WPageContext {
036:            WPage page;
037:
038:            protected WPageContext(WPage page) {
039:                this .page = page;
040:            }
041:
042:            /** Ie. the get/post parameters to the webpage,
043:             *  or artificial parameters to test cases.
044:             */
045:            abstract public String getParameter(String key);
046:
047:            /** Overriden to Redirects to a new page, typically after a successful CRUD form. */
048:            public void redirect(String url) {
049:                page.getLogger().info("Redirecting to " + url);
050:            }
051:
052:            /** Absolute URL of refering page to go back for CRUD etc. */
053:            public String getRefererUrl() {
054:                return "/";
055:            }
056:
057:            /** Add context and session id to urls iff appropriate.
058:             * (Adds Web Context iff starts with "/", adds session IDs if cookieless sessions used. */
059:            public String encodeContextUrl(String url) {
060:                return addContextToUrl(url);
061:            }
062:
063:            /** Adds context to localUrl if stars with a "/" */
064:            String addContextToUrl(String url) {
065:                if (url.startsWith("/")) {
066:                    return (getContextPath() + url);
067:                } else
068:                    return url;
069:            }
070:
071:            /** Web context, ie text after the host name.  Overriden. */
072:            String getContextPath() {
073:                return "/dummyCtx";
074:            }
075:
076:            String getCharacterEncoding() {
077:                return "UTF-8";
078:            }
079:
080:            /** returns url?name=value&name=value; encoding name and value.
081:             * Called after encodeContextUrl. */
082:            public String addParameterToUrl(String url, String name,
083:                    String value) {
084:                StringBuffer urlBuf = new StringBuffer(url);
085:                if (urlBuf.indexOf("?") == -1)
086:                    urlBuf.append("?");
087:                else
088:                    urlBuf.append("&");
089:
090:                String enc = getCharacterEncoding();
091:                try {
092:                    urlBuf.append(URLEncoder.encode(name, enc));
093:                    urlBuf.append("=");
094:                    urlBuf.append(URLEncoder.encode(value, enc));
095:                } catch (Exception ex) {
096:                    throw new WException(ex);
097:                }
098:                return urlBuf.toString();
099:            }
100:
101:            /** Overriden -- Ie. the username of the current logged in user.  */
102:            public String getRemoteUser() {
103:                return null;
104:            }
105:
106:            /** Overrriden. */
107:            public boolean isUserInRole(String role) {
108:                return true;
109:            }
110:
111:            /**
112:             * Dirty way to output to the JSP.
113:             * Note that the form is not in a good state to receive output in onProcess().
114:             * We keep the print variable hidden as it is inconsistent between JSP and Servlets.
115:             */
116:            public void println(String msg) {
117:                page.getLogger().info(msg);
118:            }
119:
120:            public OutputStream openDownloadStream(String fileName)
121:                    throws Exception {
122:                return null;
123:            }
124:
125:            public List<FileItem> parseUploadFileItems() throws Exception {
126:                return null;
127:            }
128:
129:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.