001/**
002 *
003 * Copyright 2003-2007 Jive Software.
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package org.jivesoftware.smack.packet;
019
020import java.util.Map;
021
022import org.jivesoftware.smack.util.XmlStringBuilder;
023
024/**
025 * Represents registration packets. An empty GET query will cause the server to return information
026 * about it's registration support. SET queries can be used to create accounts or update
027 * existing account information. XMPP servers may require a number of attributes to be set
028 * when creating a new account. The standard account attributes are as follows:
029 * <ul>
030 *      <li>name -- the user's name.
031 *      <li>first -- the user's first name.
032 *      <li>last -- the user's last name.
033 *      <li>email -- the user's email address.
034 *      <li>city -- the user's city.
035 *      <li>state -- the user's state.
036 *      <li>zip -- the user's ZIP code.
037 *      <li>phone -- the user's phone number.
038 *      <li>url -- the user's website.
039 *      <li>date -- the date the registration took place.
040 *      <li>misc -- other miscellaneous information to associate with the account.
041 *      <li>text -- textual information to associate with the account.
042 *      <li>remove -- empty flag to remove account.
043 * </ul>
044 *
045 * @author Matt Tucker
046 */
047public class Registration extends IQ {
048
049    private String instructions = null;
050    private Map<String, String> attributes = null;
051
052    /**
053     * Returns the registration instructions, or <tt>null</tt> if no instructions
054     * have been set. If present, instructions should be displayed to the end-user
055     * that will complete the registration process.
056     *
057     * @return the registration instructions, or <tt>null</tt> if there are none.
058     */
059    public String getInstructions() {
060        return instructions;
061    }
062
063    /**
064     * Sets the registration instructions.
065     *
066     * @param instructions the registration instructions.
067     */
068    public void setInstructions(String instructions) {
069        this.instructions = instructions;
070    }
071
072    /**
073     * Returns the map of String key/value pairs of account attributes.
074     *
075     * @return the account attributes.
076     */
077    public Map<String, String> getAttributes() {
078        return attributes;
079    }
080
081    /**
082     * Sets the account attributes. The map must only contain String key/value pairs.
083     *
084     * @param attributes the account attributes.
085     */
086    public void setAttributes(Map<String, String> attributes) {
087        this.attributes = attributes;
088    }
089
090    @Override
091    public XmlStringBuilder getChildElementXML() {
092        XmlStringBuilder xml = new XmlStringBuilder();
093        xml.halfOpenElement("query");
094        xml.xmlnsAttribute("jabber:iq:register");
095        xml.rightAngelBracket();
096        xml.optElement("instructions", instructions);
097        if (attributes != null && attributes.size() > 0) {
098            for (String name : attributes.keySet()) {
099                String value = attributes.get(name);
100                xml.element(name, value);
101            }
102        }
103        // Add packet extensions, if any are defined.
104        xml.append(getExtensionsXML());
105        xml.closeElement("query");
106        return xml;
107    }
108}