Package ome.services.blitz.repo
Class CheckedPath
- java.lang.Object
-
- ome.services.blitz.repo.CheckedPath
-
public class CheckedPath extends java.lang.Object
To prevent frequently re-calculating paths and re-creating File objects,CheckedPath
objects store various interpretations of paths that are passed in by users. One of these objects should be created at the very beginning of anyPublicRepositoryI
remote method (i.e. those public methods which takeCurrent
instance arguments. Methods are then available to check various capabilities by the current user. When a nullCheckedPath
object is passed into the constructor the caller indicates that the path is the root path, henceisRoot
will not be called.
-
-
Constructor Summary
Constructors Constructor Description CheckedPath(ServerFilePathTransformer serverPaths, java.lang.String path, ome.util.checksum.ChecksumProviderFactory checksumProviderFactory, ChecksumAlgorithm checksumAlgorithm)
Construct a CheckedPath from a relative "/"-delimited path rooted at the repository.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ome.model.core.OriginalFile
asOriginalFile(java.lang.String mimetype)
Creates anOriginalFile
instance for the givenCheckedPath
even if it doesn't exist.void
bfSetId(loci.formats.ReaderWrapper reader)
Perform BioFormatsReaderWrapper.setId(String)
for this file.boolean
canEdit()
boolean
canRead()
Check if this file is actually readable on the underlying filesystem.CheckedPath
child(java.lang.String name)
Returns a newCheckedPath
that has the given path appended to the end of this instances path.boolean
equals(java.lang.Object object)
Instances are equal if their string representations match.boolean
exists()
Check if this file actually exists on the underlying filesystem.protected java.lang.String
getDirname()
Assuming this is a directory, return relative path plus name with a final slash.ome.io.nio.FileBuffer
getFileBuffer(java.lang.String mode)
Get aFileBuffer
corresponding to this instance.protected java.lang.String
getFullFsPath()
The full path of the entity to which this path corresponds.java.lang.Long
getId()
java.lang.String
getMimetype()
Get the mimetype for a file.protected java.lang.String
getName()
Get the last component of this path, the entity to which the path corresponds.protected java.lang.String
getRelativePath()
Get the parent path of the entity to which this path corresponds.java.lang.String
hash()
int
hashCode()
On Windows systems the calculation is not case-sensitive.boolean
isDirectory()
boolean
markModified()
Mark this existing file as having been modified at the present moment.boolean
mkdir()
Create this directory on the underlying filesystem.boolean
mkdirs()
Create this directory, and parents if necessary, on the underlying filesystem.CheckedPath
mustEdit()
CheckedPath
mustExist()
Checks for existence of the original path, throwing an exception if not present.CheckedPath
parent()
Returns a newCheckedPath
usingFile.getParent()
and passing in all other values.void
setId(java.lang.Long id)
boolean
setReadOnly()
Mark the underlyingFile
as read-only and return true if the operation was successful.long
size()
Return the size of this file on the underlying filesystem.java.lang.String
toString()
-
-
-
Field Detail
-
fsFile
public final FsFile fsFile
-
isRoot
public boolean isRoot
-
id
protected java.lang.Long id
-
hash
protected java.lang.String hash
-
mime
protected java.lang.String mime
-
-
Constructor Detail
-
CheckedPath
public CheckedPath(ServerFilePathTransformer serverPaths, java.lang.String path, ome.util.checksum.ChecksumProviderFactory checksumProviderFactory, ChecksumAlgorithm checksumAlgorithm) throws ValidationException
Construct a CheckedPath from a relative "/"-delimited path rooted at the repository. The path may not contain weird or special-meaning path components, though.
and..
are understood to have their usual meaning. An empty path is the repository root.- Parameters:
serverPaths
- the server path handling servicepath
- a repository pathchecksumProviderFactory
- a source of checksum providers, may benull
ifchecksumAlgorithm
is alsonull
checksumAlgorithm
- the algorithm to use inhash()
's calculations- Throws:
ValidationException
- if the path is empty or contains illegal components
-
-
Method Detail
-
getId
public java.lang.Long getId()
-
setId
public void setId(java.lang.Long id)
-
hash
public java.lang.String hash()
-
getMimetype
public java.lang.String getMimetype()
Get the mimetype for a file.- Returns:
- A String representing the mimetype.
-
parent
public CheckedPath parent() throws ValidationException
Returns a newCheckedPath
usingFile.getParent()
and passing in all other values. Just as if calling the constructor, bad paths will cause aValidationException
to be thrown.CheckedPath
s generated with this method always return anull
hash.- Throws:
ValidationException
-
child
public CheckedPath child(java.lang.String name) throws ValidationException
Returns a newCheckedPath
that has the given path appended to the end of this instances path. A check is made that the name does not contain "/" (i.e. subpaths) nor that it is ".." or ".".CheckedPath
s generated with this method always return anull
hash.- Parameters:
name
-- Returns:
- See above.
- Throws:
ValidationException
-
exists
public boolean exists()
Check if this file actually exists on the underlying filesystem. Analogous toFile.exists()
.- Returns:
true
if the file exists,false
otherwise
-
mustExist
public CheckedPath mustExist() throws ValidationException
Checks for existence of the original path, throwing an exception if not present.- Returns:
- this instance for chaining.
- Throws:
ValidationException
-
mustEdit
public CheckedPath mustEdit() throws SecurityViolation
- Returns:
- this instance for chaining
- Throws:
SecurityViolation
-
canRead
public boolean canRead()
Check if this file is actually readable on the underlying filesystem. Analogous toFile.canRead()
.- Returns:
true
if the file is readable,false
otherwise
-
canEdit
public boolean canEdit()
-
isDirectory
public boolean isDirectory()
-
getDirname
protected java.lang.String getDirname()
Assuming this is a directory, return relative path plus name with a final slash.
-
getName
protected java.lang.String getName()
Get the last component of this path, the entity to which the path corresponds. If this entityisRoot
then this is the empty string.- Returns:
- the last path component
-
getRelativePath
protected java.lang.String getRelativePath()
Get the parent path of the entity to which this path corresponds. If this entity is not in some sub-directory below root, then this relative path is just theFsFile.separatorChar
.- Returns:
- the path components above the last,
with separators including a trailing
FsFile.separatorChar
.
-
getFullFsPath
protected java.lang.String getFullFsPath()
The full path of the entity to which this path corresponds. Path components are separated byFsFile.separatorChar
.- Returns:
- the full path
-
getFileBuffer
public ome.io.nio.FileBuffer getFileBuffer(java.lang.String mode)
Get aFileBuffer
corresponding to this instance. It is the caller's responsibility toFileBuffer.close()
it.- Parameters:
mode
- as forRandomAccessFile(File, String)
,"r"
and"rw"
being common choices- Returns:
- a new
FileBuffer
-
size
public long size()
Return the size of this file on the underlying filesystem. Analogous toFile.length()
.- Returns:
- the file size
-
mkdir
public boolean mkdir()
Create this directory on the underlying filesystem. Analogous toFile.mkdir()
.- Returns:
true
if the directory was created,false
otherwise
-
setReadOnly
public boolean setReadOnly()
Mark the underlyingFile
as read-only and return true if the operation was successful.
-
mkdirs
public boolean mkdirs()
Create this directory, and parents if necessary, on the underlying filesystem. Analogous toFile.mkdirs()
.- Returns:
true
if the directory was created,false
otherwise
-
markModified
public boolean markModified()
Mark this existing file as having been modified at the present moment.- Returns:
true
if the file's modification time was updated,false
otherwise
-
bfSetId
public void bfSetId(loci.formats.ReaderWrapper reader) throws loci.formats.FormatException, java.io.IOException
Perform BioFormatsReaderWrapper.setId(String)
for this file.- Parameters:
reader
- the BioFormats reader upon which to operate- Throws:
loci.formats.FormatException
- passed up fromReaderWrapper.setId(String)
java.io.IOException
- passed up fromReaderWrapper.setId(String)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
asOriginalFile
public ome.model.core.OriginalFile asOriginalFile(java.lang.String mimetype)
Creates anOriginalFile
instance for the givenCheckedPath
even if it doesn't exist. If it does exist, then the size and hash will be properly set. Further, if it's a directory, the mimetype passed in by the user must either be null, in which case "Directory" will be used, or must be that correct value.- Parameters:
mimetype
- The mimetype to handle.- Returns:
- See above.
-
equals
public boolean equals(java.lang.Object object)
Instances are equal if their string representations match. On Windows systems the comparison is not case-sensitive.- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
On Windows systems the calculation is not case-sensitive.- Overrides:
hashCode
in classjava.lang.Object
-
-