Source Code Cross Referenced for FileEngine.java in  » Web-Server » simple » simple » http » serve » 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 » simple » simple.http.serve 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * FileEngine.java February 2001
003:         *
004:         * Copyright (C) 2001, Niall Gallagher <niallg@users.sf.net>
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
013:         * GNU Lesser General Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser General 
016:         * Public License along with this library; if not, write to the 
017:         * Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
018:         * Boston, MA  02111-1307  USA
019:         */
020:
021:        package simple.http.serve;
022:
023:        import simple.http.Response;
024:        import simple.http.Request;
025:        import java.io.File;
026:
027:        /**
028:         * The <code>FileEngine</code> is used to produce implementations
029:         * of the <code>Resource</code> object to represent files on the
030:         * underlying filesystem. This will produce <code>Resource</code>
031:         * objects that map on to the suggested URI relative to some
032:         * given <code>Context</code>. The <code>Context</code> must be 
033:         * given as a root so all requests for <code>Resource</code>'s are 
034:         * retrieved relative to that root. 
035:         * <p>
036:         * The meaning of HTTP URI in this instance is the request URI
037:         * from a HTTP/x.x request, as RFC 2616 and RFC 2396 defines it
038:         *
039:         * <pre> 
040:         * Request-Line = Method SP Request-URI SP HTTP-Version CRLF
041:         *
042:         * Request-URI = "*" | absoluteURI | abs_path | authority
043:         * absoluteURI = "http:" "//" host [":" port] [abs_path ["?" query]] 
044:         * abs_path = "/" path_segments         
045:         * path_segments = segment *( "/" segment )
046:         * </pre> 
047:         *
048:         * So the <code>FileEngine</code> object will accept the request URI 
049:         * that come in the form outlined above. These can include formats 
050:         * like 
051:         *
052:         * <pre> 
053:         * http://some.host/pub;param=value/bin/index.html?name=value
054:         * http://some.host:8080/index.en_US.html
055:         * some.host:8080/index.html
056:         * /usr/bin;param=value/README.txt
057:         * /usr/bin/compress.tar.gz
058:         * </pre>
059:         *
060:         * The <code>FileEngine</code> object will directly take a request 
061:         * URI as defined in RFC 2616 and translate this into a system 
062:         * specific <code>Resource</code>. This keeps the objects semantics 
063:         * simple and explicit, although at the expense of performance. 
064:         *
065:         * @author Niall Gallagher
066:         *
067:         * @see simple.http.serve.CacheContext
068:         */
069:        public class FileEngine implements  ResourceEngine {
070:
071:            /**
072:             * Each <code>FileEngine</code> operates using a context.
073:             */
074:            protected Context context;
075:
076:            /**
077:             * Constructor for the <code>FileEngine</code>. This uses the 
078:             * current working directory to serve the <code>Resource</code>.
079:             * This will retrieve and represent OS specific resources such 
080:             * as files using <code>Resource</code> implementations. This
081:             * also keeps a cache of the file contents requested.
082:             */
083:            public FileEngine() {
084:                this (new CacheContext());
085:            }
086:
087:            /**
088:             * Constructor takes a <code>Context</code> implementation and
089:             * operates relative to that implementation. This will retrieve
090:             * and represent OS specific resources such as files using 
091:             * <code>Resource</code> implementations. This relies on the 
092:             * provided context to perform caching for this implementation.
093:             *
094:             * @param context this is the context the file engine will use
095:             */
096:            public FileEngine(Context context) {
097:                this .context = context;
098:            }
099:
100:            /**
101:             * This will look for and retrieve the requested resource. The 
102:             * target given must be in the form of a request URI. This will
103:             * locate the resource and return the <code>Resource</code>
104:             * implementation that will handle the target.
105:             *
106:             * @param target the URI style path that represents the target 
107:             *
108:             * @return returns the resource instance to handle the target
109:             */
110:            public Resource resolve(String target) {
111:                return resolve(target, context.getFile(target));
112:            }
113:
114:            /**
115:             * This will look for and retrieve the requested resource. The 
116:             * target given must be in the form of a request URI. This will
117:             * locate the resource and return the <code>Resource</code>
118:             * implementation that will handle the target.
119:             *
120:             * @param target the URI style path that represents the target
121:             * @param file this is the file that represents the resource 
122:             *
123:             * @return returns the resource instance to handle the target 
124:             */
125:            protected Resource resolve(String target, File file) {
126:                if (file.isDirectory()) {
127:                    return new DirectoryComponent(context, target);
128:                } else if (file.isFile()) {
129:                    return new FileComponent(context, target);
130:                } else
131:                    return new Component(context) {
132:                        protected void process(Request req, Response resp) {
133:                            handle(req, resp, 404);
134:                        }
135:                    };
136:            }
137:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.