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


001:        package simpleorm.simplewebapp.core;
002:
003:        import simpleorm.simplewebapp.context.WPageContextServlet;
004:        import simpleorm.simplewebapp.requestlet.WPropertiesRenderer;
005:        import simpleorm.simplewebapp.requestlet.WXmlRenderer;
006:        import simpleorm.simplewebapp.requestlet.WPageRenderer;
007:
008:        import javax.servlet.http.HttpServlet;
009:        import javax.servlet.http.HttpServletRequest;
010:        import javax.servlet.http.HttpServletResponse;
011:        import javax.servlet.ServletException;
012:        import java.io.IOException;
013:
014:        /**
015:         * Parent of all servelets.
016:         */
017:        public class WServlet extends HttpServlet {
018:
019:            public @Override
020:            void doGet(HttpServletRequest req, HttpServletResponse res)
021:                    throws ServletException, IOException {
022:                doGetPost(req, res);
023:
024:                //        System.err.println("WTestServelet DoGet uri " + req.getRequestURI()
025:                //                + " url " + req.getRequestURL()
026:                //                + " spath " + req.getServletPath() // NOT THIS ONE
027:                //                + " cpth " + req.getContextPath() + " pinfo " + req.getPathInfo()
028:                //                + " qstr " + req.getQueryString());
029:                //
030:                //
031:                //        String path = req.getRequestURI();
032:                //        String ctx = req.getContextPath();
033:                //        if ( path.startsWith(ctx) )
034:                //            path = path.substring(ctx.length());
035:                //        int end = path.lastIndexOf(".");
036:                //        //if (end >=0)
037:                //        //     path = path.substring(0, end);
038:                //        System.err.println("==> " + path);
039:
040:                // http://localhost:8080/plain_eg/foo/baz/bar.swb?xxx=yyy
041:                // <url-pattern>/foo/*</url-pattern>
042:                // WTestServelet DoGet uri /plain_eg/foo/baz/bar.swb
043:                // url http://localhost:8080/plain_eg/foo/baz/bar.swb
044:                // spath /foo cpth /plain_eg pinfo /baz/bar.swb qstr xxx=yyy
045:                // ==> /foo/baz/bar
046:
047:            }
048:
049:            public @Override
050:            void doPost(HttpServletRequest req, HttpServletResponse res)
051:                    throws ServletException, IOException {
052:                doGetPost(req, res);
053:            }
054:
055:            private static class Parsed {
056:                String ext, reqUrl;
057:                WMenuItemGlobal mitem;
058:            }
059:
060:            void doGetPost(HttpServletRequest req, HttpServletResponse res)
061:                    throws ServletException, IOException {
062:                WPage page = null;
063:                try {
064:                    try {
065:                        Parsed parsed = parseUrl(req);
066:
067:                        page = parsed.mitem.newPage(); // Beware that a lot of initialization happens here
068:
069:                        WPageStructure struct = page.getPageStructure();
070:                        page.setPageContext(new WPageContextServlet(page, req,
071:                                res));
072:
073:                        req.setAttribute("wPage", page);
074:
075:                        if (!page.getPageSecurity().isAuthorized()) {
076:                            // todo Many issues, the buffer, Realms etc.
077:                            // Does not actually work in Tomcat.
078:                            // The 401 is sent to the browser, which prompts for a login, but Tomcat then refuses to use it to set the role.
079:                            // Only works iff protections specified via web.xml.
080:                            // Adding a  "somebody" role that is always required at the web.xml level is a workarround.
081:                            // But I suspect that container level security is just useless in general.
082:                            res.setHeader("WWW-Authenticate",
083:                                    "Basic realm=\"Agile UI: tim/Password1\"");
084:                            res.sendError(res.SC_UNAUTHORIZED,
085:                                    "Cannot Access Page");
086:                            // The message in the second parameter is displayed to user on error page
087:                            return;
088:                        }
089:
090:                        struct.doMain();
091:
092:                        if (struct.getActualRedirectUrl() != null)
093:                            page.getPageContext().redirect(
094:                                    struct.getActualRedirectUrl());
095:                        else if (!struct.isSuppressRender()) {
096:                            renderResult(parsed, page, req, res);
097:                        }
098:                    } finally {
099:                        if (page != null)
100:                            page.getPageStructure().doFinalize();
101:                    }
102:                } catch (RuntimeException re) {
103:                    throw re;
104:                } catch (Exception ex) {
105:                    throw new WException(ex);
106:                }
107:            }
108:
109:            private Parsed parseUrl(HttpServletRequest req) {
110:                WServlet.Parsed parsed = new WServlet.Parsed();
111:                // if request was http://localhost:8080/plain_eg/swb/baz/bar.swb?xxx=yyy ...
112:                // <url-pattern>/swb/*</url-pattern>
113:                parsed.reqUrl = req.getRequestURL() + ""; // whole string, including http: but not ?xxx=yyy
114:                String pinfo = req.getPathInfo(); //  /baz/bar.swb -- ie. no context nor servlet prefix
115:                if (pinfo == null || "/".equals(pinfo))
116:                    throw new WException("Bad Url " + parsed.reqUrl);
117:                String menuName = pinfo.substring(1);
118:                if (menuName.indexOf("/") >= 0)
119:                    menuName = menuName.substring(0, menuName.indexOf("/"));
120:
121:                // Assumes exactly two level menus
122:                WMenuParentGlobal menus = WGlobalState.getMenus();
123:                WMenuParentGlobal menu = (WMenuParentGlobal) menus
124:                        .findSubMenuNotNull(menuName);
125:
126:                int extx = pinfo.lastIndexOf(".");
127:                if (extx < 0)
128:                    throw new WException("No Extension " + parsed.reqUrl);
129:                String base = pinfo.substring(0, extx); // eg /Simple/manuallisttest.swb.  Ie. includes menu name.
130:                parsed.ext = pinfo.substring(extx + 1);
131:
132:                parsed.mitem = menu.findBySwbUrlNotNull("/swb" + base + ".swb");
133:                return parsed;
134:            }
135:
136:            private void renderResult(Parsed parsed, WPage page,
137:                    HttpServletRequest req, HttpServletResponse res)
138:                    throws InstantiationException, IllegalAccessException {
139:                WPageRenderer pager = null;
140:                if ("swb".equals(parsed.ext)) {
141:                    pager = page.getPageItem().getRenderer().newInstance(); // normally WJspRenderer();
142:                } else if ("properties".equals(parsed.ext)) {
143:                    pager = new WPropertiesRenderer();
144:                } else if ("xml".equals(parsed.ext)) {
145:                    pager = new WXmlRenderer();
146:                } else
147:                    throw new WException("Unknown Extension " + parsed.reqUrl);
148:
149:                pager.initRequestlet(req, res, this , true);
150:                pager.setPage(page).doGetPost();
151:            }
152:
153:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.