//*********************************************************************************
// CLASS: jetheme.util.tree.DOMTreeNode.java
//*********************************************************************************
package tig.util.tree;
import org.w3c.dom.*;
/**********************************************************************************
Classe encapsulant un org.w3c.dom.Node, utilisée par DOMTreeModel pour être représentée par un JTree.
@author Thierry Graff
07/08/2000 : création
**********************************************************************************/
public class DOMTreeNode {
//*********************************************************************************
//************************** FIELDS ***********************************************
//*********************************************************************************
/** */
private org.w3c.dom.Node domNode;
/** Tableau contenant les types de noeud que peut contenir un arbre DOM.
Provient des commentaires de org.w3c.dom.Node. */
static final String[] typeName = {
"none",
"Element",
"Attr",
"Text",
"CDATA",
"EntityRef",
"Entity",
"ProcInstr",
"Comment",
"Document",
"DocType",
"DocFragment",
"Notation",
};
static final int ELEMENT_TYPE = 1;
static final int ATTR_TYPE = 2;
static final int TEXT_TYPE = 3;
static final int CDATA_TYPE = 4;
static final int ENTITYREF_TYPE = 5;
static final int ENTITY_TYPE = 6;
static final int PROCINSTR_TYPE = 7;
static final int COMMENT_TYPE = 8;
static final int DOCUMENT_TYPE = 9;
static final int DOCTYPE_TYPE = 10;
static final int DOCFRAG_TYPE = 11;
static final int NOTATION_TYPE = 12;
//*********************************************************************************
//************************* METHODES **********************************************
//*********************************************************************************
//**************************************
public DOMTreeNode(org.w3c.dom.Node node){
this.domNode=node;
} //fin DOMTreeNode
//**************************************
public String toString(){
String rep = typeName[this.domNode.getNodeType()];
rep += " : ";
String nodeName=this.domNode.getNodeName();
if(!nodeName.startsWith("#"))
rep+=nodeName;
if (this.domNode.getNodeValue()!=null)
rep = rep + this.domNode.getNodeValue().trim().replace('\n', ' ').replace('\t', ' ');
return rep;
} //fin toString
//**************************************
public int getChildCount(){
return this.domNode.getChildNodes().getLength();
} //fin childCount
//**************************************
public DOMTreeNode getChild(int index){
org.w3c.dom.Node aDOMNode = this.domNode.getChildNodes().item(index);
return new DOMTreeNode(aDOMNode);
} //fin childCount
//**************************************
public int getIndexOfChild(DOMTreeNode theChild){
int childCount = this.getChildCount();
for (int i=0;i<childCount;i++){
DOMTreeNode tempChild = this.getChild(i);
if (theChild==tempChild)
return i;
}
return - 1; //ne doit jamais arriver.
} //fin getIndexOfChild
} //fin public class DOMTreeNode