Commit fbdf2a96 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Code modified to take advantage of Generics and new "for" format.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@223 b35dd754-fafc-0310-a699-88a17e54d16e
parent 97aea9cc
......@@ -125,7 +125,7 @@ public interface FormField {
*
* @return an Iterator for the default values or answered values of the question.
*/
public abstract Iterator getValues();
public abstract Iterator<String> getValues();
/**
* Returns an indicative of the format for the data to answer. Valid formats are:
......
......@@ -36,8 +36,8 @@ public class XFormFieldImpl implements XMPPFragment, FormField {
private String label;
private String variable;
private String type;
private List options = new ArrayList();
private List values = new ArrayList();
private List<Option> options = new ArrayList<Option>();
private List<String> values = new ArrayList<String>();
private ConcurrentHashSet fragments = new ConcurrentHashSet();
public XFormFieldImpl() {
......@@ -90,18 +90,18 @@ public class XFormFieldImpl implements XMPPFragment, FormField {
}
// Loop through all the values and append them to the stream writer
if (values.size() > 0) {
Iterator valuesItr = getValues();
Iterator<String> valuesItr = getValues();
while (valuesItr.hasNext()) {
xmlSerializer.writeStartElement("jabber:x:data", "value");
xmlSerializer.writeCharacters((String)valuesItr.next());
xmlSerializer.writeCharacters(valuesItr.next());
xmlSerializer.writeEndElement();
}
}
// Loop through all the options and append them to the stream writer
if (options.size() > 0) {
Iterator optionsItr = getOptions();
Iterator<Option> optionsItr = getOptions();
while (optionsItr.hasNext()) {
((Option)optionsItr.next()).send(xmlSerializer, version);
(optionsItr.next()).send(xmlSerializer, version);
}
}
Iterator frags = fragments.iterator();
......@@ -132,16 +132,16 @@ public class XFormFieldImpl implements XMPPFragment, FormField {
}
// Loop through all the values and append them to the stream writer
if (values.size() > 0) {
Iterator valuesItr = getValues();
Iterator<String> valuesItr = getValues();
while (valuesItr.hasNext()) {
field.addElement("value").addText((String)valuesItr.next());
field.addElement("value").addText(valuesItr.next());
}
}
// Loop through all the options and append them to the stream writer
if (options.size() > 0) {
Iterator optionsItr = getOptions();
Iterator<Option> optionsItr = getOptions();
while (optionsItr.hasNext()) {
field.add(((Option)optionsItr.next()).asXMLElement());
field.add((optionsItr.next()).asXMLElement());
}
}
......@@ -161,8 +161,8 @@ public class XFormFieldImpl implements XMPPFragment, FormField {
copy.required = this.required;
copy.label = this.label;
copy.type = this.type;
copy.options = (List)((ArrayList)this.options).clone();
copy.values = (List)((ArrayList)this.values).clone();
copy.options = (List<Option>)((ArrayList)this.options).clone();
copy.values = (List<String>)((ArrayList)this.values).clone();
Iterator fragmentIter = getFragments();
while (fragmentIter.hasNext()) {
......@@ -247,9 +247,9 @@ public class XFormFieldImpl implements XMPPFragment, FormField {
return variable;
}
public Iterator getValues() {
public Iterator<String> getValues() {
synchronized (values) {
return Collections.unmodifiableList(new ArrayList(values)).iterator();
return Collections.unmodifiableList(new ArrayList<String>(values)).iterator();
}
}
......@@ -263,9 +263,9 @@ public class XFormFieldImpl implements XMPPFragment, FormField {
*
* @return Iterator for the available options.
*/
private Iterator getOptions() {
private Iterator<Option> getOptions() {
synchronized (options) {
return Collections.unmodifiableList(new ArrayList(options)).iterator();
return Collections.unmodifiableList(new ArrayList<Option>(options)).iterator();
}
}
......
......@@ -256,19 +256,19 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid
registrationForm = new XDataFormImpl();
registrationForm.parse(formElement);
// Get the username sent in the form
Iterator values = registrationForm.getField("username").getValues();
username = (values.hasNext() ? (String)values.next() : " ");
Iterator<String> values = registrationForm.getField("username").getValues();
username = (values.hasNext() ? values.next() : " ");
// Get the password sent in the form
field = registrationForm.getField("password");
if (field != null) {
values = field.getValues();
password = (values.hasNext() ? (String)values.next() : " ");
password = (values.hasNext() ? values.next() : " ");
}
// Get the email sent in the form
field = registrationForm.getField("email");
if (field != null) {
values = field.getValues();
email = (values.hasNext() ? (String)values.next() : " ");
email = (values.hasNext() ? values.next() : " ");
}
}
else {
......@@ -316,21 +316,21 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid
}
// Set and save the extra user info (e.g. Full name, name visible, etc.)
if (newUser != null && registrationForm != null) {
Iterator values;
Iterator<String> values;
// Get the full name sent in the form
field = registrationForm.getField("name");
if (field != null) {
values = field.getValues();
String name = (values.hasNext() ? (String)values.next() : " ");
String name = (values.hasNext() ? values.next() : " ");
newUser.getInfo().setName(name);
}
// Get the name visible flag sent in the form
values = registrationForm.getField("x-nameVisible").getValues();
String visible = (values.hasNext() ? (String)values.next() : "1");
String visible = (values.hasNext() ? values.next() : "1");
boolean nameVisible = ("1".equals(visible) ? true : false);
// Get the email visible flag sent in the form
values = registrationForm.getField("x-emailVisible").getValues();
visible = (values.hasNext() ? (String)values.next() : "0");
visible = (values.hasNext() ? values.next() : "0");
boolean emailVisible = ("1".equals(visible) ? true : false);
// Save the extra user info
newUser.getInfo().setNameVisible(nameVisible);
......
......@@ -222,7 +222,7 @@ public interface MUCRoom extends ChatDeliverer {
* join the room.
* @throws ForbiddenException If the user is not allowed to modify the owner list.
*/
public List addOwner(String bareJID, MUCRole senderRole) throws ForbiddenException;
public List<Presence> addOwner(String bareJID, MUCRole senderRole) throws ForbiddenException;
/**
* Adds a list of users to the list of owners.
......@@ -233,7 +233,8 @@ public interface MUCRoom extends ChatDeliverer {
* join the room.
* @throws ForbiddenException If the user is not allowed to modify the owner list.
*/
public List addOwners(List newOwners, MUCRole senderRole) throws ForbiddenException;
public List<Presence> addOwners(List<String> newOwners, MUCRole senderRole)
throws ForbiddenException;
/**
* Adds a list of users to the list of admins.
......@@ -245,8 +246,8 @@ public interface MUCRoom extends ChatDeliverer {
* @throws ForbiddenException If the user is not allowed to modify the admin list.
* @throws ConflictException If the room was going to lose all its owners.
*/
public List addAdmins(List newAdmins, MUCRole senderRole) throws ForbiddenException,
ConflictException;
public List<Presence> addAdmins(List<String> newAdmins, MUCRole senderRole)
throws ForbiddenException, ConflictException;
/**
* Adds a new user to the list of admins.
......@@ -258,7 +259,7 @@ public interface MUCRoom extends ChatDeliverer {
* @throws ForbiddenException If the user is not allowed to modify the admin list.
* @throws ConflictException If the room was going to lose all its owners.
*/
public List addAdmin(String bareJID, MUCRole senderRole) throws ForbiddenException,
public List<Presence> addAdmin(String bareJID, MUCRole senderRole) throws ForbiddenException,
ConflictException;
/**
......@@ -273,7 +274,7 @@ public interface MUCRoom extends ChatDeliverer {
* @throws ConflictException If the desired room nickname is already reserved for the room or if
* the room was going to lose all its owners.
*/
public List addMember(String bareJID, String nickname, MUCRole senderRole)
public List<Presence> addMember(String bareJID, String nickname, MUCRole senderRole)
throws ForbiddenException, ConflictException;
/**
......@@ -288,7 +289,7 @@ public interface MUCRoom extends ChatDeliverer {
* @throws ForbiddenException If the user is not allowed to modify the outcast list.
* @throws ConflictException If the room was going to lose all its owners.
*/
public List addOutcast(String bareJID, String reason, MUCRole senderRole)
public List<Presence> addOutcast(String bareJID, String reason, MUCRole senderRole)
throws NotAllowedException, ForbiddenException, ConflictException;
/**
......@@ -301,7 +302,7 @@ public interface MUCRoom extends ChatDeliverer {
* @throws ForbiddenException If the user is not allowed to modify the none list.
* @throws ConflictException If the room was going to lose all its owners.
*/
public List addNone(String bareJID, MUCRole senderRole) throws ForbiddenException,
public List<Presence> addNone(String bareJID, MUCRole senderRole) throws ForbiddenException,
ConflictException;
/**
......
......@@ -102,8 +102,8 @@ public class IQAdminHandler {
throw new ForbiddenException();
}
String jid;
for (Iterator it = room.getOutcasts(); it.hasNext();) {
jid = (String)it.next();
for (Iterator<String> it = room.getOutcasts(); it.hasNext();) {
jid = it.next();
metaData = new MetaDataFragment("http://jabber.org/protocol/muc#admin",
"item");
metaData.setProperty("item:affiliation", "outcast");
......@@ -123,15 +123,15 @@ public class IQAdminHandler {
throw new ForbiddenException();
}
String jid;
for (Iterator it = room.getMembers(); it.hasNext();) {
jid = (String)it.next();
for (Iterator<String> it = room.getMembers(); it.hasNext();) {
jid = it.next();
metaData = new MetaDataFragment("http://jabber.org/protocol/muc#admin",
"item");
metaData.setProperty("item:affiliation", "member");
metaData.setProperty("item:jid", jid);
try {
List roles = room.getOccupantsByBareJID(jid);
role = (MUCRole)roles.get(0);
List<MUCRole> roles = room.getOccupantsByBareJID(jid);
role = roles.get(0);
metaData.setProperty("item:role", role.getRoleAsString());
metaData.setProperty("item:nick", role.getNickname());
}
......@@ -150,8 +150,8 @@ public class IQAdminHandler {
&& MUCRole.OWNER != senderRole.getAffiliation()) {
throw new ForbiddenException();
}
for (Iterator roles = room.getModerators(); roles.hasNext();) {
role = (MUCRole)roles.next();
for (Iterator<MUCRole> roles = room.getModerators(); roles.hasNext();) {
role = roles.next();
metaData = new MetaDataFragment("http://jabber.org/protocol/muc#admin",
"item");
metaData.setProperty("item:role", "moderator");
......@@ -170,8 +170,8 @@ public class IQAdminHandler {
if (MUCRole.MODERATOR != senderRole.getRole()) {
throw new ForbiddenException();
}
for (Iterator roles = room.getParticipants(); roles.hasNext();) {
role = (MUCRole)roles.next();
for (Iterator<MUCRole> roles = room.getParticipants(); roles.hasNext();) {
role = roles.next();
metaData = new MetaDataFragment("http://jabber.org/protocol/muc#admin",
"item");
metaData.setProperty("item:role", "participant");
......@@ -195,10 +195,11 @@ public class IQAdminHandler {
String jid = null;
String nick;
String target = null;
boolean hasAffiliation = ((Element) itemsList.get(0)).attributeValue("affiliation") != null;
boolean hasAffiliation = ((Element) itemsList.get(0)).attributeValue("affiliation") !=
null;
// Keep a registry of the updated presences
List presences = new ArrayList(itemsList.size());
List<Presence> presences = new ArrayList<Presence>(itemsList.size());
// Collect the new affiliations or roles for the specified jids
for (Iterator items = itemsList.iterator(); items.hasNext();) {
......@@ -288,8 +289,8 @@ public class IQAdminHandler {
// Send the updated presences to the room occupants
try {
for (Iterator it = presences.iterator(); it.hasNext();) {
room.send((Presence)it.next());
for (Presence presence : presences) {
room.send(presence);
}
}
catch (UnauthorizedException e) {
......
......@@ -151,7 +151,7 @@ public class IQMUCRegisterHandler extends IQHandler {
else if (IQ.SET.equals(packet.getType())) {
try {
// Keep a registry of the updated presences
List presences = new ArrayList();
List<Presence> presences = new ArrayList<Presence>();
reply = packet.createResult();
XMPPFragment iq = packet.getChildFragment();
......@@ -171,9 +171,9 @@ public class IQMUCRegisterHandler extends IQHandler {
XDataFormImpl registrationForm = new XDataFormImpl();
registrationForm.parse(formElement);
// Get the desired nickname sent in the form
Iterator values = registrationForm.getField("muc#register_roomnick")
Iterator<String> values = registrationForm.getField("muc#register_roomnick")
.getValues();
String nickname = (values.hasNext() ? (String)values.next() : null);
String nickname = (values.hasNext() ? values.next() : null);
// TODO The rest of the fields of the form are ignored. If we have a
// requirement in the future where we need those fields we'll have to change
......@@ -190,8 +190,8 @@ public class IQMUCRegisterHandler extends IQHandler {
}
// Send the updated presences to the room occupants
try {
for (Iterator it = presences.iterator(); it.hasNext();) {
room.send((Presence)it.next());
for (Presence presence : presences) {
room.send(presence);
}
}
catch (UnauthorizedException e) {
......
......@@ -127,8 +127,8 @@ public class IQOwnerHandler {
MetaDataFragment ownerMetaData;
String jid;
MUCRole role;
for (Iterator owners = room.getOwners(); owners.hasNext();) {
jid = (String)owners.next();
for (Iterator<String> owners = room.getOwners(); owners.hasNext();) {
jid = owners.next();
ownerMetaData =
new MetaDataFragment("http://jabber.org/protocol/muc#owner",
"item");
......@@ -136,8 +136,8 @@ public class IQOwnerHandler {
ownerMetaData.setProperty("item:jid", jid);
// Add role and nick to the metadata if the user is in the room
try {
List roles = room.getOccupantsByBareJID(jid);
role = (MUCRole)roles.get(0);
List<MUCRole> roles = room.getOccupantsByBareJID(jid);
role = roles.get(0);
ownerMetaData.setProperty("item:role", role.getRoleAsString());
ownerMetaData.setProperty("item:nick", role.getNickname());
}
......@@ -155,8 +155,8 @@ public class IQOwnerHandler {
MetaDataFragment adminMetaData;
String jid;
MUCRole role;
for (Iterator admins = room.getAdmins(); admins.hasNext();) {
jid = (String)admins.next();
for (Iterator<String> admins = room.getAdmins(); admins.hasNext();) {
jid = admins.next();
adminMetaData =
new MetaDataFragment("http://jabber.org/protocol/muc#owner",
"item");
......@@ -164,8 +164,8 @@ public class IQOwnerHandler {
adminMetaData.setProperty("item:jid", jid);
// Add role and nick to the metadata if the user is in the room
try {
List roles = room.getOccupantsByBareJID(jid);
role = (MUCRole)roles.get(0);
List<MUCRole> roles = room.getOccupantsByBareJID(jid);
role = roles.get(0);
adminMetaData.setProperty("item:role", role.getRoleAsString());
adminMetaData.setProperty("item:nick", role.getNickname());
}
......@@ -185,7 +185,7 @@ public class IQOwnerHandler {
}
else {
// The client is modifying the list of owners or admins
Map jids = new HashMap();
Map<String,String> jids = new HashMap<String,String>();
String bareJID = null;
String nick;
// Collect the new affiliations for the specified jids
......@@ -210,7 +210,7 @@ public class IQOwnerHandler {
}
// Keep a registry of the updated presences
List presences = new ArrayList(jids.size());
List<Presence> presences = new ArrayList<Presence>(jids.size());
room.lock.readLock().lock();
try {
......@@ -227,9 +227,9 @@ public class IQOwnerHandler {
room.lock.writeLock().lock();
try {
String targetAffiliation = null;
for (Iterator it = jids.keySet().iterator(); it.hasNext();) {
bareJID = (String)it.next();
targetAffiliation = (String)jids.get(bareJID);
for (Iterator<String> it = jids.keySet().iterator(); it.hasNext();) {
bareJID = it.next();
targetAffiliation = jids.get(bareJID);
if ("owner".equals(targetAffiliation)) {
// Add the new user as an owner of the room
presences.addAll(room.addOwner(bareJID, senderRole));
......@@ -259,8 +259,8 @@ public class IQOwnerHandler {
// Send the updated presences to the room occupants
try {
for (Iterator it = presences.iterator(); it.hasNext();) {
room.send((Presence)it.next());
for (Presence presence : presences) {
room.send(presence);
}
}
catch (UnauthorizedException e) {
......@@ -311,14 +311,14 @@ public class IQOwnerHandler {
private void processConfigurationForm(XDataFormImpl completedForm, MUCRole senderRole, IQ reply)
throws ForbiddenException, ConflictException {
Iterator values;
Iterator<String> values;
String booleanValue;
List list;
FormField field;
// Get the new list of admins
field = completedForm.getField("muc#roomconfig_roomadmins");
List admins = new ArrayList();
List<String> admins = new ArrayList<String>();
if (field != null) {
values = field.getValues();
while (values.hasNext()) {
......@@ -328,7 +328,7 @@ public class IQOwnerHandler {
// Get the new list of owners
field = completedForm.getField("muc#roomconfig_roomowners");
List owners = new ArrayList();
List<String> owners = new ArrayList<String>();
if (field != null) {
values = field.getValues();
while (values.hasNext()) {
......@@ -350,28 +350,26 @@ public class IQOwnerHandler {
field = completedForm.getField("muc#roomconfig_roomname");
if (field != null) {
values = field.getValues();
room.setNaturalLanguageName((values.hasNext() ? (String)values.next() : " "));
room.setNaturalLanguageName((values.hasNext() ? values.next() : " "));
}
field = completedForm.getField("muc#roomconfig_roomdesc");
if (field != null) {
values = field.getValues();
room.setDescription((values.hasNext() ? (String)values.next() : " "));
room.setDescription((values.hasNext() ? values.next() : " "));
}
field = completedForm.getField("muc#roomconfig_changesubject");
if (field != null) {
values = field.getValues();
booleanValue = (values.hasNext() ? (String)values.next() : "1");
booleanValue = (values.hasNext() ? values.next() : "1");
room.setCanOccupantsChangeSubject(("1".equals(booleanValue) ? true : false));
}
field = completedForm.getField("muc#roomconfig_maxusers");
if (field != null) {
values = field.getValues();
room
.setMaxUsers((values.hasNext() ? Integer.parseInt((String) values.next())
: 30));
room.setMaxUsers((values.hasNext() ? Integer.parseInt(values.next()) : 30));
}
field = completedForm.getField("muc#roomconfig_presencebroadcast");
......@@ -387,14 +385,14 @@ public class IQOwnerHandler {
field = completedForm.getField("muc#roomconfig_publicroom");
if (field != null) {
values = field.getValues();
booleanValue = (values.hasNext() ? (String)values.next() : "1");
booleanValue = (values.hasNext() ? values.next() : "1");
room.setPublicRoom(("1".equals(booleanValue) ? true : false));
}
field = completedForm.getField("muc#roomconfig_persistentroom");
if (field != null) {
values = field.getValues();
booleanValue = (values.hasNext() ? (String)values.next() : "1");
booleanValue = (values.hasNext() ? values.next() : "1");
boolean isPersistent = ("1".equals(booleanValue) ? true : false);
// Delete the room from the DB if it's no longer persistent
if (room.isPersistent() && !isPersistent) {
......@@ -406,35 +404,35 @@ public class IQOwnerHandler {
field = completedForm.getField("muc#roomconfig_moderatedroom");
if (field != null) {
values = field.getValues();
booleanValue = (values.hasNext() ? (String)values.next() : "1");
booleanValue = (values.hasNext() ? values.next() : "1");
room.setModerated(("1".equals(booleanValue) ? true : false));
}
field = completedForm.getField("muc#roomconfig_inviteonly");
if (field != null) {
values = field.getValues();
booleanValue = (values.hasNext() ? (String)values.next() : "1");
booleanValue = (values.hasNext() ? values.next() : "1");
room.setInvitationRequiredToEnter(("1".equals(booleanValue) ? true : false));
}
field = completedForm.getField("muc#roomconfig_allowinvites");
if (field != null) {
values = field.getValues();
booleanValue = (values.hasNext() ? (String)values.next() : "1");
booleanValue = (values.hasNext() ? values.next() : "1");
room.setCanOccupantsInvite(("1".equals(booleanValue) ? true : false));
}
field = completedForm.getField("muc#roomconfig_passwordprotectedroom");
if (field != null) {
values = field.getValues();
booleanValue = (values.hasNext() ? (String)values.next() : "1");
booleanValue = (values.hasNext() ? values.next() : "1");
boolean isPasswordProtected = "1".equals(booleanValue);
if (isPasswordProtected) {
// The room is password protected so set the new password
field = completedForm.getField("muc#roomconfig_roomsecret");
if (field != null) {
values = completedForm.getField("muc#roomconfig_roomsecret").getValues();
room.setPassword((values.hasNext() ? (String)values.next() : null));
room.setPassword((values.hasNext() ? values.next() : null));
}
}
else {
......@@ -446,14 +444,14 @@ public class IQOwnerHandler {
field = completedForm.getField("muc#roomconfig_whois");
if (field != null) {
values = field.getValues();
booleanValue = (values.hasNext() ? (String)values.next() : "1");
booleanValue = (values.hasNext() ? values.next() : "1");
room.setCanAnyoneDiscoverJID(("anyone".equals(booleanValue) ? true : false));
}
field = completedForm.getField("muc#roomconfig_enablelogging");
if (field != null) {
values = field.getValues();
booleanValue = (values.hasNext() ? (String)values.next() : "1");
booleanValue = (values.hasNext() ? values.next() : "1");
room.setLogEnabled(("1".equals(booleanValue) ? true : false));
}
......@@ -565,14 +563,14 @@ public class IQOwnerHandler {
field = configurationForm.getField("muc#roomconfig_roomadmins");
field.clearValues();
for (Iterator it = room.getAdmins(); it.hasNext();) {
field.addValue((String)it.next());
for (Iterator<String> it = room.getAdmins(); it.hasNext();) {
field.addValue(it.next());
}
field = configurationForm.getField("muc#roomconfig_roomowners");
field.clearValues();
for (Iterator it = room.getOwners(); it.hasNext();) {
field.addValue((String)it.next());
for (Iterator<String> it = room.getOwners(); it.hasNext();) {
field.addValue(it.next());
}
}
finally {
......
......@@ -237,26 +237,26 @@ class MUCPersistentRoomSurrogate implements MUCRoom, Cacheable {
throw new UnsupportedOperationException();
}
public List addOwner(String bareJID, MUCRole sendRole) throws ForbiddenException {
public List<Presence> addOwner(String bareJID, MUCRole sendRole) throws ForbiddenException {
throw new UnsupportedOperationException();
}
public List addAdmin(String bareJID, MUCRole sendRole) throws ForbiddenException,
public List<Presence> addAdmin(String bareJID, MUCRole sendRole) throws ForbiddenException,
ConflictException {
throw new UnsupportedOperationException();
}
public List addMember(String bareJID, String nickname, MUCRole sendRole)
public List<Presence> addMember(String bareJID, String nickname, MUCRole sendRole)
throws ForbiddenException, ConflictException {
throw new UnsupportedOperationException();
}
public List addOutcast(String bareJID, String reason, MUCRole sendRole)
public List<Presence> addOutcast(String bareJID, String reason, MUCRole sendRole)
throws NotAllowedException, ForbiddenException, ConflictException {
throw new UnsupportedOperationException();
}
public List addNone(String bareJID, MUCRole sendRole) throws ForbiddenException,
public List<Presence> addNone(String bareJID, MUCRole sendRole) throws ForbiddenException,
ConflictException {
throw new UnsupportedOperationException();
}
......@@ -470,12 +470,13 @@ class MUCPersistentRoomSurrogate implements MUCRoom, Cacheable {
throw new UnsupportedOperationException();
}
public List addAdmins(List newAdmins, MUCRole sendRole) throws ForbiddenException,
ConflictException {
public List<Presence> addAdmins(List<String> newAdmins, MUCRole sendRole)
throws ForbiddenException, ConflictException {
throw new UnsupportedOperationException();
}
public List addOwners(List newOwners, MUCRole sendRole) throws ForbiddenException {
public List<Presence> addOwners(List<String> newOwners, MUCRole sendRole)
throws ForbiddenException {
throw new UnsupportedOperationException();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment