Java Doc for Context.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 Reference  Class Diagram Java Document (Java Doc) 


simple.http.serve.Context

All known Subclasses:   simple.http.serve.FileContext,
Context
public interface Context (Code)
The Context interface is used to give a view of the file system to the ResourceEngine. This provides the information to the ResourceEngine that it needs in order to serve content to the client browser. This provides the path translations for the HTTP request URI. This also provides the Format object that is used to create directory listings and error messages.

This object essentially provides a mechanism that allows the file engine to convert the HTTP request URI into OS system paths and system objects such as the File object. A context is rooted a a certain directory in the system. This directory is where the resources are gathered from. For example suppose that a Context implementation is rooted at the directory "c:\web\html\" on a DOS system. Now if the target of the browser was "http://some.host/web/pub/README". The context needs to be consulted to convert "/web/pub/README" into the real path within the system. So Context.getRealPath is invoked with the path "/web/pub/README", which responds with the system path "c:\web\html\web\pub\README". Also if this was a UNIX system with the same context rooted at "/home/user/html" then the same URL would result in "/home/user/html/web/pub/README".

The meaning of HTTP URI in this instance is the request URI from a HTTP/x.x request, as RFC 2616 and RFC 2396 defines it

 
 Request-Line = Method SP Request-URI SP HTTP-Version CRLF
 Request-URI = "*" | absoluteURI | abs_path | authority
 absoluteURI = "http:" "//" host [":" port] [abs_path ["?" query]] 
 abs_path = "/" path_segments         
 path_segments = segment *( "/" segment )
 
So the Context object must be prepared to accept the request URI that come in the form outlined above. These can include formats like
 
 http://some.host/pub;param=value/bin/index.html?name=value
 http://some.host:8080/index.en_US.html
 some.host:8080/index.html
 /usr/bin;param=value/README.txt
 /usr/bin/compress.tar.gz
 
The Context implementation should be able to directly take a Request-URI as defined in RFC 2616 and translate this into a path compatible with the OS specific file system. This keeps the objects semantics simple and explicit, although at the expense of performance.
author:
   Niall Gallagher
See Also:   simple.util.parse.URIParser
See Also:   simple.util.parse.PathParser




Method Summary
public  StringgetBasePath()
     This is used to retrieve the base path of the context.
public  ContentgetContent(String target)
     This enables the contents of some resource to be acquired using a request URI.
public  StringgetContentType(String target)
     This method will extract the type attribute of this URI.
public  FilegetDirectory(String target)
     This is used to translate the HTTP request URI into the File object that it represent the parent directory of the URI.
public  FilegetFile(String target)
     This is used to translate the HTTP request URI into the File object that it represents.
public  FormatgetFormat()
     Each Context object must be coupled with an instance of the Format object.
public  IndexgetIndex(String target)
     This is an all in one method that allows all the information on the target URI to be gathered at once.
public  LocalegetLocale(String target)
     This will parse the HTTP request URI specified and return the Locale for that resource.
public  LocatorgetLocator()
     Each Context must supply a Locator to enable the system to locate configuration information and other resources that reside outside the context path.
public  StringgetName(String target)
     This will parse and return the file name that this request URI references.
public  PathgetPath(String target)
     This is used to translate the HTTP request URI into the Path object that it represents.
public  PropertiesgetProperties(String target)
     This provides a convenient way for a Java properties file to be loaded.
public  StringgetRealPath(String target)
     This is used to translate the HTTP request URI into the OS specific path that it represents.
public  StringgetRequestPath(String target)
     This is used to translate the HTTP request URI into the URI path normalized and without query or parameter parts.



Method Detail
getBasePath
public String getBasePath()(Code)
This is used to retrieve the base path of the context. The base path of the context is that path that that this will retrieve system information from. This represents a base that the request URI paths are served from on the system. For instance a base of "c:\path" would translate a URI path of "/index.html" into "c:\path\index.html". Every resource request must be relative to the context path this allows the ResourceEngine to map the URIs onto the specific OS. The base path is the OS file system specific path. So on UNIX it could be "/home/user/" and on a DOS system it could be "c:\web\html" for example. this returns the base path of the context



getContent
public Content getContent(String target) throws IOException(Code)
This enables the contents of some resource to be acquired using a request URI. The Content is a resource that can be transmitted using an OutputStream which avoids having to deal with FileInputStream objects for files and also facilitates dynamic content. The purpose of this is to discourage the use of chaining which does not result in transferring control, that is, avoid the Java Servlet include technique used by javax.servlet.RequestDispatcher.
Parameters:
  target - the request URI that refers to a resource this returns the specified resource wrapped in theContent interface
throws:
  IOException - this is thrown if the resource does notexist or cannot be accessed



getContentType
public String getContentType(String target)(Code)
This method will extract the type attribute of this URI. The MIME type of the request URI is extracted from the name of the target. The name for the Context is the last path segment is the token defined by RFC 2396 as path_segments. So for example if the target was "some.host:8080/bin/index.html" then the name for that resource would be "index.html". Once the name has been extracted the MIME is defined by the file extension which, for the example is text/html.

Implementations of the Context may also choose to implement a method that consults the underlying resource and inspect its contents to determine its MIME type. Or for a MAC it may contain its MIME type. If the MIME type cannot be found by any of the above methods RFC 2616 suggests that the resource be given the MIME type application/octetstream. This should also make not predictions as to how the file will be served. So if the target references a directory this does not mean that the Format.getContentType can be used.
Parameters:
  target - the request URI to be parsed for its type the type of the file this path refers to




getDirectory
public File getDirectory(String target)(Code)
This is used to translate the HTTP request URI into the File object that it represent the parent directory of the URI. This will convert the URI to a format that the host system can use and then create the File object for that path. So if for example the context path was "c:\path" on a DOS system and the HTTP URI given was "/index.html" this returns the File "c:\path\". This is basically for convenience as the same could be achieved using the file retrieved from getFile and acquiring the parent.
Parameters:
  target - this is the HTTP request URI path that is usedto retrieve the File object returns the File for the directory



getFile
public File getFile(String target)(Code)
This is used to translate the HTTP request URI into the File object that it represents. This will convert the URI to a format that the system can use and then create the File object for that path. So if for example the context path was "c:\path" on a DOS system and the HTTP URI given was "/index.html" this returns the File "c:\path\index.html". This is basically for convenience as the same could be achieved using the getRealPath and then creating the File from that OS specific path.
Parameters:
  target - this is the HTTP request URI path that is usedto retrieve the File object returns the File for the given path



getFormat
public Format getFormat()(Code)
Each Context object must be coupled with an instance of the Format object. This is required because each ResourceEngine needs to serve the directory listing and the error messages in a consistent format. The resources of the instances can thus be pooled by comparing the equality of the various Context objects. When there is an object that requires a ResourceEngine it can create an instance of the Context and using a static factory method ResourceEngine with the context object there is a search for an active instance of the ResourceEngine. If one is found that uses a similar context object then it is returned to the caller. This enables instances and thus resources to be shared transparently. this returns the format used with this context object



getIndex
public Index getIndex(String target)(Code)
This is an all in one method that allows all the information on the target URI to be gathered at once. The motivation for this method is primarily convenience. However it is also used to increase the performance of the ResourceEngine when the Context implementation is synchronized. This will enable the ResourceEngine to gather the information on the target by acquiring the lock for the object instance only once.
Parameters:
  target - this is the request URI that is to be parsed



getLocale
public Locale getLocale(String target)(Code)
This will parse the HTTP request URI specified and return the Locale for that resource. The Locale is extracted from the target by examining the path segment of the HTTP request URI. The path segment is the abs_path token defined in RFC 2396. It is extracted from a second extension in the file name. So for example if the HTTP request URI was "http://some.host/usr;param=value/index.en_US.html" then the file name "index.en_US.html" would have the second file extension en_US converted into a Locale. This will not interfere if the file name was "compressed.tar.gz", it will simply ignore the "tar" second file extension and return Locale.getDefault.
Parameters:
  target - the request URI to be parsed for its locale this will return the locale for the specified URI



getLocator
public Locator getLocator()(Code)
Each Context must supply a Locator to enable the system to locate configuration information and other resources that reside outside the context path. This is useful when there are Java properties and XML configuration files required by objects interacting with a Context. The Locator employs a search to locate resources, which are identified either by name or using aliases. this returns the locator used by this context object



getName
public String getName(String target)(Code)
This will parse and return the file name that this request URI references. The name for the Context is the last path segment is the token defined by RFC 2396 as path_segments. So for example if the target was "some.host:8080/home/user/" then the name for that resource would be "user". If the path references the root path "/" then null should be returned.
Parameters:
  target - the request URI to be parsed for its name this will return the name that this references



getPath
public Path getPath(String target)(Code)
This is used to translate the HTTP request URI into the Path object that it represents. This enables the HTTP request URI to be examined thoroughly an allows various other files to be examined relative to it. For example if the URI referenced a path "/usr/bin/file" and some resource in the same directory is required then the Path can be used to acquire the relative path. This is useful if links within a HTML page are to be dynamically generated. The Path.getRelative provides this functionality.
Parameters:
  target - this is the HTTP request URI path that is usedto retrieve the Path object returns the Path for the given path



getProperties
public Properties getProperties(String target) throws IOException(Code)
This provides a convenient way for a Java properties file to be loaded. This resolves the target URI to a relative file within the context to be the same as the getFile method would return. Once the file has been acquired the Java properties file is loaded, each time, there is no caching of the loaded properties. This ensures that changes to a loaded object does not affect other users of the properties file.
Parameters:
  target - the request URI that refers to the properties returns a populated Properties objectusing the specified Java properties file
throws:
  IOException - this is thrown if the resource does notexist or cannot be accessed



getRealPath
public String getRealPath(String target)(Code)
This is used to translate the HTTP request URI into the OS specific path that it represents. This will convert the URI to a format that the system can use and also represents the resource path on that system. So if for example the context path was "c:\path" on a DOS system and the HTTP URI given was "/index.html" this returns "c:\path\index.html". If a UNIX system was running the VM and the context base was for example "/home/" then this would return the UNIX path "/home/index.html" for the same request URI.
Parameters:
  target - this is the HTTP request URI path that is to be translated into the OS specific path this returns the OS specific path name for the translate request URI



getRequestPath
public String getRequestPath(String target)(Code)
This is used to translate the HTTP request URI into the URI path normalized and without query or parameter parts. This is used so that the resource requested by the client can be discovered. For example this will convert the HTTP request URI "http://hostname/bin;param=value/../index.html?query" into the relative URI path /index.html. This is useful if a logging mechanism requires the name of the resource that was requested, it can also be used help find the resource.
Parameters:
  target - this is the HTTP request URI that is to beconverted into a normalized relative URI path the HTTP request URI as a normalized relative path



www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.