Package org.ringojs.repository
Class StringResource
- java.lang.Object
-
- org.ringojs.repository.StringResource
-
public class StringResource extends java.lang.Object implements Resource
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description StringResource(java.lang.String name, java.lang.String content)
StringResource(java.lang.String name, java.lang.String content, int lineNumber)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
exists()
Checks wether this resource actually (still) existsjava.lang.String
getBaseName()
Returns the short name of the resource with the file extension (everything following the last dot character) cut off.long
getChecksum()
Checksum of the resource content.java.lang.String
getContent()
Returns the content of the resourcejava.lang.String
getContent(java.lang.String encoding)
Returns the content of the resource in a given encodingjava.io.InputStream
getInputStream()
Returns an input stream to the content of the resourcelong
getLength()
Returns the length of the resource's contentint
getLineNumber()
Return the current line number of this resource.java.lang.String
getModuleName()
Utility method to get the name for the module defined by this resource.java.lang.String
getName()
Returns the short name of the resource.Repository
getParentRepository()
Returns the parent repository containing this resourcejava.lang.String
getPath()
Returns the path of the resource.java.io.Reader
getReader()
Returns a reader for the resourcejava.io.Reader
getReader(java.lang.String encoding)
Returns a reader for the resource using the given character encodingjava.lang.String
getRelativePath()
Get the path of this resource relative to its root repository.Repository
getRootRepository()
Returns the root repository of this resourceboolean
getStripShebang()
Returns true if the input stream for this resource will look for a first line starting with the characters #! and suppress it if foundjava.net.URL
getUrl()
Returns an url to the resource if the repository of this resource is able to provide urls.boolean
isAbsolute()
Return true if this Trackable is in absolute mode.long
lastModified()
Returns the date the resource was last modifiedvoid
setAbsolute(boolean absolute)
Set this Trackable to absolute mode.void
setStripShebang(boolean stripShebang)
Switch shebang stripping on or off
-
-
-
Method Detail
-
getBaseName
public java.lang.String getBaseName()
Description copied from interface:Resource
Returns the short name of the resource with the file extension (everything following the last dot character) cut off.- Specified by:
getBaseName
in interfaceResource
- Returns:
- the file name without the file extension
-
getLength
public long getLength()
Description copied from interface:Resource
Returns the length of the resource's content
-
getInputStream
public java.io.InputStream getInputStream() throws java.io.IOException
Description copied from interface:Resource
Returns an input stream to the content of the resource- Specified by:
getInputStream
in interfaceResource
- Returns:
- content input stream
- Throws:
java.io.IOException
- if a I/O related error occurs
-
getReader
public java.io.Reader getReader(java.lang.String encoding) throws java.io.IOException
Description copied from interface:Resource
Returns a reader for the resource using the given character encoding
-
getReader
public java.io.Reader getReader() throws java.io.IOException
Description copied from interface:Resource
Returns a reader for the resource
-
getContent
public java.lang.String getContent(java.lang.String encoding) throws java.io.IOException
Description copied from interface:Resource
Returns the content of the resource in a given encoding- Specified by:
getContent
in interfaceResource
- Parameters:
encoding
- the character encoding- Returns:
- the content
- Throws:
java.io.IOException
- if a I/O related error occurs
-
getContent
public java.lang.String getContent() throws java.io.IOException
Description copied from interface:Resource
Returns the content of the resource- Specified by:
getContent
in interfaceResource
- Returns:
- the content
- Throws:
java.io.IOException
- if a I/O related error occurs
-
getRelativePath
public java.lang.String getRelativePath()
Description copied from interface:Resource
Get the path of this resource relative to its root repository.- Specified by:
getRelativePath
in interfaceResource
- Specified by:
getRelativePath
in interfaceTrackable
- Returns:
- the relative resource path
-
getStripShebang
public boolean getStripShebang()
Description copied from interface:Resource
Returns true if the input stream for this resource will look for a first line starting with the characters #! and suppress it if found- Specified by:
getStripShebang
in interfaceResource
- Returns:
- true if shebang stripping is enabled
-
setStripShebang
public void setStripShebang(boolean stripShebang)
Description copied from interface:Resource
Switch shebang stripping on or off- Specified by:
setStripShebang
in interfaceResource
- Parameters:
stripShebang
- true to enable shebang stripping
-
getLineNumber
public int getLineNumber()
Description copied from interface:Resource
Return the current line number of this resource. Useful in combination with things like shebang stripping and shell input.- Specified by:
getLineNumber
in interfaceResource
- Returns:
- the current line number of this resource
-
lastModified
public long lastModified()
Description copied from interface:Trackable
Returns the date the resource was last modified- Specified by:
lastModified
in interfaceTrackable
- Returns:
- last modified date
-
getChecksum
public long getChecksum() throws java.io.IOException
Description copied from interface:Trackable
Checksum of the resource content. Implementations should make sure to return a different checksum if the resource's content has changed.- Specified by:
getChecksum
in interfaceTrackable
- Returns:
- checksum
- Throws:
java.io.IOException
-
exists
public boolean exists() throws java.io.IOException
Description copied from interface:Trackable
Checks wether this resource actually (still) exists
-
getPath
public java.lang.String getPath()
Description copied from interface:Trackable
Returns the path of the resource. The returned string must be in a form so that appending a child name produces a valid resource or repository name. Usually this means that it should end with a file separator character.
-
getName
public java.lang.String getName()
Description copied from interface:Trackable
Returns the short name of the resource.
-
getUrl
public java.net.URL getUrl() throws java.lang.UnsupportedOperationException, java.net.MalformedURLException
Description copied from interface:Trackable
Returns an url to the resource if the repository of this resource is able to provide urls.
-
getParentRepository
public Repository getParentRepository()
Description copied from interface:Trackable
Returns the parent repository containing this resource- Specified by:
getParentRepository
in interfaceTrackable
- Returns:
- parent repository
-
getRootRepository
public Repository getRootRepository()
Description copied from interface:Trackable
Returns the root repository of this resource- Specified by:
getRootRepository
in interfaceTrackable
- Returns:
- root repository
-
getModuleName
public java.lang.String getModuleName()
Description copied from interface:Trackable
Utility method to get the name for the module defined by this resource.- Specified by:
getModuleName
in interfaceTrackable
- Returns:
- the module name according to the securable module spec
-
setAbsolute
public void setAbsolute(boolean absolute)
Description copied from interface:Trackable
Set this Trackable to absolute mode. This will cause all its relative path operations to use absolute paths instead.- Specified by:
setAbsolute
in interfaceTrackable
- Parameters:
absolute
- true to operate in absolute mode
-
isAbsolute
public boolean isAbsolute()
Description copied from interface:Trackable
Return true if this Trackable is in absolute mode.- Specified by:
isAbsolute
in interfaceTrackable
- Returns:
- true if absolute mode is on
-
-