⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vcard.java

📁 网站即时通讯系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	}
	public void setAddress_Work_House(String value){
		if(value==null){return;}
		set=work_address=true;
		Address_Work_House=value;
	}
	public void setAddress_Work_Street(String value){
		if(value==null){return;}
		set=work_address=true;
		Address_Work_Street=value;
	}
	public void setAddress_Work_Locality(String value){
		if(value==null){return;}
		set=work_address=true;
		Address_Work_Locality=value;
	}
	public void setAddress_Work_Region(String value){
		if(value==null){return;}
		set=work_address=true;
		Address_Work_Region=value;
	}
	public void setAddress_Work_PCode(String value){
		if(value==null){return;}
		set=work_address=true;
		Address_Work_PCode=value;
	}
	public void setAddress_Work_Country(String value){
		if(value==null){return;}
		set=work_address=true;
		Address_Work_Country=value;
	}
	public void setAddress_Home_House(String value){
		if(value==null){return;}
		set=home_address=true;
		Address_Home_House=value;
	}
	public void setAddress_Home_Street(String value){
		if(value==null){return;}
		set=home_address=true;
		Address_Home_Street=value;
	}
	public void setAddress_Home_Locality(String value){
		if(value==null){return;}
		set=home_address=true;
		Address_Home_Locality=value;
	}
	public void setAddress_Home_Region(String value){
		if(value==null){return;}
		set=home_address=true;
		Address_Home_Region=value;
	}
	public void setAddress_Home_PCode(String value){
		if(value==null){return;}
		set=home_address=true;
		Address_Home_PCode=value;
	}
	public void setAddress_Home_Country(String value){
		if(value==null){return;}
		set=home_address=true;
		Address_Home_Country=value;
	}
	public void setEmail(String value){
		if(value==null){return;}
		set=true;
		Email=value;
	}

	public void setDescription(String value){
		if(value==null){return;}
		set=true;
		Description=value;
	}
	public void setJabberID(String value){
		if(value==null){return;}
		set=true;
		JabberID=value;
	}

	// Util methods

	/** Fetches the vcard for the current user.
	* Warning - This method blocks until either the connection times out,
	* or the vcard is retrieved.
	* @param connection The jabber connection.
	* @return The vcard for the connected user.
	* @exception XMPPException If there is a problem retrieving the vcard.*/
	public static VCard fetch(XMPPConnection connection) throws XMPPException, NullPointerException {
		if(connection==null){throw new NullPointerException("Null connection passed to fetch method");}
		if(!connection.isConnected()){
			throw new XMPPException("Not connected");
		}
		if(connection.isAnonymous()){
			throw new XMPPException("User must be logged in");
		}
		VCard iq=new VCard();
		iq.setType(IQ.Type.GET);
		iq.setFrom(connection.getUser());
		PacketCollector collector=connection.createPacketCollector(new PacketIDFilter(iq.getPacketID()));
		connection.sendPacket(iq);
		VCard result;
		IQ iqresult=null;
		try{
			iqresult=(IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
			result=(VCard) iqresult;
		}
		catch (ClassCastException cce){
			// probably returned a result IQ  when user has no stored vcard yet
			result=new VCard(); // return an empty vcard
		}
		if(result==null){
			throw new XMPPException(new XMPPError(408,"Request Timeout"));
		}
		if(result.getError()!=null){
			throw new XMPPException(result.getError());
		}
		return result;
	}

	/** Fetches the vcard for another user.
	* Warning - This method blocks until either the connection times out,
	* or the vcard is retrieved.
	* @param connection The jabber connection.
	* @param user The full username of the user we want the vcard of,
	* eg fred@ jabber.org
	* @return The vcard for other user.
	* @exception XMPPException If there is a problem retrieving the vcard.*/
	public static VCard fetch(XMPPConnection connection, String user) throws XMPPException, NullPointerException {
		if(connection==null || user==null){
			throw new NullPointerException("Null parameter passed to fetch method");
		}
		if(!connection.isConnected()){
			throw new XMPPException("Not connected");
		}
		VCard iq=new VCard();
		iq.setType(IQ.Type.GET);
		iq.setTo(user);
		PacketCollector collector=connection.createPacketCollector(new PacketIDFilter(iq.getPacketID()));
		connection.sendPacket(iq);
		VCard result;
		IQ iqresult=null;
		try{
			iqresult=(IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
			result=(VCard) iqresult;
		}
		catch (ClassCastException cce){
			// probably returned a result IQ  when user has no stored vcard yet
			result=new VCard(); // return an empty vcard
		}
		if(iqresult==null){
			throw new XMPPException(new XMPPError(408,"Request Timeout"));
		}
		if(iqresult.getError()!=null){
			throw new XMPPException(iqresult.getError());
		}
		return result;
	}

	/** Stores the vcard for the current user.
	* Warning - This method blocks until either the connection times out,
	* or the vcard is uploaded, or an error is returned.
	* @param connection The jabber connection.
	* @exception XMPPException If there is a problem retrieving the vcard.*/
	public void upload(XMPPConnection connection) throws XMPPException, NullPointerException {
		if(connection==null){throw new NullPointerException("Null connection passed to fetch method");}
		if(!connection.isConnected()){
			throw new XMPPException("Not connected");
		}
		if(connection.isAnonymous()){
			throw new XMPPException("User must be logged in");
		}
		this.setType(IQ.Type.SET);
		this.setFrom(connection.getUser());
		PacketCollector collector=connection.createPacketCollector(new PacketIDFilter(this.getPacketID()));
		connection.sendPacket(this);
		IQ result=(IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
		if(result==null){
			throw new XMPPException(new XMPPError(408,"Request Timeout"));
		}
		if(result.getError()!=null){
			throw new XMPPException(result.getError());
		}
	}

	/** Returns true if this VCard contains a home address.*/
	public boolean hasHomeAddress(){
		return home_address;
	}

	/** Returns true if this VCard contains a work address.*/
	public boolean hasWorkAddress(){
		return work_address;
	}

	private static String print(String text, String tag){
		if(text==null){
			return ("<"+tag+"/>");
		}
		return ("<"+tag+">"+text+"</"+tag+">");
	}

	/** Method used internally by smack.*/
	public String getChildElementXML(){
		if(!set){
			return ("<vCard xmlns='vcard-temp'/>");
		}
		StringBuffer buf = new StringBuffer();
		buf.append("<vCard xmlns='vcard-temp'>");
		// full name
		buf.append(print(FullName,"FN"));
		// name
		buf.append("<N>");
		if(Name_Prefix!=null){
			buf.append(print(Name_Prefix,"PREFIX"));
		}
		buf.append(print(Name_Given,"GIVEN")).append(print(Name_Middle,"MIDDLE"));
		buf.append(print(Name_Family,"FAMILY"));
		if(Name_Suffix!=null){
			buf.append(print(Name_Suffix,"SUFFIX"));
		}
		buf.append("</N>");
		buf.append(print(Nickname,"NICKNAME"));
		if(URL!=null){
			buf.append("<URL>"+URL+"</URL>");
		}
		if(Birthday!=null){
			buf.append("<BDAY>"+Birthday+"</BDAY>");
		}
		if(Title!=null){
			buf.append("<TITLE>"+Title+"</TITLE>");
		}
		if(Role!=null){
			buf.append("<ROLE>"+Role+"</ROLE>");
		}
		// org
		if(!(Org_Name==null && Org_Unit==null)){
			buf.append("<ORG>").append(print(Org_Name,"ORGNAME")).append(print(Org_Unit,"ORGUNIT")).append("</ORG>");
		}
		// work address
		if(work_address){
			buf.append("<ADR>").append("<WORK/>");
			buf.append(print(Address_Work_House,"EXTADR"));
			buf.append(print(Address_Work_Street,"STREET"));
			buf.append(print(Address_Work_Locality,"LOCALITY"));
			buf.append(print(Address_Work_Region,"REGION"));
			buf.append(print(Address_Work_PCode,"PCODE"));
			buf.append(print(Address_Work_Country,"CTRY")).append("</ADR>");
		}
		// home address
		if(home_address){
			buf.append("<ADR>").append("<HOME/>");
			buf.append(print(Address_Home_House,"EXTADR"));
			buf.append(print(Address_Home_Street,"STREET"));
			buf.append(print(Address_Home_Locality,"LOCALITY"));
			buf.append(print(Address_Home_Region,"REGION"));
			buf.append(print(Address_Home_PCode,"PCODE"));
			buf.append(print(Address_Home_Country,"CTRY")).append("</ADR>");
		}
		if(Email!=null){
			buf.append("<EMAIL><INTERNET/><USERID>"+Email+"</USERID></EMAIL>");
		}
		// phone
		/*if(Tel_Work_Voice!=null){
			buf.append("<TEL><WORK/><VOICE/><NUMBER>"+Tel_Work_Voice+"</NUMBER></TEL>");
		}
		if(Tel_Work_Fax!=null){
			buf.append("<TEL><WORK/><FAX/><NUMBER>"+Tel_Work_Fax+"</NUMBER></TEL>");
		}
		if(Tel_Work_Msg!=null){
			buf.append("<TEL><WORK/><MSG/><NUMBER>"+Tel_Work_Msg+"</NUMBER></TEL>");
		}*/
		if(Tel_Home_Voice!=null){
			buf.append("<TEL><VOICE/><HOME/><NUMBER>"+Tel_Home_Voice+"</NUMBER></TEL>");
		}
		if(Tel_Home_Fax!=null){
			buf.append("<TEL><FAX/><HOME/><NUMBER>"+Tel_Home_Fax+"</NUMBER></TEL>");
		}
		if(Tel_Home_Msg!=null){
			buf.append("<TEL><MSG/><HOME/><NUMBER>"+Tel_Home_Msg+"</NUMBER></TEL>");
		}
		if(Description!=null){
			buf.append("<DESC>"+Description+"</DESC>");
		}
		if(JabberID!=null){
			buf.append("<JABBERID>"+JabberID+"</JABBERID>");
		}


		buf.append("</vCard>");
		return buf.toString();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -