1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-12-08 06:01:07 +01:00

1. Clean up code

2. Refactoring work
3. Optimization work. SMACK-153
4. Fixed roster test cases. SMACK-154
4. Fixed vCard issue. SMACK-152

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@4538 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Gaston Dombiak 2006-07-18 05:14:33 +00:00 committed by gato
parent 14b50d790a
commit f57ff10ad9
77 changed files with 995 additions and 932 deletions

View file

@ -223,7 +223,7 @@ public class Bytestream extends IQ {
}
public String getChildElementXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<query xmlns=\"http://jabber.org/protocol/bytestreams\"");
if (this.getType().equals(IQ.Type.SET)) {
@ -337,7 +337,7 @@ public class Bytestream extends IQ {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<").append(getElementName()).append(" ");
buf.append("jid=\"").append(getJID()).append("\" ");
@ -394,7 +394,7 @@ public class Bytestream extends IQ {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<").append(getElementName()).append(" ");
buf.append("jid=\"").append(getJID()).append("\" ");
buf.append("/>");
@ -443,7 +443,7 @@ public class Bytestream extends IQ {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<").append(getElementName()).append(">");
buf.append(getTarget());
buf.append("</").append(getElementName()).append(">");

View file

@ -20,14 +20,14 @@
package org.jivesoftware.smackx.packet;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smackx.FormField;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smackx.FormField;
/**
* Represents a form that could be use for gathering data as well as for reporting data
* returned from a search.
@ -38,10 +38,10 @@ public class DataForm implements PacketExtension {
private String type;
private String title;
private List instructions = new ArrayList();
private List<String> instructions = new ArrayList<String>();
private ReportedData reportedData;
private List items = new ArrayList();
private List fields = new ArrayList();
private final List<Item> items = new ArrayList<Item>();
private final List<FormField> fields = new ArrayList<FormField>();
public DataForm(String type) {
this.type = type;
@ -85,9 +85,9 @@ public class DataForm implements PacketExtension {
*
* @return an Iterator for the list of instructions that explain how to fill out the form.
*/
public Iterator getInstructions() {
public Iterator<String> getInstructions() {
synchronized (instructions) {
return Collections.unmodifiableList(new ArrayList(instructions)).iterator();
return Collections.unmodifiableList(new ArrayList<String>(instructions)).iterator();
}
}
@ -105,9 +105,9 @@ public class DataForm implements PacketExtension {
*
* @return an Iterator for the items returned from a search.
*/
public Iterator getItems() {
public Iterator<Item> getItems() {
synchronized (items) {
return Collections.unmodifiableList(new ArrayList(items)).iterator();
return Collections.unmodifiableList(new ArrayList<Item>(items)).iterator();
}
}
@ -116,9 +116,9 @@ public class DataForm implements PacketExtension {
*
* @return an Iterator for the fields that are part of the form.
*/
public Iterator getFields() {
public Iterator<FormField> getFields() {
synchronized (fields) {
return Collections.unmodifiableList(new ArrayList(fields)).iterator();
return Collections.unmodifiableList(new ArrayList<FormField>(fields)).iterator();
}
}
@ -147,7 +147,7 @@ public class DataForm implements PacketExtension {
*
* @param instructions list of instructions that explain how to fill out the form.
*/
public void setInstructions(List instructions) {
public void setInstructions(List<String> instructions) {
this.instructions = instructions;
}
@ -196,7 +196,7 @@ public class DataForm implements PacketExtension {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append(
"\" type=\"" + getType() +"\">");
if (getTitle() != null) {
@ -231,9 +231,9 @@ public class DataForm implements PacketExtension {
* @author Gaston Dombiak
*/
public static class ReportedData {
private List fields = new ArrayList();
private List<FormField> fields = new ArrayList<FormField>();
public ReportedData(List fields) {
public ReportedData(List<FormField> fields) {
this.fields = fields;
}
@ -242,12 +242,12 @@ public class DataForm implements PacketExtension {
*
* @return the fields returned from a search.
*/
public Iterator getFields() {
return Collections.unmodifiableList(new ArrayList(fields)).iterator();
public Iterator<FormField> getFields() {
return Collections.unmodifiableList(new ArrayList<FormField>(fields)).iterator();
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<reported>");
// Loop through all the form items and append them to the string buffer
for (Iterator i = getFields(); i.hasNext();) {
@ -266,9 +266,9 @@ public class DataForm implements PacketExtension {
* @author Gaston Dombiak
*/
public static class Item {
private List fields = new ArrayList();
private List<FormField> fields = new ArrayList<FormField>();
public Item(List fields) {
public Item(List<FormField> fields) {
this.fields = fields;
}
@ -277,12 +277,12 @@ public class DataForm implements PacketExtension {
*
* @return the fields that define the data that goes with the item.
*/
public Iterator getFields() {
return Collections.unmodifiableList(new ArrayList(fields)).iterator();
public Iterator<FormField> getFields() {
return Collections.unmodifiableList(new ArrayList<FormField>(fields)).iterator();
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<item>");
// Loop through all the form items and append them to the string buffer
for (Iterator i = getFields(); i.hasNext();) {

View file

@ -20,10 +20,10 @@
package org.jivesoftware.smackx.packet;
import java.util.Map;
import java.util.Iterator;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* Default implementation of the PrivateData interface. Unless a PrivateDataProvider
@ -83,7 +83,7 @@ public class DefaultPrivateData implements PrivateData {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<").append(elementName).append(" xmlns=\"").append(namespace).append("\">");
for (Iterator i=getNames(); i.hasNext(); ) {
String name = (String)i.next();

View file

@ -20,12 +20,12 @@
package org.jivesoftware.smackx.packet;
import org.jivesoftware.smack.packet.PacketExtension;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import org.jivesoftware.smack.packet.PacketExtension;
/**
* Represents timestamp information about data stored for later delivery. A DelayInformation will
* always includes the timestamp when the packet was originally sent and may include more
@ -124,7 +124,7 @@ public class DelayInformation implements PacketExtension {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append(
"\"");
buf.append(" stamp=\"");

View file

@ -20,10 +20,13 @@
package org.jivesoftware.smackx.packet;
import java.util.*;
import org.jivesoftware.smack.packet.IQ;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/**
* A DiscoverInfo IQ packet, which is used by XMPP clients to request and receive information
* to/from other XMPP entities.<p>
@ -35,8 +38,8 @@ import org.jivesoftware.smack.packet.IQ;
*/
public class DiscoverInfo extends IQ {
private List features = new ArrayList();
private List identities = new ArrayList();
private final List<Feature> features = new ArrayList<Feature>();
private final List<Identity> identities = new ArrayList<Identity>();
private String node;
/**
@ -59,9 +62,9 @@ public class DiscoverInfo extends IQ {
*
* @return an Iterator on the discovered features of an XMPP entity
*/
Iterator getFeatures() {
Iterator<Feature> getFeatures() {
synchronized (features) {
return Collections.unmodifiableList(new ArrayList(features)).iterator();
return Collections.unmodifiableList(new ArrayList<Feature>(features)).iterator();
}
}
@ -81,9 +84,9 @@ public class DiscoverInfo extends IQ {
*
* @return an Iterator on the discoveted identities
*/
public Iterator getIdentities() {
public Iterator<Identity> getIdentities() {
synchronized (identities) {
return Collections.unmodifiableList(new ArrayList(identities)).iterator();
return Collections.unmodifiableList(new ArrayList<Identity>(identities)).iterator();
}
}
@ -120,15 +123,15 @@ public class DiscoverInfo extends IQ {
* @return true if the requestes feature has been discovered
*/
public boolean containsFeature(String feature) {
for (Iterator it = getFeatures(); it.hasNext();) {
if (feature.equals(((DiscoverInfo.Feature) it.next()).getVar()))
for (Iterator<Feature> it = getFeatures(); it.hasNext();) {
if (feature.equals(it.next().getVar()))
return true;
}
return false;
}
public String getChildElementXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<query xmlns=\"http://jabber.org/protocol/disco#info\"");
if (getNode() != null) {
buf.append(" node=\"");
@ -137,14 +140,12 @@ public class DiscoverInfo extends IQ {
}
buf.append(">");
synchronized (identities) {
for (int i = 0; i < identities.size(); i++) {
Identity identity = (Identity) identities.get(i);
for (Identity identity : identities) {
buf.append(identity.toXML());
}
}
synchronized (features) {
for (int i = 0; i < features.size(); i++) {
Feature feature = (Feature) features.get(i);
for (Feature feature : features) {
buf.append(feature.toXML());
}
}
@ -220,7 +221,7 @@ public class DiscoverInfo extends IQ {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<identity category=\"").append(category).append("\"");
buf.append(" name=\"").append(name).append("\"");
if (type != null) {
@ -260,7 +261,7 @@ public class DiscoverInfo extends IQ {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<feature var=\"").append(variable).append("\"/>");
return buf.toString();
}

View file

@ -20,10 +20,13 @@
package org.jivesoftware.smackx.packet;
import java.util.*;
import org.jivesoftware.smack.packet.IQ;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/**
* A DiscoverItems IQ packet, which is used by XMPP clients to request and receive items
* associated with XMPP entities.<p>
@ -35,7 +38,7 @@ import org.jivesoftware.smack.packet.IQ;
*/
public class DiscoverItems extends IQ {
private List items = new ArrayList();
private final List<DiscoverItems.Item> items = new ArrayList<DiscoverItems.Item>();
private String node;
/**
@ -54,9 +57,10 @@ public class DiscoverItems extends IQ {
*
* @return an Iterator on the discovered entity's items
*/
public Iterator getItems() {
public Iterator<DiscoverItems.Item> getItems() {
synchronized (items) {
return Collections.unmodifiableList(new ArrayList(items)).iterator();
return Collections.unmodifiableList(new ArrayList<DiscoverItems.Item>(items))
.iterator();
}
}
@ -87,7 +91,7 @@ public class DiscoverItems extends IQ {
}
public String getChildElementXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<query xmlns=\"http://jabber.org/protocol/disco#items\"");
if (getNode() != null) {
buf.append(" node=\"");
@ -97,7 +101,7 @@ public class DiscoverItems extends IQ {
buf.append(">");
synchronized (items) {
for (int i = 0; i < items.size(); i++) {
Item item = (Item) items.get(i);
Item item = items.get(i);
buf.append(item.toXML());
}
}
@ -217,7 +221,7 @@ public class DiscoverItems extends IQ {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<item jid=\"").append(entityID).append("\"");
if (name != null) {
buf.append(" name=\"").append(name).append("\"");

View file

@ -93,7 +93,7 @@ public class IBBExtensions {
}
public String getChildElementXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append("\" ");
buf.append("sid=\"").append(getSessionID()).append("\" ");
buf.append("block-size=\"").append(getBlockSize()).append("\"");
@ -193,7 +193,7 @@ public class IBBExtensions {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace())
.append("\" ");
buf.append("sid=\"").append(getSessionID()).append("\" ");
@ -230,7 +230,7 @@ public class IBBExtensions {
}
public String getChildElementXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append("\" ");
buf.append("sid=\"").append(getSessionID()).append("\"");
buf.append("/>");

View file

@ -25,10 +25,10 @@ import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.util.StringUtils;
import org.xmlpull.v1.XmlPullParser;
/**
@ -56,7 +56,7 @@ public class LastActivity extends IQ {
}
public String getChildElementXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<query xmlns=\"jabber:iq:last\"></query>");
return buf.toString();
}

View file

@ -19,10 +19,13 @@
*/
package org.jivesoftware.smackx.packet;
import java.util.*;
import org.jivesoftware.smack.packet.IQ;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/**
* IQ packet that serves for kicking users, granting and revoking voice, banning users,
* modifying the ban list, granting and revoking membership and granting and revoking
@ -60,7 +63,7 @@ public class MUCAdmin extends IQ {
}
public String getChildElementXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<query xmlns=\"http://jabber.org/protocol/muc#admin\">");
synchronized (items) {
for (int i = 0; i < items.size(); i++) {
@ -201,7 +204,7 @@ public class MUCAdmin extends IQ {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<item");
if (getAffiliation() != null) {
buf.append(" affiliation=\"").append(getAffiliation()).append("\"");

View file

@ -20,12 +20,12 @@
package org.jivesoftware.smackx.packet;
import org.jivesoftware.smack.packet.PacketExtension;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import org.jivesoftware.smack.packet.PacketExtension;
/**
* Represents extended presence information whose sole purpose is to signal the ability of
* the occupant to speak the MUC protocol when joining a room. If the room requires a password
@ -52,7 +52,7 @@ public class MUCInitialPresence implements PacketExtension {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append(
"\">");
if (getPassword() != null) {
@ -200,7 +200,7 @@ public class MUCInitialPresence implements PacketExtension {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<history");
if (getMaxChars() != -1) {
buf.append(" maxchars=\"").append(getMaxChars()).append("\"");

View file

@ -19,10 +19,13 @@
*/
package org.jivesoftware.smackx.packet;
import java.util.*;
import org.jivesoftware.smack.packet.IQ;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/**
* IQ packet that serves for granting and revoking ownership privileges, granting
* and revoking administrative privileges and destroying a room. All these operations
@ -82,7 +85,7 @@ public class MUCOwner extends IQ {
}
public String getChildElementXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<query xmlns=\"http://jabber.org/protocol/muc#owner\">");
synchronized (items) {
for (int i = 0; i < items.size(); i++) {
@ -237,7 +240,7 @@ public class MUCOwner extends IQ {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<item");
if (getAffiliation() != null) {
buf.append(" affiliation=\"").append(getAffiliation()).append("\"");
@ -317,7 +320,7 @@ public class MUCOwner extends IQ {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<destroy");
if (getJid() != null) {
buf.append(" jid=\"").append(getJid()).append("\"");

View file

@ -46,7 +46,7 @@ public class MUCUser implements PacketExtension {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append(
"\">");
if (getInvite() != null) {
@ -261,7 +261,7 @@ public class MUCUser implements PacketExtension {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<invite ");
if (getTo() != null) {
buf.append(" to=\"").append(getTo()).append("\"");
@ -346,7 +346,7 @@ public class MUCUser implements PacketExtension {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<decline ");
if (getTo() != null) {
buf.append(" to=\"").append(getTo()).append("\"");
@ -490,7 +490,7 @@ public class MUCUser implements PacketExtension {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<item");
if (getAffiliation() != null) {
buf.append(" affiliation=\"").append(getAffiliation()).append("\"");
@ -550,7 +550,7 @@ public class MUCUser implements PacketExtension {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<status code=\"").append(getCode()).append("\"/>");
return buf.toString();
}
@ -605,7 +605,7 @@ public class MUCUser implements PacketExtension {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<destroy");
if (getJid() != null) {
buf.append(" jid=\"").append(getJid()).append("\"");

View file

@ -20,10 +20,11 @@
package org.jivesoftware.smackx.packet;
import java.util.*;
import org.jivesoftware.smack.packet.PacketExtension;
import java.util.ArrayList;
import java.util.Iterator;
/**
* Represents message events relating to the delivery, display, composition and cancellation of
* messages.<p>
@ -303,7 +304,7 @@ public class MessageEvent implements PacketExtension {
*
*/
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append(
"\">");
// Note: Cancellation events don't specify any tag. They just send the packetID

View file

@ -105,7 +105,7 @@ public class MultipleAddresses implements PacketExtension {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<").append(getElementName());
buf.append(" xmlns=\"").append(getNamespace()).append("\">");
// Loop through all the addresses and append them to the string buffer
@ -175,7 +175,7 @@ public class MultipleAddresses implements PacketExtension {
}
private String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<address type=\"");
// Append the address type (e.g. TO/CC/BCC)
buf.append(type).append("\"");

View file

@ -79,7 +79,7 @@ public class OfflineMessageInfo implements PacketExtension {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append(
"\">");
if (getNode() != null)

View file

@ -102,7 +102,7 @@ public class OfflineMessageRequest extends IQ {
}
public String getChildElementXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<offline xmlns=\"http://jabber.org/protocol/offline\">");
synchronized (items) {
for (int i = 0; i < items.size(); i++) {
@ -175,7 +175,7 @@ public class OfflineMessageRequest extends IQ {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<item");
if (getAction() != null) {
buf.append(" action=\"").append(getAction()).append("\"");

View file

@ -20,11 +20,16 @@
package org.jivesoftware.smackx.packet;
import java.util.*;
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.RosterEntry;
import org.jivesoftware.smack.RosterGroup;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smackx.*;
import org.jivesoftware.smackx.RemoteRosterEntry;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/**
* Represents XMPP Roster Item Exchange packets.<p>
@ -161,7 +166,7 @@ public class RosterExchange implements PacketExtension {
*
*/
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append(
"\">");
// Loop through all roster entries and append them to the string buffer

View file

@ -31,7 +31,7 @@ public class SharedGroupsInfo extends IQ {
}
public String getChildElementXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<sharedgroup xmlns=\"http://www.jivesoftware.org/protocol/sharedgroup\">");
for (Iterator it=groups.iterator(); it.hasNext();) {
buf.append("<group>").append(it.next()).append("</group>");

View file

@ -134,7 +134,7 @@ public class StreamInitiation extends IQ {
* @see org.jivesoftware.smack.packet.IQ#getChildElementXML()
*/
public String getChildElementXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
if (this.getType().equals(IQ.Type.SET)) {
buf.append("<si xmlns=\"http://jabber.org/protocol/si\" ");
if (getSessionID() != null) {
@ -333,7 +333,7 @@ public class StreamInitiation extends IQ {
}
public String toXML() {
StringBuffer buffer = new StringBuffer();
StringBuilder buffer = new StringBuilder();
buffer.append("<").append(getElementName()).append(" xmlns=\"")
.append(getNamespace()).append("\" ");
@ -408,7 +408,7 @@ public class StreamInitiation extends IQ {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf
.append("<feature xmlns=\"http://jabber.org/protocol/feature-neg\">");
buf.append(data.toXML());

View file

@ -22,9 +22,11 @@ package org.jivesoftware.smackx.packet;
import org.jivesoftware.smack.packet.IQ;
import java.util.*;
import java.text.SimpleDateFormat;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
/**
* A Time IQ packet, which is used by XMPP clients to exchange their respective local
@ -179,7 +181,7 @@ public class Time extends IQ {
}
public String getChildElementXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<query xmlns=\"jabber:iq:time\">");
if (utc != null) {
buf.append("<utc>").append(utc).append("</utc>");

View file

@ -26,8 +26,8 @@ import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.util.StringUtils;
import java.io.BufferedInputStream;
@ -89,8 +89,8 @@ public class VCard extends IQ {
* Phone types:
* VOICE?, FAX?, PAGER?, MSG?, CELL?, VIDEO?, BBS?, MODEM?, ISDN?, PCS?, PREF?
*/
private Map homePhones = new HashMap();
private Map workPhones = new HashMap();
private Map<String, String> homePhones = new HashMap<String, String>();
private Map<String, String> workPhones = new HashMap<String, String>();
/**
@ -98,8 +98,8 @@ public class VCard extends IQ {
* POSTAL?, PARCEL?, (DOM | INTL)?, PREF?, POBOX?, EXTADR?, STREET?, LOCALITY?,
* REGION?, PCODE?, CTRY?
*/
private Map homeAddr = new HashMap();
private Map workAddr = new HashMap();
private Map<String, String> homeAddr = new HashMap<String, String>();
private Map<String, String> workAddr = new HashMap<String, String>();
private String firstName;
private String lastName;
@ -116,10 +116,10 @@ public class VCard extends IQ {
/**
* Such as DESC ROLE GEO etc.. see JEP-0054
*/
private Map otherSimpleFields = new HashMap();
private Map<String, String> otherSimpleFields = new HashMap<String, String>();
// fields that, as they are should not be escaped before forwarding to the server
private Map otherUnescapableFields = new HashMap();
private Map<String, String> otherUnescapableFields = new HashMap<String, String>();
public VCard() {
}
@ -131,7 +131,7 @@ public class VCard extends IQ {
* GEO, TITLE, ROLE, LOGO, NOTE, PRODID, REV, SORT-STRING, SOUND, UID, URL, DESC.
*/
public String getField(String field) {
return (String) otherSimpleFields.get(field);
return otherSimpleFields.get(field);
}
/**
@ -168,6 +168,8 @@ public class VCard extends IQ {
public void setFirstName(String firstName) {
this.firstName = firstName;
// Update FN field
updateFN();
}
public String getLastName() {
@ -176,6 +178,8 @@ public class VCard extends IQ {
public void setLastName(String lastName) {
this.lastName = lastName;
// Update FN field
updateFN();
}
public String getMiddleName() {
@ -184,10 +188,12 @@ public class VCard extends IQ {
public void setMiddleName(String middleName) {
this.middleName = middleName;
// Update FN field
updateFN();
}
public String getNickName() {
return (String) otherSimpleFields.get("NICKNAME");
return otherSimpleFields.get("NICKNAME");
}
public void setNickName(String nickName) {
@ -211,7 +217,7 @@ public class VCard extends IQ {
}
public String getJabberId() {
return (String) otherSimpleFields.get("JABBERID");
return otherSimpleFields.get("JABBERID");
}
public void setJabberId(String jabberId) {
@ -241,7 +247,7 @@ public class VCard extends IQ {
* LOCALITY, REGION, PCODE, CTRY
*/
public String getAddressFieldHome(String addrField) {
return (String) homeAddr.get(addrField);
return homeAddr.get(addrField);
}
/**
@ -261,7 +267,7 @@ public class VCard extends IQ {
* LOCALITY, REGION, PCODE, CTRY
*/
public String getAddressFieldWork(String addrField) {
return (String) workAddr.get(addrField);
return workAddr.get(addrField);
}
/**
@ -291,7 +297,7 @@ public class VCard extends IQ {
* @param phoneType one of VOICE, FAX, PAGER, MSG, CELL, VIDEO, BBS, MODEM, ISDN, PCS, PREF
*/
public String getPhoneHome(String phoneType) {
return (String) homePhones.get(phoneType);
return homePhones.get(phoneType);
}
/**
@ -310,7 +316,7 @@ public class VCard extends IQ {
* @param phoneType one of VOICE, FAX, PAGER, MSG, CELL, VIDEO, BBS, MODEM, ISDN, PCS, PREF
*/
public String getPhoneWork(String phoneType) {
return (String) workPhones.get(phoneType);
return workPhones.get(phoneType);
}
/**
@ -442,6 +448,20 @@ public class VCard extends IQ {
return StringUtils.encodeHex(digest.digest());
}
private void updateFN() {
StringBuilder sb = new StringBuilder();
if (firstName != null) {
sb.append(StringUtils.escapeForXML(firstName)).append(' ');
}
if (middleName != null) {
sb.append(StringUtils.escapeForXML(middleName)).append(' ');
}
if (lastName != null) {
sb.append(StringUtils.escapeForXML(lastName));
}
setField("FN", sb.toString());
}
/**
* Save this vCard for the user connected by 'connection'. Connection should be authenticated
* and not anonymous.<p>
@ -516,7 +536,7 @@ public class VCard extends IQ {
}
public String getChildElementXML() {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
new VCardWriter(sb).write();
return sb.toString();
}
@ -525,8 +545,7 @@ public class VCard extends IQ {
if (result == null) result = new VCard();
Field[] fields = VCard.class.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
Field field = fields[i];
for (Field field : fields) {
if (field.getDeclaringClass() == VCard.class &&
!Modifier.isFinal(field.getModifiers())) {
try {
@ -647,9 +666,9 @@ public class VCard extends IQ {
private class VCardWriter {
private final StringBuffer sb;
private final StringBuilder sb;
VCardWriter(StringBuffer sb) {
VCardWriter(StringBuilder sb) {
this.sb = sb;
}
@ -663,7 +682,6 @@ public class VCard extends IQ {
private void buildActualContent() {
if (hasNameField()) {
appendFN();
appendN();
}
@ -693,7 +711,7 @@ public class VCard extends IQ {
}
}
private void appendPhones(Map phones, final String code) {
private void appendPhones(Map<String, String> phones, final String code) {
Iterator it = phones.entrySet().iterator();
while (it.hasNext()) {
final Map.Entry entry = (Map.Entry) it.next();
@ -707,7 +725,7 @@ public class VCard extends IQ {
}
}
private void appendAddress(final Map addr, final String code) {
private void appendAddress(final Map<String, String> addr, final String code) {
if (addr.size() > 0) {
appendTag("ADR", true, new ContentBuilder() {
public void addTagContent() {
@ -753,23 +771,6 @@ public class VCard extends IQ {
}
}
private void appendFN() {
final ContentBuilder contentBuilder = new ContentBuilder() {
public void addTagContent() {
if (firstName != null) {
sb.append(StringUtils.escapeForXML(firstName)).append(' ');
}
if (middleName != null) {
sb.append(StringUtils.escapeForXML(middleName)).append(' ');
}
if (lastName != null) {
sb.append(StringUtils.escapeForXML(lastName));
}
}
};
appendTag("FN", true, contentBuilder);
}
private void appendN() {
appendTag("N", true, new ContentBuilder() {
public void addTagContent() {

View file

@ -115,7 +115,7 @@ public class Version extends IQ {
}
public String getChildElementXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<query xmlns=\"jabber:iq:version\">");
if (name != null) {
buf.append("<name>").append(name).append("</name>");

View file

@ -20,10 +20,13 @@
package org.jivesoftware.smackx.packet;
import java.util.*;
import org.jivesoftware.smack.packet.PacketExtension;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/**
* An XHTML sub-packet, which is used by XMPP clients to exchange formatted text. The XHTML
* extension is only a subset of XHTML 1.0.<p>
@ -78,7 +81,7 @@ public class XHTMLExtension implements PacketExtension {
*
*/
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append(
"\">");
// Loop through all the bodies and append them to the string buffer