1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-12-06 05:01:12 +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

@ -20,11 +20,15 @@
package org.jivesoftware.smackx;
import java.util.*;
import org.jivesoftware.smack.packet.*;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smackx.packet.DataForm;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
/**
* Represents a Form for gathering data. The form could be of the following types:
* <ul>
@ -334,8 +338,8 @@ public class Form {
// Clear the old values
field.resetValues();
// Set the default value
for (Iterator it = field.getValues(); it.hasNext();) {
field.addValue((String) it.next());
for (Iterator<String> it = field.getValues(); it.hasNext();) {
field.addValue(it.next());
}
}
else {
@ -348,7 +352,7 @@ public class Form {
*
* @return an Iterator for the fields that are part of the form.
*/
public Iterator getFields() {
public Iterator<FormField> getFields() {
return dataForm.getFields();
}
@ -366,8 +370,8 @@ public class Form {
}
// Look for the field whose variable matches the requested variable
FormField field;
for (Iterator it=getFields();it.hasNext();) {
field = (FormField)it.next();
for (Iterator<FormField> it=getFields();it.hasNext();) {
field = it.next();
if (variable.equals(field.getVariable())) {
return field;
}
@ -381,7 +385,7 @@ public class Form {
* @return instructions that explain how to fill out the form.
*/
public String getInstructions() {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
// Join the list of instructions together separated by newlines
for (Iterator it = dataForm.getInstructions(); it.hasNext();) {
sb.append((String) it.next());
@ -432,7 +436,7 @@ public class Form {
*/
public void setInstructions(String instructions) {
// Split the instructions into multiple instructions for each existent newline
ArrayList instructionsList = new ArrayList();
ArrayList<String> instructionsList = new ArrayList<String>();
StringTokenizer st = new StringTokenizer(instructions, "\n");
while (st.hasMoreTokens()) {
instructionsList.add(st.nextToken());
@ -464,8 +468,8 @@ public class Form {
if (isSubmitType()) {
// Create a new DataForm that contains only the answered fields
DataForm dataFormToSend = new DataForm(getType());
for(Iterator it=getFields();it.hasNext();) {
FormField field = (FormField)it.next();
for(Iterator<FormField> it=getFields();it.hasNext();) {
FormField field = it.next();
if (field.getValues().hasNext()) {
dataFormToSend.addField(field);
}
@ -513,8 +517,8 @@ public class Form {
}
// Create a new Form
Form form = new Form(TYPE_SUBMIT);
for (Iterator fields=getFields(); fields.hasNext();) {
FormField field = (FormField)fields.next();
for (Iterator<FormField> fields=getFields(); fields.hasNext();) {
FormField field = fields.next();
// Add to the new form any type of field that includes a variable.
// Note: The fields of type FIXED are the only ones that don't specify a variable
if (field.getVariable() != null) {
@ -525,9 +529,9 @@ public class Form {
if (FormField.TYPE_HIDDEN.equals(field.getType())) {
// Since a hidden field could have many values we need to collect them
// in a list
List values = new ArrayList();
for (Iterator it=field.getValues();it.hasNext();) {
values.add((String)it.next());
List<String> values = new ArrayList<String>();
for (Iterator<String> it=field.getValues();it.hasNext();) {
values.add(it.next());
}
form.setAnswer(field.getVariable(), values);
}

View file

@ -20,7 +20,10 @@
package org.jivesoftware.smackx;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/**
* Represents a field of a form. The field could be used to represent a question to complete,
@ -46,8 +49,8 @@ public class FormField {
private String label;
private String variable;
private String type;
private List options = new ArrayList();
private List values = new ArrayList();
private final List<Option> options = new ArrayList<Option>();
private final List<String> values = new ArrayList<String>();
/**
* Creates a new FormField with the variable name that uniquely identifies the field
@ -97,9 +100,9 @@ public class FormField {
*
* @return Iterator for the available options.
*/
public Iterator getOptions() {
public Iterator<Option> getOptions() {
synchronized (options) {
return Collections.unmodifiableList(new ArrayList(options)).iterator();
return Collections.unmodifiableList(new ArrayList<Option>(options)).iterator();
}
}
@ -144,9 +147,9 @@ public class FormField {
*
* @return an Iterator for the default values or answered values of the question.
*/
public Iterator getValues() {
public Iterator<String> getValues() {
synchronized (values) {
return Collections.unmodifiableList(new ArrayList(values)).iterator();
return Collections.unmodifiableList(new ArrayList<String>(values)).iterator();
}
}
@ -234,7 +237,7 @@ public class FormField {
*
* @param newValues default values or an answered values of the question.
*/
public void addValues(List newValues) {
public void addValues(List<String> newValues) {
synchronized (values) {
values.addAll(newValues);
}
@ -246,7 +249,7 @@ public class FormField {
*/
protected void resetValues() {
synchronized (values) {
values.removeAll(new ArrayList(values));
values.removeAll(new ArrayList<String>(values));
}
}
@ -263,7 +266,7 @@ public class FormField {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<field");
// Add attributes
if (getLabel() != null) {
@ -284,7 +287,7 @@ public class FormField {
buf.append("<required/>");
}
// Loop through all the values and append them to the string buffer
for (Iterator i = getValues(); i.hasNext();) {
for (Iterator<String> i = getValues(); i.hasNext();) {
buf.append("<value>").append(i.next()).append("</value>");
}
// Loop through all the values and append them to the string buffer
@ -337,7 +340,7 @@ public class FormField {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<option");
// Add attribute
if (getLabel() != null) {

View file

@ -99,7 +99,7 @@ public class GroupChatInvitation implements PacketExtension {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<x xmlns=\"jabber:x:conference\" jid=\"").append(roomAddress).append("\"/>");
return buf.toString();
}

View file

@ -20,6 +20,8 @@
package org.jivesoftware.smackx;
import org.jivesoftware.smackx.packet.DiscoverItems;
import java.util.Iterator;
@ -40,7 +42,7 @@ public interface NodeInformationProvider {
*
* @return an Iterator on the Items defined in the node.
*/
public abstract Iterator getNodeItems();
public abstract Iterator<DiscoverItems.Item> getNodeItems();
/**
* Returns an Iterator on the features defined in the node. For
@ -50,5 +52,5 @@ public interface NodeInformationProvider {
*
* @return an Iterator on the feature strings defined in the node.
*/
public abstract Iterator getNodeFeatures();
public abstract Iterator<String> getNodeFeatures();
}

View file

@ -93,7 +93,7 @@ public class OfflineMessageManager {
namespace);
Form extendedInfo = Form.getFormFrom(info);
if (extendedInfo != null) {
String value = (String) extendedInfo.getField("number_of_messages").getValues().next();
String value = extendedInfo.getField("number_of_messages").getValues().next();
return Integer.parseInt(value);
}
return 0;
@ -109,8 +109,8 @@ public class OfflineMessageManager {
* @throws XMPPException If the user is not allowed to make this request or the server does
* not support offline message retrieval.
*/
public Iterator getHeaders() throws XMPPException {
List answer = new ArrayList();
public Iterator<OfflineMessageHeader> getHeaders() throws XMPPException {
List<OfflineMessageHeader> answer = new ArrayList<OfflineMessageHeader>();
DiscoverItems items = ServiceDiscoveryManager.getInstanceFor(connection).discoverItems(
null, namespace);
for (Iterator it = items.getItems(); it.hasNext();) {
@ -132,11 +132,11 @@ public class OfflineMessageManager {
* @throws XMPPException If the user is not allowed to make this request or the server does
* not support offline message retrieval.
*/
public Iterator getMessages(final List nodes) throws XMPPException {
List messages = new ArrayList();
public Iterator<Message> getMessages(final List<String> nodes) throws XMPPException {
List<Message> messages = new ArrayList<Message>();
OfflineMessageRequest request = new OfflineMessageRequest();
for (Iterator it = nodes.iterator(); it.hasNext();) {
OfflineMessageRequest.Item item = new OfflineMessageRequest.Item((String) it.next());
for (String node : nodes) {
OfflineMessageRequest.Item item = new OfflineMessageRequest.Item(node);
item.setAction("view");
request.addItem(item);
}
@ -188,8 +188,8 @@ public class OfflineMessageManager {
* @throws XMPPException If the user is not allowed to make this request or the server does
* not support offline message retrieval.
*/
public Iterator getMessages() throws XMPPException {
List messages = new ArrayList();
public Iterator<Message> getMessages() throws XMPPException {
List<Message> messages = new ArrayList<Message>();
OfflineMessageRequest request = new OfflineMessageRequest();
request.setFetch(true);
// Filter packets looking for an answer from the server.
@ -232,10 +232,10 @@ public class OfflineMessageManager {
* @throws XMPPException If the user is not allowed to make this request or the server does
* not support offline message retrieval.
*/
public void deleteMessages(List nodes) throws XMPPException {
public void deleteMessages(List<String> nodes) throws XMPPException {
OfflineMessageRequest request = new OfflineMessageRequest();
for (Iterator it = nodes.iterator(); it.hasNext();) {
OfflineMessageRequest.Item item = new OfflineMessageRequest.Item((String) it.next());
for (String node : nodes) {
OfflineMessageRequest.Item item = new OfflineMessageRequest.Item(node);
item.setAction("remove");
request.addItem(item);
}

View file

@ -20,16 +20,20 @@
package org.jivesoftware.smackx;
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
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.smackx.packet.*;
import org.jivesoftware.smackx.provider.*;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smackx.packet.DefaultPrivateData;
import org.jivesoftware.smackx.packet.PrivateData;
import org.jivesoftware.smackx.provider.PrivateDataProvider;
import org.xmlpull.v1.XmlPullParser;
import java.util.Map;
import java.util.Hashtable;
import java.util.Map;
/**
* Manages private data, which is a mechanism to allow users to store arbitrary XML
@ -177,7 +181,7 @@ public class PrivateDataManager {
// Create an IQ packet to get the private data.
IQ privateDataGet = new IQ() {
public String getChildElementXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<query xmlns=\"jabber:iq:private\">");
buf.append("<").append(elementName).append(" xmlns=\"").append(namespace).append("\"/>");
buf.append("</query>");
@ -223,7 +227,7 @@ public class PrivateDataManager {
// Create an IQ packet to set the private data.
IQ privateDataSet = new IQ() {
public String getChildElementXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<query xmlns=\"jabber:iq:private\">");
buf.append(privateData.toXML());
buf.append("</query>");
@ -264,7 +268,7 @@ public class PrivateDataManager {
* @return a unique key for the element name and namespace pair.
*/
private static String getProviderKey(String elementName, String namespace) {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<").append(elementName).append("/><").append(namespace).append("/>");
return buf.toString();
}
@ -343,7 +347,7 @@ public class PrivateDataManager {
}
public String getChildElementXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<query xmlns=\"jabber:iq:private\">");
if (privateData != null) {
privateData.toXML();

View file

@ -99,7 +99,7 @@ public class RemoteRosterEntry {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<item jid=\"").append(user).append("\"");
if (name != null) {
buf.append(" name=\"").append(name).append("\"");

View file

@ -20,11 +20,15 @@
package org.jivesoftware.smackx;
import java.util.*;
import org.jivesoftware.smack.packet.*;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smackx.packet.DataForm;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/**
* Represents a set of data results returned as part of a search. The report is structured
* in columns and rows.
@ -33,8 +37,8 @@ import org.jivesoftware.smackx.packet.DataForm;
*/
public class ReportedData {
private List columns = new ArrayList();
private List rows = new ArrayList();
private List<Column> columns = new ArrayList<Column>();
private List<Row> rows = new ArrayList<Row>();
private String title = "";
/**
@ -73,13 +77,13 @@ public class ReportedData {
// Add the rows to the report based on the form's items
for (Iterator items = dataForm.getItems(); items.hasNext();) {
DataForm.Item item = (DataForm.Item)items.next();
List fieldList = new ArrayList(columns.size());
List<Field> fieldList = new ArrayList<Field>(columns.size());
FormField field;
for (Iterator fields = item.getFields(); fields.hasNext();) {
field = (FormField) fields.next();
// The field is created with all the values of the data form's field
List values = new ArrayList();
for (Iterator it=field.getValues(); it.hasNext();) {
List<String> values = new ArrayList<String>();
for (Iterator<String> it=field.getValues(); it.hasNext();) {
values.add(it.next());
}
fieldList.add(new Field(field.getVariable(), values));
@ -118,8 +122,8 @@ public class ReportedData {
*
* @return an Iterator for the rows returned from a search.
*/
public Iterator getRows() {
return Collections.unmodifiableList(new ArrayList(rows)).iterator();
public Iterator<Row> getRows() {
return Collections.unmodifiableList(new ArrayList<Row>(rows)).iterator();
}
/**
@ -127,8 +131,8 @@ public class ReportedData {
*
* @return an Iterator for the columns returned from a search.
*/
public Iterator getColumns() {
return Collections.unmodifiableList(new ArrayList(columns)).iterator();
public Iterator<Column> getColumns() {
return Collections.unmodifiableList(new ArrayList<Column>(columns)).iterator();
}
@ -215,9 +219,9 @@ public class ReportedData {
}
public static class Row {
private List fields = new ArrayList();
private List<Field> fields = new ArrayList<Field>();
public Row(List fields) {
public Row(List<Field> fields) {
this.fields = fields;
}
@ -228,8 +232,8 @@ public class ReportedData {
* @return the values of the field whose variable matches the requested variable.
*/
public Iterator getValues(String variable) {
for(Iterator it=getFields();it.hasNext();) {
Field field = (Field) it.next();
for(Iterator<Field> it=getFields();it.hasNext();) {
Field field = it.next();
if (variable.equalsIgnoreCase(field.getVariable())) {
return field.getValues();
}
@ -242,16 +246,16 @@ public class ReportedData {
*
* @return the fields that define the data that goes with the item.
*/
private Iterator getFields() {
return Collections.unmodifiableList(new ArrayList(fields)).iterator();
private Iterator<Field> getFields() {
return Collections.unmodifiableList(new ArrayList<Field>(fields)).iterator();
}
}
public static class Field {
private String variable;
private List values;
private List<String> values;
public Field(String variable, List values) {
public Field(String variable, List<String> values) {
this.variable = variable;
this.values = values;
}
@ -270,7 +274,7 @@ public class ReportedData {
*
* @return the returned values of the search.
*/
public Iterator getValues() {
public Iterator<String> getValues() {
return Collections.unmodifiableList(values).iterator();
}
}

View file

@ -31,6 +31,7 @@ import org.jivesoftware.smackx.packet.DiscoverInfo;
import org.jivesoftware.smackx.packet.DiscoverItems;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
* Manages discovery of services in XMPP entities. This class provides:
@ -48,11 +49,13 @@ public class ServiceDiscoveryManager {
private static String identityName = "Smack";
private static String identityType = "pc";
private static Map instances = new Hashtable();
private static Map<XMPPConnection, ServiceDiscoveryManager> instances =
new ConcurrentHashMap<XMPPConnection, ServiceDiscoveryManager>();
private XMPPConnection connection;
private List features = new ArrayList();
private Map nodeInformationProviders = new Hashtable();
private final List<String> features = new ArrayList<String>();
private Map<String, NodeInformationProvider> nodeInformationProviders =
new ConcurrentHashMap<String, NodeInformationProvider>();
// Create a new ServiceDiscoveryManager on every established connection
static {
@ -82,7 +85,7 @@ public class ServiceDiscoveryManager {
* @return the ServiceDiscoveryManager associated with a given XMPPConnection.
*/
public static ServiceDiscoveryManager getInstanceFor(XMPPConnection connection) {
return (ServiceDiscoveryManager) instances.get(connection);
return instances.get(connection);
}
/**
@ -211,8 +214,8 @@ public class ServiceDiscoveryManager {
response.addIdentity(identity);
// Add the registered features to the response
synchronized (features) {
for (Iterator it = getFeatures(); it.hasNext();) {
response.addFeature((String) it.next());
for (Iterator<String> it = getFeatures(); it.hasNext();) {
response.addFeature(it.next());
}
}
}
@ -258,7 +261,7 @@ public class ServiceDiscoveryManager {
if (node == null) {
return null;
}
return (NodeInformationProvider) nodeInformationProviders.get(node);
return nodeInformationProviders.get(node);
}
/**
@ -297,9 +300,9 @@ public class ServiceDiscoveryManager {
*
* @return an Iterator on the supported features by this XMPP entity.
*/
public Iterator getFeatures() {
public Iterator<String> getFeatures() {
synchronized (features) {
return Collections.unmodifiableList(new ArrayList(features)).iterator();
return Collections.unmodifiableList(new ArrayList<String>(features)).iterator();
}
}

View file

@ -30,7 +30,7 @@ import org.jivesoftware.smack.util.StringUtils;
*/
public class XHTMLText {
private StringBuffer text = new StringBuffer(30);
private StringBuilder text = new StringBuilder(30);
/**
* Creates a new XHTMLText with body tag params.
@ -49,7 +49,7 @@ public class XHTMLText {
* @param style the XHTML style of the anchor
*/
public void appendOpenAnchorTag(String href, String style) {
StringBuffer sb = new StringBuffer("<a");
StringBuilder sb = new StringBuilder("<a");
if (href != null) {
sb.append(" href=\"");
sb.append(href);
@ -78,7 +78,7 @@ public class XHTMLText {
* @param style the XHTML style of the blockquote
*/
public void appendOpenBlockQuoteTag(String style) {
StringBuffer sb = new StringBuffer("<blockquote");
StringBuilder sb = new StringBuilder("<blockquote");
if (style != null) {
sb.append(" style=\"");
sb.append(style);
@ -103,7 +103,7 @@ public class XHTMLText {
* @param lang the language of the body
*/
private void appendOpenBodyTag(String style, String lang) {
StringBuffer sb = new StringBuffer("<body");
StringBuilder sb = new StringBuilder("<body");
if (style != null) {
sb.append(" style=\"");
sb.append(style);
@ -184,7 +184,7 @@ public class XHTMLText {
if (level > 3 || level < 1) {
return;
}
StringBuffer sb = new StringBuffer("<h");
StringBuilder sb = new StringBuilder("<h");
sb.append(level);
if (style != null) {
sb.append(" style=\"");
@ -204,7 +204,7 @@ public class XHTMLText {
if (level > 3 || level < 1) {
return;
}
StringBuffer sb = new StringBuffer("</h");
StringBuilder sb = new StringBuilder("</h");
sb.append(level);
sb.append(">");
text.append(sb.toString());
@ -220,7 +220,7 @@ public class XHTMLText {
* @param width how wide is the picture
*/
public void appendImageTag(String align, String alt, String height, String src, String width) {
StringBuffer sb = new StringBuffer("<img");
StringBuilder sb = new StringBuilder("<img");
if (align != null) {
sb.append(" align=\"");
sb.append(align);
@ -256,7 +256,7 @@ public class XHTMLText {
* @param style the style of the line item
*/
public void appendLineItemTag(String style) {
StringBuffer sb = new StringBuffer("<li");
StringBuilder sb = new StringBuilder("<li");
if (style != null) {
sb.append(" style=\"");
sb.append(style);
@ -273,7 +273,7 @@ public class XHTMLText {
* @param style the style of the ordered list
*/
public void appendOpenOrderedListTag(String style) {
StringBuffer sb = new StringBuffer("<ol");
StringBuilder sb = new StringBuilder("<ol");
if (style != null) {
sb.append(" style=\"");
sb.append(style);
@ -298,7 +298,7 @@ public class XHTMLText {
* @param style the style of the unordered list
*/
public void appendOpenUnorderedListTag(String style) {
StringBuffer sb = new StringBuffer("<ul");
StringBuilder sb = new StringBuilder("<ul");
if (style != null) {
sb.append(" style=\"");
sb.append(style);
@ -323,7 +323,7 @@ public class XHTMLText {
* @param style the style of the paragraph
*/
public void appendOpenParagraphTag(String style) {
StringBuffer sb = new StringBuffer("<p");
StringBuilder sb = new StringBuilder("<p");
if (style != null) {
sb.append(" style=\"");
sb.append(style);
@ -348,7 +348,7 @@ public class XHTMLText {
* @param style the style of the inlined quote
*/
public void appendOpenInlinedQuoteTag(String style) {
StringBuffer sb = new StringBuffer("<q");
StringBuilder sb = new StringBuilder("<q");
if (style != null) {
sb.append(" style=\"");
sb.append(style);
@ -372,7 +372,7 @@ public class XHTMLText {
* @param style the style for a span of text
*/
public void appendOpenSpanTag(String style) {
StringBuffer sb = new StringBuffer("<span");
StringBuilder sb = new StringBuilder("<span");
if (style != null) {
sb.append(" style=\"");
sb.append(style);

View file

@ -12,10 +12,10 @@ import org.jivesoftware.smackx.provider.PrivateDataProvider;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.io.IOException;
/**
* Bookmarks is used for storing and retrieving URLS and Conference rooms.
@ -155,7 +155,7 @@ public class Bookmarks implements PrivateData {
* @return the private data as XML.
*/
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<storage xmlns=\"storage:bookmarks\">");
final Iterator urls = getBookmarkedURLS().iterator();

View file

@ -312,7 +312,7 @@ public class FileTransferNegotiator {
* @return Returns a new, unique, stream ID to identify a file transfer.
*/
public String getNextStreamID() {
StringBuffer buffer = new StringBuffer();
StringBuilder buffer = new StringBuilder();
buffer.append(STREAM_INIT_PREFIX);
buffer.append(Math.abs(randomGenerator.nextLong()));
@ -398,8 +398,8 @@ public class FileTransferNegotiator {
String variable;
boolean isByteStream = false;
boolean isIBB = false;
for (Iterator it = field.getValues(); it.hasNext();) {
variable = (it.next().toString());
for (Iterator<String> it = field.getValues(); it.hasNext();) {
variable = it.next();
if (variable.equals(BYTE_STREAM) && !IBB_ONLY) {
isByteStream = true;
}

View file

@ -65,7 +65,7 @@ public class DeafOccupantInterceptor implements PacketInterceptor {
}
public String toXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace())
.append("\">");
buf.append("<deaf-occupant/>");

File diff suppressed because it is too large Load diff

View file

@ -20,8 +20,8 @@
package org.jivesoftware.smackx.muc;
import org.jivesoftware.smackx.packet.DiscoverInfo;
import org.jivesoftware.smackx.Form;
import org.jivesoftware.smackx.packet.DiscoverInfo;
/**
* Represents the room information that was discovered using Service Discovery. It's possible to
@ -87,10 +87,10 @@ public class RoomInfo {
Form form = Form.getFormFrom(info);
if (form != null) {
this.description =
(String) form.getField("muc#roominfo_description").getValues().next();
this.subject = (String) form.getField("muc#roominfo_subject").getValues().next();
form.getField("muc#roominfo_description").getValues().next();
this.subject = form.getField("muc#roominfo_subject").getValues().next();
this.occupantsCount =
Integer.parseInt((String) form.getField("muc#roominfo_occupants").getValues()
Integer.parseInt(form.getField("muc#roominfo_occupants").getValues()
.next());
}
}

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

View file

@ -47,7 +47,7 @@ public class BytestreamsProvider implements IQProvider {
* @see org.jivesoftware.smack.provider.IQProvider#parseIQ(org.xmlpull.v1.XmlPullParser)
*/
public IQ parseIQ(XmlPullParser parser) throws Exception {
// StringBuffer buf = new StringBuffer();
// StringBuilder buf = new StringBuilder();
boolean done = false;
Bytestream toReturn = new Bytestream();

View file

@ -20,15 +20,15 @@
package org.jivesoftware.smackx.provider;
import java.util.ArrayList;
import java.util.List;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smackx.FormField;
import org.jivesoftware.smackx.packet.DataForm;
import org.xmlpull.v1.XmlPullParser;
import java.util.ArrayList;
import java.util.List;
/**
* The DataFormProvider parses DataForm packets.
*
@ -45,7 +45,7 @@ public class DataFormProvider implements PacketExtensionProvider {
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
boolean done = false;
StringBuffer buffer = null;
StringBuilder buffer = null;
DataForm dataForm = new DataForm(parser.getAttributeValue("", "type"));
while (!done) {
int eventType = parser.next();

View file

@ -32,8 +32,8 @@ import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
import java.util.List;
/**
* vCard provider.
@ -45,7 +45,7 @@ public class VCardProvider implements IQProvider {
private final static String PREFERRED_ENCODING = "UTF-8";
public IQ parseIQ(XmlPullParser parser) throws Exception {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
try {
int event = parser.getEventType();
// get the content
@ -229,12 +229,12 @@ public class VCardProvider implements IQProvider {
}
private String getTextContent(Node node) {
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
appendText(result, node);
return result.toString();
}
private void appendText(StringBuffer result, Node node) {
private void appendText(StringBuilder result, Node node) {
NodeList childNodes = node.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node nd = childNodes.item(i);

View file

@ -51,7 +51,7 @@ public class XHTMLExtensionProvider implements PacketExtensionProvider {
throws Exception {
XHTMLExtension xhtmlExtension = new XHTMLExtension();
boolean done = false;
StringBuffer buffer = new StringBuffer();
StringBuilder buffer = new StringBuilder();
int startDepth = parser.getDepth();
int depth = parser.getDepth();
String lastTag = "";
@ -59,7 +59,7 @@ public class XHTMLExtensionProvider implements PacketExtensionProvider {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("body")) {
buffer = new StringBuffer();
buffer = new StringBuilder();
depth = parser.getDepth();
}
lastTag = parser.getText();

View file

@ -42,7 +42,7 @@ class SimpleUserSearch extends IQ {
public String getChildElementXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<query xmlns=\"jabber:iq:search\">");
buf.append(getItemsToSearch());
buf.append("</query>");
@ -50,7 +50,7 @@ class SimpleUserSearch extends IQ {
}
private String getItemsToSearch() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
if (form == null) {
form = Form.getFormFrom(this);
@ -60,9 +60,9 @@ class SimpleUserSearch extends IQ {
return "";
}
Iterator fields = form.getFields();
Iterator<FormField> fields = form.getFields();
while (fields.hasNext()) {
FormField field = (FormField) fields.next();
FormField field = fields.next();
String name = field.getVariable();
String value = getSingleValue(field);
if (value.trim().length() > 0) {
@ -74,9 +74,9 @@ class SimpleUserSearch extends IQ {
}
private static String getSingleValue(FormField formField) {
Iterator values = formField.getValues();
Iterator<String> values = formField.getValues();
while (values.hasNext()) {
return (String) values.next();
return values.next();
}
return "";
}
@ -87,11 +87,11 @@ class SimpleUserSearch extends IQ {
boolean done = false;
List fields = new ArrayList();
List<ReportedData.Field> fields = new ArrayList<ReportedData.Field>();
while (!done) {
if (parser.getAttributeCount() > 0) {
String jid = parser.getAttributeValue("", "jid");
List valueList = new ArrayList();
List<String> valueList = new ArrayList<String>();
valueList.add(jid);
ReportedData.Field field = new ReportedData.Field("jid", valueList);
fields.add(field);
@ -100,7 +100,7 @@ class SimpleUserSearch extends IQ {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG && parser.getName().equals("item")) {
fields = new ArrayList();
fields = new ArrayList<ReportedData.Field>();
}
else if (eventType == XmlPullParser.END_TAG && parser.getName().equals("item")) {
ReportedData.Row row = new ReportedData.Row(fields);
@ -110,7 +110,7 @@ class SimpleUserSearch extends IQ {
String name = parser.getName();
String value = parser.nextText();
List valueList = new ArrayList();
List<String> valueList = new ArrayList<String>();
valueList.add(value);
ReportedData.Field field = new ReportedData.Field(name, valueList);
fields.add(field);

View file

@ -43,7 +43,7 @@ public class UserSearch extends IQ {
}
public String getChildElementXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<query xmlns=\"jabber:iq:search\">");
buf.append(getExtensionsXML());
buf.append("</query>");