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.smackx.iqregister.packet; 019 020import java.util.Map; 021 022import org.jivesoftware.smack.packet.ExtensionElement; 023import org.jivesoftware.smack.packet.IQ; 024 025/** 026 * Represents registration packets. An empty GET query will cause the server to return information 027 * about it's registration support. SET queries can be used to create accounts or update 028 * existing account information. XMPP servers may require a number of attributes to be set 029 * when creating a new account. The standard account attributes are as follows: 030 * <ul> 031 * <li>name -- the user's name. 032 * <li>first -- the user's first name. 033 * <li>last -- the user's last name. 034 * <li>email -- the user's email address. 035 * <li>city -- the user's city. 036 * <li>state -- the user's state. 037 * <li>zip -- the user's ZIP code. 038 * <li>phone -- the user's phone number. 039 * <li>url -- the user's website. 040 * <li>date -- the date the registration took place. 041 * <li>misc -- other miscellaneous information to associate with the account. 042 * <li>text -- textual information to associate with the account. 043 * <li>remove -- empty flag to remove account. 044 * </ul> 045 * 046 * @author Matt Tucker 047 */ 048public class Registration extends IQ { 049 050 public static final String ELEMENT = QUERY_ELEMENT; 051 public static final String NAMESPACE = "jabber:iq:register"; 052 053 private final String instructions; 054 private final Map<String, String> attributes; 055 056 public Registration() { 057 this(null); 058 } 059 060 public Registration(Map<String, String> attributes) { 061 this(null, attributes); 062 } 063 064 public Registration(String instructions, Map<String, String> attributes) { 065 super(ELEMENT, NAMESPACE); 066 this.instructions = instructions; 067 this.attributes = attributes; 068 } 069 070 /** 071 * Returns the registration instructions, or <tt>null</tt> if no instructions 072 * have been set. If present, instructions should be displayed to the end-user 073 * that will complete the registration process. 074 * 075 * @return the registration instructions, or <tt>null</tt> if there are none. 076 */ 077 public String getInstructions() { 078 return instructions; 079 } 080 081 /** 082 * Returns the map of String key/value pairs of account attributes. 083 * 084 * @return the account attributes. 085 */ 086 public Map<String, String> getAttributes() { 087 return attributes; 088 } 089 090 @Override 091 protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) { 092 xml.rightAngleBracket(); 093 xml.optElement("instructions", instructions); 094 if (attributes != null && attributes.size() > 0) { 095 for (String name : attributes.keySet()) { 096 String value = attributes.get(name); 097 xml.element(name, value); 098 } 099 } 100 return xml; 101 } 102 103 public static final class Feature implements ExtensionElement { 104 105 public static final String ELEMENT = "register"; 106 public static final String NAMESPACE = "http://jabber.org/features/iq-register"; 107 public static final Feature INSTANCE = new Registration.Feature(); 108 109 private Feature() { 110 } 111 112 @Override 113 public String getElementName() { 114 return ELEMENT; 115 } 116 117 @Override 118 public CharSequence toXML(String enclosingNamespace) { 119 return '<' + ELEMENT + " xmlns='" + NAMESPACE + "'/>"; 120 } 121 122 @Override 123 public String getNamespace() { 124 return NAMESPACE; 125 } 126 127 } 128}