Search in sources :

Example 6 with Registration

use of org.jivesoftware.smackx.iqregister.packet.Registration in project Smack by igniterealtime.

the class RegistrationProvider method parse.

@Override
public Registration parse(XmlPullParser parser, int initialDepth) throws Exception {
    String instruction = null;
    Map<String, String> fields = new HashMap<String, String>();
    List<ExtensionElement> packetExtensions = new LinkedList<ExtensionElement>();
    outerloop: while (true) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG) {
            // attempt to parse it if it's in the form <name>value</name>.
            if (parser.getNamespace().equals(Registration.NAMESPACE)) {
                String name = parser.getName();
                String value = "";
                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 {
                    instruction = value;
                }
            } else // Otherwise, it must be a packet extension.
            {
                PacketParserUtils.addExtensionElement(packetExtensions, parser);
            }
        } else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals(IQ.QUERY_ELEMENT)) {
                break outerloop;
            }
        }
    }
    Registration registration = new Registration(instruction, fields);
    registration.addExtensions(packetExtensions);
    return registration;
}
Also used : HashMap(java.util.HashMap) Registration(org.jivesoftware.smackx.iqregister.packet.Registration) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) LinkedList(java.util.LinkedList)

Example 7 with Registration

use of org.jivesoftware.smackx.iqregister.packet.Registration in project Smack by igniterealtime.

the class AccountManager method deleteAccount.

/**
     * 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 XMPPErrorException if an error occurs when deleting the account.
     * @throws NoResponseException if there was no response from the server.
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
public void deleteAccount() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    Map<String, String> attributes = new HashMap<String, String>();
    // To delete an account, we add a single attribute, "remove", that is blank.
    attributes.put("remove", "");
    Registration reg = new Registration(attributes);
    reg.setType(IQ.Type.set);
    reg.setTo(connection().getXMPPServiceDomain());
    createStanzaCollectorAndSend(reg).nextResultOrThrow();
}
Also used : HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) Registration(org.jivesoftware.smackx.iqregister.packet.Registration)

Aggregations

Registration (org.jivesoftware.smackx.iqregister.packet.Registration)7 HashMap (java.util.HashMap)3 WeakHashMap (java.util.WeakHashMap)2 LinkedList (java.util.LinkedList)1 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)1 IQ (org.jivesoftware.smack.packet.IQ)1