当前位置: 首页>>代码示例>>Java>>正文


Java Registration.setAttributes方法代码示例

本文整理汇总了Java中org.jivesoftware.smack.packet.Registration.setAttributes方法的典型用法代码示例。如果您正苦于以下问题:Java Registration.setAttributes方法的具体用法?Java Registration.setAttributes怎么用?Java Registration.setAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jivesoftware.smack.packet.Registration的用法示例。


在下文中一共展示了Registration.setAttributes方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: changePassword

import org.jivesoftware.smack.packet.Registration; //导入方法依赖的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());
    }
}
 
开发者ID:ice-coffee,项目名称:EIM,代码行数:31,代码来源:AccountManager.java

示例2: deleteAccount

import org.jivesoftware.smack.packet.Registration; //导入方法依赖的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());
    }
}
 
开发者ID:ice-coffee,项目名称:EIM,代码行数:34,代码来源:AccountManager.java

示例3: createAccount

import org.jivesoftware.smack.packet.Registration; //导入方法依赖的package包/类
/**
 * 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());
	}
}
 
开发者ID:ikantech,项目名称:xmppsupport_v2,代码行数:41,代码来源:AccountManager.java

示例4: changePassword

import org.jivesoftware.smack.packet.Registration; //导入方法依赖的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());
	}
}
 
开发者ID:ikantech,项目名称:xmppsupport_v2,代码行数:34,代码来源:AccountManager.java

示例5: unregister

import org.jivesoftware.smack.packet.Registration; //导入方法依赖的package包/类
/**
 * @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());
    }
}
 
开发者ID:visit,项目名称:spark-svn-mirror,代码行数:27,代码来源:TransportUtils.java

示例6: createAccount

import org.jivesoftware.smack.packet.Registration; //导入方法依赖的package包/类
/**
 * 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());
    }
}
 
开发者ID:ice-coffee,项目名称:EIM,代码行数:38,代码来源:AccountManager.java

示例7: deleteAccount

import org.jivesoftware.smack.packet.Registration; //导入方法依赖的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());
	}
}
 
开发者ID:ikantech,项目名称:xmppsupport_v2,代码行数:39,代码来源:AccountManager.java

示例8: registerUser

import org.jivesoftware.smack.packet.Registration; //导入方法依赖的package包/类
/**
 * Registers a user with a gateway.
 *
 * @param con           the XMPPConnection.
 * @param gatewayDomain the domain of the gateway (service name)
 * @param username      the username.
 * @param password      the password.
 * @param nickname      the nickname.
 * @throws XMPPException thrown if there was an issue registering with the gateway.
 */
public static void registerUser(XMPPConnection con, String gatewayDomain, String username, String password, String nickname) throws XMPPException {
    Registration registration = new Registration();
    registration.setType(IQ.Type.SET);
    registration.setTo(gatewayDomain);
    registration.addExtension(new GatewayRegisterExtension());

    Map<String, String> attributes = new HashMap<String, String>();
    if (username != null) {
        attributes.put("username", username);
    }
    if (password != null) {
        attributes.put("password", password);
    }
    if (nickname != null) {
        attributes.put("nick", nickname);
    }
    registration.setAttributes(attributes);

    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());
    }

}
 
开发者ID:visit,项目名称:spark-svn-mirror,代码行数:42,代码来源:TransportUtils.java

示例9: parseRegistration

import org.jivesoftware.smack.packet.Registration; //导入方法依赖的package包/类
private static Registration parseRegistration(XmlPullParser parser) throws Exception {
    Registration registration = new Registration();
    Map<String, String> fields = null;
    boolean done = false;
    while (!done) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG) {
            // Any element that's in the jabber:iq:register namespace,
            // attempt to parse it if it's in the form <name>value</name>.
            if (parser.getNamespace().equals("jabber:iq:register")) {
                String name = parser.getName();
                String value = "";
                if (fields == null) {
                    fields = new HashMap<String, String>();
                }

                if (parser.next() == XmlPullParser.TEXT) {
                    value = parser.getText();
                }
                // Ignore instructions, but anything else should be added to the map.
                if (!name.equals("instructions")) {
                    fields.put(name, value);
                }
                else {
                    registration.setInstructions(value);
                }
            }
            // Otherwise, it must be a packet extension.
            else {
                registration.addExtension(
                    PacketParserUtils.parsePacketExtension(
                        parser.getName(),
                        parser.getNamespace(),
                        parser));
            }
        }
        else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals("query")) {
                done = true;
            }
        }
    }
    registration.setAttributes(fields);
    return registration;
}
 
开发者ID:CJC-ivotten,项目名称:androidPN-client.,代码行数:46,代码来源:PacketParserUtils.java


注:本文中的org.jivesoftware.smack.packet.Registration.setAttributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。