org.chenillekit.core.resources
Class URIResource

java.lang.Object
  extended by org.chenillekit.core.resources.URIResource
All Implemented Interfaces:
Resource

public class URIResource
extends Object
implements Resource

A resource stored with in any location (local, remote or jar archive).

Version:
$Id: URIResource.java 594 2009-12-05 15:17:26Z mlusetti $

Constructor Summary
URIResource(File file)
           
URIResource(String uri)
           
URIResource(URI uri)
           
URIResource(URL url)
           
 
Method Summary
 boolean equals(Object obj)
           
 boolean exists()
          Returns true if the resource exists; if a stream to the content of the file may be openned.
 Resource forFile(String relativePath)
          Returns a Resource based on a relative path, relative to the folder containing the resource.
 Resource forLocale(Locale locale)
          Returns a localized version of the resource.
 String getFile()
          Returns the file portion of the Resource path, everything that follows the final forward slash.
 String getFolder()
          Returns the portion of the path up to the last forward slash; this is the directory or folder portion of the Resource.
 String getPath()
          Return the path (the combination of folder and file).
 int hashCode()
           
protected  Resource newResource(String uri)
           
 InputStream openStream()
          Opens a stream to the content of the resource, or returns null if the resource does not exist.
 String toString()
           
 URL toURL()
          Returns the URL for the resource, or null if it does not exist.
 Resource withExtension(String extension)
          Returns a new Resource with the extension changed (or, if the resource does not have an extension, the extension is added).
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

URIResource

public URIResource(String uri)

URIResource

public URIResource(URI uri)
            throws MalformedURLException
Throws:
MalformedURLException

URIResource

public URIResource(File file)
            throws MalformedURLException
Throws:
MalformedURLException

URIResource

public URIResource(URL url)
            throws URISyntaxException,
                   MalformedURLException
Throws:
URISyntaxException
MalformedURLException
Method Detail

newResource

protected Resource newResource(String uri)

exists

public boolean exists()
Returns true if the resource exists; if a stream to the content of the file may be openned.

Specified by:
exists in interface Resource
Returns:
true if the resource exists, false if it does not

openStream

public InputStream openStream()
                       throws IOException
Opens a stream to the content of the resource, or returns null if the resource does not exist.

Specified by:
openStream in interface Resource
Returns:
an open, buffered stream to the content, if available
Throws:
IOException

toURL

public URL toURL()
Returns the URL for the resource, or null if it does not exist.

Specified by:
toURL in interface Resource

forLocale

public Resource forLocale(Locale locale)
Returns a localized version of the resource. May return null if no such resource exists.

Specified by:
forLocale in interface Resource

forFile

public Resource forFile(String relativePath)
Returns a Resource based on a relative path, relative to the folder containing the resource. Understands the "." (current folder) and ".." (parent folder) conventions, and treats multiple sequential slashes as a single slash.

Specified by:
forFile in interface Resource

withExtension

public Resource withExtension(String extension)
Returns a new Resource with the extension changed (or, if the resource does not have an extension, the extension is added). The new Resource may not exist (that is, toURL() may return null.

Specified by:
withExtension in interface Resource
Parameters:
extension - to apply to the resource, such as "html" or "properties"
Returns:
the new resource

getFolder

public String getFolder()
Returns the portion of the path up to the last forward slash; this is the directory or folder portion of the Resource.

Specified by:
getFolder in interface Resource

getFile

public String getFile()
Returns the file portion of the Resource path, everything that follows the final forward slash.

Specified by:
getFile in interface Resource

getPath

public String getPath()
Return the path (the combination of folder and file).

Specified by:
getPath in interface Resource

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2008-2010 ChenilleKit. All Rights Reserved.