Package org.ringojs.repository
Class AbstractResource
- java.lang.Object
-
- org.ringojs.repository.AbstractResource
-
- Direct Known Subclasses:
FileResource
,WebappResource
,ZipResource
public abstract class AbstractResource extends java.lang.Object implements Resource
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
baseName
protected java.lang.String
name
protected java.lang.String
path
protected AbstractRepository
repository
-
Constructor Summary
Constructors Constructor Description AbstractResource()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.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 encodingint
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 foundboolean
isAbsolute()
Return true if this Resource is in absolute mode.void
setAbsolute(boolean absolute)
Set this Resource to absolute mode.protected void
setBaseNameFromName(java.lang.String name)
void
setStripShebang(boolean stripShebang)
Switch shebang stripping on or offprotected java.io.InputStream
stripShebang(java.io.InputStream stream)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.ringojs.repository.Resource
getInputStream, getLength
-
Methods inherited from interface org.ringojs.repository.Trackable
exists, getUrl, lastModified
-
-
-
-
Field Detail
-
repository
protected AbstractRepository repository
-
path
protected java.lang.String path
-
name
protected java.lang.String name
-
baseName
protected java.lang.String baseName
-
-
Method Detail
-
setBaseNameFromName
protected void setBaseNameFromName(java.lang.String name)
-
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.
-
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
-
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
-
stripShebang
protected java.io.InputStream stripShebang(java.io.InputStream stream) throws java.io.IOException
- Throws:
java.io.IOException
-
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()
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
-
getModuleName
public java.lang.String getModuleName()
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
-
getChecksum
public long getChecksum()
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
-
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
-
setAbsolute
public void setAbsolute(boolean absolute)
Set this Resource 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()
Return true if this Resource is in absolute mode.- Specified by:
isAbsolute
in interfaceTrackable
- Returns:
- true if absolute mode is on
-
-