Source Code Cross Referenced for Context.java in  » Sevlet-Container » jetty-modules » org » mortbay » jetty » servlet » 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 » Sevlet Container » jetty modules » org.mortbay.jetty.servlet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //========================================================================
002:        //$Id: WebAppContext.java,v 1.5 2005/11/16 22:02:45 gregwilkins Exp $
003:        //Copyright 2004-2006 Mort Bay Consulting Pty. Ltd.
004:        //------------------------------------------------------------------------
005:        //Licensed under the Apache License, Version 2.0 (the "License");
006:        //you may not use this file except in compliance with the License.
007:        //You may obtain a copy of the License at 
008:        //http://www.apache.org/licenses/LICENSE-2.0
009:        //Unless required by applicable law or agreed to in writing, software
010:        //distributed under the License is distributed on an "AS IS" BASIS,
011:        //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012:        //See the License for the specific language governing permissions and
013:        //limitations under the License.
014:        //========================================================================
015:
016:        package org.mortbay.jetty.servlet;
017:
018:        import javax.servlet.RequestDispatcher;
019:        import javax.servlet.ServletContext;
020:
021:        import org.mortbay.jetty.HandlerContainer;
022:        import org.mortbay.jetty.handler.ContextHandler;
023:        import org.mortbay.jetty.handler.ErrorHandler;
024:        import org.mortbay.jetty.security.SecurityHandler;
025:        import org.mortbay.log.Log;
026:        import org.mortbay.util.URIUtil;
027:
028:        /* ------------------------------------------------------------ */
029:        /** Servlet Context.
030:         * This conveniance extention to the ContextHandler allows for
031:         * simple construction of a context with ServletHandler and optionally
032:         * session and security handlers, et.<pre>
033:         *   new ServletContext("/context",Context.SESSIONS|Context.NO_SECURITY);
034:         * </pre>
035:         * <p/>
036:         * This class should have been called ServletContext, but this would have
037:         * cause confusion with {@link ServletContext}.
038:         */
039:        public class Context extends ContextHandler {
040:            public final static int SESSIONS = 1;
041:            public final static int SECURITY = 2;
042:            public final static int NO_SESSIONS = 0;
043:            public final static int NO_SECURITY = 0;
044:
045:            protected SecurityHandler _securityHandler;
046:            protected ServletHandler _servletHandler;
047:            protected SessionHandler _sessionHandler;
048:
049:            /* ------------------------------------------------------------ */
050:            public Context() {
051:                this (null, null, null, null, null);
052:            }
053:
054:            /* ------------------------------------------------------------ */
055:            public Context(int options) {
056:                this (null, null, options);
057:            }
058:
059:            /* ------------------------------------------------------------ */
060:            public Context(HandlerContainer parent, String contextPath) {
061:                this (parent, null, null, null, null);
062:                setContextPath(contextPath);
063:            }
064:
065:            /* ------------------------------------------------------------ */
066:            public Context(HandlerContainer parent, String contextPath,
067:                    int options) {
068:                this (parent, ((options & SESSIONS) != 0) ? new SessionHandler()
069:                        : null,
070:                        ((options & SECURITY) != 0) ? new SecurityHandler()
071:                                : null, null, null);
072:                setContextPath(contextPath);
073:            }
074:
075:            /* ------------------------------------------------------------ */
076:            public Context(HandlerContainer parent, String contextPath,
077:                    boolean sessions, boolean security) {
078:                this (parent, contextPath, (sessions ? SESSIONS : 0)
079:                        | (security ? SECURITY : 0));
080:            }
081:
082:            /* ------------------------------------------------------------ */
083:            /**
084:             */
085:            public Context(HandlerContainer parent,
086:                    SessionHandler sessionHandler,
087:                    SecurityHandler securityHandler,
088:                    ServletHandler servletHandler, ErrorHandler errorHandler) {
089:                super ((ContextHandler.SContext) null);
090:                _scontext = new SContext();
091:                _sessionHandler = sessionHandler;
092:                _securityHandler = securityHandler;
093:                _servletHandler = servletHandler != null ? servletHandler
094:                        : new ServletHandler();
095:
096:                if (_sessionHandler != null) {
097:                    setHandler(_sessionHandler);
098:
099:                    if (securityHandler != null) {
100:                        _sessionHandler.setHandler(_securityHandler);
101:                        _securityHandler.setHandler(_servletHandler);
102:                    } else {
103:                        _sessionHandler.setHandler(_servletHandler);
104:                    }
105:                } else if (_securityHandler != null) {
106:                    setHandler(_securityHandler);
107:                    _securityHandler.setHandler(_servletHandler);
108:                } else {
109:                    setHandler(_servletHandler);
110:                }
111:
112:                if (errorHandler != null)
113:                    setErrorHandler(errorHandler);
114:
115:                if (parent != null) {
116:                    parent.addHandler(this );
117:                }
118:
119:            }
120:
121:            /* ------------------------------------------------------------ */
122:            /**
123:             * @see org.mortbay.jetty.handler.ContextHandler#startContext()
124:             */
125:            protected void startContext() throws Exception {
126:                super .startContext();
127:
128:                // OK to Initialize servlet handler now
129:                if (_servletHandler != null && _servletHandler.isStarted())
130:                    _servletHandler.initialize();
131:            }
132:
133:            /* ------------------------------------------------------------ */
134:            /**
135:             * @return Returns the securityHandler.
136:             */
137:            public SecurityHandler getSecurityHandler() {
138:                return _securityHandler;
139:            }
140:
141:            /* ------------------------------------------------------------ */
142:            /**
143:             * @return Returns the servletHandler.
144:             */
145:            public ServletHandler getServletHandler() {
146:                return _servletHandler;
147:            }
148:
149:            /* ------------------------------------------------------------ */
150:            /**
151:             * @return Returns the sessionHandler.
152:             */
153:            public SessionHandler getSessionHandler() {
154:                return _sessionHandler;
155:            }
156:
157:            /* ------------------------------------------------------------ */
158:            /** conveniance method to add a servlet.
159:             */
160:            public ServletHolder addServlet(String className, String pathSpec) {
161:                return _servletHandler.addServletWithMapping(className,
162:                        pathSpec);
163:            }
164:
165:            /* ------------------------------------------------------------ */
166:            /** conveniance method to add a servlet.
167:             */
168:            public ServletHolder addServlet(Class servlet, String pathSpec) {
169:                return _servletHandler.addServletWithMapping(servlet.getName(),
170:                        pathSpec);
171:            }
172:
173:            /* ------------------------------------------------------------ */
174:            /** conveniance method to add a servlet.
175:             */
176:            public void addServlet(ServletHolder servlet, String pathSpec) {
177:                _servletHandler.addServletWithMapping(servlet, pathSpec);
178:            }
179:
180:            /* ------------------------------------------------------------ */
181:            /** conveniance method to add a filter
182:             */
183:            public void addFilter(FilterHolder holder, String pathSpec,
184:                    int dispatches) {
185:                _servletHandler.addFilterWithMapping(holder, pathSpec,
186:                        dispatches);
187:            }
188:
189:            /* ------------------------------------------------------------ */
190:            /** conveniance method to add a filter
191:             */
192:            public FilterHolder addFilter(Class filterClass, String pathSpec,
193:                    int dispatches) {
194:                return _servletHandler.addFilterWithMapping(filterClass,
195:                        pathSpec, dispatches);
196:            }
197:
198:            /* ------------------------------------------------------------ */
199:            /** conveniance method to add a filter
200:             */
201:            public FilterHolder addFilter(String filterClass, String pathSpec,
202:                    int dispatches) {
203:                return _servletHandler.addFilterWithMapping(filterClass,
204:                        pathSpec, dispatches);
205:            }
206:
207:            public class SContext extends ContextHandler.SContext {
208:
209:                /* ------------------------------------------------------------ */
210:                /* 
211:                 * @see javax.servlet.ServletContext#getNamedDispatcher(java.lang.String)
212:                 */
213:                public RequestDispatcher getNamedDispatcher(String name) {
214:                    ContextHandler context = org.mortbay.jetty.servlet.Context.this ;
215:                    if (_servletHandler == null
216:                            || _servletHandler.getServlet(name) == null)
217:                        return null;
218:                    return new Dispatcher(context, name);
219:                }
220:
221:                /* ------------------------------------------------------------ */
222:                /* 
223:                 * @see javax.servlet.ServletContext#getRequestDispatcher(java.lang.String)
224:                 */
225:                public RequestDispatcher getRequestDispatcher(
226:                        String uriInContext) {
227:                    if (uriInContext == null)
228:                        return null;
229:
230:                    if (!uriInContext.startsWith("/"))
231:                        return null;
232:
233:                    try {
234:                        String query = null;
235:                        int q = 0;
236:                        if ((q = uriInContext.indexOf('?')) > 0) {
237:                            query = uriInContext.substring(q + 1);
238:                            uriInContext = uriInContext.substring(0, q);
239:                        }
240:                        if ((q = uriInContext.indexOf(';')) > 0)
241:                            uriInContext = uriInContext.substring(0, q);
242:
243:                        String pathInContext = URIUtil.canonicalPath(URIUtil
244:                                .decodePath(uriInContext));
245:                        String uri = URIUtil.addPaths(getContextPath(),
246:                                uriInContext);
247:                        ContextHandler context = org.mortbay.jetty.servlet.Context.this ;
248:                        return new Dispatcher(context, uri, pathInContext,
249:                                query);
250:                    } catch (Exception e) {
251:                        Log.ignore(e);
252:                    }
253:                    return null;
254:                }
255:            }
256:
257:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.