?? attribute.java~4~
字號(hào):
package XML;
import java.util.*;
//import Utilities.*;
/**
* <p>Title: Moto EMS Tool</p>
* <p>Description: 摩托羅拉 EMS 工具</p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: 北京映翰通網(wǎng)絡(luò)技術(shù)有限公司</p>
* @author 韓傳俊 shock2000@21cn.com
* @version 1.0
*/
public class Attribute{
protected String name;
protected String value;
public Attribute(){
this.name="";
this.value="";
}
public Attribute(Attribute attr){
this.name=attr.name;
this.value=attr.value;
}
public Attribute(String name,String value) {
this.name=name;
this.value=value;
}
public Attribute(String name,int value) {
this.name=name;
this.value=""+value;
}
//屬性值是FLOAT型(如 "version='1.0'")的處理
public Attribute(String name,double value){
this.name=name;
this.value=""+value;
}
public String toString(){
String result="";
if (!name.equals("")){
result=name+"=\""+value+"\"";
}
return result;
}
public static Attribute getAttribute(String attr){
//System.out.println("in Attribute.getAttribute():"+attr);
StringTokenizer st=new StringTokenizer(attr,"=");
Attribute at=new Attribute();
if (st.hasMoreTokens()){
String nam=st.nextToken();
at.setName(nam.trim());
String v=st.nextToken();
//System.out.println(v);
at.setValue(Attribute.getXMLAttributeValue(v));
}
String temp=attr.trim();
return at;
}
public static Vector getAttributes(String eleStr){
String[] str=Attribute.getXMLAttributeStr(eleStr);
Vector attrs=new Vector();
for (int i=0;i<str.length;i++){
System.out.println(str[i]);
attrs.add(Attribute.getAttribute(str[i]));
}
return attrs;
}
protected static String getXMLAttributeValue(String str){
String temp=str.trim();
//System.out.println(temp);
int start=temp.indexOf("\"");
int end=temp.lastIndexOf("\"");
String result=temp.substring(start+1,end);
return result;
}
protected static String[] getXMLAttributeStr(String str){
String temp=str.trim();
StringTokenizer st=new StringTokenizer(temp,"=");
//System.out.println("in Utility.getXMLAttributeStr()\t\ntemp: "+temp);
int num=st.countTokens()-1;
//System.out.println("in Utility.getXMLAttributeStr()\t\nnum: "+num);
String[] results=new String[num];
String substr=temp;
int i=0;
int j=0;
while((i=substr.indexOf("\""))!=-1){
//System.out.println("in Utility.getXMLAttributeStr()\t\ni: "+i);
results[j]=substr.substring(0,i+1);
substr=substr.substring(i+1,substr.length());
//System.out.println("in Utility.getXMLAttributeStr()\t\nsubstr: "+substr);
//if((i=substr.indexOf("\""))==-1){
// i=substr.length();
//}
i=substr.indexOf("\"");
results[j]+=substr.substring(0,i+1);
substr=substr.substring(i+1,substr.length());
//substr.trim();
j++;
//System.out.println("in Utility.getXMLAttributeStr()\t\nj: "+j);
}
return results;
}
public void setName(String name){
this.name=name;
}
public void setValue(String value){
this.value=value;
}
public void setValue(int value) {
this.value=""+value;
}
public void setValue(double value) {
this.value=""+value;
}
public String getName(){
return this.name;
}
public String getValue(){
return this.value;
}
public static void main(String args[]){
//Attribute attr=new Attribute("version",1.2);
//System.out.println(attr);
Attribute.getAttribute("version=\"1.2\"");
Attribute.getAttribute(" version=\"1.2\"");
Attribute.getAttribute("content=\"this is a dog!\" ");
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -