KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > smack > packet > Registration


1 /**
2  * $RCSfile$
3  * $Revision: 2503 $
4  * $Date: 2005-06-17 19:28:12 -0300 (Fri, 17 Jun 2005) $
5  *
6  * Copyright 2003-2004 Jive Software.
7  *
8  * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */

20
21 package org.jivesoftware.smack.packet;
22
23 import java.util.Map JavaDoc;
24 import java.util.Iterator JavaDoc;
25
26 /**
27  * Represents registration packets. An empty GET query will cause the server to return information
28  * about it's registration support. SET queries can be used to create accounts or update
29  * existing account information. XMPP servers may require a number of attributes to be set
30  * when creating a new account. The standard account attributes are as follows:
31  * <ul>
32  * <li>name -- the user's name.
33  * <li>first -- the user's first name.
34  * <li>last -- the user's last name.
35  * <li>email -- the user's email address.
36  * <li>city -- the user's city.
37  * <li>state -- the user's state.
38  * <li>zip -- the user's ZIP code.
39  * <li>phone -- the user's phone number.
40  * <li>url -- the user's website.
41  * <li>date -- the date the registration took place.
42  * <li>misc -- other miscellaneous information to associate with the account.
43  * <li>text -- textual information to associate with the account.
44  * <li>remove -- empty flag to remove account.
45  * </ul>
46  *
47  * @author Matt Tucker
48  */

49 public class Registration extends IQ {
50
51     private String JavaDoc instructions = null;
52     private Map JavaDoc attributes = null;
53
54     /**
55      * Returns the registration instructions, or <tt>null</tt> if no instructions
56      * have been set. If present, instructions should be displayed to the end-user
57      * that will complete the registration process.
58      *
59      * @return the registration instructions, or <tt>null</tt> if there are none.
60      */

61     public String JavaDoc getInstructions() {
62         return instructions;
63     }
64
65     /**
66      * Sets the registration instructions.
67      *
68      * @param instructions the registration instructions.
69      */

70     public void setInstructions(String JavaDoc instructions) {
71         this.instructions = instructions;
72     }
73
74     /**
75      * Returns the map of String key/value pairs of account attributes.
76      *
77      * @return the account attributes.
78      */

79     public Map JavaDoc getAttributes() {
80         return attributes;
81     }
82
83     /**
84      * Sets the account attributes. The map must only contain String key/value pairs.
85      *
86      * @param attributes the account attributes.
87      */

88     public void setAttributes(Map JavaDoc attributes) {
89         this.attributes = attributes;
90     }
91
92     public String JavaDoc getChildElementXML() {
93         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
94         buf.append("<query xmlns=\"jabber:iq:register\">");
95         if (instructions != null) {
96             buf.append("<instructions>").append(instructions).append("</instructions>");
97         }
98         if (attributes != null && attributes.size() > 0) {
99             Iterator JavaDoc fieldNames = attributes.keySet().iterator();
100             while (fieldNames.hasNext()) {
101                 String JavaDoc name = (String JavaDoc)fieldNames.next();
102                 String JavaDoc value = (String JavaDoc)attributes.get(name);
103                 buf.append("<").append(name).append(">");
104                 buf.append(value);
105                 buf.append("</").append(name).append(">");
106             }
107         }
108         // Add packet extensions, if any are defined.
109
buf.append(getExtensionsXML());
110         buf.append("</query>");
111         return buf.toString();
112     }
113 }
Popular Tags