com.caucho.vfs
Class HttpPath

java.lang.Object
  extended by com.caucho.vfs.Path
      extended by com.caucho.vfs.FilesystemPath
          extended by com.caucho.vfs.HttpPath
All Implemented Interfaces:
java.lang.Comparable<Path>
Direct Known Subclasses:
HttpsPath

public class HttpPath
extends FilesystemPath

The HTTP scheme. Currently it supports GET and POST.

TODO: support WEBDAV, enabling the full Path API.


Field Summary
protected static LruCache<java.lang.String,com.caucho.vfs.HttpPath.CacheEntry> _cache
           
protected  com.caucho.vfs.HttpPath.CacheEntry _cacheEntry
           
protected  java.lang.String _host
           
protected  int _port
           
protected  java.lang.String _query
           
protected  java.lang.String _virtualHost
           
protected static L10N L
           
 
Fields inherited from class com.caucho.vfs.FilesystemPath
_bindRoot, _pathname, _root, _userPath
 
Fields inherited from class com.caucho.vfs.Path
_pathSeparatorChar, _schemeMap, _separatorChar
 
Constructor Summary
HttpPath(java.lang.String host, int port)
          Creates a new HTTP root path with a host and a port.
 
Method Summary
protected  Path cacheCopy()
          Copy for caching.
 boolean canRead()
          Returns true if the file is readable.
protected  HttpPath create(FilesystemPath root, java.lang.String userPath, java.util.Map<java.lang.String,java.lang.Object> newAttributes, java.lang.String path, java.lang.String query)
           
protected  HttpPath create(java.lang.String host, int port)
           
 boolean equals(java.lang.Object o)
          Overrides equals to test for equality with an HTTP path.
 boolean exists()
          Returns true if the file exists.
 Path fsWalk(java.lang.String userPath, java.util.Map<java.lang.String,java.lang.Object> attributes, java.lang.String uri)
          Scans the path portion of the URI, i.e.
protected  com.caucho.vfs.HttpPath.CacheEntry getCache()
           
 java.lang.String getHost()
          Returns the host part of the url.
 long getLastModified()
          Returns the last modified time.
 long getLength()
          Returns the file's length
 int getPort()
          Returns the port part of the url.
 java.lang.String getQuery()
          Returns the query string.
 java.lang.String getScheme()
          Returns the scheme, http.
 java.lang.String getURL()
          Returns a full URL for the path.
 java.lang.String getUserPath()
          Returns the user's path.
 java.lang.String getVirtualHost()
          Returns the virtual host, if any.
 int hashCode()
          Returns a hashCode for the path.
 boolean isDirectory()
          Returns the last modified time.
 boolean isFile()
          Returns true if the file exists.
 Path lookupImpl(java.lang.String userPath, java.util.Map<java.lang.String,java.lang.Object> newAttributes)
          Overrides the default lookup to parse the host and port before parsing the path.
 StreamImpl openReadImpl()
          Returns a read stream for a GET request.
 StreamImpl openReadWriteImpl()
          Returns a read/write pair for a POST request.
 Path schemeWalk(java.lang.String userPath, java.util.Map<java.lang.String,java.lang.Object> attributes, java.lang.String uri, int offset)
          Walk down the path starting from the portion immediately following the scheme.
 java.lang.String toString()
          Returns the string form of the http path.
 
Methods inherited from class com.caucho.vfs.FilesystemPath
bind, createRoot, getFullPath, getParent, getPath, getRoot, getTail, normalizePath, normalizePath, setUserPath
 
Methods inherited from class com.caucho.vfs.Path
canExecute, canWrite, changeGroup, changeGroup, changeOwner, changeOwner, chmod, clearStatusCache, compareTo, copy, createDepend, createLink, createNewFile, createRoot, createTempFile, escapeURL, getAttribute, getAttributeNames, getBlockCount, getBlockSize, getCache, getCertificates, getContentType, getCrc64, getCreateTime, getDevice, getDeviceId, getDiskSpaceFree, getDiskSpaceTotal, getFileSeparatorChar, getGroup, getInode, getLastAccessTime, getLastStatusChangeTime, getMode, getNativePath, getNewlineString, getNumberOfLinks, getObject, getOwner, getPathSeparatorChar, getRelativePath, getResources, getResources, getSchemeMap, getSeparatorChar, getUser, getUserDir, getValue, isBlockDevice, isCharacterDevice, isExecutable, isFIFO, isHardLink, isLink, isObject, isPathCacheable, isSocket, isSymbolicLink, isWindows, isWindowsInsecure, iterator, list, lookup, lookup, lookup, lookupNative, lookupNative, lookupRelativeNativePath, mkdir, mkdirs, openAppend, openAppendImpl, openFileRandomAccess, openMemoryMappedFile, openRandomAccess, openRead, openReadWrite, openReadWrite, openReadWrite, openWrite, openWriteImpl, putCache, readLink, realPath, remove, removeAll, renameTo, renameTo, scanScheme, setDefaultSchemeMap, setExecutable, setLastModified, setObject, setTestWindows, setValue, truncate, truncate, unbind, writeToStream, writeToStream
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

L

protected static L10N L

_cache

protected static LruCache<java.lang.String,com.caucho.vfs.HttpPath.CacheEntry> _cache

_host

protected java.lang.String _host

_port

protected int _port

_query

protected java.lang.String _query

_virtualHost

protected java.lang.String _virtualHost

_cacheEntry

protected com.caucho.vfs.HttpPath.CacheEntry _cacheEntry
Constructor Detail

HttpPath

public HttpPath(java.lang.String host,
                int port)
Creates a new HTTP root path with a host and a port.

Parameters:
host - the target host
port - the target port, if zero, uses port 80.
Method Detail

lookupImpl

public Path lookupImpl(java.lang.String userPath,
                       java.util.Map<java.lang.String,java.lang.Object> newAttributes)
Overrides the default lookup to parse the host and port before parsing the path.

Overrides:
lookupImpl in class Path
Parameters:
userPath - the path passed in by the user
newAttributes - attributes passed by the user
Returns:
the final path.

schemeWalk

public Path schemeWalk(java.lang.String userPath,
                       java.util.Map<java.lang.String,java.lang.Object> attributes,
                       java.lang.String uri,
                       int offset)
Walk down the path starting from the portion immediately following the scheme. i.e. schemeWalk is responsible for parsing the host and port from the URL.

Overrides:
schemeWalk in class FilesystemPath
Parameters:
userPath - the user's passed in path
attributes - the attributes for the new path
uri - the normalized full uri
offset - offset into the uri to start processing, i.e. after the scheme.
Returns:
the looked-up path.

fsWalk

public Path fsWalk(java.lang.String userPath,
                   java.util.Map<java.lang.String,java.lang.Object> attributes,
                   java.lang.String uri)
Scans the path portion of the URI, i.e. everything after the host and port.

Specified by:
fsWalk in class FilesystemPath
Parameters:
userPath - the user's supplied path
attributes - the attributes for the new path
uri - the full uri for the new path.
Returns:
the found path.

create

protected HttpPath create(java.lang.String host,
                          int port)

create

protected HttpPath create(FilesystemPath root,
                          java.lang.String userPath,
                          java.util.Map<java.lang.String,java.lang.Object> newAttributes,
                          java.lang.String path,
                          java.lang.String query)

getScheme

public java.lang.String getScheme()
Returns the scheme, http.

Specified by:
getScheme in class Path

getURL

public java.lang.String getURL()
Returns a full URL for the path.

Overrides:
getURL in class Path

getHost

public java.lang.String getHost()
Returns the host part of the url.

Overrides:
getHost in class Path

getPort

public int getPort()
Returns the port part of the url.

Overrides:
getPort in class Path

getUserPath

public java.lang.String getUserPath()
Returns the user's path.

Overrides:
getUserPath in class FilesystemPath

getVirtualHost

public java.lang.String getVirtualHost()
Returns the virtual host, if any.


getQuery

public java.lang.String getQuery()
Returns the query string.

Overrides:
getQuery in class Path

getLastModified

public long getLastModified()
Returns the last modified time.

Overrides:
getLastModified in class Path
Returns:
0 for non-files.

getLength

public long getLength()
Returns the file's length

Overrides:
getLength in class Path
Returns:
0 for non-files

exists

public boolean exists()
Returns true if the file exists.

Overrides:
exists in class Path

isFile

public boolean isFile()
Returns true if the file exists.

Overrides:
isFile in class Path

canRead

public boolean canRead()
Returns true if the file is readable.

Overrides:
canRead in class Path

isDirectory

public boolean isDirectory()
Returns the last modified time.

Overrides:
isDirectory in class Path

getCache

protected com.caucho.vfs.HttpPath.CacheEntry getCache()
Returns:
The contents of this directory or null if the path does not refer to a directory.

openReadImpl

public StreamImpl openReadImpl()
                        throws java.io.IOException
Returns a read stream for a GET request.

Overrides:
openReadImpl in class Path
Throws:
java.io.IOException

openReadWriteImpl

public StreamImpl openReadWriteImpl()
                             throws java.io.IOException
Returns a read/write pair for a POST request.

Overrides:
openReadWriteImpl in class Path
Throws:
java.io.IOException

cacheCopy

protected Path cacheCopy()
Description copied from class: Path
Copy for caching.

Overrides:
cacheCopy in class Path

toString

public java.lang.String toString()
Returns the string form of the http path.

Overrides:
toString in class Path

hashCode

public int hashCode()
Returns a hashCode for the path.

Overrides:
hashCode in class FilesystemPath

equals

public boolean equals(java.lang.Object o)
Overrides equals to test for equality with an HTTP path.

Overrides:
equals in class FilesystemPath