Class AbstractResource
- java.lang.Object
-
- org.apache.tapestry5.commons.internal.util.LockSupport
-
- org.apache.tapestry5.ioc.internal.util.AbstractResource
-
- All Implemented Interfaces:
Resource
- Direct Known Subclasses:
ClasspathResource,ContextResource
public abstract class AbstractResource extends LockSupport implements Resource
Abstract implementation ofResource. Subclasses must implement the abstract methodsResource.toURL()andnewResource(String)as well as toString(), hashCode() and equals().
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractResource(java.lang.String path)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanexists()Simple check for whetherResource.toURL()returns null or not.ResourceforFile(java.lang.String relativePath)Returns a Resource based on a relative path, relative to the folder containing the resource.ResourceforLocale(java.util.Locale locale)Returns a localized version of the resource.java.lang.StringgetFile()Returns the file portion of the Resource path, everything that follows the final forward slash.java.lang.StringgetFolder()Returns the portion of the path up to the last forward slash; this is the directory or folder portion of the Resource.java.lang.StringgetPath()Return the path (the combination of folder and file).booleanisVirtual()Returns true if the resource is virtual, meaning this is no underlying file.protected abstract ResourcenewResource(java.lang.String path)Factory method provided by subclasses.java.io.InputStreamopenStream()Obtains the URL for the Resource and opens the stream, wrapped by a BufferedInputStream.protected voidvalidateURL(java.net.URL url)Validates that the URL is correct; at this time, a correct URL is one of: null a non-file: URL a file: URL where the case of the file matches the corresponding path element See TAP5-1007ResourcewithExtension(java.lang.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 org.apache.tapestry5.commons.internal.util.LockSupport
acquireReadLock, downgradeWriteLockToReadLock, releaseReadLock, releaseWriteLock, takeWriteLock, upgradeReadLockToWriteLock
-
-
-
-
Constructor Detail
-
AbstractResource
protected AbstractResource(java.lang.String path)
-
-
Method Detail
-
getPath
public final java.lang.String getPath()
Description copied from interface:ResourceReturn the path (the combination of folder and file). Starting in 5.4, certain "virtual resources", may return an arbitrary value here.
-
getFile
public final java.lang.String getFile()
Description copied from interface:ResourceReturns the file portion of the Resource path, everything that follows the final forward slash. Starting in 5.4, certain kinds of "virtual resources" may return null here.
-
getFolder
public final java.lang.String getFolder()
Description copied from interface:ResourceReturns the portion of the path up to the last forward slash; this is the directory or folder portion of the Resource.
-
forFile
public final Resource forFile(java.lang.String relativePath)
Description copied from interface:ResourceReturns 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. Virtual resources (resources fabricated at runtime) return themselves.
-
forLocale
public final Resource forLocale(java.util.Locale locale)
Description copied from interface:ResourceReturns a localized version of the resource. May return null if no such resource exists. Starting in release 5.3.4, the result of this method is cached internally.
-
withExtension
public final Resource withExtension(java.lang.String extension)
Description copied from interface:ResourceReturns 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,Resource.toURL()may return null.- Specified by:
withExtensionin interfaceResource- Parameters:
extension- to apply to the resource, such as "html" or "properties"- Returns:
- the new resource
-
exists
public boolean exists()
Simple check for whetherResource.toURL()returns null or not.
-
openStream
public java.io.InputStream openStream() throws java.io.IOException
Obtains the URL for the Resource and opens the stream, wrapped by a BufferedInputStream.- Specified by:
openStreamin interfaceResource- Returns:
- an open, buffered stream to the content, if available
- Throws:
java.io.IOException
-
newResource
protected abstract Resource newResource(java.lang.String path)
Factory method provided by subclasses.
-
validateURL
protected void validateURL(java.net.URL url)
Validates that the URL is correct; at this time, a correct URL is one of:- null
- a non-file: URL
- a file: URL where the case of the file matches the corresponding path element
- Parameters:
url- to validate- Since:
- 5.4
-
isVirtual
public boolean isVirtual()
Description copied from interface:ResourceReturns true if the resource is virtual, meaning this is no underlying file. Many operations are unsupported on virtual resources, includingResource.toURL(),Resource.forLocale(java.util.Locale),Resource.withExtension(String),Resource.getFile(),Resource.getFolder(),Resource.getPath()}; these operations will throw anUnsupportedOperationException.
-
-