Source Code Cross Referenced for GeneratedFrame.java in  » Web-Server » Jigsaw » org » w3c » jigsaw » pagecompile » 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 » Web Server » Jigsaw » org.w3c.jigsaw.pagecompile 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // GeneratedFrame.java
002:        // $Id: GeneratedFrame.java,v 1.11 2000/08/16 21:37:42 ylafon Exp $
003:        // (c) COPYRIGHT MIT and INRIA, 1998.
004:        // Please first read the full copyright statement in file COPYRIGHT.html
005:
006:        package org.w3c.jigsaw.pagecompile;
007:
008:        import java.io.IOException;
009:        import java.io.InputStream;
010:        import java.io.PrintWriter;
011:        import java.io.StringBufferInputStream;
012:        import org.w3c.jigsaw.http.HTTPException;
013:        import org.w3c.jigsaw.http.Reply;
014:        import org.w3c.jigsaw.http.Request;
015:        import org.w3c.jigsaw.frames.PostableFrame;
016:        import org.w3c.www.mime.MimeType;
017:        import org.w3c.jigsaw.forms.URLDecoder;
018:        import org.w3c.jigsaw.forms.URLDecoderException;
019:        import org.w3c.tools.resources.ProtocolException;
020:        import org.w3c.tools.resources.ReplyInterface;
021:        import org.w3c.tools.resources.RequestInterface;
022:        import org.w3c.tools.resources.ResourceException;
023:
024:        import org.w3c.www.http.HTTP;
025:        import org.w3c.tools.resources.ProtocolException;
026:        import org.w3c.tools.resources.ResourceException;
027:
028:        /**
029:         * @version $Revision: 1.11 $
030:         * @author  Benoît Mahé (bmahe@w3.org)
031:         */
032:        public abstract class GeneratedFrame extends PostableFrame {
033:            /**
034:             * Get the 'convert GET to POST' flag.
035:             * Always return false in GeneratedFrame, could be overriden.
036:             * @return a boolean.
037:             */
038:            public boolean getConvertGetFlag() {
039:                return false;
040:            }
041:
042:            /**
043:             * Perform the request
044:             * @param req The request to handle.
045:             * @exception ProtocolException If processsing the request failed.
046:             * @exception ResourceException If the resource got a fatal error.
047:             */
048:
049:            public ReplyInterface perform(RequestInterface req)
050:                    throws ProtocolException, ResourceException {
051:                try {
052:                    return super .perform(req);
053:                } catch (ProtocolException ex) {
054:                    throw ex;
055:                } catch (ResourceException ex) {
056:                    throw ex;
057:                } catch (Exception ex) {
058:                    Request request = (Request) req;
059:                    Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
060:                    PageCompileOutputStream err = new PageCompileOutputStream();
061:                    PrintWriter writer = new PrintWriter(err);
062:                    writer.print("The generated frame at\n\n"
063:                            + request.getURL() + "\n\n"
064:                            + "reported this exception : \n\n"
065:                            + ex.getMessage() + "\n\nStack trace : \n\n");
066:                    ex.printStackTrace(writer);
067:                    writer.flush();
068:                    writer.close();
069:                    error.setStream(err.getInputStream());
070:                    error.setContentLength(err.size());
071:                    error.setContentType(MimeType.TEXT_PLAIN);
072:                    return error;
073:                }
074:            }
075:
076:            /**
077:             * The default GET method.
078:             * @param request The request to handle.
079:             * @exception ProtocolException If processsing the request failed.
080:             * @exception ResourceException If the resource got a fatal error.
081:             */
082:            public Reply get(Request request) throws ProtocolException,
083:                    ResourceException {
084:                if (getConvertGetFlag() && request.hasState("query")) {
085:                    String query = request.getQueryString();
086:                    InputStream in = new StringBufferInputStream(query);
087:                    URLDecoder d = new URLDecoder(in, getOverrideFlag());
088:                    try {
089:                        d.parse();
090:                    } catch (URLDecoderException e) {
091:                        Reply error = request.makeReply(HTTP.BAD_REQUEST);
092:                        error.setContent("Invalid request: "
093:                                + "unable to decode form data.");
094:                        throw new HTTPException(error);
095:                    } catch (IOException e) {
096:                        Reply error = request.makeReply(HTTP.BAD_REQUEST);
097:                        error
098:                                .setContent("Invalid request: unable to read form data.");
099:                        throw new HTTPException(error);
100:                    }
101:                    return handle(request, d);
102:                }
103:                Reply reply = createDefaultReply(request, HTTP.OK);
104:                PageCompileOutputStream out = new PageCompileOutputStream();
105:                try {
106:                    get(request, reply, out);
107:                } catch (IOException ex) {
108:                    Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
109:                    PageCompileOutputStream err = new PageCompileOutputStream();
110:                    PrintWriter writer = new PrintWriter(err);
111:                    writer.print("The generated frame at\n\n"
112:                            + request.getURL() + "\n\n"
113:                            + "reported this exception : \n\n"
114:                            + ex.getMessage() + "\n\nStack trace : \n\n");
115:                    ex.printStackTrace(writer);
116:                    writer.flush();
117:                    writer.close();
118:                    error.setStream(err.getInputStream());
119:                    error.setContentLength(err.size());
120:                    error.setContentType(MimeType.TEXT_PLAIN);
121:                    return error;
122:                }
123:                reply.setStream(out.getInputStream());
124:                reply.setContentLength(out.size());
125:                return reply;
126:            }
127:
128:            /**
129:             * Handle the form submission, after posted data parsing.
130:             * This methos always return "Method POST not allowed".
131:             * @param request The request proper.
132:             * @param reply The reply.
133:             * @param data The parsed data content.
134:             * @param out the output stream.
135:             * @exception ProtocolException If form data processing failed.
136:             * @exception IOException If an IO error occurs.
137:             * @see org.w3c.jigsaw.forms.URLDecoder
138:             */
139:            protected void post(Request request, Reply reply, URLDecoder data,
140:                    PageCompileOutputStream out) throws ProtocolException,
141:                    IOException {
142:                Reply error = request.makeReply(HTTP.NOT_ALLOWED);
143:                if (allowed != null)
144:                    error.setHeaderValue(Reply.H_ALLOW, allowed);
145:                error.setContent("Method POST not allowed on this resource.");
146:                throw new HTTPException(error);
147:            }
148:
149:            /**
150:             * Handle the form submission, after posted data parsing.
151:             * @param request The request proper.
152:             * @param data The parsed data content.
153:             * @exception ProtocolException If form data processing failed.
154:             * @see org.w3c.jigsaw.forms.URLDecoder
155:             */
156:
157:            public Reply handle(Request request, URLDecoder data)
158:                    throws ProtocolException {
159:                PageCompileOutputStream out = new PageCompileOutputStream();
160:                Reply reply = createDefaultReply(request, HTTP.OK);
161:
162:                try {
163:                    post(request, reply, data, out);
164:                } catch (IOException ex) {
165:                    Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
166:                    PageCompileOutputStream err = new PageCompileOutputStream();
167:                    PrintWriter writer = new PrintWriter(err);
168:                    writer.print("The generated frame at\n\n"
169:                            + request.getURL() + "\n\n"
170:                            + "reported this exception : \n\n"
171:                            + ex.getMessage() + "\n\nStack trace : \n\n");
172:                    ex.printStackTrace(writer);
173:                    writer.flush();
174:                    writer.close();
175:                    error.setStream(err.getInputStream());
176:                    error.setContentLength(err.size());
177:                    error.setContentType(MimeType.TEXT_PLAIN);
178:                    return error;
179:                }
180:                reply.setStream(out.getInputStream());
181:                reply.setContentLength(out.size());
182:                return reply;
183:            }
184:
185:            /**
186:             * All java code extracted between <java type=code> and </java> from 
187:             * the jhtml page will be put in this method body.
188:             * @param request the incomming request.
189:             * @param reply the reply.
190:             * @param out the output stream.
191:             * @exception IOException if an IO error occurs.
192:             */
193:            abstract protected void get(Request request, Reply reply,
194:                    PageCompileOutputStream out) throws IOException;
195:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.