本文整理匯總了Java中org.jivesoftware.smack.filter.PacketFilter類的典型用法代碼示例。如果您正苦於以下問題:Java PacketFilter類的具體用法?Java PacketFilter怎麽用?Java PacketFilter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PacketFilter類屬於org.jivesoftware.smack.filter包,在下文中一共展示了PacketFilter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: changePassword
import org.jivesoftware.smack.filter.PacketFilter; //導入依賴的package包/類
/**
* Changes the password of the currently logged-in account. This operation can only
* be performed after a successful login operation has been completed. Not all servers
* support changing passwords; an XMPPException will be thrown when that is the case.
*
* @throws IllegalStateException if not currently logged-in to the server.
* @throws XMPPException if an error occurs when changing the password.
*/
public void changePassword(String newPassword) throws XMPPException {
Registration reg = new Registration();
reg.setType(IQ.Type.SET);
reg.setTo(connection.getServiceName());
Map<String, String> map = new HashMap<String, String>();
map.put("username",StringUtils.parseName(connection.getUser()));
map.put("password",newPassword);
reg.setAttributes(map);
PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
new PacketTypeFilter(IQ.class));
PacketCollector collector = connection.createPacketCollector(filter);
connection.sendPacket(reg);
IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
collector.cancel();
if (result == null) {
throw new XMPPException("No response from server.");
}
else if (result.getType() == IQ.Type.ERROR) {
throw new XMPPException(result.getError());
}
}
示例2: deleteAccount
import org.jivesoftware.smack.filter.PacketFilter; //導入依賴的package包/類
/**
* Deletes the currently logged-in account from the server. This operation can only
* be performed after a successful login operation has been completed. Not all servers
* support deleting accounts; an XMPPException will be thrown when that is the case.
*
* @throws IllegalStateException if not currently logged-in to the server.
* @throws XMPPException if an error occurs when deleting the account.
*/
public void deleteAccount() throws XMPPException {
if (!connection.isAuthenticated()) {
throw new IllegalStateException("Must be logged in to delete a account.");
}
Registration reg = new Registration();
reg.setType(IQ.Type.SET);
reg.setTo(connection.getServiceName());
Map<String, String> attributes = new HashMap<String, String>();
// To delete an account, we add a single attribute, "remove", that is blank.
attributes.put("remove", "");
reg.setAttributes(attributes);
PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
new PacketTypeFilter(IQ.class));
PacketCollector collector = connection.createPacketCollector(filter);
connection.sendPacket(reg);
IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
collector.cancel();
if (result == null) {
throw new XMPPException("No response from server.");
}
else if (result.getType() == IQ.Type.ERROR) {
throw new XMPPException(result.getError());
}
}
示例3: getRegistrationInfo
import org.jivesoftware.smack.filter.PacketFilter; //導入依賴的package包/類
/**
* Gets the account registration info from the server.
*
* @throws XMPPException if an error occurs.
*/
private synchronized void getRegistrationInfo() throws XMPPException {
Registration reg = new Registration();
reg.setTo(connection.getServiceName());
PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
new PacketTypeFilter(IQ.class));
PacketCollector collector = connection.createPacketCollector(filter);
connection.sendPacket(reg);
IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
collector.cancel();
if (result == null) {
throw new XMPPException("No response from server.");
}
else if (result.getType() == IQ.Type.ERROR) {
throw new XMPPException(result.getError());
}
else {
info = (Registration)result;
}
}
示例4: getConfigurationForm
import org.jivesoftware.smack.filter.PacketFilter; //導入依賴的package包/類
/**
* Returns the room's configuration form that the room's owner can use or <tt>null</tt> if
* no configuration is possible. The configuration form allows to set the room's language,
* enable logging, specify room's type, etc..
*
* @return the Form that contains the fields to complete together with the instrucions or
* <tt>null</tt> if no configuration is possible.
* @throws XMPPException if an error occurs asking the configuration form for the room.
*/
public Form getConfigurationForm() throws XMPPException {
MUCOwner iq = new MUCOwner();
iq.setTo(room);
iq.setType(IQ.Type.GET);
// Filter packets looking for an answer from the server.
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
PacketCollector response = connection.createPacketCollector(responseFilter);
// Request the configuration form to the server.
connection.sendPacket(iq);
// Wait up to a certain number of seconds for a reply.
IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
response.cancel();
if (answer == null) {
throw new XMPPException("No response from server.");
}
else if (answer.getError() != null) {
throw new XMPPException(answer.getError());
}
return Form.getFormFrom(answer);
}
示例5: sendConfigurationForm
import org.jivesoftware.smack.filter.PacketFilter; //導入依賴的package包/類
/**
* Sends the completed configuration form to the server. The room will be configured
* with the new settings defined in the form. If the form is empty then the server
* will create an instant room (will use default configuration).
*
* @param form the form with the new settings.
* @throws XMPPException if an error occurs setting the new rooms' configuration.
*/
public void sendConfigurationForm(Form form) throws XMPPException {
MUCOwner iq = new MUCOwner();
iq.setTo(room);
iq.setType(IQ.Type.SET);
iq.addExtension(form.getDataFormToSend());
// Filter packets looking for an answer from the server.
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
PacketCollector response = connection.createPacketCollector(responseFilter);
// Send the completed configuration form to the server.
connection.sendPacket(iq);
// Wait up to a certain number of seconds for a reply.
IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
response.cancel();
if (answer == null) {
throw new XMPPException("No response from server.");
}
else if (answer.getError() != null) {
throw new XMPPException(answer.getError());
}
}
示例6: getRegistrationForm
import org.jivesoftware.smack.filter.PacketFilter; //導入依賴的package包/類
/**
* Returns the room's registration form that an unaffiliated user, can use to become a member
* of the room or <tt>null</tt> if no registration is possible. Some rooms may restrict the
* privilege to register members and allow only room admins to add new members.<p>
*
* If the user requesting registration requirements is not allowed to register with the room
* (e.g. because that privilege has been restricted), the room will return a "Not Allowed"
* error to the user (error code 405).
*
* @return the registration Form that contains the fields to complete together with the
* instrucions or <tt>null</tt> if no registration is possible.
* @throws XMPPException if an error occurs asking the registration form for the room or a
* 405 error if the user is not allowed to register with the room.
*/
public Form getRegistrationForm() throws XMPPException {
Registration reg = new Registration();
reg.setType(IQ.Type.GET);
reg.setTo(room);
PacketFilter filter =
new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));
PacketCollector collector = connection.createPacketCollector(filter);
connection.sendPacket(reg);
IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
collector.cancel();
if (result == null) {
throw new XMPPException("No response from server.");
}
else if (result.getType() == IQ.Type.ERROR) {
throw new XMPPException(result.getError());
}
return Form.getFormFrom(result);
}
示例7: sendRegistrationForm
import org.jivesoftware.smack.filter.PacketFilter; //導入依賴的package包/類
/**
* Sends the completed registration form to the server. After the user successfully submits
* the form, the room may queue the request for review by the room admins or may immediately
* add the user to the member list by changing the user's affiliation from "none" to "member.<p>
*
* If the desired room nickname is already reserved for that room, the room will return a
* "Conflict" error to the user (error code 409). If the room does not support registration,
* it will return a "Service Unavailable" error to the user (error code 503).
*
* @param form the completed registration form.
* @throws XMPPException if an error occurs submitting the registration form. In particular, a
* 409 error can occur if the desired room nickname is already reserved for that room;
* or a 503 error can occur if the room does not support registration.
*/
public void sendRegistrationForm(Form form) throws XMPPException {
Registration reg = new Registration();
reg.setType(IQ.Type.SET);
reg.setTo(room);
reg.addExtension(form.getDataFormToSend());
PacketFilter filter =
new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));
PacketCollector collector = connection.createPacketCollector(filter);
connection.sendPacket(reg);
IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
collector.cancel();
if (result == null) {
throw new XMPPException("No response from server.");
}
else if (result.getType() == IQ.Type.ERROR) {
throw new XMPPException(result.getError());
}
}
示例8: changeAffiliationByOwner
import org.jivesoftware.smack.filter.PacketFilter; //導入依賴的package包/類
private void changeAffiliationByOwner(String jid, String affiliation) throws XMPPException {
MUCOwner iq = new MUCOwner();
iq.setTo(room);
iq.setType(IQ.Type.SET);
// Set the new affiliation.
MUCOwner.Item item = new MUCOwner.Item(affiliation);
item.setJid(jid);
iq.addItem(item);
// Wait for a response packet back from the server.
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
PacketCollector response = connection.createPacketCollector(responseFilter);
// Send the change request to the server.
connection.sendPacket(iq);
// Wait up to a certain number of seconds for a reply.
IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
response.cancel();
if (answer == null) {
throw new XMPPException("No response from server.");
}
else if (answer.getError() != null) {
throw new XMPPException(answer.getError());
}
}
示例9: AgentRoster
import org.jivesoftware.smack.filter.PacketFilter; //導入依賴的package包/類
/**
* Constructs a new AgentRoster.
*
* @param connection an XMPP connection.
*/
AgentRoster(Connection connection, String workgroupJID) {
this.connection = connection;
this.workgroupJID = workgroupJID;
entries = new ArrayList<String>();
listeners = new ArrayList<AgentRosterListener>();
presenceMap = new HashMap<String, Map<String, Presence>>();
// Listen for any roster packets.
PacketFilter rosterFilter = new PacketTypeFilter(AgentStatusRequest.class);
connection.addPacketListener(new AgentStatusListener(), rosterFilter);
// Listen for any presence packets.
connection.addPacketListener(new PresencePacketListener(),
new PacketTypeFilter(Presence.class));
// Send request for roster.
AgentStatusRequest request = new AgentStatusRequest();
request.setTo(workgroupJID);
connection.sendPacket(request);
}
示例10: getReply
import org.jivesoftware.smack.filter.PacketFilter; //導入依賴的package包/類
static public Packet getReply(Connection connection, Packet packet, long timeout)
throws XMPPException
{
PacketFilter responseFilter = new PacketIDFilter(packet.getPacketID());
PacketCollector response = connection.createPacketCollector(responseFilter);
connection.sendPacket(packet);
// Wait up to a certain number of seconds for a reply.
Packet result = response.nextResult(timeout);
// Stop queuing results
response.cancel();
if (result == null) {
throw new XMPPException("No response from server.");
}
else if (result.getError() != null) {
throw new XMPPException(result.getError());
}
return result;
}
示例11: addSubscriptionListener
import org.jivesoftware.smack.filter.PacketFilter; //導入依賴的package包/類
/**
* ���һ�����������������������
*/
private void addSubscriptionListener() {
PacketFilter filter = new PacketFilter() {
@Override
public boolean accept(Packet packet) {
if (packet instanceof Presence) {
Presence presence = (Presence) packet;
if (presence.getType().equals(Presence.Type.subscribe)) {
return true;
}
}
return false;
}
};
XmppConnectionManager.getInstance().getConnection()
.addPacketListener(subscriptionPacketListener, filter);
}
示例12: changePassword
import org.jivesoftware.smack.filter.PacketFilter; //導入依賴的package包/類
/**
* Changes the password of the currently logged-in account. This operation can only
* be performed after a successful login operation has been completed. Not all servers
* support changing passwords; an XMPPException will be thrown when that is the case.
*
* @throws IllegalStateException if not currently logged-in to the server.
* @throws XMPPException if an error occurs when changing the password.
*/
public void changePassword(String newPassword) throws XMPPException {
Registration reg = new Registration();
reg.setType(IQ.Type.SET);
reg.setTo(connection.getServiceName());
reg.setUsername(StringUtils.parseName(connection.getUser()));
reg.setPassword(newPassword);
PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
new PacketTypeFilter(IQ.class));
PacketCollector collector = connection.createPacketCollector(filter);
connection.sendPacket(reg);
IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
collector.cancel();
if (result == null) {
throw new XMPPException("No response from server.");
}
else if (result.getType() == IQ.Type.ERROR) {
throw new XMPPException(result.getError());
}
}
示例13: reload
import org.jivesoftware.smack.filter.PacketFilter; //導入依賴的package包/類
/**
* Reloads the entire roster from the server. This is an asynchronous operation,
* which means the method will return immediately, and the roster will be
* reloaded at a later point when the server responds to the reload request.
*
* @throws IllegalStateException if connection is not logged in or logged in anonymously
*/
public void reload() {
if (!connection.isAuthenticated()) {
throw new IllegalStateException("Not logged in to server.");
}
if (connection.isAnonymous()) {
throw new IllegalStateException("Anonymous users can't have a roster.");
}
RosterPacket packet = new RosterPacket();
if(persistentStorage!=null){
packet.setVersion(persistentStorage.getRosterVersion());
}
requestPacketId = packet.getPacketID();
PacketFilter idFilter = new PacketIDFilter(requestPacketId);
connection.addPacketListener(new RosterResultListener(), idFilter);
connection.sendPacket(packet);
}
示例14: regist
import org.jivesoftware.smack.filter.PacketFilter; //導入依賴的package包/類
/**
* 注冊用戶
* @param xmppConnection
* @param userName
* @param password
* @return 1、注冊成功 0、服務器沒有返回結果2、這個賬號已經存在3、注冊失敗
*/
public static int regist(XMPPConnection xmppConnection, String userName, String password) {
Registration registration = new Registration();
registration.setType(IQ.Type.SET);
registration.setTo(xmppConnection.getServiceName());
registration.setUsername(userName);
registration.setPassword(password);
// 這邊addAttribute不能為空,否則出錯。所以做個標誌是android手機創建的吧!!!!!
registration.addAttribute("android", "fhr");
PacketFilter filter = new AndFilter(new PacketIDFilter(registration.getPacketID()), new PacketTypeFilter(IQ.class));
PacketCollector collector = xmppConnection.createPacketCollector(filter);
xmppConnection.sendPacket(registration);
IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results停止請求results(是否成功的結果)
collector.cancel();
if (result == null) {
Log.e("regist", "No response from server.");
return 0;
} else if (result.getType() == IQ.Type.RESULT) {
Log.v("regist", "regist success.");
return 1;
} else {
if (result.getError().toString().equalsIgnoreCase("conflict(409)")) {
Log.e("regist", "IQ.Type.ERROR: " + result.getError().toString());
return 2;
} else {
Log.e("regist", "IQ.Type.ERROR: " + result.getError().toString());
return 3;
}
}
}
示例15: register
import org.jivesoftware.smack.filter.PacketFilter; //導入依賴的package包/類
/**
* 注冊
*
* @param account
* 注冊帳號
* @param password
* 注冊密碼
* @return 1、注冊成功 0、服務器沒有返回結果2、這個賬號已經存在3、注冊失敗
*/
public static int register(XMPPConnection mXMPPConnection,String account, String password) {
Registration reg = new Registration();
reg.setType(IQ.Type.SET);
reg.setTo(mXMPPConnection.getServiceName());
// 注意這裏createAccount注冊時,參數是UserName,不是jid,是"@"前麵的部分。
reg.setUsername(account);
reg.setPassword(password);
// 這邊addAttribute不能為空,否則出錯。所以做個標誌是android手機創建的吧!!!!!
reg.addAttribute("android", "geolo_createUser_android");
PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));
PacketCollector collector =mXMPPConnection.createPacketCollector(filter);
mXMPPConnection.sendPacket(reg);
IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results停止請求results(是否成功的結果)
collector.cancel();
if (result == null) {
return 0;
} else if (result.getType() == IQ.Type.RESULT) {
return 1;
} else {
if (result.getError().toString().equalsIgnoreCase("conflict(409)")) {
return 2;
} else {
return 3;
}
}
}