Source Code Cross Referenced for JspRequestDispatcher.java in  » Portal » Open-Portal » com » sun » portal » providers » jsp » 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 » Portal » Open Portal » com.sun.portal.providers.jsp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001 Sun Microsystems, Inc.  All rights reserved.
003:         * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms.
004:         */
005:        package com.sun.portal.providers.jsp;
006:
007:        import java.io.FileReader;
008:        import java.io.FileNotFoundException;
009:        import java.io.IOException;
010:        import java.io.PrintWriter;
011:
012:        import java.lang.IllegalArgumentException;
013:
014:        import java.util.Enumeration;
015:        import java.util.Hashtable;
016:        import java.util.logging.LogRecord;
017:        import java.util.logging.Level;
018:        import java.util.logging.Logger;
019:
020:        import javax.servlet.RequestDispatcher;
021:        import javax.servlet.ServletException;
022:        import javax.servlet.ServletResponse;
023:        import javax.servlet.ServletRequest;
024:
025:        import javax.servlet.http.HttpServletRequest;
026:        import javax.servlet.http.HttpServletResponse;
027:        import javax.servlet.http.HttpUtils;
028:
029:        import com.sun.portal.providers.context.ProviderContext;
030:
031:        import com.sun.portal.desktop.context.ProviderContextThreadLocalizer;
032:        import com.sun.portal.providers.ProviderException;
033:        import com.sun.portal.log.common.PortalLogger;
034:
035:        /*
036:         * The JspRequestDispatcher represents the RequestDispatcher for the 
037:         * JSPProvider JspServletEnvironment.  It implements the include and
038:         * forward functionality.  
039:         * 
040:         **/
041:
042:        class JspRequestDispatcher implements  RequestDispatcher {
043:
044:            private JspServletEnvironment jspEnv;
045:            private ProviderContext providerContext;
046:            private String path;
047:            private String baseuri;
048:            private static Logger logger = PortalLogger
049:                    .getLogger(JspRequestDispatcher.class);
050:
051:            /*
052:             * Constructor
053:             *
054:             * @param path   The path of the requested resource. Format:
055:             *               /resource  
056:             *               /resource?qstring
057:             * @param jspEnv The JspServletEnvironment of the parent resource
058:             */
059:            public JspRequestDispatcher(String path,
060:                    JspServletEnvironment jspEnv) {
061:                this .path = path;
062:                this .baseuri = path;
063:                this .jspEnv = jspEnv;
064:                this .providerContext = ProviderContextThreadLocalizer.get();
065:
066:                int index = path.indexOf('?');
067:
068:                if (index != -1) {
069:                    baseuri = path.substring(0, index);
070:                }
071:            }
072:
073:            /*
074:             * Include a server resource.  
075:             * 
076:             * If the resource is a local reference to a JSP, e.g. "/foo.jsp", 
077:             * then the request is processed within the JSPProvider's 
078:             * ServletEnvironment and the resource is retrieved from the same
079:             * area that the JSPProvider looks for files.
080:             * 
081:             * If the resource is a local reference to a non-JSP file, 
082:             * e.g. "/foo.html", then content of the static file is retrieved and
083:             * returned as is.
084:             * 
085:             * 
086:             * @param request   ServletRequest object
087:             * @param response  ServletResponse object
088:             */
089:            public void include(ServletRequest request, ServletResponse response)
090:                    throws ServletException, IOException {
091:
092:                if ((path.length() == 0) || (path == null)) {
093:                    return;
094:                }
095:
096:                StringBuffer icontent = new StringBuffer();
097:
098:                try {
099:                    // JSP Server Resource
100:                    // 
101:                    if (baseuri.endsWith(".jsp")) {
102:                        icontent = getJspResource(request, response);
103:
104:                        // Static Server Resource
105:                        // 
106:                    } else {
107:                        icontent = getStaticResource();
108:                    }
109:                } catch (ServletException se) {
110:                    if (logger.isLoggable(Level.INFO)) {
111:                        LogRecord record = new LogRecord(Level.INFO,
112:                                "PSDT_CSPPJ0010");
113:                        record.setLoggerName(logger.getName());
114:                        record.setParameters(new Object[] { baseuri });
115:                        record.setThrown(se);
116:                        logger.log(record);
117:                    }
118:                    throw se;
119:                }
120:
121:                if (icontent != null) {
122:                    PrintWriter pw = response.getWriter();
123:                    pw.print(icontent.toString());
124:                    pw.flush();
125:                }
126:            }
127:
128:            /*
129:             * Forward to a server resource.
130:             *
131:             * If the resource is a local reference to a JSP, e.g. "/foo.jsp",
132:             * then the request is processed within the JSPProvider's
133:             * ServletEnvironment and the resource is retrieved from the same
134:             * area that the JSPProvider looks for files.
135:             *
136:             * If the resource is a local reference to a non-JSP file,
137:             * e.g. "/foo.html", then content of the static file is retrieved and
138:             * returned as is.
139:             *
140:             *
141:             * @param request   ServletRequest object
142:             * @param response  ServletResponse object
143:             */
144:            public void forward(ServletRequest request, ServletResponse response)
145:                    throws ServletException, IOException {
146:
147:                include(request, response);
148:            }
149:
150:            /**
151:             *  Retrieve JSP Resource from server
152:             *  
153:             *  URI Format:  /foo.jsp
154:             *  URI Format:  /foo.jsp?parm1=value1
155:             *  URI Format:  /foo.jsp?parm1=value1&parm2=value2
156:             *
157:             * @return StringBuffer  content from JSP server resource
158:             */
159:            private StringBuffer getJspResource(ServletRequest request,
160:                    ServletResponse response) throws ServletException {
161:
162:                Hashtable parameters = getRequestParameters(request);
163:                HttpServletRequest hrequest = (HttpServletRequest) request;
164:                HttpServletResponse hresponse = (HttpServletResponse) response;
165:                StringBuffer buffer = new StringBuffer();
166:
167:                JSPProvider jp = (JSPProvider) hrequest
168:                        .getAttribute(JspFactoryImpl.providerKey);
169:
170:                if (jp != null) {
171:                    try {
172:                        buffer = jp.includeJspPage(path, parameters, hrequest,
173:                                hresponse);
174:                    } catch (ProviderException pe) {
175:                        logger.log(Level.FINE, "PSDT_CSPPJ0013", new Object[] {
176:                                path, parameters });
177:                        throw new ServletException("Problem processing JSP: "
178:                                + path, pe);
179:                    } catch (Exception e) {
180:                        logger.log(Level.FINE, "PSDT_CSPPJ0013", new Object[] {
181:                                path, parameters });
182:                        throw new ServletException("Problem processing JSP: "
183:                                + path, e);
184:                    }
185:                }
186:
187:                return buffer;
188:            }
189:
190:            /**
191:             *  Retrieve Static resource from server
192:             *  
193:             *  URI Format:  /foo.html 
194:             *  URI Format:  /foo.html?qstring
195:             *
196:             * @return StringBuffer  content from static server resource
197:             */
198:
199:            private StringBuffer getStaticResource() throws ServletException {
200:
201:                StringBuffer buffer = new StringBuffer();
202:
203:                try {
204:                    FileReader fr = new FileReader(jspEnv.getRealPath(path));
205:                    char c[] = new char[4096];
206:                    int read = 0;
207:
208:                    while ((read = fr.read(c)) != -1) {
209:                        buffer.append(c, 0, read);
210:                    }
211:
212:                    fr.close();
213:
214:                } catch (FileNotFoundException fnf) {
215:                    if (logger.isLoggable(Level.FINE)) {
216:                        LogRecord record = new LogRecord(Level.FINE,
217:                                "PSDT_CSPPJ0014");
218:                        record.setLoggerName(logger.getName());
219:                        record.setParameters(new Object[] { path });
220:                        record.setThrown(fnf);
221:                        logger.log(record);
222:                    }
223:                    throw new ServletException("File Not Found: " + path, fnf);
224:                } catch (IOException ioe) {
225:                    if (logger.isLoggable(Level.FINE)) {
226:                        LogRecord record = new LogRecord(Level.FINE,
227:                                "PSDT_CSPPJ0014");
228:                        record.setLoggerName(logger.getName());
229:                        record.setParameters(new Object[] { path });
230:                        record.setThrown(ioe);
231:                        logger.log(record);
232:                    }
233:                    throw new ServletException("Problem processing file: "
234:                            + path, ioe);
235:                } catch (Exception e) {
236:                    if (logger.isLoggable(Level.FINE)) {
237:                        LogRecord record = new LogRecord(Level.FINE,
238:                                "PSDT_CSPPJ0014");
239:                        record.setLoggerName(logger.getName());
240:                        record.setParameters(new Object[] { path });
241:                        record.setThrown(e);
242:                        logger.log(record);
243:                    }
244:                    throw new ServletException("Problem processing file: "
245:                            + path, e);
246:                }
247:
248:                return buffer;
249:            }
250:
251:            /**
252:             *  Retrieve parameters from both the ServletRequest and the 
253:             *  query string. 
254:             *
255:             * @return Hashtable  of request parameters
256:             */
257:            private Hashtable getRequestParameters(ServletRequest req)
258:                    throws ServletException {
259:
260:                Hashtable parameters = new Hashtable();
261:                int index = path.indexOf('?');
262:                String qstring = null;
263:
264:                if (index != -1) {
265:                    qstring = path.substring(index + 1);
266:
267:                    try {
268:                        parameters = HttpUtils.parseQueryString(qstring);
269:                    } catch (IllegalArgumentException e) {
270:                        if (logger.isLoggable(Level.FINE)) {
271:                            LogRecord record = new LogRecord(Level.FINE,
272:                                    "PSDT_CSPPJ0015");
273:                            record.setLoggerName(logger.getName());
274:                            record.setParameters(new Object[] { path });
275:                            record.setThrown(e);
276:                            logger.log(record);
277:                        }
278:                        throw new ServletException(
279:                                "Problem parsing query string:" + qstring, e);
280:                    } catch (Exception e) {
281:                        if (logger.isLoggable(Level.FINE)) {
282:                            LogRecord record = new LogRecord(Level.FINE,
283:                                    "PSDT_CSPPJ0015");
284:                            record.setLoggerName(logger.getName());
285:                            record.setParameters(new Object[] { path });
286:                            record.setThrown(e);
287:                            logger.log(record);
288:                        }
289:                        throw new ServletException(
290:                                "Problem parsing query string:" + qstring, e);
291:                    }
292:
293:                }
294:
295:                for (Enumeration pe = req.getParameterNames(); pe
296:                        .hasMoreElements();) {
297:                    String pname = (String) pe.nextElement();
298:                    parameters.put(pname, req.getParameterValues(pname));
299:                }
300:
301:                return parameters;
302:            }
303:
304:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.