org.greenstone.gs3client.data
Class DocumentNodeData

java.lang.Object
  extended by org.greenstone.gs3client.data.NodeData
      extended by org.greenstone.gs3client.data.DocumentNodeData

public class DocumentNodeData
extends NodeData

Represents the data stored in the <documentNode> Elements of Greenstone 3's XML response messages. A DocumentNodeData may have descendants of type DocumentNodeData. Some DocumentNodeData objects are the root of a structure, others are internal nodes or leaves. See p.47 to p.49 in the manual.

Author:
ak19

Field Summary
protected  DocumentNodeData[] childnodes
          children of this node: part of <nodeStructure> Element
 java.lang.String docType
          DocType can be Hierarchical for instance
protected  java.lang.String nodeContent
          The text content of the document
protected  java.util.HashMap nodeStructureInfo_map
          A Hashmap to store <nodeStructureInfo> of a DocumentNodeData (if it has any)
 java.lang.String nodeType
          NodeType of this DocumentNodeData: root, internal or leaf
 double rank
          Rank of this DocumentNodeData if the <documentNode> Element was returned in a search result
protected  DocumentNodeData rootDoc
          Reference to this doc's root
 
Fields inherited from class org.greenstone.gs3client.data.NodeData
hasChildren, nodeID, nodeMetadata, nodeTag
 
Constructor Summary
DocumentNodeData(org.w3c.dom.Element docNodeTag)
          Given tags of the form <documentNode nodeID="HASHac0a04dd14571c60d7fbfd.4.2" nodeType="x" docType="y"> <nodeContent>Text</nodeContent> <nodeStructureInfo><info name="i" value="1" /> <info name = "ii" value = "2" /></nodeStructureInfo> <metadataList><metadata name="a">Value </metadata></metadataList> <nodeStructure> <documentNode ....></documentNode> <documentNode ....></documentNode> </nodeStructure> </documentNode> this constructor extracts the nodeId out of it and any other fields that might be set in the docNodeTag <documentNode> element.
 
Method Summary
 boolean canBeImage()
           
protected static void descNodeIDsAsList(java.util.Vector v, DocumentNodeData parent, boolean onlyTheUntitled)
          Recursive method that adds all the nodeIDs of the descendents of DocumentNodeData parent into the Vector v.
 java.lang.String getAssocFilePath()
           
 java.util.Vector getAssociatedFileNames()
           
 NodeData[] getChildren()
           
 java.lang.String getContent()
           
 DocumentNodeData[] getDescendents()
           
 java.lang.String[] getDescNodeIDsAsList(boolean onlyTheUntitled)
          When called on a rootNode, returns an array of all the descendents' nodeIDs.
 java.lang.String getDocType()
           
 java.lang.String getImgName()
           
 java.lang.String getImgURL()
           
 java.lang.String getNodeType()
           
 DocumentNodeData getRoot()
           
 boolean hasNoText()
           
 boolean isLeaf()
           
protected  void setDescendents(DocumentNodeData root, org.w3c.dom.Element docNodeTag, java.util.Map nodeIDsToDocNodes_map)
          Recursive method.
 DocumentNodeData setDescendentsOfRootNode(org.w3c.dom.Element nodeStructure, java.util.Map nodeIDsToDocNodes_map)
          Given a <nodeStructure></nodeStructure> element returned from a request for the *ENTIRE* nodeStructure, this method will find the <documentNode> that is the Root (nodeType=ROOT) and from there on proceed to set all descendent <documentNode>s.
 void setNodeContent(org.w3c.dom.Element docNodeTag)
          Sets member variable nodeContent with the text (if any) inside any <nodeContent></nodeContent> child element of <documentNode>, else the value of nodeContent is set to empty string ("").
 void setNodeStructInfo(org.w3c.dom.Element docNodeTag)
          Sets structureInfo member variable <nodeStructureInfo> element is present as child of <documentNode>, else value of structureInfo remains unchanged.
 java.lang.String show()
           
 
Methods inherited from class org.greenstone.gs3client.data.NodeData
getMetadataList, getTitle, setChildren, setMetadataList, showMeta, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nodeType

public final java.lang.String nodeType
NodeType of this DocumentNodeData: root, internal or leaf


docType

public final java.lang.String docType
DocType can be Hierarchical for instance


rank

public final double rank
Rank of this DocumentNodeData if the <documentNode> Element was returned in a search result


rootDoc

protected DocumentNodeData rootDoc
Reference to this doc's root


childnodes

protected DocumentNodeData[] childnodes
children of this node: part of <nodeStructure> Element


nodeStructureInfo_map

protected java.util.HashMap nodeStructureInfo_map
A Hashmap to store <nodeStructureInfo> of a DocumentNodeData (if it has any)


nodeContent

protected java.lang.String nodeContent
The text content of the document

Constructor Detail

DocumentNodeData

public DocumentNodeData(org.w3c.dom.Element docNodeTag)
Given tags of the form <documentNode nodeID="HASHac0a04dd14571c60d7fbfd.4.2" nodeType="x" docType="y"> <nodeContent>Text</nodeContent> <nodeStructureInfo><info name="i" value="1" /> <info name = "ii" value = "2" /></nodeStructureInfo> <metadataList><metadata name="a">Value </metadata></metadataList> <nodeStructure> <documentNode ....></documentNode> <documentNode ....></documentNode> </nodeStructure> </documentNode> this constructor extracts the nodeId out of it and any other fields that might be set in the docNodeTag <documentNode> element.

Parameters:
docNodeTag - is an <documentNode> XML element to construct this DocumentNodeData object from
Method Detail

setDescendentsOfRootNode

public DocumentNodeData setDescendentsOfRootNode(org.w3c.dom.Element nodeStructure,
                                                 java.util.Map nodeIDsToDocNodes_map)
Given a <nodeStructure></nodeStructure> element returned from a request for the *ENTIRE* nodeStructure, this method will find the <documentNode> that is the Root (nodeType=ROOT) and from there on proceed to set all descendent <documentNode>s. If either the root or any descendent <documentNode>s have already been instantiated at any point during program execution, it will be reused, else a new object representing that descendent/root <documentNode> will be created. The nodeIDsToDocNodes_map is a mapping of nodeIDs to existing documentNodeData objects, so that the DocumentNodeData objects with the same ID need not be instantiated where they already exist. This method returns the rootNode if it completes successfully, otherwise it returns null.

Parameters:
nodeStructure - is the <nodeStructure></nodeStructure> element returned from a request for the *ENTIRE* nodeStructure
nodeIDsToDocNodes_map - is the Map of node IDs to DocumentNodeData objects being maintained
Returns:
the root DocumentNodeData object of the <documentNode>s in the <nodeStructure>

setDescendents

protected void setDescendents(DocumentNodeData root,
                              org.w3c.dom.Element docNodeTag,
                              java.util.Map nodeIDsToDocNodes_map)
Recursive method. Called by setDescendentsOfRootNode(). Given a docNodeTag (of the Root) which was nested within a <nodeStructure> element, this method sets all the descendents of that root. This means that each documentNodeData object in the hierarchy of the root will have its childnodes[] variable set, iff that object is not a nodeType==LEAF. With leaves, the childnodes array will remain null. The nodeIDsToDocNodes_map is a mapping of nodeIDs to existing documentNodeData objects, so that the DocumentNodeData objects with the same ID need not be instantiated where they already exist.

Parameters:
root - - the root element of this documentNodeData
docNodeTag - - the <documentNode> XML Element of the Root nested within a <nodeStructure> element
nodeIDsToDocNodes_map - is the Map of node IDs to DocumentNodeData objects being maintained

setNodeStructInfo

public void setNodeStructInfo(org.w3c.dom.Element docNodeTag)
Sets structureInfo member variable <nodeStructureInfo> element is present as child of <documentNode>, else value of structureInfo remains unchanged. A <docNode> has no more than one child <nodeStructureInfo> in a response to a DocumentStructureRetrieve. However, the response can contain many such <docNodes>. See manual p.49.

Parameters:
docNodeTag - is the <documentNode> XML element containing the <nodeStructureInfo> Element that is to be processed

setNodeContent

public void setNodeContent(org.w3c.dom.Element docNodeTag)
Sets member variable nodeContent with the text (if any) inside any <nodeContent></nodeContent> child element of <documentNode>, else the value of nodeContent is set to empty string (""). The empty string will prevent it from being retrieved again and again (which would happen if nodeContent remained at null) if it had already been retrieved once. However, if the docNodeTag parameter is not the response from a documentContentRetrieve (if it doesn't have the proper XML structure for that), nodeContent remains null and can be set in future when given an appropriate docNodeTag.

Parameters:
docNodeTag - is the <documentNode> XML element containing the content information for this DocumentNodeData object

show

public java.lang.String show()
Overrides:
show in class NodeData
Returns:
the data stored in this DocumentNodeData object, all except the document content which can be accessed by calling toString(). This method is useful for debugging purposes: to view what each field's values are.

isLeaf

public boolean isLeaf()
Returns:
true if the (nodeType of) this DocumentNodeData is a leaf

getNodeType

public java.lang.String getNodeType()
Returns:
the nodeType of this DocumentNodeData

getDocType

public java.lang.String getDocType()
Returns:
the docType of this DocumentNodeData

getRoot

public DocumentNodeData getRoot()
Returns:
the root of the structure of which this documentNodeData is part (this docNodeData is either the root itself or its child or descenedent). A null is returned if the Root docNode and its descendents have not been set yet.

getContent

public java.lang.String getContent()
Returns:
this document's text content (which may be empty string if there was none). It will return null if the nodeContent has not been set yet.

getDescendents

public DocumentNodeData[] getDescendents()
Returns:
an array of all this DocNode's children. Each childnode in turn, can further contain children, etc. Null is returned if there are no childnodes or if setDescendentsOfRootNode() has not been called (that is, if the root has not yet been set).

getChildren

public NodeData[] getChildren()
Specified by:
getChildren in class NodeData
Returns:
gets the children (NodeData) of this DocumentNodeData but does not guarantee that their children are set. That is, it's possible that this DocumentNodeData's children may have children of their own but that these may not be set yet (and are temporarily still null).

getDescNodeIDsAsList

public java.lang.String[] getDescNodeIDsAsList(boolean onlyTheUntitled)
When called on a rootNode, returns an array of all the descendents' nodeIDs. If this object is not a rootNode, it returns null. Parameter onlyTheUntitled, if true, makes this method return only the nodeIDs of those documentNodeData descendents for whom the title has not yet been set. If false, the nodeIDs of all dDcumentNodeData descendents will be returned, regardless of whether their titles are already set.

Parameters:
onlyTheUntitled - - if true this method is only to return those descendants' IDs whose titles have not yet been set. If false, all descendants' nodeIDs are returned.
Returns:
an array of all the descendant DocumentNodeData's NodeIDs

descNodeIDsAsList

protected static void descNodeIDsAsList(java.util.Vector v,
                                        DocumentNodeData parent,
                                        boolean onlyTheUntitled)
Recursive method that adds all the nodeIDs of the descendents of DocumentNodeData parent into the Vector v. If parameter onlyTheUntitled=true, then only the nodeIDs of the untitled DocumentNodeData descendents are added in. Otherwise, all descendents' nodeIDs are.

Parameters:
v - is the Vector being populated with descendant documentNodeData's IDs.
parent - is the parent DocumentNodeData node currently being considered in this recursion step.
onlyTheUntitled - should be true if only those descendant DocumentNodeData objects that don't yet have a title need to be returned. If false, it returns all descendants' nodeIDs in the Vector v.

canBeImage

public boolean canBeImage()
Returns:
true if this documentNode's root is associated with the ImagePlug or PagedImgPlug.
See Also:
The scanned image collection, for names of Plugin metadata values PagedImgPlug and ImagePlug

hasNoText

public boolean hasNoText()
Returns:
value of "notext" metadata field, if any. If true, this indicates that the document is purely an image. Otherwise it indicates that there is both a text view and an image view associated with this document.

getImgURL

public java.lang.String getImgURL()
Returns:
the image url stored in the "srcicon" metadata field, if any.

getImgName

public java.lang.String getImgName()
Returns:
the Source metadata value which represents the image file name. Returns "" if this DocumentNodeData is not a root or does not have Source meta.

getAssociatedFileNames

public java.util.Vector getAssociatedFileNames()
Returns:
the vector of values for metadata name "gsdlassocfile": a vector of MetaPairs(filename, mimetype). An empty vector is returned for all docNodes other than the root. And the root too need not always have associated files listed in its metadata.

getAssocFilePath

public java.lang.String getAssocFilePath()
Returns:
the root document's assocfilepath metadata field, if any. This will indicate the directory path where the associated images and other files are stored.