Class VirtualResource
- java.lang.Object
-
- org.apache.tapestry5.internal.util.VirtualResource
-
- All Implemented Interfaces:
Resource
- Direct Known Subclasses:
ClientLocalizationMessageResource,MessageCatalogResource,UrlResource
public abstract class VirtualResource extends java.lang.Object implements Resource
Base class for virtual resources: resources that are not simply mapped to stored files, but are assembled, as necessary, on the fly. This is used inside Tapestry to expose the application's localized message catalog as a module. Subclasses should implement theResource.openStream()method to return a stream of the contents of the virtual resource.- Since:
- 5.4
- See Also:
ModuleManager,ModuleDispatcher
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.nio.charset.CharsetUTF8
-
Constructor Summary
Constructors Constructor Description VirtualResource()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanexists()Returns true if the resource exists; if a stream to the content of the file may be opened.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 java.io.InputStreamtoInputStream(byte[] content)protected java.io.InputStreamtoInputStream(java.lang.String content)java.net.URLtoURL()Returns the URL for the resource, or null if it does not exist.ResourcewithExtension(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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.tapestry5.commons.Resource
openStream
-
-
-
-
Field Detail
-
UTF8
protected static final java.nio.charset.Charset UTF8
-
-
Constructor Detail
-
VirtualResource
public VirtualResource()
-
-
Method Detail
-
exists
public boolean exists()
Description copied from interface:ResourceReturns true if the resource exists; if a stream to the content of the file may be opened. A resource exists ifResource.toURL()returns a non-null value. Starting in release 5.3.4, the result of this is cached. Starting in 5.4, some "virtual resources", may return true even thoughResource.toURL()returns null.
-
toURL
public java.net.URL toURL()
Description copied from interface:ResourceReturns the URL for the resource, or null if it does not exist. This value is lazily computed; starting in 5.3.4, subclasses may cache the result. Starting in 5.4, some "virtual resources" may return null.
-
forLocale
public 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.
-
forFile
public 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.
-
withExtension
public 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
-
getFolder
public 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.
-
getFile
public 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.
-
getPath
public 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.
-
toInputStream
protected java.io.InputStream toInputStream(java.lang.String content) throws java.io.IOException
- Throws:
java.io.IOException
-
toInputStream
protected java.io.InputStream toInputStream(byte[] content) throws java.io.IOException
- Throws:
java.io.IOException
-
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.
-
-