org.mycore.datamodel.ifs2
Class MCRNode

java.lang.Object
  extended by org.mycore.datamodel.ifs2.MCRNode
Direct Known Subclasses:
MCRStoredNode, MCRVirtualNode

public abstract class MCRNode
extends Object

Represents a file, directory or file collection within a file store. Files and directories can be either really stored, or virtually existing as a child node contained within a stored container file like zip or tar.

Author:
Frank Lützenkirchen

Field Summary
protected  org.apache.commons.vfs.FileObject fo
          The file object representing this node in the underlying filesystem.
protected  MCRNode parent
          The parent node owning this file, a directory or container file
 
Constructor Summary
protected MCRNode(MCRNode parent, org.apache.commons.vfs.FileObject fo)
          Creates a new node representing a child of the given parent
 
Method Summary
protected abstract  MCRNode buildChildNode(org.apache.commons.vfs.FileObject fo)
          Creates a node instance for the given FileObject, which represents the child
 MCRNode getChild(String name)
          Returns the child node with the given filename, or null
 List<MCRNode> getChildren()
          Returns the children of this node.
 MCRContent getContent()
          Returns the content of this node for output.
 Date getLastModified()
          Returns the time this node was last modified, or null if no such time is defined in the underlying filesystem
 String getName()
          Returns the file or directory name
 MCRNode getNodeByPath(String path)
          Returns the node with the given relative or absolute path in the file collection this node belongs to.
 int getNumChildren()
          Returns the number of child nodes of this node.
 MCRNode getParent()
          Returns the parent node containing this node
 String getPath()
          Returns the complete path of this node up to the root file collection.
 org.apache.commons.vfs.RandomAccessContent getRandomAccessContent()
          Returns the content of this node for random access read.
 MCRFileCollection getRoot()
          Returns the root file collection this node belongs to
 long getSize()
          For file nodes, returns the file content size in bytes, otherwise returns 0.
 boolean hasChildren()
          Returns true if this node has child nodes.
 boolean isDirectory()
          Returns true if this node is a directory
 boolean isFile()
          Returns true if this node is a file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fo

protected org.apache.commons.vfs.FileObject fo
The file object representing this node in the underlying filesystem.


parent

protected MCRNode parent
The parent node owning this file, a directory or container file

Constructor Detail

MCRNode

protected MCRNode(MCRNode parent,
                  org.apache.commons.vfs.FileObject fo)
Creates a new node representing a child of the given parent

Parameters:
parent - the parent node
fo - the file object representing this node in the underlying filesystem
Method Detail

getName

public String getName()
Returns the file or directory name

Returns:
the node's filename

getPath

public String getPath()
               throws Exception
Returns the complete path of this node up to the root file collection. Path always start with a slash, slash is used as directory delimiter.

Returns:
the absolute path of this node
Throws:
Exception

getParent

public MCRNode getParent()
Returns the parent node containing this node

Returns:
the parent directory or container file

getRoot

public MCRFileCollection getRoot()
Returns the root file collection this node belongs to

Returns:
the root file collection

isFile

public boolean isFile()
               throws Exception
Returns true if this node is a file

Returns:
true if this node is a file
Throws:
Exception

isDirectory

public boolean isDirectory()
                    throws Exception
Returns true if this node is a directory

Returns:
true if this node is a directory
Throws:
Exception

getSize

public long getSize()
             throws Exception
For file nodes, returns the file content size in bytes, otherwise returns 0.

Returns:
the file size in bytes
Throws:
Exception

getLastModified

public Date getLastModified()
                     throws Exception
Returns the time this node was last modified, or null if no such time is defined in the underlying filesystem

Returns:
the time this node was last modified
Throws:
Exception

hasChildren

public boolean hasChildren()
                    throws Exception
Returns true if this node has child nodes. Directories and container files like zip or tar may have child nodes.

Returns:
true if children exist
Throws:
Exception

getNumChildren

public int getNumChildren()
                   throws Exception
Returns the number of child nodes of this node.

Returns:
the number of child nodes of this node.
Throws:
Exception

getChildren

public List<MCRNode> getChildren()
                          throws Exception
Returns the children of this node. Directories and container files like zip or tar may have child nodes.

Returns:
a List of child nodes, which may be empty, in undefined order
Throws:
Exception

buildChildNode

protected abstract MCRNode buildChildNode(org.apache.commons.vfs.FileObject fo)
                                   throws Exception
Creates a node instance for the given FileObject, which represents the child

Parameters:
fo - the FileObject representing the child in the underlying filesystem
Returns:
the child node
Throws:
Exception

getChild

public MCRNode getChild(String name)
                 throws Exception
Returns the child node with the given filename, or null

Parameters:
name - the name of the child node
Returns:
the child node with that name, or null when no such file exists
Throws:
Exception

getNodeByPath

public MCRNode getNodeByPath(String path)
                      throws Exception
Returns the node with the given relative or absolute path in the file collection this node belongs to. Slash is used as directory delimiter. When the path starts with a slash, it is an absolute path and resolving is startet at the root file collection. When the path is relative, resolving starts with the current node. One dot represents the current node, Two dots represent the parent node, like in paths used by typical real filesystems.

Parameters:
path - the absolute or relative path of the node to find, may contain . or ..
Returns:
the node at the given path, or null
Throws:
Exception

getContent

public MCRContent getContent()
                      throws Exception
Returns the content of this node for output. For a directory, it will return null.

Returns:
the content of the file
Throws:
Exception

getRandomAccessContent

public org.apache.commons.vfs.RandomAccessContent getRandomAccessContent()
                                                                  throws Exception
Returns the content of this node for random access read. Be sure not to write to the node using the returned object, use just for reading! For a directory, it will return null.

Returns:
the content of this file, for random access
Throws:
Exception