Java 类org.jivesoftware.smack.packet.Registration 实例源码

项目:EIM    文件:AccountManager.java   
/**
 * 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());
    }
}
项目:EIM    文件:AccountManager.java   
/**
 * 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());
    }
}
项目:EIM    文件:AccountManager.java   
/**
 * 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;
    }
}
项目:EIM    文件:MultiUserChat.java   
/**
 * 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);
}
项目:EIM    文件:MultiUserChat.java   
/**
 * 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());
    }
}
项目:androidpn_enhanced_client    文件:AccountManager.java   
/**
 * 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());
    }
}
项目:androidpn_enhanced_client    文件:AccountManager.java   
/**
 * 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());
    // To delete an account, we set remove to true
    reg.setRemove(true);
    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());
    }
}
项目:androidpn_enhanced_client    文件:AccountManager.java   
/**
 * 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;
    }
}
项目:androidPN-client.    文件:AccountManager.java   
/**
 * 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());
    }
}
项目:androidPN-client.    文件:AccountManager.java   
/**
 * 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());
    }
}
项目:androidPN-client.    文件:AccountManager.java   
/**
 * 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;
    }
}
项目:androidPN-client.    文件:MultiUserChat.java   
/**
 * 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);
}
项目:androidPN-client.    文件:MultiUserChat.java   
/**
 * 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());
    }
}
项目:xmppsupport_v2    文件:AccountManager.java   
/**
 * Creates a new account using the specified username, password and account
 * attributes. The attributes Map must contain only String name/value pairs
 * and must also have values for all required attributes.
 * 
 * @param username
 *            the username.
 * @param password
 *            the password.
 * @param attributes
 *            the account attributes.
 * @throws XMPPException
 *             if an error occurs creating the account.
 * @see #getAccountAttributes()
 */
public void createAccount(String username, String password,
        Map<String, String> attributes) throws XMPPException {
    if (!supportsAccountCreation()) {
        throw new XMPPException("Server does not support account creation.");
    }
    Registration reg = new Registration();
    reg.setType(IQ.Type.SET);
    reg.setTo(connection.getServiceName());
    attributes.put("username", username);
    attributes.put("password", password);
    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());
    }
}
项目:xmppsupport_v2    文件:AccountManager.java   
/**
 * 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());
    }
}
项目:xmppsupport_v2    文件:AccountManager.java   
/**
 * 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;
    }
}
项目:xmppsupport_v2    文件:Gateway.java   
private void refreshRegisterInfo() {
    Registration packet = new Registration();
    packet.setFrom(connection.getUser());
    packet.setType(IQ.Type.GET);
    packet.setTo(entityJID);
    PacketCollector collector = connection
            .createPacketCollector(new PacketIDFilter(packet.getPacketID()));
    connection.sendPacket(packet);
    Packet result = collector.nextResult(SmackConfiguration
            .getPacketReplyTimeout());
    collector.cancel();
    if (result instanceof Registration && result.getError() == null) {
        Registration register = (Registration) result;
        this.registerInfo = register;
    }
}
项目:xmppsupport_v2    文件:MultiUserChat.java   
/**
 * 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);
}
项目:AndroidPNClient    文件:AccountManager.java   
/**
 * 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 org.jivesoftware.smack.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());
    }
}
项目:AndroidPNClient    文件:AccountManager.java   
/**
 * 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 org.jivesoftware.smack.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());
    // To delete an account, we set remove to true
    reg.setRemove(true);
    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());
    }
}
项目:AndroidPNClient    文件:AccountManager.java   
/**
 * Gets the account registration info from the server.
 *
 * @throws org.jivesoftware.smack.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;
    }
}
项目:Chatting-App-    文件:NumberValidator.java   
private Packet createRegistrationForm() {
    Registration iq = new Registration();
    iq.setType(IQ.Type.SET);
    iq.setTo(mConnector.getConnection().getServiceName());
    Form form = new Form(Form.TYPE_SUBMIT);

    FormField type = new FormField("FORM_TYPE");
    type.setType(FormField.TYPE_HIDDEN);
    type.addValue("jabber:iq:register");
    form.addField(type);

    FormField phone = new FormField("phone");
    phone.setLabel("Phone number");
    phone.setType(FormField.TYPE_TEXT_SINGLE);
    phone.addValue(mPhone);
    form.addField(phone);

    iq.addExtension(form.getDataFormToSend());
    return iq;
}
项目:java-bells    文件:AccountManager.java   
/**
 * 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());
    }
}
项目:java-bells    文件:AccountManager.java   
/**
 * 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());
    }
}
项目:java-bells    文件:AccountManager.java   
/**
 * 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;
    }
}
项目:java-bells    文件:MultiUserChat.java   
/**
 * 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);
}
项目:java-bells    文件:MultiUserChat.java   
/**
 * 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());
    }
}
项目:telegraph    文件:AccountManager.java   
/**
 * 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());
    }
}
项目:telegraph    文件:AccountManager.java   
/**
 * 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());
    }
}
项目:telegraph    文件:AccountManager.java   
/**
 * 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;
    }
}
项目:telegraph    文件:MultiUserChat.java   
/**
 * 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);
}
项目:telegraph    文件:MultiUserChat.java   
/**
 * 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());
    }
}
项目:NewCommunication-Android    文件:AccountManager.java   
/**
 * 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());
    }
}
项目:NewCommunication-Android    文件:AccountManager.java   
/**
 * 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());
    // To delete an account, we set remove to true
    reg.setRemove(true);
    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());
    }
}
项目:NewCommunication-Android    文件:AccountManager.java   
/**
 * 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;
    }
}
项目:NewCommunication-Android    文件:MultiUserChat.java   
/**
 * 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);
}
项目:NewCommunication-Android    文件:MultiUserChat.java   
/**
 * 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());
    }
}
项目:spark-svn-mirror    文件:TransportUtils.java   
/**
 * @param con           the XMPPConnection.
 * @param gatewayDomain the domain of the gateway (service name)
 * @throws XMPPException thrown if there was an issue unregistering with the gateway.
 */
public static void unregister(XMPPConnection con, String gatewayDomain) throws XMPPException {
    Registration registration = new Registration();
    registration.setType(IQ.Type.SET);
    registration.setTo(gatewayDomain);
    Map<String,String> map = new HashMap<String,String>();
    map.put("remove", "");
    registration.setAttributes(map);


    PacketCollector collector = con.createPacketCollector(new PacketIDFilter(registration.getPacketID()));
    con.sendPacket(registration);

    IQ response = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    collector.cancel();
    if (response == null) {
        throw new XMPPException("Server timed out");
    }
    if (response.getType() == IQ.Type.ERROR) {
        throw new XMPPException("Error registering user", response.getError());
    }
}
项目:SmackStudy    文件:XMPPUtil.java   
/**
 * 注册用户
 * @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;
        }
    }
}
项目:AyoSunny    文件:XmppUtil.java   
/** 
 * 注册 
 *  
 * @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;  
        }  
    }  
}