org.bibalex.daf.entities.phase
Class FolderElement

java.lang.Object
  extended by org.bibalex.daf.entities.phase.PhysicalElement
      extended by org.bibalex.daf.entities.phase.FolderElement

public class FolderElement
extends PhysicalElement

Represents the folder definition within the physical section of a phase.
The FolderElement capabilities are not limited to parsing XML and converting it to an object.
The following are also included:
1) Count the number of the files within the folder. See getFilesCount().
2) Copy the folder form a given folder to another. See uploadFolder() and downloadFolder().
3) Get the number of modified files after a given date. See getModifiedFilesCount()

Author:
Shehab.Kamal

Field Summary
 boolean create
          The 'Create' property of the element.
 java.lang.String mode
          The 'Mode' property of the element.
 java.lang.String name
          The 'Name' property of the element.
 java.lang.String newName
          The 'NewName' property of the element.
private  java.util.ArrayList<PhysicalElement> subElements
          The physical elements that are contained within this FolderElement
 boolean toDestination
          The 'ToDestination' property of the element.
 
Constructor Summary
FolderElement()
          Creates a new instance of FolderElement.
FolderElement(org.w3c.dom.Node node)
          Creates a new instance of FolderElement.
FolderElement(java.lang.String nodeRep)
          Creates a new instance of FolderElement.
FolderElement(java.lang.String name, boolean toDestination, java.lang.String newName, java.lang.String mode, boolean create)
          Creates a new instance of FolderElement.
 
Method Summary
 void addChild(PhysicalElement element)
          Adds the given element to the list of sub-elements.
private  void addChildren(org.w3c.dom.Node parent)
          Adds the children of the given node to the list of children of this element.
private  void createElementFromNode(org.w3c.dom.Node node)
          Creates the folder element by supplying its XmlNode represenation.
 boolean downloadFolder(java.lang.String source, java.lang.String destination, FileHandler handler)
          Downloads this folder.
 PhysicalElement[] getChildren()
          Gets the children contained within this folder.
 int getFilesCount(java.lang.String folderPath, FileHandler handler)
          Gets the total number of files within the folder recursively.
 int getModifiedFilesCount(java.lang.String path, FileHandler handler, java.util.Date startDate)
          Gets the number of the files modified after startDate within the given folder.
 FileElement[] getSubFiles()
          Gets the files defined within this FolderElement.
 FolderElement[] getSubFolders()
          Gets the folders defined within this FolderElement.
 void makeFilesReadOnly(java.lang.String folderPath, FileHandler handler)
          Makes the files within the folder read-only.
 void swapNameAndNewName()
          Swaps the 'Name' with the 'NewName'.
private  java.lang.String tabifyString(java.lang.String in)
          Adds tab to each line of the given String.
 java.lang.String toString()
          Returns the string representation of this object.
 java.lang.String toXmlString()
          Converts this instance to a valid XML string.
 boolean uploadFolder(java.lang.String source, java.lang.String destination, FileHandler handler)
          Uploads this folder.
 
Methods inherited from class org.bibalex.daf.entities.phase.PhysicalElement
createElement
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

public java.lang.String name
The 'Name' property of the element.


toDestination

public boolean toDestination
The 'ToDestination' property of the element.


newName

public java.lang.String newName
The 'NewName' property of the element.


mode

public java.lang.String mode
The 'Mode' property of the element.


create

public boolean create
The 'Create' property of the element.


subElements

private java.util.ArrayList<PhysicalElement> subElements
The physical elements that are contained within this FolderElement

Constructor Detail

FolderElement

public FolderElement(java.lang.String name,
                     boolean toDestination,
                     java.lang.String newName,
                     java.lang.String mode,
                     boolean create)
Creates a new instance of FolderElement.

Parameters:
name - The 'Name' property of the element.
toDestination - The 'ToDestination' property of the element.
newName - The 'NewName' property of the element.
mode - The 'Mode' property of the element.
create - The 'Create' property of the element.

FolderElement

public FolderElement()
Creates a new instance of FolderElement.


FolderElement

public FolderElement(org.w3c.dom.Node node)
              throws PhaseDefinitionException
Creates a new instance of FolderElement.

Parameters:
node - The Xml Node representing this element.
Throws:
PhaseDefinitionException - If the node couldn't be parsed.

FolderElement

public FolderElement(java.lang.String nodeRep)
              throws PhaseDefinitionException
Creates a new instance of FolderElement.

Parameters:
nodeRep - The Xml String representing this element.
Throws:
PhaseDefinitionException - If the given String couldn't be parsed.
Method Detail

createElementFromNode

private void createElementFromNode(org.w3c.dom.Node node)
                            throws PhaseDefinitionException
Creates the folder element by supplying its XmlNode represenation.

Parameters:
node - The Xml Node representing this element.
Throws:
PhaseDefinitionException - If the node name is not 'Folder', attributes are missing or couldn't add children.

addChildren

private void addChildren(org.w3c.dom.Node parent)
                  throws PhaseDefinitionException
Adds the children of the given node to the list of children of this element.

Parameters:
parent - The parent node to traverse its children.
Throws:
PhaseDefinitionException - If a child couldn't be added.

addChild

public void addChild(PhysicalElement element)
Adds the given element to the list of sub-elements.

Parameters:
element - The element to add.

getChildren

public PhysicalElement[] getChildren()
Gets the children contained within this folder.

Returns:
An array of type PhysicalElement containing the children or an empty array if there is no children.

getSubFolders

public FolderElement[] getSubFolders()
Gets the folders defined within this FolderElement.

Returns:
An array of type FolderElement containing the subfolders or an empty array if there is no subfolders.

getSubFiles

public FileElement[] getSubFiles()
Gets the files defined within this FolderElement.

Returns:
An array of type FileElement containing the subfiles or an empty array if there is no subfiles.

swapNameAndNewName

public void swapNameAndNewName()
Swaps the 'Name' with the 'NewName'.


toString

public java.lang.String toString()
Returns the string representation of this object.

Overrides:
toString in class java.lang.Object
Returns:
The string representation of this object.

tabifyString

private java.lang.String tabifyString(java.lang.String in)
Adds tab to each line of the given String.

Parameters:
in - The input string to tabify.
Returns:
The String with tabs added to the begining of each line.

toXmlString

public java.lang.String toXmlString()
Converts this instance to a valid XML string.

Specified by:
toXmlString in class PhysicalElement
Returns:
A valid XML string representing this instance.

makeFilesReadOnly

public void makeFilesReadOnly(java.lang.String folderPath,
                              FileHandler handler)
Makes the files within the folder read-only.

Parameters:
folderPath - The parent folder that contains this folder.
handler - The file handler used to make the files read-only.

getFilesCount

public int getFilesCount(java.lang.String folderPath,
                         FileHandler handler)
Gets the total number of files within the folder recursively.

Parameters:
folderPath - The path of the folder to count the files within it.
handler - The FileHanlder used to count the files.
Returns:
The total number of files within the folder.

downloadFolder

public boolean downloadFolder(java.lang.String source,
                              java.lang.String destination,
                              FileHandler handler)
Downloads this folder.

Parameters:
source - The parent folder that contains this folder.
destination - The parent folder that will conatin this folder.
handler - The file handler used to downlaod the folder.
Returns:
True if the folder has been downloaded successfully otherwise flase.

uploadFolder

public boolean uploadFolder(java.lang.String source,
                            java.lang.String destination,
                            FileHandler handler)
Uploads this folder.

Parameters:
source - The parent folder that contains this folder.
destination - The parent folder that will conatin this folder.
handler - The file handler used to downlaod the folder.
Returns:
True if the folder has been uploaded successfully otherwise flase.

getModifiedFilesCount

public int getModifiedFilesCount(java.lang.String path,
                                 FileHandler handler,
                                 java.util.Date startDate)
Gets the number of the files modified after startDate within the given folder. The folder is visited recursively.

Parameters:
path - The path of the folder containing the folder.
handler - The handler to get the count of folder.
startDate - The date to count the files modified after it. This parameter can be null.
Returns:
The number of files modified after the given date.
If the start date is not specified all the files are considered as modified.
-1 in the following cases:
1) If path is null or empty string.
2) If handler is null.
3) If the files within the folder couldn't be obtained.