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


001:        // AsIsFrame.java
002:        // $Id: AsIsFrame.java,v 1.1 2001/04/12 14:05:54 ylafon Exp $
003:        // (c) COPYRIGHT MIT, INRIA and Keio, 2001.
004:        // Please first read the full copyright statement in file COPYRIGHT.html
005:
006:        package org.w3c.jigsaw.frames;
007:
008:        import java.io.File;
009:        import java.io.FileInputStream;
010:        import java.io.FileNotFoundException;
011:        import java.io.IOException;
012:
013:        import java.util.Enumeration;
014:
015:        import org.w3c.tools.resources.ProtocolException;
016:        import org.w3c.tools.resources.ResourceException;
017:
018:        import org.w3c.tools.resources.event.AttributeChangedEvent;
019:
020:        import org.w3c.util.CountInputStream;
021:
022:        import org.w3c.www.mime.MimeParser;
023:        import org.w3c.www.mime.MimeParserException;
024:
025:        import org.w3c.www.http.ByteRangeOutputStream;
026:        import org.w3c.www.http.HTTP;
027:        import org.w3c.www.http.HeaderDescription;
028:        import org.w3c.www.http.HeaderValue;
029:        import org.w3c.www.http.MimeParserReplyFactory;
030:        import org.w3c.www.http.HttpContentRange;
031:        import org.w3c.www.http.HttpEntityTag;
032:        import org.w3c.www.http.HttpRange;
033:        import org.w3c.www.http.HttpReplyMessage;
034:        import org.w3c.www.http.HttpFactory;
035:
036:        import org.w3c.jigsaw.http.Reply;
037:        import org.w3c.jigsaw.http.Request;
038:
039:        /**
040:         * Read the HTTP reply directly from a file. Like in Apache mod_asis
041:         * http://httpd.apache.org/docs/mod/mod_asis.html
042:         * 
043:         */
044:        public class AsIsFrame extends HTTPFrame {
045:
046:            // the file offset
047:            int foffset = -1;
048:            HttpReplyMessage asisreply = null;
049:
050:            /**
051:             * Listen its resource.
052:             */
053:            public void attributeChanged(AttributeChangedEvent evt) {
054:                super .attributeChanged(evt);
055:                asisreply = null;
056:            }
057:
058:            /**
059:             * shadows the call from HTTPFrame
060:             * It updates the cached headers for the automagic reply generation
061:             */
062:            protected void updateCachedHeaders() {
063:                super .updateCachedHeaders();
064:                if (asisreply == null) {
065:                    if (fresource != null) {
066:                        // read the reply from the file stream
067:                        FileInputStream fis = null;
068:                        try {
069:                            fis = new FileInputStream(fresource.getFile());
070:                        } catch (FileNotFoundException fex) {
071:                            // should never happen
072:                        }
073:                        CountInputStream cis = new CountInputStream(fis);
074:                        MimeParserReplyFactory repfact = new MimeParserReplyFactory();
075:                        MimeParser mp = new MimeParser(cis, repfact);
076:                        try {
077:                            asisreply = (HttpReplyMessage) mp.parse();
078:                        } catch (MimeParserException mex) {
079:                            // probably a "normal" file, serve it as-is...
080:                            return;
081:                        } catch (IOException ioex) {
082:                            // silently fail, iot will fail later anyway
083:                            return;
084:                        }
085:                        // update the offset and the Content-Length
086:                        foffset = (int) cis.getBytesRead();
087:                        try {
088:                            cis.close();
089:                        } catch (IOException ioex) {
090:                        }
091:                        ;
092:                        int cl = fresource.getFileLength();
093:                        cl -= foffset;
094:                        setValue(ATTR_CONTENT_LENGTH, new Integer(cl));
095:                        contentlength = HttpFactory.makeInteger(cl);
096:                        // reset the md5, as we don't yet compute it
097:                        md5Digest = null;
098:                    }
099:                }
100:            }
101:
102:            /**
103:             * Create a reply to answer to request on this file.
104:             * This method will create a suitable reply (matching the given request)
105:             * and will set all its default header values to the appropriate 
106:             * values.
107:             * The Status is ignored as it is superceded byt the Asis file
108:             * @param request The request to make a reply for.
109:             * @return An instance of Reply, suited to answer this request.
110:             */
111:            public Reply createDefaultReply(Request request, int status) {
112:                if (asisreply == null) {
113:                    updateCachedHeaders();
114:                }
115:                if (asisreply == null) {
116:                    // not parsed, try to serve it as a normal file
117:                    return super .createDefaultReply(request, status);
118:                }
119:                // create the reply with the parsed status
120:                Reply reply = super .createDefaultReply(request, asisreply
121:                        .getStatus());
122:                reply.setReason(asisreply.getReason());
123:                // and update all defined headers
124:                Enumeration e = asisreply.enumerateHeaderDescriptions();
125:                while (e.hasMoreElements()) {
126:                    HeaderDescription d = (HeaderDescription) e.nextElement();
127:                    HeaderValue v = asisreply.getHeaderValue(d);
128:                    if (v != null)
129:                        reply.setHeaderValue(d, v);
130:                }
131:                return reply;
132:            }
133:
134:            /**
135:             * Create the reply relative to the given file.
136:             * @param request the incomming request.
137:             * @return A Reply instance
138:             * @exception ProtocolException If processsing the request failed.
139:             * @exception ResourceException If the resource got a fatal error.
140:             */
141:            protected Reply createFileReply(Request request)
142:                    throws ProtocolException, ResourceException {
143:                File file = fresource.getFile();
144:                Reply reply = null;
145:                // Won't check for range request, as we don't control the status
146:                // Default to full reply then
147:                reply = createDefaultReply(request, HTTP.OK);
148:                try {
149:                    FileInputStream fis = new FileInputStream(file);
150:                    // and escape the headers
151:                    fis.skip(foffset);
152:                    reply.setStream(fis);
153:                } catch (IOException ex) {
154:                    Reply error = request.makeReply(HTTP.SERVICE_UNAVAILABLE);
155:                    error.setContent(ex.getMessage());
156:                    return error;
157:                }
158:                return reply;
159:            }
160:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.