📄 node.java
字号:
package org.gggeye.easymf.xml;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
/** *//**
* @author shizhongqin
* @date 2006-5-1
* mail:shizhongqin@gmail.com
*/
public class Node {
private String name;
private Node parent;
private String value;
private String description;
private Hashtable attributes=new Hashtable();
private Vector childNodes=new Vector();
public Node(String name){
this.name=name;
}
public String getName(){
return this.name;
}
public void setName(String name){
this.name=name;
}
public String getValue(){
return this.value;
}
public void setValue(String value){
this.value=value;
}
public void setAttribute(String name,String value){
this.attributes.put(name,value);
}
public String getAttribute(String attributeName){
return (String)attributes.get(attributeName);
}
public void setDescription(String desc){
this.description=desc;
}
public String getDescription(){
return this.description;
}
public void setParent(Node parent){
this.parent=parent;
}
public Node getParent(){
return this.parent;
}
public void addChild(Node childNode){
this.childNodes.addElement(childNode);
childNode.setParent(this);
}
public String toString(){
StringBuffer xml=new StringBuffer();
if ((this.getDescription()!=null)&&(this.getDescription().length()>0))
xml.append("<!--"+this.getDescription()+"--> ");
xml.append("<");
xml.append(this.getName());
Enumeration keys=this.attributes.elements();
while(keys.hasMoreElements()){
String key=(String)keys.nextElement();
String value=(String)this.attributes.get(key);
xml.append(" "+ key+ "=" + value + " ");
}
if (((this.getValue()==null)||(this.getValue().length()==0))&&(this.childNodes.size()==0)){
xml.append(" /> ");
}else{
xml.append(" >");
if ((this.getValue()!=null)&&(this.getValue().length()>0)){
xml.append(this.getValue());
}
for(int i=0;i<this.childNodes.size();i++)
xml.append(((Node)this.childNodes.elementAt(i)).toString());
xml.append("</"+this.getName()+"> ");
}
return xml.toString();
}
public Hashtable getAttributes() {
return attributes;
}
public Vector getChildNodes() {
return childNodes;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -